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 -------------------------------------------------------------------------------
10 License
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 
36 namespace Foam
37 {
38  defineTypeNameAndDebug(waveMethod, 0);
39  addToRunTimeSelectionTable(meshToMeshMethod, waveMethod, components);
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 
74  List<meshToMeshData> cellData(src.nCells());
75  List<meshToMeshData> faceData(src.nFaces());
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 
159 Foam::waveMethod::waveMethod
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 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::returnReduce
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
Definition: PstreamReduceOps.H:94
Foam::DynamicList< label >
Foam::waveMethod::calculate
static void calculate(const polyMesh &src, const polyMesh &tgt, labelList &srcToTgtAddr)
Calculate addressing.
Definition: waveMethod.C:45
Foam::treeBoundBox
Standard boundBox with extra functionality for use in octree.
Definition: treeBoundBox.H:86
Foam::primitiveMesh::cells
const cellList & cells() const
Definition: primitiveMeshCells.C:138
Foam::List::append
void append(const T &val)
Append an element at the end of the list.
Definition: ListI.H:175
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::Pout
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
Foam::meshToMeshData
Transfers refinement levels such that slow transition between levels is maintained....
Definition: meshToMeshData.H:62
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::sumOp
Definition: ops.H:213
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::meshToMeshMethod
Base class for mesh-to-mesh calculation methods.
Definition: meshToMeshMethod.H:51
Foam::primitiveMesh::nCells
label nCells() const noexcept
Number of mesh cells.
Definition: primitiveMeshI.H:96
Foam::meshToMeshData::trackData
Class used to pass non-cell data to the update function.
Definition: meshToMeshData.H:75
Foam::List::setSize
void setSize(const label n)
Alias for resize()
Definition: List.H:222
Foam::andOp
Definition: ops.H:233
Foam::waveMethod::~waveMethod
virtual ~waveMethod()
Destructor.
Definition: waveMethod.C:171
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
treeDataCell.H
Foam::FaceCellWave
Wave propagation of information through grid. Every iteration information goes through one layer of c...
Definition: FaceCellWave.H:78
Foam::polyMesh::cellTree
const indexedOctree< treeDataCell > & cellTree() const
Return the cell search tree.
Definition: polyMesh.C:926
Foam::polyMesh::findCell
label findCell(const point &p, const cellDecomposition=CELL_TETS) const
Find cell enclosing this location and return index.
Definition: polyMesh.C:1507
Foam::primitiveMesh::cellCentres
const vectorField & cellCentres() const
Definition: primitiveMeshCellCentresAndVols.C:84
meshToMeshData.H
Foam::treeBoundBox::contains
bool contains(const vector &dir, const point &) const
Contains point (inside or on edge) and moving in direction.
Definition: treeBoundBox.C:320
Foam::Vector< scalar >
Foam::List< label >
FaceCellWave.H
Foam::globalMeshData::nTotalCells
label nTotalCells() const noexcept
Return total number of cells in decomposed mesh.
Definition: globalMeshData.H:371
Foam::primitiveMesh::nFaces
label nFaces() const noexcept
Number of mesh faces.
Definition: primitiveMeshI.H:90
Foam::polyMesh::globalData
const globalMeshData & globalData() const
Return parallel info.
Definition: polyMesh.C:1295
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
waveMethod.H
Foam::polyMesh::tetBasePtIs
const labelIOList & tetBasePtIs() const
Return the tetBasePtIs.
Definition: polyMesh.C:892