CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

Copy a turbulent field and correct it using fvOptions

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 18, 2021, 02:42
Default Copy a turbulent field and correct it using fvOptions
  #1
Senior Member
 
Agustín Villa
Join Date: Apr 2013
Location: Alcorcón
Posts: 313
Rep Power: 15
agustinvo is on a distinguished road
Hello,


during my simulations I have to add an extra term in the Reynolds stress tensor R. This new term is only applicable when using eddy viscosity models, so I was planning to add it using the fvOptions.correct() function to enable this modification whenever is needed.


As far as I found, I can import R in my code using:
Code:
const volSymmTensorField& R = turbModel.R();
but obviously later on I have to correct it, therefore I can't call it using const. How can I copy this R field and apply on it an fvOptions properly?.


Regards,
Agustín
agustinvo is offline   Reply With Quote

Old   February 18, 2021, 16:00
Default
  #2
HPE
Senior Member
 
HPE's Avatar
 
Herpes Free Engineer
Join Date: Sep 2019
Location: The Home Under The Ground with the Lost Boys
Posts: 932
Rep Power: 12
HPE is on a distinguished road
Out of my head:

tmp<volSymmTensorField> tR = turbModel.R();
auto& R = tR.ref();

There might be something similar in one of those fvOptions: link. Have a look, please.
HPE is offline   Reply With Quote

Old   February 19, 2021, 07:13
Default
  #3
Senior Member
 
Agustín Villa
Join Date: Apr 2013
Location: Alcorcón
Posts: 313
Rep Power: 15
agustinvo is on a distinguished road
Thanks! Now it works.


EDIT: well, it works as far as the turbulence models belongs to the eddyViscosity class. If I try to use a Reynolds stress model, I get the next error message:




Code:
Attempt to acquire non-const reference to const object from a tmp<N4Foam14GeometricFieldINS_10SymmTensorIdEENS_12fvPatchFieldENS_7volMeshEEE> 

    From function T& Foam::tmp<T>::ref() const [with T = Foam::GeometricField<Foam::SymmTensor<double>, Foam::fvPatchField, Foam::volMesh>] 
    in file /home/user/OpenFOAM/OpenFOAM-7/src/OpenFOAM/lnInclude/tmpI.H at line 187.
I suppose it happens because R is now a model variable and not a model output. The code should be able to take the R value (it doesn't matter its origin) and apply, if needed, the fvOption. I will check this again.




EDIT2: I managed to implement this feature. The Reynolds stress needed to be called like:
Code:
tmp<volSymmTensorField> tR = turbModel.R();
volSymmTensorField& R = const_cast<volSymmTensorField&>(tR());
and it runs now. The reference couldn't be constant, otherwise you cannot modify the R variable. Using this code I'm able to modify the R field if needed.

Last edited by agustinvo; February 19, 2021 at 09:46.
agustinvo is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Turbulence injection via fvOptions: addSup, constrain, or correct? pbachant OpenFOAM Programming & Development 1 May 22, 2020 22:48
Turbulent Dissipation Rate Field Function osulax STAR-CCM+ 1 April 5, 2017 15:15
rhoSimplecFoam: error in Forces output (correct pressure field) WhiteW OpenFOAM Running, Solving & CFD 1 December 8, 2015 13:02
Moving mesh Niklas Wikstrom (Wikstrom) OpenFOAM Running, Solving & CFD 122 June 15, 2014 06:20
Is this understanding of turbulence models correct? 3kha Main CFD Forum 3 January 31, 2011 21:31


All times are GMT -4. The time now is 04:49.