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 239 of file optimization_ex1.C.
243 #ifndef LIBMESH_HAVE_PETSC_TAO
245 libmesh_example_requires(
false,
"PETSc >= 3.5.0 with built-in TAO support");
247 #elif !defined(LIBMESH_ENABLE_GHOSTED)
249 libmesh_example_requires(
false,
"--enable-ghosted");
251 #elif LIBMESH_USE_COMPLEX_NUMBERS
256 libmesh_example_requires(
false,
"PETSc >= 3.5.0 with built-in TAO support & real-numbers only");
261 libmesh_example_requires(LIBMESH_DIM > 1,
"--disable-1D-only");
264 #ifndef LIBMESH_ENABLE_DIRICHLET
265 libmesh_example_requires(
false,
"--enable-dirichlet");
270 libMesh::err <<
"This example requires an OptimizationSolver, and therefore does not "
271 <<
"support --use-eigen on the command line."
276 GetPot infile(
"optimization_ex1.in");
277 const std::string approx_order = infile(
"approx_order",
"FIRST");
278 const std::string fe_family = infile(
"fe_family",
"LAGRANGE");
279 const unsigned int n_elem = infile(
"n_elem", 10);
299 const std::string optimization_solver_type = infile(
"optimization_solver_type",
301 SolverPackage sp = Utility::string_to_enum<SolverPackage>(optimization_solver_type);
302 std::unique_ptr<OptimizationSolver<Number>> new_solver =
324 assemble_opt.A_matrix = &system.
get_matrix(
"A_matrix");
325 assemble_opt.F_vector = &system.
get_vector(
"F_vector");
327 #ifdef LIBMESH_ENABLE_DIRICHLET
329 Utility::string_to_enum<Order> (approx_order),
330 Utility::string_to_enum<FEFamily>(fe_family));
334 std::set<boundary_id_type> boundary_ids;
335 boundary_ids.insert(0);
336 boundary_ids.insert(1);
337 boundary_ids.insert(2);
338 boundary_ids.insert(3);
339 std::vector<unsigned int> variables;
340 variables.push_back(u_var);
348 #endif // LIBMESH_ENABLE_DIRICHLET
350 equation_systems.init();
351 equation_systems.print_info();
353 assemble_opt.assemble_A_and_F();
363 #ifdef LIBMESH_HAVE_EXODUS_API
364 std::stringstream filename;
References AssembleOptimization::A_matrix, libMesh::DofMap::add_dirichlet_boundary(), 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(), libMesh::err, AssembleOptimization::F_vector, libMesh::System::get_dof_map(), libMesh::ImplicitSystem::get_matrix(), libMesh::System::get_vector(), libMesh::TriangleWrapper::init(), libMesh::EquationSystems::init(), libMesh::LOCAL_VARIABLE_ORDER, libMesh::ImplicitSystem::matrix, mesh, libMesh::MeshTools::n_elem(), libMesh::on_command_line(), libMesh::OptimizationSystem::optimization_solver, 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.
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
void add_dirichlet_boundary(const DirichletBoundary &dirichlet_boundary)
Adds a copy of the specified Dirichlet boundary to the system.
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.
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.
ConstFunction that simply returns 0.
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 print_info(std::ostream &os=libMesh::out) const
Prints relevant information about the mesh.
This class allows one to associate Dirichlet boundary values with a given set of mesh boundary ids an...
bool on_command_line(std::string arg)
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 DofMap & get_dof_map() const
const SparseMatrix< Number > & get_matrix(const std::string &mat_name) const
const NumericVector< Number > & get_vector(const std::string &vec_name) const