OpenCMISS-Zinc C++ API Documentation
 All Classes Namespaces Files Functions Typedefs Enumerations Enumerator Pages
fieldcache.hpp
Go to the documentation of this file.
1 
4 /* OpenCMISS-Zinc Library
5 *
6 * This Source Code Form is subject to the terms of the Mozilla Public
7 * License, v. 2.0. If a copy of the MPL was not distributed with this
8 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
9 
10 #ifndef CMZN_FIELDCACHE_HPP__
11 #define CMZN_FIELDCACHE_HPP__
12 
13 #include "zinc/field.h"
14 #include "zinc/fieldcache.h"
15 #include "zinc/differentialoperator.hpp"
16 #include "zinc/element.hpp"
17 #include "zinc/fieldmodule.hpp"
18 #include "zinc/node.hpp"
19 
20 namespace OpenCMISS
21 {
22 namespace Zinc
23 {
24 
34 {
35 protected:
36  cmzn_fieldcache_id id;
37 
38 public:
39 
40  Fieldcache() : id(0)
41  { }
42 
43  // takes ownership of C handle, responsibility for destroying it
44  explicit Fieldcache(cmzn_fieldcache_id in_field_cache_id) :
45  id(in_field_cache_id)
46  { }
47 
48  Fieldcache(const Fieldcache& fieldCache) :
49  id(cmzn_fieldcache_access(fieldCache.id))
50  { }
51 
52  Fieldcache& operator=(const Fieldcache& fieldCache)
53  {
54  cmzn_fieldcache_id temp_id = cmzn_fieldcache_access(fieldCache.id);
55  if (0 != id)
56  {
57  cmzn_fieldcache_destroy(&id);
58  }
59  id = temp_id;
60  return *this;
61  }
62 
63  ~Fieldcache()
64  {
65  if (0 != id)
66  {
67  cmzn_fieldcache_destroy(&id);
68  }
69  }
70 
76  bool isValid() const
77  {
78  return (0 != id);
79  }
80 
86  cmzn_fieldcache_id getId() const
87  {
88  return id;
89  }
90 
101  {
102  return cmzn_fieldcache_clear_location(id);
103  }
104 
114  int setElement(const Element& element)
115  {
116  return cmzn_fieldcache_set_element(id, element.getId());
117  }
118 
134  int setMeshLocation(const Element& element, int coordinatesCount,
135  const double *coordinatesIn)
136  {
137  return cmzn_fieldcache_set_mesh_location(id, element.getId(),
138  coordinatesCount, coordinatesIn);
139  }
140 
153  int setFieldReal(const Field& referenceField, int valuesCount,
154  const double *valuesIn)
155  {
156  return cmzn_fieldcache_set_field_real(id,
157  referenceField.getId(), valuesCount, valuesIn);
158  }
159 
169  int setNode(const Node& node)
170  {
171  return cmzn_fieldcache_set_node(id, node.getId());
172  }
173 
180  int setTime(double time)
181  {
182  return cmzn_fieldcache_set_time(id, time);
183  }
184 };
185 
187 {
188  return Fieldcache(cmzn_fieldmodule_create_fieldcache(id));
189 }
190 
191 inline int Field::assignMeshLocation(const Fieldcache& cache, const Element& element,
192  int coordinatesCount, const double *coordinatesIn)
193 {
194  return cmzn_field_assign_mesh_location(id, cache.getId(), element.getId(),
195  coordinatesCount, coordinatesIn);
196 }
197 
198 inline int Field::assignReal(const Fieldcache& cache, int valuesCount, const double *valuesIn)
199 {
200  return cmzn_field_assign_real(id, cache.getId(), valuesCount, valuesIn);
201 }
202 
203 inline int Field::assignString(const Fieldcache& cache, const char *stringValue)
204 {
205  return cmzn_field_assign_string(id, cache.getId(), stringValue);
206 }
207 
208 inline Element Field::evaluateMeshLocation(const Fieldcache& cache, int coordinatesCount,
209  double *coordinatesOut)
210 {
211  return Element(cmzn_field_evaluate_mesh_location(id,
212  cache.getId(), coordinatesCount, coordinatesOut));
213 }
214 
215 inline int Field::evaluateReal(const Fieldcache& cache, int valuesCount, double *valuesOut)
216 {
217  return cmzn_field_evaluate_real(id, cache.getId(), valuesCount, valuesOut);
218 }
219 
220 inline char *Field::evaluateString(const Fieldcache& cache)
221 {
222  return cmzn_field_evaluate_string(id, cache.getId());
223 }
224 
225 inline int Field::evaluateDerivative(const Differentialoperator& differentialOperator,
226  const Fieldcache& cache, int valuesCount, double *valuesOut)
227 {
228  return cmzn_field_evaluate_derivative(id, differentialOperator.getId(),
229  cache.getId(), valuesCount, valuesOut);
230 }
231 
232 inline bool Field::isDefinedAtLocation(const Fieldcache& cache)
233 {
234  return cmzn_field_is_defined_at_location(id, cache.getId());
235 }
236 
237 } // namespace Zinc
238 }
239 
240 #endif /* CMZN_FIELDCACHE_HPP__ */
int evaluateDerivative(const Differentialoperator&differentialOperator, const Fieldcache &cache, int valuesCount, double *valuesOut)
Definition: fieldcache.hpp:225
A single finite element from a mesh.
Definition: element.hpp:205
Element evaluateMeshLocation(const Fieldcache &cache, int coordinatesCount, double *coordinatesOut)
Definition: fieldcache.hpp:208
Base field type: an abstraction of a mathematical field.
Definition: field.hpp:46
int assignReal(const Fieldcache &cache, int valuesCount, const double *valuesIn)
Definition: fieldcache.hpp:198
int clearLocation()
Definition: fieldcache.hpp:100
int setNode(const Node &node)
Definition: fieldcache.hpp:169
Describes the derivative of a field to evaluate.
Definition: differentialoperator.hpp:26
int assignString(const Fieldcache &cache, const char *stringValue)
Definition: fieldcache.hpp:203
int setElement(const Element &element)
Definition: fieldcache.hpp:114
int setTime(double time)
Definition: fieldcache.hpp:180
int setFieldReal(const Field &referenceField, int valuesCount, const double *valuesIn)
Definition: fieldcache.hpp:153
char * evaluateString(const Fieldcache &cache)
Definition: fieldcache.hpp:220
cmzn_field_id getId() const
Definition: field.hpp:98
bool isDefinedAtLocation(const Fieldcache &cache)
Definition: fieldcache.hpp:232
cmzn_element_id getId() const
Definition: element.hpp:351
int assignMeshLocation(const Fieldcache &cache, const Element &element, int coordinatesCount, const double *coordinatesIn)
Definition: fieldcache.hpp:191
cmzn_node_id getId() const
Definition: node.hpp:139
Cache for setting domain locations at which fields are evaluated or assigned.
Definition: fieldcache.hpp:33
bool isValid() const
Definition: fieldcache.hpp:76
cmzn_differentialoperator_id getId() const
Definition: differentialoperator.hpp:79
int setMeshLocation(const Element &element, int coordinatesCount, const double *coordinatesIn)
Definition: fieldcache.hpp:134
Point object used to represent finite element nodes.
Definition: node.hpp:37
Fieldcache createFieldcache()
Definition: fieldcache.hpp:186
cmzn_fieldcache_id getId() const
Definition: fieldcache.hpp:86
int evaluateReal(const Fieldcache &cache, int valuesCount, double *valuesOut)
Definition: fieldcache.hpp:215