PolyFEM
Loading...
Searching...
No Matches
State.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <polyfem/Common.hpp>
4
5#include <polyfem/Units.hpp>
6
9
18
19#include <polyfem/mesh/Mesh.hpp>
23
26
32
34
35#include <polysolve/linear/Solver.hpp>
36
37#include <Eigen/Dense>
38#include <Eigen/Sparse>
39
40#include <memory>
41#include <string>
42#include <unordered_map>
43
44#include <spdlog/sinks/basic_file_sink.h>
45
46#include <ipc/collision_mesh.hpp>
47#include <ipc/utils/logger.hpp>
48
49// Forward declaration
51{
52 class Solver;
53}
54
55namespace polyfem::assembler
56{
57 class Mass;
58 class ViscousDamping;
59 class ViscousDampingPrev;
60} // namespace polyfem::assembler
61
62namespace polyfem
63{
64 namespace mesh
65 {
66 class Mesh2D;
67 class Mesh3D;
68 } // namespace mesh
69
70 enum class CacheLevel
71 {
72 None,
75 };
76
78 class State
79 {
80 public:
81 //---------------------------------------------------
82 //-----------------initialization--------------------
83 //---------------------------------------------------
84
85 ~State() = default;
87 State();
88
90 void set_max_threads(const int max_threads = std::numeric_limits<int>::max());
91
95 void init(const json &args, const bool strict_validation);
96
98 void init_time();
99
102
103 //---------------------------------------------------
104 //-----------------logger----------------------------
105 //---------------------------------------------------
106
112 void init_logger(
113 const std::string &log_file,
114 const spdlog::level::level_enum log_level,
115 const spdlog::level::level_enum file_log_level,
116 const bool is_quiet);
117
121 void init_logger(std::ostream &os, const spdlog::level::level_enum log_level);
122
125 void set_log_level(const spdlog::level::level_enum log_level);
126
130 std::string get_log(const Eigen::MatrixXd &sol)
131 {
132 std::stringstream ss;
133 save_json(sol, ss);
134 return ss.str();
135 }
136
137 private:
139 void init_logger(const std::vector<spdlog::sink_ptr> &sinks, const spdlog::level::level_enum log_level);
140
142 spdlog::sink_ptr console_sink_ = nullptr;
143 spdlog::sink_ptr file_sink_ = nullptr;
144
145 public:
146 //---------------------------------------------------
147 //-----------------assembly--------------------------
148 //---------------------------------------------------
149
151
153
155 std::shared_ptr<assembler::Assembler> assembler = nullptr;
156
157 std::shared_ptr<assembler::Mass> mass_matrix_assembler = nullptr;
158
159 std::shared_ptr<assembler::MixedAssembler> mixed_assembler = nullptr;
160 std::shared_ptr<assembler::Assembler> pressure_assembler = nullptr;
161
162 std::shared_ptr<assembler::PressureAssembler> elasticity_pressure_assembler = nullptr;
163
164 std::shared_ptr<assembler::ViscousDamping> damping_assembler = nullptr;
165 std::shared_ptr<assembler::ViscousDampingPrev> damping_prev_assembler = nullptr;
166
168 std::shared_ptr<assembler::Problem> problem;
169
171 std::vector<basis::ElementBases> bases;
173 std::vector<basis::ElementBases> pressure_bases;
175 std::vector<basis::ElementBases> geom_bases_;
176
183
185 std::map<int, Eigen::MatrixXd> polys;
187 std::map<int, std::pair<Eigen::MatrixXd, Eigen::MatrixXi>> polys_3d;
188
190 Eigen::VectorXi disc_orders;
191
193 std::shared_ptr<polyfem::mesh::MeshNodes> mesh_nodes, geom_mesh_nodes, pressure_mesh_nodes;
194
200
204 double avg_mass;
205
207 Eigen::MatrixXd rhs;
208
212
215 std::string formulation() const;
216
219 bool iso_parametric() const;
220
223 const std::vector<basis::ElementBases> &geom_bases() const
224 {
225 return iso_parametric() ? bases : geom_bases_;
226 }
227
232 void build_basis();
236 void assemble_rhs();
240 void assemble_mass_mat();
241
243 std::shared_ptr<assembler::RhsAssembler> build_rhs_assembler(
244 const int n_bases,
245 const std::vector<basis::ElementBases> &bases,
248 std::shared_ptr<assembler::RhsAssembler> build_rhs_assembler() const
249 {
251 }
252
253 std::shared_ptr<assembler::PressureAssembler> build_pressure_assembler(
254 const int n_bases_,
255 const std::vector<basis::ElementBases> &bases_) const;
256 std::shared_ptr<assembler::PressureAssembler> build_pressure_assembler() const
257 {
259 }
260
264 {
266 const int n_b_samples_j = args["space"]["advanced"]["n_boundary_samples"];
267 const int gdiscr_order = mesh->orders().size() <= 0 ? 1 : mesh->orders().maxCoeff();
268 const int discr_order = std::max(disc_orders.maxCoeff(), gdiscr_order);
269
270 const int n_b_samples = std::max(n_b_samples_j, AssemblerUtils::quadrature_order("Mass", discr_order, AssemblerUtils::BasisType::POLY, mesh->dimension()));
271
272 return n_b_samples;
273 }
274
275 private:
279 void sol_to_pressure(Eigen::MatrixXd &sol, Eigen::MatrixXd &pressure);
282
283 public:
286 void set_materials(std::vector<std::shared_ptr<assembler::Assembler>> &assemblers) const;
290
291 //---------------------------------------------------
292 //-----------------solver----------------------------
293 //---------------------------------------------------
294
295 public:
299 void solve_problem(Eigen::MatrixXd &sol, Eigen::MatrixXd &pressure);
303 void solve(Eigen::MatrixXd &sol, Eigen::MatrixXd &pressure)
304 {
305 if (!mesh)
306 {
307 logger().error("Load the mesh first!");
308 return;
309 }
311
312 build_basis();
313
314 assemble_rhs();
316
317 solve_export_to_file = false;
318 solution_frames.clear();
319 solve_problem(sol, pressure);
321 }
322
328 void init_solve(Eigen::MatrixXd &sol, Eigen::MatrixXd &pressure);
334 void solve_transient_navier_stokes_split(const int time_steps, const double dt, Eigen::MatrixXd &sol, Eigen::MatrixXd &pressure);
341 void solve_transient_navier_stokes(const int time_steps, const double t0, const double dt, Eigen::MatrixXd &sol, Eigen::MatrixXd &pressure);
348 void solve_transient_linear(const int time_steps, const double t0, const double dt, Eigen::MatrixXd &sol, Eigen::MatrixXd &pressure);
354 void solve_transient_tensor_nonlinear(const int time_steps, const double t0, const double dt, Eigen::MatrixXd &sol);
358 void init_nonlinear_tensor_solve(Eigen::MatrixXd &sol, const double t = 1.0, const bool init_time_integrator = true);
361 void init_linear_solve(Eigen::MatrixXd &sol, const double t = 1.0);
364 void initial_solution(Eigen::MatrixXd &solution) const;
367 void initial_velocity(Eigen::MatrixXd &velocity) const;
370 void initial_acceleration(Eigen::MatrixXd &acceleration) const;
374 void solve_linear(Eigen::MatrixXd &sol, Eigen::MatrixXd &pressure);
378 void solve_navier_stokes(Eigen::MatrixXd &sol, Eigen::MatrixXd &pressure);
382 void solve_tensor_nonlinear(Eigen::MatrixXd &sol, const int t = 0, const bool init_lagging = true);
383
386 std::shared_ptr<polysolve::nonlinear::Solver> make_nl_solver(bool for_al) const;
387
389 std::shared_ptr<utils::PeriodicBoundary> periodic_bc;
390 bool has_periodic_bc() const
391 {
392 return args["boundary_conditions"]["periodic_boundary"]["enabled"].get<bool>();
393 }
394
402 void solve_linear(
403 const std::unique_ptr<polysolve::linear::Solver> &solver,
405 Eigen::VectorXd &b,
406 const bool compute_spectrum,
407 Eigen::MatrixXd &sol, Eigen::MatrixXd &pressure);
408
410 bool is_problem_linear() const { return assembler->is_linear() && !is_contact_enabled() && !is_pressure_enabled(); }
411
412 public:
415 void build_stiffness_mat(StiffnessMatrix &stiffness);
416
417 //---------------------------------------------------
418 //-----------------nodes flags-----------------------
419 //---------------------------------------------------
420
421 public:
423 std::unordered_map<int, std::array<bool, 3>>
424 boundary_conditions_ids(const std::string &bc_type) const;
425
427 std::vector<int> boundary_nodes;
429 std::vector<int> pressure_boundary_nodes;
431 std::vector<mesh::LocalBoundary> total_local_boundary;
433 std::vector<mesh::LocalBoundary> local_boundary;
435 std::vector<mesh::LocalBoundary> local_neumann_boundary;
437 std::vector<mesh::LocalBoundary> local_pressure_boundary;
439 std::unordered_map<int, std::vector<mesh::LocalBoundary>> local_pressure_cavity;
441 std::map<int, basis::InterfaceData> poly_edge_to_data;
443 std::vector<int> dirichlet_nodes;
444 std::vector<RowVectorNd> dirichlet_nodes_position;
446 std::vector<int> neumann_nodes;
447 std::vector<RowVectorNd> neumann_nodes_position;
448
450 Eigen::VectorXi in_node_to_node;
453
454 std::vector<int> primitive_to_node() const;
455 std::vector<int> node_to_primitive() const;
456
457 private:
459 void build_node_mapping();
460
461 //---------------------------------------------------
462 //-----------------Geometry--------------------------
463 //---------------------------------------------------
464 public:
466 std::unique_ptr<mesh::Mesh> mesh;
469
475 void load_mesh(bool non_conforming = false,
476 const std::vector<std::string> &names = std::vector<std::string>(),
477 const std::vector<Eigen::MatrixXi> &cells = std::vector<Eigen::MatrixXi>(),
478 const std::vector<Eigen::MatrixXd> &vertices = std::vector<Eigen::MatrixXd>());
479
485 void load_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);
486
491 void load_mesh(const Eigen::MatrixXd &V, const Eigen::MatrixXi &F, bool non_conforming = false)
492 {
493 mesh = mesh::Mesh::create(V, F, non_conforming);
494 load_mesh(non_conforming);
495 }
496
498 void reset_mesh();
499
501 void build_mesh_matrices(Eigen::MatrixXd &V, Eigen::MatrixXi &F);
502
508 bool remesh(const double time, const double dt, Eigen::MatrixXd &sol);
509
510 //---------------------------------------------------
511 //-----------------IPC-------------------------------
512 //---------------------------------------------------
513
515 ipc::CollisionMesh collision_mesh;
516
518 ipc::CollisionMesh periodic_collision_mesh;
521
523 static void build_collision_mesh(
524 const mesh::Mesh &mesh,
525 const int n_bases,
526 const std::vector<basis::ElementBases> &bases,
527 const std::vector<basis::ElementBases> &geom_bases,
528 const std::vector<mesh::LocalBoundary> &total_local_boundary,
530 const json &args,
531 const std::function<std::string(const std::string &)> &resolve_input_path,
532 const Eigen::VectorXi &in_node_to_node,
533 ipc::CollisionMesh &collision_mesh);
534
538
542 bool is_obstacle_vertex(const size_t vi) const
543 {
544 // The obstalce vertices are at the bottom of the collision mesh vertices
545 return vi >= collision_mesh.full_num_vertices() - obstacle.n_vertices();
546 }
547
552 {
553 return args["contact"]["enabled"];
554 }
555
560 {
561 return (args["boundary_conditions"]["pressure_boundary"].size() > 0)
562 || (args["boundary_conditions"]["pressure_cavity"].size() > 0);
563 }
564
566 bool has_dhat = false;
567
568 //---------------------------------------------------
569 //-----------------OUTPUT----------------------------
570 //---------------------------------------------------
571 public:
573 std::string output_dir;
574
579 std::vector<io::SolutionFrame> solution_frames;
589
593 void export_data(const Eigen::MatrixXd &sol, const Eigen::MatrixXd &pressure);
594
602 void save_timestep(const double time, const int t, const double t0, const double dt, const Eigen::MatrixXd &sol, const Eigen::MatrixXd &pressure);
603
609 void save_subsolve(const int i, const int t, const Eigen::MatrixXd &sol, const Eigen::MatrixXd &pressure);
610
614 void save_json(const Eigen::MatrixXd &sol, std::ostream &out);
615
618 void save_json(const Eigen::MatrixXd &sol);
619
621 void compute_errors(const Eigen::MatrixXd &sol);
622
625 void save_restart_json(const double t0, const double dt, const int t) const;
626
627 //-----------PATH management
630 std::string root_path() const;
631
636 std::string resolve_input_path(const std::string &path, const bool only_if_exists = false) const;
637
641 std::string resolve_output_path(const std::string &path) const;
642
643 //---------------------------------------------------
644 //-----------------differentiable--------------------
645 //---------------------------------------------------
646 public:
648 void cache_transient_adjoint_quantities(const int current_step, const Eigen::MatrixXd &sol, const Eigen::MatrixXd &disp_grad);
650
651 std::unique_ptr<polysolve::linear::Solver> lin_solver_cached; // matrix factorization of last linear solve
652
653 int ndof() const
654 {
655 const int actual_dim = problem->is_scalar() ? 1 : mesh->dimension();
656 if (mixed_assembler == nullptr)
657 return actual_dim * n_bases;
658 else
659 return actual_dim * n_bases + n_pressure_bases;
660 }
661
662 // Aux functions for setting up adjoint equations
663 void compute_force_jacobian(const Eigen::MatrixXd &sol, const Eigen::MatrixXd &disp_grad, StiffnessMatrix &hessian);
664 void compute_force_jacobian_prev(const int force_step, const int sol_step, StiffnessMatrix &hessian_prev) const;
665 // Solves the adjoint PDE for derivatives and caches
666 void solve_adjoint_cached(const Eigen::MatrixXd &rhs);
667 Eigen::MatrixXd solve_adjoint(const Eigen::MatrixXd &rhs) const;
668 // Returns cached adjoint solve
669 Eigen::MatrixXd get_adjoint_mat(int type) const
670 {
671 assert(diff_cached.adjoint_mat().size() > 0);
672 if (problem->is_time_dependent())
673 {
674 if (type == 0)
675 return diff_cached.adjoint_mat().leftCols(diff_cached.adjoint_mat().cols() / 2);
676 else if (type == 1)
677 return diff_cached.adjoint_mat().middleCols(diff_cached.adjoint_mat().cols() / 2, diff_cached.adjoint_mat().cols() / 2);
678 else
679 log_and_throw_adjoint_error("Invalid adjoint type!");
680 }
681
682 return diff_cached.adjoint_mat();
683 }
684 Eigen::MatrixXd solve_static_adjoint(const Eigen::MatrixXd &adjoint_rhs) const;
685 Eigen::MatrixXd solve_transient_adjoint(const Eigen::MatrixXd &adjoint_rhs) const;
686 // Change geometric node positions
687 void set_mesh_vertex(int v_id, const Eigen::VectorXd &vertex);
688 void get_vertices(Eigen::MatrixXd &vertices) const;
689 void get_elements(Eigen::MatrixXi &elements) const;
690
691 // Get geometric node indices for surface/volume
692 void compute_surface_node_ids(const int surface_selection, std::vector<int> &node_ids) const;
693 void compute_total_surface_node_ids(std::vector<int> &node_ids) const;
694 void compute_volume_node_ids(const int volume_selection, std::vector<int> &node_ids) const;
695
696 // to replace the initial condition in json during initial condition optimization
698 // mapping from positions of FE basis nodes to positions of geometry nodes
700
701 //---------------------------------------------------
702 //-----------------homogenization--------------------
703 //---------------------------------------------------
704 public:
706
708 void solve_homogenization_step(Eigen::MatrixXd &sol, const int t = 0, bool adaptive_initial_weight = false); // sol is the extended solution, i.e. [periodic fluctuation, macro strain]
709 void init_homogenization_solve(const double t);
710 void solve_homogenization(const int time_steps, const double t0, const double dt, Eigen::MatrixXd &sol);
711 bool is_homogenization() const
712 {
713 return args["boundary_conditions"]["periodic_boundary"]["linear_displacement_offset"].size() > 0;
714 }
715 };
716
717} // namespace polyfem
int V
main class that contains the polyfem solver and all its state
Definition State.hpp:79
void get_vertices(Eigen::MatrixXd &vertices) const
Definition StateDiff.cpp:69
Eigen::MatrixXd initial_vel_update
Definition State.hpp:697
io::OutRuntimeData timings
runtime statistics
Definition State.hpp:583
assembler::MacroStrainValue macro_strain_constraint
Definition State.hpp:705
std::shared_ptr< utils::PeriodicBoundary > periodic_bc
periodic BC and periodic mesh utils
Definition State.hpp:389
int n_bases
number of bases
Definition State.hpp:178
void cache_transient_adjoint_quantities(const int current_step, const Eigen::MatrixXd &sol, const Eigen::MatrixXd &disp_grad)
int n_pressure_bases
number of pressure bases
Definition State.hpp:180
std::string formulation() const
return the formulation (checks if the problem is scalar or not and deals with multiphysics)
Definition State.cpp:328
assembler::AssemblyValsCache ass_vals_cache
used to store assembly values for small problems
Definition State.hpp:196
int n_boundary_samples() const
quadrature used for projecting boundary conditions
Definition State.hpp:263
void set_mesh_vertex(int v_id, const Eigen::VectorXd &vertex)
Definition StateDiff.cpp:94
const std::vector< basis::ElementBases > & geom_bases() const
Get a constant reference to the geometry mapping bases.
Definition State.hpp:223
double starting_max_edge_length
Definition State.hpp:587
std::vector< mesh::LocalBoundary > local_pressure_boundary
mapping from elements to nodes for pressure boundary conditions
Definition State.hpp:437
void sol_to_pressure(Eigen::MatrixXd &sol, Eigen::MatrixXd &pressure)
splits the solution in solution and pressure for mixed problems
Definition State.cpp:386
std::shared_ptr< assembler::ViscousDamping > damping_assembler
Definition State.hpp:164
void init(const json &args, const bool strict_validation)
initialize the polyfem solver with a json settings
std::string root_path() const
Get the root path for the state (e.g., args["root_path"] or ".")
bool is_pressure_enabled() const
does the simulation has pressure
Definition State.hpp:559
void assemble_mass_mat()
assemble mass, step 4 of solve build mass matrix based on defined basis modifies mass (and maybe more...
Definition State.cpp:1487
Eigen::VectorXi in_node_to_node
Inpute nodes (including high-order) to polyfem nodes, only for isoparametric.
Definition State.hpp:450
void build_polygonal_basis()
builds bases for polygons, called inside build_basis
Definition State.cpp:1068
void solve(Eigen::MatrixXd &sol, Eigen::MatrixXd &pressure)
solves the problem, call other methods
Definition State.hpp:303
mesh::Obstacle obstacle
Obstacles used in collisions.
Definition State.hpp:468
std::shared_ptr< assembler::Assembler > assembler
assemblers
Definition State.hpp:155
void compute_errors(const Eigen::MatrixXd &sol)
computes all errors
ipc::CollisionMesh periodic_collision_mesh
IPC collision mesh under periodic BC.
Definition State.hpp:518
void build_periodic_collision_mesh()
Definition State.cpp:1231
void save_subsolve(const int i, const int t, const Eigen::MatrixXd &sol, const Eigen::MatrixXd &pressure)
saves a subsolve when save_solve_sequence_debug is true
io::OutGeometryData out_geom
visualization stuff
Definition State.hpp:581
bool use_avg_pressure
use average pressure for stokes problem to fix the additional dofs, true by default if false,...
Definition State.hpp:211
std::string resolve_output_path(const std::string &path) const
Resolve output path relative to output_dir if the path is not absolute.
std::vector< int > neumann_nodes
per node neumann
Definition State.hpp:446
ipc::CollisionMesh collision_mesh
IPC collision mesh.
Definition State.hpp:515
std::string output_dir
Directory for output files.
Definition State.hpp:573
void load_mesh(bool non_conforming=false, const std::vector< std::string > &names=std::vector< std::string >(), const std::vector< Eigen::MatrixXi > &cells=std::vector< Eigen::MatrixXi >(), const std::vector< Eigen::MatrixXd > &vertices=std::vector< Eigen::MatrixXd >())
loads the mesh from the json arguments
Definition StateLoad.cpp:91
std::vector< basis::ElementBases > geom_bases_
Geometric mapping bases, if the elements are isoparametric, this list is empty.
Definition State.hpp:175
solver::CacheLevel optimization_enabled
Definition State.hpp:647
void solve_homogenization_step(Eigen::MatrixXd &sol, const int t=0, bool adaptive_initial_weight=false)
In Elasticity PDE, solve for "min W(disp_grad + \grad u)" instead of "min W(\grad u)".
Eigen::VectorXi in_primitive_to_primitive
maps in vertices/edges/faces/cells to polyfem vertices/edges/faces/cells
Definition State.hpp:452
void set_materials(std::vector< std::shared_ptr< assembler::Assembler > > &assemblers) const
set the material and the problem dimension
std::string get_log(const Eigen::MatrixXd &sol)
gets the output log as json this is not what gets printed but more informative information,...
Definition State.hpp:130
std::map< int, basis::InterfaceData > poly_edge_to_data
nodes on the boundary of polygonal elements, used for harmonic bases
Definition State.hpp:441
std::vector< int > pressure_boundary_nodes
list of neumann boundary nodes
Definition State.hpp:429
void set_max_threads(const int max_threads=std::numeric_limits< int >::max())
void save_timestep(const double time, const int t, const double t0, const double dt, const Eigen::MatrixXd &sol, const Eigen::MatrixXd &pressure)
saves a timestep
std::vector< basis::ElementBases > pressure_bases
FE pressure bases for mixed elements, the size is #elements.
Definition State.hpp:173
void save_json(const Eigen::MatrixXd &sol, std::ostream &out)
saves the output statistic to a stream
bool is_homogenization() const
Definition State.hpp:711
Eigen::MatrixXd get_adjoint_mat(int type) const
Definition State.hpp:669
void load_mesh(const Eigen::MatrixXd &V, const Eigen::MatrixXi &F, bool non_conforming=false)
loads the mesh from V and F,
Definition State.hpp:491
void solve_transient_tensor_nonlinear(const int time_steps, const double t0, const double dt, Eigen::MatrixXd &sol)
solves transient tensor nonlinear problem
void initial_solution(Eigen::MatrixXd &solution) const
Load or compute the initial solution.
std::shared_ptr< assembler::Assembler > pressure_assembler
Definition State.hpp:160
std::shared_ptr< polysolve::nonlinear::Solver > make_nl_solver(bool for_al) const
factory to create the nl solver depending on input
double starting_min_edge_length
Definition State.hpp:586
std::shared_ptr< assembler::Mass > mass_matrix_assembler
Definition State.hpp:157
void build_node_mapping()
build the mapping from input nodes to polyfem nodes
Definition State.cpp:245
bool remesh(const double time, const double dt, Eigen::MatrixXd &sol)
Remesh the FE space and update solution(s).
std::vector< int > primitive_to_node() const
Definition State.cpp:228
bool has_dhat
stores if input json contains dhat
Definition State.hpp:566
Eigen::MatrixXd solve_static_adjoint(const Eigen::MatrixXd &adjoint_rhs) const
void compute_force_jacobian(const Eigen::MatrixXd &sol, const Eigen::MatrixXd &disp_grad, StiffnessMatrix &hessian)
std::shared_ptr< polyfem::mesh::MeshNodes > pressure_mesh_nodes
Definition State.hpp:193
std::unique_ptr< mesh::Mesh > mesh
current mesh, it can be a Mesh2D or Mesh3D
Definition State.hpp:466
void reset_mesh()
Resets the mesh.
Definition StateLoad.cpp:22
std::unordered_map< int, std::array< bool, 3 > > boundary_conditions_ids(const std::string &bc_type) const
Construct a vector of boundary conditions ids with their dimension flags.
std::shared_ptr< polyfem::mesh::MeshNodes > mesh_nodes
Mapping from input nodes to FE nodes.
Definition State.hpp:193
StiffnessMatrix mass
Mass matrix, it is computed only for time dependent problems.
Definition State.hpp:202
void solve_homogenization(const int time_steps, const double t0, const double dt, Eigen::MatrixXd &sol)
std::vector< int > dirichlet_nodes
per node dirichlet
Definition State.hpp:443
bool has_periodic_bc() const
Definition State.hpp:390
void solve_problem(Eigen::MatrixXd &sol, Eigen::MatrixXd &pressure)
solves the problems
Definition State.cpp:1683
void build_basis()
builds the bases step 2 of solve modifies bases, pressure_bases, geom_bases_, boundary_nodes,...
Definition State.cpp:518
void solve_navier_stokes(Eigen::MatrixXd &sol, Eigen::MatrixXd &pressure)
solves a navier stokes
std::shared_ptr< assembler::Problem > problem
current problem, it contains rhs and bc
Definition State.hpp:168
std::vector< RowVectorNd > dirichlet_nodes_position
Definition State.hpp:444
spdlog::sink_ptr file_sink_
Definition State.hpp:143
spdlog::sink_ptr console_sink_
logger sink to stdout
Definition State.hpp:142
State()
Constructor.
Definition StateInit.cpp:56
std::map< int, std::pair< Eigen::MatrixXd, Eigen::MatrixXi > > polys_3d
polyhedra, used since poly have no geom mapping
Definition State.hpp:187
std::vector< int > node_to_primitive() const
Definition State.cpp:235
~State()=default
json args
main input arguments containing all defaults
Definition State.hpp:101
void set_log_level(const spdlog::level::level_enum log_level)
change log level
void save_restart_json(const double t0, const double dt, const int t) const
Save a JSON sim file for restarting the simulation at time t.
std::vector< io::SolutionFrame > solution_frames
saves the frames in a vector instead of VTU
Definition State.hpp:579
solver::DiffCache diff_cached
Definition State.hpp:649
void initial_velocity(Eigen::MatrixXd &velocity) const
Load or compute the initial velocity.
io::OutStatsData stats
Other statistics.
Definition State.hpp:585
std::vector< RowVectorNd > neumann_nodes_position
Definition State.hpp:447
void assemble_rhs()
compute rhs, step 3 of solve build rhs vector based on defined basis and given rhs of the problem mod...
Definition State.cpp:1611
double min_boundary_edge_length
Definition State.hpp:588
Eigen::VectorXi periodic_collision_mesh_to_basis
index mapping from periodic 2x2 collision mesh to FE periodic mesh
Definition State.hpp:520
void init_time()
initialize time settings if args contains "time"
void initial_acceleration(Eigen::MatrixXd &acceleration) const
Load or compute the initial acceleration.
std::vector< basis::ElementBases > bases
FE bases, the size is #elements.
Definition State.hpp:171
void solve_adjoint_cached(const Eigen::MatrixXd &rhs)
void solve_transient_navier_stokes_split(const int time_steps, const double dt, Eigen::MatrixXd &sol, Eigen::MatrixXd &pressure)
solves transient navier stokes with operator splitting
Eigen::MatrixXd solve_adjoint(const Eigen::MatrixXd &rhs) const
void get_elements(Eigen::MatrixXi &elements) const
Definition StateDiff.cpp:77
int n_geom_bases
number of geometric bases
Definition State.hpp:182
assembler::AssemblyValsCache pressure_ass_vals_cache
used to store assembly values for pressure for small problems
Definition State.hpp:199
void build_stiffness_mat(StiffnessMatrix &stiffness)
utility that builds the stiffness matrix and collects stats, used only for linear problems
std::vector< mesh::LocalBoundary > local_boundary
mapping from elements to nodes for dirichlet boundary conditions
Definition State.hpp:433
double avg_mass
average system mass, used for contact with IPC
Definition State.hpp:204
bool iso_parametric() const
check if using iso parametric bases
Definition State.cpp:477
std::shared_ptr< assembler::RhsAssembler > build_rhs_assembler() const
build a RhsAssembler for the problem
Definition State.hpp:248
void compute_volume_node_ids(const int volume_selection, std::vector< int > &node_ids) const
std::vector< mesh::LocalBoundary > total_local_boundary
mapping from elements to nodes for all mesh
Definition State.hpp:431
void solve_transient_navier_stokes(const int time_steps, const double t0, const double dt, Eigen::MatrixXd &sol, Eigen::MatrixXd &pressure)
solves transient navier stokes with FEM
void init_solve(Eigen::MatrixXd &sol, Eigen::MatrixXd &pressure)
initialize solver
void init_linear_solve(Eigen::MatrixXd &sol, const double t=1.0)
initialize the linear solve
int ndof() const
Definition State.hpp:653
void export_data(const Eigen::MatrixXd &sol, const Eigen::MatrixXd &pressure)
saves all data on the disk according to the input params
assembler::AssemblyValsCache mass_ass_vals_cache
Definition State.hpp:197
bool is_obstacle_vertex(const size_t vi) const
checks if vertex is obstacle
Definition State.hpp:542
void solve_tensor_nonlinear(Eigen::MatrixXd &sol, const int t=0, const bool init_lagging=true)
solves nonlinear problems
std::string resolve_input_path(const std::string &path, const bool only_if_exists=false) const
Resolve input path relative to root_path() if the path is not absolute.
std::vector< int > boundary_nodes
list of boundary nodes
Definition State.hpp:427
solver::SolveData solve_data
timedependent stuff cached
Definition State.hpp:324
std::unique_ptr< polysolve::linear::Solver > lin_solver_cached
Definition State.hpp:651
std::shared_ptr< polyfem::mesh::MeshNodes > geom_mesh_nodes
Definition State.hpp:193
void solve_linear(Eigen::MatrixXd &sol, Eigen::MatrixXd &pressure)
solves a linear problem
void init_nonlinear_tensor_solve(Eigen::MatrixXd &sol, const double t=1.0, const bool init_time_integrator=true)
initialize the nonlinear solver
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 StateInit.cpp:65
std::shared_ptr< assembler::ViscousDampingPrev > damping_prev_assembler
Definition State.hpp:165
bool is_contact_enabled() const
does the simulation has contact
Definition State.hpp:551
Eigen::MatrixXd solve_transient_adjoint(const Eigen::MatrixXd &adjoint_rhs) const
void build_collision_mesh()
extracts the boundary mesh for collision, called in build_basis
Definition State.cpp:1364
Eigen::VectorXi disc_orders
vector of discretization orders, used when not all elements have the same degree, one per element
Definition State.hpp:190
void compute_force_jacobian_prev(const int force_step, const int sol_step, StiffnessMatrix &hessian_prev) const
std::vector< mesh::LocalBoundary > local_neumann_boundary
mapping from elements to nodes for neumann boundary conditions
Definition State.hpp:435
std::shared_ptr< assembler::PressureAssembler > build_pressure_assembler() const
Definition State.hpp:256
bool solve_export_to_file
flag to decide if exporting the time dependent solution to files or save it in the solution_frames ar...
Definition State.hpp:577
void solve_transient_linear(const int time_steps, const double t0, const double dt, Eigen::MatrixXd &sol, Eigen::MatrixXd &pressure)
solves transient linear problem
void compute_total_surface_node_ids(std::vector< int > &node_ids) const
std::shared_ptr< assembler::PressureAssembler > elasticity_pressure_assembler
Definition State.hpp:162
void build_mesh_matrices(Eigen::MatrixXd &V, Eigen::MatrixXi &F)
Build the mesh matrices (vertices and elements) from the mesh using the bases node ordering.
void compute_surface_node_ids(const int surface_selection, std::vector< int > &node_ids) const
bool is_problem_linear() const
Returns whether the system is linear. Collisions and pressure add nonlinearity to the problem.
Definition State.hpp:410
std::shared_ptr< assembler::MixedAssembler > mixed_assembler
Definition State.hpp:159
Eigen::MatrixXd initial_sol_update
Definition State.hpp:697
std::map< int, Eigen::MatrixXd > polys
polygons, used since poly have no geom mapping
Definition State.hpp:185
Eigen::MatrixXd rhs
System right-hand side.
Definition State.hpp:207
std::unordered_map< int, std::vector< mesh::LocalBoundary > > local_pressure_cavity
mapping from elements to nodes for pressure boundary conditions
Definition State.hpp:439
void init_homogenization_solve(const double t)
StiffnessMatrix basis_nodes_to_gbasis_nodes
Definition State.hpp:699
static int quadrature_order(const std::string &assembler, const int basis_degree, const BasisType &b_type, const int dim)
utility for retrieving the needed quadrature order to precisely integrate the given form on the given...
Caches basis evaluation and geometric mapping at every element.
Utilies related to export of geometry.
Definition OutData.hpp:45
stores all runtime data
Definition OutData.hpp:365
all stats from polyfem
Definition OutData.hpp:392
void compute_mesh_stats(const polyfem::mesh::Mesh &mesh)
compute stats (counts els type, mesh lenght, etc), step 1 of solve
Definition OutData.cpp:2721
Abstract mesh class to capture 2d/3d conforming and non-conforming meshes.
Definition Mesh.hpp:39
static std::unique_ptr< Mesh > create(const std::string &path, const bool non_conforming=false)
factory to build the proper mesh
Definition Mesh.cpp:173
const Eigen::MatrixXd & adjoint_mat() const
Definition DiffCache.hpp:99
class to store time stepping data
Definition SolveData.hpp:57
Used for test only.
spdlog::logger & logger()
Retrieves the current logger.
Definition Logger.cpp:42
nlohmann::json json
Definition Common.hpp:9
void log_and_throw_adjoint_error(const std::string &msg)
Definition Logger.cpp:77
Eigen::Matrix< double, 1, Eigen::Dynamic, Eigen::RowMajor, 1, 3 > RowVectorNd
Definition Types.hpp:13
Eigen::SparseMatrix< double, Eigen::ColMajor > StiffnessMatrix
Definition Types.hpp:22