G+Smo  25.01.0
Geometry + Simulation Modules
 
Loading...
Searching...
No Matches
gsParaviewDataSet.h
Go to the documentation of this file.
1
14#pragma once
15
17#include <gsMSplines/gsMappedBasis.h> // Only to make linker happy
18#include <gsCore/gsDofMapper.h> // Only to make linker happy
21#include <gsIO/gsIOUtils.h>
23
24#include<fstream>
25
26namespace gismo
27{
37class GISMO_EXPORT gsParaviewDataSet // a collection of .vts files
38{
39private:
40 std::string m_basename;
41 std::vector<std::string> m_filenames;
42 const gsMultiPatch<real_t> * m_geometry;
43 gsExprEvaluator<real_t> * m_evaltr;
44 gsOptionList m_options;
45 bool m_isSaved;
46
47public:
53 gsParaviewDataSet(std::string basename,
54 gsMultiPatch<real_t> * const geometry,
55 gsExprEvaluator<real_t> * eval=nullptr,
56 gsOptionList options=defaultOptions());
57
58 gsParaviewDataSet():m_basename(""),
59 m_geometry(nullptr),
60 m_evaltr(nullptr),
61 m_options(defaultOptions()),
62 m_isSaved(false)
63 {}
64
69 template <class E>
70 void addField(const expr::_expr<E>& expr, std::string label) {
71 GISMO_ENSURE(!m_isSaved,
72 "You cannot add more fields if the gsParaviewDataSet has "
73 "been saved.");
74 // evaluates the expression and appends it to the vts files
75 // for every patch
76 const unsigned nPts = m_options.askInt("numPoints", 1000);
77 const unsigned precision = m_options.askInt("precision", 5);
78 const bool export_base64 = m_options.askSwitch("base64", false);
79
80 // gsExprEvaluator<real_t> ev;
81 // gsMultiBasis<real_t> mb(*m_geometry);
82 // ev.setIntegrationElements(mb);
83 const std::vector<std::string> tags =
84 toVTK(expr, m_evaltr, nPts, precision, label, export_base64);
85 std::vector<std::string> fnames = filenames();
86
87 for (index_t k = 0; k != m_geometry->nPieces();
88 k++) // For every patch.
89 {
90 std::ofstream file;
91 file.open(fnames[k].c_str(), std::ios_base::app); // Append to file
92 file << tags[k];
93 file.close();
94 }
95 }
96
97 // Just here to stop the recursion
98 void addFields(std::vector<std::string>){ }
99
100
107 template <class E, typename... Rest>
108 void addFields(std::vector<std::string> labels, const expr::_expr<E> & expr, Rest... rest) {
109 // keep all but first label
110 GISMO_ENSURE( sizeof...(Rest) == labels.size() - 1, "The length of labels must match the number of expressions provided" );
111 std::vector<std::string> newlabels(labels.cbegin()+1, labels.cend());
112
113
114 addField( expr, labels[0]); // Add the expression 'expr' with it's corresponding label ( first one )
115 addFields( newlabels, rest...); // Recursion
116 }
117
123 template <class T>
124 void addField(const gsField<T> field, std::string label) {
125 GISMO_ENSURE(!m_isSaved,
126 "You cannot add more fields if the gsParaviewDataSet has "
127 "been saved.");
129 (field.parDim() == m_geometry->domainDim() &&
130 field.geoDim() == m_geometry->targetDim() &&
131 field.nPieces() == m_geometry->nPieces() &&
132 field.patches().coefsSize() == m_geometry->coefsSize()),
133 "Provided gsField and stored geometry are not compatible!");
134 // evaluates the field and appends it to the vts files
135 // for every patch
136 const unsigned nPts = m_options.askInt("numPoints", 1000);
137 const unsigned precision = m_options.askInt("precision", 5);
138 const bool export_base64 = m_options.askSwitch("base64", false);
139
140 const std::vector<std::string> tags =
141 toVTK(field, nPts, precision, label, export_base64);
142 const std::vector<std::string> fnames = filenames();
143
144 for (index_t k = 0; k != m_geometry->nPieces();
145 k++) // For every patch.
146 {
147 std::ofstream file;
148 file.open(fnames[k].c_str(), std::ios_base::app); // Append to file
149 file << tags[k];
150 file.close();
151 }
152 }
153
160 template <class T, typename... Rest>
161 void addFields(std::vector<std::string> labels, const gsField<T> field, Rest... rest) {
162 // keep all but first label
163 std::vector<std::string> newlabels(labels.cbegin()+1, labels.cend());
164
165 addField( field, labels[0]); // Add the expression 'expr' with it's corresponding label ( first one )
166 addFields( newlabels, rest...); // Recursion
167 }
168
171 const std::vector<std::string> filenames();
172
173 void save();
174
175 bool isEmpty();
176
177 bool isSaved();
178
181 {
182 gsOptionList opt;
183 opt.addInt("numPoints", "Number of points per-patch.", 1000);
184 opt.addInt("precision", "Number of decimal digits.", 5);
185 opt.addInt("plotElements.resolution", "Drawing resolution for element mesh.", -1);
186 opt.addSwitch("makeSubfolder", "Export vtk files to subfolder ( below the .pvd file ).", true);
187 opt.addSwitch("base64", "Export in base64 binary format", false);
188 opt.addString("subfolder","Name of subfolder where the vtk files will be stored.", "");
189 opt.addSwitch("plotElements", "Controls plotting of element mesh.", false);
190 opt.addSwitch("plotControlNet", "Controls plotting of control point grid.", false);
191 return opt;
192 }
193
194 gsOptionList & options() {return m_options;}
195
196private:
197
198 void initFilenames();
199};
200} // End namespace gismo
Generic evaluator of isogeometric expressions.
Definition gsExprEvaluator.h:39
A scalar of vector field defined on a m_parametric geometry.
Definition gsField.h:55
int nPieces() const
Returns the number of pieces.
Definition gsField.h:200
short_t geoDim() const
Returns the dimension of the physical domain (e.g., if the domain is a surface in three-dimensional s...
Definition gsField.h:190
short_t parDim() const
Returns the dimension of the parameter domain (e.g., if the domain is a surface in three-dimensional ...
Definition gsField.h:186
const gsMultiPatch< T > & patches() const
Returns gsMultiPatch containing the geometric information on the domain.
Definition gsField.h:210
Container class for a set of geometry patches and their topology, that is, the interface connections ...
Definition gsMultiPatch.h:100
short_t targetDim() const
Dimension of the target space.
Definition gsMultiPatch.h:258
index_t nPieces() const
Number of pieces in the domain of definition.
Definition gsMultiPatch.h:193
short_t domainDim() const
Dimension of the (source) domain.
Definition gsMultiPatch.h:254
index_t coefsSize() const
Return the number of coefficients (control points)
Definition gsMultiPatch.h:198
Class which holds a list of parameters/options, and provides easy access to them.
Definition gsOptionList.h:33
void addInt(const std::string &label, const std::string &desc, const index_t &value)
Adds a option named label, with description desc and value value.
Definition gsOptionList.cpp:201
bool askSwitch(const std::string &label, const bool &value=false) const
Reads value for option label from options.
Definition gsOptionList.cpp:128
index_t askInt(const std::string &label, const index_t &value=0) const
Reads value for option label from options.
Definition gsOptionList.cpp:117
void addSwitch(const std::string &label, const std::string &desc, const bool &value)
Adds a option named label, with description desc and value value.
Definition gsOptionList.cpp:235
void addString(const std::string &label, const std::string &desc, const std::string &value)
Adds a option named label, with description desc and value value.
Definition gsOptionList.cpp:190
This class represents a group of vtk (Paraview) files that refer to one multiPatch,...
Definition gsParaviewDataSet.h:38
void addField(const expr::_expr< E > &expr, std::string label)
Evaluates an expression, and writes that data to the vtk files.
Definition gsParaviewDataSet.h:70
void addFields(std::vector< std::string > labels, const expr::_expr< E > &expr, Rest... rest)
Recursive form of addField()
Definition gsParaviewDataSet.h:108
void addField(const gsField< T > field, std::string label)
Evaluates a gsField ( the function part ), and writes that data to the vtk files.
Definition gsParaviewDataSet.h:124
void addFields(std::vector< std::string > labels, const gsField< T > field, Rest... rest)
Recursive form of addField()
Definition gsParaviewDataSet.h:161
static gsOptionList defaultOptions()
Accessor to the current options.
Definition gsParaviewDataSet.h:180
#define index_t
Definition gsConfig.h:32
#define GISMO_ENSURE(cond, message)
Definition gsDebug.h:102
Provides the gsDofMapper class for re-indexing DoFs.
Generic expressions evaluator.
Generic expressions helper.
Provides forward declarations of types and structs.
Input and output Utilities.
Provides declaration of Basis abstract interface.
ParaView output Utilities.
The G+Smo namespace, containing all definitions for the library.
std::vector< std::string > toVTK(const gsFunctionSet< T > &funSet, unsigned nPts=1000, unsigned precision=5, std::string label="", const bool &export_base64=false)
Evaluates gsFunctionSet over all pieces( patches ) and returns all <DataArray> xml tags as a vector o...
Definition gsParaviewUtils.hpp:35