Conditions.h 12.3 KB
Newer Older
Joe Frazier's avatar
Joe Frazier committed
1
2
////////////////////////////////////////////////////////////////////////////////
//
Spencer Sherwin's avatar
Spencer Sherwin committed
3
//  File:  Conditions.h
Joe Frazier's avatar
Joe Frazier committed
4
5
6
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
//
//  For more information, please see: http://www.nektar.info/
//
//  The MIT License
//
//  Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
//  Department of Aeronautics, Imperial College London (UK), and Scientific
//  Computing and Imaging Institute, University of Utah (USA).
//
//  License for the specific language governing rights and limitations under
//  Permission is hereby granted, free of charge, to any person obtaining a
//  copy of this software and associated documentation files (the "Software"),
//  to deal in the Software without restriction, including without limitation
//  the rights to use, copy, modify, merge, publish, distribute, sublicense,
//  and/or sell copies of the Software, and to permit persons to whom the
//  Software is furnished to do so, subject to the following conditions:
//
//  The above copyright notice and this permission notice shall be included
//  in all copies or substantial portions of the Software.
//
//  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
//  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
//  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
//  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
//  DEALINGS IN THE SOFTWARE.
//
//  Description:
//
//
////////////////////////////////////////////////////////////////////////////////
#ifndef NEKTAR_SPATIALDOMAINS_BOUNDARYCONDITIONS_H
#define NEKTAR_SPATIALDOMAINS_BOUNDARYCONDITIONS_H

#include <string>
#include <map>

42
#include <LibUtilities/BasicUtils/SessionReader.h>
43
#include <LibUtilities/BasicUtils/Equation.h>
Joe Frazier's avatar
Joe Frazier committed
44
45
46
47
48
#include <SpatialDomains/MeshGraph.h>


namespace Nektar
{
49
50
    struct OneD;

Joe Frazier's avatar
Joe Frazier committed
51
52
    namespace SpatialDomains
    {
53
54
55
56
        enum BoundaryConditionType
        {
            eDirichlet,
            eNeumann,
57
            eRobin,
58
            ePeriodic,
59
60
61
            eJunction,
            eBifurcation,
            eMerging
62
        };
63

64
65
66
67
68
69
70
71
72
73
74
75
        enum BndUserDefinedType
        {
            eI,
            eMG,
            eHigh,
            eWall,
            eWALL,
            eSymmetry,
            eRinglebFlow,
            eTimeDependent,
            eIsentropicVortex,
            eCalcBC,
76
            eQinflow,
77
78
79
80
            eTerminal,
            eRterminal,
            eCRterminal,
            eRCRterminal,
81
82
83
            eNoUserDefined
        };

84
85
        struct BoundaryConditionBase
        {
86
87
            BoundaryConditionBase(
                    BoundaryConditionType type,
88
89
90
91
92
93
94
95
96
                    const std::string &userDefined = std::string("NoUserDefined")):
                m_boundaryConditionType(type)
            {
                std::map<const std::string, BndUserDefinedType>  known_type;
                known_type["H"] = eHigh;
                known_type["I"] = eI;
                known_type["MG"] = eMG;
                known_type["Wall"] = eWall;
                known_type["Q-inflow"] = eQinflow;
97
98
99
100
                known_type["Terminal"] = eTerminal;
                known_type["R-terminal"] = eRterminal;
                known_type["CR-terminal"] = eCRterminal;
                known_type["RCR-terminal"] = eRCRterminal;
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
                known_type["WALL"] = eWALL;
                known_type["CalcBC"] = eCalcBC;
                known_type["RinglebFlow"] = eRinglebFlow;
                known_type["Symmetry"] = eSymmetry;
                known_type["TimeDependent"] = eTimeDependent;
                known_type["IsentropicVortex"] = eIsentropicVortex;
                known_type["NoUserDefined"] = eNoUserDefined;

                std::map<const std::string, BndUserDefinedType>::const_iterator it = known_type.find(userDefined);
                if (it != known_type.end())
                {
                    m_userDefined = it->second;
                }
                else
                {
                    //ASSERTL0(false, std::string("Unknown boundary condition user defined type [") + userDefined + std::string("]"));
                    m_userDefined = eNoUserDefined;
                }
            }

            virtual ~BoundaryConditionBase()
            {};

            BoundaryConditionType GetBoundaryConditionType() const
            {
                return m_boundaryConditionType;
            }

            void SetUserDefined(BndUserDefinedType type)
            {
                m_userDefined = type;
            }
133

134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
            BndUserDefinedType GetUserDefined() const
            {
                return m_userDefined;
            }

