oomph::Shape Class Reference

#include <shape.h>

+ Inheritance diagram for oomph::Shape:

Public Member Functions

 Shape (const unsigned &N)
 Constructor for a single-index set of shape functions. More...
 
 Shape (const unsigned &N, const unsigned &M)
 Constructor for a two-index set of shape functions. More...
 
 Shape (const Shape &shape)=delete
 Broken copy constructor. More...
 
 Shape ()
 
void operator= (const Shape &shape)
 
void operator= (Shape *const &shape_pt)
 
 ~Shape ()
 Destructor, clear up the memory allocated by the object. More...
 
void resize (const unsigned &N, const unsigned &M=1)
 Change the size of the storage. More...
 
doubleoperator[] (const unsigned &i)
 Overload the bracket operator to provide access to values. More...
 
const doubleoperator[] (const unsigned &i) const
 Overload the bracket operator (const version) More...
 
doubleoperator() (const unsigned &i)
 Overload the round bracket operator to provide access to values. More...
 
const doubleoperator() (const unsigned &i) const
 Overload the round bracket operator (const version) More...
 
doubleoperator() (const unsigned &i, const unsigned &j)
 Overload the round bracket operator, allowing for two indices. More...
 
const doubleoperator() (const unsigned &i, const unsigned &j) const
 
unsigned nindex1 () const
 Return the range of index 1 of the shape function object. More...
 
unsigned nindex2 () const
 Return the range of index 2 of the shape function object. More...
 

Protected Member Functions

void range_check (const unsigned &i, const unsigned &j) const
 Private function that checks whether the index is in range. More...
 

Protected Attributes

doublePsi
 
doubleAllocated_storage
 
unsigned Index1
 Size of the first index of the shape function. More...
 
unsigned Index2
 Size of the second index of the shape function. More...
 

Detailed Description

A Class for shape functions. In simple cases, the shape functions have only one index that can be thought of as corresponding to the nodal points. In general, however, when quantities and their gradients are interpolated separately, the shape function have two indices: one corresponding to the nodal points, and the other to the "type" of quantity being interpolated: function, derivative, &c The second index can also represent the vector coordinate for vector-valued (Nedelec) shape functions.

The implementation of Shape functions is designed to permit fast copying of entire sets of values by resetting the internal pointer to the data, Psi; functionality that is required, for example, when setting the test functions in Galerkin elements and when reading pre-computed values of the shape functions. In general, we cannot know at construction time whether the pointer to the values will be reset or not and, therefore, whether the storage for values should be allocated by the object. We choose to allocate storage on construction and store an additional pointer Allocated_data that always addresses the storage allocated by the object. If the Psi pointer is reset then this storage will be "wasted", but only for the lifetime of the object. The cost for non-copied Shape functions is one additional pointer.

Constructor & Destructor Documentation

◆ Shape() [1/4]

oomph::Shape::Shape ( const unsigned N)
inline

Constructor for a single-index set of shape functions.

119  : Index1(N), Index2(1)
120  {
121  Allocated_storage = new double[N];
123  }
double * Allocated_storage
Definition: shape.h:86
unsigned Index1
Size of the first index of the shape function.
Definition: shape.h:89
unsigned Index2
Size of the second index of the shape function.
Definition: shape.h:92
double * Psi
Definition: shape.h:81
@ N
Definition: constructor.cpp:22

References Allocated_storage, N, and Psi.

◆ Shape() [2/4]

oomph::Shape::Shape ( const unsigned N,
const unsigned M 
)
inline

Constructor for a two-index set of shape functions.

126  : Index1(N), Index2(M)
127  {
128  Allocated_storage = new double[N * M];
130  }
Matrix< RealScalar, Dynamic, Dynamic > M
Definition: bench_gemm.cpp:50
The matrix class, also used for vectors and row-vectors.
Definition: Eigen/Eigen/src/Core/Matrix.h:186

References Allocated_storage, N, and Psi.

◆ Shape() [3/4]

oomph::Shape::Shape ( const Shape shape)
delete

Broken copy constructor.

◆ Shape() [4/4]

oomph::Shape::Shape ( )
inline

Default constructor - just assigns a null pointers and zero index sizes.

137 : Psi(0), Allocated_storage(0), Index1(0), Index2(0) {}

◆ ~Shape()

oomph::Shape::~Shape ( )
inline

Destructor, clear up the memory allocated by the object.

183  {
184  delete[] Allocated_storage;
185  Allocated_storage = 0;
186  }

References Allocated_storage.

Member Function Documentation

◆ nindex1()

◆ nindex2()

◆ operator()() [1/4]

double& oomph::Shape::operator() ( const unsigned i)
inline

Overload the round bracket operator to provide access to values.

223  {
224 #ifdef RANGE_CHECKING
225  range_check(i, 0);
226 #endif
227  return Psi[i * Index2];
228  }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
void range_check(const unsigned &i, const unsigned &j) const
Private function that checks whether the index is in range.
Definition: shape.h:95

References i, Index2, Psi, and range_check().

◆ operator()() [2/4]

const double& oomph::Shape::operator() ( const unsigned i) const
inline

Overload the round bracket operator (const version)

232  {
233 #ifdef RANGE_CHECKING
234  range_check(i, 0);
235 #endif
236  return Psi[i * Index2];
237  }

References i, Index2, Psi, and range_check().

◆ operator()() [3/4]

double& oomph::Shape::operator() ( const unsigned i,
const unsigned j 
)
inline

Overload the round bracket operator, allowing for two indices.

241  {
242 #ifdef RANGE_CHECKING
243  range_check(i, j);
244 #endif
245  return Psi[i * Index2 + j];
246  }
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2

