CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   How to assign value in OpenFOAM (https://www.cfd-online.com/Forums/openfoam-programming-development/223058-how-assign-value-openfoam.html)

ndtrong December 19, 2019 22:23

How to assign value in OpenFOAM
 
1 Attachment(s)
Hi everyone,

I have a problem related to assign value in OpenFOAM, the detail is as follow:

in interFoam solver, two variable alpha1 and alpha2 are defined as:
volScalarField& alpha1(mixture.alpha1());
volScalarField& alpha2(mixture.alpha2());


Now, I declare a variable with same type as:

volScalarField H
(
IOobject
(
"H",
runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
alpha1
);

to compute something.
After computation, I want to reassign value of alpha1 by H as:
alpha1 = H;
However, my assignment did not work since when I check the printed output of two files alpha1 and H, the value in same cell mesh are not identical as shown in the attachement.

Could anyone help me to explain the reason for that.

I thank you very much in advance.

Tobi December 22, 2019 12:56

Hi,


I would expect that this is related to the topic when is the mixture updated. E.g., your alpha is referenced to the mixture class (mixture.alpha1()).

Now, if you would do the following:
Code:



alpha1 = H;


Info<< alpha1 << endl;
Info<< H << endl;


You should have both variables with the H values.
However, depending when you set this assignment, the following can happen:


Code:



alpha1 = H;



Info<< alpha1 << endl;
Info<< H << endl;


// Other code that is executed and the mixture is updated
some code that updates the mixture


// Now alpha1 is updated with the mixture class again
// alpha1 != H


// Even though you assigned H to alpha 1 before, it was overwritten again by the mixture class

runTime.write();


ndtrong December 22, 2019 22:46

Quote:

Originally Posted by Tobi (Post 753055)
Hi,


I would expect that this is related to the topic when is the mixture updated. E.g., your alpha is referenced to the mixture class (mixture.alpha1()).

Now, if you would do the following:
Code:



alpha1 = H;


Info<< alpha1 << endl;
Info<< H << endl;


You should have both variables with the H values.
However, depending when you set this assignment, the following can happen:


Code:



alpha1 = H;



Info<< alpha1 << endl;
Info<< H << endl;


// Other code that is executed and the mixture is updated
some code that updates the mixture


// Now alpha1 is updated with the mixture class again
// alpha1 != H


// Even though you assigned H to alpha 1 before, it was overwritten again by the mixture class

runTime.write();


Dear Dr. Tobias

I thank you very much for your comments.
You are right at alpha1 = H and the value have same as H values.
My alpha1 value differ from H value because of update in MULES that I called after above assignment.

Kind regards,
Trong Nguyen


All times are GMT -4. The time now is 10:03.