How to create a field without reading from 0 directroy
Hello,
I have created a volScalarField using the following: Code:
volScalarField X The code compiles fine, but when I run it, I get this error message: Code:
Thank you |
Does something like this work?
Code:
volScalarField X |
Quote:
I wonder why does this work? could you please elaborate and explain why NO_READ has no effect? |
Agreed that this is misleading, but the field has to be initialised with something. The TLDR version is that the original constructor that you used is the "READ constructor" for a field, and will try read from file regardless of the NO_READ flag; the "corrected" constructor is the one to use if you do not want to read from file, but in that case you have to supply the initialisation data for the field.
If you want to see the detail, read on. In your code, you have defined a new volScalarField, which is a templated type of GemetricField. For the constructor, you passed an IOobject and a mesh, i.e. you used the constructor (line 366 in https://cpp.openfoam.org/v8/Geometri..._source.html): Code:
//- Construct and read given IOobject Code:
template<class Type, template<class> class PatchField, class GeoMesh> Let's now look at the "corrected" constructor, i.e. the one that works for you. This uses the constructor at line 327 of GeometricField.H: Code:
//- Constructor given IOobject, mesh, dimensioned<Type> Code:
template<class Type, template<class> class PatchField, class GeoMesh> Hope this helps! |
Great explanation!
Quote:
|
Quote:
In the openfoam.com version you should at least have seen a warning message: Code:
read option IOobject::MUST_READ or MUST_READ_IF_MODIFIED If you want to create without initialization, you should at least provide the dimensionSet (eg, length, velocity etc) so that later assignments make sense. |
Quote:
|
Quote:
Yes you are correct, the warning message are for some of the other constructors, not for the one that you are using. It actually does go off and attempt to read in fields regardless of the IOobject read setting. The best advice (and the conclusion that you've already reached) is not to use that particular constructor. Aside from the reading issue, the missing dimensions are a bit of a showstopper. Still undecided if it is worth raising an issue for this behaviour. I'll leave that up to you. |
Quote:
Thank you |
Quote:
|
Quote:
Opened an issue: https://develop.openfoam.com/Develop.../-/issues/2926 can add comments/preferences/ideas there. |
All times are GMT -4. The time now is 05:00. |