Skip to content

Commit d562dcb

Browse files
authored
Merge branch 'main' into flux_profile_error
2 parents 0137caf + 1a27c43 commit d562dcb

File tree

23 files changed

+343
-46
lines changed

23 files changed

+343
-46
lines changed

Code/Source/solver/Parameters.cpp

Lines changed: 63 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
#include "Parameters.h"
6464
#include "consts.h"
6565
#include "LinearAlgebra.h"
66+
#include "ustruct.h"
6667

6768
#include <iostream>
6869
#include <regex>
@@ -165,6 +166,9 @@ void Parameters::read_xml(std::string file_name)
165166
// Set Add_mesh values.
166167
set_mesh_values(root_element);
167168

169+
// Set Precomputed_solution values.
170+
set_precomputed_solution_values(root_element);
171+
168172
// Set mesh projection parameters.
169173
set_projection_values(root_element);
170174

@@ -217,6 +221,16 @@ void Parameters::set_mesh_values(tinyxml2::XMLElement* root_element)
217221
}
218222
}
219223

224+
void Parameters::set_precomputed_solution_values(tinyxml2::XMLElement* root_element)
225+
{
226+
auto add_pre_sol_item = root_element->FirstChildElement(PrecomputedSolutionParameters::xml_element_name_.c_str());
227+
if (add_pre_sol_item == nullptr) {
228+
return;
229+
}
230+
231+
precomputed_solution_parameters.set_values(add_pre_sol_item);
232+
}
233+
220234
void Parameters::set_projection_values(tinyxml2::XMLElement* root_element)
221235
{
222236
auto add_proj_item = root_element->FirstChildElement(ProjectionParameters::xml_element_name_.c_str());
@@ -791,6 +805,20 @@ void ConstitutiveModelParameters::set_values(tinyxml2::XMLElement* xml_elem)
791805
value_set = true;
792806
}
793807

808+
/// @brief Check if a constitutive model is valid for the given equation.
809+
//
810+
void ConstitutiveModelParameters::check_constitutive_model(const Parameter<std::string>& eq_type_str)
811+
{
812+
auto eq_type = consts::equation_name_to_type.at(eq_type_str.value());
813+
auto model = consts::constitutive_model_name_to_type.at(type.value());
814+
815+
if (eq_type == consts::EquationType::phys_ustruct) {
816+
if (! ustruct::constitutive_model_is_valid(model)) {
817+
throw std::runtime_error("The " + type.value() + " constitutive model is not valid for ustruct equations.");
818+
}
819+
}
820+
}
821+
794822
//////////////////////////////////////////////////////////
795823
// CoupleCplBCParameters //
796824
//////////////////////////////////////////////////////////
@@ -1864,7 +1892,6 @@ void EquationParameters::set_values(tinyxml2::XMLElement* eq_elem)
18641892
//
18651893
while (item != nullptr) {
18661894
auto name = std::string(item->Value());
1867-
//std::cout << "[EquationParameters::set_values] name: " << name << std::endl;
18681895

18691896
if (name == BodyForceParameters::xml_element_name_) {
18701897
auto bf_params = new BodyForceParameters();
@@ -1878,6 +1905,7 @@ void EquationParameters::set_values(tinyxml2::XMLElement* eq_elem)
18781905

18791906
} else if (name == ConstitutiveModelParameters::xml_element_name_) {
18801907
default_domain->constitutive_model.set_values(item);
1908+
default_domain->constitutive_model.check_constitutive_model(type);
18811909

18821910
} else if (name == CoupleCplBCParameters::xml_element_name_) {
18831911
couple_to_cplBC.set_values(item);
@@ -2004,12 +2032,8 @@ GeneralSimulationParameters::GeneralSimulationParameters()
20042032
set_parameter("Starting time step", 0, !required, starting_time_step);
20052033

20062034
set_parameter("Time_step_size", 0.0, required, time_step_size);
2007-
set_parameter("Precomputed_time_step_size", 0.0, !required, precomputed_time_step_size);
20082035
set_parameter("Verbose", false, !required, verbose);
20092036
set_parameter("Warning", false, !required, warning);
2010-
set_parameter("Use_precomputed_solution", false, !required, use_precomputed_solution);
2011-
set_parameter("Precomputed_solution_file_path", "", !required, precomputed_solution_file_path);
2012-
set_parameter("Precomputed_solution_field_name", "", !required, precomputed_solution_field_name);
20132037
}
20142038

20152039
void GeneralSimulationParameters::print_parameters()
@@ -2301,6 +2325,40 @@ void MeshParameters::set_values(tinyxml2::XMLElement* mesh_elem)
23012325
}
23022326
}
23032327

