AMIMethod.H 9.74 KB
Newer Older
1
2
3
4
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
5
    \\  /    A nd           | Copyright (C) 2013-2016 OpenFOAM Foundation
6
     \\/     M anipulation  | Copyright (C) 2016-2018 OpenCFD Ltd.
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

    OpenFOAM is free software: you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.

    You should have received a copy of the GNU General Public License
    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.

Class
    Foam::AMIMethod

Description
    Base class for Arbitrary Mesh Interface (AMI) methods

SourceFiles
    AMIMethod.C

\*---------------------------------------------------------------------------*/

#ifndef AMIMethod_H
#define AMIMethod_H

#include "className.H"
#include "DynamicList.H"
#include "faceAreaIntersect.H"
#include "indexedOctree.H"
#include "treeDataPrimitivePatch.H"
#include "treeBoundBoxList.H"
#include "runTimeSelectionTables.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

namespace Foam
{

51
52
template<class SourcePatch, class TargetPatch> class AMIInterpolation;

53
54
55
56
57
58
59
60
61
62
63
64
/*---------------------------------------------------------------------------*\
                          Class AMIMethod Declaration
\*---------------------------------------------------------------------------*/

template<class SourcePatch, class TargetPatch>
class AMIMethod
{

private:

    // Private Member Functions

65
66
        //- No copy construct
        AMIMethod(const AMIMethod&) = delete;
67

68
69
        //- No copy assignment
        void operator=(const AMIMethod&) = delete;
70
71
72
73


protected:

74
    //- Local typedef to octree tree-type
75
76
77
78
79
80
81
82
83
    typedef treeDataPrimitivePatch<TargetPatch> treeType;


    // Protected data

        //- Reference to source patch
        const SourcePatch& srcPatch_;

        //- Reference to target patch
Henry's avatar
Henry committed
84
        const TargetPatch& tgtPatch_;
85
86

        //- Flag to indicate that the two patches are co-directional and
87
        //- that the orientation of the target patch should be reversed
88
89
        const bool reverseTarget_;

90
        //- Flag to indicate that the two patches must be matched/an overlap
91
        //- exists between them
92
93
        const bool requireMatch_;

94
        //- Source face areas
95
        List<scalar> srcMagSf_;
96
97

        //- Target face areas
98
        List<scalar> tgtMagSf_;
99
100

        //- Labels of faces that are not overlapped by any target faces
101
        //- (should be empty for correct functioning)
102
103
104
        labelList srcNonOverlap_;

        //- Octree used to find face seeds
105
        autoPtr<indexedOctree<treeType>> treePtr_;
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124

        //- Face triangulation mode
        const faceAreaIntersect::triangulationMode triMode_;


    // Protected Member Functions

        // Helper functions

            //- Check AMI patch coupling
            void checkPatches() const;

            //- Initialise and return true if all ok
            bool initialise
            (
                labelListList& srcAddress,
                scalarListList& srcWeights,
                labelListList& tgtAddress,
                scalarListList& tgtWeights,
125
126
                label& srcFacei,
                label& tgtFacei
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
            );

            //- Write triangle intersection to OBJ file
            void writeIntersectionOBJ
            (
                const scalar area,
                const face& f1,
                const face& f2,
                const pointField& f1Points,
                const pointField& f2Points
            ) const;


        // Common AMI method functions

            //- Reset the octree for the target patch face search
            void resetTree();

            //- Find face on target patch that overlaps source face
146
            label findTargetFace(const label srcFacei) const;
147

148
            //- Add faces neighbouring facei to the ID list
149
150
            void appendNbrFaces
            (
151
                const label facei,
152
153
154
155
156
                const TargetPatch& patch,
                const DynamicList<label>& visitedFaces,
                DynamicList<label>& faceIDs
            ) const;

157
158
159
160
161
162
163
164
165
            //- Helper function to decompose a patch
            template<class PatchType>
            void triangulatePatch
            (
                const PatchType& patch,
                List<DynamicList<face>>& tris,
                List<scalar>& magSf
            ) const;

166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181

public:

    //- Runtime type information
    TypeName("AMIMethod");

