ENH: patch boundarySlice() for extraction from a flat boundary list

- remove redundant raw patch slice and non-const patchSlice, which
  were only used internally by finiteArea.

STYLE: noexcept on more patch methods
This commit is contained in:
Mark Olesen 2023-01-26 22:04:48 +01:00
parent 911c28f17d
commit c206b12c80
12 changed files with 192 additions and 118 deletions

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017, 2020 OpenFOAM Foundation
Copyright (C) 2018-2022 OpenCFD Ltd.
Copyright (C) 2018-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -454,13 +454,13 @@ public:
virtual const pointField& oldCellCentres() const;
//- Return boundary mesh
const polyBoundaryMesh& boundaryMesh() const
const polyBoundaryMesh& boundaryMesh() const noexcept
{
return boundary_;
}
//- Return mesh bounding box
const boundBox& bounds() const
const boundBox& bounds() const noexcept
{
return bounds_;
}

View File

@ -307,13 +307,14 @@ Foam::wordList Foam::polyPatch::constraintTypes()
}
Foam::label Foam::polyPatch::offset() const
Foam::label Foam::polyPatch::offset() const noexcept
{
return start_ - boundaryMesh().start();
// Same as start_ - polyMesh::nInternalFaces()
return start_ - boundaryMesh_.start();
}
const Foam::polyBoundaryMesh& Foam::polyPatch::boundaryMesh() const
const Foam::polyBoundaryMesh& Foam::polyPatch::boundaryMesh() const noexcept
{
return boundaryMesh_;
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2015 OpenFOAM Foundation
Copyright (C) 2015-2020 OpenCFD Ltd.
Copyright (C) 2015-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -359,10 +359,10 @@ public:
//- The offset where this patch starts in the boundary face list
// The value is the same as patch.start() - mesh.nInternalFaces()
label offset() const;
label offset() const noexcept;
//- Return start label of this patch in the polyMesh face list
label start() const
label start() const noexcept
{
return start_;
}
@ -374,7 +374,7 @@ public:
}
//- Return boundaryMesh reference
const polyBoundaryMesh& boundaryMesh() const;
const polyBoundaryMesh& boundaryMesh() const noexcept;
//- Return true if this patch is geometrically coupled (i.e. faces and
// points correspondence)
@ -399,18 +399,30 @@ public:
return UIndirectList<T>(internalValues, faceCells());
}
//- Slice List to patch, using the number of patch faces
//- This patch slice from the complete list, which has size
//- mesh::nFaces(), using the number of patch faces.
template<class T>
const typename List<T>::subList patchSlice(const UList<T>& l) const
const typename List<T>::subList
patchSlice(const UList<T>& values) const
{
return typename List<T>::subList(l, this->size(), start_);
return typename List<T>::subList(values, this->size(), start_);
}
//- Slice Field to patch, using the number of patch faces
//- This patch slice from the list of boundary values, which has size
//- mesh::nBoundaryFaces(), using the number of patch faces.
template<class T>
const typename Field<T>::subField patchSlice(const Field<T>& l) const
const typename List<T>::subList
boundarySlice(const List<T>& values) const
{
return typename Field<T>::subField(l, this->size(), start_);
return typename List<T>::subList(values, this->size(), offset());
}
//- Slice Field to patch, using the number of patch faces.
template<class T>
const typename Field<T>::subField
patchSlice(const Field<T>& values) const
{
return typename Field<T>::subField(values, this->size(), start_);
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016-2017 Wikki Ltd
Copyright (C) 2019-2022 OpenCFD Ltd.
Copyright (C) 2019-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -194,6 +194,17 @@ const Foam::faBoundaryMesh& Foam::faPatch::boundaryMesh() const noexcept
}
Foam::label Foam::faPatch::offset() const
{
return max
(
0,
boundaryMesh().mesh().patchStarts()[index()]
- boundaryMesh().mesh().nInternalEdges()
);
}
Foam::label Foam::faPatch::start() const
{
return boundaryMesh().mesh().patchStarts()[index()];

View File

@ -305,6 +305,10 @@ public:
return false;
}
//- The offset where this patch starts in the boundary edge list.
// The value is the same as patch.start() - mesh.nInternalEdges()
label offset() const;
//- Patch start in edge list
label start() const;
@ -320,18 +324,26 @@ public:
return edgei - start();
}
//- Slice List to patch, using the virtual patch size
//- This patch slice from the complete list of values, which has
//- size mesh::nEdges(), using the virtual patch size.
template<class T>
typename List<T>::subList patchSlice(const List<T>& l) const
const typename List<T>::subList patchSlice(const List<T>& values) const
{
return typename List<T>::subList(l, size(), start());
return typename List<T>::subList(values, size(), start());
}
//- Slice List to patch, using the number of patch edges
//- This patch slice from the list of boundary values, which has
//- size mesh::nBoundaryEdges(), using the virtual patch size.
template<class T>
typename List<T>::subList patchRawSlice(const List<T>& l) const
const typename List<T>::subList
boundarySlice(const List<T>& values) const
{
return typename List<T>::subList(l, nEdges(), start());
return typename List<T>::subList
(
values,
size(),
offset()
);
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017 OpenCFD Ltd.
Copyright (C) 2017-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -35,13 +35,22 @@ Foam::slicedFvPatchField<Type>::slicedFvPatchField
(
const fvPatch& p,
const DimensionedField<Type, volMesh>& iF,
const Field<Type>& completeField
const Field<Type>& completeOrBoundaryField,
const bool isBoundaryOnly
)
:
fvPatchField<Type>(p, iF, Field<Type>())
{
// Set fvPatchField to a slice of the given complete field
UList<Type>::shallowCopy(p.patchSlice(completeField));
if (isBoundaryOnly)
{
// Set to a slice of the boundary field
UList<Type>::shallowCopy(p.boundarySlice(completeOrBoundaryField));
}
else
{
// Set to a slice of the complete field
UList<Type>::shallowCopy(p.patchSlice(completeOrBoundaryField));
}
}
@ -64,8 +73,11 @@ Foam::slicedFvPatchField<Type>::slicedFvPatchField
const dictionary& dict
)
:
fvPatchField<Type>(p, iF, dict, false)
fvPatchField<Type>(p, iF) // bypass dictionary constructor
{
fvPatchFieldBase::readDict(dict);
// Read "value" if present...
NotImplemented;
}
@ -142,10 +154,12 @@ Foam::slicedFvPatchField<Type>::clone
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class Type>
Foam::slicedFvPatchField<Type>::~slicedFvPatchField()
{
// Set fvPatchField to nullptr to avoid deletion of underlying field
// Set to nullptr to avoid deletion of underlying field
UList<Type>::shallowCopy(UList<Type>());
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2017 OpenCFD Ltd.
Copyright (C) 2017-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -47,10 +47,11 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef slicedFvPatchField_H
#define slicedFvPatchField_H
#ifndef Foam_slicedFvPatchField_H
#define Foam_slicedFvPatchField_H
#include "fvPatchField.H"
#include "processorFvPatch.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -58,7 +59,7 @@ namespace Foam
{
/*---------------------------------------------------------------------------*\
Class slicedFvPatch Declaration
Class slicedFvPatchField Declaration
\*---------------------------------------------------------------------------*/
template<class Type>
@ -66,9 +67,12 @@ class slicedFvPatchField
:
public fvPatchField<Type>
{
public:
//- The mesh processor patch type
typedef processorFvPatch processorPatchType;
//- Runtime type information
TypeName("sliced");
@ -80,7 +84,8 @@ public:
(
const fvPatch&,
const DimensionedField<Type, volMesh>&,
const Field<Type>&
const Field<Type>& completeOrBoundaryField,
const bool isBoundaryOnly = false
);
//- Construct from patch and internal field. Assign value later.

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -34,13 +35,22 @@ Foam::slicedFvsPatchField<Type>::slicedFvsPatchField
(
const fvPatch& p,
const DimensionedField<Type, surfaceMesh>& iF,
const Field<Type>& completeField
const Field<Type>& completeOrBoundaryField,
const bool isBoundaryOnly
)
:
fvsPatchField<Type>(p, iF, Field<Type>())
{
// Set fvsPatchField to a slice of the given complete field
UList<Type>::shallowCopy(p.patchSlice(completeField));
if (isBoundaryOnly)
{
// Set to a slice of the boundary field
UList<Type>::shallowCopy(p.boundarySlice(completeOrBoundaryField));
}
else
{
// Set to a slice of the complete field
UList<Type>::shallowCopy(p.patchSlice(completeOrBoundaryField));
}
}
@ -63,8 +73,11 @@ Foam::slicedFvsPatchField<Type>::slicedFvsPatchField
const dictionary& dict
)
:
fvsPatchField<Type>(p, iF, Field<Type>("value", dict, p.size()))
fvsPatchField<Type>(p, iF) // bypass dictionary constructor
{
fvsPatchFieldBase::readDict(dict);
// Read "value" if present...
NotImplemented;
}
@ -141,10 +154,12 @@ Foam::slicedFvsPatchField<Type>::clone
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class Type>
Foam::slicedFvsPatchField<Type>::~slicedFvsPatchField()
{
// Set fvsPatchField to nullptr to avoid deletion of underlying field
// Set to nullptr to avoid deletion of underlying field
UList<Type>::shallowCopy(UList<Type>());
}

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -40,10 +41,11 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef slicedFvsPatchField_H
#define slicedFvsPatchField_H
#ifndef Foam_slicedFvsPatchField_H
#define Foam_slicedFvsPatchField_H
#include "fvsPatchField.H"
#include "processorFvPatch.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -51,7 +53,7 @@ namespace Foam
{
/*---------------------------------------------------------------------------*\
Class slicedFvsPatch Declaration
Class slicedFvsPatchField Declaration
\*---------------------------------------------------------------------------*/
template<class Type>
@ -59,9 +61,12 @@ class slicedFvsPatchField
:
public fvsPatchField<Type>
{
public:
//- The mesh processor patch type
typedef processorFvPatch processorPatchType;
//- Runtime type information
TypeName("sliced");
@ -73,7 +78,8 @@ public:
(
const fvPatch&,
const DimensionedField<Type, surfaceMesh>&,
const Field<Type>&
const Field<Type>& completeOrBoundaryField,
const bool isBoundaryOnly = false
);
//- Construct from patch and internal field

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017,2022 OpenFOAM Foundation
Copyright (C) 2016-2022 OpenCFD Ltd.
Copyright (C) 2016-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -201,7 +201,7 @@ void Foam::fvMesh::storeOldVol(const scalarField& V)
scalarField& V0 = *V0Ptr_;
// Note: V0 now sized with current mesh, not with (potentially
// different size) V.
V0.setSize(V.size());
V0.resize_nocopy(V.size());
V0 = V;
}
@ -665,7 +665,6 @@ void Foam::fvMesh::removeFvBoundary()
// Remove fvBoundaryMesh data first.
boundary_.clear();
boundary_.setSize(0);
polyMesh::removeBoundary();
clearOut();
@ -709,12 +708,6 @@ Foam::polyMesh::readUpdateState Foam::fvMesh::readUpdate()
}
const Foam::fvBoundaryMesh& Foam::fvMesh::boundary() const
{
return boundary_;
}
const Foam::lduAddressing& Foam::fvMesh::lduAddr() const
{
if (!lduPtr_)
@ -814,7 +807,7 @@ void Foam::fvMesh::mapFields(const mapPolyMesh& meshMap)
scalarField& V0 = *V0Ptr_;
scalarField savedV0(V0);
V0.setSize(nCells());
V0.resize_nocopy(nCells());
forAll(V0, i)
{
@ -856,7 +849,7 @@ void Foam::fvMesh::mapFields(const mapPolyMesh& meshMap)
scalarField& V00 = *V00Ptr_;
scalarField savedV00(V00);
V00.setSize(nCells());
V00.resize_nocopy(nCells());
forAll(V00, i)
{

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017,2022 OpenFOAM Foundation
Copyright (C) 2016-2022 OpenCFD Ltd.
Copyright (C) 2016-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -97,6 +97,7 @@ protected:
//- Boundary mesh
fvBoundaryMesh boundary_;
// Demand-driven data
mutable fvMeshLduAddressing* lduPtr_;
@ -314,7 +315,10 @@ public:
}
//- Return reference to boundary mesh
const fvBoundaryMesh& boundary() const;
const fvBoundaryMesh& boundary() const noexcept
{
return boundary_;
}
//- Return ldu addressing
virtual const lduAddressing& lduAddr() const;

View File

@ -166,78 +166,79 @@ public:
// Access
//- Return the polyPatch
const polyPatch& patch() const noexcept
{
return polyPatch_;
}
//- Return the polyPatch
const polyPatch& patch() const noexcept
{
return polyPatch_;
}
//- Return name
virtual const word& name() const
{
return polyPatch_.name();
}
//- Return name
virtual const word& name() const
{
return polyPatch_.name();
}
//- Return start label of this patch in the polyMesh face list
virtual label start() const
{
return polyPatch_.start();
}
//- The index of this patch in the boundary mesh
label index() const noexcept
{
return polyPatch_.index();
}
//- Return size
virtual label size() const
{
return polyPatch_.size();
}
//- The patch start within the polyMesh face list
label start() const noexcept
{
return polyPatch_.start();
}
//- Return true if this patch is coupled
virtual bool coupled() const
{
return polyPatch_.coupled();
}
//- Patch size is the number of faces, but can be overloaded
virtual label size() const
{
return polyPatch_.size();
}
//- Return true if the given type is a constraint type
static bool constraintType(const word& patchType);
//- Return true if this patch is coupled
virtual bool coupled() const
{
return polyPatch_.coupled();
}
//- Return a list of all the constraint patch types
static wordList constraintTypes();
//- Return true if the given type is a constraint type
static bool constraintType(const word& patchType);
//- Return the index of this patch in the fvBoundaryMesh
label index() const noexcept
{
return polyPatch_.index();
}
//- Return a list of all the constraint patch types
static wordList constraintTypes();
//- Return boundaryMesh reference
const fvBoundaryMesh& boundaryMesh() const noexcept
{
return boundaryMesh_;
}
//- Return boundaryMesh reference
const fvBoundaryMesh& boundaryMesh() const noexcept
{
return boundaryMesh_;
}
//- Slice List to patch, using the virtual patch size
template<class T>
const typename List<T>::subList patchSlice(const List<T>& l) const
{
return typename List<T>::subList(l, size(), start());
}
//- This patch slice from the complete list, which has size
//- mesh::nFaces(), using the virtual patch size.
template<class T>
const typename List<T>::subList
patchSlice(const List<T>& values) const
{
return typename List<T>::subList(values, size(), start());
}
//- Slice List to patch, using the underlying polyPatch information
template<class T>
const typename List<T>::subList patchRawSlice
//- This patch slice from the list of boundary values, which has size
//- mesh::nBoundaryFaces(), using the virtual patch size.
template<class T>
const typename List<T>::subList
boundarySlice(const List<T>& values) const
{
return typename List<T>::subList
(
const List<T>& l
) const
{
return typename List<T>::subList
(
l,
polyPatch_.size(),
polyPatch_.start()
);
}
values,
size(),
polyPatch_.offset()
);
}
//- Return faceCells
virtual const labelUList& faceCells() const;
//- Return faceCells
virtual const labelUList& faceCells() const;
// Access functions for geometrical data