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

How to assign value in OpenFOAM

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 19, 2019, 22:23
Default How to assign value in OpenFOAM
  #1
Senior Member
 
Nguyen Duy Trong
Join Date: Apr 2014
Posts: 124
Rep Power: 12
ndtrong is on a distinguished road
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.
Attached Images
File Type: png compare_2files.png (82.7 KB, 22 views)
ndtrong is offline   Reply With Quote

Old   December 22, 2019, 12:56
Default
  #2
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Tussenhausen
Posts: 2,708
Blog Entries: 6
Rep Power: 51
Tobi has a spectacular aura aboutTobi has a spectacular aura aboutTobi has a spectacular aura about
Send a message via ICQ to Tobi Send a message via Skype™ to Tobi
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();
__________________
Keep foaming,
Tobias Holzmann
Tobi is offline   Reply With Quote

Old   December 22, 2019, 22:46
Default
  #3
Senior Member
 
Nguyen Duy Trong
Join Date: Apr 2014
Posts: 124
Rep Power: 12
ndtrong is on a distinguished road
Quote:
Originally Posted by Tobi View Post
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
ndtrong 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
OpenFOAM 5.0 Released CFDFoundation OpenFOAM Announcements from OpenFOAM Foundation 11 June 5, 2018 23:48
OpenFOAM Training Jan-Jul 2017, Virtual, London, Houston, Berlin CFDFoundation OpenFOAM Announcements from Other Sources 0 January 4, 2017 06:15
OpenFOAM Training, London, Chicago, Munich, Sep-Oct 2015 cfd.direct OpenFOAM Announcements from Other Sources 2 August 31, 2015 13:36
Superlinear speedup in OpenFOAM 13 msrinath80 OpenFOAM Running, Solving & CFD 18 March 3, 2015 05:36
Adventure of fisrst openfoam installation on Ubuntu 710 jussi OpenFOAM Installation 0 April 24, 2008 14:25


All times are GMT -4. The time now is 12:57.