    //- Declare runtime constructor selection table
    declareRunTimeSelectionTable
    (
        autoPtr,
        AMIMethod,
        components,
        (
            const SourcePatch& srcPatch,
            const TargetPatch& tgtPatch,
            const faceAreaIntersect::triangulationMode& triMode,
182
183
            const bool reverseTarget,
            const bool requireMatch
184
        ),
185
186
187
188
189
190
191
        (
            srcPatch,
            tgtPatch,
            triMode,
            reverseTarget,
            requireMatch
        )
192
193
194
195
196
197
198
199
    );

    //- Construct from components
    AMIMethod
    (
        const SourcePatch& srcPatch,
        const TargetPatch& tgtPatch,
        const faceAreaIntersect::triangulationMode& triMode,
200
201
        const bool reverseTarget,
        const bool requireMatch
202
203
204
205
206
207
208
209
210
    );

    //- Selector
    static autoPtr<AMIMethod> New
    (
        const word& methodName,
        const SourcePatch& srcPatch,
        const TargetPatch& tgtPatch,
        const faceAreaIntersect::triangulationMode& triMode,
211
212
        const bool reverseTarget,
        const bool requireMatch
213
214
215
216
    );


    //- Destructor
217
    virtual ~AMIMethod() = default;
218
219
220
221
222
223
224
225
226
227


    // Member Functions

        // Access

            //- Labels of faces that are not overlapped by any target faces
            //  Note: this should be empty for correct functioning
            inline const labelList& srcNonOverlap() const;

228
229
            //- Flag to indicate that interpolation patches are conformal
            virtual bool conformal() const;
230

231
232
233
234
235
236
237
238
239
240
241
242
            //- Return const access to source patch face areas
            inline const List<scalar>& srcMagSf() const;

            //- Return access to source patch face areas
            inline List<scalar>& srcMagSf();

            //- Return const access to target patch face areas
            inline const List<scalar>& tgtMagSf() const;

            //- Return access to target patch face areas
            inline List<scalar>& tgtMagSf();

243
244
245
246
247
248
249
250
251
252

        // Manipulation

            //- Update addressing and weights
            virtual void calculate
            (
                labelListList& srcAddress,
                scalarListList& srcWeights,
                labelListList& tgtAddress,
                scalarListList& tgtWeights,
253
254
                label srcFacei = -1,
                label tgtFacei = -1
255
            ) = 0;
256

257
258
259
260
261
262
263
264
265
            //- Set the face areas for parallel runs
            virtual void setMagSf
            (
                const TargetPatch& tgtPatch,
                const mapDistribute& map,
                scalarList& srcMagSf,
                scalarList& tgtMagSf
            ) const = 0;

266
            //- Normalise the weight. Can optionally subset addressing
267
            //- (e.g. for mapNearest)
268
269
270
271
272
            virtual void normaliseWeights
            (
                const bool verbose,
                AMIInterpolation<SourcePatch, TargetPatch>& inter
            ) = 0;
273
274
275
276
277
278
279
280
281
};


// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

} // End namespace Foam

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

282
283
284
285
286
287
#define makeAMIMethod(AMIType)                                                 \
                                                                               \
    typedef AMIMethod<AMIType::sourcePatchType,AMIType::targetPatchType>       \
        AMIMethod##AMIType;                                                    \
                                                                               \
    defineNamedTemplateTypeNameAndDebug(AMIMethod##AMIType, 0);                \
288
289
290
    defineTemplateRunTimeSelectionTable(AMIMethod##AMIType, components);


291
292
293
294
295
296
297
298
299
#define makeAMIMethodType(AMIType, Method)                                     \
                                                                               \
    typedef Method<AMIType::sourcePatchType,AMIType::targetPatchType>          \
        Method##AMIType;                                                       \
                                                                               \
    defineNamedTemplateTypeNameAndDebug(Method##AMIType, 0);                   \
                                                                               \
    AMIMethod<AMIType::sourcePatchType,AMIType::targetPatchType>::             \
        addcomponentsConstructorToTable<Method##AMIType>                       \
300
301
302
303
304
305
306
307
308
309
        add##Method##AMIType##ConstructorToTable_;


// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

#include "AMIMethodI.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

#ifdef NoRepository
310
311
    #include "AMIMethod.C"
    #include "AMIMethodNew.C"
312
313
314
315
316
317
318
#endif

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

#endif

// ************************************************************************* //