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

Real distance ( const Point p)

Definition at line 49 of file subdomains_ex3.C.

References radius.

Referenced by 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(), integrand(), integrate_function(), libMesh::StoredRange< iterator_type, object_type >::is_divisible(), libMesh::Parallel::Histogram< KeyType, IdxType >::local_bin_size(), 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::LinearPartitioner::partition_range(), libMesh::MetisPartitioner::partition_range(), libMesh::SFCPartitioner::partition_range(), libMesh::Partitioner::partition_unpartitioned_elements(), libMesh::Parallel::Communicator::receive(), libMesh::Parallel::Communicator::send_packed_range(), libMesh::FE< Dim, T >::shape(), libMesh::FE< Dim, T >::shape_deriv(), libMesh::FE< Dim, T >::shape_second_deriv(), libMesh::StoredRange< iterator_type, object_type >::size(), libMesh::Parallel::BinSorter< KeyType, IdxType >::sizeof_bin(), libMesh::StoredRange< iterator_type, object_type >::StoredRange(), CheckpointIOTest::testSplitter(), libMesh::TetGenMeshInterface::triangulate_conformingDelaunayMesh_carvehole(), libMesh::Nemesis_IO_Helper::write_exodus_initialization_info(), and libMesh::VariationalMeshSmoother::writegr().

50 {
51  Point cent(0.8, 0.9);
52  return ((p-cent).norm() - radius);
53 }
const Real radius
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:38
Real integrand ( const Point p)

Definition at line 55 of file subdomains_ex3.C.

References distance().

Referenced by integrate_function().

56 {
57  return (distance(p) < 0) ? 10. : 1.;
58 }
Real distance(const Point &p)
void integrate_function ( const MeshBase mesh)

Definition at line 120 of file subdomains_ex3.C.

References libMesh::MeshBase::active_local_element_ptr_range(), libMesh::FEGenericBase< OutputType >::build(), libMesh::ParallelObject::comm(), distance(), libMesh::FIRST, integrand(), libMesh::LAGRANGE, libMesh::libmesh_ignore(), libMesh::MeshBase::mesh_dimension(), libMesh::out, libMesh::pi, radius, libMesh::Real, and libMesh::Parallel::Communicator::sum().

Referenced by main().

121 {
122 #if defined(LIBMESH_HAVE_TRIANGLE) && defined(LIBMESH_HAVE_TETGEN)
123 
124  std::vector<Real> vertex_distance;
125 
126  QComposite<QGauss> qrule (mesh.mesh_dimension(), FIRST);
127  //QGauss qrule (mesh.mesh_dimension(), FIRST);
128 
129  UniquePtr<FEBase> fe (FEBase::build (mesh.mesh_dimension(), FEType (FIRST, LAGRANGE)));
130 
131  Real int_val=0.;
132 
133  const std::vector<Point> & q_points = fe->get_xyz();
134  const std::vector<Real> & JxW = fe->get_JxW();
135 
136  for (const auto & elem : mesh.active_local_element_ptr_range())
137  {
138  vertex_distance.clear();
139 
140  for (unsigned int v=0; v<elem->n_vertices(); v++)
141  vertex_distance.push_back (distance(elem->point(v)));
142 
143  qrule.init (*elem, vertex_distance);
144 
145  fe->reinit (elem,
146  &(qrule.get_points()),
147  &(qrule.get_weights()));
148 
149 
150  // TODO: would it be valuable to have the composite quadrature rule sort
151  // from smallest to largest JxW value to help prevent
152  // ... large + small + large + large + small ...
153  // type truncation errors?
154  for (std::size_t qp=0; qp<q_points.size(); qp++)
155  int_val += JxW[qp] * integrand(q_points[qp]);
156  }
157 
158  mesh.comm().sum (int_val);
159 
160  libMesh::out << "\n***********************************\n"
161  << " int_val = " << int_val << std::endl
162  << " exact_val = " << 1*(2*2 - radius*radius*pi) + 10.*(radius*radius*pi)
163  << "\n***********************************\n"
164  << std::endl;
165 #else
166  libmesh_ignore(mesh);
167 #endif
168 }
class FEType hides (possibly multiple) FEFamily and approximation orders, thereby enabling specialize...
Definition: fe_type.h:178
const Real radius
Real distance(const Point &p)
Real integrand(const Point &p)
std::unique_ptr< T > UniquePtr
Definition: auto_ptr.h:46
virtual SimpleRange< element_iterator > active_local_element_ptr_range()=0
void libmesh_ignore(const T &)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const Parallel::Communicator & comm() const
OStreamProxy out
unsigned int mesh_dimension() const
Definition: mesh_base.C:148
void sum(T &r) const
Take a local variable and replace it with the sum of it&#39;s values on all processors.
const Real pi
.
Definition: libmesh.h:172
int main ( int  argc,
char **  argv 
)

Definition at line 63 of file subdomains_ex3.C.

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

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

Variable Documentation

const Real radius = 0.5