moab
moab::ElemEvaluator Class Reference

Class facilitating local discretization-related functionsThis class implements discretization-related functionality operating on data in MOAB. A member of this class caches certain data about the element it's currently operating on, but is not meant to be instantiated one-per-element, but rather one-per-search (or other operation on a collection of elements). More...

#include <ElemEvaluator.hpp>

List of all members.

Public Member Functions

 ElemEvaluator (Interface *impl, EntityHandle ent=0, Tag tag=0, int tagged_ent_dim=-1)
 Constructor.
ErrorCode eval (const double *params, double *result, int num_tuples=-1) const
 Evaluate cached tag at a given parametric location within the cached entity If evaluating coordinates, call set_tag(0, 0), which indicates coords instead of a tag.
ErrorCode reverse_eval (const double *posn, double iter_tol, double inside_tol, double *params, int *is_inside=NULL) const
 Reverse-evaluate the cached entity at a given physical position.
ErrorCode jacobian (const double *params, double *result) const
 Evaluate the jacobian of the cached entity at a given parametric location.
ErrorCode integrate (double *result) const
 Integrate the cached tag over the cached entity.
int inside (const double *params, const double tol) const
 Return whether a physical position is inside the cached entity to within a tolerance.
ErrorCode find_containing_entity (Range &entities, const double *point, const double iter_tol, const double inside_tol, EntityHandle &containing_ent, double *params, unsigned int *num_evals=NULL)
 Given a list of entities, return the entity the point is in, or none This function reverse-evaluates the entities, returning the first entity containing the point. If no entity contains the point, containing_ent is returned as 0 and params are unchanged. This function returns something other than MB_SUCCESS only when queries go wrong for some reason. num_evals, if non-NULL, is always incremented for each call to reverse_eval. This function calls set_ent_handle for each entity before calling reverse_eval, so the ElemEvaluator object is changed.
ErrorCode find_containing_entity (EntityHandle ent_set, const double *point, const double iter_tol, const double inside_tol, EntityHandle &containing_ent, double *params, unsigned int *num_evals=NULL)
 Given an entity set, return the contained entity the point is in, or none This function reverse-evaluates the entities, returning the first entity containing the point. If no entity contains the point, containing_ent is returned as 0 and params are unchanged. This function returns something other than MB_SUCCESS only when queries go wrong for some reason. num_evals, if non-NULL, is always incremented for each call to reverse_eval. This function calls set_ent_handle for each entity before calling reverse_eval, so the ElemEvaluator object is changed.
ErrorCode set_eval_set (EntityType tp, const EvalSet &eval_set)
 Set the eval set for a given type entity.
ErrorCode set_eval_set (const EntityHandle eh)
 Set the eval set using a given entity handle This function queries the entity type and number of vertices on the entity to decide which type of shape function to use. NOTE: this function should only be called after setting a valid MOAB instance on the evaluator.
EvalSet get_eval_set (EntityType tp)
 Get the eval set for a given type entity.
ErrorCode set_ent_handle (EntityHandle ent)
 Set entity handle & cache connectivty & vertex positions.
EntityHandle get_ent_handle () const
 Get entity handle for this ElemEval.
double * get_vert_pos ()
const EntityHandleget_vert_handles () const
int get_num_verts () const
Tag get_tag_handle () const
ErrorCode set_tag_handle (Tag tag, int tagged_ent_dim=-1)
ErrorCode set_tag (const char *tag_name, int tagged_ent_dim=-1)
int get_tagged_ent_dim () const
ErrorCode set_tagged_ent_dim (int dim)
double * get_work_space ()
Interfaceget_moab ()

Private Attributes

InterfacembImpl
 Interface.
EntityHandle entHandle
 Entity handle being evaluated.
EntityType entType
 Entity type.
int entDim
 Entity dimension.
int numVerts
 Number of vertices cached here.
const EntityHandlevertHandles
 Cached copy of vertex handle ptr.
CartVect vertPos [CN::MAX_NODES_PER_ELEMENT]
 Cached copy of vertex positions.
Tag tagHandle
 Tag being evaluated.
bool tagCoords
 Whether tag is coordinates or something else.
int numTuples
 Number of values in this tag.
int taggedEntDim
 Dimension of entities from which to grab tag.
std::vector< unsigned char > tagSpace
 Tag space.
