initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / dynamicMesh / fvMeshAdder / fvMeshAdder.C
blob9ece1057103869bab0fae09eda556bc060273c2b
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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 \*---------------------------------------------------------------------------*/
27 #include "fvMesh.H"
28 #include "fvMeshAdder.H"
29 #include "faceCoupleInfo.H"
30 #include "fvMesh.H"
32 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
34 //- Calculate map from new patch faces to old patch faces. -1 where
35 //  could not map.
36 Foam::labelList Foam::fvMeshAdder::calcPatchMap
38     const label oldStart,
39     const label oldSize,
40     const labelList& oldToNew,
41     const polyPatch& newPatch,
42     const label unmappedValue
45     labelList newToOld(newPatch.size(), unmappedValue);
47     label newStart = newPatch.start();
48     label newSize = newPatch.size();
50     for (label i = 0; i < oldSize; i++)
51     {
52         label newFaceI = oldToNew[oldStart+i];
54         if (newFaceI >= newStart && newFaceI < newStart+newSize)
55         {
56             newToOld[newFaceI-newStart] = i;
57         }
58     }
59     return newToOld;
63 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
65 // Inplace add mesh1 to mesh0
66 Foam::autoPtr<Foam::mapAddedPolyMesh> Foam::fvMeshAdder::add
68     fvMesh& mesh0,
69     const fvMesh& mesh1,
70     const faceCoupleInfo& coupleInfo,
71     const bool validBoundary
74     mesh0.clearOut();
76     // Resulting merged mesh (polyMesh only!)
77     autoPtr<mapAddedPolyMesh> mapPtr
78     (
79         polyMeshAdder::add
80         (
81             mesh0,
82             mesh1,
83             coupleInfo,
84             validBoundary
85         )
86     );
88     // Adjust the fvMesh part.
89     const polyBoundaryMesh& patches = mesh0.boundaryMesh();
91     fvBoundaryMesh& fvPatches = const_cast<fvBoundaryMesh&>(mesh0.boundary());
92     fvPatches.setSize(patches.size());
93     forAll(patches, patchI)
94     {
95         fvPatches.set(patchI, fvPatch::New(patches[patchI], fvPatches));
96     }
98     // Do the mapping of the stored fields
99     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
100     fvMeshAdder::MapVolFields<scalar>(mapPtr, mesh0, mesh1);
101     fvMeshAdder::MapVolFields<vector>(mapPtr, mesh0, mesh1);
102     fvMeshAdder::MapVolFields<sphericalTensor>(mapPtr, mesh0, mesh1);
103     fvMeshAdder::MapVolFields<symmTensor>(mapPtr, mesh0, mesh1);
104     fvMeshAdder::MapVolFields<tensor>(mapPtr, mesh0, mesh1);
106     fvMeshAdder::MapSurfaceFields<scalar>(mapPtr, mesh0, mesh1);
107     fvMeshAdder::MapSurfaceFields<vector>(mapPtr, mesh0, mesh1);
108     fvMeshAdder::MapSurfaceFields<sphericalTensor>(mapPtr, mesh0, mesh1);
109     fvMeshAdder::MapSurfaceFields<symmTensor>(mapPtr, mesh0, mesh1);
110     fvMeshAdder::MapSurfaceFields<tensor>(mapPtr, mesh0, mesh1);
112     return mapPtr;
116 // ************************************************************************* //