SCIRun  5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Basis.h
Go to the documentation of this file.
1 //
2 // For more information, please see: http://software.sci.utah.edu
3 //
4 // The MIT License
5 //
6 // Copyright (c) 2009 Scientific Computing and Imaging Institute,
7 // University of Utah.
8 //
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining a
11 // copy of this software and associated documentation files (the "Software"),
12 // to deal in the Software without restriction, including without limitation
13 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 // and/or sell copies of the Software, and to permit persons to whom the
15 // Software is furnished to do so, subject to the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be included
18 // in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26 // DEALINGS IN THE SOFTWARE.
27 //
28 /// @file Basis.h
29 /// @author Frank B. Sachse
30 /// @date Mon Oct 21
31 
32 #ifndef CORE_BASIS_BASIS_H
33 #define CORE_BASIS_BASIS_H 1
34 
35 #include <vector>
36 #include <cfloat>
37 #include <boost/array.hpp>
39 #include <Core/Utils/Exception.h>
41 
42 namespace SCIRun {
43 namespace Core {
44 namespace Basis {
45 
46 /// Class for describing interfaces to basis elements
47 template <class T>
49 {
50 public:
52  virtual ~BasisSimple() {}
53 
54  /// @todo: exceptions being used to avoid virtual inheritance?
55  //
56  /// @todo: SCIRun 5 porting note: ASSERTFAIL replaced by
57  // REPORT_NOT_IMPLEMENTED (should not need this in production code)
58 
59 
60  /// get value at parametric coordinate
61  template <class ElemData, class VECTOR>
62  T interpolate(const VECTOR& /*coords*/, const ElemData &) const
63  {
64  REPORT_NOT_IMPLEMENTED("interpolate not supported by basis");
65  }
66 
67  /// get first derivative at parametric coordinate
68  template <class ElemData, class VECTOR1, class VECTOR2>
69  void derivate(const VECTOR1& /*coords*/, const ElemData &,
70  VECTOR2& /*derivs*/) const
71  {
72  REPORT_NOT_IMPLEMENTED("derivate not supported by basis");
73  }
74 
75  /// get parametric coordinate for value within the element
76  template <class ElemData, class VECTOR>
77  bool get_coords(VECTOR& /*coords*/, const T& /*value*/,
78  const ElemData &) const
79  {
80  REPORT_NOT_IMPLEMENTED("get_coords not supported by basis");
81  }
82 
83  /// get arc length for edge of element
84  template <class ElemData>
85  double get_arc_length(const unsigned /*edge*/, const ElemData&) const
86  {
87  REPORT_NOT_IMPLEMENTED("get_arc_length not supported by basis");
88  }
89 
90  /// get area for face of element
91  template <class ElemData>
92  double get_area(const unsigned /*face*/, const ElemData&) const
93  {
94  REPORT_NOT_IMPLEMENTED("get_area not supported by basis");
95  }
96 
97  /// get volume for element
98  template <class ElemData>
99  double get_volume(const ElemData &) const
100  {
101  REPORT_NOT_IMPLEMENTED("get_volume not supported by basis");
102  }
103 
104  /// add a node value
105  void add_node_value(const T &)
106  {
107  REPORT_NOT_IMPLEMENTED("add_node_value not supported by basis");
108  }
109 
110  void set_node_value(const T &, unsigned int)
111  {
112  REPORT_NOT_IMPLEMENTED("set_node_value not supported by basis");
113  }
114 
115  void get_node_value(T &, unsigned int) const
116  {
117  REPORT_NOT_IMPLEMENTED("get_node_value not supported by basis");
118  }
119 
120  void resize_node_values(size_t)
121  {
122  }
123 
124  /// return number of additional nodes
125  inline size_t size_node_values()
126  {
127  return (0);
128  }
129 
130  /// add a derivative value
131  void add_derivatives(const std::vector<T> &)
132  {
133  REPORT_NOT_IMPLEMENTED("add_derivative not supported by basis");
134  }
135 
136  /// add scale factors
137  void add_scalefactors(const std::vector<T> &)
138  {
139  REPORT_NOT_IMPLEMENTED("add_scalefactors not supported by basis");
140  }
141 
142  /// return number of additional derivatives
143  inline int size_derivatives()
144  {
145  return 0;
146  }
147 
148  inline std::vector<T>& get_nodes()
149  {
150  return (nodes_);
151  }
152 
153  inline std::vector<std::vector<T> >& get_derivs()
154  {
155  return (derivs_);
156  }
157 
158 protected:
159  std::vector<T> nodes_;
160  std::vector<std::vector<T> > derivs_;
161  std::vector<std::vector<double> > scalefactors_;
162  std::vector<double> scalefactorse_;
163 
164 };
165 
166 
167 /// Class for describing interfaces to basis elements with additional nodes
168 template <class T>
169 class BasisAddNodes : public BasisSimple<T>
170 {
171 public:
173  virtual ~BasisAddNodes() {}
174 
175  /// add a node value corresponding to edge
176  inline void add_node_value(const T &p) { BasisSimple<T>::nodes_.push_back(p); }
177 
178  /// get and set node value
179  template<class INDEX>
180  inline void set_node_value(const T &p, INDEX i) { BasisSimple<T>::nodes_[i] = p; }
181 
182  template<class INDEX>
183  inline void get_node_value(T &p, INDEX i) const { p = BasisSimple<T>::nodes_[i]; }
184 
185  /// set the proper size
186  template<class SIZE>
187  inline void resize_node_values(SIZE s) { BasisSimple<T>::nodes_.resize(s); }
188 
189  /// return node value
190  template<class INDEX>
191  inline T& node_values(INDEX i) { return &BasisSimple<T>::nodes_[i]; }
192 
193  inline size_t size_node_values() { return BasisSimple<T>::nodes_.size(); }
194 };
195 
196 
197 /// Class for describing interfaces to basis elements with
198 /// additional derivatives
199 template <class T>
201 {
202 public:
204  virtual ~BasisAddDerivatives() {}
205 
206  /// add derivative values (dx, dy, dxy) for nodes.
207  inline void add_derivatives(const std::vector<T> &p)
208  {
209  BasisSimple<T>::derivs_.push_back(p);
210  }
211 
212  /// get and set node value
213  inline void set_deriv_value(const T &p, unsigned int i,unsigned int j) { BasisSimple<T>::derivs_[i][j] = p; }
214  inline void get_deriv_value(T &p, unsigned int i,unsigned int j) const { p = BasisSimple<T>::derivs_[i][j]; }
215 
216  /// set the proper size
217  inline void resize_deriv_values(size_t s) { BasisSimple<T>::derivs_.resize(s); }
218 
219  /// return number of additional derivatives
220  inline int size_derivatives() { return BasisSimple<T>::derivs_.size(); }
221 
222 };
223 
224 /// Class for describing interfaces to basis elements with
225 /// additional derivatives and scale factors at nodes.
226 template <class T>
228 {
229 public:
232 
233  /// add scale factors (sdx, sdy) for nodes.
234  inline void add_scalefactors(const std::vector<double> &p)
235  {
236  BasisSimple<T>::scalefactors_.push_back(p);
237  }
238 
239  /// return number of additional derivatives
240  inline int size_scalefactors() { return BasisSimple<T>::scalefactors_.size(); }
241 
242 };
243 
244 /// Class for describing interfaces to basis elements with
245 /// additional derivatives and scale factors at edges
246 template <class T>
248 {
249 public:
252 
253  /// add scale factors (sdx, sdy) for nodes.
254  inline void add_scalefactors(const std::vector<double> &p)
255  { BasisSimple<T>::scalefactorse_.push_back(p[0]); }
256 
257  /// return number of additional derivatives
258  inline int size_scalefactors() { return BasisSimple<T>::scalefactorse_.size(); }
259 
260 };
261 
262 }}}
263 
264 #endif
void resize_node_values(SIZE s)
set the proper size
Definition: Basis.h:187
double get_area(const unsigned, const ElemData &) const
get area for face of element
Definition: Basis.h:92
virtual ~BasisAddNodes()
Definition: Basis.h:173
void get_node_value(T &p, INDEX i) const
Definition: Basis.h:183
int size_scalefactors()
return number of additional derivatives
Definition: Basis.h:258
void add_derivatives(const std::vector< T > &)
add a derivative value
Definition: Basis.h:131
virtual ~BasisAddDerivatives()
Definition: Basis.h:204
int size_derivatives()
return number of additional derivatives
Definition: Basis.h:143
void set_node_value(const T &p, INDEX i)
get and set node value
Definition: Basis.h:180
void set_deriv_value(const T &p, unsigned int i, unsigned int j)
get and set node value
Definition: Basis.h:213
std::vector< T > nodes_
Definition: Basis.h:159
Utility for specifying data invariants (Assertions)
double get_volume(const ElemData &) const
get volume for element
Definition: Basis.h:99
std::vector< T > & get_nodes()
Definition: Basis.h:148
Class for describing interfaces to basis elements.
Definition: Basis.h:48
void add_scalefactors(const std::vector< double > &p)
add scale factors (sdx, sdy) for nodes.
Definition: Basis.h:234
int size_derivatives()
return number of additional derivatives
Definition: Basis.h:220
std::vector< std::vector< T > > & get_derivs()
Definition: Basis.h:153
int size_scalefactors()
return number of additional derivatives
Definition: Basis.h:240
void add_node_value(const T &p)
add a node value corresponding to edge
Definition: Basis.h:176
BasisSimple()
Definition: Basis.h:51
void set_node_value(const T &, unsigned int)
Definition: Basis.h:110
Base class for persistent objects...
void get_node_value(T &, unsigned int) const
Definition: Basis.h:115
void get_deriv_value(T &p, unsigned int i, unsigned int j) const
Definition: Basis.h:214
void resize_deriv_values(size_t s)
set the proper size
Definition: Basis.h:217
virtual ~BasisAddDerivativesScaleFactorsEdges()
Definition: Basis.h:251
void resize_node_values(size_t)
Definition: Basis.h:120
bool get_coords(VECTOR &, const T &, const ElemData &) const
get parametric coordinate for value within the element
Definition: Basis.h:77
size_t size_node_values()
return number of additional nodes
Definition: Basis.h:125
void derivate(const VECTOR1 &, const ElemData &, VECTOR2 &) const
get first derivative at parametric coordinate
Definition: Basis.h:69
double get_arc_length(const unsigned, const ElemData &) const
get arc length for edge of element
Definition: Basis.h:85
std::vector< std::vector< double > > scalefactors_
Definition: Basis.h:161
T interpolate(const VECTOR &, const ElemData &) const
get value at parametric coordinate
Definition: Basis.h:62
BasisAddNodes()
Definition: Basis.h:172
Class for describing interfaces to basis elements with additional nodes.
Definition: Basis.h:169
#define REPORT_NOT_IMPLEMENTED(message)
Definition: Exception.h:106
virtual ~BasisSimple()
Definition: Basis.h:52
void add_derivatives(const std::vector< T > &p)
add derivative values (dx, dy, dxy) for nodes.
Definition: Basis.h:207
std::vector< double > scalefactorse_
Definition: Basis.h:162
std::vector< std::vector< T > > derivs_
Definition: Basis.h:160
BasisAddDerivatives()
Definition: Basis.h:203
void add_scalefactors(const std::vector< T > &)
add scale factors
Definition: Basis.h:137
T & node_values(INDEX i)
return node value
Definition: Basis.h:191
size_t size_node_values()
Definition: Basis.h:193
virtual ~BasisAddDerivativesScaleFactors()
Definition: Basis.h:231
void add_scalefactors(const std::vector< double > &p)
add scale factors (sdx, sdy) for nodes.
Definition: Basis.h:254
void add_node_value(const T &)
add a node value
Definition: Basis.h:105