Skip to content

Commit

Permalink
Update inputs to allow size or corners and num_cells or dx
Browse files Browse the repository at this point in the history
  • Loading branch information
streeve committed Nov 22, 2024
1 parent 788b280 commit 2c20fc5
Showing 1 changed file with 68 additions and 17 deletions.
85 changes: 68 additions & 17 deletions src/CabanaPD_Input.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,7 @@ class Inputs
inputs = parse( filename );

// Add additional derived inputs to json. 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++ )
{
double s = size[d];
double low = -0.5 * s;
double high = 0.5 * s;
inputs["low_corner"]["value"][d] = low;
inputs["high_corner"]["value"][d] = high;

double nc = inputs["num_cells"]["value"][d];
inputs["dx"]["value"][d] = ( high - low ) / nc;
}
inputs["low_corner"]["unit"] = size_unit;
inputs["high_corner"]["unit"] = size_unit;
inputs["dx"]["unit"] = size_unit;
setupSize();

// Number of steps.
double tf = inputs["final_time"]["value"];
Expand Down Expand Up @@ -104,7 +89,73 @@ class Inputs
// Not yet a user option.
inputs["half_neigh"]["value"] = false;
}
~Inputs() {}

void setupSize()
{
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++ )
{
double s = size[d];
double low = -0.5 * s;
double high = 0.5 * s;
inputs["low_corner"]["value"][d] = low;
inputs["high_corner"]["value"][d] = high;
}
inputs["low_corner"]["unit"] = size_unit;
inputs["high_corner"]["unit"] = size_unit;
}
else if ( inputs.contains( "low_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"];
for ( std::size_t d = 0; d < low_corner.size(); d++ )
{
double low = low_corner[d];
double high = high_corner[d];
inputs["system_size"]["value"][d] = high - low;
}
inputs["system_size"]["unit"] = size_unit;
}
else
{
throw std::runtime_error( "Must input either system_size or "
"both low_corner and high_corner." );
}

if ( inputs.contains( "dx" ) )
{
auto size = inputs["system_size"]["value"];
for ( std::size_t d = 0; d < size.size(); d++ )
{
double system_size = inputs["system_size"]["value"][d];
double dx = inputs["dx"]["value"][d];
inputs["num_cells"]["value"][d] =
static_cast<int>( system_size / dx );
}
}
else if ( inputs.contains( "num_cells" ) )
{
auto size = inputs["system_size"]["value"];
for ( std::size_t d = 0; d < size.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;
}
std::string size_unit = inputs["system_size"]["unit"];
inputs["dx"]["unit"] = size_unit;
}
else
{
throw std::runtime_error( "Must input either num_cells or dx." );
}
}

void computeCriticalTimeStep()
{
Expand Down

0 comments on commit 2c20fc5

Please sign in to comment.