FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

splitCell.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software: you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 #include "splitCell.H"
00027 #include <OpenFOAM/error.H>
00028 
00029 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00030 
00031 // Construct from cell number and parent
00032 Foam::splitCell::splitCell(const label cellI, splitCell* parent)
00033 :
00034     cellI_(cellI),
00035     parent_(parent),
00036     master_(NULL),
00037     slave_(NULL)
00038 {}
00039 
00040 
00041 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00042 
00043 Foam::splitCell::~splitCell()
00044 {
00045     splitCell* myParent = parent();
00046 
00047     if (myParent)
00048     {
00049         // Make sure parent does not refer to me anymore.
00050         if (myParent->master() == this)
00051         {
00052             myParent->master() = NULL;
00053         }
00054         else if (myParent->slave() == this)
00055         {
00056             myParent->slave() = NULL;
00057         }
00058         else
00059         {
00060             FatalErrorIn("splitCell::~splitCell()") << "this not equal to"
00061                 << " parent's master or slave pointer" << endl
00062                 << "Cell:" << cellLabel() << abort(FatalError);
00063         }
00064     }
00065 }
00066 
00067 
00068 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00069 
00070 bool Foam::splitCell::isMaster() const
00071 {
00072     splitCell* myParent = parent();
00073 
00074     if (!myParent)
00075     {
00076         FatalErrorIn("splitCell::isMaster()") << "parent not set"
00077             << "Cell:" << cellLabel() << abort(FatalError);
00078 
00079         return false;
00080     }
00081     else if (myParent->master() == this)
00082     {
00083         return true;
00084     }
00085     else if (myParent->slave() == this)
00086     {
00087         return false;
00088     }
00089     else
00090     {
00091         FatalErrorIn("splitCell::isMaster()") << "this not equal to"
00092             << " parent's master or slave pointer" << endl
00093             << "Cell:" << cellLabel() << abort(FatalError);
00094 
00095         return false;
00096     }
00097 }
00098 
00099 
00100 bool Foam::splitCell::isUnrefined() const
00101 {
00102     return !master() && !slave();
00103 }
00104 
00105 
00106 Foam::splitCell* Foam::splitCell::getOther() const
00107 {
00108     splitCell* myParent = parent();
00109 
00110     if (!myParent)
00111     {
00112         FatalErrorIn("splitCell::getOther()") << "parent not set"
00113             << "Cell:" << cellLabel() << abort(FatalError);
00114 
00115         return NULL;
00116     }
00117     else if (myParent->master() == this)
00118     {
00119         return myParent->slave();
00120     }
00121     else if (myParent->slave() == this)
00122     {
00123         return myParent->master();
00124     }
00125     else
00126     {
00127         FatalErrorIn("splitCell::getOther()") << "this not equal to"
00128             << " parent's master or slave pointer" << endl
00129             << "Cell:" << cellLabel() << abort(FatalError);
00130 
00131         return NULL;
00132     }
00133 }
00134 
00135 
00136 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines