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

Add dimension and consistency checks for size / corners and num_cells / dx #155

Merged
merged 1 commit into from
Dec 12, 2024
Merged
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
54 changes: 37 additions & 17 deletions src/CabanaPD_Input.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,31 +94,39 @@ class Inputs
{
if ( inputs.contains( "system_size" ) )
{
auto size = inputs["system_size"]["value"];
std::string size_unit = inputs["system_size"]["unit"];
for ( std::size_t d = 0; d < size.size(); d++ )
auto system_size = inputs["system_size"]["value"];
if ( system_size.size() != 3 )
log_err( std::cout, "CabanaPD requires 3d (system_size)." );

for ( std::size_t d = 0; d < system_size.size(); d++ )
{
double s = size[d];
double s = system_size[d];
double low = -0.5 * s;
double high = 0.5 * s;
inputs["low_corner"]["value"][d] = low;
inputs["high_corner"]["value"][d] = high;
}
std::string size_unit = inputs["system_size"]["unit"];
inputs["low_corner"]["unit"] = size_unit;
inputs["high_corner"]["unit"] = size_unit;
}
else if ( inputs.contains( "low_corner" ) &&
( inputs.contains( "high_corner" ) ) )
inputs.contains( "high_corner" ) )
{
auto low_corner = inputs["low_corner"]["value"];
auto high_corner = inputs["high_corner"]["value"];
std::string size_unit = inputs["low_corner"]["unit"];
if ( low_corner.size() != 3 )
log_err( std::cout, "CabanaPD requires 3d (low_corner)." );
if ( high_corner.size() != 3 )
log_err( std::cout, "CabanaPD requires 3d (high_corner)." );

for ( std::size_t d = 0; d < low_corner.size(); d++ )
streeve marked this conversation as resolved.
Show resolved Hide resolved
{
double low = low_corner[d];
double high = high_corner[d];
inputs["system_size"]["value"][d] = high - low;
}
std::string size_unit = inputs["low_corner"]["unit"];
inputs["system_size"]["unit"] = size_unit;
}
else
Expand All @@ -129,24 +137,29 @@ class Inputs

if ( inputs.contains( "dx" ) )
{
auto size = inputs["system_size"]["value"];
for ( std::size_t d = 0; d < size.size(); d++ )
auto dx = inputs["dx"]["value"];
if ( dx.size() != 3 )
log_err( std::cout, "CabanaPD requires 3d (dx)." );

for ( std::size_t d = 0; d < dx.size(); d++ )
{
double system_size = inputs["system_size"]["value"][d];
double dx = inputs["dx"]["value"][d];
double size_d = inputs["system_size"]["value"][d];
double dx_d = dx[d];
inputs["num_cells"]["value"][d] =
static_cast<int>( system_size / dx );
static_cast<int>( size_d / dx_d );
}
}
else if ( inputs.contains( "num_cells" ) )
{
auto size = inputs["system_size"]["value"];
for ( std::size_t d = 0; d < size.size(); d++ )
auto nc = inputs["num_cells"]["value"];
if ( nc.size() != 3 )
log_err( std::cout, "CabanaPD requires 3d (num_cells)." );

for ( std::size_t d = 0; d < nc.size(); d++ )
{
double low = inputs["low_corner"]["value"][d];
double high = inputs["low_corner"]["value"][d];
double nc = inputs["num_cells"]["value"][d];
inputs["dx"]["value"][d] = ( high - low ) / nc;
double size_d = inputs["system_size"]["value"][d];
double nc_d = nc[d];
inputs["dx"]["value"][d] = size_d / nc_d;
}
std::string size_unit = inputs["system_size"]["unit"];
inputs["dx"]["unit"] = size_unit;
Expand All @@ -155,6 +168,13 @@ class Inputs
{
throw std::runtime_error( "Must input either num_cells or dx." );
}

// Error for inconsistent units. There is currently no conversion.
if ( inputs["low_corner"]["unit"] != inputs["high_corner"]["unit"] )
log_err( std::cout,
"Units for low_corner and high_corner do not match." );
if ( inputs["dx"]["unit"] != inputs["high_corner"]["unit"] )
log_err( std::cout, "Units for dx do not match system units." );
}

void computeCriticalTimeStep()
Expand Down
Loading