|
[Sponsors] |
custom solver interDyMFoam : how to read the centreOfRotation ? |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
December 9, 2014, 18:02 |
custom solver interDyMFoam : how to read the centreOfRotation ?
|
#1 |
Member
Jean-Michel FONTAINE
Join Date: Aug 2009
Location: Orleans - France
Posts: 55
Rep Power: 17 |
Hi
I would like to implement a sort of position control for floating objects. For this I attempt to customize interDyMFoam. But I am new in C++, and doing this is a steep mountain for me ! This is my modified interDyMFoam.C. I try to read the current position of the floating object like this : Code:
#include "fvCFD.H" #include "dynamicFvMesh.H" #include "CMULES.H" #include "subCycle.H" #include "immiscibleIncompressibleTwoPhaseMixture.H" #include "turbulenceModel.H" #include "pimpleControl.H" #include "fvIOoptionList.H" #include "fixedFluxPressureFvPatchScalarField.H" // my additions : #include "sixDoFRigidBodyMotion.H" #include "sixDoFRigidBodyMotionI.H" #include "sixDoFRigidBodyMotionState.H" #include "sixDoFRigidBodyMotionStateI.H" #include "point.H" while (runTime.run()) { #include "readControls.H" #include "alphaCourantNo.H" #include "CourantNo.H" #include "setDeltaT.H" runTime++; Info<< "Time = " << runTime.timeName() << nl << endl; // this is my attempt to access to the motion state Foam::point centre; Foam::sixDoFRigidBodyMotionState motionState; centre = motionState.centreOfRotation(); Code:
Make/linux64GccDPOpt/interRelativeDyMFoam.o: In function `main': interRelativeDyMFoam.C:(.text.startup+0x23ec): undefined reference to `Foam::sixDoFRigidBodyMotionState::sixDoFRigidBodyMotionState()' interRelativeDyMFoam.C:(.text.startup+0x5a7a): undefined reference to `Foam::sixDoFRigidBodyMotionState::~sixDoFRigidBodyMotionState()' interRelativeDyMFoam.C:(.text.startup+0x63e0): undefined reference to `Foam::sixDoFRigidBodyMotionState::~sixDoFRigidBodyMotionState()' collect2: error: ld returned 1 exit status Kind regards Jean-Michel |
|
December 9, 2014, 18:35 |
custom solver interDyMFoam : how to read the centreOfRotation ?
|
#2 |
Member
Jean-Michel FONTAINE
Join Date: Aug 2009
Location: Orleans - France
Posts: 55
Rep Power: 17 |
Oh, of course it was an extract of the code
Please find attached the c++ source. It is for OF2.3.0 Best wishes Jean-Michel |
|
December 10, 2014, 03:21 |
|
#3 |
Senior Member
|
Hi,
1. It seems you're missing -lsixDoFRigidBodyMotion in your Make/options 2. Maybe I miss something but sixDoFRigidBodyMotionState doesn't have centreOfRotation method (only centreOfMass). Also the way you're constructing the object value will be vector::zero. |
|
December 10, 2014, 16:39 |
custom solver interDyMFoam : how to read the centreOfRotation ?
|
#4 |
Member
Jean-Michel FONTAINE
Join Date: Aug 2009
Location: Orleans - France
Posts: 55
Rep Power: 17 |
Dear Alexey
Thanks for your kind attention Your first suggestion solved the compilation error, thanks. The compilator doesn't complain about centreOfRotation, which is a method declared in 'sixDoFRigidBodyMotionState.H'. Now you are fully right, the point 'centre' is always zero. I don't know how to solve this. I only know Python, and in C++ the way to call an existing class instance is obscur to me. How to find the first usage of the class, and the name of the objects ? What is the role of the third constructor in 'sixDoFRigidBodyMotionState.C' ? is it the one I should use ? If yes, what should be the arguments ? Sorry for my elementary questions. Best wishes Jean-Michel |
|
December 10, 2014, 17:20 |
|
#5 | |
Senior Member
|
Hi,
Quote:
Code:
centreOfRotation_ ( dict.lookupOrDefault ( "centreOfRotation", dict.lookupOrDefault("centreOfMass", vector::zero) ) ), Q_(dict.lookupOrDefault("orientation", tensor::I)), v_(dict.lookupOrDefault("velocity", vector::zero)), a_(dict.lookupOrDefault("acceleration", vector::zero)), pi_(dict.lookupOrDefault("angularMomentum", vector::zero)), tau_(dict.lookupOrDefault("torque", vector::zero)) |
||
December 10, 2014, 17:45 |
custom solver interDyMFoam : how to read the centreOfRotation ?
|
#6 |
Member
Jean-Michel FONTAINE
Join Date: Aug 2009
Location: Orleans - France
Posts: 55
Rep Power: 17 |
Dear Alexey
What I miss are the classes and objects involved in the 6DOFmotion analysis. I understood that the dynamic mesh is created in 'createDynamicFvMesh.H' and the object is called 'mesh'. But after I don't see anything in the main() that invoques the class 'sixDoFRigidBodyMotion' and creates an object like 'motion'. Despite this, the link between 'mesh' and 'motion' is likely existing, since 'sixDoFRigidBodyMotionRestraint' work as expected. I I don't know how to access this mysterious object 'motion' through 'motionState()'. Wow, diving into OpenFoam is not the easiest way to begin in C++! Jean-Michel |
|
December 11, 2014, 04:28 |
|
#7 |
Senior Member
|
Well, if you take a look at createDynamicFvMesh.H:
Code:
autoPtr<dynamicFvMesh> meshPtr ( dynamicFvMesh::New ( IOobject ( dynamicFvMesh::defaultRegion, runTime.timeName(), runTime, IOobject::MUST_READ ) ) ); Code:
Foam::autoPtr<Foam::dynamicFvMesh> Foam::dynamicFvMesh::New(const IOobject& io) { ... IOdictionary dict ( IOobject ( "dynamicMeshDict", io.time().constant(), (io.name() == polyMesh::defaultRegion ? "" : io.name()), io.db(), IOobject::MUST_READ_IF_MODIFIED, IOobject::NO_WRITE, false ) ); const word dynamicFvMeshTypeName(dict.lookup("dynamicFvMesh")); ... IOobjectConstructorTable::iterator cstrIter = IOobjectConstructorTablePtr_->find(dynamicFvMeshTypeName); ... } Then in you take a look at the constructor of dynamicMotionSolverFvMesh, it's just Code:
Foam::dynamicMotionSolverFvMesh::dynamicMotionSolverFvMesh(const IOobject& io) : dynamicFvMesh(io), motionPtr_(motionSolver::New(*this)) {} If you just need to know centre of rotation, you can read it from dictionary with something like: Code:
dictionary dict_ ( IOobject ( "dynamicMeshDict", mesh.time().constant(), mesh, IOobject::MUST_READ, IOobject::NO_WRITE ) ); vector c(dict_.subDict("sixDoFRigidBodyMotionCoeffs").lookupOrDefault<vector>("centreOfMass", vector::zero)); |
|
December 12, 2014, 07:03 |
custom solver interDyMFoam : how to read the centreOfRotation ?
|
#8 |
Member
Jean-Michel FONTAINE
Join Date: Aug 2009
Location: Orleans - France
Posts: 55
Rep Power: 17 |
Should I rebuild an instance of the motion from the dynamicMeshDictionary, its values will remain constant, won't they ?
I need rather the current values of the motion, at each real time step. A solution would be to call a global variable with the current state of the motion. I digged around what is done in 'linearSpring.C' in 'sixDoFRigidBodyMotion/sixDoFRigidBodyMotion/restraints' : there is a member function that calculates a restraint force depending on the current motion position. It is exactely what I need, but I was not able to reproduce it in interDyMFoam.C, and access to that current position Jean-Michel * |
|
December 12, 2014, 11:56 |
|
#9 |
Senior Member
|
Yes, value read from dictionary will be constant.
You don't have direct access to from solver but you can create your own myDynamicMotionSolverFvMesh based upon dynamicMotionSolverFvMesh and expose motionSolver property to your solver (i.e. move definition of autoPtr<motionSolver> motionPtr_ from private to public). This is quick and dirty way to get access to motionState object in solver. |
|
December 15, 2014, 15:19 |
custom solver interDyMFoam : how to read the centreOfRotation ?
|
#10 |
Member
Jean-Michel FONTAINE
Join Date: Aug 2009
Location: Orleans - France
Posts: 55
Rep Power: 17 |
i will try this.
Since I first have to learn C++, it won't be quick. But dirty for sure... Thanks |
|
March 24, 2015, 12:49 |
|
#11 |
Senior Member
Join Date: Jul 2011
Posts: 120
Rep Power: 15 |
Just curious, since I am working on something similar, would it be possible to create access functions in the sixDoFRigidBodyMotion?
Would we need to modify the motionSolver class as well? Last edited by haze_1986; March 26, 2015 at 22:56. |
|
April 8, 2015, 21:56 |
Custom solver interDyMFoam : how to read the centreOfRotation ?
|
#12 |
Member
Jean-Michel FONTAINE
Join Date: Aug 2009
Location: Orleans - France
Posts: 55
Rep Power: 17 |
Hi
I obtained something working, based on a global variable (c++ specialists will object for sure) In myInterDyMFoam.C: Code:
// global variables Foam::point g_Centre; // updated in myRestraint.C ... while (runTime.run()) { #include "readControls.H" #include "alphaCourantNo.H" #include "CourantNo.H" #include "setDeltaT.H" runTime++; ... Info << nl << nl << "> Running myInterDyMFoam" << endl; Info<< "Main: centre = " << g_Centre << endl; .... Code:
g_Centre = motion.centreOfRotation(); Code:
extern Foam::point g_Centre; Hope it helps Jean-Michel |
|
April 11, 2015, 05:56 |
|
#13 | |
Senior Member
Join Date: Jul 2011
Posts: 120
Rep Power: 15 |
Quote:
Code:
error: storage class specified for g_Centre |
||
April 14, 2015, 19:28 |
Custom solver interDyMFoam : how to read the centreOfRotation ?
|
#14 |
Member
Jean-Michel FONTAINE
Join Date: Aug 2009
Location: Orleans - France
Posts: 55
Rep Power: 17 |
Hi
Did you solve your 'error: storage class specified' ? The declaration is just as written : Code:
extern Foam::point g_Centre; Best wishes Jean-Michel |
|
April 15, 2015, 00:35 |
|
#15 |
Senior Member
Join Date: Jul 2011
Posts: 120
Rep Power: 15 |
I read that extern cannot be declared within the class, do tell me if otherwise. Declaring at the top outside the class compiles fine but didnt work when running with an error saying that solver table is empty.
|
|
Tags |
custom solver, interdymfoam, sixdofrigidbodymotion |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Can't get data from OpenFoam to external solver using externalCoupled | perry | OpenFOAM Running, Solving & CFD | 4 | May 26, 2014 09:09 |
Different errors when linking custom library via solver vs controlDict | chrisb2244 | OpenFOAM Programming & Development | 0 | February 21, 2014 04:12 |
Divergence problem | Smaras | FLUENT | 13 | February 21, 2013 06:03 |
CFX 5.5 | Roued | CFX | 1 | October 2, 2001 17:49 |
Setting a B.C using UserFortran in 4.3 | tokai | CFX | 10 | July 17, 2001 17:25 |