-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow in memory manipulation of nalu yaml files (#51)
* Adjust nalu to construct with yaml * Add logfile naming option * Add test case that shows syntax * Style * Add comments and parallel check for file writing * Style * Fix logic error * Subtle fix for being careles with what I renamed in nalu
- Loading branch information
1 parent
1ac5d55
commit 20610d1
Showing
9 changed files
with
466 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
.DS_Store | ||
spack* | ||
compile_commands.json | ||
.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
#include "yaml-cpp/yaml.h" | ||
#include <stdexcept> | ||
#include <iostream> | ||
|
||
namespace YEDIT { | ||
|
||
/* Exception if the graph is not formatted correctly | ||
* This exception is designed to reproduce the failing portion of the YAML graph | ||
* when called recursively so it can be echo'd to the user | ||
*/ | ||
class YamlNodeMatchException : public std::exception | ||
{ | ||
public: | ||
YamlNodeMatchException( | ||
std::string currentNode, std::string accumulatedPath = "") | ||
: std::exception() | ||
{ | ||
std::string extra = | ||
accumulatedPath.empty() ? "" : ":" + accumulatedPath; | ||
graphPath_ = currentNode + extra; | ||
} | ||
const char* what() const noexcept override { return graphPath_.c_str(); } | ||
|
||
private: | ||
std::string graphPath_; | ||
}; | ||
|
||
namespace { | ||
/* A function that will traverse the src node based on the key node | ||
* The two nodes must be identical until the final leaf values and then the | ||
* values of the key will override the src values. If the two graphs don't match | ||
* at any point prior to the leaves then it will trigger a | ||
* YamlNodeMatchException. | ||
*/ | ||
inline void impl_find_and_replace(YAML::Node src, YAML::Node key) | ||
{ | ||
switch (key.Type()) { | ||
case YAML::NodeType::Map: | ||
// case 1: it's a map | ||
//- pass the contents of the map recursively | ||
for (auto n : key) { | ||
std::string k = static_cast<std::string>(n.first.Scalar()); | ||
try { | ||
impl_find_and_replace(src[k], key[k]); | ||
} catch (YamlNodeMatchException& e) { | ||
throw YamlNodeMatchException(k, std::string(e.what())); | ||
} | ||
} | ||
break; | ||
case YAML::NodeType::Sequence: | ||
// case 2: it's a list | ||
//- pass the contents of the list recursively (order matters when | ||
// looking for a match) | ||
for (int i = 0; i < key.size(); ++i) { | ||
try { | ||
impl_find_and_replace(src[i], key[i]); | ||
} catch (YamlNodeMatchException& e) { | ||
throw YamlNodeMatchException( | ||
"[" + std::to_string(i) + "]", std::string(e.what())); | ||
} | ||
} | ||
break; | ||
case YAML::NodeType::Scalar: { | ||
// case 3: it's a scalar | ||
//- replace value | ||
if (src.Type() != key.Type()) { | ||
// we have a invalid path in the key | ||
throw YamlNodeMatchException(key.as<std::string>()); | ||
} | ||
src = key; | ||
break; | ||
} | ||
default: | ||
break; | ||
} | ||
} | ||
} // namespace | ||
|
||
/* The accessible version of impl_find_and_replace that collects the final | ||
* error and makes it more readable | ||
*/ | ||
inline void find_and_replace(YAML::Node src, YAML::Node key) | ||
{ | ||
try { | ||
impl_find_and_replace(src, key); | ||
} catch (YamlNodeMatchException& e) { | ||
auto failingPath = static_cast<std::string>(e.what()); | ||
std::string message = | ||
"\nFailure trying to replace YAML\nFailing Graph:\n\t"; | ||
message += failingPath + "\n"; | ||
message += | ||
"Please double check and make sure this matches the source YAML"; | ||
throw std::runtime_error(message); | ||
} | ||
} | ||
|
||
} // namespace YEDIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# | ||
# SIMULATION STOP # | ||
#.......................................# | ||
time.stop_time = 22000.0 # Max (# | ||
tim.max_step = -1 | ||
time.fixed_dt = 0.15 | ||
time.cfl = 1.0 | ||
time.plot_interval = 10 | ||
time.checkpoint_interval = -10 | ||
io.plot_file = out/plt | ||
io.check_file = out/chk | ||
# PHYSICS # | ||
#.......................................# | ||
incflo.gravity = 0. 0. 0.0 # Gravitational force (3D) | ||
|
||
incflo.use_godunov = 1 | ||
incflo.do_initial_proj = 0 | ||
incflo.initial_iterations = 0 | ||
transport.viscosity = 0.005 | ||
turbulence.model = Laminar | ||
|
||
|
||
incflo.physics = FreeStream | ||
incflo.velocity = 1.0 0.0 0.0 | ||
incflo.density = 1.0 | ||
|
||
amr.n_cell = 160 56 4 # Grid cells at coarsest AMRlevel | ||
amr.max_level = 0 # Max AMR level in hierarchy | ||
amr.blocking_factor_z = 4 | ||
amr.blocking_factor_x = 8 | ||
amr.blocking_factor_y = 8 | ||
amr.max_grid_size_z = 4 | ||
amr.max_grid_size_x = 16 | ||
amr.max_grid_size_y = 16 | ||
|
||
geometry.prob_lo = -15 -5.0 -0.375 # Lo corner coordinates | ||
geometry.prob_hi = 7.5 5.0 0.375 # Hi corner coordinates | ||
geometry.is_periodic = 0 0 1 # Periodicity x y z (0/1) | ||
|
||
|
||
# Boundary conditions | ||
xlo.type = "mass_inflow" | ||
xlo.velocity = 1.0 0.0 0.0 | ||
xlo.density = 1.0 | ||
xhi.type = "pressure_outflow" | ||
xhi.pressure = 0.0 | ||
ylo.type = "slip_wall" | ||
yhi.type = "slip_wall" | ||
#zlo.type = "slip_wall" | ||
#zhi.type = "slip_wall" | ||
|
||
incflo.verbose = 0 # incflo_level | ||
amrex.fpe_trap_invalid = 0 # Trap NaNs | ||
amrex.throw_exception = 1 | ||
amrex.signal_handling = 0 | ||
|
||
mac_proj.verbose = 0 | ||
nodal_proj.verbose = 0 | ||
nodal_proj.mg_rtol = 1.0e-6 | ||
nodal_proj.mg_atol = 1.0e-10 | ||
nodal_proj.num_pre_smooth = 10 | ||
nodal_proj.num_post_smooth = 10 |
Oops, something went wrong.