Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
41 changes: 20 additions & 21 deletions Source/FieldSolver/FiniteDifferenceSolver/MacroscopicEvolveE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,20 @@ void FiniteDifferenceSolver::MacroscopicEvolveECartesian (
int use_lumped_resistor = warpx.use_lumped_resistor;
int use_lumped_capacitor = warpx.use_lumped_capacitor;

// Geometric factor (edge length)/(cross-sectional area) for a lumped element on an
// x-, y-, or z-edge: sigma_eff = geom/R, eps_eff = eps + C*geom.
// Lumped elements are only supported in 3D (enforced in WarpX::ReadParameters).
#if defined(WARPX_DIM_3D)
amrex::Real const lumped_geom_x = dx[0] / (dx[1]*dx[2]);
amrex::Real const lumped_geom_y = dx[1] / (dx[0]*dx[2]);
amrex::Real const lumped_geom_z = dx[2] / (dx[0]*dx[1]);
#else
amrex::ignore_unused(dx);
amrex::Real const lumped_geom_x = 0._rt;
amrex::Real const lumped_geom_y = 0._rt;
amrex::Real const lumped_geom_z = 0._rt;
#endif

amrex::MultiFab& sigma_mf = macroscopic_properties->getsigma_mf();
amrex::MultiFab& epsilon_mf = macroscopic_properties->getepsilon_mf();

Expand Down Expand Up @@ -173,18 +187,6 @@ void FiniteDifferenceSolver::MacroscopicEvolveECartesian (
amrex::GpuArray<int, 3> const& epsilon_stag = macroscopic_properties->epsilon_IndexType;
amrex::GpuArray<int, 3> const& macro_cr = macroscopic_properties->macro_cr_ratio;

if (use_lumped_resistor){
amrex::GpuArray<int, 3> const& lumped_resistor_x_stag = macroscopic_properties->lumped_resistor_x_IndexType;
amrex::GpuArray<int, 3> const& lumped_resistor_y_stag = macroscopic_properties->lumped_resistor_y_IndexType;
amrex::GpuArray<int, 3> const& lumped_resistor_z_stag = macroscopic_properties->lumped_resistor_z_IndexType;
}

if (use_lumped_capacitor){
amrex::GpuArray<int, 3> const& lumped_capacitor_x_stag = macroscopic_properties->lumped_capacitor_x_IndexType;
amrex::GpuArray<int, 3> const& lumped_capacitor_y_stag = macroscopic_properties->lumped_capacitor_y_IndexType;
amrex::GpuArray<int, 3> const& lumped_capacitor_z_stag = macroscopic_properties->lumped_capacitor_z_IndexType;
}

amrex::GpuArray<int, 3> const& Ex_stag = macroscopic_properties->Ex_IndexType;
amrex::GpuArray<int, 3> const& Ey_stag = macroscopic_properties->Ey_IndexType;
amrex::GpuArray<int, 3> const& Ez_stag = macroscopic_properties->Ez_IndexType;
Expand Down Expand Up @@ -283,12 +285,12 @@ void FiniteDifferenceSolver::MacroscopicEvolveECartesian (
// Extra conductance term from a lumped resistor on Ex edges
amrex::Real const fac1 = (dt/epsilon_interp) *
( sigma_interp + ((use_lumped_resistor && resistor_x_arr(i,j,k)!=0._rt)
? dx[0] / (dx[1]*dx[2]*resistor_x_arr(i,j,k))
? lumped_geom_x / resistor_x_arr(i,j,k)
: 0._rt) );

// Extra term from a lumped capacitor on Ex edges
amrex::Real const fac2 = (use_lumped_capacitor && capacitor_x_arr(i,j,k)!=0._rt)
? capacitor_x_arr(i,j,k) * dx[0] / (dx[1]*dx[2]*epsilon_interp)
? capacitor_x_arr(i,j,k) * lumped_geom_x / epsilon_interp
: 0._rt;

amrex::Real alpha_compact = T_MacroAlgo::alpha_compact(fac1, fac2);
Expand Down Expand Up @@ -320,15 +322,12 @@ void FiniteDifferenceSolver::MacroscopicEvolveECartesian (
// Extra conductance term from a lumped resistor on Ey edges
amrex::Real const fac1 = (dt/epsilon_interp) *
( sigma_interp + ((use_lumped_resistor && resistor_y_arr(i,j,k)!=0._rt)
? dx[1] / (dx[0]*dx[2]*resistor_y_arr(i,j,k))
? lumped_geom_y / resistor_y_arr(i,j,k)
: 0._rt) );
// if (use_lumped_resistor && resistor_y_arr(i,j,k)!=0._rt){
// printf("fac1=%f\n", fac1);
// }

// Extra term from a lumped capacitor on Ey edges
amrex::Real const fac2 = (use_lumped_capacitor && capacitor_y_arr(i,j,k)!=0._rt)
? capacitor_y_arr(i,j,k) * dx[1] / (dx[0]*dx[2]*epsilon_interp)
? capacitor_y_arr(i,j,k) * lumped_geom_y / epsilon_interp
: 0._rt;

amrex::Real alpha_compact = T_MacroAlgo::alpha_compact(fac1, fac2);
Expand All @@ -355,12 +354,12 @@ void FiniteDifferenceSolver::MacroscopicEvolveECartesian (
// Extra conductance term from a lumped resistor on Ez edges
amrex::Real const fac1 = (dt/epsilon_interp) *
( sigma_interp + ((use_lumped_resistor && resistor_z_arr(i,j,k)!=0._rt)
? dx[2] / (dx[0]*dx[1]*resistor_z_arr(i,j,k))
? lumped_geom_z / resistor_z_arr(i,j,k)
: 0._rt) );

// Extra term from a lumped capacitor on Ez edges
amrex::Real const fac2 = (use_lumped_capacitor && capacitor_z_arr(i,j,k)!=0._rt)
? capacitor_z_arr(i,j,k) * dx[2] / (dx[0]*dx[1]*epsilon_interp)
? capacitor_z_arr(i,j,k) * lumped_geom_z / epsilon_interp
: 0._rt;

amrex::Real alpha_compact = T_MacroAlgo::alpha_compact(fac1, fac2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,32 +166,42 @@ MacroscopicProperties::ReadParameters ()
}


if (warpx.use_lumped_resistor == 1){
utils::parser::Store_parserString(pp_macroscopic, "lumped_resistor_x_function(x,y,z)", m_str_lumped_resistor_x_function);
m_lumped_resistor_x_parser = std::make_unique<amrex::Parser>(
utils::parser::makeParser(m_str_lumped_resistor_x_function,{"x","y","z"}));

utils::parser::Store_parserString(pp_macroscopic, "lumped_resistor_y_function(x,y,z)", m_str_lumped_resistor_y_function);
m_lumped_resistor_y_parser = std::make_unique<amrex::Parser>(
utils::parser::makeParser(m_str_lumped_resistor_y_function,{"x","y","z"}));
// Lumped resistor / capacitor values per edge direction. Any direction that is not
// specified defaults to "0", which means "no element" on those edges.
auto read_lumped_parser = [&pp_macroscopic] (std::string const& name, std::string& str,
std::unique_ptr<amrex::Parser>& parser) -> bool {
bool const specified = pp_macroscopic.contains(name.c_str());
if (specified) {
utils::parser::Store_parserString(pp_macroscopic, name, str);
} else {
str = "0";
}
parser = std::make_unique<amrex::Parser>(utils::parser::makeParser(str, {"x","y","z"}));
return specified;
};

utils::parser::Store_parserString(pp_macroscopic, "lumped_resistor_z_function(x,y,z)", m_str_lumped_resistor_z_function);
m_lumped_resistor_z_parser = std::make_unique<amrex::Parser>(
utils::parser::makeParser(m_str_lumped_resistor_z_function,{"x","y","z"}));
if (warpx.use_lumped_resistor == 1){
bool any = false;
any |= read_lumped_parser("lumped_resistor_x_function(x,y,z)", m_str_lumped_resistor_x_function, m_lumped_resistor_x_parser);
any |= read_lumped_parser("lumped_resistor_y_function(x,y,z)", m_str_lumped_resistor_y_function, m_lumped_resistor_y_parser);
any |= read_lumped_parser("lumped_resistor_z_function(x,y,z)", m_str_lumped_resistor_z_function, m_lumped_resistor_z_parser);
if (!any) {
ablastr::warn_manager::WMRecordWarning("Lumped elements",
"algo.use_lumped_resistor = 1 but no macroscopic.lumped_resistor_{x,y,z}_function(x,y,z) "
"was given; no resistors will be applied.");
}
}

if (warpx.use_lumped_capacitor == 1){
utils::parser::Store_parserString(pp_macroscopic, "lumped_capacitor_x_function(x,y,z)", m_str_lumped_capacitor_x_function);
m_lumped_capacitor_x_parser = std::make_unique<amrex::Parser>(
utils::parser::makeParser(m_str_lumped_capacitor_x_function,{"x","y","z"}));

utils::parser::Store_parserString(pp_macroscopic, "lumped_capacitor_y_function(x,y,z)", m_str_lumped_capacitor_y_function);
m_lumped_capacitor_y_parser = std::make_unique<amrex::Parser>(
utils::parser::makeParser(m_str_lumped_capacitor_y_function,{"x","y","z"}));

utils::parser::Store_parserString(pp_macroscopic, "lumped_capacitor_z_function(x,y,z)", m_str_lumped_capacitor_z_function);
m_lumped_capacitor_z_parser = std::make_unique<amrex::Parser>(
utils::parser::makeParser(m_str_lumped_capacitor_z_function,{"x","y","z"}));
bool any = false;
any |= read_lumped_parser("lumped_capacitor_x_function(x,y,z)", m_str_lumped_capacitor_x_function, m_lumped_capacitor_x_parser);
any |= read_lumped_parser("lumped_capacitor_y_function(x,y,z)", m_str_lumped_capacitor_y_function, m_lumped_capacitor_y_parser);
any |= read_lumped_parser("lumped_capacitor_z_function(x,y,z)", m_str_lumped_capacitor_z_function, m_lumped_capacitor_z_parser);
if (!any) {
ablastr::warn_manager::WMRecordWarning("Lumped elements",
"algo.use_lumped_capacitor = 1 but no macroscopic.lumped_capacitor_{x,y,z}_function(x,y,z) "
"was given; no capacitors will be applied.");
}
}

#ifdef WARPX_MAG_LLG
Expand Down Expand Up @@ -293,6 +303,18 @@ MacroscopicProperties::InitData ()
jy_IndexType[idim] = jy_stag[idim];
jz_IndexType[idim] = jz_stag[idim];
}
// lumped elements live at the same (edge) locations as J and E
for (int idim = 0; idim < 3; ++idim) {
int const sx = (idim < AMREX_SPACEDIM) ? jx_stag[idim] : 0;
int const sy = (idim < AMREX_SPACEDIM) ? jy_stag[idim] : 0;
int const sz = (idim < AMREX_SPACEDIM) ? jz_stag[idim] : 0;
lumped_resistor_x_IndexType[idim] = sx;
lumped_resistor_y_IndexType[idim] = sy;
lumped_resistor_z_IndexType[idim] = sz;
lumped_capacitor_x_IndexType[idim] = sx;
lumped_capacitor_y_IndexType[idim] = sy;
lumped_capacitor_z_IndexType[idim] = sz;
}

// Define material property multifabs using ba and dmap from WarpX instance
// sigma is cell-centered MultiFab
Expand Down Expand Up @@ -411,6 +433,12 @@ MacroscopicProperties::InitData ()
InitializeMacroMultiFabUsingParser(m_lumped_resistor_x_mf.get(), m_lumped_resistor_x_parser->compile<3>(), lev);
InitializeMacroMultiFabUsingParser(m_lumped_resistor_y_mf.get(), m_lumped_resistor_y_parser->compile<3>(), lev);
InitializeMacroMultiFabUsingParser(m_lumped_resistor_z_mf.get(), m_lumped_resistor_z_parser->compile<3>(), lev);

// R < 0 is a negative conductance and makes the E update unstable; R = 0 means "no resistor"
for (auto const* mf : {m_lumped_resistor_x_mf.get(), m_lumped_resistor_y_mf.get(), m_lumped_resistor_z_mf.get()}) {
WARPX_ALWAYS_ASSERT_WITH_MESSAGE(mf->min(0, mf->nGrow()) >= 0._rt,
"macroscopic.lumped_resistor_*_function must be non-negative (0 means no resistor)");
}
}

if (warpx.use_lumped_capacitor == 1){
Expand All @@ -421,6 +449,11 @@ MacroscopicProperties::InitData ()
InitializeMacroMultiFabUsingParser(m_lumped_capacitor_x_mf.get(), m_lumped_capacitor_x_parser->compile<3>(), lev);
InitializeMacroMultiFabUsingParser(m_lumped_capacitor_y_mf.get(), m_lumped_capacitor_y_parser->compile<3>(), lev);
InitializeMacroMultiFabUsingParser(m_lumped_capacitor_z_mf.get(), m_lumped_capacitor_z_parser->compile<3>(), lev);

for (auto const* mf : {m_lumped_capacitor_x_mf.get(), m_lumped_capacitor_y_mf.get(), m_lumped_capacitor_z_mf.get()}) {
WARPX_ALWAYS_ASSERT_WITH_MESSAGE(mf->min(0, mf->nGrow()) >= 0._rt,
"macroscopic.lumped_capacitor_*_function must be non-negative (0 means no capacitor)");
}
}

#ifdef WARPX_MAG_LLG
Expand Down
27 changes: 24 additions & 3 deletions Source/WarpX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1073,9 +1073,6 @@ WarpX::ReadParameters ()
);
}

pp_warpx.query("use_lumped_resistor", use_lumped_resistor);
pp_warpx.query("use_lumped_capacitor", use_lumped_capacitor);

#ifdef WARPX_MAG_LLG
// Read the value of the time advancement scheme of M field
pp_warpx.query("mag_time_scheme_order", mag_time_scheme_order);
Expand Down Expand Up @@ -1313,6 +1310,30 @@ WarpX::ReadParameters ()
pp_algo.query("use_lumped_inductor",use_lumped_inductor);
pp_algo.query("use_josephson_junction",use_josephson_junction);

// Lumped resistor / capacitor (values set via macroscopic.lumped_{resistor,capacitor}_*_function)
pp_algo.query("use_lumped_resistor", use_lumped_resistor);
pp_algo.query("use_lumped_capacitor", use_lumped_capacitor);
{
// backward compatibility: these used to be read as warpx.use_lumped_*
const amrex::ParmParse pp_warpx_old("warpx");
for (auto const& [name, flag] : {std::pair<const char*, int*>{"use_lumped_resistor", &use_lumped_resistor},
std::pair<const char*, int*>{"use_lumped_capacitor", &use_lumped_capacitor}}) {
if (pp_warpx_old.contains(name)) {
ablastr::warn_manager::WMRecordWarning("Lumped elements",
std::string("warpx.") + name + " is deprecated; use algo." + name + " instead.");
if (!pp_algo.contains(name)) { pp_warpx_old.query(name, *flag); }
}
}
}
if (use_lumped_resistor || use_lumped_capacitor) {
WARPX_ALWAYS_ASSERT_WITH_MESSAGE(em_solver_medium == MediumForEM::Macroscopic,
"algo.use_lumped_resistor / algo.use_lumped_capacitor require algo.em_solver_medium = macroscopic");
#if !defined(WARPX_DIM_3D)
WARPX_ABORT_WITH_MESSAGE(
"algo.use_lumped_resistor / algo.use_lumped_capacitor are only implemented in 3D");
#endif
}

// Load balancing parameters
std::vector<std::string> load_balance_intervals_string_vec = {"0"};
pp_algo.queryarr("load_balance_intervals", load_balance_intervals_string_vec);
Expand Down