PolyFEM
Loading...
Searching...
No Matches
polyfem::OptState Class Reference

Main class containing the PolyFEM adjoint solver and its optimization data. More...

#include <OptState.hpp>

Collaboration diagram for polyfem::OptState:
[legend]

Public Member Functions

 ~OptState ()
 
 OptState ()
 Constructor.
 
void init (const json &args, const bool strict_validation)
 initialize the polyfem solver with a json settings
 
void init (const json &args, const io::ResourceIO &resources, bool strict_validation)
 
int run (json args, const bool strict_validation)
 Run optimization, including remeshing restarts when the selected trigger requests them.
 
int run (json args, const io::ResourceIO &resources, bool strict_validation)
 
void init_logger (const std::string &log_file, const spdlog::level::level_enum log_level, const spdlog::level::level_enum file_log_level, const bool is_quiet)
 initializing the logger
 
void init_logger (std::ostream &os, const spdlog::level::level_enum log_level)
 initializing the logger writes to an output stream
 
void set_log_level (const spdlog::level::level_enum log_level)
 change log level
 
void create_varforms (const int max_threads=-1)
 Create the optimization variational formulations.
 
void init_variables ()
 init variables
 
void create_problem ()
 
void initial_guess (Eigen::VectorXd &x)
 
double eval (Eigen::VectorXd &x) const
 
polysolve::nonlinear::Status solve (Eigen::VectorXd &x)
 

Public Attributes

json args
 main input arguments containing all defaults
 
std::vector< std::shared_ptr< varform::DifferentiableVarForm > > varforms
 Variational formulations used by the optimization.
 
std::vector< json > state_args
 
std::vector< std::unique_ptr< const io::ResourceIO > > state_resources
 
std::vector< std::shared_ptr< DiffCache > > diff_caches
 
std::vector< int > variable_sizes
 variables
 
int ndof
 
solver::VariableToSimulationGroup variable_to_simulations
 
std::unique_ptr< solver::AdjointNLProblem > nl_problem
 
std::string output_dir
 Directory for output files.
 

Private Member Functions

void check_unsupported () const
 Check and throw if any forward simulation varform::DifferentiableVarForm is not supported.
 
void init_logger (const std::vector< spdlog::sink_ptr > &sinks, const spdlog::level::level_enum log_level)
 initializing the logger meant for internal usage
 

Private Attributes

spdlog::sink_ptr console_sink_ = nullptr
 logger sink to stdout
 
spdlog::sink_ptr file_sink_ = nullptr
 
bool remeshing_requested_ = false
 
bool strict_validation_ = true
 
std::unique_ptr< const io::ResourceIO > resources_
 

Detailed Description

Main class containing the PolyFEM adjoint solver and its optimization data.

Definition at line 29 of file OptState.hpp.

Constructor & Destructor Documentation

◆ ~OptState()

polyfem::OptState::~OptState ( )

Definition at line 268 of file OptState.cpp.

◆ OptState()

polyfem::OptState::OptState ( )

Constructor.

Definition at line 272 of file OptState.cpp.

References polyfem::utils::GeogramUtils::initialize(), and polyfem::utils::GeogramUtils::instance().

Here is the call graph for this function:

Member Function Documentation

◆ check_unsupported()

void polyfem::OptState::check_unsupported ( ) const
private

Check and throw if any forward simulation varform::DifferentiableVarForm is not supported.

Definition at line 512 of file OptState.cpp.

References polyfem::varform::FESpace::geometry_basis_list(), polyfem::varform::DifferentiableVarForm::get_args(), polyfem::varform::DifferentiableVarForm::get_problem(), polyfem::varform::DifferentiableVarForm::is_contact_enabled(), polyfem::varform::DifferentiableVarForm::is_problem_linear(), polyfem::assembler::Problem::is_time_dependent(), polyfem::log_and_throw_adjoint_error(), polyfem::varform::DifferentiableVarForm::name(), polyfem::varform::DifferentiableVarForm::primary_space(), polyfem::varform::DifferentiableVarForm::solve_data(), and varforms.

Referenced by create_varforms().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ create_problem()

void polyfem::OptState::create_problem ( )

Definition at line 640 of file OptState.cpp.

