12 #ifndef BEMBEL_SRC_IO_VTKSURFACEEXPORT_HPP_
13 #define BEMBEL_SRC_IO_VTKSURFACEEXPORT_HPP_
32 init_VTKSurfaceExport(geo, M);
34 inline void init_VTKSurfaceExport(
const Geometry& geo,
int M) {
38 normals = Eigen::MatrixXd(cells.rows(), 3);
39 patch_number = Eigen::VectorXi(cells.rows());
44 .evalNormal(e->referenceMidpoint())
50 patch_number(e->id_) = e->patch_;
58 const std::string& name,
59 std::function<
double(
int,
const Eigen::Vector2d&)> fun) {
60 addDataSet_(name, getData_<double>(fun));
67 const std::string& name,
68 std::function<std::complex<double>(
int,
const Eigen::Vector2d&)> fun) {
69 Eigen::VectorXcd data = getData_<std::complex<double>>(fun);
70 addDataSet_(name + std::string(
"_real"), data.real());
71 addDataSet_(name + std::string(
"_imag"), data.imag());
78 const std::string& name,
79 std::function<Eigen::Vector3d(
int,
const Eigen::Vector2d&)> fun) {
80 addDataSet_(name, getData_<double, 3>(fun));
87 const std::string& name,
88 std::function<Eigen::Vector3cd(
int,
const Eigen::Vector2d&)> fun) {
89 Eigen::MatrixXcd data = getData_<std::complex<double>, 3>(fun);
90 addDataSet_(name + std::string(
"_real"), data.real());
91 addDataSet_(name + std::string(
"_imag"), data.imag());
98 const std::string& name,
99 std::function<Eigen::Vector3d(
const Eigen::Vector3d&)> fun) {
100 addDataSet_(name, getData_<double, 3>(fun));
107 const std::string& name,
108 std::function<Eigen::Vector3cd(
const Eigen::Vector3d&)> fun) {
109 Eigen::MatrixXcd data = getData_<std::complex<double>, 3>(fun);
110 addDataSet_(name + std::string(
"_real"), data.real());
111 addDataSet_(name + std::string(
"_imag"), data.imag());
118 std::function<
double(
const Eigen::Vector3d&)> fun) {
119 addDataSet_(name, getData_<double>(fun));
126 const std::string& name,
127 std::function<std::complex<double>(
const Eigen::Vector3d&)> fun) {
128 Eigen::VectorXcd data = getData_<std::complex<double>>(fun);
129 addDataSet_(name + std::string(
"_real"), data.real());
130 addDataSet_(name + std::string(
"_imag"), data.imag());
137 template <
typename LinOp>
141 Eigen::Dynamic, Eigen::Dynamic>& coefficients) {
144 evaluator.set_function(coefficients);
151 constexpr
int dimension =
154 FunctionSpaceOutputDimension;
155 std::function<ReturnType(
int,
const Eigen::Vector2d&)> fun =
156 getEvaluatorFunction_<LinOp, dimension>::get(evaluator);
168 std::ofstream output;
169 output.open(filename);
170 output <<
"<VTKFile type=\"PolyData\" version=\"0.1\" "
171 "byte_order=\"LittleEndian\">\n"
173 "<Piece NumberOfPoints=\" "
175 <<
"\" NumberOfVerts=\"0\" NumberOfLines=\"0\" NumberOfStrips=\"0\" "
180 "<DataArray type=\"Float32\" NumberOfComponents=\"3\" "
181 "format=\"ascii\">\n";
183 output <<
"</DataArray>\n</Points>";
184 output <<
"<CellData Scalars=\"patch_number\" Normals=\"cell_normals\">\n"
185 "<DataArray type=\"Int32\" Name=\"patch_number\" "
186 "format=\"ascii\">\n";
187 output << patch_number;
188 output <<
"</DataArray>\n<DataArray type=\"Float32\" Name=\"cell_normals\" "
189 "NumberOfComponents=\"3\" format=\"ascii\">";
191 output <<
"</DataArray>\n";
192 for (
auto data : additionalData) {
195 output <<
"</CellData>\n"
197 "<DataArray type=\"Int32\" Name=\"connectivity\" "
198 "format=\"ascii\">\n";
200 output <<
"</DataArray>\n"
201 "<DataArray type=\"Int32\" Name=\"offsets\" "
202 "format=\"ascii\">\n";
203 for (
int i = 0; i < cells.rows(); ++i) {
204 output << (i + 1) * 4;
207 output <<
"</DataArray>\n"
216 inline void clearData() {
218 additionalData.shrink_to_fit();
224 inline void addDataSet_(
const std::string& name,
const Eigen::MatrixXd& mat) {
225 assert(mat.cols() == 1 || mat.cols() == 3);
226 assert(mat.rows() == cells.rows());
228 const int cols = mat.cols();
229 std::string data_ascii =
"<DataArray type=\"Float32\" Name=\"" + name +
230 "\" NumberOfComponents=\"" +
231 std::to_string(mat.cols()) +
232 "\" format=\"ascii\">\n";
233 std::ostringstream out;
235 for (
int i = 0; i < mat.rows(); ++i) {
236 for (
int j = 0; j < cols; ++j) {
237 out << std::scientific << mat(i, j);
238 data_ascii.append(std::move(out).str() +
" ");
242 data_ascii.append(
"\n");
244 data_ascii.append(
"</DataArray>\n");
245 additionalData.push_back(data_ascii);
249 template <
typename Scalar,
int dim>
250 inline Eigen::Matrix<Scalar, Eigen::Dynamic, dim> getData_(
252 Eigen::Matrix<Scalar, dim, 1>(
const Eigen::Vector3d&)>& fun) {
253 Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> data(cells.rows(),
259 fun(msh.
get_geometry()[e->patch_].eval(e->referenceMidpoint()))
264 template <
typename Scalar>
265 inline Eigen::Matrix<Scalar, Eigen::Dynamic, 1> getData_(
266 std::function<Scalar(
const Eigen::Vector3d&)>& fun) {
267 Eigen::Matrix<Scalar, Eigen::Dynamic, 1> data(cells.rows());
272 fun(msh.
get_geometry()[e->patch_].eval(e->referenceMidpoint()));
278 template <
typename Scalar,
int dim>
279 inline Eigen::Matrix<Scalar, Eigen::Dynamic, dim> getData_(
281 Eigen::Matrix<Scalar, dim, 1>(
int,
const Eigen::Vector2d&)>& fun) {
282 Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> data(cells.rows(),
287 data.row(e->id_) = fun(e->patch_, e->referenceMidpoint()).transpose();
291 template <
typename Scalar>
292 inline Eigen::Matrix<Scalar, Eigen::Dynamic, 1> getData_(
293 std::function<Scalar(
int,
const Eigen::Vector2d&)>& fun) {
294 Eigen::Matrix<Scalar, Eigen::Dynamic, 1> data(cells.rows());
298 data(e->id_) = fun(e->patch_, e->referenceMidpoint());
305 template <
typename LinOp,
int size>
306 struct getEvaluatorFunction_ {
307 static std::function<
308 Eigen::Matrix<typename LinearOperatorTraits<LinOp>::Scalar, size, 1>(
309 int,
const Eigen::Vector2d&)>
310 get(
const FunctionEvaluator<LinOp>& evaluator) {
311 typedef typename LinearOperatorTraits<LinOp>::Scalar Scalar;
313 typename Eigen::Matrix<typename LinearOperatorTraits<LinOp>::Scalar,
316 std::function<ReturnType(
int,
const Eigen::Vector2d&)> fun =
317 [&](
int patch_number,
const Eigen::Vector2d& reference_domain_point) {
318 return evaluator.evaluateOnPatch(patch_number,
319 reference_domain_point);
324 template <
typename LinOp>
325 struct getEvaluatorFunction_<LinOp, 1> {
326 static std::function<typename LinearOperatorTraits<LinOp>::Scalar(
327 int,
const Eigen::Vector2d&)>
328 get(
const FunctionEvaluator<LinOp>& evaluator) {
329 typedef typename LinearOperatorTraits<LinOp>::Scalar Scalar;
330 std::function<
typename DifferentialFormTraits<
331 LinearOperatorTraits<LinOp>::Form,
332 typename LinearOperatorTraits<LinOp>::Scalar>::
333 FunctionSpaceValue(
int,
const Eigen::Vector2d&)>
334 fun = [&](
int patch_number,
335 const Eigen::Vector2d& reference_domain_point) {
336 return evaluator.evaluateOnPatch(patch_number,
337 reference_domain_point)(0);
344 Eigen::MatrixXd points;
345 Eigen::MatrixXi cells;
346 Eigen::MatrixXd normals;
347 Eigen::VectorXi patch_number;
348 std::vector<std::string> additionalData;
void init_ClusterTree(const Geometry &geom, int M)
init
const PatchVector & get_geometry() const
Return const reference to the Geometry.
ElementTree & get_element_tree()
getter
ElementTreeNode::const_iterator cpbegin() const
Returns an iterator to the beginning of the sequence represented by the leafs as ElementTreeNodes of ...
ElementTreeNode::const_iterator cpend() const
Returns an iterator one past the end of the sequence represented by the leafs as ElementTreeNodes of ...
Eigen::MatrixXd generatePointList(Eigen::VectorXi *idct=nullptr) const
Return the coordinates of all points of the elements.
Eigen::MatrixXi generateElementList() const
Return list of elements containing the indices of the vertices.
this class wraps a GeometryVector and provides some basic functionality, like reading Geometry files
Provides export routines from functions on geometries to the VTK file format.
void addDataSet(const std::string &name, std::function< Eigen::Vector3d(int, const Eigen::Vector2d &)> fun)
Add a function of the given type to the visualization.
void writeToFile(const std::string &filename)
Write geometry with passed visualization data to file.
void addDataSet(const std::string &name, std::function< std::complex< double >(const Eigen::Vector3d &)> fun)
Add a function of the given type to the visualization.
void addDataSet(const std::string &name, std::function< Eigen::Vector3cd(int, const Eigen::Vector2d &)> fun)
Add a function of the given type to the visualization.
void addDataSet(const std::string &name, const AnsatzSpace< LinOp > &ansatz_space, const Eigen::Matrix< typename LinearOperatorTraits< LinOp >::Scalar, Eigen::Dynamic, Eigen::Dynamic > &coefficients)
Add a function given through coefficients of an AnsatzSpace to the visualization.
VTKSurfaceExport(const Geometry &geo, int M)
void addDataSet(const std::string &name, std::function< Eigen::Vector3d(const Eigen::Vector3d &)> fun)
Add a function of the given type to the visualization.
void addDataSet(const std::string &name, std::function< Eigen::Vector3cd(const Eigen::Vector3d &)> fun)
Add a function of the given type to the visualization.
void addDataSet(const std::string &name, std::function< double(int, const Eigen::Vector2d &)> fun)
Add a function of the given type to the visualization.
void addDataSet(const std::string &name, std::function< double(const Eigen::Vector3d &)> fun)
Add a function of the given type to the visualization.
void addDataSet(const std::string &name, std::function< std::complex< double >(int, const Eigen::Vector2d &)> fun)
Add a function of the given type to the visualization.
Routines for the evalutation of pointwise errors.
struct containing specifications on the linear operator has to be specialized or derived for any part...