Alright I am still pretty new to this. So the idea is I would like to take an array from one class, send it through some equations and then output an updated version. I also need it to iterate a few times. My best guess at this was to setup a while loop in my main class with the class method inside of it that corresponds to the array updater. Its just spitting out the same values (not updated) I would really appreciate any suggestions or tips on what I might be doing wrong.
**If you are going to tell me to read a book or take a class, please move on. I'm learning on my own and this site is extremely helpful only when it is used correctly. Thanks
The code is really long so I will try to post what snippets I feel will be most helpful.
** This portion contains the original arrays (rad[ ] , vol[ ]...) I would like to update
public class InitialGrids {
PlanMat pm = new PlanMat();
int iic,ioc,iman ;
int nic, noc;
int iccomp, occomp, mcomp;
double masIC, masOC, masMAN;
double volp;
double radIC, radOC, radp;
public int iMat[ ];
public double rad[ ];
public double vol[ ];
public double rho0[ ];
public double mas[ ];
public double dmas[ ];
double pi = Math.PI;
public InitialGrids(int icMat, int ocMat, int manMat, int shells, double massP, double ficore, double focore, double fman)
{}
**This class is supposed to update the array. sorry for the length
public class Iterator
{
final double G;
final double PI;
double Pave;
double x, z, dy, dz, dydx; // this is for the iteration that will update the density
double delta;
public double grav[ ];
public double P[ ];
public double rho0n[ ];
int mix;
public Iterator(int icMat, int ocMat, int manMat, int shells, double massP, double ficore,
double focore, double fman)
{
InitialGrids ig = new InitialGrids(icMat, ocMat, manMat, shells, massP, ficore,
focore, fman);
Constants c = new Constants();
PlanMat pm = new PlanMat();
G = c.GC;
PI = c.PI;
// calculation of gravity force at each shell
grav = new double [ shells + 1 ];
for(int k = 0; k <= shells; k++)
{
grav[ k ] = ( (G*ig.mas[k]) / (Math.pow(ig.rad[k], 2)) );
}
// calculation of pressure at zone boundaries
P = new double [ shells + 1 ];
for(int k = shells - 1; k >= 0; k-- )
{
P[shells] = 0;
P[ k ] = 0.5 * (grav[ k + 1 ] + grav[ k ]) * (ig.rad[ k + 1] - ig.rad[ k ]) *
ig.rho0[ k + 1 ];
}
// this will calculate for the average pressure grid
rho0n = new double[ shells + 1 ];
for(int k = 1; k <= shells; k++)
{
rho0n[ 0 ] = 0;
Pave = 0.5 * (P[ k ] + P[ k - 1 ]);
if(pm.eos[ ig.iMat[ k ] ] == 1)
{
z = 0.75*(pm.Ksp[ ig.iMat[ k ] ] - 4.0);
x = 1.0;
for(int j = 1; j <= 20; j++)
{
dy = 1.5 * (pm.Ks0[ ig.iMat[k] ]) * Math.pow(x, 5) *
(z * Math.pow(x,4) + (1.0 - 2.0 * z) * Math.pow(x, 2) + (z - 1.0)) - Pave ;
dydx = 1.5 * (pm.Ks0[ ig.iMat[ k ] ]) * Math.pow(x, 4) *
(9.0 * z *
Math.pow(x, 4) + 7.0 * (1.0 - 2*z) * Math.pow(x, 2) + 5 * (z - 1.8)) ;
x = x - ( dy / dydx );
}
rho0n[ k ] = ig.rho0[ k ] * Math.pow(x, 3);
}
else
{
rho0n[ k ] = pm.c[ ig.iMat[k] ] * Math.pow(Pave , pm.nn[ ig.iMat[k] ]);
rho0n[ k ] = rho0n[ k ] + pm.rho0[ ig.iMat[k] ] ;
}
}
// The following will: define the change in density after iterations, mix the old and new densities and then update the radial grids
delta = (Math.abs( rho0n[1] / ig.rho0[1] ) - 1);
mix = 1;
for(int k = 0; k <= shells; k++)
{
rho0n[ k ] = rho0n[ k ] + ig.rho0[ k ] * (1 - mix); //notice that rho0 = rho in desch's code. dont worry
}
// radius update using density dependent volume and then calculating radius from volume
for(int k = 1; k <= shells; k++)
{
ig.rad[ 0 ] = 0;
ig.vol[ 0 ] = 0;
ig.vol[ k ] = ( ig.dmas[ k ] / ig.rho0[ k ] );
ig.rad[ k ] = Math.pow( ( 0.75 * ig.dmas[ k ] / ig.rad[ k ] / PI + Math.pow(ig.rad[ k - 1 ], 3) ) , 1.0 / 3 );
}
InitialGrid), and have an array ofInitialGridinstead. Regarding your problem, you haven't posted any of the code that actually deals with changing anything.