245 #ifndef LIBMESH_HAVE_PETSC_TAO 247 libmesh_example_requires(
false,
"PETSc >= 3.5.0 with built-in TAO support");
249 #elif !defined(LIBMESH_ENABLE_GHOSTED) 251 libmesh_example_requires(
false,
"--enable-ghosted");
253 #elif LIBMESH_USE_COMPLEX_NUMBERS 258 libmesh_example_requires(
false,
"PETSc >= 3.5.0 with built-in TAO support & real-numbers only");
263 libmesh_example_requires(LIBMESH_DIM > 1,
"--disable-1D-only");
266 #ifndef LIBMESH_ENABLE_DIRICHLET 267 libmesh_example_requires(
false,
"--enable-dirichlet");
272 libMesh::err <<
"This example requires an OptimizationSolver, and therefore does not " 273 <<
"support --use-eigen on the command line." 278 GetPot infile(
"optimization_ex1.in");
279 infile.parse_command_line(argc, argv);
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);
303 const std::string optimization_solver_type = infile(
"optimization_solver_type",
305 SolverPackage sp = Utility::string_to_enum<SolverPackage>(optimization_solver_type);
306 std::unique_ptr<OptimizationSolver<Number>> new_solver =
328 assemble_opt.A_matrix = &system.
get_matrix(
"A_matrix");
329 assemble_opt.F_vector = &system.
get_vector(
"F_vector");
331 #ifdef LIBMESH_ENABLE_DIRICHLET 333 Utility::string_to_enum<Order> (approx_order),
334 Utility::string_to_enum<FEFamily>(fe_family));
345 #endif // LIBMESH_ENABLE_DIRICHLET 347 equation_systems.init();
348 equation_systems.print_info();
350 assemble_opt.assemble_A_and_F();
366 #ifdef LIBMESH_HAVE_EXODUS_API 367 std::stringstream filename;
The FPEDisabler class puts Floating-Point Exception (FPE) trapping on hold during its lifetime...
This is the EquationSystems class.
ConstFunction that simply returns 0.
The ExodusII_IO class implements reading meshes in the ExodusII file format from Sandia National Labs...
virtual void solve() override
Solves the optimization problem.
This class allows one to associate Dirichlet boundary values with a given set of mesh boundary ids an...
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.
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
This class encapsulate all functionality required for assembling the objective function, gradient, and hessian.
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.
This System subclass enables us to assemble an objective function, gradient, Hessian and bounds for o...
void print_info(std::ostream &os=libMesh::out, const unsigned int verbosity=0, const bool global=true) const
Prints relevant information about the mesh.
void init(triangulateio &t)
Initializes the fields of t to nullptr/0 as necessary.
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.
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...
This base class can be inherited from to provide interfaces to optimization solvers from different pa...
void add_dirichlet_boundary(const DirichletBoundary &dirichlet_boundary)
Adds a copy of the specified Dirichlet boundary to the system.
bool on_command_line(std::string arg)
SolverPackage
Defines an enum for various linear solver packages.
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
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 DofMap & get_dof_map() const
const SparseMatrix< Number > & get_matrix(std::string_view mat_name) const
const SparseMatrix< Number > & get_system_matrix() const
const NumericVector< Number > & get_vector(std::string_view vec_name) const