EvalSet evalSets [MBMAXTYPE]
 Evaluation methods for elements of various topologies.
double * workSpace
 Work space for element-specific data.

Detailed Description

Class facilitating local discretization-related functions

This class implements discretization-related functionality operating on data in MOAB. A member of this class caches certain data about the element it's currently operating on, but is not meant to be instantiated one-per-element, but rather one-per-search (or other operation on a collection of elements).

Actual discretization functionality is accessed through function pointers, allowing applications to specialize the implementation of specific functions while still using this class.

This class depends on MOAB functionality for gathering entity-based data; the functions it calls through function pointers depend only on POD (plain old data, or intrinsic data types). This allows the use of other packages for serving these functions, without having to modify them to get data through MOAB. This should also promote efficiency, since in many cases they will be able to read data from its native storage locations.

Definition at line 117 of file ElemEvaluator.hpp.


Constructor & Destructor Documentation

moab::ElemEvaluator::ElemEvaluator ( Interface impl,
EntityHandle  ent = 0,
Tag  tag = 0,
int  tagged_ent_dim = -1 
) [inline]

Constructor.

Parameters:
implMOAB instance
entEntity handle to cache on the evaluator; if non-zero, calls set_ent_handle, which does some other stuff.
tagTag to cache on the evaluator; if non-zero, calls set_tag_handle, which does some other stuff too.
tagged_ent_dimDimension of entities to be tagged to cache on the evaluator

Definition at line 319 of file ElemEvaluator.hpp.

            : mbImpl(impl), entHandle(0), entType(MBMAXTYPE), entDim(-1), numVerts(0), 
              vertHandles(NULL), tagHandle(0), tagCoords(false), numTuples(0), 
              taggedEntDim(0), workSpace(NULL)
    {
      if (ent) set_ent_handle(ent);
      if (tag) set_tag_handle(tag, tagged_ent_dim);
    }

Member Function Documentation

ErrorCode moab::ElemEvaluator::eval ( const double *  params,
double *  result,
int  num_tuples = -1 
) const [inline]

Evaluate cached tag at a given parametric location within the cached entity If evaluating coordinates, call set_tag(0, 0), which indicates coords instead of a tag.

Parameters:
paramsParameters at which to evaluate field
resultResult of evaluation
num_tuplesSize of evaluated field, in number of values

Definition at line 449 of file ElemEvaluator.hpp.

    {
      assert(entHandle && MBMAXTYPE != entType);
      return (*evalSets[entType].evalFcn)(params, 
                                          (tagCoords ? (const double*) vertPos[0].array(): (const double*)&tagSpace[0]), 
                                          entDim, 
                                          (-1 == num_tuples ? numTuples : num_tuples), workSpace, result);
    }
ErrorCode moab::ElemEvaluator::find_containing_entity ( Range entities,
const double *  point,
const double  iter_tol,
const double  inside_tol,
EntityHandle containing_ent,
double *  params,
unsigned int *  num_evals = NULL 
)

Given a list of entities, return the entity the point is in, or none This function reverse-evaluates the entities, returning the first entity containing the point. If no entity contains the point, containing_ent is returned as 0 and params are unchanged. This function returns something other than MB_SUCCESS only when queries go wrong for some reason. num_evals, if non-NULL, is always incremented for each call to reverse_eval. This function calls set_ent_handle for each entity before calling reverse_eval, so the ElemEvaluator object is changed.

Parameters:
entitiesEntities tested
pointPoint tested, must have 3 dimensions, even for edge and face entities
iter_tolTolerance for non-linear reverse evaluation
inside_tolTolerance for is_inside test
containing_entEntity containing the point, returned 0 if no entity
paramsParameters of point in containing entity, unchanged if no containing entity
num_evalsIf non-NULL, incremented each time reverse_eval is called
Returns:
Returns non-success only if evaulation failed for some reason (point not in element is NOT a reason for failure)

Definition at line 117 of file ElemEvaluator.cpp.

    {
      int is_inside;
      ErrorCode rval = MB_SUCCESS;
      unsigned int nevals = 0;
      Range::iterator i;
      for(i = entities.begin(); i != entities.end(); i++) {
        nevals++;
        set_ent_handle(*i);
        rval = reverse_eval(point, iter_tol, inside_tol, params, &is_inside);
        if (MB_SUCCESS != rval) return rval;
        if (is_inside) break;
      }
      containing_ent = (i == entities.end() ? 0 : *i);
      if (num_evals) *num_evals += nevals;
      return MB_SUCCESS;
    }
