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

Is it possible to add comments to fields files from the code?

Register Blogs Community New Posts Updated Threads Search

Like Tree3Likes
  • 1 Post By Tobermory
  • 2 Post By olesen

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 31, 2021, 14:13
Question Is it possible to add comments to fields files from the code?
  #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 OpenFOAM, is there any way how can I add comments to vol{Vector,Scalar,...}Field from the code?

Say I have created a variable:

Code:
volVectorField X
(
  IOobject
  (
     "X",
     runTime().timeName(),
     mesh,
     IOobject::NO_READ,
     IOobject::AUTO_WRITE
  )
)
The output of this is the usual OpenFOAM files: a header, dimensions, internalField, boundaryField, etc.

Here is an example of the output I expect:

Code:
/*--------------------------------*- C++ -*----------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     | Website:  https://openfoam.com
    \\  /    A nd           | Version:  2006
     \\/     M anipulation  |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version         2;
    format          binary;
    class           volVectorField;
    location        "0.1";
    object          X;
}

dimensions      [ 0 1 -1 0 0 0 0 ];

// >>> I  want to add a comment here <<<
internalField   uniform (15 3.0 -5.0 );

boundaryField
{
    ...
    ...
}
I know that I can add that manually when the program finishes. But is it possible to add the comment from the code itself so the output field will contain that comment in every time folder?

Thank you
NotOverUnderated is offline   Reply With Quote

Old   November 1, 2021, 09:08
Default
  #2
Senior Member
 
Join Date: Apr 2020
Location: UK
Posts: 668
Rep Power: 14
Tobermory will become famous soon enough
To be honest, this is not trivial (due to the way that OF handles IOobjects, the write action is a pretty low level functionality, buried deep in the class hierarchy; you'd need to generate your own flavour of IOobject, with an additional constructor to take the comment, and then update a whole buch of other buried, connected stuff as well ...).

I would strongly recommend trying to do it another way, e.g. use a functionObject to run a sed command on the file when it is written, to insert the comment ... or even simpler just run a script at the end of the run to add the comment to all the save files. If you want it done on the fly, you could write the script to keep checking for new, unchanged save files, and when it finds one pause (to allow tge write to complete) and then update ... you can then run this script alongside your real run.

Probably not what you wanted to hear, but good luck anyway.
NotOverUnderated likes this.
Tobermory is offline   Reply With Quote

Old   November 1, 2021, 12:10
Default
  #3
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,685
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
Can second what Tobermory says. You can easily drop in some regular comments in the input, or even drop them in as input entries. For example


Code:
comment1  "This is an internalField";


internalFIeld ....

These will survive things like foamDictionary expansion, much like how you see files being assembled with various "#include" statements. However, when the volume field is written out, it only knows about its dimensions, internalField, boundaryField and each of the boundary condition types know how to write out their content. Since this content has been generated from OpenFOAM itself, there is no direct connection with your original input file whatsoever.
olesen 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
Fortran->Assembly : How to remove redundant non-vectorized code? aerosayan Main CFD Forum 6 November 20, 2020 05:37
defining fields extended code guide chkammer1989 OpenFOAM Programming & Development 1 July 28, 2020 20:10
Visual Studio Code (VSCode) extension for OpenFOAM dictionary files and case setup cosscholar OpenFOAM 0 June 15, 2020 14:47
Results saving in CFD hawk Main CFD Forum 16 July 21, 2005 20:51
public CFD Code development Heinz Wilkening Main CFD Forum 38 March 5, 1999 11:44


All times are GMT -4. The time now is 22:40.