|
[Sponsors] |
How to create a field without reading from 0 directroy |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
June 25, 2023, 22:49 |
How to create a field without reading from 0 directroy
|
#1 |
Senior Member
ONESP-RO
Join Date: Feb 2021
Location: Somwhere on Planet Earth
Posts: 127
Rep Power: 5 |
Hello,
I have created a volScalarField using the following: Code:
volScalarField X ( IOobject ( "X", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::NO_WRITE ), mesh ); The code compiles fine, but when I run it, I get this error message: Code:
Create time Create mesh for time = 0 --> FOAM FATAL ERROR: (openfoam-2112 patch=220610) cannot find file "/tmp/test/case/0/X" From virtual Foam::autoPtr<Foam::ISstream> Foam::fileOperations::uncollatedFileOperation::readStream(Foam::regIOobject&, const Foam::fileName&, const Foam::word&, bool) const in file global/fileOperations/uncollatedFileOperation/uncollatedFileOperation.C at line 542. FOAM exiting Thank you |
|
June 26, 2023, 07:37 |
|
#2 |
Senior Member
Adhiraj
Join Date: Sep 2010
Location: Karnataka, India
Posts: 187
Rep Power: 15 |
Does something like this work?
Code:
volScalarField X ( IOobject ( "X", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::AUTO_WRITE ), mesh, dimensionedScalar("Z", dimless, 0.0) ); |
|
June 26, 2023, 13:37 |
|
#3 | |
Senior Member
ONESP-RO
Join Date: Feb 2021
Location: Somwhere on Planet Earth
Posts: 127
Rep Power: 5 |
Quote:
I wonder why does this work? could you please elaborate and explain why NO_READ has no effect? |
||
June 27, 2023, 03:38 |
|
#4 |
Senior Member
Join Date: Apr 2020
Location: UK
Posts: 668
Rep Power: 14 |
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 GeometricField ( const IOobject&, const Mesh& ); Code:
template<class Type, template<class> class PatchField, class GeoMesh> Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField ( const IOobject& io, const Mesh& mesh ) : Internal(io, mesh, dimless, false), timeIndex_(this->time().timeIndex()), field0Ptr_(nullptr), fieldPrevIterPtr_(nullptr), boundaryField_(mesh.boundary()) { readFields(); ... etc - I pruned out some of the lines here } } 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> // and patch field type. GeometricField ( const IOobject&, const Mesh&, const dimensioned<Type>&, const word& patchFieldType=PatchField<Type>::calculatedType() ); Code:
template<class Type, template<class> class PatchField, class GeoMesh> Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField ( const IOobject& io, const Mesh& mesh, const dimensioned<Type>& dt, const word& patchFieldType ) : Internal(io, mesh, dt, false), timeIndex_(this->time().timeIndex()), field0Ptr_(nullptr), fieldPrevIterPtr_(nullptr), boundaryField_(mesh.boundary(), *this, patchFieldType) { if (debug) { InfoInFunction << "Creating temporary" << endl << this->info() << endl; } boundaryField_ == dt.value(); readIfPresent(); } Hope this helps! |
|
June 27, 2023, 04:34 |
Great explanation!
|
#5 | |
Senior Member
ONESP-RO
Join Date: Feb 2021
Location: Somwhere on Planet Earth
Posts: 127
Rep Power: 5 |
Quote:
|
||
June 27, 2023, 08:49 |
|
#6 | |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,686
Rep Power: 40 |
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 suggests that a read constructor for field " field-name would be more appropriate." If you want to create without initialization, you should at least provide the dimensionSet (eg, length, velocity etc) so that later assignments make sense. |
||
June 27, 2023, 16:07 |
|
#7 |
Senior Member
ONESP-RO
Join Date: Feb 2021
Location: Somwhere on Planet Earth
Posts: 127
Rep Power: 5 |
I am using OpenFOAM v2112 but I do not see that warning message. I have tried with v2212 but no warning message as well.
|
|
June 28, 2023, 06:03 |
|
#8 | |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,686
Rep Power: 40 |
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. |
||
June 28, 2023, 13:03 |
|
#9 | |
Senior Member
ONESP-RO
Join Date: Feb 2021
Location: Somwhere on Planet Earth
Posts: 127
Rep Power: 5 |
Quote:
Thank you |
||
June 29, 2023, 03:05 |
|
#10 |
Senior Member
Join Date: Apr 2020
Location: UK
Posts: 668
Rep Power: 14 |
As you pointed out Mark - it's working as intended, but also agreed that it's a little confusing. I think the best way to make this more transparent would be to simply ammend the description of the constructor in the header file, to state that this is the read constructor (OF refers to it like this in the warning message that you highlighted), or something similar.
|
|
June 30, 2023, 03:54 |
|
#11 | |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,686
Rep Power: 40 |
Quote:
Opened an issue: https://develop.openfoam.com/Develop.../-/issues/2926 can add comments/preferences/ideas there. |
||
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Illegal cell label -1, fluent3DMeshToFoam | BenGher | OpenFOAM | 7 | October 10, 2023 00:02 |
[Commercial meshers] Problem converting fluent mesh | vinz | OpenFOAM Meshing & Mesh Conversion | 28 | October 12, 2015 06:37 |
[General] How to create an additional vector with {Field 4, Field 5, Field 6} | Bombacar | ParaView | 1 | August 15, 2015 18:05 |
[Commercial meshers] fluentMeshToFoam multidomain mesh conversion problem | Attesz | OpenFOAM Meshing & Mesh Conversion | 12 | May 2, 2013 10:52 |
Actuator disk model | audrich | FLUENT | 0 | September 21, 2009 07:06 |