splitCell.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 | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-2016 OpenFOAM Foundation
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26\*---------------------------------------------------------------------------*/
27
28#include "splitCell.H"
29#include "error.H"
30
31// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32
33Foam::splitCell::splitCell(const label celli, splitCell* parent)
34:
35 celli_(celli),
36 parent_(parent),
37 master_(nullptr),
38 slave_(nullptr)
39{}
40
41
42// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
43
45{
46 splitCell* myParent = parent();
47
48 if (myParent)
49 {
50 // Make sure parent does not refer to me anymore.
51 if (myParent->master() == this)
52 {
53 myParent->master() = nullptr;
54 }
55 else if (myParent->slave() == this)
56 {
57 myParent->slave() = nullptr;
58 }
59 else
60 {
62 << " parent's master or slave pointer" << endl
63 << "Cell:" << cellLabel() << abort(FatalError);
64 }
65 }
66}
67
68
69// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
70
72{
73 splitCell* myParent = parent();
74
75 if (!myParent)
76 {
78 << "Cell:" << cellLabel() << abort(FatalError);
79
80 return false;
81 }
82 else if (myParent->master() == this)
83 {
84 return true;
85 }
86 else if (myParent->slave() == this)
87 {
88 return false;
89 }
90 else
91 {
93 << " parent's master or slave pointer" << endl
94 << "Cell:" << cellLabel() << abort(FatalError);
95
96 return false;
97 }
98}
99
100
102{
103 return !master() && !slave();
104}
105
106
108{
109 splitCell* myParent = parent();
110
111 if (!myParent)
112 {
114 << "Cell:" << cellLabel() << abort(FatalError);
115
116 return nullptr;
117 }
118 else if (myParent->master() == this)
119 {
120 return myParent->slave();
121 }
122 else if (myParent->slave() == this)
123 {
124 return myParent->master();
125 }
126 else
127 {
129 << " parent's master or slave pointer" << endl
130 << "Cell:" << cellLabel() << abort(FatalError);
131
132 return nullptr;
133 }
134}
135
136
137// ************************************************************************* //
Description of cell after splitting. Contains cellLabel and pointers to cells it it split in....
Definition: splitCell.H:52
bool isMaster() const
Check if this is master cell of split.
Definition: splitCell.C:71
bool isUnrefined() const
Check if this is unrefined (i.e. has no master or slave)
Definition: splitCell.C:101
~splitCell()
Destructor.
Definition: splitCell.C:44
splitCell * master() const
Definition: splitCell.H:113
splitCell * getOther() const
Returns other half of split cell. I.e. slave if this is master.
Definition: splitCell.C:107
splitCell * slave() const
Definition: splitCell.H:123
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
errorManip< error > abort(error &err)
Definition: errorManip.H:144
error FatalError