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

Reading a volumeField from a file at every timestep

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 20, 2022, 07:37
Default Reading a volumeField from a file at every timestep
  #1
New Member
 
Jesus
Join Date: Sep 2021
Posts: 11
Rep Power: 4
jgs55 is on a distinguished road
Hi everyone,

I want to implement a new discretization scheme for the convective term in OpenFOAM. At every timestep, I have a coefficient file generated by python with the format:

Code:
... header

internalField   nonuniform List<vector> 
16384
(
(1.03544e-05 -1.06153e-05 1.03544e-05 1.03544e-05 ) // Cell 0
(3.06175e-05 -1.01041e-05 -1.01041e-05 -1.01041e-05) // Cell 1
(5.11404e-05 -9.46919e-06 -9.46919e-06 -9.46919e-06) // Cell 2
(7.20913e-05 -9.58538e-06 -9.58538e-06 -9.58538e-06 ) // ... 
(9.31207e-05 -9.87433e-06 -9.87433e-06 -9.87433e-06 )
(0.000115088 -1.02901e-05 -1.02901e-05 -1.02901e-05 )
I need to read the file "coefficients" like any other field (e.g. u,p,k,etc) but at every timestep and load it to OpenFOAM as a volumeField.

I guess I should implement this on the runTime.loop(), since createFields.H is only executed once at the beginning of the main loop, but I do not have a clear idea of how to do that.

Thank you in advance!
jgs55 is offline   Reply With Quote

Old   September 21, 2022, 01:58
Default
  #2
New Member
 
Sen Wang
Join Date: Jul 2018
Location: Singapore / Notre Dame, U.S.
Posts: 19
Blog Entries: 1
Rep Power: 7
wangsen992 is on a distinguished road
Have you tried including this as a volVectorField (just like U) but in the arguments for IOobject, use MUST_READ_IF_MODIFIED?
wangsen992 is offline   Reply With Quote

Old   September 21, 2022, 07:37
Default
  #3
New Member
 
Jesus
Join Date: Sep 2021
Posts: 11
Rep Power: 4
jgs55 is on a distinguished road
Thank you Mr Wang for your reply, it was what I was looking for. For anyone with the same doubt, the solution was to modify the createFields.H of your solver, and add the following lines:

Code:
volVectorField coefficients
(
    IOobject
    (
        "coefficients",
        runTime.timeName(),
        mesh,
        IOobject::MUST_READ_IF_MODIFIED, //If object is registered its timestamp will be checked every timestep and possibly re-read.
        IOobject::NO_WRITE  //No automatic writing, but can be written explicitly
    ),
    mesh
);
jgs55 is offline   Reply With Quote

Reply

Tags
createfields, new implementation, read fields


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
Postprocess: sampleDict works but creates no output folder shock77 OpenFOAM Post-Processing 14 November 15, 2021 08:27
Problem compiling a custom Lagrangian library brbbhatti OpenFOAM Programming & Development 2 July 7, 2014 11:32
[swak4Foam] Error bulding swak4Foam sfigato OpenFOAM Community Contributions 18 August 22, 2013 12:41
Version 15 on Mac OS X gschaider OpenFOAM Installation 113 December 2, 2009 10:23
OpenFOAM on MinGW crosscompiler hosted on Linux allenzhao OpenFOAM Installation 127 January 30, 2009 19:08


All times are GMT -4. The time now is 06:36.