1 2 3 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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 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 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 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266
|
// This file is part of ff3d - http://www.freefem.org/ff3d
// Copyright (C) 2001, 2002, 2003 Stphane Del Pino
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2, or (at your option)
// any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// $Id: Cell.hpp,v 1.12 2007/05/20 23:02:47 delpinux Exp $
#ifndef CELL_HPP
#define CELL_HPP
#include <Vertex.hpp>
#include <Stringify.hpp>
#include <ErrorHandler.hpp>
/**
* @file Cell.hpp
* @author Stephane Del Pino
* @date Sun Jun 15 19:49:43 2003
*
* @brief This class describes 3D Mesh cells.
*
*
*/
class Cell {
public:
enum Type {
hexahedron,
cartesianHexahedron,
hexahedronByEdge,
tetrahedron,
triangle3d,
quadrangle3d
};
protected:
//! Reference of the Cell
size_t __reference;
//! Volume or surface of the cell
real_t __volume;
//! Pointers on vertices of the cell
Vertex** __vertices;
//! indicates if the cell is to be taken into accounts for computations
mutable bool __isFictitious;
public:
/**
* Find the vertex @a P in the cell
*
*
* @return bool
*/
inline bool find(const Vertex * P) {
for(size_t i=0 ; i<numberOfVertices() ; ++i) {
if(__vertices[i]==P) {
return true;
}
}
return false;
}
/**
* Read-only access to the volume of the cell
*
* @return the volume
*/
inline const real_t& volume() const
{
return __volume;
}
/**
* Replaces a vertex by another
*
* @param v0 the vertex to replace
* @param v1 the new vertex
*/
inline void replace(Vertex* v0, Vertex* v1)
{
for (size_t i = 0; i<numberOfVertices(); ++i) {
if (__vertices[i] == v0) {
__vertices[i] = v1;
return;
}
}
const std::string errorMsg
= "vertex "+stringify(v0)+" was not found while replacing "+stringify(v1);
throw ErrorHandler(__FILE__,__LINE__,
errorMsg,
ErrorHandler::unexpected);
}
/**
* Read-only access to the fictitious state of the cell
*
* @return true if the cell is fictitious
*/
const bool& isFictitious() const
{
return __isFictitious;
}
/**
* Sets fictitious state of the cell
*
* @note method is const since this does not change the cell.
* Fictitious state is a mutable member!
*/
void setFictitious(const bool& b) const
{
__isFictitious = b;
}
/**
* Read-only ccess to the number of vertices
*
* @return the number of vertices
*/
virtual size_t numberOfVertices() const = 0;
/**
* Access to the type of the cell
*
* @return the cell type
*/
virtual Cell::Type type() const = 0;
/**
* Read-only access to the reference of the Cell.
*
* @return a const reference to the reference
*/
inline const size_t& reference() const
{
return __reference;
}
/**
* Access to the reference of the Cell.
*
* @return a reference to the reference
*/
inline size_t& reference()
{
return __reference;
}
/**
* Access to the ith Vertex of the Cell.
*
* @param i the local number of the vertex
*
* @return a reference to a the vertex
*/
inline Vertex& operator () (const size_t& i)
{
ASSERT (i<numberOfVertices());
return *__vertices[i];
}
/**
* Read-only access to the ith Vertex of the Cell.
*
* @param i the local number of the vertex
*
* @return a const reference to a the vertex
*/
inline const Vertex& operator () (const size_t& i) const
{
ASSERT (i<numberOfVertices());
return *(__vertices[i]);
}
/**
* Sets the cell to a given one
*
* @param C the given cell
*
* @return the modified cell
*/
inline const Cell& operator=(const Cell& C)
{
__reference = C.__reference;
__volume = C.__volume;
for (size_t i=0; i<C.numberOfVertices(); ++i)
__vertices[i] = C.__vertices[i];
return *this;
}
/**
* Constructs a cell with a given number of vertices
*
* @param numberOfVertices the number of vertices
*/
Cell(const size_t& numberOfVertices)
: __reference(0),
__volume(0),
__isFictitious(false)
{
ASSERT(numberOfVertices > 0);
__vertices = new Vertex*[numberOfVertices];
}
/**
* Constructs a cell with a given number of vertices and a given
* reference
*
* @param numberOfVertices the number of vertices
* @param reference the given reference
*/
Cell(const size_t& numberOfVertices, const size_t& reference)
: __reference(reference),
__volume(0),
__isFictitious(false)
{
ASSERT(numberOfVertices > 0);
__vertices = new Vertex*[numberOfVertices];
}
/**
* Copies a given cell
*
* @param C the given cell
*/
Cell(const Cell& C)
: __reference(C.__reference),
__volume(C.__volume),
__isFictitious(C.__isFictitious)
{
__vertices = new Vertex*[C.numberOfVertices()];
for (size_t i=0; i<C.numberOfVertices(); ++i)
__vertices[i] = C.__vertices[i];
}
/**
* The destructor
*
*/
virtual ~Cell()
{
delete [] __vertices;
}
};
#endif // CELL_HPP
|