Example #1
0
SparseElementList *crm114__list_map(void **addr, void *last_addr, int *n_elts_ptr) {
  SparseElementList *l;
  SparseNode n, pn;
  int n_elts = *n_elts_ptr, i;

  if (!addr || !*addr || !last_addr || n_elts < 0 || *addr >= last_addr) {
    if (CRM114__MATR_DEBUG_MODE) {
      fprintf(stderr, "crm114__list_map: null arguments.\n");
    }
    *n_elts_ptr = 0;
    return NULL;
  }

  if ((void *)((SparseElementList *)*addr + 1) > last_addr) {
    if (CRM114__MATR_DEBUG_MODE) {
      fprintf(stderr, "crm114__list_map: not enough memory for list.\n");
    }
    *n_elts_ptr = 0;
    return NULL;
  }

  l = (SparseElementList *)(*addr);
  *addr = l + 1;
  l->head = node_map(l->compact, addr, last_addr);
  pn = l->head;
  for (i = 1; i < n_elts; i++) {
    if (null_node(pn)) {
      break;
    }
    n = node_map(l->compact, addr, last_addr);
    if (null_node(n)) {
      break;
    }
    if (l->compact) {
      pn.compact->next = n.compact;
      n.compact->prev = pn.compact;
    } else {
      pn.precise->next = n.precise;
      n.precise->prev = pn.precise;
    }
    pn = n;
  }
  if (i != n_elts) {
    if (!null_node(pn)) {
      if (l->compact) {
	pn.compact->next = NULL;
      } else {
	pn.precise->next = NULL;
      }
    }
    *n_elts_ptr = i;
    if (CRM114__MATR_DEBUG_MODE) {
      fprintf(stderr, "crm114__list_map: Couldn't read in enough elements.\n");
    }
  }
  l->last_addr = *addr;
  l->tail = pn;
  return l;
}
    void TestDeleteFirstOrder() throw(Exception)
    {
#ifdef CHASTE_VTK
        VtkMeshReader<1,3> mesh_reader("lung/test/data/TestSubject002MajorAirways.vtu");

        MutableMesh<1,3> mesh;
        mesh.ConstructFromMeshReader(mesh_reader);

        //Assign valid radii
        for(unsigned node_index = 0; node_index < mesh.GetNumNodes(); ++node_index)
        {
            mesh.GetNode(node_index)->AddNodeAttribute(1.0);
        }

        TS_ASSERT_EQUALS(mesh.GetNumNodes(), 12065u);
        TS_ASSERT_EQUALS(mesh.GetNumElements(), 12064u);

        MajorAirwaysCentreLinesCleaner cleaner(mesh, 0u);
        cleaner.CleanUsingHorsfieldOrder(1u);

        NodeMap node_map(mesh.GetNumAllNodes());
        mesh.ReIndex(node_map);

        //Confirmed visually to be correct
        TS_ASSERT_EQUALS(mesh.GetNumNodes(), 3683u);
        TS_ASSERT_EQUALS(mesh.GetNumElements(), 3682u);

// Uncomment to visualise
//        VtkMeshWriter<1,3> mesh_writer("TestMajorAirwaysCentreLinesCleaner", "Novartis002Trimmed");
//        mesh_writer.WriteFilesUsingMesh(mesh);
#endif //CHASTE_VTK
    }
