예제 #1
0
void SF2Reader::readList(SimpleArray<T, E>& a, const chunkHeader& h) {
    size_t n = h.chunkSize;
    if(n%sizeof(T)!=0)
        throw ReadError("list "+std::string(h.chunkId, 4)+" not a multiple of record size");
    Assert(n/sizeof(T)>=E);
    a.resize(n/sizeof(T)-E);
    readArray(a.begin(), a.size()+E);
}
예제 #2
0
// Performs a reverse topological traversal, starting from the exit block and
// following back-edges.  The dominator is serialized before any predecessors,
// which guarantees that all blocks are serialized after their dominator and
// before their post-dominator (because it's a reverse topological traversal).
// ID should be initially set to 0.
//
// This sort assumes that (1) dominators have been computed, (2) there are no
// critical edges, and (3) the entry block is reachable from the exit block
// and no blocks are accessible via traversal of back-edges from the exit that
// weren't accessible via forward edges from the entry.
unsigned BasicBlock::topologicalFinalSort(SimpleArray<BasicBlock *> &Blocks,
                                          unsigned ID) {
  // Visited is assumed to have been set by the topologicalSort.  This pass
  // assumes !Visited means that we've visited this node before.
  if (!Visited) return ID;
  Visited = false;
  if (DominatorNode.Parent)
    ID = DominatorNode.Parent->topologicalFinalSort(Blocks, ID);
  for (auto *Pred : Predecessors)
    ID = Pred->topologicalFinalSort(Blocks, ID);
  assert(static_cast<size_t>(ID) < Blocks.size());
  BlockID = ID++;
  Blocks[BlockID] = this;
  return ID;
}
예제 #3
0
/**\brief Add copied entities/sets recursively
 *
 * Helper function for process_ce_sets. This adds any entities directly
 * contained in the current set to the dest set and then loops through the
 * contained sets and adds the children if they are also CE sets. If not, it
 * adds the entities in the child set and recurses down a level.
 * \param imeshImpl the iMesh instance handle
 * \param src the source set
 * \param current the child set to examine (start with current == src)
 * \param local_tag the tag relating source and target sets
 */
