39 _args = autoPtr<argList>
41 new argList(argc, argv)
44 if (!
_args->checkRootCase())
46 Foam::FatalError.exit();
49 argList& args =
_args();
50#include "createTime.H"
52 Info <<
"Create a dynamic mesh for time = "
53 << runTime.timeName() << nl << endl;
54 meshPtr = autoPtr<dynamicFvMesh> (dynamicFvMesh::New(args, runTime));
55 dynamicFvMesh& mesh = meshPtr();
56 _pimple = autoPtr<pimpleControl>
64#include "createFields.H"
65#include "initContinuityErrs.H"
139 NUmodesOut = para->ITHACAdict->lookupOrDefault<label>(
"NmodesUout", 15);
141 NPmodesOut = para->ITHACAdict->lookupOrDefault<label>(
"NmodesPout", 15);
143 NNutModesOut = para->ITHACAdict->lookupOrDefault<label>(
"NmodesNutOut", 15);
145 NUmodes = para->ITHACAdict->lookupOrDefault<label>(
"NmodesUproj", 10);
147 NPmodes = para->ITHACAdict->lookupOrDefault<label>(
"NmodesPproj", 10);
149 NNutModes = para->ITHACAdict->lookupOrDefault<label>(
"NmodesNutProj", 0);
155 dynamicFvMesh& mesh = meshPtr();
161 pimpleControl& pimple =
_pimple();
162 volScalarField& p =
_p();
163 volVectorField& U =
_U();
164 surfaceScalarField& phi =
_phi();
165 IOMRFZoneList& MRF =
_MRF();
168 instantList Times = runTime.times();
171 runTime.setTime(Times[1], 1);
178 meshToMesh0::order mapOrder = meshToMesh0::MAP;
179 dictionary dictCoeffs(dyndict().findDict(
"sixDoFRigidBodyMotionCoeffs"));
180 Foam::functionObjects::forces fomforces(
"fomforces", mesh, dictCoeffs);
181 surfaceVectorField N = mesh.Sf() / mesh.magSf();
183#include "createUfIfPresent.H"
184 Info <<
"\nStarting time loop\n" << endl;
186 while (runTime.run())
188#include "CourantNo.H"
191 Info <<
"Time = " << runTime.timeName() << nl << endl;
194 while (pimple.loop())
196 if (pimple.firstIter() || moveMeshOuterCorrectors)
207 mesh.movePoints(sDRBMS().curPoints());
219 phi = mesh.Sf() & Uf();
220#include "correctPhi.H"
222 fvc::makeRelative(phi, U);
225 if (checkMeshCourantNo)
227#include "meshCourantNo.H"
235 while (pimple.correct())
240 if (pimple.turbCorr())
242 laminarTransport.correct();
247 scalar alffa = sDRBMS().motion().omega().z() / runTime.deltaTValue();
264 fomforcex.append(fomforces.forceEff().x());
265 fomforcey.append(fomforces.forceEff().y());
267 centerofmassy.append(sDRBMS().motion().centreOfMass().y());
268 centerofmassz.append(quaternion(sDRBMS().motion().orientation()).eulerAngles(
269 quaternion::XYZ).z());
273 //tmp<volVectorField> U_mapped(U);
274 //tmp<volScalarField> p_mapped(p);
275 volVectorField U_mapped
277 IOobject("U", runTime.timeName(), mesh0),
279 dimensionedVector("U", U.dimensions(), Zero)
282 volScalarField p_mapped
284 IOobject("p", runTime.timeName(), mesh0),
286 dimensionedScalar("p", p.dimensions(), Zero)
290 Info << "[mapFieldToMesh0] Meshes are identical. Copying field..." << endl;
296 U_mapped = mapper.interpolate<Foam::vector, Foam::plusEqOp<Foam::vector>>(U, mapOrder, Foam::plusEqOp<Foam::vector>() );
298 p_mapped = mapper.interpolate<scalar,Foam::plusEqOp<scalar>>(p, mapOrder, Foam::plusEqOp<scalar>() );
301 U_mapped.ref().rename("U");
302 p_mapped.ref().rename("p");
303 U_mapped.correctBoundaryConditions();
304 p_mapped.correctBoundaryConditions();*/
306 word localFolder = folder + name(
folderN + 1);
314 localFolder, name(
counter) +
"/polyMesh/");
327 Ufield.append(U.clone() );
328 Pfield.append(p.clone() );
329 Dfield.append(sDRBMS().pointDisplacement().clone());
333 if (runTime.time().value() + runTime.deltaT().value() >=
finalTime)
335 Info <<
"===== Storing final mesh =====" << endl;
336 meshes.append(meshPtr.ptr());
388 argList& args =
_args();
390 instantList Times = runTime.times();
391 runTime.setTime(0, 1);
398 Info <<
"ReCreating dynamic mesh for time = "
399 << runTime.timeName() << nl << endl;
400 meshPtr = autoPtr<dynamicFvMesh> (dynamicFvMesh::New(args, runTime));
404 Foam::dynamicFvMesh& mesh = meshPtr();
406 _pimple = autoPtr<pimpleControl>
413#include "createFields.H"
422 volScalarField& mu_new =
const_cast<volScalarField&
>(nu);
425 for (label i = 0; i < mu_new.boundaryFieldRef().size(); i++)
431void fsiBasic::change_stiffness(scalar& mu)
433 dictionary& dictCoeffs = dyndict->subDict(
"sixDoFRigidBodyMotionCoeffs");
434 dictionary& restraints = dictCoeffs.subDict(
"restraints");
435 dictionary& spring = restraints.subDict(
"verticalSpring1");
436 scalar stiffness = spring.get<scalar>(
"stiffness");
437 Info <<
"==== stiffness ==== " << stiffness << endl;
439 spring.set(
"stiffness",
mu);
440 stiffness = spring.get<scalar>(
"stiffness");
445 Info <<
"==== New stiffness ==== " << stiffness << endl;
447 dyndict->regIOobject::write();
451 const word& fileName,
452 const List<scalar>& foamField)
455 cnpy::save(eigenData, outputDir +
"/" + fileName +
".npy");
463 word fullPath =
"./" + outputPath;
477 fileNameList dirs = readDir(baseDir, fileName::DIRECTORY);
478 Eigen::VectorXd vecOfCentreOfMasses;
483 if (dirs[i].find(
"DataFromFoam_") == 0)
485 sortedDirs.append(dirs[i]);
489 std::sort(sortedDirs.begin(), sortedDirs.end(),
490 [](
const word & a,
const word & b)
492 int numA = std::stoi(a.substr(std::string(
"DataFromFoam_").length()));
493 int numB = std::stoi(b.substr(std::string(
"DataFromFoam_").length()));
497 forAll(sortedDirs, i)
499 fileName targetFile = baseDir / sortedDirs[i] /
"CentreOfMassY.npy";
501 if (exists(targetFile))
503 Info <<
"Found CentreOfMassY.npy in " << targetFile << endl;
504 Eigen::MatrixXd CentreOfMassY;
505 cnpy::load(CentreOfMassY, targetFile);
506 Eigen::VectorXd currentVec = CentreOfMassY.col(0);
509 vecOfCentreOfMasses.conservativeResize(vecOfCentreOfMasses.size() +
511 vecOfCentreOfMasses.tail(currentVec.size()) = currentVec;
512 Info <<
"Loaded: " << targetFile << endl;
516 Info <<
"CentreOfMassY.npy not found in " << targetFile << endl;
519 this->CylDispl = vecOfCentreOfMasses;
526 dictionary& dictCoeffs = dyndict().subDict(
"sixDoFRigidBodyMotionCoeffs");
527 dictionary& restraints = dictCoeffs.subDict(
"restraints");
528 dictionary& spring = restraints.subDict(
"verticalSpring1");
529 scalar oldMu = spring.get<scalar>(param_name);
531 spring.set(param_name, newMu);
533 dyndict().regIOobject::write(
true);
538 dyndict = autoPtr<IOdictionary>
545 meshPtr().time().constant(),
554 sDRBMS = autoPtr<sixDoFRigidBodyMotionSolver>
556 new sixDoFRigidBodyMotionSolver(meshPtr(), dyndict())
558 Info <<
">>> Motion solver rebuilt with new stiffness.\n";
static Eigen::MatrixXd field2Eigen(GeometricField< Type, PatchField, GeoMesh > &field)
Convert a vector OpenFOAM field into an Eigen Vector.
Class for the definition of some general parameters, the parameters must be defined from the file ITH...
static ITHACAparameters * getInstance()
Gets an instance of ITHACAparameters, to be used if the instance is already existing.
bool checkWrite(Time &timeObject)
Function to check if the solution must be exported.
scalar startTime
Start Time (initial time to start storing the snapshots).
scalar writeEvery
Time step of the writing procedure.
scalar timeStep
Time step of the simulation.
scalar nextWrite
Auxiliary variable to store the next writing instant.
scalar finalTime
Final time (final time of the simulation and consequently of the acquisition of the snapshots).
void updateStiffnessAndRebuildSolver(scalar &newMu, word param_name="stiffness")
autoPtr< pointVectorField > _pointDisplacement
pointDisplacement field
List< scalar > fomforcey
List to save lift and drag forces.
void prepareFoamData(const word &outputPath)
Prepare data such forces and centre of mass.
PtrList< surfaceVectorField > NormalFields
List of surface normal vectors.
autoPtr< pimpleControl > _pimple
pimpleControl
void exportFoamFieldToNpy(const word &outputDir, const word &fileName, const List< scalar > &foamField)
Help function for the prepareFoamData routine.
PtrList< pointVectorField > Dfield
List of pointers used to form the displacement snapshots matrix.
void change_viscosity(double mu)
Method to construct RBFI for pointDisplacement void PodIpointDispl(Eigen::MatrixXd muu,...
void restart()
method to set all fields back to values in 0 folder
fsiBasic()
Construct Null.
List< scalar > centerofmassx
List scalar for access the centerofmass.
void loadCentreOfMassY(const fileName &baseDir="ITHACAoutput")
to load all centre of mass for training RBF network
label counter
Counter used for the output of the full order solutions.
void assignBC(volVectorField &s, label BC_ind, Vector< double > &value)
Assign Boundary Condition to a volVectorField.
void assignIF(T &s, G &value)
Assign internal field condition.
bool offline
Boolean variable, it is 1 if the Offline phase has already been computed, else 0.
label folderN
Counter to save intermediate steps in the correct folder, for unsteady and some stationary cases.
IOdictionary * ITHACAdict
dictionary to store input output infos
Eigen::MatrixXd mu
Row matrix of parameters.
autoPtr< argList > _args
argList
bool podex
Boolean variable, it is 1 if the POD has already been computed, else 0.
void truthSolve()
Perform a TruthSolve.
label NPmodes
Number of pressure modes used for the projection.
autoPtr< surfaceScalarField > _phi
Flux.
PtrList< volScalarField > Pfield
List of pointers used to form the pressure snapshots matrix.
autoPtr< fv::options > _fvOptions
fvOptions
autoPtr< Time > _runTime
Time.
autoPtr< singlePhaseTransportModel > _laminarTransport
Laminar transport (used by turbulence model).
label NUmodes
Number of velocity modes used for the projection.
label NNutModesOut
Number of nut modes to be calculated.
autoPtr< IOMRFZoneList > _MRF
MRF variable.
label NNutModes
Number of nut modes used for the projection.
autoPtr< incompressible::turbulenceModel > turbulence
Turbulence model.
label NUmodesOut
Number of velocity modes to be calculated.
label NPmodesOut
Number of pressure modes to be calculated.
autoPtr< volVectorField > _U
Velocity field.
autoPtr< volScalarField > _p
Pressure field.
Header file of the fsiBasic class.
void writePoints(pointField points, fileName folder, fileName subfolder)
Write points of a mesh to a file.
void exportSolution(GeometricField< Type, PatchField, GeoMesh > &s, fileName subfolder, fileName folder, word fieldName)
Export a field to file in a certain folder and subfolder.
bool check_pod()
Check if the POD data folder "./ITHACAoutput/POD" exists.
bool check_off()
Check if the offline data folder "./ITHACAoutput/Offline" exists.
bool check_folder(word folder)
Checks if a folder exists.