libMesh
Functions | Variables
subdomains_ex3.C File Reference

Go to the source code of this file.

Functions

void integrate_function (const MeshBase &mesh)
 
Real distance (const Point &p)
 
Real integrand (const Point &p)
 
int main (int argc, char **argv)
 

Variables

const Real radius = 0.5
 

Function Documentation

◆ distance()

Real distance ( const Point p)

Definition at line 50 of file subdomains_ex3.C.

51 {
52  Point cent(0.8, 0.9);
53  return ((p-cent).norm() - radius);
54 }

References std::norm(), and radius.

Referenced by OverlappingTestPartitioner::_do_partition(), libMesh::MeshCommunication::assign_global_indices(), libMesh::InfElemBuilder::build_inf_elem(), libMesh::EquationSystems::build_parallel_solution_vector(), libMesh::MeshCommunication::find_global_indices(), libMesh::RBParametrized::get_closest_value(), libMesh::ParmetisPartitioner::initialize(), libMesh::ExodusII_IO_Helper::initialize(), LinearElasticityWithContact::initialize_contact_load_paths(), libMesh::ExodusII_IO_Helper::initialize_element_variables(), integrand(), integrate_function(), libMesh::StoredRange< iterator_type, object_type >::is_divisible(), libMesh::Parallel::Histogram< KeyType, IdxType >::local_bin_size(), libMesh::DistributedVector< T >::localize(), AugmentSparsityOnInterface::mesh_reinit(), libMesh::ReplicatedMesh::n_active_elem(), libMesh::DistributedMesh::n_active_elem(), libMesh::MeshTools::n_active_elem_of_type(), libMesh::MeshBase::n_active_elem_on_proc(), libMesh::BoundaryInfo::n_boundary_ids(), libMesh::MeshTools::n_elem(), libMesh::MeshTools::n_elem_of_type(), libMesh::MeshBase::n_elem_on_proc(), libMesh::DofMap::n_local_constrained_dofs(), libMesh::MeshTools::n_nodes(), libMesh::MeshBase::n_nodes_on_proc(), libMesh::PetscMatrix< libMesh::Number >::operator()(), libMesh::LinearPartitioner::partition_range(), libMesh::MetisPartitioner::partition_range(), libMesh::SFCPartitioner::partition_range(), libMesh::Partitioner::partition_unpartitioned_elements(), libMesh::LaspackMatrix< T >::pos(), OverlappingFunctorTest::run_coupling_functor_test(), libMesh::FE< Dim, LAGRANGE_VEC >::shape(), libMesh::FE< Dim, LAGRANGE_VEC >::shape_deriv(), libMesh::FE< Dim, LAGRANGE_VEC >::shape_second_deriv(), libMesh::StoredRange< iterator_type, object_type >::size(), libMesh::Parallel::BinSorter< KeyType, IdxType >::sizeof_bin(), libMesh::StoredRange< iterator_type, object_type >::StoredRange(), DefaultCouplingTest::testCoupling(), EquationSystemsTest::testDisableDefaultGhosting(), PartitionerTest< PartitionerSubclass, MeshClass >::testPartition(), CheckpointIOTest::testSplitter(), libMesh::TetGenMeshInterface::triangulate_conformingDelaunayMesh_carvehole(), libMesh::ExodusII_IO::write_element_data_from_discontinuous_nodal_data(), libMesh::ExodusII_IO_Helper::write_element_values_element_major(), libMesh::Nemesis_IO_Helper::write_exodus_initialization_info(), libMesh::Nemesis_IO_Helper::write_nodal_solution(), and libMesh::VariationalMeshSmoother::writegr().

◆ integrand()

Real integrand ( const Point p)

Definition at line 56 of file subdomains_ex3.C.

57 {
58  return (distance(p) < 0) ? 10. : 1.;
59 }

References distance().

Referenced by integrate_function().

◆ integrate_function()

void integrate_function ( const MeshBase mesh)

Definition at line 121 of file subdomains_ex3.C.

122 {
123 #if defined(LIBMESH_HAVE_TRIANGLE) && defined(LIBMESH_HAVE_TETGEN)
124 
125  std::vector<Real> vertex_distance;
126 
128  //QGauss qrule (mesh.mesh_dimension(), FIRST);
129 
130  std::unique_ptr<FEBase> fe (FEBase::build (mesh.mesh_dimension(), FEType (FIRST, LAGRANGE)));
131 
132  Real int_val=0.;
133 
134  const std::vector<Point> & q_points = fe->get_xyz();
135  const std::vector<Real> & JxW = fe->get_JxW();
136 
137  for (const auto & elem : mesh.active_local_element_ptr_range())
138  {
139  vertex_distance.clear();
140 
141  for (unsigned int v=0; v<elem->n_vertices(); v++)
142  vertex_distance.push_back (distance(elem->point(v)));
143 
144  qrule.init (*elem, vertex_distance);
145 
146  fe->reinit (elem,
147  &(qrule.get_points()),
148  &(qrule.get_weights()));
149 
150 
151  // TODO: would it be valuable to have the composite quadrature rule sort
152  // from smallest to largest JxW value to help prevent
153  // ... large + small + large + large + small ...
154  // type truncation errors?
155  for (std::size_t qp=0; qp<q_points.size(); qp++)
156  int_val += JxW[qp] * integrand(q_points[qp]);
157  }
158 
159  mesh.comm().sum (int_val);
160 
161  libMesh::out << "\n***********************************\n"
162  << " int_val = " << int_val << std::endl
163  << " exact_val = " << 1*(2*2 - radius*radius*pi) + 10.*(radius*radius*pi)
164  << "\n***********************************\n"
165  << std::endl;
166 #else
168 #endif
169 }

