SCOREC core
Parallel unstructured mesh tools
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
apf.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011 Scientific Computation Research Center
3  *
4  * This work is open source software, licensed under the terms of the
5  * BSD license as described in the LICENSE file in the top-level directory.
6  */
7 
8 #ifndef APF_H
9 #define APF_H
10 
11 #include "apfMatrix.h"
12 #include "apfNew.h"
13 #include "apfDynamicArray.h"
14 
15 #include <vector>
16 #include <limits>
17 
31 namespace apf {
32 
33 class Field;
34 class Element;
35 class Mesh;
36 class MeshEntity;
37 class VectorElement;
39 typedef VectorElement MeshElement;
40 class FieldShape;
41 struct Sharing;
42 template <class T> class ReductionOp;
43 template <class T> class ReductionSum;
44 
52 template <class T>
53 class ReductionOp
54 {
55  public:
56  /* \brief apply operation, returning a single value */
57  virtual T apply(T val1, T val2) const = 0;
58 
59  /* \brief returns a value such that apply(val, neutral_val) == val */
60  virtual T getNeutralElement() const = 0;
61 };
62 
63 template <class T>
64 class ReductionSum : public ReductionOp<T>
65 {
66  T apply(T val1, T val2) const { return val1 + val2; };
67  T getNeutralElement() const { return 0; };
68 };
69 
70 template <class T>
71 class ReductionMin : public ReductionOp<T>
72 {
73  T apply(T val1, T val2) const { return ( (val1 < val2) ? val1 : val2 ); };
74  T getNeutralElement() const { return std::numeric_limits<T>::max(); };
75 };
76 
77 template <class T>
78 class ReductionMax : public ReductionOp<T>
79 {
80  T apply(T val1, T val2) const { return ( (val1 < val2) ? val2 : val1 ); };
81  T getNeutralElement() const { return std::numeric_limits<T>::min(); };
82 };
83 
90 void destroyMesh(Mesh* m);
91 
99 MeshElement* createMeshElement(Mesh* m, MeshEntity* e);
100 
110 MeshElement* createMeshElement(Field* c, MeshEntity* e);
111 
114 MeshEntity * getMeshEntity(MeshElement * me);
115 
122 
127 enum ValueType {
138 };
139 
147 Field* createLagrangeField(Mesh* m, const char* name, int valueType, int order);
148 
159 Field* createStepField(Mesh* m, const char* name, int valueType);
160 
168 Field* createIPField(Mesh* m, const char* name, int valueType, int order);
169 
172 Field* createField(Mesh* m, const char* name, int valueType, FieldShape* shape);
173 
175 Field* createFieldOn(Mesh* m, const char* name, int valueType);
176 
183 Field* createPackedField(Mesh* m, const char* name, int components,
184  apf::FieldShape* shape = 0);
185 
187 Field* createGeneralField(
188  Mesh* m,
189  const char* name,
190  int valueType,
191  int components,
192  FieldShape* shape);
193 
197 Field* cloneField(Field* f, Mesh* onto);
198 
201 Mesh* getMesh(Field* f);
202 
205 bool hasEntity(Field* f, MeshEntity* e);
206 
212 const char* getName(Field* f);
213 
216 int getValueType(Field* f);
217 
223 void destroyField(Field* f);
224 
231 void setScalar(Field* f, MeshEntity* e, int node, double value);
232 
237 double getScalar(Field* f, MeshEntity* e, int node);
238 
243 void setVector(Field* f, MeshEntity* e, int node, Vector3 const& value);
244 
247 void getVector(Field* f, MeshEntity* e, int node, Vector3& value);
248 
253 void setMatrix(Field* f, MeshEntity* e, int node, Matrix3x3 const& value);
254 
257 void getMatrix(Field* f, MeshEntity* e, int node, Matrix3x3& value);
258 
260 void setComponents(Field* f, MeshEntity* e, int node, double const* components);
261 
266 void getComponents(Field* f, MeshEntity* e, int node, double* components);
267 
278 Element* createElement(Field* f, MeshElement* e);
279 
284 Element* createElement(Field* f, MeshEntity* e);
285 
288 void destroyElement(Element* e);
289 
297 MeshElement* getMeshElement(Element* e);
298 
300 MeshEntity* getMeshEntity(Element* e);
301 
307 double getScalar(Element* e, Vector3 const& param);
308 
314 void getGrad(Element* e, Vector3 const& param, Vector3& grad);
315 
321 void getVector(Element* e, Vector3 const& param, Vector3& value);
322 
328 double getDiv(Element* e, Vector3 const& param);
329 
335 void getCurl(Element* e, Vector3 const& param, Vector3& curl);
336 
346 void getVectorGrad(Element* e, Vector3 const& param, Matrix3x3& deriv);
347 
353 void getMatrix(Element* e, Vector3 const& param, Matrix3x3& value);
354 
360 void getMatrixGrad(Element* e, Vector3 const& param, Vector<27>& value);
361 
363 void getComponents(Element* e, Vector3 const& param, double* components);
364 
370 int countIntPoints(MeshElement* e, int order);
371 
378 void getIntPoint(MeshElement* e, int order, int point, Vector3& param);
379 
386 double getIntWeight(MeshElement* e, int order, int point);
387 
390 void mapLocalToGlobal(MeshElement* e, Vector3 const& local, Vector3& global);
391 
401 double getDV(MeshElement* e, Vector3 const& param);
402 
416 {
417  public:
419  Integrator(int o);
420  virtual ~Integrator();
427  void process(Mesh* m, int dim=-1);
429  void process(MeshElement* e);
436  virtual void inElement(MeshElement*);
443  virtual void outElement();
454  virtual void atPoint(Vector3 const& p, double w, double dV) = 0;
461  virtual void parallelReduce();
462  protected:
463  int order;
464  int ipnode;
465 };
466 
475 double measure(MeshElement* e);
476 
481 double measure(Mesh* m, MeshEntity* e);
482 
485 int getOrder(MeshElement* e);
486 
489 void getJacobian(MeshElement* e, Vector3 const& local, Matrix3x3& j);
490 
498 void getJacobianInv(MeshElement* e, Vector3 const& local, Matrix3x3& jinv);
499 
515 double computeCosAngle(Mesh* m, MeshEntity* pe, MeshEntity* e1, MeshEntity* e2,
516  const Matrix3x3& Q);
517 
518 double computeCosAngleInTri(Mesh* m, MeshEntity* tri,
519  MeshEntity* e1, MeshEntity* e2, const Matrix3x3& Q);
520 
521 double computeCosAngleInTet(Mesh* m, MeshEntity* tet,
522  MeshEntity* e1, MeshEntity* e2, const Matrix3x3& Q);
523 
524 Vector3 computeFaceNormalAtEdgeInTet(Mesh* m, MeshEntity* tet,
525  MeshEntity* face, MeshEntity* edge, Matrix3x3 Q);
526 
527 Vector3 computeFaceNormalAtVertex(Mesh* m, MeshEntity* face,
528  MeshEntity* vert, const Matrix3x3& Q);
529 
530 Vector3 computeEdgeTangentAtVertex(Mesh* m, MeshEntity* edge,
531  MeshEntity* vert, const Matrix3x3& Q);
532 
540 double computeShortestHeightInTet(Mesh* m, MeshEntity* tet,
541  const Matrix3x3& Q = Matrix3x3(1.,0.,0.,0.,1.,0.,0.,0.,1.));
542 
550 double computeLargestHeightInTet(Mesh* m, MeshEntity* tet,
551  const Matrix3x3& Q = Matrix3x3(1.,0.,0.,0.,1.,0.,0.,0.,1.));
552 
553 
561 double computeShortestHeightInTri(Mesh* m, MeshEntity* tri,
562  const Matrix3x3& Q = Matrix3x3(1.,0.,0.,0.,1.,0.,0.,0.,1.));
563 
571 double computeLargestHeightInTri(Mesh* m, MeshEntity* tri,
572  const Matrix3x3& Q = Matrix3x3(1.,0.,0.,0.,1.,0.,0.,0.,1.));
573 
574 
580 int countNodes(Element* e);
581 
584 void getScalarNodes(Element* e, NewArray<double>& values);
585 
588 void getVectorNodes(Element* e, NewArray<Vector3>& values);
589 
592 void getMatrixNodes(Element* e, NewArray<Matrix3x3>& values);
593 
596 void getShapeValues(Element* e, Vector3 const& local,
597  NewArray<double>& values);
598 
603 void getShapeGrads(Element* e, Vector3 const& local,
604  NewArray<Vector3>& grads);
605 
606 
609 FieldShape* getShape(Field* f);
610 
613 int countComponents(Field* f);
614 
623 #define APF_ITERATE(t,w,i) \
624 for (t::iterator i = (w).begin(); \
625  (i) != (w).end(); ++(i))
626 
628 #define APF_CONST_ITERATE(t,w,i) \
629 for (t::const_iterator i = (w).begin(); \
630  (i) != (w).end(); ++(i))
631 
637 void writeVtkFiles(const char* prefix, Mesh* m, int cellDim = -1);
638 
645 void writeVtkFiles(const char* prefix, Mesh* m,
646  std::vector<std::string> writeFields, int cellDim = -1);
647 
651 void writeOneVtkFile(const char* prefix, Mesh* m);
652 
658 void writeASCIIVtkFiles(const char* prefix, Mesh* m);
659 
666 void writeASCIIVtkFiles(const char* prefix, Mesh* m,
667  std::vector<std::string> writeFields);
668 
675 void getGaussPoint(int type, int order, int point, Vector3& param);
676 
678 int countGaussPoints(int type, int order);
679 
687 double getJacobianDeterminant(Matrix3x3 const& J, int dimension);
688 
690 int getDimension(MeshElement* me);
691 
697 void synchronize(Field* f, Sharing* shr = 0);
698 
705 void accumulate(Field* f, Sharing* shr = 0, bool delete_shr = false);
706 
713 void sharedReduction(Field* f, Sharing* shr, bool delete_shr,
714  const ReductionOp<double>& sum = ReductionSum<double>());
715 
719 bool isPrintable(Field* f);
720 
727 void fail(const char* why) __attribute__((noreturn));
728 
730 void freeze(Field* f);
731 
733 void unfreeze(Field* f);
734 
736 bool isFrozen(Field* f);
737 
743 double* getArrayData(Field* f);
744 
746 void zeroField(Field* f);
747 
749 struct Function
750 {
752  virtual ~Function();
759  virtual void eval(MeshEntity* e, double* result) = 0;
760 };
761 
762 /* \brief Create a Field from a user's analytic function.
763  * \details This field will use no memory, has values on all
764  * nodes, and calls the user Function for all value queries.
765  * Writing to this field does nothing.
766  * \warning if you copy the mesh with apf::convert you may want to use
767  * apf::updateUserField to update function that this field refers to. This is
768  * extremely important if the analytic function you use references user fields.
769  */
770 Field* createUserField(Mesh* m, const char* name, int valueType, FieldShape* s,
771  Function* f);
772 
773 /* \brief update the analytic function from a user field
774  * \details this field updates the apf::Function which the UserField refers to
775  */
776 void updateUserField(Field* field, Function* newFunc);
777 
782 Field* recoverGradientByVolume(Field* f);
783 
784 void copyData(Field* to, Field* from);
785 
787 void projectField(Field* to, Field* from);
788 
789 void axpy(double a, Field* x, Field* y);
790 
791 void renameField(Field* f, const char* name);
792 
800 void getBF(FieldShape* s, MeshElement* e, Vector3 const& p,
801  NewArray<double>& BF);
802 
807 void getGradBF(FieldShape* s, MeshElement* e, Vector3 const& p,
808  NewArray<Vector3>& gradBF);
809 
810 }
811 
812 #endif
bool isFrozen(Field *f)
Returns true iff the Field uses array storage.
virtual void eval(MeshEntity *e, double *result)=0
The user&#39;s analytic function call.
a single scalar value.
Definition: apf.h:129
double * getArrayData(Field *f)
Return the contiguous array storing this field.
User-defined Analytic Function.
Definition: apf.h:749
void destroyElement(Element *e)
Destroy a Field Element.
void accumulate(Field *f, Sharing *shr=0, bool delete_shr=false)
Add field values along partition boundary.
ValueType
The type of value the field stores.
Definition: apf.h:127
void getComponents(Field *f, MeshEntity *e, int node, double *components)
Copy the nodal value into an array of component values.
void setScalar(Field *f, MeshEntity *e, int node, double value)
Set a nodal value of a scalar field.
void getIntPoint(MeshElement *e, int order, int point, Vector3 &param)
Get an integration point in an element.
Field * createPackedField(Mesh *m, const char *name, int components, apf::FieldShape *shape=0)
Create a field of N components without a tensor type.
double getIntWeight(MeshElement *e, int order, int point)
Get the weight of an integration point in an element.
Field * createLagrangeField(Mesh *m, const char *name, int valueType, int order)
Create an apf::Field using a Lagrange distribution.
void getJacobianInv(MeshElement *e, Vector3 const &local, Matrix3x3 &jinv)
Returns the Jacobian inverse at a local point.
Element * createElement(Field *f, MeshElement *e)
Create a Field Element from a Mesh Element.
Field * cloneField(Field *f, Mesh *onto)
Declare a copy of a field on another apf::Mesh.
virtual void parallelReduce()
User callback: parallel reduction.
void setMatrix(Field *f, MeshEntity *e, int node, Matrix3x3 const &value)
Set the nodal value of a matrix field.
bool isPrintable(Field *f)
Checks whether a Field/Numbering/GlobalNumbering is complete and therefore printable to visualization...
Describes field distribution and shape functions.
Definition: apfShape.h:73
int countIntPoints(MeshElement *e, int order)
Get the number of integration points for an element.
int getDimension(Mesh *m, MeshEntity *e)
get the dimension of a mesh entity
void synchronize(Field *f, Sharing *shr=0)
Synchronize field values along partition boundary.
double computeLargestHeightInTet(Mesh *m, MeshEntity *tet, const Matrix3x3 &Q=Matrix3x3(1., 0., 0., 0., 1., 0., 0., 0., 1.))
Returns the largest height in a tet.
void destroyMesh(Mesh *m)
Destroys an apf::Mesh.
virtual void atPoint(Vector3 const &p, double w, double dV)=0
User callback: accumulation.
double computeShortestHeightInTet(Mesh *m, MeshEntity *tet, const Matrix3x3 &Q=Matrix3x3(1., 0., 0., 0., 1., 0., 0., 0., 1.))
Returns the shortest height in a tet.
The APF linear algebra matrix interface.
a 3D vector value
Definition: apf.h:131
void mapLocalToGlobal(MeshElement *e, Vector3 const &local, Vector3 &global)
Map a local coordinate to a global coordinate.
void getBF(FieldShape *s, MeshElement *e, Vector3 const &p, NewArray< double > &BF)
Get the basis functions over a mesh element.
void zeroField(Field *f)
Initialize all nodal values with all-zero components.
Field * createIPField(Mesh *m, const char *name, int valueType, int order)
Create an apf::Field of integration point data.
Field * recoverGradientByVolume(Field *f)
Compute a nodal gradient field from a nodal input field.
void getShapeValues(Element *e, Vector3 const &local, NewArray< double > &values)
Returns the shape function values at a point.
void getCurl(Element *e, Vector3 const &param, Vector3 &curl)
Evaluate the curl of a vector field at a point.
void writeVtkFiles(const char *prefix, Mesh *m, int cellDim=-1)
Write a set of parallel VTK Unstructured Mesh files from an apf::Mesh with binary (base64) encoding a...
int countGaussPoints(int type, int order)
Return the number of Gaussian integration points.
Base class for applying operations to make a Field consistent in parallel.
Definition: apf.h:42
Field * createGeneralField(Mesh *m, const char *name, int valueType, int components, FieldShape *shape)
Encompasses both packed and typed fields.
void setVector(Field *f, MeshEntity *e, int node, Vector3 const &value)
Set the nodal value of a vector field.
convenience wrapper over apf::Matrix&lt;3,3&gt;
Definition: apfMatrix.h:178
void getVectorNodes(Element *e, NewArray< Vector3 > &values)
Returns the element nodal values for a vector field.
double computeCosAngle(Mesh *m, MeshEntity *pe, MeshEntity *e1, MeshEntity *e2, const Matrix3x3 &Q)
Returns the cosine of the angle between 2 entities of the parent entity.
void process(Mesh *m, int dim=-1)
Run the Integrator over the local Mesh.
placeholder used to set array sizes
Definition: apf.h:137
double measure(MeshElement *e)
Measures the volume, area, or length of a Mesh Element.
double getDV(MeshElement *e, Vector3 const &param)
Get the differential volume at a point.
void writeOneVtkFile(const char *prefix, Mesh *m)
Output just the .vtu file with ASCII encoding for this part.
Field * createStepField(Mesh *m, const char *name, int valueType)
Create an apf::Field using a step distribution.
MeshElement * createMeshElement(Mesh *m, MeshEntity *e)
Creates a Mesh Element over an entity.
a 3x3 matrix
Definition: apf.h:133
void getVector(Field *f, MeshEntity *e, int node, Vector3 &value)
Get the nodal value of a vector field.
virtual void outElement()
User callback: element exit.
double computeLargestHeightInTri(Mesh *m, MeshEntity *tri, const Matrix3x3 &Q=Matrix3x3(1., 0., 0., 0., 1., 0., 0., 0., 1.))
Returns the largest height in a tri.
Interface to a mesh part.
Definition: apfMesh.h:103
int countNodes(Element *e)
Returns the number of element nodes.
void getVectorGrad(Element *e, Vector3 const &param, Matrix3x3 &deriv)
Get the gradient of a vector field w.r.t. global coordinates.
virtual ~Function()
Possible user-defined cleanup.
FieldShape * getShape(Field *f)
Retrieve the apf::FieldShape used by a field.
void getMatrix(Field *f, MeshEntity *e, int node, Matrix3x3 &value)
Get the nodal value of a matrix field.
void getGradBF(FieldShape *s, MeshElement *e, Vector3 const &p, NewArray< Vector3 > &gradBF)
Get global gradients of basis functions over a mesh element.
void fail(const char *why) __attribute__((noreturn))
Declare failure of code inside APF.
void getMatrixGrad(Element *e, Vector3 const &param, Vector< 27 > &value)
get the gradient of a matrix field
void projectField(Field *to, Field *from)
Project a field from an existing field.
apf::Mesh2 Mesh
convenient mesh name
Definition: maMesh.h:27
abstract description of entity copy sharing
Definition: apfMesh.h:483
void setComponents(Field *f, MeshEntity *e, int node, double const *components)
Set the nodal value from an array of component values.
void getScalarNodes(Element *e, NewArray< double > &values)
Returns the element nodal values for a scalar field.
Integrator(int o)
Construct an Integrator given an order of accuracy.
void sharedReduction(Field *f, Sharing *shr, bool delete_shr, const ReductionOp< double > &sum=ReductionSum< double >())
Apply a reudction operator along partition boundaries.
convenience wrapper over apf::Vector&lt;3&gt;
Definition: apfVector.h:150
MeshEntity * getMeshEntity(MeshElement *me)
Retrieve the mesh entity associated with an apf::MeshElement.
void freeze(Field *f)
Convert a Field from Tag to array storage.
virtual void inElement(MeshElement *)
User callback: element entry.
Field * createFieldOn(Mesh *m, const char *name, int valueType)
Create a field using the mesh&#39;s coordinate nodal distribution.
double getScalar(Field *f, MeshEntity *e, int node)
Get the node value of a scalar field.
void getGaussPoint(int type, int order, int point, Vector3 &param)
Return the location of a gaussian integration point.
void writeASCIIVtkFiles(const char *prefix, Mesh *m)
Write a set of parallel VTK Unstructured Mesh files from an apf::Mesh with ASCII encoding.
void destroyField(Field *f)
Destroy an apf::Field.
Field * createField(Mesh *m, const char *name, int valueType, FieldShape *shape)
Create a Field from any builtin or user defined FieldShape.
Mesh * getMesh(Field *f)
Retrieve the Mesh over which a Field is defined.
int countComponents(Field *f)
Count the number of scalar components in the field&#39;s value type.
void getMatrixNodes(Element *e, NewArray< Matrix3x3 > &values)
Returns the element nodal values for a matrix field.
int getValueType(Field *f)
Retrieve the type of value a field distributes.
double getDiv(Element *e, Vector3 const &param)
Evaluate the divergence of a vector field at a point.
int getOrder(MeshElement *e)
Returns the polynomial order of the coordinate field.
bool hasEntity(Field *f, MeshEntity *e)
Returns true iff an entity has data associate with a field.
a user-defined set of components
Definition: apf.h:135
void unfreeze(Field *f)
Convert a Field from array to Tag storage.
void getGrad(Element *e, Vector3 const &param, Vector3 &grad)
Get the gradient of a scalar field w.r.t. global coordinates.
double getJacobianDeterminant(Matrix3x3 const &J, int dimension)
Return the Jacobian determinant or dimensional equivalent.
double computeShortestHeightInTri(Mesh *m, MeshEntity *tri, const Matrix3x3 &Q=Matrix3x3(1., 0., 0., 0., 1., 0., 0., 0., 1.))
Returns the shortest height in a tri.
VectorElement MeshElement
Mesh Elements represent the mesh coordinate vector field.
Definition: apf.h:37
void getJacobian(MeshElement *e, Vector3 const &local, Matrix3x3 &j)
Returns the Jacobian at a local point.
void destroyMeshElement(MeshElement *e)
Destroys a Mesh Element.
const char * getName(Field *f)
Get the name of a Field.
A virtual base for user-defined integrators.
Definition: apf.h:415
void getShapeGrads(Element *e, Vector3 const &local, NewArray< Vector3 > &grads)
Returns the shape function gradients at a point.
MeshElement * getMeshElement(Element *e)
Get the Mesh Element of a Field Element.