Commit c3571b73 authored by mattijs's avatar mattijs
Browse files

ENH: topoDistanceData: templated on passive data type.

Also adds pointTopoDistance, edgeTopoDistance.
parent 9b4462e0
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2018 OpenCFD Ltd.
Copyright (C) 2016-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -88,12 +88,12 @@ labelList nearestPatch(const polyMesh& mesh, const labelList& patchIDs)
}
// Field on cells and faces.
List<topoDistanceData> cellData(mesh.nCells());
List<topoDistanceData> faceData(mesh.nFaces());
List<topoDistanceData<label>> cellData(mesh.nCells());
List<topoDistanceData<label>> faceData(mesh.nFaces());
// Start of changes
labelList patchFaces(nFaces);
List<topoDistanceData> patchData(nFaces);
List<topoDistanceData<label>> patchData(nFaces);
nFaces = 0;
for (const label patchi : patchIDs)
{
......@@ -102,13 +102,13 @@ labelList nearestPatch(const polyMesh& mesh, const labelList& patchIDs)
forAll(pp, i)
{
patchFaces[nFaces] = pp.start()+i;
patchData[nFaces] = topoDistanceData(patchi, 0);
patchData[nFaces] = topoDistanceData<label>(0, patchi);
++nFaces;
}
}
// Propagate information inwards
FaceCellWave<topoDistanceData> deltaCalc
FaceCellWave<topoDistanceData<label>> deltaCalc
(
mesh,
patchFaces,
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2015 OpenFOAM Foundation
Copyright (C) 2015-2019 OpenCFD Ltd.
Copyright (C) 2015-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -34,7 +34,7 @@ License
#include "syncTools.H"
#include "meshTools.H"
#include "PatchEdgeFaceWave.H"
#include "patchEdgeFaceRegion.H"
#include "edgeTopoDistanceData.H"
#include "globalIndex.H"
#include "OBJstream.H"
#include "addToRunTimeSelectionTable.H"
......@@ -511,8 +511,8 @@ void Foam::functionObjects::fluxSummary::initialiseCellZoneAndDirection
// Data on all edges and faces
List<patchEdgeFaceRegion> allEdgeInfo(patch.nEdges());
List<patchEdgeFaceRegion> allFaceInfo(patch.size());
List<edgeTopoDistanceData<label>> allEdgeInfo(patch.nEdges());
List<edgeTopoDistanceData<label>> allFaceInfo(patch.size());
bool search = true;
......@@ -528,12 +528,12 @@ void Foam::functionObjects::fluxSummary::initialiseCellZoneAndDirection
while (search)
{
DynamicList<label> changedEdges;
DynamicList<patchEdgeFaceRegion> changedInfo;
DynamicList<edgeTopoDistanceData<label>> changedInfo;
label seedFacei = labelMax;
for (; oldFaceID < patch.size(); oldFaceID++)
{
if (allFaceInfo[oldFaceID].region() == -1)
if (allFaceInfo[oldFaceID].data() == -1)
{
seedFacei = globalFaces.toGlobal(oldFaceID);
break;
......@@ -553,7 +553,7 @@ void Foam::functionObjects::fluxSummary::initialiseCellZoneAndDirection
forAll(fEdges, i)
{
if (allEdgeInfo[fEdges[i]].region() != -1)
if (allEdgeInfo[fEdges[i]].data() != -1)
{
WarningInFunction
<< "Problem in edge face wave: attempted to assign a "
......@@ -563,7 +563,14 @@ void Foam::functionObjects::fluxSummary::initialiseCellZoneAndDirection
}
changedEdges.append(fEdges[i]);
changedInfo.append(regioni);
changedInfo.append
(
edgeTopoDistanceData<label>
(
0, // distance
regioni
)
);
}
}
......@@ -571,7 +578,7 @@ void Foam::functionObjects::fluxSummary::initialiseCellZoneAndDirection
PatchEdgeFaceWave
<
indirectPrimitivePatch,
patchEdgeFaceRegion
edgeTopoDistanceData<label>
> calc
(
mesh_,
......@@ -588,7 +595,7 @@ void Foam::functionObjects::fluxSummary::initialiseCellZoneAndDirection
label nCells = 0;
forAll(allFaceInfo, facei)
{
if (allFaceInfo[facei].region() == regioni)
if (allFaceInfo[facei].data() == regioni)
{
nCells++;
}
......@@ -611,7 +618,7 @@ void Foam::functionObjects::fluxSummary::initialiseCellZoneAndDirection
forAll(allFaceInfo, facei)
{
regioni = allFaceInfo[facei].region();
regioni = allFaceInfo[facei].data();
regionFaceIDs[regioni].append(faceLocalPatchIDs[facei]);
regionFacePatchIDs[regioni].append(facePatchIDs[facei]);
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2015-2019 OpenCFD Ltd.
Copyright (C) 2015-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -417,12 +417,12 @@ Foam::labelList Foam::meshRefinement::nearestPatch
}
// Field on cells and faces.
List<topoDistanceData> cellData(mesh_.nCells());
List<topoDistanceData> faceData(mesh_.nFaces());
List<topoDistanceData<label>> cellData(mesh_.nCells());
List<topoDistanceData<label>> faceData(mesh_.nFaces());
// Start of changes
labelList patchFaces(nFaces);
List<topoDistanceData> patchData(nFaces);
List<topoDistanceData<label>> patchData(nFaces);
nFaces = 0;
forAll(adaptPatchIDs, i)
{
......@@ -432,13 +432,13 @@ Foam::labelList Foam::meshRefinement::nearestPatch
forAll(pp, i)
{
patchFaces[nFaces] = pp.start()+i;
patchData[nFaces] = topoDistanceData(patchi, 0);
patchData[nFaces] = topoDistanceData<label>(0, patchi);
nFaces++;
}
}
// Propagate information inwards
FaceCellWave<topoDistanceData> deltaCalc
FaceCellWave<topoDistanceData<label>> deltaCalc
(
mesh_,
patchFaces,
......@@ -542,12 +542,12 @@ Foam::labelList Foam::meshRefinement::nearestIntersection
labelList nearestRegion(mesh_.nFaces(), defaultRegion);
// Field on cells and faces.
List<topoDistanceData> cellData(mesh_.nCells());
List<topoDistanceData> faceData(mesh_.nFaces());
List<topoDistanceData<label>> cellData(mesh_.nCells());
List<topoDistanceData<label>> faceData(mesh_.nFaces());
// Start walking from all intersected faces
DynamicList<label> patchFaces(start.size());
DynamicList<topoDistanceData> patchData(start.size());
DynamicList<topoDistanceData<label>> patchData(start.size());
forAll(start, i)
{
label facei = testFaces[i];
......@@ -555,18 +555,18 @@ Foam::labelList Foam::meshRefinement::nearestIntersection
{
patchFaces.append(facei);
label regioni = surfaces_.globalRegion(surface1[i], region1[i]);
patchData.append(topoDistanceData(regioni, 0));
patchData.append(topoDistanceData<label>(0, regioni));
}
else if (surface2[i] != -1)
{
patchFaces.append(facei);
label regioni = surfaces_.globalRegion(surface2[i], region2[i]);
patchData.append(topoDistanceData(regioni, 0));
patchData.append(topoDistanceData<label>(0, regioni));
}
}
// Propagate information inwards
FaceCellWave<topoDistanceData> deltaCalc
FaceCellWave<topoDistanceData<label>> deltaCalc
(
mesh_,
patchFaces,
......
......@@ -47,7 +47,7 @@ License
#include "OBJstream.H"
#include "patchFaceOrientation.H"
#include "PatchEdgeFaceWave.H"
#include "patchEdgeFaceRegion.H"
#include "edgeTopoDistanceData.H"
#include "polyMeshAdder.H"
#include "IOmanip.H"
#include "refinementParameters.H"
......@@ -3507,8 +3507,8 @@ Foam::label Foam::meshRefinement::markPatchZones
labelList& faceToZone
) const
{
List<patchEdgeFaceRegion> allEdgeInfo(patch.nEdges());
List<patchEdgeFaceRegion> allFaceInfo(patch.size());
List<edgeTopoDistanceData<label>> allEdgeInfo(patch.nEdges());
List<edgeTopoDistanceData<label>> allFaceInfo(patch.size());
// Protect all non-manifold edges
......@@ -3519,7 +3519,7 @@ Foam::label Foam::meshRefinement::markPatchZones
{
if (nMasterFacesPerEdge[edgeI] > 2)
{
allEdgeInfo[edgeI] = -2;
allEdgeInfo[edgeI] = edgeTopoDistanceData<label>(0, -2);
nProtected++;
}
}
......@@ -3532,12 +3532,12 @@ Foam::label Foam::meshRefinement::markPatchZones
// Hand out zones
DynamicList<label> changedEdges;
DynamicList<patchEdgeFaceRegion> changedInfo;
DynamicList<edgeTopoDistanceData<label>> changedInfo;
const scalar tol = PatchEdgeFaceWave
<
indirectPrimitivePatch,
patchEdgeFaceRegion
edgeTopoDistanceData<label>
>::propagationTol();
int dummyTrackData;
......@@ -3577,11 +3577,11 @@ Foam::label Foam::meshRefinement::markPatchZones
if (procI == Pstream::myProcNo())
{
patchEdgeFaceRegion& faceInfo = allFaceInfo[seedFaceI];
edgeTopoDistanceData<label>& faceInfo = allFaceInfo[seedFaceI];
// Set face
faceInfo = currentZoneI;
faceInfo = edgeTopoDistanceData<label>(0, currentZoneI);
// .. and seed its edges
const labelList& fEdges = patch.faceEdges()[seedFaceI];
......@@ -3589,7 +3589,7 @@ Foam::label Foam::meshRefinement::markPatchZones
{
label edgeI = fEdges[fEdgeI];
patchEdgeFaceRegion& edgeInfo = allEdgeInfo[edgeI];
edgeTopoDistanceData<label>& edgeInfo = allEdgeInfo[edgeI];
if
(
......@@ -3622,7 +3622,7 @@ Foam::label Foam::meshRefinement::markPatchZones
PatchEdgeFaceWave
<
indirectPrimitivePatch,
patchEdgeFaceRegion
edgeTopoDistanceData<label>
> calc
(
mesh_,
......@@ -3648,7 +3648,7 @@ Foam::label Foam::meshRefinement::markPatchZones
<< " at " << patch.faceCentres()[faceI]
<< exit(FatalError);
}
faceToZone[faceI] = allFaceInfo[faceI].region();
faceToZone[faceI] = allFaceInfo[faceI].data();
}
return currentZoneI;
......
......@@ -94,7 +94,6 @@ patchWave = $(algorithms)/PatchEdgeFaceWave
$(patchWave)/PatchEdgeFaceWaveName.C
$(patchWave)/patchEdgeFaceInfo.C
$(patchWave)/patchPatchDist.C
$(patchWave)/patchEdgeFaceRegion.C
$(patchWave)/patchEdgeFaceRegions.C
......@@ -297,8 +296,6 @@ PatchFunction1/makePatchFunction1s.C
PatchFunction1/coordinateLabelScaling.C
meshStructure/meshStructure.C
meshStructure/topoDistanceData.C
meshStructure/pointTopoDistanceData.C
output/foamVtkIndPatchWriter.C
output/foamVtkWriteTopoSet.C
......
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
template<class Type, class PrimitivePatchType>
Foam::Ostream& Foam::operator<<
(
Foam::Ostream& os,
const Foam::edgeTopoDistanceData<Type, PrimitivePatchType>& wDist
)
{
return os << wDist.distance_ << token::SPACE << wDist.data_;
}
template<class Type, class PrimitivePatchType>
Foam::Istream& Foam::operator>>
(
Foam::Istream& is,
Foam::edgeTopoDistanceData<Type, PrimitivePatchType>& wDist
)
{
return is >> wDist.distance_ >> wDist.data_;
}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2012-2016 OpenFOAM Foundation
Copyright (C) 2019,2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::edgeTopoDistanceData
Description
For use with PatchEdgeFaceWave. Determines topological distance to
starting edges. Templated on passive transported data.
SourceFiles
edgeTopoDistanceDataI.H
edgeTopoDistanceData.C
\*---------------------------------------------------------------------------*/
#ifndef edgeTopoDistanceData_H
#define edgeTopoDistanceData_H
#include "point.H"
#include "tensor.H"
#include "indirectPrimitivePatch.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward Declarations
class polyPatch;
class polyMesh;
template<class Type, class PrimitivePatchType>
class edgeTopoDistanceData;
template<class Type, class PrimitivePatchType>
Istream& operator>>
(
Istream&,
edgeTopoDistanceData<Type, PrimitivePatchType>&
);
template<class Type, class PrimitivePatchType>
Ostream& operator<<
(
Ostream&,
const edgeTopoDistanceData<Type, PrimitivePatchType>&
);
/*---------------------------------------------------------------------------*\
Class edgeTopoDistanceData Declaration
\*---------------------------------------------------------------------------*/
template<class Type, class PrimitivePatchType = indirectPrimitivePatch>
class edgeTopoDistanceData
{
protected:
// Protected data
//- Distance
label distance_;
//- Starting data
Type data_;
public:
typedef Type dataType;
// Constructors
//- Construct null with invalid (-1) for distance, null constructor
// for data
inline edgeTopoDistanceData();
//- Construct from distance, data
inline edgeTopoDistanceData
(
const label distance,
const Type& data
);
// Member Functions
// Access
inline label distance() const
{
return distance_;
}
inline const Type& data() const
{
return data_;
}
// Needed by PatchEdgeFaceWave
//- Check whether origin has been changed at all or
// still contains original (invalid) value.
template<class TrackingData>
inline bool valid(TrackingData& td) const;
//- Apply rotation matrix
template<class TrackingData>
inline void transform
(
const polyMesh& mesh,
const PrimitivePatchType& patch,
const tensor& rotTensor,
const scalar tol,
TrackingData& td
);
//- Influence of face on edge
template<class TrackingData>
inline bool updateEdge
(
const polyMesh& mesh,
const PrimitivePatchType& patch,
const label edgeI,
const label facei,
const edgeTopoDistanceData<Type, PrimitivePatchType>& faceInfo,
const scalar tol,
TrackingData& td
);
//- New information for edge (from e.g. coupled edge)
template<class TrackingData>
inline bool updateEdge
(
const polyMesh& mesh,
const PrimitivePatchType& patch,
const edgeTopoDistanceData<Type, PrimitivePatchType>& edgeInfo,
const bool sameOrientation,
const scalar tol,
TrackingData& td
);
//- Influence of edge on face.
template<class TrackingData>
inline bool updateFace
(
const polyMesh& mesh,
const PrimitivePatchType& patch,
const label facei,
const label edgeI,
const edgeTopoDistanceData<Type, PrimitivePatchType>& edgeInfo,
const scalar tol,
TrackingData& td
);
//- Same (like operator==)
template<class TrackingData>
inline bool equal
(
const edgeTopoDistanceData<Type, PrimitivePatchType>&,
TrackingData&
) const;
// Member Operators
// Needed for List IO
inline bool operator==
(
const edgeTopoDistanceData<Type, PrimitivePatchType>&
) const;
inline bool operator!=
(
const edgeTopoDistanceData<Type, PrimitivePatchType>&
) const;
// IOstream Operators
friend Ostream& operator<< <Type, PrimitivePatchType>
(
Ostream&,
const edgeTopoDistanceData<Type, PrimitivePatchType>&
);
friend Istream& operator>> <Type, PrimitivePatchType>
(
Istream&,
edgeTopoDistanceData<Type, PrimitivePatchType>&
);
};
// * * * * * * * * * * * * * * * * * Traits * * * * * * * * * * * * * * * * //
//- Data are contiguous if data type is contiguous
template<class Type, class PrimitivePatchType>
struct is_contiguous<edgeTopoDistanceData<Type, PrimitivePatchType>> :
is_contiguous<Type> {};
//- Data are contiguous label if data type is label
template<class Type, class PrimitivePatchType>
struct is_contiguous_label<edgeTopoDistanceData<Type, PrimitivePatchType>> :
is_contiguous_label<Type> {};
//- Data are contiguous scalar if data type is scalar
template<class Type, class PrimitivePatchType>
struct is_contiguous_scalar<edgeTopoDistanceData<Type, PrimitivePatchType>> :
is_contiguous_scalar<Type>{};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //