CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Post-Processing

fieldValues integration

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 28, 2013, 15:21
Default fieldValues integration
  #1
Member
 
Ronald McDonald
Join Date: Jul 2012
Posts: 38
Rep Power: 13
mcdonalds is on a distinguished road
Dear openFoamers,Spring is right around the corner! Hope you all are feeling the warmth!



Anyway, I am trying to integrate a scalarfield jbv over my length in the y-direction. I found this while googling integration in openFoam:

HTML Code:
Post-processing The fieldValues function object has been extended to include: ensemble field averaging (average); area-weighted field averaging and integration in a user-defined direction (areaNormalAverage, areaNormalIntegrate); operation on a user-defined surface (sampledSurface) instead of mesh faces. The Mach, Pe, wallHeatFlux and yPlusRASutilities have been extended to use any basicThermo thermodynamics packages.

Apparently, the fieldValue function object can "integrate in a user-defined direction". That is exactly what I'd like to do. The only problem: I'm not sure how to use it. Can anyone help?



Sincerely,


Benjamin
mcdonalds is offline   Reply With Quote

Old   April 1, 2013, 09:28
Default
  #2
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,974
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
Greetings Benjamin,

I'm guessing you haven't read the release notes for OpenFOAM 2.2: http://www.openfoam.org/version2.2.0/index.php

In particular: http://www.openfoam.org/version2.2.0/documentation.php
Which leads us to: http://foam.sourceforge.net/docs/cpp/modules.html

Best regards,
Bruno
__________________
wyldckat is offline   Reply With Quote

Old   April 12, 2013, 13:40
Default
  #3
Member
 
Ronald McDonald
Join Date: Jul 2012
Posts: 38
Rep Power: 13
mcdonalds is on a distinguished road
Quote:
Originally Posted by wyldckat View Post
Greetings Benjamin,

I'm guessing you haven't read the release notes for OpenFOAM 2.2: http://www.openfoam.org/version2.2.0/index.php

In particular: http://www.openfoam.org/version2.2.0/documentation.php
Which leads us to: http://foam.sourceforge.net/docs/cpp/modules.html

Best regards,
Bruno

Thanks, Bruno. The last link is very helpful as it leads to some documentation on post-processing functions within openfoam.

There is a list of field functions that I look at with this link:
http://foam.sourceforge.net/docs/cpp/a09432.html

And under that there is a faceSource function I found with this link:
http://foam.sourceforge.net/docs/cpp...5.html#details

Now apparently to use this function I need to copy and paste the code, with some modification, into my controlDict file. Is this correct?

Now, to my problem. I would like to use the fieldValue function and integrate my field along the y-axis of my geometry as in my simulation things are only changing along that one dimension. It is found with this link:
http://foam.sourceforge.net/docs/cpp...1.html#details

However, unlike faceSource there is no example code for fieldValue, even though faceSource is a "class" of fieldValue. I am not sure what "class" means and if I can use the same code from faceSource for fieldValue.

So, my problem is I do not have an example code from fieldValue to insert into my controlDict file and I do not understand the documentation enough to create my own code.

Any help you can provide would be a life saver.

Sincerely,

Benjamin
mcdonalds is offline   Reply With Quote

Old   April 14, 2013, 12:21
Default
  #4
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,974
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
Hi Benjamin,

OK, let's address one issue at a time:
  1. As documented, "fieldValues" is only the basis for object functions. I've looked at the code to confirm and by itself, it doesn't do anything with any field. It only prepares things for the derived classes.
  2. From your description, there seems to be a missing detail: how exactly do you want to integrate? Is it only integrated along that line?
    1. If so, is your case 1D or 2D?
    2. If it's 1D or 2D, then I think you should use the "cellSource" function object: http://foam.sourceforge.net/docs/cpp...7.html#details - and then use the operation "volIntegrate".
      • Selecting a cell zone can be done with topoSet or setSet. Search online for "topoSetDict" and you should find out how to use topoSet.
If "cellSource" is not what you're looking for, then you need to know which exact mathematical operation you want to do. Then you either have to:
Best regards,
Bruno
__________________
wyldckat is offline   Reply With Quote

Old   April 16, 2013, 17:05
Default A bit off topic
  #5
Member
 
