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

How to update volVectorField from files

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 20, 2021, 06:44
Default How to update volVectorField from files
  #1
New Member
 
Join Date: Sep 2021
Posts: 10
Rep Power: 4
newOpenfoamUser is on a distinguished road
Hi,

I am new to OpenFOAM and new to C++ as well. I have a basic question. My question is what is the proper way to update volScalarField or volVectorField from files (the files come from previous calculation)?

My problem is that I want to use scalarTransportFoam with prescribed time-varying velocity and phi field (calculated from pisoFoam). You might ask why don't I customise this into the time loop in pisoFoam. The thing is I know that my solution is periodic (with period of around 1s) so I only have to run pisoFoam for 3 periods for the solution to converge. Then, I can run scalarTransportFoam for 100 periods with the periodic velocity and phi field calculated earlier. By doing this, I think I can save a lot of time because I suppose pisoFoam is more computationally expensive than scalarTransportFoam.

The problem is that scalarTransportFoam only works for time-independent velocity and it will overwrite all the subsequent velocity with the initial velocity. My solution is to first change IOobject::AUTO_WRITE to IOobject::NO_WRITE in the initialisation of U and phi in "createFields.H" and "createPhi.H". While this will prevent it to overwrite the prescribed U and phi field, it does not read the U and phi field for each time step.

My second step is to include the following code inside the time loop of scalarTransportFoam:
Code:
U = volVectorField 
(
    IOobject
    (
        "U",
        runTime.timeName(),
        mesh,
        IOobject::MUST_READ,
        IOobject::NO_WRITE
    ),
    mesh
);

phi = surfaceScalarField 
(
    IOobject
    (
        "phi",
        runTime.timeName(),
        mesh,
        IOobject::READ_IF_PRESENT,
        IOobject::NO_WRITE
    ),
    fvc::flux(U)
);
This seems to work as I intended. However, I wonder whether this will create a new copy of volVectorField and surfaceScalarField while the previous copies will still live in the memory? So will this cause some memory and performance issues? I tried calling the destructor but that doesn't seem to work. This might be a basic C++ question but I am not very familiar with how memory allocation work in C++. Another question is that whether there are some member functions in the volVectorField and surfaceScalarField class that allow us to update the field values from files directly without having to create a new copy?
newOpenfoamUser 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
SIGSEGV Memory Access Exeption when Exporting Files using 'Update' JamesPermain STAR-CCM+ 0 April 22, 2020 10:50
The udf.h headers are unable to open- in VISUAL STUDIO 13 sanjeetlimbu Fluent UDF and Scheme Programming 4 May 2, 2016 05:38
UDF help for Rapid compression machine ECM. sanjeetlimbu Fluent UDF and Scheme Programming 0 March 17, 2015 22:45
Writing Case and Data Files Using Journal/Scheme Files svp Fluent UDF and Scheme Programming 0 April 5, 2011 11:04
Problems with result files Kasper CFX 5 December 14, 2006 02:41


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