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 polyfem::varform
19{
20 class VarForm;
21}
22
23namespace polyfem::io
24{
25 class CheckpointReader;
26}
27
28namespace polyfem
29{
31 class State
32 {
33 public:
35 ~State() = default;
36
40 void init(
41 const json &args,
42 bool strict_validation,
43 bool is_adjoint_optimization = false);
44
45 void init(
46 const io::CheckpointReader &checkpoint,
47 bool strict_validation);
48 void init(
49 const json &args,
50 const io::CheckpointReader &checkpoint,
51 bool strict_validation);
52
53 void init(
54 const json &args,
55 const io::ResourceIO &resources,
56 bool strict_validation,
57 bool is_adjoint_optimization = false);
58
60 void set_max_threads(const int max_threads = std::numeric_limits<int>::max());
61
64
66 std::shared_ptr<varform::VarForm> variational_formulation;
67
69 std::function<void(int, int, double, double)> time_callback = nullptr;
70
71 //---------------------------------------------------
72 //-----------------logger----------------------------
73 //---------------------------------------------------
74
80 void init_logger(
81 const std::string &log_file,
82 const spdlog::level::level_enum log_level,
83 const spdlog::level::level_enum file_log_level,
84 const bool is_quiet);
85
89 void init_logger(std::ostream &os, const spdlog::level::level_enum log_level);
90
93 void set_log_level(const spdlog::level::level_enum log_level);
94
95 private:
97 void init_logger(const std::vector<spdlog::sink_ptr> &sinks, const spdlog::level::level_enum log_level);
98
100 spdlog::sink_ptr console_sink_ = nullptr;
101 spdlog::sink_ptr file_sink_ = nullptr;
102
103 public:
105 void solve(Eigen::MatrixXd &sol);
106
107 //---------------------------------------------------
108 //-----------------Geometry--------------------------
109 //---------------------------------------------------
110
113 void load_mesh(bool non_conforming = false);
114
119 void set_mesh(const Eigen::MatrixXd &V, const Eigen::MatrixXi &F, bool non_conforming = false);
120
121 private:
122 std::unique_ptr<const io::ResourceIO> resources_;
123 std::optional<std::reference_wrapper<const io::CheckpointReader>> checkpoint_;
124 };
125
126} // namespace polyfem
int V
VarForm-only simulation state.
Definition State.hpp:32
std::shared_ptr< varform::VarForm > variational_formulation
active variational formulation
Definition State.hpp:66
void init(const json &args, bool strict_validation, bool is_adjoint_optimization=false)
initialize the polyfem solver with a json settings
Definition State.cpp:258
void solve(Eigen::MatrixXd &sol)
solves the problem, call other methods
Definition State.cpp:490
void set_max_threads(const int max_threads=std::numeric_limits< int >::max())
Definition State.cpp:429
void set_mesh(const Eigen::MatrixXd &V, const Eigen::MatrixXi &F, bool non_conforming=false)
loads the mesh from V and F,
Definition State.cpp:497
std::optional< std::reference_wrapper< const io::CheckpointReader > > checkpoint_
Definition State.hpp:123
spdlog::sink_ptr file_sink_
Definition State.hpp:101
spdlog::sink_ptr console_sink_
logger sink to stdout
Definition State.hpp:100
~State()=default
json args
main input arguments containing all defaults
Definition State.hpp:63
void set_log_level(const spdlog::level::level_enum log_level)
change log level
Definition State.cpp:244
std::unique_ptr< const io::ResourceIO > resources_
Definition State.hpp:122
std::function< void(int, int, double, double)> time_callback
Optional UI progress callback.
Definition State.hpp:69
void load_mesh(bool non_conforming=false)
loads the mesh from the json arguments
Definition State.cpp:434
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:198
Read-only interface to a hierarchical collection of simulation resources.
nlohmann::json json
Definition Common.hpp:9