// TFSF boundaries Field TFSF(Field EM, Loss lass, Loss1d lass1d, double Cour){ int dx, dy; // TFSF boundary Bound first, last; first.x = 10; last.x = 390; first.y = 10; last.y = 190; // Update along right dx = last.x; for (int dy = first.y; dy <= last.y; dy++){ EM.Hz(dx, dy) -= lass.HzE(dx, dy) * EM.Ey1d[dx]; } // Updating Hz along left dx = first.x - 1; for (int dy = first.y; dy <= last.y; dy++){ EM.Hz(dx, dy) += lass.HzE(dx, dy) * EM.Ey1d[dx + 1]; } // Insert 1d grid stuff here. Update magnetic and electric field Hupdate1d(EM, lass1d, EM.t); Eupdate1d(EM, lass1d, EM.t); //EM.Ey1d[10] = ricker(EM.t,0, Cour); EM.Ey1d[10] = planewave(EM.t, 15, Cour, 30, 40); EM.t++; std::cout << EM.t << '\n'; // Check mag instead of ricker. // Update along right edge! dx = last.x; for (int dy = first.y; dy <= last.y; dy++){ EM.Ey(dx,dy) -= lass.EyH(dx, dy) * EM.Hz1d[dx]; } // Updating along left edge dx = first.x; for (int dy = first.y; dy <= last.y; dy++){ EM.Ey(dx,dy) += lass.EyH(dx, dy) * EM.Hz1d[dx-1]; } // Updating along top dy = last.y; for (int dx = first.x; dx <= last.x; dx++){ EM.Ex(dx,dy) += lass.ExH(dx, dy) * EM.Hz1d[dx]; } // Update along bot dy = first.y; for (int dx = first.x; dx <= last.x; dx++){ EM.Ex(dx,dy) -= lass.ExH(dx, dy) * EM.Hz1d[dx]; } return EM; }
Field Eupdate2d(Field EM, Loss lass, int t){ // update electric field for (size_t dx = 0; dx < spacex - 1; dx++){ for (size_t dy = 1; dy < spacey - 1; dy++){ EM.Ex(dx,dy) = lass.ExE(dx,dy) * EM.Ex(dx,dy) + lass.ExH(dx,dy) * (EM.Hz(dx, dy) - EM.Hz(dx, dy - 1)); } } for (size_t dx = 1; dx < spacex - 1; dx++){ for (size_t dy = 0; dy < spacey - 1; dy++){ EM.Ey(dx,dy) = lass.EyE(dx,dy) * EM.Ey(dx,dy) - lass.EyH(dx,dy) * (EM.Hz(dx, dy) - EM.Hz(dx - 1, dy)); } } return EM; }
// Checking Absorbing Boundary Conditions (ABC) Field ABCcheck(Field EM, Loss lass){ // defining constant for ABC double c1, c2, c3, temp1, temp2; temp1 = sqrt(lass.ExH(0,0) * lass.HzE(0,0)); temp2 = 1.0 / temp1 + 2.0 + temp1; c1 = -(1.0 / temp1 - 2.0 + temp1) / temp2; c2 = -2.0 * (temp1 - 1.0 / temp1) / temp2; c3 = 4.0 * (temp1 + 1.0 / temp1) / temp2; size_t dx, dy; // Setting ABC for top for (dx = 0; dx < spacex; dx++){ EM.Ex(dx, spacey - 1) = c1 * (EM.Ex(dx, spacey - 3) + EM.Etop(0, 1, dx)) + c2 * (EM.Etop(0, 0, dx) + EM.Etop(2, 0 , dx) -EM.Ex(dx,spacey - 2) -EM.Etop(1, 1, dx)) + c3 * EM.Etop(1, 0, dx) - EM.Etop(2, 1, dx); // memorizing fields... for (dy = 0; dy < 3; dy++){ EM.Etop(dy, 1, dx) = EM.Etop(dy, 0, dx); EM.Etop(dy, 0, dx) = EM.Ex(dx, spacey - 1 - dy); } } // Setting ABC for bottom for (dx = 0; dx < spacex; dx++){ EM.Ex(dx,0) = c1 * (EM.Ex(dx, 2) + EM.Ebot(0, 1, dx)) + c2 * (EM.Ebot(0, 0, dx) + EM.Ebot(2, 0 , dx) -EM.Ex(dx,1) -EM.Ebot(1, 1, dx)) + c3 * EM.Ebot(1, 0, dx) - EM.Ebot(2, 1, dx); // memorizing fields... for (dy = 0; dy < 3; dy++){ EM.Ebot(dy, 1, dx) = EM.Ebot(dy, 0, dx); EM.Ebot(dy, 0, dx) = EM.Ex(dx, dy); } } // ABC on right for (dy = 0; dy < spacey; dy++){ EM.Ey(spacex - 1,dy) = c1 * (EM.Ey(spacex - 3,dy) + EM.Eright(0, 1, dy)) + c2 * (EM.Eright(0, 0, dy) + EM.Eright(2, 0 , dy) -EM.Ey(spacex - 2,dy) -EM.Eright(1, 1, dy)) + c3 * EM.Eright(1, 0, dy) - EM.Eright(2, 1, dy); // memorizing fields... for (dx = 0; dx < 3; dx++){ EM.Eright(dx, 1, dy) = EM.Eright(dx, 0, dy); EM.Eright(dx, 0, dy) = EM.Ey(spacex - 1 - dx, dy); } } // Setting ABC for left side of grid. Woo! for (dy = 0; dy < spacey; dy++){ EM.Ey(0,dy) = c1 * (EM.Ey(2,dy) + EM.Eleft(0, 1, dy)) + c2 * (EM.Eleft(0, 0, dy) + EM.Eleft(2, 0 , dy) -EM.Ey(1,dy) -EM.Eleft(1, 1, dy)) + c3 * EM.Eleft(1, 0, dy) - EM.Eleft(2, 1, dy); // memorizing fields... for (dx = 0; dx < 3; dx++){ EM.Eleft(dx, 1, dy) = EM.Eleft(dx, 0, dy); EM.Eleft(dx, 0, dy) = EM.Ey(dx, dy); } } return EM; }
// Creating loss Loss createloss2d(Loss lass, double eps, double Cour, double loss){ double radius = 40; int sourcex = 200, sourcex2 = 100; int sourcey = 100, sourcey2 = 100; double dist, var, Q, epsp, mup, dist2; for (size_t dx = 0; dx < spacex; dx++){ for (size_t dy = 0; dy < spacey; dy++){ dist = sqrt((dx - sourcex)*(dx - sourcex) + (dy - sourcey)*(dy - sourcey)); dist2 = sqrt((dx - sourcex2)*(dx - sourcex2) + (dy - sourcey2)*(dy - sourcey2)); // if (dx > 100 && dx < 150 && dy > 75 && dy < 125){ if (dist < radius){ Q = cbrt(-(radius / dist) + sqrt((radius/dist) * (radius/dist) + (1.0/27.0))); var = (Q - (1.0 / (3.0 * Q))) * (Q - (1.0/ (3.0 * Q))); // var = 1.4; if (abs(var) > 1000){ var = 1000; } if (isnan(var)){ var = 1000; } epsp = eps / (var * var); mup = 1 / (var * var); lass.ExH(dx, dy) = Cour * epsp /(1.0 - loss); lass.ExE(dx, dy) = (1.0 - loss) / (1.0 + loss); lass.EyE(dx, dy) = (1.0 - loss) / (1.0 + loss); lass.EyH(dx, dy) = Cour * epsp / (1.0 + loss); lass.HzE(dx, dy) = Cour * (mup / eps) / (1.0 + loss); lass.HzH(dx, dy) = (1.0 - loss) / (1.0 + loss); /* // PEC stuff -- not complete! lass.ExH(dx, dy) = 0; lass.ExE(dx, dy) = 0; lass.HzH(dx, dy) = 0; lass.HzE(dx, dy) = 0; lass.ExE(dx, dy) = 0; lass.ExH(dx, dy) = 0; */ } else{ lass.ExH(dx, dy) = Cour * eps; lass.ExE(dx, dy) = 1.0; lass.EyE(dx, dy) = 1.0; lass.EyH(dx, dy) = Cour * eps; lass.HzE(dx, dy) = Cour / eps; lass.HzH(dx, dy) = 1.0; } } } return lass; }