ErrorCode moab::ElemEvaluator::find_containing_entity ( EntityHandle  ent_set,
const double *  point,
const double  iter_tol,
const double  inside_tol,
EntityHandle containing_ent,
double *  params,
unsigned int *  num_evals = NULL 
) [inline]

Given an entity set, return the contained entity the point is in, or none This function reverse-evaluates the entities, returning the first entity containing the point. If no entity contains the point, containing_ent is returned as 0 and params are unchanged. This function returns something other than MB_SUCCESS only when queries go wrong for some reason. num_evals, if non-NULL, is always incremented for each call to reverse_eval. This function calls set_ent_handle for each entity before calling reverse_eval, so the ElemEvaluator object is changed.

Parameters:
ent_setEntity set containing the entities to be tested
pointPoint tested, must have 3 dimensions, even for edge and face entities
iter_tolTolerance for non-linear reverse evaluation
inside_tolTolerance for is_inside test
containing_entEntity containing the point, returned 0 if no entity
paramsParameters of point in containing entity, unchanged if no containing entity
num_evalsIf non-NULL, incremented each time reverse_eval is called
Returns:
Returns non-success only if evaulation failed for some reason (point not in element is NOT a reason for failure)

Definition at line 489 of file ElemEvaluator.hpp.

    {
      assert(mbImpl->type_from_handle(ent_set) == MBENTITYSET);
      Range entities;
      ErrorCode rval = mbImpl->get_entities_by_handle(ent_set, entities);
      if (MB_SUCCESS != rval) return rval;
      else return find_containing_entity(entities, point, iter_tol, inside_tol, containing_ent, params, num_evals);
    }

Get entity handle for this ElemEval.

Definition at line 228 of file ElemEvaluator.hpp.

{return entHandle;}
EvalSet moab::ElemEvaluator::get_eval_set ( EntityType  tp) [inline]

Get the eval set for a given type entity.

Definition at line 222 of file ElemEvaluator.hpp.

{return evalSets[tp];}

Definition at line 271 of file ElemEvaluator.hpp.

{return mbImpl;}
int moab::ElemEvaluator::get_num_verts ( ) const [inline]

Definition at line 238 of file ElemEvaluator.hpp.

{return numVerts;}

Definition at line 241 of file ElemEvaluator.hpp.

{return tagHandle;};

Definition at line 260 of file ElemEvaluator.hpp.

{return taggedEntDim;};

Definition at line 235 of file ElemEvaluator.hpp.

{return vertHandles;}
double* moab::ElemEvaluator::get_vert_pos ( ) [inline]

Definition at line 232 of file ElemEvaluator.hpp.

{return vertPos[0].array();}

Definition at line 268 of file ElemEvaluator.hpp.

{return workSpace;}
int moab::ElemEvaluator::inside ( const double *  params,
const double  tol 
) const [inline]

Return whether a physical position is inside the cached entity to within a tolerance.

Parameters:
paramsParameters at which to query the element
tolTolerance, usually 10^-6 or so

Definition at line 501 of file ElemEvaluator.hpp.

    {
      return (*evalSets[entType].insideFcn)(params, entDim, tol);
    }
ErrorCode moab::ElemEvaluator::integrate ( double *  result) const [inline]

Integrate the cached tag over the cached entity.

Parameters:
resultResult of the integration

Definition at line 475 of file ElemEvaluator.hpp.

    {
      assert(entHandle && MBMAXTYPE != entType && (tagCoords || tagHandle));
      ErrorCode rval = MB_SUCCESS;
      if (!tagCoords) {
        if (0 == taggedEntDim) rval = mbImpl->tag_get_data(tagHandle, vertHandles, numVerts, (void*)&tagSpace[0]);
        else rval = mbImpl->tag_get_data(tagHandle, &entHandle, 1, (void*)&tagSpace[0]);
        if (MB_SUCCESS != rval) return rval;
      }
      return (*evalSets[entType].integrateFcn)((tagCoords ? vertPos[0].array() : (const double *)&tagSpace[0]), 
                                               vertPos[0].array(), numVerts, entDim, numTuples, 
                                               workSpace, result);
    }
