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 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();
59  Pstream::parRun() = false;
60 
61  label nSeeds = 0;
62 
63  if (tgt.nCells() == 0)
64  {
65  srcToTgtAddr.setSize(src.nCells());
66  srcToTgtAddr = -1;
67  }
68  else
69  {
70  const treeBoundBox& tgtBb = tgt.cellTree().bb();
71 
72  DynamicList<label> changedFaces(src.nFaces()/100 + 100);
73  DynamicList<meshToMeshData> changedFacesInfo(changedFaces.size());
74 
75  List<meshToMeshData> cellData(src.nCells());
76  List<meshToMeshData> faceData(src.nFaces());
77 
79 
80  label startCelli = 0;
81 
82  while (true)
83  {
84  changedFaces.clear();
85  changedFacesInfo.clear();
86 
87  // Search for starting seed
88  for (; startCelli < src.nCells(); startCelli++)
89  {
90  if (!cellData[startCelli].valid(td))
91  {
92  nSeeds++;
93  const point& cc = src.cellCentres()[startCelli];
94 
95  if (!tgtBb.contains(cc))
96  {
97  // Point outside local bb of tgt mesh. No need to
98  // search. Register as no correspondence
99  cellData[startCelli] = meshToMeshData(-1);
100  }
101  else
102  {
103  label tgtCelli = tgt.findCell(cc, polyMesh::CELL_TETS);
104  if (tgtCelli != -1)
105  {
106  // Insert any face of cell
107  label facei = src.cells()[startCelli][0];
108  changedFaces.append(facei);
109  changedFacesInfo.append(meshToMeshData(tgtCelli));
110  break;
111  }
112  else
113  {
114  // Register as no correspondence
115  cellData[startCelli] = meshToMeshData(-1);
116  }
117  }
118  }
119  }
120 
121  if (returnReduce(changedFaces.empty(), andOp<bool>()))
122  {
123  break;
124  }
125 
127  (
128  src,
129  changedFaces,
130  changedFacesInfo,
131  faceData,
132  cellData,
133  src.globalData().nTotalCells(), // max iterations
134  td
135  );
136  }
137 
138  // Copy into srcToTgt
139  srcToTgtAddr.setSize(src.nCells());
140 
141  forAll(cellData, celli)
142  {
143  srcToTgtAddr[celli] = cellData[celli].tgtCelli_;
144  }
145  }
146 
147  Pstream::parRun() = oldParRun;
148 
149  if (debug)
150  {
151  Pout<< "nSeeds:" << returnReduce(nSeeds, sumOp<label>())
152  << " out of nCells:" << returnReduce(src.nCells(), sumOp<label>())
153  << endl;
154  }
155 }
156 
157 
158 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
159 
160 Foam::waveMethod::waveMethod
161 (
162  const polyMesh& src,
163  const polyMesh& tgt
164 )
165 :
166  meshToMeshMethod(src, tgt)
167 {}
168 
169 
170 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
171 
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::primitiveMesh::nFaces
label nFaces() const
Number of mesh faces.
Definition: primitiveMeshI.H:90
Foam::treeBoundBox
Standard boundBox with extra functionality for use in octree.
Definition: treeBoundBox.H:87
Foam::primitiveMesh::cells
const cellList & cells() const
Definition: primitiveMeshCells.C:138
Foam::globalMeshData::nTotalCells
label nTotalCells() const
Return total number of cells in decomposed mesh.
Definition: globalMeshData.H:394
Foam::List::append
void append(const T &val)
Append an element at the end of the list.
Definition: ListI.H:182
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
Foam::Pout
prefixOSstream Pout
An Ostream wrapper for parallel output to std::cout.
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:290
Foam::meshToMeshMethod
Base class for mesh-to-mesh calculation methods.
Definition: meshToMeshMethod.H:51
Foam::primitiveMesh::nCells
label nCells() const
Number of mesh cells.
Definition: primitiveMeshI.H:96
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:62
Foam::meshToMeshData::trackData
Class used to pass non-cell data to the update function.
Definition: meshToMeshData.H:67
Foam::andOp
Definition: ops.H:233
Foam::waveMethod::~waveMethod
virtual ~waveMethod()
Destructor.
Definition: waveMethod.C:172
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:895
Foam::polyMesh::findCell
label findCell(const point &p, const cellDecomposition=CELL_TETS) const
Find cell enclosing this location and return index.
Definition: polyMesh.C:1453
Foam::primitiveMesh::cellCentres
const vectorField & cellCentres() const
Definition: primitiveMeshCellCentresAndVols.C:176
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::polyMesh::globalData
const globalMeshData & globalData() const
Return parallel info.
Definition: polyMesh.C:1241
Foam::List::setSize
void setSize(const label newSize)
Alias for resize(const label)
Definition: ListI.H:146
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
waveMethod.H
Foam::polyMesh::tetBasePtIs
const labelIOList & tetBasePtIs() const
Return the tetBasePtIs.
Definition: polyMesh.C:861