int main() { Grid *g; /*@ \label{improved1A} @*/ double imp0 = 377.0; int mm; ALLOC_1D(g, 1, Grid); /*@ \label{improved1F} @*/ SizeX = 200; // size of grid /*@ \label{improved1B} @*/ MaxTime = 250; // duration of simulation /*@ \label{improved1E} @*/ Cdtds = 1.0; // Courant number (unused) ALLOC_1D(g->ez, SizeX, double); /*@ \label{improved1C} @*/ ALLOC_1D(g->hy, SizeX, double); /*@ \label{improved1D} @*/ /* do time stepping */ for (Time = 0; Time < MaxTime; Time++) { /* update magnetic field */ for (mm = 0; mm < SizeX - 1; mm++) Hy(mm) = Hy(mm) + (Ez(mm + 1) - Ez(mm)) / imp0; /* update electric field */ for (mm = 1; mm < SizeX; mm++) Ez(mm) = Ez(mm) + (Hy(mm) - Hy(mm - 1)) * imp0; /* hardwire a source node */ Ez(0) = exp(-(Time - 30.0) * (Time - 30.0) / 100.0); printf("%g\n", Ez(50)); } /* end of time-stepping */ return 0; }
int main() { Grid *g; ALLOC_1D(g, 1, Grid); // allocate memory for Grid gridInit(g); // initialize the grid ezIncInit(g); snapshotInit2d(g); // initialize snapshots /* do time stepping */ for (Time = 0; Time < MaxTime; Time++) { updateH2d(g); // update magnetic field updateE2d(g); // update electric field Ez(SizeX / 2, SizeY / 2) = ezInc(Time, 0.0); // add a source snapshot2d(g); // take a snapshot (if appropriate) } // end of time-stepping return 0; }
int main() { Grid *g; /*@ \label{improved2A} @*/ ALLOC_1D(g, 1, Grid); // allocate memory for Grid /*@ \label{improved2B} @*/ gridInit2(g); // initialize the grid /*@ \label{improved2C} @*/ ezIncInit(g); // initialize source function /*@ \label{improved2H} @*/ /* do time stepping */ for (Time = 0; Time < MaxTime; Time++) { /*@ \label{improved2D} @*/ updateH2(g); // update magnetic field /*@ \label{improved2E} @*/ updateE2(g); // update electric field /*@ \label{improved2F} @*/ Ez(0) = ezInc(Time, 0.0); // apply source function /*@ \label{improved2Z} @*/ printf("%g\n", Ez(50)); // print output /*@ \label{improved2G} @*/ } // end of time-stepping return 0; }
int main() { Grid *g; ALLOC_1D(g, 1, Grid); // allocate memory for Grid gridInit(g); // initialize the grid abcInit(g); // initialize ABC /*@ \label{abcdemo1A} @*/ tfsfInit(g); // initialize TFSF boundary snapshotInit(g); // initialize snapshots /* do time stepping */ for (Time = 0; Time < MaxTime; Time++) { updateH3(g); // update magnetic field tfsfUpdate(g); // correct field on TFSF boundary updateE3(g); // update electric field /*b*/ abc(g);/*n*/ // apply ABC -- after E-field update/*@ \label{abcdemo1B} @*/ snapshot(g); // take a snapshot (if appropriate) } /* end of time-stepping */ return 0; }