61{
62
64
65
67 "--enable-petsc, --enable-trilinos, or --enable-eigen");
68
69#ifndef LIBMESH_ENABLE_AMR
70 libmesh_example_requires(false, "--enable-amr");
71#else
72
73
74#ifndef LIBMESH_ENABLE_DIRICHLET
75 libmesh_example_requires(false, "--enable-dirichlet");
76#endif
77
78
79 libmesh_example_requires(
sizeof(
Real) > 4,
"--disable-singleprecision");
80
81
82 GetPot infile("fem_system_ex4.in");
83
84
85 infile.parse_command_line(argc, argv);
86
87
88 const Real global_tolerance = infile(
"global_tolerance", 0.);
89 const unsigned int nelem_target = infile("n_elements", 400);
90 const Real deltat = infile(
"deltat", 0.005);
91 const unsigned int coarsegridsize = infile("coarsegridsize", 20);
92 const unsigned int coarserefinements = infile("coarserefinements", 0);
93 const unsigned int max_adaptivesteps = infile("max_adaptivesteps", 10);
94 const unsigned int dim = infile(
"dimension", 2);
95
96
97 libmesh_example_requires(
dim <= LIBMESH_DIM,
"2D/3D support");
98
99
101
102
103
105
106
108 mesh_refinement.coarsen_by_parents() = true;
109 mesh_refinement.absolute_global_tolerance() = global_tolerance;
110 mesh_refinement.nelem_target() = nelem_target;
111 mesh_refinement.refine_fraction() = 0.3;
112 mesh_refinement.coarsen_fraction() = 0.3;
113 mesh_refinement.coarsen_threshold() = 0.1;
114
115
116
117
120 {
123 coarsegridsize,
124 coarsegridsize*2/3,
125 0., 1.,
126 0., 2./3.,
128 bcid = 2;
129 }
131 {
134 coarsegridsize,
135 coarsegridsize*2/3,
136 coarsegridsize,
137 0., 1.,
138 0., 2./3.,
139 0., 1.,
141 }
142
143 {
144
145
146 std::set<boundary_id_type> bcids;
147 bcids.insert(bcid);
150 }
151
152
153
154
155
156 for (
auto & elem :
mesh.element_ptr_range())
158 elem->subdomain_id() = 1;
159
160
162
163 mesh_refinement.uniformly_refine(coarserefinements);
164
165
167
168
170
171
173 equation_systems.add_system<
HeatSystem> (
"Heat");
174
175
176 system.
time_solver = std::make_unique<SteadySolver>(system);
177
178
179 equation_systems.init ();
180
181
183
184
186 solver.
quiet = infile(
"solver_quiet",
true);
192
193
196
197
198 equation_systems.print_info();
199
200
201 unsigned int a_step = 0;
202 for (; a_step != max_adaptivesteps; ++a_step)
203 {
205
207
209
210 std::unique_ptr<ErrorEstimator> error_estimator;
211
212
213
214 if (global_tolerance != 0.)
215 {
216
217
218 libmesh_assert_equal_to (nelem_target, 0);
219
220 auto u = std::make_unique<UniformRefinementEstimator>();
221
222
223
225 error_estimator = std::move(u);
226 }
227 else
228 {
229
230
231 libmesh_assert_greater (nelem_target, 0);
232
233
234
235
236
237 error_estimator = std::make_unique<KellyErrorEstimator>();
238 }
239
240 error_estimator->estimate_error(system, error);
241
242
245 << a_step
246 << ": "
247 << std::endl;
248
249 if (global_tolerance != 0.)
251 << global_error
252 << std::endl;
253
254 if (global_tolerance != 0.)
257 << ", mean = "
259 << std::endl;
260
261 if (global_tolerance != 0.)
262 {
263
264
265 if (global_error < global_tolerance)
266 break;
267 mesh_refinement.flag_elements_by_error_tolerance(error);
268 }
269 else
270 {
271
272
273 if (mesh_refinement.flag_elements_by_nelem_target(error))
274 {
275 mesh_refinement.refine_and_coarsen_elements();
276 equation_systems.reinit();
277 a_step = max_adaptivesteps;
278 break;
279 }
280 }
281
282
283 mesh_refinement.refine_and_coarsen_elements();
284 equation_systems.reinit();
285
288 << " active elements and "
289 << equation_systems.n_active_dofs()
290 << " active dofs."
291 << std::endl;
292 }
293
294 if (a_step == max_adaptivesteps)
295 {
297
299 }
300
301
302#ifdef LIBMESH_HAVE_EXODUS_API
304 ("out.e", equation_systems);
305#endif
306
307#ifdef LIBMESH_HAVE_GMV
309 ("out.gmv", equation_systems);
310#endif
311
312#ifdef LIBMESH_HAVE_FPARSER
313
315 const std::string exact_str = (
dim == 2) ?
316 "sin(pi*x)*sin(pi*y)" : "sin(pi*x)*sin(pi*y)*sin(pi*z)";
318 exact_sol.attach_exact_value(0, &exact_func);
319 exact_sol.compute_error("Heat", "T");
320
321 Real err = exact_sol.l2_error(
"Heat",
"T");
322
323
325
326 libmesh_assert_less(
err, 2e-3);
327
328#endif
329
330#endif
331
332
333 return 0;
334}
void add_elements(const std::set< boundary_id_type > &requested_boundary_ids, UnstructuredMesh &boundary_mesh, bool store_parent_side_ids=false, const std::vector< subdomain_id_type > &new_subdomain_ids={})
Generates elements along the boundary of our _mesh, which use pre-existing nodes on the boundary_mesh...
This is a generic class that defines a solver to handle ImplicitSystem classes, including NonlinearIm...
Real absolute_residual_tolerance
The DiffSolver should exit after the residual is reduced to either less than absolute_residual_tolera...
unsigned int max_linear_iterations
Each linear solver step should exit after max_linear_iterations is exceeded.
double initial_linear_tolerance
Any required linear solves will at first be done with this tolerance; the DiffSolver may tighten the ...
Real relative_residual_tolerance
Real relative_step_tolerance
bool verbose
The DiffSolver may print a lot more to libMesh::out if verbose is set to true; default is false.
unsigned int max_nonlinear_iterations
The DiffSolver should exit in failure if max_nonlinear_iterations is exceeded and continue_after_max_...
bool quiet
The DiffSolver should not print anything to libMesh::out unless quiet is set to false; default is tru...
Real deltat
For time-dependent problems, this is the amount delta t to advance the solution in time.
std::unique_ptr< TimeSolver > time_solver
A pointer to the solver object we're going to use.
This is the EquationSystems class.
The ErrorVector is a specialization of the StatisticsVector for error data computed on a finite eleme...
virtual Real mean() const override
This class handles the computation of the L2 and/or H1 error for the Systems in the EquationSystems o...
The ExodusII_IO class implements reading meshes in the ExodusII file format from Sandia National Labs...
virtual void write_equation_systems(const std::string &fname, const EquationSystems &es, const std::set< std::string > *system_names=nullptr) override
Writes out the solution for no specific time or timestep.
virtual void solve() override
Invokes the solver associated with the system.
virtual void postprocess() override
Runs a postprocessing loop over all elements, and if postprocess_sides is true over all sides.
This class implements writing meshes in the GMV format.
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
const BoundaryInfo & get_boundary_info() const
The information about boundary ids on the mesh.
void prepare_for_use(const bool skip_renumber_nodes_and_elements, const bool skip_find_neighbors)
Prepare a newly created (or read) mesh for use.
void print_info(std::ostream &os=libMesh::out, const unsigned int verbosity=0, const bool global=true) const
Prints relevant information about the mesh.
virtual dof_id_type n_active_elem() const =0
virtual void write_equation_systems(const std::string &, const EquationSystems &, const std::set< std::string > *system_names=nullptr)
This method implements writing a mesh with data to a specified file where the data is taken from the ...
Implements (adaptive) mesh refinement algorithms for a MeshBase.
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
A Function generated (via FParser) by parsing a mathematical expression.
virtual T maximum() const
virtual Real l2_norm() const
void init(triangulateio &t)
Initializes the fields of t to nullptr/0 as necessary.
SolverPackage default_solver_package()
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real