2#include "StoredParameters.H"
3#include "SnapshotConfiguration.H"
6struct StrLookup :
public std::map<std::string, Enum> {
7 using Base = std::map<std::string, Enum>;
9 Enum lookup(std::string str, Enum defaultValue)
22StoredParameters::StoredParameters(
int argc,
char* argv[]):
33 _args = autoPtr<argList>(
34 new argList(argc, argv));
36 if (!_args->checkRootCase())
38 Foam::FatalError.exit();
41 argList& args = _args();
43 for (
int i = 0; i < argc; i++)
45 Info <<
"argv[" << i <<
"] = " << argv[i] << endl;
48 runTime0 = autoPtr<Foam::Time>(
new Foam::Time(Foam::Time::controlDictName,
52 meshConfig_->set_mesh(
55 Foam::fvMesh::defaultRegion,
58 Foam::IOobject::MUST_READ)));
61 meshConfig_->set_nCells(get_mesh().cells().size());
63 ITHACAdict = ithacaLibraryParameters->ITHACAdict;
65 snapshotConfiguration_->set_casenameData(ITHACAdict->lookupOrDefault<fileName>(
"casename",
"./"));
67 PODConfiguration_->set_fieldlist(
static_cast<List<word>
>(ITHACAdict->lookup(
"fields")));
68 solverConfiguration_->set_eigensolver(ithacaLibraryParameters->eigensolver);
69 solverConfiguration_->set_precision(ithacaLibraryParameters->precision);
70 SimulationFlags_->set_exportPython(ithacaLibraryParameters->exportPython);
71 SimulationFlags_->set_exportMatlab(ithacaLibraryParameters->exportMatlab);
72 SimulationFlags_->set_exportTxt(ithacaLibraryParameters->exportTxt);
73 solverConfiguration_->set_outytpe(ithacaLibraryParameters->outytpe);
74 ROMExecutionConfig_->setPressureResolutionKind(StrLookup<PressureResolutionKind>(
76 {
"FullOrder", PressureResolutionKind::FullOrder },
77 {
"ReducedOrder", PressureResolutionKind::ReducedOrder },
78 {
"Neglected", PressureResolutionKind::Neglected },
80 .lookup(ITHACAdict->lookupOrDefault<word>(
"pressureResolutionKind",
""), PressureResolutionKind::Undefined));
81 solverConfiguration_->set_nBlocks(ITHACAdict->lookupOrDefault<label>(
"nBlocks", 1));
82 solverConfiguration_->set_centeredOrNot(ITHACAdict->lookupOrDefault<
bool>(
"centeredOrNot", 1));
83 HyperreductionConfiguration_->set_interpFieldCentered(ITHACAdict->lookupOrDefault<
bool>(
"interpFieldCenteredOrNot", 0));
85 HyperreductionConfiguration_->setHRMethod(ITHACAdict->lookupOrDefault<word>(
"HyperReduction",
"DEIM"));
86 HyperreductionConfiguration_->setHRInterpolatedField(ITHACAdict->lookupOrDefault<word>(
"DEIMInterpolatedField",
"fullStressFunction"));
87 HyperreductionConfiguration_->setECPAlgo(ITHACAdict->lookupOrDefault<word>(
"ECPAlgo",
"Global"));
88 SimulationFlags_->set_onLineReconstruct(ITHACAdict->lookupOrDefault<
bool>(
"onLineReconstruct", 0));
89 SimulationFlags_->set_forcingOrNot(ITHACAdict->lookupOrDefault<
bool>(
"forcingOrNot", 0));
90 SimulationFlags_->set_symDiff(ITHACAdict->lookupOrDefault<
bool>(
"symDiff", 0));
91 ROMExecutionConfig_->setROMTemporalScheme(ITHACAdict->lookupOrDefault<word>(
"ROMTemporalScheme",
"euler"));
93 ROMExecutionConfig_->setUseSOTA(ITHACAdict->lookupOrDefault<word>(
"useSOTA",
"None"));
95 if (ROMExecutionConfig_->useSOTA() !=
"None")
97 Info <<
"===============================================================" << endl;
98 Info <<
" RedLUM is launched in " << ROMExecutionConfig_->useSOTA() <<
"-SOTA mode" << endl;
99 Info <<
" Ithacadict file will be overidden by parameters specified in m_parameters.C" << endl;
100 Info <<
"===============================================================" << endl;
103 if ((!(ROMExecutionConfig_->ROMTemporalScheme() ==
"adams-bashforth")) && (!(ROMExecutionConfig_->ROMTemporalScheme() ==
"euler")) && (!(ROMExecutionConfig_->ROMTemporalScheme() ==
"euler–maruyama")))
105 Info <<
"This temporal scheme is not implemented." << endl;
110 runTimeData =
new Foam::Time(Foam::Time::controlDictName,
".", get_casenameData());
113 if (Pstream::parRun())
115 Foam::fileName casenamePar = get_casenameData() +
"processor" + name(Pstream::myProcNo());
116 Foam::Time* runTimePar =
new Foam::Time(Foam::Time::controlDictName,
".", casenamePar);
117 runTime = runTimePar;
120 runTime = runTimeData;
124 fieldTemplates_->set_U(
new volVectorField(
127 runTime->times()[1].name(),
129 IOobject::MUST_READ),
133 fieldTemplates_->set_p(
new volScalarField(
136 runTime->times()[1].name(),
138 IOobject::MUST_READ),
142 snapshotConfiguration_->set_nSimu(ITHACAdict->lookupOrDefault(
"nSimu", 100));
145 initializeFieldConfiguration();
147 PODConfiguration_->set_weightH1(1.0);
148 PODConfiguration_->set_weightBC(ITHACAdict->lookupOrDefault<
double>(
"weightBC", 0.));
149 PODConfiguration_->set_patchBC(ITHACAdict->lookupOrDefault<word>(
"patchBC",
"inlet"));
154 instantList Times = runTime->times();
157 const entry* existnsnap = ITHACAdict->findEntry(
"Nsnapshots");
158 const entry* existLT = ITHACAdict->findEntry(
"FinalTime");
161 if ((existnsnap) && (existLT))
163 Info <<
"Error you cannot define LatestTime and NSnapShots together" << endl;
165 }
else if (existnsnap)
167 snapshotConfiguration_->set_initialTime(ITHACAdict->lookupOrDefault<scalar>(
"InitialTime", 0));
168 snapshotConfiguration_->set_finalTime(ITHACAdict->lookupOrDefault<scalar>(
"FinalTime", 100000000000000));
169 snapshotConfiguration_->set_nSnapshots(readScalar(ITHACAdict->lookup(
"Nsnapshots")));
170 snapshotConfiguration_->set_startTime(Time::findClosestTimeIndex(runTime->times(), get_initialTime()));
171 snapshotConfiguration_->set_nSnapshots(
min(get_nSnapshots(), Times.size() - get_startTime()));
172 snapshotConfiguration_->set_endTime(get_startTime() + get_nSnapshots() - 1);
173 snapshotConfiguration_->set_finalTime(std::stof(runTime->times()[get_endTime()].name()));
176 snapshotConfiguration_->set_initialTime(ITHACAdict->lookupOrDefault<scalar>(
"InitialTime", 0));
177 snapshotConfiguration_->set_finalTime(ITHACAdict->lookupOrDefault<scalar>(
"FinalTime", 100000000000000));
178 snapshotConfiguration_->set_endTime(Time::findClosestTimeIndex(runTime->times(), get_finalTime()));
179 snapshotConfiguration_->set_startTime(Time::findClosestTimeIndex(runTime->times(), get_initialTime()));
180 snapshotConfiguration_->set_nSnapshots(get_endTime() - get_startTime() + 1);
181 if (get_initialTime() > get_finalTime())
183 Info <<
"FinalTime cannot be smaller than the InitialTime check your ITHACAdict file\n"
187 snapshotConfiguration_->set_finalTime(std::stof(runTime->times()[get_endTime()].name()));
191 const entry* existnsnapSimulation = ITHACAdict->findEntry(
"NsnapshotsSimulation");
192 const entry* existLTSimulation = ITHACAdict->findEntry(
"FinalTimeSimulation");
194 scalar InitialTimeSimulation(get_finalTime());
195 label startTimeSimulation(Time::findClosestTimeIndex(runTime->times(), InitialTimeSimulation));
197 if ((existnsnapSimulation) && (existLTSimulation))
199 Info <<
"Error you cannot define LatestTimeSimulation and NSnapShotsSimulation together" << endl;
201 }
else if (existnsnapSimulation)
203 snapshotConfiguration_->set_nSnapshotsSimulation(readScalar(ITHACAdict->lookup(
"NsnapshotsSimulation")));
204 snapshotConfiguration_->set_nSnapshotsSimulation(
min(get_nSnapshotsSimulation(), Times.size() - startTimeSimulation));
205 snapshotConfiguration_->set_endTimeSimulation(startTimeSimulation + get_nSnapshotsSimulation() - 1);
206 snapshotConfiguration_->set_finalTimeSimulation(std::stof(runTime->times()[get_endTimeSimulation()].name()));
209 snapshotConfiguration_->set_finalTimeSimulation(ITHACAdict->lookupOrDefault<scalar>(
"FinalTimeSimulation", 100000000000000));
210 snapshotConfiguration_->set_endTimeSimulation(Time::findClosestTimeIndex(runTime->times(), get_finalTimeSimulation()));
211 snapshotConfiguration_->set_nSnapshotsSimulation(get_endTimeSimulation() - startTimeSimulation + 1);
212 if (InitialTimeSimulation > get_finalTimeSimulation())
214 Info <<
"FinalTimeSimulation cannot be smaller than the InitialTimeSimulation check your ITHACAdict file\n"
218 snapshotConfiguration_->set_finalTimeSimulation(std::stof(runTime->times()[get_endTimeSimulation()].name()));
222 IOdictionary controlDict(
225 runTimeData->system(),
228 IOobject::NO_WRITE));
229 snapshotConfiguration_->set_writeInterval(controlDict.lookupOrDefault<
double>(
"writeInterval", 1));
231 IOdictionary transportProperties(
233 "transportProperties",
234 runTimeData->constant(),
237 IOobject::NO_WRITE));
239 ROMExecutionConfig_->setNu(
new dimensionedScalar(
242 transportProperties));
244 meshConfig_->set_volume(
new volScalarField(
247 runTimeData->timeName(),
252 dimensionedScalar(
"volume", dimensionSet(0, 3, 0, 0, 0, 0, 0), 1.0)));
254 meshConfig_->get_volume().primitiveFieldRef() = get_mesh().V().field();
256 meshConfig_->set_totalVolume(volVect.sum());
258 meshConfig_->set_delta(
new volScalarField(pow(get_volume(), 1.0 / 3.0)));
262 string simulationType;
267 string filename =
"constant/turbulenceProperties";
268 std::ifstream strm(filename);
273 while (line.find(
"simulationType") == string::npos || line.find(
"//") != string::npos)
293 line.erase(line.size() - 1, 1);
295 simulationType = line;
298 Info <<
"--------------------------------------------" << endl;
299 Info <<
"Simulation type:" << simulationType << endl;
302 if (simulationType ==
"laminar")
304 Info <<
"DNS simulation will be performed" << endl;
307 }
else if (simulationType ==
"LES")
309 fieldTemplates_->set_nut(
new volScalarField(
312 runTime->path() + runTime->times()[1].name(),
314 IOobject::MUST_READ),
318 while (line.find(
"LESModel") == string::npos || line.find(
"//") != string::npos)
336 line.erase(N - 1, 1);
341 if (LESModel ==
"Smagorinsky")
344 set_Ck(ITHACAdict->lookupOrDefault<
double>(
"Ck", 0.094));
345 set_Ce(ITHACAdict->lookupOrDefault<
double>(
"Ce", 1.048));
348 }
else if (LESModel ==
"kOmegaSSTDDES")
352 fieldTemplates_->set_omega(
new volScalarField(
355 runTime->path() + runTime->times()[1].name(),
357 IOobject::MUST_READ),
359 fieldTemplates_->set_k(
new volScalarField(
362 runTime->path() + runTime->times()[1].name(),
364 IOobject::MUST_READ),
368 Info <<
"Only turbulence model Smagorinsky is supported with simulation type LES" << endl;
369 Info <<
"DDES NOT USED**0**" << endl;
375 Info <<
"Simulation type not LES, no DEIM will be performed" << endl;
378 <<
"No DDES was performed" << endl;
381 <<
"No DNS simulation was perfomed" << endl;
386 HyperreductionConfiguration_->setFolderDEIM(
"./ITHACAoutput/");
387 if (SimulationFlags_->useDEIM())
389 if (get_hilbertSpacePOD()[
"nut"] ==
"dL2")
393 HyperreductionConfiguration_->initializeHyperreduction(PODConfiguration_);
397void StoredParameters::initializeFieldConfiguration()
399 const auto& fieldlist = PODConfiguration_->fieldlist();
401 Foam::List<Foam::word> field_names(fieldlist.size());
402 Foam::List<Foam::word> field_types(fieldlist.size());
404 for (label k = 0; k < fieldlist.size(); k++)
406 dictionary& subDict = ITHACAdict->subDict(fieldlist[k]);
408 field_names[k] =
static_cast<word
>(subDict.lookup(
"field_name"));
409 field_types[k] =
static_cast<word
>(subDict.lookup(
"field_type"));
411 label nMode = subDict.lookupOrDefault<label>(
"nmodes", 1);
412 word hilbertSpace = subDict.lookupOrDefault<word>(
"hilbertSpacePOD",
"L2");
415 PODConfiguration_->insert_nModes(field_names[k], nMode);
416 PODConfiguration_->insert_hilbertSpacePOD(field_names[k], hilbertSpace);
417 PODConfiguration_->set_varyingEnergy(field_names[k], 0);
418 PODConfiguration_->set_resolvedVaryingEnergy(field_names[k], 0);
422 PODConfiguration_->set_field_name(field_names);
423 PODConfiguration_->set_field_type(field_types);
427Foam::word StoredParameters::get_pathHilbertSpace_fromHS(Foam::word hilbertSp)
429 Foam::word pathHilbertSpace =
"";
431 if (hilbertSp ==
"L2" || hilbertSp ==
"dL2")
433 pathHilbertSpace =
"";
434 }
else if (hilbertSp ==
"L2wBC")
436 pathHilbertSpace =
"_L2wBC";
437 }
else if (hilbertSp ==
"H1")
439 pathHilbertSpace =
"_H1";
440 }
else if (hilbertSp ==
"wH1")
442 pathHilbertSpace =
"_wH1";
445 Foam::Info <<
"Error: hilbertSpacePOD type " << hilbertSp
446 <<
" is not valid." << Foam::endl;
447 Foam::Info <<
"dot_product_POD is available for L2, L2wBC, H1 and wH1 only." << Foam::endl;
451 return pathHilbertSpace;
454Foam::word StoredParameters::get_pathHilbertSpace(Foam::word fieldName)
456 return get_pathHilbertSpace_fromHS(PODConfiguration_->hilbertSpacePOD()[fieldName]);
Header file of the ITHACAsystem file.
Stores template fields for velocity, pressure, and turbulence quantities.
static Eigen::MatrixXd field2Eigen(GeometricField< Type, PatchField, GeoMesh > &field)
Convert a vector OpenFOAM field into an Eigen Vector.
Discrete Empirical Interpolation Method settings.
static ITHACAparameters * getInstance()
Gets an instance of ITHACAparameters, to be used if the instance is already existing.
Manages mesh-related parameters and geometric information.
Manages POD-specific parameters including modes, energy, and Hilbert spaces.
Manages boolean flags for various simulation options.
Manages snapshot and time-related parameters.
Controls which eigensolver algorithm is used and output formatting.
T min(Eigen::SparseMatrix< T > &mat, label &ind_row, label &ind_col)
Find the minimum of a sparse Matrix (Useful for DEIM).
Eigen::VectorXd getMassMatrixFV(GeometricField< Type, PatchField, GeoMesh > &snapshot)
Gets a vector containing the volumes of each cell of the mesh.