Example #3
0
static int
ps_option_iterator(pOption o, aux_t l) {
    FILE *f = (FILE *) l;
    fprintf(f, "[\n");
    node_map(o->atoms, (NodeIterator) & ps_node_iterator, l);
    fprintf(f, "] {exec outputstring} forall\n");
}
    void TestDeleteOrderSimpleMesh() throw(Exception)
    {
        TrianglesMeshReader<1,3> mesh_reader("lung/test/airway_generation/data/test_major_airways_mesh");
        MutableMesh<1,3> mesh;
        mesh.ConstructFromMeshReader(mesh_reader);

        //Assign valid radii
        for(unsigned node_index = 0; node_index < mesh.GetNumNodes(); ++node_index)
        {
            mesh.GetNode(node_index)->rGetNodeAttributes()[0] = 1.0;
        }

        TS_ASSERT_EQUALS(mesh.GetNumNodes(), 6u);
        TS_ASSERT_EQUALS(mesh.GetNumElements(), 5u);

        MajorAirwaysCentreLinesCleaner cleaner(mesh, 0u);
        cleaner.CleanUsingHorsfieldOrder(1u);

        NodeMap node_map(mesh.GetNumAllNodes());
        mesh.ReIndex(node_map);

        TS_ASSERT_EQUALS(mesh.GetNumNodes(), 2u);
        TS_ASSERT_EQUALS(mesh.GetNumElements(), 1u);
        TS_ASSERT_DELTA(mesh.GetNode(0u)->rGetLocation()[0], 0.0, 1e-6);
        TS_ASSERT_DELTA(mesh.GetNode(0u)->rGetLocation()[1], 0.0, 1e-6);
        TS_ASSERT_DELTA(mesh.GetNode(0u)->rGetLocation()[2], -2.0, 1e-6);
        TS_ASSERT_DELTA(mesh.GetNode(1u)->rGetLocation()[0], 0.0, 1e-6);
        TS_ASSERT_DELTA(mesh.GetNode(1u)->rGetLocation()[1], 0.0, 1e-6);
        TS_ASSERT_DELTA(mesh.GetNode(1u)->rGetLocation()[2], 0.0, 1e-6);
    }