References polyfem::adjoint_logger(), args, polyfem::from_json::build_form(), diff_caches, nl_problem, remeshing_requested_, state_resources, varforms, and variable_to_simulations.

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ create_varforms()

void polyfem::OptState::create_varforms ( const int  max_threads = -1)

Create the optimization variational formulations.

Definition at line 484 of file OptState.cpp.

References polyfem::adjoint_logger(), args, polyfem::from_json::build_differentiable_varform(), check_unsupported(), diff_caches, polyfem::utils::GeogramUtils::instance(), resources_, polyfem::utils::GeogramUtils::set_logger(), state_args, state_resources, and varforms.

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ eval()

double polyfem::OptState::eval ( Eigen::VectorXd &  x) const

Definition at line 700 of file OptState.cpp.

References nl_problem, and x.

Referenced by run().

Here is the caller graph for this function:

◆ init() [1/2]

void polyfem::OptState::init ( const json &  args,
const bool  strict_validation 
)

initialize the polyfem solver with a json settings

Parameters
[in]argsinput arguments
[in]strict_validationstrict validation of input

Definition at line 432 of file OptState.cpp.

References init(), polyfem::utils::is_param_valid(), and resources_.

Referenced by init(), and run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ init() [2/2]

void polyfem::OptState::init ( const json &  args,
const io::ResourceIO &  resources,
bool  strict_validation 
)

Definition at line 441 of file OptState.cpp.

References polyfem::adjoint_logger(), polyfem::solver::AdjointOptUtils::apply_opt_json_spec(), args, polyfem::utils::NThread::get(), init_logger(), output_dir, resources_, polyfem::utils::NThread::set_num_threads(), strict_validation_, and polyfem::io::ResourceIO::with_root().

Here is the call graph for this function:

◆ init_logger() [1/3]

void polyfem::OptState::init_logger ( const std::string &  log_file,
const spdlog::level::level_enum  log_level,
const spdlog::level::level_enum  file_log_level,
const bool  is_quiet 
)

initializing the logger

Parameters
[in]log_fileis to write it to a file (use log_file="") to output to stdout
[in]log_level0 all message, 6 no message. 2 is info, 1 is debug
[in]file_log_level0 all message, 6 no message. 2 is info, 1 is debug
[in]is_quitquiets the log

Definition at line 381 of file OptState.cpp.

References console_sink_, file_sink_, and init_logger().

Referenced by init(), init_logger(), and init_logger().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ init_logger() [2/3]

void polyfem::OptState::init_logger ( const std::vector< spdlog::sink_ptr > &  sinks,
const spdlog::level::level_enum  log_level 
)
private

initializing the logger meant for internal usage

Definition at line 414 of file OptState.cpp.

References polyfem::adjoint_logger(), polyfem::set_adjoint_logger(), and set_log_level().

Here is the call graph for this function:

◆ init_logger() [3/3]

void polyfem::OptState::init_logger ( std::ostream &  os,
const spdlog::level::level_enum  log_level 
)

initializing the logger writes to an output stream

Parameters
[in]osoutput stream
[in]log_level0 all message, 6 no message. 2 is info, 1 is debug

Definition at line 407 of file OptState.cpp.

References init_logger().

Here is the call graph for this function:

◆ init_variables()

void polyfem::OptState::init_variables ( )

init variables

Definition at line 575 of file OptState.cpp.

References args, polyfem::from_json::build_variable_to_simulation_group(), polyfem::solver::AdjointOptUtils::compute_variable_size(), polyfem::solver::VariableToSimulationGroup::data, diff_caches, polyfem::utils::json_as_array(), polyfem::log_and_throw_adjoint_error(), ndof, state_resources, varforms, variable_sizes, and variable_to_simulations.

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ initial_guess()

void polyfem::OptState::initial_guess ( Eigen::VectorXd &  x)

Definition at line 693 of file OptState.cpp.

References args, polyfem::solver::AdjointOptUtils::inverse_evaluation(), ndof, polyfem::solver::VariableToSimulationGroup::update(), variable_sizes, variable_to_simulations, and x.

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ run() [1/2]

int polyfem::OptState::run ( json  args,
const bool  strict_validation 
)

Run optimization, including remeshing restarts when the selected trigger requests them.

Definition at line 277 of file OptState.cpp.

