deal.II version 9.7.0
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
data_out_base.cc
Go to the documentation of this file.
1// ------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4// Copyright (C) 1999 - 2025 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Part of the source code is dual licensed under Apache-2.0 WITH
9// LLVM-exception OR LGPL-2.1-or-later. Detailed license information
10// governing the source code and code contributions can be found in
11// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
12//
13// ------------------------------------------------------------------------
14
15
18#include <deal.II/base/mpi.h>
23
25
26#include <algorithm>
27#include <cmath>
28#include <cstdint>
29#include <cstring>
30#include <ctime>
31#include <fstream>
32#include <future>
33#include <iomanip>
34#include <limits>
35#include <memory>
36#include <numeric>
37#include <set>
38#include <sstream>
39#include <vector>
40
41#ifdef DEAL_II_WITH_ZLIB
42# include <zlib.h>
43#endif
44
45#ifdef DEAL_II_WITH_HDF5
46# include <hdf5.h>
47#endif
48
49#include <boost/iostreams/copy.hpp>
50#include <boost/iostreams/device/back_inserter.hpp>
51#include <boost/iostreams/filtering_stream.hpp>
52#ifdef DEAL_II_WITH_ZLIB
53# include <boost/iostreams/filter/zlib.hpp>
54#endif
55
56
57
59
60#ifndef DOXYGEN
61// we need the following exception from a global function, so can't declare it
62// in the usual way inside a class
63namespace
64{
65 DeclException2(ExcUnexpectedInput,
66 std::string,
67 std::string,
68 << "Unexpected input: expected line\n <" << arg1
69 << ">\nbut got\n <" << arg2 << ">");
70
71# ifdef DEAL_II_WITH_ZLIB
72 constexpr bool deal_ii_with_zlib = true;
73# else
74 constexpr bool deal_ii_with_zlib = false;
75# endif
76
77
78# ifdef DEAL_II_WITH_ZLIB
83 int
84 get_zlib_compression_level(const DataOutBase::CompressionLevel level)
85 {
86 switch (level)
87 {
89 return Z_NO_COMPRESSION;
91 return Z_BEST_SPEED;
93 return Z_BEST_COMPRESSION;
95 return Z_DEFAULT_COMPRESSION;
96 default:
98 return Z_NO_COMPRESSION;
99 }
100 }
101
102# ifdef DEAL_II_WITH_MPI
107 int
108 get_boost_zlib_compression_level(const DataOutBase::CompressionLevel level)
109 {
110 switch (level)
111 {
113 return boost::iostreams::zlib::no_compression;
115 return boost::iostreams::zlib::best_speed;
117 return boost::iostreams::zlib::best_compression;
119 return boost::iostreams::zlib::default_compression;
120 default:
122 return boost::iostreams::zlib::no_compression;
123 }
124 }
125# endif
126# endif
127
132 template <typename T>
133 std::string
134 compress_array(const std::vector<T> &data,
135 const DataOutBase::CompressionLevel compression_level)
136 {
137# ifdef DEAL_II_WITH_ZLIB
138 if (data.size() != 0)
139 {
140 const std::size_t uncompressed_size = (data.size() * sizeof(T));
141
142 // While zlib's compress2 uses unsigned long (which is 64bits
143 // on Linux), the vtu compression header stores the block size
144 // as an std::uint32_t (see below). While we could implement
145 // writing several smaller blocks, we haven't done that. Let's
146 // trigger an error for the user instead:
147 AssertThrow(uncompressed_size <=
148 std::numeric_limits<std::uint32_t>::max(),
150
151 // allocate a buffer for compressing data and do so
152 auto compressed_data_length = compressBound(uncompressed_size);
153 AssertThrow(compressed_data_length <=
154 std::numeric_limits<std::uint32_t>::max(),
156
157 std::vector<unsigned char> compressed_data(compressed_data_length);
158
159 int err = compress2(&compressed_data[0],
160 &compressed_data_length,
161 reinterpret_cast<const Bytef *>(data.data()),
162 uncompressed_size,
163 get_zlib_compression_level(compression_level));
164 (void)err;
165 Assert(err == Z_OK, ExcInternalError());
166
167 // Discard the unnecessary bytes
168 compressed_data.resize(compressed_data_length);
169
170 // now encode the compression header
171 const std::uint32_t compression_header[4] = {
172 1, /* number of blocks */
173 static_cast<std::uint32_t>(uncompressed_size), /* size of block */
174 static_cast<std::uint32_t>(
175 uncompressed_size), /* size of last block */
176 static_cast<std::uint32_t>(
177 compressed_data_length)}; /* list of compressed sizes of blocks */
178
179 const auto *const header_start =
180 reinterpret_cast<const unsigned char *>(&compression_header[0]);
181
183 {header_start, header_start + 4 * sizeof(std::uint32_t)}) +
184 Utilities::encode_base64(compressed_data));
185 }
186 else
187 return {};
188# else
189 (void)data;
190 (void)compression_level;
191 Assert(false,
192 ExcMessage("This function can only be called if cmake found "
193 "a working libz installation."));
194 return {};
195# endif
196 }
197
198
199
208 template <typename T>
209 std::string
210 vtu_stringize_array(const std::vector<T> &data,
211 const DataOutBase::CompressionLevel compression_level,
212 const int precision)
213 {
214 if (deal_ii_with_zlib &&
215 (compression_level != DataOutBase::CompressionLevel::plain_text))
216 {
217 // compress the data we have in memory
218 return compress_array(data, compression_level);
219 }
220 else
221 {
222 std::ostringstream stream;
223 stream.precision(precision);
224 for (const T &el : data)
225 stream << el << ' ';
226 return stream.str();
227 }
228 }
229
230
239 struct ParallelIntermediateHeader
240 {
241 std::uint64_t magic;
242 std::uint64_t version;
243 std::uint64_t compression;
244 std::uint64_t dimension;
245 std::uint64_t space_dimension;
246 std::uint64_t n_ranks;
247 std::uint64_t n_patches;
248 };
249} // namespace
250#endif
251
252
253// some declarations of functions and locally used classes
254namespace DataOutBase
255{
256#ifndef DOXYGEN
257 namespace
258 {
264 class SvgCell
265 {
266 public:
267 // Center of the cell (three-dimensional)
268 Point<3> center;
269
273 Point<3> vertices[4];
274
279 float depth;
280
284 Point<2> projected_vertices[4];
285
286 // Center of the cell (projected, two-dimensional)
287 Point<2> projected_center;
288
292 bool
293 operator<(const SvgCell &) const;
294 };
295
296 bool
297 SvgCell::operator<(const SvgCell &e) const
298 {
299 // note the "wrong" order in which we sort the elements
300 return depth > e.depth;
301 }
302
303
304
310 class EpsCell2d
311 {
312 public:
316 Point<2> vertices[4];
317
322 float color_value;
323
328 float depth;
329
333 bool
334 operator<(const EpsCell2d &) const;
335 };
336
337 bool
338 EpsCell2d::operator<(const EpsCell2d &e) const
339 {
340 // note the "wrong" order in which we sort the elements
341 return depth > e.depth;
342 }
343
344
345
352 * this table, rather than scattered throughout the various patches.
353 *
354 * This function is used by all those output formats that write
355 * data one data set at a time, rather than one cell at a time.
356 */
357 template <int dim, int spacedim, typename Number = double>
358 std::unique_ptr<Table<2, Number>>
359 create_global_data_table(const std::vector<Patch<dim, spacedim>> &patches)
360 {
361 // If there is nothing to write, just return
362 if (patches.empty())
363 return std::make_unique<Table<2, Number>>();
364
365 // unlike in the main function, we don't have here the data_names field,
366 // so we initialize it with the number of data sets in the first patch.
367 // the equivalence of these two definitions is checked in the main
368 // function.
369
370 // we have to take care, however, whether the points are appended to the
371 // end of the patch.data table
372 const unsigned int n_data_sets = patches[0].points_are_available ?
373 (patches[0].data.n_rows() - spacedim) :
374 patches[0].data.n_rows();
375 const unsigned int n_data_points =
376 std::accumulate(patches.begin(),
377 patches.end(),
378 0U,
379 [](const unsigned int count,
380 const Patch<dim, spacedim> &patch) {
381 return count + patch.data.n_cols();
382 });
383
384 std::unique_ptr<Table<2, Number>> global_data_table =
385 std::make_unique<Table<2, Number>>(n_data_sets, n_data_points);
386
387 // loop over all patches
388 unsigned int next_value = 0;
389 for (const auto &patch : patches)
390 {
391 const unsigned int n_subdivisions = patch.n_subdivisions;
392 (void)n_subdivisions;
393
394 Assert((patch.data.n_rows() == n_data_sets &&
395 !patch.points_are_available) ||
396 (patch.data.n_rows() == n_data_sets + spacedim &&
397 patch.points_are_available),
398 ExcDimensionMismatch(patch.points_are_available ?
399 (n_data_sets + spacedim) :
400 n_data_sets,
401 patch.data.n_rows()));
402 Assert(patch.reference_cell != ReferenceCells::get_hypercube<dim>() ||
403 (n_data_sets == 0) ||
404 (patch.data.n_cols() ==
406 ExcInvalidDatasetSize(patch.data.n_cols(),
407 n_subdivisions + 1));
408
409 for (unsigned int i = 0; i < patch.data.n_cols(); ++i, ++next_value)
410 for (unsigned int data_set = 0; data_set < n_data_sets; ++data_set)
411 (*global_data_table)[data_set][next_value] =
412 patch.data(data_set, i);
413 }
414 Assert(next_value == n_data_points, ExcInternalError());
415
416 return global_data_table;
417 }
418 } // namespace
419
420
421#endif
422
423
425 : flags(false, true)
426 , node_dim(numbers::invalid_unsigned_int)
427 , num_cells(0)
428 {}
429
430
431
433 : flags(flags)
434 , node_dim(numbers::invalid_unsigned_int)
435 , num_cells(0)
436 {}
437
438
439
440 template <int dim>
441 void
442 DataOutFilter::write_point(const unsigned int index, const Point<dim> &p)
443 {
444 node_dim = dim;
445
446 Point<3> int_pt;
447 for (unsigned int d = 0; d < dim; ++d)
448 int_pt[d] = p[d];
449
450 const Map3DPoint::const_iterator it = existing_points.find(int_pt);
451 unsigned int internal_ind;
452
453 // If the point isn't in the set, or we're not filtering duplicate points,
454 // add it
455 if (it == existing_points.end() || !flags.filter_duplicate_vertices)
456 {
457 internal_ind = existing_points.size();
458 existing_points.insert(std::make_pair(int_pt, internal_ind));
459 }
460 else
461 {
462 internal_ind = it->second;
463 }
464 // Now add the index to the list of filtered points
465 filtered_points[index] = internal_ind;
466 }
467
468
469
470 void
471 DataOutFilter::internal_add_cell(const unsigned int cell_index,
472 const unsigned int pt_index)
473 {
474 filtered_cells[cell_index] = filtered_points[pt_index];
475
476 // (Re)-initialize counter at any first call to this method.
477 if (cell_index == 0)
478 num_cells = 1;
479 }
480
481
482
483 void
484 DataOutFilter::fill_node_data(std::vector<double> &node_data) const
485 {
486 node_data.resize(existing_points.size() * node_dim);
487
488 for (const auto &existing_point : existing_points)
489 {
490 for (unsigned int d = 0; d < node_dim; ++d)
491 node_data[node_dim * existing_point.second + d] =
492 existing_point.first[d];
493 }
494 }
495
496
497
498 void
499 DataOutFilter::fill_cell_data(const unsigned int local_node_offset,
500 std::vector<unsigned int> &cell_data) const
501 {
502 cell_data.resize(filtered_cells.size());
503
504 for (const auto &filtered_cell : filtered_cells)
505 {
506 cell_data[filtered_cell.first] =
507 filtered_cell.second + local_node_offset;
508 }
509 }
510
511
512
513 std::string
514 DataOutFilter::get_data_set_name(const unsigned int set_num) const
515 {
516 return data_set_names.at(set_num);
517 }
518
519
520
521 unsigned int
522 DataOutFilter::get_data_set_dim(const unsigned int set_num) const
523 {
524 return data_set_dims.at(set_num);
525 }
526
527
528
529 const double *
530 DataOutFilter::get_data_set(const unsigned int set_num) const
531 {
532 return data_sets[set_num].data();
533 }
534
535
536
537 unsigned int
539 {
540 return existing_points.size();
541 }
542
543
544
545 unsigned int
547 {
548 return num_cells;
549 }
550
551
552
553 unsigned int
555 {
556 return data_set_names.size();
557 }
558
559
560
561 void
564
565
566
567 void
570
571
572
573 template <int dim>
574 void
575 DataOutFilter::write_cell(const unsigned int index,
576 const unsigned int start,
577 const std::array<unsigned int, dim> &offsets)
578 {
579 ++num_cells;
580
581 const unsigned int base_entry =
583
584 switch (dim)
585 {
586 case 0:
587 {
588 internal_add_cell(base_entry + 0, start);
589 break;
590 }
591
592 case 1:
593 {
594 const unsigned int d1 = offsets[0];
595
596 internal_add_cell(base_entry + 0, start);
597 internal_add_cell(base_entry + 1, start + d1);
598 break;
599 }
600
601 case 2:
602 {
603 const unsigned int d1 = offsets[0];
604 const unsigned int d2 = offsets[1];
605
606 internal_add_cell(base_entry + 0, start);
607 internal_add_cell(base_entry + 1, start + d1);
608 internal_add_cell(base_entry + 2, start + d2 + d1);
609 internal_add_cell(base_entry + 3, start + d2);
610 break;
611 }
612
613 case 3:
614 {
615 const unsigned int d1 = offsets[0];
616 const unsigned int d2 = offsets[1];
617 const unsigned int d3 = offsets[2];
618
619 internal_add_cell(base_entry + 0, start);
620 internal_add_cell(base_entry + 1, start + d1);
621 internal_add_cell(base_entry + 2, start + d2 + d1);
622 internal_add_cell(base_entry + 3, start + d2);
623 internal_add_cell(base_entry + 4, start + d3);
624 internal_add_cell(base_entry + 5, start + d3 + d1);
625 internal_add_cell(base_entry + 6, start + d3 + d2 + d1);
626 internal_add_cell(base_entry + 7, start + d3 + d2);
627 break;
628 }
629
630 default:
632 }
633 }
634
635
636
637 void
638 DataOutFilter::write_cell_single(const unsigned int index,
639 const unsigned int start,
640 const unsigned int n_points,
642 {
643 ++num_cells;
644
645 const unsigned int base_entry = index * n_points;
646
647 static const std::array<unsigned int, 5> table = {{0, 1, 3, 2, 4}};
648
649 for (unsigned int i = 0; i < n_points; ++i)
650 internal_add_cell(base_entry + i,
652 table[i] :
653 i));
654 }
655
656
657
658 void
659 DataOutFilter::write_data_set(const std::string &name,
660 const unsigned int dimension,
661 const unsigned int set_num,
662 const Table<2, double> &data_vectors)
663 {
664 unsigned int new_dim;
665
666 // HDF5/XDMF output only supports 1d or 3d output, so force rearrangement if
667 // needed
668 if (flags.xdmf_hdf5_output && dimension != 1)
669 new_dim = 3;
670 else
671 new_dim = dimension;
672
673 // Record the data set name, dimension, and allocate space for it
674 data_set_names.push_back(name);
675 data_set_dims.push_back(new_dim);
676 data_sets.emplace_back(new_dim * existing_points.size());
677
678 // TODO: averaging, min/max, etc for merged vertices
679 for (unsigned int i = 0; i < filtered_points.size(); ++i)
680 {
681 const unsigned int r = filtered_points[i];
682
683 for (unsigned int d = 0; d < new_dim; ++d)
684 {
685 if (d < dimension)
686 data_sets.back()[r * new_dim + d] = data_vectors(set_num + d, i);
687 else
688 data_sets.back()[r * new_dim + d] = 0;
689 }
690 }
691 }
692} // namespace DataOutBase
693
694
695
696//----------------------------------------------------------------------//
697// Auxiliary data
698//----------------------------------------------------------------------//
699
700namespace
701{
702 const char *gmv_cell_type[4] = {"", "line 2", "quad 4", "hex 8"};
703
704 const char *ucd_cell_type[4] = {"pt", "line", "quad", "hex"};
705
706 const char *tecplot_cell_type[4] = {"", "lineseg", "quadrilateral", "brick"};
707
721 template <int dim, int spacedim>
722 std::array<unsigned int, 3>
723 extract_vtk_patch_info(const DataOutBase::Patch<dim, spacedim> &patch,
724 const bool write_higher_order_cells)
725 {
726 std::array<unsigned int, 3> vtk_cell_id = {
727 {/* cell type, tbd: */ numbers::invalid_unsigned_int,
728 /* # of cells, default: just one cell */ 1,
729 /* # of nodes, default: as many nodes as vertices */
730 patch.reference_cell.n_vertices()}};
731
732 if (write_higher_order_cells)
733 {
734 vtk_cell_id[0] = patch.reference_cell.vtk_lagrange_type();
735 vtk_cell_id[2] = patch.data.n_cols();
736 }
737 else if (patch.data.n_cols() == patch.reference_cell.n_vertices())
738 // One data set per vertex -> a linear cell
739 vtk_cell_id[0] = patch.reference_cell.vtk_linear_type();
740 else if (patch.reference_cell == ReferenceCells::Triangle &&
741 patch.data.n_cols() == 6)
742 {
744 vtk_cell_id[0] = patch.reference_cell.vtk_quadratic_type();
745 vtk_cell_id[2] = patch.data.n_cols();
746 }
748 patch.data.n_cols() == 10)
749 {
751 vtk_cell_id[0] = patch.reference_cell.vtk_quadratic_type();
752 vtk_cell_id[2] = patch.data.n_cols();
753 }
754 else if (patch.reference_cell.is_hyper_cube())
755 {
756 // For hypercubes, we support sub-divided linear cells
757 vtk_cell_id[0] = patch.reference_cell.vtk_linear_type();
758 vtk_cell_id[1] = Utilities::pow(patch.n_subdivisions, dim);
759 }
760 else if (patch.reference_cell.is_simplex())
761 {
762 vtk_cell_id[0] = patch.reference_cell.vtk_lagrange_type();
763 vtk_cell_id[2] = patch.data.n_cols();
764 }
765 else
766 {
768 }
769
770 return vtk_cell_id;
771 }
772
773 //----------------------------------------------------------------------//
774 // Auxiliary functions
775 //----------------------------------------------------------------------//
776
777 // For a given patch that corresponds to a hypercube cell, compute the
778 // location of a node interpolating the corner nodes linearly
779 // at the point lattice_location/n_subdivisions where lattice_location
780 // is a dim-dimensional integer vector. If the points are
781 // saved in the patch.data member, return the saved point instead.
782 template <int dim, int spacedim>
783 inline Point<spacedim>
784 get_equispaced_location(
786 const std::initializer_list<unsigned int> &lattice_location,
787 const unsigned int n_subdivisions)
788 {
789 // This function only makes sense when called on hypercube cells
791
792 Assert(lattice_location.size() == dim, ExcInternalError());
793
794 const unsigned int xstep = (dim > 0 ? *(lattice_location.begin() + 0) : 0);
795 const unsigned int ystep = (dim > 1 ? *(lattice_location.begin() + 1) : 0);
796 const unsigned int zstep = (dim > 2 ? *(lattice_location.begin() + 2) : 0);
797
798 // If the patch stores the locations of nodes (rather than of only the
799 // vertices), then obtain the location by direct lookup.
800 if (patch.points_are_available)
801 {
802 Assert(n_subdivisions == patch.n_subdivisions, ExcNotImplemented());
803
804 unsigned int point_no = 0;
805 switch (dim)
806 {
807 case 3:
808 AssertIndexRange(zstep, n_subdivisions + 1);
809 point_no += (n_subdivisions + 1) * (n_subdivisions + 1) * zstep;
811 case 2:
812 AssertIndexRange(ystep, n_subdivisions + 1);
813 point_no += (n_subdivisions + 1) * ystep;
815 case 1:
816 AssertIndexRange(xstep, n_subdivisions + 1);
817 point_no += xstep;
819 case 0:
820 // break here for dim<=3
821 break;
822
823 default:
825 }
826 Point<spacedim> node;
827 for (unsigned int d = 0; d < spacedim; ++d)
828 node[d] = patch.data(patch.data.size(0) - spacedim + d, point_no);
829 return node;
830 }
831 else
832 // The patch does not store node locations, so we have to interpolate
833 // between its vertices:
834 {
835 if constexpr (dim == 0)
836 return patch.vertices[0];
837 else
838 {
839 // perform a dim-linear interpolation
840 const double stepsize = 1. / n_subdivisions;
841 const double xfrac = xstep * stepsize;
842
843 Point<spacedim> node =
844 (patch.vertices[1] * xfrac) + (patch.vertices[0] * (1 - xfrac));
845 if (dim > 1)
846 {
847 const double yfrac = ystep * stepsize;
848 node *= 1 - yfrac;
849 node += ((patch.vertices[3] * xfrac) +
850 (patch.vertices[2] * (1 - xfrac))) *
851 yfrac;
852 if (dim > 2)
853 {
854 const double zfrac = zstep * stepsize;
855 node *= (1 - zfrac);
856 node += (((patch.vertices[5] * xfrac) +
857 (patch.vertices[4] * (1 - xfrac))) *
858 (1 - yfrac) +
859 ((patch.vertices[7] * xfrac) +
860 (patch.vertices[6] * (1 - xfrac))) *
861 yfrac) *
862 zfrac;
863 }
864 }
865 return node;
866 }
867 }
868 }
869
870 // For a given patch, compute the nodes for arbitrary (non-hypercube) cells.
871 // If the points are saved in the patch.data member, return the saved point
872 // instead.
873 template <int dim, int spacedim>
874 inline Point<spacedim>
875 get_node_location(const DataOutBase::Patch<dim, spacedim> &patch,
876 const unsigned int node_index)
877 {
878 // Due to a historical accident, we are using a different indexing
879 // for pyramids in this file than we do where we create patches.
880 // So translate if necessary.
881 unsigned int point_no_actual = node_index;
883 {
885
886 static const std::array<unsigned int, 5> table = {{0, 1, 3, 2, 4}};
887 point_no_actual = table[node_index];
888 }
889
890 // If the patch stores the locations of nodes (rather than of only the
891 // vertices), then obtain the location by direct lookup.
892 if (patch.points_are_available)
893 {
894 Point<spacedim> node;
895 for (unsigned int d = 0; d < spacedim; ++d)
896 node[d] =
897 patch.data(patch.data.size(0) - spacedim + d, point_no_actual);
898 return node;
899 }
900 else
901 // The patch does not store node locations, so we have to interpolate
902 // between its vertices. This isn't currently implemented for anything
903 // other than one subdivision, but would go here.
904 //
905 // For n_subdivisions==1, the locations are simply those of vertices, so
906 // get the information from there.
907 {
909
910 return patch.vertices[point_no_actual];
911 }
912 }
913
914
915
921 template <int dim, int spacedim>
922 std::tuple<unsigned int, unsigned int>
923 count_nodes_and_cells(
924 const std::vector<DataOutBase::Patch<dim, spacedim>> &patches)
925 {
926 unsigned int n_nodes = 0;
927 unsigned int n_cells = 0;
928 for (const auto &patch : patches)
929 {
932 "The reference cell for this patch is set to 'Invalid', "
933 "but that is clearly not a valid choice. Did you forget "
934 "to set the reference cell for the patch?"));
935
936 if (patch.reference_cell.is_hyper_cube())
937 {
938 n_nodes += Utilities::fixed_power<dim>(patch.n_subdivisions + 1);
940 }
941 else
942 {
944 n_nodes += patch.reference_cell.n_vertices();
945 n_cells += 1;
946 }
947 }
948
949 return std::make_tuple(n_nodes, n_cells);
950 }
951
952
953
959 template <int dim, int spacedim>
960 std::tuple<unsigned int, unsigned int, unsigned int>
961 count_nodes_and_cells_and_points(
962 const std::vector<DataOutBase::Patch<dim, spacedim>> &patches,
963 const bool write_higher_order_cells)
964 {
965 unsigned int n_nodes = 0;
966 unsigned int n_cells = 0;
967 unsigned int n_points_and_n_cells = 0;
968
969 for (const auto &patch : patches)
970 {
971 if (patch.reference_cell.is_hyper_cube())
972 {
973 n_nodes += Utilities::fixed_power<dim>(patch.n_subdivisions + 1);
974
975 if (write_higher_order_cells)
976 {
977 // Write all of these nodes as a single higher-order cell. So
978 // add one to the number of cells, and update the number of
979 // points appropriately.
980 n_cells += 1;
981 n_points_and_n_cells +=
983 }
984 else
985 {
986 // Write all of these nodes as a collection of d-linear
987 // cells. Add the number of sub-cells to the total number of
988 // cells, and then add one for each cell plus the number of
989 // vertices per cell for each subcell to the number of points.
990 const unsigned int n_subcells =
992 n_cells += n_subcells;
993 n_points_and_n_cells +=
994 n_subcells * (1 + GeometryInfo<dim>::vertices_per_cell);
995 }
996 }
997 else
998 {
999 n_nodes += patch.data.n_cols();
1000 n_cells += 1;
1001 n_points_and_n_cells += patch.data.n_cols() + 1;
1002 }
1003 }
1004
1005 return std::make_tuple(n_nodes, n_cells, n_points_and_n_cells);
1006 }
1007
1013 template <typename FlagsType>
1014 class StreamBase
1015 {
1016 public:
1017 /*
1018 * Constructor. Stores a reference to the output stream for immediate use.
1019 */
1020 StreamBase(std::ostream &stream, const FlagsType &flags)
1021 : selected_component(numbers::invalid_unsigned_int)
1022 , stream(stream)
1023 , flags(flags)
1024 {}
1025
1030 template <int dim>
1031 void
1032 write_point(const unsigned int, const Point<dim> &)
1033 {
1034 Assert(false,
1035 ExcMessage("The derived class you are using needs to "
1036 "reimplement this function if you want to call "
1037 "it."));
1038 }
1039
1045 void
1046 flush_points()
1047 {}
1048
1054 template <int dim>
1055 void
1056 write_cell(const unsigned int /*index*/,
1057 const unsigned int /*start*/,
1058 std::array<unsigned int, dim> & /*offsets*/)
1059 {
1060 Assert(false,
1061 ExcMessage("The derived class you are using needs to "
1062 "reimplement this function if you want to call "
1063 "it."));
1064 }
1065
1072 void
1073 write_cell_single(const unsigned int index,
1074 const unsigned int start,
1075 const unsigned int n_points,
1076 const ReferenceCell &reference_cell)
1077 {
1078 (void)index;
1079 (void)start;
1080 (void)n_points;
1081 (void)reference_cell;
1082
1083 Assert(false,
1084 ExcMessage("The derived class you are using needs to "
1085 "reimplement this function if you want to call "
1086 "it."));
1087 }
1088
1095 void
1096 flush_cells()
1097 {}
1098
1103 template <typename T>
1104 std::ostream &
1105 operator<<(const T &t)
1106 {
1107 stream << t;
1108 return stream;
1109 }
1110
1117 unsigned int selected_component;
1118
1119 protected:
1124 std::ostream &stream;
1125
1129 const FlagsType flags;
1130 };
1131
1135 class DXStream : public StreamBase<DataOutBase::DXFlags>
1136 {
1137 public:
1138 DXStream(std::ostream &stream, const DataOutBase::DXFlags &flags);
1139
1140 template <int dim>
1141 void
1142 write_point(const unsigned int index, const Point<dim> &);
1143
1152 template <int dim>
1153 void
1154 write_cell(const unsigned int index,
1155 const unsigned int start,
1156 const std::array<unsigned int, dim> &offsets);
1157
1164 template <typename data>
1165 void
1166 write_dataset(const unsigned int index, const std::vector<data> &values);
1167 };
1168
1172 class GmvStream : public StreamBase<DataOutBase::GmvFlags>
1173 {
1174 public:
1175 GmvStream(std::ostream &stream, const DataOutBase::GmvFlags &flags);
1176
1177 template <int dim>
1178 void
1179 write_point(const unsigned int index, const Point<dim> &);
1180
1189 template <int dim>
1190 void
1191 write_cell(const unsigned int index,
1192 const unsigned int start,
1193 const std::array<unsigned int, dim> &offsets);
1194 };
1195
1199 class TecplotStream : public StreamBase<DataOutBase::TecplotFlags>
1200 {
1201 public:
1202 TecplotStream(std::ostream &stream, const DataOutBase::TecplotFlags &flags);
1203
1204 template <int dim>
1205 void
1206 write_point(const unsigned int index, const Point<dim> &);
1207
1216 template <int dim>
1217 void
1218 write_cell(const unsigned int index,
1219 const unsigned int start,
1220 const std::array<unsigned int, dim> &offsets);
1221 };
1222
1226 class UcdStream : public StreamBase<DataOutBase::UcdFlags>
1227 {
1228 public:
1229 UcdStream(std::ostream &stream, const DataOutBase::UcdFlags &flags);
1230
1231 template <int dim>
1232 void
1233 write_point(const unsigned int index, const Point<dim> &);
1234
1245 template <int dim>
1246 void
1247 write_cell(const unsigned int index,
1248 const unsigned int start,
1249 const std::array<unsigned int, dim> &offsets);
1250
1257 template <typename data>
1258 void
1259 write_dataset(const unsigned int index, const std::vector<data> &values);
1260 };
1261
1265 class VtkStream : public StreamBase<DataOutBase::VtkFlags>
1266 {
1267 public:
1268 VtkStream(std::ostream &stream, const DataOutBase::VtkFlags &flags);
1269
1270 template <int dim>
1271 void
1272 write_point(const unsigned int index, const Point<dim> &);
1273
1282 template <int dim>
1283 void
1284 write_cell(const unsigned int index,
1285 const unsigned int start,
1286 const std::array<unsigned int, dim> &offsets);
1287
1291 void
1292 write_cell_single(const unsigned int index,
1293 const unsigned int start,
1294 const unsigned int n_points,
1295 const ReferenceCell &reference_cell);
1296
1304 template <int dim>
1305 void
1306 write_high_order_cell(const unsigned int start,
1307 const std::vector<unsigned> &connectivity);
1308 };
1309
1310
1311 //----------------------------------------------------------------------//
1312
1313 DXStream::DXStream(std::ostream &out, const DataOutBase::DXFlags &f)
1314 : StreamBase<DataOutBase::DXFlags>(out, f)
1315 {}
1316
1317
1318 template <int dim>
1319 void
1320 DXStream::write_point(const unsigned int, const Point<dim> &p)
1321 {
1322 if (flags.coordinates_binary)
1323 {
1324 float data[dim];
1325 for (unsigned int d = 0; d < dim; ++d)
1326 data[d] = p[d];
1327 stream.write(reinterpret_cast<const char *>(data), dim * sizeof(*data));
1328 }
1329 else
1330 {
1331 for (unsigned int d = 0; d < dim; ++d)
1332 stream << p[d] << '\t';
1333 stream << '\n';
1334 }
1335 }
1336
1337
1338
1339 // Separate these out to avoid an internal compiler error with intel 17
1341 {
1346 std::array<unsigned int, GeometryInfo<0>::vertices_per_cell>
1347 set_node_numbers(const unsigned int /*start*/,
1348 const std::array<unsigned int, 0> & /*d1*/)
1349 {
1351 return {};
1352 }
1353
1354
1355
1356 std::array<unsigned int, GeometryInfo<1>::vertices_per_cell>
1357 set_node_numbers(const unsigned int start,
1358 const std::array<unsigned int, 1> &offsets)
1359 {
1360 std::array<unsigned int, GeometryInfo<1>::vertices_per_cell> nodes;
1361 nodes[0] = start;
1362 nodes[1] = start + offsets[0];
1363 return nodes;
1364 }
1365
1366
1367
1368 std::array<unsigned int, GeometryInfo<2>::vertices_per_cell>
1369 set_node_numbers(const unsigned int start,
1370 const std::array<unsigned int, 2> &offsets)
1371
1372 {
1373 const unsigned int d1 = offsets[0];
1374 const unsigned int d2 = offsets[1];
1375
1376 std::array<unsigned int, GeometryInfo<2>::vertices_per_cell> nodes;
1377 nodes[0] = start;
1378 nodes[1] = start + d1;
1379 nodes[2] = start + d2;
1380 nodes[3] = start + d2 + d1;
1381 return nodes;
1382 }
1383
1384
1385
1386 std::array<unsigned int, GeometryInfo<3>::vertices_per_cell>
1387 set_node_numbers(const unsigned int start,
1388 const std::array<unsigned int, 3> &offsets)
1389 {
1390 const unsigned int d1 = offsets[0];
1391 const unsigned int d2 = offsets[1];
1392 const unsigned int d3 = offsets[2];
1393
1394 std::array<unsigned int, GeometryInfo<3>::vertices_per_cell> nodes;
1395 nodes[0] = start;
1396 nodes[1] = start + d1;
1397 nodes[2] = start + d2;
1398 nodes[3] = start + d2 + d1;
1399 nodes[4] = start + d3;
1400 nodes[5] = start + d3 + d1;
1401 nodes[6] = start + d3 + d2;
1402 nodes[7] = start + d3 + d2 + d1;
1403 return nodes;
1404 }
1405 } // namespace DataOutBaseImplementation
1406
1407
1408
1409 template <int dim>
1410 void
1411 DXStream::write_cell(const unsigned int,
1412 const unsigned int start,
1413 const std::array<unsigned int, dim> &offsets)
1414 {
1415 const auto nodes =
1416 DataOutBaseImplementation::set_node_numbers(start, offsets);
1417
1418 if (flags.int_binary)
1419 {
1420 std::array<unsigned int, GeometryInfo<dim>::vertices_per_cell> temp;
1421 for (unsigned int i = 0; i < nodes.size(); ++i)
1422 temp[i] = nodes[GeometryInfo<dim>::dx_to_deal[i]];
1423 stream.write(reinterpret_cast<const char *>(temp.data()),
1424 temp.size() * sizeof(temp[0]));
1425 }
1426 else
1427 {
1428 for (unsigned int i = 0; i < nodes.size() - 1; ++i)
1429 stream << nodes[GeometryInfo<dim>::dx_to_deal[i]] << '\t';
1430 stream << nodes[GeometryInfo<dim>::dx_to_deal[nodes.size() - 1]]
1431 << '\n';
1432 }
1433 }
1434
1435
1436
1437 template <typename data>
1438 inline void
1439 DXStream::write_dataset(const unsigned int, const std::vector<data> &values)
1440 {
1441 if (flags.data_binary)
1442 {
1443 stream.write(reinterpret_cast<const char *>(values.data()),
1444 values.size() * sizeof(data));
1445 }
1446 else
1447 {
1448 for (unsigned int i = 0; i < values.size(); ++i)
1449 stream << '\t' << values[i];
1450 stream << '\n';
1451 }
1452 }
1453
1454
1455
1456 //----------------------------------------------------------------------//
1457
1458 GmvStream::GmvStream(std::ostream &out, const DataOutBase::GmvFlags &f)
1459 : StreamBase<DataOutBase::GmvFlags>(out, f)
1460 {}
1461
1462
1463 template <int dim>
1464 void
1465 GmvStream::write_point(const unsigned int, const Point<dim> &p)
1466 {
1467 Assert(selected_component != numbers::invalid_unsigned_int,
1469 stream << p[selected_component] << ' ';
1470 }
1471
1472
1473
1474 template <int dim>
1475 void
1476 GmvStream::write_cell(const unsigned int,
1477 const unsigned int s,
1478 const std::array<unsigned int, dim> &offsets)
1479 {
1480 // Vertices are numbered starting with one.
1481 const unsigned int start = s + 1;
1482 stream << gmv_cell_type[dim] << '\n';
1483
1484 switch (dim)
1485 {
1486 case 0:
1487 {
1488 stream << start;
1489 break;
1490 }
1491
1492 case 1:
1493 {
1494 const unsigned int d1 = offsets[0];
1495 stream << start;
1496 stream << '\t' << start + d1;
1497 break;
1498 }
1499
1500 case 2:
1501 {
1502 const unsigned int d1 = offsets[0];
1503 const unsigned int d2 = offsets[1];
1504 stream << start;
1505 stream << '\t' << start + d1;
1506 stream << '\t' << start + d2 + d1 << '\t' << start + d2;
1507 break;
1508 }
1509
1510 case 3:
1511 {
1512 const unsigned int d1 = offsets[0];
1513 const unsigned int d2 = offsets[1];
1514 const unsigned int d3 = offsets[2];
1515 stream << start;
1516 stream << '\t' << start + d1;
1517 stream << '\t' << start + d2 + d1 << '\t' << start + d2;
1518 stream << '\t' << start + d3 << '\t' << start + d3 + d1 << '\t'
1519 << start + d3 + d2 + d1 << '\t' << start + d3 + d2;
1520 break;
1521 }
1522
1523 default:
1525 }
1526 stream << '\n';
1527 }
1528
1529
1530
1531 TecplotStream::TecplotStream(std::ostream &out,
1532 const DataOutBase::TecplotFlags &f)
1533 : StreamBase<DataOutBase::TecplotFlags>(out, f)
1534 {}
1535
1536
1537 template <int dim>
1538 void
1539 TecplotStream::write_point(const unsigned int, const Point<dim> &p)
1540 {
1541 Assert(selected_component != numbers::invalid_unsigned_int,
1543 stream << p[selected_component] << '\n';
1544 }
1545
1546
1547
1548 template <int dim>
1549 void
1550 TecplotStream::write_cell(const unsigned int,
1551 const unsigned int s,
1552 const std::array<unsigned int, dim> &offsets)
1553 {
1554 const unsigned int start = s + 1;
1555
1556 switch (dim)
1557 {
1558 case 0:
1559 {
1560 stream << start;
1561 break;
1562 }
1563
1564 case 1:
1565 {
1566 const unsigned int d1 = offsets[0];
1567 stream << start;
1568 stream << '\t' << start + d1;
1569 break;
1570 }
1571
1572 case 2:
1573 {
1574 const unsigned int d1 = offsets[0];
1575 const unsigned int d2 = offsets[1];
1576 stream << start;
1577 stream << '\t' << start + d1;
1578 stream << '\t' << start + d2 + d1 << '\t' << start + d2;
1579 break;
1580 }
1581
1582 case 3:
1583 {
1584 const unsigned int d1 = offsets[0];
1585 const unsigned int d2 = offsets[1];
1586 const unsigned int d3 = offsets[2];
1587 stream << start;
1588 stream << '\t' << start + d1;
1589 stream << '\t' << start + d2 + d1 << '\t' << start + d2;
1590 stream << '\t' << start + d3 << '\t' << start + d3 + d1 << '\t'
1591 << start + d3 + d2 + d1 << '\t' << start + d3 + d2;
1592 break;
1593 }
1594
1595 default:
1597 }
1598 stream << '\n';
1599 }
1600
1601
1602
1603 UcdStream::UcdStream(std::ostream &out, const DataOutBase::UcdFlags &f)
1604 : StreamBase<DataOutBase::UcdFlags>(out, f)
1605 {}
1606
1607
1608 template <int dim>
1609 void
1610 UcdStream::write_point(const unsigned int index, const Point<dim> &p)
1611 {
1612 stream << index + 1 << " ";
1613 // write out coordinates
1614 for (unsigned int i = 0; i < dim; ++i)
1615 stream << p[i] << ' ';
1616 // fill with zeroes
1617 for (unsigned int i = dim; i < 3; ++i)
1618 stream << "0 ";
1619 stream << '\n';
1620 }
1621
1622
1623
1624 template <int dim>
1625 void
1626 UcdStream::write_cell(const unsigned int index,
1627 const unsigned int start,
1628 const std::array<unsigned int, dim> &offsets)
1629 {
1630 const auto nodes =
1631 DataOutBaseImplementation::set_node_numbers(start, offsets);
1632
1633 // Write out all cells and remember that all indices must be shifted by one.
1634 stream << index + 1 << "\t0 " << ucd_cell_type[dim];
1635 for (unsigned int i = 0; i < nodes.size(); ++i)
1636 stream << '\t' << nodes[GeometryInfo<dim>::ucd_to_deal[i]] + 1;
1637 stream << '\n';
1638 }
1639
1640
1641
1642 template <typename data>
1643 inline void
1644 UcdStream::write_dataset(const unsigned int index,
1645 const std::vector<data> &values)
1646 {
1647 stream << index + 1;
1648 for (unsigned int i = 0; i < values.size(); ++i)
1649 stream << '\t' << values[i];
1650 stream << '\n';
1651 }
1652
1653
1654
1655 //----------------------------------------------------------------------//
1656
1657 VtkStream::VtkStream(std::ostream &out, const DataOutBase::VtkFlags &f)
1658 : StreamBase<DataOutBase::VtkFlags>(out, f)
1659 {}
1660
1661
1662 template <int dim>
1663 void
1664 VtkStream::write_point(const unsigned int, const Point<dim> &p)
1665 {
1666 // write out coordinates
1667 stream << p;
1668 // fill with zeroes
1669 for (unsigned int i = dim; i < 3; ++i)
1670 stream << " 0";
1671 stream << '\n';
1672 }
1673
1674
1675
1676 template <int dim>
1677 void
1678 VtkStream::write_cell(const unsigned int,
1679 const unsigned int start,
1680 const std::array<unsigned int, dim> &offsets)
1681 {
1682 stream << GeometryInfo<dim>::vertices_per_cell << '\t';
1683
1684 switch (dim)
1685 {
1686 case 0:
1687 {
1688 stream << start;
1689 break;
1690 }
1691
1692 case 1:
1693 {
1694 const unsigned int d1 = offsets[0];
1695 stream << start;
1696 stream << '\t' << start + d1;
1697 break;
1698 }
1699
1700 case 2:
1701 {
1702 const unsigned int d1 = offsets[0];
1703 const unsigned int d2 = offsets[1];
1704 stream << start;
1705 stream << '\t' << start + d1;
1706 stream << '\t' << start + d2 + d1 << '\t' << start + d2;
1707 break;
1708 }
1709
1710 case 3:
1711 {
1712 const unsigned int d1 = offsets[0];
1713 const unsigned int d2 = offsets[1];
1714 const unsigned int d3 = offsets[2];
1715 stream << start;
1716 stream << '\t' << start + d1;
1717 stream << '\t' << start + d2 + d1 << '\t' << start + d2;
1718 stream << '\t' << start + d3 << '\t' << start + d3 + d1 << '\t'
1719 << start + d3 + d2 + d1 << '\t' << start + d3 + d2;
1720 break;
1721 }
1722
1723 default:
1725 }
1726 stream << '\n';
1727 }
1728
1729
1730
1731 void
1732 VtkStream::write_cell_single(const unsigned int index,
1733 const unsigned int start,
1734 const unsigned int n_points,
1735 const ReferenceCell &reference_cell)
1736 {
1737 (void)index;
1738
1739 static const std::array<unsigned int, 5> table = {{0, 1, 3, 2, 4}};
1740
1741 stream << '\t' << n_points;
1742 for (unsigned int i = 0; i < n_points; ++i)
1743 stream << '\t'
1744 << start +
1745 (reference_cell == ReferenceCells::Pyramid ? table[i] : i);
1746 stream << '\n';
1747 }
1748
1749 template <int dim>
1750 void
1751 VtkStream::write_high_order_cell(const unsigned int start,
1752 const std::vector<unsigned> &connectivity)
1753 {
1754 stream << connectivity.size();
1755 for (const auto &c : connectivity)
1756 stream << '\t' << start + c;
1757 stream << '\n';
1758 }
1759} // namespace
1760
1761
1762
1763namespace DataOutBase
1764{
1765 const unsigned int Deal_II_IntermediateFlags::format_version = 4;
1766
1767
1768 template <int dim, int spacedim>
1770
1771
1772 template <int dim, int spacedim>
1774
1775
1776 template <int dim, int spacedim>
1779 , n_subdivisions(1)
1780 , points_are_available(false)
1781 , reference_cell(ReferenceCells::Invalid)
1782 // all the other data has a constructor of its own, except for the "neighbors"
1783 // field, which we set to invalid values.
1784 {
1785 for (const unsigned int i : GeometryInfo<dim>::face_indices())
1787
1788 AssertIndexRange(dim, spacedim + 1);
1789 Assert(spacedim <= 3, ExcNotImplemented());
1790 }
1791
1792
1793
1794 template <int dim, int spacedim>
1795 bool
1797 {
1798 if (reference_cell != patch.reference_cell)
1799 return false;
1800
1801 // TODO: make tolerance relative
1802 const double epsilon = 3e-16;
1803 for (const unsigned int i : GeometryInfo<dim>::vertex_indices())
1804 if (vertices[i].distance(patch.vertices[i]) > epsilon)
1805 return false;
1806
1807 for (const unsigned int i : GeometryInfo<dim>::face_indices())
1808 if (neighbors[i] != patch.neighbors[i])
1809 return false;
1810
1811 if (patch_index != patch.patch_index)
1812 return false;
1813
1814 if (n_subdivisions != patch.n_subdivisions)
1815 return false;
1816
1818 return false;
1819
1820 if (data.n_rows() != patch.data.n_rows())
1821 return false;
1822
1823 if (data.n_cols() != patch.data.n_cols())
1824 return false;
1825
1826 for (unsigned int i = 0; i < data.n_rows(); ++i)
1827 for (unsigned int j = 0; j < data.n_cols(); ++j)
1828 if (data[i][j] != patch.data[i][j])
1829 return false;
1830
1831 return true;
1832 }
1833
1834
1835
1836 template <int dim, int spacedim>
1837 std::size_t
1850
1851
1852
1853 template <int dim, int spacedim>
1854 void
1856 {
1857 std::swap(vertices, other_patch.vertices);
1858 std::swap(neighbors, other_patch.neighbors);
1859 std::swap(patch_index, other_patch.patch_index);
1860 std::swap(n_subdivisions, other_patch.n_subdivisions);
1861 data.swap(other_patch.data);
1862 std::swap(points_are_available, other_patch.points_are_available);
1863 std::swap(reference_cell, other_patch.reference_cell);
1864 }
1865
1866
1867
1868 template <int spacedim>
1870
1871
1872 template <int spacedim>
1874
1875
1876 template <int spacedim>
1879
1880 template <int spacedim>
1882
1883 template <int spacedim>
1886
1887 template <int spacedim>
1890 , points_are_available(false)
1891 {
1892 Assert(spacedim <= 3, ExcNotImplemented());
1893 }
1894
1895
1896
1897 template <int spacedim>
1898 bool
1900 {
1901 const unsigned int dim = 0;
1902
1903 // TODO: make tolerance relative
1904 const double epsilon = 3e-16;
1905 for (const unsigned int i : GeometryInfo<dim>::vertex_indices())
1906 if (vertices[i].distance(patch.vertices[i]) > epsilon)
1907 return false;
1908
1909 if (patch_index != patch.patch_index)
1910 return false;
1911
1913 return false;
1914
1915 if (data.n_rows() != patch.data.n_rows())
1916 return false;
1917
1918 if (data.n_cols() != patch.data.n_cols())
1919 return false;
1920
1921 for (unsigned int i = 0; i < data.n_rows(); ++i)
1922 for (unsigned int j = 0; j < data.n_cols(); ++j)
1923 if (data[i][j] != patch.data[i][j])
1924 return false;
1925
1926 return true;
1927 }
1928
1929
1930
1931 template <int spacedim>
1932 std::size_t
1940
1941
1942
1943 template <int spacedim>
1944 void
1946 {
1947 std::swap(vertices, other_patch.vertices);
1948 std::swap(patch_index, other_patch.patch_index);
1949 data.swap(other_patch.data);
1950 std::swap(points_are_available, other_patch.points_are_available);
1951 }
1952
1953
1954
1958
1959
1960
1962 {
1963 space_dimension_labels.emplace_back("x");
1964 space_dimension_labels.emplace_back("y");
1965 space_dimension_labels.emplace_back("z");
1966 }
1967
1968
1969
1970 GnuplotFlags::GnuplotFlags(const std::vector<std::string> &labels)
1971 : space_dimension_labels(labels)
1972 {}
1973
1974
1975
1976 std::size_t
1981
1982
1983
1985 const bool bicubic_patch,
1986 const bool external_data)
1987 : smooth(smooth)
1990 {}
1991
1992
1998
1999
2000 void
2002 {
2003 prm.declare_entry(
2004 "Filter duplicate vertices",
2005 "false",
2007 "Whether to remove duplicate vertex values. deal.II duplicates "
2008 "vertices once for each adjacent cell so that it can output "
2009 "discontinuous quantities for which there may be more than one "
2010 "value for each vertex position. Setting this flag to "
2011 "'true' will merge all of these values by selecting a "
2012 "random one and outputting this as 'the' value for the vertex. "
2013 "As long as the data to be output corresponds to continuous "
2014 "fields, merging vertices has no effect. On the other hand, "
2015 "if the data to be output corresponds to discontinuous fields "
2016 "(either because you are using a discontinuous finite element, "
2017 "or because you are using a DataPostprocessor that yields "
2018 "discontinuous data, or because the data to be output has been "
2019 "produced by entirely different means), then the data in the "
2020 "output file no longer faithfully represents the underlying data "
2021 "because the discontinuous field has been replaced by a "
2022 "continuous one. Note also that the filtering can not occur "
2023 "on processor boundaries. Thus, a filtered discontinuous field "
2024 "looks like a continuous field inside of a subdomain, "
2025 "but like a discontinuous field at the subdomain boundary."
2026 "\n\n"
2027 "In any case, filtering results in drastically smaller output "
2028 "files (smaller by about a factor of 2^dim).");
2029 prm.declare_entry(
2030 "XDMF HDF5 output",
2031 "false",
2033 "Whether the data will be used in an XDMF/HDF5 combination.");
2034 }
2035
2036
2037
2038 void
2040 {
2041 filter_duplicate_vertices = prm.get_bool("Filter duplicate vertices");
2042 xdmf_hdf5_output = prm.get_bool("XDMF HDF5 output");
2043 }
2044
2045
2046
2048 const bool int_binary,
2049 const bool coordinates_binary,
2050 const bool data_binary)
2055 , data_double(false)
2056 {}
2057
2058
2059 void
2061 {
2062 prm.declare_entry("Write neighbors",
2063 "true",
2065 "A boolean field indicating whether neighborship "
2066 "information between cells is to be written to the "
2067 "OpenDX output file");
2068 prm.declare_entry("Integer format",
2069 "ascii",
2070 Patterns::Selection("ascii|32|64"),
2071 "Output format of integer numbers, which is "
2072 "either a text representation (ascii) or binary integer "
2073 "values of 32 or 64 bits length");
2074 prm.declare_entry("Coordinates format",
2075 "ascii",
2076 Patterns::Selection("ascii|32|64"),
2077 "Output format of vertex coordinates, which is "
2078 "either a text representation (ascii) or binary "
2079 "floating point values of 32 or 64 bits length");
2080 prm.declare_entry("Data format",
2081 "ascii",
2082 Patterns::Selection("ascii|32|64"),
2083 "Output format of data values, which is "
2084 "either a text representation (ascii) or binary "
2085 "floating point values of 32 or 64 bits length");
2086 }
2087
2088
2089
2090 void
2092 {
2093 write_neighbors = prm.get_bool("Write neighbors");
2094 // TODO:[GK] Read the new parameters
2095 }
2096
2097
2098
2099 void
2101 {
2102 prm.declare_entry("Write preamble",
2103 "true",
2105 "A flag indicating whether a comment should be "
2106 "written to the beginning of the output file "
2107 "indicating date and time of creation as well "
2108 "as the creating program");
2109 }
2110
2111
2112
2113 void
2115 {
2116 write_preamble = prm.get_bool("Write preamble");
2117 }
2118
2119
2120
2122 const int azimuth_angle,
2123 const int polar_angle,
2124 const unsigned int line_thickness,
2125 const bool margin,
2126 const bool draw_colorbar)
2127 : height(4000)
2128 , width(0)
2133 , margin(margin)
2135 {}
2136
2137
2138
2139 void
2141 {
2142 prm.declare_entry("Use smooth triangles",
2143 "false",
2145 "A flag indicating whether POVRAY should use smoothed "
2146 "triangles instead of the usual ones");
2147 prm.declare_entry("Use bicubic patches",
2148 "false",
2150 "Whether POVRAY should use bicubic patches");
2151 prm.declare_entry("Include external file",
2152 "true",
2154 "Whether camera and lighting information should "
2155 "be put into an external file \"data.inc\" or into "
2156 "the POVRAY input file");
2157 }
2158
2159
2160
2161 void
2163 {
2164 smooth = prm.get_bool("Use smooth triangles");
2165 bicubic_patch = prm.get_bool("Use bicubic patches");
2166 external_data = prm.get_bool("Include external file");
2167 }
2168
2169
2170
2172 const unsigned int color_vector,
2173 const SizeType size_type,
2174 const unsigned int size,
2175 const double line_width,
2176 const double azimut_angle,
2177 const double turn_angle,
2178 const double z_scaling,
2179 const bool draw_mesh,
2180 const bool draw_cells,
2181 const bool shade_cells,
2186 , size(size)
2195 {}
2196
2197
2198
2201 const double xmin,
2202 const double xmax)
2203 {
2204 RgbValues rgb_values = {0, 0, 0};
2205
2206 // A difficult color scale:
2207 // xmin = black [1]
2208 // 3/4*xmin+1/4*xmax = blue [2]
2209 // 1/2*xmin+1/2*xmax = green (3)
2210 // 1/4*xmin+3/4*xmax = red (4)
2211 // xmax = white (5)
2212 // Makes the following color functions:
2213 //
2214 // red green blue
2215 // __
2216 // / /\ / /\ /
2217 // ____/ __/ \/ / \__/
2218
2219 // { 0 [1] - (3)
2220 // r = { ( 4*x-2*xmin+2*xmax)/(xmax-xmin) (3) - (4)
2221 // { 1 (4) - (5)
2222 //
2223 // { 0 [1] - [2]
2224 // g = { ( 4*x-3*xmin- xmax)/(xmax-xmin) [2] - (3)
2225 // { (-4*x+ xmin+3*xmax)/(xmax-xmin) (3) - (4)
2226 // { ( 4*x- xmin-3*xmax)/(xmax-xmin) (4) - (5)
2227 //
2228 // { ( 4*x-4*xmin )/(xmax-xmin) [1] - [2]
2229 // b = { (-4*x+2*xmin+2*xmax)/(xmax-xmin) [2] - (3)
2230 // { 0 (3) - (4)
2231 // { ( 4*x- xmin-3*xmax)/(xmax-xmin) (4) - (5)
2232
2233 double sum = xmax + xmin;
2234 double sum13 = xmin + 3 * xmax;
2235 double sum22 = 2 * xmin + 2 * xmax;
2236 double sum31 = 3 * xmin + xmax;
2237 double dif = xmax - xmin;
2238 double rezdif = 1.0 / dif;
2239
2240 int where;
2241
2242 if (x < (sum31) / 4)
2243 where = 0;
2244 else if (x < (sum22) / 4)
2245 where = 1;
2246 else if (x < (sum13) / 4)
2247 where = 2;
2248 else
2249 where = 3;
2250
2251 if (dif != 0)
2252 {
2253 switch (where)
2254 {
2255 case 0:
2256 rgb_values.red = 0;
2257 rgb_values.green = 0;
2258 rgb_values.blue = (x - xmin) * 4. * rezdif;
2259 break;
2260 case 1:
2261 rgb_values.red = 0;
2262 rgb_values.green = (4 * x - 3 * xmin - xmax) * rezdif;
2263 rgb_values.blue = (sum22 - 4. * x) * rezdif;
2264 break;
2265 case 2:
2266 rgb_values.red = (4 * x - 2 * sum) * rezdif;
2267 rgb_values.green = (xmin + 3 * xmax - 4 * x) * rezdif;
2268 rgb_values.blue = 0;
2269 break;
2270 case 3:
2271 rgb_values.red = 1;
2272 rgb_values.green = (4 * x - xmin - 3 * xmax) * rezdif;
2273 rgb_values.blue = (4. * x - sum13) * rezdif;
2274 break;
2275 default:
2276 break;
2277 }
2278 }
2279 else // White
2280 rgb_values.red = rgb_values.green = rgb_values.blue = 1;
2281
2282 return rgb_values;
2283 }
2284
2285
2286
2289 const double xmin,
2290 const double xmax)
2291 {
2292 EpsFlags::RgbValues rgb_values;
2293 rgb_values.red = rgb_values.blue = rgb_values.green =
2294 (x - xmin) / (xmax - xmin);
2295 return rgb_values;
2296 }
2297
2298
2299
2302 const double xmin,
2303 const double xmax)
2304 {
2305 EpsFlags::RgbValues rgb_values;
2306 rgb_values.red = rgb_values.blue = rgb_values.green =
2307 1 - (x - xmin) / (xmax - xmin);
2308 return rgb_values;
2309 }
2310
2311
2312
2313 void
2315 {
2316 prm.declare_entry("Index of vector for height",
2317 "0",
2319 "Number of the input vector that is to be used to "
2320 "generate height information");
2321 prm.declare_entry("Index of vector for color",
2322 "0",
2324 "Number of the input vector that is to be used to "
2325 "generate color information");
2326 prm.declare_entry("Scale to width or height",
2327 "width",
2328 Patterns::Selection("width|height"),
2329 "Whether width or height should be scaled to match "
2330 "the given size");
2331 prm.declare_entry("Size (width or height) in eps units",
2332 "300",
2334 "The size (width or height) to which the eps output "
2335 "file is to be scaled");
2336 prm.declare_entry("Line widths in eps units",
2337 "0.5",
2339 "The width in which the postscript renderer is to "
2340 "plot lines");
2341 prm.declare_entry("Azimut angle",
2342 "60",
2343 Patterns::Double(0, 180),
2344 "Angle of the viewing position against the vertical "
2345 "axis");
2346 prm.declare_entry("Turn angle",
2347 "30",
2348 Patterns::Double(0, 360),
2349 "Angle of the viewing direction against the y-axis");
2350 prm.declare_entry("Scaling for z-axis",
2351 "1",
2353 "Scaling for the z-direction relative to the scaling "
2354 "used in x- and y-directions");
2355 prm.declare_entry("Draw mesh lines",
2356 "true",
2358 "Whether the mesh lines, or only the surface should be "
2359 "drawn");
2360 prm.declare_entry("Fill interior of cells",
2361 "true",
2363 "Whether only the mesh lines, or also the interior of "
2364 "cells should be plotted. If this flag is false, then "
2365 "one can see through the mesh");
2366 prm.declare_entry("Color shading of interior of cells",
2367 "true",
2369 "Whether the interior of cells shall be shaded");
2370 prm.declare_entry("Color function",
2371 "default",
2373 "default|grey scale|reverse grey scale"),
2374 "Name of a color function used to colorize mesh lines "
2375 "and/or cell interiors");
2376 }
2377
2378
2379
2380 void
2382 {
2383 height_vector = prm.get_integer("Index of vector for height");
2384 color_vector = prm.get_integer("Index of vector for color");
2385 if (prm.get("Scale to width or height") == "width")
2386 size_type = width;
2387 else
2388 size_type = height;
2389 size = prm.get_integer("Size (width or height) in eps units");
2390 line_width = prm.get_double("Line widths in eps units");
2391 azimut_angle = prm.get_double("Azimut angle");
2392 turn_angle = prm.get_double("Turn angle");
2393 z_scaling = prm.get_double("Scaling for z-axis");
2394 draw_mesh = prm.get_bool("Draw mesh lines");
2395 draw_cells = prm.get_bool("Fill interior of cells");
2396 shade_cells = prm.get_bool("Color shading of interior of cells");
2397 if (prm.get("Color function") == "default")
2399 else if (prm.get("Color function") == "grey scale")
2401 else if (prm.get("Color function") == "reverse grey scale")
2403 else
2404 // we shouldn't get here, since the parameter object should already have
2405 // checked that the given value is valid
2407 }
2408
2409
2413
2414
2419
2420
2421
2422 std::size_t
2424 {
2425 return sizeof(*this) + MemoryConsumption::memory_consumption(zone_name);
2426 }
2427
2428
2429
2431 const unsigned int cycle,
2432 const bool print_date_and_time,
2434 const bool write_higher_order_cells,
2435 const std::map<std::string, std::string> &physical_units)
2436 : time(time)
2437 , cycle(cycle)
2442 {}
2443
2444
2445
2447 parse_output_format(const std::string &format_name)
2448 {
2449 if (format_name == "none")
2450 return none;
2451
2452 if (format_name == "dx")
2453 return dx;
2454
2455 if (format_name == "ucd")
2456 return ucd;
2457
2458 if (format_name == "gnuplot")
2459 return gnuplot;
2460
2461 if (format_name == "povray")
2462 return povray;
2463
2464 if (format_name == "eps")
2465 return eps;
2466
2467 if (format_name == "gmv")
2468 return gmv;
2469
2470 if (format_name == "tecplot")
2471 return tecplot;
2472
2473 if (format_name == "vtk")
2474 return vtk;
2475
2476 if (format_name == "vtu")
2477 return vtu;
2478
2479 if (format_name == "deal.II intermediate")
2480 return deal_II_intermediate;
2481
2482 if (format_name == "hdf5")
2483 return hdf5;
2484
2485 AssertThrow(false,
2486 ExcMessage("The given file format name is not recognized: <" +
2487 format_name + ">"));
2488
2489 // return something invalid
2490 return OutputFormat(-1);
2491 }
2492
2493
2494
2495 std::string
2497 {
2498 return "none|dx|ucd|gnuplot|povray|eps|gmv|tecplot|vtk|vtu|hdf5|svg|deal.II intermediate";
2499 }
2500
2501
2502
2503 std::string
2504 default_suffix(const OutputFormat output_format)
2505 {
2506 switch (output_format)
2507 {
2508 case none:
2509 return "";
2510 case dx:
2511 return ".dx";
2512 case ucd:
2513 return ".inp";
2514 case gnuplot:
2515 return ".gnuplot";
2516 case povray:
2517 return ".pov";
2518 case eps:
2519 return ".eps";
2520 case gmv:
2521 return ".gmv";
2522 case tecplot:
2523 return ".dat";
2524 case vtk:
2525 return ".vtk";
2526 case vtu:
2527 return ".vtu";
2529 return ".d2";
2530 case hdf5:
2531 return ".h5";
2532 case svg:
2533 return ".svg";
2534 default:
2536 return "";
2537 }
2538 }
2539
2540
2541 //----------------------------------------------------------------------//
2542
2543
2548 template <int dim, int spacedim>
2549 std::vector<Point<spacedim>>
2550 get_node_positions(const std::vector<Patch<dim, spacedim>> &patches)
2551 {
2552 Assert(dim <= 3, ExcNotImplemented());
2553 static const std::array<unsigned int, 5> table = {{0, 1, 3, 2, 4}};
2554
2555 std::vector<Point<spacedim>> node_positions;
2556 for (const auto &patch : patches)
2557 {
2558 // special treatment of non-hypercube cells
2560 {
2561 for (unsigned int point_no = 0; point_no < patch.data.n_cols();
2562 ++point_no)
2563 node_positions.emplace_back(get_node_location(
2564 patch,
2566 table[point_no] :
2567 point_no)));
2568 }
2569 else
2570 {
2571 const unsigned int n_subdivisions = patch.n_subdivisions;
2572 const unsigned int n = n_subdivisions + 1;
2573
2574 switch (dim)
2575 {
2576 case 0:
2577 node_positions.emplace_back(
2578 get_equispaced_location(patch, {}, n_subdivisions));
2579 break;
2580 case 1:
2581 for (unsigned int i1 = 0; i1 < n; ++i1)
2582 node_positions.emplace_back(
2583 get_equispaced_location(patch, {i1}, n_subdivisions));
2584 break;
2585 case 2:
2586 for (unsigned int i2 = 0; i2 < n; ++i2)
2587 for (unsigned int i1 = 0; i1 < n; ++i1)
2588 node_positions.emplace_back(get_equispaced_location(
2589 patch, {i1, i2}, n_subdivisions));
2590 break;
2591 case 3:
2592 for (unsigned int i3 = 0; i3 < n; ++i3)
2593 for (unsigned int i2 = 0; i2 < n; ++i2)
2594 for (unsigned int i1 = 0; i1 < n; ++i1)
2595 node_positions.emplace_back(get_equispaced_location(
2596 patch, {i1, i2, i3}, n_subdivisions));
2597 break;
2598
2599 default:
2601 }
2602 }
2603 }
2604
2605 return node_positions;
2606 }
2607
2608
2609 template <int dim, int spacedim, typename StreamType>
2610 void
2611 write_nodes(const std::vector<Patch<dim, spacedim>> &patches, StreamType &out)
2612 {
2613 // Obtain the node locations, and then output them via the given stream
2614 // object
2615 const std::vector<Point<spacedim>> node_positions =
2616 get_node_positions(patches);
2617
2618 int count = 0;
2619 for (const auto &node : node_positions)
2620 out.write_point(count++, node);
2621 out.flush_points();
2622 }
2623
2624
2625
2626 template <int dim, int spacedim, typename StreamType>
2627 void
2628 write_cells(const std::vector<Patch<dim, spacedim>> &patches, StreamType &out)
2629 {
2631 unsigned int count = 0;
2632 unsigned int first_vertex_of_patch = 0;
2633 for (const auto &patch : patches)
2634 {
2635 // special treatment of simplices since they are not subdivided
2637 {
2638 out.write_cell_single(count++,
2639 first_vertex_of_patch,
2640 patch.data.n_cols(),
2641 patch.reference_cell);
2642 first_vertex_of_patch += patch.data.n_cols();
2644 else // hypercube cell
2645 {
2646 const unsigned int n_subdivisions = patch.n_subdivisions;
2647 const unsigned int n = n_subdivisions + 1;
2648
2649 switch (dim)
2651 case 0:
2652 {
2653 const unsigned int offset = first_vertex_of_patch;
2654 out.template write_cell<0>(count++, offset, {});
2655 break;
2656 }
2658 case 1:
2659 {
2660 constexpr unsigned int d1 = 1;
2661
2662 for (unsigned int i1 = 0; i1 < n_subdivisions; ++i1)
2663 {
2664 const unsigned int offset =
2665 first_vertex_of_patch + i1 * d1;
2666 out.template write_cell<1>(count++, offset, {{d1}});
2667 }
2668
2669 break;
2670 }
2672 case 2:
2673 {
2674 constexpr unsigned int d1 = 1;
2675 const unsigned int d2 = n;
2676
2677 for (unsigned int i2 = 0; i2 < n_subdivisions; ++i2)
2678 for (unsigned int i1 = 0; i1 < n_subdivisions; ++i1)
2679 {
2680 const unsigned int offset =
2681 first_vertex_of_patch + i2 * d2 + i1 * d1;
2682 out.template write_cell<2>(count++,
2683 offset,
2684 {{d1, d2}});
2686
2687 break;
2688 }
2689
2690 case 3:
2691 {
2692 constexpr unsigned int d1 = 1;
2693 const unsigned int d2 = n;
2694 const unsigned int d3 = n * n;
2695
2696 for (unsigned int i3 = 0; i3 < n_subdivisions; ++i3)
2697 for (unsigned int i2 = 0; i2 < n_subdivisions; ++i2)
2698 for (unsigned int i1 = 0; i1 < n_subdivisions; ++i1)
2700 const unsigned int offset = first_vertex_of_patch +
2701 i3 * d3 + i2 * d2 +
2702 i1 * d1;
2703 out.template write_cell<3>(count++,
2704 offset,
2705 {{d1, d2, d3}});
2706 }
2707
2708 break;
2709 }
2710 default:
2712 }
2713
2714 // Update the number of the first vertex of this patch
2715 first_vertex_of_patch +=
2717 }
2718 }
2719
2720 out.flush_cells();
2721 }
2722
2723
2724
2725 template <int dim, int spacedim, typename StreamType>
2726 void
2728 StreamType &out,
2729 const bool legacy_format)
2730 {
2731 unsigned int first_vertex_of_patch = 0;
2732 // Array to hold all the node numbers of a cell
2733 std::vector<unsigned> connectivity;
2734
2735 for (const auto &patch : patches)
2736 {
2738 {
2739 connectivity.resize(patch.data.n_cols());
2740
2741 for (unsigned int i = 0; i < patch.data.n_cols(); ++i)
2742 connectivity[i] = i;
2743
2744 out.template write_high_order_cell<dim>(first_vertex_of_patch,
2745 connectivity);
2746
2747 first_vertex_of_patch += patch.data.n_cols();
2748 }
2749 else
2750 {
2751 const unsigned int n_subdivisions = patch.n_subdivisions;
2752 const unsigned int n = n_subdivisions + 1;
2753
2754 connectivity.resize(Utilities::fixed_power<dim>(n));
2755
2756 switch (dim)
2757 {
2758 case 0:
2759 {
2760 Assert(false,
2761 ExcMessage("Point-like cells should not be possible "
2762 "when writing higher-order cells."));
2763 break;
2764 }
2765 case 1:
2766 {
2767 for (unsigned int i1 = 0; i1 < n_subdivisions + 1; ++i1)
2768 {
2769 const unsigned int local_index = i1;
2770 const unsigned int connectivity_index =
2771 patch.reference_cell
2772 .template vtk_lexicographic_to_node_index<1>(
2773 {{i1}}, {{n_subdivisions}}, legacy_format);
2774 connectivity[connectivity_index] = local_index;
2775 }
2776
2777 break;
2778 }
2779 case 2:
2780 {
2781 for (unsigned int i2 = 0; i2 < n_subdivisions + 1; ++i2)
2782 for (unsigned int i1 = 0; i1 < n_subdivisions + 1; ++i1)
2783 {
2784 const unsigned int local_index = i2 * n + i1;
2785 const unsigned int connectivity_index =
2786 patch.reference_cell
2787 .template vtk_lexicographic_to_node_index<2>(
2788 {{i1, i2}},
2790 legacy_format);
2791 connectivity[connectivity_index] = local_index;
2792 }
2793
2794 break;
2795 }
2796 case 3:
2797 {
2798 for (unsigned int i3 = 0; i3 < n_subdivisions + 1; ++i3)
2799 for (unsigned int i2 = 0; i2 < n_subdivisions + 1; ++i2)
2800 for (unsigned int i1 = 0; i1 < n_subdivisions + 1; ++i1)
2801 {
2802 const unsigned int local_index =
2803 i3 * n * n + i2 * n + i1;
2804 const unsigned int connectivity_index =
2805 patch.reference_cell
2806 .template vtk_lexicographic_to_node_index<3>(
2807 {{i1, i2, i3}},
2811 legacy_format);
2812 connectivity[connectivity_index] = local_index;
2813 }
2814
2815 break;
2816 }
2817 default:
2819 }
2820
2821 // Having so set up the 'connectivity' data structure,
2822 // output it:
2823 out.template write_high_order_cell<dim>(first_vertex_of_patch,
2824 connectivity);
2825
2826 // Finally update the number of the first vertex of this patch
2827 first_vertex_of_patch += Utilities::fixed_power<dim>(n);
2828 }
2829 }
2831 out.flush_cells();
2832 }
2833
2834
2835 template <int dim, int spacedim, typename StreamType>
2836 void
2837 write_data(const std::vector<Patch<dim, spacedim>> &patches,
2838 unsigned int n_data_sets,
2839 const bool double_precision,
2840 StreamType &out)
2841 {
2842 Assert(dim <= 3, ExcNotImplemented());
2843 unsigned int count = 0;
2844
2845 for (const auto &patch : patches)
2846 {
2847 const unsigned int n_subdivisions = patch.n_subdivisions;
2848 const unsigned int n = n_subdivisions + 1;
2849 // Length of loops in all dimensions
2850 Assert((patch.data.n_rows() == n_data_sets &&
2851 !patch.points_are_available) ||
2852 (patch.data.n_rows() == n_data_sets + spacedim &&
2853 patch.points_are_available),
2855 (n_data_sets + spacedim) :
2856 n_data_sets,
2857 patch.data.n_rows()));
2858 Assert(patch.data.n_cols() == Utilities::fixed_power<dim>(n),
2859 ExcInvalidDatasetSize(patch.data.n_cols(), n));
2860
2861 std::vector<float> floats(n_data_sets);
2862 std::vector<double> doubles(n_data_sets);
2863
2864 // Data is already in lexicographic ordering
2865 for (unsigned int i = 0; i < Utilities::fixed_power<dim>(n);
2866 ++i, ++count)
2867 if (double_precision)
2868 {
2869 for (unsigned int data_set = 0; data_set < n_data_sets;
2870 ++data_set)
2871 doubles[data_set] = patch.data(data_set, i);
2872 out.write_dataset(count, doubles);
2873 }
2874 else
2875 {
2876 for (unsigned int data_set = 0; data_set < n_data_sets;
2877 ++data_set)
2878 floats[data_set] = patch.data(data_set, i);
2879 out.write_dataset(count, floats);
2880 }
2881 }
2882 }
2883
2884
2885
2886 namespace
2887 {
2896 Point<2>
2897 svg_project_point(Point<3> point,
2898 Point<3> camera_position,
2899 Point<3> camera_direction,
2900 Point<3> camera_horizontal,
2901 float camera_focus)
2902 {
2903 Point<3> camera_vertical;
2904 camera_vertical[0] = camera_horizontal[1] * camera_direction[2] -
2905 camera_horizontal[2] * camera_direction[1];
2906 camera_vertical[1] = camera_horizontal[2] * camera_direction[0] -
2907 camera_horizontal[0] * camera_direction[2];
2908 camera_vertical[2] = camera_horizontal[0] * camera_direction[1] -
2909 camera_horizontal[1] * camera_direction[0];
2910
2911 float phi;
2912 phi = camera_focus;
2913 phi /= (point[0] - camera_position[0]) * camera_direction[0] +
2914 (point[1] - camera_position[1]) * camera_direction[1] +
2915 (point[2] - camera_position[2]) * camera_direction[2];
2916
2917 Point<3> projection;
2918 projection[0] =
2919 camera_position[0] + phi * (point[0] - camera_position[0]);
2920 projection[1] =
2921 camera_position[1] + phi * (point[1] - camera_position[1]);
2922 projection[2] =
2923 camera_position[2] + phi * (point[2] - camera_position[2]);
2924
2925 Point<2> projection_decomposition;
2926 projection_decomposition[0] = (projection[0] - camera_position[0] -
2927 camera_focus * camera_direction[0]) *
2928 camera_horizontal[0];
2929 projection_decomposition[0] += (projection[1] - camera_position[1] -
2930 camera_focus * camera_direction[1]) *
2931 camera_horizontal[1];
2932 projection_decomposition[0] += (projection[2] - camera_position[2] -
2933 camera_focus * camera_direction[2]) *
2934 camera_horizontal[2];
2935
2936 projection_decomposition[1] = (projection[0] - camera_position[0] -
2937 camera_focus * camera_direction[0]) *
2938 camera_vertical[0];
2939 projection_decomposition[1] += (projection[1] - camera_position[1] -
2940 camera_focus * camera_direction[1]) *
2941 camera_vertical[1];
2942 projection_decomposition[1] += (projection[2] - camera_position[2] -
2943 camera_focus * camera_direction[2]) *
2944 camera_vertical[2];
2945
2946 return projection_decomposition;
2947 }
2948
2949
2954 Point<6>
2955 svg_get_gradient_parameters(Point<3> points[])
2956 {
2957 Point<3> v_min, v_max, v_inter;
2958
2959 // Use the Bubblesort algorithm to sort the points with respect to the
2960 // third coordinate
2961 for (int i = 0; i < 2; ++i)
2963 for (int j = 0; j < 2 - i; ++j)
2964 {
2965 if (points[j][2] > points[j + 1][2])
2966 {
2967 Point<3> temp = points[j];
2968 points[j] = points[j + 1];
2969 points[j + 1] = temp;
2970 }
2971 }
2972 }
2973
2974 // save the related three-dimensional vectors v_min, v_inter, and v_max
2975 v_min = points[0];
2976 v_inter = points[1];
2977 v_max = points[2];
2978
2979 Point<2> A[2];
2980 Point<2> b, gradient;
2981
2982 // determine the plane offset c
2983 A[0][0] = v_max[0] - v_min[0];
2984 A[0][1] = v_inter[0] - v_min[0];
2985 A[1][0] = v_max[1] - v_min[1];
2986 A[1][1] = v_inter[1] - v_min[1];
2987
2988 b[0] = -v_min[0];
2989 b[1] = -v_min[1];
2990
2991 double x, sum;
2992 bool col_change = false;
2993
2994 if (A[0][0] == 0)
2995 {
2996 col_change = true;
2997
2998 A[0][0] = A[0][1];
2999 A[0][1] = 0;
3000
3001 double temp = A[1][0];
3002 A[1][0] = A[1][1];
3003 A[1][1] = temp;
3004 }
3005
3006 for (unsigned int k = 0; k < 1; ++k)
3007 {
3008 for (unsigned int i = k + 1; i < 2; ++i)
3009 {
3010 x = A[i][k] / A[k][k];
3011
3012 for (unsigned int j = k + 1; j < 2; ++j)
3013 A[i][j] = A[i][j] - A[k][j] * x;
3014
3015 b[i] = b[i] - b[k] * x;
3016 }
3017 }
3018
3019 b[1] = b[1] / A[1][1];
3020
3021 for (int i = 0; i >= 0; i--)
3022 {
3023 sum = b[i];
3024
3025 for (unsigned int j = i + 1; j < 2; ++j)
3026 sum = sum - A[i][j] * b[j];
3027
3028 b[i] = sum / A[i][i];
3029 }
3030
3031 if (col_change)
3032 {
3033 double temp = b[0];
3034 b[0] = b[1];
3035 b[1] = temp;
3036 }
3037
3038 double c = b[0] * (v_max[2] - v_min[2]) + b[1] * (v_inter[2] - v_min[2]) +
3039 v_min[2];
3040
3041 // Determine the first entry of the gradient (phi, cf. documentation)
3042 A[0][0] = v_max[0] - v_min[0];
3043 A[0][1] = v_inter[0] - v_min[0];
3044 A[1][0] = v_max[1] - v_min[1];
3045 A[1][1] = v_inter[1] - v_min[1];
3046
3047 b[0] = 1.0 - v_min[0];
3048 b[1] = -v_min[1];
3049
3050 col_change = false;
3051
3052 if (A[0][0] == 0)
3053 {
3054 col_change = true;
3055
3056 A[0][0] = A[0][1];
3057 A[0][1] = 0;
3058
3059 double temp = A[1][0];
3060 A[1][0] = A[1][1];
3061 A[1][1] = temp;
3062 }
3063
3064 for (unsigned int k = 0; k < 1; ++k)
3065 {
3066 for (unsigned int i = k + 1; i < 2; ++i)
3067 {
3068 x = A[i][k] / A[k][k];
3069
3070 for (unsigned int j = k + 1; j < 2; ++j)
3071 A[i][j] = A[i][j] - A[k][j] * x;
3072
3073 b[i] = b[i] - b[k] * x;
3074 }
3075 }
3076
3077 b[1] = b[1] / A[1][1];
3078
3079 for (int i = 0; i >= 0; i--)
3080 {
3081 sum = b[i];
3083 for (unsigned int j = i + 1; j < 2; ++j)
3084 sum = sum - A[i][j] * b[j];
3085
3086 b[i] = sum / A[i][i];
3087 }
3088
3089 if (col_change)
3090 {
3091 double temp = b[0];
3092 b[0] = b[1];
3093 b[1] = temp;
3094 }
3095
3096 gradient[0] = b[0] * (v_max[2] - v_min[2]) +
3097 b[1] * (v_inter[2] - v_min[2]) - c + v_min[2];
3098
3099 // determine the second entry of the gradient
3100 A[0][0] = v_max[0] - v_min[0];
3101 A[0][1] = v_inter[0] - v_min[0];
3102 A[1][0] = v_max[1] - v_min[1];
3103 A[1][1] = v_inter[1] - v_min[1];
3104
3105 b[0] = -v_min[0];
3106 b[1] = 1.0 - v_min[1];
3107
3108 col_change = false;
3109
3110 if (A[0][0] == 0)
3111 {
3112 col_change = true;
3113
3114 A[0][0] = A[0][1];
3115 A[0][1] = 0;
3116
3117 double temp = A[1][0];
3118 A[1][0] = A[1][1];
3119 A[1][1] = temp;
3120 }
3121
3122 for (unsigned int k = 0; k < 1; ++k)
3123 {
3124 for (unsigned int i = k + 1; i < 2; ++i)
3125 {
3126 x = A[i][k] / A[k][k];
3127
3128 for (unsigned int j = k + 1; j < 2; ++j)
3129 A[i][j] = A[i][j] - A[k][j] * x;
3130
3131 b[i] = b[i] - b[k] * x;
3132 }
3133 }
3134
3135 b[1] = b[1] / A[1][1];
3136
3137 for (int i = 0; i >= 0; i--)
3138 {
3139 sum = b[i];
3140
3141 for (unsigned int j = i + 1; j < 2; ++j)
3142 sum = sum - A[i][j] * b[j];
3143
3144 b[i] = sum / A[i][i];
3145 }
3146
3147 if (col_change)
3148 {
3149 double temp = b[0];
3150 b[0] = b[1];
3151 b[1] = temp;
3152 }
3153
3154 gradient[1] = b[0] * (v_max[2] - v_min[2]) +
3155 b[1] * (v_inter[2] - v_min[2]) - c + v_min[2];
3156
3157 // normalize the gradient
3158 gradient /= gradient.norm();
3159
3160 const double lambda = -gradient[0] * (v_min[0] - v_max[0]) -
3161 gradient[1] * (v_min[1] - v_max[1]);
3162
3163 Point<6> gradient_parameters;
3164
3165 gradient_parameters[0] = v_min[0];
3166 gradient_parameters[1] = v_min[1];
3167
3168 gradient_parameters[2] = v_min[0] + lambda * gradient[0];
3169 gradient_parameters[3] = v_min[1] + lambda * gradient[1];
3170
3171 gradient_parameters[4] = v_min[2];
3172 gradient_parameters[5] = v_max[2];
3173
3174 return gradient_parameters;
3175 }
3176 } // namespace
3177
3178
3179
3180 template <int dim, int spacedim>
3181 void
3183 const std::vector<Patch<dim, spacedim>> &patches,
3184 const std::vector<std::string> &data_names,
3185 const std::vector<
3186 std::tuple<unsigned int,
3187 unsigned int,
3188 std::string,
3190 const UcdFlags &flags,
3191 std::ostream &out)
3192 {
3193 // Note that while in theory dim==0 should be implemented, this is not
3194 // tested, therefore currently not allowed.
3195 AssertThrow(dim > 0, ExcNotImplemented());
3196
3197 AssertThrow(out.fail() == false, ExcIO());
3198
3199#ifndef DEAL_II_WITH_MPI
3200 // verify that there are indeed patches to be written out. most of the
3201 // times, people just forget to call build_patches when there are no
3202 // patches, so a warning is in order. that said, the assertion is disabled
3203 // if we support MPI since then it can happen that on the coarsest mesh, a
3204 // processor simply has no cells it actually owns, and in that case it is
3205 // legit if there are no patches
3206 Assert(patches.size() > 0, ExcNoPatches());
3207#else
3208 if (patches.empty())
3209 return;
3210#endif
3211
3212 const unsigned int n_data_sets = data_names.size();
3213
3214 UcdStream ucd_out(out, flags);
3215
3216 // first count the number of cells and cells for later use
3217 unsigned int n_nodes;
3218 unsigned int n_cells;
3219 std::tie(n_nodes, n_cells) = count_nodes_and_cells(patches);
3220 //---------------------
3221 // preamble
3222 if (flags.write_preamble)
3223 {
3224 out
3225 << "# This file was generated by the deal.II library." << '\n'
3226 << "# Date = " << Utilities::System::get_date() << '\n'
3227 << "# Time = " << Utilities::System::get_time() << '\n'
3228 << "#" << '\n'
3229 << "# For a description of the UCD format see the AVS Developer's guide."
3230 << '\n'
3231 << "#" << '\n';
3232 }
3233
3234 // start with ucd data
3235 out << n_nodes << ' ' << n_cells << ' ' << n_data_sets << ' ' << 0
3236 << ' ' // no cell data at present
3237 << 0 // no model data
3238 << '\n';
3239
3240 write_nodes(patches, ucd_out);
3241 out << '\n';
3242
3243 write_cells(patches, ucd_out);
3244 out << '\n';
3245
3246 //---------------------------
3247 // now write data
3248 if (n_data_sets != 0)
3249 {
3250 out << n_data_sets << " "; // number of vectors
3251 for (unsigned int i = 0; i < n_data_sets; ++i)
3252 out << 1 << ' '; // number of components;
3253 // only 1 supported presently
3254 out << '\n';
3255
3256 for (unsigned int data_set = 0; data_set < n_data_sets; ++data_set)
3257 out << data_names[data_set]
3258 << ",dimensionless" // no units supported at present
3259 << '\n';
3260
3261 write_data(patches, n_data_sets, true, ucd_out);
3262 }
3263 // make sure everything now gets to disk
3264 out.flush();
3265
3266 // assert the stream is still ok
3267 AssertThrow(out.fail() == false, ExcIO());
3268 }
3269
3270
3271 template <int dim, int spacedim>
3272 void
3274 const std::vector<Patch<dim, spacedim>> &patches,
3275 const std::vector<std::string> &data_names,
3276 const std::vector<
3277 std::tuple<unsigned int,
3278 unsigned int,
3279 std::string,
3281 const DXFlags &flags,
3282 std::ostream &out)
3283 {
3284 // Point output is currently not implemented.
3285 AssertThrow(dim > 0, ExcNotImplemented());
3286
3287 AssertThrow(out.fail() == false, ExcIO());
3288
3289#ifndef DEAL_II_WITH_MPI
3290 // verify that there are indeed patches to be written out. most of the
3291 // times, people just forget to call build_patches when there are no
3292 // patches, so a warning is in order. that said, the assertion is disabled
3293 // if we support MPI since then it can happen that on the coarsest mesh, a
3294 // processor simply has no cells it actually owns, and in that case it is
3295 // legit if there are no patches
3296 Assert(patches.size() > 0, ExcNoPatches());
3297#else
3298 if (patches.empty())
3299 return;
3300#endif
3301 // Stream with special features for dx output
3302 DXStream dx_out(out, flags);
3303
3304 // Variable counting the offset of binary data.
3305 unsigned int offset = 0;
3306
3307 const unsigned int n_data_sets = data_names.size();
3308
3309 // first count the number of cells and cells for later use
3310 unsigned int n_nodes;
3311 unsigned int n_cells;
3312 std::tie(n_nodes, n_cells) = count_nodes_and_cells(patches);
3313
3314 // start with vertices order is lexicographical, x varying fastest
3315 out << "object \"vertices\" class array type float rank 1 shape "
3316 << spacedim << " items " << n_nodes;
3317
3318 if (flags.coordinates_binary)
3319 {
3320 out << " lsb ieee data 0" << '\n';
3321 offset += n_nodes * spacedim * sizeof(float);
3322 }
3323 else
3324 {
3325 out << " data follows" << '\n';
3326 write_nodes(patches, dx_out);
3327 }
3328
3329 //-----------------------------
3330 // first write the coordinates of all vertices
3331
3332 //---------------------------------------
3333 // write cells
3334 out << "object \"cells\" class array type int rank 1 shape "
3335 << GeometryInfo<dim>::vertices_per_cell << " items " << n_cells;
3336
3337 if (flags.int_binary)
3338 {
3339 out << " lsb binary data " << offset << '\n';
3340 offset += n_cells * sizeof(int);
3341 }
3342 else
3343 {
3344 out << " data follows" << '\n';
3345 write_cells(patches, dx_out);
3346 out << '\n';
3347 }
3348
3349
3350 out << "attribute \"element type\" string \"";
3351 if constexpr (dim == 1)
3352 out << "lines";
3353 else if constexpr (dim == 2)
3354 out << "quads";
3355 else if constexpr (dim == 3)
3356 out << "cubes";
3357 out << "\"" << '\n' << "attribute \"ref\" string \"positions\"" << '\n';
3358
3359 // TODO:[GK] Patches must be of same size!
3360 //---------------------------
3361 // write neighbor information
3362 if (flags.write_neighbors)
3363 {
3364 out << "object \"neighbors\" class array type int rank 1 shape "
3365 << GeometryInfo<dim>::faces_per_cell << " items " << n_cells
3366 << " data follows";
3367
3368 for (const auto &patch : patches)
3369 {
3370 const unsigned int n = patch.n_subdivisions;
3371 const unsigned int n1 = (dim > 0) ? n : 1;
3372 const unsigned int n2 = (dim > 1) ? n : 1;
3373 const unsigned int n3 = (dim > 2) ? n : 1;
3374 const unsigned int x_minus = (dim > 0) ? 0 : 0;
3375 const unsigned int x_plus = (dim > 0) ? 1 : 0;
3376 const unsigned int y_minus = (dim > 1) ? 2 : 0;
3377 const unsigned int y_plus = (dim > 1) ? 3 : 0;
3378 const unsigned int z_minus = (dim > 2) ? 4 : 0;
3379 const unsigned int z_plus = (dim > 2) ? 5 : 0;
3380 unsigned int cells_per_patch = Utilities::fixed_power<dim>(n);
3381 unsigned int dx = 1;
3382 unsigned int dy = n;
3383 unsigned int dz = n * n;
3384
3385 const unsigned int patch_start =
3386 patch.patch_index * cells_per_patch;
3387
3388 for (unsigned int i3 = 0; i3 < n3; ++i3)
3389 for (unsigned int i2 = 0; i2 < n2; ++i2)
3390 for (unsigned int i1 = 0; i1 < n1; ++i1)
3391 {
3392 const unsigned int nx = i1 * dx;
3393 const unsigned int ny = i2 * dy;
3394 const unsigned int nz = i3 * dz;
3395
3396 // There are no neighbors for dim==0. Note that this case is
3397 // caught by the AssertThrow at the beginning of this
3398 // function anyway. This condition avoids compiler warnings.
3399 if (dim < 1)
3400 continue;
3401
3402 out << '\n';
3403 // Direction -x Last cell in row of other patch
3404 if (i1 == 0)
3405 {
3406 const unsigned int nn = patch.neighbors[x_minus];
3407 out << '\t';
3408 if (nn != patch.no_neighbor)
3409 out
3410 << (nn * cells_per_patch + ny + nz + dx * (n - 1));
3411 else
3412 out << "-1";
3413 }
3414 else
3415 {
3416 out << '\t' << patch_start + nx - dx + ny + nz;
3417 }
3418 // Direction +x First cell in row of other patch
3419 if (i1 == n - 1)
3420 {
3421 const unsigned int nn = patch.neighbors[x_plus];
3422 out << '\t';
3423 if (nn != patch.no_neighbor)
3424 out << (nn * cells_per_patch + ny + nz);
3425 else
3426 out << "-1";
3427 }
3428 else
3429 {
3430 out << '\t' << patch_start + nx + dx + ny + nz;
3431 }
3432 if (dim < 2)
3433 continue;
3434 // Direction -y
3435 if (i2 == 0)
3436 {
3437 const unsigned int nn = patch.neighbors[y_minus];
3438 out << '\t';
3439 if (nn != patch.no_neighbor)
3440 out
3441 << (nn * cells_per_patch + nx + nz + dy * (n - 1));
3442 else
3443 out << "-1";
3444 }
3445 else
3446 {
3447 out << '\t' << patch_start + nx + ny - dy + nz;
3448 }
3449 // Direction +y
3450 if (i2 == n - 1)
3451 {
3452 const unsigned int nn = patch.neighbors[y_plus];
3453 out << '\t';
3454 if (nn != patch.no_neighbor)
3455 out << (nn * cells_per_patch + nx + nz);
3456 else
3457 out << "-1";
3458 }
3459 else
3460 {
3461 out << '\t' << patch_start + nx + ny + dy + nz;
3462 }
3463 if (dim < 3)
3464 continue;
3465
3466 // Direction -z
3467 if (i3 == 0)
3468 {
3469 const unsigned int nn = patch.neighbors[z_minus];
3470 out << '\t';
3471 if (nn != patch.no_neighbor)
3472 out
3473 << (nn * cells_per_patch + nx + ny + dz * (n - 1));
3474 else
3475 out << "-1";
3476 }
3477 else
3478 {
3479 out << '\t' << patch_start + nx + ny + nz - dz;
3480 }
3481 // Direction +z
3482 if (i3 == n - 1)
3483 {
3484 const unsigned int nn = patch.neighbors[z_plus];
3485 out << '\t';
3486 if (nn != patch.no_neighbor)
3487 out << (nn * cells_per_patch + nx + ny);
3488 else
3489 out << "-1";
3490 }
3491 else
3492 {
3493 out << '\t' << patch_start + nx + ny + nz + dz;
3494 }
3495 }
3496 out << '\n';
3497 }
3498 }
3499 //---------------------------
3500 // now write data
3501 if (n_data_sets != 0)
3502 {
3503 out << "object \"data\" class array type float rank 1 shape "
3504 << n_data_sets << " items " << n_nodes;
3505
3506 if (flags.data_binary)
3507 {
3508 out << " lsb ieee data " << offset << '\n';
3509 offset += n_data_sets * n_nodes *
3510 ((flags.data_double) ? sizeof(double) : sizeof(float));
3511 }
3512 else
3513 {
3514 out << " data follows" << '\n';
3515 write_data(patches, n_data_sets, flags.data_double, dx_out);
3516 }
3517
3518 // loop over all patches
3519 out << "attribute \"dep\" string \"positions\"" << '\n';
3520 }
3521 else
3522 {
3523 out << "object \"data\" class constantarray type float rank 0 items "
3524 << n_nodes << " data follows" << '\n'
3525 << '0' << '\n';
3526 }
3527
3528 // no model data
3529
3530 out << "object \"deal data\" class field" << '\n'
3531 << "component \"positions\" value \"vertices\"" << '\n'
3532 << "component \"connections\" value \"cells\"" << '\n'
3533 << "component \"data\" value \"data\"" << '\n';
3534
3535 if (flags.write_neighbors)
3536 out << "component \"neighbors\" value \"neighbors\"" << '\n';
3537
3538 {
3539 out << "attribute \"created\" string \"" << Utilities::System::get_date()
3540 << ' ' << Utilities::System::get_time() << '"' << '\n';
3541 }
3542
3543 out << "end" << '\n';
3544 // Write all binary data now
3545 if (flags.coordinates_binary)
3546 write_nodes(patches, dx_out);
3547 if (flags.int_binary)
3548 write_cells(patches, dx_out);
3549 if (flags.data_binary)
3550 write_data(patches, n_data_sets, flags.data_double, dx_out);
3551
3552 // make sure everything now gets to disk
3553 out.flush();
3554
3555 // assert the stream is still ok
3556 AssertThrow(out.fail() == false, ExcIO());
3557 }
3558
3559
3560
3561 template <int dim, int spacedim>
3562 void
3564 const std::vector<Patch<dim, spacedim>> &patches,
3565 const std::vector<std::string> &data_names,
3566 const std::vector<
3567 std::tuple<unsigned int,
3568 unsigned int,
3569 std::string,
3571 const GnuplotFlags &flags,
3572 std::ostream &out)
3573 {
3574 AssertThrow(out.fail() == false, ExcIO());
3575
3576#ifndef DEAL_II_WITH_MPI
3577 // verify that there are indeed patches to be written out. most
3578 // of the times, people just forget to call build_patches when there
3579 // are no patches, so a warning is in order. that said, the
3580 // assertion is disabled if we support MPI since then it can
3581 // happen that on the coarsest mesh, a processor simply has no
3582 // cells it actually owns, and in that case it is legit if there
3583 // are no patches
3584 Assert(patches.size() > 0, ExcNoPatches());
3585#else
3586 if (patches.empty())
3587 return;
3588#endif
3589
3590 const unsigned int n_data_sets = data_names.size();
3591
3592 // write preamble
3593 {
3594 out << "# This file was generated by the deal.II library." << '\n'
3595 << "# Date = " << Utilities::System::get_date() << '\n'
3596 << "# Time = " << Utilities::System::get_time() << '\n'
3597 << "#" << '\n'
3598 << "# For a description of the GNUPLOT format see the GNUPLOT manual."
3599 << '\n'
3600 << "#" << '\n'
3601 << "# ";
3602
3603 AssertThrow(spacedim <= flags.space_dimension_labels.size(),
3605 for (unsigned int spacedim_n = 0; spacedim_n < spacedim; ++spacedim_n)
3606 {
3607 out << '<' << flags.space_dimension_labels.at(spacedim_n) << "> ";
3608 }
3609
3610 for (const auto &data_name : data_names)
3611 out << '<' << data_name << "> ";
3612 out << '\n';
3613 }
3614
3615
3616 // loop over all patches
3617 for (const auto &patch : patches)
3618 {
3619 const unsigned int n_subdivisions = patch.n_subdivisions;
3620 const unsigned int n_points_per_direction = n_subdivisions + 1;
3621
3622 Assert((patch.data.n_rows() == n_data_sets &&
3623 !patch.points_are_available) ||
3624 (patch.data.n_rows() == n_data_sets + spacedim &&
3625 patch.points_are_available),
3627 (n_data_sets + spacedim) :
3628 n_data_sets,
3629 patch.data.n_rows()));
3630
3631 auto output_point_data =
3632 [&out, &patch, n_data_sets](const unsigned int point_index) mutable {
3633 for (unsigned int data_set = 0; data_set < n_data_sets; ++data_set)
3634 out << patch.data(data_set, point_index) << ' ';
3635 };
3636
3637 switch (dim)
3638 {
3639 case 0:
3640 {
3641 Assert(patch.reference_cell == ReferenceCells::Vertex,
3643 Assert(patch.data.n_cols() == 1,
3644 ExcInvalidDatasetSize(patch.data.n_cols(),
3645 n_subdivisions + 1));
3646
3647
3648 // compute coordinates for this patch point
3649 out << get_equispaced_location(patch, {}, n_subdivisions)
3650 << ' ';
3651 output_point_data(0);
3652 out << '\n';
3653 out << '\n';
3654 break;
3655 }
3656
3657 case 1:
3658 {
3659 Assert(patch.reference_cell == ReferenceCells::Line,
3661 Assert(patch.data.n_cols() ==
3662 Utilities::fixed_power<dim>(n_points_per_direction),
3663 ExcInvalidDatasetSize(patch.data.n_cols(),
3664 n_subdivisions + 1));
3665
3666 for (unsigned int i1 = 0; i1 < n_points_per_direction; ++i1)
3667 {
3668 // compute coordinates for this patch point
3669 out << get_equispaced_location(patch, {i1}, n_subdivisions)
3670 << ' ';
3671
3672 output_point_data(i1);
3673 out << '\n';
3674 }
3675 // end of patch
3676 out << '\n';
3677 out << '\n';
3678 break;
3679 }
3680
3681 case 2:
3682 {
3683 if (patch.reference_cell == ReferenceCells::Quadrilateral)
3684 {
3685 Assert(patch.data.n_cols() == Utilities::fixed_power<dim>(
3686 n_points_per_direction),
3687 ExcInvalidDatasetSize(patch.data.n_cols(),
3688 n_subdivisions + 1));
3689
3690 for (unsigned int i2 = 0; i2 < n_points_per_direction; ++i2)
3691 {
3692 for (unsigned int i1 = 0; i1 < n_points_per_direction;
3693 ++i1)
3694 {
3695 // compute coordinates for this patch point
3696 out << get_equispaced_location(patch,
3697 {i1, i2},
3699 << ' ';
3700
3701 output_point_data(i1 + i2 * n_points_per_direction);
3702 out << '\n';
3703 }
3704 // end of row in patch
3705 out << '\n';
3706 }
3707 }
3708 else if (patch.reference_cell == ReferenceCells::Triangle)
3709 {
3711
3712 Assert(patch.data.n_cols() == 3, ExcInternalError());
3713
3714 // Gnuplot can only plot surfaces if each facet of the
3715 // surface is a bilinear patch, or a subdivided bilinear
3716 // patch with equally many points along each row of the
3717 // subdivision. This is what the code above for
3718 // quadrilaterals does. We emulate this by repeating the
3719 // third point of a triangle twice so that there are two
3720 // points for that row as well -- i.e., we write a 2x2
3721 // bilinear patch where two of the points are collapsed onto
3722 // one vertex.
3723 //
3724 // This also matches the example here:
3725 // https://stackoverflow.com/questions/42784369/drawing-triangular-mesh-using-gnuplot
3726 out << get_node_location(patch, 0) << ' ';
3727 output_point_data(0);
3728 out << '\n';
3729
3730 out << get_node_location(patch, 1) << ' ';
3731 output_point_data(1);
3732 out << '\n';
3733 out << '\n'; // end of one row of points
3734
3735 out << get_node_location(patch, 2) << ' ';
3736 output_point_data(2);
3737 out << '\n';
3738
3739 out << get_node_location(patch, 2) << ' ';
3740 output_point_data(2);
3741 out << '\n';
3742 out << '\n'; // end of the second row of points
3743 out << '\n'; // end of the entire patch
3744 }
3745 else
3746 // There aren't any other reference cells in 2d than the
3747 // quadrilateral and the triangle. So whatever we got here
3748 // can't be any good
3750 // end of patch
3751 out << '\n';
3752
3753 break;
3754 }
3755
3756 case 3:
3757 {
3758 if (patch.reference_cell == ReferenceCells::Hexahedron)
3759 {
3760 Assert(patch.data.n_cols() == Utilities::fixed_power<dim>(
3761 n_points_per_direction),
3762 ExcInvalidDatasetSize(patch.data.n_cols(),
3763 n_subdivisions + 1));
3764
3765 // for all grid points: draw lines into all positive
3766 // coordinate directions if there is another grid point
3767 // there
3768 for (unsigned int i3 = 0; i3 < n_points_per_direction; ++i3)
3769 for (unsigned int i2 = 0; i2 < n_points_per_direction;
3770 ++i2)
3771 for (unsigned int i1 = 0; i1 < n_points_per_direction;
3772 ++i1)
3773 {
3774 // compute coordinates for this patch point
3775 const Point<spacedim> this_point =
3776 get_equispaced_location(patch,
3777 {i1, i2, i3},
3779 // line into positive x-direction if possible
3780 if (i1 < n_subdivisions)
3781 {
3782 // write point here and its data
3783 out << this_point << ' ';
3784 output_point_data(i1 +
3785 i2 * n_points_per_direction +
3786 i3 * n_points_per_direction *
3787 n_points_per_direction);
3788 out << '\n';
3789
3790 // write point there and its data
3791 out << get_equispaced_location(patch,
3792 {i1 + 1, i2, i3},
3794 << ' ';
3795
3796 output_point_data((i1 + 1) +
3797 i2 * n_points_per_direction +
3798 i3 * n_points_per_direction *
3799 n_points_per_direction);
3800 out << '\n';
3801
3802 // end of line
3803 out << '\n' << '\n';
3804 }
3805
3806 // line into positive y-direction if possible
3807 if (i2 < n_subdivisions)
3808 {
3809 // write point here and its data
3810 out << this_point << ' ';
3811 output_point_data(i1 +
3812 i2 * n_points_per_direction +
3813 i3 * n_points_per_direction *
3814 n_points_per_direction);
3815 out << '\n';
3816
3817 // write point there and its data
3818 out << get_equispaced_location(patch,
3819 {i1, i2 + 1, i3},
3821 << ' ';
3822
3823 output_point_data(
3824 i1 + (i2 + 1) * n_points_per_direction +
3825 i3 * n_points_per_direction *
3826 n_points_per_direction);
3827 out << '\n';
3828
3829 // end of line
3830 out << '\n' << '\n';
3831 }
3832
3833 // line into positive z-direction if possible
3834 if (i3 < n_subdivisions)
3835 {
3836 // write point here and its data
3837 out << this_point << ' ';
3838 output_point_data(i1 +
3839 i2 * n_points_per_direction +
3840 i3 * n_points_per_direction *
3841 n_points_per_direction);
3842 out << '\n';
3843
3844 // write point there and its data
3845 out << get_equispaced_location(patch,
3846 {i1, i2, i3 + 1},
3848 << ' ';
3849
3850 output_point_data(
3851 i1 + i2 * n_points_per_direction +
3852 (i3 + 1) * n_points_per_direction *
3853 n_points_per_direction);
3854 out << '\n';
3855 // end of line
3856 out << '\n' << '\n';
3857 }
3858 }
3859 }
3860 else if (patch.reference_cell == ReferenceCells::Tetrahedron)
3861 {
3863
3864 // Draw the tetrahedron as a collection of two lines.
3865 for (const unsigned int v : {0, 1, 2, 0, 3, 2})
3866 {
3867 out << get_node_location(patch, v) << ' ';
3868 output_point_data(v);
3869 out << '\n';
3870 }
3871 out << '\n'; // end of first line
3872
3873 for (const unsigned int v : {3, 1})
3874 {
3875 out << get_node_location(patch, v) << ' ';
3876 output_point_data(v);
3877 out << '\n';
3878 }
3879 out << '\n'; // end of second line
3880 }
3881 else if (patch.reference_cell == ReferenceCells::Pyramid)
3882 {
3884
3885 // Draw the pyramid as a collection of two lines.
3886 for (const unsigned int v : {0, 1, 3, 2, 0, 4, 1})
3887 {
3888 out << get_node_location(patch, v) << ' ';
3889 output_point_data(v);
3890 out << '\n';
3891 }
3892 out << '\n'; // end of first line
3893
3894 for (const unsigned int v : {2, 4, 3})
3895 {
3896 out << get_node_location(patch, v) << ' ';
3897 output_point_data(v);
3898 out << '\n';
3899 }
3900 out << '\n'; // end of second line
3901 }
3902 else if (patch.reference_cell == ReferenceCells::Wedge)
3903 {
3905
3906 // Draw the wedge as a collection of three
3907 // lines. The first one wraps around the base,
3908 // goes up to the top, and wraps around that. The
3909 // second and third are just individual lines
3910 // going from base to top.
3911 for (const unsigned int v : {0, 1, 2, 0, 3, 4, 5, 3})
3912 {
3913 out << get_node_location(patch, v) << ' ';
3914 output_point_data(v);
3915 out << '\n';
3916 }
3917 out << '\n'; // end of first line
3918
3919 for (const unsigned int v : {1, 4})
3920 {
3921 out << get_node_location(patch, v) << ' ';
3922 output_point_data(v);
3923 out << '\n';
3924 }
3925 out << '\n'; // end of second line
3926
3927 for (const unsigned int v : {2, 5})
3928 {
3929 out << get_node_location(patch, v) << ' ';
3930 output_point_data(v);
3931 out << '\n';
3932 }
3933 out << '\n'; // end of second line
3934 }
3935 else
3936 // No other reference cells are currently implemented
3938
3939 break;
3940 }
3941
3942 default:
3944 }
3945 }
3946 // make sure everything now gets to disk
3947 out.flush();
3948
3949 AssertThrow(out.fail() == false, ExcIO());
3950 }
3951
3952
3953 namespace
3954 {
3955 template <int dim, int spacedim>
3956 void
3957 do_write_povray(const std::vector<Patch<dim, spacedim>> &,
3958 const std::vector<std::string> &,
3959 const PovrayFlags &,
3960 std::ostream &)
3961 {
3962 Assert(false,
3963 ExcMessage("Writing files in POVRAY format is only supported "
3964 "for two-dimensional meshes."));
3965 }
3966
3967
3968
3969 void
3970 do_write_povray(const std::vector<Patch<2, 2>> &patches,
3971 const std::vector<std::string> &data_names,
3972 const PovrayFlags &flags,
3973 std::ostream &out)
3974 {
3975 AssertThrow(out.fail() == false, ExcIO());
3976
3977#ifndef DEAL_II_WITH_MPI
3978 // verify that there are indeed patches to be written out. most
3979 // of the times, people just forget to call build_patches when there
3980 // are no patches, so a warning is in order. that said, the
3981 // assertion is disabled if we support MPI since then it can
3982 // happen that on the coarsest mesh, a processor simply has no cells it
3983 // actually owns, and in that case it is legit if there are no patches
3984 Assert(patches.size() > 0, ExcNoPatches());
3985#else
3986 if (patches.empty())
3987 return;
3988#endif
3989 constexpr int dim = 2;
3990 (void)dim;
3991 constexpr int spacedim = 2;
3992
3993 const unsigned int n_data_sets = data_names.size();
3994 (void)n_data_sets;
3995
3996 // write preamble
3997 {
3998 out
3999 << "/* This file was generated by the deal.II library." << '\n'
4000 << " Date = " << Utilities::System::get_date() << '\n'
4001 << " Time = " << Utilities::System::get_time() << '\n'
4002 << '\n'
4003 << " For a description of the POVRAY format see the POVRAY manual."
4004 << '\n'
4005 << "*/ " << '\n';
4006
4007 // include files
4008 out << "#include \"colors.inc\" " << '\n'
4009 << "#include \"textures.inc\" " << '\n';
4010
4011
4012 // use external include file for textures, camera and light
4013 if (flags.external_data)
4014 out << "#include \"data.inc\" " << '\n';
4015 else // all definitions in data file
4016 {
4017 // camera
4018 out << '\n'
4019 << '\n'
4020 << "camera {" << '\n'
4021 << " location <1,4,-7>" << '\n'
4022 << " look_at <0,0,0>" << '\n'
4023 << " angle 30" << '\n'
4024 << "}" << '\n';
4025
4026 // light
4027 out << '\n'
4028 << "light_source {" << '\n'
4029 << " <1,4,-7>" << '\n'
4030 << " color Grey" << '\n'
4031 << "}" << '\n';
4032 out << '\n'
4033 << "light_source {" << '\n'
4034 << " <0,20,0>" << '\n'
4035 << " color White" << '\n'
4036 << "}" << '\n';
4037 }
4038 }
4039
4040 // max. and min. height of solution
4041 Assert(patches.size() > 0, ExcNoPatches());
4042 double hmin = patches[0].data(0, 0);
4043 double hmax = patches[0].data(0, 0);
4044
4045 for (const auto &patch : patches)
4046 {
4047 const unsigned int n_subdivisions = patch.n_subdivisions;
4048
4049 Assert((patch.data.n_rows() == n_data_sets &&
4050 !patch.points_are_available) ||
4051 (patch.data.n_rows() == n_data_sets + spacedim &&
4052 patch.points_are_available),
4054 (n_data_sets + spacedim) :
4055 n_data_sets,
4056 patch.data.n_rows()));
4057 Assert(patch.data.n_cols() ==
4059 ExcInvalidDatasetSize(patch.data.n_cols(),
4060 n_subdivisions + 1));
4061
4062 for (unsigned int i = 0; i < n_subdivisions + 1; ++i)
4063 for (unsigned int j = 0; j < n_subdivisions + 1; ++j)
4064 {
4065 const int dl = i * (n_subdivisions + 1) + j;
4066 if (patch.data(0, dl) < hmin)
4067 hmin = patch.data(0, dl);
4068 if (patch.data(0, dl) > hmax)
4069 hmax = patch.data(0, dl);
4070 }
4071 }
4072
4073 out << "#declare HMIN=" << hmin << ";" << '\n'
4074 << "#declare HMAX=" << hmax << ";" << '\n'
4075 << '\n';
4076
4077 if (!flags.external_data)
4078 {
4079 // texture with scaled niveau lines 10 lines in the surface
4080 out << "#declare Tex=texture{" << '\n'
4081 << " pigment {" << '\n'
4082 << " gradient y" << '\n'
4083 << " scale y*(HMAX-HMIN)*" << 0.1 << '\n'
4084 << " color_map {" << '\n'
4085 << " [0.00 color Light_Purple] " << '\n'
4086 << " [0.95 color Light_Purple] " << '\n'
4087 << " [1.00 color White] " << '\n'
4088 << "} } }" << '\n'
4089 << '\n';
4090 }
4091
4092 if (!flags.bicubic_patch)
4093 {
4094 // start of mesh header
4095 out << '\n' << "mesh {" << '\n';
4096 }
4097
4098 // loop over all patches
4099 for (const auto &patch : patches)
4100 {
4101 const unsigned int n_subdivisions = patch.n_subdivisions;
4102 const unsigned int n = n_subdivisions + 1;
4103 const unsigned int d1 = 1;
4104 const unsigned int d2 = n;
4105
4106 Assert((patch.data.n_rows() == n_data_sets &&
4107 !patch.points_are_available) ||
4108 (patch.data.n_rows() == n_data_sets + spacedim &&
4109 patch.points_are_available),
4111 (n_data_sets + spacedim) :
4112 n_data_sets,
4113 patch.data.n_rows()));
4114 Assert(patch.data.n_cols() == Utilities::fixed_power<dim>(n),
4115 ExcInvalidDatasetSize(patch.data.n_cols(),
4116 n_subdivisions + 1));
4117
4118
4119 std::vector<Point<spacedim>> ver(n * n);
4120
4121 for (unsigned int i2 = 0; i2 < n; ++i2)
4122 for (unsigned int i1 = 0; i1 < n; ++i1)
4123 {
4124 // compute coordinates for this patch point, storing in ver
4125 ver[i1 * d1 + i2 * d2] =
4126 get_equispaced_location(patch, {i1, i2}, n_subdivisions);
4127 }
4128
4129
4130 if (!flags.bicubic_patch)
4131 {
4132 // approximate normal vectors in patch
4133 std::vector<Point<3>> nrml;
4134 // only if smooth triangles are used
4135 if (flags.smooth)
4136 {
4137 nrml.resize(n * n);
4138 // These are difference quotients of the surface
4139 // mapping. We take them symmetric inside the
4140 // patch and one-sided at the edges
4141 Point<3> h1, h2;
4142 // Now compute normals in every point
4143 for (unsigned int i = 0; i < n; ++i)
4144 for (unsigned int j = 0; j < n; ++j)
4145 {
4146 const unsigned int il = (i == 0) ? i : (i - 1);
4147 const unsigned int ir =
4148 (i == n_subdivisions) ? i : (i + 1);
4149 const unsigned int jl = (j == 0) ? j : (j - 1);
4150 const unsigned int jr =
4151 (j == n_subdivisions) ? j : (j + 1);
4152
4153 h1[0] =
4154 ver[ir * d1 + j * d2][0] - ver[il * d1 + j * d2][0];
4155 h1[1] = patch.data(0, ir * d1 + j * d2) -
4156 patch.data(0, il * d1 + j * d2);
4157 h1[2] =
4158 ver[ir * d1 + j * d2][1] - ver[il * d1 + j * d2][1];
4159
4160 h2[0] =
4161 ver[i * d1 + jr * d2][0] - ver[i * d1 + jl * d2][0];
4162 h2[1] = patch.data(0, i * d1 + jr * d2) -
4163 patch.data(0, i * d1 + jl * d2);
4164 h2[2] =
4165 ver[i * d1 + jr * d2][1] - ver[i * d1 + jl * d2][1];
4166
4167 nrml[i * d1 + j * d2][0] =
4168 h1[1] * h2[2] - h1[2] * h2[1];
4169 nrml[i * d1 + j * d2][1] =
4170 h1[2] * h2[0] - h1[0] * h2[2];
4171 nrml[i * d1 + j * d2][2] =
4172 h1[0] * h2[1] - h1[1] * h2[0];
4173
4174 // normalize Vector
4175 double norm = std::hypot(nrml[i * d1 + j * d2][0],
4176 nrml[i * d1 + j * d2][1],
4177 nrml[i * d1 + j * d2][2]);
4178
4179 if (nrml[i * d1 + j * d2][1] < 0)
4180 norm *= -1.;
4181
4182 for (unsigned int k = 0; k < 3; ++k)
4183 nrml[i * d1 + j * d2][k] /= norm;
4184 }
4185 }
4186
4187 // setting up triangles
4188 for (unsigned int i = 0; i < n_subdivisions; ++i)
4189 for (unsigned int j = 0; j < n_subdivisions; ++j)
4190 {
4191 // down/left vertex of triangle
4192 const int dl = i * d1 + j * d2;
4193 if (flags.smooth)
4194 {
4195 // writing smooth_triangles
4196
4197 // down/right triangle
4198 out << "smooth_triangle {" << '\n'
4199 << "\t<" << ver[dl][0] << "," << patch.data(0, dl)
4200 << "," << ver[dl][1] << ">, <" << nrml[dl][0]
4201 << ", " << nrml[dl][1] << ", " << nrml[dl][2]
4202 << ">," << '\n';
4203 out << " \t<" << ver[dl + d1][0] << ","
4204 << patch.data(0, dl + d1) << "," << ver[dl + d1][1]
4205 << ">, <" << nrml[dl + d1][0] << ", "
4206 << nrml[dl + d1][1] << ", " << nrml[dl + d1][2]
4207 << ">," << '\n';
4208 out << "\t<" << ver[dl + d1 + d2][0] << ","
4209 << patch.data(0, dl + d1 + d2) << ","
4210 << ver[dl + d1 + d2][1] << ">, <"
4211 << nrml[dl + d1 + d2][0] << ", "
4212 << nrml[dl + d1 + d2][1] << ", "
4213 << nrml[dl + d1 + d2][2] << ">}" << '\n';
4214
4215 // upper/left triangle
4216 out << "smooth_triangle {" << '\n'
4217 << "\t<" << ver[dl][0] << "," << patch.data(0, dl)
4218 << "," << ver[dl][1] << ">, <" << nrml[dl][0]
4219 << ", " << nrml[dl][1] << ", " << nrml[dl][2]
4220 << ">," << '\n';
4221 out << "\t<" << ver[dl + d1 + d2][0] << ","
4222 << patch.data(0, dl + d1 + d2) << ","
4223 << ver[dl + d1 + d2][1] << ">, <"
4224 << nrml[dl + d1 + d2][0] << ", "
4225 << nrml[dl + d1 + d2][1] << ", "
4226 << nrml[dl + d1 + d2][2] << ">," << '\n';
4227 out << "\t<" << ver[dl + d2][0] << ","
4228 << patch.data(0, dl + d2) << "," << ver[dl + d2][1]
4229 << ">, <" << nrml[dl + d2][0] << ", "
4230 << nrml[dl + d2][1] << ", " << nrml[dl + d2][2]
4231 << ">}" << '\n';
4232 }
4233 else
4234 {
4235 // writing standard triangles down/right triangle
4236 out << "triangle {" << '\n'
4237 << "\t<" << ver[dl][0] << "," << patch.data(0, dl)
4238 << "," << ver[dl][1] << ">," << '\n';
4239 out << "\t<" << ver[dl + d1][0] << ","
4240 << patch.data(0, dl + d1) << "," << ver[dl + d1][1]
4241 << ">," << '\n';
4242 out << "\t<" << ver[dl + d1 + d2][0] << ","
4243 << patch.data(0, dl + d1 + d2) << ","
4244 << ver[dl + d1 + d2][1] << ">}" << '\n';
4245
4246 // upper/left triangle
4247 out << "triangle {" << '\n'
4248 << "\t<" << ver[dl][0] << "," << patch.data(0, dl)
4249 << "," << ver[dl][1] << ">," << '\n';
4250 out << "\t<" << ver[dl + d1 + d2][0] << ","
4251 << patch.data(0, dl + d1 + d2) << ","
4252 << ver[dl + d1 + d2][1] << ">," << '\n';
4253 out << "\t<" << ver[dl + d2][0] << ","
4254 << patch.data(0, dl + d2) << "," << ver[dl + d2][1]
4255 << ">}" << '\n';
4256 }
4257 }
4258 }
4259 else
4260 {
4261 // writing bicubic_patch
4264 out << '\n'
4265 << "bicubic_patch {" << '\n'
4266 << " type 0" << '\n'
4267 << " flatness 0" << '\n'
4268 << " u_steps 0" << '\n'
4269 << " v_steps 0" << '\n';
4270 for (int i = 0; i < 16; ++i)
4271 {
4272 out << "\t<" << ver[i][0] << "," << patch.data(0, i) << ","
4273 << ver[i][1] << ">";
4274 if (i != 15)
4275 out << ",";
4276 out << '\n';
4277 }
4278 out << " texture {Tex}" << '\n' << "}" << '\n';
4279 }
4280 }
4281
4282 if (!flags.bicubic_patch)
4283 {
4284 // the end of the mesh
4285 out << " texture {Tex}" << '\n' << "}" << '\n' << '\n';
4286 }
4287
4288 // make sure everything now gets to disk
4289 out.flush();
4290
4291 AssertThrow(out.fail() == false, ExcIO());
4292 }
4293 } // namespace
4294
4295
4296
4297 template <int dim, int spacedim>
4298 void
4300 const std::vector<Patch<dim, spacedim>> &patches,
4301 const std::vector<std::string> &data_names,
4302 const std::vector<
4303 std::tuple<unsigned int,
4304 unsigned int,
4305 std::string,
4307 const PovrayFlags &flags,
4308 std::ostream &out)
4309 {
4310 do_write_povray(patches, data_names, flags, out);
4311 }
4312
4313
4314
4315 template <int dim, int spacedim>
4316 void
4318 const std::vector<Patch<dim, spacedim>> & /*patches*/,
4319 const std::vector<std::string> & /*data_names*/,
4320 const std::vector<
4321 std::tuple<unsigned int,
4322 unsigned int,
4323 std::string,
4325 const EpsFlags & /*flags*/,
4326 std::ostream & /*out*/)
4327 {
4328 // not implemented, see the documentation of the function
4329 AssertThrow(dim == 2, ExcNotImplemented());
4330 }
4331
4332
4333 template <int spacedim>
4334 void
4336 const std::vector<Patch<2, spacedim>> &patches,
4337 const std::vector<std::string> & /*data_names*/,
4338 const std::vector<
4339 std::tuple<unsigned int,
4340 unsigned int,
4341 std::string,
4343 const EpsFlags &flags,
4344 std::ostream &out)
4345 {
4346 AssertThrow(out.fail() == false, ExcIO());
4347
4348#ifndef DEAL_II_WITH_MPI
4349 // verify that there are indeed patches to be written out. most of the
4350 // times, people just forget to call build_patches when there are no
4351 // patches, so a warning is in order. that said, the assertion is disabled
4352 // if we support MPI since then it can happen that on the coarsest mesh, a
4353 // processor simply has no cells it actually owns, and in that case it is
4354 // legit if there are no patches
4355 Assert(patches.size() > 0, ExcNoPatches());
4356#else
4357 if (patches.empty())
4358 return;
4359#endif
4360
4361 // set up an array of cells to be written later. this array holds the cells
4362 // of all the patches as projected to the plane perpendicular to the line of
4363 // sight.
4364 //
4365 // note that they are kept sorted by the set, where we chose the value of
4366 // the center point of the cell along the line of sight as value for sorting
4367 std::multiset<EpsCell2d> cells;
4368
4369 // two variables in which we will store the minimum and maximum values of
4370 // the field to be used for colorization
4371 float min_color_value = std::numeric_limits<float>::max();
4372 float max_color_value = std::numeric_limits<float>::min();
4373
4374 // Array for z-coordinates of points. The elevation determined by a function
4375 // if spacedim=2 or the z-coordinate of the grid point if spacedim=3
4376 double heights[4] = {0, 0, 0, 0};
4377
4378 // compute the cells for output and enter them into the set above note that
4379 // since dim==2, we have exactly four vertices per patch and per cell
4380 for (const auto &patch : patches)
4381 {
4382 const unsigned int n_subdivisions = patch.n_subdivisions;
4383 const unsigned int n = n_subdivisions + 1;
4384 const unsigned int d1 = 1;
4385 const unsigned int d2 = n;
4386
4387 for (unsigned int i2 = 0; i2 < n_subdivisions; ++i2)
4388 for (unsigned int i1 = 0; i1 < n_subdivisions; ++i1)
4389 {
4390 Point<spacedim> points[4];
4391 points[0] =
4392 get_equispaced_location(patch, {i1, i2}, n_subdivisions);
4393 points[1] =
4394 get_equispaced_location(patch, {i1 + 1, i2}, n_subdivisions);
4395 points[2] =
4396 get_equispaced_location(patch, {i1, i2 + 1}, n_subdivisions);
4397 points[3] = get_equispaced_location(patch,
4398 {i1 + 1, i2 + 1},
4400
4401 switch (spacedim)
4402 {
4403 case 2:
4404 Assert((flags.height_vector < patch.data.n_rows()) ||
4405 patch.data.n_rows() == 0,
4407 0,
4408 patch.data.n_rows()));
4409 heights[0] =
4410 patch.data.n_rows() != 0 ?
4411 patch.data(flags.height_vector, i1 * d1 + i2 * d2) *
4412 flags.z_scaling :
4413 0;
4414 heights[1] = patch.data.n_rows() != 0 ?
4415 patch.data(flags.height_vector,
4416 (i1 + 1) * d1 + i2 * d2) *
4417 flags.z_scaling :
4418 0;
4419 heights[2] = patch.data.n_rows() != 0 ?
4420 patch.data(flags.height_vector,
4421 i1 * d1 + (i2 + 1) * d2) *
4422 flags.z_scaling :
4423 0;
4424 heights[3] = patch.data.n_rows() != 0 ?
4425 patch.data(flags.height_vector,
4426 (i1 + 1) * d1 + (i2 + 1) * d2) *
4427 flags.z_scaling :
4428 0;
4429
4430 break;
4431 case 3:
4432 // Copy z-coordinates into the height vector
4433 for (unsigned int i = 0; i < 4; ++i)
4434 heights[i] = points[i][2];
4435 break;
4436 default:
4438 }
4439
4440
4441 // now compute the projection of the bilinear cell given by the
4442 // four vertices and their heights and write them to a proper cell
4443 // object. note that we only need the first two components of the
4444 // projected position for output, but we need the value along the
4445 // line of sight for sorting the cells for back-to- front-output
4446 //
4447 // this computation was first written by Stefan Nauber. please
4448 // no-one ask me why it works that way (or may be not), especially
4449 // not about the angles and the sign of the height field, I don't
4450 // know it.
4451 EpsCell2d eps_cell;
4452 const double pi = numbers::PI;
4453 const double cx =
4454 -std::cos(pi - flags.azimut_angle * 2 * pi / 360.),
4455 cz = -std::cos(flags.turn_angle * 2 * pi / 360.),
4456 sx =
4457 std::sin(pi - flags.azimut_angle * 2 * pi / 360.),
4458 sz = std::sin(flags.turn_angle * 2 * pi / 360.);
4459 for (unsigned int vertex = 0; vertex < 4; ++vertex)
4460 {
4461 const double x = points[vertex][0], y = points[vertex][1],
4462 z = -heights[vertex];
4463
4464 eps_cell.vertices[vertex][0] = -cz * x + sz * y;
4465 eps_cell.vertices[vertex][1] =
4466 -cx * sz * x - cx * cz * y - sx * z;
4467
4468 // ( 1 0 0 )
4469 // D1 = ( 0 cx -sx )
4470 // ( 0 sx cx )
4471
4472 // ( cy 0 sy )
4473 // Dy = ( 0 1 0 )
4474 // (-sy 0 cy )
4475
4476 // ( cz -sz 0 )
4477 // Dz = ( sz cz 0 )
4478 // ( 0 0 1 )
4479
4480 // ( cz -sz 0 )( 1 0 0 )(x) (
4481 // cz*x-sz*(cx*y-sx*z)+0*(sx*y+cx*z) )
4482 // Dxz = ( sz cz 0 )( 0 cx -sx )(y) = (
4483 // sz*x+cz*(cx*y-sx*z)+0*(sx*y+cx*z) )
4484 // ( 0 0 1 )( 0 sx cx )(z) ( 0*x+
4485 // *(cx*y-sx*z)+1*(sx*y+cx*z) )
4486 }
4487
4488 // compute coordinates of center of cell
4489 const Point<spacedim> center_point =
4490 (points[0] + points[1] + points[2] + points[3]) / 4;
4491 const double center_height =
4492 -(heights[0] + heights[1] + heights[2] + heights[3]) / 4;
4493
4494 // compute the depth into the picture
4495 eps_cell.depth = -sx * sz * center_point[0] -
4496 sx * cz * center_point[1] + cx * center_height;
4497
4498 if (flags.draw_cells && flags.shade_cells)
4499 {
4500 Assert((flags.color_vector < patch.data.n_rows()) ||
4501 patch.data.n_rows() == 0,
4503 0,
4504 patch.data.n_rows()));
4505 const double color_values[4] = {
4506 patch.data.n_rows() != 0 ?
4507 patch.data(flags.color_vector, i1 * d1 + i2 * d2) :
4508 1,
4509
4510 patch.data.n_rows() != 0 ?
4511 patch.data(flags.color_vector, (i1 + 1) * d1 + i2 * d2) :
4512 1,
4513
4514 patch.data.n_rows() != 0 ?
4515 patch.data(flags.color_vector, i1 * d1 + (i2 + 1) * d2) :
4516 1,
4517
4518 patch.data.n_rows() != 0 ?
4519 patch.data(flags.color_vector,
4520 (i1 + 1) * d1 + (i2 + 1) * d2) :
4521 1};
4522
4523 // set color value to average of the value at the vertices
4524 eps_cell.color_value = (color_values[0] + color_values[1] +
4525 color_values[3] + color_values[2]) /
4526 4;
4527
4528 // update bounds of color field
4529 min_color_value =
4530 std::min(min_color_value, eps_cell.color_value);
4531 max_color_value =
4532 std::max(max_color_value, eps_cell.color_value);
4533 }
4534
4535 // finally add this cell
4536 cells.insert(eps_cell);
4537 }
4538 }
4539
4540 // find out minimum and maximum x and y coordinates to compute offsets and
4541 // scaling factors
4542 double x_min = cells.begin()->vertices[0][0];
4543 double x_max = x_min;
4544 double y_min = cells.begin()->vertices[0][1];
4545 double y_max = y_min;
4546
4547 for (const auto &cell : cells)
4548 for (const auto &vertex : cell.vertices)
4549 {
4550 x_min = std::min(x_min, vertex[0]);
4551 x_max = std::max(x_max, vertex[0]);
4552 y_min = std::min(y_min, vertex[1]);
4553 y_max = std::max(y_max, vertex[1]);
4554 }
4555
4556 // scale in x-direction such that in the output 0 <= x <= 300. don't scale
4557 // in y-direction to preserve the shape of the triangulation
4558 const double scale =
4559 (flags.size /
4560 (flags.size_type == EpsFlags::width ? x_max - x_min : y_min - y_max));
4561
4562 const Point<2> offset(x_min, y_min);
4563
4564
4565 // now write preamble
4566 {
4567 out << "%!PS-Adobe-2.0 EPSF-1.2" << '\n'
4568 << "%%Title: deal.II Output" << '\n'
4569 << "%%Creator: the deal.II library" << '\n'
4570 << "%%Creation Date: " << Utilities::System::get_date() << " - "
4571 << Utilities::System::get_time() << '\n'
4572 << "%%BoundingBox: "
4573 // lower left corner
4574 << "0 0 "
4575 // upper right corner
4576 << static_cast<unsigned int>((x_max - x_min) * scale + 0.5) << ' '
4577 << static_cast<unsigned int>((y_max - y_min) * scale + 0.5) << '\n';
4578
4579 // define some abbreviations to keep the output small:
4580 // m=move turtle to
4581 // l=define a line
4582 // s=set rgb color
4583 // sg=set gray value
4584 // lx=close the line and plot the line
4585 // lf=close the line and fill the interior
4586 out << "/m {moveto} bind def" << '\n'
4587 << "/l {lineto} bind def" << '\n'
4588 << "/s {setrgbcolor} bind def" << '\n'
4589 << "/sg {setgray} bind def" << '\n'
4590 << "/lx {lineto closepath stroke} bind def" << '\n'
4591 << "/lf {lineto closepath fill} bind def" << '\n';
4592
4593 out << "%%EndProlog" << '\n' << '\n';
4594 // set fine lines
4595 out << flags.line_width << " setlinewidth" << '\n';
4596 }
4597
4598 // check if min and max values for the color are actually different. If
4599 // that is not the case (such things happen, for example, in the very first
4600 // time step of a time dependent problem, if the initial values are zero),
4601 // all values are equal, and then we can draw everything in an arbitrary
4602 // color. Thus, change one of the two values arbitrarily
4603 if (max_color_value == min_color_value)
4604 max_color_value = min_color_value + 1;
4605
4606 // now we've got all the information we need. write the cells. note: due to
4607 // the ordering, we traverse the list of cells back-to-front
4608 for (const auto &cell : cells)
4609 {
4610 if (flags.draw_cells)
4611 {
4612 if (flags.shade_cells)
4613 {
4614 const EpsFlags::RgbValues rgb_values =
4615 (*flags.color_function)(cell.color_value,
4616 min_color_value,
4617 max_color_value);
4618
4619 // write out color
4620 if (rgb_values.is_grey())
4621 out << rgb_values.red << " sg ";
4622 else
4623 out << rgb_values.red << ' ' << rgb_values.green << ' '
4624 << rgb_values.blue << " s ";
4625 }
4626 else
4627 out << "1 sg ";
4628
4629 out << (cell.vertices[0] - offset) * scale << " m "
4630 << (cell.vertices[1] - offset) * scale << " l "
4631 << (cell.vertices[3] - offset) * scale << " l "
4632 << (cell.vertices[2] - offset) * scale << " lf" << '\n';
4633 }
4634
4635 if (flags.draw_mesh)
4636 out << "0 sg " // draw lines in black
4637 << (cell.vertices[0] - offset) * scale << " m "
4638 << (cell.vertices[1] - offset) * scale << " l "
4639 << (cell.vertices[3] - offset) * scale << " l "
4640 << (cell.vertices[2] - offset) * scale << " lx" << '\n';
4641 }
4642 out << "showpage" << '\n';
4643
4644 out.flush();
4645
4646 AssertThrow(out.fail() == false, ExcIO());
4647 }
4648
4649
4650
4651 template <int dim, int spacedim>
4652 void
4654 const std::vector<Patch<dim, spacedim>> &patches,
4655 const std::vector<std::string> &data_names,
4656 const std::vector<
4657 std::tuple<unsigned int,
4658 unsigned int,
4659 std::string,
4661 const GmvFlags &flags,
4662 std::ostream &out)
4663 {
4664 // The gmv format does not support cells that only consist of a single
4665 // point. It does support the output of point data using the keyword
4666 // 'tracers' instead of 'nodes' and 'cells', but this output format is
4667 // currently not implemented.
4668 AssertThrow(dim > 0, ExcNotImplemented());
4669
4670 Assert(dim <= 3, ExcNotImplemented());
4671 AssertThrow(out.fail() == false, ExcIO());
4672
4673#ifndef DEAL_II_WITH_MPI
4674 // verify that there are indeed patches to be written out. most of the
4675 // times, people just forget to call build_patches when there are no
4676 // patches, so a warning is in order. that said, the assertion is disabled
4677 // if we support MPI since then it can happen that on the coarsest mesh, a
4678 // processor simply has no cells it actually owns, and in that case it is
4679 // legit if there are no patches
4680 Assert(patches.size() > 0, ExcNoPatches());
4681#else
4682 if (patches.empty())
4683 return;
4684#endif
4685
4686 GmvStream gmv_out(out, flags);
4687 const unsigned int n_data_sets = data_names.size();
4688 // check against # of data sets in first patch. checks against all other
4689 // patches are made in write_gmv_reorder_data_vectors
4690 Assert((patches[0].data.n_rows() == n_data_sets &&
4691 !patches[0].points_are_available) ||
4692 (patches[0].data.n_rows() == n_data_sets + spacedim &&
4693 patches[0].points_are_available),
4694 ExcDimensionMismatch(patches[0].points_are_available ?
4695 (n_data_sets + spacedim) :
4696 n_data_sets,
4697 patches[0].data.n_rows()));
4698
4699 //---------------------
4700 // preamble
4701 out << "gmvinput ascii" << '\n' << '\n';
4702
4703 // first count the number of cells and cells for later use
4704 unsigned int n_nodes;
4705 unsigned int n_cells;
4706 std::tie(n_nodes, n_cells) = count_nodes_and_cells(patches);
4707
4708 // For the format we write here, we need to write all node values relating
4709 // to one variable at a time. We could in principle do this by looping
4710 // over all patches and extracting the values corresponding to the one
4711 // variable we're dealing with right now, and then start the process over
4712 // for the next variable with another loop over all patches.
4713 //
4714 // An easier way is to create a global table that for each variable
4715 // lists all values. This copying of data vectors can be done in the
4716 // background while we're already working on vertices and cells,
4717 // so do this on a separate task and when wanting to write out the
4718 // data, we wait for that task to finish.
4720 create_global_data_table_task = Threads::new_task(
4721 [&patches]() { return create_global_data_table(patches); });
4722
4723 //-----------------------------
4724 // first make up a list of used vertices along with their coordinates
4725 //
4726 // note that we have to print 3 dimensions
4727 out << "nodes " << n_nodes << '\n';
4728 for (unsigned int d = 0; d < spacedim; ++d)
4729 {
4730 gmv_out.selected_component = d;
4731 write_nodes(patches, gmv_out);
4732 out << '\n';
4733 }
4734 gmv_out.selected_component = numbers::invalid_unsigned_int;
4735
4736 for (unsigned int d = spacedim; d < 3; ++d)
4737 {
4738 for (unsigned int i = 0; i < n_nodes; ++i)
4739 out << "0 ";
4740 out << '\n';
4741 }
4742
4743 //-------------------------------
4744 // now for the cells. note that vertices are counted from 1 onwards
4745 out << "cells " << n_cells << '\n';
4746 write_cells(patches, gmv_out);
4747
4748 //-------------------------------------
4749 // data output.
4750 out << "variable" << '\n';
4751
4752 // Wait for the reordering to be done and retrieve the reordered data:
4753 const Table<2, double> data_vectors =
4754 std::move(*create_global_data_table_task.return_value());
4755
4756 // then write data. the '1' means: node data (as opposed to cell data, which
4757 // we do not support explicitly here)
4758 for (unsigned int data_set = 0; data_set < n_data_sets; ++data_set)
4759 {
4760 out << data_names[data_set] << " 1" << '\n';
4761 std::copy(data_vectors[data_set].begin(),
4762 data_vectors[data_set].end(),
4763 std::ostream_iterator<double>(out, " "));
4764 out << '\n' << '\n';
4765 }
4766
4767
4768
4769 // end of variable section
4770 out << "endvars" << '\n';
4771
4772 // end of output
4773 out << "endgmv" << '\n';
4774
4775 // make sure everything now gets to disk
4776 out.flush();
4777
4778 // assert the stream is still ok
4779 AssertThrow(out.fail() == false, ExcIO());
4780 }
4781
4782
4783
4784 template <int dim, int spacedim>
4785 void
4787 const std::vector<Patch<dim, spacedim>> &patches,
4788 const std::vector<std::string> &data_names,
4789 const std::vector<
4790 std::tuple<unsigned int,
4791 unsigned int,
4792 std::string,
4794 const TecplotFlags &flags,
4795 std::ostream &out)
4796 {
4797 AssertThrow(out.fail() == false, ExcIO());
4798
4799 // The FEBLOCK or FEPOINT formats of tecplot only allows full elements (e.g.
4800 // triangles), not single points. Other tecplot format allow point output,
4801 // but they are currently not implemented.
4802 AssertThrow(dim > 0, ExcNotImplemented());
4803
4804#ifndef DEAL_II_WITH_MPI
4805 // verify that there are indeed patches to be written out. most of the
4806 // times, people just forget to call build_patches when there are no
4807 // patches, so a warning is in order. that said, the assertion is disabled
4808 // if we support MPI since then it can happen that on the coarsest mesh, a
4809 // processor simply has no cells it actually owns, and in that case it is
4810 // legit if there are no patches
4811 Assert(patches.size() > 0, ExcNoPatches());
4812#else
4813 if (patches.empty())
4814 return;
4815#endif
4816
4817 TecplotStream tecplot_out(out, flags);
4818
4819 const unsigned int n_data_sets = data_names.size();
4820 // check against # of data sets in first patch. checks against all other
4821 // patches are made in write_gmv_reorder_data_vectors
4822 Assert((patches[0].data.n_rows() == n_data_sets &&
4823 !patches[0].points_are_available) ||
4824 (patches[0].data.n_rows() == n_data_sets + spacedim &&
4825 patches[0].points_are_available),
4826 ExcDimensionMismatch(patches[0].points_are_available ?
4827 (n_data_sets + spacedim) :
4828 n_data_sets,
4829 patches[0].data.n_rows()));
4830
4831 // first count the number of cells and cells for later use
4832 unsigned int n_nodes;
4833 unsigned int n_cells;
4834 std::tie(n_nodes, n_cells) = count_nodes_and_cells(patches);
4835
4836 //---------
4837 // preamble
4838 {
4839 out
4840 << "# This file was generated by the deal.II library." << '\n'
4841 << "# Date = " << Utilities::System::get_date() << '\n'
4842 << "# Time = " << Utilities::System::get_time() << '\n'
4843 << "#" << '\n'
4844 << "# For a description of the Tecplot format see the Tecplot documentation."
4845 << '\n'
4846 << "#" << '\n';
4847
4848
4849 out << "Variables=";
4850
4851 switch (spacedim)
4852 {
4853 case 1:
4854 out << "\"x\"";
4855 break;
4856 case 2:
4857 out << "\"x\", \"y\"";
4858 break;
4859 case 3:
4860 out << "\"x\", \"y\", \"z\"";
4861 break;
4862 default:
4864 }
4865
4866 for (unsigned int data_set = 0; data_set < n_data_sets; ++data_set)
4867 out << ", \"" << data_names[data_set] << "\"";
4868
4869 out << '\n';
4870
4871 out << "zone ";
4872 if (flags.zone_name)
4873 out << "t=\"" << flags.zone_name << "\" ";
4874
4875 if (flags.solution_time >= 0.0)
4876 out << "strandid=1, solutiontime=" << flags.solution_time << ", ";
4877
4878 out << "f=feblock, n=" << n_nodes << ", e=" << n_cells
4879 << ", et=" << tecplot_cell_type[dim] << '\n';
4880 }
4881
4882
4883 // For the format we write here, we need to write all node values relating
4884 // to one variable at a time. We could in principle do this by looping
4885 // over all patches and extracting the values corresponding to the one
4886 // variable we're dealing with right now, and then start the process over
4887 // for the next variable with another loop over all patches.
4888 //
4889 // An easier way is to create a global table that for each variable
4890 // lists all values. This copying of data vectors can be done in the
4891 // background while we're already working on vertices and cells,
4892 // so do this on a separate task and when wanting to write out the
4893 // data, we wait for that task to finish.
4895 create_global_data_table_task = Threads::new_task(
4896 [&patches]() { return create_global_data_table(patches); });
4897
4898 //-----------------------------
4899 // first make up a list of used vertices along with their coordinates
4900
4901
4902 for (unsigned int d = 0; d < spacedim; ++d)
4903 {
4904 tecplot_out.selected_component = d;
4905 write_nodes(patches, tecplot_out);
4906 out << '\n';
4907 }
4908
4909
4910 //-------------------------------------
4911 // data output.
4912 //
4913 // Wait for the reordering to be done and retrieve the reordered data:
4914 const Table<2, double> data_vectors =
4915 std::move(*create_global_data_table_task.return_value());
4916
4917 // then write data.
4918 for (unsigned int data_set = 0; data_set < n_data_sets; ++data_set)
4919 {
4920 std::copy(data_vectors[data_set].begin(),
4921 data_vectors[data_set].end(),
4922 std::ostream_iterator<double>(out, "\n"));
4923 out << '\n';
4924 }
4925
4926 write_cells(patches, tecplot_out);
4927
4928 // make sure everything now gets to disk
4929 out.flush();
4930
4931 // assert the stream is still ok
4932 AssertThrow(out.fail() == false, ExcIO());
4933 }
4934
4935
4936
4937 template <int dim, int spacedim>
4938 void
4940 const std::vector<Patch<dim, spacedim>> &patches,
4941 const std::vector<std::string> &data_names,
4942 const std::vector<
4943 std::tuple<unsigned int,
4944 unsigned int,
4945 std::string,
4947 &nonscalar_data_ranges,
4948 const VtkFlags &flags,
4949 std::ostream &out)
4950 {
4951 AssertThrow(out.fail() == false, ExcIO());
4952
4953#ifndef DEAL_II_WITH_MPI
4954 // verify that there are indeed patches to be written out. most of the
4955 // times, people just forget to call build_patches when there are no
4956 // patches, so a warning is in order. that said, the assertion is disabled
4957 // if we support MPI since then it can happen that on the coarsest mesh, a
4958 // processor simply has no cells it actually owns, and in that case it is
4959 // legit if there are no patches
4960 Assert(patches.size() > 0, ExcNoPatches());
4961#else
4962 if (patches.empty())
4963 return;
4964#endif
4965
4966 VtkStream vtk_out(out, flags);
4967
4968 const unsigned int n_data_sets = data_names.size();
4969 // check against # of data sets in first patch.
4970 if (patches[0].points_are_available)
4971 {
4972 AssertDimension(n_data_sets + spacedim, patches[0].data.n_rows());
4973 }
4974 else
4975 {
4976 AssertDimension(n_data_sets, patches[0].data.n_rows());
4977 }
4978
4979 //---------------------
4980 // preamble
4981 {
4982 out << "# vtk DataFile Version 3.0" << '\n'
4983 << "#This file was generated by the deal.II library";
4984 if (flags.print_date_and_time)
4985 {
4986 out << " on " << Utilities::System::get_date() << " at "
4988 }
4989 else
4990 out << '.';
4991 out << '\n' << "ASCII" << '\n';
4992 // now output the data header
4993 out << "DATASET UNSTRUCTURED_GRID\n" << '\n';
4994 }
4995
4996 // if desired, output time and cycle of the simulation, following the
4997 // instructions at
4998 // http://www.visitusers.org/index.php?title=Time_and_Cycle_in_VTK_files
4999 {
5000 const unsigned int n_metadata =
5001 ((flags.cycle != std::numeric_limits<unsigned int>::min() ? 1 : 0) +
5002 (flags.time != std::numeric_limits<double>::min() ? 1 : 0));
5003 if (n_metadata > 0)
5004 {
5005 out << "FIELD FieldData " << n_metadata << '\n';
5006
5007 if (flags.cycle != std::numeric_limits<unsigned int>::min())
5008 {
5009 out << "CYCLE 1 1 int\n" << flags.cycle << '\n';
5010 }
5011 if (flags.time != std::numeric_limits<double>::min())
5012 {
5013 out << "TIME 1 1 double\n" << flags.time << '\n';
5014 }
5015 }
5016 }
5017
5018 // first count the number of cells and cells for later use
5019 unsigned int n_nodes;
5020 unsigned int n_cells;
5021 unsigned int n_points_and_n_cells;
5022 std::tie(n_nodes, n_cells, n_points_and_n_cells) =
5023 count_nodes_and_cells_and_points(patches, flags.write_higher_order_cells);
5024
5025 // For the format we write here, we need to write all node values relating
5026 // to one variable at a time. We could in principle do this by looping
5027 // over all patches and extracting the values corresponding to the one
5028 // variable we're dealing with right now, and then start the process over
5029 // for the next variable with another loop over all patches.
5030 //
5031 // An easier way is to create a global table that for each variable
5032 // lists all values. This copying of data vectors can be done in the
5033 // background while we're already working on vertices and cells,
5034 // so do this on a separate task and when wanting to write out the
5035 // data, we wait for that task to finish.
5037 create_global_data_table_task = Threads::new_task(
5038 [&patches]() { return create_global_data_table(patches); });
5039
5040 //-----------------------------
5041 // first make up a list of used vertices along with their coordinates
5042 //
5043 // note that we have to print d=1..3 dimensions
5044 out << "POINTS " << n_nodes << " double" << '\n';
5045 write_nodes(patches, vtk_out);
5046 out << '\n';
5047 //-------------------------------
5048 // now for the cells
5049 out << "CELLS " << n_cells << ' ' << n_points_and_n_cells << '\n';
5050 if (flags.write_higher_order_cells)
5051 write_high_order_cells(patches, vtk_out, /* legacy_format = */ true);
5052 else
5053 write_cells(patches, vtk_out);
5054 out << '\n';
5055 // next output the types of the cells. since all cells are the same, this is
5056 // simple
5057 out << "CELL_TYPES " << n_cells << '\n';
5058
5059 // need to distinguish between linear cells, simplex cells (linear or
5060 // quadratic), and high order cells
5061 for (const auto &patch : patches)
5062 {
5063 const auto vtk_cell_id =
5064 extract_vtk_patch_info(patch, flags.write_higher_order_cells);
5065
5066 for (unsigned int i = 0; i < vtk_cell_id[1]; ++i)
5067 out << ' ' << vtk_cell_id[0];
5068 }
5069
5070 out << '\n';
5071 //-------------------------------------
5072 // data output.
5073
5074 // Wait for the reordering to be done and retrieve the reordered data:
5075 const Table<2, double> data_vectors =
5076 std::move(*create_global_data_table_task.return_value());
5077
5078 // then write data. the 'POINT_DATA' means: node data (as opposed to cell
5079 // data, which we do not support explicitly here). all following data sets
5080 // are point data
5081 out << "POINT_DATA " << n_nodes << '\n';
5082
5083 // when writing, first write out all vector data, then handle the scalar
5084 // data sets that have been left over
5085 std::vector<bool> data_set_written(n_data_sets, false);
5086 for (const auto &nonscalar_data_range : nonscalar_data_ranges)
5087 {
5088 AssertThrow(std::get<3>(nonscalar_data_range) !=
5090 ExcMessage(
5091 "The VTK writer does not currently support outputting "
5092 "tensor data. Use the VTU writer instead."));
5093
5094 AssertThrow(std::get<1>(nonscalar_data_range) >=
5095 std::get<0>(nonscalar_data_range),
5096 ExcLowerRange(std::get<1>(nonscalar_data_range),
5097 std::get<0>(nonscalar_data_range)));
5098 AssertThrow(std::get<1>(nonscalar_data_range) < n_data_sets,
5099 ExcIndexRange(std::get<1>(nonscalar_data_range),
5100 0,
5101 n_data_sets));
5102 AssertThrow(std::get<1>(nonscalar_data_range) + 1 -
5103 std::get<0>(nonscalar_data_range) <=
5104 3,
5105 ExcMessage(
5106 "Can't declare a vector with more than 3 components "
5107 "in VTK"));
5108
5109 // mark these components as already written:
5110 for (unsigned int i = std::get<0>(nonscalar_data_range);
5111 i <= std::get<1>(nonscalar_data_range);
5112 ++i)
5113 data_set_written[i] = true;
5114
5115 // write the header. concatenate all the component names with double
5116 // underscores unless a vector name has been specified
5117 out << "VECTORS ";
5118
5119 if (!std::get<2>(nonscalar_data_range).empty())
5120 out << std::get<2>(nonscalar_data_range);
5121 else
5122 {
5123 for (unsigned int i = std::get<0>(nonscalar_data_range);
5124 i < std::get<1>(nonscalar_data_range);
5125 ++i)
5126 out << data_names[i] << "__";
5127 out << data_names[std::get<1>(nonscalar_data_range)];
5128 }
5129
5130 out << " double" << '\n';
5131
5132 // now write data. pad all vectors to have three components
5133 for (unsigned int n = 0; n < n_nodes; ++n)
5134 {
5135 switch (std::get<1>(nonscalar_data_range) -
5136 std::get<0>(nonscalar_data_range))
5137 {
5138 case 0:
5139 out << data_vectors(std::get<0>(nonscalar_data_range), n)
5140 << " 0 0" << '\n';
5141 break;
5142
5143 case 1:
5144 out << data_vectors(std::get<0>(nonscalar_data_range), n)
5145 << ' '
5146 << data_vectors(std::get<0>(nonscalar_data_range) + 1, n)
5147 << " 0" << '\n';
5148 break;
5149 case 2:
5150 out << data_vectors(std::get<0>(nonscalar_data_range), n)
5151 << ' '
5152 << data_vectors(std::get<0>(nonscalar_data_range) + 1, n)
5153 << ' '
5154 << data_vectors(std::get<0>(nonscalar_data_range) + 2, n)
5155 << '\n';
5156 break;
5157
5158 default:
5159 // VTK doesn't support anything else than vectors with 1, 2,
5160 // or 3 components
5162 }
5163 }
5164 }
5165
5166 // now do the left over scalar data sets
5167 for (unsigned int data_set = 0; data_set < n_data_sets; ++data_set)
5168 if (data_set_written[data_set] == false)
5169 {
5170 out << "SCALARS " << data_names[data_set] << " double 1" << '\n'
5171 << "LOOKUP_TABLE default" << '\n';
5172 std::copy(data_vectors[data_set].begin(),
5173 data_vectors[data_set].end(),
5174 std::ostream_iterator<double>(out, " "));
5175 out << '\n';
5176 }
5177
5178 // make sure everything now gets to disk
5179 out.flush();
5180
5181 // assert the stream is still ok
5182 AssertThrow(out.fail() == false, ExcIO());
5183 }
5184
5185
5186 void
5187 write_vtu_header(std::ostream &out, const VtkFlags &flags)
5188 {
5189 AssertThrow(out.fail() == false, ExcIO());
5190 out << "<?xml version=\"1.0\" ?> \n";
5191 out << "<!-- \n";
5192 out << "# vtk DataFile Version 3.0" << '\n'
5193 << "#This file was generated by the deal.II library";
5194 if (flags.print_date_and_time)
5195 {
5196 out << " on " << Utilities::System::get_time() << " at "
5198 }
5199 else
5200 out << '.';
5201 out << "\n-->\n";
5202
5203 if (flags.write_higher_order_cells)
5204 out << "<VTKFile type=\"UnstructuredGrid\" version=\"2.2\"";
5205 else
5206 out << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\"";
5207 if (deal_ii_with_zlib &&
5209 out << " compressor=\"vtkZLibDataCompressor\"";
5210#ifdef DEAL_II_WORDS_BIGENDIAN
5211 out << " byte_order=\"BigEndian\"";
5212#else
5213 out << " byte_order=\"LittleEndian\"";
5214#endif
5215 out << ">";
5216 out << '\n';
5217 out << "<UnstructuredGrid>";
5218 out << '\n';
5219 }
5220
5221
5222
5223 void
5224 write_vtu_footer(std::ostream &out)
5225 {
5226 AssertThrow(out.fail() == false, ExcIO());
5227 out << " </UnstructuredGrid>\n";
5228 out << "</VTKFile>\n";
5229 }
5230
5231
5232
5233 template <int dim, int spacedim>
5234 void
5236 const std::vector<Patch<dim, spacedim>> &patches,
5237 const std::vector<std::string> &data_names,
5238 const std::vector<
5239 std::tuple<unsigned int,
5240 unsigned int,
5241 std::string,
5243 &nonscalar_data_ranges,
5244 const VtkFlags &flags,
5245 std::ostream &out)
5246 {
5247 write_vtu_header(out, flags);
5248 write_vtu_main(patches, data_names, nonscalar_data_ranges, flags, out);
5249 write_vtu_footer(out);
5250
5251 out << std::flush;
5252 }
5253
5254
5255 template <int dim, int spacedim>
5256 void
5258 const std::vector<Patch<dim, spacedim>> &patches,
5259 const std::vector<std::string> &data_names,
5260 const std::vector<
5261 std::tuple<unsigned int,
5262 unsigned int,
5263 std::string,
5265 &nonscalar_data_ranges,
5266 const VtkFlags &flags,
5267 std::ostream &out)
5268 {
5269 AssertThrow(out.fail() == false, ExcIO());
5270
5271 // If the user provided physical units, make sure that they don't contain
5272 // quote characters as this would make the VTU file invalid XML and
5273 // probably lead to all sorts of difficult error messages. Other than that,
5274 // trust the user that whatever they provide makes sense somehow.
5275 for (const auto &unit : flags.physical_units)
5276 {
5277 (void)unit;
5278 Assert(
5279 unit.second.find('\"') == std::string::npos,
5280 ExcMessage(
5281 "A physical unit you provided, <" + unit.second +
5282 ">, contained a quotation mark character. This is not allowed."));
5283 }
5284
5285#ifndef DEAL_II_WITH_MPI
5286 // verify that there are indeed patches to be written out. most of the
5287 // times, people just forget to call build_patches when there are no
5288 // patches, so a warning is in order. that said, the assertion is disabled
5289 // if we support MPI since then it can happen that on the coarsest mesh, a
5290 // processor simply has no cells it actually owns, and in that case it is
5291 // legit if there are no patches
5292 Assert(patches.size() > 0, ExcNoPatches());
5293#else
5294 if (patches.empty())
5295 {
5296 // we still need to output a valid vtu file, because other CPUs might
5297 // output data. This is the minimal file that is accepted by paraview
5298 // and visit. if we remove the field definitions, visit is complaining.
5299 out << "<Piece NumberOfPoints=\"0\" NumberOfCells=\"0\" >\n"
5300 << "<Cells>\n"
5301 << "<DataArray type=\"UInt8\" Name=\"types\"></DataArray>\n"
5302 << "</Cells>\n"
5303 << " <PointData Scalars=\"scalars\">\n";
5304 std::vector<bool> data_set_written(data_names.size(), false);
5305 for (const auto &nonscalar_data_range : nonscalar_data_ranges)
5306 {
5307 // mark these components as already written:
5308 for (unsigned int i = std::get<0>(nonscalar_data_range);
5309 i <= std::get<1>(nonscalar_data_range);
5310 ++i)
5311 data_set_written[i] = true;
5312
5313 // write the header. concatenate all the component names with double
5314 // underscores unless a vector name has been specified
5315 out << " <DataArray type=\"Float32\" Name=\"";
5316
5317 if (!std::get<2>(nonscalar_data_range).empty())
5318 out << std::get<2>(nonscalar_data_range);
5319 else
5320 {
5321 for (unsigned int i = std::get<0>(nonscalar_data_range);
5322 i < std::get<1>(nonscalar_data_range);
5323 ++i)
5324 out << data_names[i] << "__";
5325 out << data_names[std::get<1>(nonscalar_data_range)];
5326 }
5327
5328 out << "\" NumberOfComponents=\"3\"></DataArray>\n";
5329 }
5330
5331 for (unsigned int data_set = 0; data_set < data_names.size();
5332 ++data_set)
5333 if (data_set_written[data_set] == false)
5334 {
5335 out << " <DataArray type=\"Float32\" Name=\""
5336 << data_names[data_set] << "\"></DataArray>\n";
5337 }
5338
5339 out << " </PointData>\n";
5340 out << "</Piece>\n";
5341
5342 out << std::flush;
5343
5344 return;
5345 }
5346#endif
5347
5348 // first up: metadata
5349 //
5350 // if desired, output time and cycle of the simulation, following the
5351 // instructions at
5352 // http://www.visitusers.org/index.php?title=Time_and_Cycle_in_VTK_files
5353 {
5354 const unsigned int n_metadata =
5355 ((flags.cycle != std::numeric_limits<unsigned int>::min() ? 1 : 0) +
5356 (flags.time != std::numeric_limits<double>::min() ? 1 : 0));
5357 if (n_metadata > 0)
5358 out << "<FieldData>\n";
5359
5360 if (flags.cycle != std::numeric_limits<unsigned int>::min())
5361 {
5362 out
5363 << "<DataArray type=\"Float32\" Name=\"CYCLE\" NumberOfTuples=\"1\" format=\"ascii\">"
5364 << flags.cycle << "</DataArray>\n";
5365 }
5366 if (flags.time != std::numeric_limits<double>::min())
5367 {
5368 out
5369 << "<DataArray type=\"Float32\" Name=\"TIME\" NumberOfTuples=\"1\" format=\"ascii\">"
5370 << flags.time << "</DataArray>\n";
5371 }
5372
5373 if (n_metadata > 0)
5374 out << "</FieldData>\n";
5375 }
5376
5377
5378 const unsigned int n_data_sets = data_names.size();
5379 // check against # of data sets in first patch. checks against all other
5380 // patches are made in write_gmv_reorder_data_vectors
5381 if (patches[0].points_are_available)
5382 {
5383 AssertDimension(n_data_sets + spacedim, patches[0].data.n_rows());
5384 }
5385 else
5386 {
5387 AssertDimension(n_data_sets, patches[0].data.n_rows());
5388 }
5389
5390 const char *ascii_or_binary =
5391 (deal_ii_with_zlib &&
5393 "binary" :
5394 "ascii";
5395
5396
5397 // first count the number of cells and cells for later use
5398 unsigned int n_nodes;
5399 unsigned int n_cells;
5400 std::tie(n_nodes, n_cells, std::ignore) =
5401 count_nodes_and_cells_and_points(patches, flags.write_higher_order_cells);
5402
5403 // -----------------
5404 // In the following, let us first set up a number of lambda functions that
5405 // will be used in building the different parts of the VTU file. We will
5406 // later call them in turn on different tasks.
5407 // first make up a list of used vertices along with their coordinates
5408 const auto stringize_vertex_information = [&patches,
5409 &flags,
5410 output_precision =
5411 out.precision(),
5412 ascii_or_binary]() {
5413 std::ostringstream o;
5414 o << " <Points>\n";
5415 o << " <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\""
5416 << ascii_or_binary << "\">\n";
5417 const std::vector<Point<spacedim>> node_positions =
5418 get_node_positions(patches);
5419
5420 // VTK/VTU always wants to see three coordinates, even if we are
5421 // in 1d or 2d. So pad node positions with zeros as appropriate.
5422 std::vector<float> node_coordinates_3d;
5423 node_coordinates_3d.reserve(node_positions.size() * 3);
5424 for (const auto &node_position : node_positions)
5425 {
5426 for (unsigned int d = 0; d < 3; ++d)
5427 if (d < spacedim)
5428 node_coordinates_3d.emplace_back(node_position[d]);
5429 else
5430 node_coordinates_3d.emplace_back(0.0f);
5431 }
5432 o << vtu_stringize_array(node_coordinates_3d,
5433 flags.compression_level,
5434 output_precision)
5435 << '\n';
5436 o << " </DataArray>\n";
5437 o << " </Points>\n\n";
5438
5439 return o.str();
5440 };
5441
5442
5443 //-------------------------------
5444 // Now for the cells. The first part of this is how vertices
5445 // build cells.
5446 const auto stringize_cell_to_vertex_information = [&patches,
5447 &flags,
5448 ascii_or_binary,
5449 output_precision =
5450 out.precision()]() {
5451 std::ostringstream o;
5452
5453 o << " <Cells>\n";
5454 o << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\""
5455 << ascii_or_binary << "\">\n";
5456
5457 std::vector<std::int32_t> cells;
5458 Assert(dim <= 3, ExcNotImplemented());
5459
5460 unsigned int first_vertex_of_patch = 0;
5461
5462 for (const auto &patch : patches)
5463 {
5464 // First treat a slight oddball case: For triangles and tetrahedra,
5465 // the case with n_subdivisions==2 is treated as if the cell was
5466 // output as a single, quadratic, cell rather than as one would
5467 // expect as 4 sub-cells (for triangles; and the corresponding
5468 // number of sub-cells for tetrahedra). This is courtesy of some
5469 // special-casing in the function extract_vtk_patch_info().
5470 if ((dim >= 2) &&
5472 (patch.n_subdivisions == 2))
5473 {
5474 const unsigned int n_points = patch.data.n_cols();
5475 Assert((dim == 2 && n_points == 6) ||
5476 (dim == 3 && n_points == 10),
5478
5479 if (deal_ii_with_zlib &&
5480 (flags.compression_level !=
5482 {
5483 for (unsigned int i = 0; i < n_points; ++i)
5484 cells.push_back(first_vertex_of_patch + i);
5485 }
5486 else
5487 {
5488 for (unsigned int i = 0; i < n_points; ++i)
5489 o << '\t' << first_vertex_of_patch + i;
5490 o << '\n';
5491 }
5492
5493 first_vertex_of_patch += n_points;
5494 }
5495 // Then treat all of the other non-hypercube cases since they can
5496 // currently not be subdivided (into sub-cells, or into higher-order
5497 // cells):
5499 {
5501
5502 const unsigned int n_points = patch.data.n_cols();
5503
5504 if (deal_ii_with_zlib &&
5505 (flags.compression_level !=
5507 {
5508 for (unsigned int i = 0; i < n_points; ++i)
5509 cells.push_back(
5510 first_vertex_of_patch +
5512 }
5513 else
5514 {
5515 for (unsigned int i = 0; i < n_points; ++i)
5516 o << '\t'
5517 << (first_vertex_of_patch +
5519 o << '\n';
5520 }
5521
5522 first_vertex_of_patch += n_points;
5523 }
5524 else // a hypercube cell
5525 {
5526 const unsigned int n_subdivisions = patch.n_subdivisions;
5527 const unsigned int n_points_per_direction = n_subdivisions + 1;
5528
5529 std::vector<unsigned> local_vertex_order;
5530
5531 // Output the current state of the local_vertex_order array,
5532 // then clear it:
5533 const auto flush_current_cell = [&flags,
5534 &o,
5535 &cells,
5536 first_vertex_of_patch,
5537 &local_vertex_order]() {
5538 if (deal_ii_with_zlib &&
5539 (flags.compression_level !=
5541 {
5542 for (const auto &c : local_vertex_order)
5543 cells.push_back(first_vertex_of_patch + c);
5544 }
5545 else
5546 {
5547 for (const auto &c : local_vertex_order)
5548 o << '\t' << first_vertex_of_patch + c;
5549 o << '\n';
5550 }
5551
5552 local_vertex_order.clear();
5553 };
5554
5555 if (flags.write_higher_order_cells == false)
5556 {
5557 local_vertex_order.reserve(Utilities::fixed_power<dim>(2));
5558
5559 switch (dim)
5560 {
5561 case 0:
5562 {
5563 local_vertex_order.emplace_back(0);
5564 flush_current_cell();
5565 break;
5566 }
5567
5568 case 1:
5569 {
5570 for (unsigned int i1 = 0; i1 < n_subdivisions; ++i1)
5571 {
5572 const unsigned int starting_offset = i1;
5573 local_vertex_order.emplace_back(starting_offset);
5574 local_vertex_order.emplace_back(starting_offset +
5575 1);
5576 flush_current_cell();
5577 }
5578 break;
5579 }
5580
5581 case 2:
5582 {
5583 for (unsigned int i2 = 0; i2 < n_subdivisions; ++i2)
5584 for (unsigned int i1 = 0; i1 < n_subdivisions; ++i1)
5585 {
5586 const unsigned int starting_offset =
5587 i2 * n_points_per_direction + i1;
5588 local_vertex_order.emplace_back(
5589 starting_offset);
5590 local_vertex_order.emplace_back(
5591 starting_offset + 1);
5592 local_vertex_order.emplace_back(
5593 starting_offset + n_points_per_direction + 1);
5594 local_vertex_order.emplace_back(
5595 starting_offset + n_points_per_direction);
5596 flush_current_cell();
5597 }
5598 break;
5599 }
5600
5601 case 3:
5602 {
5603 for (unsigned int i3 = 0; i3 < n_subdivisions; ++i3)
5604 for (unsigned int i2 = 0; i2 < n_subdivisions; ++i2)
5605 for (unsigned int i1 = 0; i1 < n_subdivisions;
5606 ++i1)
5607 {
5608 const unsigned int starting_offset =
5609 i3 * n_points_per_direction *
5610 n_points_per_direction +
5611 i2 * n_points_per_direction + i1;
5612 local_vertex_order.emplace_back(
5613 starting_offset);
5614 local_vertex_order.emplace_back(
5615 starting_offset + 1);
5616 local_vertex_order.emplace_back(
5617 starting_offset + n_points_per_direction +
5618 1);
5619 local_vertex_order.emplace_back(
5620 starting_offset + n_points_per_direction);
5621 local_vertex_order.emplace_back(
5622 starting_offset + n_points_per_direction *
5623 n_points_per_direction);
5624 local_vertex_order.emplace_back(
5625 starting_offset +
5626 n_points_per_direction *
5627 n_points_per_direction +
5628 1);
5629 local_vertex_order.emplace_back(
5630 starting_offset +
5631 n_points_per_direction *
5632 n_points_per_direction +
5633 n_points_per_direction + 1);
5634 local_vertex_order.emplace_back(
5635 starting_offset +
5636 n_points_per_direction *
5637 n_points_per_direction +
5638 n_points_per_direction);
5639 flush_current_cell();
5640 }
5641 break;
5642 }
5643
5644 default:
5646 }
5647 }
5648 else // use higher-order output
5649 {
5650 local_vertex_order.resize(
5651 Utilities::fixed_power<dim>(n_points_per_direction));
5652
5653 switch (dim)
5654 {
5655 case 0:
5656 {
5657 Assert(false,
5658 ExcMessage(
5659 "Point-like cells should not be possible "
5660 "when writing higher-order cells."));
5661 break;
5662 }
5663 case 1:
5664 {
5665 for (unsigned int i1 = 0; i1 < n_subdivisions + 1;
5666 ++i1)
5667 {
5668 const unsigned int local_index = i1;
5669 const unsigned int connectivity_index =
5670 patch.reference_cell
5671 .template vtk_lexicographic_to_node_index<1>(
5672 {{i1}},
5673 {{n_subdivisions}},
5674 /* use VTU, not VTK: */ false);
5675 local_vertex_order[connectivity_index] =
5676 local_index;
5677 }
5678 flush_current_cell();
5679
5680 break;
5681 }
5682 case 2:
5683 {
5684 for (unsigned int i2 = 0; i2 < n_subdivisions + 1;
5685 ++i2)
5686 for (unsigned int i1 = 0; i1 < n_subdivisions + 1;
5687 ++i1)
5688 {
5689 const unsigned int local_index =
5690 i2 * n_points_per_direction + i1;
5691 const unsigned int connectivity_index =
5692 patch.reference_cell
5693 .template vtk_lexicographic_to_node_index<
5694 2>({{i1, i2}},
5696 /* use VTU, not VTK: */ false);
5697 local_vertex_order[connectivity_index] =
5698 local_index;
5699 }
5700 flush_current_cell();
5701
5702 break;
5703 }
5704 case 3:
5705 {
5706 for (unsigned int i3 = 0; i3 < n_subdivisions + 1;
5707 ++i3)
5708 for (unsigned int i2 = 0; i2 < n_subdivisions + 1;
5709 ++i2)
5710 for (unsigned int i1 = 0; i1 < n_subdivisions + 1;
5711 ++i1)
5712 {
5713 const unsigned int local_index =
5714 i3 * n_points_per_direction *
5715 n_points_per_direction +
5716 i2 * n_points_per_direction + i1;
5717 const unsigned int connectivity_index =
5718 patch.reference_cell
5719 .template vtk_lexicographic_to_node_index<
5720 3>({{i1, i2, i3}},
5724 /* use VTU, not VTK: */ false);
5725 local_vertex_order[connectivity_index] =
5726 local_index;
5727 }
5728
5729 flush_current_cell();
5730 break;
5731 }
5732 default:
5734 }
5735 }
5736
5737 // Finally update the number of the first vertex of this
5738 // patch
5739 first_vertex_of_patch +=
5741 }
5742 }
5743
5744 // Flush the 'cells' object we created herein.
5745 if (deal_ii_with_zlib && (flags.compression_level !=
5747 {
5748 o << vtu_stringize_array(cells,
5749 flags.compression_level,
5750 output_precision)
5751 << '\n';
5752 }
5753 o << " </DataArray>\n";
5754
5755 return o.str();
5756 };
5757
5758
5759 //-------------------------------
5760 // The second part of cell information is the offsets in
5761 // the array built by the previous lambda function that indicate
5762 // individual cells.
5763 //
5764 // Note that this separates XML VTU format from the VTK format; the latter
5765 // puts the number of nodes per cell in front of the connectivity list for
5766 // each cell, whereas the VTU format uses one large list of vertex indices
5767 // and a separate array of offsets.
5768 //
5769 // The third piece to cell information is that we need to
5770 // output the types of the cells.
5771 //
5772 // The following function does both of these pieces.
5773 const auto stringize_cell_offset_and_type_information =
5774 [&patches,
5775 &flags,
5776 ascii_or_binary,
5777 n_cells,
5778 output_precision = out.precision()]() {
5779 std::ostringstream o;
5780
5781 o << " <DataArray type=\"Int32\" Name=\"offsets\" format=\""
5782 << ascii_or_binary << "\">\n";
5783
5784 std::vector<std::int32_t> offsets;
5785 offsets.reserve(n_cells);
5786
5787 // std::uint8_t might be an alias to unsigned char which is then not
5788 // printed as ascii integers
5789 std::vector<unsigned int> cell_types;
5790 cell_types.reserve(n_cells);
5791
5792 unsigned int first_vertex_of_patch = 0;
5793
5794 for (const auto &patch : patches)
5795 {
5796 const auto vtk_cell_id =
5797 extract_vtk_patch_info(patch, flags.write_higher_order_cells);
5798
5799 for (unsigned int i = 0; i < vtk_cell_id[1]; ++i)
5800 {
5801 cell_types.push_back(vtk_cell_id[0]);
5802 first_vertex_of_patch += vtk_cell_id[2];
5803 offsets.push_back(first_vertex_of_patch);
5804 }
5805 }
5806
5807 o << vtu_stringize_array(offsets,
5808 flags.compression_level,
5809 output_precision);
5810 o << '\n';
5811 o << " </DataArray>\n";
5812
5813 o << " <DataArray type=\"UInt8\" Name=\"types\" format=\""
5814 << ascii_or_binary << "\">\n";
5815
5816 if (deal_ii_with_zlib &&
5818 {
5819 std::vector<std::uint8_t> cell_types_uint8_t(cell_types.size());
5820 for (unsigned int i = 0; i < cell_types.size(); ++i)
5821 cell_types_uint8_t[i] = static_cast<std::uint8_t>(cell_types[i]);
5822
5823 o << vtu_stringize_array(cell_types_uint8_t,
5824 flags.compression_level,
5825 output_precision);
5826 }
5827 else
5828 {
5829 o << vtu_stringize_array(cell_types,
5830 flags.compression_level,
5831 output_precision);
5832 }
5833
5834 o << '\n';
5835 o << " </DataArray>\n";
5836 o << " </Cells>\n";
5837
5838 return o.str();
5839 };
5840
5841
5842 //-------------------------------------
5843 // data output.
5844
5845 const auto stringize_nonscalar_data_range =
5846 [&flags,
5847 &data_names,
5848 ascii_or_binary,
5849 n_data_sets,
5850 n_nodes,
5851 output_precision = out.precision()](const Table<2, float> &data_vectors,
5852 const auto &range) {
5853 std::ostringstream o;
5854
5855 const auto first_component = std::get<0>(range);
5856 const auto last_component = std::get<1>(range);
5857 const auto &name = std::get<2>(range);
5858 const bool is_tensor =
5859 (std::get<3>(range) ==
5861 const unsigned int n_components = (is_tensor ? 9 : 3);
5862 AssertThrow(last_component >= first_component,
5863 ExcLowerRange(last_component, first_component));
5864 AssertThrow(last_component < n_data_sets,
5865 ExcIndexRange(last_component, 0, n_data_sets));
5866 if (is_tensor)
5867 {
5868 AssertThrow((last_component + 1 - first_component <= 9),
5869 ExcMessage(
5870 "Can't declare a tensor with more than 9 components "
5871 "in VTK/VTU format."));
5872 }
5873 else
5874 {
5875 AssertThrow((last_component + 1 - first_component <= 3),
5876 ExcMessage(
5877 "Can't declare a vector with more than 3 components "
5878 "in VTK/VTU format."));
5879 }
5880
5881 // write the header. concatenate all the component names with double
5882 // underscores unless a vector name has been specified
5883 o << " <DataArray type=\"Float32\" Name=\"";
5884
5885 if (!name.empty())
5886 o << name;
5887 else
5888 {
5889 for (unsigned int i = first_component; i < last_component; ++i)
5890 o << data_names[i] << "__";
5891 o << data_names[last_component];
5892 }
5893
5894 o << "\" NumberOfComponents=\"" << n_components << "\" format=\""
5895 << ascii_or_binary << "\"";
5896 // If present, also list the physical units for this quantity. Look
5897 // this up for either the name of the whole vector/tensor, or if that
5898 // isn't listed, via its first component.
5899 if (!name.empty())
5900 {
5901 if (flags.physical_units.find(name) != flags.physical_units.end())
5902 o << " units=\"" << flags.physical_units.at(name) << "\"";
5903 }
5904 else
5905 {
5906 if (flags.physical_units.find(data_names[first_component]) !=
5907 flags.physical_units.end())
5908 o << " units=\""
5909 << flags.physical_units.at(data_names[first_component]) << "\"";
5910 }
5911 o << ">\n";
5912
5913 // now write data. pad all vectors to have three components
5914 std::vector<float> data;
5915 data.reserve(n_nodes * n_components);
5916
5917 for (unsigned int n = 0; n < n_nodes; ++n)
5918 {
5919 if (!is_tensor)
5920 {
5921 switch (last_component - first_component)
5922 {
5923 case 0:
5924 data.push_back(data_vectors(first_component, n));
5925 data.push_back(0);
5926 data.push_back(0);
5927 break;
5928
5929 case 1:
5930 data.push_back(data_vectors(first_component, n));
5931 data.push_back(data_vectors(first_component + 1, n));
5932 data.push_back(0);
5933 break;
5934
5935 case 2:
5936 data.push_back(data_vectors(first_component, n));
5937 data.push_back(data_vectors(first_component + 1, n));
5938 data.push_back(data_vectors(first_component + 2, n));
5939 break;
5940
5941 default:
5942 // Anything else is not yet implemented
5944 }
5945 }
5946 else
5947 {
5948 Tensor<2, 3> vtk_data;
5949 vtk_data = 0.;
5950
5951 const unsigned int size = last_component - first_component + 1;
5952 if (size == 1)
5953 // 1d, 1 element
5954 {
5955 vtk_data[0][0] = data_vectors(first_component, n);
5956 }
5957 else if (size == 4)
5958 // 2d, 4 elements
5959 {
5960 for (unsigned int c = 0; c < size; ++c)
5961 {
5962 const auto ind =
5964 vtk_data[ind[0]][ind[1]] =
5965 data_vectors(first_component + c, n);
5966 }
5967 }
5968 else if (size == 9)
5969 // 3d 9 elements
5970 {
5971 for (unsigned int c = 0; c < size; ++c)
5972 {
5973 const auto ind =
5975 vtk_data[ind[0]][ind[1]] =
5976 data_vectors(first_component + c, n);
5977 }
5978 }
5979 else
5980 {
5982 }
5983
5984 // now put the tensor into data
5985 // note we pad with zeros because VTK format always wants to
5986 // see a 3x3 tensor, regardless of dimension
5987 for (unsigned int i = 0; i < 3; ++i)
5988 for (unsigned int j = 0; j < 3; ++j)
5989 data.push_back(vtk_data[i][j]);
5990 }
5991 } // loop over nodes
5992
5993 o << vtu_stringize_array(data,
5994 flags.compression_level,
5995 output_precision);
5996 o << '\n';
5997 o << " </DataArray>\n";
5998
5999 return o.str();
6000 };
6001
6002 const auto stringize_scalar_data_set =
6003 [&flags,
6004 &data_names,
6005 ascii_or_binary,
6006 output_precision = out.precision()](const Table<2, float> &data_vectors,
6007 const unsigned int data_set) {
6008 std::ostringstream o;
6009
6010 o << " <DataArray type=\"Float32\" Name=\"" << data_names[data_set]
6011 << "\" format=\"" << ascii_or_binary << "\"";
6012 // If present, also list the physical units for this quantity.
6013 if (flags.physical_units.find(data_names[data_set]) !=
6014 flags.physical_units.end())
6015 o << " units=\"" << flags.physical_units.at(data_names[data_set])
6016 << "\"";
6017
6018 o << ">\n";
6019
6020 const std::vector<float> data(data_vectors[data_set].begin(),
6021 data_vectors[data_set].end());
6022 o << vtu_stringize_array(data,
6023 flags.compression_level,
6024 output_precision);
6025 o << '\n';
6026 o << " </DataArray>\n";
6027
6028 return o.str();
6029 };
6030
6031
6032 // For the format we write here, we need to write all node values relating
6033 // to one variable at a time. We could in principle do this by looping
6034 // over all patches and extracting the values corresponding to the one
6035 // variable we're dealing with right now, and then start the process over
6036 // for the next variable with another loop over all patches.
6037 //
6038 // An easier way is to create a global table that for each variable
6039 // lists all values. This copying of data vectors can be done in the
6040 // background while we're already working on vertices and cells,
6041 // so do this on a separate task and when wanting to write out the
6042 // data, we wait for that task to finish.
6044 create_global_data_table_task = Threads::new_task([&patches]() {
6045 return create_global_data_table<dim, spacedim, float>(patches);
6046 });
6047
6048 // -----------------------------
6049 // Now finally get around to actually doing anything. Let's start with
6050 // running the first three tasks generating the vertex and cell information:
6052 mesh_tasks += Threads::new_task(stringize_vertex_information);
6053 mesh_tasks += Threads::new_task(stringize_cell_to_vertex_information);
6054 mesh_tasks += Threads::new_task(stringize_cell_offset_and_type_information);
6055
6056 // For what follows, we have to have the reordered data available. So wait
6057 // for that task to conclude and get the resulting data table:
6058 const Table<2, float> data_vectors =
6059 std::move(*create_global_data_table_task.return_value());
6060
6061 // Then create the strings for the actual values of the solution vectors,
6062 // again on separate tasks:
6064 // When writing, first write out all vector and tensor data
6065 std::vector<bool> data_set_handled(n_data_sets, false);
6066 for (const auto &range : nonscalar_data_ranges)
6067 {
6068 // Mark these components as already handled:
6069 const auto first_component = std::get<0>(range);
6070 const auto last_component = std::get<1>(range);
6071 for (unsigned int i = first_component; i <= last_component; ++i)
6072 data_set_handled[i] = true;
6073
6074 data_tasks += Threads::new_task([&, range]() {
6075 return stringize_nonscalar_data_range(data_vectors, range);
6076 });
6077 }
6078
6079 // Now do the left over scalar data sets
6080 for (unsigned int data_set = 0; data_set < n_data_sets; ++data_set)
6081 if (data_set_handled[data_set] == false)
6082 {
6083 data_tasks += Threads::new_task([&, data_set]() {
6084 return stringize_scalar_data_set(data_vectors, data_set);
6085 });
6086 }
6087
6088 // Alright, all tasks are now running. Wait for their conclusion and output
6089 // all of the data they have produced:
6090 out << "<Piece NumberOfPoints=\"" << n_nodes << "\" NumberOfCells=\""
6091 << n_cells << "\" >\n";
6092 for (const auto &s : mesh_tasks.return_values())
6093 out << s;
6094 out << " <PointData Scalars=\"scalars\">\n";
6095 for (const auto &s : data_tasks.return_values())
6096 out << s;
6097 out << " </PointData>\n";
6098 out << " </Piece>\n";
6099
6100 // make sure everything now gets to disk
6101 out.flush();
6102
6103 // assert the stream is still ok
6104 AssertThrow(out.fail() == false, ExcIO());
6105 }
6106
6107
6108
6109 void
6111 std::ostream &out,
6112 const std::vector<std::string> &piece_names,
6113 const std::vector<std::string> &data_names,
6114 const std::vector<
6115 std::tuple<unsigned int,
6116 unsigned int,
6117 std::string,
6119 &nonscalar_data_ranges,
6120 const VtkFlags &flags)
6121 {
6122 AssertThrow(out.fail() == false, ExcIO());
6123
6124 // If the user provided physical units, make sure that they don't contain
6125 // quote characters as this would make the VTU file invalid XML and
6126 // probably lead to all sorts of difficult error messages. Other than that,
6127 // trust the user that whatever they provide makes sense somehow.
6128 for (const auto &unit : flags.physical_units)
6129 {
6130 (void)unit;
6131 Assert(
6132 unit.second.find('\"') == std::string::npos,
6133 ExcMessage(
6134 "A physical unit you provided, <" + unit.second +
6135 ">, contained a quotation mark character. This is not allowed."));
6136 }
6137
6138 const unsigned int n_data_sets = data_names.size();
6139
6140 out << "<?xml version=\"1.0\"?>\n";
6141
6142 out << "<!--\n";
6143 out << "#This file was generated by the deal.II library"
6144 << " on " << Utilities::System::get_date() << " at "
6145 << Utilities::System::get_time() << "\n-->\n";
6146
6147 out
6148 << "<VTKFile type=\"PUnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\">\n";
6149 out << " <PUnstructuredGrid GhostLevel=\"0\">\n";
6150 out << " <PPointData Scalars=\"scalars\">\n";
6151
6152 // We need to output in the same order as the write_vtu function does:
6153 std::vector<bool> data_set_written(n_data_sets, false);
6154 for (const auto &nonscalar_data_range : nonscalar_data_ranges)
6155 {
6156 const auto first_component = std::get<0>(nonscalar_data_range);
6157 const auto last_component = std::get<1>(nonscalar_data_range);
6158 const bool is_tensor =
6159 (std::get<3>(nonscalar_data_range) ==
6161 const unsigned int n_components = (is_tensor ? 9 : 3);
6162 AssertThrow(last_component >= first_component,
6163 ExcLowerRange(last_component, first_component));
6164 AssertThrow(last_component < n_data_sets,
6165 ExcIndexRange(last_component, 0, n_data_sets));
6166 if (is_tensor)
6167 {
6168 AssertThrow((last_component + 1 - first_component <= 9),
6169 ExcMessage(
6170 "Can't declare a tensor with more than 9 components "
6171 "in VTK"));
6172 }
6173 else
6174 {
6175 Assert((last_component + 1 - first_component <= 3),
6176 ExcMessage(
6177 "Can't declare a vector with more than 3 components "
6178 "in VTK"));
6179 }
6180
6181 // mark these components as already written:
6182 for (unsigned int i = std::get<0>(nonscalar_data_range);
6183 i <= std::get<1>(nonscalar_data_range);
6184 ++i)
6185 data_set_written[i] = true;
6186
6187 // write the header. concatenate all the component names with double
6188 // underscores unless a vector name has been specified
6189 out << " <PDataArray type=\"Float32\" Name=\"";
6190
6191 const std::string &name = std::get<2>(nonscalar_data_range);
6192 if (!name.empty())
6193 out << name;
6194 else
6195 {
6196 for (unsigned int i = std::get<0>(nonscalar_data_range);
6197 i < std::get<1>(nonscalar_data_range);
6198 ++i)
6199 out << data_names[i] << "__";
6200 out << data_names[std::get<1>(nonscalar_data_range)];
6201 }
6202
6203 out << "\" NumberOfComponents=\"" << n_components
6204 << "\" format=\"ascii\"";
6205 // If present, also list the physical units for this quantity. Look this
6206 // up for either the name of the whole vector/tensor, or if that isn't
6207 // listed, via its first component.
6208 if (!name.empty())
6209 {
6210 if (flags.physical_units.find(name) != flags.physical_units.end())
6211 out << " units=\"" << flags.physical_units.at(name) << "\"";
6212 }
6213 else
6214 {
6215 if (flags.physical_units.find(
6216 data_names[std::get<1>(nonscalar_data_range)]) !=
6217 flags.physical_units.end())
6218 out << " units=\""
6219 << flags.physical_units.at(
6220 data_names[std::get<1>(nonscalar_data_range)])
6221 << "\"";
6222 }
6223
6224 out << "/>\n";
6225 }
6226
6227 // Now for the scalar fields
6228 for (unsigned int data_set = 0; data_set < n_data_sets; ++data_set)
6229 if (data_set_written[data_set] == false)
6230 {
6231 out << " <PDataArray type=\"Float32\" Name=\""
6232 << data_names[data_set] << "\" format=\"ascii\"";
6233
6234 if (flags.physical_units.find(data_names[data_set]) !=
6235 flags.physical_units.end())
6236 out << " units=\"" << flags.physical_units.at(data_names[data_set])
6237 << "\"";
6238
6239 out << "/>\n";
6240 }
6241
6242 out << " </PPointData>\n";
6243
6244 out << " <PPoints>\n";
6245 out << " <PDataArray type=\"Float32\" NumberOfComponents=\"3\"/>\n";
6246 out << " </PPoints>\n";
6247
6248 for (const auto &piece_name : piece_names)
6249 out << " <Piece Source=\"" << piece_name << "\"/>\n";
6250
6251 out << " </PUnstructuredGrid>\n";
6252 out << "</VTKFile>\n";
6253
6254 out.flush();
6255
6256 // assert the stream is still ok
6257 AssertThrow(out.fail() == false, ExcIO());
6258 }
6259
6260
6261
6262 void
6264 std::ostream &out,
6265 const std::vector<std::pair<double, std::string>> &times_and_names)
6266 {
6267 AssertThrow(out.fail() == false, ExcIO());
6268
6269 out << "<?xml version=\"1.0\"?>\n";
6270
6271 out << "<!--\n";
6272 out << "#This file was generated by the deal.II library"
6273 << " on " << Utilities::System::get_date() << " at "
6274 << Utilities::System::get_time() << "\n-->\n";
6275
6276 out
6277 << "<VTKFile type=\"Collection\" version=\"0.1\" ByteOrder=\"LittleEndian\">\n";
6278 out << " <Collection>\n";
6279
6280 std::streamsize ss = out.precision();
6281 out.precision(12);
6282
6283 for (const auto &time_and_name : times_and_names)
6284 out << " <DataSet timestep=\"" << time_and_name.first
6285 << "\" group=\"\" part=\"0\" file=\"" << time_and_name.second
6286 << "\"/>\n";
6287
6288 out << " </Collection>\n";
6289 out << "</VTKFile>\n";
6290
6291 out.flush();
6292 out.precision(ss);
6293
6294 AssertThrow(out.fail() == false, ExcIO());
6295 }
6296
6297
6298
6299 void
6300 write_visit_record(std::ostream &out,
6301 const std::vector<std::string> &piece_names)
6302 {
6303 out << "!NBLOCKS " << piece_names.size() << '\n';
6304 for (const auto &piece_name : piece_names)
6305 out << piece_name << '\n';
6306
6307 out << std::flush;
6308 }
6309
6310
6311
6312 void
6313 write_visit_record(std::ostream &out,
6314 const std::vector<std::vector<std::string>> &piece_names)
6315 {
6316 AssertThrow(out.fail() == false, ExcIO());
6317
6318 if (piece_names.empty())
6319 return;
6320
6321 const double nblocks = piece_names[0].size();
6322 Assert(nblocks > 0,
6323 ExcMessage("piece_names should be a vector of nonempty vectors."));
6324
6325 out << "!NBLOCKS " << nblocks << '\n';
6326 for (const auto &domain : piece_names)
6327 {
6328 Assert(domain.size() == nblocks,
6329 ExcMessage(
6330 "piece_names should be a vector of equal sized vectors."));
6331 for (const auto &subdomain : domain)
6332 out << subdomain << '\n';
6333 }
6334
6335 out << std::flush;
6336 }
6337
6338
6339
6340 void
6342 std::ostream &out,
6343 const std::vector<std::pair<double, std::vector<std::string>>>
6344 &times_and_piece_names)
6345 {
6346 AssertThrow(out.fail() == false, ExcIO());
6347
6348 if (times_and_piece_names.empty())
6349 return;
6350
6351 const double nblocks = times_and_piece_names[0].second.size();
6352 Assert(
6353 nblocks > 0,
6354 ExcMessage(
6355 "time_and_piece_names should contain nonempty vectors of filenames for every timestep."));
6356
6357 for (const auto &domain : times_and_piece_names)
6358 out << "!TIME " << domain.first << '\n';
6359
6360 out << "!NBLOCKS " << nblocks << '\n';
6361 for (const auto &domain : times_and_piece_names)
6362 {
6363 Assert(domain.second.size() == nblocks,
6364 ExcMessage(
6365 "piece_names should be a vector of equal sized vectors."));
6366 for (const auto &subdomain : domain.second)
6367 out << subdomain << '\n';
6368 }
6369
6370 out << std::flush;
6371 }
6372
6373
6374
6375 template <int dim, int spacedim>
6376 void
6378 const std::vector<Patch<dim, spacedim>> &,
6379 const std::vector<std::string> &,
6380 const std::vector<
6381 std::tuple<unsigned int,
6382 unsigned int,
6383 std::string,
6385 const SvgFlags &,
6386 std::ostream &)
6387 {
6389 }
6390
6391 template <int spacedim>
6392 void
6394 const std::vector<Patch<2, spacedim>> &patches,
6395 const std::vector<std::string> & /*data_names*/,
6396 const std::vector<
6397 std::tuple<unsigned int,
6398 unsigned int,
6399 std::string,
6401 & /*nonscalar_data_ranges*/,
6402 const SvgFlags &flags,
6403 std::ostream &out)
6404 {
6405 const unsigned int height = flags.height;
6406 unsigned int width = flags.width;
6407
6408 // margin around the plotted area
6409 unsigned int margin_in_percent = 0;
6410 if (flags.margin)
6411 margin_in_percent = 5;
6412
6413
6414 // determine the bounding box in the model space
6415 double x_dimension, y_dimension, z_dimension;
6416
6417 const auto &first_patch = patches[0];
6418
6419 unsigned int n_subdivisions = first_patch.n_subdivisions;
6420 unsigned int n = n_subdivisions + 1;
6421 const unsigned int d1 = 1;
6422 const unsigned int d2 = n;
6423
6424 Point<spacedim> projected_point;
6425 std::array<Point<spacedim>, 4> projected_points;
6426
6427 Point<2> projection_decomposition;
6428 std::array<Point<2>, 4> projection_decompositions;
6429
6430 projected_point =
6431 get_equispaced_location(first_patch, {0, 0}, n_subdivisions);
6432
6433 if (first_patch.data.n_rows() != 0)
6434 {
6435 AssertIndexRange(flags.height_vector, first_patch.data.n_rows());
6436 }
6437
6438 double x_min = projected_point[0];
6439 double x_max = x_min;
6440 double y_min = projected_point[1];
6441 double y_max = y_min;
6442 double z_min = first_patch.data.n_rows() != 0 ?
6443 first_patch.data(flags.height_vector, 0) :
6444 0;
6445 double z_max = z_min;
6446
6447 // iterate over the patches
6448 for (const auto &patch : patches)
6449 {
6451 n = n_subdivisions + 1;
6452
6453 for (unsigned int i2 = 0; i2 < n_subdivisions; ++i2)
6454 {
6455 for (unsigned int i1 = 0; i1 < n_subdivisions; ++i1)
6456 {
6457 projected_points[0] =
6458 get_equispaced_location(patch, {i1, i2}, n_subdivisions);
6459 projected_points[1] =
6460 get_equispaced_location(patch, {i1 + 1, i2}, n_subdivisions);
6461 projected_points[2] =
6462 get_equispaced_location(patch, {i1, i2 + 1}, n_subdivisions);
6463 projected_points[3] = get_equispaced_location(patch,
6464 {i1 + 1, i2 + 1},
6466
6467 x_min = std::min(x_min, projected_points[0][0]);
6468 x_min = std::min(x_min, projected_points[1][0]);
6469 x_min = std::min(x_min, projected_points[2][0]);
6470 x_min = std::min(x_min, projected_points[3][0]);
6471
6472 x_max = std::max(x_max, projected_points[0][0]);
6473 x_max = std::max(x_max, projected_points[1][0]);
6474 x_max = std::max(x_max, projected_points[2][0]);
6475 x_max = std::max(x_max, projected_points[3][0]);
6476
6477 y_min = std::min(y_min, projected_points[0][1]);
6478 y_min = std::min(y_min, projected_points[1][1]);
6479 y_min = std::min(y_min, projected_points[2][1]);
6480 y_min = std::min(y_min, projected_points[3][1]);
6481
6482 y_max = std::max(y_max, projected_points[0][1]);
6483 y_max = std::max(y_max, projected_points[1][1]);
6484 y_max = std::max(y_max, projected_points[2][1]);
6485 y_max = std::max(y_max, projected_points[3][1]);
6486
6487 Assert((flags.height_vector < patch.data.n_rows()) ||
6488 patch.data.n_rows() == 0,
6490 0,
6491 patch.data.n_rows()));
6492
6493 z_min = std::min<double>(z_min,
6494 patch.data(flags.height_vector,
6495 i1 * d1 + i2 * d2));
6496 z_min = std::min<double>(z_min,
6497 patch.data(flags.height_vector,
6498 (i1 + 1) * d1 + i2 * d2));
6499 z_min = std::min<double>(z_min,
6500 patch.data(flags.height_vector,
6501 i1 * d1 + (i2 + 1) * d2));
6502 z_min =
6503 std::min<double>(z_min,
6504 patch.data(flags.height_vector,
6505 (i1 + 1) * d1 + (i2 + 1) * d2));
6506
6507 z_max = std::max<double>(z_max,
6508 patch.data(flags.height_vector,
6509 i1 * d1 + i2 * d2));
6510 z_max = std::max<double>(z_max,
6511 patch.data(flags.height_vector,
6512 (i1 + 1) * d1 + i2 * d2));
6513 z_max = std::max<double>(z_max,
6514 patch.data(flags.height_vector,
6515 i1 * d1 + (i2 + 1) * d2));
6516 z_max =
6517 std::max<double>(z_max,
6518 patch.data(flags.height_vector,
6519 (i1 + 1) * d1 + (i2 + 1) * d2));
6520 }
6521 }
6522 }
6523
6524 x_dimension = x_max - x_min;
6525 y_dimension = y_max - y_min;
6526 z_dimension = z_max - z_min;
6527
6528
6529 // set initial camera position
6530 Point<3> camera_position;
6531 Point<3> camera_direction;
6532 Point<3> camera_horizontal;
6533 float camera_focus = 0;
6534
6535 // translate camera from the origin to the initial position
6536 camera_position[0] = 0.;
6537 camera_position[1] = 0.;
6538 camera_position[2] = z_min + 2. * z_dimension;
6539
6540 camera_direction[0] = 0.;
6541 camera_direction[1] = 0.;
6542 camera_direction[2] = -1.;
6543
6544 camera_horizontal[0] = 1.;
6545 camera_horizontal[1] = 0.;
6546 camera_horizontal[2] = 0.;
6547
6548 camera_focus = .5 * z_dimension;
6549
6550 Point<3> camera_position_temp;
6551 Point<3> camera_direction_temp;
6552 Point<3> camera_horizontal_temp;
6553
6554 const float angle_factor = 3.14159265f / 180.f;
6555
6556 // (I) rotate the camera to the chosen polar angle
6557 camera_position_temp[1] =
6558 std::cos(angle_factor * flags.polar_angle) * camera_position[1] -
6559 std::sin(angle_factor * flags.polar_angle) * camera_position[2];
6560 camera_position_temp[2] =
6561 std::sin(angle_factor * flags.polar_angle) * camera_position[1] +
6562 std::cos(angle_factor * flags.polar_angle) * camera_position[2];
6563
6564 camera_direction_temp[1] =
6565 std::cos(angle_factor * flags.polar_angle) * camera_direction[1] -
6566 std::sin(angle_factor * flags.polar_angle) * camera_direction[2];
6567 camera_direction_temp[2] =
6568 std::sin(angle_factor * flags.polar_angle) * camera_direction[1] +
6569 std::cos(angle_factor * flags.polar_angle) * camera_direction[2];
6570
6571 camera_horizontal_temp[1] =
6572 std::cos(angle_factor * flags.polar_angle) * camera_horizontal[1] -
6573 std::sin(angle_factor * flags.polar_angle) * camera_horizontal[2];
6574 camera_horizontal_temp[2] =
6575 std::sin(angle_factor * flags.polar_angle) * camera_horizontal[1] +
6576 std::cos(angle_factor * flags.polar_angle) * camera_horizontal[2];
6577
6578 camera_position[1] = camera_position_temp[1];
6579 camera_position[2] = camera_position_temp[2];
6580
6581 camera_direction[1] = camera_direction_temp[1];
6582 camera_direction[2] = camera_direction_temp[2];
6583
6584 camera_horizontal[1] = camera_horizontal_temp[1];
6585 camera_horizontal[2] = camera_horizontal_temp[2];
6586
6587 // (II) rotate the camera to the chosen azimuth angle
6588 camera_position_temp[0] =
6589 std::cos(angle_factor * flags.azimuth_angle) * camera_position[0] -
6590 std::sin(angle_factor * flags.azimuth_angle) * camera_position[1];
6591 camera_position_temp[1] =
6592 std::sin(angle_factor * flags.azimuth_angle) * camera_position[0] +
6593 std::cos(angle_factor * flags.azimuth_angle) * camera_position[1];
6594
6595 camera_direction_temp[0] =
6596 std::cos(angle_factor * flags.azimuth_angle) * camera_direction[0] -
6597 std::sin(angle_factor * flags.azimuth_angle) * camera_direction[1];
6598 camera_direction_temp[1] =
6599 std::sin(angle_factor * flags.azimuth_angle) * camera_direction[0] +
6600 std::cos(angle_factor * flags.azimuth_angle) * camera_direction[1];
6601
6602 camera_horizontal_temp[0] =
6603 std::cos(angle_factor * flags.azimuth_angle) * camera_horizontal[0] -
6604 std::sin(angle_factor * flags.azimuth_angle) * camera_horizontal[1];
6605 camera_horizontal_temp[1] =
6606 std::sin(angle_factor * flags.azimuth_angle) * camera_horizontal[0] +
6607 std::cos(angle_factor * flags.azimuth_angle) * camera_horizontal[1];
6608
6609 camera_position[0] = camera_position_temp[0];
6610 camera_position[1] = camera_position_temp[1];
6611
6612 camera_direction[0] = camera_direction_temp[0];
6613 camera_direction[1] = camera_direction_temp[1];
6614
6615 camera_horizontal[0] = camera_horizontal_temp[0];
6616 camera_horizontal[1] = camera_horizontal_temp[1];
6617
6618 // (III) translate the camera
6619 camera_position[0] = x_min + .5 * x_dimension;
6620 camera_position[1] = y_min + .5 * y_dimension;
6621
6622 camera_position[0] += (z_min + 2. * z_dimension) *
6623 std::sin(angle_factor * flags.polar_angle) *
6624 std::sin(angle_factor * flags.azimuth_angle);
6625 camera_position[1] -= (z_min + 2. * z_dimension) *
6626 std::sin(angle_factor * flags.polar_angle) *
6627 std::cos(angle_factor * flags.azimuth_angle);
6628
6629
6630 // determine the bounding box on the projection plane
6631 double x_min_perspective, y_min_perspective;
6632 double x_max_perspective, y_max_perspective;
6633 double x_dimension_perspective, y_dimension_perspective;
6634
6635 n_subdivisions = first_patch.n_subdivisions;
6636 n = n_subdivisions + 1;
6637
6638 Point<3> point;
6639
6640 projected_point =
6641 get_equispaced_location(first_patch, {0, 0}, n_subdivisions);
6642
6643 if (first_patch.data.n_rows() != 0)
6644 {
6645 AssertIndexRange(flags.height_vector, first_patch.data.n_rows());
6646 }
6647
6648 point[0] = projected_point[0];
6649 point[1] = projected_point[1];
6650 point[2] = first_patch.data.n_rows() != 0 ?
6651 first_patch.data(flags.height_vector, 0) :
6652 0;
6653
6654 projection_decomposition = svg_project_point(point,
6655 camera_position,
6656 camera_direction,
6657 camera_horizontal,
6658 camera_focus);
6659
6660 x_min_perspective = projection_decomposition[0];
6661 x_max_perspective = projection_decomposition[0];
6662 y_min_perspective = projection_decomposition[1];
6663 y_max_perspective = projection_decomposition[1];
6664
6665 // iterate over the patches
6666 for (const auto &patch : patches)
6667 {
6669 for (unsigned int i2 = 0; i2 < n_subdivisions; ++i2)
6670 {
6671 for (unsigned int i1 = 0; i1 < n_subdivisions; ++i1)
6672 {
6673 const std::array<Point<spacedim>, 4> projected_vertices{
6674 {get_equispaced_location(patch, {i1, i2}, n_subdivisions),
6675 get_equispaced_location(patch, {i1 + 1, i2}, n_subdivisions),
6676 get_equispaced_location(patch, {i1, i2 + 1}, n_subdivisions),
6677 get_equispaced_location(patch,
6678 {i1 + 1, i2 + 1},
6679 n_subdivisions)}};
6680
6681 Assert((flags.height_vector < patch.data.n_rows()) ||
6682 patch.data.n_rows() == 0,
6684 0,
6685 patch.data.n_rows()));
6686
6687 const std::array<Point<3>, 4> vertices = {
6688 {Point<3>{projected_vertices[0][0],
6689 projected_vertices[0][1],
6690 patch.data.n_rows() != 0 ?
6691 patch.data(0, i1 * d1 + i2 * d2) :
6692 0},
6693 Point<3>{projected_vertices[1][0],
6694 projected_vertices[1][1],
6695 patch.data.n_rows() != 0 ?
6696 patch.data(0, (i1 + 1) * d1 + i2 * d2) :
6697 0},
6698 Point<3>{projected_vertices[2][0],
6699 projected_vertices[2][1],
6700 patch.data.n_rows() != 0 ?
6701 patch.data(0, i1 * d1 + (i2 + 1) * d2) :
6702 0},
6703 Point<3>{projected_vertices[3][0],
6704 projected_vertices[3][1],
6705 patch.data.n_rows() != 0 ?
6706 patch.data(0, (i1 + 1) * d1 + (i2 + 1) * d2) :
6707 0}}};
6708
6709 projection_decompositions = {
6710 {svg_project_point(vertices[0],
6711 camera_position,
6712 camera_direction,
6713 camera_horizontal,
6714 camera_focus),
6715 svg_project_point(vertices[1],
6716 camera_position,
6717 camera_direction,
6718 camera_horizontal,
6719 camera_focus),
6720 svg_project_point(vertices[2],
6721 camera_position,
6722 camera_direction,
6723 camera_horizontal,
6724 camera_focus),
6725 svg_project_point(vertices[3],
6726 camera_position,
6727 camera_direction,
6728 camera_horizontal,
6729 camera_focus)}};
6730
6731 x_min_perspective =
6732 std::min(x_min_perspective,
6733 static_cast<double>(
6734 projection_decompositions[0][0]));
6735 x_min_perspective =
6736 std::min(x_min_perspective,
6737 static_cast<double>(
6738 projection_decompositions[1][0]));
6739 x_min_perspective =
6740 std::min(x_min_perspective,
6741 static_cast<double>(
6742 projection_decompositions[2][0]));
6743 x_min_perspective =
6744 std::min(x_min_perspective,
6745 static_cast<double>(
6746 projection_decompositions[3][0]));
6747
6748 x_max_perspective =
6749 std::max(x_max_perspective,
6750 static_cast<double>(
6751 projection_decompositions[0][0]));
6752 x_max_perspective =
6753 std::max(x_max_perspective,
6754 static_cast<double>(
6755 projection_decompositions[1][0]));
6756 x_max_perspective =
6757 std::max(x_max_perspective,
6758 static_cast<double>(
6759 projection_decompositions[2][0]));
6760 x_max_perspective =
6761 std::max(x_max_perspective,
6762 static_cast<double>(
6763 projection_decompositions[3][0]));
6764
6765 y_min_perspective =
6766 std::min(y_min_perspective,
6767 static_cast<double>(
6768 projection_decompositions[0][1]));
6769 y_min_perspective =
6770 std::min(y_min_perspective,
6771 static_cast<double>(
6772 projection_decompositions[1][1]));
6773 y_min_perspective =
6774 std::min(y_min_perspective,
6775 static_cast<double>(
6776 projection_decompositions[2][1]));
6777 y_min_perspective =
6778 std::min(y_min_perspective,
6779 static_cast<double>(
6780 projection_decompositions[3][1]));
6781
6782 y_max_perspective =
6783 std::max(y_max_perspective,
6784 static_cast<double>(
6785 projection_decompositions[0][1]));
6786 y_max_perspective =
6787 std::max(y_max_perspective,
6788 static_cast<double>(
6789 projection_decompositions[1][1]));
6790 y_max_perspective =
6791 std::max(y_max_perspective,
6792 static_cast<double>(
6793 projection_decompositions[2][1]));
6794 y_max_perspective =
6795 std::max(y_max_perspective,
6796 static_cast<double>(
6797 projection_decompositions[3][1]));
6798 }
6799 }
6800 }
6801
6802 x_dimension_perspective = x_max_perspective - x_min_perspective;
6803 y_dimension_perspective = y_max_perspective - y_min_perspective;
6804
6805 std::multiset<SvgCell> cells;
6806
6807 // iterate over the patches
6808 for (const auto &patch : patches)
6809 {
6811
6812 for (unsigned int i2 = 0; i2 < n_subdivisions; ++i2)
6813 {
6814 for (unsigned int i1 = 0; i1 < n_subdivisions; ++i1)
6815 {
6816 const std::array<Point<spacedim>, 4> projected_vertices = {
6817 {get_equispaced_location(patch, {i1, i2}, n_subdivisions),
6818 get_equispaced_location(patch, {i1 + 1, i2}, n_subdivisions),
6819 get_equispaced_location(patch, {i1, i2 + 1}, n_subdivisions),
6820 get_equispaced_location(patch,
6821 {i1 + 1, i2 + 1},
6822 n_subdivisions)}};
6823
6824 Assert((flags.height_vector < patch.data.n_rows()) ||
6825 patch.data.n_rows() == 0,
6827 0,
6828 patch.data.n_rows()));
6829
6830 SvgCell cell;
6831
6832 cell.vertices[0][0] = projected_vertices[0][0];
6833 cell.vertices[0][1] = projected_vertices[0][1];
6834 cell.vertices[0][2] = patch.data.n_rows() != 0 ?
6835 patch.data(0, i1 * d1 + i2 * d2) :
6836 0;
6837
6838 cell.vertices[1][0] = projected_vertices[1][0];
6839 cell.vertices[1][1] = projected_vertices[1][1];
6840 cell.vertices[1][2] = patch.data.n_rows() != 0 ?
6841 patch.data(0, (i1 + 1) * d1 + i2 * d2) :
6842 0;
6843
6844 cell.vertices[2][0] = projected_vertices[2][0];
6845 cell.vertices[2][1] = projected_vertices[2][1];
6846 cell.vertices[2][2] = patch.data.n_rows() != 0 ?
6847 patch.data(0, i1 * d1 + (i2 + 1) * d2) :
6848 0;
6849
6850 cell.vertices[3][0] = projected_vertices[3][0];
6851 cell.vertices[3][1] = projected_vertices[3][1];
6852 cell.vertices[3][2] =
6853 patch.data.n_rows() != 0 ?
6854 patch.data(0, (i1 + 1) * d1 + (i2 + 1) * d2) :
6855 0;
6856
6857 cell.projected_vertices[0] =
6858 svg_project_point(cell.vertices[0],
6859 camera_position,
6860 camera_direction,
6861 camera_horizontal,
6862 camera_focus);
6863 cell.projected_vertices[1] =
6864 svg_project_point(cell.vertices[1],
6865 camera_position,
6866 camera_direction,
6867 camera_horizontal,
6868 camera_focus);
6869 cell.projected_vertices[2] =
6870 svg_project_point(cell.vertices[2],
6871 camera_position,
6872 camera_direction,
6873 camera_horizontal,
6874 camera_focus);
6875 cell.projected_vertices[3] =
6876 svg_project_point(cell.vertices[3],
6877 camera_position,
6878 camera_direction,
6879 camera_horizontal,
6880 camera_focus);
6881
6882 cell.center = .25 * (cell.vertices[0] + cell.vertices[1] +
6883 cell.vertices[2] + cell.vertices[3]);
6884 cell.projected_center = svg_project_point(cell.center,
6885 camera_position,
6886 camera_direction,
6887 camera_horizontal,
6888 camera_focus);
6889
6890 cell.depth = cell.center.distance(camera_position);
6891
6892 cells.insert(cell);
6893 }
6894 }
6895 }
6896
6897
6898 // write the svg file
6899 if (width == 0)
6900 width = static_cast<unsigned int>(
6901 .5 + height * (x_dimension_perspective / y_dimension_perspective));
6902 unsigned int additional_width = 0;
6903
6904 if (flags.draw_colorbar)
6905 additional_width = static_cast<unsigned int>(
6906 .5 + height * .3); // additional width for colorbar
6907
6908 // basic svg header and background rectangle
6909 out << "<svg width=\"" << width + additional_width << "\" height=\""
6910 << height << "\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">"
6911 << '\n'
6912 << " <rect width=\"" << width + additional_width << "\" height=\""
6913 << height << "\" style=\"fill:white\"/>" << '\n'
6914 << '\n';
6915
6916 unsigned int triangle_counter = 0;
6917
6918 // write the cells in the correct order
6919 for (const auto &cell : cells)
6920 {
6921 Point<3> points3d_triangle[3];
6922
6923 for (unsigned int triangle_index = 0; triangle_index < 4;
6924 triangle_index++)
6925 {
6926 switch (triangle_index)
6927 {
6928 case 0:
6929 points3d_triangle[0] = cell.vertices[0],
6930 points3d_triangle[1] = cell.vertices[1],
6931 points3d_triangle[2] = cell.center;
6932 break;
6933 case 1:
6934 points3d_triangle[0] = cell.vertices[1],
6935 points3d_triangle[1] = cell.vertices[3],
6936 points3d_triangle[2] = cell.center;
6937 break;
6938 case 2:
6939 points3d_triangle[0] = cell.vertices[3],
6940 points3d_triangle[1] = cell.vertices[2],
6941 points3d_triangle[2] = cell.center;
6942 break;
6943 case 3:
6944 points3d_triangle[0] = cell.vertices[2],
6945 points3d_triangle[1] = cell.vertices[0],
6946 points3d_triangle[2] = cell.center;
6947 break;
6948 default:
6949 break;
6950 }
6951
6952 Point<6> gradient_param =
6953 svg_get_gradient_parameters(points3d_triangle);
6954
6955 double start_h =
6956 .667 - ((gradient_param[4] - z_min) / z_dimension) * .667;
6957 double stop_h =
6958 .667 - ((gradient_param[5] - z_min) / z_dimension) * .667;
6959
6960 unsigned int start_r = 0;
6961 unsigned int start_g = 0;
6962 unsigned int start_b = 0;
6963
6964 unsigned int stop_r = 0;
6965 unsigned int stop_g = 0;
6966 unsigned int stop_b = 0;
6967
6968 unsigned int start_i = static_cast<unsigned int>(start_h * 6.);
6969 unsigned int stop_i = static_cast<unsigned int>(stop_h * 6.);
6970
6971 double start_f = start_h * 6. - start_i;
6972 double start_q = 1. - start_f;
6973
6974 double stop_f = stop_h * 6. - stop_i;
6975 double stop_q = 1. - stop_f;
6976
6977 switch (start_i % 6)
6978 {
6979 case 0:
6980 start_r = 255,
6981 start_g = static_cast<unsigned int>(.5 + 255. * start_f);
6982 break;
6983 case 1:
6984 start_r = static_cast<unsigned int>(.5 + 255. * start_q),
6985 start_g = 255;
6986 break;
6987 case 2:
6988 start_g = 255,
6989 start_b = static_cast<unsigned int>(.5 + 255. * start_f);
6990 break;
6991 case 3:
6992 start_g = static_cast<unsigned int>(.5 + 255. * start_q),
6993 start_b = 255;
6994 break;
6995 case 4:
6996 start_r = static_cast<unsigned int>(.5 + 255. * start_f),
6997 start_b = 255;
6998 break;
6999 case 5:
7000 start_r = 255,
7001 start_b = static_cast<unsigned int>(.5 + 255. * start_q);
7002 break;
7003 default:
7004 break;
7005 }
7006
7007 switch (stop_i % 6)
7008 {
7009 case 0:
7010 stop_r = 255,
7011 stop_g = static_cast<unsigned int>(.5 + 255. * stop_f);
7012 break;
7013 case 1:
7014 stop_r = static_cast<unsigned int>(.5 + 255. * stop_q),
7015 stop_g = 255;
7016 break;
7017 case 2:
7018 stop_g = 255,
7019 stop_b = static_cast<unsigned int>(.5 + 255. * stop_f);
7020 break;
7021 case 3:
7022 stop_g = static_cast<unsigned int>(.5 + 255. * stop_q),
7023 stop_b = 255;
7024 break;
7025 case 4:
7026 stop_r = static_cast<unsigned int>(.5 + 255. * stop_f),
7027 stop_b = 255;
7028 break;
7029 case 5:
7030 stop_r = 255,
7031 stop_b = static_cast<unsigned int>(.5 + 255. * stop_q);
7032 break;
7033 default:
7034 break;
7035 }
7036
7037 Point<3> gradient_start_point_3d, gradient_stop_point_3d;
7038
7039 gradient_start_point_3d[0] = gradient_param[0];
7040 gradient_start_point_3d[1] = gradient_param[1];
7041 gradient_start_point_3d[2] = gradient_param[4];
7042
7043 gradient_stop_point_3d[0] = gradient_param[2];
7044 gradient_stop_point_3d[1] = gradient_param[3];
7045 gradient_stop_point_3d[2] = gradient_param[5];
7046
7047 Point<2> gradient_start_point =
7048 svg_project_point(gradient_start_point_3d,
7049 camera_position,
7050 camera_direction,
7051 camera_horizontal,
7052 camera_focus);
7053 Point<2> gradient_stop_point =
7054 svg_project_point(gradient_stop_point_3d,
7055 camera_position,
7056 camera_direction,
7057 camera_horizontal,
7058 camera_focus);
7059
7060 // define linear gradient
7061 out << " <linearGradient id=\"" << triangle_counter
7062 << "\" gradientUnits=\"userSpaceOnUse\" "
7063 << "x1=\""
7064 << static_cast<unsigned int>(
7065 .5 +
7066 ((gradient_start_point[0] - x_min_perspective) /
7067 x_dimension_perspective) *
7068 (width - (width / 100.) * 2. * margin_in_percent) +
7069 ((width / 100.) * margin_in_percent))
7070 << "\" "
7071 << "y1=\""
7072 << static_cast<unsigned int>(
7073 .5 + height - (height / 100.) * margin_in_percent -
7074 ((gradient_start_point[1] - y_min_perspective) /
7075 y_dimension_perspective) *
7076 (height - (height / 100.) * 2. * margin_in_percent))
7077 << "\" "
7078 << "x2=\""
7079 << static_cast<unsigned int>(
7080 .5 +
7081 ((gradient_stop_point[0] - x_min_perspective) /
7082 x_dimension_perspective) *
7083 (width - (width / 100.) * 2. * margin_in_percent) +
7084 ((width / 100.) * margin_in_percent))
7085 << "\" "
7086 << "y2=\""
7087 << static_cast<unsigned int>(
7088 .5 + height - (height / 100.) * margin_in_percent -
7089 ((gradient_stop_point[1] - y_min_perspective) /
7090 y_dimension_perspective) *
7091 (height - (height / 100.) * 2. * margin_in_percent))
7092 << "\""
7093 << ">" << '\n'
7094 << " <stop offset=\"0\" style=\"stop-color:rgb(" << start_r
7095 << "," << start_g << "," << start_b << ")\"/>" << '\n'
7096 << " <stop offset=\"1\" style=\"stop-color:rgb(" << stop_r
7097 << "," << stop_g << "," << stop_b << ")\"/>" << '\n'
7098 << " </linearGradient>" << '\n';
7099
7100 // draw current triangle
7101 double x1 = 0, y1 = 0, x2 = 0, y2 = 0;
7102 double x3 = cell.projected_center[0];
7103 double y3 = cell.projected_center[1];
7104
7105 switch (triangle_index)
7106 {
7107 case 0:
7108 x1 = cell.projected_vertices[0][0],
7109 y1 = cell.projected_vertices[0][1],
7110 x2 = cell.projected_vertices[1][0],
7111 y2 = cell.projected_vertices[1][1];
7112 break;
7113 case 1:
7114 x1 = cell.projected_vertices[1][0],
7115 y1 = cell.projected_vertices[1][1],
7116 x2 = cell.projected_vertices[3][0],
7117 y2 = cell.projected_vertices[3][1];
7118 break;
7119 case 2:
7120 x1 = cell.projected_vertices[3][0],
7121 y1 = cell.projected_vertices[3][1],
7122 x2 = cell.projected_vertices[2][0],
7123 y2 = cell.projected_vertices[2][1];
7124 break;
7125 case 3:
7126 x1 = cell.projected_vertices[2][0],
7127 y1 = cell.projected_vertices[2][1],
7128 x2 = cell.projected_vertices[0][0],
7129 y2 = cell.projected_vertices[0][1];
7130 break;
7131 default:
7132 break;
7133 }
7134
7135 out << " <path d=\"M "
7136 << static_cast<unsigned int>(
7137 .5 +
7138 ((x1 - x_min_perspective) / x_dimension_perspective) *
7139 (width - (width / 100.) * 2. * margin_in_percent) +
7140 ((width / 100.) * margin_in_percent))
7141 << ' '
7142 << static_cast<unsigned int>(
7143 .5 + height - (height / 100.) * margin_in_percent -
7144 ((y1 - y_min_perspective) / y_dimension_perspective) *
7145 (height - (height / 100.) * 2. * margin_in_percent))
7146 << " L "
7147 << static_cast<unsigned int>(
7148 .5 +
7149 ((x2 - x_min_perspective) / x_dimension_perspective) *
7150 (width - (width / 100.) * 2. * margin_in_percent) +
7151 ((width / 100.) * margin_in_percent))
7152 << ' '
7153 << static_cast<unsigned int>(
7154 .5 + height - (height / 100.) * margin_in_percent -
7155 ((y2 - y_min_perspective) / y_dimension_perspective) *
7156 (height - (height / 100.) * 2. * margin_in_percent))
7157 << " L "
7158 << static_cast<unsigned int>(
7159 .5 +
7160 ((x3 - x_min_perspective) / x_dimension_perspective) *
7161 (width - (width / 100.) * 2. * margin_in_percent) +
7162 ((width / 100.) * margin_in_percent))
7163 << ' '
7164 << static_cast<unsigned int>(
7165 .5 + height - (height / 100.) * margin_in_percent -
7166 ((y3 - y_min_perspective) / y_dimension_perspective) *
7167 (height - (height / 100.) * 2. * margin_in_percent))
7168 << " L "
7169 << static_cast<unsigned int>(
7170 .5 +
7171 ((x1 - x_min_perspective) / x_dimension_perspective) *
7172 (width - (width / 100.) * 2. * margin_in_percent) +
7173 ((width / 100.) * margin_in_percent))
7174 << ' '
7175 << static_cast<unsigned int>(
7176 .5 + height - (height / 100.) * margin_in_percent -
7177 ((y1 - y_min_perspective) / y_dimension_perspective) *
7178 (height - (height / 100.) * 2. * margin_in_percent))
7179 << "\" style=\"stroke:black; fill:url(#" << triangle_counter
7180 << "); stroke-width:" << flags.line_thickness << "\"/>" << '\n';
7181
7182 ++triangle_counter;
7183 }
7184 }
7185
7186
7187 // draw the colorbar
7188 if (flags.draw_colorbar)
7189 {
7190 out << '\n' << " <!-- colorbar -->" << '\n';
7191
7192 unsigned int element_height = static_cast<unsigned int>(
7193 ((height / 100.) * (71. - 2. * margin_in_percent)) / 4);
7194 unsigned int element_width =
7195 static_cast<unsigned int>(.5 + (height / 100.) * 2.5);
7196
7197 additional_width = 0;
7198 if (!flags.margin)
7199 additional_width =
7200 static_cast<unsigned int>(.5 + (height / 100.) * 2.5);
7201
7202 for (unsigned int index = 0; index < 4; ++index)
7203 {
7204 double start_h = .667 - ((index + 1) / 4.) * .667;
7205 double stop_h = .667 - (index / 4.) * .667;
7206
7207 unsigned int start_r = 0;
7208 unsigned int start_g = 0;
7209 unsigned int start_b = 0;
7210
7211 unsigned int stop_r = 0;
7212 unsigned int stop_g = 0;
7213 unsigned int stop_b = 0;
7214
7215 unsigned int start_i = static_cast<unsigned int>(start_h * 6.);
7216 unsigned int stop_i = static_cast<unsigned int>(stop_h * 6.);
7217
7218 double start_f = start_h * 6. - start_i;
7219 double start_q = 1. - start_f;
7220
7221 double stop_f = stop_h * 6. - stop_i;
7222 double stop_q = 1. - stop_f;
7223
7224 switch (start_i % 6)
7225 {
7226 case 0:
7227 start_r = 255,
7228 start_g = static_cast<unsigned int>(.5 + 255. * start_f);
7229 break;
7230 case 1:
7231 start_r = static_cast<unsigned int>(.5 + 255. * start_q),
7232 start_g = 255;
7233 break;
7234 case 2:
7235 start_g = 255,
7236 start_b = static_cast<unsigned int>(.5 + 255. * start_f);
7237 break;
7238 case 3:
7239 start_g = static_cast<unsigned int>(.5 + 255. * start_q),
7240 start_b = 255;
7241 break;
7242 case 4:
7243 start_r = static_cast<unsigned int>(.5 + 255. * start_f),
7244 start_b = 255;
7245 break;
7246 case 5:
7247 start_r = 255,
7248 start_b = static_cast<unsigned int>(.5 + 255. * start_q);
7249 break;
7250 default:
7251 break;
7252 }
7253
7254 switch (stop_i % 6)
7255 {
7256 case 0:
7257 stop_r = 255,
7258 stop_g = static_cast<unsigned int>(.5 + 255. * stop_f);
7259 break;
7260 case 1:
7261 stop_r = static_cast<unsigned int>(.5 + 255. * stop_q),
7262 stop_g = 255;
7263 break;
7264 case 2:
7265 stop_g = 255,
7266 stop_b = static_cast<unsigned int>(.5 + 255. * stop_f);
7267 break;
7268 case 3:
7269 stop_g = static_cast<unsigned int>(.5 + 255. * stop_q),
7270 stop_b = 255;
7271 break;
7272 case 4:
7273 stop_r = static_cast<unsigned int>(.5 + 255. * stop_f),
7274 stop_b = 255;
7275 break;
7276 case 5:
7277 stop_r = 255,
7278 stop_b = static_cast<unsigned int>(.5 + 255. * stop_q);
7279 break;
7280 default:
7281 break;
7282 }
7283
7284 // define gradient
7285 out << " <linearGradient id=\"colorbar_" << index
7286 << "\" gradientUnits=\"userSpaceOnUse\" "
7287 << "x1=\"" << width + additional_width << "\" "
7288 << "y1=\""
7289 << static_cast<unsigned int>(.5 + (height / 100.) *
7290 (margin_in_percent + 29)) +
7291 (3 - index) * element_height
7292 << "\" "
7293 << "x2=\"" << width + additional_width << "\" "
7294 << "y2=\""
7295 << static_cast<unsigned int>(.5 + (height / 100.) *
7296 (margin_in_percent + 29)) +
7297 (4 - index) * element_height
7298 << "\""
7299 << ">" << '\n'
7300 << " <stop offset=\"0\" style=\"stop-color:rgb(" << start_r
7301 << "," << start_g << "," << start_b << ")\"/>" << '\n'
7302 << " <stop offset=\"1\" style=\"stop-color:rgb(" << stop_r
7303 << "," << stop_g << "," << stop_b << ")\"/>" << '\n'
7304 << " </linearGradient>" << '\n';
7305
7306 // draw box corresponding to the gradient above
7307 out
7308 << " <rect"
7309 << " x=\"" << width + additional_width << "\" y=\""
7310 << static_cast<unsigned int>(.5 + (height / 100.) *
7311 (margin_in_percent + 29)) +
7312 (3 - index) * element_height
7313 << "\" width=\"" << element_width << "\" height=\""
7314 << element_height
7315 << "\" style=\"stroke:black; stroke-width:2; fill:url(#colorbar_"
7316 << index << ")\"/>" << '\n';
7317 }
7318
7319 for (unsigned int index = 0; index < 5; ++index)
7320 {
7321 out
7322 << " <text x=\""
7323 << width + additional_width +
7324 static_cast<unsigned int>(1.5 * element_width)
7325 << "\" y=\""
7326 << static_cast<unsigned int>(
7327 .5 + (height / 100.) * (margin_in_percent + 29) +
7328 (4. - index) * element_height + 30.)
7329 << "\""
7330 << " style=\"text-anchor:start; font-size:80; font-family:Helvetica";
7331
7332 if (index == 0 || index == 4)
7333 out << "; font-weight:bold";
7334
7335 out << "\">"
7336 << static_cast<float>(
7337 (static_cast<int>((z_min + index * (z_dimension / 4.)) *
7338 10000)) /
7339 10000.);
7340
7341 if (index == 4)
7342 out << " max";
7343 if (index == 0)
7344 out << " min";
7345
7346 out << "</text>" << '\n';
7347 }
7348 }
7349
7350 // finalize the svg file
7351 out << '\n' << "</svg>";
7352 out.flush();
7353 }
7354
7355
7356
7357 template <int dim, int spacedim>
7358 void
7360 const std::vector<Patch<dim, spacedim>> &patches,
7361 const std::vector<std::string> &data_names,
7362 const std::vector<
7363 std::tuple<unsigned int,
7364 unsigned int,
7365 std::string,
7367 &nonscalar_data_ranges,
7368 const Deal_II_IntermediateFlags & /*flags*/,
7369 std::ostream &out)
7370 {
7371 AssertThrow(out.fail() == false, ExcIO());
7372
7373 // first write tokens indicating the template parameters. we need this in
7374 // here because we may want to read in data again even if we don't know in
7375 // advance the template parameters:
7376 out << dim << ' ' << spacedim << '\n';
7377
7378 // then write a header
7379 out << "[deal.II intermediate format graphics data]" << '\n'
7380 << "[written by " << DEAL_II_PACKAGE_NAME << " "
7381 << DEAL_II_PACKAGE_VERSION << "]" << '\n'
7382 << "[Version: " << Deal_II_IntermediateFlags::format_version << "]"
7383 << '\n';
7384
7385 out << data_names.size() << '\n';
7386 for (const auto &data_name : data_names)
7387 out << data_name << '\n';
7388
7389 out << patches.size() << '\n';
7390 for (unsigned int i = 0; i < patches.size(); ++i)
7391 out << patches[i] << '\n';
7392
7393 out << nonscalar_data_ranges.size() << '\n';
7394 for (const auto &nonscalar_data_range : nonscalar_data_ranges)
7395 out << std::get<0>(nonscalar_data_range) << ' '
7396 << std::get<1>(nonscalar_data_range) << '\n'
7397 << std::get<2>(nonscalar_data_range) << '\n';
7398
7399 out << '\n';
7400 // make sure everything now gets to disk
7401 out.flush();
7402 }
7403
7404
7405 template <int dim, int spacedim>
7406 void
7408 const std::vector<Patch<dim, spacedim>> &patches,
7409 const std::vector<std::string> &data_names,
7410 const std::vector<
7411 std::tuple<unsigned int,
7412 unsigned int,
7413 std::string,
7415 &nonscalar_data_ranges,
7416 const Deal_II_IntermediateFlags &flags,
7417 const std::string &filename,
7418 const MPI_Comm comm,
7419 const CompressionLevel compression)
7420 {
7421#ifndef DEAL_II_WITH_MPI
7422 (void)patches;
7423 (void)data_names;
7424 (void)nonscalar_data_ranges;
7425 (void)flags;
7426 (void)filename;
7427 (void)comm;
7428 (void)compression;
7429
7430 AssertThrow(false,
7431 ExcMessage("This functionality requires MPI to be enabled."));
7432
7433#else
7434
7435 // We write a simple format based on the text format of
7436 // write_deal_II_intermediate() on each MPI rank. The text format
7437 // is quite verbose and we should probably change this to a more
7438 // efficient binary representation at some point. The file layout
7439 // is as follows:
7440 //
7441 // 1. A binary header with layout struct
7442 // ParallelIntermediateHeaderType.
7443 // 2. A list of uint64_t with one value per rank denoting the
7444 // compressed size of the chunks of the next step.
7445 // 3. The (potentially compressed) chunks as generated by
7446 // write_deal_II_intermediate() on each MPI rank.
7447
7448 // First generate my data by writing (optionally compressed) data into
7449 // my_buffer:
7450 std::vector<char> my_buffer;
7451 {
7452 boost::iostreams::filtering_ostream f;
7453
7456
7457 if (compression != CompressionLevel::no_compression)
7458# ifdef DEAL_II_WITH_ZLIB
7459 f.push(boost::iostreams::zlib_compressor(
7460 get_boost_zlib_compression_level(compression)));
7461# else
7463 false,
7464 ExcMessage(
7465 "Compression requires deal.II to be configured with ZLIB support."));
7466# endif
7467
7468 boost::iostreams::back_insert_device<std::vector<char>> inserter(
7469 my_buffer);
7470 f.push(inserter);
7471
7473 patches, data_names, nonscalar_data_ranges, flags, f);
7474 }
7475 const std::uint64_t my_size = my_buffer.size();
7476
7477 const unsigned int my_rank = Utilities::MPI::this_mpi_process(comm);
7478 const std::uint64_t n_ranks = Utilities::MPI::n_mpi_processes(comm);
7479 const std::uint64_t n_patches = Utilities::MPI::sum(patches.size(), comm);
7480
7481 const ParallelIntermediateHeader header{
7482 0x00dea111,
7484 static_cast<std::uint64_t>(compression),
7485 dim,
7486 spacedim,
7487 n_ranks,
7488 n_patches};
7489
7490 // Rank 0 also collects and writes the size of the data from each
7491 // rank in bytes. The static_cast for the destination buffer looks
7492 // useless, but without it clang-tidy will complain about a wrong
7493 // MPI type.
7494 std::vector<std::uint64_t> chunk_sizes(n_ranks);
7495 int ierr = MPI_Gather(&my_size,
7496 1,
7498 static_cast<std::uint64_t *>(chunk_sizes.data()),
7499 1,
7501 0,
7502 comm);
7503 AssertThrowMPI(ierr);
7504
7505 MPI_Info info;
7506 ierr = MPI_Info_create(&info);
7507 AssertThrowMPI(ierr);
7508 MPI_File fh;
7509 ierr = MPI_File_open(
7510 comm, filename.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &fh);
7511 AssertThrow(ierr == MPI_SUCCESS, ExcFileNotOpen(filename));
7512 ierr = MPI_Info_free(&info);
7513 AssertThrowMPI(ierr);
7514
7515 // Delete the file contents:
7516 ierr = MPI_File_set_size(fh, 0);
7517 AssertThrowMPI(ierr);
7518 // This barrier is necessary, because otherwise others might already write
7519 // while one core is still setting the size to zero.
7520 ierr = MPI_Barrier(comm);
7521 AssertThrowMPI(ierr);
7522
7523 // Write the two parts of the header on rank 0:
7524 if (my_rank == 0)
7525 {
7527 fh, 0, &header, sizeof(header), MPI_CHAR, MPI_STATUS_IGNORE);
7528 AssertThrowMPI(ierr);
7529
7531 fh,
7532 /* offset = */ sizeof(header),
7533 chunk_sizes.data(),
7534 chunk_sizes.size(),
7536 MPI_STATUS_IGNORE);
7537 AssertThrowMPI(ierr);
7538 }
7539
7540 // Write the main part on each rank:
7541 {
7542 std::uint64_t prefix_sum = 0;
7543 ierr = MPI_Exscan(&my_size,
7544 &prefix_sum,
7545 1,
7547 MPI_SUM,
7548 comm);
7549 AssertThrowMPI(ierr);
7550
7551 // Locate specific offset for each processor.
7552 const MPI_Offset offset = static_cast<MPI_Offset>(sizeof(header)) +
7553 n_ranks * sizeof(std::uint64_t) + prefix_sum;
7554
7556 fh, offset, my_buffer.data(), my_size, MPI_CHAR, MPI_STATUS_IGNORE);
7557 AssertThrowMPI(ierr);
7558 }
7559
7560 // Make sure we sync to disk. As written in the standard,
7561 // MPI_File_close() actually already implies a sync but there seems
7562 // to be a bug on at least one configuration (running with multiple
7563 // nodes using OpenMPI 4.1) that requires it. Without this call, the
7564 // footer is sometimes missing.
7565 ierr = MPI_File_sync(fh);
7566 AssertThrowMPI(ierr);
7567
7568 ierr = MPI_File_close(&fh);
7569 AssertThrowMPI(ierr);
7570#endif
7571 }
7572
7573
7574
7575 std::pair<unsigned int, unsigned int>
7577 {
7578 AssertThrow(input.fail() == false, ExcIO());
7579
7580 unsigned int dim, spacedim;
7581 input >> dim >> spacedim;
7582
7583 return std::make_pair(dim, spacedim);
7584 }
7585} // namespace DataOutBase
7586
7587
7588
7589/* --------------------------- class DataOutInterface ---------------------- */
7590
7591
7592template <int dim, int spacedim>
7597
7598
7599
7600template <int dim, int spacedim>
7601void
7610
7611
7612
7613template <int dim, int spacedim>
7614void
7623
7624
7625
7626template <int dim, int spacedim>
7627void
7636
7637
7638
7639template <int dim, int spacedim>
7640void
7649
7650
7651
7652template <int dim, int spacedim>
7653void
7662
7663
7664
7665template <int dim, int spacedim>
7666void
7675
7676
7677
7678template <int dim, int spacedim>
7679void
7688
7689
7690
7691template <int dim, int spacedim>
7692void
7701
7702template <int dim, int spacedim>
7703void
7712
7713template <int dim, int spacedim>
7714void
7723
7724
7725template <int dim, int spacedim>
7726void
7728 const std::string &filename,
7729 const MPI_Comm comm) const
7730{
7731#ifndef DEAL_II_WITH_MPI
7732 // without MPI fall back to the normal way to write a vtu file :
7733 (void)comm;
7734
7735 std::ofstream f(filename);
7736 AssertThrow(f, ExcFileNotOpen(filename));
7737 write_vtu(f);
7738#else
7739
7740 const unsigned int myrank = Utilities::MPI::this_mpi_process(comm);
7741 const unsigned int n_ranks = Utilities::MPI::n_mpi_processes(comm);
7742 MPI_Info info;
7743 int ierr = MPI_Info_create(&info);
7744 AssertThrowMPI(ierr);
7745 MPI_File fh;
7746 ierr = MPI_File_open(
7747 comm, filename.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &fh);
7748 AssertThrow(ierr == MPI_SUCCESS, ExcFileNotOpen(filename));
7749
7750 ierr = MPI_File_set_size(fh, 0); // delete the file contents
7751 AssertThrowMPI(ierr);
7752 // this barrier is necessary, because otherwise others might already write
7753 // while one core is still setting the size to zero.
7754 ierr = MPI_Barrier(comm);
7755 AssertThrowMPI(ierr);
7756 ierr = MPI_Info_free(&info);
7757 AssertThrowMPI(ierr);
7758
7759 // Define header size so we can broadcast later.
7760 unsigned int header_size;
7761 std::uint64_t footer_offset;
7762
7763 // write header
7764 if (myrank == 0)
7765 {
7766 std::stringstream ss;
7768 header_size = ss.str().size();
7769 // Write the header on rank 0 at the start of a file, i.e., offset 0.
7771 fh, 0, ss.str().c_str(), header_size, MPI_CHAR, MPI_STATUS_IGNORE);
7772 AssertThrowMPI(ierr);
7773 }
7774
7775 ierr = MPI_Bcast(&header_size, 1, MPI_UNSIGNED, 0, comm);
7776 AssertThrowMPI(ierr);
7777
7778 {
7779 const auto &patches = get_patches();
7780 const types::global_dof_index my_n_patches = patches.size();
7781 const types::global_dof_index global_n_patches =
7782 Utilities::MPI::sum(my_n_patches, comm);
7783
7784 // Do not write pieces with 0 cells as this will crash paraview if this is
7785 // the first piece written. But if nobody has any pieces to write (file is
7786 // empty), let processor 0 write their empty data, otherwise the vtk file is
7787 // invalid.
7788 std::stringstream ss;
7789 if (my_n_patches > 0 || (global_n_patches == 0 && myrank == 0))
7793 vtk_flags,
7794 ss);
7795
7796 // Use prefix sum to find specific offset to write at.
7797 const std::uint64_t size_on_proc = ss.str().size();
7798 std::uint64_t prefix_sum = 0;
7799 ierr = MPI_Exscan(&size_on_proc,
7800 &prefix_sum,
7801 1,
7803 MPI_SUM,
7804 comm);
7805 AssertThrowMPI(ierr);
7806
7807 // Locate specific offset for each processor.
7808 const MPI_Offset offset = static_cast<MPI_Offset>(header_size) + prefix_sum;
7809
7811 offset,
7812 ss.str().c_str(),
7813 ss.str().size(),
7814 MPI_CHAR,
7815 MPI_STATUS_IGNORE);
7816 AssertThrowMPI(ierr);
7817
7818 if (myrank == n_ranks - 1)
7819 {
7820 // Locating Footer with offset on last rank.
7821 footer_offset = size_on_proc + offset;
7822
7823 std::stringstream ss;
7825 const unsigned int footer_size = ss.str().size();
7826
7827 // Writing footer:
7829 footer_offset,
7830 ss.str().c_str(),
7831 footer_size,
7832 MPI_CHAR,
7833 MPI_STATUS_IGNORE);
7834 AssertThrowMPI(ierr);
7835 }
7836 }
7837
7838 // Make sure we sync to disk. As written in the standard,
7839 // MPI_File_close() actually already implies a sync but there seems
7840 // to be a bug on at least one configuration (running with multiple
7841 // nodes using OpenMPI 4.1) that requires it. Without this call, the
7842 // footer is sometimes missing.
7843 ierr = MPI_File_sync(fh);
7844 AssertThrowMPI(ierr);
7845
7846 ierr = MPI_File_close(&fh);
7847 AssertThrowMPI(ierr);
7848#endif
7849}
7850
7851
7852
7853template <int dim, int spacedim>
7854void
7856 std::ostream &out,
7857 const std::vector<std::string> &piece_names) const
7858{
7860 piece_names,
7863 vtk_flags);
7864}
7865
7866
7867
7868template <int dim, int spacedim>
7869std::string
7871 const std::string &directory,
7872 const std::string &filename_without_extension,
7873 const unsigned int counter,
7874 const MPI_Comm mpi_communicator,
7875 const unsigned int n_digits_for_counter,
7876 const unsigned int n_groups) const
7877{
7878 const unsigned int rank = Utilities::MPI::this_mpi_process(mpi_communicator);
7879 const unsigned int n_ranks =
7880 Utilities::MPI::n_mpi_processes(mpi_communicator);
7881 const unsigned int n_files_written =
7882 (n_groups == 0 || n_groups > n_ranks) ? n_ranks : n_groups;
7883
7884 Assert(n_files_written >= 1, ExcInternalError());
7885 // the "-1" is needed since we use C++ style counting starting with 0, so
7886 // writing 10 files means the filename runs from 0 to 9
7887 const unsigned int n_digits =
7888 Utilities::needed_digits(std::max(0, int(n_files_written) - 1));
7889
7890 const unsigned int color = rank % n_files_written;
7891 const std::string filename =
7892 directory + filename_without_extension + "_" +
7893 Utilities::int_to_string(counter, n_digits_for_counter) + "." +
7894 Utilities::int_to_string(color, n_digits) + ".vtu";
7895
7896 if (n_groups == 0 || n_groups > n_ranks)
7897 {
7898 // every processor writes one file
7899 std::ofstream output(filename);
7900 AssertThrow(output, ExcFileNotOpen(filename));
7901 this->write_vtu(output);
7902 }
7903 else if (n_groups == 1)
7904 {
7905 // write only a single data file in parallel
7906 this->write_vtu_in_parallel(filename, mpi_communicator);
7907 }
7908 else
7909 {
7910#ifdef DEAL_II_WITH_MPI
7911 // write n_groups data files
7912 MPI_Comm comm_group;
7913 int ierr = MPI_Comm_split(mpi_communicator, color, rank, &comm_group);
7914 AssertThrowMPI(ierr);
7915 this->write_vtu_in_parallel(filename, comm_group);
7917#else
7918 AssertThrow(false, ExcMessage("Logical error. Should not arrive here."));
7919#endif
7920 }
7921
7922 // write pvtu record
7923 const std::string pvtu_filename =
7924 filename_without_extension + "_" +
7925 Utilities::int_to_string(counter, n_digits_for_counter) + ".pvtu";
7926
7927 if (rank == 0)
7928 {
7929 std::vector<std::string> filename_vector;
7930 for (unsigned int i = 0; i < n_files_written; ++i)
7931 {
7932 const std::string filename =
7933 filename_without_extension + "_" +
7934 Utilities::int_to_string(counter, n_digits_for_counter) + "." +
7935 Utilities::int_to_string(i, n_digits) + ".vtu";
7936
7937 filename_vector.emplace_back(filename);
7938 }
7939
7940 std::ofstream pvtu_output(directory + pvtu_filename);
7941 this->write_pvtu_record(pvtu_output, filename_vector);
7942 }
7943
7944 return pvtu_filename;
7945}
7946
7947
7948
7949template <int dim, int spacedim>
7950void
7960
7961
7962
7963template <int dim, int spacedim>
7964void
7966 const std::string &filename,
7967 const MPI_Comm comm,
7968 const DataOutBase::CompressionLevel compression) const
7969{
7971 get_patches(),
7975 filename,
7976 comm,
7977 compression);
7978}
7979
7980
7981
7982template <int dim, int spacedim>
7985 const DataOutBase::DataOutFilter &data_filter,
7986 const std::string &h5_filename,
7987 const double cur_time,
7988 const MPI_Comm comm) const
7989{
7990 return create_xdmf_entry(
7991 data_filter, h5_filename, h5_filename, cur_time, comm);
7992}
7993
7994
7995
7996template <int dim, int spacedim>
7999 const DataOutBase::DataOutFilter &data_filter,
8000 const std::string &h5_mesh_filename,
8001 const std::string &h5_solution_filename,
8002 const double cur_time,
8003 const MPI_Comm comm) const
8004{
8005 AssertThrow(spacedim == 2 || spacedim == 3,
8006 ExcMessage("XDMF only supports 2 or 3 space dimensions."));
8007
8008#ifndef DEAL_II_WITH_HDF5
8009 // throw an exception, but first make sure the compiler does not warn about
8010 // the now unused function arguments
8011 (void)data_filter;
8012 (void)h5_mesh_filename;
8013 (void)h5_solution_filename;
8014 (void)cur_time;
8015 (void)comm;
8016 AssertThrow(false, ExcMessage("XDMF support requires HDF5 to be turned on."));
8017
8018 return {};
8019
8020#else
8021
8022 std::uint64_t local_node_cell_count[2], global_node_cell_count[2];
8023
8024 local_node_cell_count[0] = data_filter.n_nodes();
8025 local_node_cell_count[1] = data_filter.n_cells();
8026
8027 const int myrank = Utilities::MPI::this_mpi_process(comm);
8028 // And compute the global total
8029 int ierr = MPI_Allreduce(local_node_cell_count,
8030 global_node_cell_count,
8031 2,
8033 MPI_SUM,
8034 comm);
8035 AssertThrowMPI(ierr);
8036
8037 // The implementation is a bit complicated because we are supposed to return
8038 // the correct data on rank 0 and an empty object on all other ranks but all
8039 // information (for example the attributes) are only available on ranks that
8040 // have any cells.
8041 // We will identify the smallest rank that has data and then communicate
8042 // from this rank to rank 0 (if they are different ranks).
8043
8044 const bool have_data = (data_filter.n_nodes() > 0);
8045 MPI_Comm split_comm;
8046 {
8047 const int key = myrank;
8048 const int color = (have_data ? 1 : 0);
8049 const int ierr = MPI_Comm_split(comm, color, key, &split_comm);
8050 AssertThrowMPI(ierr);
8051 }
8052
8053 const bool am_i_first_rank_with_data =
8054 have_data && (Utilities::MPI::this_mpi_process(split_comm) == 0);
8055
8056 ierr = MPI_Comm_free(&split_comm);
8057 AssertThrowMPI(ierr);
8058
8059 const int tag = 47381;
8060
8061 // Output the XDMF file only on the root process of all ranks with data:
8062 if (am_i_first_rank_with_data)
8063 {
8064 const auto &patches = get_patches();
8065 Assert(patches.size() > 0, DataOutBase::ExcNoPatches());
8066
8067 // We currently don't support writing mixed meshes:
8068 if constexpr (running_in_debug_mode())
8069 {
8070 for (const auto &patch : patches)
8071 Assert(patch.reference_cell == patches[0].reference_cell,
8073 }
8074
8075 XDMFEntry entry(h5_mesh_filename,
8076 h5_solution_filename,
8077 cur_time,
8078 global_node_cell_count[0],
8079 global_node_cell_count[1],
8080 dim,
8081 spacedim,
8082 patches[0].reference_cell);
8083 const unsigned int n_data_sets = data_filter.n_data_sets();
8084
8085 // The vector names generated here must match those generated in
8086 // the HDF5 file
8087 for (unsigned int i = 0; i < n_data_sets; ++i)
8088 {
8089 entry.add_attribute(data_filter.get_data_set_name(i),
8090 data_filter.get_data_set_dim(i));
8091 }
8092
8093 if (myrank != 0)
8094 {
8095 // send to rank 0
8096 const std::vector<char> buffer = Utilities::pack(entry, false);
8097 ierr = MPI_Send(buffer.data(), buffer.size(), MPI_BYTE, 0, tag, comm);
8098 AssertThrowMPI(ierr);
8099
8100 return {};
8101 }
8102
8103 return entry;
8104 }
8105
8106 if (myrank == 0 && !am_i_first_rank_with_data)
8107 {
8108 // receive the XDMF data on rank 0 if we don't have it...
8109
8110 MPI_Status status;
8111 int ierr = MPI_Probe(MPI_ANY_SOURCE, tag, comm, &status);
8112 AssertThrowMPI(ierr);
8113
8114 int len;
8115 ierr = MPI_Get_count(&status, MPI_BYTE, &len);
8116 AssertThrowMPI(ierr);
8117
8118 std::vector<char> buffer(len);
8119 ierr = MPI_Recv(buffer.data(),
8120 len,
8121 MPI_BYTE,
8122 status.MPI_SOURCE,
8123 tag,
8124 comm,
8125 MPI_STATUS_IGNORE);
8126 AssertThrowMPI(ierr);
8127
8128 return Utilities::unpack<XDMFEntry>(buffer, false);
8129 }
8130
8131 // default case for any other rank is to return an empty object
8132 return {};
8133#endif
8134}
8135
8136template <int dim, int spacedim>
8137void
8139 const std::vector<XDMFEntry> &entries,
8140 const std::string &filename,
8141 const MPI_Comm comm) const
8142{
8143#ifdef DEAL_II_WITH_MPI
8144 const int myrank = Utilities::MPI::this_mpi_process(comm);
8145#else
8146 (void)comm;
8147 const int myrank = 0;
8148#endif
8149
8150 // Only rank 0 process writes the XDMF file
8151 if (myrank == 0)
8152 {
8153 std::ofstream xdmf_file(filename);
8154
8155 xdmf_file << "<?xml version=\"1.0\" ?>\n";
8156 xdmf_file << "<!DOCTYPE Xdmf SYSTEM \"Xdmf.dtd\" []>\n";
8157 xdmf_file << "<Xdmf Version=\"2.0\">\n";
8158 xdmf_file << " <Domain>\n";
8159 xdmf_file
8160 << " <Grid Name=\"CellTime\" GridType=\"Collection\" CollectionType=\"Temporal\">\n";
8161
8162 for (const auto &entry : entries)
8163 {
8164 xdmf_file << entry.get_xdmf_content(3);
8165 }
8166
8167 xdmf_file << " </Grid>\n";
8168 xdmf_file << " </Domain>\n";
8169 xdmf_file << "</Xdmf>\n";
8170
8171 xdmf_file.close();
8172 }
8173}
8174
8175
8176
8177/*
8178 * Write the data in this DataOutInterface to a DataOutFilter object. Filtering
8179 * is performed based on the DataOutFilter flags.
8180 */
8181template <int dim, int spacedim>
8182void
8191
8192
8193namespace
8194{
8195#ifdef DEAL_II_WITH_HDF5
8199 template <int dim, int spacedim>
8200 void
8201 do_write_hdf5(const std::vector<DataOutBase::Patch<dim, spacedim>> &patches,
8202 const DataOutBase::DataOutFilter &data_filter,
8203 const DataOutBase::Hdf5Flags &flags,
8204 const bool write_mesh_file,
8205 const std::string &mesh_filename,
8206 const std::string &solution_filename,
8207 const MPI_Comm comm)
8208 {
8209 hid_t h5_mesh_file_id = -1, h5_solution_file_id, file_plist_id, plist_id;
8210 hid_t node_dataspace, node_dataset, node_file_dataspace,
8211 node_memory_dataspace, node_dataset_id;
8212 hid_t cell_dataspace, cell_dataset, cell_file_dataspace,
8213 cell_memory_dataspace;
8214 hid_t pt_data_dataspace, pt_data_dataset, pt_data_file_dataspace,
8215 pt_data_memory_dataspace;
8216 herr_t status;
8217 std::uint64_t local_node_cell_count[2];
8218 hsize_t count[2], offset[2], node_ds_dim[2], cell_ds_dim[2];
8219 std::vector<double> node_data_vec;
8220 std::vector<unsigned int> cell_data_vec;
8221
8222
8223
8224 local_node_cell_count[0] = data_filter.n_nodes();
8225 local_node_cell_count[1] = data_filter.n_cells();
8226
8227 // Create file access properties
8228 file_plist_id = H5Pcreate(H5P_FILE_ACCESS);
8229 AssertThrow(file_plist_id != -1, ExcIO());
8230 // If MPI is enabled *and* HDF5 is parallel, we can do parallel output
8231# ifdef DEAL_II_WITH_MPI
8232# ifdef H5_HAVE_PARALLEL
8233 // Set the access to use the specified MPI_Comm object
8234 status = H5Pset_fapl_mpio(file_plist_id, comm, MPI_INFO_NULL);
8235 AssertThrow(status >= 0, ExcIO());
8236# endif
8237# endif
8238 // if zlib support is disabled flags are unused
8239# ifndef DEAL_II_WITH_ZLIB
8240 (void)flags;
8241# endif
8242
8243 // Compute the global total number of nodes/cells and determine the offset
8244 // of the data for this process
8245
8246 std::uint64_t global_node_cell_count[2] = {0, 0};
8247 std::uint64_t global_node_cell_offsets[2] = {0, 0};
8248
8249# ifdef DEAL_II_WITH_MPI
8250 int ierr =
8251 MPI_Allreduce(local_node_cell_count,
8252 global_node_cell_count,
8253 2,
8255 MPI_SUM,
8256 comm);
8257 AssertThrowMPI(ierr);
8258 ierr = MPI_Exscan(local_node_cell_count,
8259 global_node_cell_offsets,
8260 2,
8262 MPI_SUM,
8263 comm);
8264 AssertThrowMPI(ierr);
8265# else
8266 global_node_cell_count[0] = local_node_cell_count[0];
8267 global_node_cell_count[1] = local_node_cell_count[1];
8268 global_node_cell_offsets[0] = global_node_cell_offsets[1] = 0;
8269# endif
8270
8271 // Create the property list for a collective write
8272 plist_id = H5Pcreate(H5P_DATASET_XFER);
8273 AssertThrow(plist_id >= 0, ExcIO());
8274# ifdef DEAL_II_WITH_MPI
8275# ifdef H5_HAVE_PARALLEL
8276 status = H5Pset_dxpl_mpio(plist_id, H5FD_MPIO_COLLECTIVE);
8277 AssertThrow(status >= 0, ExcIO());
8278# endif
8279# endif
8280
8281 if (write_mesh_file)
8282 {
8283 // Overwrite any existing files (change this to an option?)
8284 h5_mesh_file_id = H5Fcreate(mesh_filename.c_str(),
8285 H5F_ACC_TRUNC,
8286 H5P_DEFAULT,
8287 file_plist_id);
8288 AssertThrow(h5_mesh_file_id >= 0, ExcIO());
8289
8290 // Create the dataspace for the nodes and cells. HDF5 only supports 2-
8291 // or 3-dimensional coordinates
8292 node_ds_dim[0] = global_node_cell_count[0];
8293 node_ds_dim[1] = (spacedim < 2) ? 2 : spacedim;
8294 node_dataspace = H5Screate_simple(2, node_ds_dim, nullptr);
8295 AssertThrow(node_dataspace >= 0, ExcIO());
8296
8297 cell_ds_dim[0] = global_node_cell_count[1];
8298 cell_ds_dim[1] = patches[0].reference_cell.n_vertices();
8299 cell_dataspace = H5Screate_simple(2, cell_ds_dim, nullptr);
8300 AssertThrow(cell_dataspace >= 0, ExcIO());
8301
8302 // Create the dataset for the nodes and cells
8303# if H5Gcreate_vers == 1
8304 node_dataset = H5Dcreate(h5_mesh_file_id,
8305 "nodes",
8306 H5T_NATIVE_DOUBLE,
8307 node_dataspace,
8308 H5P_DEFAULT);
8309# else
8310 node_dataset_id = H5Pcreate(H5P_DATASET_CREATE);
8311# ifdef DEAL_II_WITH_ZLIB
8312 H5Pset_deflate(node_dataset_id,
8313 get_zlib_compression_level(flags.compression_level));
8314 H5Pset_chunk(node_dataset_id, 2, node_ds_dim);
8315# endif
8316 node_dataset = H5Dcreate(h5_mesh_file_id,
8317 "nodes",
8318 H5T_NATIVE_DOUBLE,
8319 node_dataspace,
8320 H5P_DEFAULT,
8321 node_dataset_id,
8322 H5P_DEFAULT);
8323 H5Pclose(node_dataset_id);
8324# endif
8325 AssertThrow(node_dataset >= 0, ExcIO());
8326# if H5Gcreate_vers == 1
8327 cell_dataset = H5Dcreate(h5_mesh_file_id,
8328 "cells",
8329 H5T_NATIVE_UINT,
8330 cell_dataspace,
8331 H5P_DEFAULT);
8332# else
8333 node_dataset_id = H5Pcreate(H5P_DATASET_CREATE);
8334# ifdef DEAL_II_WITH_ZLIB
8335 H5Pset_deflate(node_dataset_id,
8336 get_zlib_compression_level(flags.compression_level));
8337 H5Pset_chunk(node_dataset_id, 2, cell_ds_dim);
8338# endif
8339 cell_dataset = H5Dcreate(h5_mesh_file_id,
8340 "cells",
8341 H5T_NATIVE_UINT,
8342 cell_dataspace,
8343 H5P_DEFAULT,
8344 node_dataset_id,
8345 H5P_DEFAULT);
8346 H5Pclose(node_dataset_id);
8347# endif
8348 AssertThrow(cell_dataset >= 0, ExcIO());
8349
8350 // Close the node and cell dataspaces since we're done with them
8351 status = H5Sclose(node_dataspace);
8352 AssertThrow(status >= 0, ExcIO());
8353 status = H5Sclose(cell_dataspace);
8354 AssertThrow(status >= 0, ExcIO());
8355
8356 // Create the data subset we'll use to read from memory. HDF5 only
8357 // supports 2- or 3-dimensional coordinates
8358 count[0] = local_node_cell_count[0];
8359 count[1] = (spacedim < 2) ? 2 : spacedim;
8360
8361 offset[0] = global_node_cell_offsets[0];
8362 offset[1] = 0;
8363
8364 node_memory_dataspace = H5Screate_simple(2, count, nullptr);
8365 AssertThrow(node_memory_dataspace >= 0, ExcIO());
8366
8367 // Select the hyperslab in the file
8368 node_file_dataspace = H5Dget_space(node_dataset);
8369 AssertThrow(node_file_dataspace >= 0, ExcIO());
8370 status = H5Sselect_hyperslab(
8371 node_file_dataspace, H5S_SELECT_SET, offset, nullptr, count, nullptr);
8372 AssertThrow(status >= 0, ExcIO());
8373
8374 // And repeat for cells
8375 count[0] = local_node_cell_count[1];
8376 count[1] = patches[0].reference_cell.n_vertices();
8377 offset[0] = global_node_cell_offsets[1];
8378 offset[1] = 0;
8379 cell_memory_dataspace = H5Screate_simple(2, count, nullptr);
8380 AssertThrow(cell_memory_dataspace >= 0, ExcIO());
8381
8382 cell_file_dataspace = H5Dget_space(cell_dataset);
8383 AssertThrow(cell_file_dataspace >= 0, ExcIO());
8384 status = H5Sselect_hyperslab(
8385 cell_file_dataspace, H5S_SELECT_SET, offset, nullptr, count, nullptr);
8386 AssertThrow(status >= 0, ExcIO());
8387
8388 // And finally, write the node data
8389 data_filter.fill_node_data(node_data_vec);
8390 status = H5Dwrite(node_dataset,
8391 H5T_NATIVE_DOUBLE,
8392 node_memory_dataspace,
8393 node_file_dataspace,
8394 plist_id,
8395 node_data_vec.data());
8396 AssertThrow(status >= 0, ExcIO());
8397 node_data_vec.clear();
8398
8399 // And the cell data
8400 data_filter.fill_cell_data(global_node_cell_offsets[0], cell_data_vec);
8401 status = H5Dwrite(cell_dataset,
8402 H5T_NATIVE_UINT,
8403 cell_memory_dataspace,
8404 cell_file_dataspace,
8405 plist_id,
8406 cell_data_vec.data());
8407 AssertThrow(status >= 0, ExcIO());
8408 cell_data_vec.clear();
8409
8410 // Close the file dataspaces
8411 status = H5Sclose(node_file_dataspace);
8412 AssertThrow(status >= 0, ExcIO());
8413 status = H5Sclose(cell_file_dataspace);
8414 AssertThrow(status >= 0, ExcIO());
8415
8416 // Close the memory dataspaces
8417 status = H5Sclose(node_memory_dataspace);
8418 AssertThrow(status >= 0, ExcIO());
8419 status = H5Sclose(cell_memory_dataspace);
8420 AssertThrow(status >= 0, ExcIO());
8421
8422 // Close the datasets
8423 status = H5Dclose(node_dataset);
8424 AssertThrow(status >= 0, ExcIO());
8425 status = H5Dclose(cell_dataset);
8426 AssertThrow(status >= 0, ExcIO());
8427
8428 // If the filenames are different, we need to close the mesh file
8429 if (mesh_filename != solution_filename)
8430 {
8431 status = H5Fclose(h5_mesh_file_id);
8432 AssertThrow(status >= 0, ExcIO());
8433 }
8434 }
8435
8436 // If the filenames are identical, continue with the same file
8437 if (mesh_filename == solution_filename && write_mesh_file)
8438 {
8439 h5_solution_file_id = h5_mesh_file_id;
8440 }
8441 else
8442 {
8443 // Otherwise we need to open a new file
8444 h5_solution_file_id = H5Fcreate(solution_filename.c_str(),
8445 H5F_ACC_TRUNC,
8446 H5P_DEFAULT,
8447 file_plist_id);
8448 AssertThrow(h5_solution_file_id >= 0, ExcIO());
8449 }
8450
8451 // when writing, first write out all vector data, then handle the scalar
8452 // data sets that have been left over
8453 unsigned int i;
8454 std::string vector_name;
8455 for (i = 0; i < data_filter.n_data_sets(); ++i)
8456 {
8457 // Allocate space for the point data
8458 // Must be either 1d or 3d
8459 const unsigned int pt_data_vector_dim = data_filter.get_data_set_dim(i);
8460 vector_name = data_filter.get_data_set_name(i);
8461
8462 // Create the dataspace for the point data
8463 node_ds_dim[0] = global_node_cell_count[0];
8464 node_ds_dim[1] = pt_data_vector_dim;
8465 pt_data_dataspace = H5Screate_simple(2, node_ds_dim, nullptr);
8466 AssertThrow(pt_data_dataspace >= 0, ExcIO());
8467
8468# if H5Gcreate_vers == 1
8469 pt_data_dataset = H5Dcreate(h5_solution_file_id,
8470 vector_name.c_str(),
8471 H5T_NATIVE_DOUBLE,
8472 pt_data_dataspace,
8473 H5P_DEFAULT);
8474# else
8475 node_dataset_id = H5Pcreate(H5P_DATASET_CREATE);
8476# ifdef DEAL_II_WITH_ZLIB
8477 H5Pset_deflate(node_dataset_id,
8478 get_zlib_compression_level(flags.compression_level));
8479 H5Pset_chunk(node_dataset_id, 2, node_ds_dim);
8480# endif
8481 pt_data_dataset = H5Dcreate(h5_solution_file_id,
8482 vector_name.c_str(),
8483 H5T_NATIVE_DOUBLE,
8484 pt_data_dataspace,
8485 H5P_DEFAULT,
8486 node_dataset_id,
8487 H5P_DEFAULT);
8488 H5Pclose(node_dataset_id);
8489# endif
8490 AssertThrow(pt_data_dataset >= 0, ExcIO());
8491
8492 // Create the data subset we'll use to read from memory
8493 count[0] = local_node_cell_count[0];
8494 count[1] = pt_data_vector_dim;
8495 offset[0] = global_node_cell_offsets[0];
8496 offset[1] = 0;
8497 pt_data_memory_dataspace = H5Screate_simple(2, count, nullptr);
8498 AssertThrow(pt_data_memory_dataspace >= 0, ExcIO());
8499
8500 // Select the hyperslab in the file
8501 pt_data_file_dataspace = H5Dget_space(pt_data_dataset);
8502 AssertThrow(pt_data_file_dataspace >= 0, ExcIO());
8503 status = H5Sselect_hyperslab(pt_data_file_dataspace,
8504 H5S_SELECT_SET,
8505 offset,
8506 nullptr,
8507 count,
8508 nullptr);
8509 AssertThrow(status >= 0, ExcIO());
8510
8511 // And finally, write the data
8512 status = H5Dwrite(pt_data_dataset,
8513 H5T_NATIVE_DOUBLE,
8514 pt_data_memory_dataspace,
8515 pt_data_file_dataspace,
8516 plist_id,
8517 data_filter.get_data_set(i));
8518 AssertThrow(status >= 0, ExcIO());
8519
8520 // Close the dataspaces
8521 status = H5Sclose(pt_data_dataspace);
8522 AssertThrow(status >= 0, ExcIO());
8523 status = H5Sclose(pt_data_memory_dataspace);
8524 AssertThrow(status >= 0, ExcIO());
8525 status = H5Sclose(pt_data_file_dataspace);
8526 AssertThrow(status >= 0, ExcIO());
8527 // Close the dataset
8528 status = H5Dclose(pt_data_dataset);
8529 AssertThrow(status >= 0, ExcIO());
8530 }
8531
8532 // Close the file property list
8533 status = H5Pclose(file_plist_id);
8534 AssertThrow(status >= 0, ExcIO());
8535
8536 // Close the parallel access
8537 status = H5Pclose(plist_id);
8538 AssertThrow(status >= 0, ExcIO());
8539
8540 // Close the file
8541 status = H5Fclose(h5_solution_file_id);
8542 AssertThrow(status >= 0, ExcIO());
8543 }
8544#endif
8545} // namespace
8546
8547
8548
8549template <int dim, int spacedim>
8550void
8552 const std::vector<Patch<dim, spacedim>> &patches,
8553 const std::vector<std::string> &data_names,
8554 const std::vector<
8555 std::tuple<unsigned int,
8556 unsigned int,
8557 std::string,
8559 &nonscalar_data_ranges,
8560 DataOutBase::DataOutFilter &filtered_data)
8561{
8562 const unsigned int n_data_sets = data_names.size();
8563
8564#ifndef DEAL_II_WITH_MPI
8565 // verify that there are indeed patches to be written out. most of the times,
8566 // people just forget to call build_patches when there are no patches, so a
8567 // warning is in order. that said, the assertion is disabled if we support MPI
8568 // since then it can happen that on the coarsest mesh, a processor simply has
8569 // no cells it actually owns, and in that case it is legit if there are no
8570 // patches
8571 Assert(patches.size() > 0, ExcNoPatches());
8572#else
8573 if (patches.empty())
8574 return;
8575#endif
8576
8577 unsigned int n_nodes;
8578 std::tie(n_nodes, std::ignore) = count_nodes_and_cells(patches);
8579
8580 // For the format we write here, we need to write all node values relating
8581 // to one variable at a time. We could in principle do this by looping
8582 // over all patches and extracting the values corresponding to the one
8583 // variable we're dealing with right now, and then start the process over
8584 // for the next variable with another loop over all patches.
8585 //
8586 // An easier way is to create a global table that for each variable
8587 // lists all values. This copying of data vectors can be done in the
8588 // background while we're already working on vertices and cells,
8589 // so do this on a separate task and when wanting to write out the
8590 // data, we wait for that task to finish.
8592 create_global_data_table_task = Threads::new_task(
8593 [&patches]() { return create_global_data_table(patches); });
8594
8595 // Write the nodes/cells to the DataOutFilter object.
8596 write_nodes(patches, filtered_data);
8597 write_cells(patches, filtered_data);
8598
8599 // Wait for the reordering to be done and retrieve the reordered data:
8600 const Table<2, double> data_vectors =
8601 std::move(*create_global_data_table_task.return_value());
8602
8603 // when writing, first write out all vector data, then handle the scalar data
8604 // sets that have been left over
8605 unsigned int i, n_th_vector, data_set, pt_data_vector_dim;
8606 std::string vector_name;
8607 for (n_th_vector = 0, data_set = 0; data_set < n_data_sets;)
8608 {
8609 // Advance n_th_vector to at least the current data set we are on
8610 while (n_th_vector < nonscalar_data_ranges.size() &&
8611 std::get<0>(nonscalar_data_ranges[n_th_vector]) < data_set)
8612 ++n_th_vector;
8613
8614 // Determine the dimension of this data
8615 if (n_th_vector < nonscalar_data_ranges.size() &&
8616 std::get<0>(nonscalar_data_ranges[n_th_vector]) == data_set)
8617 {
8618 // Multiple dimensions
8619 pt_data_vector_dim = std::get<1>(nonscalar_data_ranges[n_th_vector]) -
8620 std::get<0>(nonscalar_data_ranges[n_th_vector]) +
8621 1;
8622
8623 // Ensure the dimensionality of the data is correct
8625 std::get<1>(nonscalar_data_ranges[n_th_vector]) >=
8626 std::get<0>(nonscalar_data_ranges[n_th_vector]),
8627 ExcLowerRange(std::get<1>(nonscalar_data_ranges[n_th_vector]),
8628 std::get<0>(nonscalar_data_ranges[n_th_vector])));
8630 std::get<1>(nonscalar_data_ranges[n_th_vector]) < n_data_sets,
8631 ExcIndexRange(std::get<1>(nonscalar_data_ranges[n_th_vector]),
8632 0,
8633 n_data_sets));
8634
8635 // Determine the vector name. Concatenate all the component names with
8636 // double underscores unless a vector name has been specified
8637 if (!std::get<2>(nonscalar_data_ranges[n_th_vector]).empty())
8638 {
8639 vector_name = std::get<2>(nonscalar_data_ranges[n_th_vector]);
8640 }
8641 else
8642 {
8643 vector_name = "";
8644 for (i = std::get<0>(nonscalar_data_ranges[n_th_vector]);
8645 i < std::get<1>(nonscalar_data_ranges[n_th_vector]);
8646 ++i)
8647 vector_name += data_names[i] + "__";
8648 vector_name +=
8649 data_names[std::get<1>(nonscalar_data_ranges[n_th_vector])];
8650 }
8651 }
8652 else
8653 {
8654 // One dimension
8655 pt_data_vector_dim = 1;
8656 vector_name = data_names[data_set];
8657 }
8658
8659 // Write data to the filter object
8660 filtered_data.write_data_set(vector_name,
8661 pt_data_vector_dim,
8662 data_set,
8663 data_vectors);
8664
8665 // Advance the current data set
8666 data_set += pt_data_vector_dim;
8667 }
8668}
8669
8670
8671
8672template <int dim, int spacedim>
8673void
8675 const DataOutBase::DataOutFilter &data_filter,
8676 const std::string &filename,
8677 const MPI_Comm comm) const
8678{
8680 get_patches(), data_filter, hdf5_flags, filename, comm);
8681}
8682
8683
8684
8685template <int dim, int spacedim>
8686void
8688 const DataOutBase::DataOutFilter &data_filter,
8689 const bool write_mesh_file,
8690 const std::string &mesh_filename,
8691 const std::string &solution_filename,
8692 const MPI_Comm comm) const
8693{
8695 data_filter,
8696 hdf5_flags,
8697 write_mesh_file,
8698 mesh_filename,
8699 solution_filename,
8700 comm);
8701}
8702
8703
8704
8705template <int dim, int spacedim>
8706void
8708 const std::vector<Patch<dim, spacedim>> &patches,
8709 const DataOutBase::DataOutFilter &data_filter,
8710 const DataOutBase::Hdf5Flags &flags,
8711 const std::string &filename,
8712 const MPI_Comm comm)
8713{
8715 patches, data_filter, flags, true, filename, filename, comm);
8716}
8717
8718
8719
8720template <int dim, int spacedim>
8721void
8723 const std::vector<Patch<dim, spacedim>> &patches,
8724 const DataOutBase::DataOutFilter &data_filter,
8725 const DataOutBase::Hdf5Flags &flags,
8726 const bool write_mesh_file,
8727 const std::string &mesh_filename,
8728 const std::string &solution_filename,
8729 const MPI_Comm comm)
8730{
8732 spacedim >= 2,
8733 ExcMessage(
8734 "DataOutBase was asked to write HDF5 output for a space dimension of 1. "
8735 "HDF5 only supports datasets that live in 2 or 3 dimensions."));
8736
8737#ifndef DEAL_II_WITH_HDF5
8738 // throw an exception, but first make sure the compiler does not warn about
8739 // the now unused function arguments
8740 (void)patches;
8741 (void)data_filter;
8742 (void)flags;
8743 (void)write_mesh_file;
8744 (void)mesh_filename;
8745 (void)solution_filename;
8746 (void)comm;
8747 AssertThrow(false, ExcNeedsHDF5());
8748#else
8749
8750 const unsigned int n_ranks = Utilities::MPI::n_mpi_processes(comm);
8751 (void)n_ranks;
8752
8753 // If HDF5 is not parallel and we're using multiple processes, abort:
8754# ifndef H5_HAVE_PARALLEL
8756 n_ranks <= 1,
8757 ExcMessage(
8758 "Serial HDF5 output on multiple processes is not yet supported."));
8759# endif
8760
8761 // Verify that there are indeed patches to be written out. most of
8762 // the times, people just forget to call build_patches when there
8763 // are no patches, so a warning is in order. That said, the
8764 // assertion is disabled if we run with more than one MPI rank,
8765 // since then it can happen that, on coarse meshes, a processor
8766 // simply has no cells it actually owns, and in that case it is
8767 // legit if there are no patches.
8768 Assert((patches.size() > 0) || (n_ranks > 1), ExcNoPatches());
8769
8770 // The HDF5 routines perform a bunch of collective calls that expect all
8771 // ranks to participate. One ranks without any patches we are missing
8772 // critical information, so rather than broadcasting that information, just
8773 // create a new communicator that only contains ranks with cells and
8774 // use that to perform the write operations:
8775 const bool have_patches = (patches.size() > 0);
8776 MPI_Comm split_comm;
8777 {
8778 const int key = Utilities::MPI::this_mpi_process(comm);
8779 const int color = (have_patches ? 1 : 0);
8780 const int ierr = MPI_Comm_split(comm, color, key, &split_comm);
8781 AssertThrowMPI(ierr);
8782 }
8783
8784 if (have_patches)
8785 {
8786 do_write_hdf5<dim, spacedim>(patches,
8787 data_filter,
8788 flags,
8789 write_mesh_file,
8790 mesh_filename,
8791 solution_filename,
8792 split_comm);
8793 }
8794
8795 const int ierr = MPI_Comm_free(&split_comm);
8796 AssertThrowMPI(ierr);
8797
8798#endif
8799}
8800
8801
8802
8803template <int dim, int spacedim>
8804void
8806 std::ostream &out,
8807 const DataOutBase::OutputFormat output_format_) const
8808{
8809 DataOutBase::OutputFormat output_format = output_format_;
8810 if (output_format == DataOutBase::default_format)
8811 output_format = default_fmt;
8812
8813 switch (output_format)
8814 {
8815 case DataOutBase::none:
8816 break;
8817
8818 case DataOutBase::dx:
8819 write_dx(out);
8820 break;
8821
8822 case DataOutBase::ucd:
8823 write_ucd(out);
8824 break;
8825
8827 write_gnuplot(out);
8828 break;
8829
8831 write_povray(out);
8832 break;
8833
8834 case DataOutBase::eps:
8835 write_eps(out);
8836 break;
8837
8838 case DataOutBase::gmv:
8839 write_gmv(out);
8840 break;
8841
8843 write_tecplot(out);
8844 break;
8845
8846 case DataOutBase::vtk:
8847 write_vtk(out);
8848 break;
8849
8850 case DataOutBase::vtu:
8851 write_vtu(out);
8852 break;
8853
8854 case DataOutBase::svg:
8855 write_svg(out);
8856 break;
8857
8860 break;
8861
8862 default:
8864 }
8865}
8866
8867
8868
8869template <int dim, int spacedim>
8870void
8877
8878template <int dim, int spacedim>
8879template <typename FlagType>
8880void
8882{
8883 if constexpr (std::is_same_v<FlagType, DataOutBase::DXFlags>)
8884 dx_flags = flags;
8885 else if constexpr (std::is_same_v<FlagType, DataOutBase::UcdFlags>)
8886 ucd_flags = flags;
8887 else if constexpr (std::is_same_v<FlagType, DataOutBase::PovrayFlags>)
8888 povray_flags = flags;
8889 else if constexpr (std::is_same_v<FlagType, DataOutBase::EpsFlags>)
8890 eps_flags = flags;
8891 else if constexpr (std::is_same_v<FlagType, DataOutBase::GmvFlags>)
8892 gmv_flags = flags;
8893 else if constexpr (std::is_same_v<FlagType, DataOutBase::Hdf5Flags>)
8894 hdf5_flags = flags;
8895 else if constexpr (std::is_same_v<FlagType, DataOutBase::TecplotFlags>)
8896 tecplot_flags = flags;
8897 else if constexpr (std::is_same_v<FlagType, DataOutBase::VtkFlags>)
8898 vtk_flags = flags;
8899 else if constexpr (std::is_same_v<FlagType, DataOutBase::SvgFlags>)
8900 svg_flags = flags;
8901 else if constexpr (std::is_same_v<FlagType, DataOutBase::GnuplotFlags>)
8902 gnuplot_flags = flags;
8903 else if constexpr (std::is_same_v<FlagType,
8906 else
8908}
8909
8910
8911
8912template <int dim, int spacedim>
8913std::string
8915 const DataOutBase::OutputFormat output_format) const
8916{
8917 if (output_format == DataOutBase::default_format)
8919 else
8920 return DataOutBase::default_suffix(output_format);
8921}
8922
8923
8924
8925template <int dim, int spacedim>
8926void
8928{
8929 prm.declare_entry("Output format",
8930 "gnuplot",
8932 "A name for the output format to be used");
8933 prm.declare_entry("Subdivisions",
8934 "1",
8936 "Number of subdivisions of each mesh cell");
8937
8938 prm.enter_subsection("DX output parameters");
8940 prm.leave_subsection();
8941
8942 prm.enter_subsection("UCD output parameters");
8944 prm.leave_subsection();
8945
8946 prm.enter_subsection("Gnuplot output parameters");
8948 prm.leave_subsection();
8949
8950 prm.enter_subsection("Povray output parameters");
8952 prm.leave_subsection();
8953
8954 prm.enter_subsection("Eps output parameters");
8956 prm.leave_subsection();
8957
8958 prm.enter_subsection("Gmv output parameters");
8960 prm.leave_subsection();
8961
8962 prm.enter_subsection("HDF5 output parameters");
8964 prm.leave_subsection();
8965
8966 prm.enter_subsection("Tecplot output parameters");
8968 prm.leave_subsection();
8969
8970 prm.enter_subsection("Vtk output parameters");
8972 prm.leave_subsection();
8973
8974
8975 prm.enter_subsection("deal.II intermediate output parameters");
8977 prm.leave_subsection();
8978}
8979
8980
8981
8982template <int dim, int spacedim>
8983void
8985{
8986 const std::string &output_name = prm.get("Output format");
8988 default_subdivisions = prm.get_integer("Subdivisions");
8989
8990 prm.enter_subsection("DX output parameters");
8991 dx_flags.parse_parameters(prm);
8992 prm.leave_subsection();
8993
8994 prm.enter_subsection("UCD output parameters");
8995 ucd_flags.parse_parameters(prm);
8996 prm.leave_subsection();
8997
8998 prm.enter_subsection("Gnuplot output parameters");
8999 gnuplot_flags.parse_parameters(prm);
9000 prm.leave_subsection();
9001
9002 prm.enter_subsection("Povray output parameters");
9003 povray_flags.parse_parameters(prm);
9004 prm.leave_subsection();
9005
9006 prm.enter_subsection("Eps output parameters");
9007 eps_flags.parse_parameters(prm);
9008 prm.leave_subsection();
9009
9010 prm.enter_subsection("Gmv output parameters");
9011 gmv_flags.parse_parameters(prm);
9012 prm.leave_subsection();
9013
9014 prm.enter_subsection("HDF5 output parameters");
9015 hdf5_flags.parse_parameters(prm);
9016 prm.leave_subsection();
9017
9018 prm.enter_subsection("Tecplot output parameters");
9019 tecplot_flags.parse_parameters(prm);
9020 prm.leave_subsection();
9021
9022 prm.enter_subsection("Vtk output parameters");
9023 vtk_flags.parse_parameters(prm);
9024 prm.leave_subsection();
9025
9026 prm.enter_subsection("deal.II intermediate output parameters");
9027 deal_II_intermediate_flags.parse_parameters(prm);
9028 prm.leave_subsection();
9029}
9030
9031
9032
9033template <int dim, int spacedim>
9034std::size_t
9050
9051
9052
9053template <int dim, int spacedim>
9054std::vector<
9055 std::tuple<unsigned int,
9056 unsigned int,
9057 std::string,
9060{
9061 return std::vector<
9062 std::tuple<unsigned int,
9063 unsigned int,
9064 std::string,
9066}
9067
9068
9069template <int dim, int spacedim>
9070void
9072{
9073 if constexpr (running_in_debug_mode())
9074 {
9075 {
9076 // Check that names for datasets are only used once. This is somewhat
9077 // complicated, because vector ranges might have a name or not.
9078 std::set<std::string> all_names;
9079
9080 const std::vector<
9081 std::tuple<unsigned int,
9082 unsigned int,
9083 std::string,
9085 ranges = this->get_nonscalar_data_ranges();
9086 const std::vector<std::string> data_names = this->get_dataset_names();
9087 const unsigned int n_data_sets = data_names.size();
9088 std::vector<bool> data_set_written(n_data_sets, false);
9089
9090 for (const auto &range : ranges)
9091 {
9092 const std::string &name = std::get<2>(range);
9093 if (!name.empty())
9094 {
9095 Assert(all_names.find(name) == all_names.end(),
9096 ExcMessage(
9097 "Error: names of fields in DataOut need to be unique, "
9098 "but '" +
9099 name + "' is used more than once."));
9100 all_names.insert(name);
9101 for (unsigned int i = std::get<0>(range);
9102 i <= std::get<1>(range);
9103 ++i)
9104 data_set_written[i] = true;
9105 }
9106 }
9107
9108 for (unsigned int data_set = 0; data_set < n_data_sets; ++data_set)
9109 if (data_set_written[data_set] == false)
9110 {
9111 const std::string &name = data_names[data_set];
9112 Assert(all_names.find(name) == all_names.end(),
9113 ExcMessage(
9114 "Error: names of fields in DataOut need to be unique, "
9115 "but '" +
9116 name + "' is used more than once."));
9117 all_names.insert(name);
9118 }
9119 }
9120 }
9121}
9122
9123
9124
9125// ---------------------------------------------- DataOutReader ----------
9126
9127template <int dim, int spacedim>
9128void
9130{
9131 AssertThrow(in.fail() == false, ExcIO());
9132
9133 // first empty previous content
9134 {
9135 std::vector<typename ::DataOutBase::Patch<dim, spacedim>> tmp;
9136 tmp.swap(patches);
9137 }
9138 {
9139 std::vector<std::string> tmp;
9140 tmp.swap(dataset_names);
9141 }
9142 {
9143 std::vector<
9144 std::tuple<unsigned int,
9145 unsigned int,
9146 std::string,
9148 tmp;
9149 tmp.swap(nonscalar_data_ranges);
9150 }
9151
9152 // then check that we have the correct header of this file. both the first and
9153 // second real lines have to match, as well as the dimension information
9154 // written before that and the Version information written in the third line
9155 {
9156 std::pair<unsigned int, unsigned int> dimension_info =
9158 AssertThrow((dimension_info.first == dim) &&
9159 (dimension_info.second == spacedim),
9161 dimension_info.first, dim, dimension_info.second, spacedim));
9162
9163 // read to the end of the line
9164 std::string tmp;
9165 getline(in, tmp);
9166 }
9167
9168 {
9169 std::string header;
9170 getline(in, header);
9171
9172 std::ostringstream s;
9173 s << "[deal.II intermediate format graphics data]";
9174
9175 Assert(header == s.str(), ExcUnexpectedInput(s.str(), header));
9176 }
9177 {
9178 std::string header;
9179 getline(in, header);
9180
9181 std::ostringstream s;
9182 s << "[written by " << DEAL_II_PACKAGE_NAME << " "
9183 << DEAL_II_PACKAGE_VERSION << "]";
9184
9185 Assert(header == s.str(), ExcUnexpectedInput(s.str(), header));
9186 }
9187 {
9188 std::string header;
9189 getline(in, header);
9190
9191 std::ostringstream s;
9192 s << "[Version: "
9194
9195 Assert(header == s.str(),
9196 ExcMessage(
9197 "Invalid or incompatible file format. Intermediate format "
9198 "files can only be read by the same deal.II version as they "
9199 "are written by."));
9200 }
9201
9202 // then read the rest of the data
9203 unsigned int n_datasets;
9204 in >> n_datasets;
9205 dataset_names.resize(n_datasets);
9206 for (unsigned int i = 0; i < n_datasets; ++i)
9207 in >> dataset_names[i];
9208
9209 unsigned int n_patches;
9210 in >> n_patches;
9211 patches.resize(n_patches);
9212 for (unsigned int i = 0; i < n_patches; ++i)
9213 in >> patches[i];
9214
9215 unsigned int n_nonscalar_data_ranges;
9216 in >> n_nonscalar_data_ranges;
9217 nonscalar_data_ranges.resize(n_nonscalar_data_ranges);
9218 for (unsigned int i = 0; i < n_nonscalar_data_ranges; ++i)
9219 {
9220 in >> std::get<0>(nonscalar_data_ranges[i]) >>
9221 std::get<1>(nonscalar_data_ranges[i]);
9222
9223 // read in the name of that vector range. because it is on a separate
9224 // line, we first need to read to the end of the previous line (nothing
9225 // should be there any more after we've read the previous two integers)
9226 // and then read the entire next line for the name
9227 std::string name;
9228 getline(in, name);
9229 getline(in, name);
9230 std::get<2>(nonscalar_data_ranges[i]) = name;
9231 }
9232
9233 AssertThrow(in.fail() == false, ExcIO());
9234}
9235
9236
9237
9238template <int dim, int spacedim>
9239void
9241{
9242 AssertThrow(in.fail() == false, ExcIO());
9243
9244 ParallelIntermediateHeader header;
9245 in.read(reinterpret_cast<char *>(&header), sizeof(header));
9247 header.magic == 0x00dea111,
9248 ExcMessage(
9249 "Invalid header of parallel deal.II intermediate format encountered."));
9252 ExcMessage(
9253 "Incorrect header version of parallel deal.II intermediate format."));
9254
9255 std::vector<std::uint64_t> chunk_sizes(header.n_ranks);
9256 in.read(reinterpret_cast<char *>(chunk_sizes.data()),
9257 header.n_ranks * sizeof(std::uint64_t));
9258
9259 for (unsigned int n = 0; n < header.n_ranks; ++n)
9260 {
9261 // First read the compressed data into temp_buffer and then
9262 // decompress and put into datastream
9263 std::vector<char> temp_buffer(chunk_sizes[n]);
9264 in.read(temp_buffer.data(), chunk_sizes[n]);
9265
9267 header.compression) !=
9270
9271 boost::iostreams::filtering_istreambuf f;
9272 if (static_cast<DataOutBase::CompressionLevel>(header.compression) !=
9274#ifdef DEAL_II_WITH_ZLIB
9275 f.push(boost::iostreams::zlib_decompressor());
9276#else
9278 false,
9279 ExcMessage(
9280 "Decompression requires deal.II to be configured with ZLIB support."));
9281#endif
9282
9283 boost::iostreams::basic_array_source<char> source(temp_buffer.data(),
9284 temp_buffer.size());
9285 f.push(source);
9286
9287 std::stringstream datastream;
9288 boost::iostreams::copy(f, datastream);
9289
9290 // Now we can load the data and merge this chunk into *this
9291 if (n == 0)
9292 {
9293 read(datastream);
9294 }
9295 else
9296 {
9297 DataOutReader<dim, spacedim> temp_reader;
9298 temp_reader.read(datastream);
9299 merge(temp_reader);
9300 }
9301 }
9302}
9303
9304
9305
9306template <int dim, int spacedim>
9307void
9309{
9310 using Patch = typename ::DataOutBase::Patch<dim, spacedim>;
9311
9312
9313 const std::vector<Patch> &source_patches = source.get_patches();
9315 Assert(source_patches.size() != 0, DataOutBase::ExcNoPatches());
9316 // check equality of component names
9319
9320 // check equality of the vector data specifications
9322 source.get_nonscalar_data_ranges().size(),
9323 ExcMessage("Both sources need to declare the same components "
9324 "as vectors."));
9325 for (unsigned int i = 0; i < get_nonscalar_data_ranges().size(); ++i)
9326 {
9327 Assert(std::get<0>(get_nonscalar_data_ranges()[i]) ==
9328 std::get<0>(source.get_nonscalar_data_ranges()[i]),
9329 ExcMessage("Both sources need to declare the same components "
9330 "as vectors."));
9331 Assert(std::get<1>(get_nonscalar_data_ranges()[i]) ==
9332 std::get<1>(source.get_nonscalar_data_ranges()[i]),
9333 ExcMessage("Both sources need to declare the same components "
9334 "as vectors."));
9335 Assert(std::get<2>(get_nonscalar_data_ranges()[i]) ==
9336 std::get<2>(source.get_nonscalar_data_ranges()[i]),
9337 ExcMessage("Both sources need to declare the same components "
9338 "as vectors."));
9339 }
9340
9341 // make sure patches are compatible
9342 Assert(patches[0].n_subdivisions == source_patches[0].n_subdivisions,
9344 Assert(patches[0].data.n_rows() == source_patches[0].data.n_rows(),
9346 Assert(patches[0].data.n_cols() == source_patches[0].data.n_cols(),
9348
9349 // merge patches. store old number of elements, since we need to adjust patch
9350 // numbers, etc afterwards
9351 const unsigned int old_n_patches = patches.size();
9352 patches.insert(patches.end(), source_patches.begin(), source_patches.end());
9353
9354 // adjust patch numbers
9355 for (unsigned int i = old_n_patches; i < patches.size(); ++i)
9356 patches[i].patch_index += old_n_patches;
9357
9358 // adjust patch neighbors
9359 for (unsigned int i = old_n_patches; i < patches.size(); ++i)
9360 for (const unsigned int n : GeometryInfo<dim>::face_indices())
9361 if (patches[i].neighbors[n] !=
9363 patches[i].neighbors[n] += old_n_patches;
9364}
9365
9366
9367
9368template <int dim, int spacedim>
9369const std::vector<typename ::DataOutBase::Patch<dim, spacedim>> &
9374
9375
9376
9377template <int dim, int spacedim>
9378std::vector<std::string>
9383
9384
9385
9386template <int dim, int spacedim>
9387std::vector<
9388 std::tuple<unsigned int,
9389 unsigned int,
9390 std::string,
9396
9397
9398
9399// ---------------------------------------------- XDMFEntry ----------
9400
9402 : valid(false)
9403 , h5_sol_filename("")
9404 , h5_mesh_filename("")
9405 , entry_time(0.0)
9406 , num_nodes(numbers::invalid_unsigned_int)
9407 , num_cells(numbers::invalid_unsigned_int)
9408 , dimension(numbers::invalid_unsigned_int)
9409 , space_dimension(numbers::invalid_unsigned_int)
9410 , cell_type()
9411{}
9412
9413
9414
9415XDMFEntry::XDMFEntry(const std::string &filename,
9416 const double time,
9417 const std::uint64_t nodes,
9418 const std::uint64_t cells,
9419 const unsigned int dim,
9420 const ReferenceCell &cell_type)
9421 : XDMFEntry(filename, filename, time, nodes, cells, dim, dim, cell_type)
9422{}
9423
9424
9425
9426XDMFEntry::XDMFEntry(const std::string &mesh_filename,
9427 const std::string &solution_filename,
9428 const double time,
9429 const std::uint64_t nodes,
9430 const std::uint64_t cells,
9431 const unsigned int dim,
9432 const ReferenceCell &cell_type)
9433 : XDMFEntry(mesh_filename,
9434 solution_filename,
9435 time,
9436 nodes,
9437 cells,
9438 dim,
9439 dim,
9440 cell_type)
9441{}
9442
9443
9444
9445namespace
9446{
9452 cell_type_hex_if_invalid(const ReferenceCell &cell_type,
9453 const unsigned int dimension)
9454 {
9455 if (cell_type == ReferenceCells::Invalid)
9456 {
9457 switch (dimension)
9458 {
9459 case 0:
9461 case 1:
9463 case 2:
9465 case 3:
9467 default:
9468 AssertThrow(false, ExcMessage("Invalid dimension"));
9469 }
9470 }
9471 else
9472 return cell_type;
9473 }
9474} // namespace
9475
9476
9477
9478XDMFEntry::XDMFEntry(const std::string &mesh_filename,
9479 const std::string &solution_filename,
9480 const double time,
9481 const std::uint64_t nodes,
9482 const std::uint64_t cells,
9483 const unsigned int dim,
9484 const unsigned int spacedim,
9485 const ReferenceCell &cell_type_)
9486 : valid(true)
9487 , h5_sol_filename(solution_filename)
9488 , h5_mesh_filename(mesh_filename)
9489 , entry_time(time)
9490 , num_nodes(nodes)
9491 , num_cells(cells)
9492 , dimension(dim)
9493 , space_dimension(spacedim)
9494 , cell_type(cell_type_hex_if_invalid(cell_type_, dim))
9495{}
9496
9497
9498
9499void
9500XDMFEntry::add_attribute(const std::string &attr_name,
9501 const unsigned int dimension)
9502{
9503 attribute_dims[attr_name] = dimension;
9504}
9505
9506
9507
9508namespace
9509{
9513 std::string
9514 indent(const unsigned int indent_level)
9515 {
9516 std::string res = "";
9517 for (unsigned int i = 0; i < indent_level; ++i)
9518 res += " ";
9519 return res;
9520 }
9521} // namespace
9522
9523
9524
9525std::string
9526XDMFEntry::get_xdmf_content(const unsigned int indent_level) const
9527{
9528 if (!valid)
9529 return "";
9530
9531 std::stringstream ss;
9532 ss.precision(12);
9533 ss << indent(indent_level + 0)
9534 << "<Grid Name=\"mesh\" GridType=\"Uniform\">\n";
9535 ss << indent(indent_level + 1) << "<Time Value=\"" << entry_time << "\"/>\n";
9536 ss << indent(indent_level + 1) << "<Geometry GeometryType=\""
9537 << (space_dimension <= 2 ? "XY" : "XYZ") << "\">\n";
9538 ss << indent(indent_level + 2) << "<DataItem Dimensions=\"" << num_nodes
9539 << " " << (space_dimension <= 2 ? 2 : space_dimension)
9540 << "\" NumberType=\"Float\" Precision=\"8\" Format=\"HDF\">\n";
9541 ss << indent(indent_level + 3) << h5_mesh_filename << ":/nodes\n";
9542 ss << indent(indent_level + 2) << "</DataItem>\n";
9543 ss << indent(indent_level + 1) << "</Geometry>\n";
9544
9545 // If we have cells defined, use the topology corresponding to the dimension
9546 if (num_cells > 0)
9547 {
9548 ss << indent(indent_level + 1) << "<Topology TopologyType=\"";
9549
9550 if (dimension == 0)
9551 {
9552 ss << "Polyvertex";
9553 }
9554 else if (dimension == 1)
9555 {
9556 ss << "Polyline";
9557 }
9558 else if (dimension == 2)
9559 {
9563
9565 {
9566 ss << "Quadrilateral";
9567 }
9568 else // if (cell_type == ReferenceCells::Triangle)
9569 {
9570 ss << "Triangle";
9571 }
9572 }
9573 else if (dimension == 3)
9574 {
9578
9580 {
9581 ss << "Hexahedron";
9582 }
9583 else // if (reference_cell == ReferenceCells::Tetrahedron)
9584 {
9585 ss << "Tetrahedron";
9586 }
9587 }
9588
9589 ss << "\" NumberOfElements=\"" << num_cells;
9590 if (dimension == 0)
9591 ss << "\" NodesPerElement=\"1\">\n";
9592 else if (dimension == 1)
9593 ss << "\" NodesPerElement=\"2\">\n";
9594 else
9595 // no "NodesPerElement" for dimension 2 and higher
9596 ss << "\">\n";
9597
9598 ss << indent(indent_level + 2) << "<DataItem Dimensions=\"" << num_cells
9599 << " " << cell_type.n_vertices()
9600 << "\" NumberType=\"UInt\" Format=\"HDF\">\n";
9601
9602 ss << indent(indent_level + 3) << h5_mesh_filename << ":/cells\n";
9603 ss << indent(indent_level + 2) << "</DataItem>\n";
9604 ss << indent(indent_level + 1) << "</Topology>\n";
9605 }
9606 // Otherwise, we assume the points are isolated in space and use a Polyvertex
9607 // topology
9608 else
9609 {
9610 ss << indent(indent_level + 1)
9611 << "<Topology TopologyType=\"Polyvertex\" NumberOfElements=\""
9612 << num_nodes << "\">\n";
9613 ss << indent(indent_level + 1) << "</Topology>\n";
9614 }
9615
9616 for (const auto &attribute_dim : attribute_dims)
9617 {
9618 ss << indent(indent_level + 1) << "<Attribute Name=\""
9619 << attribute_dim.first << "\" AttributeType=\""
9620 << (attribute_dim.second > 1 ? "Vector" : "Scalar")
9621 << "\" Center=\"Node\">\n";
9622 // Vectors must have 3 elements even for 2d models
9623 ss << indent(indent_level + 2) << "<DataItem Dimensions=\"" << num_nodes
9624 << " " << (attribute_dim.second > 1 ? 3 : 1)
9625 << "\" NumberType=\"Float\" Precision=\"8\" Format=\"HDF\">\n";
9626 ss << indent(indent_level + 3) << h5_sol_filename << ":/"
9627 << attribute_dim.first << '\n';
9628 ss << indent(indent_level + 2) << "</DataItem>\n";
9629 ss << indent(indent_level + 1) << "</Attribute>\n";
9630 }
9631
9632 ss << indent(indent_level + 0) << "</Grid>\n";
9633
9634 return ss.str();
9635}
9636
9637
9638
9639namespace DataOutBase
9640{
9641 template <int dim, int spacedim>
9642 std::ostream &
9643 operator<<(std::ostream &out, const Patch<dim, spacedim> &patch)
9644 {
9645 // write a header line
9646 out << "[deal.II intermediate Patch<" << dim << ',' << spacedim << ">]"
9647 << '\n';
9648
9649 // First export what kind of reference cell we are looking at:
9650 out << patch.reference_cell << '\n';
9651
9652 // then write all the data that is in this patch
9653 for (const unsigned int i : patch.reference_cell.vertex_indices())
9654 out << patch.vertices[i] << ' ';
9655 out << '\n';
9656
9657 for (const unsigned int i : patch.reference_cell.face_indices())
9658 out << patch.neighbors[i] << ' ';
9659 out << '\n';
9660
9661 out << patch.patch_index << ' ' << patch.n_subdivisions << '\n';
9662
9663 out << patch.points_are_available << '\n';
9664
9665 out << patch.data.n_rows() << ' ' << patch.data.n_cols() << '\n';
9666 for (unsigned int i = 0; i < patch.data.n_rows(); ++i)
9667 for (unsigned int j = 0; j < patch.data.n_cols(); ++j)
9668 out << patch.data[i][j] << ' ';
9669 out << '\n';
9670 out << '\n';
9671
9672 return out;
9673 }
9674
9675
9676
9677 template <int dim, int spacedim>
9678 std::istream &
9679 operator>>(std::istream &in, Patch<dim, spacedim> &patch)
9680 {
9681 AssertThrow(in.fail() == false, ExcIO());
9682
9683 // read a header line and compare it to what we usually write. skip all
9684 // lines that contain only blanks at the start
9685 {
9686 std::string header;
9687 do
9688 {
9689 getline(in, header);
9690 while ((header.size() != 0) && (header.back() == ' '))
9691 header.erase(header.size() - 1);
9692 }
9693 while ((header.empty()) && in);
9694
9695 std::ostringstream s;
9696 s << "[deal.II intermediate Patch<" << dim << ',' << spacedim << ">]";
9697
9698 Assert(header == s.str(), ExcUnexpectedInput(s.str(), header));
9699 }
9700
9701 // First import what kind of reference cell we are looking at:
9702 if constexpr (dim > 0)
9703 in >> patch.reference_cell;
9704
9705 // then read all the data that is in this patch
9706 for (const unsigned int i : patch.reference_cell.vertex_indices())
9707 in >> patch.vertices[i];
9708
9709 for (const unsigned int i : patch.reference_cell.face_indices())
9710 in >> patch.neighbors[i];
9711
9712 in >> patch.patch_index;
9713
9714 // If dim>1, we also need to set the number of subdivisions, whereas
9715 // in dim==1, this is a const variable equal to one that can't be changed.
9716 unsigned int n_subdivisions;
9717 in >> n_subdivisions;
9718 if constexpr (dim > 1)
9720
9721 in >> patch.points_are_available;
9722
9723 unsigned int n_rows, n_cols;
9724 in >> n_rows >> n_cols;
9725 patch.data.reinit(n_rows, n_cols);
9726 for (unsigned int i = 0; i < patch.data.n_rows(); ++i)
9727 for (unsigned int j = 0; j < patch.data.n_cols(); ++j)
9728 in >> patch.data[i][j];
9729
9730 AssertThrow(in.fail() == false, ExcIO());
9731
9732 return in;
9733 }
9734} // namespace DataOutBase
9735
9736
9737
9738// explicit instantiations
9739#include "base/data_out_base.inst"
9740
const double * get_data_set(const unsigned int set_num) const
std::map< unsigned int, unsigned int > filtered_points
std::string get_data_set_name(const unsigned int set_num) const
void internal_add_cell(const unsigned int cell_index, const unsigned int pt_index)
void write_cell(const unsigned int index, const unsigned int start, const std::array< unsigned int, dim > &offsets)
std::vector< unsigned int > data_set_dims
unsigned int n_nodes() const
void fill_node_data(std::vector< double > &node_data) const
std::vector< std::vector< double > > data_sets
unsigned int get_data_set_dim(const unsigned int set_num) const
void write_data_set(const std::string &name, const unsigned int dimension, const unsigned int set_num, const Table< 2, double > &data_vectors)
std::map< unsigned int, unsigned int > filtered_cells
void write_cell_single(const unsigned int index, const unsigned int start, const unsigned int n_points, const ReferenceCell &reference_cell)
std::vector< std::string > data_set_names
void fill_cell_data(const unsigned int local_node_offset, std::vector< unsigned int > &cell_data) const
void write_point(const unsigned int index, const Point< dim > &p)
unsigned int n_cells() const
DataOutBase::DataOutFilterFlags flags
unsigned int n_data_sets() const
XDMFEntry create_xdmf_entry(const DataOutBase::DataOutFilter &data_filter, const std::string &h5_filename, const double cur_time, const MPI_Comm comm) const
virtual std::vector< std::tuple< unsigned int, unsigned int, std::string, DataComponentInterpretation::DataComponentInterpretation > > get_nonscalar_data_ranges() const
unsigned int default_subdivisions
void parse_parameters(ParameterHandler &prm)
DataOutBase::Deal_II_IntermediateFlags deal_II_intermediate_flags
void write_filtered_data(DataOutBase::DataOutFilter &filtered_data) const
void write_pvtu_record(std::ostream &out, const std::vector< std::string > &piece_names) const
static void declare_parameters(ParameterHandler &prm)
virtual std::vector< std::string > get_dataset_names() const =0
DataOutBase::TecplotFlags tecplot_flags
void write_ucd(std::ostream &out) const
void write_povray(std::ostream &out) const
std::string default_suffix(const DataOutBase::OutputFormat output_format=DataOutBase::default_format) const
void write_xdmf_file(const std::vector< XDMFEntry > &entries, const std::string &filename, const MPI_Comm comm) const
DataOutBase::GmvFlags gmv_flags
std::size_t memory_consumption() const
void set_default_format(const DataOutBase::OutputFormat default_format)
DataOutBase::Hdf5Flags hdf5_flags
DataOutBase::PovrayFlags povray_flags
DataOutBase::UcdFlags ucd_flags
void write(std::ostream &out, const DataOutBase::OutputFormat output_format=DataOutBase::default_format) const
DataOutBase::OutputFormat default_fmt
DataOutBase::GnuplotFlags gnuplot_flags
void write_gnuplot(std::ostream &out) const
void write_vtu(std::ostream &out) const
void write_hdf5_parallel(const DataOutBase::DataOutFilter &data_filter, const std::string &filename, const MPI_Comm comm) const
void write_tecplot(std::ostream &out) const
void write_deal_II_intermediate_in_parallel(const std::string &filename, const MPI_Comm comm, const DataOutBase::CompressionLevel compression) const
void write_svg(std::ostream &out) const
void write_vtu_in_parallel(const std::string &filename, const MPI_Comm comm) const
DataOutBase::SvgFlags svg_flags
void validate_dataset_names() const
void set_flags(const FlagType &flags)
void write_vtk(std::ostream &out) const
virtual const std::vector< DataOutBase::Patch< dim, spacedim > > & get_patches() const =0
DataOutBase::VtkFlags vtk_flags
void write_gmv(std::ostream &out) const
std::string write_vtu_with_pvtu_record(const std::string &directory, const std::string &filename_without_extension, const unsigned int counter, const MPI_Comm mpi_communicator, const unsigned int n_digits_for_counter=numbers::invalid_unsigned_int, const unsigned int n_groups=0) const
DataOutBase::EpsFlags eps_flags
void write_eps(std::ostream &out) const
DataOutBase::DXFlags dx_flags
void write_dx(std::ostream &out) const
void write_deal_II_intermediate(std::ostream &out) const
void merge(const DataOutReader< dim, spacedim > &other)
void read_whole_parallel_file(std::istream &in)
std::vector< std::tuple< unsigned int, unsigned int, std::string, DataComponentInterpretation::DataComponentInterpretation > > nonscalar_data_ranges
virtual const std::vector<::DataOutBase::Patch< dim, spacedim > > & get_patches() const override
void read(std::istream &in)
virtual std::vector< std::tuple< unsigned int, unsigned int, std::string, DataComponentInterpretation::DataComponentInterpretation > > get_nonscalar_data_ranges() const override
virtual std::vector< std::string > get_dataset_names() const override
std::vector< std::string > dataset_names
std::vector<::DataOutBase::Patch< dim, spacedim > > patches
void enter_subsection(const std::string &subsection, const bool create_path_if_needed=true)
long int get_integer(const std::string &entry_string) const
bool get_bool(const std::string &entry_name) const
void declare_entry(const std::string &entry, const std::string &default_value, const Patterns::PatternBase &pattern=Patterns::Anything(), const std::string &documentation="", const bool has_to_be_set=false)
std::string get(const std::string &entry_string) const
double get_double(const std::string &entry_name) const
Definition point.h:113
std_cxx20::ranges::iota_view< unsigned int, unsigned int > vertex_indices() const
unsigned int n_vertices() const
bool is_hyper_cube() const
unsigned int vtk_linear_type() const
unsigned int vtk_vertex_to_deal_vertex(const unsigned int vertex_index) const
unsigned int vtk_quadratic_type() const
unsigned int vtk_lagrange_type() const
bool is_simplex() const
std_cxx20::ranges::iota_view< unsigned int, unsigned int > face_indices() const
static constexpr TableIndices< rank_ > unrolled_to_component_indices(const unsigned int i)
std::vector< RT > return_values()
internal::return_value< RT >::reference_type return_value()
ReferenceCell cell_type
std::uint64_t num_nodes
unsigned int dimension
std::string h5_sol_filename
double entry_time
std::string h5_mesh_filename
std::string get_xdmf_content(const unsigned int indent_level) const
void add_attribute(const std::string &attr_name, const unsigned int dimension)
std::uint64_t num_cells
std::map< std::string, unsigned int > attribute_dims
unsigned int space_dimension
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:40
#define DEAL_II_PACKAGE_VERSION
Definition config.h:29
constexpr bool running_in_debug_mode()
Definition config.h:78
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:41
#define DEAL_II_FALLTHROUGH
Definition config.h:273
#define DEAL_II_PACKAGE_NAME
Definition config.h:27
std::ostream & operator<<(std::ostream &out, const DerivativeForm< order, dim, spacedim, Number > &df)
const unsigned int DoFAccessor< structdim, dim, spacedim, level_dof_access >::space_dimension
const unsigned int DoFAccessor< structdim, dim, spacedim, level_dof_access >::dimension
#define DEAL_II_ASSERT_UNREACHABLE()
#define DEAL_II_NOT_IMPLEMENTED()
static ::ExceptionBase & ExcIO()
static ::ExceptionBase & ExcIncompatiblePatchLists()
static ::ExceptionBase & ExcFileNotOpen(std::string arg1)
static ::ExceptionBase & ExcNotEnoughSpaceDimensionLabels()
static ::ExceptionBase & ExcNotImplemented()
#define Assert(cond, exc)
static ::ExceptionBase & ExcNoPatches()
#define DeclException2(Exception2, type1, type2, outsequence)
#define AssertDimension(dim1, dim2)
static ::ExceptionBase & ExcLowerRange(int arg1, int arg2)
#define AssertThrowMPI(error_code)
static ::ExceptionBase & ExcIncompatibleDimensions(int arg1, int arg2, int arg3, int arg4)
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcNeedsHDF5()
static ::ExceptionBase & ExcIndexRange(std::size_t arg1, std::size_t arg2, std::size_t arg3)
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
static ::ExceptionBase & ExcNotInitialized()
static ::ExceptionBase & ExcIncompatibleDatasetNames()
static ::ExceptionBase & ExcInvalidDatasetSize(int arg1, int arg2)
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
Task< RT > new_task(const std::function< RT()> &function)
void write_eps(const std::vector< Patch< 2, spacedim > > &patches, const std::vector< std::string > &data_names, const std::vector< std::tuple< unsigned int, unsigned int, std::string, DataComponentInterpretation::DataComponentInterpretation > > &nonscalar_data_ranges, const EpsFlags &flags, std::ostream &out)
std::pair< unsigned int, unsigned int > determine_intermediate_format_dimensions(std::istream &input)
std::ostream & operator<<(std::ostream &out, const Patch< dim, spacedim > &patch)
void write_nodes(const std::vector< Patch< dim, spacedim > > &patches, StreamType &out)
void write_deal_II_intermediate_in_parallel(const std::vector< Patch< dim, spacedim > > &patches, const std::vector< std::string > &data_names, const std::vector< std::tuple< unsigned int, unsigned int, std::string, DataComponentInterpretation::DataComponentInterpretation > > &nonscalar_data_ranges, const Deal_II_IntermediateFlags &flags, const std::string &filename, const MPI_Comm comm, const CompressionLevel compression)
void write_ucd(const std::vector< Patch< dim, spacedim > > &patches, const std::vector< std::string > &data_names, const std::vector< std::tuple< unsigned int, unsigned int, std::string, DataComponentInterpretation::DataComponentInterpretation > > &nonscalar_data_ranges, const UcdFlags &flags, std::ostream &out)
void write_dx(const std::vector< Patch< dim, spacedim > > &patches, const std::vector< std::string > &data_names, const std::vector< std::tuple< unsigned int, unsigned int, std::string, DataComponentInterpretation::DataComponentInterpretation > > &nonscalar_data_ranges, const DXFlags &flags, std::ostream &out)
void write_vtu_header(std::ostream &out, const VtkFlags &flags)
void write_vtu(const std::vector< Patch< dim, spacedim > > &patches, const std::vector< std::string > &data_names, const std::vector< std::tuple< unsigned int, unsigned int, std::string, DataComponentInterpretation::DataComponentInterpretation > > &nonscalar_data_ranges, const VtkFlags &flags, std::ostream &out)
void write_gmv(const std::vector< Patch< dim, spacedim > > &patches, const std::vector< std::string > &data_names, const std::vector< std::tuple< unsigned int, unsigned int, std::string, DataComponentInterpretation::DataComponentInterpretation > > &nonscalar_data_ranges, const GmvFlags &flags, std::ostream &out)
const unsigned int Patch< 0, spacedim >::n_subdivisions
void write_data(const std::vector< Patch< dim, spacedim > > &patches, unsigned int n_data_sets, const bool double_precision, StreamType &out)
void write_vtu_main(const std::vector< Patch< dim, spacedim > > &patches, const std::vector< std::string > &data_names, const std::vector< std::tuple< unsigned int, unsigned int, std::string, DataComponentInterpretation::DataComponentInterpretation > > &nonscalar_data_ranges, const VtkFlags &flags, std::ostream &out)
const ReferenceCell Patch< 0, spacedim >::reference_cell
void write_pvd_record(std::ostream &out, const std::vector< std::pair< double, std::string > > &times_and_names)
void write_deal_II_intermediate(const std::vector< Patch< dim, spacedim > > &patches, const std::vector< std::string > &data_names, const std::vector< std::tuple< unsigned int, unsigned int, std::string, DataComponentInterpretation::DataComponentInterpretation > > &nonscalar_data_ranges, const Deal_II_IntermediateFlags &flags, std::ostream &out)
void write_vtu_footer(std::ostream &out)
void write_cells(const std::vector< Patch< dim, spacedim > > &patches, StreamType &out)
void write_tecplot(const std::vector< Patch< dim, spacedim > > &patches, const std::vector< std::string > &data_names, const std::vector< std::tuple< unsigned int, unsigned int, std::string, DataComponentInterpretation::DataComponentInterpretation > > &nonscalar_data_ranges, const TecplotFlags &flags, std::ostream &out)
void write_filtered_data(const std::vector< Patch< dim, spacedim > > &patches, const std::vector< std::string > &data_names, const std::vector< std::tuple< unsigned int, unsigned int, std::string, DataComponentInterpretation::DataComponentInterpretation > > &nonscalar_data_ranges, DataOutFilter &filtered_data)
OutputFormat parse_output_format(const std::string &format_name)
std::vector< Point< spacedim > > get_node_positions(const std::vector< Patch< dim, spacedim > > &patches)
void write_hdf5_parallel(const std::vector< Patch< dim, spacedim > > &patches, const DataOutFilter &data_filter, const DataOutBase::Hdf5Flags &flags, const std::string &filename, const MPI_Comm comm)
std::istream & operator>>(std::istream &in, Patch< dim, spacedim > &patch)
std::string get_output_format_names()
void write_svg(const std::vector< Patch< 2, spacedim > > &patches, const std::vector< std::string > &data_names, const std::vector< std::tuple< unsigned int, unsigned int, std::string, DataComponentInterpretation::DataComponentInterpretation > > &nonscalar_data_ranges, const SvgFlags &flags, std::ostream &out)
void write_visit_record(std::ostream &out, const std::vector< std::string > &piece_names)
void write_high_order_cells(const std::vector< Patch< dim, spacedim > > &patches, StreamType &out, const bool legacy_format)
std::string default_suffix(const OutputFormat output_format)
void write_povray(const std::vector< Patch< dim, spacedim > > &patches, const std::vector< std::string > &data_names, const std::vector< std::tuple< unsigned int, unsigned int, std::string, DataComponentInterpretation::DataComponentInterpretation > > &nonscalar_data_ranges, const PovrayFlags &flags, std::ostream &out)
void write_gnuplot(const std::vector< Patch< dim, spacedim > > &patches, const std::vector< std::string > &data_names, const std::vector< std::tuple< unsigned int, unsigned int, std::string, DataComponentInterpretation::DataComponentInterpretation > > &nonscalar_data_ranges, const GnuplotFlags &flags, std::ostream &out)
void write_vtk(const std::vector< Patch< dim, spacedim > > &patches, const std::vector< std::string > &data_names, const std::vector< std::tuple< unsigned int, unsigned int, std::string, DataComponentInterpretation::DataComponentInterpretation > > &nonscalar_data_ranges, const VtkFlags &flags, std::ostream &out)
void write_pvtu_record(std::ostream &out, const std::vector< std::string > &piece_names, const std::vector< std::string > &data_names, const std::vector< std::tuple< unsigned int, unsigned int, std::string, DataComponentInterpretation::DataComponentInterpretation > > &nonscalar_data_ranges, const VtkFlags &flags)
constexpr char A
double norm(const FEValuesBase< dim > &fe, const ArrayView< const std::vector< Tensor< 1, dim > > > &Du)
Definition divergence.h:471
std::enable_if_t< std::is_fundamental_v< T >, std::size_t > memory_consumption(const T &t)
Point< spacedim > point(const gp_Pnt &p, const double tolerance=1e-10)
Definition utilities.cc:193
SymmetricTensor< 2, dim, Number > e(const Tensor< 2, dim, Number > &F)
SymmetricTensor< 2, dim, Number > b(const Tensor< 2, dim, Number > &F)
SymmetricTensor< 2, dim, Number > d(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
constexpr ReferenceCell Triangle
constexpr ReferenceCell Hexahedron
constexpr ReferenceCell Pyramid
constexpr ReferenceCell Wedge
constexpr ReferenceCell Vertex
constexpr const ReferenceCell & get_hypercube()
constexpr ReferenceCell Invalid
constexpr ReferenceCell Quadrilateral
constexpr ReferenceCell Tetrahedron
constexpr const ReferenceCell & get_simplex()
constexpr ReferenceCell Line
int File_write_at_c(MPI_File fh, MPI_Offset offset, const void *buf, MPI_Count count, MPI_Datatype datatype, MPI_Status *status)
int File_write_at_all_c(MPI_File fh, MPI_Offset offset, const void *buf, MPI_Count count, MPI_Datatype datatype, MPI_Status *status)
T sum(const T &t, const MPI_Comm mpi_communicator)
unsigned int n_mpi_processes(const MPI_Comm mpi_communicator)
Definition mpi.cc:105
unsigned int this_mpi_process(const MPI_Comm mpi_communicator)
Definition mpi.cc:120
const MPI_Datatype mpi_type_id_for_type
Definition mpi.h:1662
void free_communicator(MPI_Comm mpi_communicator)
Definition mpi.cc:167
std::string get_time()
std::string get_date()
std::size_t pack(const T &object, std::vector< char > &dest_buffer, const bool allow_compression=true)
Definition utilities.h:1382
std::string encode_base64(const std::vector< unsigned char > &binary_input)
Definition utilities.cc:427
constexpr T fixed_power(const T t)
Definition utilities.h:943
std::string int_to_string(const unsigned int value, const unsigned int digits=numbers::invalid_unsigned_int)
Definition utilities.cc:466
T unpack(const std::vector< char > &buffer, const bool allow_compression=true)
Definition utilities.h:1539
unsigned int needed_digits(const unsigned int max_number)
Definition utilities.cc:561
constexpr T pow(const T base, const int iexp)
Definition utilities.h:967
unsigned int n_cells(const internal::TriangulationImplementation::NumberCache< 1 > &c)
Definition tria.cc:14906
constexpr double PI
Definition numbers.h:239
constexpr unsigned int invalid_unsigned_int
Definition types.h:238
::VectorizedArray< Number, width > min(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > max(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > cos(const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > sin(const ::VectorizedArray< Number, width > &)
unsigned int global_dof_index
Definition types.h:94
*braid_SplitCommworld & comm
void parse_parameters(const ParameterHandler &prm)
DXFlags(const bool write_neighbors=false, const bool int_binary=false, const bool coordinates_binary=false, const bool data_binary=false)
static void declare_parameters(ParameterHandler &prm)
static void declare_parameters(ParameterHandler &prm)
void parse_parameters(const ParameterHandler &prm)
DataOutFilterFlags(const bool filter_duplicate_vertices=false, const bool xdmf_hdf5_output=false)
static const unsigned int format_version
RgbValues(*)(const double value, const double min_value, const double max_value) ColorFunction
static void declare_parameters(ParameterHandler &prm)
static RgbValues default_color_function(const double value, const double min_value, const double max_value)
void parse_parameters(const ParameterHandler &prm)
ColorFunction color_function
static RgbValues grey_scale_color_function(const double value, const double min_value, const double max_value)
EpsFlags(const unsigned int height_vector=0, const unsigned int color_vector=0, const SizeType size_type=width, const unsigned int size=300, const double line_width=0.5, const double azimut_angle=60, const double turn_angle=30, const double z_scaling=1.0, const bool draw_mesh=true, const bool draw_cells=true, const bool shade_cells=true, const ColorFunction color_function=&default_color_function)
unsigned int color_vector
static RgbValues reverse_grey_scale_color_function(const double value, const double min_value, const double max_value)
@ width
Scale to given width.
@ height
Scale to given height.
unsigned int height_vector
std::vector< std::string > space_dimension_labels
std::size_t memory_consumption() const
DataOutBase::CompressionLevel compression_level
Hdf5Flags(const CompressionLevel compression_level=CompressionLevel::best_speed)
static void declare_parameters(ParameterHandler &prm)
static const unsigned int no_neighbor
std::size_t memory_consumption() const
unsigned int patch_index
ReferenceCell reference_cell
Table< 2, float > data
static const unsigned int no_neighbor
bool operator==(const Patch &patch) const
void swap(Patch< dim, spacedim > &other_patch) noexcept
static const unsigned int space_dim
std::array< Point< spacedim >, GeometryInfo< dim >::vertices_per_cell > vertices
std::array< unsigned int, GeometryInfo< dim >::faces_per_cell > neighbors
static void declare_parameters(ParameterHandler &prm)
PovrayFlags(const bool smooth=false, const bool bicubic_patch=false, const bool external_data=false)
void parse_parameters(const ParameterHandler &prm)
SvgFlags(const unsigned int height_vector=0, const int azimuth_angle=37, const int polar_angle=45, const unsigned int line_thickness=1, const bool margin=true, const bool draw_colorbar=true)
unsigned int line_thickness
std::size_t memory_consumption() const
TecplotFlags(const char *zone_name=nullptr, const double solution_time=-1.0)
void parse_parameters(const ParameterHandler &prm)
static void declare_parameters(ParameterHandler &prm)
UcdFlags(const bool write_preamble=false)
VtkFlags(const double time=std::numeric_limits< double >::min(), const unsigned int cycle=std::numeric_limits< unsigned int >::min(), const bool print_date_and_time=true, const CompressionLevel compression_level=CompressionLevel::best_speed, const bool write_higher_order_cells=false, const std::map< std::string, std::string > &physical_units={})
std::map< std::string, std::string > physical_units
DataOutBase::CompressionLevel compression_level
static constexpr unsigned int vertices_per_cell
static constexpr std::array< unsigned int, vertices_per_cell > ucd_to_deal
static constexpr unsigned int faces_per_cell
static std_cxx20::ranges::iota_view< unsigned int, unsigned int > face_indices()
static constexpr std::array< unsigned int, vertices_per_cell > dx_to_deal
static std_cxx20::ranges::iota_view< unsigned int, unsigned int > vertex_indices()
bool operator<(const SynchronousIterators< Iterators > &a, const SynchronousIterators< Iterators > &b)