void SequentialLoop(int startupflags) { int i; double theta; long daytime, newtinc; Entity et; Vector sunpos; while (plausible && actime < tend) { daytime = ((int)(timeofday*3600.)+actime) % 86400; printf("Now at %li seconds = %02li:%02li:%02li ", actime, daytime / 3600, (daytime % 3600)/60, daytime % 60); ActualiseValuesInTime(actime); /* Actualise Border values */ for (et = maxentity; et--; ) CalculateLayerAverage(g[et], pstat, avg+et*nz); SetAvgMountains(); CalcMeanHydrostaticPressure(); InterpolateToFaces(); /* Interpolate wind speeds from center to faces */ InterpolateToCenter(-1., pressuretype == NONHYDROSTATIC); if (tstart == actime) Continuity(); CheckTimeStep(&tinc, &chemtinc, 0.8); if (pressuretype == NONHYDROSTATIC) ApplyBuoyancy(tinc); /* Calculate Buoyancy */ if (pressuretype != NOPRESSURE) { /* Calc wind acceleration */ switch (pressuretype) { /* Calculate Pressure field */ case HYDROSTATIC : CalcHydrostaticPressure(); break; case NONHYDROSTATIC : SolveForPressure(tinc); break; } ApplyPressure(tinc); } Continuity(); /* Mass conservation */ InterpolateToCenter(1., pressuretype == NONHYDROSTATIC); if (coriolistype != NOCORIOLIS) ApplyCoriolis(tinc); if (filtertype != NO_FILTER) { SetBoundary(WWIND+1); switch (filtertype) { case PEPPER_FILTER : for (i = nz; i--; ) for (et = HUMIDITY; et--; ) ApplyFilter(g[et]+i*layer, pstat+i*layer, spatialfilter); break; case SHAPIRO_FILTER : for (i = nz; i--; ) { for (et = HUMIDITY; et--; ) ShapiroFilter(g[et]+i*layer, pstat+i*layer, 3, spatialfilter); /* if (turbtype == KEPS_T) { ShapiroFilter(g[TKE]+i*layer, pstat+i*layer, 3, spatialfilter); ShapiroFilter(g[EPS]+i*layer, pstat+i*layer, 3, spatialfilter); } */ } break; case DIFFUSION_FILTER : for (i = nz; i--; ) for (et = HUMIDITY; et--; ) ShapiroFilter(g[et]+i*layer, pstat+i*layer, 1, spatialfilter); break; } } SetBoundary(WWIND+1); CheckTimeStep(&newtinc, &chemtinc, 1.); if (newtinc < tinc) { fprintf(stderr, "Warning: Time step had to be changed in the middle of iteration\n"); tinc = newtinc; } chemtinc = (chemtime <= actime ? chemtinc : 0); if (nsubs) printf("chemtinc = %3ld ", chemtinc); if (advection || windadvection) switch (advectiontype) { case MPDATA_A : Advect(tinc, chemtinc); break; case PPM_A : PPM_Transport(tinc, chemtinc, smiord); break; } if (dampinglayer) DampTop(); if (groundinterface || shortwaveradiation) { GroundInterface(timeofday + (double)actime / 3600., dayofyear, tinc, &sunpos); sunelevation = (sunpos.z > 0. ? 57.29578 * asin(sunpos.z) : 0.); } if (cloudwater) CloudPhysics(); if (turbtype == TTTT) { if (groundinterface) CalcGroundTurbulence(tinc); CalcTransilientTurbulence(tinc); } else if (turbtype == KEPS_T) { CalcKEpsilon(tinc); if (groundinterface) CalcGroundTurbulence(tinc); CalcKTurb(tinc, chemtinc); } Emit(tinc); Deposit(tinc); if (!(radiationtype && shortwaveradiation) && // When using the two-stream module, ChemicalTimeStep // must be called from within ShortWaveRadiation! nsubs && actime % tchem == 0) ChemicalTimeStep(tchem, &sunpos); SetBoundary(chemtinc ? maxentity : SUBS); // Call ModuleManager McInterface::modmanager.DoCalc(actime+tinc); /* TestChemicals("Boundary"); */ actime += tinc; chemtime += chemtinc; if (!(startupflags & NO_OUTPUT)) { WriteOutData(actime, FALSE); WriteToDomainFiles(actime); } if (dumpnow || (dumptime && (actime % dumptime == 0))) { MakeAFullDump(); dumpnow = 0; } if (mailtime) { mailtime = 0; MailTheTime(); } printf("Energy = %lf\n", CalcTopEnergy()); } }
void WorkersLoop(int startupflags) { double theta; long daytime, newtinc; Entity et; Vector sunpos; VarDesc *v; int i, j, k; char varname[80]; while (1) { switch (GetCommand()) { case DO_TIME_STEP : if (plausible) { daytime = ((int)(timeofday*3600.)+actime) % 86400; ActualiseValuesInTime(actime); /* Actualise Border values */ for (et = maxentity; et--; ) CalculateLayerAverage(g[et], pstat, avg+et*nz); SetAvgMountains(); CalcMeanHydrostaticPressure(); InterpolateToFaces(); /* Interpolate wind speeds from center to faces */ InterpolateToCenter(-1., pressuretype == NONHYDROSTATIC); if (tstart == actime) Continuity(); CheckTimeStep(&tinc, &chemtinc, 0.8); if (pressuretype == NONHYDROSTATIC) ApplyBuoyancy(tinc); /* Calculate Buoyancy */ if (pressuretype != NOPRESSURE) { /* Calc wind acceleration */ switch (pressuretype) { /* Calculate Pressure field */ case HYDROSTATIC : CalcHydrostaticPressure(); break; case NONHYDROSTATIC : SolveForPressure(tinc); break; } ApplyPressure(tinc); } Continuity(); /* Mass conservation */ InterpolateToCenter(1., pressuretype == NONHYDROSTATIC); if (coriolistype != NOCORIOLIS) ApplyCoriolis(tinc); if (filtertype != NO_FILTER) { SetBoundary(WWIND+1); /* Set Boundary for Wind only */ switch (filtertype) { case PEPPER_FILTER : for (i = nz; i--; ) for (et = HUMIDITY; et--; ) ApplyFilter(g[et]+i*layer, pstat+i*layer, spatialfilter); break; case SHAPIRO_FILTER : for (i = nz; i--; ) for (et = HUMIDITY; et--; ) ShapiroFilter(g[et]+i*layer, pstat+i*layer, 3, spatialfilter); break; case DIFFUSION_FILTER : for (i = nz; i--; ) for (et = HUMIDITY; et--; ) ShapiroFilter(g[et]+i*layer, pstat+i*layer, 1, spatialfilter); break; } } SetBoundary(WWIND+1); CheckTimeStep(&newtinc, &chemtinc, 1.); if (newtinc < tinc) { tinc = newtinc; } chemtinc = (chemtime <= actime ? chemtinc : 0); if (advection || windadvection) switch (advectiontype) { case MPDATA_A : Advect(tinc, chemtinc); break; case PPM_A : PPM_Transport(tinc, chemtinc, smiord); break; } if (dampinglayer) DampTop(); if (groundinterface || shortwaveradiation) { GroundInterface(timeofday + (double)actime / 3600., dayofyear, tinc, &sunpos); sunelevation = (sunpos.z > 0. ? 57.29578 * asin(sunpos.z) : 0.); } if (cloudwater) CloudPhysics(); if (turbtype == TTTT) { if (groundinterface) CalcGroundTurbulence(tinc); CalcTransilientTurbulence(tinc); } else if (turbtype == KEPS_T) { CalcKEpsilon(tinc); if (groundinterface) CalcGroundTurbulence(tinc); CalcKTurb(tinc, chemtinc); } Emit(tinc); Deposit(tinc); if (!(radiationtype && shortwaveradiation) && // When using the two-stream module, ChemicalTimeStep // mus be called from within ShortWaveRadiation! nsubs && actime % tchem == 0) ChemicalTimeStep(tchem, &sunpos); SetBoundary(chemtinc ? maxentity : SUBS); // Call ModuleManager McInterface::modmanager.DoCalc(actime+tinc); actime += tinc; chemtime += chemtinc; if (dumpnow || (dumptime && (actime % dumptime == 0))) { MakeAFullDump(); dumpnow = 0; } } /* if (plausible) */ SendStatus(plausible); break; case SENDGRIDVAL : pvm_upkint((int *)&et, 1, 1); pvm_upkint(&i, 1, 1); pvm_upkint(&j, 1, 1); pvm_upkint(&k, 1, 1); pvm_initsend(PvmDataRaw); pvm_pkdouble(g[et]+i*row+j+k*layer, 1, 1); pvm_send(myparent, VALUES); break; case SENDMESHVAL : pvm_upkstr(varname); v = GetNamedVar(varname); pvm_upkint(&i, 1, 1); pvm_upkint(&j, 1, 1); pvm_upkint(&k, 1, 1); pvm_initsend(PvmDataRaw); if (v->storetype == PROC_VAL) { theta = v->v.proc(k, i, j, v); pvm_pkdouble(&theta, 1, 1); } else pvm_pkdouble(GetNamedVar(varname)->v.d+i*row+j+k*layer, 1, 1); pvm_send(myparent, VALUES); break; case SENDGRID : pvm_upkint((int *)&et, 1, 1); SendMeshToMaster(g[et], 0, ALL_DIM); break; case SENDMESH : pvm_upkstr(varname); v = GetNamedVar(varname); if (v->storetype == PROC_VAL) { for (k = nz; k--; ) for (i = nx+1; i--; ) for (j = ny+1; j--; ) flux[0][i*row+j+k*layer] = v->v.proc(k, i, j, v); SendMeshToMaster(flux[0], 0, v->dims); memset(flux[0], 0, mesh * sizeof(double)); } else SendMeshToMaster(v->v.d, 0, v->dims); break; case SENDGROUND : SendGroundToMaster(); break; case EXIT : pvm_exit(); exit (0); } } }
void Calculate(int data) { glViewport(0, 0, g_iWidth, g_iHeight); Advect(Velocity.Ping, Velocity.Ping, Boundaries, Velocity.Pong, VelocityDissipation); SwapSurfaces(&Velocity); /*Advect(Velocity2.Ping, Velocity2.Ping, Boundaries, Velocity2.Pong, VelocityDissipation); SwapSurfaces(&Velocity2);*/ Advect(Velocity.Ping, Temperature.Ping, Boundaries, Temperature.Pong, TemperatureDissipation); SwapSurfaces(&Temperature); /*Advect(Velocity2.Ping, Temperature2.Ping, Boundaries, Temperature2.Pong, TemperatureDissipation); SwapSurfaces(&Temperature2);*/ Advect(Velocity.Ping, Density.Ping, Boundaries, Density.Pong, DensityDissipation); SwapSurfaces(&Density); /*Advect(Velocity2.Ping, Density2.Ping, Boundaries, Density2.Pong, DensityDissipation); SwapSurfaces(&Density2);*/ glutMouseFunc(Mouse); ApplyBuoyancy(Velocity.Ping, Temperature.Ping, Density.Ping, Velocity.Pong, ax, ay); SwapSurfaces(&Velocity); /*ApplyBuoyancy2(Velocity.Ping, Temperature.Ping, Density.Ping, Velocity.Pong); SwapSurfaces(&Velocity);*/ ApplyImpulse(Temperature.Ping, ImpulsePosition, ImpulseTemperature); ApplyImpulse(Density.Ping, ImpulsePosition, ImpulseDensity); /*ApplyImpulse(Temperature2.Ping, ImpulsePosition2, ImpulseTemperature); ApplyImpulse(Density2.Ping, ImpulsePosition2, ImpulseDensity);*/ ComputeDivergence(Velocity.Ping, Boundaries, Divergence); ClearSurface(Pressure.Ping, 0); /*ComputeDivergence(Velocity2.Ping, Boundaries, Divergence2); ClearSurface(Pressure2.Ping, 0);*/ for (int i = 0; i < NumJacobiIterations; ++i) { Jacobi(Pressure.Ping, Divergence, Boundaries, Pressure.Pong); SwapSurfaces(&Pressure); } /*for (int i = 0; i < NumJacobiIterations; ++i) { Jacobi(Pressure2.Ping, Divergence2, Boundaries, Pressure2.Pong); SwapSurfaces(&Pressure2); }*/ SubtractGradient(Velocity.Ping, Pressure.Ping, Boundaries, Velocity.Pong); SwapSurfaces(&Velocity); /*SubtractGradient(Velocity2.Ping, Pressure2.Ping, Boundaries, Velocity2.Pong); SwapSurfaces(&Velocity2);*/ glutPostRedisplay(); glutTimerFunc(30, Calculate, 1); }