SCIRun  5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Constant.h
Go to the documentation of this file.
1 //
2 // For more information, please see: http://software.sci.utah.edu
3 //
4 // he 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 Constant.h
29 /// @author Martin Cole, Frank B. Sachse
30 /// @date Mon Aug 23 09:57:14 2004
31 
32 #ifndef CORE_BASIS_CONSTANT_H
33 #define CORE_BASIS_CONSTANT_H 1
34 
35 #include <Core/Basis/Basis.h>
41 #include <Core/Basis/share.h>
42 
43 namespace SCIRun {
44 namespace Core {
45 namespace Basis {
46 
47 /// Class for describing unit geometry of ConstantBasis
49 public:
50  static double unit_vertices[1][1]; ///< Parametric coordinates of vertices
51  static int unit_edges[1][1]; ///< References to vertices of unit edge
52  static double unit_center[3];
53 
56 
57  /// return dimension of domain
58  static int domain_dimension()
59  { return 0; }
60 
61  /// return size of domain
62  static double domain_size()
63  { return 0.0; }
64 
65  /// return number of vertices
66  static int number_of_vertices()
67  { return 0; }
68 
69  /// return number of vertices
71  { return 0; }
72 
73  /// return number of edges
74  static int number_of_edges()
75  { return 0; }
76 
77  /// return degrees of freedom
78  static int dofs()
79  { return 1; }
80 
81  /// return number of vertices per face
82  static int vertices_of_face()
83  { return 0; }
84 
85  /// return number of faces per cell
86  static int faces_of_cell()
87  { return 0; }
88 
89  /// return volume
90  static double volume()
91  { return 0.; }
92 
93 };
94 
95 
97 public:
99  virtual ~ConstantApprox() {}
100 
101  /// Approximate edge for element by piecewise linear segments
102  /// return: coords gives parametric coordinates of the approximation.
103  /// Use interpolate with coordinates to get the world coordinates.
104  template<class VECTOR>
105  void approx_edge(const unsigned edge,
106  const unsigned div_per_unit,
107  VECTOR& coords) const
108  {
109  coords.resize(0);
110  }
111 
112  /// Approximate faces for element by piecewise linear elements
113  /// return: coords gives parametric coordinates at the approximation point.
114  /// Use interpolate with coordinates to get the world coordinates.
115  template<class VECTOR>
116  void approx_face(const unsigned face,
117  const unsigned div_per_unit,
118  VECTOR &coords) const
119  {
120  coords.resize(0);
121  }
122 
123 };
124 
125 
126 /// Class for handling of element with constant field variables
127 template <class T>
128  class ConstantBasis : public BasisSimple<T>,
130  public ConstantApprox,
131  public NoElementWeights,
132  public PntSamplingSchemes
133 {
134 public:
135  typedef T value_type;
136 
138  virtual ~ConstantBasis() {}
139 
140 
141  static int polynomial_order() { return 0; }
142 
143  /// get value at parametric coordinate
144  template <class ElemData, class VECTOR>
145  T interpolate(const VECTOR &, const ElemData &cd) const
146  {
147  return cd.elem();
148  }
149 
150  /// get first derivative at parametric coordinate
151  template <class ElemData, class VECTOR1, class VECTOR2>
152  void derivate(const VECTOR1 &coords, const ElemData &,
153  VECTOR2 &derivs) const
154  {
155  typename VECTOR1::size_type s=coords.size();
156  derivs.resize(s);
157  for(typename VECTOR1::size_type si=0; si<s; si++)
158  derivs[si] = static_cast<typename VECTOR2::value_type>(0);
159  }
160 
161  /// Get the weights for doing an interpolation
162  template <class VECTOR>
163  void get_weights(const VECTOR &coords, double *w) const
164  {
165  w[0]=1;
166  }
167 
168  /// Get the weights for doing a gradient
169  template <class VECTOR>
170  void get_derivate_weights(const VECTOR &coords, double *w) const
171  {
172  std::vector<double>::size_type s=coords.size();
173  for(std::vector<double>::size_type si=0; si<s; si++)
174  w[si] = 0;
175  }
176 
177  /// Functions for dynamic compilation and storing this object on disk
178  static const std::string type_name(int n = -1);
179  virtual void io (Piostream& str);
180 };
181 
182 template <class T>
183 const std::string
185 {
186  ASSERT((n >= -1) && n <= 1);
187  if (n == -1)
188  {
189  static const std::string name = TypeNameGenerator::make_template_id(type_name(0), type_name(1));
190  return name;
191  }
192  else if (n == 0)
193  {
194  static const std::string nm("ConstantBasis");
195  return nm;
196  }
197  else
198  {
199  return find_type_name((T *)0);
200  }
201 }
202 
203 
204 #define CONSTANTBASIS_VERSION 1
205 
206 }}
207 
208 template <class T>
210 {
211  static TypeDescription* td = 0;
212  if(!td){
213  const TypeDescription *sub = get_type_description((T*)0);
215  (*subs)[0] = sub;
216  td = new TypeDescription("ConstantBasis", subs,
217  std::string(__FILE__),
218  "SCIRun",
220  }
221  return td;
222 }
223 
224  template <class T>
225  void
227  {
228  stream.begin_class(get_type_description(this)->get_name(),
230  stream.end_class();
231  }
232 }
233 
234 #endif
ConstantApprox()
Definition: Constant.h:98
void get_derivate_weights(const VECTOR &coords, double *w) const
Get the weights for doing a gradient.
Definition: Constant.h:170
static int vertices_of_face()
return number of vertices per face
Definition: Constant.h:82
specializations of template&lt;class T&gt; find_type_name() function for build-in and simple types not deri...
static int domain_dimension()
return dimension of domain
Definition: Constant.h:58
ConstantBasis()
Definition: Constant.h:137
Class for describing unit geometry of ConstantBasis.
Definition: Constant.h:48
Definition: Persistent.h:89
void approx_face(const unsigned face, const unsigned div_per_unit, VECTOR &coords) const
Definition: Constant.h:116
Definition: TypeDescription.h:45
#define SCISHARE
Definition: share.h:39
void derivate(const VECTOR1 &coords, const ElemData &, VECTOR2 &derivs) const
get first derivative at parametric coordinate
Definition: Constant.h:152
std::vector< const TypeDescription * > td_vec
Definition: TypeDescription.h:56
static double volume()
return volume
Definition: Constant.h:90
static const std::string type_name(int n=-1)
Functions for dynamic compilation and storing this object on disk.
Definition: Constant.h:184
static int dofs()
return degrees of freedom
Definition: Constant.h:78
virtual ~ConstantBasis()
Definition: Constant.h:138
#define ASSERT(condition)
Definition: Assert.h:110
Class for describing interfaces to basis elements.
Definition: Basis.h:48
static int faces_of_cell()
return number of faces per cell
Definition: Constant.h:86
virtual int begin_class(const std::string &name, int current_version)
Definition: Persistent.cc:143
virtual ~ConstantBasisUnitElement()
Definition: Constant.h:55
const string find_type_name(float *)
Definition: TypeName.cc:63
Base class for persistent objects...
ConstantBasisUnitElement()
Definition: Constant.h:54
const char * name[]
Definition: BoostGraphExampleTests.cc:87
long long size_type
Definition: Types.h:40
Class for handling of element with constant field variables.
Definition: Constant.h:128
T interpolate(const VECTOR &, const ElemData &cd) const
get value at parametric coordinate
Definition: Constant.h:145
static int number_of_mesh_vertices()
return number of vertices
Definition: Constant.h:70
static int number_of_edges()
return number of edges
Definition: Constant.h:74
T value_type
Definition: Constant.h:135
void get_weights(const VECTOR &coords, double *w) const
Get the weights for doing an interpolation.
Definition: Constant.h:163
static int polynomial_order()
Definition: Constant.h:141
static const std::string make_template_id(const std::string &templateName, const std::string &templateParam)
Definition: TypeName.h:62
Definition: PntSamplingSchemes.h:42
virtual void end_class()
Definition: Persistent.cc:178
Definition: NoElementWeights.h:36
#define CONSTANTBASIS_VERSION
Definition: Constant.h:204
static int number_of_vertices()
return number of vertices
Definition: Constant.h:66
virtual ~ConstantApprox()
Definition: Constant.h:99
static double domain_size()
return size of domain
Definition: Constant.h:62
int n
Definition: eab.py:9
virtual void io(Piostream &str)
Definition: Constant.h:226
Definition: TypeDescription.h:49
void approx_edge(const unsigned edge, const unsigned div_per_unit, VECTOR &coords) const
Definition: Constant.h:105
const TypeDescription * get_type_description(Core::Basis::ConstantBasis< T > *)
Definition: Constant.h:209
Definition: Constant.h:96