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

Reading field only at the first time folder

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 14, 2016, 11:29
Default Reading field only at the first time folder
  #1
Member
 
Join Date: Sep 2014
Posts: 32
Rep Power: 11
yongxiang is on a distinguished road
Hello everyone,
I am implementing a new solver with openfoam, I need to subtract a constant source term from the momentum equation. Since this source term is constant and is pre-obtained, it is better to only save it in the first time step folder. The following is the code (in red) I am using now, but this would end up with saving this term in every time step folder. If anyone hows how to implement it ?

Info<< "Reading field dU0dt\n" << endl;
volVectorField dU0dt
(
IOobject
(
"dU0dt",
runTime.timeName(),
mesh,
IOobject::MUST_READ,
IOobject::AUTO_WRITE
),
mesh
);

ps: Saving this constant term in /constant folder is not an option, since it would work with parallel computing. Therefore, it is better to be saved in the time folder.
yongxiang is offline   Reply With Quote

Old   September 14, 2016, 15:50
Default
  #2
New Member
 
AnthonyP's Avatar
 
Tony
Join Date: May 2016
Posts: 22
Rep Power: 9
AnthonyP is on a distinguished road
Hi yongxiang,

I'm quite new at this, but this looks like it works.

In createFields.H
I wrote the following code snippet:
Code:
Info<< "Reading field dU0dt\n" << endl;
volVectorField dU0dt
(
IOobject
(
"dU0dt",
runTime.constant(),
mesh,
IOobject::MUST_READ,
IOobject::NO_WRITE
),
mesh
);
in the solver, I added the following lines:

Before the while (runTime.run()) loop:
Code:
bool write_dUdT = true;
After the first round of calculations (or wherever it is feasible for your code):
I placed it after runTime.write();
Code:
if(write_dUdT){
	dU0dt.write();
	write_dUdT = false;
	}
and that's it.

After the first time step, it will create a constant (placed in your constant folder) which will then be referred to (and unedited) for following calculations.
--
Note, I am not sure if you need this value for your first timestep, If you do, you should probably initialize it with some approximation.
You could also move the dU0dt.write(); further up in the solver and use READ_IF_PRESENT.
--
Let me know if this helps,

Tony
AnthonyP is offline   Reply With Quote

Old   September 14, 2016, 16:58
Default
  #3
Member
 
Join Date: Sep 2014
Posts: 32
Rep Power: 11
yongxiang is on a distinguished road
Hi Tony,
thanks very much for your reply. You provide me an option to complete my desired task. However, the thing is if dU0dt is saved in the /constant folder, there would be problem with parallel computation. As far as I understood, the parallel computation only decompose the /polyMesh folder, where the mesh is stored, into different /processor* folder. Therefore, if dU0dt is stored in the /constant folder, it would not be decomposed, which would make the parallel computing fail.
That's why I think saving dU0dt in time folder would be better, since it would be automatically decomposed for parallel computation. I know function like:

runTime.constant(), and
runTime.timeName(),

but do you know something like:

runTime.startTime() or
runTime.timeName(startTime) or
runTime.timeName().startTime()

which would allow us to read the dU0dt always from the startTime folder. (All the above are not working as I already tried.)

Thanks again for your suggestion.
Yongxiang
yongxiang is offline   Reply With Quote

Old   September 14, 2016, 19:26
Default
  #4
New Member
 
AnthonyP's Avatar
 
Tony
Join Date: May 2016
Posts: 22
Rep Power: 9
AnthonyP is on a distinguished road
Whoops,

Sorry about that...

Note: I accidently posted an incorrect solution.

I'll keep looking for a solution.

Last edited by AnthonyP; September 14, 2016 at 19:38. Reason: Incorrect solution.
AnthonyP is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
simpleFoam error - "Floating point exception" mbcx4jc2 OpenFOAM Running, Solving & CFD 12 August 4, 2015 02:20
''unknown radialModelType type Gidaspow'' PROBLEM WITH THE BED TUTORIAL AndoniBM OpenFOAM Running, Solving & CFD 2 March 25, 2015 18:44
same geometry,structured and unstructured mesh,different behaviour. sharonyue OpenFOAM Running, Solving & CFD 13 January 2, 2013 22:40
Upgraded from Karmic Koala 9.10 to Lucid Lynx10.04.3 bookie56 OpenFOAM Installation 8 August 13, 2011 04:03
Differences between serial and parallel runs carsten OpenFOAM Bugs 11 September 12, 2008 11:16


All times are GMT -4. The time now is 00:50.