Example #5
0
//--------------------------------------------------------------------------
void
HexNElementDescription::set_isoparametric_coordinates()
{
  for (int k = 0; k < nodes1D; ++k) {
    for (int j = 0; j < nodes1D; ++j) {
      for (int i = 0; i < nodes1D; ++i) {
        std::vector<double> nodeLoc = { nodeLocs1D.at(i), nodeLocs1D.at(j), nodeLocs1D.at(k) };
        nodeLocs.insert({node_map(i,j,k), nodeLoc});
      }
    }
  }
}
Example #6
0
MutableMesh<ELEMENT_DIM, SPACE_DIM>::MutableMesh(std::vector<Node<SPACE_DIM> *> nodes)
{
    this->mMeshChangesDuringSimulation = true;
    Clear();
    for (unsigned index=0; index<nodes.size(); index++)
    {
        Node<SPACE_DIM>* p_temp_node = nodes[index];
        this->mNodes.push_back(p_temp_node);
    }
    mAddedNodes = true;
    NodeMap node_map(nodes.size());
    ReMesh(node_map);
}
Example #7
0
//--------------------------------------------------------------------------
void HexNElementDescription::set_tensor_product_node_mappings()
{
  set_base_node_maps();

  if (polyOrder > 1) {
    for (int edgeOrdinal = 0; edgeOrdinal < numEdges; ++edgeOrdinal) {
      auto newNodeOrdinals = edgeNodeConnectivities.at(edgeOrdinal);

      for (int k = 0; k < newNodesPerEdge; ++k) {
        for (int j = 0; j < newNodesPerEdge; ++j) {
          for (int i = 0; i < newNodesPerEdge; ++i) {
            auto offsets = get_edge_offsets(i,j,k,edgeOrdinal);
            nodeMap.at(offsets.first) = newNodeOrdinals.at(offsets.second);
          }
        }
      }
    }

    for (int faceOrdinal = 0; faceOrdinal < numFaces; ++faceOrdinal) {
      auto newNodeOrdinals = faceNodeConnectivities.at(faceOrdinal);
      for (int k = 0; k < newNodesPerEdge; ++k) {
        for (int j = 0; j < newNodesPerEdge; ++j) {
          for (int i = 0; i < newNodesPerEdge; ++i) {
            auto offsets = get_face_offsets(i,j,k,faceOrdinal);
            nodeMap.at(offsets.first) = newNodeOrdinals.at(offsets.second);
          }
        }
      }
    }

    auto newVolumeNodes = volumeNodeConnectivities.at(0);
    for (int k = 0; k < newNodesPerEdge; ++k) {
      for (int j = 0; j < newNodesPerEdge; ++j) {
        for (int i = 0; i < newNodesPerEdge; ++i) {
          nmap(i + 1, j + 1, k + 1) = newVolumeNodes.at(i + newNodesPerEdge * (j + newNodesPerEdge * k));
        }
      }
    }
  }

  //inverse map
  inverseNodeMap.resize(nodes1D*nodes1D*nodes1D);
  for (int i = 0; i < nodes1D; ++i) {
    for (int j = 0; j < nodes1D; ++j) {
      for (int k = 0; k < nodes1D; ++k) {
        inverseNodeMap[node_map(i,j,k)] = {i, j, k};
      }
    }
  }
}
Example #8
0
Cylindrical2dMesh::Cylindrical2dMesh(double width, std::vector<Node<2>* > nodes)
  : MutableMesh<2,2>(),
    mWidth(width)
{
    assert(width > 0.0);
//    mMismatchedBoundaryElements = false;
    for (unsigned index=0; index<nodes.size(); index++)
    {
        Node<2>* p_temp_node = nodes[index];
        double x = p_temp_node->rGetLocation()[0];
        UNUSED_OPT(x); // Fix optimised build
        assert( 0 <= x && x < width);
        mNodes.push_back(p_temp_node);
    }

    NodeMap node_map(nodes.size());
    ReMesh(node_map);
}
Example #9
0
Graph::Graph(vector<char>& char_map, int map_width, int map_depth):map_width(map_width),map_depth(map_depth)
{
	vector<Node*> node_map(char_map.size());
	for (int i = 0; i < map_depth; ++i)
	{
		for (int j = 0; j < map_width; ++j)
		{
			node_map[(i * map_width) + j] = new Node(j, i);
		}
	}

	//For each node create a list of Connections
	for (int i = 0; i < map_depth; ++i)
	{
		for (int j = 0; j < map_width; ++j)
		{
			int key = (i * map_width) + j;
			Node* curr_node = node_map[key];
			connections[key] = vector<Node*>();
			int temp_index = ((i - 1) * map_width) + j;

			// 1 is walkable
			if (i - 1 >= 0 && char_map[temp_index] == '\x1')
			{
				connections[key].push_back(node_map[temp_index]);
			}
			temp_index = ((i + 1) * map_width) + j;
			if (i + 1 < map_depth && char_map[temp_index] == '\x1')
			{
				connections[key].push_back(node_map[temp_index]);
			}
			temp_index = key - 1;
			if (j - 1 >= 0 && char_map[temp_index] == '\x1')
			{
				connections[key].push_back(node_map[temp_index]);
			}
			temp_index = key + 1;
			if (j + 1 < map_width && char_map[temp_index] == '\x1')
			{
				connections[key].push_back(node_map[temp_index]);
			}
		}
	}
}
Example #10
0
//--------------------------------------------------------------------------
void
HexNElementDescription::set_subelement_connectivites()
{
  subElementConnectivity.resize((nodes1D-1)*(nodes1D-1)*(nodes1D-1));
  for (int k = 0; k < nodes1D-1; ++k) {
    for (int j = 0; j < nodes1D-1; ++j) {
      for (int i = 0; i < nodes1D-1; ++i) {
        subElementConnectivity[i+(nodes1D-1)*(j+(nodes1D-1)*k)] =
        {
            node_map(i+0,j+0,k+0),
            node_map(i+1,j+0,k+0),
            node_map(i+1,j+0,k+1),
            node_map(i+0,j+0,k+1),
            node_map(i+0,j+1,k+0),
            node_map(i+1,j+1,k+0),
            node_map(i+1,j+1,k+1),
            node_map(i+0,j+1,k+1)
        };
      }
    }
  }
}
Example #11
0
//--------------------------------------------------------------------------
void HexNElementDescription::set_boundary_node_mappings()
{
  // node mapping needs to be consistent with quad element's
  nodeMapBC = QuadNElementDescription(nodeLocs1D).nodeMap;

  inverseNodeMap.resize(nodes1D*nodes1D*nodes1D);
  for (int i = 0; i < nodes1D; ++i) {
    for (int j = 0; j < nodes1D; ++j) {
      for (int k = 0; k < nodes1D; ++k) {
        inverseNodeMap[node_map(i,j,k)] = {i, j, k};
      }
    }
  }

  inverseNodeMapBC.resize(nodes1D*nodes1D);
  for (int i = 0; i < nodes1D; ++i) {
    for (int j = 0; j < nodes1D; ++j) {
      inverseNodeMapBC[node_map_bc(i,j)] = { i,j };
    }
  }
}
Example #12
0
/// @brief dumps node contents, optionally recursively
/// @param[in] node_addr  block number of node
/// @param[in] recurse    enable depth-first recursion through branch nodes
void node_dump(uint32_t node_addr, bool recurse) {
	node_ptr node = node_map(node_addr, false);
	
	warnx("%s: this 0x%" PRIx32 " parent 0x%" PRIx32 " prev 0x%" PRIx32
		" next 0x%" PRIx32 " cnt %" PRIu16 " free %" PRIu32,
		__func__, node->hdr.this, node->hdr.parent, node->hdr.prev,
		node->hdr.next, node->hdr.cnt, node_free(node));
	
	if (node->hdr.leaf) {
		node_dump_leaf(node);
	} else {
		node_dump_branch(node);
		
		if (recurse) {
			const node_ref *elem_end = node->b_elems + node->hdr.cnt;
			for (const node_ref *elem = node->b_elems;
				elem < elem_end; ++elem) {
				node_dump(elem->addr, true);
			}
		}
	}
	
	node_unmap(node);
}
Example #13
0
void
node_free( nh_t *nhp )
{
    nh_t nh;
    nix_t nix;
    u_char_t *p;
    register nix_t *linkagep;
#ifdef NODECHK
    register u_char_t *hkpp;
    register u_char_t hdlgen;
    register u_char_t nodegen;
    register u_char_t nodeunq;
#endif /* NODECHK */

    ASSERT( nhp );
    nh = *nhp;
    ASSERT( nh != NH_NULL );

    /* convert the handle into an index
     */
#ifdef NODECHK
    hdlgen = HDLGETGEN( nh );
    nix = HDLGETNIX( nh );
#else /* NODECHK */
    nix = ( nix_t )nh;
#endif /* NODECHK */

    ASSERT( nix <= NIX_MAX );

    /* map in
     */
    p = ( u_char_t * )node_map( nh );
    if (p == NULL) {
        *nhp = NH_NULL;
        return;
    }

#ifdef NODECHK
    /* fix up unique field
     */
    hkpp = p + node_hdrp->nh_nodehkix;
    nodegen = HKPGETGEN( *hkpp );
    nodeunq = HKPGETUNQ( *hkpp );
    ASSERT( nodegen == hdlgen );
    ASSERT( nodeunq != NODEUNQFREE );
    ASSERT( nodeunq == NODEUNQALCD );
    *hkpp = HKPMKHKP( nodegen, NODEUNQFREE );
#endif /* NODECHK */

    /* put node on free list
     */
    linkagep = ( nix_t * )p;
    *linkagep = node_hdrp->nh_freenix;
    node_hdrp->nh_freenix = nix;

    /* map out
     */
    node_unmap_internal( nh, ( void ** )&p, BOOL_TRUE );

    /* invalidate caller's handle
     */
    *nhp = NH_NULL;
}
Example #14
0
//--------------------------------------------------------------------------
void
HexNElementDescription::set_side_node_ordinals()
{
  // index of the "left"-most node along an edge
  int il = 0;
  int jl = 0;
  int kl = 0;

  // index of the "right"-most node along an edge
  int ir = nodes1D - 1;
  int jr = nodes1D - 1;
  int kr = nodes1D - 1;

  // face node ordinals, reordered according to
  // the face permutation
  std::vector<std::vector<int>> reorderedFaceNodeMap;

  faceNodeMap.resize(numBoundaries);
  reorderedFaceNodeMap.resize(numBoundaries);
  for (int j = 0; j < numBoundaries; ++j) {
    faceNodeMap.at(j).resize(nodesPerSide);
    reorderedFaceNodeMap.at(j).resize(nodesPerSide);
  }

  //front
  for (int n = 0; n < nodes1D; ++n) {
    for (int m = 0; m < nodes1D; ++m) {
      faceNodeMap.at(0).at(m+nodes1D*n) = node_map(m,jl,n);
      reorderedFaceNodeMap.at(0).at(m+nodes1D*n) = node_map(m,jl,n);
    }
  }

  // right
  for (int n = 0; n < nodes1D; ++n) {
    for (int m = 0; m < nodes1D; ++m) {
      faceNodeMap.at(1).at(m+nodes1D*n) = node_map(ir,m,n);
      reorderedFaceNodeMap.at(1).at(m+nodes1D*n) = node_map(ir,m,n);
    }
  }

  //back
  for (int n = 0; n < nodes1D; ++n) {
    for (int m = 0; m < nodes1D; ++m) {
      faceNodeMap.at(2).at(m+nodes1D*n) = node_map(m,jr,n);
      reorderedFaceNodeMap.at(2).at(m+nodes1D*n) = node_map(nodes1D-m-1,jr,n);
    }
  }

  //left
  for (int n = 0; n < nodes1D; ++n) {
    for (int m = 0; m < nodes1D; ++m) {
      faceNodeMap.at(3).at(m+nodes1D*n) = node_map(il,m,n);
      reorderedFaceNodeMap.at(3).at(m+nodes1D*n) = node_map(il,n,m);
    }
  }

  //bottom
  for (int n = 0; n < nodes1D; ++n) {
    for (int m = 0; m < nodes1D; ++m) {
      faceNodeMap.at(4).at(m+nodes1D*n) = node_map(m,n,kl);
      reorderedFaceNodeMap.at(4).at(m+nodes1D*n) = node_map(n,m,kl);
    }
  }

  //top
  for (int n = 0; n < nodes1D; ++n) {
    for (int m = 0; m < nodes1D; ++m) {
      faceNodeMap.at(5).at(m+nodes1D*n) = node_map(m,n,kr);
      reorderedFaceNodeMap.at(5).at(m+nodes1D*n) = node_map(m,n,kr);
    }
  }

  sideOrdinalMap.resize(6);
  for (int face_ordinal = 0; face_ordinal < 6; ++face_ordinal) {
    sideOrdinalMap[face_ordinal].resize(nodesPerSide);
    for (int j = 0; j < nodes1D*nodes1D; ++j) {
      const auto& ords = inverseNodeMapBC[j];
      sideOrdinalMap.at(face_ordinal).at(j) = reorderedFaceNodeMap.at(face_ordinal).at(ords[0]+nodes1D*ords[1]);
    }
  }
}
Example #15
0
static int undef_iter1(pOption o, struct rule_closure *closure)
{
  node_map(o->atoms, (NodeIterator)&undef_iter2, closure);
};
void MeshBasedCellPopulation<ELEMENT_DIM,SPACE_DIM>::Update(bool hasHadBirthsOrDeaths)
{
    ///\todo check if there is a more efficient way of keeping track of node velocity information (#2404)
    bool output_node_velocities = (this-> template HasWriter<NodeVelocityWriter>());

    /**
     * If node radii are set, then we must keep a record of these, since they will be cleared during
     * the remeshing process. We then restore these attributes to the nodes after calling ReMesh().
     *
     * At present, we check whether node radii are set by interrogating the radius of the first node
     * in the mesh and asking if it is strictly greater than zero (the default value, as set in the
     * NodeAttributes constructor). Hence, we assume that either ALL node radii are set, or NONE are.
     *
     * \todo There may be a better way of checking if node radii are set (#2694)
     */
    std::map<unsigned, double> old_node_radius_map;
    old_node_radius_map.clear();
    if (this->mrMesh.GetNodeIteratorBegin()->HasNodeAttributes())
    {
        if (this->mrMesh.GetNodeIteratorBegin()->GetRadius() > 0.0)
        {
            for (typename AbstractMesh<ELEMENT_DIM, SPACE_DIM>::NodeIterator node_iter = this->mrMesh.GetNodeIteratorBegin();
                 node_iter != this->mrMesh.GetNodeIteratorEnd();
                 ++node_iter)
            {
                unsigned node_index = node_iter->GetIndex();
                old_node_radius_map[node_index] = node_iter->GetRadius();
            }
        }
    }

    std::map<unsigned, c_vector<double, SPACE_DIM> > old_node_applied_force_map;
    old_node_applied_force_map.clear();
    if (output_node_velocities)
    {
        /*
         * If outputting node velocities, we must keep a record of the applied force at each
         * node, since this will be cleared during the remeshing process. We then restore
         * these attributes to the nodes after calling ReMesh().
         */
        for (typename AbstractMesh<ELEMENT_DIM, SPACE_DIM>::NodeIterator node_iter = this->mrMesh.GetNodeIteratorBegin();
             node_iter != this->mrMesh.GetNodeIteratorEnd();
             ++node_iter)
        {
            unsigned node_index = node_iter->GetIndex();
            old_node_applied_force_map[node_index] = node_iter->rGetAppliedForce();
        }
    }

    NodeMap node_map(this->mrMesh.GetNumAllNodes());

    // We must use a static_cast to call ReMesh() as this method is not defined in parent mesh classes
    static_cast<MutableMesh<ELEMENT_DIM,SPACE_DIM>&>((this->mrMesh)).ReMesh(node_map);

    if (!node_map.IsIdentityMap())
    {
        UpdateGhostNodesAfterReMesh(node_map);

        // Update the mappings between cells and location indices
        std::map<Cell*, unsigned> old_cell_location_map = this->mCellLocationMap;

        // Remove any dead pointers from the maps (needed to avoid archiving errors)
        this->mLocationCellMap.clear();
        this->mCellLocationMap.clear();

        for (std::list<CellPtr>::iterator it = this->mCells.begin(); it != this->mCells.end(); ++it)
        {
            unsigned old_node_index = old_cell_location_map[(*it).get()];

            // This shouldn't ever happen, as the cell vector only contains living cells
            assert(!node_map.IsDeleted(old_node_index));

            unsigned new_node_index = node_map.GetNewIndex(old_node_index);
            this->SetCellUsingLocationIndex(new_node_index,*it);

            if (old_node_radius_map[old_node_index] > 0.0)
            {
                this->GetNode(new_node_index)->SetRadius(old_node_radius_map[old_node_index]);
            }
            if (output_node_velocities)
            {
                this->GetNode(new_node_index)->AddAppliedForceContribution(old_node_applied_force_map[old_node_index]);
            }
        }

        this->Validate();
    }
    else
    {
        if (old_node_radius_map[this->mCellLocationMap[(*(this->mCells.begin())).get()]] > 0.0)
        {
            for (std::list<CellPtr>::iterator it = this->mCells.begin(); it != this->mCells.end(); ++it)
            {
                unsigned node_index = this->mCellLocationMap[(*it).get()];
                this->GetNode(node_index)->SetRadius(old_node_radius_map[node_index]);
            }
        }
        if (output_node_velocities)
        {
            for (std::list<CellPtr>::iterator it = this->mCells.begin(); it != this->mCells.end(); ++it)
            {
                unsigned node_index = this->mCellLocationMap[(*it).get()];
                this->GetNode(node_index)->AddAppliedForceContribution(old_node_applied_force_map[node_index]);
            }
        }
    }

    // Purge any marked springs that are no longer springs
    std::vector<const std::pair<CellPtr,CellPtr>*> springs_to_remove;
    for (std::set<std::pair<CellPtr,CellPtr> >::iterator spring_it = this->mMarkedSprings.begin();
         spring_it != this->mMarkedSprings.end();
         ++spring_it)
    {
        CellPtr p_cell_1 = spring_it->first;
        CellPtr p_cell_2 = spring_it->second;
        Node<SPACE_DIM>* p_node_1 = this->GetNodeCorrespondingToCell(p_cell_1);
        Node<SPACE_DIM>* p_node_2 = this->GetNodeCorrespondingToCell(p_cell_2);

        bool joined = false;

        // For each element containing node1, if it also contains node2 then the cells are joined
        std::set<unsigned> node2_elements = p_node_2->rGetContainingElementIndices();
        for (typename Node<SPACE_DIM>::ContainingElementIterator elem_iter = p_node_1->ContainingElementsBegin();
             elem_iter != p_node_1->ContainingElementsEnd();
             ++elem_iter)
        {
            if (node2_elements.find(*elem_iter) != node2_elements.end())
            {
                joined = true;
                break;
            }
        }

        // If no longer joined, remove this spring from the set
        if (!joined)
        {
            springs_to_remove.push_back(&(*spring_it));
        }
    }

    // Remove any springs necessary
    for (std::vector<const std::pair<CellPtr,CellPtr>* >::iterator spring_it = springs_to_remove.begin();
         spring_it != springs_to_remove.end();
         ++spring_it)
    {
        this->mMarkedSprings.erase(**spring_it);
    }

    // Tessellate if needed
    TessellateIfNeeded();

    static_cast<MutableMesh<ELEMENT_DIM,SPACE_DIM>&>((this->mrMesh)).SetMeshHasChangedSinceLoading();
}
Example #17
0
void FillPlane::createEdgesOnPlane(vtkUnstructuredGrid *edge_grid)
{
  vtkIdType num_edges = 0;
  vtkIdType num_nodes = 0;

  QVector<bool> is_edge_node(m_Grid->GetNumberOfPoints(), false);
  for (vtkIdType id_face = 0; id_face < m_Grid->GetNumberOfCells(); ++id_face) {
    vtkIdType num_pts, *pts;
    if (isSurface(id_face, m_Grid)) {
      m_Grid->GetCellPoints(id_face, num_pts, pts);
      for (int i = 0; i < num_pts; ++i) {
        if (m_Part.c2cGG(id_face, i) == -1) {
          vtkIdType id_node1 = pts[i];
          vtkIdType id_node2 = pts[0];
          if (i < num_pts - 1) {
            id_node2 = pts[i + 1];
          }
          vec3_t x1, x2;
          m_Grid->GetPoint(id_node1, x1.data());
          m_Grid->GetPoint(id_node2, x2.data());
          if (isWithinTolerance(x1) && isWithinTolerance(x2)) {
            is_edge_node[id_node1] = true;
            is_edge_node[id_node2] = true;
            ++num_edges;
          }
        }
      }
    }
  }


  QVector<vtkIdType> node_map(m_Grid->GetNumberOfPoints(), -1);
  for (vtkIdType id_node1 = 0; id_node1 < m_Grid->GetNumberOfPoints(); ++id_node1) {
    if (is_edge_node[id_node1]) {
      node_map[id_node1] = num_nodes;
      ++num_nodes;
    }
  }
  m_NodeMap.resize(num_nodes);
  allocateGrid(edge_grid, 2*num_edges, num_nodes, false);
  for (vtkIdType id_node1 = 0; id_node1 < m_Grid->GetNumberOfPoints(); ++id_node1) {
    if (node_map[id_node1] != -1) {
      m_NodeMap[node_map[id_node1]] = id_node1;
      vec3_t x;
      m_Grid->GetPoint(id_node1, x.data());
      edge_grid->GetPoints()->SetPoint(node_map[id_node1], x.data());
    }
  }


  for (vtkIdType id_face = 0; id_face < m_Grid->GetNumberOfCells(); ++id_face) {
    vtkIdType num_pts, *pts;
    if (isSurface(id_face, m_Grid)) {
      m_Grid->GetCellPoints(id_face, num_pts, pts);
      for (int i = 0; i < num_pts; ++i) {
        if (m_Part.c2cGG(id_face, i) == -1) {
          vtkIdType id_node1 = pts[i];
          vtkIdType id_node2 = pts[0];
          if (i < num_pts - 1) {
            id_node2 = pts[i + 1];
          }
          if (is_edge_node[id_node1] && is_edge_node[id_node2]) {
            vtkIdType pts[2];
            pts[0] = node_map[id_node1];
            pts[1] = node_map[id_node2];
            edge_grid->InsertNextCell(VTK_LINE, 2, pts);
          }
        }
      }
    }
  }
}
Example #18
0
void use_case_5_generate_mesh(
  const std::string& mesh_options ,
  stk::mesh::BulkData & mesh ,
  const VectorFieldType & node_coord ,
  stk::mesh::Part & hex_block ,
  stk::mesh::Part & quad_shell_block )
{
  mesh.modification_begin();

  const unsigned parallel_size = mesh.parallel_size();
  const unsigned parallel_rank = mesh.parallel_rank();

  double t = 0 ;
  size_t num_hex = 0 ;
  size_t num_shell = 0 ;
  size_t num_nodes = 0 ;
  size_t num_block = 0 ;
  int error_flag = 0 ;

  try {

    Iogn::GeneratedMesh gmesh( mesh_options, parallel_size, parallel_rank );

    num_nodes = gmesh.node_count_proc();
    num_block = gmesh.block_count();

    t = stk::wall_time();

    std::vector<int> node_map( num_nodes , 0 );

    gmesh.node_map( node_map );

    {

      for ( size_t i = 1 ; i <= num_block ; ++i ) {
        const size_t                        num_elem = gmesh.element_count_proc(i);
        const std::pair<std::string,int> top_info = gmesh.topology_type(i);

	std::vector<int> elem_map( num_elem , 0 );
        std::vector<int> elem_conn( num_elem * top_info.second );

	gmesh.element_map( i, elem_map );
        gmesh.connectivity( i , elem_conn );

        if ( top_info.second == 8 ) {

          for ( size_t j = 0 ; j < num_elem ; ++j ) {

            const int * const local_node_id = & elem_conn[ j * 8 ] ;

            const stk::mesh::EntityId node_id[8] = {
              local_node_id[0] ,
              local_node_id[1] ,
              local_node_id[2] ,
              local_node_id[3] ,
              local_node_id[4] ,
              local_node_id[5] ,
              local_node_id[6] ,
              local_node_id[7]
            };

            const stk::mesh::EntityId elem_id = elem_map[ j ];

            stk::mesh::fem::declare_element( mesh , hex_block , elem_id , node_id );

            ++num_hex ;
          }
        }
        else if ( top_info.second == 4 ) {

          for ( size_t j = 0 ; j < num_elem ; ++j ) {

            const int * const local_node_id = & elem_conn[ j * 4 ] ;

            const stk::mesh::EntityId node_id[4] = {
              local_node_id[0] ,
              local_node_id[1] ,
              local_node_id[2] ,
              local_node_id[3]
            };

            const stk::mesh::EntityId elem_id = elem_map[ j ];

            stk::mesh::fem::declare_element( mesh , quad_shell_block , elem_id , node_id );

            ++num_shell ;
          }
        }
      }
    }

    std::vector<double> node_coordinates( 3 * node_map.size() );

    gmesh.coordinates( node_coordinates );

    if ( 3 * node_map.size() != node_coordinates.size() ) {
      std::ostringstream msg ;
      msg << "  P" << mesh.parallel_rank()
          << ": ERROR, node_map.size() = "
          << node_map.size()
          << " , node_coordinates.size() / 3 = "
          << ( node_coordinates.size() / 3 );
      throw std::runtime_error( msg.str() );
    }

    for ( unsigned i = 0 ; i < node_map.size() ; ++i ) {
      const unsigned i3 = i * 3 ;

      stk::mesh::Entity * const node = mesh.get_entity( stk::mesh::fem::FEMMetaData::NODE_RANK , node_map[i] );

      if ( NULL == node ) {
        std::ostringstream msg ;
        msg << "  P:" << mesh.parallel_rank()
            << " ERROR, Node not found: "
            << node_map[i] << " = node_map[" << i << "]" ;
        throw std::runtime_error( msg.str() );
      }

      double * const data = field_data( node_coord , *node );
      data[0] = node_coordinates[ i3 + 0 ];
      data[1] = node_coordinates[ i3 + 1 ];
      data[2] = node_coordinates[ i3 + 2 ];
    }
  }
  catch ( const std::exception & X ) {
    std::cout << "  P:" << mesh.parallel_rank() << ": " << X.what()
              << std::endl ;
    std::cout.flush();
    error_flag = 1 ;
  }
  catch( ... ) {
    std::cout << "  P:" << mesh.parallel_rank()
              << " Caught unknown exception"
              << std::endl ;
    std::cout.flush();
    error_flag = 1 ;
  }

  stk::all_reduce( mesh.parallel() , stk::ReduceMax<1>( & error_flag ) );

  if ( error_flag ) {
    std::string msg( "Failed mesh generation" );
    throw std::runtime_error( msg );
  }

  mesh.modification_end();

  double dt = stk::wall_dtime( t );

  stk::all_reduce( mesh.parallel() , stk::ReduceMax<1>( & dt ) );

  std::cout << "  P" << mesh.parallel_rank()
            << ": Meshed Hex = " << num_hex
            << " , Shell = " << num_shell
            << " , Node = " << num_nodes
            << " in " << dt << " sec"
            << std::endl ;
  std::cout.flush();
}
Example #19
0
static int dump_atoms(pNode atoms)
{
  node_map(atoms, (NodeIterator)&node_iterator, NULL);
};