|
[Sponsors] |
Reading rigidBody motion state from custom library |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
June 22, 2022, 18:56 |
Reading rigidBody motion state from custom library
|
#1 |
New Member
Pere
Join Date: Mar 2022
Location: Mallorca
Posts: 16
Rep Power: 4 |
Dear foamers,
I am currently working on a custom type of source term (via a new library), which the user can specify through fvOptions. The idea is that the applied force field depends on the position and velocity of a rigid body, which is defined in dynamicMeshDict using the sixDoFRigidBody library: Code:
... dynamicFvMesh dynamicMotionSolverFvMesh; motionSolverLibs ( "libsixDoFRigidBodyMotion.so" ); solver sixDoFRigidBodyMotion; diffusivity quadratic inverseDistance ( cylinder ); sixDoFRigidBodyMotionCoeffs { ... } I have seen a similar issue tackled in a 2015 post, but unfortunately, I cannot understand it fully. I think they propose modifying the original sixDoF library to export a motion dictionary, which can then be accessed from their custom program. I think there has to be a well-defined manner to access and pass object information between different libraries, but I am very new to programming in OpenFOAM and such things still escape my understanding. Thus, I would really appreciate any guidance in this regard. Thank you very much! Last edited by katiuskas; June 23, 2022 at 05:53. |
|
June 24, 2022, 08:07 |
Found a solution :)
|
#2 |
New Member
Pere
Join Date: Mar 2022
Location: Mallorca
Posts: 16
Rep Power: 4 |
I finally went through the 2015 post and adapted the proposal from yuhan1991 (reply #5). Just in case anyone is trying to do something similar, this is what I did:
Code:
void Foam::sixDoFRigidBodyMotion::createDict() { // Create dictionary if it has not been created before if(!time_.foundObject<IOdictionary>("sixDoFMotion")) { dictionary motionDict; time_.store ( new IOdictionary ( IOobject ( "sixDoFMotion", time_.timeName(), time_, IOobject::NO_READ, IOobject::AUTO_WRITE ), motionDict ) ); Info << "Rigid body IOdictionary 'sixDoFMotion' created" << endl; updateDict(); } } Code:
void Foam::sixDoFRigidBodyMotion::updateDict() { if(time_.foundObject<IOdictionary>("sixDoFMotion")) { // Open and write const dictionary& motionDict = time_.lookupObject<IOdictionary>("sixDoFMotion"); // Update for the motion solver dictionary updateDbDictionary = &motionDict; updateDbDictionary.set("centreOfRotation", centreOfRotation()); updateDbDictionary.set("orientation", orientation()); updateDbDictionary.set("velocity", v()); updateDbDictionary.set("omega", omega()); // Needed to update the IOdictionary const_cast<dictionary& > (motionDict) = updateDbDictionary; Info << "Updating 'sixDoFMotion' IOdictionary" << endl; } } The createDict() function is called only once inside the constructor, whereas updateDict() is called inside sixDoFRigidBodyMotion::update(): Code:
... if (Pstream::master()) { solver_->solve(firstIter, fGlobal, tauGlobal, deltaT, deltaT0); if (report_) { status(); } updateDict(); }
Code:
void Foam::fv::myLib::readRigidBodyDict(const fvMesh& mesh) { // If rigid body dictionary exists if(mesh.time().foundObject<IOdictionary>("sixDoFMotion")) { // Access dictionary const dictionary& motionDict = mesh.time().lookupObject<IOdictionary>("sixDoFMotion"); // Save its reference rigidBodyDict_ = motionDict; } else { Info << "Rigid body IOdictionary ('sixDoFMotion') could not be accessed." << endl; } } Note that in sixDoFRigidBodyMotion.C, I had access to the runtime variable time_ whereas in my custom library I have access to the fvMesh object mesh. Thus, the syntax to access the dictionary in both cases might be slightly different. This is, as of now, the only way I know to transfer data between classes. I am very open to any suggestions! I hope this can help someone in a similar situation. |
|
November 21, 2023, 06:49 |
sharing .C
|
#3 |
New Member
Ivan
Join Date: Dec 2021
Posts: 6
Rep Power: 5 |
Dear Katiuskas,
Thank you so much for posting the solution as I am dealing with something similar. Are you willing to share the .C file of the sixDoFRigidBodyMotion ? I am also trying to inherit the rigid body state in my custom library and I think I have declared something wrong in the sixDoF file. Kind regards, Ivan |
|
Tags |
dynamic mesh, fvoptions, rigid body, sixdof |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
transform in the new motion library rigidBodyMeshMotion | jiadongw | OpenFOAM Running, Solving & CFD | 18 | November 15, 2024 12:26 |
How to access to the solid body motion state from a custom interDyMFoam.C ? | jmf | OpenFOAM Programming & Development | 9 | January 29, 2022 20:31 |
[Commercial meshers] Problem converting fluent mesh | vinz | OpenFOAM Meshing & Mesh Conversion | 28 | October 12, 2015 07:37 |
Compression stoke is giving higher pressure than calculated | nickjuana | CFX | 62 | May 19, 2015 14:32 |
Constant velocity of the material | Sas | CFX | 15 | July 13, 2010 09:56 |