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 -------------------------------------------------------------------------------
10 License
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 
33 // Construct from cell number and parent
34 Foam::splitCell::splitCell(const label celli, splitCell* parent)
35 :
36  celli_(celli),
37  parent_(parent),
38  master_(nullptr),
39  slave_(nullptr)
40 {}
41 
42 
43 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
44 
46 {
47  splitCell* myParent = parent();
48 
49  if (myParent)
50  {
51  // Make sure parent does not refer to me anymore.
52  if (myParent->master() == this)
53  {
54  myParent->master() = nullptr;
55  }
56  else if (myParent->slave() == this)
57  {
58  myParent->slave() = nullptr;
59  }
60  else
61  {
63  << " parent's master or slave pointer" << endl
64  << "Cell:" << cellLabel() << abort(FatalError);
65  }
66  }
67 }
68 
69 
70 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
71 
73 {
74  splitCell* myParent = parent();
75 
76  if (!myParent)
77  {
79  << "Cell:" << cellLabel() << abort(FatalError);
80 
81  return false;
82  }
83  else if (myParent->master() == this)
84  {
85  return true;
86  }
87  else if (myParent->slave() == this)
88  {
89  return false;
90  }
91  else
92  {
94  << " parent's master or slave pointer" << endl
95  << "Cell:" << cellLabel() << abort(FatalError);
96 
97  return false;
98  }
99 }
100 
101 
103 {
104  return !master() && !slave();
105 }
106 
107 
109 {
110  splitCell* myParent = parent();
111 
112  if (!myParent)
113  {
115  << "Cell:" << cellLabel() << abort(FatalError);
116 
117  return nullptr;
118  }
119  else if (myParent->master() == this)
120  {
121  return myParent->slave();
122  }
123  else if (myParent->slave() == this)
124  {
125  return myParent->master();
126  }
127  else
128  {
130  << " parent's master or slave pointer" << endl
131  << "Cell:" << cellLabel() << abort(FatalError);
132 
133  return nullptr;
134  }
135 }
136 
137 
138 // ************************************************************************* //
splitCell.H
Foam::splitCell::slave
splitCell * slave() const
Definition: splitCell.H:125
Foam::splitCell::isUnrefined
bool isUnrefined() const
Check if this is unrefined (i.e. has no master or slave)
Definition: splitCell.C:102
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
Foam::splitCell::getOther
splitCell * getOther() const
Returns other half of split cell. I.e. slave if this is master.
Definition: splitCell.C:108
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:62
error.H
Foam::FatalError
error FatalError
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:137
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:355
Foam::splitCell
Description of cell after splitting. Contains cellLabel and pointers to cells it it split in....
Definition: splitCell.H:53
Foam::splitCell::master
splitCell * master() const
Definition: splitCell.H:115
Foam::splitCell::isMaster
bool isMaster() const
Check if this is master cell of split.
Definition: splitCell.C:72
Foam::splitCell::~splitCell
~splitCell()
Destructor.
Definition: splitCell.C:45