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
10
11namespace polyfem
12{
13 class State;
14
15 namespace solver
16 {
17 class AdjointNLProblem;
18 } // namespace solver
19
22 {
23 public:
24 //---------------------------------------------------
25 //-----------------initialization--------------------
26 //---------------------------------------------------
27
28 ~OptState();
30 OptState();
31
35 void init(const json &args, const bool strict_validation);
36
39
45 void init_logger(
46 const std::string &log_file,
47 const spdlog::level::level_enum log_level,
48 const spdlog::level::level_enum file_log_level,
49 const bool is_quiet);
50
54 void init_logger(std::ostream &os, const spdlog::level::level_enum log_level);
55
58 void set_log_level(const spdlog::level::level_enum log_level);
59
61 void create_states(const polyfem::solver::CacheLevel level, const int max_threads = -1);
62
64 void init_variables();
65
66 void create_problem();
67
68 void initial_guess(Eigen::VectorXd &x); // shoud be const
69
70 double eval(Eigen::VectorXd &x) const;
71
72 void solve(Eigen::VectorXd &x);
73
74 private:
75 inline std::string root_path() const
76 {
77 if (utils::is_param_valid(args, "root_path"))
78 return args["root_path"].get<std::string>();
79 return "";
80 }
81
83 void init_logger(const std::vector<spdlog::sink_ptr> &sinks, const spdlog::level::level_enum log_level);
84
86 spdlog::sink_ptr console_sink_ = nullptr;
87 spdlog::sink_ptr file_sink_ = nullptr;
88
89 //---------------------------------------------------
90 //-----------------state--------------------
91 //---------------------------------------------------
92
94 std::vector<std::shared_ptr<State>> states;
95
97 std::vector<int> variable_sizes;
98 int ndof;
99
101
102 std::unique_ptr<solver::AdjointNLProblem> nl_problem;
103
104 public:
106 std::string output_dir;
107 };
108} // namespace polyfem
int x
main class that contains the polyfem adjoint solver and all its state
Definition OptState.hpp:22
std::vector< std::shared_ptr< State > > states
State used in the opt.
Definition OptState.hpp:94
void solve(Eigen::VectorXd &x)
Definition OptState.cpp:185
void initial_guess(Eigen::VectorXd &x)
Definition OptState.cpp:172
void set_log_level(const spdlog::level::level_enum log_level)
change log level
Definition OptState.cpp:93
json args
main input arguments containing all defaults
Definition OptState.hpp:38
void init(const json &args, const bool strict_validation)
initialize the polyfem solver with a json settings
Definition OptState.cpp:100
spdlog::sink_ptr file_sink_
Definition OptState.hpp:87
std::string root_path() const
Definition OptState.hpp:75
double eval(Eigen::VectorXd &x) const
Definition OptState.cpp:179
std::vector< int > variable_sizes
variables
Definition OptState.hpp:97
std::unique_ptr< solver::AdjointNLProblem > nl_problem
Definition OptState.hpp:102
std::string output_dir
Directory for output files.
Definition OptState.hpp:106
spdlog::sink_ptr console_sink_
logger sink to stdout
Definition OptState.hpp:86
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:49
void create_states(const polyfem::solver::CacheLevel level, const int max_threads=-1)
create the opt states
Definition OptState.cpp:131
solver::VariableToSimulationGroup variable_to_simulations
Definition OptState.hpp:100
void init_variables()
init variables
Definition OptState.cpp:141
OptState()
Constructor.
Definition OptState.cpp:44
A collection of VariableToSimulation.
bool is_param_valid(const json &params, const std::string &key)
Determine if a key exists and is non-null in a json object.
nlohmann::json json
Definition Common.hpp:9