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; }
/* update magnetic field */ void updateH3(Grid *g) { int mm; for (mm = 0; mm < SizeX - 1; mm++) Hy(mm) = Chyh(mm) * Hy(mm) + /*@ \label{update3A} @*/ Chye(mm) * (Ez(mm + 1) - Ez(mm)); return; }
/* update electric field */ void updateE3(Grid *g) { int mm; for (mm = 1; mm < SizeX - 1; mm++) Ez(mm) = Ceze(mm) * Ez(mm) + /*@ \label{update3B} @*/ Cezh(mm) * (Hy(mm) - Hy(mm - 1)); return; }
void KneeJointR::checkInitPos( SP::SiconosVector x1 , SP::SiconosVector x2 ) { //x1->display(); double X1 = x1->getValue(0); double Y1 = x1->getValue(1); double Z1 = x1->getValue(2); double q10 = x1->getValue(3); double q11 = x1->getValue(4); double q12 = x1->getValue(5); double q13 = x1->getValue(6); double X2 = 0; double Y2 = 0; double Z2 = 0; double q20 = 1; double q21 = 0; double q22 = 0; double q23 = 0; if(x2) { //printf("checkInitPos x2:\n"); //x2->display(); X2 = x2->getValue(0); Y2 = x2->getValue(1); Z2 = x2->getValue(2); q20 = x2->getValue(3); q21 = x2->getValue(4); q22 = x2->getValue(5); q23 = x2->getValue(6); } if (Hx(X1, Y1, Z1, q10, q11, q12, q13, X2, Y2, Z2, q20, q21, q22, q23) > DBL_EPSILON ) { std::cout << "KneeJointR::checkInitPos( SP::SiconosVector x1 , SP::SiconosVector x2 )" << std::endl; std::cout << " Hx is large :" << Hx(X1, Y1, Z1, q10, q11, q12, q13, X2, Y2, Z2, q20, q21, q22, q23) << std::endl; } if (Hy(X1, Y1, Z1, q10, q11, q12, q13, X2, Y2, Z2, q20, q21, q22, q23) > DBL_EPSILON ) { std::cout << "KneeJointR::checkInitPos( SP::SiconosVector x1 , SP::SiconosVector x2 )" << std::endl; std::cout << " Hy is large :" << Hy(X1, Y1, Z1, q10, q11, q12, q13, X2, Y2, Z2, q20, q21, q22, q23) << std::endl; } if (Hz(X1, Y1, Z1, q10, q11, q12, q13, X2, Y2, Z2, q20, q21, q22, q23) > DBL_EPSILON ) { std::cout << "KneeJointR::checkInitPos( SP::SiconosVector x1 , SP::SiconosVector x2 )" << std::endl; std::cout << " Hz is large :" << Hz(X1, Y1, Z1, q10, q11, q12, q13, X2, Y2, Z2, q20, q21, q22, q23) << std::endl; } // printf("checkInitPos Hx : %e\n", Hx(X1, Y1, Z1, q10, q11, q12, q13, X2, Y2, Z2, q20, q21, q22, q23)); // printf("checkInitPos Hy : %e\n", Hy(X1, Y1, Z1, q10, q11, q12, q13, X2, Y2, Z2, q20, q21, q22, q23)); // printf("checkInitPos Hz : %e\n", Hz(X1, Y1, Z1, q10, q11, q12, q13, X2, Y2, Z2, q20, q21, q22, q23)); }
void tfsfUpdate(Grid *g){ /* check if tfsfinit has run */ if (tfsfBoundary <= 0) { fprintf(stderr, "tfsfinit must be called first.\n" "Boundary location must be a positive int.\n"); exit(-1); } char filename[100], base[20]="ezinc"; FILE *source; sprintf(filename, "%s.%d",base,Time); source = fopen(filename, "w"); fprintf(source, "%g\n", ezInc(Time, 0)); fclose(source); //corret hy adajcent to tfsf boundary Hy(tfsfBoundary) -= ezInc(Time, 0.0) * Chye(tfsfBoundary); // correct ez adjacnet to tfsf boundary Ez(tfsfBoundary + 1) += ezInc(Time + 0.5, -0.5); return; }
void Update2D(double *ez, double *hx, double *hy){ for(int mm = 0; mm < SIZE; mm++){ for(int nn = 0; nn < SIZE-1; nn++){ Hx(mm,nn) = Chxh*Hx(mm,nn) - Chxe * ( Ez(mm, nn+1) - Ez(mm, nn)); } } for(int mm = 0; mm < SIZE-1; mm++){ for(int nn = 0; nn < SIZE; nn++){ Hy(mm,nn) = Chyh*Hy(mm,nn)+Chye*( Ez( mm + 1 , nn) - Ez(mm, nn) ); } } for(int mm = 0; mm < SIZE-1; mm++){ for(int nn = 0; nn < SIZE-1; nn++){ Ez(mm,nn) = Ceze*Ez(mm,nn)+ Cezh * ( (Hy(mm,nn) - Hy(mm-1,nn))- (Hx(mm,nn)-Hx(mm,nn-1))); } } }
void tfsfUpdate(Grid *g) { /* check if tfsfInit() has been called */ if (tfsfBoundary <= 0) { fprintf(stderr,"tfsfUpdate: tfsfInit must be called before tfsfUpdate.\n""Boundary location must be set to positive value.\n"); exit(-1); } /* correct Hy adjacent to TFSF boundary */ Hy(tfsfBoundary) -= ezInc(Time, 0.0) * Chye(tfsfBoundary); /* correct Ez adjacent to TFSF boundary */ Ez(tfsfBoundary + 1) += ezInc(Time + 0.5, -0.5); return; }
void KneeJointR::computeh(double time, BlockVector& q0, SiconosVector& y) { DEBUG_BEGIN("KneeJointR::computeh(double time, BlockVector& q0, SiconosVector& y)\n"); DEBUG_EXPR(q0.display()); double X1 = q0.getValue(0); double Y1 = q0.getValue(1); double Z1 = q0.getValue(2); double q10 = q0.getValue(3); double q11 = q0.getValue(4); double q12 = q0.getValue(5); double q13 = q0.getValue(6); DEBUG_PRINTF("X1 = %12.8e,\t Y1 = %12.8e,\t Z1 = %12.8e,\n",X1,Y1,Z1); DEBUG_PRINTF("q10 = %12.8e,\t q11 = %12.8e,\t q12 = %12.8e,\t q13 = %12.8e,\n",q10,q11,q12,q13); double X2 = 0; double Y2 = 0; double Z2 = 0; double q20 = 1; double q21 = 0; double q22 = 0; double q23 = 0; if(q0.getNumberOfBlocks()>1) { // SP::SiconosVector x2 = _d2->q(); // DEBUG_EXPR( _d2->q()->display();); X2 = q0.getValue(7); Y2 = q0.getValue(8); Z2 = q0.getValue(9); q20 = q0.getValue(10); q21 = q0.getValue(11); q22 = q0.getValue(12); q23 = q0.getValue(13); } y.setValue(0, Hx(X1, Y1, Z1, q10, q11, q12, q13, X2, Y2, Z2, q20, q21, q22, q23)); y.setValue(1, Hy(X1, Y1, Z1, q10, q11, q12, q13, X2, Y2, Z2, q20, q21, q22, q23)); y.setValue(2, Hz(X1, Y1, Z1, q10, q11, q12, q13, X2, Y2, Z2, q20, q21, q22, q23)); DEBUG_EXPR(y.display()); DEBUG_END("KneeJointR::computeh(double time, BlockVector& q0, SiconosVector& y)\n"); }