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;
202 DofMappingType dof_map(space);
203 TrafoEval trafo_eval(_trafo);
204 SpaceEval space_eval(space);
205 TrafoData trafo_data;
206 SpaceData space_data;
209 _ofs <<
"VECTORS " << name <<
" double\n";
212 for(
Index cell(trafo_eval.begin()); cell != trafo_eval.end(); ++cell)
215 dof_map.prepare(cell);
216 for(
int i(0); i < dof_map.get_num_local_dofs(); ++i)
218 loc_vec[i] = v(dof_map.get_index(i));
223 trafo_eval.prepare(cell);
224 space_eval.prepare(trafo_eval);
230 typename TrafoEval::DomainPointType
dom_point;
235 space_eval(space_data, trafo_data);
239 for(
int i(0); i < space_eval.get_num_local_dofs(); ++i)
240 value += space_data.phi[i].value * loc_vec[i];
243 for(
int d(0); d < ValueType::n; ++d)
244 _ofs <<
" " <<
value(d);
246 for(
int d(ValueType::n); d < 3; ++d)
269 template<
typename Space_,
typename T_>
273 typedef Space_ SpaceType;
274 typedef typename SpaceType::template Evaluator<TrafoEval>::Type SpaceEval;
275 static_assert(*(SpaceEval::eval_caps &
SpaceTags::value),
"space cannot evaluate basis function values!");
276 typedef typename SpaceType::DofMappingType DofMappingType;
277 typedef typename SpaceEval::template ConfigTraits<SpaceTags::value> SpaceConfigTraits;
278 typedef typename SpaceConfigTraits::EvalDataType SpaceData;
279 static constexpr TrafoTags trafo_value_config = SpaceConfigTraits::trafo_config;
280 typedef typename TrafoEval::template ConfigTraits<trafo_value_config>::EvalDataType TrafoData;
281 typedef typename SpaceEval::DataType DataType;
284 DofMappingType dof_map(space);
285 TrafoEval trafo_eval(_trafo);
286 SpaceEval space_eval(space);
287 TrafoData trafo_data;
288 SpaceData space_data;
291 _ofs <<
"SCALARS " << name <<
" double 1\n";
292 _ofs <<
"LOOKUP_TABLE default\n";
295 for(
Index cell(trafo_eval.begin()); cell != trafo_eval.end(); ++cell)
298 dof_map.prepare(cell);
299 for(
int i(0); i < dof_map.get_num_local_dofs(); ++i)
301 loc_vec[i] = DataType(data[dof_map.get_index(i)]);
306 trafo_eval.prepare(cell);
307 space_eval.prepare(trafo_eval);
313 typename TrafoEval::DomainPointType
dom_point;
318 space_eval(space_data, trafo_data);
322 for(
int i(0); i < space_eval.get_num_local_dofs(); ++i)
323 value += loc_vec[i] * space_data.phi[i].value;
326 _ofs <<
value <<
"\n";
347 template<
typename Space_,
typename T_>
351 typedef Space_ SpaceType;
352 typedef typename SpaceType::template Evaluator<TrafoEval>::Type SpaceEval;
353 static_assert(*(SpaceEval::eval_caps &
SpaceTags::grad),
"space cannot evaluate basis function gradients!");
354 typedef typename SpaceType::DofMappingType DofMappingType;
355 typedef typename SpaceEval::template ConfigTraits<SpaceTags::grad> SpaceConfigTraits;
356 typedef typename SpaceConfigTraits::EvalDataType SpaceData;
357 static constexpr TrafoTags trafo_grad_config = SpaceConfigTraits::trafo_config;
358 typedef typename TrafoEval::template ConfigTraits<trafo_grad_config>::EvalDataType TrafoData;
359 typedef typename SpaceEval::DataType DataType;
360 typedef typename SpaceEval::SpaceEvalTraits SpaceEvalTraits;
361 typedef typename SpaceEvalTraits::BasisGradientType BasisGradientType;
364 DofMappingType dof_map(space);
365 TrafoEval trafo_eval(_trafo);
366 SpaceEval space_eval(space);
367 TrafoData trafo_data;
368 SpaceData space_data;
371 _ofs <<
"VECTORS " << name <<
" double\n";
374 for(
Index cell(trafo_eval.begin()); cell != trafo_eval.end(); ++cell)
377 dof_map.prepare(cell);
378 for(
int i(0); i < dof_map.get_num_local_dofs(); ++i)
380 loc_vec[i] = DataType(data[dof_map.get_index(i)]);
385 trafo_eval.prepare(cell);
386 space_eval.prepare(trafo_eval);
392 typename TrafoEval::DomainPointType
dom_point;
397 space_eval(space_data, trafo_data);
400 BasisGradientType
grad;
402 for(
int i(0); i < space_eval.get_num_local_dofs(); ++i)
403 grad += loc_vec[i] * space_data.phi[i].grad;
407 for(
int i(1); i < ShapeType::dimension; ++i)
408 _ofs <<
" " <<
grad[i];
409 for(
int i(ShapeType::dimension); i < 3; ++i)
433 template<
typename Space_,
typename T_>
437 typedef Space_ SpaceType;
438 typedef typename SpaceType::template Evaluator<TrafoEval>::Type SpaceEval;
439 static_assert(*(SpaceEval::eval_caps &
SpaceTags::hess),
"space cannot evaluate basis function hessians!");
440 typedef typename SpaceType::DofMappingType DofMappingType;
441 typedef typename SpaceEval::template ConfigTraits<SpaceTags::hess> SpaceConfigTraits;
442 typedef typename SpaceConfigTraits::EvalDataType SpaceData;
443 static constexpr TrafoTags trafo_hess_config = SpaceConfigTraits::trafo_config;
444 typedef typename TrafoEval::template ConfigTraits<trafo_hess_config>::EvalDataType TrafoData;
445 typedef typename SpaceEval::DataType DataType;
446 typedef typename SpaceEval::SpaceEvalTraits SpaceEvalTraits;
447 typedef typename SpaceEvalTraits::BasisHessianType BasisHessianType;
450 DofMappingType dof_map(space);
451 TrafoEval trafo_eval(_trafo);
452 SpaceEval space_eval(space);
453 TrafoData trafo_data;
454 SpaceData space_data;
457 _ofs <<
"TENSORS " << name <<
" double\n";
460 for(
Index cell(trafo_eval.begin()); cell != trafo_eval.end(); ++cell)
463 dof_map.prepare(cell);
464 for(
int i(0); i < dof_map.get_num_local_dofs(); ++i)
466 loc_vec[i] = DataType(data[dof_map.get_index(i)]);
471 trafo_eval.prepare(cell);
472 space_eval.prepare(trafo_eval);
478 typename TrafoEval::DomainPointType
dom_point;
483 space_eval(space_data, trafo_data);
486 BasisHessianType
hess;
488 for(
int i(0); i < space_eval.get_num_local_dofs(); ++i)
489 hess += loc_vec[i] * space_data.phi[i].hess;
492 for(
int i(0); i < ShapeType::dimension; ++i)
495 for(
int j(1); j < ShapeType::dimension; ++j)
496 _ofs <<
" " <<
hess(i,j);
497 for(
int j(ShapeType::dimension); j < 3; ++j)
501 for(
int i(ShapeType::dimension); i < 3; ++i)
504 for(
int j(1); j < 3; ++j)
517 void write_vertices()
520 const TrafoType& trafo = _trafo;
521 const MeshType& mesh = trafo.get_mesh();
524 const Index num_cells = mesh.get_num_entities(ShapeType::dimension);
526 _ofs <<
"POINTS " << num_ref_verts <<
" double\n";
529 typedef typename TrafoEval::DomainPointType DomainPointType;
530 typedef typename TrafoEval::template ConfigTraits<TrafoTags::img_point>::EvalDataType TrafoData;
532 TrafoEval trafo_eval(trafo);
533 TrafoData trafo_data;
536 for(
Index cell(trafo_eval.begin()); cell != trafo_eval.end(); ++cell)
539 trafo_eval.prepare(cell);
551 _ofs << trafo_data.img_point[0];
552 for(
int j(1); j < ShapeType::dimension; ++j)
553 _ofs <<
" " << trafo_data.img_point[j];
554 for(
int j(ShapeType::dimension); j < 3; ++j)
567 const TrafoType& trafo = _trafo;
568 const MeshType& mesh = trafo.get_mesh();
571 const Index num_cells = mesh.get_num_entities(ShapeType::dimension);
574 const typename RefMeshType::template IndexSet<ShapeType::dimension,0>::Type& idx =
575 _ref_mesh->template get_index_set<ShapeType::dimension, 0>();
576 int num_idx = idx.get_num_indices();
578 typedef Geometry::Intern::VTKShape<ShapeType> VTKHelperType;
580 _ofs <<
"CELLS " << (num_cells*num_ref_cells) <<
" " << (
Index(num_idx+1)*num_cells*num_ref_cells) <<
"\n";
583 for(
Index cell(0); cell < num_cells; ++cell)
586 Index voff = num_ref_verts * cell;
587 for(
Index i(0); i < num_ref_cells; ++i)
590 for(
int j(0); j < num_idx; ++j)
592 _ofs <<
" " << voff + idx(i,VTKHelperType::map(j));
599 _ofs <<
"CELL_TYPES " << (num_cells*num_ref_cells) <<
"\n";
602 for(
Index cell(0); cell < num_cells*num_ref_cells; ++cell)
604 _ofs << VTKHelperType::type <<
"\n";
608 void get_dom_point(
typename TrafoEval::DomainPointType&
dom_point,
Index i)
const
614 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.
static constexpr int version_major
FEAT major version number.
static constexpr int version_patch
FEAT patch version number.
static constexpr int version_minor
FEAT minor version number.
@ 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