Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
ktbolt committed Jan 9, 2025
2 parents 9cba173 + 98a6982 commit 029f52d
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 17 deletions.
51 changes: 47 additions & 4 deletions Code/Source/solver/Parameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ void Parameters::read_xml(std::string file_name)
// Set Add_mesh values.
set_mesh_values(root_element);

// Set Precomputed_solution values.
set_precomputed_solution_values(root_element);

// Set mesh projection parameters.
set_projection_values(root_element);

Expand Down Expand Up @@ -218,6 +221,16 @@ void Parameters::set_mesh_values(tinyxml2::XMLElement* root_element)
}
}

void Parameters::set_precomputed_solution_values(tinyxml2::XMLElement* root_element)
{
auto add_pre_sol_item = root_element->FirstChildElement(PrecomputedSolutionParameters::xml_element_name_.c_str());
if (add_pre_sol_item == nullptr) {
return;
}

precomputed_solution_parameters.set_values(add_pre_sol_item);
}

void Parameters::set_projection_values(tinyxml2::XMLElement* root_element)
{
auto add_proj_item = root_element->FirstChildElement(ProjectionParameters::xml_element_name_.c_str());
Expand Down Expand Up @@ -2019,12 +2032,8 @@ GeneralSimulationParameters::GeneralSimulationParameters()
set_parameter("Starting time step", 0, !required, starting_time_step);

set_parameter("Time_step_size", 0.0, required, time_step_size);
set_parameter("Precomputed_time_step_size", 0.0, !required, precomputed_time_step_size);
set_parameter("Verbose", false, !required, verbose);
set_parameter("Warning", false, !required, warning);
set_parameter("Use_precomputed_solution", false, !required, use_precomputed_solution);
set_parameter("Precomputed_solution_file_path", "", !required, precomputed_solution_file_path);
set_parameter("Precomputed_solution_field_name", "", !required, precomputed_solution_field_name);
}

void GeneralSimulationParameters::print_parameters()
Expand Down Expand Up @@ -2316,6 +2325,40 @@ void MeshParameters::set_values(tinyxml2::XMLElement* mesh_elem)
}
}

/////////////////////////////////////////////////////////////////////////////
// P r e c o m p u t e d S o l u t i o n P a r a m e t e r s //
/////////////////////////////////////////////////////////////////////////////

// The PrecomputedSolutionParameters class stores parameters for the
// 'Precomputed_solution' XML element used to read in the data from a
// precomputed solution for the simulation state.

const std::string PrecomputedSolutionParameters::xml_element_name_ = "Precomputed_solution";

PrecomputedSolutionParameters::PrecomputedSolutionParameters()
{
// A parameter that must be defined.
bool required = true;

set_parameter("Field_name", "", required, field_name);
set_parameter("File_path", "", required, file_path);
set_parameter("Time_step", 0.0, !required, time_step);
set_parameter("Use_precomputed_solution", false, !required, use_precomputed_solution);
}

void PrecomputedSolutionParameters::set_values(tinyxml2::XMLElement* xml_elem)
{
using namespace tinyxml2;
std::string error_msg = "Unknown " + xml_element_name_ + " XML element '";
using std::placeholders::_1;
using std::placeholders::_2;

std::function<void(const std::string&, const std::string&)> ftpr =
std::bind( &PrecomputedSolutionParameters::set_parameter_value, *this, _1, _2);

xml_util_set_parameters(ftpr, xml_elem, error_msg);
}

//////////////////////////////////////////////////////////
// P r o j e c t i o n P a r a m e t e r s //
//////////////////////////////////////////////////////////
Expand Down
30 changes: 26 additions & 4 deletions Code/Source/solver/Parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,30 @@ class OutputParameters : public ParameterLists
std::vector<Parameter<std::string>> alias_list;
};

/// @brief The PrecomputedSolutionParameters class stores parameters for the
/// 'Precomputed_solution' XML element used to read in the data from a precomputed solution
/// for the simulation state
/// \code {.xml}
/// <Precomputed_solution>
/// <Project_from_face> lumen_wall </Project_from_face>
/// </Precomputed_solution>
/// \endcode

class PrecomputedSolutionParameters: public ParameterLists
{
public:
PrecomputedSolutionParameters();

void set_values(tinyxml2::XMLElement* xml_elem);

static const std::string xml_element_name_;

Parameter<std::string> field_name;
Parameter<std::string> file_path;
Parameter<double> time_step;
Parameter<bool> use_precomputed_solution;
};

/// @brief The ProjectionParameters class stores parameters for the
/// 'Add_projection' XML element used for fluid-structure interaction
/// simulations.
Expand Down Expand Up @@ -1304,11 +1328,9 @@ class GeneralSimulationParameters : public ParameterLists
Parameter<bool> start_averaging_from_zero;
Parameter<bool> verbose;
Parameter<bool> warning;
Parameter<bool> use_precomputed_solution;

