|
[Sponsors] |
Access the Time object in sixDoFRigidBodyMotionRestraints |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
January 19, 2016, 13:31 |
Access the Time object in sixDoFRigidBodyMotionRestraints
|
#1 |
Member
Yuanchuan Liu
Join Date: Oct 2012
Posts: 31
Rep Power: 14 |
Dear Foamers,
I have been trying to implement a new restraint type for the sixDoFRigidBodyMotion class and need to access the Time object for the current time value as well as the time step size deltaT. Does anybody know how to do that in OpenFOAM-2.4.x? Thanks in advance. Best wishes, Yuanchuan Liu |
|
January 20, 2016, 03:51 |
|
#2 |
New Member
Join Date: Dec 2015
Posts: 24
Rep Power: 11 |
I believe it might be as simple as:
Code:
const Time &runTime= db().time() |
|
January 20, 2016, 07:36 |
|
#3 |
Member
Yuanchuan Liu
Join Date: Oct 2012
Posts: 31
Rep Power: 14 |
Hi, thank you for your reply.
Unfortunately, inserting the line you suggested to my code results in an error message: error: ‘db’ was not declared in this scope It seems I do not have access to db as well. Cheers. |
|
January 20, 2016, 08:57 |
|
#4 |
New Member
Join Date: Dec 2015
Posts: 24
Rep Power: 11 |
Code:
const objectRegistry & db () const IOObject belongs to the inheritance tree of sixDoFRigidBodyMotionSolver so it should be accessible whithin the scope of this class. I assumed that you were modifying this class. Sorry if I missunderstood your question. If you are working in the "application" scope, runTime should be directly accessible if you created it: Code:
#include "createTime.H" |
|
January 20, 2016, 09:00 |
|
#5 |
Senior Member
|
Hi,
If you take a look at documentation (http://foam.sourceforge.net/docs/cpp/a02312.html), you find, sixDoFRigidBodyMotion class has nothing connecting it to object registry (where you usually find Time object). It has general geometric fields, sixDoFRigidBodyMotionState, and lists of sixDoFRigidBodyMotionRestraint and sixDoFRigidBodyMotionConstrain. None of those classes has access to object registry. So, I guess, the problem, as it is described in the first post, has no solution. Yet, you can describe in more details, what you are trying to achieve, maybe there is a solution (for example you can get object registry as a parameter or something else). |
|
January 20, 2016, 09:49 |
|
#6 |
Member
Yuanchuan Liu
Join Date: Oct 2012
Posts: 31
Rep Power: 14 |
Hi metalfox and alexeym,
Thank you both so much for your time. I think it might be best if I can describe what I want to achieve in more details. Bascially, I created a new restraint class for the sixDoFRigidBodyMotion class. I just copied the built-in linearSpring restraint class and made some modifications based on it. The new restraint class is designed to employ a simple model to simulate mooring lines, where I need to know the time step size deltaT for force calculation and also the current time value to save the line geometry to VTK files with the current time name only to distinguish each file with others. alexeym was right to the point. What makes it difficult is that None of those classes has access to object registry so I am unable to reference it in the way mentioned by metalfox. The current solution I adopted is to modify the sixDoFRigidBodyMotion class by adding some functions to get the values I need from its caller and also return the values to other classes which need them, as the sixDoFRigidBodyMotionRestraints class does not interact with other classes but the sixDoFRigidBodyMotion class. The method mentioned by alexeym might be a better solution as it only involves a single modification to the sixDoFRigidBodyMotion class so I do not have to edit it again if next time another variable related to the object registry is needed. Thanks to your guys very much. Now I know it is not possible if I do not want to edit the sixDoFRigidBodyMotion class. Best wishes, Yuanchuan Liu |
|
January 20, 2016, 11:37 |
|
#7 |
New Member
Join Date: Dec 2015
Posts: 24
Rep Power: 11 |
I apologize because the OpenFOAM objects I'm familiar with usually inherit in some way from IOObject.
However, I believe that there is another workaround that would require no modification to sixDoFRigidBodyMotion. Wouldn't: Code:
extern Time runTime; It's not very elegant but I think it migth work (though it may require the solver to be linked with -rdynamic, not sure...). Please let me know... |
|
January 20, 2016, 12:37 |
|
#8 |
Member
Yuanchuan Liu
Join Date: Oct 2012
Posts: 31
Rep Power: 14 |
Hi metalfox,
I am very grateful for the help you provided. I am not very familiar with the extern keyword in C++. After a quick search, it seems to me that by defining a variable extern, you are telling the compiler that this variable has been defined somewhere else in another file so you can use it here. I tried to insert the code into my cpp file and the library compiled successfully. However, when I tried to run my solver, there was an error saying the sixDoFRigidBodyMotionRestraint type is unknown. Maybe it has something to do with the linkage to the solver you mentioned? Let us use a simple example to illustrate the problem. Say the solver I am going to use is mooringTest which is compiled from the source file mooringTest.C where I define the sixDoFRigidBodyMotion variable. The restraint class I inherited from the sixDoFRigidBodyMotionRestraints base class is called mooringLine which has a header file mooringLine.H and mooringLine.C. The mooringLine class is compiled to the libudfSixDoFRigidBodyMotionRestraints.so library. So when I want to use this restraint model with the mooringTest solver, I include the library in the case controlDict file. If I want to use the method you suggested, should I add the Code:
extern Time runTime; Thank you. |
|
January 20, 2016, 13:33 |
|
#9 |
New Member
Join Date: Dec 2015
Posts: 24
Rep Power: 11 |
I've made a quick test, and I convinced myself that my solution should work:
File libfoo.cpp: Code:
#include <iostream> extern int foo; void func() { std::cout << "foo = " << foo << std::endl; } Code:
g++ -fPIC -shared libfoo.cpp -o libfoo.so Code:
void func(); int foo = 666; int main() { func(); } Code:
g++ main.cpp -o main -L. -lfoo Code:
./main foo = 666 |
|
January 20, 2016, 15:36 |
|
#10 |
Member
Yuanchuan Liu
Join Date: Oct 2012
Posts: 31
Rep Power: 14 |
Hmm, things go a bit strange here.
I tried the test program you posted. For the libfoo.cpp: Code:
#include <iostream> extern int foo; void func() { std::cout << "foo = " << foo << std::endl; } Code:
g++ -fPIC -shared libfoo.cpp -o libfoo.so Code:
void func(); int foo = 666; int main() { func(); } Code:
g++ main.cpp -o main -L. -lfoo Code:
./main Code:
./main: error while loading shared libraries: libfoo.so: cannot open shared object file: No such file or directory Code:
int foo = 666; Code:
./libfoo.so: undefined reference to `foo' |
|
January 21, 2016, 04:20 |
|
#11 |
New Member
Join Date: Dec 2015
Posts: 24
Rep Power: 11 |
Dear SailorLiu
The executable does not find the library because it is not in the library path (LD_LIBRARY_PATH). However, your are right. It would only work if runTime were in the global scope, which is not because argv need to be parsed for runTime to be constructed. Furthermore, I was curious whether global variables can be accessed through shared libraries in the OpenFOAM framework. So, I created a Time object in the global scope of icoFoam and tried to access it through a custom bc. I got: Code:
dlopen error : boundaryCondition/oddBC.so: undefined symbol: runTime I'm sorry. |
|
January 21, 2016, 08:50 |
|
#12 |
Member
Yuanchuan Liu
Join Date: Oct 2012
Posts: 31
Rep Power: 14 |
Dear metalfox,
Please don't be sorry. I really appreciate the time and effort you devoted to my problem. But at least I can still solve it although not in an elegant way by cracking the sixDoFRigidBodyMotion class. Thank you very much! Hope everything goes well with you. Cheers. Yuanchuan Liu |
|
January 15, 2017, 17:41 |
|
#13 |
New Member
Join Date: Dec 2013
Posts: 11
Rep Power: 13 |
Hey SailorLiu.
I've stumbled upon you post while looking for the same kind of info. I've then played around a little bit with some of the existing libraries where time is actually used (e.g. forces in function objects) and managed to access the time in the library I'm trying to code. "Simply" add the objectregistry in the constructors of your source file and to the class declaration in your header file and then access the time via "obr_.time().value()". Let me know if you still have problems. Hope this helps, Rick |
|
September 26, 2017, 10:48 |
Mooring line
|
#14 |
New Member
Xiaokang Deng
Join Date: Sep 2017
Posts: 9
Rep Power: 9 |
Hi SailorLiu,
Do you want to add the mooring line in sixDoFRigidBodyMotion? Are you successful? I am studying how to add the mooring line in sixDoFRigidBodyMotion, but I am a newer. Can you share me some materials or examples. I think they will be very helpful to me. Thank you in advance. Xiaokang Deng |
|
March 3, 2019, 04:17 |
|
#15 | |||||
Member
Paul Palladium
Join Date: Jan 2016
Posts: 94
Rep Power: 10 |
Quote:
Dear Rick, Could you give a little bit more detail about your solution ? Does it work within a restrain function ?My problem is the following : I would like to use the function forces in a custom restraint : Quote:
The problem is I need to access to db() or mesh for the function forces. alexeym says that is it not possible to access mesh because mesh is carried by the registry which is not accessible from the rigidBodyDynamic class (or sixDoFRigidBodyMotion). Can you tell me how to add the objectregistry in the constructors of your source file ? In my case : Quote:
Quote:
********************** I have to mention that I tried to add : Quote:
By this way the compilation works but when I tried to compile interDyMFoam (including the library created with my custom restraint) I get an error message : /home/paul/OpenFOAM/paul-v1712/platforms/linux64GccDPInt32Opt/lib/libcustomRestraint.so : undefined reference to « Foam::RBD::restraints::customRestraint::db() const » collect2: error: ld returned 1 exit status /opt/OpenFOAM-v1712/wmake/makefiles/general:1 I know that there is a possibilty to extract forces from a txt.file (using IOstream) created by the solver by calling functionObjects::forces within each PIMPLE loop but I would like to find a more "elegant" way. Any help will be amazing ! Last edited by Fauster; March 4, 2019 at 09:08. Reason: Add : IOstream possibilty |
||||||
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Elastic or Plastic Deformations in OpenFOAM | NickolasPl | OpenFOAM Pre-Processing | 36 | September 23, 2023 09:22 |
Floating point exception error | lpz_michele | OpenFOAM Running, Solving & CFD | 53 | October 19, 2015 03:50 |
How to write k and epsilon before the abnormal end | xiuying | OpenFOAM Running, Solving & CFD | 8 | August 27, 2013 16:33 |
dynamic Mesh is faster than MRF???? | sharonyue | OpenFOAM Running, Solving & CFD | 14 | August 26, 2013 08:47 |
plot over time | fferroni | OpenFOAM Post-Processing | 7 | June 8, 2012 08:56 |