FreeFOAM The Cross-Platform CFD Toolkit
fvFieldDecomposerDecomposeFields.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 "fvFieldDecomposer.H"
29 
30 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 
35 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
36 
37 template<class Type>
38 tmp<GeometricField<Type, fvPatchField, volMesh> >
40 (
41  const GeometricField<Type, fvPatchField, volMesh>& field
42 ) const
43 {
44  // Create and map the internal field values
45  Field<Type> internalField(field.internalField(), cellAddressing_);
46 
47  // Create and map the patch field values
48  PtrList<fvPatchField<Type> > patchFields(boundaryAddressing_.size());
49 
50  forAll (boundaryAddressing_, patchi)
51  {
52  if (boundaryAddressing_[patchi] >= 0)
53  {
54  patchFields.set
55  (
56  patchi,
57  fvPatchField<Type>::New
58  (
59  field.boundaryField()[boundaryAddressing_[patchi]],
60  procMesh_.boundary()[patchi],
62  *patchFieldDecomposerPtrs_[patchi]
63  )
64  );
65  }
66  else
67  {
68  patchFields.set
69  (
70  patchi,
71  new processorFvPatchField<Type>
72  (
73  procMesh_.boundary()[patchi],
75  Field<Type>
76  (
77  field.internalField(),
78  *processorVolPatchFieldDecomposerPtrs_[patchi]
79  )
80  )
81  );
82  }
83  }
84 
85  // Create the field for the processor
86  return tmp<GeometricField<Type, fvPatchField, volMesh> >
87  (
88  new GeometricField<Type, fvPatchField, volMesh>
89  (
90  IOobject
91  (
92  field.name(),
93  procMesh_.time().timeName(),
94  procMesh_,
97  ),
98  procMesh_,
99  field.dimensions(),
100  internalField,
101  patchFields
102  )
103  );
104 }
105 
106 
107 template<class Type>
108 tmp<GeometricField<Type, fvsPatchField, surfaceMesh> >
110 (
111  const GeometricField<Type, fvsPatchField, surfaceMesh>& field
112 ) const
113 {
114  labelList mapAddr
115  (
117  (
118  faceAddressing_,
119  procMesh_.nInternalFaces()
120  )
121  );
122  forAll (mapAddr, i)
123  {
124  mapAddr[i] -= 1;
125  }
126 
127  // Create and map the internal field values
128  Field<Type> internalField
129  (
130  field.internalField(),
131  mapAddr
132  );
133 
134  // Problem with addressing when a processor patch picks up both internal
135  // faces and faces from cyclic boundaries. This is a bit of a hack, but
136  // I cannot find a better solution without making the internal storage
137  // mechanism for surfaceFields correspond to the one of faces in polyMesh
138  // (i.e. using slices)
139  Field<Type> allFaceField(field.mesh().nFaces());
140 
141  forAll (field.internalField(), i)
142  {
143  allFaceField[i] = field.internalField()[i];
144  }
145 
146  forAll (field.boundaryField(), patchi)
147  {
148  const Field<Type> & p = field.boundaryField()[patchi];
149 
150  const label patchStart = field.mesh().boundaryMesh()[patchi].start();
151 
152  forAll (p, i)
153  {
154  allFaceField[patchStart + i] = p[i];
155  }
156  }
157 
158  // Create and map the patch field values
159  PtrList<fvsPatchField<Type> > patchFields(boundaryAddressing_.size());
160 
161  forAll (boundaryAddressing_, patchi)
162  {
163  if (boundaryAddressing_[patchi] >= 0)
164  {
165  patchFields.set
166  (
167  patchi,
168  fvsPatchField<Type>::New
169  (
170  field.boundaryField()[boundaryAddressing_[patchi]],
171  procMesh_.boundary()[patchi],
173  *patchFieldDecomposerPtrs_[patchi]
174  )
175  );
176  }
177  else
178  {
179  patchFields.set
180  (
181  patchi,
182  new processorFvsPatchField<Type>
183  (
184  procMesh_.boundary()[patchi],
186  Field<Type>
187  (
188  allFaceField,
189  *processorSurfacePatchFieldDecomposerPtrs_[patchi]
190  )
191  )
192  );
193  }
194  }
195 
196  // Create the field for the processor
197  return tmp<GeometricField<Type, fvsPatchField, surfaceMesh> >
198  (
199  new GeometricField<Type, fvsPatchField, surfaceMesh>
200  (
201  IOobject
202  (
203  field.name(),
204  procMesh_.time().timeName(),
205  procMesh_,
208  ),
209  procMesh_,
210  field.dimensions(),
211  internalField,
212  patchFields
213  )
214  );
215 }
216 
217 
218 template<class GeoField>
220 (
221  const PtrList<GeoField>& fields
222 ) const
223 {
224  forAll (fields, fieldI)
225  {
226  decomposeField(fields[fieldI])().write();
227  }
228 }
229 
230 
231 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
232 
233 } // End namespace Foam
234 
235 // ************************ vim: set sw=4 sts=4 et: ************************ //