242{
244
245#ifndef LIBMESH_HAVE_PETSC_TAO
246
247 libmesh_example_requires(false, "PETSc >= 3.5.0 with built-in TAO support");
248
249#elif !defined(LIBMESH_ENABLE_GHOSTED)
250
251 libmesh_example_requires(false, "--enable-ghosted");
252
253#elif LIBMESH_USE_COMPLEX_NUMBERS
254
255
256
257
258 libmesh_example_requires(false, "PETSc >= 3.5.0 with built-in TAO support & real-numbers only");
259
260#endif
261
262
263 libmesh_example_requires(LIBMESH_DIM > 1, "--disable-1D-only");
264
265
266#ifndef LIBMESH_ENABLE_DIRICHLET
267 libmesh_example_requires(false, "--enable-dirichlet");
268#endif
269
271 {
272 libMesh::err <<
"This example requires an OptimizationSolver, and therefore does not "
273 << "support --use-eigen on the command line."
274 << std::endl;
275 return 0;
276 }
277
278 GetPot infile("optimization_ex1.in");
279 infile.parse_command_line(argc, argv);
280
281 const std::string approx_order = infile("approx_order", "FIRST");
282 const std::string fe_family = infile("fe_family", "LAGRANGE");
283 const unsigned int n_elem = infile(
"n_elem", 10);
284
287 n_elem,
288 n_elem,
289 -1., 1.,
290 -1., 1.,
292
294
296
299
300
301
302 {
303 const std::string optimization_solver_type = infile("optimization_solver_type",
304 "PETSC_SOLVERS");
305 SolverPackage sp = Utility::string_to_enum<SolverPackage>(optimization_solver_type);
306 std::unique_ptr<OptimizationSolver<Number>> new_solver =
309 }
310
311
315
317
321
322
323
324
325
328 assemble_opt.A_matrix = &system.
get_matrix(
"A_matrix");
329 assemble_opt.F_vector = &system.
get_vector(
"F_vector");
330
331#ifdef LIBMESH_ENABLE_DIRICHLET
333 Utility::string_to_enum<Order> (approx_order),
334 Utility::string_to_enum<FEFamily>(fe_family));
335
336
337
339
340
341
345#endif
346
347 equation_systems.init();
348 equation_systems.print_info();
349
350 assemble_opt.assemble_A_and_F();
351
352
353
355
356
357
358
360
362
363
365
366#ifdef LIBMESH_HAVE_EXODUS_API
367 std::stringstream filename;
369 equation_systems);
370#endif
371
372 return 0;
373}
This class encapsulate all functionality required for assembling the objective function,...
This class allows one to associate Dirichlet boundary values with a given set of mesh boundary ids an...
void add_dirichlet_boundary(const DirichletBoundary &dirichlet_boundary)
Adds a copy of the specified Dirichlet boundary to the system.
This is the EquationSystems class.
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.
const SparseMatrix< Number > & get_system_matrix() const
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
void print_info(std::ostream &os=libMesh::out, const unsigned int verbosity=0, const bool global=true) const
Prints relevant information about the mesh.
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
static std::unique_ptr< OptimizationSolver< T > > build(sys_type &s, const SolverPackage solver_package=libMesh::default_solver_package())
Builds an OptimizationSolver using the package specified by solver_package.
This System subclass enables us to assemble an objective function, gradient, Hessian and bounds for o...
virtual void solve() override
Solves the optimization problem.
std::unique_ptr< OptimizationSolver< Number > > optimization_solver
The OptimizationSolver that is used for performing the optimization.
virtual void close()=0
Calls the SparseMatrix's internal assembly routines, ensuring that the values are consistent across p...
SparseMatrix< Number > & add_matrix(std::string_view mat_name, ParallelType type=PARALLEL, MatrixBuildType mat_build_type=MatrixBuildType::AUTOMATIC)
Adds the additional matrix mat_name to this system.
const SparseMatrix< Number > & get_matrix(std::string_view mat_name) const
unsigned int add_variable(std::string_view var, const FEType &type, const std::set< subdomain_id_type > *const active_subdomains=nullptr)
Adds the variable var to the list of variables for this system.
NumericVector< Number > & add_vector(std::string_view vec_name, const bool projections=true, const ParallelType type=PARALLEL)
Adds the additional vector vec_name to this system.
const DofMap & get_dof_map() const
const NumericVector< Number > & get_vector(std::string_view vec_name) const
ConstFunction that simply returns 0.
void init(triangulateio &t)
Initializes the fields of t to nullptr/0 as necessary.
SolverPackage
Defines an enum for various linear solver packages.
bool on_command_line(std::string arg)
The FPEDisabler class puts Floating-Point Exception (FPE) trapping on hold during its lifetime,...