Go to the source code of this file.
|
class | AssembleOptimization |
| This class encapsulate all functionality required for assembling the objective function, gradient, and hessian. More...
|
|
◆ main()
int main |
( |
int |
argc, |
|
|
char ** |
argv |
|
) |
| |
Definition at line 396 of file optimization_ex2.C.
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;
References AssembleOptimization::A_matrix, libMesh::ImplicitSystem::add_matrix(), libMesh::EquationSystems::add_system(), libMesh::System::add_variable(), libMesh::System::add_vector(), AssembleOptimization::assemble_A_and_F(), libMesh::MeshTools::Generation::build_square(), libMesh::SparseMatrix< T >::close(), AssembleOptimization::F_vector, libMesh::ImplicitSystem::get_matrix(), libMesh::System::get_vector(), libMesh::TriangleWrapper::init(), libMesh::EquationSystems::init(), libMesh::OptimizationSystem::initialize_equality_constraints_storage(), libMesh::OptimizationSystem::initialize_inequality_constraints_storage(), libMesh::ImplicitSystem::matrix, mesh, libMesh::MeshTools::n_elem(), libMesh::OptimizationSystem::optimization_solver, libMesh::out, libMesh::EquationSystems::print_info(), libMesh::MeshBase::print_info(), libMesh::QUAD9, libMesh::OptimizationSystem::solve(), and libMesh::MeshOutput< MT >::write_equation_systems().
This System subclass enables us to assemble an objective function, gradient, Hessian and bounds for o...
virtual void close()=0
Calls the SparseMatrix's internal assembly routines, ensuring that the values are consistent across p...
SolverPackage
Defines an enum for various linear solver packages.
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 Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
virtual void solve() override
Solves the optimization problem.
SparseMatrix< Number > & add_matrix(const std::string &mat_name)
Adds the additional matrix mat_name to this system.
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,...
The ExodusII_IO class implements reading meshes in the ExodusII file format from Sandia National Labs...
void init(triangulateio &t)
Initializes the fields of t to nullptr/0 as necessary.
This base class can be inherited from to provide interfaces to optimization solvers from different pa...
std::unique_ptr< OptimizationSolver< Number > > optimization_solver
The OptimizationSolver that is used for performing the optimization.
unsigned int add_variable(const std::string &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.
SparseMatrix< Number > * matrix
The system matrix.
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
This is the EquationSystems class.
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 ...
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.
void print_info(std::ostream &os=libMesh::out) const
Prints relevant information about the mesh.
NumericVector< Number > & add_vector(const std::string &vec_name, const bool projections=true, const ParallelType type=PARALLEL)
Adds the additional vector vec_name to this system.
const SparseMatrix< Number > & get_matrix(const std::string &mat_name) const
const NumericVector< Number > & get_vector(const std::string &vec_name) const