            int m_parent;
            int m_daughter1;
            int m_daughter2;

            void SetJunction(int P, int D1)
            {
                m_parent = P;
				m_daughter1 = D1;
            }
			
			void SetBifurcation(int P, int D1, int D2)
            {
                m_parent = P;
				m_daughter1 = D1;
				m_daughter2 = D2;
            }
			
			void SetMerging(int P, int D1, int D2)
            {
                m_parent = P;
				m_daughter1 = D1;
				m_daughter2 = D2;
            }
			
			int GetParent() const
            {
                return m_parent;
            }
			
			int GetDaughter1() const
            {
                return m_daughter1;
            }
			
			int GetDaughter2() const
            {
                return m_daughter2;
            }
177

178

179
        protected:
180
            BoundaryConditionType m_boundaryConditionType;
181
            BndUserDefinedType    m_userDefined;
182
183
        };

Sophia Han's avatar
Sophia Han committed
184

185
186
        struct DirichletBoundaryCondition : public BoundaryConditionBase
        {
187

188
             DirichletBoundaryCondition(
189
                    const LibUtilities::SessionReaderSharedPtr &pSession,
190
191
192
193
                    const std::string& eqn,
                    const std::string& userDefined = std::string("NoUserDefined"),
                    const std::string& filename=std::string("")):
                BoundaryConditionBase(eDirichlet, userDefined),
194
                m_dirichletCondition(pSession, eqn),
195
                m_filename(filename)
196
197
                {
                }
198

199
200
            LibUtilities::Equation m_dirichletCondition;
            std::string m_filename;
201
202
203
204
        };

        struct NeumannBoundaryCondition : public BoundaryConditionBase
        {
205
            NeumannBoundaryCondition(
206
                    const LibUtilities::SessionReaderSharedPtr &pSession,
207
208
209
                    const std::string& eqn,
                    const std::string& userDefined = std::string("NoUserDefined"),
                    const std::string& filename=std::string("")):
210
                BoundaryConditionBase(eNeumann, userDefined),
211
                m_neumannCondition(pSession, eqn),
212
                m_filename(filename)
213
            {
214
            }
215

216
            LibUtilities::Equation m_neumannCondition;
217
            std::string m_filename;
218
219
220
221
        };

        struct RobinBoundaryCondition : public BoundaryConditionBase
        {
222
            RobinBoundaryCondition(
223
                    const LibUtilities::SessionReaderSharedPtr &pSession,
224
225
226
227
                    const std::string &a,
                    const std::string &b,
                    const std::string &userDefined = std::string("NoUserDefined"),
                    const std::string& filename=std::string("")):
228
                BoundaryConditionBase(eRobin, userDefined),
229
230
                m_robinFunction(pSession, a),
                m_robinPrimitiveCoeff(pSession, b),
231
                m_filename(filename)
232
233
            {
            }
234
                // \frac{\partial {u}}{\partial{n}} +
235
                // m_robinPrimativeCoeff(x,y,z)*u = m_robinFunction(x,y,z)
236
237
            LibUtilities::Equation m_robinFunction;
            LibUtilities::Equation m_robinPrimitiveCoeff;
238
            std::string m_filename;
239
        };
240

241

242
243
244
245
        struct PeriodicBoundaryCondition : public BoundaryConditionBase
        {
            PeriodicBoundaryCondition(const unsigned int n):
                BoundaryConditionBase(ePeriodic),
246
                m_connectedBoundaryRegion(n)
247
248
            {
            }
249
250

            unsigned int m_connectedBoundaryRegion;
251
        };
252
253

        struct JunctionBoundaryCondition : public BoundaryConditionBase
254
        {
255
256
257
258
259
260
            JunctionBoundaryCondition( const int &P, const int &D1, const std::string &userDefined = std::string("NoUserDefined")):
            BoundaryConditionBase(eJunction, userDefined),
            m_parent(P), m_daughter1(D1)
            {
                SetJunction(P, D1);
            }
261
262
263
            int m_parent;
            int m_daughter1;
        };
264
265

