9#include <kernel/geometry/export_vtk.hpp>
10#include <kernel/geometry/reference_cell_factory.hpp>
11#include <kernel/space/eval_data.hpp>
12#include <kernel/util/math.hpp>
25 template<
bool _enable>
26 struct ExtVtkValueWriter
28 template<
typename ExtVtkWriter_>
29 static void write(
const ExtVtkWriter_&, std::ostream&) {}
32 template<
bool _enable>
33 struct ExtVtkGradWriter
35 template<
typename ExtVtkWriter_>
36 static void write(
const ExtVtkWriter_&, std::ostream&) {}
39 template<
bool _enable>
40 struct ExtVtkHessWriter
42 template<
typename ExtVtkWriter_>
43 static void write(
const ExtVtkWriter_&, std::ostream&) {}
47 struct ExtVtkValueWriter<true>
49 template<
typename ExtVtkWriter_>
50 static void write(
const ExtVtkWriter_& writer, std::ostream& os)
52 writer.write_values(os);
57 struct ExtVtkGradWriter<true>
59 template<
typename ExtVtkWriter_>
60 static void write(
const ExtVtkWriter_& writer, std::ostream& os)
62 writer.write_gradients(os);
67 struct ExtVtkHessWriter<true>
69 template<
typename ExtVtkWriter_>
70 static void write(
const ExtVtkWriter_& writer, std::ostream& os)
72 writer.write_hessians(os);
86 template<
typename Trafo_>
89 friend struct Intern::ExtVtkValueWriter<true>;
90 friend struct Intern::ExtVtkGradWriter<true>;
91 friend struct Intern::ExtVtkHessWriter<true>;
94 typedef Trafo_ TrafoType;
95 typedef typename TrafoType::MeshType MeshType;
96 typedef typename MeshType::ShapeType ShapeType;
100 typedef typename TrafoType::template Evaluator<>::Type TrafoEval;
103 const TrafoType& _trafo;
115 RefCellFactory ref_factory;
117 for(
Index i(0); i < num_refines; ++i)
121 RefCellRefinery refinery(*old_mesh);
126 _ref_mesh = ref_mesh;
131 if(_ref_mesh !=
nullptr)
142 _ofs.open(filename.c_str());
143 if(!_ofs.is_open() || !_ofs.good())
147 _ofs <<
"# vtk DataFile Version 2.0\n";
152 _ofs <<
"DATASET UNSTRUCTURED_GRID\n";
161 _ofs <<
"POINT_DATA " << (_trafo.get_mesh().get_num_entities(ShapeType::dimension)
188 template<
typename Space_,
typename VectorType_>
191 typedef Space_ SpaceType;
192 typedef typename SpaceType::template Evaluator<TrafoEval>::Type SpaceEval;
194 typedef typename SpaceType::DofMappingType DofMappingType;
195 typedef typename SpaceEval::template ConfigTraits<SpaceTags::value> SpaceConfigTraits;
196 typedef typename SpaceConfigTraits::EvalDataType SpaceData;
197 static constexpr TrafoTags trafo_value_config = SpaceConfigTraits::trafo_config;
198 typedef typename TrafoEval::template ConfigTraits<trafo_value_config>::EvalDataType TrafoData;
199 typedef typename VectorType_::ValueType ValueType;
204 DofMappingType dof_map(space);
205 TrafoEval trafo_eval(_trafo);
206 SpaceEval space_eval(space);
207 TrafoData trafo_data;
208 SpaceData space_data;
211 _ofs <<
"VECTORS " << name <<
" double\n";
214 for(
Index cell(trafo_eval.begin()); cell != trafo_eval.end(); ++cell)
217 dof_map.prepare(cell);
218 for(
int i(0); i < dof_map.get_num_local_dofs(); ++i)
220 loc_vec[i] = vv(dof_map.get_index(i));
225 trafo_eval.prepare(cell);
226 space_eval.prepare(trafo_eval);
232 typename TrafoEval::DomainPointType
dom_point;
237 space_eval(space_data, trafo_data);
241 for(
int i(0); i < space_eval.get_num_local_dofs(); ++i)
242 value += space_data.phi[i].value * loc_vec[i];
245 for(
int d(0); d < ValueType::n; ++d)
246 _ofs <<
" " <<
value(d);
248 for(
int d(ValueType::n); d < 3; ++d)
271 template<
typename Space_,
typename T_>
275 typedef Space_ SpaceType;
276 typedef typename SpaceType::template Evaluator<TrafoEval>::Type SpaceEval;
277 static_assert(*(SpaceEval::eval_caps &
SpaceTags::value),
"space cannot evaluate basis function values!");
278 typedef typename SpaceType::DofMappingType DofMappingType;
279 typedef typename SpaceEval::template ConfigTraits<SpaceTags::value> SpaceConfigTraits;
280 typedef typename SpaceConfigTraits::EvalDataType SpaceData;
281 static constexpr TrafoTags trafo_value_config = SpaceConfigTraits::trafo_config;
282 typedef typename TrafoEval::template ConfigTraits<trafo_value_config>::EvalDataType TrafoData;
283 typedef typename SpaceEval::DataType DataType;
286 DofMappingType dof_map(space);
287 TrafoEval trafo_eval(_trafo);
288 SpaceEval space_eval(space);
289 TrafoData trafo_data;
290 SpaceData space_data;
293 _ofs <<
"SCALARS " << name <<
" double 1\n";
294 _ofs <<
"LOOKUP_TABLE default\n";
297 for(
Index cell(trafo_eval.begin()); cell != trafo_eval.end(); ++cell)
300 dof_map.prepare(cell);
301 for(
int i(0); i < dof_map.get_num_local_dofs(); ++i)
303 loc_vec[i] = DataType(data[dof_map.get_index(i)]);
308 trafo_eval.prepare(cell);
309 space_eval.prepare(trafo_eval);
315 typename TrafoEval::DomainPointType
dom_point;
320 space_eval(space_data, trafo_data);
324 for(
int i(0); i < space_eval.get_num_local_dofs(); ++i)
325 value += loc_vec[i] * space_data.phi[i].value;
328 _ofs <<
value <<
"\n";
349 template<
typename Space_,
typename T_>
353 typedef Space_ SpaceType;
354 typedef typename SpaceType::template Evaluator<TrafoEval>::Type SpaceEval;
355 static_assert(*(SpaceEval::eval_caps &
SpaceTags::grad),
"space cannot evaluate basis function gradients!");
356 typedef typename SpaceType::DofMappingType DofMappingType;
357 typedef typename SpaceEval::template ConfigTraits<SpaceTags::grad> SpaceConfigTraits;
358 typedef typename SpaceConfigTraits::EvalDataType SpaceData;
359 static constexpr TrafoTags trafo_grad_config = SpaceConfigTraits::trafo_config;
360 typedef typename TrafoEval::template ConfigTraits<trafo_grad_config>::EvalDataType TrafoData;
361 typedef typename SpaceEval::DataType DataType;
362 typedef typename SpaceEval::SpaceEvalTraits SpaceEvalTraits;
363 typedef typename SpaceEvalTraits::BasisGradientType BasisGradientType;
366 DofMappingType dof_map(space);
367 TrafoEval trafo_eval(_trafo);
368 SpaceEval space_eval(space);
369 TrafoData trafo_data;
370 SpaceData space_data;
373 _ofs <<
"VECTORS " << name <<
" double\n";
376 for(
Index cell(trafo_eval.begin()); cell != trafo_eval.end(); ++cell)
379 dof_map.prepare(cell);
380 for(
int i(0); i < dof_map.get_num_local_dofs(); ++i)
382 loc_vec[i] = DataType(data[dof_map.get_index(i)]);
387 trafo_eval.prepare(cell);
388 space_eval.prepare(trafo_eval);
394 typename TrafoEval::DomainPointType
dom_point;
399 space_eval(space_data, trafo_data);
402 BasisGradientType
grad;
404 for(
int i(0); i < space_eval.get_num_local_dofs(); ++i)
405 grad += loc_vec[i] * space_data.phi[i].grad;
409 for(
int i(1); i < ShapeType::dimension; ++i)
410 _ofs <<
" " <<
grad[i];
411 for(
int i(ShapeType::dimension); i < 3; ++i)
435 template<
typename Space_,
typename T_>
439 typedef Space_ SpaceType;
440 typedef typename SpaceType::template Evaluator<TrafoEval>::Type SpaceEval;
441 static_assert(*(SpaceEval::eval_caps &
SpaceTags::hess),
"space cannot evaluate basis function hessians!");
442 typedef typename SpaceType::DofMappingType DofMappingType;
443 typedef typename SpaceEval::template ConfigTraits<SpaceTags::hess> SpaceConfigTraits;
444 typedef typename SpaceConfigTraits::EvalDataType SpaceData;
445 static constexpr TrafoTags trafo_hess_config = SpaceConfigTraits::trafo_config;
446 typedef typename TrafoEval::template ConfigTraits<trafo_hess_config>::EvalDataType TrafoData;
447 typedef typename SpaceEval::DataType DataType;
448 typedef typename SpaceEval::SpaceEvalTraits SpaceEvalTraits;
449 typedef typename SpaceEvalTraits::BasisHessianType BasisHessianType;
452 DofMappingType dof_map(space);
453 TrafoEval trafo_eval(_trafo);
454 SpaceEval space_eval(space);
455 TrafoData trafo_data;
456 SpaceData space_data;
459 _ofs <<
"TENSORS " << name <<
" double\n";
462 for(
Index cell(trafo_eval.begin()); cell != trafo_eval.end(); ++cell)
465 dof_map.prepare(cell);
466 for(
int i(0); i < dof_map.get_num_local_dofs(); ++i)
468 loc_vec[i] = DataType(data[dof_map.get_index(i)]);
473 trafo_eval.prepare(cell);
474 space_eval.prepare(trafo_eval);
480 typename TrafoEval::DomainPointType
dom_point;
485 space_eval(space_data, trafo_data);
488 BasisHessianType
hess;
490 for(
int i(0); i < space_eval.get_num_local_dofs(); ++i)
491 hess += loc_vec[i] * space_data.phi[i].hess;
494 for(
int i(0); i < ShapeType::dimension; ++i)
497 for(
int j(1); j < ShapeType::dimension; ++j)
498 _ofs <<
" " <<
hess(i,j);
499 for(
int j(ShapeType::dimension); j < 3; ++j)
503 for(
int i(ShapeType::dimension); i < 3; ++i)
506 for(
int j(1); j < 3; ++j)
519 void write_vertices()
522 const TrafoType& trafo = _trafo;
523 const MeshType& mesh = trafo.get_mesh();
526 const Index num_cells = mesh.get_num_entities(ShapeType::dimension);
528 _ofs <<
"POINTS " << num_ref_verts <<
" double\n";
531 typedef typename TrafoEval::DomainPointType DomainPointType;
532 typedef typename TrafoEval::template ConfigTraits<TrafoTags::img_point>::EvalDataType TrafoData;
534 TrafoEval trafo_eval(trafo);
535 TrafoData trafo_data;
538 for(
Index cell(trafo_eval.begin()); cell != trafo_eval.end(); ++cell)
541 trafo_eval.prepare(cell);
553 _ofs << trafo_data.img_point[0];
554 for(
int j(1); j < ShapeType::dimension; ++j)
555 _ofs <<
" " << trafo_data.img_point[j];
556 for(
int j(ShapeType::dimension); j < 3; ++j)
569 const TrafoType& trafo = _trafo;
570 const MeshType& mesh = trafo.get_mesh();
573 const Index num_cells = mesh.get_num_entities(ShapeType::dimension);
576 const typename RefMeshType::template IndexSet<ShapeType::dimension,0>::Type& idx =
577 _ref_mesh->template get_index_set<ShapeType::dimension, 0>();
578 int num_idx = idx.get_num_indices();
580 typedef Geometry::Intern::VTKShape<ShapeType> VTKHelperType;
582 _ofs <<
"CELLS " << (num_cells*num_ref_cells) <<
" " << (
Index(num_idx+1)*num_cells*num_ref_cells) <<
"\n";
585 for(
Index cell(0); cell < num_cells; ++cell)
588 Index voff = num_ref_verts * cell;
589 for(
Index i(0); i < num_ref_cells; ++i)
592 for(
int j(0); j < num_idx; ++j)
594 _ofs <<
" " << voff + idx(i,VTKHelperType::map(j));
601 _ofs <<
"CELL_TYPES " << (num_cells*num_ref_cells) <<
"\n";
604 for(
Index cell(0); cell < num_cells*num_ref_cells; ++cell)
606 _ofs << VTKHelperType::type <<
"\n";
610 void get_dom_point(
typename TrafoEval::DomainPointType&
dom_point,
Index i)
const
616 for(
int j(0); j < ShapeType::dimension; ++j)
#define XASSERT(expr)
Assertion macro definition.
Reference Cell Mesh factory.
Standard Refinery class template.
Extended VTK writer class template.
void close()
Closes the VTK file.
void write_gradients(String name, const Space_ &space, const T_ *data)
Writes a finite element function gradient field to the VTK file.
void write_values_blocked(String name, const Space_ &space, const VectorType_ &v)
Writes a finite element function to the VTK file.
bool open(String filename)
Opens a VTK files and writes basic information.
void write_hessians(String name, const Space_ &space, const T_ *data)
Writes a finite element function Hessian field to the VTK file.
void write_values(String name, const Space_ &space, const T_ *data)
Writes a finite element function to the VTK file.
String class implementation.
Tiny Vector class template.
@ write
write-only access (see attention note above)
static constexpr int version_major
FEAT major version number.
static constexpr int version_patch
FEAT patch version number (month)
static constexpr int version_minor
FEAT minor version number (year)
@ value
specifies whether the space should supply basis function values
@ hess
specifies whether the space should supply basis function hessians
@ grad
specifies whether the space should supply basis function gradients
std::uint64_t Index
Index data type.
TrafoTags
Trafo configuration tags enum.
@ dom_point
specifies whether the trafo should supply domain point coordinates