waveMethod.C
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2017-2021 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26\*---------------------------------------------------------------------------*/
27
28#include "waveMethod.H"
29#include "meshToMeshData.H"
30#include "FaceCellWave.H"
32#include "treeDataCell.H"
33
34// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35
36namespace Foam
37{
40}
41
42// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
43
45(
46 const polyMesh& src,
47 const polyMesh& tgt,
48 labelList& srcToTgtAddr
49)
50{
51 // If parallel running a local domain might have zero cells thus never
52 // constructing the face-diagonal decomposition which uses parallel
53 // transfers.
54 (void)tgt.tetBasePtIs();
55
56 // The actual matching is only w.r.t local cells so cannot be run in
57 // parallel.
58 const bool oldParRun = Pstream::parRun(false);
59
60 label nSeeds = 0;
61
62 if (tgt.nCells() == 0)
63 {
64 srcToTgtAddr.setSize(src.nCells());
65 srcToTgtAddr = -1;
66 }
67 else
68 {
69 const treeBoundBox& tgtBb = tgt.cellTree().bb();
70
71 DynamicList<label> changedFaces(src.nFaces()/100 + 100);
72 DynamicList<meshToMeshData> changedFacesInfo(changedFaces.size());
73
76
78
79 label startCelli = 0;
80
81 while (true)
82 {
83 changedFaces.clear();
84 changedFacesInfo.clear();
85
86 // Search for starting seed
87 for (; startCelli < src.nCells(); startCelli++)
88 {
89 if (!cellData[startCelli].valid(td))
90 {
91 nSeeds++;
92 const point& cc = src.cellCentres()[startCelli];
93
94 if (!tgtBb.contains(cc))
95 {
96 // Point outside local bb of tgt mesh. No need to
97 // search. Register as no correspondence
98 cellData[startCelli] = meshToMeshData(-1);
99 }
100 else
101 {
102 label tgtCelli = tgt.findCell(cc, polyMesh::CELL_TETS);
103 if (tgtCelli != -1)
104 {
105 // Insert any face of cell
106 label facei = src.cells()[startCelli][0];
107 changedFaces.append(facei);
108 changedFacesInfo.append(meshToMeshData(tgtCelli));
109 break;
110 }
111 else
112 {
113 // Register as no correspondence
114 cellData[startCelli] = meshToMeshData(-1);
115 }
116 }
117 }
118 }
119
120 if (returnReduce(changedFaces.empty(), andOp<bool>()))
121 {
122 break;
123 }
124
126 (
127 src,
128 changedFaces,
129 changedFacesInfo,
130 faceData,
131 cellData,
132 src.globalData().nTotalCells()+1, // max iterations
133 td
134 );
135 }
136
137 // Copy into srcToTgt
138 srcToTgtAddr.setSize(src.nCells());
139
140 forAll(cellData, celli)
141 {
142 srcToTgtAddr[celli] = cellData[celli].tgtCell();
143 }
144 }
145
146 Pstream::parRun(oldParRun); // Restore parallel state
147
148 if (debug)
149 {
150 Pout<< "nSeeds:" << returnReduce(nSeeds, sumOp<label>())
151 << " out of nCells:" << returnReduce(src.nCells(), sumOp<label>())
152 << endl;
153 }
154}
155
156
157// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
158
160(
161 const polyMesh& src,
162 const polyMesh& tgt
163)
164:
165 meshToMeshMethod(src, tgt)
166{}
167
168
169// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
170
172{}
173
174
175// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
176
178(
179 labelListList& srcToTgtAddr,
180 scalarListList& srcToTgtWght,
181 pointListList& srcToTgtVec,
182 labelListList& tgtToSrcAddr,
183 scalarListList& tgtToSrcWght,
184 pointListList& tgtToSrcVec
185)
186{
187 {
188 labelList srcToTgt(src_.nCells());
189 calculate(src_, tgt_, srcToTgt);
190 srcToTgtAddr.setSize(srcToTgt.size());
191 srcToTgtWght.setSize(srcToTgt.size());
192 forAll(srcToTgtAddr, celli)
193 {
194 srcToTgtAddr[celli].setSize(1);
195 srcToTgtAddr[celli][0] = srcToTgt[celli];
196 srcToTgtWght[celli].setSize(1);
197 srcToTgtWght[celli][0] = src_.cellVolumes()[celli];
198 }
199 }
200
201 {
202 labelList tgtToSrc(tgt_.nCells());
203 calculate(tgt_, src_, tgtToSrc);
204 tgtToSrcAddr.setSize(tgtToSrc.size());
205 tgtToSrcWght.setSize(tgtToSrc.size());
206 forAll(tgtToSrcAddr, celli)
207 {
208 tgtToSrcAddr[celli].setSize(1);
209 tgtToSrcAddr[celli][0] = tgtToSrc[celli];
210 tgtToSrcWght[celli].setSize(1);
211 tgtToSrcWght[celli][0] = tgt_.cellVolumes()[celli];
212 }
213 }
214}
215
216
217// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:72
void clear() noexcept
Clear the addressed list, i.e. set the size to zero.
Definition: DynamicListI.H:391
void append(const T &val)
Copy append an element to the end of this list.
Definition: DynamicListI.H:503
Wave propagation of information through grid. Every iteration information goes through one layer of c...
Definition: FaceCellWave.H:81
void setSize(const label n)
Alias for resize()
Definition: List.H:218
bool empty() const noexcept
True if the UList is empty (ie, size() is zero)
Definition: UListI.H:427
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
static bool & parRun() noexcept
Test if this a parallel run.
Definition: UPstream.H:433
label nTotalCells() const noexcept
Return total number of cells in decomposed mesh.
Class used to pass non-cell data to the update function.
Transfers refinement levels such that slow transition between levels is maintained....
Base class for mesh-to-mesh calculation methods.
const polyMesh & src() const
Return const access to the source mesh.
const polyMesh & tgt() const
Return const access to the target mesh.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
label findCell(const point &p, const cellDecomposition=CELL_TETS) const
Find cell enclosing this location and return index.
Definition: polyMesh.C:1522
const labelIOList & tetBasePtIs() const
Return the tetBasePtIs.
Definition: polyMesh.C:906
const globalMeshData & globalData() const
Return parallel info.
Definition: polyMesh.C:1310
const indexedOctree< treeDataCell > & cellTree() const
Return the cell search tree.
Definition: polyMesh.C:940
const vectorField & cellCentres() const
label nCells() const noexcept
Number of mesh cells.
label nFaces() const noexcept
Number of mesh faces.
const cellList & cells() const
Standard boundBox with extra functionality for use in octree.
Definition: treeBoundBox.H:89
bool contains(const vector &dir, const point &) const
Contains point (inside or on edge) and moving in direction.
Definition: treeBoundBox.C:320
Direct (one-to-one cell correspondence) mesh-to-mesh interpolation class.
Definition: waveMethod.H:53
virtual ~waveMethod()
Destructor.
Definition: waveMethod.C:171
static void calculate(const polyMesh &src, const polyMesh &tgt, labelList &srcToTgtAddr)
Calculate addressing.
Definition: waveMethod.C:45
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
Namespace for OpenFOAM.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
T returnReduce(const T &value, const BinaryOp &bop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Reduce (copy) and return value.
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333