PolyFEM
Loading...
Searching...
No Matches
OptState.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <polyfem/Common.hpp>
4
7
12
13#include <Eigen/Core>
14
15#include <polysolve/nonlinear/Criteria.hpp>
16
17#include <string>
18#include <vector>
19#include <memory>
20
21namespace polyfem
22{
23 namespace solver
24 {
25 class AdjointNLProblem;
26 } // namespace solver
27
30 {
31 public:
32 //---------------------------------------------------
33 //-----------------initialization--------------------
34 //---------------------------------------------------
35
36 ~OptState();
38 OptState();
39
43 void init(const json &args, const bool strict_validation);
44 void init(const json &args, const io::ResourceIO &resources, bool strict_validation);
45
47 int run(json args, const bool strict_validation);
48 int run(json args, const io::ResourceIO &resources, bool strict_validation);
49
52
58 void init_logger(
59 const std::string &log_file,
60 const spdlog::level::level_enum log_level,
61 const spdlog::level::level_enum file_log_level,
62 const bool is_quiet);
63
67 void init_logger(std::ostream &os, const spdlog::level::level_enum log_level);
68
71 void set_log_level(const spdlog::level::level_enum log_level);
72
74 void create_varforms(const int max_threads = -1);
75
77 void init_variables();
78
79 void create_problem();
80
81 void initial_guess(Eigen::VectorXd &x); // shoud be const
82
83 double eval(Eigen::VectorXd &x) const;
84
85 polysolve::nonlinear::Status solve(Eigen::VectorXd &x);
86
87 //---------------------------------------------------
88 //-----------------varforms--------------------
89 //---------------------------------------------------
90
92 std::vector<std::shared_ptr<varform::DifferentiableVarForm>> varforms;
93 std::vector<json> state_args;
94 std::vector<std::unique_ptr<const io::ResourceIO>> state_resources;
95 std::vector<std::shared_ptr<DiffCache>> diff_caches;
96
98 std::vector<int> variable_sizes;
99 int ndof;
100
102
103 std::unique_ptr<solver::AdjointNLProblem> nl_problem;
104
105 private:
107 void check_unsupported() const;
108
110 void init_logger(const std::vector<spdlog::sink_ptr> &sinks, const spdlog::level::level_enum log_level);
111
113 spdlog::sink_ptr console_sink_ = nullptr;
114 spdlog::sink_ptr file_sink_ = nullptr;
115
118 std::unique_ptr<const io::ResourceIO> resources_;
119
120 //---------------------------------------------------
121 //-----------------output--------------------
122 //---------------------------------------------------
123
124 public:
126 std::string output_dir;
127 };
128} // namespace polyfem
int x
Main class containing the PolyFEM adjoint solver and its optimization data.
Definition OptState.hpp:30
void initial_guess(Eigen::VectorXd &x)
Definition OptState.cpp:693
void set_log_level(const spdlog::level::level_enum log_level)
change log level
Definition OptState.cpp:425
json args
main input arguments containing all defaults
Definition OptState.hpp:51
std::vector< std::shared_ptr< varform::DifferentiableVarForm > > varforms
Variational formulations used by the optimization.
Definition OptState.hpp:92
void init(const json &args, const bool strict_validation)
initialize the polyfem solver with a json settings
Definition OptState.cpp:432
int run(json args, const bool strict_validation)
Run optimization, including remeshing restarts when the selected trigger requests them.
Definition OptState.cpp:277
std::vector< std::shared_ptr< DiffCache > > diff_caches
Definition OptState.hpp:95
spdlog::sink_ptr file_sink_
Definition OptState.hpp:114
void check_unsupported() const
Check and throw if any forward simulation varform::DifferentiableVarForm is not supported.
Definition OptState.cpp:512
double eval(Eigen::VectorXd &x) const
Definition OptState.cpp:700
std::vector< std::unique_ptr< const io::ResourceIO > > state_resources
Definition OptState.hpp:94
std::vector< int > variable_sizes
variables
Definition OptState.hpp:98
std::unique_ptr< solver::AdjointNLProblem > nl_problem
Definition OptState.hpp:103
std::string output_dir
Directory for output files.
Definition OptState.hpp:126
std::vector< json > state_args
Definition OptState.hpp:93
spdlog::sink_ptr console_sink_
logger sink to stdout
Definition OptState.hpp:113
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
Definition OptState.cpp:381
std::unique_ptr< const io::ResourceIO > resources_
Definition OptState.hpp:118
solver::VariableToSimulationGroup variable_to_simulations
Definition OptState.hpp:101
void create_varforms(const int max_threads=-1)
Create the optimization variational formulations.
Definition OptState.cpp:484
polysolve::nonlinear::Status solve(Eigen::VectorXd &x)
Definition OptState.cpp:706
void init_variables()
init variables
Definition OptState.cpp:575
OptState()
Constructor.
Definition OptState.cpp:272
Read-only interface to a hierarchical collection of simulation resources.
nlohmann::json json
Definition Common.hpp:9