CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Post-Processing (http://www.cfd-online.com/Forums/openfoam-post-processing/)
-   -   fieldValues integration (http://www.cfd-online.com/Forums/openfoam-post-processing/115348-fieldvalues-integration.html)

mcdonalds March 28, 2013 15:21

fieldValues integration
 
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

wyldckat April 1, 2013 08:28

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

mcdonalds April 12, 2013 12:40

Quote:

Originally Posted by wyldckat (Post 417567)
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

wyldckat April 14, 2013 11:21

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 April 16, 2013 16:05

A bit off topic
 
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

wyldckat April 17, 2013 16:12

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

mcdonalds April 21, 2013 11:56

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

wyldckat April 21, 2013 15:27

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

mcdonalds April 21, 2013 16:00

This last link in your post doesn't seem to be working. Can you repost it please?

Benjamin

Quote:

Originally Posted by wyldckat (Post 422154)

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 April 21, 2013 16:01

Nevermind it works, sorry!

mcdonalds April 24, 2013 17:14

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 (Post 420454)
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 April 26, 2013 16:42

Source term
 
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

wyldckat April 26, 2013 19:01

Hi Benjamin,

Quote:

Originally Posted by mcdonalds (Post 422949)
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 (Post 423416)
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


All times are GMT -4. The time now is 22:27.