PolyFEM
Loading...
Searching...
No Matches
OutData.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <polyfem/Common.hpp>
4
6
8
10
12
13#include <paraviewo/ParaviewWriter.hpp>
14#include <paraviewo/VTUWriter.hpp>
15#include <paraviewo/HDF5VTUWriter.hpp>
16
18
19#include <Eigen/Dense>
20
21namespace polyfem
22{
23 class State;
24}
25
26namespace polyfem::io
27{
30 {
31 public:
32 std::string name;
33 Eigen::MatrixXd points;
34 Eigen::MatrixXi connectivity;
35 Eigen::MatrixXd solution;
36 Eigen::MatrixXd pressure;
37 Eigen::MatrixXd exact;
38 Eigen::MatrixXd error;
39 Eigen::MatrixXd scalar_value;
40 Eigen::MatrixXd scalar_value_avg;
41 };
42
45 {
46 public:
49 {
50 bool volume;
51 bool surface;
52 bool wire;
53 bool points;
56 bool forces;
58
69 bool nodes;
70
73
75
77
83 ExportOptions(const json &args,
84 const bool is_mesh_linear,
85 const bool is_problem_scalar,
86 const bool solve_export_to_file);
87
90 inline std::string file_extension() const { return use_hdf5 ? ".hdf" : ".vtu"; }
91 };
92
102 static void extract_boundary_mesh(
103 const mesh::Mesh &mesh,
104 const int n_bases,
105 const std::vector<basis::ElementBases> &bases,
106 const std::vector<mesh::LocalBoundary> &total_local_boundary,
107 Eigen::MatrixXd &node_positions,
108 Eigen::MatrixXi &boundary_edges,
109 Eigen::MatrixXi &boundary_triangles,
110 std::vector<Eigen::Triplet<double>> &displacement_map_entries);
111
115 void init_sampler(const polyfem::mesh::Mesh &mesh, const double vismesh_rel_area);
116
120 void build_grid(const polyfem::mesh::Mesh &mesh, const double spacing);
121
137 void export_data(
138 const State &state,
139 const Eigen::MatrixXd &sol,
140 const Eigen::MatrixXd &pressure,
141 const bool is_time_dependent,
142 const double tend_in,
143 const double dt,
144 const ExportOptions &opts,
145 const std::string &vis_mesh_path,
146 const std::string &nodes_path,
147 const std::string &solution_path,
148 const std::string &stress_path,
149 const std::string &mises_path,
150 const bool is_contact_enabled,
151 std::vector<SolutionFrame> &solution_frames) const;
152
163 void save_vtu(const std::string &path,
164 const State &state,
165 const Eigen::MatrixXd &sol,
166 const Eigen::MatrixXd &pressure,
167 const double t,
168 const double dt,
169 const ExportOptions &opts,
170 const bool is_contact_enabled,
171 std::vector<SolutionFrame> &solution_frames) const;
172
182 void save_volume(const std::string &path,
183 const State &state,
184 const Eigen::MatrixXd &sol,
185 const Eigen::MatrixXd &pressure,
186 const double t,
187 const double dt,
188 const ExportOptions &opts,
189 std::vector<SolutionFrame> &solution_frames) const;
190
201 void save_surface(const std::string &export_surface,
202 const State &state,
203 const Eigen::MatrixXd &sol,
204 const Eigen::MatrixXd &pressure,
205 const double t,
206 const double dt_in,
207 const ExportOptions &opts,
208 const bool is_contact_enabled,
209 std::vector<SolutionFrame> &solution_frames) const;
210
222 const std::string &export_surface,
223 const State &state,
224 const Eigen::MatrixXd &sol,
225 const Eigen::MatrixXd &pressure,
226 const double t,
227 const double dt_in,
228 const ExportOptions &opts,
229 const bool is_contact_enabled,
230 std::vector<SolutionFrame> &solution_frames) const;
231
239 void save_wire(const std::string &name,
240 const State &state,
241 const Eigen::MatrixXd &sol,
242 const double t,
243 const ExportOptions &opts,
244 std::vector<SolutionFrame> &solution_frames) const;
245
252 void save_points(
253 const std::string &path,
254 const State &state,
255 const Eigen::MatrixXd &sol,
256 const ExportOptions &opts,
257 std::vector<SolutionFrame> &solution_frames) const;
258
266 void save_pvd(const std::string &name, const std::function<std::string(int)> &vtu_names,
267 int time_steps, double t0, double dt, int skip_frame = 1) const;
268
269 private:
272
274 Eigen::MatrixXd grid_points;
276 Eigen::MatrixXi grid_points_to_elements;
278 Eigen::MatrixXd grid_points_bc;
279
295 const mesh::Mesh &mesh,
296 const std::vector<basis::ElementBases> &bases,
297 const std::vector<basis::ElementBases> &gbases,
298 const std::vector<mesh::LocalBoundary> &total_local_boundary,
299 const Eigen::MatrixXd &solution,
300 const int problem_dim,
301 Eigen::MatrixXd &boundary_vis_vertices,
302 Eigen::MatrixXd &boundary_vis_local_vertices,
303 Eigen::MatrixXi &boundary_vis_elements,
304 Eigen::MatrixXi &boundary_vis_elements_ids,
305 Eigen::MatrixXi &boundary_vis_primitive_ids,
306 Eigen::MatrixXd &boundary_vis_normals,
307 Eigen::MatrixXd &displaced_boundary_vis_normals) const;
308
323 void build_vis_mesh(
324 const mesh::Mesh &mesh,
325 const Eigen::VectorXi &disc_orders,
326 const std::vector<basis::ElementBases> &gbases,
327 const std::map<int, Eigen::MatrixXd> &polys,
328 const std::map<int, std::pair<Eigen::MatrixXd, Eigen::MatrixXi>> &polys_3d,
329 const bool boundary_only,
330 Eigen::MatrixXd &points,
331 Eigen::MatrixXi &tets,
332 Eigen::MatrixXi &el_id,
333 Eigen::MatrixXd &discr) const;
334
346 const mesh::Mesh &mesh,
347 const Eigen::VectorXi &disc_orders,
348 const std::vector<basis::ElementBases> &bases,
349 Eigen::MatrixXd &points,
350 std::vector<std::vector<int>> &elements,
351 Eigen::MatrixXi &el_id,
352 Eigen::MatrixXd &discr) const;
353
355 const State &state,
356 const Eigen::MatrixXd &points,
357 const ExportOptions &opts,
358 const std::string &name,
359 const Eigen::VectorXd &field,
360 paraviewo::ParaviewWriter &writer) const;
361 };
362
389
392 {
393 public:
395 Eigen::Vector4d spectrum;
396
400
402 double mesh_size;
407
410
414
416 double max_angle;
419
422
443
452 void compute_errors(const int n_bases,
453 const std::vector<polyfem::basis::ElementBases> &bases,
454 const std::vector<polyfem::basis::ElementBases> &gbases,
455 const polyfem::mesh::Mesh &mesh,
456 const assembler::Problem &problem,
457 const double tend,
458 const Eigen::MatrixXd &sol);
459
462 void compute_mesh_stats(const polyfem::mesh::Mesh &mesh);
463
471 void compute_mesh_size(const polyfem::mesh::Mesh &mesh_in, const std::vector<polyfem::basis::ElementBases> &bases_in, const int n_samples, const bool use_curved_mesh_size);
472
474 void reset();
475
479 void count_flipped_elements(const polyfem::mesh::Mesh &mesh, const std::vector<polyfem::basis::ElementBases> &gbases);
480
483
497 void save_json(const nlohmann::json &args,
498 const int n_bases, const int n_pressure_bases,
499 const Eigen::MatrixXd &sol,
500 const mesh::Mesh &mesh,
501 const Eigen::VectorXi &disc_orders,
502 const assembler::Problem &problem,
503 const OutRuntimeData &runtime,
504 const std::string &formulation,
505 const bool isoparametric,
506 const int sol_at_node_id,
507 nlohmann::json &j);
508 };
509
511 {
512 public:
513 EnergyCSVWriter(const std::string &path, const solver::SolveData &solve_data);
515
516 void write(const int i, const Eigen::MatrixXd &sol);
517
518 protected:
519 std::ofstream file;
521 };
522
524 {
525 public:
526 RuntimeStatsCSVWriter(const std::string &path, const State &state, const double t0, const double dt);
528
529 void write(const int t, const double forward, const double remeshing, const double global_relaxation, const Eigen::MatrixXd &sol);
530
531 protected:
532 std::ofstream file;
533 const State &state;
534 const double t0;
535 const double dt;
539 };
540} // namespace polyfem::io
main class that contains the polyfem solver and all its state
Definition State.hpp:79
const solver::SolveData & solve_data
Definition OutData.hpp:520
void write(const int i, const Eigen::MatrixXd &sol)
Definition OutData.cpp:2943
Utilies related to export of geometry.
Definition OutData.hpp:45
void build_vis_mesh(const mesh::Mesh &mesh, const Eigen::VectorXi &disc_orders, const std::vector< basis::ElementBases > &gbases, const std::map< int, Eigen::MatrixXd > &polys, const std::map< int, std::pair< Eigen::MatrixXd, Eigen::MatrixXi > > &polys_3d, const bool boundary_only, Eigen::MatrixXd &points, Eigen::MatrixXi &tets, Eigen::MatrixXi &el_id, Eigen::MatrixXd &discr) const
builds visualzation mesh, upsampled mesh used for visualization the visualization mesh is a dense mes...
Definition OutData.cpp:645
void build_high_order_vis_mesh(const mesh::Mesh &mesh, const Eigen::VectorXi &disc_orders, const std::vector< basis::ElementBases > &bases, Eigen::MatrixXd &points, std::vector< std::vector< int > > &elements, Eigen::MatrixXi &el_id, Eigen::MatrixXd &discr) const
builds high-der visualzation mesh per element all disconnected it also retuns the mapping to element ...
Definition OutData.cpp:788
void save_points(const std::string &path, const State &state, const Eigen::MatrixXd &sol, const ExportOptions &opts, std::vector< SolutionFrame > &solution_frames) const
saves the nodal values
Definition OutData.cpp:2261
void save_volume_vector_field(const State &state, const Eigen::MatrixXd &points, const ExportOptions &opts, const std::string &name, const Eigen::VectorXd &field, paraviewo::ParaviewWriter &writer) const
Definition OutData.cpp:1751
Eigen::MatrixXd grid_points_bc
grid mesh boundaries
Definition OutData.hpp:278
Eigen::MatrixXd grid_points
grid mesh points to export solution sampled on a grid
Definition OutData.hpp:274
void save_wire(const std::string &name, const State &state, const Eigen::MatrixXd &sol, const double t, const ExportOptions &opts, std::vector< SolutionFrame > &solution_frames) const
saves the wireframe
Definition OutData.cpp:2073
void save_surface(const std::string &export_surface, const State &state, const Eigen::MatrixXd &sol, const Eigen::MatrixXd &pressure, const double t, const double dt_in, const ExportOptions &opts, const bool is_contact_enabled, std::vector< SolutionFrame > &solution_frames) const
saves the surface vtu file for for surface quantites, eg traction forces
Definition OutData.cpp:1780
void build_vis_boundary_mesh(const mesh::Mesh &mesh, const std::vector< basis::ElementBases > &bases, const std::vector< basis::ElementBases > &gbases, const std::vector< mesh::LocalBoundary > &total_local_boundary, const Eigen::MatrixXd &solution, const int problem_dim, Eigen::MatrixXd &boundary_vis_vertices, Eigen::MatrixXd &boundary_vis_local_vertices, Eigen::MatrixXi &boundary_vis_elements, Eigen::MatrixXi &boundary_vis_elements_ids, Eigen::MatrixXi &boundary_vis_primitive_ids, Eigen::MatrixXd &boundary_vis_normals, Eigen::MatrixXd &displaced_boundary_vis_normals) const
builds the boundary mesh for visualization
Definition OutData.cpp:397
void build_grid(const polyfem::mesh::Mesh &mesh, const double spacing)
builds the grid to export the solution
Definition OutData.cpp:2330
void save_volume(const std::string &path, const State &state, const Eigen::MatrixXd &sol, const Eigen::MatrixXd &pressure, const double t, const double dt, const ExportOptions &opts, std::vector< SolutionFrame > &solution_frames) const
saves the volume vtu file
Definition OutData.cpp:1197
static void extract_boundary_mesh(const mesh::Mesh &mesh, const int n_bases, const std::vector< basis::ElementBases > &bases, const std::vector< mesh::LocalBoundary > &total_local_boundary, Eigen::MatrixXd &node_positions, Eigen::MatrixXi &boundary_edges, Eigen::MatrixXi &boundary_triangles, std::vector< Eigen::Triplet< double > > &displacement_map_entries)
extracts the boundary mesh
Definition OutData.cpp:145
void save_pvd(const std::string &name, const std::function< std::string(int)> &vtu_names, int time_steps, double t0, double dt, int skip_frame=1) const
save a PVD of a time dependent simulation
Definition OutData.cpp:2317
void export_data(const State &state, const Eigen::MatrixXd &sol, const Eigen::MatrixXd &pressure, const bool is_time_dependent, const double tend_in, const double dt, const ExportOptions &opts, const std::string &vis_mesh_path, const std::string &nodes_path, const std::string &solution_path, const std::string &stress_path, const std::string &mises_path, const bool is_contact_enabled, std::vector< SolutionFrame > &solution_frames) const
exports everytihng, txt, vtu, etc
Definition OutData.cpp:940
void save_vtu(const std::string &path, const State &state, const Eigen::MatrixXd &sol, const Eigen::MatrixXd &pressure, const double t, const double dt, const ExportOptions &opts, const bool is_contact_enabled, std::vector< SolutionFrame > &solution_frames) const
saves the vtu file for time t
Definition OutData.cpp:1114
void save_contact_surface(const std::string &export_surface, const State &state, const Eigen::MatrixXd &sol, const Eigen::MatrixXd &pressure, const double t, const double dt_in, const ExportOptions &opts, const bool is_contact_enabled, std::vector< SolutionFrame > &solution_frames) const
saves the surface vtu file for for constact quantites, eg contact or friction forces
Definition OutData.cpp:1979
void init_sampler(const polyfem::mesh::Mesh &mesh, const double vismesh_rel_area)
unitalize the ref element sampler
Definition OutData.cpp:2325
Eigen::MatrixXi grid_points_to_elements
grid mesh mapping to fe elements
Definition OutData.hpp:276
utils::RefElementSampler ref_element_sampler
used to sample the solution
Definition OutData.hpp:271
stores all runtime data
Definition OutData.hpp:365
double loading_mesh_time
time to load the mesh
Definition OutData.hpp:370
double total_time()
computes total time
Definition OutData.hpp:384
double assembling_stiffness_mat_time
time to assembly
Definition OutData.hpp:374
double assigning_rhs_time
time to computing the rhs
Definition OutData.hpp:378
double assembling_mass_mat_time
time to assembly mass
Definition OutData.hpp:376
double building_basis_time
time to construct the basis
Definition OutData.hpp:368
double solving_time
time to solve
Definition OutData.hpp:380
double computing_poly_basis_time
time to build the polygonal/polyhedral bases
Definition OutData.hpp:372
all stats from polyfem
Definition OutData.hpp:392
void save_json(const nlohmann::json &args, const int n_bases, const int n_pressure_bases, const Eigen::MatrixXd &sol, const mesh::Mesh &mesh, const Eigen::VectorXi &disc_orders, const assembler::Problem &problem, const OutRuntimeData &runtime, const std::string &formulation, const bool isoparametric, const int sol_at_node_id, nlohmann::json &j)
saves the output statistic to a json object
Definition OutData.cpp:2793
int n_flipped
number of flipped elements, compute only when using count_flipped_els (false by default)
Definition OutData.hpp:421
int simplex_count
statiscs on the mesh (simplices)
Definition OutData.hpp:424
json solver_info
information of the solver, eg num iteration, time, errors, etc the informations varies depending on t...
Definition OutData.hpp:399
int simple_singular_count
statiscs on the mesh (irregular quad/hex part of the mesh), see Polyspline paper for desciption
Definition OutData.hpp:430
Eigen::Vector4d spectrum
spectrum of the stiffness matrix, enable only if POLYSOLVE_WITH_SPECTRA is ON (off by default)
Definition OutData.hpp:395
void count_flipped_elements(const polyfem::mesh::Mesh &mesh, const std::vector< polyfem::basis::ElementBases > &gbases)
counts the number of flipped elements
Definition OutData.cpp:2515
double l2_err
errors, lp_err is in fact an L8 error
Definition OutData.hpp:409
int undefined_count
statiscs on the mesh (not quad/hex simplex), see Polyspline paper for desciption
Definition OutData.hpp:440
void compute_errors(const int n_bases, const std::vector< polyfem::basis::ElementBases > &bases, const std::vector< polyfem::basis::ElementBases > &gbases, const polyfem::mesh::Mesh &mesh, const assembler::Problem &problem, const double tend, const Eigen::MatrixXd &sol)
compute errors
Definition OutData.cpp:2560
void compute_mesh_size(const polyfem::mesh::Mesh &mesh_in, const std::vector< polyfem::basis::ElementBases > &bases_in, const int n_samples, const bool use_curved_mesh_size)
computes the mesh size, it samples every edges n_samples times uses curved_mesh_size (false by defaul...
Definition OutData.cpp:2428
double average_edge_length
avg edge lenght
Definition OutData.hpp:406
double max_angle
statiscs on angle, compute only when using p_ref (false by default)
Definition OutData.hpp:416
int non_regular_boundary_count
statiscs on the mesh (irregular boundary quad/hex part of the mesh), see Polyspline paper for descipt...
Definition OutData.hpp:436
int non_regular_count
statiscs on the mesh (irregular quad/hex part of the mesh), see Polyspline paper for desciption
Definition OutData.hpp:438
int regular_boundary_count
statiscs on the mesh (regular quad/hex boundary part of the mesh), see Polyspline paper for desciptio...
Definition OutData.hpp:428
long long nn_zero
non zeros and sytem matrix size num dof is the total dof in the system
Definition OutData.hpp:413
double mesh_size
max edge lenght
Definition OutData.hpp:402
void reset()
clears all stats
Definition OutData.cpp:2506
int multi_singular_boundary_count
statiscs on the mesh (irregular boundary quad/hex part of the mesh), see Polyspline paper for descipt...
Definition OutData.hpp:442
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
double sigma_max
statiscs on tri/tet quality, compute only when using p_ref (false by default)
Definition OutData.hpp:418
int boundary_count
statiscs on the mesh (boundary quads/hexs), see Polyspline paper for desciption
Definition OutData.hpp:434
int regular_count
statiscs on the mesh (regular quad/hex part of the mesh), see Polyspline paper for desciption
Definition OutData.hpp:426
double min_edge_length
min edge lenght
Definition OutData.hpp:404
int multi_singular_count
statiscs on the mesh (irregular quad/hex part of the mesh), see Polyspline paper for desciption
Definition OutData.hpp:432
void write(const int t, const double forward, const double remeshing, const double global_relaxation, const Eigen::MatrixXd &sol)
Definition OutData.cpp:2969
class used to save the solution of time dependent problems in code instead of saving it to the disc
Definition OutData.hpp:30
Eigen::MatrixXi connectivity
Definition OutData.hpp:34
Eigen::MatrixXd scalar_value_avg
Definition OutData.hpp:40
Eigen::MatrixXd solution
Definition OutData.hpp:35
Eigen::MatrixXd exact
Definition OutData.hpp:37
Eigen::MatrixXd scalar_value
Definition OutData.hpp:39
Eigen::MatrixXd error
Definition OutData.hpp:38
Eigen::MatrixXd points
Definition OutData.hpp:33
Eigen::MatrixXd pressure
Definition OutData.hpp:36
Abstract mesh class to capture 2d/3d conforming and non-conforming meshes.
Definition Mesh.hpp:39
class to store time stepping data
Definition SolveData.hpp:57
nlohmann::json json
Definition Common.hpp:9
std::string file_extension() const
return the extension of the output paraview files depending on use_hdf5
Definition OutData.hpp:90