2328+
/////////////////////////////////////////////////////////////////////////////
2329+
// 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 //
2330+
/////////////////////////////////////////////////////////////////////////////
2331+
2332+
// The PrecomputedSolutionParameters class stores parameters for the
2333+
// 'Precomputed_solution' XML element used to read in the data from a
2334+
// precomputed solution for the simulation state.
2335+
2336+
const std::string PrecomputedSolutionParameters::xml_element_name_ = "Precomputed_solution";
2337+
2338+
PrecomputedSolutionParameters::PrecomputedSolutionParameters()
2339+
{
2340+
// A parameter that must be defined.
2341+
bool required = true;
2342+
2343+
set_parameter("Field_name", "", required, field_name);
2344+
set_parameter("File_path", "", required, file_path);
2345+
set_parameter("Time_step", 0.0, !required, time_step);
2346+
set_parameter("Use_precomputed_solution", false, !required, use_precomputed_solution);
2347+
}
2348+
2349+
void PrecomputedSolutionParameters::set_values(tinyxml2::XMLElement* xml_elem)
2350+
{
2351+
using namespace tinyxml2;
2352+
std::string error_msg = "Unknown " + xml_element_name_ + " XML element '";
2353+
using std::placeholders::_1;
2354+
using std::placeholders::_2;
2355+
2356+
std::function<void(const std::string&, const std::string&)> ftpr =
2357+
std::bind( &PrecomputedSolutionParameters::set_parameter_value, *this, _1, _2);
2358+
2359+
xml_util_set_parameters(ftpr, xml_elem, error_msg);
2360+
}
2361+
23042362
//////////////////////////////////////////////////////////
23052363
// P r o j e c t i o n P a r a m e t e r s //
23062364
//////////////////////////////////////////////////////////

Code/Source/solver/Parameters.h

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,7 @@ class ConstitutiveModelParameters : public ParameterLists
510510
public:
511511
ConstitutiveModelParameters();
512512
void print_parameters();
513+
void check_constitutive_model(const Parameter<std::string>& eq_type);
513514
bool defined() const { return value_set; };
514515
void set_values(tinyxml2::XMLElement* modl_params);
515516
static const std::string xml_element_name_;
@@ -752,6 +753,30 @@ class OutputParameters : public ParameterLists
752753
std::vector<Parameter<std::string>> alias_list;
753754
};
754755

756+
/// @brief The PrecomputedSolutionParameters class stores parameters for the
757+
/// 'Precomputed_solution' XML element used to read in the data from a precomputed solution
758+
/// for the simulation state
759+
/// \code {.xml}
760+
/// <Precomputed_solution>
761+
/// <Project_from_face> lumen_wall </Project_from_face>
762+
/// </Precomputed_solution>
763+
/// \endcode
764+
765+
class PrecomputedSolutionParameters: public ParameterLists
766+
{
767+
public:
768+
PrecomputedSolutionParameters();
769+
770+
void set_values(tinyxml2::XMLElement* xml_elem);
771+
772+
static const std::string xml_element_name_;
773+
774+
Parameter<std::string> field_name;
775+
Parameter<std::string> file_path;
776+
Parameter<double> time_step;
777+
Parameter<bool> use_precomputed_solution;
778+
};
779+
755780
/// @brief The ProjectionParameters class stores parameters for the
756781
/// 'Add_projection' XML element used for fluid-structure interaction
757782
/// simulations.
@@ -1303,11 +1328,9 @@ class GeneralSimulationParameters : public ParameterLists
13031328
Parameter<bool> start_averaging_from_zero;
13041329
Parameter<bool> verbose;
13051330
Parameter<bool> warning;
1306-
Parameter<bool> use_precomputed_solution;
13071331

