Esempio n. 1
0
void UCDIO::write_interior_elems(std::ostream& out_stream, const MeshBase& mesh)
{
  std::string type[] =
    { "edge",  "edge",  "edge",
      "tri",   "tri",
      "quad",  "quad",  "quad",
      "tet",   "tet",
      "hex",   "hex",   "hex",
      "prism", "prism", "prism",
      "pyramid" };

  MeshBase::const_element_iterator it  = mesh.elements_begin();
  const MeshBase::const_element_iterator end = mesh.elements_end();

  unsigned int e=1; // 1-based element number for UCD

  // Write element information
  for (; it != end; ++it)
    {
      libmesh_assert (out_stream.good());

      // PB: I believe these are the only supported ElemTypes.
      const ElemType etype = (*it)->type();
      if( (etype != TRI3) && (etype != QUAD4) &&
          (etype != TET4) && (etype != HEX8) &&
          (etype != PRISM6) && (etype != PYRAMID5) )
        libmesh_error_msg("Error: Unsupported ElemType for UCDIO.");

      out_stream << e++ << " 0 " << type[etype] << "\t";
      // (*it)->write_ucd_connectivity(out_stream);
      (*it)->write_connectivity(out_stream, UCD);
    }

  return;
}
Esempio n. 2
0
void TopologyMap::fill(const MeshBase& mesh)
{
  // Populate the nodes map
  MeshBase::const_element_iterator
    it = mesh.elements_begin(),
    end = mesh.elements_end();
  for (; it != end; ++it)
    {
      const Elem* elem = *it;

      // We only need to add nodes which might be added during mesh
      // refinement; this means they need to be child nodes.
      if (!elem->has_children())
        continue;

      for (unsigned int c = 0; c != elem->n_children(); ++c)
        {
          if (elem->child(c)->is_remote())
            continue;

          for (unsigned int n = 0; n != elem->n_nodes_in_child(c); ++n)
            {
              const std::vector<std::pair<dof_id_type, dof_id_type> >
                bracketing_nodes = elem->bracketing_nodes(c,n);

              this->add_node(*elem->child(c)->get_node(n),
                             bracketing_nodes);
            }
        }
    }
}
Esempio n. 3
0
void MeshTools::Subdivision::tag_boundary_ghosts(MeshBase & mesh)
{
  MeshBase::element_iterator       el     = mesh.elements_begin();
  const MeshBase::element_iterator end_el = mesh.elements_end();
  for (; el != end_el; ++el)
    {
      Elem * elem = *el;
      libmesh_assert_equal_to(elem->type(), TRI3SUBDIVISION);

      Tri3Subdivision * sd_elem = static_cast<Tri3Subdivision *>(elem);
      for (unsigned int i = 0; i < elem->n_sides(); ++i)
        {
          if (elem->neighbor(i) == libmesh_nullptr)
            {
              sd_elem->set_ghost(true);
              // set all other neighbors to ghosts as well
              if (elem->neighbor(next[i]))
                {
                  Tri3Subdivision * nb = static_cast<Tri3Subdivision *>(elem->neighbor(next[i]));
                  nb->set_ghost(true);
                }
              if (elem->neighbor(prev[i]))
                {
                  Tri3Subdivision * nb = static_cast<Tri3Subdivision *>(elem->neighbor(prev[i]));
                  nb->set_ghost(true);
                }
            }
        }
    }
}
void findElementsIntersectedByPlane(const Plane & plane, const MeshBase & mesh, std::vector<const Elem *> & intersected_elems)
{
  // Loop over all elements to find elements intersected by the plane
  MeshBase::const_element_iterator el = mesh.elements_begin();
  const MeshBase::const_element_iterator end_el = mesh.elements_end();
  for (; el != end_el; ++el)
  {
    const Elem * elem = *el;
    bool intersected = false;

    // Check whether the first node of this element is below or above the plane
    const Node node0 = *elem->get_node(0);
    bool node0_above_plane = plane.above_surface(node0);

    // Loop over the rest of the nodes and check if any node is on the other side of the plane
    for (unsigned int i = 1; i < elem->n_nodes(); ++i)
    {
      const Node node = *elem->get_node(i);

      bool node_above_plane = plane.above_surface(node);
      if (node0_above_plane != node_above_plane)
        intersected = true;
    }

    if (intersected)
      intersected_elems.push_back(elem);
  }
}
void SubdomainPartitioner::_do_partition (MeshBase & mesh,
                                          const unsigned int n)
{
  libmesh_assert_greater (n, 0);

  // Check for an easy return.  If the user has not specified any
  // entries in the chunks vector, we just do a single partitioning.
  if ((n == 1) || chunks.empty())
    {
      this->single_partition (mesh);
      return;
    }

  // Now actually do the partitioning.
  LOG_SCOPE ("_do_partition()", "SubdomainPartitioner");

  // For each chunk, construct an iterator range for the set of
  // subdomains in question, and pass it to the internal Partitioner.
  for (std::size_t c=0; c<chunks.size(); ++c)
    {
      MeshBase::element_iterator
        it = mesh.active_subdomain_set_elements_begin(chunks[c]),
        end = mesh.active_subdomain_set_elements_end(chunks[c]);

      _internal_partitioner->partition_range(mesh, it, end, n);
    }
}
Esempio n. 6
0
void Partitioner::repartition (MeshBase & mesh,
                               const unsigned int n)
{
  // we cannot partition into more pieces than we have
  // active elements!
  const unsigned int n_parts =
    static_cast<unsigned int>
    (std::min(mesh.n_active_elem(), static_cast<dof_id_type>(n)));

  // Set the number of partitions in the mesh
  mesh.set_n_partitions()=n_parts;

  if (n_parts == 1)
    {
      this->single_partition (mesh);
      return;
    }

  // First assign a temporary partitioning to any unpartitioned elements
  Partitioner::partition_unpartitioned_elements(mesh, n_parts);

  // Call the partitioning function
  this->_do_repartition(mesh,n_parts);

  // Set the parent's processor ids
  Partitioner::set_parent_processor_ids(mesh);

  // Set the node's processor ids
  Partitioner::set_node_processor_ids(mesh);
}
Esempio n. 7
0
void SFCPartitioner::_do_partition (MeshBase & mesh,
                                    const unsigned int n)
{
  this->partition_range(mesh,
                        mesh.active_elements_begin(),
                        mesh.active_elements_end(),
                        n);
}
Esempio n. 8
0
void LocationMap<Elem>::fill(MeshBase& mesh)
{
  // Populate the elem map
  MeshBase::element_iterator       it  = mesh.active_elements_begin(),
                                   end = mesh.active_elements_end();
  for (; it != end; ++it)
    this->insert(**it);
}
Esempio n. 9
0
void MetisPartitioner::_do_partition (MeshBase & mesh,
                                      const unsigned int n_pieces)
{
  this->partition_range(mesh,
                        mesh.active_elements_begin(),
                        mesh.active_elements_end(),
                        n_pieces);
}
Esempio n. 10
0
void LocationMap<Node>::fill(MeshBase& mesh)
{
  // Populate the nodes map
  MeshBase::node_iterator  it = mesh.nodes_begin(),
                          end = mesh.nodes_end();
  for (; it != end; ++it)
    this->insert(**it);
}
Esempio n. 11
0
void MeshBase::addAttribs(const MeshBase& other)
{
    int num = other.numAttribs();
    for (int i = 0; i < num; i++)
    {
        const AttribSpec& spec = other.attribSpec(i);
        addAttrib(spec.type, spec.format, spec.length);
    }
}
Esempio n. 12
0
void Partitioner::partition (MeshBase & mesh,
                             const unsigned int n)
{
  libmesh_parallel_only(mesh.comm());

  // BSK - temporary fix while redistribution is integrated 6/26/2008
  // Uncomment this to not repartition in parallel
  //   if (!mesh.is_serial())
  //     return;

  // we cannot partition into more pieces than we have
  // active elements!
  const unsigned int n_parts =
    static_cast<unsigned int>
    (std::min(mesh.n_active_elem(), static_cast<dof_id_type>(n)));

  // Set the number of partitions in the mesh
  mesh.set_n_partitions()=n_parts;

  if (n_parts == 1)
    {
      this->single_partition (mesh);
      return;
    }

  // First assign a temporary partitioning to any unpartitioned elements
  Partitioner::partition_unpartitioned_elements(mesh, n_parts);

  // Call the partitioning function
  this->_do_partition(mesh,n_parts);

  // Set the parent's processor ids
  Partitioner::set_parent_processor_ids(mesh);

  // Redistribute elements if necessary, before setting node processor
  // ids, to make sure those will be set consistently
  mesh.redistribute();

#ifdef DEBUG
  MeshTools::libmesh_assert_valid_remote_elems(mesh);

  // Messed up elem processor_id()s can leave us without the child
  // elements we need to restrict vectors on a distributed mesh
  MeshTools::libmesh_assert_valid_procids<Elem>(mesh);
#endif

  // Set the node's processor ids
  Partitioner::set_node_processor_ids(mesh);

#ifdef DEBUG
  MeshTools::libmesh_assert_valid_procids<Elem>(mesh);
#endif

  // Give derived Mesh classes a chance to update any cached data to
  // reflect the new partitioning
  mesh.update_post_partitioning();
}
Esempio n. 13
0
void MeshData::translate (const MeshBase & out_mesh,
                          std::vector<Number> & values,
                          std::vector<std::string> & names) const
{
  libmesh_assert (_active || _compatibility_mode);

  START_LOG("translate()", "MeshData");

  const unsigned int n_comp = this->n_val_per_node();

  // transfer our nodal data to a vector
  // that may be written concurrently
  // with the \p out_mesh.
  {
    // reserve memory for the nodal data
    values.reserve(n_comp*out_mesh.n_nodes());

    // iterate over the mesh's nodes
    MeshBase::const_node_iterator       nodes_it  = out_mesh.nodes_begin();
    const MeshBase::const_node_iterator nodes_end = out_mesh.nodes_end();

    // Do not use the \p get_data() method, but the operator()
    // method, since this returns by default a zero value,
    // when there is no nodal data.
    for (; nodes_it != nodes_end; ++nodes_it)
      {
        const Node * node = *nodes_it;

        for (unsigned int c= 0; c<n_comp; c++)
          values.push_back(this->operator()(node, c));
      }
  }



  // Now we have the data, nicely stored in \p values.
  // It remains to give names to the data, then write to
  // file.
  {
    names.reserve(n_comp);

    // this naming scheme only works up to n_comp=100
    // (at least for gmv-accepted variable names)
    libmesh_assert_less (n_comp, 100);

    for (unsigned int n=0; n<n_comp; n++)
      {
        std::ostringstream name_buf;
        name_buf << "bc_" << n;
        names.push_back(name_buf.str());
      }
  }

  STOP_LOG("translate()", "MeshData");
}
Esempio n. 14
0
void
MoosePreconditioner::copyVarValues(MeshBase & mesh,
                                   const unsigned int from_system,
                                   const unsigned int from_var,
                                   const NumericVector<Number> & from_vector,
                                   const unsigned int to_system,
                                   const unsigned int to_var,
                                   NumericVector<Number> & to_vector)
{
  {
    MeshBase::node_iterator it = mesh.local_nodes_begin();
    MeshBase::node_iterator it_end = mesh.local_nodes_end();

    for (; it != it_end; ++it)
    {
      Node * node = *it;

      unsigned int n_comp = node->n_comp(from_system, from_var);

      mooseAssert(node->n_comp(from_system, from_var) == node->n_comp(to_system, to_var),
                  "Number of components does not match in each system");

      for (unsigned int i = 0; i < n_comp; i++)
      {
        dof_id_type from_dof = node->dof_number(from_system, from_var, i);
        dof_id_type to_dof = node->dof_number(to_system, to_var, i);

        to_vector.set(to_dof, from_vector(from_dof));
      }
    }
  }
  {
    MeshBase::element_iterator it = mesh.local_elements_begin();
    MeshBase::element_iterator it_end = mesh.local_elements_end();

    for (; it != it_end; ++it)
    {
      Elem * elem = *it;

      unsigned int n_comp = elem->n_comp(from_system, from_var);

      mooseAssert(elem->n_comp(from_system, from_var) == elem->n_comp(to_system, to_var),
                  "Number of components does not match in each system");

      for (unsigned int i = 0; i < n_comp; i++)
      {
        dof_id_type from_dof = elem->dof_number(from_system, from_var, i);
        dof_id_type to_dof = elem->dof_number(to_system, to_var, i);

        to_vector.set(to_dof, from_vector(from_dof));
      }
    }
  }
}
Esempio n. 15
0
unsigned int CheckpointIO::n_active_levels_on_processor(const MeshBase & mesh) const
{
  unsigned int max_level = 0;

  MeshBase::const_element_iterator el = mesh.active_elements_begin();
  const MeshBase::const_element_iterator end_el = mesh.active_elements_end();

  for( ; el != end_el; ++el)
    max_level = std::max((*el)->level(), max_level);

  return max_level + 1;
}
Esempio n. 16
0
void integrate_function (const MeshBase &mesh)
{
#if defined(LIBMESH_HAVE_TRIANGLE) && defined(LIBMESH_HAVE_TETGEN)
    MeshBase::const_element_iterator       el     = mesh.active_local_elements_begin();
    const MeshBase::const_element_iterator end_el = mesh.active_local_elements_end();

    std::vector<Real> vertex_distance;

    QComposite<QGauss> qrule (mesh.mesh_dimension(), FIRST);
    //QGauss qrule (mesh.mesh_dimension(), FIRST);

    UniquePtr<FEBase> fe (FEBase::build (mesh.mesh_dimension(), FEType (FIRST, LAGRANGE)));

    Real int_val=0.;

    const std::vector<Point> &q_points = fe->get_xyz();
    const std::vector<Real>  &JxW      = fe->get_JxW();

    for (; el!=end_el; ++el)
    {
        const Elem *elem = *el;

        vertex_distance.clear();

        for (unsigned int v=0; v<elem->n_vertices(); v++)
            vertex_distance.push_back (distance(elem->point(v)));

        qrule.init (*elem, vertex_distance);

        fe->reinit (elem,
                    &(qrule.get_points()),
                    &(qrule.get_weights()));


        // TODO:  would it be valuable to have the composite quadrature rule sort
        // from smallest to largest JxW value to help prevent
        // ... large + small + large + large + small ...
        // type truncation errors?
        for (unsigned int qp=0; qp<q_points.size(); qp++)
            int_val += JxW[qp] * integrand(q_points[qp]);
    }

    mesh.comm().sum (int_val);

    std::cout  << "\n***********************************\n"
               << " int_val   = " << int_val << std::endl
               << " exact_val = " <<  1*(2*2 - radius*radius*pi) + 10.*(radius*radius*pi)
               << "\n***********************************\n"
               << std::endl;
#else
    libmesh_ignore(mesh);
#endif
}
Esempio n. 17
0
	void Object::updateBoundSphere()
	{
		mBoundSphere.center.setValue(0,0,0);
		mBoundSphere.radius = 0;
		MeshIterator iter = getElements();
		for(  ; iter.haveMore() ; iter.next() )
		{
			MeshBase* mesh = iter.get()->getMesh();
			BoundSphere sphere;
			mesh->calcBoundSphere( sphere );
			mBoundSphere.merge( sphere );
		}
	}
