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

How to edit OpenFOAM files at runtime without crashing the simulations?

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes
  • 2 Post By NotOverUnderated

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 30, 2023, 22:19
Default How to edit OpenFOAM files at runtime without crashing the simulations?
  #1
Senior Member
 
NotOverUnderated's Avatar
 
ONESP-RO
Join Date: Feb 2021
Location: Somwhere on Planet Earth
Posts: 127
Rep Power: 5
NotOverUnderated is on a distinguished road
Hello,

In my system/controlDict file I set:

Code:
runTimeModifiable   true;
As expected, this works just fine and I could edit the simulation files (e.g. system/fvSchemes, system/fvSolution, etc.) at runtime and the solver reads the new files at the next time step.


Problem:

Sometimes I am lucky enough that the simulations do not crash when I save the modifications of the files but in most cases, the simulation crashes. I think this happens because while the text editor writes to the disk, the solver tries to re-read the file which leads to the crash of the simulation.

Question

Is there any reliable solution to this issue so I could modify simulation files at runtime without the risk of crashing when I save the file using the text editor?

P.S: I am using OpenFOAM v2212
NotOverUnderated is offline   Reply With Quote

Old   July 1, 2023, 05:07
Default
  #2
Senior Member
 
Join Date: Oct 2017
Posts: 133
Rep Power: 9
Krapf is on a distinguished road
In my experience, crashes of this kind have to do with making a mistake yourself (e.g. forgetting a semicolon). Could you please show an error message?
Krapf is offline   Reply With Quote

Old   July 1, 2023, 23:15
Default
  #3
Senior Member
 
NotOverUnderated's Avatar
 
ONESP-RO
Join Date: Feb 2021
Location: Somwhere on Planet Earth
Posts: 127
Rep Power: 5
NotOverUnderated is on a distinguished road
Quote:
Originally Posted by Krapf View Post
In my experience, crashes of this kind have to do with making a mistake yourself (e.g. forgetting a semicolon). Could you please show an error message?
Thank you for your reply.

No. There are no mistakes while editing files. This happened to me hundreds of times. When I re-run the simulation it works fine (this demonstrates that there are no mistakes in the files).
NotOverUnderated is offline   Reply With Quote

Old   July 2, 2023, 06:02
Default
  #4
Senior Member
 
Yann
Join Date: Apr 2012
Location: France
Posts: 1,238
Rep Power: 29
Yann will become famous soon enoughYann will become famous soon enough
What is your work environment? (OS, running simulations locally or remotely, etc...)