13081332
Parameter<double> spectral_radius_of_infinite_time_step;
13091333
Parameter<double> time_step_size;
1310-
Parameter<double> precomputed_time_step_size;
13111334

13121335
Parameter<int> increment_in_saving_restart_files;
13131336
Parameter<int> increment_in_saving_vtk_files;
@@ -1322,8 +1345,6 @@ class GeneralSimulationParameters : public ParameterLists
13221345
Parameter<std::string> searched_file_name_to_trigger_stop;
13231346
Parameter<std::string> save_results_in_folder;
13241347
Parameter<std::string> simulation_initialization_file_path;
1325-
Parameter<std::string> precomputed_solution_file_path;
1326-
Parameter<std::string> precomputed_solution_field_name;
13271348
};
13281349

13291350
/// @brief The FaceParameters class is used to store parameters for the
@@ -1427,6 +1448,7 @@ class Parameters {
14271448
void set_contact_values(tinyxml2::XMLElement* root_element);
14281449
void set_equation_values(tinyxml2::XMLElement* root_element);
14291450
void set_mesh_values(tinyxml2::XMLElement* root_element);
1451+
void set_precomputed_solution_values(tinyxml2::XMLElement* root_element);
14301452
void set_projection_values(tinyxml2::XMLElement* root_element);
14311453

14321454
// Objects representing each parameter section of XML file.
@@ -1435,6 +1457,7 @@ class Parameters {
14351457
std::vector<MeshParameters*> mesh_parameters;
14361458
std::vector<EquationParameters*> equation_parameters;
14371459
std::vector<ProjectionParameters*> projection_parameters;
1460+
PrecomputedSolutionParameters precomputed_solution_parameters;
14381461
};
14391462

14401463
#endif

Code/Source/solver/Simulation.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,12 @@ void Simulation::set_module_parameters()
100100
com_mod.stFileIncr = general.increment_in_saving_restart_files.value();
101101
com_mod.rmsh.isReqd = general.simulation_requires_remeshing.value();
102102

103-
com_mod.usePrecomp = general.use_precomputed_solution.value();
104-
com_mod.precompFileName = general.precomputed_solution_file_path.value();
105-
com_mod.precompFieldName = general.precomputed_solution_field_name.value();
106-
com_mod.precompDt = general.precomputed_time_step_size.value();
103+
auto& precomp_sol = parameters.precomputed_solution_parameters;
104+
com_mod.usePrecomp = precomp_sol.use_precomputed_solution.value();
105+
com_mod.precompFileName = precomp_sol.file_path.value();
106+
com_mod.precompFieldName = precomp_sol.field_name.value();
107+
com_mod.precompDt = precomp_sol.time_step.value();
108+
107109
if ((com_mod.precompDt == 0.0) && (com_mod.usePrecomp)) {
108110
std::cout << "Precomputed time step size is zero. Setting to simulation time step size." << std::endl;
109111
com_mod.precompDt = com_mod.dt;

Code/Source/solver/initialize.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -328,19 +328,21 @@ void initialize(Simulation* simulation, Vector<double>& timeP)
328328
dmsg.banner();
329329
#endif
330330

331-
std::string hist_file_name;
331+
// Setup logging to history file.
332+
if (!simulation->com_mod.cm.slv(simulation->cm_mod)) {
333+
std::string hist_file_name;
332334

333-
if (chnl_mod.appPath != "") {
334-
auto mkdir_arg = std::string("mkdir -p ") + chnl_mod.appPath;
335-
std::system(mkdir_arg.c_str());
336-
hist_file_name = chnl_mod.appPath + "/" + simulation->history_file_name;
337-
} else {
338-
hist_file_name = simulation->history_file_name;
339-
}
335+
if (chnl_mod.appPath != "") {
336+
auto mkdir_arg = std::string("mkdir -p ") + chnl_mod.appPath;
337+
std::system(mkdir_arg.c_str());
338+
hist_file_name = chnl_mod.appPath + "/" + simulation->history_file_name;
339+
} else {
340+
hist_file_name = simulation->history_file_name;
341+
}
340342

341-
// Setup logging to history file.
342-
bool output_to_cout = true;
343-
simulation->logger.initialize(hist_file_name, output_to_cout);
343+
bool output_to_cout = true;
344+
simulation->logger.initialize(hist_file_name, output_to_cout);
345+
}
344346

345347
#ifdef debug_initialize
346348
dmsg << "Set time " << std::endl;

Code/Source/solver/mat_models.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -408,21 +408,13 @@ void compute_pk2cc(const ComMod& com_mod, const CepMod& cep_mod, const dmnType&
408408
// Now, add isochoric and total stress, elasticity tensors
409409
switch (stM.isoType) {
410410
case ConstitutiveModelType::stIso_lin: {
411-
if (ustruct) {
412-
throw std::runtime_error("[compute_pk2cc] Linear isotropic material model not valid for ustruct physics.");
413-
}
414-
415411
double g1 = stM.C10; // mu
416412
S += g1*Idm;
417413
return;
418414
} break;
419415

420416
// St.Venant-Kirchhoff
421417
case ConstitutiveModelType::stIso_StVK: {
422-
if (ustruct) {
423-
throw std::runtime_error("[compute_pk2cc] St.Venant-Kirchhoff material model not valid for ustruct physics.");
424-
}
425-
426418
double g1 = stM.C10; // lambda
427419
double g2 = stM.C01 * 2.0; // 2*mu
428420

@@ -432,10 +424,6 @@ void compute_pk2cc(const ComMod& com_mod, const CepMod& cep_mod, const dmnType&
432424

433425
// modified St.Venant-Kirchhoff
434426
case ConstitutiveModelType::stIso_mStVK: {
435-
if (ustruct) {
436-
throw std::runtime_error("[compute_pk2cc] Modified St.Venant-Kirchhoff material model not valid for ustruct physics.");
437-
}
438-
439427
double g1 = stM.C10; // kappa
440428
double g2 = stM.C01; // mu
441429

Code/Source/solver/read_files.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ void face_match(ComMod& com_mod, faceType& lFa, faceType& gFa, Vector<int>& ptr)
122122
blk[iBlk].n = blk[iBlk].n + 1;
123123
}
124124

125-
for (int a = 0; a < gFa.nNo; a++) {
125+
for (int a = 0; a < lFa.nNo; a++) {
126126
auto coord = lFa.x.col(a);
127127
int iBlk = find_blk(nsd, nBlkd, nFlt, xMin, dx, coord);
128128
auto minS = std::numeric_limits<double>::max();
@@ -1744,9 +1744,8 @@ void read_files(Simulation* simulation, const std::string& file_name)
17441744

17451745
if (eq.phys == EquationType::phys_heatF) {
17461746
auto& eq1_params = simulation->parameters.equation_parameters[0];
1747-
auto& general_params = simulation->parameters.general_simulation_parameters;
17481747
auto eq1_type = eq1_params->type.value();
1749-
if ((eq1_type != "fluid") && (eq1_type != "FSI") && (!general_params.use_precomputed_solution.value())) {
1748+
if ((eq1_type != "fluid") && (eq1_type != "FSI") && (!com_mod.usePrecomp)) {
17501749
throw std::runtime_error("heatF equation has to be specified after fluid/FSI equation");
17511750
}
17521751
}

Code/Source/solver/set_bc.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ void calc_der_cpl_bc(ComMod& com_mod, const CmMod& cm_mod)
8484
// if (ALL(cplBC.fa.bGrp .EQ. cplBC_Dir)) RETURN
8585

8686
// Determine current physics
87-
auto& cDmn = com_mod.cDmn;
88-
auto cPhys = eq.dmn[cDmn].phys;
87+
auto cPhys = eq.phys;
8988

9089
// Mechanical configuration in which to compute flowrate
9190
auto cfg_o = MechanicalConfigurationType::reference;
@@ -686,8 +685,7 @@ void set_bc_cpl(ComMod& com_mod, CmMod& cm_mod)
686685
auto& eq = com_mod.eq[iEq];
687686

688687
// Determine current physics
689-
auto& cDmn = com_mod.cDmn;
690-
auto cPhys = eq.dmn[cDmn].phys;
688+
auto cPhys = eq.phys;
691689

692690
// Configuration in which to compute flowrate
693691
auto cfg_o = MechanicalConfigurationType::reference;

Code/Source/solver/ustruct.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,21 @@ void b_ustruct_3d(const ComMod& com_mod, const int eNoN, const double w, const V
210210
}
211211
}
212212

213+
/// @brief Check is a constitutive model is valid for the ustruct equation.
214+
//
215+
bool constitutive_model_is_valid(consts::ConstitutiveModelType model)
216+
{
217+
using namespace consts;
218+
219+
static std::set<ConstitutiveModelType> unsupported_models {
220+
ConstitutiveModelType::stIso_lin,
221+
ConstitutiveModelType::stIso_StVK,
222+
ConstitutiveModelType::stIso_mStVK
223+
};
224+
225+
return unsupported_models.count(model) == 0;
226+
}
227+
213228
/// @brief Reproduces Fortran CONSTRUCT_uSOLID.
214229
//
215230
void construct_usolid(ComMod& com_mod, CepMod& cep_mod, const mshType& lM, const Array<double>& Ag,

Code/Source/solver/ustruct.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ void b_ustruct_3d(const ComMod& com_mod, const int eNoN, const double w, const V
4343
const Array<double>& Nx, const Array<double>& dl, const Vector<double>& hl, const Vector<double>& nV,
4444
Array<double>& lR, Array3<double>& lK, Array3<double>& lKd);
4545

46+
bool constitutive_model_is_valid(consts::ConstitutiveModelType model);
47+
4648
void construct_usolid(ComMod& com_mod, CepMod& cep_mod, const mshType& lM, const Array<double>& Ag, const Array<double>& Yg,
4749
const Array<double>& Dg);
4850

tests/cases/fluid/precomputed_dye_AD/solver.xml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
<Number_of_spatial_dimensions> 3 </Number_of_spatial_dimensions>
77
<Number_of_time_steps> 1 </Number_of_time_steps>
88
<Time_step_size> 0.01 </Time_step_size>
9-
<Use_precomputed_solution> true </Use_precomputed_solution>
10-
<Precomputed_solution_file_path> precomputed_velocity.vtu </Precomputed_solution_file_path>
11-
<Precomputed_solution_field_name> Velocity </Precomputed_solution_field_name>
9+
1210
<Spectral_radius_of_infinite_time_step> 0.50 </Spectral_radius_of_infinite_time_step>
1311
<Searched_file_name_to_trigger_stop> STOP_SIM </Searched_file_name_to_trigger_stop>
1412

@@ -25,6 +23,12 @@
2523
<Debug> 1 </Debug>
2624
</GeneralSimulationParameters>
2725

26+
<Precomputed_solution>
27+
<Use_precomputed_solution> true </Use_precomputed_solution>
28+
<File_path> precomputed_velocity.vtu </File_path>
29+
<Field_name> Velocity </Field_name>
30+
</Precomputed_solution>
31+
2832
<Add_mesh name="msh" >
2933

3034
<Mesh_file_path> mesh/mesh-complete.mesh.vtu </Mesh_file_path>

0 commit comments

Comments
 (0)