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

get all cells x>0 for postProcessing with Solver

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes
  • 2 Post By olesen

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 10, 2022, 11:31
Default get all cells x>0 for postProcessing with Solver
  #1
New Member
 
Sebastian
Join Date: Apr 2019
Location: Germany
Posts: 12
Rep Power: 7
aeroBassti is on a distinguished road
Hi there,



Unfortunately, I am an early beginner with programming in OpenFOAM.

I would like to get a for each time step a value (here U) averaged over all cells in the (inner) mesh that are at positions x>0 (or other values). Is it possible to split the field into two areas: before (x<0) and after the object (x>0) and output each value via

Quote:
"Info << UposX.weightedAverage(mesh.V()).value() << endl;
Info << UnegX.weightedAverage(mesh.V()).value() << endl;"
?
aeroBassti is offline   Reply With Quote

Old   February 12, 2022, 06:07
Default
  #2
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,686
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
For this particular requirement do it yourself will be the best approach. Build two quantities during the loop, followed by any reductions. For example,
Code:
scalar volNeg = 0, volPos = 0;
for (label celli=0; celli < mesh.nCells(); ++celli) 
{
    const scalar vol = mesh.V()[celli];
    if (mesh.C()[celli].x() >= 0)
    {
        volPos += vol;
    }
    else
    {
        volNeg += vol;
    } 
}
reduce(volNeg, sumOp<scalar>());
reduce(volPos, sumOp<scalar>());
If you are going to do this a lot (or for several different fields) you can also build a labelList with the cell ids where x>=0 and another for the others. Then use a UIndirectList for walking the fields.
aeroBassti and joshwilliams like this.

Last edited by olesen; February 12, 2022 at 11:15.
olesen 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
SimpleFoam & Theater jipai OpenFOAM Running, Solving & CFD 3 June 18, 2019 10:11
Problem with divergence TDK FLUENT 13 December 14, 2018 06:00
fluent divergence for no reason sufjanst FLUENT 2 March 23, 2016 16:08
killed "snappyHexMesh" parkh32 OpenFOAM Pre-Processing 2 April 8, 2012 17:12
physical boundary error!! kris Siemens 2 August 3, 2005 00:32


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