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
11#include <Eigen/Core>
12
13#include <string>
14#include <vector>
15#include <memory>
16
17namespace polyfem
18{
19 namespace legacy
20 {
21 class State;
22 }
23
24 namespace solver
25 {
26 class AdjointNLProblem;
27 } // namespace solver
28
31 {
32 public:
33 //---------------------------------------------------
34 //-----------------initialization--------------------
35 //---------------------------------------------------
36
37 ~OptState();
39 OptState();
40
44 void init(const json &args, const bool strict_validation);
45
48
54 void init_logger(
55 const std::string &log_file,
56 const spdlog::level::level_enum log_level,
57 const spdlog::level::level_enum file_log_level,
58 const bool is_quiet);
59
63 void init_logger(std::ostream &os, const spdlog::level::level_enum log_level);
64
67 void set_log_level(const spdlog::level::level_enum log_level);
68
70 void create_states(const int max_threads = -1);
71
73 void init_variables();
74
75 void create_problem();
76
77 void initial_guess(Eigen::VectorXd &x); // shoud be const
78
79 double eval(Eigen::VectorXd &x) const;
80
81 void solve(Eigen::VectorXd &x);
82
83 //---------------------------------------------------
84 //-----------------state--------------------
85 //---------------------------------------------------
86
88 std::vector<std::shared_ptr<legacy::State>> states;
89 std::vector<std::shared_ptr<DiffCache>> diff_caches;
90
92 std::vector<int> variable_sizes;
93 int ndof;
94
96
97 std::unique_ptr<solver::AdjointNLProblem> nl_problem;
98
99 private:
100 inline std::string root_path() const
101 {
102 if (utils::is_param_valid(args, "root_path"))
103 return args["root_path"].get<std::string>();
104 return "";
105 }
106
108 void check_unsupported() const;
109
111 void init_logger(const std::vector<spdlog::sink_ptr> &sinks, const spdlog::level::level_enum log_level);
112
114 spdlog::sink_ptr console_sink_ = nullptr;
115 spdlog::sink_ptr file_sink_ = nullptr;
116
117 //---------------------------------------------------
118 //-----------------output--------------------
119 //---------------------------------------------------
120
121 public:
123 std::string output_dir;
124 };
125} // namespace polyfem
int x
main class that contains the polyfem adjoint solver and all its state
Definition OptState.hpp:31
void solve(Eigen::VectorXd &x)
Definition OptState.cpp:306
void initial_guess(Eigen::VectorXd &x)
Definition OptState.cpp:293
void set_log_level(const spdlog::level::level_enum log_level)
change log level
Definition OptState.cpp:103
void create_states(const int max_threads=-1)
create the opt states
Definition OptState.cpp:141
json args
main input arguments containing all defaults
Definition OptState.hpp:47
void init(const json &args, const bool strict_validation)
initialize the polyfem solver with a json settings
Definition OptState.cpp:110
std::vector< std::shared_ptr< DiffCache > > diff_caches
Definition OptState.hpp:89
spdlog::sink_ptr file_sink_
Definition OptState.hpp:115
std::string root_path() const
Definition OptState.hpp:100
void check_unsupported() const
Check and throw if any forward simulation legacy::State is not supported.
Definition OptState.cpp:160
double eval(Eigen::VectorXd &x) const
Definition OptState.cpp:300
std::vector< int > variable_sizes
variables
Definition OptState.hpp:92
std::unique_ptr< solver::AdjointNLProblem > nl_problem
Definition OptState.hpp:97
std::string output_dir
Directory for output files.
Definition OptState.hpp:123
std::vector< std::shared_ptr< legacy::State > > states
legacy::State used in the opt
Definition OptState.hpp:88
spdlog::sink_ptr console_sink_
logger sink to stdout
Definition OptState.hpp:114
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:59
solver::VariableToSimulationGroup variable_to_simulations
Definition OptState.hpp:95
void init_variables()
init variables
Definition OptState.cpp:217
OptState()
Constructor.
Definition OptState.cpp:54
polyfem::legacy::State State
Definition Remesher.hpp:19
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