References polyfem::utils::is_param_valid(), resources_, and run().

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ run() [2/2]

int polyfem::OptState::run ( json  args,
const io::ResourceIO &  resources,
bool  strict_validation 
)

Definition at line 286 of file OptState.cpp.

References polyfem::solver::AdjointOptUtils::apply_opt_json_spec(), args, create_problem(), create_varforms(), eval(), init(), init_variables(), initial_guess(), polyfem::logger(), remeshing_requested_, resources_, solve(), state_args, state_resources, polyfem::io::ResourceIO::with_root(), and x.

Here is the call graph for this function:

◆ set_log_level()

void polyfem::OptState::set_log_level ( const spdlog::level::level_enum  log_level)

change log level

Parameters
[in]log_level0 all message, 6 no message. 2 is info, 1 is debug

Definition at line 425 of file OptState.cpp.

References polyfem::adjoint_logger(), and console_sink_.

Referenced by init_logger().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ solve()

polysolve::nonlinear::Status polyfem::OptState::solve ( Eigen::VectorXd &  x)

Definition at line 706 of file OptState.cpp.

References args, polyfem::solver::AdjointOptUtils::make_nl_solver(), nl_problem, strict_validation_, and x.

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ args

json polyfem::OptState::args

main input arguments containing all defaults

Definition at line 51 of file OptState.hpp.

Referenced by create_problem(), create_varforms(), init(), init_variables(), initial_guess(), run(), and solve().

◆ console_sink_

spdlog::sink_ptr polyfem::OptState::console_sink_ = nullptr
private

logger sink to stdout

Definition at line 113 of file OptState.hpp.

Referenced by init_logger(), and set_log_level().

◆ diff_caches

std::vector<std::shared_ptr<DiffCache> > polyfem::OptState::diff_caches

Definition at line 95 of file OptState.hpp.

Referenced by create_problem(), create_varforms(), and init_variables().

◆ file_sink_

spdlog::sink_ptr polyfem::OptState::file_sink_ = nullptr
private

Definition at line 114 of file OptState.hpp.

Referenced by init_logger().

◆ ndof

int polyfem::OptState::ndof

Definition at line 99 of file OptState.hpp.

Referenced by init_variables(), and initial_guess().

◆ nl_problem

std::unique_ptr<solver::AdjointNLProblem> polyfem::OptState::nl_problem

Definition at line 103 of file OptState.hpp.

Referenced by create_problem(), eval(), and solve().

◆ output_dir

std::string polyfem::OptState::output_dir

Directory for output files.

Definition at line 126 of file OptState.hpp.

Referenced by init().

◆ remeshing_requested_

bool polyfem::OptState::remeshing_requested_ = false
private

Definition at line 116 of file OptState.hpp.

Referenced by create_problem(), and run().

◆ resources_

std::unique_ptr<const io::ResourceIO> polyfem::OptState::resources_
private

Definition at line 118 of file OptState.hpp.

Referenced by create_varforms(), init(), init(), run(), and run().

◆ state_args

std::vector<json> polyfem::OptState::state_args

Definition at line 93 of file OptState.hpp.

Referenced by create_varforms(), and run().

◆ state_resources

std::vector<std::unique_ptr<const io::ResourceIO> > polyfem::OptState::state_resources

Definition at line 94 of file OptState.hpp.

Referenced by create_problem(), create_varforms(), init_variables(), and run().

◆ strict_validation_

bool polyfem::OptState::strict_validation_ = true
private

Definition at line 117 of file OptState.hpp.

Referenced by init(), and solve().

◆ varforms

std::vector<std::shared_ptr<varform::DifferentiableVarForm> > polyfem::OptState::varforms

Variational formulations used by the optimization.

Definition at line 92 of file OptState.hpp.

Referenced by check_unsupported(), create_problem(), create_varforms(), and init_variables().

◆ variable_sizes

std::vector<int> polyfem::OptState::variable_sizes

variables

Definition at line 98 of file OptState.hpp.

Referenced by init_variables(), and initial_guess().

◆ variable_to_simulations

solver::VariableToSimulationGroup polyfem::OptState::variable_to_simulations

Definition at line 101 of file OptState.hpp.

Referenced by create_problem(), init_variables(), and initial_guess().


The documentation for this class was generated from the following files: