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

accessing 0 time directory in coded functionObject

Register Blogs Community New Posts Updated Threads Search

Like Tree4Likes
  • 4 Post By raumpolizei

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 21, 2018, 09:34
Question accessing 0 time directory in coded functionObject
  #1
Member
 
Join Date: Apr 2018
Location: UK
Posts: 78
Rep Power: 8
JM27 is on a distinguished road
Hi there,


I am hoping to get some help with coded function objects in openFoam.



I have written a function object to compute the radius of a bubble based on volume fraction alpha and cell volume as follows (compressibleInterFoam):



Code:
// section of coded to be executed, in controlDict

forAll(centers, I)   
            {
                        if (alpha[I] < th)         
                {

                    // TO COMPUTE RADIUS

                    // compute numerator, time-varying
                            sumNumerator   += (1-alpha[I])*(V[I]); // per time-step
                                                               
                 
                    // compute denominator, constant at t = 0
                          sumDenominator += (1-alpha[I])*(V[I]);     // CHANGE TO ACCESS VALUES AT TIME = 0 -- how?
        

                   // At each time-step
                    bracket        = pow(sumNumerator/sumDenominator, 1/3);    

                   

                    // compute Radius                
                    Radius         = Rstart*bracket;
               }
       }
However, I cannot seem to figure out how to access the properties at time directory 0.

The code compiles and runs but with the above setting the radius clearly stays constant for all time-directories.
Please help. Any advice will be greatly appreciated.



p.s. I know I can do something similar in swak4Foam but so far I have not managed to make this work for my current version (v5.0) and I want to try out some coding in OpenFOAM and c++ as an exercise (still a newbie).
JM27 is offline   Reply With Quote

Old   December 18, 2018, 11:06
Default
  #2
New Member
 
Francisco
Join Date: Sep 2018
Location: Portugal
Posts: 27
Rep Power: 8
ships26 is on a distinguished road
Hi! I'm also a newbie, so I'm not sure if this'll help, but have you tried to compile that function as a functionObject? That way it would available as postProcess utility (I think).

I haven't done this myself, yet, if it works, you can employ it at time 0 by stating
Code:
postProcess -func Nameofutility -time 0
in the console.


EDIT: Now that I'm checking, it's been a while since this was posted... Sorry if it qualifies as necroing!
ships26 is offline   Reply With Quote

Old   December 19, 2018, 13:20
Default Suggestion
  #3
Member
 
Join Date: Dec 2018
Location: Darmstadt, Germany
Posts: 87
Rep Power: 8
raumpolizei is on a distinguished road
Hey,
here is a suggestion how you could compute the volume of your bubble (or whatever you would like to calculate). Sometimes, I'm doing this myself in order to get some calculations done when the simulation is already over. The way is to write some postprocessing utility. Write a tool, wmake it and run it on your case. This can look like this:

bubbleVolume.C

Code:
#include "timeSelector.H"
#include "Time.H"
#include "fvMesh.H"
#include "volFields.H"
using namespace Foam;
int main(int argc, char *argv[])
{
timeselector::addOptions();
#include "setRootCase.H"
#include "createTime.H"
#include "createMesh.H"

// create a list of the times, from time directories given the time arguments 
// example: -time <ranges>  or -latestTime
instantList timeDirs = timeSelector::select0(runTime, args);

// loop over this list
forAll(timeDirs,timeI)
{
    runTime.setTime(timeDirs[timeI],timeI);
    mesh.readUpdate();
    // now get the fields you need for computation
     volScalarField fieldNeeded
     (
        IOobject
        (
              "fieldNeeded",
              runTime.timeName(),
              mesh,
              IOobject::MUST_READ,
              IOobject::NO_WRITE
        ),
        mesh
     );

    scalar bubbleVolume;
     // ....
     // compute bubbleVolume
     // ....

     Info << runTime.timeName() << " " << bubbleVolume << nl;
}

return 0;
}
Sorry for the bad inlining. May also contain some typos, there is a good documentation page for timeselector though (may be worth a try, Google is your friend).

Best regards and good luck
RP
raumpolizei is offline   Reply With Quote

Old   May 26, 2023, 17:50
Default
  #4
Member
 
Uttam
Join Date: May 2020
Location: Southampton, United Kingdom
Posts: 35
Rep Power: 6
openfoam_aero is on a distinguished road
You are a legend. Thanks for this.
__________________
Best Regards
Uttam

-----------------------------------------------------------------

“When everything seem to be going against you, remember that the airplane takes off against the wind, not with it.” – Henry Ford.
openfoam_aero is offline   Reply With Quote

Reply

Tags
coded function object, compressibleinterfoam, directories, functionobjects


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
how to calculate mass flow rate on patches and summation of that during the run? immortality OpenFOAM Post-Processing 104 February 16, 2021 09:46
[swak4Foam] funkyDoCalc with OF2.3 massflow NiFl OpenFOAM Community Contributions 14 November 25, 2020 04:30
pressure in incompressible solvers e.g. simpleFoam chrizzl OpenFOAM Running, Solving & CFD 13 March 28, 2017 06:49
High Courant Number @ icoFoam Artex85 OpenFOAM Running, Solving & CFD 11 February 16, 2017 14:40
same geometry,structured and unstructured mesh,different behaviour. sharonyue OpenFOAM Running, Solving & CFD 13 January 2, 2013 23:40


All times are GMT -4. The time now is 13:20.