1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
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
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
28 #include "coupledInfo.H"
29 #include "dynamicTopoFvMesh.H"
30 #include "emptyFvPatchFields.H"
31 #include "emptyFvsPatchFields.H"
32 #include "fixedValueFvPatchFields.H"
37 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
39 // Constructor for coupledInfo
40 coupledInfo::coupledInfo
42 const dynamicTopoFvMesh& mesh,
43 const coupleMap& cMap,
51 masterFaceZone_(mfzIndex),
52 slaveFaceZone_(sfzIndex)
56 coupledInfo::coupledInfo
58 const dynamicTopoFvMesh& mesh,
59 const bool isTwoDMesh,
62 const label patchIndex,
79 + word(isLocal ? "_Local" : "_Proc")
80 + word(isSend ? "_Send" : "_Recv"),
81 mesh.time().timeName(),
94 masterFaceZone_(mfzIndex),
95 slaveFaceZone_(sfzIndex)
99 //- Construct given addressing
100 coupledInfo::subMeshMapper::subMeshMapper
102 const coupledInfo& cInfo,
106 sizeBeforeMapping_(cInfo.baseMesh().boundary()[patchI].size()),
111 cInfo.map().faceMap(),
112 cInfo.subMesh().boundary()[patchI].size(),
113 cInfo.subMesh().boundary()[patchI].patch().start()
118 label pStart = cInfo.baseMesh().boundary()[patchI].patch().start();
120 forAll(directAddressing_, faceI)
122 directAddressing_[faceI] -= pStart;
127 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
129 const dynamicTopoFvMesh& coupledInfo::baseMesh() const
135 void coupledInfo::setMesh
138 dynamicTopoFvMesh* mesh
145 dynamicTopoFvMesh& coupledInfo::subMesh()
147 if (!subMesh_.valid())
149 FatalErrorIn("dynamicTopoFvMesh& coupledInfo::subMesh()")
150 << " Sub-mesh pointer has not been set."
151 << abort(FatalError);
158 const dynamicTopoFvMesh& coupledInfo::subMesh() const
160 if (!subMesh_.valid())
162 FatalErrorIn("const dynamicTopoFvMesh& coupledInfo::subMesh() const")
163 << " Sub-mesh pointer has not been set."
164 << abort(FatalError);
171 bool coupledInfo::builtMaps() const
177 void coupledInfo::setBuiltMaps()
183 coupleMap& coupledInfo::map()
189 const coupleMap& coupledInfo::map() const
195 label coupledInfo::masterFaceZone() const
197 return masterFaceZone_;
201 label coupledInfo::slaveFaceZone() const
203 return slaveFaceZone_;
207 // Set subMesh centres
208 void coupledInfo::setCentres(PtrList<volVectorField>& centres) const
210 // Fetch reference to subMesh
211 const dynamicTopoFvMesh& mesh = subMesh();
216 vectorField Cv(mesh.cellCentres());
217 vectorField Cf(mesh.faceCentres());
219 // Create and map the patch field values
220 label nPatches = mesh.boundary().size();
222 // Create field parts
223 PtrList<fvPatchField<vector> > volCentrePatches(nPatches);
225 // Over-ride and set all patches to fixedValue
226 for (label patchI = 0; patchI < nPatches; patchI++)
231 new fixedValueFvPatchField<vector>
233 mesh.boundary()[patchI],
234 DimensionedField<vector, volMesh>::null()
238 // Slice field to patch (forced assignment)
239 volCentrePatches[patchI] ==
241 mesh.boundaryMesh()[patchI].patchSlice(Cf)
245 // Set the cell-centres pointer.
254 mesh.time().timeName(),
262 SubField<vector>(Cv, mesh.nCells()),
269 // Subset volume field
270 template <class Type>
271 tmp<GeometricField<Type, fvPatchField, volMesh> >
272 coupledInfo::subSetVolField
274 const GeometricField<Type, fvPatchField, volMesh>& fld
277 // Create and map the internal-field values
278 Field<Type> internalField
284 // Create and map the patch field values
285 label nPatches = subMesh().boundary().size();
286 PtrList<fvPatchField<Type> > patchFields(nPatches);
288 forAll(patchFields, patchI)
290 if (patchI == (nPatches - 1))
292 // Artificially set last patch
296 new emptyFvPatchField<Type>
298 subMesh().boundary()[patchI],
299 DimensionedField<Type, volMesh>::null()
308 fvPatchField<Type>::New
310 fld.boundaryField()[patchI],
311 subMesh().boundary()[patchI],
312 DimensionedField<Type, volMesh>::null(),
313 subMeshMapper(*this, patchI)
319 // Create new field from pieces
320 tmp<GeometricField<Type, fvPatchField, volMesh> > subFld
322 new GeometricField<Type, fvPatchField, volMesh>
326 "subField_" + fld.name(),
327 subMesh().time().timeName(),
344 // Subset surface field
345 template <class Type>
346 tmp<GeometricField<Type, fvsPatchField, surfaceMesh> >
347 coupledInfo::subSetSurfaceField
349 const GeometricField<Type, fvsPatchField, surfaceMesh>& fld
352 // Create and map the internal-field values
353 Field<Type> internalField
359 subMesh().nInternalFaces()
363 // Create and map the patch field values
364 label nPatches = subMesh().boundary().size();
365 PtrList<fvsPatchField<Type> > patchFields(nPatches);
367 forAll(patchFields, patchI)
369 if (patchI == (nPatches - 1))
371 // Artificially set last patch
375 new emptyFvsPatchField<Type>
377 subMesh().boundary()[patchI],
378 DimensionedField<Type, surfaceMesh>::null()
387 fvsPatchField<Type>::New
389 fld.boundaryField()[patchI],
390 subMesh().boundary()[patchI],
391 DimensionedField<Type, surfaceMesh>::null(),
392 subMeshMapper(*this, patchI)
398 // Create new field from pieces
399 tmp<GeometricField<Type, fvsPatchField, surfaceMesh> > subFld
401 new GeometricField<Type, fvsPatchField, surfaceMesh>
405 "subField_" + fld.name(),
406 subMesh().time().timeName(),
423 template <class Type>
424 void coupledInfo::mapVolField
426 const wordList& fieldNames,
427 const word& fieldType,
432 << fieldType << token::NL
433 << token::BEGIN_BLOCK << token::NL;
435 forAll(fieldNames, i)
437 const GeometricField<Type, fvPatchField, volMesh>& fld =
441 GeometricField<Type, fvPatchField, volMesh>
445 tmp<GeometricField<Type, fvPatchField, volMesh> > tsubFld =
450 // Send field through stream
453 << token::NL << token::BEGIN_BLOCK
455 << token::NL << token::END_BLOCK
460 << token::END_BLOCK << token::NL;
464 template <class Type>
465 void coupledInfo::mapSurfaceField
467 const wordList& fieldNames,
468 const word& fieldType,
473 << fieldType << token::NL
474 << token::BEGIN_BLOCK << token::NL;
476 forAll(fieldNames, i)
478 const GeometricField<Type, fvsPatchField, surfaceMesh>& fld =
482 GeometricField<Type, fvsPatchField, surfaceMesh>
486 tmp<GeometricField<Type, fvsPatchField, surfaceMesh> > tsubFld =
488 subSetSurfaceField(fld)
491 // Send field through stream
494 << token::NL << token::BEGIN_BLOCK
496 << token::NL << token::END_BLOCK
501 << token::END_BLOCK << token::NL;
505 // Set volume field pointer from input dictionary
506 template <class GeomField>
507 void coupledInfo::setField
509 const wordList& fieldNames,
510 const dictionary& fieldDicts,
511 PtrList<GeomField>& fields
514 // Size up the pointer list
515 fields.setSize(fieldNames.size());
517 forAll(fieldNames, i)
527 subMesh().time().timeName(),
534 fieldDicts.subDict(fieldNames[i])
541 template <class GeomField>
542 void coupledInfo::resizeMap
544 const label srcIndex,
545 const subMeshMapper& internalMapper,
546 const List<labelList>& internalReverseMaps,
547 const PtrList<subMeshMapper>& boundaryMapper,
548 const List<labelListList>& boundaryReverseMaps,
549 const List<PtrList<GeomField> >& srcFields,
553 // autoMap the internal field
554 field.internalField().autoMap(internalMapper);
556 // Reverse map for additional cells
557 forAll(srcFields, pI)
559 // Fetch field for this processor
560 const GeomField& srcField = srcFields[pI][srcIndex];
562 field.internalField().rmap
564 srcField.internalField(),
565 internalReverseMaps[pI]
569 // Map physical boundary-fields
570 forAll(boundaryMapper, patchI)
572 // autoMap the patchField
573 field.boundaryField()[patchI].autoMap(boundaryMapper[patchI]);
575 // Reverse map for additional patch faces
576 forAll(srcFields, pI)
578 // Fetch field for this processor
579 const GeomField& srcField = srcFields[pI][srcIndex];
581 field.boundaryField()[patchI].rmap
583 srcField.boundaryField()[patchI],
584 boundaryReverseMaps[pI][patchI]
591 // Resize all fields in registry
592 template <class GeomField>
593 void coupledInfo::resizeMap
595 const wordList& names,
596 const objectRegistry& mesh,
597 const subMeshMapper& internalMapper,
598 const List<labelList>& internalReverseMaps,
599 const PtrList<subMeshMapper>& boundaryMapper,
600 const List<labelListList>& boundaryReverseMaps,
601 const List<PtrList<GeomField> >& srcFields
604 forAll(names, indexI)
606 // Fetch field from registry
609 const_cast<GeomField&>
611 mesh.lookupObject<GeomField>(names[indexI])
616 coupledInfo::resizeMap
630 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
632 void coupledInfo::operator=(const coupledInfo& rhs)
634 // Check for assignment to self
639 "void coupledInfo::operator=(const Foam::coupledInfo&)"
641 << "Attempted assignment to self"
642 << abort(FatalError);
646 } // End namespace Foam
648 // ************************************************************************* //