CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (http://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   How to temporarily store fields and use them in for loop (http://www.cfd-online.com/Forums/openfoam-programming-development/124352-how-temporarily-store-fields-use-them-loop.html)

CHARLES October 2, 2013 21:50

How to temporarily store fields and use them in for loop
 
Hello all,

I have implemented some changes to the k-omega model in order to update it (2006 version) but I have run into some problems... although the code compiles, the computer seems to run out of memory when I run a simulation.

I was wondering if anybody could please help me out...

Below you will find the changes I have made, I believe the problem is in the way that I have defined the volTensorFields. I think I should define them as a tmp<volTensorField> but I don't know how to do so, or how to use the values obtained from tmp in the for loop that follows the volTensorField definitions.

Commenting out the lines below allowed the code to compile.

Something I find troubling is that it seems to me like RORP_ and RORS_ should be checked at every cell but for some reason the compiler doesn't like that... so I commented them out. I'm very new to modifying OpenFOAM so I have no clue about what I'm doing most of the time.

The goal: to modify beta_ (which requires for the computer to look into RORP_,RORS_) for every cell according to the definition in the code below.

Thank you in advance!

Code:

const volTensorField& RORP_(skew(fvc::grad(U_)) & skew(fvc::grad(U_))); //O_ij O_jk
const volTensorField& RORS_(RORP_ & symm(fvc::grad(U_))); //R_ik S_ki
const volScalarField& Chi_(tr(RORS_)/pow((0.09*omega_),3));
//const volScalarField& fomega_(0.0708*((1+85*Chi_)/(1+100*Chi_)));

//modify the values of Chi,fomega, beta, for the corresponding cell, cellI:
    forAll(beta_, cellI)
    {
    //RORP_[cellI]=(skew(fvc::grad(U_)) & skew(fvc::grad(U_)));
    //RORS_[cellI]=(RORP_[cellI] & symm(fvc::grad(U_)));
    //Chi_[cellI]=(tr(RORS_[cellI])/pow((0.09*omega_[cellI]),3));
    fomega_[cellI]=(1+85*Chi_[cellI])/(1+100*Chi_[cellI]);
    beta_[cellI]=0.0708*fomega_[cellI];
    }


lixx October 2, 2013 23:07

At first look, the "const" key word prevents you from modifying RORP_ etc. But I don't know if there are any further problems with your code.

CHARLES October 3, 2013 11:46

I believe that may have solved the running out of memory problem... Thank you very much!!!


I still have my doubts about my implementation with the goal of checking/modifying the variables at every cell. If there is anyone who has experience modifying OpenFOAM, your input would be greatly appreciated!

Bernhard October 4, 2013 02:57

Fields in OpenFoam are cleverly designed, such that you do not need to use loops. In your case, you can easily

Code:

fomega_=(1.+85.*Chi_)/(1.+100.*Chi_)
beta_=0.0708*fomega_

At least as long as Chi is dimensionless.

For the latter statement for beta, I highly doubt if you really gain anything by the beta variable, as it is only a multiplication with a scalar.

CHARLES October 4, 2013 12:10

Thanks for replying Bernhard!

That answers my question of why OpenFOAM doesn't have any loops in any of the source files for the equations. :rolleyes:

Could you explain what you mean by "For the latter statement for beta, I highly doubt if you really gain anything by the beta variable, as it is only a multiplication with a scalar"?

You doubt I'll gain anything in what sense?


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