Continuum Membrane 719025a62b1e384a6ff80e2f2a223ef4012153dc
Loading...
Searching...
No Matches
io.hpp
Go to the documentation of this file.
1
12#pragma once
13
14#include <fstream>
15#include <sstream>
16#include <iostream>
17#include <stdlib.h>
18#include <string>
19#include <vector>
20#include <stdexcept>
21#include <sys/stat.h>
22
23#include "mesh/Mesh.hpp"
24#include "model/Record.hpp"
25#include "model/Model.hpp"
26#include "mesh/Vertex.hpp"
27#include "Parameters.hpp"
29#include "Dynamics.hpp"
30
40std::string pop_space(std::string rawString);
41
42std::string trim_trailing_semicolon(std::string rawString);
43
57bool import_kv_string(std::string variableNameStr, std::string variableValueStr, Param& param);
58
70bool import_param_file(Param& param, std::string filepath);
71
86template <typename T>
87std::vector<std::vector<T>> read_data_from_csv(const std::string& filepath, char separator = ',') {
88 // Open and read CSV file
89 std::ifstream csvFile(filepath);
90 if (!csvFile.is_open()) {
91 // Handle error: Unable to open CSV file
92 throw std::invalid_argument("Unable to open CSV file.");
93 }
94
95 // Data structure to store data
96 std::vector<std::vector<T>> data;
97
98 // Read each line from the CSV file
99 std::string line;
100 while (std::getline(csvFile, line)) {
101 std::vector<T> row;
102 std::istringstream iss(line);
103 std::string value;
104
105 // Parse the line using the specified separator
106 while (std::getline(iss, value, separator)) {
107 try {
108 T typedValue = static_cast<T>(std::stod(value));
109 row.push_back(typedValue);
110 } catch (const std::invalid_argument& e) {
111 // Handle error: Unable to convert to the specified data type
112 csvFile.close(); // Close CSV file before throwing exception
113 throw std::invalid_argument("Unable to convert data to the specified data type.");
114 }
115 }
116
117 // Add the row to the data vector
118 data.push_back(row);
119 }
120
121 // Close the CSV file
122 csvFile.close();
123
124 return data;
125}
126
137bool import_mesh_from_vertices_faces(Mesh& mesh, std::string verticesFilepath, std::string facesFilepath);
138
149std::vector<Matrix> import_scaffolding_mesh(std::string filepath);
150
170void write_vertex_data_to_csv(const Mesh &mesh, const int iteration)
171__attribute__((deprecated("Use Mesh::write_vertex_data_to_csv instead.")));
172
185void write_energy_force_data_to_csv(const Model &model);
186
194bool write_model_restart_checkpoint(const Model &model,
195 const std::string &filepath,
196 const int nextIteration);
197
201bool load_model_restart_checkpoint(Model &model, const std::string &filepath);
202
217void write_element_face_energy_to_csv(const Model &model);
218
235void write_final_vertex_data_to_csv(const Mesh &mesh);
236
244void dynamics_create_trajectory_files(DynamicMesh &mesh, const std::string &filename);
245
252void output_trajectory_files(Mesh &mesh, const std::string &input_filename);
253
263void dynamics_output_trajectory_files(DynamicMesh &mesh, const std::string &filename);
This file defines dynamic mesh class that inherits mesh with support of time-resolved dynamics.
This file defines mesh class containing a vector of vertices and a vector of faces that are required ...
Contains the Model class, which encapsulates a mesh and a record object.
This file defines essential parameters used in continuum membrane as well as membrane dynamics code....
This file defines the Vertex class which includes information of coordinate and forces exerted at a v...
A class representing a dynamic mesh.
Definition Dynamics.hpp:44
A class representing a triangular mesh that defines a limit surface.
Definition Mesh.hpp:54
The Model class encapsulates a Mesh and a Record object.
Definition Model.hpp:94
bool import_param_file(Param &param, std::string filepath)
Import parameters from a file.
bool import_kv_string(std::string variableNameStr, std::string variableValueStr, Param &param)
Import key-value pairs from a string.
std::string pop_space(std::string rawString)
Remove spaces from a string.
std::string trim_trailing_semicolon(std::string rawString)
bool import_mesh_from_vertices_faces(Mesh &mesh, std::string verticesFilepath, std::string facesFilepath)
Import a mesh from separate files containing vertices and faces.
std::vector< std::vector< T > > read_data_from_csv(const std::string &filepath, char separator=',')
Read data from a CSV file and store it in a vector of vectors with the specified data type.
Definition io.hpp:87
std::vector< Matrix > import_scaffolding_mesh(std::string filepath)
Import scaffolding mesh from a file.
Contains simulation parameters and physical constants.
Definition Parameters.hpp:117