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

reading in a field into fvOptions with type: scalarCodedSource

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes
  • 1 Post By Ali Blues
  • 1 Post By JackW

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 6, 2016, 12:40
Default reading in a field into fvOptions with type: scalarCodedSource
  #1
Member
 
Join Date: Jun 2015
Posts: 30
Rep Power: 10
Ali Blues is on a distinguished road
Hi,
I'm trying to add an explicit source term (Sp) to the scalarTransportFoam, say for the field T. The source Term involves the product of T with another volScalarField object, lets call it E, which actually remains constant through the simulation. I'm trying to use the type scalarCodedSource in fvOptions as in https://github.com/OpenFOAM/OpenFOAM.../CodedSource.H


Since I'm using an explicit source term, T.oldTime() is used as an estimate.
For E, since it remains constant during the simulations, I thought of putting it in the constant directory and read it from there, and that's where I'm having getting difficulties. Here is the code:


Code:
energySource 
     { 
         type            scalarCodedSource; 
         active          yes; 
         scalarCodedSourceCoeffs 
         { 
             selectionMode   all; 
             fieldNames      (T); 
             redirectType    sourceTime; 
  
             codeInclude 
             #{ 
             #}; 
  
             codeCorrect 
             #{ 
             #}; 
  
             codeAddSup 
             #{ 
                 const Time& time = mesh().time();             
                 const scalarField& V = mesh_.V(); 
  
                const volScalarField& Temp = mesh_.lookupObject<volScalarField>("T"); 

                volScalarField E  
             (  
             IOobject  
             (  
                 "E",  
                 runTime.constant(),  
                 mesh_,  
                 IOobject::MUST_READ,  
                 IOobject::NO_WRITE  
             ),  
             mesh_  
             ); 
                 
             scalarField& heSource = eqn.source(); 
             heSource -=E*Temp.oldTime()*V;           
  
             #}; 
  
             codeSetValue 
             #{                
             #}; 
              
             code 
             #{ 
                 $codeInclude 
                 $codeCorrect 
                 $codeAddSup 
                 $codeSetValue 
             #}; 

         } 
         sourceTimeCoeffs 
         { 
             
         } 
     }
Q1) I get the following error: ‘runTime’ was not declared in this scope. So I appreciate any suggestions on how to fix this?
Q2) Following the link for the CodedSource.H, I was wondering why can I interchangeably use mesh().time() and mesh_.time() ?

Thanks,
Ali
Zhiheng Wang likes this.
Ali Blues is offline   Reply With Quote

Old   June 7, 2016, 21:19
Default
  #2
Member
 
Jack
Join Date: Aug 2012
Posts: 47
Rep Power: 13
JackW is on a distinguished road
add
Code:
const Time& time = mesh().time();
then replace
Code:
runTime.timeName()
with
Code:
time.timeName()
As for your second question, mesh_ is declared in the compilation. mesh() is a function that returns the same object.
Zhiheng Wang likes this.
JackW is offline   Reply With Quote

Old   June 8, 2016, 05:53
Default
  #3
Member
 
Join Date: Jun 2015
Posts: 30
Rep Power: 10
Ali Blues is on a distinguished road
Thanks Jack for the reply.
As I noted, field E remains constant during the simulations, and it is computed prior to running the scalarTransportFoam solver. So I prefer to read it from a different path say the constant/ directory.
Giving time.timeName() as path would only work for the first time step if I include the field E in the 0/ directory. but for the later time steps in would give error since field E is non-existent.

Best
Ali
Ali Blues is offline   Reply With Quote

Old   June 10, 2016, 05:11
Default
  #4
Member
 
Join Date: Jun 2015
Posts: 30
Rep Power: 10
Ali Blues is on a distinguished road
just realized time is actually of object Time. So accessing the constant directory is possible via time.constant(). So reading field E is as follows:


Code:
volScalarField E                
(
          IOobject                
          ( 
            "E", 
            time.constant(),                     
            mesh_,                    
            IOobject::MUST_READ,                    
            IOobject::NO_WRITE                
           ),                
          mesh_                
);
Ali Blues is offline   Reply With Quote

Old   June 7, 2018, 10:25
Default
  #5
New Member
 
JPeternel
Join Date: Oct 2014
Posts: 19
Rep Power: 11
jpeter3 is on a distinguished road
You need to get mesh and time objects, they do not exist in every class under this names.

Maybe try to Access them through velocity field, something like:

U_.mesh() instead of mesh

and

U_.time() instead of runTime
jpeter3 is offline   Reply With Quote

Reply

Tags
fvoptions, read in field


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
[OpenFOAM.org] compile error in dynamicMesh and thermophysicalModels libraries NickG OpenFOAM Installation 3 December 30, 2019 00:21
time step continuity problem in VAWT simulation lpz_michele OpenFOAM Running, Solving & CFD 5 February 22, 2018 19:50
Time step continuity error lpz_michele OpenFOAM Running, Solving & CFD 0 October 12, 2015 06:05
''unknown radialModelType type Gidaspow'' PROBLEM WITH THE BED TUTORIAL AndoniBM OpenFOAM Running, Solving & CFD 2 March 25, 2015 18:44
Problem in running ICEM grid in Openfoam Tarak OpenFOAM 6 September 9, 2011 17:51


All times are GMT -4. The time now is 09:32.