Esempio n. 18
0
	void Object::xform( bool beAllInstance )
	{
		Matrix4 const& trans = getLocalTransform();

		MeshIterator iter = getElements();
		for ( ; iter.haveMore() ; iter.next() )
		{
			MeshBase* mesh = iter.get()->getMesh();
			iter.get()->getUnit().mesh = mesh->xform( trans , beAllInstance );
		}

		mLocalTrans.setIdentity();
	}
Esempio n. 19
0
bool MeshBase::isCompatible(const MeshBase& other) const
{
    if (numAttribs() != other.numAttribs())
        return false;

    for (int i = 0; i < numAttribs(); i++)
    {
        const AttribSpec& a = attribSpec(i);
        const AttribSpec& b = other.attribSpec(i);
        if (a.type != b.type || a.format != b.format || a.length != b.length)
            return false;
    }
    return true;
}
Esempio n. 20
0
//--------------------------------------------------------------------------
void TopologyMap::init(MeshBase& mesh)
{
  // This function must be run on all processors at once
  // for non-serial meshes
  if (!mesh.is_serial())
    libmesh_parallel_only(mesh.comm());

  START_LOG("init()", "TopologyMap");

  // Clear the old map
  _map.clear();

  this->fill(mesh);

  STOP_LOG("init()", "TopologyMap");
}
Esempio n. 21
0
void MeshBase::set(const MeshBase& other)
{
    if (&other == this)
        return;

    FW_ASSERT(other.isInMemory());
    clear();

    if (!isCompatible(other))
    {
        append(other);
        compact();
        return;
    }

    m_stride = other.m_stride;
    m_numVertices = other.m_numVertices;
    m_attribs = other.m_attribs;
    m_vertices = other.m_vertices;

    resizeSubmeshes(other.m_submeshes.getSize());
    for (int i = 0; i < m_submeshes.getSize(); i++)
    {
        *m_submeshes[i].indices = *other.m_submeshes[i].indices;
        m_submeshes[i].material = other.m_submeshes[i].material;
    }
}
Esempio n. 22
0
void
SideSetsGeneratorBase::flood(const Elem * elem,
                             Point normal,
                             boundary_id_type side_id,
                             MeshBase & mesh)
{
  if (elem == nullptr || (_visited[side_id].find(elem) != _visited[side_id].end()))
    return;

  _visited[side_id].insert(elem);
  for (unsigned int side = 0; side < elem->n_sides(); ++side)
  {
    if (elem->neighbor_ptr(side))
      continue;

    _fe_face->reinit(elem, side);
    const std::vector<Point> normals = _fe_face->get_normals();

    // We'll just use the normal of the first qp
    if (std::abs(1.0 - normal * normals[0]) <= _variance)
    {
      mesh.get_boundary_info().add_side(elem, side, side_id);
      for (unsigned int neighbor = 0; neighbor < elem->n_sides(); ++neighbor)
      {
        // Flood to the neighboring elements using the current matching side normal from this
        // element.
        // This will allow us to tolerate small changes in the normals so we can "paint" around a
        // curve.
        flood(elem->neighbor_ptr(neighbor), _fixed_normal ? normal : normals[0], side_id, mesh);
      }
    }
  }
}
Esempio n. 23
0
void LocationMap<T>::init(MeshBase& mesh)
{
  // This function must be run on all processors at once
  // for non-serial meshes
  if (!mesh.is_serial())
    parallel_only();

  START_LOG("init()", "LocationMap");

  // Clear the old map
  _map.clear();

  // Cache a bounding box
  _lower_bound.clear();
  _lower_bound.resize(LIBMESH_DIM, std::numeric_limits<Real>::max());
  _upper_bound.clear();
  _upper_bound.resize(LIBMESH_DIM, -std::numeric_limits<Real>::max());

  MeshBase::node_iterator       it  = mesh.nodes_begin();
  const MeshBase::node_iterator end = mesh.nodes_end();

  for (; it != end; ++it)
    {
      Node* node = *it;

      for (unsigned int i=0; i != LIBMESH_DIM; ++i)
        {
          // Expand the bounding box if necessary
          _lower_bound[i] = std::min(_lower_bound[i],
                                     (*node)(i));
          _upper_bound[i] = std::max(_upper_bound[i],
                                     (*node)(i));
        }
    }

  // On a parallel mesh we might not yet have a full bounding box
  if (!mesh.is_serial())
    {
      CommWorld.min(_lower_bound);
      CommWorld.max(_upper_bound);
    }

  this->fill(mesh);

  STOP_LOG("init()", "LocationMap");
}
Esempio n. 24
0
// ------------------------------------------------------------
// LinearPartitioner implementation
void LinearPartitioner::_do_partition (MeshBase& mesh,
                                       const unsigned int n)
{
  libmesh_assert_greater (n, 0);

  // Check for an easy return
  if (n == 1)
    {
      this->single_partition (mesh);
      return;
    }

  // Create a simple linear partitioning
  {
    START_LOG ("partition()", "LinearPartitioner");

    const dof_id_type n_active_elem = mesh.n_active_elem();
    const dof_id_type blksize       = n_active_elem/n;

    dof_id_type e = 0;

    MeshBase::element_iterator       elem_it  = mesh.active_elements_begin();
    const MeshBase::element_iterator elem_end = mesh.active_elements_end();

    for ( ; elem_it != elem_end; ++elem_it)
      {
        if ((e/blksize) < n)
          {
            Elem *elem = *elem_it;
            elem->processor_id() =
              libmesh_cast_int<processor_id_type>(e/blksize);
          }
        else
          {
            Elem *elem = *elem_it;
            elem->processor_id() = 0;
            elem = elem->parent();
          }

        e++;
      }

    STOP_LOG ("partition()", "LinearPartitioner");
  }
}
Esempio n. 25
0
void UCDIO::write_nodes(std::ostream& out_stream, const MeshBase& mesh)
{
  MeshBase::const_node_iterator       it  = mesh.nodes_begin();
  const MeshBase::const_node_iterator end = mesh.nodes_end();

  unsigned int n=1; // 1-based node number for UCD

  // Write the node coordinates
  for (; it != end; ++it)
    {
      libmesh_assert (out_stream.good());

      out_stream << n++ << "\t";
      (*it)->write_unformatted(out_stream);
    }

  return;
}
Esempio n. 26
0
void CentroidPartitioner::compute_centroids (MeshBase& mesh)
{
  _elem_centroids.clear();
  _elem_centroids.reserve(mesh.n_elem());

  //   elem_iterator it(mesh.elements_begin());
  //   const elem_iterator it_end(mesh.elements_end());

  MeshBase::element_iterator       it     = mesh.elements_begin();
  const MeshBase::element_iterator it_end = mesh.elements_end();

  for (; it != it_end; ++it)
    {
      Elem* elem = *it;

      _elem_centroids.push_back(std::make_pair(elem->centroid(), elem));
    }
}
Esempio n. 27
0
void Partitioner::single_partition (MeshBase & mesh)
{
  LOG_SCOPE("single_partition()","Partitioner");

  // Loop over all the elements and assign them to processor 0.
  MeshBase::element_iterator       elem_it  = mesh.elements_begin();
  const MeshBase::element_iterator elem_end = mesh.elements_end();

  for ( ; elem_it != elem_end; ++elem_it)
    (*elem_it)->processor_id() = 0;

  // For a single partition, all the nodes are on processor 0
  MeshBase::node_iterator       node_it  = mesh.nodes_begin();
  const MeshBase::node_iterator node_end = mesh.nodes_end();

  for ( ; node_it != node_end; ++node_it)
    (*node_it)->processor_id() = 0;
}
Esempio n. 28
0
 MeshSerializer::MeshSerializer(MeshBase& mesh, bool need_serial) :
   _mesh(mesh),
   reparallelize(false)
 {
   libmesh_parallel_only(mesh.comm());
   if (need_serial && !_mesh.is_serial()) {
     reparallelize = true;
     _mesh.allgather();
   }
 }
