39 std::string m_basename;
40 std::vector<std::string> m_filenames;
60 m_options(defaultOptions()),
69 void addField(
const expr::_expr<E>& expr, std::string label) {
71 "You cannot add more fields if the gsParaviewDataSet has "
75 const unsigned nPts = m_options.askInt(
"numPoints", 1000);
76 const unsigned precision = m_options.askInt(
"precision", 5);
77 const bool export_base64 = m_options.askSwitch(
"base64",
false);
82 const std::vector<std::string> tags =
83 toVTK(expr, nPts, precision, label, export_base64);
84 std::vector<std::string> fnames = filenames();
86 for (
index_t k = 0; k != m_geometry->nPieces();
90 file.open(fnames[k].c_str(), std::ios_base::app);
97 void addFields(std::vector<std::string>){ }
106 template <
class E,
typename... Rest>
107 void addFields(std::vector<std::string> labels,
const expr::_expr<E> & expr, Rest... rest) {
109 GISMO_ENSURE(
sizeof...(Rest) == labels.size() - 1,
"The length of labels must match the number of expressions provided" );
110 std::vector<std::string> newlabels(labels.cbegin()+1, labels.cend());
113 addField( expr, labels[0]);
114 addFields( newlabels, rest...);
125 "You cannot add more fields if the gsParaviewDataSet has "
128 (field.
parDim() == m_geometry->domainDim() &&
129 field.
geoDim() == m_geometry->targetDim() &&
130 field.
nPieces() == m_geometry->nPieces() &&
131 field.
patches().coefsSize() == m_geometry->coefsSize()),
132 "Provided gsField and stored geometry are not compatible!");
135 const unsigned nPts = m_options.askInt(
"numPoints", 1000);
136 const unsigned precision = m_options.askInt(
"precision", 5);
137 const bool export_base64 = m_options.askSwitch(
"base64",
false);
139 const std::vector<std::string> tags =
140 toVTK(field, nPts, precision, label, export_base64);
141 const std::vector<std::string> fnames = filenames();
143 for (
index_t k = 0; k != m_geometry->nPieces();
147 file.open(fnames[k].c_str(), std::ios_base::app);
159 template <
class T,
typename... Rest>
162 std::vector<std::string> newlabels(labels.cbegin()+1, labels.cend());
164 addField( field, labels[0]);
165 addFields( newlabels, rest...);
170 const std::vector<std::string> filenames();
182 opt.
addInt(
"numPoints",
"Number of points per-patch.", 1000);
183 opt.
addInt(
"precision",
"Number of decimal digits.", 5);
184 opt.
addInt(
"plotElements.resolution",
"Drawing resolution for element mesh.", -1);
185 opt.
addSwitch(
"makeSubfolder",
"Export vtk files to subfolder ( below the .pvd file ).",
true);
186 opt.
addSwitch(
"base64",
"Export in base64 binary format",
false);
187 opt.
addString(
"subfolder",
"Name of subfolder where the vtk files will be stored.",
"");
188 opt.
addSwitch(
"plotElements",
"Controls plotting of element mesh.",
false);
189 opt.
addSwitch(
"plotControlNet",
"Controls plotting of control point grid.",
false);
206 unsigned nPts = 1000,
207 unsigned precision = 5,
208 std::string label =
"",
209 const bool& export_base64 =
false) {
210 std::vector<std::string> out;
216 gsGridIterator<T,CUBE> grid(funSet.
piece(i).support(), nPts);
219 xyzPoints.resize( funSet.
targetDim(), grid.numPoints() );
221 for( grid.reset(); grid; ++grid )
224 xyzPoints.col(col) = funSet.
piece(i).eval(evalPoint);
228 out.push_back( toDataArray(xyzPoints, label, precision, export_base64) );
234 static std::vector<std::string> toVTK(
const gsField<T>& field,
235 unsigned nPts = 1000,
236 unsigned precision = 5,
237 std::string label =
"",
238 const bool& export_base64 =
false) {
239 std::vector<std::string> out;
245 gsGridIterator<T,CUBE> grid(field.
fields().piece(i).support(), nPts);
248 xyzPoints.resize( field.
dim(), grid.numPoints());
250 for( grid.reset(); grid; ++grid )
253 xyzPoints.col(col) = field.
value(evalPoint, i);
258 toDataArray(xyzPoints, label, precision, export_base64));
272 std::vector<std::string>
toVTK(
const expr::_expr<E>& expr,
273 unsigned nPts = 1000,
unsigned precision = 5,
274 std::string label =
"SolutionField",
275 const bool& export_base64 =
false) {
276 std::vector<std::string> out;
277 std::stringstream data_array_stream;
280 data_array_stream.setf(std::ios::fixed);
281 data_array_stream.precision(precision);
284 const index_t n = m_evaltr->exprData()->multiBasis().nBases();
288 for (
index_t i = 0; i != n; ++i) {
290 bounding_box_dimensions =
291 m_evaltr->exprData()->multiBasis().piece(i).support();
292 gsGridIterator<real_t, CUBE> grid_iterator(bounding_box_dimensions,
294 m_evaltr->eval(expr, grid_iterator, i);
297 evaluated_values = m_evaltr->allValues(
298 m_evaltr->elementwise().size() / grid_iterator.numPoints(),
299 grid_iterator.numPoints());
304 const std::string vtk_typename = []() {
305 if (std::is_same<real_t, float>::value) {
306 return std::string(
"Float32");
307 }
else if (std::is_same<real_t, double>::value) {
308 return std::string(
"Float64");
312 GISMO_ERROR(
"Unspported floating point type requested");
317 data_array_stream <<
"<DataArray type=\"" << vtk_typename
318 <<
"\" format=\"binary\" ";
320 data_array_stream <<
"Name=\"" << label <<
"\" ";
324 data_array_stream <<
"NumberOfComponents=\""
325 << evaluated_values.rows() <<
"\">\n";
331 evaluated_values.cols() * evaluated_values.rows() *
337 data_array_stream <<
"<DataArray type=\"Float32\" Name=\"" << label
338 <<
"\" format=\"ascii\" NumberOfComponents=\""
339 << (evaluated_values.rows() == 1 ? 1 : 3)
341 if (evaluated_values.rows() == 1)
342 for (
index_t j = 0; j < evaluated_values.cols(); ++j)
343 data_array_stream << evaluated_values.
at(j) <<
" ";
345 for (
index_t j = 0; j < evaluated_values.cols(); ++j) {
346 for (
index_t k = 0; k != evaluated_values.rows(); ++k)
347 data_array_stream << evaluated_values(k, j) <<
" ";
348 for (
index_t k = evaluated_values.rows(); k < 3; ++k)
349 data_array_stream <<
"0 ";
353 data_array_stream <<
"\n</DataArray>\n";
354 out.push_back(data_array_stream.str());
355 data_array_stream.str(
373 const std::string label,
unsigned precision,
374 const bool& export_base64) {
375 std::stringstream stream;
379 const std::string vtk_typename = []() {
380 if (std::is_same<T, float>::value) {
381 return std::string(
"Float32");
382 }
else if (std::is_same<T, double>::value) {
383 return std::string(
"Float64");
388 std::vector<T> copy_of_matrix;
389 copy_of_matrix.reserve(points.cols() * 3);
391 for (
index_t j = 0; j < points.cols(); ++j) {
392 for (
index_t i = 0; i < points.rows(); ++i) {
393 copy_of_matrix.push_back(points(i, j));
395 for (
index_t i = points.rows(); i < 3; ++i)
396 copy_of_matrix.push_back(0);
400 stream <<
"<DataArray type=\"" << vtk_typename
401 <<
"\" format=\"binary\" ";
403 stream <<
"Name=\"" << label <<
"\" ";
406 stream <<
"NumberOfComponents=\"3\">\n";
409 stream << Base64::Encode(std::vector<uint64_t>(1,copy_of_matrix.size() *
414 stream.setf(std::ios::fixed);
416 stream.precision(precision);
418 stream <<
"<DataArray type=\"Float32\" format=\"ascii\" ";
419 if (
"" != label) stream <<
"Name=\"" << label <<
"\" ";
420 stream <<
"NumberOfComponents=\"3\">\n";
422 for (
index_t j = 0; j < points.cols(); ++j) {
423 for (
index_t i = 0; i != points.rows(); ++i)
424 stream << points(i, j) <<
" ";
425 for (
index_t i = points.rows(); i < 3; ++i) stream <<
"0 ";
428 stream <<
"\n</DataArray>\n";
433 void initFilenames();
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
void addFields(std::vector< std::string > labels, const expr::_expr< E > &expr, Rest...rest)
Recursive form of addField()
Definition: gsParaviewDataSet.h:107
static gsOptionList defaultOptions()
Accessor to the current options.
Definition: gsParaviewDataSet.h:179
A scalar of vector field defined on a m_parametric geometry.
Definition: gsField.h:54
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
static std::string Encode(const std::vector< BaseType > &data_vector)
Helper routine for std::vector data.
Definition: gsBase64.h:218
#define index_t
Definition: gsConfig.h:32
Generic expressions helper.
std::vector< std::string > toVTK(const expr::_expr< E > &expr, unsigned nPts=1000, unsigned precision=5, std::string label="SolutionField", const bool &export_base64=false)
Evaluates one expression over all patches and returns all <DataArray> xml tags as a vector of strings...
Definition: gsParaviewDataSet.h:272
#define GISMO_ENSURE(cond, message)
Definition: gsDebug.h:102
const gsMultiPatch< T > & patches() const
Returns gsMultiPatch containing the geometric information on the domain.
Definition: gsField.h:210
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
void addField(const expr::_expr< E > &expr, std::string label)
Evaluates an expression, and writes that data to the vtk files.
Definition: gsParaviewDataSet.h:69
Input and output Utilities.
virtual short_t targetDim() const
Dimension of the target space.
Definition: gsFunctionSet.h:560
const gsFunctionSet< T > & fields() const
Returns the fields (defined per patch)
Definition: gsField.h:218
Generic expressions evaluator.
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
virtual const gsFunctionSet & piece(const index_t) const
Returns the piece(s) of the function(s) at subdomain k.
Definition: gsFunctionSet.h:239
Provides the gsDofMapper class for re-indexing DoFs.
T at(index_t i) const
Returns the i-th element of the vectorization of the matrix.
Definition: gsMatrix.h:211
Provides declaration of Basis abstract interface.
static 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: gsParaviewDataSet.h:205
Interface for the set of functions defined on a domain (the total number of functions in the set equa...
Definition: gsFuncData.h:23
Provides forward declarations of types and structs.
void addFields(std::vector< std::string > labels, const gsField< T > field, Rest...rest)
Recursive form of addField()
Definition: gsParaviewDataSet.h:160
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:123
This class represents a group of vtk (Paraview) files that refer to one multiPatch, for one timestep.
Definition: gsParaviewDataSet.h:36
virtual index_t nPieces() const
Number of pieces in the domain of definition.
Definition: gsFunctionSet.h:584
gsMatrix< T > value(const gsMatrix< T > &u, int i=0) const
Evaluation of the field at points u.
Definition: gsField.h:122
#define GISMO_ERROR(message)
Definition: gsDebug.h:118
int nPieces() const
Returns the number of pieces.
Definition: gsField.h:200
Class which holds a list of parameters/options, and provides easy access to them. ...
Definition: gsOptionList.h:32
short_t dim() const
Returns the dimension of the physical domain (e.g., if the domain is a surface in three-dimensional s...
Definition: gsField.h:194
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
static std::string toDataArray(const gsMatrix< T > &points, const std::string label, unsigned precision, const bool &export_base64)
Formats the coordinates of points as a <DataArray> xml tag for ParaView export.
Definition: gsParaviewDataSet.h:372