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 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
/* Copyright (C) 2005-2015 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 of the License, 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
*/
/* Anisotropic dispersion test program */
/* For comparison, we solve for the dispersion relation
analytically in Matlab using the fsolve command to solve
the nonlinear eigenproblem. The Matlab code is as follows.
function result = detMwk(f,k)
sigE = [ 2.92724 0.45948 0.70117;
0.45948 2.89689 0.45083;
0.70117 0.45083 2.17378; ];
epsinf = [ 2.41104 0.48709 0.41226;
0.48709 2.43172 1.62060;
0.41226 1.62060 3.61498; ];
sigH = 0;
muinf = [ 1 0 0; 0 1 0; 0 0 1; ];
f0 = 1.1; g0 = 1e-5;
epsinv = inv(epsinf + ((f0^2)/(f0^2 - f^2 -i*f*g0))*sigE);
muinv = inv(muinf + ((f0^2)/(f0^2 - f^2 -i*f*g0))*sigH);
E = [ 0 0; 1 0; 0 1; ];
kx = k * [ 0 0 0; 0 0 -1; 0 1 0; ];
result = det(E' * (f.^2*eye(3) + kx * muinv * kx * epsinv) * E);
endfunction
k = 0.813;
w1 = fsolve(@(w)detMwk(w,k),0.9);
w2 = fsolve(@(w)detMwk(w,k),w1-0.1);
*/
#include <meep.hpp>
using namespace meep;
using namespace std;
class anisodisp_material : public material_function {
public:
virtual void eff_chi1inv_row(component c, double chi1inv_row[3],
const volume &v,
double tol=DEFAULT_SUBPIXEL_TOL,
int maxeval=DEFAULT_SUBPIXEL_MAXEVAL) {
(void) v; (void) tol; (void) maxeval; // unused
if (component_direction(c) == X) {
chi1inv_row[0] = 0.432818;
chi1inv_row[1] = -0.076724;
chi1inv_row[2] = -0.014964;
}
else if (component_direction(c) == Y) {
chi1inv_row[0] = -0.076724;
chi1inv_row[1] = 0.600041;
chi1inv_row[2] = -0.260249;
}
else {
chi1inv_row[0] = -0.014964;
chi1inv_row[1] = -0.260249;
chi1inv_row[2] = 0.395003;
}
}
virtual void sigma_row(component c, double sigrow[3], const vec &r) {
(void) r; // unused
if (component_direction(c) == X) {
sigrow[0] = 2.92724;
sigrow[1] = 0.45948;
sigrow[2] = 0.70117;
}
else if (component_direction(c) == Y) {
sigrow[0] = 0.45948;
sigrow[1] = 2.89689;
sigrow[2] = 0.45083;
}
else {
sigrow[0] = 0.70117;
sigrow[1] = 0.45083;
sigrow[2] = 2.17378;
}
}
};
int main(int argc, char **argv) {
initialize mpi(argc, argv);
bool ok = true;
// we can only use one process for this 1-pixel simulation
if (0 == divide_parallel_processes(count_processors())) {
quiet = true;
const double res = 200;
grid_volume gv = vol3d(0,0,0, res);
gv.center_origin();
anisodisp_material anisodispmat;
structure s(gv, anisodispmat);
s.add_susceptibility(anisodispmat, E_stuff,
lorentzian_susceptibility(1.1,1e-5));
fields f(&s);
f.use_bloch(vec(0.813,0,0));
f.add_point_source(Ez, 0.5, 1.0, 0.0, 4.0, vec(0,0,0));
double T = f.last_source_time();
int iT = T / f.dt;
while (f.t < iT) {
if (f.t % (iT / 10) == 0)
master_printf("%g%% done with source\n", f.time()/T * 100);
f.step();
}
double T2 = 200;
int iT2 = T2 / f.dt;
complex<double> *vals = new complex<double>[iT2];
while (f.t - iT < iT2) {
if ((f.t - iT) % (iT2 / 10) == 0)
master_printf("%g%% done with harminv\n", (f.t - iT) * 100.0 / iT2);
vals[f.t - iT] = f.get_field(Ez, vec(0.,0.,0.));
f.step();
}
complex<double> amps[8];
double freqs_re[8], freqs_im[8];
master_printf("done with timestepping, running harminv...\n");
int num = do_harminv(vals, iT2, f.dt, 0.0, 1.0, 8,
amps, freqs_re, freqs_im);
// compute the error compared to analytical solution
int i0 = 0;
for (int i=0;i<num;i++) {
master_printf("freq %d is %0.6g, %0.6g\n",i,freqs_re[i],freqs_im[i]);
if (fabs(freqs_re[i]-0.41562) < fabs(freqs_re[i0]-0.41562))
i0 = i;
}
master_printf("err. real: %g\n",fabs(freqs_re[i0]-0.41562)/0.41562);
master_printf("err. imag: %g\n",fabs(freqs_im[i0]+4.8297e-07)/4.8297e-7);
ok = fabs(freqs_re[i0]-0.41562)/0.41562 < 1e-4
&& fabs(freqs_im[i0]+4.8297e-07)/4.8297e-7 < 0.2;
}
end_divide_parallel();
return !and_to_all(ok);
}
|