void fields_chunk::step_source(field_type ft, bool including_integrated) { if (doing_solve_cw && !including_integrated) return; for (src_vol *sv = sources[ft]; sv; sv = sv->next) { component c = direction_component(first_field_component(ft), component_direction(sv->c)); const realnum *cndinv = s->condinv[c][component_direction(sv->c)]; if ((including_integrated || !sv->t->is_integrated) && f[c][0] && ((ft == D_stuff && is_electric(sv->c)) || (ft == B_stuff && is_magnetic(sv->c)))) { if (cndinv) for (int j=0; j<sv->npts; j++) { const int i = sv->index[j]; const complex<double> A = sv->current(j) * dt * double(cndinv[i]); f[c][0][i] -= real(A); if (!is_real) f[c][1][i] -= imag(A); } else for (int j=0; j<sv->npts; j++) { const complex<double> A = sv->current(j) * dt; const int i = sv->index[j]; f[c][0][i] -= real(A); if (!is_real) f[c][1][i] -= imag(A); } } } }
void dft_ldos::update(fields &f) { complex<double> EJ = 0.0; // integral E * J* complex<double> HJ = 0.0; // integral H * J* for magnetic currents double scale = (f.dt/sqrt(2*pi)); // compute Jsum for LDOS normalization purposes // ...don't worry about the tiny inefficiency of recomputing this repeatedly Jsum = 0.0; for (int ic=0;ic<f.num_chunks;ic++) if (f.chunks[ic]->is_mine()) { for (src_vol *sv = f.chunks[ic]->sources[D_stuff]; sv; sv = sv->next) { component c = direction_component(Ex, component_direction(sv->c)); realnum *fr = f.chunks[ic]->f[c][0]; realnum *fi = f.chunks[ic]->f[c][1]; if (fr && fi) // complex E for (meep::integer j=0; j<sv->npts; j++) { const meep::integer idx = sv->index[j]; const complex<double> A = sv->A[j]; EJ += complex<double>(fr[idx],fi[idx]) * conj(A); Jsum += abs(A); } else if (fr) { // E is purely real for (meep::integer j=0; j<sv->npts; j++) { const meep::integer idx = sv->index[j]; const complex<double> A = sv->A[j]; EJ += double(fr[idx]) * conj(A); Jsum += abs(A); } } } for (src_vol *sv = f.chunks[ic]->sources[B_stuff]; sv; sv = sv->next) { component c = direction_component(Hx, component_direction(sv->c)); realnum *fr = f.chunks[ic]->f[c][0]; realnum *fi = f.chunks[ic]->f[c][1]; if (fr && fi) // complex H for (meep::integer j=0; j<sv->npts; j++) { const meep::integer idx = sv->index[j]; const complex<double> A = sv->A[j]; HJ += complex<double>(fr[idx],fi[idx]) * conj(A); Jsum += abs(A); } else if (fr) { // H is purely real for (meep::integer j=0; j<sv->npts; j++) { const meep::integer idx = sv->index[j]; const complex<double> A = sv->A[j]; HJ += double(fr[idx]) * conj(A); Jsum += abs(A); } } } } for (int i = 0; i < Nomega; ++i) { complex<double> Ephase = polar(1.0, (omega_min+i*domega)*f.time())*scale; complex<double> Hphase = polar(1.0, (omega_min+i*domega)*(f.time()-f.dt/2))*scale; Fdft[i] += Ephase * EJ + Hphase * HJ; // NOTE: take only 1st time dependence: assumes all sources have same J(t) if (f.sources) { if (f.is_real) // todo: not quite right if A is complex Jdft[i] += Ephase * real(f.sources->current()); else Jdft[i] += Ephase * f.sources->current(); } } // correct for dV factors Jsum *= sqrt(f.gv.dV(f.gv.icenter(),1).computational_volume()); }