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

OpenFOAM construct for conditional field modification

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 23, 2019, 12:12
Default OpenFOAM construct for conditional field modification
  #1
Senior Member
 
Joachim Herb
Join Date: Sep 2010
Posts: 650
Rep Power: 22
jherb is on a distinguished road
I would like to ask if there is a standard OpenFOAM construction/macro/??? to write the following algorithm in a more concise way:
Code:
forAll(TPatch, faceI)
{
    if (TPatch[faceI] > whatever)
    {
         xPatch[faceI] = get_something(TPatch[faceI] );
    }
     else
    {
         xPatch[faceI] = get_something_else(TPatch[faceI]);
    }
}
something like:
Code:
xPatch = (TPach > watever ? get_something(TPatch) : get_something_else(TPatch))
jherb is offline   Reply With Quote

Old   May 25, 2019, 13:34
Default
  #2
Senior Member
 
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 616
Rep Power: 16
mAlletto will become famous soon enough
I do not know precisely, but when construction the pressure contribution in the energy equation of of compressible flow it is done something similar:


Code:
    fvScalarMatrix EEqn     (         fvm::ddt(rho, he) + fvm::div(phi, he)   

    + fvc::ddt(rho, K) + fvc::div(phi, K)     

  + (             he.name() == "e"           ? fvc::div             (                 fvc::absolute(phi/fvc::interpolate(rho), U),                 p,                 "div(phiv,p)"             )           : -dpdt         )     

  - fvm::laplacian(turbulence.alphaEff(), he)  

   ==         rho*(U&g)       + rad.Sh(thermo, he)       + Qdot       + fvOptions(rho, he)     );
mAlletto is offline   Reply With Quote

Old   May 25, 2019, 18:04
Default
  #3
Senior Member
 
Joachim Herb
Join Date: Sep 2010
Posts: 650
Rep Power: 22
jherb is on a distinguished road
Thank you for your answer. But this is only testing the name of the energy field and selected on of two possible ways for the calculation.



What I look for is a way to calcuate a field differently for each cell based on a condition.
jherb is offline   Reply With Quote

Old   May 27, 2019, 08:06
Default
  #4
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,938
Rep Power: 39
alexeym has a spectacular aura aboutalexeym has a spectacular aura about
Send a message via Skype™ to alexeym
Hi,

@jherb

There are neg and pos functions for fields, so your code could look like:

Code:
xPatch = pos(TPach - watever)*get_something(TPatch) + neg(TPach - watever)*get_something_else(TPatch))
alexeym is offline   Reply With Quote

Old   May 30, 2019, 08:38
Default
  #5
Senior Member
 
Joachim Herb
Join Date: Sep 2010
Posts: 650
Rep Power: 22
jherb is on a distinguished road
@alexeym: Thank you for your answer. This will work (if using neg0 to also catch all cells with value 0). But it would require to two both calculations/function calls for each cell. Also I am not sure it this would not require some temporary fields. So for large meshes this might be significantly slower than a cell-by-cell decision.
jherb is offline   Reply With Quote

Old   May 30, 2019, 18:43
Default
  #6
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,938
Rep Power: 39
alexeym has a spectacular aura aboutalexeym has a spectacular aura about
Send a message via Skype™ to alexeym
@jherb, well, surely it won't be faster (for any size of the mesh), since it requires creation of temporary fields and (at least) double evaluation of TPach - watever. Yet there is "vectorisation" mantra. Which is usually supported (or imposed) by certain prof.

Also your code is a candidate for either transforming into macro or a template.
alexeym 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
[Other] dynamicTopoFVMesh and pointDisplacement RandomUser OpenFOAM Meshing & Mesh Conversion 6 April 26, 2018 08:30
How to contribute to the community of OpenFOAM users and to the OpenFOAM technology wyldckat OpenFOAM 17 November 10, 2017 16:54
Suggestion for a new sub-forum at OpenFOAM's Forum wyldckat Site Help, Feedback & Discussions 20 October 28, 2014 10:04
Moving mesh Niklas Wikstrom (Wikstrom) OpenFOAM Running, Solving & CFD 122 June 15, 2014 07:20
Problem with rhoSimpleFoam matteo_gautero OpenFOAM Running, Solving & CFD 0 February 28, 2008 07:51


All times are GMT -4. The time now is 02:42.