![]() |
Access to protected Ubar_ in fvOption (Urgent Help)
Hi all,
I have a question about fvOption. I am using meanVelocityForce as the type of momentum source in my fvOption file. However, by looking the source file of this momentum type at OpenFOAM-5.x/src/fvOptions/sources/derived/meanVelocityForce, something seems hard to me. https://github.com/OpenFOAM/OpenFOAM...ityForce.C#L89 We have a Ubar_ vector as a protected value which is read from fvOption file. Due to its protected type, it cannot be used at the outside of its class. So can anybody help me to just print its value (Info) at each timestep of my solver. I think a solution is defining a public function at the class to print its value, and use this function at each time step in our solver coding (fvOptions.functionforUbar). But it has lots of c++ details. |
Dear mostanad,
As you said, the Ubar_ defined at class "meanVelocityForce" is read from "fvOptions" file. And it's just a user-defined fixed vector value which is not changed during the calculation. So if you want to use it in your solver, i think an easy way is to (1) define the same "Ubar" in your solver's dict file and read it in your code or (2) read 'fvOptions' in your solver's code to get the user-defined "Ubar" value. Timo |
Quote:
Thank you Dear Timo for your quick reply. The problem cannot be solved by these two methods. Yes, the Ubar_ is a user defined vector and by #include "createFvOptions.H" in my solver, the solver reads just once the fvOption file and gives the Ubar value to this vector. So it cannot be changed in different timestep. However, if I can define a function in meanVelocityForce.C (like constrain or correct functions), I report this value in every timestep or as my final goal, I can change its value(because I want to change Ubar_ based on some results in each timestep). So do you have any solution for that? Thanks, Mohammad |
Quote:
I have found something similar to my problem, but with no details!!! So still help me! https://www.cfd-online.com/Forums/op...-variable.html |
Dear Mohammad,
Okay, I get your point. I think it's possible to change the Ubar_ value on the fly. The idea is to pass a parameter to meanVelocityForce::correct(volVectorField& U) or meanVelocityForce::constrain. Say, (1)change the following function: Code:
void Foam::fv::meanVelocityForce::correct(volVectorField& U) Code:
void Foam::fv::meanVelocityForce::correct(volVectorField& U, vector& Ubar_New) Code:
Code:
This *correct* and *constrain* function is called in the UEqn.H. You can check pimpleFoam solver for more information and choose one by your own situation. Timo |
Quote:
|
Dear Mohammad,
Yes, this solution will introduce some inconvenience. It's much better to define a separate function to just set your desired Ubar value. I'll have a look at it when I finish my dinner. By the way, both solution need to define virtual functions in the *fvOptions* so that you can access it in your solver. Timo |
Quote:
1. create virtual functions in fvOption.[CH]: fvOptions/fvOptions/fvOption.H Code:
virtual void setUbar(vector& UbarTarget); Code:
void Foam::fv::option::setUbar(vector& UbarTarget) fvOptions/fvOptions/fvOpitonList.H Code:
Code:
void Foam::fv::optionList::setUbar(vector& UbarTarget) meanVelocityForce.H Code:
//- Set target ubar Code:
void Foam::fv::meanVelocityForce::setUbar Code:
vector UbarTarget(5.0,0.0,0.0); Timo |
Quote:
Code:
fvOptions.Uvalue(); Code:
virtual void Uvalue(); Code:
void Foam::fv::meanVelocityForce::Uvalue()//insert by Mo Code:
virtual void Uvalue(); Code:
void Foam::fv::option::Uvalue(){} Code:
void Uvalue()//insert by Mo Thank you, Mohammad |
Quote:
|
Haha, yes, we did the same thing at the same time.
I think you should pass a parameter in your Uvalue() function and modify Ubar_ in it, such that the Ubar_ will be changed every time you call fvOptions.Uvalue. Here is my test result using the code in my last post: Code:
Time = 0.200001 UbarTarget:(5 0 0) (36 0 0) Second step, Ubar is changed to 5 which is modified by setUbar(UbarTarget): UbarTarget:(5 0 0) (5 0 0) Timo |
Quote:
Dear Time, I followed all the steps you posted, but it is getting the following error in solver compilation: Code:
periodiccfdemSolverIB.C:(.text.startup+0x28a4): undefined reference to `Foam::fv::optionList::setUbar(Foam::Vector<double>&)' |
1 Attachment(s)
Quote:
Well, this is weird. I don't have OpenFOAM-5.x compiled on my computer, so I can't reproduce this error. I tested it under OpenFOAM-2.3./2.3x and it's okay. So I recommend you to check the code again because i don't know what's the difference between 2.3.x and 5.x. See the attachment of my case for more info. Timo |
I think this is because of this part:
Code:
this->operator[](i).setUbar(UbarTarget); Code:
option& source = this->operator[](i);; Thank you again. |
Quote:
Timo |
Quote:
Thanks Mohammad |
I'm not in my office so I can't sent you the code right now.
But it's very simple. My test solver is just the original pimpleFoam solver of OpenFOAM-2.3.1.I only add that two lines in the end of UEqn.H file. Timo |
Quote:
|
Finally, the modification suggested by Timo worked for me. I just recompiled all the src library again.
|
All times are GMT -4. The time now is 01:47. |