FreeFOAM The Cross-Platform CFD Toolkit
meshToMesh.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) 1991-2010 OpenCFD Ltd.
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 "meshToMesh.H"
29 
30 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 
37 defineTypeNameAndDebug(meshToMesh, 0);
38 
39 const scalar meshToMesh::directHitTol = 1e-5;
40 
41 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
42 
44 (
45  const fvMesh& meshFrom,
46  const fvMesh& meshTo,
47  const HashTable<word>& patchMap,
48  const wordList& cuttingPatchNames
49 )
50 :
51  fromMesh_(meshFrom),
52  toMesh_(meshTo),
53  patchMap_(patchMap),
54  cellAddressing_(toMesh_.nCells()),
55  boundaryAddressing_(toMesh_.boundaryMesh().size()),
56  inverseDistanceWeightsPtr_(NULL)
57 {
58  forAll (fromMesh_.boundaryMesh(), patchi)
59  {
60  fromMeshPatches_.insert
61  (
62  fromMesh_.boundaryMesh()[patchi].name(),
63  patchi
64  );
65  }
66 
67  forAll (toMesh_.boundaryMesh(), patchi)
68  {
69  toMeshPatches_.insert
70  (
71  toMesh_.boundaryMesh()[patchi].name(),
72  patchi
73  );
74  }
75 
76  forAll (cuttingPatchNames, i)
77  {
78  if (toMeshPatches_.found(cuttingPatchNames[i]))
79  {
80  cuttingPatches_.insert
81  (
82  cuttingPatchNames[i],
83  toMeshPatches_.find(cuttingPatchNames[i])()
84  );
85  }
86  else
87  {
88  WarningIn
89  (
90  "meshToMesh::meshToMesh"
91  "(const fvMesh& meshFrom, const fvMesh& meshTo,"
92  "const HashTable<word>& patchMap,"
93  "const wordList& cuttingPatchNames)"
94  ) << "Cannot find cutting-patch " << cuttingPatchNames[i]
95  << " in destination mesh" << endl;
96  }
97  }
98 
99  forAll (toMesh_.boundaryMesh(), patchi)
100  {
101  // Add the processor patches in the toMesh to the cuttingPatches list
102  if (isA<processorPolyPatch>(toMesh_.boundaryMesh()[patchi]))
103  {
104  cuttingPatches_.insert
105  (
106  toMesh_.boundaryMesh()[patchi].name(),
107  patchi
108  );
109  }
110  }
111 
112  calcAddressing();
113 }
114 
115 
117 (
118  const fvMesh& meshFrom,
119  const fvMesh& meshTo
120 )
121 :
122  fromMesh_(meshFrom),
123  toMesh_(meshTo),
124  cellAddressing_(toMesh_.nCells()),
125  boundaryAddressing_(toMesh_.boundaryMesh().size()),
126  inverseDistanceWeightsPtr_(NULL)
127 {
128  // check whether both meshes have got the same number
129  // of boundary patches
130  if (fromMesh_.boundary().size() != toMesh_.boundary().size())
131  {
133  (
134  "meshToMesh::meshToMesh"
135  "(const fvMesh& meshFrom, const fvMesh& meshTo)"
136  ) << "Incompatible meshes: different number of patches, "
137  << "fromMesh = " << fromMesh_.boundary().size()
138  << ", toMesh = " << toMesh_.boundary().size()
139  << exit(FatalError);
140  }
141 
142  forAll (fromMesh_.boundaryMesh(), patchi)
143  {
144  if
145  (
146  fromMesh_.boundaryMesh()[patchi].name()
147  != toMesh_.boundaryMesh()[patchi].name()
148  )
149  {
151  (
152  "meshToMesh::meshToMesh"
153  "(const fvMesh& meshFrom, const fvMesh& meshTo)"
154  ) << "Incompatible meshes: different patch names for patch "
155  << patchi
156  << ", fromMesh = " << fromMesh_.boundary()[patchi].name()
157  << ", toMesh = " << toMesh_.boundary()[patchi].name()
158  << exit(FatalError);
159  }
160 
161  if
162  (
163  fromMesh_.boundaryMesh()[patchi].type()
164  != toMesh_.boundaryMesh()[patchi].type()
165  )
166  {
168  (
169  "meshToMesh::meshToMesh"
170  "(const fvMesh& meshFrom, const fvMesh& meshTo)"
171  ) << "Incompatible meshes: different patch types for patch "
172  << patchi
173  << ", fromMesh = " << fromMesh_.boundary()[patchi].type()
174  << ", toMesh = " << toMesh_.boundary()[patchi].type()
175  << exit(FatalError);
176  }
177 
178  fromMeshPatches_.insert
179  (
180  fromMesh_.boundaryMesh()[patchi].name(),
181  patchi
182  );
183 
184  toMeshPatches_.insert
185  (
186  toMesh_.boundaryMesh()[patchi].name(),
187  patchi
188  );
189 
190  patchMap_.insert
191  (
192  toMesh_.boundaryMesh()[patchi].name(),
193  fromMesh_.boundaryMesh()[patchi].name()
194  );
195  }
196 
197  calcAddressing();
198 }
199 
200 
201 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
202 
204 {
205  deleteDemandDrivenData(inverseDistanceWeightsPtr_);
206 }
207 
208 
209 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
210 
211 } // End namespace Foam
212 
213 // ************************ vim: set sw=4 sts=4 et: ************************ //