Skip to content
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

Two improvements to API for BFAST feature #2728

Merged
merged 2 commits into from
Nov 29, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
rename need_bfast to use_bfast and remove ternary operator
oskooi committed Nov 28, 2023
commit ee9e68d0cffe1f97609162aefa18ddfe09bdd122
12 changes: 6 additions & 6 deletions python/tests/test_refl_angular.py
Original file line number Diff line number Diff line change
@@ -30,13 +30,13 @@ def setUpClass(cls):
cls.num_freq = 11

def reflectance_angular(
self, theta_deg: float, need_bfast: bool
self, theta_deg: float, use_bfast: bool
) -> Tuple[List, List, np.ndarray]:
"""Computes properties of the incident and reflected planewave.
Args:
theta_deg: angle of incident planewave.
need_bfast: whether to use the same angle for the incident planewave
use_bfast: whether to use the same angle for the incident planewave
for all frequencies. If False, the incident angle is frequency
dependent.
@@ -46,7 +46,7 @@ def reflectance_angular(
"""
theta_rad = math.radians(theta_deg)

if need_bfast:
if use_bfast:
bfast_scaled_k = (self.n1 * np.sin(theta_rad), 0, 0)

Courant = (1 - bfast_scaled_k[0]) / 3**0.5
@@ -142,7 +142,7 @@ def reflectance_angular(

reflectance = -np.array(flux_monitor_flux) / np.array(empty_flux)

if need_bfast:
if use_bfast:
theta_in_rad = [theta_rad] * self.num_freq
else:
# Returns the angle of the incident planewave in medium n1 based
@@ -154,12 +154,12 @@ def reflectance_angular(
return freqs, theta_in_rad, reflectance

@parameterized.parameterized.expand([(0, False), (20.6, False), (35.7, True)])
def test_reflectance_angular(self, theta_deg: float, need_bfast: bool):
def test_reflectance_angular(self, theta_deg: float, use_bfast: bool):
(
frequency_meep,
theta_in_rad_meep,
reflectance_meep,
) = self.reflectance_angular(theta_deg, need_bfast)
) = self.reflectance_angular(theta_deg, use_bfast)

# Returns angle of refracted planewave in medium n2 given
# an incident planewave in medium n1 at angle theta_in_rad.
6 changes: 3 additions & 3 deletions src/step_db.cpp
Original file line number Diff line number Diff line change
@@ -62,7 +62,7 @@ bool fields_chunk::step_db(field_type ft) {
realnum *f_p = have_p ? f[c_p][cmp] : NULL;
realnum *f_m = have_m ? f[c_m][cmp] : NULL;
realnum *the_f = f[cc][cmp];
bool need_bfast = (bfast_scaled_k[0] || bfast_scaled_k[1] || bfast_scaled_k[2]) ? 1 : 0;
bool use_bfast = bfast_scaled_k[0] || bfast_scaled_k[1] || bfast_scaled_k[2];

if (dsig != NO_DIRECTION && s->conductivity[cc][d_c] && !f_cond[cc][cmp]) {
f_cond[cc][cmp] = new realnum[gv.ntot()];
@@ -73,7 +73,7 @@ bool fields_chunk::step_db(field_type ft) {
memcpy(f_u[cc][cmp], the_f, gv.ntot() * sizeof(realnum));
allocated_u = true;
}
if (need_bfast && !f_bfast[cc][cmp]) {
if (use_bfast && !f_bfast[cc][cmp]) {
f_bfast[cc][cmp] = new realnum[gv.ntot()];
memset(f_bfast[cc][cmp], 0, sizeof(realnum) * gv.ntot());
}
@@ -126,7 +126,7 @@ bool fields_chunk::step_db(field_type ft) {
f_u[cc][cmp], dsigu, s->sig[dsigu], s->kap[dsigu], s->siginv[dsigu], dt,
s->conductivity[cc][d_c], s->condinv[cc][d_c], f_cond[cc][cmp]);

if (need_bfast) {
if (use_bfast) {
realnum k1 =
have_m ? bfast_scaled_k[component_index(c_m)] : 0; // puts k1 in direction of g2
realnum k2 =