splitCell.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "splitCell.H"
27 #include "error.H"
28 
29 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30 
31 // Construct from cell number and parent
33 :
34  celli_(celli),
35  parent_(parent),
36  master_(nullptr),
37  slave_(nullptr)
38 {}
39 
40 
41 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
42 
44 {
45  splitCell* myParent = parent();
46 
47  if (myParent)
48  {
49  // Make sure parent does not refer to me anymore.
50  if (myParent->master() == this)
51  {
52  myParent->master() = nullptr;
53  }
54  else if (myParent->slave() == this)
55  {
56  myParent->slave() = nullptr;
57  }
58  else
59  {
61  << " parent's master or slave pointer" << endl
62  << "Cell:" << cellLabel() << abort(FatalError);
63  }
64  }
65 }
66 
67 
68 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
69 
71 {
72  splitCell* myParent = parent();
73 
74  if (!myParent)
75  {
77  << "Cell:" << cellLabel() << abort(FatalError);
78 
79  return false;
80  }
81  else if (myParent->master() == this)
82  {
83  return true;
84  }
85  else if (myParent->slave() == this)
86  {
87  return false;
88  }
89  else
90  {
92  << " parent's master or slave pointer" << endl
93  << "Cell:" << cellLabel() << abort(FatalError);
94 
95  return false;
96  }
97 }
98 
99 
101 {
102  return !master() && !slave();
103 }
104 
105 
107 {
108  splitCell* myParent = parent();
109 
110  if (!myParent)
111  {
113  << "Cell:" << cellLabel() << abort(FatalError);
114 
115  return nullptr;
116  }
117  else if (myParent->master() == this)
118  {
119  return myParent->slave();
120  }
121  else if (myParent->slave() == this)
122  {
123  return myParent->master();
124  }
125  else
126  {
128  << " parent's master or slave pointer" << endl
129  << "Cell:" << cellLabel() << abort(FatalError);
130 
131  return nullptr;
132  }
133 }
134 
135 
136 // ************************************************************************* //
bool isMaster() const
Check if this is master cell of split.
Definition: splitCell.C:70
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
splitCell * getOther() const
Returns other half of split cell. I.e. slave if this is master.
Definition: splitCell.C:106
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
label cellLabel() const
Definition: splitCell.H:87
splitCell * slave() const
Definition: splitCell.H:117
bool isUnrefined() const
Check if this is unrefined (i.e. has no master or slave)
Definition: splitCell.C:100
splitCell * parent() const
Definition: splitCell.H:97
Description of cell after splitting. Contains cellLabel and pointers to cells it it split in...
Definition: splitCell.H:51
errorManip< error > abort(error &err)
Definition: errorManip.H:131
splitCell(const label celli, splitCell *parent)
Construct from cell number and parent.
Definition: splitCell.C:32
splitCell * master() const
Definition: splitCell.H:107
~splitCell()
Destructor.
Definition: splitCell.C:43