ErrorCode moab::ElemEvaluator::jacobian ( const double *  params,
double *  result 
) const [inline]

Evaluate the jacobian of the cached entity at a given parametric location.

Parameters:
paramsParameters at which to evaluate jacobian
resultResult of evaluation, in the form of a 3x3 matrix, stored in column-major order

Definition at line 468 of file ElemEvaluator.hpp.

    {
      assert(entHandle && MBMAXTYPE != entType);
      return (*evalSets[entType].jacobianFcn)(params, vertPos[0].array(), numVerts, entDim, workSpace, result);
    }
ErrorCode moab::ElemEvaluator::reverse_eval ( const double *  posn,
double  iter_tol,
double  inside_tol,
double *  params,
int *  is_inside = NULL 
) const [inline]

Reverse-evaluate the cached entity at a given physical position.

Parameters:
posnPosition at which to evaluate parameters
iter_tolTolerance of reverse evaluation non-linear iteration, usually 10^-10 or so
inside_tolTolerance of is_inside evaluation, usually 10^-6 or so
paramsResult of evaluation
is_insideIf non-NULL, returns true of resulting parameters place the point inside the element (in most cases, within [-1]*(dim)

Definition at line 458 of file ElemEvaluator.hpp.

    {
      assert(entHandle && MBMAXTYPE != entType);
      return (*evalSets[entType].reverseEvalFcn)(evalSets[entType].evalFcn, evalSets[entType].jacobianFcn, evalSets[entType].insideFcn,
                                                 posn, vertPos[0].array(), numVerts, 
                                                 entDim, iter_tol, inside_tol, workSpace, params, ins);
    }

Set entity handle & cache connectivty & vertex positions.

Definition at line 328 of file ElemEvaluator.hpp.

    {
      entHandle = ent;
      if (workSpace) {
        delete [] workSpace;
        workSpace = NULL;
      }

      entType = mbImpl->type_from_handle(ent);
      entDim = mbImpl->dimension_from_handle(ent);

      std::vector<EntityHandle> dum_vec;
      ErrorCode rval = mbImpl->get_connectivity(ent, vertHandles, numVerts, false, &dum_vec);
      if (MB_SUCCESS != rval) return rval;

      if (!evalSets[entType].evalFcn)
        EvalSet::get_eval_set(entType, numVerts, evalSets[entType]);

      rval = mbImpl->get_coords(vertHandles, numVerts, vertPos[0].array());
      if (MB_SUCCESS != rval) return rval;

      if (tagHandle) {
        rval = set_tag_handle(tagHandle);
        if (MB_SUCCESS != rval) return rval;
      }
      if (evalSets[entType].initFcn) return (*evalSets[entType].initFcn)(vertPos[0].array(), numVerts, workSpace);
      return MB_SUCCESS;
    }
ErrorCode moab::ElemEvaluator::set_eval_set ( EntityType  tp,
const EvalSet eval_set 
) [inline]

Set the eval set for a given type entity.

Parameters:
tpEntity type for which to set the eval set
eval_setEval set object to use

Definition at line 439 of file ElemEvaluator.hpp.

    {
      evalSets[tp] = eval_set;
      if (entHandle && evalSets[entType].initFcn) {
        ErrorCode rval = (*evalSets[entType].initFcn)(vertPos[0].array(), numVerts, workSpace);
        if (MB_SUCCESS != rval) return rval;
      }
      return MB_SUCCESS;
    }

Set the eval set using a given entity handle This function queries the entity type and number of vertices on the entity to decide which type of shape function to use. NOTE: this function should only be called after setting a valid MOAB instance on the evaluator.

Parameters:
ehEntity handle whose type and #vertices are queried

Definition at line 506 of file ElemEvaluator.hpp.

    {
      EvalSet eset;
      ErrorCode rval = EvalSet::get_eval_set(mbImpl, eh, evalSets[mbImpl->type_from_handle(eh)]); 
      return rval;
    }
ErrorCode moab::ElemEvaluator::set_tag ( const char *  tag_name,
int  tagged_ent_dim = -1 
) [inline]

Definition at line 394 of file ElemEvaluator.hpp.

    {
      ErrorCode rval = MB_SUCCESS;
      if (!tag_name || strlen(tag_name) == 0) return MB_FAILURE;
      Tag tag;
      if (!strcmp(tag_name, "COORDS")) {
        tagCoords = true;
        taggedEntDim = 0;
        numTuples = 3;
        tagHandle = 0;
          // can return here, because vertex coords already cached when entity handle set
        return rval;
      }
      else {
        rval = mbImpl->tag_get_handle(tag_name, tag);
        if (MB_SUCCESS != rval) return rval;
      
        if (tagHandle != tag) {
          tagHandle = tag;
          rval = mbImpl->tag_get_length(tagHandle, numTuples);
          if (MB_SUCCESS != rval) return rval;
          int sz;
          rval = mbImpl->tag_get_bytes(tag, sz);
          if (MB_SUCCESS != rval) return rval;
          tagSpace.reserve(CN::MAX_NODES_PER_ELEMENT*sz);
          tagCoords = false;
        }

        taggedEntDim = (-1 == tagged_ent_dim ? entDim : tagged_ent_dim);
      }
      
      if (entHandle) {
        if (0 == taggedEntDim) {
          rval = mbImpl->tag_get_data(tagHandle, vertHandles, numVerts, &tagSpace[0]);
          if (MB_SUCCESS != rval) return rval;
        }
        else if (taggedEntDim == entDim) {
          rval = mbImpl->tag_get_data(tagHandle, &entHandle, 1, &tagSpace[0]);
          if (MB_SUCCESS != rval) return rval;
        }
      }

      return rval;
    }
ErrorCode moab::ElemEvaluator::set_tag_handle ( Tag  tag,
int  tagged_ent_dim = -1 
) [inline]

Definition at line 357 of file ElemEvaluator.hpp.

    {
      ErrorCode rval = MB_SUCCESS;
      if (!tag && !tagged_ent_dim) {
        tagCoords = true;
        numTuples = 3;
        taggedEntDim = 0;
        tagHandle = 0;
        return rval;
      }
      else if (tagHandle != tag) {
        tagHandle = tag;
        rval = mbImpl->tag_get_length(tagHandle, numTuples);
        if (MB_SUCCESS != rval) return rval;
        int sz;
        rval = mbImpl->tag_get_bytes(tag, sz);
        if (MB_SUCCESS != rval) return rval;
        tagSpace.reserve(CN::MAX_NODES_PER_ELEMENT*sz);
        tagCoords = false;
      }

      taggedEntDim = (-1 == tagged_ent_dim ? 0 : tagged_ent_dim);
      
      if (entHandle) {
        if (0 == taggedEntDim) {
          rval = mbImpl->tag_get_data(tagHandle, vertHandles, numVerts, &tagSpace[0]);
          if (MB_SUCCESS != rval) return rval;
        }
        else if (taggedEntDim == entDim) {
          rval = mbImpl->tag_get_data(tagHandle, &entHandle, 1, &tagSpace[0]);
          if (MB_SUCCESS != rval) return rval;
        }
      }

      return rval;
    }

Member Data Documentation

Entity dimension.

Definition at line 285 of file ElemEvaluator.hpp.

Entity handle being evaluated.

Definition at line 279 of file ElemEvaluator.hpp.

EntityType moab::ElemEvaluator::entType [private]

Entity type.

Definition at line 282 of file ElemEvaluator.hpp.

Evaluation methods for elements of various topologies.

Definition at line 312 of file ElemEvaluator.hpp.

Interface.

Definition at line 276 of file ElemEvaluator.hpp.

Number of values in this tag.

Definition at line 303 of file ElemEvaluator.hpp.

Number of vertices cached here.

Definition at line 288 of file ElemEvaluator.hpp.

Whether tag is coordinates or something else.

Definition at line 300 of file ElemEvaluator.hpp.

Dimension of entities from which to grab tag.

Definition at line 306 of file ElemEvaluator.hpp.

Tag being evaluated.

Definition at line 297 of file ElemEvaluator.hpp.

std::vector<unsigned char> moab::ElemEvaluator::tagSpace [private]

Tag space.

Definition at line 309 of file ElemEvaluator.hpp.

Cached copy of vertex handle ptr.

Definition at line 291 of file ElemEvaluator.hpp.

Cached copy of vertex positions.

Definition at line 294 of file ElemEvaluator.hpp.

double* moab::ElemEvaluator::workSpace [private]

Work space for element-specific data.

Definition at line 315 of file ElemEvaluator.hpp.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines