MOAB: Mesh Oriented datABase  (version 5.2.1)
smoab::detail::ReadSparseTag Struct Reference

#include <ReadSparseTag.h>

+ Collaboration diagram for smoab::detail::ReadSparseTag:

Public Member Functions

 ReadSparseTag (const smoab::CellSets &mSets, const smoab::Range &cells, const smoab::Interface &interface)
void fill (vtkIntArray *array, const Tag *cellTag) const
void fill (vtkIdTypeArray *array, const Tag *cellTag) const

Private Member Functions

template<typename T >
void fillRawArray (T *sparseTagArray, std::size_t length, const Tag *cellTag) const
template<typename T >
void singleSetRead (T *sparseTagArray, const std::vector< int > &values, std::size_t length) const
template<typename T >
void multiSetRead (T *sparseTagArray, const std::vector< int > &values, std::size_t length, int defaultTagValue) const

Private Attributes

const smoab::InterfaceInterface
const smoab::CellSetsMeshSets
const smoab::RangeCells

Detailed Description

Definition at line 15 of file ReadSparseTag.h.


Constructor & Destructor Documentation

smoab::detail::ReadSparseTag::ReadSparseTag ( const smoab::CellSets mSets,
const smoab::Range cells,
const smoab::Interface interface 
) [inline]

Definition at line 18 of file ReadSparseTag.h.

                                                :
    Interface(interface),
    MeshSets(mSets),
    Cells(cells)
    {
    }

Member Function Documentation

void smoab::detail::ReadSparseTag::fill ( vtkIntArray *  array,
const Tag cellTag 
) const

Definition at line 54 of file ReadSparseTag.h.

References Cells, fillRawArray(), length(), and moab::Range::size().

Referenced by smoab::DataSetConverter::fill(), multiSetRead(), and singleSetRead().

{
  const std::size_t length = this->Cells.size();
  array->SetNumberOfValues(length);
  int *raw = static_cast<int*>(array->GetVoidPointer(0));
  this->fillRawArray(raw,length,cellTag);
}
void smoab::detail::ReadSparseTag::fill ( vtkIdTypeArray *  array,
const Tag cellTag 
) const

Definition at line 63 of file ReadSparseTag.h.

References Cells, fillRawArray(), length(), and moab::Range::size().

{
  const std::size_t length = this->Cells.size();
  array->SetNumberOfValues(length);
  vtkIdType *raw = static_cast<vtkIdType*>(array->GetVoidPointer(0));
  this->fillRawArray(raw,length,cellTag);
}
template<typename T >
void smoab::detail::ReadSparseTag::fillRawArray ( T sparseTagArray,
std::size_t  length,
const Tag cellTag 
) const [private]

Definition at line 73 of file ReadSparseTag.h.

References smoab::Interface::getDefaultTagVaue(), smoab::Interface::getMoabTag(), smoab::Interface::getTagData(), MeshSets, multiSetRead(), and singleSetRead().

Referenced by fill().

{

  typedef std::vector<int>::const_iterator IdConstIterator;
  typedef std::vector<int>::iterator IdIterator;
  typedef smoab::CellSets::const_iterator CellSetIterator;

  std::vector<int> sparseTagValues(this->MeshSets.size());
  //first off iterate the entities and determine which ones
  //have moab material ids

  //todo get proper default value from moab
  //wrap this area with scope, to remove local variables

  {
    const moab::Tag stag = this->Interface.getMoabTag(*sparseTag);
    IdIterator tagIds = sparseTagValues.begin();
    for(CellSetIterator i=this->MeshSets.begin();
        i != this->MeshSets.end();
        ++i, ++tagIds)
      {
      //getTagData clobbers defaultValue
      int defaultValue = this->Interface.getDefaultTagVaue<int>(stag);
      *tagIds = this->Interface.getTagData(stag,i->entity(),defaultValue);
      }

    //now determine ids for all entities that don't have materials
    IdConstIterator maxPos = std::max_element(sparseTagValues.begin(),
                                              sparseTagValues.end());
    int maxValue = *maxPos;
    for(IdIterator i=sparseTagValues.begin(); i!= sparseTagValues.end(); ++i)
      {
      if(*i==-1)
        {
        *i = ++maxValue;
        }
      }
  }
  if(this->MeshSets.size() == 1)
    {
    this->singleSetRead(sparseTagArray,sparseTagValues,length);
    }
  else
    {
    int defaultValue = this->Interface.getDefaultTagVaue<int>(*sparseTag);
    this->multiSetRead(sparseTagArray,sparseTagValues,length,defaultValue);
    }
}
template<typename T >
void smoab::detail::ReadSparseTag::multiSetRead ( T sparseTagArray,
const std::vector< int > &  values,
std::size_t  length,
int  defaultTagValue 
) const [private]

Definition at line 139 of file ReadSparseTag.h.

References moab::Range::begin(), Cells, moab::Range::end(), fill(), MeshSets, smoab::RangeToVector(), T, and value().

Referenced by fillRawArray().

  {
  typedef std::vector<smoab::EntityHandle>::const_iterator EntityHandleIterator;
  typedef std::vector<int>::const_iterator IdConstIterator;
  typedef smoab::CellSets::const_iterator CellSetIterator;
  typedef smoab::Range::const_iterator RangeIterator;

  //create the search structure as a range is really slow to search with
  //lower_bounds
  std::vector<smoab::EntityHandle> searchableCells;
  smoab::RangeToVector(this->Cells,searchableCells);


  //pre fill with -1 to mark cells we don't touch, since some cells
  //might no have a default tag
  T defaultValue = T(defaultTagValue);
  std::fill(sparseTagArray,sparseTagArray+numCells,defaultValue);

  EntityHandleIterator s_begin = searchableCells.begin();
  EntityHandleIterator s_end = searchableCells.end();

  IdConstIterator currentTagValue = sparseTagValues.begin();
  for(CellSetIterator i=this->MeshSets.begin();
      i!=this->MeshSets.end(); ++i, ++currentTagValue)
    {
    T value = static_cast<T>(*currentTagValue);

    const smoab::Range& entitiesCells = i->cells();
    for(RangeIterator j=entitiesCells.begin(); j != entitiesCells.end();++j)
      {
      EntityHandleIterator result = std::lower_bound(s_begin,
                                                     s_end,
                                                     *j);
      std::size_t newId = std::distance(s_begin,result);
      sparseTagArray[newId] = value;
      }
    }

}
template<typename T >
void smoab::detail::ReadSparseTag::singleSetRead ( T sparseTagArray,
const std::vector< int > &  values,
std::size_t  length 
) const [private]

Definition at line 126 of file ReadSparseTag.h.

References fill(), T, and value().

Referenced by fillRawArray().

  {

  //now we set all the values as this has a single meshset so we
  //have no complicated logic for mapping each cell to a meshset
  T value = static_cast<T>(values[0]);
  std::fill(sparseTagArray,sparseTagArray+length,value);
  }

Member Data Documentation

Definition at line 50 of file ReadSparseTag.h.

Referenced by fill(), and multiSetRead().

Definition at line 48 of file ReadSparseTag.h.

Definition at line 49 of file ReadSparseTag.h.

Referenced by fillRawArray(), and multiSetRead().

List of all members.


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