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

Read a field at different times

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 8, 2015, 05:02
Default Read a field at different times
  #1
Senior Member
 
Gerhard Holzinger
Join Date: Feb 2012
Location: Austria
Posts: 339
Rep Power: 28
GerhardHolzinger will become famous soon enoughGerhardHolzinger will become famous soon enough
Hi,

I want to create a post-processing utility, which traverses all time steps and compares the data with the data of all other time steps. So I end up with two nested loops traversing all time steps.

So, in pseudo code, it looks like this:

Code:
    // go over all time steps
    forAll(timeDirs, timeI)
    {
        runTime.setTime(timeDirs[timeI], timeI);
        
        // go over all time steps
        forAll(timeDirs, timeJ)
        {
            secTime.setTime(timeDirs[timeJ], timeJ);
            
            if (timeI == timeJ)
            {
                // easy
                recurrenceMatrixAlpha[timeI][timeJ] = 1;
            }
            else
            {
                // do stuff
            }
        }
    }
In the "// do stuff" section, I read the fields at the two different times. Right now, I call the constructor, like this:

Code:
volScalarField alpha1
(
    IOobject
    (
        "alpha.air",
        runTime.timeName(),
        mesh,
        IOobject::MUST_READ,
        IOobject::NO_WRITE
    ),
    mesh
);
volScalarField alpha2
(
    IOobject
    (
        "alpha.air",
        secTime.timeName(),
        mesh,
        IOobject::MUST_READ,
        IOobject::NO_WRITE
    ),
    mesh
);

I assume, that this might be done faster.

Is there a way to just read the field at the current time, like read()?
GerhardHolzinger is offline   Reply With Quote

Old   May 28, 2019, 09:18
Default solved yet?
  #2
Member
 
Join Date: Sep 2013
Posts: 46
Rep Power: 12
ma-tri-x is on a distinguished road
Hi Gerhard,


did you solve this already? I'm also interested...


best regards,
Shir


---- edit 2019-06-03:
seems to be the only way.

Last edited by ma-tri-x; June 3, 2019 at 09:10. Reason: solution
ma-tri-x is offline   Reply With Quote

Old   May 29, 2019, 07:26
Default
  #3
Senior Member
 
Gerhard Holzinger
Join Date: Feb 2012
Location: Austria
Posts: 339
Rep Power: 28
GerhardHolzinger will become famous soon enoughGerhardHolzinger will become famous soon enough
As of now, there are two ways to deal with this problem:
  • Either, we read a pair of fields for each combination of times
  • Or, we read the fields at all times, and then compare each combination of times


So,we can choose between
  • Reading a lot
  • Using a lot of memory


I ended up implementing the second variant.
GerhardHolzinger is offline   Reply With Quote

Old   June 3, 2019, 04:50
Default
  #4
Member
 
Fabien Robaux
Join Date: Oct 2016
Posts: 51
Rep Power: 9
frobaux is on a distinguished road
I'm quite new to OpenFoam, so maybe there is a better answer but if you know the time you need to read, you can convert into a word with the right precision using the runTime.timeName(scalar time) function.


For example, in my solver there is:

Code:
word cTime(runTime.timeName(currentTime[i].value()));

pointScalarField potPhi1
        (
            IOobject
            (
                "Phi",
                cTime,
                externalPhiRegions[i],
                IOobject::MUST_READ,
                IOobject::NO_WRITE
            ),
            pMeshes[i]
        );
frobaux is offline   Reply With Quote

Old   June 3, 2019, 09:18
Default Code for writeAlpha2
  #5
Member
 
Join Date: Sep 2013
Posts: 46
Rep Power: 12
ma-tri-x is on a distinguished road
Hi everyone,


I'd like to share my successful code for writing int_V(alpha2)dV = "volume of gas phase" to postProcessing/volumeIntegrate_volumeIntegral/0/alpha2.
It's written for foam-extend-4.0.



Can also be used for postProcessing of a parallel case via e.g.

mpirun -np $threads writeAlpha2 -parallel


Install:

extract tar.gz to
$WM_PROJECT_DIR/applications/utilities/postProcessing/miscellaneous/
and cd there and do "wmake".
Attached Files
File Type: gz writeAlpha2.tar.gz (1.6 KB, 21 views)
ma-tri-x 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
Foam::error::PrintStack almir OpenFOAM Running, Solving & CFD 91 December 21, 2022 04:50
problems after decomposing for running alessio.nz OpenFOAM 7 March 5, 2021 04:49
creating an internal field? maybee OpenFOAM Programming & Development 2 February 4, 2021 17:15
Starting field averaging using libFunctionObject after certain time eelcovv OpenFOAM Programming & Development 25 December 7, 2015 22:28
Jobs are exited simanoj FLUENT 0 June 20, 2013 05:36


All times are GMT -4. The time now is 05:45.