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

Save data between two time steps

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 30, 2022, 04:14
Default Save data between two time steps
  #1
New Member
 
Charles Guaquiere
Join Date: Sep 2022
Posts: 14
Rep Power: 3
CGuaq is on a distinguished road
Dear foamers,

I need to save different values during a time step to use them for the next time step, to do that I thought of using 2 volVectorFields defined in the constructor to "stored" values in vectors components:

Code:
sigma_n
(
	IOobject
	(
		"sigma_n",
		this->owner_.mesh().time().timeName(),
		this->owner_.mesh(),
		IOobject::NO_READ,
		IOobject::AUTO_WRITE
	),
	this->owner_.mesh(),
	dimensionedVector("sigma_n", dimless, vector(10e-12, 10e-12, 10e-12))
 ),

 u_n
 (
	IOobject
	(
		"u_n",
		this->owner_.mesh().time().timeName(),
		this->owner_.mesh(),
		IOobject::NO_READ,
		IOobject::AUTO_WRITE
	),
	this->owner_.mesh(),
	dimensionedVector("u_n", dimless, vector(0, 0, 0))
    )
Now my problem is to modified this volVectorFields in each cells and for each time steps. I use the following lines to access to values in cells in volVectorFields:

Code:
const volVectorField& sigma_n = obr.lookupObject<volVectorField>("sigma_n");
volVectorField& sigma_nMod = const_cast<volVectorField&>(sigma_n);
    
const volVectorField& u_n = obr.lookupObject<volVectorField>("u_n");
volVectorField& u_nMod = const_cast<volVectorField&>(u_n);
And futher I modify the values in each cells with:

Code:
u_nMod.primitiveFieldRef()[celli].component(0) = UTurb.component(0);
u_nMod.primitiveFieldRef()[celli].component(1) = UTurb.component(1);
u_nMod.primitiveFieldRef()[celli].component(2) = UTurb.component(2);
            	
sigma_nMod.primitiveFieldRef()[celli].component(0) = sigma_x;
sigma_nMod.primitiveFieldRef()[celli].component(1) = sigma_y;
sigma_nMod.primitiveFieldRef()[celli].component(2) = sigma_z;
I can compile my code and lauch simulation without errors but it doesn't seem to work ...
So I wonder if it's possible to save datas in volVectorFIeld between two consecutive time step with this method, if not can you help me to find another solution ?
I'am beginner in programming under OpenFOAM so any idea could be helpful for me !

Thanks in advance!

Best regards
CGuaq is offline   Reply With Quote

Old   July 4, 2023, 05:19
Default
  #2
rku
New Member
 
Join Date: Feb 2018
Posts: 17
Rep Power: 8
rku is on a distinguished road
Hi Charles,

I am struggling to do a similar thing where I need the values of a vectorField to be carried over to the next timestep. Did you manage to solve your problem?

Thanks!
rku is offline   Reply With Quote

Old   July 4, 2023, 05:57
Default
  #3
New Member
 
Charles Guaquiere
Join Date: Sep 2022
Posts: 14
Rep Power: 3
CGuaq is on a distinguished road
Quote:
Originally Posted by rku View Post
Hi Charles,

I am struggling to do a similar thing where I need the values of a vectorField to be carried over to the next timestep. Did you manage to solve your problem?

Thanks!
Hello rku,
To solve this problem I modified other files in the code (for turbulent dispersion) to add the vector fields I need as "input variables" in the turbulent dispersion model. With this solution this fields are automatically saved at each time steps and you can use them. But the different lines of code I added in my previous message can also do it. If you need more informations don't hesitate.
CGuaq is offline   Reply With Quote

Old   July 5, 2023, 05:21
Default
  #4
rku
New Member
 
Join Date: Feb 2018
Posts: 17
Rep Power: 8
rku is on a distinguished road
Thanks for your quick reply!

I think I'll need to do some re-coding of other files as well.. The issue is the field I wanted to modify is vectorField which makes it more difficult in some ways. I'm trying now to generate a volVectorField which atleast allows me to use the oldTimes method. Lets see. Thanks anyways!
rku 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
how to export all time steps' data alubacyj CFX 11 June 22, 2023 18:18
How to export time series of variables for one point? mary mor OpenFOAM Post-Processing 8 July 19, 2017 10:54
pressure in incompressible solvers e.g. simpleFoam chrizzl OpenFOAM Running, Solving & CFD 13 March 28, 2017 05:49
[General] 2 datas on one plot Akuji ParaView 46 December 1, 2013 14:06
same geometry,structured and unstructured mesh,different behaviour. sharonyue OpenFOAM Running, Solving & CFD 13 January 2, 2013 22:40


All times are GMT -4. The time now is 17:55.