        struct BifurcationBoundaryCondition : public BoundaryConditionBase
266
        {
267
268
269
270
271
272
            BifurcationBoundaryCondition( const int &P, const int &D1, const int &D2, const std::string &userDefined = std::string("NoUserDefined")):
            BoundaryConditionBase(eBifurcation, userDefined),
            m_parent(P), m_daughter1(D1), m_daughter2(D2)
            {
                SetBifurcation(P, D1, D2);
            }
273
274
            int m_parent;
            int m_daughter1;
275
            int m_daughter2;
276
        };
277

278
        struct MergingBoundaryCondition : public BoundaryConditionBase
279
        {
280
281
282
283
284
285
            MergingBoundaryCondition( const int &P, const int &D1, const int &D2, const std::string &userDefined = std::string("NoUserDefined")):
            BoundaryConditionBase(eMerging, userDefined),
            m_parent(P), m_daughter1(D1), m_daughter2(D2)
            {
                SetMerging(P, D1, D2);
            }
286
287
            int m_parent;
            int m_daughter1;
288
            int m_daughter2;
289
        };
290
291


292
        typedef std::map<int, Composite> BoundaryRegion;
Blake Nelson's avatar
Blake Nelson committed
293
294
        typedef boost::shared_ptr<BoundaryRegion> BoundaryRegionShPtr;
        typedef boost::shared_ptr<const BoundaryRegion> ConstBoundaryRegionShPtr;
295
        typedef std::vector<BoundaryRegionShPtr> BoundaryRegionCollection;
Joe Frazier's avatar
Joe Frazier committed
296

Blake Nelson's avatar
Blake Nelson committed
297
        typedef boost::shared_ptr<BoundaryConditionBase> BoundaryConditionShPtr;
Joe Frazier's avatar
Joe Frazier committed
298
        typedef boost::shared_ptr<DirichletBoundaryCondition> DirichletBCShPtr;
299
300
        typedef boost::shared_ptr<NeumannBoundaryCondition>   NeumannBCShPtr;
        typedef boost::shared_ptr<RobinBoundaryCondition>     RobinBCShPtr;
301
        typedef boost::shared_ptr<JunctionBoundaryCondition>  JunctionBCShPtr;
302
303
        typedef boost::shared_ptr<BifurcationBoundaryCondition>  BifurcationBCShPtr;
        typedef boost::shared_ptr<MergingBoundaryCondition>   MergingBCShPtr;
304
305
        typedef std::map<std::string,BoundaryConditionShPtr>  BoundaryConditionMap;
        typedef boost::shared_ptr<BoundaryConditionMap>  BoundaryConditionMapShPtr;
306
        typedef std::map<int, BoundaryConditionMapShPtr> BoundaryConditionCollection;
Joe Frazier's avatar
Joe Frazier committed
307

308
309
        const static Array<OneD, BoundaryConditionShPtr> NullBoundaryConditionShPtrArray;

Joe Frazier's avatar
Joe Frazier committed
310
311
312
        class BoundaryConditions
        {
        public:
313
            SPATIAL_DOMAINS_EXPORT BoundaryConditions(const LibUtilities::SessionReaderSharedPtr &pSession, const MeshGraphSharedPtr &meshGraph);
314
            SPATIAL_DOMAINS_EXPORT ~BoundaryConditions();
Joe Frazier's avatar
Joe Frazier committed
315

316
317
318
319
320
321
322
323
324
325
326
327
328
329
            const BoundaryRegionCollection &GetBoundaryRegions(void) const
            {
                return m_boundaryRegions;
            }

            const BoundaryConditionCollection &GetBoundaryConditions(void) const
            {
                return m_boundaryConditions;
            }

            const std::string GetVariable(unsigned int indx)
            {
                return m_session->GetVariable(indx);
            }
Spencer Sherwin's avatar
Spencer Sherwin committed
330

331
332
        protected:
            /// The mesh graph to use for referencing geometry info.
333
            MeshGraphSharedPtr                      m_meshGraph;
334
            LibUtilities::SessionReaderSharedPtr    m_session;
335

336
337
            BoundaryRegionCollection                m_boundaryRegions;
            BoundaryConditionCollection             m_boundaryConditions;
338

339
340
        private:
            BoundaryConditions();
341

342
343
            /// Read segments (and general MeshGraph) given TiXmlDocument.
            void Read(TiXmlElement *conditions);
344

Joe Frazier's avatar
Joe Frazier committed
345
            void ReadBoundaryRegions(TiXmlElement *regions);
Joe Frazier's avatar
Joe Frazier committed
346
347
            void ReadBoundaryConditions(TiXmlElement *conditions);
        };
348

349
350
        typedef boost::shared_ptr<BoundaryConditions> BoundaryConditionsSharedPtr;
    }
Joe Frazier's avatar
Joe Frazier committed
351
352
}

Blake Nelson's avatar
Blake Nelson committed
353
#endif //NEKTAR_SPATIALDOMAINS_BOUNDARYCONDITIONS_H
354