mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
DOC: document/warn about GeometricField constructor being always read (#2926)
- no change in behaviour except to emit a warning when called with the a non-reading readOption STYLE: remove redundant size check - size checking is already done by Field::assign() within the DimensionedField::readField
This commit is contained in:
@ -390,6 +390,8 @@ public:
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Resize to the mesh size and read the field from the dictionary.
|
||||
//- Internal implementation checks field vs mesh size.
|
||||
void readField
|
||||
(
|
||||
const dictionary& fieldDict,
|
||||
|
||||
@ -46,7 +46,7 @@ void Foam::DimensionedField<Type, GeoMesh>::readField
|
||||
// an old run where the oriented state may not have been set
|
||||
if (oriented_.oriented() != orientedType::ORIENTED)
|
||||
{
|
||||
oriented_.read(fieldDict);
|
||||
oriented_.read(fieldDict); // The "oriented" entry (if present)
|
||||
}
|
||||
|
||||
|
||||
@ -54,7 +54,7 @@ void Foam::DimensionedField<Type, GeoMesh>::readField
|
||||
auto& fld = static_cast<Field<Type>&>(*this);
|
||||
|
||||
fld.resize_nocopy(GeoMesh::size(mesh_));
|
||||
fld.assign(fieldDictEntry, fieldDict, fld.size());
|
||||
fld.assign(fieldDictEntry, fieldDict, fld.size()); // <- MUST_READ
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -25,8 +25,8 @@ License
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef DimensionedFields_H
|
||||
#define DimensionedFields_H
|
||||
#ifndef Foam_DimensionedFields_H
|
||||
#define Foam_DimensionedFields_H
|
||||
|
||||
#include "DimensionedScalarField.H"
|
||||
//#include "DimensionedVectorField.H"
|
||||
|
||||
@ -56,7 +56,7 @@ void Foam::GeometricField<Type, PatchField, GeoMesh>::readFields
|
||||
const dictionary& dict
|
||||
)
|
||||
{
|
||||
Internal::readField(dict, "internalField");
|
||||
Internal::readField(dict, "internalField"); // Includes size check
|
||||
|
||||
boundaryField_.readField(*this, dict.subDict("boundaryField"));
|
||||
|
||||
@ -85,9 +85,9 @@ void Foam::GeometricField<Type, PatchField, GeoMesh>::readFields()
|
||||
this->instance(),
|
||||
this->local(),
|
||||
this->db(),
|
||||
IOobject::MUST_READ,
|
||||
IOobject::NO_WRITE,
|
||||
IOobject::NO_REGISTER
|
||||
IOobjectOption::MUST_READ,
|
||||
IOobjectOption::NO_WRITE,
|
||||
IOobjectOption::NO_REGISTER
|
||||
),
|
||||
typeName
|
||||
);
|
||||
@ -104,7 +104,7 @@ bool Foam::GeometricField<Type, PatchField, GeoMesh>::readIfPresent()
|
||||
if (this->isReadRequired())
|
||||
{
|
||||
WarningInFunction
|
||||
<< "read option IOobject::MUST_READ or MUST_READ_IF_MODIFIED"
|
||||
<< "The readOption MUST_READ or READ_MODIFIED"
|
||||
<< " suggests that a read constructor for field " << this->name()
|
||||
<< " would be more appropriate." << endl;
|
||||
}
|
||||
@ -118,17 +118,6 @@ bool Foam::GeometricField<Type, PatchField, GeoMesh>::readIfPresent()
|
||||
)
|
||||
{
|
||||
readFields();
|
||||
|
||||
// Check compatibility between field and mesh
|
||||
if (this->size() != GeoMesh::size(this->mesh()))
|
||||
{
|
||||
FatalIOErrorInFunction(this->readStream(typeName))
|
||||
<< " number of field elements = " << this->size()
|
||||
<< " number of mesh elements = "
|
||||
<< GeoMesh::size(this->mesh())
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
|
||||
readOldTimeIfPresent();
|
||||
|
||||
return true;
|
||||
@ -147,8 +136,8 @@ bool Foam::GeometricField<Type, PatchField, GeoMesh>::readOldTimeIfPresent()
|
||||
this->name() + "_0",
|
||||
this->time().timeName(),
|
||||
this->db(),
|
||||
IOobject::READ_IF_PRESENT,
|
||||
IOobject::AUTO_WRITE,
|
||||
IOobjectOption::LAZY_READ,
|
||||
IOobjectOption::AUTO_WRITE,
|
||||
this->registerObject()
|
||||
);
|
||||
|
||||
@ -235,7 +224,6 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<class Type, template<class> class PatchField, class GeoMesh>
|
||||
Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField
|
||||
(
|
||||
@ -561,18 +549,21 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField
|
||||
fieldPrevIterPtr_(nullptr),
|
||||
boundaryField_(mesh.boundary())
|
||||
{
|
||||
readFields();
|
||||
DebugInFunction
|
||||
<< "Read construct" << nl << this->info() << endl;
|
||||
|
||||
// Check compatibility between field and mesh
|
||||
|
||||
if (this->size() != GeoMesh::size(this->mesh()))
|
||||
if (!this->isAnyRead())
|
||||
{
|
||||
FatalIOErrorInFunction(this->readStream(typeName))
|
||||
<< " number of field elements = " << this->size()
|
||||
<< " number of mesh elements = " << GeoMesh::size(this->mesh())
|
||||
<< exit(FatalIOError);
|
||||
// Do not warn about LAZY_READ since we may have already checked
|
||||
// the IOobject before calling.
|
||||
WarningInFunction
|
||||
<< "Had readOption NO_READ for field "
|
||||
<< this->name() << ", but constructor always reads field!"
|
||||
<< endl;
|
||||
}
|
||||
|
||||
readFields();
|
||||
|
||||
if (readOldTime)
|
||||
{
|
||||
readOldTimeIfPresent();
|
||||
@ -599,16 +590,6 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField
|
||||
{
|
||||
readFields(dict);
|
||||
|
||||
// Check compatibility between field and mesh
|
||||
|
||||
if (this->size() != GeoMesh::size(this->mesh()))
|
||||
{
|
||||
FatalIOErrorInFunction(dict)
|
||||
<< " number of field elements = " << this->size()
|
||||
<< " number of mesh elements = " << GeoMesh::size(this->mesh())
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
|
||||
DebugInFunction
|
||||
<< "Finishing dictionary-construct" << nl << this->info() << endl;
|
||||
}
|
||||
@ -637,7 +618,7 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField
|
||||
);
|
||||
}
|
||||
|
||||
this->writeOpt(IOobject::NO_WRITE);
|
||||
this->writeOpt(IOobjectOption::NO_WRITE);
|
||||
}
|
||||
|
||||
|
||||
@ -656,7 +637,7 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField
|
||||
DebugInFunction
|
||||
<< "Constructing from tmp" << nl << this->info() << endl;
|
||||
|
||||
this->writeOpt(IOobject::NO_WRITE);
|
||||
this->writeOpt(IOobjectOption::NO_WRITE);
|
||||
|
||||
tgf.clear();
|
||||
}
|
||||
@ -1029,8 +1010,8 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::oldTime() const
|
||||
this->name() + "_0",
|
||||
this->time().timeName(),
|
||||
this->db(),
|
||||
IOobject::NO_READ,
|
||||
IOobject::NO_WRITE,
|
||||
IOobjectOption::NO_READ,
|
||||
IOobjectOption::NO_WRITE,
|
||||
this->registerObject()
|
||||
),
|
||||
*this
|
||||
|
||||
@ -307,7 +307,7 @@ public:
|
||||
const PtrList<PatchField<Type>>& ptfl
|
||||
);
|
||||
|
||||
//- Construct and read given IOobject
|
||||
//- Read construct using given IOobject. Always reads!
|
||||
GeometricField
|
||||
(
|
||||
const IOobject& io,
|
||||
|
||||
@ -34,8 +34,8 @@ SourceFiles
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef GeometricFieldOps_H
|
||||
#define GeometricFieldOps_H
|
||||
#ifndef Foam_GeometricFieldOps_H
|
||||
#define Foam_GeometricFieldOps_H
|
||||
|
||||
#include "FieldOps.H"
|
||||
#include "GeometricField.H"
|
||||
|
||||
@ -32,8 +32,8 @@ Description
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef GeometricFields_H
|
||||
#define GeometricFields_H
|
||||
#ifndef Foam_GeometricFields_H
|
||||
#define Foam_GeometricFields_H
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
Reference in New Issue
Block a user