-
Notifications
You must be signed in to change notification settings - Fork 644
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Correct the weights for dipole sources in cylindrical coordinates #2476
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -270,7 +270,13 @@ static void src_vol_chunkloop(fields_chunk *fc, int ichunk, component c, ivec is | |
loc += shift * (0.5 * inva); | ||
|
||
vec rel_loc = loc - data->center; | ||
amps_array[idx_vol] = IVEC_LOOP_WEIGHT(s0, s1, e0, e1, 1) * amp * data->A(rel_loc); | ||
|
||
// in cylindrical coordinates, we need to account for the r term in the integral. | ||
if (fc->gv.dim == Dcyl) | ||
amps_array[idx_vol] = | ||
IVEC_LOOP_WEIGHT(s0, s1, e0, e1, dV0 + dV1 * loop_i2) * amp * data->A(rel_loc); | ||
else | ||
amps_array[idx_vol] = IVEC_LOOP_WEIGHT(s0, s1, e0, e1, 1) * amp * data->A(rel_loc); | ||
|
||
// check for invalid sources at r=0 in cylindrical coordinates | ||
if (fc->gv.dim == Dcyl && loc.r() == 0 && amps_array[idx_vol] != 0.0) { | ||
|
@@ -478,9 +484,16 @@ void fields::add_volume_source(component c, const src_time &src, const volume &w | |
src_vol_chunkloop_data data; | ||
data.A = A ? A : one; | ||
data.amp = amp; | ||
// correct units for J delta-function amplitude | ||
LOOP_OVER_DIRECTIONS(gv.dim, d) { | ||
if (where.in_direction(d) == 0.0 && !nosize_direction(d)) // delta-fun | ||
data.amp *= gv.a; // correct units for J delta-function amplitude | ||
if (where.in_direction(d) == 0.0 && !nosize_direction(d)) { // delta-fun | ||
if (d == R && where.center().in_direction(d) > 0) | ||
// in cylindrical coordinates, we need to scale by $r$ for a dipole. | ||
data.amp *= 1.0 / where.center().in_direction(d); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why was the scaling by There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See the code comment below:
|
||
else if (gv.dim != Dcyl) | ||
// we handle the resolution scaling at the chunk level for cylindrical coordinates. | ||
data.amp *= gv.a; | ||
} | ||
} | ||
sources = src.add_to(sources, &data.src); | ||
data.center = (where.get_min_corner() + where.get_max_corner()) * 0.5; | ||
|
@@ -755,4 +768,29 @@ diffractedplanewave::diffractedplanewave(int g_[3], double axis_[3], std::comple | |
p = p_; | ||
}; | ||
|
||
/* | ||
Occasionally, it's useful to check the sum of all the actual source amplitudes | ||
(e.g. to ensure that the boundary weights are being computed properly). | ||
`sum_sources()` provides a convenient interface to do just that. | ||
*/ | ||
std::complex<double> fields::sum_sources(field_type ft) { | ||
std::complex<double> total_sources = 0.0; | ||
|
||
for (int i = 0; i < num_chunks; i++) | ||
if (chunks[i]->is_mine()) total_sources += chunks[i]->sum_sources(ft); | ||
|
||
return sum_to_all(total_sources); | ||
} | ||
|
||
std::complex<double> fields_chunk::sum_sources(field_type ft) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this function just used for debugging and was forgotten to be removed from the commit? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No I think we should keep it, as mentioned in the code comment above and the blurb above:
|
||
std::complex<double> total_sources = 0.0; | ||
for (const src_vol &sv : sources[ft]) { | ||
for (size_t j = 0; j < sv.num_points(); j++) { | ||
meep::master_printf("src %f\n", sv.amplitude_at(j)); | ||
total_sources += sv.amplitude_at(j); | ||
} | ||
} | ||
return total_sources; | ||
} | ||
|
||
} // namespace meep |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can block can be more cleanly expressed as:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, but let's make sure things work before we golf the code.