Ronald McDonald
Join Date: Jul 2012
Posts: 38
Rep Power: 13
mcdonalds is on a distinguished road
Hey Bruno,

Thanks for the help with the volIntegration. I haven't gotten it to work yet but I was able to make some zones and am about to try it out. I'll post if I get it to work.

I had a question you may or may not be able to answer. It is about the time loops. In my code I have:
HTML Code:
 while (simple.loop())
    {
        Info<< "Time = " << runTime.timeName() << nl << endl;



        while (simple.correctNonOrthogonal())
        {
   
Dum = phi;
   
        solve
            (
                 fvm::laplacian(sigmaeff, phi) + phiao - phi - EaEqgCell 
            );

Check = phi;

        }

    #include "mapToCell.H"


    
        #include "write.H"

        Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s"
            << "  ClockTime = " << runTime.elapsedClockTime() << " s"
            << nl << endl;
    }
Now if I look at the Dum field before the solve function I get a different phi than the one after the solve function called Check. I would have thought the field Dum and Check would be the same. Why is that? How does this time loop work? Do I need a different time loop?

Sincerely,

Benjamin
mcdonalds is offline   Reply With Quote

Old   April 17, 2013, 17:12
Default
  #6
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,974
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
Hi Benjamin,

I'm not sure understand your questions... or at least, I'm not understanding very well your logic.

The "Dum" and "Check" variables are giving you copies of the "phi" field, as it was before and after the solve code. For example, it's the same as:
Code:
Dum =  1;
Check = 2;
It is what it is: 1 and 2

At first, I thought you were asking why both "Dum" and "Check" had the same "phi" value for after the solve variable...

Perhaps it's easier for me to understand if you describe what you're trying to do.

Best regards,
Bruno
__________________
wyldckat is offline   Reply With Quote

Old   April 21, 2013, 12:56
Thumbs up
  #7
Member
 
Ronald McDonald
Join Date: Jul 2012
Posts: 38
Rep Power: 13
mcdonalds is on a distinguished road
Hi Bruno,

Thank you for your reply.

So, what I'd really like to do is basically the same just looks more complex. I'll try and explain it first.

I have a variable, the charge density or jbvagcell, that needs as an input the phi variable. The phi variable, meanwhile, I have as an initial condition as zeros on the internal field with two boundary conditions in a 2-D model with changes occurring only in the y-direction. (A simple rectangular geometry with sides as zeroGradient and the two ends as a fixedValue boundary condition). Here is my equation for jbvagcell:

HTML Code:
    jbvagCell == iagCell*exp((alphaaa*F*(phiao-phi-EaEqgCell)/(Rg*T))-exp(-alphaca*F*(phiao-phi-EaEqgCell)/(Rg*T)));
where all variables are a constant except for phi and EaEgqCell, the latter is calculated from concentration diffusion fields. Those diffusion equations are calculated with this pde:

HTML Code:
         solve
            (
                fvm::ddt(H2O) - fvm::laplacian(DH2Oeff, H2O) - sa*H2OMM/(n5*F)
            );
where H2O is the scalarfield, dh2oeff is an effective diffusion coefficient, h2oMM is the molar mass of water, and sa is a source term, mapped directly from the aforementioned jbvagcell. The rest are constants.

Then I take the jbvagCell and place it into a pde, which becomes an implicitly differentiated pde, because I am solving for phi and it is also contained in jbvagCell. It looks as follows:

HTML Code:
        solve
            (
                fvm::laplacian(sigmaeff, phi) + jbvagCell
            );
And all of these equations occur in the following time loop.
Here is is:

HTML Code:
#include "simpleControl.H"

simpleControl simple(mesh);

    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

    Info<< "\nCalculating concentration distribution\n" << endl;

    while (simple.loop())
    {
        Info<< "Time = " << runTime.timeName() << nl << endl;



//**Add laplacians to all four species: O2, N2, H2O, H2
        while (simple.correctNonOrthogonal())
        {

***************equations*******************


        }
****mapping function from local to global meshes******
    #include "mapToCell.H"


    
        #include "write.H"

        Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s"
            << "  ClockTime = " << runTime.elapsedClockTime() << " s"
            << nl << endl;
    }
Now for my problem. I would think all of this works well, but I am getting strange results when I calculate phi. So I need to figure out why this is.

