PolyFEM
Loading...
Searching...
No Matches
State.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <polyfem/Common.hpp>
6
7#include <Eigen/Dense>
8
9#include <spdlog/spdlog.h>
10
11#include <functional>
12#include <limits>
13#include <memory>
14#include <optional>
15#include <string>
16#include <vector>
17
18namespace GEO
19{
20 class Mesh;
21}
22
23namespace polyfem::varform
24{
25 class VarForm;
26}
27
28namespace polyfem::io
29{
30 class CheckpointReader;
31}
32
33namespace polyfem
34{
36 class State
37 {
38 public:
39 State();
40 ~State() = default;
41
45 void init(
46 const json &args,
47 bool strict_validation,
48 bool is_adjoint_optimization = false);
49
50 void init(
51 const io::CheckpointReader &checkpoint,
52 bool strict_validation);
53 void init(
54 const json &args,
55 const io::CheckpointReader &checkpoint,
56 bool strict_validation);
57
58 void init(
59 const json &args,
60 const io::ResourceIO &resources,
61 bool strict_validation,
62 bool is_adjoint_optimization = false);
63
65 void set_max_threads(const int max_threads = std::numeric_limits<int>::max());
66
69
71 std::shared_ptr<varform::VarForm> variational_formulation;
72
74 std::function<void(int, int, double, double)> time_callback = nullptr;
75
76 //---------------------------------------------------
77 //-----------------logger----------------------------
78 //---------------------------------------------------
79
85 void init_logger(
86 const std::string &log_file,
87 const spdlog::level::level_enum log_level,
88 const spdlog::level::level_enum file_log_level,
89 const bool is_quiet);
90
94 void init_logger(std::ostream &os, const spdlog::level::level_enum log_level);
95
98 void set_log_level(const spdlog::level::level_enum log_level);
99
100 private:
102 void init_logger(const std::vector<spdlog::sink_ptr> &sinks, const spdlog::level::level_enum log_level);
103
105 spdlog::sink_ptr console_sink_ = nullptr;
106 spdlog::sink_ptr file_sink_ = nullptr;
107
108 public:
110 void solve(Eigen::MatrixXd &sol);
111
112 //---------------------------------------------------
113 //-----------------Geometry--------------------------
114 //---------------------------------------------------
115
118 void load_mesh(bool non_conforming = false);
119
125 void set_mesh(GEO::Mesh &meshin, const std::function<int(const size_t, const std::vector<int> &, const RowVectorNd &, bool)> &boundary_marker, bool non_conforming = false, bool skip_boundary_sideset = false);
126
131 void set_mesh(const Eigen::MatrixXd &V, const Eigen::MatrixXi &F, bool non_conforming = false);
132
133 private:
134 std::unique_ptr<const io::ResourceIO> resources_;
135 std::optional<std::reference_wrapper<const io::CheckpointReader>> checkpoint_;
136 };
137
138} // namespace polyfem
int V
VarForm-only simulation state.
Definition State.hpp:37
std::shared_ptr< varform::VarForm > variational_formulation
active variational formulation
Definition State.hpp:71
void init(const json &args, bool strict_validation, bool is_adjoint_optimization=false)
initialize the polyfem solver with a json settings
Definition State.cpp:239
void solve(Eigen::MatrixXd &sol)
solves the problem, call other methods
Definition State.cpp:502
void set_mesh(GEO::Mesh &meshin, const std::function< int(const size_t, const std::vector< int > &, const RowVectorNd &, bool)> &boundary_marker, bool non_conforming=false, bool skip_boundary_sideset=false)
loads the mesh from a geogram mesh
Definition State.cpp:413
void set_max_threads(const int max_threads=std::numeric_limits< int >::max())
Definition State.cpp:408
std::optional< std::reference_wrapper< const io::CheckpointReader > > checkpoint_
Definition State.hpp:135
spdlog::sink_ptr file_sink_
Definition State.hpp:106
spdlog::sink_ptr console_sink_
logger sink to stdout
Definition State.hpp:105
~State()=default
json args
main input arguments containing all defaults
Definition State.hpp:68
void set_log_level(const spdlog::level::level_enum log_level)
change log level
Definition State.cpp:225
std::unique_ptr< const io::ResourceIO > resources_
Definition State.hpp:134
std::function< void(int, int, double, double)> time_callback
Optional UI progress callback.
Definition State.hpp:74
void load_mesh(bool non_conforming=false)
loads the mesh from the json arguments
Definition State.cpp:446
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 State.cpp:171
Read-only interface to a hierarchical collection of simulation resources.
nlohmann::json json
Definition Common.hpp:9
Eigen::Matrix< double, 1, Eigen::Dynamic, Eigen::RowMajor, 1, 3 > RowVectorNd
Definition Types.hpp:13