References i, Index2, j, Psi, and range_check().

◆ operator()() [4/4]

const double& oomph::Shape::operator() ( const unsigned i,
const unsigned j 
) const
inline

Overload the round bracket operator, allowing for two indices (const version)

251  {
252 #ifdef RANGE_CHECKING
253  range_check(i, j);
254 #endif
255  return Psi[i * Index2 + j];
256  }

References i, Index2, j, Psi, and range_check().

◆ operator=() [1/2]

void oomph::Shape::operator= ( const Shape shape)
inline

The assignment operator does a shallow copy (resets the pointer to the data)

142  {
143 #ifdef PARANOID
144  // Check the dimensions
145  if ((shape.Index1 != Index1) || (shape.Index2 != Index2))
146  {
147  std::ostringstream error_stream;
148  error_stream << "Cannot assign Shape object:" << std::endl
149  << "Indices do not match "
150  << "LHS: " << Index1 << " " << Index2
151  << ", RHS: " << shape.Index1 << " " << shape.Index2
152  << std::endl;
153  throw OomphLibError(
154  error_stream.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
155  }
156 #endif
157  Psi = shape.Psi;
158  }
void shape(const double &s, double Psi[2][2])
Constructor sets the values of the shape functions at the position s.
Definition: shape.h:1194
#define OOMPH_EXCEPTION_LOCATION
Definition: oomph_definitions.h:61
#define OOMPH_CURRENT_FUNCTION
Definition: oomph_definitions.h:86

References Index1, Index2, OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION, Psi, and oomph::OneDimHermite::shape().

◆ operator=() [2/2]

void oomph::Shape::operator= ( Shape *const &  shape_pt)
inline

The assignment operator does a shallow copy (resets the pointer to the data)

163  {
164 #ifdef PARANOID
165  // Check the dimensions
166  if ((shape_pt->Index1 != Index1) || (shape_pt->Index2 != Index2))
167  {
168  std::ostringstream error_stream;
169  error_stream << "Cannot assign Shape object:" << std::endl
170  << "Indices do not match "
171  << "LHS: " << Index1 << " " << Index2
172  << ", RHS: " << shape_pt->Index1 << " " << shape_pt->Index2
173  << std::endl;
174  throw OomphLibError(
175  error_stream.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
176  }
177 #endif
178  Psi = shape_pt->Psi;
179  }

References Index1, Index2, OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION, and Psi.

◆ operator[]() [1/2]

double& oomph::Shape::operator[] ( const unsigned i)
inline

Overload the bracket operator to provide access to values.

205  {
206 #ifdef RANGE_CHECKING
207  range_check(i, 0);
208 #endif
209  return Psi[i * Index2];
210  }

References i, Index2, Psi, and range_check().

◆ operator[]() [2/2]

const double& oomph::Shape::operator[] ( const unsigned i) const
inline

Overload the bracket operator (const version)

214  {
215 #ifdef RANGE_CHECKING
216  range_check(i, 0);
217 #endif
218  return Psi[i * Index2];
219  }

References i, Index2, Psi, and range_check().

◆ range_check()

void oomph::Shape::range_check ( const unsigned i,
const unsigned j 
) const
inlineprotected

Private function that checks whether the index is in range.

96  {
97  // If an index is out of range, throw an error
98  if ((i >= Index1) || (j >= Index2))
99  {
100  std::ostringstream error_stream;
101  error_stream << "Range Error: ";
102  if (i >= Index1)
103  {
104  error_stream << i << " is not in the range (0," << Index1 - 1 << ")"
105  << std::endl;
106  }
107  if (j >= Index2)
108  {
109  error_stream << j << " is not in the range (0," << Index2 - 1 << ")"
110  << std::endl;
111  }
112  throw OomphLibError(
113  error_stream.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
114  }
115  }

References i, Index1, Index2, j, OOMPH_CURRENT_FUNCTION, and OOMPH_EXCEPTION_LOCATION.

Referenced by operator()(), and operator[]().

◆ resize()

void oomph::Shape::resize ( const unsigned N,
const unsigned M = 1 
)
inline

Change the size of the storage.

190  {
191  // Clear old storage
192  delete[] Allocated_storage;
193  Allocated_storage = 0;
194  Psi = 0;
195 
196  // Allocate new storage
197  Index1 = N;
198  Index2 = M;
199  Allocated_storage = new double[N * M];
201  }

References Allocated_storage, Index1, Index2, N, and Psi.

Member Data Documentation

◆ Allocated_storage

double* oomph::Shape::Allocated_storage
protected

Pointer that addresses the storage allocated by the object on construction. This will be the same as Psi if the object is not copied.

Referenced by resize(), Shape(), ~Shape(), and oomph::ShapeWithDeepCopy::~ShapeWithDeepCopy().

◆ Index1

unsigned oomph::Shape::Index1
protected

Size of the first index of the shape function.

Referenced by nindex1(), operator=(), range_check(), resize(), and oomph::ShapeWithDeepCopy::ShapeWithDeepCopy().

◆ Index2

unsigned oomph::Shape::Index2
protected

Size of the second index of the shape function.

Referenced by nindex2(), operator()(), operator=(), operator[](), range_check(), resize(), and oomph::ShapeWithDeepCopy::ShapeWithDeepCopy().

◆ Psi

double* oomph::Shape::Psi
protected

Pointer that addresses the storage that will be used to read and set the shape functions. The shape functions are packed into a flat array of doubles.

Referenced by operator()(), operator=(), operator[](), resize(), Shape(), and oomph::ShapeWithDeepCopy::ShapeWithDeepCopy().


The documentation for this class was generated from the following file: