OpenCMISS-Zinc C++ API Documentation
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 "opencmiss/zinc/field.h"
14 #include "opencmiss/zinc/fieldcache.h"
15 #include "opencmiss/zinc/differentialoperator.hpp"
16 #include "opencmiss/zinc/element.hpp"
17 #include "opencmiss/zinc/fieldmodule.hpp"
18 #include "opencmiss/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 
115  int setElement(const Element& element)
116  {
117  return cmzn_fieldcache_set_element(id, element.getId());
118  }
119 
135  int setMeshLocation(const Element& element, int coordinatesCount,
136  const double *coordinatesIn)
137  {
138  return cmzn_fieldcache_set_mesh_location(id, element.getId(),
139  coordinatesCount, coordinatesIn);
140  }
141 
154  int setFieldReal(const Field& referenceField, int valuesCount,
155  const double *valuesIn)
156  {
157  return cmzn_fieldcache_set_field_real(id,
158  referenceField.getId(), valuesCount, valuesIn);
159  }
160 
170  int setNode(const Node& node)
171  {
172  return cmzn_fieldcache_set_node(id, node.getId());
173  }
174 
181  int setTime(double time)
182  {
183  return cmzn_fieldcache_set_time(id, time);
184  }
185 };
186 
188 {
189  return Fieldcache(cmzn_fieldmodule_create_fieldcache(id));
190 }
191 
192 inline int Field::assignMeshLocation(const Fieldcache& cache, const Element& element,
193  int coordinatesCount, const double *coordinatesIn)
194 {
195  return cmzn_field_assign_mesh_location(id, cache.getId(), element.getId(),
196  coordinatesCount, coordinatesIn);
197 }
198 
199 inline int Field::assignReal(const Fieldcache& cache, int valuesCount, const double *valuesIn)
200 {
201  return cmzn_field_assign_real(id, cache.getId(), valuesCount, valuesIn);
202 }
203 
204 inline int Field::assignString(const Fieldcache& cache, const char *stringValue)
205 {
206  return cmzn_field_assign_string(id, cache.getId(), stringValue);
207 }
208 
209 inline Element Field::evaluateMeshLocation(const Fieldcache& cache, int coordinatesCount,
210  double *coordinatesOut)
211 {
212  return Element(cmzn_field_evaluate_mesh_location(id,
213  cache.getId(), coordinatesCount, coordinatesOut));
214 }
215 
216 inline int Field::evaluateReal(const Fieldcache& cache, int valuesCount, double *valuesOut)
217 {
218  return cmzn_field_evaluate_real(id, cache.getId(), valuesCount, valuesOut);
219 }
220 
221 inline char *Field::evaluateString(const Fieldcache& cache)
222 {
223  return cmzn_field_evaluate_string(id, cache.getId());
224 }
225 
226 inline int Field::evaluateDerivative(const Differentialoperator& differentialOperator,
227  const Fieldcache& cache, int valuesCount, double *valuesOut)
228 {
229  return cmzn_field_evaluate_derivative(id, differentialOperator.getId(),
230  cache.getId(), valuesCount, valuesOut);
231 }
232 
233 inline bool Field::isDefinedAtLocation(const Fieldcache& cache)
234 {
235  return cmzn_field_is_defined_at_location(id, cache.getId());
236 }
237 
238 } // namespace Zinc
239 }
240 
241 #endif /* CMZN_FIELDCACHE_HPP__ */
int evaluateDerivative(const Differentialoperator&differentialOperator, const Fieldcache &cache, int valuesCount, double *valuesOut)
Definition: fieldcache.hpp:226
A single finite element from a mesh.
Definition: element.hpp:34
Element evaluateMeshLocation(const Fieldcache &cache, int coordinatesCount, double *coordinatesOut)
Definition: fieldcache.hpp:209
Base field type: an abstraction of a mathematical field.
Definition: field.hpp:51
int assignReal(const Fieldcache &cache, int valuesCount, const double *valuesIn)
Definition: fieldcache.hpp:199
int clearLocation()
Definition: fieldcache.hpp:100
int setNode(const Node &node)
Definition: fieldcache.hpp:170
Describes the derivative of a field to evaluate.
Definition: differentialoperator.hpp:26
int assignString(const Fieldcache &cache, const char *stringValue)
Definition: fieldcache.hpp:204
int setElement(const Element &element)
Definition: fieldcache.hpp:115
int setTime(double time)
Definition: fieldcache.hpp:181
int setFieldReal(const Field &referenceField, int valuesCount, const double *valuesIn)
Definition: fieldcache.hpp:154
char * evaluateString(const Fieldcache &cache)
Definition: fieldcache.hpp:221
cmzn_field_id getId() const
Definition: field.hpp:103
bool isDefinedAtLocation(const Fieldcache &cache)
Definition: fieldcache.hpp:233
cmzn_element_id getId() const
Definition: element.hpp:207
int assignMeshLocation(const Fieldcache &cache, const Element &element, int coordinatesCount, const double *coordinatesIn)
Definition: fieldcache.hpp:192
cmzn_node_id getId() const
Definition: node.hpp:136
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:135
The OpenCMISS namespace.
Definition: context.hpp:20
Point object used to represent finite element nodes.
Definition: node.hpp:34
Fieldcache createFieldcache()
Definition: fieldcache.hpp:187
cmzn_fieldcache_id getId() const
Definition: fieldcache.hpp:86
int evaluateReal(const Fieldcache &cache, int valuesCount, double *valuesOut)
Definition: fieldcache.hpp:216