References libMesh::MeshBase::active_local_element_ptr_range(), libMesh::FEGenericBase< OutputType >::build(), libMesh::ParallelObject::comm(), distance(), libMesh::FIRST, libMesh::QComposite< QSubCell >::init(), integrand(), libMesh::LAGRANGE, libMesh::libmesh_ignore(), mesh, libMesh::MeshBase::mesh_dimension(), libMesh::out, libMesh::pi, radius, and libMesh::Real.

Referenced by main().

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 64 of file subdomains_ex3.C.

65 {
66  // Initialize libMesh and any dependent libraries, like in example 2.
67  LibMeshInit init (argc, argv);
68 
69  // This example requires Adaptive Mesh Refinement support - although
70  // it only refines uniformly, the refinement code used is the same
71  // underneath. It also requires libmesh support for Triangle and
72  // Tetgen, which means that libmesh must be configured with
73  // --disable-strict-lgpl for this example to run.
74 #if !defined(LIBMESH_HAVE_TRIANGLE) || !defined(LIBMESH_HAVE_TETGEN) || !defined(LIBMESH_ENABLE_AMR)
75  libmesh_example_requires(false, "--disable-strict-lgpl --enable-amr");
76 #else
77 
78  // Skip this 2D example if libMesh was compiled as 1D-only.
79  libmesh_example_requires(2 <= LIBMESH_DIM, "2D support");
80 
81  // Read the mesh from file. This is the coarse mesh that will be used
82  // in example 10 to demonstrate adaptive mesh refinement. Here we will
83  // simply read it in and uniformly refine it 5 times before we compute
84  // with it.
85  Mesh mesh(init.comm());
86 
87  {
88  unsigned int dim=2;
89 
90  if (argc == 3 && std::atoi(argv[2]) == 3)
91  {
92  libmesh_here();
93  dim=3;
94  }
95 
96  mesh.read ((dim==2) ? "mesh.xda" : "hybrid_3d.xda");
97  }
98 
99  // Create a MeshRefinement object to handle refinement of our mesh.
100  // This class handles all the details of mesh refinement and coarsening.
101  MeshRefinement mesh_refinement (mesh);
102 
103  // Uniformly refine the mesh 4 times. This is the
104  // first time we use the mesh refinement capabilities
105  // of the library.
106  mesh_refinement.uniformly_refine (4);
107 
108  // Print information about the mesh to the screen.
109  mesh.print_info();
110 
111  // integrate the desired function
113 
114  // All done.
115  return 0;
116 #endif
117 }

References dim, libMesh::TriangleWrapper::init(), integrate_function(), mesh, libMesh::MeshBase::print_info(), libMesh::MeshBase::read(), and libMesh::MeshRefinement::uniformly_refine().

Variable Documentation

◆ radius

const Real radius = 0.5
libMesh::pi
const Real pi
.
Definition: libmesh.h:237
integrate_function
void integrate_function(const MeshBase &mesh)
Definition: subdomains_ex3.C:121
libMesh::Mesh
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50
libMesh::MeshBase::read
virtual void read(const std::string &name, void *mesh_data=nullptr, bool skip_renumber_nodes_and_elements=false, bool skip_find_neighbors=false)=0
Interfaces for reading/writing a mesh to/from a file.
libMesh::MeshBase::active_local_element_ptr_range
virtual SimpleRange< element_iterator > active_local_element_ptr_range()=0
libMesh::ParallelObject::comm
const Parallel::Communicator & comm() const
Definition: parallel_object.h:94
mesh
MeshBase & mesh
Definition: mesh_communication.C:1257
libMesh::MeshBase::mesh_dimension
unsigned int mesh_dimension() const
Definition: mesh_base.C:135
dim
unsigned int dim
Definition: adaptivity_ex3.C:113
libMesh::TriangleWrapper::init
void init(triangulateio &t)
Initializes the fields of t to nullptr/0 as necessary.
libMesh::MeshRefinement
Implements (adaptive) mesh refinement algorithms for a MeshBase.
Definition: mesh_refinement.h:61
radius
const Real radius
Definition: subdomains_ex3.C:48
libMesh::libmesh_ignore
void libmesh_ignore(const Args &...)
Definition: libmesh_common.h:526
integrand
Real integrand(const Point &p)
Definition: subdomains_ex3.C:56
libMesh::Point
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:38
libMesh::LibMeshInit
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
Definition: libmesh.h:83
distance
Real distance(const Point &p)
Definition: subdomains_ex3.C:50
libMesh::QComposite
This class implements generic composite quadrature rules.
Definition: quadrature_composite.h:51
libMesh::FEType
class FEType hides (possibly multiple) FEFamily and approximation orders, thereby enabling specialize...
Definition: fe_type.h:178
libMesh::MeshBase::print_info
void print_info(std::ostream &os=libMesh::out) const
Prints relevant information about the mesh.
Definition: mesh_base.C:585
std::norm
MetaPhysicL::DualNumber< T, D > norm(const MetaPhysicL::DualNumber< T, D > &in)
libMesh::LAGRANGE
Definition: enum_fe_family.h:36
libMesh::Real
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Definition: libmesh_common.h:121
libMesh::out
OStreamProxy out
libMesh::FIRST
Definition: enum_order.h:42