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

Correct way to write intermediate values of field calculations

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 4, 2020, 14:22
Default Correct way to write intermediate values of field calculations
  #1
New Member
 
Joseph E Weaver
Join Date: Sep 2019
Posts: 2
Rep Power: 0
joeeweaver is on a distinguished road
I am extending a solver whose final fields are calculated using a collection of intermediate values. Generically, it writes field F, which is the sum A+B+C+D.

I would like to visualize the individual components (per cell) over time to get a feel for their relative contributions under different conditions and in different locations.

While I'm able to just spit a bunch of output to the terminal and parse it, I'm also aware that the better way to do this would be to be output them using the built-in OpenFOAM registry functionality (IOobject) etc.

I'm not particularly familiar with how that part of the code works, particularly in the context of local variables (the A,B,C,D components) within a function.


Following the wiki, I've successfully set up an IOobject for component A

Code:
volScalarField A_comp
(
    IOobject
    (
        "A_comp",
        fc_->mesh_.time().timeName(),
        fc_->mesh_,
        IOobject::NO_READ,
        IOobject::AUTO_WRITE
    ),
    fc_->mesh_
);

A_comp = fc_->calculate_A();
The
Code:
fc_
object is just a pointer to a class which calculates some of the components and has a handy reference to the mesh. This all compiles and the solver runs to the first time it tries to write. I get the error

Code:
--> FOAM FATAL ERROR: 
cannot find file "~/case/0.002/A_comp"
I'm interpreting this as I need to do some additional setup for preparing a file to write the A_comp field. I'm not sure where to go from that point and googling around hasn't provided much illumination.

Note that we have no idea of what the initial values of A,B,C,D are, nor would guesses at those ICs be used in calculating them. I don't think I need to set up blank files in the 0 directory, but could be wrong.

Any guidance would be appreciated.
joeeweaver is offline   Reply With Quote

Old   February 5, 2020, 11:10
Default
  #2
New Member
 
Morteza Mousavi
Join Date: Jul 2019
Location: Lund, Sweden
Posts: 15
Rep Power: 7
Mirza8 is on a distinguished road
That might be because of the type of the constructor that you use for your volScalarField. According to following lines from GeometricField.H file, this constructor is used when you want to read an object:

Code:
//- Construct and read given IOobject
        GeometricField
        (
            const IOobject&,
            const Mesh&
        );
So maybe you need to use another constructor. I usually use something like this:
Code:
volVectorField A_comp
(
    IOobject
    (
        "A_comp",
        runTime.timeName(),
        mesh,
        IOobject::NO_READ,
        IOobject::AUTO_WRITE
    ),
    fc_->calculate_A()   // the value of the volScalarField
);
So I use the desired value of the volScalarField instead of fc_->mesh_ that you previously used, in the constructor.
Mirza8 is offline   Reply With Quote

Old   February 5, 2020, 13:30
Default
  #3
New Member
 
Joseph E Weaver
Join Date: Sep 2019
Posts: 2
Rep Power: 0
joeeweaver is on a distinguished road
Thanks, this makes sense but revealed a further issue.

It turns out
Code:
fc_->calculate_A()
is actually calculating a scalar for a single cell rather than volScalarField. The values get recombined higher up the call stack into a field.

I'll be looking for a better place to run this, unless there's some variant of IOobject where you can insert individual scalars and have it recreate the field.
joeeweaver 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
mesh file for flow over a circular cylinder Ardalan Main CFD Forum 7 December 15, 2020 14:06
How can write a field in openFOAM sven82 OpenFOAM Programming & Development 27 December 11, 2019 12:57
Field values at the boundary cells vcvedant OpenFOAM Running, Solving & CFD 4 August 2, 2017 18:50
howto write a patch field during the run m2montazari OpenFOAM 15 September 6, 2016 09:57
Phase locked average in run time panara OpenFOAM 2 February 20, 2008 15:37


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