Esempio n. 29
0
void
SideSetsGeneratorBase::setup(MeshBase & mesh)
{
  mooseAssert(_fe_face == nullptr, "FE Face has already been initialized");

  unsigned int dim = mesh.mesh_dimension();

  // Setup the FE Object so we can calculate normals
  FEType fe_type(Utility::string_to_enum<Order>("CONSTANT"),
                 Utility::string_to_enum<FEFamily>("MONOMIAL"));
  _fe_face = FEBase::build(dim, fe_type);
  _qface = libmesh_make_unique<QGauss>(dim - 1, FIRST);
  _fe_face->attach_quadrature_rule(_qface.get());
}
Esempio n. 30
0
void LocationMap<T>::init(MeshBase & mesh)
{
  // This function must be run on all processors at once
  // for non-serial meshes
  if (!mesh.is_serial())
    libmesh_parallel_only(mesh.comm());

  LOG_SCOPE("init()", "LocationMap");

  // Clear the old map
  _map.clear();

  // Cache a bounding box
  _lower_bound.clear();
  _lower_bound.resize(LIBMESH_DIM, std::numeric_limits<Real>::max());
  _upper_bound.clear();
  _upper_bound.resize(LIBMESH_DIM, -std::numeric_limits<Real>::max());

  for (auto & node : mesh.node_ptr_range())
    for (unsigned int i=0; i != LIBMESH_DIM; ++i)
      {
        // Expand the bounding box if necessary
        _lower_bound[i] = std::min(_lower_bound[i],
                                   (*node)(i));
        _upper_bound[i] = std::max(_upper_bound[i],
                                   (*node)(i));
      }

  // On a parallel mesh we might not yet have a full bounding box
  if (!mesh.is_serial())
    {
      mesh.comm().min(_lower_bound);
      mesh.comm().max(_upper_bound);
    }

  this->fill(mesh);
}