First question: When I look at phi before the implicit pde for phi, I get a linear curve which happens immediately, right after the first time step and held constant thereafter, between its two initial boundary conditions. I would at least expect an ever changing curve until it hits a steady state.

Also, when I look at the actual phi I get a bell shaped curve whose max is huge, way above realistic capability. But this is changing up until steady state.

Why do two different phi's show up? Why is it linear and constant before the solve and then look different after the solve? Does it have to do with the time loop?

Second question: I would like to look at the overpotential, or etta, which is calculated as:

HTML Code:
etta = phiao-phi-EaEqgCell;
It should range from -.1 to .1 volts. phiao is around -.5 while EaEgqCell is around .3. When I place this equation before the solve I get a range of -.8 to .1 volts. Obviously it is because of the linear curve of the phi before the solve. If I put it after I get results that are way too large. Again I suspect that there is something going on with the time loop but I am not sure, I just want to be able to rule that out as a problem.

Third question: Is it good openFoam coding to put all of these equations and pdes in succession, one after the other, and within pdes? Maybe I am getting these incorrect results because of poor sequencing or coding?

Anything you can think of, even the smallest inkling of a doubt, please let me know. I am utterly confused and stumped on why my results are showing up this way. When I created my simulation I had the utmost confidence that it would work meticulously, robustly, and accurately. Now, I am humbled beyond compare.

Sincerely,

Benjamin
mcdonalds is offline   Reply With Quote

Old   April 21, 2013, 16:27
Default
  #8
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,974
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
Hi Benjamin,

Mmm... well, this is a bit over my head... Nonetheless, there are two things that leave me a bit suspicious:
  1. The first equation... why is it using "==" when outside of an explicit "solve" or equation variable? I say this because, for example, the file "applications/solvers/compressible/rhoPimpleFoam/UEqn.H" gives two demonstrations of how to use "==", and your first equation doesn't seem to apply to either one of the coding examples.
  2. Have you checked each equation step with a simple and analytical example?
    1. Better yet, have you tried solving a simple example using OpenFOAM's source code, which requires the same kinds of calculations you're trying to perform? Something like a response in time to a step function: http://en.wikipedia.org/wiki/Step_response
Based on my current and limited experience, this is all I can figure out and suggest that you try.


As for having so many equations solved so closely, there shouldn't be any problems... as long as it makes mathematical sense . I've seen something similarly complex just the other day... here we go: http://www.cfd-online.com/Forums/ope...tml#post421629 - post #7

Best regards,
Bruno
__________________
wyldckat is offline   Reply With Quote

Old   April 21, 2013, 17:00
Default
  #9
Member
 
Ronald McDonald
Join Date: Jul 2012
Posts: 38
Rep Power: 13
mcdonalds is on a distinguished road
This last link in your post doesn't seem to be working. Can you repost it please?

Benjamin

Quote:
Originally Posted by wyldckat View Post

As for having so many equations solved so closely, there shouldn't be any problems... as long as it makes mathematical sense . I've seen something similarly complex just the other day... here we go: http://www.cfd-online.com/Forums/ope...tml#post421629 - post #7

Best regards,
Bruno
mcdonalds is offline   Reply With Quote

Old   April 21, 2013, 17:01
Default
  #10
Member
 
Ronald McDonald
Join Date: Jul 2012
Posts: 38
Rep Power: 13
mcdonalds is on a distinguished road
Nevermind it works, sorry!
mcdonalds is offline   Reply With Quote

Old   April 24, 2013, 18:14
Default
  #11
Member
 
Ronald McDonald
Join Date: Jul 2012
Posts: 38
Rep Power: 13
mcdonalds is on a distinguished road
Hi Bruno,

So as it turns out there was an incorrect equation in my file, which was giving me incorrect results. They look pretty good now. Thanks for the help with that .

I am still trying to figure out the integration. I placed the following code in my controlDict file:

HTML Code:
cellSource1
{
    type            cellSource;
    functionObjectLibs ("libfieldFunctionObjects.so");
    log             true;
    valueOutput     true;
    source          cellZone;
    sourceName      anode;
    operation       volIntegrate;
    fields
    (
        jbvagCell
        
    );
}

