directMethod.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 | Copyright (C) 2013-2015 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "directMethod.H"
27 #include "indexedOctree.H"
28 #include "treeDataCell.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35  defineTypeNameAndDebug(directMethod, 0);
36  addToRunTimeSelectionTable(meshToMeshMethod, directMethod, components);
37 }
38 
39 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
40 
42 (
43  const label srcCellI,
44  const label tgtCellI
45 ) const
46 {
47  return tgt_.pointInCell
48  (
49  src_.cellCentres()[srcCellI],
50  tgtCellI,
51  polyMesh::FACE_PLANES
52  );
53 }
54 
55 
57 (
58  const labelList& srcCellIDs,
59  const boolList& mapFlag,
60  const label startSeedI,
61  label& srcSeedI,
62  label& tgtSeedI
63 ) const
64 {
65  const cellList& srcCells = src_.cells();
66  const faceList& srcFaces = src_.faces();
67  const pointField& srcPts = src_.points();
68 
69  for (label i = startSeedI; i < srcCellIDs.size(); i++)
70  {
71  label srcI = srcCellIDs[i];
72 
73  if (mapFlag[srcI])
74  {
75  const point srcCtr(srcCells[srcI].centre(srcPts, srcFaces));
76  label tgtI = tgt_.cellTree().findInside(srcCtr);
77 
78  if (tgtI != -1 && intersect(srcI, tgtI))
79  {
80  srcSeedI = srcI;
81  tgtSeedI = tgtI;
82 
83  return true;
84  }
85  }
86  }
87 
88  if (debug)
89  {
90  Pout<< "could not find starting seed" << endl;
91  }
92 
93  return false;
94 }
95 
96 
98 (
99  labelListList& srcToTgtCellAddr,
100  scalarListList& srcToTgtCellWght,
101  labelListList& tgtToSrcCellAddr,
102  scalarListList& tgtToSrcCellWght,
103  const label srcSeedI,
104  const label tgtSeedI,
105  const labelList& srcCellIDs, // not used
106  boolList& mapFlag,
107  label& startSeedI
108 )
109 {
110  // store a list of src cells already mapped
111  labelList srcTgtSeed(src_.nCells(), -1);
112 
113  List<DynamicList<label> > srcToTgt(src_.nCells());
114  List<DynamicList<label> > tgtToSrc(tgt_.nCells());
115 
116  DynamicList<label> srcSeeds(10);
117 
118  const scalarField& srcVc = src_.cellVolumes();
119  const scalarField& tgtVc = tgt_.cellVolumes();
120 
121  label srcCellI = srcSeedI;
122  label tgtCellI = tgtSeedI;
123 
124  do
125  {
126  // store src/tgt cell pair
127  srcToTgt[srcCellI].append(tgtCellI);
128  tgtToSrc[tgtCellI].append(srcCellI);
129 
130  // mark source cell srcSeedI as matched
131  mapFlag[srcCellI] = false;
132 
133  // accumulate intersection volume
134  V_ += srcVc[srcCellI];
135 
136  // find new source seed cell
137  appendToDirectSeeds
138  (
139  mapFlag,
140  srcTgtSeed,
141  srcSeeds,
142  srcCellI,
143  tgtCellI
144  );
145  }
146  while (srcCellI >= 0);
147 
148  // transfer addressing into persistent storage
149  forAll(srcToTgtCellAddr, i)
150  {
151  srcToTgtCellWght[i] = scalarList(srcToTgt[i].size(), srcVc[i]);
152  srcToTgtCellAddr[i].transfer(srcToTgt[i]);
153  }
154 
155  forAll(tgtToSrcCellAddr, i)
156  {
157  tgtToSrcCellWght[i] = scalarList(tgtToSrc[i].size(), tgtVc[i]);
158  tgtToSrcCellAddr[i].transfer(tgtToSrc[i]);
159  }
160 }
161 
162 
164 (
165  boolList& mapFlag,
166  labelList& srcTgtSeed,
167  DynamicList<label>& srcSeeds,
168  label& srcSeedI,
169  label& tgtSeedI
170 ) const
171 {
172  const labelList& srcNbr = src_.cellCells()[srcSeedI];
173  const labelList& tgtNbr = tgt_.cellCells()[tgtSeedI];
174 
175  forAll(srcNbr, i)
176  {
177  label srcI = srcNbr[i];
178 
179  if (mapFlag[srcI] && (srcTgtSeed[srcI] == -1))
180  {
181  // source cell srcI not yet mapped
182 
183  // identfy if target cell exists for source cell srcI
184  bool found = false;
185  forAll(tgtNbr, j)
186  {
187  label tgtI = tgtNbr[j];
188 
189  if (intersect(srcI, tgtI))
190  {
191  // new match - append to lists
192  found = true;
193 
194  srcTgtSeed[srcI] = tgtI;
195  srcSeeds.append(srcI);
196 
197  break;
198  }
199  }
200 
201  if (!found)
202  {
203  // no match available for source cell srcI
204  mapFlag[srcI] = false;
205  }
206  }
207  }
208 
209  if (srcSeeds.size())
210  {
211  srcSeedI = srcSeeds.remove();
212  tgtSeedI = srcTgtSeed[srcSeedI];
213  }
214  else
215  {
216  srcSeedI = -1;
217  tgtSeedI = -1;
218  }
219 }
220 
221 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
222 
224 (
225  const polyMesh& src,
226  const polyMesh& tgt
227 )
228 :
229  meshToMeshMethod(src, tgt)
230 {}
231 
232 
233 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
234 
236 {}
237 
238 
239 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
240 
242 (
243  labelListList& srcToTgtAddr,
244  scalarListList& srcToTgtWght,
245  pointListList& srcToTgtVec,
246  labelListList& tgtToSrcAddr,
247  scalarListList& tgtToSrcWght,
248  pointListList& tgtToSrcVec
249 )
250 {
251  bool ok = initialise
252  (
253  srcToTgtAddr,
254  srcToTgtWght,
255  tgtToSrcAddr,
256  tgtToSrcWght
257  );
258 
259  if (!ok)
260  {
261  return;
262  }
263 
264  // (potentially) participating source mesh cells
265  const labelList srcCellIDs(maskCells());
266 
267  // list to keep track of whether src cell can be mapped
268  boolList mapFlag(src_.nCells(), false);
269  UIndirectList<bool>(mapFlag, srcCellIDs) = true;
270 
271  // find initial point in tgt mesh
272  label srcSeedI = -1;
273  label tgtSeedI = -1;
274  label startSeedI = 0;
275 
276  bool startWalk =
277  findInitialSeeds
278  (
279  srcCellIDs,
280  mapFlag,
281  startSeedI,
282  srcSeedI,
283  tgtSeedI
284  );
285 
286  if (startWalk)
287  {
288  calculateAddressing
289  (
290  srcToTgtAddr,
291  srcToTgtWght,
292  tgtToSrcAddr,
293  tgtToSrcWght,
294  srcSeedI,
295  tgtSeedI,
296  srcCellIDs,
297  mapFlag,
298  startSeedI
299  );
300  }
301  else
302  {
303  // if meshes are collocated, after inflating the source mesh bounding
304  // box tgt mesh cells may be transferred, but may still not overlap
305  // with the source mesh
306  return;
307  }
308 }
309 
310 
311 // ************************************************************************* //
Foam::scalarList
List< scalar > scalarList
A List of scalars.
Definition: scalarList.H:50
Foam::directMethod::calculateAddressing
virtual void calculateAddressing(labelListList &srcToTgtCellAddr, scalarListList &srcToTgtCellWght, labelListList &tgtToSrcCellAddr, scalarListList &tgtToSrcCellWght, const label srcSeedI, const label tgtSeedI, const labelList &srcCellIDs, boolList &mapFlag, label &startSeedI)
Calculate the mesh-to-mesh addressing and weights.
Definition: directMethod.C:98
directMethod.H
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::DynamicList< label >
Foam::directMethod::~directMethod
virtual ~directMethod()
Destructor.
Definition: directMethod.C:235
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
indexedOctree.H
Foam::directMethod::appendToDirectSeeds
virtual void appendToDirectSeeds(boolList &mapFlag, labelList &srcTgtSeed, DynamicList< label > &srcSeeds, label &srcSeedI, label &tgtSeedI) const
Append to list of src mesh seed indices.
Definition: directMethod.C:164
Foam::List::transfer
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Foam::meshToMeshMethod
Base class for mesh-to-mesh calculation methods.
Definition: meshToMeshMethod.H:48
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:59
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::List::append
void append(const T &)
Append an element at the end of the list.
Foam::directMethod::directMethod
directMethod(const directMethod &)
Disallow default bitwise copy construct.
intersect
Raster intersect(const Raster &rast1, const Raster &rast2)
Definition: Raster.C:666
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
treeDataCell.H
Foam::directMethod::intersect
virtual bool intersect(const label srcCellI, const label tgtCellI) const
Return the true if cells intersect.
Definition: directMethod.C:42
Foam::DynamicList::append
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
Foam::directMethod::calculate
virtual void calculate(labelListList &srcToTgtAddr, scalarListList &srcToTgtWght, pointListList &srcToTgtVec, labelListList &tgtToSrcAddr, scalarListList &tgtToSrcWght, pointListList &tgtToSrcVec)
Calculate addressing and weights and optionally offset vectors.
Definition: directMethod.C:242
found
bool found
Definition: TABSMDCalcMethod2.H:32
Foam::Pout
prefixOSstream Pout(cout, "Pout")
Definition: IOstreams.H:53
Foam::Vector< scalar >
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::DynamicList::remove
T remove()
Remove and return the top element.
Definition: DynamicListI.H:365
Foam::UIndirectList
A List with indirect addressing.
Definition: fvMatrix.H:106
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::directMethod::findInitialSeeds
virtual bool findInitialSeeds(const labelList &srcCellIDs, const boolList &mapFlag, const label startSeedI, label &srcSeedI, label &tgtSeedI) const
Find indices of overlapping cells in src and tgt meshes - returns.
Definition: directMethod.C:57
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)