libMesh
Loading...
Searching...
No Matches
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)

◆ integrand()

Real integrand ( const Point p)

Definition at line 57 of file subdomains_ex3.C.

58{
59 return (distance(p) < 0) ? 10. : 1.;
60}
Real distance(const Point &p)

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}
static std::unique_ptr< FEGenericBase > build(const unsigned int dim, const FEType &type)
Builds a specific finite element type.
class FEType hides (possibly multiple) FEFamily and approximation orders, thereby enabling specialize...
Definition fe_type.h:197
unsigned int mesh_dimension() const
Definition mesh_base.C:430
const Parallel::Communicator & comm() const
This class implements generic composite quadrature rules.
MeshBase & mesh
void libmesh_ignore(const Args &...)
OStreamProxy out
const Real pi
.
Definition libmesh.h:292
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Real integrand(const Point &p)

References 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, libMesh::Real, and libMesh::Parallel::Communicator::sum().

Referenced by main().

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 65 of file subdomains_ex3.C.

66{
67 // Initialize libMesh and any dependent libraries, like in example 2.
68 LibMeshInit init (argc, argv);
69
70 // This example requires Adaptive Mesh Refinement support - although
71 // it only refines uniformly, the refinement code used is the same
72 // underneath. It also requires libmesh support for Triangle and
73 // Tetgen, which means that libmesh must be configured with
74 // --disable-strict-lgpl for this example to run.
75#if !defined(LIBMESH_HAVE_TRIANGLE) || !defined(LIBMESH_HAVE_TETGEN) || !defined(LIBMESH_ENABLE_AMR)
76 libmesh_example_requires(false, "--disable-strict-lgpl --enable-amr");
77#else
78
79 // Skip this 2D example if libMesh was compiled as 1D-only.
80 libmesh_example_requires(2 <= LIBMESH_DIM, "2D support");
81
82 // Read the mesh from file. This is the coarse mesh that will be used
83 // in example 10 to demonstrate adaptive mesh refinement. Here we will
84 // simply read it in and uniformly refine it 5 times before we compute
85 // with it.
86 Mesh mesh(init.comm());
87
88 {
89 const unsigned int dim =
91
92 if (dim == 3)
93 std::cout << "Running in 3D" << std::endl;
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, by default 4 times.
103 const int n_refinements =
104 libMesh::command_line_next("-n_refinements", 4);
105
106 mesh_refinement.uniformly_refine (n_refinements);
107
108 // Print information about the mesh to the screen.
110
111 // integrate the desired function
113
114 // All done.
115 return 0;
116#endif
117}
unsigned int dim
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
Definition libmesh.h:92
virtual void read(const std::string &name, void *mesh_data=nullptr, bool skip_renumber_nodes_and_elements=false, bool skip_find_neighbors=false, bool skip_detect_interior_parents=false)=0
Interfaces for reading/writing a mesh to/from a file.
void print_info(std::ostream &os=libMesh::out, const unsigned int verbosity=0, const bool global=true) const
Prints relevant information about the mesh.
Definition mesh_base.C:1755
Implements (adaptive) mesh refinement algorithms for a MeshBase.
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition mesh.h:51
void init(triangulateio &t)
Initializes the fields of t to nullptr/0 as necessary.
T command_line_next(std::string name, T default_value)
Use GetPot's search()/next() functions to get following arguments from the command line.
Definition libmesh.C:1025
void integrate_function(const MeshBase &mesh)

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

Variable Documentation

◆ radius

const Real radius = 0.5