where jbvagCell is the scalarfield I'd like to integrate. I created a cellZone named anode. I then run my simulation and there are no errors. But I do not know how to access the volIntegrate results. They are not in paraView. Where can I find them?


Sincerely,

Benjamin


Quote:
Originally Posted by wyldckat View Post
Hi Benjamin,

OK, let's address one issue at a time:
  1. As documented, "fieldValues" is only the basis for object functions. I've looked at the code to confirm and by itself, it doesn't do anything with any field. It only prepares things for the derived classes.
  2. From your description, there seems to be a missing detail: how exactly do you want to integrate? Is it only integrated along that line?
    1. If so, is your case 1D or 2D?
    2. If it's 1D or 2D, then I think you should use the "cellSource" function object: http://foam.sourceforge.net/docs/cpp...7.html#details - and then use the operation "volIntegrate".
      • Selecting a cell zone can be done with topoSet or setSet. Search online for "topoSetDict" and you should find out how to use topoSet.
If "cellSource" is not what you're looking for, then you need to know which exact mathematical operation you want to do. Then you either have to:
Best regards,
Bruno
mcdonalds is offline   Reply With Quote

Old   April 26, 2013, 17:42
Default Source term
  #12
Member
 
Ronald McDonald
Join Date: Jul 2012
Posts: 38
Rep Power: 13
mcdonalds is on a distinguished road
Hi Bruno,

So I'd like to add an implicit source term to my pde. It would look like this:

HTML Code:
  solve
            (
                Foam::fvm::laplacian(sigmaeff, phi) == iagCell*((Foam::exp(alphaaa*F*(phiao-phi-EaEqgCell)/(Rg*T)))-(Foam::exp(-alphaca*F*(phiao-phi-EaEqgCell)/(Rg*T)))) 
            );

Where phi is my volscalarfield. Other variables are independent or constant.

I looked at OpenFoam documentation, specifically from this site:
http://www.foamcfd.org/Nabla/guides/...sGuidese9.html

And it talks about using Su, Sp, and SuSp. I would like to use those things but I'm not sure how to. In the documentation it talks about a rho and phi, where rho can either be a dimensioned scalar or a volscalarField, and phi is the volscalarfield.

Now in my pde I do not know what rho would be.

Also, I found another link talking about this:
http://openfoamwiki.net/index.php/Ho...sport_equation

Any help you could provide would be great!

Sincerely,

Benjamin
mcdonalds is offline   Reply With Quote

Old   April 26, 2013, 20:01
Default
  #13
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,974
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
Hi Benjamin,

Quote:
Originally Posted by mcdonalds View Post
where jbvagCell is the scalarfield I'd like to integrate. I created a cellZone named anode. I then run my simulation and there are no errors. But I do not know how to access the volIntegrate results. They are not in paraView. Where can I find them?
In theory, you should find the values inside the folder "postProcessing/cellSource1", if you are using OpenFOAM 2.2, or "cellSource1" if you are using an older version.

Quote:
Originally Posted by mcdonalds View Post
So I'd like to add an implicit source term to my pde. It would look like this:
[...]
What you're asking is a bit over my level of knowledge. What I can suggest is this:
  1. Start a thread on this topic about the PDE equation and so on in the programming sub-forum: http://www.cfd-online.com/Forums/ope...g-development/
  2. Check OpenFOAM's folder "doc/Guides-a4/", which has the latest User and Programmer Guides, albeit the Programmer Guide still has several typos, last time I checked.
    You can see the path to this folder if you run:
    Code:
    echo $WM_PROJECT_DIR/doc/Guides-a4/
Best regards,
Bruno
__________________
wyldckat is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 are the integration constants for the JANAFthermo class derived? tomf OpenFOAM Running, Solving & CFD 2 May 15, 2015 08:47
CFD-Post: Polyline Export at Integration Points minger ANSYS 4 February 22, 2014 10:23
Fluent Integration Numerics RodriguezFatz FLUENT 11 February 21, 2013 07:35
About Aspen and Fluent Integration! xfish FLUENT 0 March 24, 2005 22:51
Any numerical triple integration program is available in Fortran? Radhakrishnan Main CFD Forum 3 March 4, 1999 02:03


All times are GMT -4. The time now is 23:51.