Updates to reduce unnecessary registration of tmp fields
As outlined in #2723 (closed) the registration/deregistration of tmp fields adds unnecessary hashing operations. These changes remove most of these cases and make more extensive use of various factory methods to simplify future changes. The largest contributor to tmp items is GeometricField (eg, volScalarField).
In general, the preference is to use more compact factory methods when dealing with tmp/autoPtr/refPtr. For example,
auto tfld = tmp<scalarField>::New(patch.size());
auto& fld = tfld.ref();
instead of
tmp<scalarField> tfld(new scalarField(patch.size()));
auto& fld = tfld.ref();
When dealing with regIOobject
types (which can be registered in an objectRegistry
), the syntax with the IOobject
becomes messier. Thus for tmp GeometricFields etc there is are dedicated factory methods that use the current timeName and the relevant mesh for the registry. For example,
auto tfld = volScalarField::New("foo", mesh, dimensionedScalar(dimless, Zero));
auto& fld = tfld.ref();
instead of
auto tfld = tmp<volScalarField>::New
(
IOobject
(
"foo",
mesh.time().timeName(),
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE,
IOobject::NO_REGISTER
),
mesh,
dimensionedScalar(dimless, Zero)
);
auto& fld = tfld.ref();
There are however instances when the tmp field must registered (eg, used for boundary conditions). In those cases it is also possible to explicitly specify the preferred registration handling:
auto tfld = volScalarField::New("foo", IOobject::REGISTER, mesh, dimensionedScalar(dimless, Zero));
auto& fld = tfld.ref();