400 #ifndef LIBMESH_HAVE_PETSC_TAO 402 libmesh_example_requires(
false,
"PETSc >= 3.5.0 with built-in TAO support");
404 #elif LIBMESH_USE_COMPLEX_NUMBERS 409 libmesh_example_requires(
false,
"PETSc >= 3.5.0 with built-in TAO support & real-numbers only");
414 libmesh_example_requires(LIBMESH_DIM > 1,
"--disable-1D-only");
417 if (
init.comm().size() != 1)
419 libMesh::out <<
"This example can currently only be run in serial." << std::endl;
423 GetPot infile(
"optimization_ex2.in");
424 const std::string approx_order = infile(
"approx_order",
"FIRST");
425 const std::string fe_family = infile(
"fe_family",
"LAGRANGE");
426 const unsigned int n_elem = infile(
"n_elem", 10);
446 const std::string optimization_solver_type = infile(
"optimization_solver_type",
448 SolverPackage sp = Utility::string_to_enum<SolverPackage>(optimization_solver_type);
449 std::unique_ptr<OptimizationSolver<Number>> new_solver =
462 Utility::string_to_enum<Order> (approx_order),
463 Utility::string_to_enum<FEFamily>(fe_family));
480 assemble_opt.A_matrix = &system.
get_matrix(
"A_matrix");
481 assemble_opt.F_vector = &system.
get_vector(
"F_vector");
484 equation_systems.
init();
485 equation_systems.print_info();
487 assemble_opt.assemble_A_and_F();
490 std::vector<std::set<numeric_index_type>> constraint_jac_sparsity;
491 std::set<numeric_index_type> sparsity_row;
492 sparsity_row.insert(17);
493 constraint_jac_sparsity.push_back(sparsity_row);
494 sparsity_row.clear();
496 sparsity_row.insert(23);
497 constraint_jac_sparsity.push_back(sparsity_row);
498 sparsity_row.clear();
500 sparsity_row.insert(98);
501 sparsity_row.insert(185);
502 constraint_jac_sparsity.push_back(sparsity_row);
508 std::vector<std::set<numeric_index_type>> constraint_jac_sparsity;
509 std::set<numeric_index_type> sparsity_row;
510 sparsity_row.insert(200);
511 sparsity_row.insert(201);
512 constraint_jac_sparsity.push_back(sparsity_row);
528 std::stringstream filename;
This is the EquationSystems class.
void initialize_inequality_constraints_storage(const std::vector< std::set< numeric_index_type >> &constraint_jac_sparsity)
Initialize storage for the inequality constraints, as per initialize_equality_constraints_storage.
The ExodusII_IO class implements reading meshes in the ExodusII file format from Sandia National Labs...
virtual void solve() override
Solves the optimization problem.
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.
virtual void init(const numeric_index_type n, const numeric_index_type n_local, const bool fast=false, const ParallelType ptype=AUTOMATIC)=0
Change the dimension of the vector to n.
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...
void initialize_equality_constraints_storage(const std::vector< std::set< numeric_index_type >> &constraint_jac_sparsity)
Initialize storage for the equality constraints, and the corresponding Jacobian.
This base class can be inherited from to provide interfaces to optimization solvers from different pa...
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 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