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
13
14#include <paraviewo/ParaviewWriter.hpp>
15#include <paraviewo/VTUWriter.hpp>
16#include <paraviewo/HDF5VTUWriter.hpp>
17
19
20#include <Eigen/Dense>
21
22#include <ipc/potentials/normal_adhesion_potential.hpp>
23#include <ipc/potentials/tangential_adhesion_potential.hpp>
24
25namespace polyfem::legacy
26{
27 class State;
28} // namespace polyfem::legacy
29
30namespace polyfem::legacy::io
31{
34
37 {
38 public:
41 {
42 std::vector<std::string> fields; // fields to export, empty means all
43
44 bool volume;
45 bool surface;
46 bool wire;
47 bool points;
52 bool forces;
54
65 bool nodes;
66
69
71
77 ExportOptions(const json &args,
78 const bool is_mesh_linear,
79 const bool mesh_has_prisms,
80 const bool is_problem_scalar);
81
84 inline std::string file_extension() const
85 {
86 return use_hdf5 ? ".hdf" : ".vtu";
87 }
88
89 bool export_field(const std::string &field) const;
90 };
91
101 static void extract_boundary_mesh(
102 const mesh::Mesh &mesh,
103 const int n_bases,
104 const std::vector<basis::ElementBases> &bases,
105 const std::vector<mesh::LocalBoundary> &total_local_boundary,
106 Eigen::MatrixXd &node_positions,
107 Eigen::MatrixXi &boundary_edges,
108 Eigen::MatrixXi &boundary_triangles,
109 std::vector<Eigen::Triplet<double>> &displacement_map_entries);
110
114 void init_sampler(const polyfem::mesh::Mesh &mesh, const double vismesh_rel_area);
115
119 void build_grid(const polyfem::mesh::Mesh &mesh, const double spacing);
120
135 void export_data(
136 const State &state,
137 const Eigen::MatrixXd &sol,
138 const Eigen::MatrixXd &pressure,
139 const bool is_time_dependent,
140 const double tend_in,
141 const double dt,
142 const ExportOptions &opts,
143 const std::string &vis_mesh_path,
144 const std::string &nodes_path,
145 const std::string &solution_path,
146 const std::string &stress_path,
147 const std::string &mises_path,
148 const bool is_contact_enabled) const;
149
159 void save_vtu(const std::string &path,
160 const State &state,
161 const Eigen::MatrixXd &sol,
162 const Eigen::MatrixXd &pressure,
163 const double t,
164 const double dt,
165 const ExportOptions &opts,
166 const bool is_contact_enabled) const;
167
176 void save_volume(const std::string &path,
177 const State &state,
178 const Eigen::MatrixXd &sol,
179 const Eigen::MatrixXd &pressure,
180 const double t,
181 const double dt,
182 const ExportOptions &opts) const;
183
193 void save_surface(const std::string &export_surface,
194 const State &state,
195 const Eigen::MatrixXd &sol,
196 const Eigen::MatrixXd &pressure,
197 const double t,
198 const double dt_in,
199 const ExportOptions &opts,
200 const bool is_contact_enabled) const;
201
212 const std::string &export_surface,
213 const State &state,
214 const Eigen::MatrixXd &sol,
215 const Eigen::MatrixXd &pressure,
216 const double t,
217 const double dt_in,
218 const ExportOptions &opts,
219 const bool is_contact_enabled) const;
220
227 void save_wire(const std::string &name,
228 const State &state,
229 const Eigen::MatrixXd &sol,
230 const double t,
231 const ExportOptions &opts) const;
232
238 void save_points(
239 const std::string &path,
240 const State &state,
241 const Eigen::MatrixXd &sol,
242 const ExportOptions &opts) const;
243
251 void save_pvd(const std::string &name, const std::function<std::string(int)> &vtu_names,
252 int time_steps, double t0, double dt, int skip_frame = 1) const;
253
254 private:
257
259 Eigen::MatrixXd grid_points;
261 Eigen::MatrixXi grid_points_to_elements;
263 Eigen::MatrixXd grid_points_bc;
264
280 const mesh::Mesh &mesh,
281 const std::vector<basis::ElementBases> &bases,
282 const std::vector<basis::ElementBases> &gbases,
283 const std::vector<mesh::LocalBoundary> &total_local_boundary,
284 const Eigen::MatrixXd &solution,
285 const int problem_dim,
286 Eigen::MatrixXd &boundary_vis_vertices,
287 Eigen::MatrixXd &boundary_vis_local_vertices,
288 Eigen::MatrixXi &boundary_vis_elements,
289 Eigen::MatrixXi &boundary_vis_elements_ids,
290 Eigen::MatrixXi &boundary_vis_primitive_ids,
291 Eigen::MatrixXd &boundary_vis_normals,
292 Eigen::MatrixXd &displaced_boundary_vis_normals) const;
293
308 void build_vis_mesh(
309 const mesh::Mesh &mesh,
310 const Eigen::VectorXi &disc_orders,
311 const std::vector<basis::ElementBases> &gbases,
312 const std::map<int, Eigen::MatrixXd> &polys,
313 const std::map<int, std::pair<Eigen::MatrixXd, Eigen::MatrixXi>> &polys_3d,
314 const bool boundary_only,
315 Eigen::MatrixXd &points,
316 Eigen::MatrixXi &tets,
317 Eigen::MatrixXi &el_id,
318 Eigen::MatrixXd &discr) const;
319
332 const mesh::Mesh &mesh,
333 const Eigen::VectorXi &disc_orders,
334 const Eigen::VectorXi &disc_ordersq,
335 const std::vector<basis::ElementBases> &bases,
336 Eigen::MatrixXd &points,
337 std::vector<paraviewo::CellElement> &elements,
338 Eigen::MatrixXi &el_id,
339 Eigen::MatrixXd &discr) const;
340
342 const State &state,
343 const Eigen::MatrixXd &points,
344 const ExportOptions &opts,
345 const std::string &name,
346 const Eigen::VectorXd &field,
347 paraviewo::ParaviewWriter &writer) const;
348 };
349
351 {
352 public:
353 EnergyCSVWriter(const std::string &path, const solver::SolveData &solve_data);
355
356 void write(const int i, const Eigen::MatrixXd &sol);
357
358 protected:
359 std::ofstream file;
361 };
362
364 {
365 public:
366 RuntimeStatsCSVWriter(const std::string &path, const State &state, const double t0, const double dt);
368
369 void write(const int t, const double forward, const double remeshing, const double global_relaxation, const Eigen::MatrixXd &sol);
370
371 protected:
372 std::ofstream file;
373 const State &state;
374 const double t0;
375 const double dt;
379 };
380} // namespace polyfem::legacy::io
timers from polyfem.
all stats from polyfem
main class that contains the polyfem solver and all its state
Definition State.hpp:114
void write(const int i, const Eigen::MatrixXd &sol)
Definition OutData.cpp:2896
const solver::SolveData & solve_data
Definition OutData.hpp:360
Utilies related to export of geometry.
Definition OutData.hpp:37
utils::RefElementSampler ref_element_sampler
used to sample the solution
Definition OutData.hpp:256
void build_high_order_vis_mesh(const mesh::Mesh &mesh, const Eigen::VectorXi &disc_orders, const Eigen::VectorXi &disc_ordersq, const std::vector< basis::ElementBases > &bases, Eigen::MatrixXd &points, std::vector< paraviewo::CellElement > &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 ...
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:2769
Eigen::MatrixXd grid_points_bc
grid mesh boundaries
Definition OutData.hpp:263
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) const
exports everytihng, txt, vtu, etc
Definition OutData.cpp:1205
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) const
saves the vtu file for time t
Definition OutData.cpp:1390
void save_wire(const std::string &name, const State &state, const Eigen::MatrixXd &sol, const double t, const ExportOptions &opts) const
saves the wireframe
Definition OutData.cpp:2489
void save_points(const std::string &path, const State &state, const Eigen::MatrixXd &sol, const ExportOptions &opts) const
saves the nodal values
Definition OutData.cpp:2715
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:2077
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) const
saves the volume vtu file
Definition OutData.cpp:1474
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:551
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:813
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) const
saves the surface vtu file for for constact quantites, eg contact or friction forces
Definition OutData.cpp:2298
Eigen::MatrixXi grid_points_to_elements
grid mesh mapping to fe elements
Definition OutData.hpp:261
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:151
void build_grid(const polyfem::mesh::Mesh &mesh, const double spacing)
builds the grid to export the solution
Definition OutData.cpp:2782
void init_sampler(const polyfem::mesh::Mesh &mesh, const double vismesh_rel_area)
unitalize the ref element sampler
Definition OutData.cpp:2777
Eigen::MatrixXd grid_points
grid mesh points to export solution sampled on a grid
Definition OutData.hpp:259
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) const
saves the surface vtu file for for surface quantites, eg traction forces
Definition OutData.cpp:2102
void write(const int t, const double forward, const double remeshing, const double global_relaxation, const Eigen::MatrixXd &sol)
Definition OutData.cpp:2922
Abstract mesh class to capture 2d/3d conforming and non-conforming meshes.
Definition Mesh.hpp:41
class to store time stepping data
Definition SolveData.hpp:59
polyfem::legacy::State State
Definition Remesher.hpp:19
nlohmann::json json
Definition Common.hpp:9
bool export_field(const std::string &field) const
Definition OutData.cpp:1347
std::string file_extension() const
return the extension of the output paraview files depending on use_hdf5
Definition OutData.hpp:84