|
[Sponsors] |
January 31, 2022, 09:22 |
Obtaining forces/moments during runtime
|
#1 |
New Member
Adrian del Ser
Join Date: Oct 2021
Posts: 15
Rep Power: 5 |
Hi,
Is there a way to obtain forces and moments on an object in a simulation directly in the solver (eg myCustomSolver.C). I know I can generate them using ForceCoeffs and output them in a .dat file or a log file, but I would like to obtain the most recent moment/force as a variable in myCustomSolver.C during runtime directly (instead of trying to read it from the log/dat files, which might be slower. Is this possible? Thanks. |
|
February 1, 2022, 18:19 |
|
#2 |
Super Moderator
Tobias Holzmann
Join Date: Oct 2010
Location: Bad Wörishofen
Posts: 2,711
Blog Entries: 6
Rep Power: 52 |
The latest developments of OpenFOAM v2112 has to feature to sent the data of any FO to other FO. Hence, it should be stored in the db() and hence, you should be able to access it in your own solver directly without reading it from any file.
__________________
Keep foaming, Tobias Holzmann |
|
February 2, 2022, 18:12 |
|
#3 | |
New Member
Adrian del Ser
Join Date: Oct 2021
Posts: 15
Rep Power: 5 |
Quote:
Hi Tobi, This is good to know! I am still relatively new to openfoam, how would one practically access this value? I am unfamiliar with db() (for now). Say I wish to access the moment coefficient of the patch "obstacle" along the axis (0 0 1) as one might define in this example forceCoeffs file: Code:
forceCoeffs1 { type forceCoeffs; libs ("libforces.so"); writeControl timeStep; timeInterval 20; log yes; patches (obstacle); rho rhoInf; //Indicates Incompressible flow rhoInf; //irrelevent for inc flow liftDir (0 1 0); dragDir (1 0 0); CofR (0 0 0); pitchAxis (0 0 1); magUInf 7.5e-4; lRef 4; //diameter Aref 8; //projected area } Adrian Last edited by adrian.delser; February 2, 2022 at 22:37. |
||
February 3, 2022, 18:31 |
|
#4 |
Super Moderator
Tobias Holzmann
Join Date: Oct 2010
Location: Bad Wörishofen
Posts: 2,711
Blog Entries: 6
Rep Power: 52 |
https://www.openfoam.com/documentati...ce.html#l00234
Here we have the setResults() functionality which stores (need to check further) the data in the database. So what we might need is: Code:
const scalar cd = this->db().lookupObject<scalar>("Cd"); However, if that one is not stored in the db() you should get an error and a list of objects which are stored there . Probably, we first need to access the FO itself and then we have access to the values.
__________________
Keep foaming, Tobias Holzmann |
|
February 4, 2022, 05:30 |
|
#5 |
Super Moderator
Tobias Holzmann
Join Date: Oct 2010
Location: Bad Wörishofen
Posts: 2,711
Blog Entries: 6
Rep Power: 52 |
I got the hint from the developers, that the results are stored in the functionObjectProperties which is owned by Time. So you should have access in that way.
__________________
Keep foaming, Tobias Holzmann |
|
February 7, 2022, 10:45 |
|
#6 | |
New Member
Adrian del Ser
Join Date: Oct 2021
Posts: 15
Rep Power: 5 |
Quote:
Excellent, thank you, I will be testing this shortly. I need to have boundary conditions that depend on certain runtime field quantities (the moment potentially being one of them). This would be very useful for runtime control systems (such as simulating a 2d "rocket" landing and trying to keep itself upright with either small jets or fins like the SpaceX Falcon 9, but in OpenFOAM. codedFixedValue boundary conditions come to mind but I'll have to see how they work. |
||
April 7, 2022, 03:34 |
|
#7 |
Senior Member
TWB
Join Date: Mar 2009
Posts: 414
Rep Power: 19 |
Hi everyone,
I also need to obtain the forces to modify my custom inlet boundary condition using codedFixedValue. Currently, I need to filter the force output file, and then read in to get the value. It works but it's slow and ugly! I tried to use the mtd suggested by Tobi: Code:
const scalar cd = this->db().lookupObject<scalar>("Cd"); Code:
Creating new library in "dynamicCode/u_6dof_change/platforms/linux64GccDPInt32Opt/lib/libu_6dof_change_a2f851b6065ae560f5bda633cf2c3064fa5c7783.so" Invoking wmake libso /home/user/Woodstock_OF_tmp/3D/WS_full_S0R45_PV_5e-4_dihedral_overset_sym_tb_0.9M_6dof_x/dynamicCode/u_6dof_change wmake libso /home/user/Woodstock_OF_tmp/3D/WS_full_S0R45_PV_5e-4_dihedral_overset_sym_tb_0.9M_6dof_x/dynamicCode/u_6dof_change ln: ./lnInclude dep: fixedValueFvPatchFieldTemplate.C Ctoo: fixedValueFvPatchFieldTemplate.C In file included from /usr/lib/openfoam/openfoam2112/src/OpenFOAM/lnInclude/objectRegistry.H:571, from /usr/lib/openfoam/openfoam2112/src/OpenFOAM/lnInclude/polyMesh.H:47, from /usr/lib/openfoam/openfoam2112/src/finiteVolume/lnInclude/fvMesh.H:53, from /usr/lib/openfoam/openfoam2112/src/finiteVolume/lnInclude/fvPatchField.C:31, from /usr/lib/openfoam/openfoam2112/src/finiteVolume/lnInclude/fvPatchField.H:608, from /usr/lib/openfoam/openfoam2112/src/finiteVolume/lnInclude/fixedValueFvPatchField.H:59, from /usr/lib/openfoam/openfoam2112/src/finiteVolume/lnInclude/fixedValueFvPatchFields.H:31, from fixedValueFvPatchFieldTemplate.H:40, from fixedValueFvPatchFieldTemplate.C:29: /usr/lib/openfoam/openfoam2112/src/OpenFOAM/lnInclude/objectRegistryTemplates.C: In instantiation of ‘const Type& Foam::objectRegistry::lookupObject(const Foam::word&, bool) const [with Type = double]’: /home/user/Woodstock_OF_tmp/3D/WS_full_S0R45_PV_5e-4_dihedral_overset_sym_tb_0.9M_6dof_x/0/U.boundaryField.inlet:182:53: required from here /usr/lib/openfoam/openfoam2112/src/OpenFOAM/lnInclude/objectRegistryTemplates.C:443:27: error: cannot dynamic_cast ‘iter.Foam::HashTable<Foam::regIOobject*>::const_iterator::operator()()’ (of type ‘class Foam::regIOobject* const’) to type ‘const double*’ (target is not pointer or reference to class) 443 | const Type* ptr = dynamic_cast<const Type*>(iter()); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/lib/openfoam/openfoam2112/src/OpenFOAM/lnInclude/objectRegistryTemplates.C:454:37: error: ‘typeName’ is not a member of ‘double’ 454 | << ")\n expected a " << Type::typeName /usr/lib/openfoam/openfoam2112/src/OpenFOAM/lnInclude/objectRegistryTemplates.C:467:48: error: ‘typeName’ is not a member of ‘double’ 467 | << ")\n available objects of type " << Type::typeName make: *** [/usr/lib/openfoam/openfoam2112/wmake/rules/General/transform:35: Make/linux64GccDPInt32Opt/fixedValueFvPatchFieldTemplate.o] Error 1 --> FOAM FATAL IO ERROR: (openfoam-2112) Failed wmake "dynamicCode/u_6dof_change/platforms/linux64GccDPInt32Opt/lib/libu_6dof_change_a2f851b6065ae560f5bda633cf2c3064fa5c7783.so" file: 0/U.boundaryField.inlet at line 64 to 250. From void Foam::codedBase::createLibrary(Foam::dynamicCode&, const Foam::dynamicCodeContext&) const in file db/dynamicLibrary/codedBase/codedBase.C at line 240. FOAM exiting PS: Btw, I can access the deltaT using : Code:
delta_time = this->db().time().deltaTValue(); |
|
April 15, 2022, 22:00 |
|
#8 |
Senior Member
TWB
Join Date: Mar 2009
Posts: 414
Rep Power: 19 |
Hi,
I realised that I can get the force thru: Code:
const vector force = this->db().lookupObject<vector>("force"); However, when I run my case and I tried to print the force value: Code:
Info << "drag from force " << force[0] << endl; Code:
FOAM parallel run exiting [4] [13] [13] --> FOAM FATAL ERROR: (openfoam-2112) [13] failed lookup of force (objectRegistry region0) available objects of type vector: 0() [13] [13] [13] From const Type& Foam::objectRegistry::lookupObject(const Foam::word&, bool) const [with Type = Foam::Vector<double>] [13] in file /usr/lib/openfoam/openfoam2112/src/OpenFOAM/lnInclude/objectRegistryTemplates.C at line 463. Thanks. |
|
Tags |
forcecoeffs, moment coefficient, processing |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Duplicate entry alphaContactAngle in runtime selection table fvPatchField | Roesch | OpenFOAM Programming & Development | 2 | January 12, 2021 04:35 |
Probes/Sensors in runtime | gabitinho | OpenFOAM Post-Processing | 9 | August 14, 2015 13:55 |
wallGradU at runtime | kkpal | OpenFOAM Post-Processing | 6 | June 12, 2015 20:56 |
Problem in3D model processing | mebinitap | OpenFOAM | 2 | December 12, 2014 05:40 |
runTime out of scope in functionObject | Sune | OpenFOAM Programming & Development | 2 | September 26, 2012 03:11 |