Parameter<double> spectral_radius_of_infinite_time_step;
Parameter<double> time_step_size;
Parameter<double> precomputed_time_step_size;

Parameter<int> increment_in_saving_restart_files;
Parameter<int> increment_in_saving_vtk_files;
Expand All @@ -1323,8 +1345,6 @@ class GeneralSimulationParameters : public ParameterLists
Parameter<std::string> searched_file_name_to_trigger_stop;
Parameter<std::string> save_results_in_folder;
Parameter<std::string> simulation_initialization_file_path;
Parameter<std::string> precomputed_solution_file_path;
Parameter<std::string> precomputed_solution_field_name;
};

/// @brief The FaceParameters class is used to store parameters for the
Expand Down Expand Up @@ -1428,6 +1448,7 @@ class Parameters {
void set_contact_values(tinyxml2::XMLElement* root_element);
void set_equation_values(tinyxml2::XMLElement* root_element);
void set_mesh_values(tinyxml2::XMLElement* root_element);
void set_precomputed_solution_values(tinyxml2::XMLElement* root_element);
void set_projection_values(tinyxml2::XMLElement* root_element);

// Objects representing each parameter section of XML file.
Expand All @@ -1436,6 +1457,7 @@ class Parameters {
std::vector<MeshParameters*> mesh_parameters;
std::vector<EquationParameters*> equation_parameters;
std::vector<ProjectionParameters*> projection_parameters;
PrecomputedSolutionParameters precomputed_solution_parameters;
};

#endif
Expand Down
10 changes: 6 additions & 4 deletions Code/Source/solver/Simulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,12 @@ void Simulation::set_module_parameters()
com_mod.stFileIncr = general.increment_in_saving_restart_files.value();
com_mod.rmsh.isReqd = general.simulation_requires_remeshing.value();

com_mod.usePrecomp = general.use_precomputed_solution.value();
com_mod.precompFileName = general.precomputed_solution_file_path.value();
com_mod.precompFieldName = general.precomputed_solution_field_name.value();
com_mod.precompDt = general.precomputed_time_step_size.value();
auto& precomp_sol = parameters.precomputed_solution_parameters;
com_mod.usePrecomp = precomp_sol.use_precomputed_solution.value();
com_mod.precompFileName = precomp_sol.file_path.value();
com_mod.precompFieldName = precomp_sol.field_name.value();
com_mod.precompDt = precomp_sol.time_step.value();

if ((com_mod.precompDt == 0.0) && (com_mod.usePrecomp)) {
std::cout << "Precomputed time step size is zero. Setting to simulation time step size." << std::endl;
com_mod.precompDt = com_mod.dt;
Expand Down
3 changes: 1 addition & 2 deletions Code/Source/solver/read_files.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1742,9 +1742,8 @@ void read_files(Simulation* simulation, const std::string& file_name)

if (eq.phys == EquationType::phys_heatF) {
auto& eq1_params = simulation->parameters.equation_parameters[0];
auto& general_params = simulation->parameters.general_simulation_parameters;
auto eq1_type = eq1_params->type.value();
if ((eq1_type != "fluid") && (eq1_type != "FSI") && (!general_params.use_precomputed_solution.value())) {
if ((eq1_type != "fluid") && (eq1_type != "FSI") && (!com_mod.usePrecomp)) {
throw std::runtime_error("heatF equation has to be specified after fluid/FSI equation");
}
}
Expand Down
10 changes: 7 additions & 3 deletions tests/cases/fluid/precomputed_dye_AD/solver.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
<Number_of_spatial_dimensions> 3 </Number_of_spatial_dimensions>
<Number_of_time_steps> 1 </Number_of_time_steps>
<Time_step_size> 0.01 </Time_step_size>
<Use_precomputed_solution> true </Use_precomputed_solution>
<Precomputed_solution_file_path> precomputed_velocity.vtu </Precomputed_solution_file_path>
<Precomputed_solution_field_name> Velocity </Precomputed_solution_field_name>

<Spectral_radius_of_infinite_time_step> 0.50 </Spectral_radius_of_infinite_time_step>
<Searched_file_name_to_trigger_stop> STOP_SIM </Searched_file_name_to_trigger_stop>

Expand All @@ -25,6 +23,12 @@
<Debug> 1 </Debug>
</GeneralSimulationParameters>

<Precomputed_solution>
<Use_precomputed_solution> true </Use_precomputed_solution>
<File_path> precomputed_velocity.vtu </File_path>
<Field_name> Velocity </Field_name>
</Precomputed_solution>

<Add_mesh name="msh" >

<Mesh_file_path> mesh/mesh-complete.mesh.vtu </Mesh_file_path>
Expand Down

0 comments on commit 029f52d

Please sign in to comment.