static
void process_ce_subsets(iMesh_Instance imeshImpl, iBase_EntitySetHandle src,
                        iBase_EntitySetHandle current,
                        const std::set<iBase_EntitySetHandle> &cesets,
                        iBase_TagHandle local_tag) 
{
  int err;
  iBase_EntitySetHandle dest;

  // First, add entities directly contained in this set.
  std::vector<iBase_EntityHandle> tmp_tags;
  get_copied_ents(imeshImpl, current, local_tag, tmp_tags);

  if (!tmp_tags.empty()) {
    get_dest_set(imeshImpl, local_tag, src, &dest);
    iMesh_addEntArrToSet(imeshImpl, &tmp_tags[0], tmp_tags.size(), dest,
                         &err);
    check_error(imeshImpl, err);
  }

  // Next, start looking at children.
  SimpleArray<iBase_EntitySetHandle> children;
  iMesh_getEntSets(imeshImpl, current, 1, ARRAY_INOUT(children), &err);
  check_error(imeshImpl, err);

  for (int i = 0; i < children.size(); i++) {

    // If this child set is one of our cesets, add just the set...
    if (cesets.find(children[i]) != cesets.end()) {
      get_dest_set(imeshImpl, local_tag, src, &dest);
      if (src == dest) continue;

      iMesh_addEntSet(imeshImpl, children[i], dest, &err);
      check_error(imeshImpl, err);
    }

    // ... otherwise, add the entities and recurse into the next level of
    // children.
    else {
      process_ce_subsets(imeshImpl, src, children[i], cesets, local_tag);
    }
  }
}
예제 #4
0
void Discretize_Geometric_Model(GeomMesh &geomesh)
{
    char *options = NULL;
    int optlen = 0;
    int err;

    iMesh_Instance mesh = geomesh.mesh;
    iGeom_Instance geom = geomesh.geom;
    iRel_Instance assoc = geomesh.assoc;
    iRel_RelationHandle relation00 = geomesh.relation00;

    iBase_EntitySetHandle geomRootSet = geomesh.geomRootSet;

    ///////////////////////////////////////////////////////////////////////////////
    // Step I: Collect all the feature nodes in Geometry:
    ///////////////////////////////////////////////////////////////////////////////
    SimpleArray<iBase_EntityHandle> geoNodes;
    iGeom_getEntities(geom, geomRootSet, iBase_VERTEX, ARRAY_INOUT(geoNodes), &err);

    double x, y, z;
    iBase_EntityHandle newHandle;
    for (int i = 0; i < geoNodes.size(); i++)
    {
        iGeom_getVtxCoord(geom, geoNodes[i], &x, &y, &z, &err);
        iMesh_createVtx(mesh, x, y, z, &newHandle, &err);
        iRel_setEntEntAssociation(assoc, relation00, geoNodes[i], newHandle, &err);
    }

    ///////////////////////////////////////////////////////////////////////////////
    // Step II: Collect all the geometric edges and discretize them.
    ///////////////////////////////////////////////////////////////////////////////
    SimpleArray<iBase_EntityHandle> geoEdges;
    iGeom_getEntities(geom, geomRootSet, iBase_EDGE, ARRAY_INOUT(geoEdges), &err);

    int numGeoEdges = geoEdges.size();

    vector<double> elen(numGeoEdges);
    for (int i = 0; i < numGeoEdges; i++) {
        elen[i] = get_geom_edge_length(geom, geoEdges[i]);
    }
    vector<double> tmpelen;
    tmpelen = elen;
    sort( tmpelen.begin(), tmpelen.end() );
    double mean_edge_length = tmpelen[numGeoEdges/2];

    cout << " Minimum Edge Length : " << *min_element( elen.begin(), elen.end() ) << endl;
    cout << " Maximum Edge Length : " << *max_element( elen.begin(), elen.end() ) << endl;
    cout << " Mean Length         : " <<  mean_edge_length << endl;

    double spacing = mean_edge_length /(double) 10.0;

    int numEdges;
    EdgeMesher *edgeMesher = geomesh.edgeMesher;
    for (int i = 0; i < numGeoEdges; i++) {
        if( elen[i] < 0.5*mean_edge_length) 
            numEdges = 1;
        else
            numEdges = elen[i]/ spacing;

        edgeMesher->discretize(geomesh, geoEdges[i], numEdges);
    }
    //return;
   
    ///////////////////////////////////////////////////////////////////////////////
    //Step III: Collect all the geometric faces and discretize them.
    ///////////////////////////////////////////////////////////////////////////////
    SimpleArray<iBase_EntityHandle> geoFaces;
    iGeom_getEntities(geom, geomRootSet, iBase_FACE, ARRAY_INOUT(geoFaces), &err);

    int numGeomFaces = geoFaces.size();

    SurfaceMesher *surfMesher = geomesh.surfMesher;
    for (int i = 2; i < numGeomFaces; i++) {
        surfMesher->discretize(geomesh, geoFaces[i]);
        //exit(0);
    }

    //return ;

    ///////////////////////////////////////////////////////////////////////////////
    //Step IV: Collect all the geometric regions and discretize them.
    ///////////////////////////////////////////////////////////////////////////////
    SimpleArray<iBase_EntityHandle> geoCells;
    iGeom_getEntities(geom, geomRootSet, iBase_REGION, ARRAY_INOUT(geoCells), &err);

    VolumeMesher *volMesher = geomesh.volMesher;
    for (int i = 0; i < geoCells.size(); i++)
        volMesher->discretize(geomesh, geoCells[i]);

    ///////////////////////////////////////////////////////////////////////////////
    //Step V: Generate Spectral (Higher order) elements:
    ///////////////////////////////////////////////////////////////////////////////
    //generate_spectral_elements(geomesh, 10); // 10 noded tetrahedra.
}