1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
/* Copyright (C) 2005-2022 Massachusetts Institute of Technology
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 2, or (at your option)
% any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program; if not, write to the Free Software Foundation,
% Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <stdio.h>
#include <stdlib.h>
#include <meep.hpp>
using namespace meep;
using std::complex;
double one(const vec &) { return 1.0; }
int radiating_2D(const double xmax) {
const double a = 10.0;
const double ymax = 3.0;
grid_volume gv = voltwo(xmax, ymax, a);
structure s(gv, one, pml(ymax / 3));
fields f(&s);
double w = 0.30;
double dx = 2.0;
continuous_src_time src(w);
f.add_point_source(Ez, src, vec(xmax / 2 - dx, ymax / 2));
vec p1(xmax / 2 + 0 * dx, ymax / 2);
vec p2(xmax / 2 + 1 * dx, ymax / 2);
// let the source reach steady state
#if 1
f.solve_cw(sizeof(realnum) == sizeof(float) ? 1e-5 : 1e-6);
#else
while (f.time() < 400)
f.step();
#endif
complex<double> amp1 = f.get_field(Ez, p1);
complex<double> amp2 = f.get_field(Ez, p2);
double ratio = pow(abs(amp1) / abs(amp2), 2.0);
master_printf("Ratio is %g from (%g %g) and (%g %g)\n", ratio, real(amp1), imag(amp1), real(amp2),
imag(amp2));
if (ratio > 2.12 || ratio < 1.88)
meep::abort(
"Failed: amp1 = (%g, %g), amp2 = (%g, %g)\n abs(amp1/amp2)^2 = %g, too far from 2.0\n",
real(amp1), imag(amp1), real(amp2), imag(amp2), ratio);
return 1;
}
int radiating_3D(const double xmax) {
const double a = 10.0;
const double ymax = 3.0;
grid_volume gv = vol3d(xmax, ymax, ymax, a);
symmetry S = mirror(Y, gv) - mirror(Z, gv);
structure s(gv, one, pml(ymax / 3));
fields f(&s);
double w = 0.30;
double dx = 2.0;
continuous_src_time src(w);
f.add_point_source(Ez, src, vec(xmax / 2 - dx, ymax / 2, ymax / 2));
vec p1(xmax / 2 + 0 * dx, ymax / 2, ymax / 2);
vec p2(xmax / 2 + 1 * dx, ymax / 2, ymax / 2);
// let the source reach steady state
#if 1
f.solve_cw(1e-3);
#else
while (f.time() < 400)
f.step();
#endif
complex<double> amp1 = f.get_field(Ez, p1);
complex<double> amp2 = f.get_field(Ez, p2);
double ratio = abs(amp1) / abs(amp2);
master_printf("Ratio is %g from (%g %g) and (%g %g)\n", ratio, real(amp1), imag(amp1), real(amp2),
imag(amp2));
if (ratio > 2.12 || ratio < 1.88)
meep::abort(
"Failed: amp1 = (%g, %g), amp2 = (%g, %g)\n abs(amp1/amp2) = %g, too far from 2.0\n",
real(amp1), imag(amp1), real(amp2), imag(amp2), ratio);
return 1;
}
void attempt(const char *name, int allright) {
if (allright)
master_printf("Passed %s\n", name);
else
meep::abort("Failed %s!\n", name);
}
int main(int argc, char **argv) {
initialize mpi(argc, argv);
// verbosity = 0;
master_printf("Trying out some physical tests...\n");
attempt("radiating source should decay spatially as 1/sqrt(r) in 2D.", radiating_2D(8.0));
attempt("radiating source should decay spatially as 1/r in 3D.", radiating_3D(7.0));
return 0;
}
|