ENH: use emplace_set, emplace_back to simplify code

- eg, for cloud fields, tmp emplace when reading fields etc.
This commit is contained in:
Mark Olesen
2023-07-21 12:32:04 +02:00
parent 63258d0b33
commit 8117cde596
25 changed files with 373 additions and 620 deletions

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017-2022 OpenCFD Ltd.
Copyright (C) 2017-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -72,26 +72,22 @@ Foam::probes::getOrLoadField(const word& fieldName) const
if (loadFromFiles_)
{
tfield.reset
tfield.emplace
(
new GeoField
IOobject
(
IOobject
(
fieldName,
mesh_.time().timeName(),
mesh_,
IOobject::MUST_READ,
IOobject::NO_WRITE,
IOobject::NO_REGISTER
),
mesh_
)
fieldName,
mesh_.time().timeName(),
mesh_.thisDb(),
IOobjectOption::MUST_READ,
IOobjectOption::NO_WRITE,
IOobjectOption::NO_REGISTER
),
mesh_
);
}
else
{
// Slightly paranoid here
tfield.cref(mesh_.cfindObject<GeoField>(fieldName));
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011 OpenFOAM Foundation
Copyright (C) 2015-2022 OpenCFD Ltd.
Copyright (C) 2015-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -42,26 +42,22 @@ Foam::sampledSets::getOrLoadField(const word& fieldName) const
if (loadFromFiles_)
{
tfield.reset
tfield.emplace
(
new GeoField
IOobject
(
IOobject
(
fieldName,
mesh_.time().timeName(),
mesh_,
IOobject::MUST_READ,
IOobject::NO_WRITE,
IOobject::NO_REGISTER
),
mesh_
)
fieldName,
mesh_.time().timeName(),
mesh_.thisDb(),
IOobjectOption::MUST_READ,
IOobjectOption::NO_WRITE,
IOobjectOption::NO_REGISTER
),
mesh_
);
}
else
{
// Slightly paranoid here
tfield.cref(mesh_.cfindObject<GeoField>(fieldName));
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2015-2022 OpenCFD Ltd.
Copyright (C) 2015-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -220,29 +220,32 @@ void Foam::sampledSurfaces::performAction
Info<< "sampleWrite: " << fieldName << endl;
}
refPtr<GeoField> tfield;
if (loadFromFiles_)
{
const GeoField fld
tfield.emplace
(
IOobject
(
fieldName,
time_.timeName(),
mesh_,
IOobject::MUST_READ
mesh_.thisDb(),
IOobjectOption::MUST_READ,
IOobjectOption::NO_WRITE,
IOobjectOption::NO_REGISTER
),
mesh_
);
performAction(fld, request);
}
else
{
performAction
(
mesh_.thisDb().lookupObject<GeoField>(fieldName),
request
);
tfield.cref(mesh_.thisDb().cfindObject<GeoField>(fieldName));
}
if (tfield)
{
performAction(tfield(), request);
}
}
}

View File

@ -946,9 +946,9 @@ void Foam::isoSurfaceCell::calcAddressing
// Determine edgeFaces
edgeFace0.resize(nUnique);
edgeFace0.resize_nocopy(nUnique);
edgeFace0 = -1;
edgeFace1.resize(nUnique);
edgeFace1.resize_nocopy(nUnique);
edgeFace1 = -1;
edgeFacesRest.clear();
@ -972,19 +972,8 @@ void Foam::isoSurfaceCell::calcAddressing
// << " used by more than two triangles: " << edgeFace0[edgeI]
// << ", "
// << edgeFace1[edgeI] << " and " << triI << endl;
Map<labelList>::iterator iter = edgeFacesRest.find(edgeI);
if (iter != edgeFacesRest.end())
{
labelList& eFaces = iter();
label sz = eFaces.size();
eFaces.setSize(sz+1);
eFaces[sz] = triI;
}
else
{
edgeFacesRest.insert(edgeI, labelList(1, triI));
}
edgeFacesRest(edgeI).push_back(triI);
}
}
}

View File

@ -1406,9 +1406,9 @@ Foam::isoSurfacePoint::isoSurfacePoint
);
// Clear old value. Cannot resize it since is a slice.
bfld.set(patchi, nullptr);
// Set new value we can change
bfld.release(patchi);
bfld.set
(
patchi,

View File

@ -75,9 +75,9 @@ Foam::isoSurfacePoint::adaptPatchFields
)
{
// Clear old value. Cannot resize it since is a slice.
sliceFldBf.set(patchi, nullptr);
// Set new value we can change
sliceFldBf.release(patchi);
sliceFldBf.set
(
patchi,