I've edited countless of controlDict/fvSchemes/fvSolution files at runtime for the past 10 years, using multiple OpenFOAM versions on multiple systems, and from my experience it's quite reliable (actually I don't remember facing any crash, except the ones due to typos)

Yann
Yann is offline   Reply With Quote

Old   July 2, 2023, 16:32
Default
  #5
Senior Member
 
NotOverUnderated's Avatar
 
ONESP-RO
Join Date: Feb 2021
Location: Somwhere on Planet Earth
Posts: 127
Rep Power: 5
NotOverUnderated is on a distinguished road
Quote:
Originally Posted by Yann View Post
What is your work environment? (OS, running simulations locally or remotely, etc...)

I've edited countless of controlDict/fvSchemes/fvSolution files at runtime for the past 10 years, using multiple OpenFOAM versions on multiple systems, and from my experience it's quite reliable (actually I don't remember facing any crash, except the ones due to typos)

Yann
I am running my simulations using a cluster running CentOS 7. For example while running a simulation of flow around a cylinder with 16 processors, I have tried to change the end time from 100 to 200 and then saved using :w in Vim text editor, the simulation crashed with the following error (again there are not typos, and after the crash I can re-run the simulation just fine):

Code:
    From virtual bool Foam::regIOobject::readIfModified()
    in file db/regIOobject/regIOobjectRead.C at line 271
        Re-reading object controlDict from file "/home/feelTheFearAndDoItAnyway/scratch/squareCylinder/piso/system/controlDict"
--> FOAM Warning : 
    From bool Foam::IOobject::readHeader(Foam::dictionary&, Foam::Istream&)
    in file db/IOobject/IOobjectReadHeader.C at line 116
    Reading "/home/feelTheFearAndDoItAnyway/scratch/squareCylinder/piso/system/controlDict" at line 1
    First token could not be read or is not 'FoamFile'

Check header is of the form:

/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  2112                                  |
|   \\  /    A nd           | Website:  www.openfoam.com                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    arch        "LSB;label=32;scalar=64";
    class       dictionary;
    location    "system";
    object      controlDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //



[0] --> FOAM FATAL IO ERROR: (openfoam-2112)
[0] problem while reading header for object controlDict
[0] 
[0] file: system/controlDict at line 1.
[0] 
[0]     From virtual Foam::autoPtr<Foam::ISstream> Foam::fileOperations::uncollatedFileOperation::readStream(Foam::regIOobject&, const Foam::fileName&, const Foam::word&, bool) const
[0]     in file global/fileOperations/uncollatedFileOperation/uncollatedFileOperation.C at line 563.
[0] 
FOAM parallel run exiting
[0] 
--------------------------------------------------------------------------
MPI_ABORT was invoked on rank 0 in communicator MPI_COMM_WORLD
with errorcode 1.

NOTE: invoking MPI_ABORT causes Open MPI to kill all MPI processes.
You may or may not see output from other processes, depending on
exactly when Open MPI kills them.
--------------------------------------------------------------------------
In: PMI_Abort(1, N/A)
srun: Job step aborted: Waiting up to 32 seconds for job step to finish.
slurmstepd: error: *** STEP 6296119.0 ON ngm552 CANCELLED AT 2023-07-02T12:23:16 ***
srun: error: ngm555: tasks 11-15: Killed
srun: Terminating StepId=6296119.0
srun: error: ngm552: tasks 0-10: Killed
---- END ----
NotOverUnderated is offline   Reply With Quote

Old   July 3, 2023, 10:04
Default
  #6
Senior Member
 
NotOverUnderated's Avatar
 
ONESP-RO
Join Date: Feb 2021
Location: Somwhere on Planet Earth
Posts: 127
Rep Power: 5
NotOverUnderated is on a distinguished road
I have finally solved the issue!

It turned out that Vim saves the changes directly to the file so the file goes through a period of time where it is in inconsistent state and when OpenFOAM attempts to read the file during this period, it may not find what it expects and hence fail.


The solution is to told Vim to use an "atomic" save method (saves to a temporary file then replaces the old one) by adding this command in ~/.vimrc:

Code:
:set backupcopy=yes
Now, the simulations no longer crash during runtime modifications of the files!
Yann and Zena27 like this.
NotOverUnderated is offline   Reply With Quote

Old   July 3, 2023, 10:59
Default
  #7
Senior Member
 
Yann
Join Date: Apr 2012
Location: France
Posts: 1,238
Rep Power: 29
Yann will become famous soon enoughYann will become famous soon enough
Thanks for your feedback, it's definitely good to know!

Yann
Yann 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 View OpenFOAM files from WSL Bash Environment ajcib Main CFD Forum 0 February 11, 2022 17:42
Planning a (EPYC?) workstation for thermal/reacting simulations (OpenFOAM) hsnyder Hardware 14 October 30, 2020 11:13
OpenFOAM v3.0+ ?? SBusch OpenFOAM 22 December 26, 2016 15:24
OpenFOAM v3.0.1 Training, London, Houston, Berlin, Jan-Mar 2016 cfd.direct OpenFOAM Announcements from Other Sources 0 January 5, 2016 04:18
OpenFOAM15 paraFoam bug koen OpenFOAM Bugs 19 June 30, 2009 11:46


All times are GMT -4. The time now is 01:29.