397{
399
400#ifndef LIBMESH_HAVE_PETSC_TAO
401
402 libmesh_example_requires(false, "PETSc >= 3.5.0 with built-in TAO support");
403
404#elif LIBMESH_USE_COMPLEX_NUMBERS
405
406
407
408
409 libmesh_example_requires(false, "PETSc >= 3.5.0 with built-in TAO support & real-numbers only");
410
411#endif
412
413
414 libmesh_example_requires(LIBMESH_DIM > 1, "--disable-1D-only");
415
416
417 if (
init.comm().size() != 1)
418 {
419 libMesh::out <<
"This example can currently only be run in serial." << std::endl;
420 return 77;
421 }
422
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);
427
430 n_elem,
431 n_elem,
432 -1., 1.,
433 -1., 1.,
435
437
439
442
443
444
445 {
446 const std::string optimization_solver_type = infile("optimization_solver_type",
447 "PETSC_SOLVERS");
448 SolverPackage sp = Utility::string_to_enum<SolverPackage>(optimization_solver_type);
449 std::unique_ptr<OptimizationSolver<Number>> new_solver =
452 }
453
454
458
460
462 Utility::string_to_enum<Order> (approx_order),
463 Utility::string_to_enum<FEFamily>(fe_family));
464
473
474
475
476
477
480 assemble_opt.A_matrix = &system.
get_matrix(
"A_matrix");
481 assemble_opt.F_vector = &system.
get_vector(
"F_vector");
482
483
484 equation_systems.
init();
485 equation_systems.print_info();
486
487 assemble_opt.assemble_A_and_F();
488
489 {
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();
495
496 sparsity_row.insert(23);
497 constraint_jac_sparsity.push_back(sparsity_row);
498 sparsity_row.clear();
499
500 sparsity_row.insert(98);
501 sparsity_row.insert(185);
502 constraint_jac_sparsity.push_back(sparsity_row);
503
505 }
506
507 {
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);
513
515 }
516
517
518
521
522
524
525
527 {
528 std::stringstream filename;
530 equation_systems);
531 }
532
533 return 0;
534}
This class encapsulate all functionality required for assembling the objective function,...
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.
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.
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...
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.
virtual void solve() override
Solves the optimization problem.
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.
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 NumericVector< Number > & get_vector(std::string_view vec_name) const
void init(triangulateio &t)
Initializes the fields of t to nullptr/0 as necessary.
SolverPackage
Defines an enum for various linear solver packages.