Reference documentation for deal.II version 9.1.0-pre
grid_out.cc
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 1999 - 2018 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE.md at
12 // the top level directory of deal.II.
13 //
14 // ---------------------------------------------------------------------
15 
16 #include <deal.II/base/exceptions.h>
17 #include <deal.II/base/geometry_info.h>
18 #include <deal.II/base/parameter_handler.h>
19 #include <deal.II/base/point.h>
20 #include <deal.II/base/qprojector.h>
21 #include <deal.II/base/quadrature.h>
22 
23 #include <deal.II/fe/mapping.h>
24 
25 #include <deal.II/grid/grid_out.h>
26 #include <deal.II/grid/tria.h>
27 #include <deal.II/grid/tria_accessor.h>
28 #include <deal.II/grid/tria_iterator.h>
29 
30 #include <deal.II/numerics/data_out.h>
31 
32 #include <algorithm>
33 #include <cmath>
34 #include <cstring>
35 #include <ctime>
36 #include <fstream>
37 #include <iomanip>
38 #include <list>
39 #include <set>
40 
41 
42 DEAL_II_NAMESPACE_OPEN
43 
44 
45 namespace GridOutFlags
46 {
47  DX::DX(const bool write_cells,
48  const bool write_faces,
49  const bool write_diameter,
50  const bool write_measure,
51  const bool write_all_faces)
52  : write_cells(write_cells)
53  , write_faces(write_faces)
54  , write_diameter(write_diameter)
55  , write_measure(write_measure)
56  , write_all_faces(write_all_faces)
57  {}
58 
59  void
61  {
62  param.declare_entry("Write cells",
63  "true",
65  "Write the mesh connectivity as DX grid cells");
66  param.declare_entry("Write faces",
67  "false",
69  "Write faces of cells. These may be boundary faces "
70  "or all faces between mesh cells, according to "
71  "\"Write all faces\"");
72  param.declare_entry("Write diameter",
73  "false",
75  "If cells are written, additionally write their"
76  " diameter as data for visualization");
77  param.declare_entry("Write measure",
78  "false",
80  "Write the volume of each cell as data");
81  param.declare_entry("Write all faces",
82  "true",
84  "Write all faces, not only boundary");
85  }
86 
87  void
89  {
90  write_cells = param.get_bool("Write cells");
91  write_faces = param.get_bool("Write faces");
92  write_diameter = param.get_bool("Write diameter");
93  write_measure = param.get_bool("Write measure");
94  write_all_faces = param.get_bool("Write all faces");
95  }
96 
97 
98  Msh::Msh(const bool write_faces, const bool write_lines)
99  : write_faces(write_faces)
100  , write_lines(write_lines)
101  {}
102 
103  void
105  {
106  param.declare_entry("Write faces", "false", Patterns::Bool());
107  param.declare_entry("Write lines", "false", Patterns::Bool());
108  }
109 
110 
111  void
113  {
114  write_faces = param.get_bool("Write faces");
115  write_lines = param.get_bool("Write lines");
116  }
117 
118 
119  Ucd::Ucd(const bool write_preamble,
120  const bool write_faces,
121  const bool write_lines)
122  : write_preamble(write_preamble)
123  , write_faces(write_faces)
124  , write_lines(write_lines)
125  {}
126 
127 
128 
129  void
131  {
132  param.declare_entry("Write preamble", "true", Patterns::Bool());
133  param.declare_entry("Write faces", "false", Patterns::Bool());
134  param.declare_entry("Write lines", "false", Patterns::Bool());
135  }
136 
137 
138  void
140  {
141  write_preamble = param.get_bool("Write preamble");
142  write_faces = param.get_bool("Write faces");
143  write_lines = param.get_bool("Write lines");
144  }
145 
146 
147 
148  Gnuplot::Gnuplot(const bool write_cell_numbers,
149  const unsigned int n_extra_curved_line_points,
150  const bool curved_inner_cells,
151  const bool write_additional_boundary_lines)
152  : write_cell_numbers(write_cell_numbers)
153  , n_extra_curved_line_points(n_extra_curved_line_points)
154  , n_boundary_face_points(this->n_extra_curved_line_points)
155  , curved_inner_cells(curved_inner_cells)
156  , write_additional_boundary_lines(write_additional_boundary_lines)
157  {}
158 
159 
160  // TODO we can get rid of these extra constructors and assignment operators
161  // once we remove the reference member variable.
162  Gnuplot::Gnuplot(const Gnuplot &flags)
163  : Gnuplot(flags.write_cell_numbers,
165  flags.curved_inner_cells,
167  {}
168 
169 
170 
171  Gnuplot &
173  {
178 
179  return *this;
180  }
181 
182 
183 
184  void
186  {
187  param.declare_entry("Cell number", "false", Patterns::Bool());
188  param.declare_entry("Boundary points", "2", Patterns::Integer());
189  }
190 
191 
192  void
194  {
195  write_cell_numbers = param.get_bool("Cell number");
196  n_boundary_face_points = param.get_integer("Boundary points");
197  }
198 
199 
201  const unsigned int size,
202  const double line_width,
203  const bool color_lines_on_user_flag,
204  const unsigned int n_boundary_face_points,
205  const bool color_lines_level)
206  : size_type(size_type)
207  , size(size)
208  , line_width(line_width)
209  , color_lines_on_user_flag(color_lines_on_user_flag)
210  , n_boundary_face_points(n_boundary_face_points)
211  , color_lines_level(color_lines_level)
212  {}
213 
214 
215  void
217  {
218  param.declare_entry("Size by",
219  "width",
220  Patterns::Selection("width|height"),
221  "Depending on this parameter, either the"
222  "width or height "
223  "of the eps is scaled to \"Size\"");
224  param.declare_entry("Size",
225  "300",
227  "Size of the output in points");
228  param.declare_entry("Line width",
229  "0.5",
231  "Width of the lines drawn in points");
232  param.declare_entry("Color by flag",
233  "false",
234  Patterns::Bool(),
235  "Draw lines with user flag set in different color");
236  param.declare_entry("Boundary points",
237  "2",
239  "Number of points on boundary edges. "
240  "Increase this beyond 2 to see curved boundaries.");
241  param.declare_entry("Color by level",
242  "false",
243  Patterns::Bool(),
244  "Draw different colors according to grid level.");
245  }
246 
247 
248  void
250  {
251  if (param.get("Size by") == std::string("width"))
252  size_type = width;
253  else if (param.get("Size by") == std::string("height"))
254  size_type = height;
255  size = param.get_integer("Size");
256  line_width = param.get_double("Line width");
257  color_lines_on_user_flag = param.get_bool("Color by flag");
258  n_boundary_face_points = param.get_integer("Boundary points");
259  color_lines_level = param.get_bool("Color by level");
260  }
261 
262 
263 
265  const unsigned int size,
266  const double line_width,
267  const bool color_lines_on_user_flag,
268  const unsigned int n_boundary_face_points)
269  : EpsFlagsBase(size_type,
270  size,
271  line_width,
272  color_lines_on_user_flag,
273  n_boundary_face_points)
274  {}
275 
276 
277  void
279  {}
280 
281 
282  void
284  {
286  }
287 
288 
289 
290  Eps<2>::Eps(const SizeType size_type,
291  const unsigned int size,
292  const double line_width,
293  const bool color_lines_on_user_flag,
294  const unsigned int n_boundary_face_points,
295  const bool write_cell_numbers,
296  const bool write_cell_number_level,
297  const bool write_vertex_numbers,
298  const bool color_lines_level)
299  : EpsFlagsBase(size_type,
300  size,
301  line_width,
302  color_lines_on_user_flag,
303  n_boundary_face_points,
304  color_lines_level)
305  , write_cell_numbers(write_cell_numbers)
306  , write_cell_number_level(write_cell_number_level)
307  , write_vertex_numbers(write_vertex_numbers)
308  {}
309 
310 
311  void
313  {
314  param.declare_entry("Cell number",
315  "false",
316  Patterns::Bool(),
317  "(2D only) Write cell numbers"
318  " into the centers of cells");
319  param.declare_entry("Level number",
320  "false",
321  Patterns::Bool(),
322  "(2D only) if \"Cell number\" is true, write"
323  "numbers in the form level.number");
324  param.declare_entry("Vertex number",
325  "false",
326  Patterns::Bool(),
327  "Write numbers for each vertex");
328  }
329 
330 
331  void
333  {
335  write_cell_numbers = param.get_bool("Cell number");
336  write_cell_number_level = param.get_bool("Level number");
337  write_vertex_numbers = param.get_bool("Vertex number");
338  }
339 
340 
341 
342  Eps<3>::Eps(const SizeType size_type,
343  const unsigned int size,
344  const double line_width,
345  const bool color_lines_on_user_flag,
346  const unsigned int n_boundary_face_points,
347  const double azimut_angle,
348  const double turn_angle)
349  : EpsFlagsBase(size_type,
350  size,
351  line_width,
352  color_lines_on_user_flag,
353  n_boundary_face_points)
354  , azimut_angle(azimut_angle)
355  , turn_angle(turn_angle)
356  {}
357 
358 
359  void
361  {
362  param.declare_entry("Azimuth",
363  "30",
365  "Azimuth of the viw point, that is, the angle "
366  "in the plane from the x-axis.");
367  param.declare_entry("Elevation",
368  "30",
370  "Elevation of the view point above the xy-plane.");
371  }
372 
373 
374  void
376  {
378  azimut_angle = 90 - param.get_double("Elevation");
379  turn_angle = param.get_double("Azimuth");
380  }
381 
382 
383 
385  : draw_boundary(true)
386  , color_by(material_id)
387  , level_depth(true)
388  , n_boundary_face_points(0)
389  , scaling(1., 1.)
390  , fill_style(20)
391  , line_style(0)
392  , line_thickness(1)
393  , boundary_style(0)
394  , boundary_thickness(3)
395  {}
396 
397 
398  void
400  {
401  param.declare_entry("Boundary", "true", Patterns::Bool());
402  param.declare_entry("Level color", "false", Patterns::Bool());
403  param.declare_entry("Level depth", "true", Patterns::Bool());
404  // TODO: Unify this number with other output formats
405  param.declare_entry("Boundary points", "0", Patterns::Integer());
406  param.declare_entry("Fill style", "20", Patterns::Integer());
407  param.declare_entry("Line style", "0", Patterns::Integer());
408  param.declare_entry("Line width", "1", Patterns::Integer());
409  param.declare_entry("Boundary style", "0", Patterns::Integer());
410  param.declare_entry("Boundary width", "3", Patterns::Integer());
411  }
412 
413 
414  void
416  {
417  draw_boundary = param.get_bool("Boundary");
418  level_depth = param.get_bool("Level depth");
419  n_boundary_face_points = param.get_integer("Boundary points");
420  fill_style = param.get_integer("Fill style");
421  line_style = param.get_integer("Line style");
422  line_thickness = param.get_integer("Line width");
423  boundary_style = param.get_integer("Boundary style");
424  boundary_thickness = param.get_integer("Boundary width");
425  }
426 
427  Svg::Svg(const unsigned int line_thickness,
428  const unsigned int boundary_line_thickness,
429  bool margin,
430  const Background background,
431  const int azimuth_angle,
432  const int polar_angle,
433  const Coloring coloring,
434  const bool convert_level_number_to_height,
435  const bool label_level_number,
436  const bool label_cell_index,
437  const bool label_material_id,
438  const bool label_subdomain_id,
439  const bool draw_colorbar,
440  const bool draw_legend)
441  : height(1000)
442  , width(0)
443  , line_thickness(line_thickness)
444  , boundary_line_thickness(boundary_line_thickness)
445  , margin(margin)
446  , background(background)
447  , azimuth_angle(azimuth_angle)
448  , polar_angle(polar_angle)
449  , coloring(coloring)
450  , convert_level_number_to_height(convert_level_number_to_height)
451  , level_height_factor(0.3f)
452  , cell_font_scaling(1.f)
453  , label_level_number(label_level_number)
454  , label_cell_index(label_cell_index)
455  , label_material_id(label_material_id)
456  , label_subdomain_id(label_subdomain_id)
457  , label_level_subdomain_id(false)
458  , draw_colorbar(draw_colorbar)
459  , draw_legend(draw_legend)
460  {}
461 
463  : draw_bounding_box(false) // box
464  {}
465 
466  void
468  {
469  param.declare_entry("Draw bounding box", "false", Patterns::Bool());
470  }
471 
472  void
474  {
475  draw_bounding_box = param.get_bool("Draw bounding box");
476  }
477 } // end namespace GridOutFlags
478 
479 
480 
482  : default_format(none)
483 {}
484 
485 
486 void
488 {
489  dx_flags = flags;
490 }
491 
492 
493 
494 void
496 {
497  msh_flags = flags;
498 }
499 
500 
501 void
503 {
504  ucd_flags = flags;
505 }
506 
507 
508 
509 void
511 {
512  gnuplot_flags = flags;
513 }
514 
515 
516 
517 void
519 {
520  eps_flags_1 = flags;
521 }
522 
523 
524 
525 void
527 {
528  eps_flags_2 = flags;
529 }
530 
531 
532 
533 void
535 {
536  eps_flags_3 = flags;
537 }
538 
539 
540 
541 void
543 {
544  xfig_flags = flags;
545 }
546 
547 
548 void
550 {
551  svg_flags = flags;
552 }
553 
554 
555 void
557 {
558  mathgl_flags = flags;
559 }
560 
561 void
563 {
564  vtk_flags = flags;
565 }
566 
567 void
569 {
570  vtu_flags = flags;
571 }
572 
573 std::string
575 {
576  switch (output_format)
577  {
578  case none:
579  return "";
580  case dx:
581  return ".dx";
582  case gnuplot:
583  return ".gnuplot";
584  case ucd:
585  return ".inp";
586  case eps:
587  return ".eps";
588  case xfig:
589  return ".fig";
590  case msh:
591  return ".msh";
592  case svg:
593  return ".svg";
594  case mathgl:
595  return ".mathgl";
596  case vtk:
597  return ".vtk";
598  case vtu:
599  return ".vtu";
600  default:
601  Assert(false, ExcNotImplemented());
602  return "";
603  }
604 }
605 
606 
607 
608 std::string
610 {
612 }
613 
614 
615 
617 GridOut::parse_output_format(const std::string &format_name)
618 {
619  if (format_name == "none" || format_name == "false")
620  return none;
621 
622  if (format_name == "dx")
623  return dx;
624 
625  if (format_name == "ucd")
626  return ucd;
627 
628  if (format_name == "gnuplot")
629  return gnuplot;
630 
631  if (format_name == "eps")
632  return eps;
633 
634  if (format_name == "xfig")
635  return xfig;
636 
637  if (format_name == "msh")
638  return msh;
639 
640  if (format_name == "svg")
641  return svg;
642 
643  if (format_name == "mathgl")
644  return mathgl;
645 
646  if (format_name == "vtk")
647  return vtk;
648 
649  if (format_name == "vtu")
650  return vtu;
651 
652  AssertThrow(false, ExcInvalidState());
653  // return something weird
654  return OutputFormat(-1);
655 }
656 
657 
658 
659 std::string
661 {
662  return "none|dx|gnuplot|eps|ucd|xfig|msh|svg|mathgl|vtk|vtu";
663 }
664 
665 
666 void
668 {
669  param.declare_entry("Format",
670  "none",
672 
673  param.enter_subsection("DX");
675  param.leave_subsection();
676 
677  param.enter_subsection("Msh");
679  param.leave_subsection();
680 
681  param.enter_subsection("Ucd");
683  param.leave_subsection();
684 
685  param.enter_subsection("Gnuplot");
687  param.leave_subsection();
688 
689  param.enter_subsection("Eps");
694  param.leave_subsection();
695 
696  param.enter_subsection("XFig");
698  param.leave_subsection();
699 
700  param.enter_subsection("MathGL");
702  param.leave_subsection();
703 
704  param.enter_subsection("Vtk");
706  param.leave_subsection();
707 
708  param.enter_subsection("Vtu");
710  param.leave_subsection();
711 }
712 
713 
714 
715 void
717 {
718  default_format = parse_output_format(param.get("Format"));
719 
720  param.enter_subsection("DX");
721  dx_flags.parse_parameters(param);
722  param.leave_subsection();
723 
724  param.enter_subsection("Msh");
726  param.leave_subsection();
727 
728  param.enter_subsection("Ucd");
730  param.leave_subsection();
731 
732  param.enter_subsection("Gnuplot");
734  param.leave_subsection();
735 
736  param.enter_subsection("Eps");
740  param.leave_subsection();
741 
742  param.enter_subsection("XFig");
744  param.leave_subsection();
745 
746  param.enter_subsection("MathGL");
748  param.leave_subsection();
749 
750  param.enter_subsection("Vtk");
752  param.leave_subsection();
753 
754  param.enter_subsection("Vtu");
756  param.leave_subsection();
757 }
758 
759 
760 
761 std::size_t
763 {
764  return (sizeof(dx_flags) + sizeof(msh_flags) + sizeof(ucd_flags) +
765  sizeof(gnuplot_flags) + sizeof(eps_flags_1) + sizeof(eps_flags_2) +
766  sizeof(eps_flags_3) + sizeof(xfig_flags) + sizeof(svg_flags) +
767  sizeof(mathgl_flags) + sizeof(vtk_flags) + sizeof(vtu_flags));
768 }
769 
770 
771 
772 template <>
773 void
774 GridOut::write_dx(const Triangulation<1> &, std::ostream &) const
775 {
776  Assert(false, ExcNotImplemented());
777 }
778 
779 template <>
780 void
781 GridOut::write_dx(const Triangulation<1, 2> &, std::ostream &) const
782 {
783  Assert(false, ExcNotImplemented());
784 }
785 
786 template <>
787 void
788 GridOut::write_dx(const Triangulation<1, 3> &, std::ostream &) const
789 {
790  Assert(false, ExcNotImplemented());
791 }
792 
793 
794 
795 template <int dim, int spacedim>
796 void
798  std::ostream & out) const
799 {
800  // TODO:[GK] allow for boundary faces only
802  AssertThrow(out, ExcIO());
803  // Copied and adapted from write_ucd
804  const std::vector<Point<spacedim>> &vertices = tria.get_vertices();
805  const std::vector<bool> & vertex_used = tria.get_used_vertices();
806 
807  const unsigned int n_vertices = tria.n_used_vertices();
808 
809  // vertices are implicitly numbered from 0 to
810  // n_vertices-1. we have to renumber the
811  // vertices, because otherwise we would end
812  // up with wrong results, if there are unused
813  // vertices
814  std::vector<unsigned int> renumber(vertices.size());
815  // fill this vector with new vertex numbers
816  // ranging from 0 to n_vertices-1
817  unsigned int new_number = 0;
818  for (unsigned int i = 0; i < vertices.size(); ++i)
819  if (vertex_used[i])
820  renumber[i] = new_number++;
821  Assert(new_number == n_vertices, ExcInternalError());
822 
825  tria.end();
826 
827 
828  // write the vertices
829  out << "object \"vertices\" class array type float rank 1 shape " << dim
830  << " items " << n_vertices << " data follows" << '\n';
831 
832  for (unsigned int i = 0; i < vertices.size(); ++i)
833  if (vertex_used[i])
834  out << '\t' << vertices[i] << '\n';
835 
836  // write cells or faces
837  const bool write_cells = dx_flags.write_cells;
838  const bool write_faces = (dim > 1) ? dx_flags.write_faces : false;
839 
840  const unsigned int n_cells = tria.n_active_cells();
841  const unsigned int n_faces =
843 
844  const unsigned int n_vertices_per_cell = GeometryInfo<dim>::vertices_per_cell;
845  const unsigned int n_vertices_per_face = GeometryInfo<dim>::vertices_per_face;
846 
847  if (write_cells)
848  {
849  out << "object \"cells\" class array type int rank 1 shape "
850  << n_vertices_per_cell << " items " << n_cells << " data follows"
851  << '\n';
852 
853  for (cell = tria.begin_active(); cell != endc; ++cell)
854  {
855  for (unsigned int v = 0; v < GeometryInfo<dim>::vertices_per_cell;
856  ++v)
857  out
858  << '\t'
859  << renumber[cell->vertex_index(GeometryInfo<dim>::dx_to_deal[v])];
860  out << '\n';
861  }
862  out << "attribute \"element type\" string \"";
863  if (dim == 1)
864  out << "lines";
865  if (dim == 2)
866  out << "quads";
867  if (dim == 3)
868  out << "cubes";
869  out << "\"" << '\n'
870  << "attribute \"ref\" string \"positions\"" << '\n'
871  << '\n';
872 
873  // Additional cell information
874 
875  out << "object \"material\" class array type int rank 0 items " << n_cells
876  << " data follows" << '\n';
877  for (cell = tria.begin_active(); cell != endc; ++cell)
878  out << ' ' << (unsigned int)cell->material_id();
879  out << '\n' << "attribute \"dep\" string \"connections\"" << '\n' << '\n';
880 
881  out << "object \"level\" class array type int rank 0 items " << n_cells
882  << " data follows" << '\n';
883  for (cell = tria.begin_active(); cell != endc; ++cell)
884  out << ' ' << cell->level();
885  out << '\n' << "attribute \"dep\" string \"connections\"" << '\n' << '\n';
886 
888  {
889  out << "object \"measure\" class array type float rank 0 items "
890  << n_cells << " data follows" << '\n';
891  for (cell = tria.begin_active(); cell != endc; ++cell)
892  out << '\t' << cell->measure();
893  out << '\n'
894  << "attribute \"dep\" string \"connections\"" << '\n'
895  << '\n';
896  }
897 
899  {
900  out << "object \"diameter\" class array type float rank 0 items "
901  << n_cells << " data follows" << '\n';
902  for (cell = tria.begin_active(); cell != endc; ++cell)
903  out << '\t' << cell->diameter();
904  out << '\n'
905  << "attribute \"dep\" string \"connections\"" << '\n'
906  << '\n';
907  }
908  }
909 
910  if (write_faces)
911  {
912  out << "object \"faces\" class array type int rank 1 shape "
913  << n_vertices_per_face << " items " << n_faces << " data follows"
914  << '\n';
915 
916  for (cell = tria.begin_active(); cell != endc; ++cell)
917  {
918  for (unsigned int f = 0; f < GeometryInfo<dim>::faces_per_cell; ++f)
919  {
921  cell->face(f);
922 
923  for (unsigned int v = 0; v < GeometryInfo<dim>::vertices_per_face;
924  ++v)
925  out << '\t'
926  << renumber[face->vertex_index(
928  out << '\n';
929  }
930  }
931  out << "attribute \"element type\" string \"";
932  if (dim == 2)
933  out << "lines";
934  if (dim == 3)
935  out << "quads";
936  out << "\"" << '\n'
937  << "attribute \"ref\" string \"positions\"" << '\n'
938  << '\n';
939 
940 
941  // Additional face information
942 
943  out << "object \"boundary\" class array type int rank 0 items " << n_faces
944  << " data follows" << '\n';
945  for (cell = tria.begin_active(); cell != endc; ++cell)
946  {
947  // Little trick to get -1
948  // for the interior
949  for (unsigned int f = 0; f < GeometryInfo<dim>::faces_per_cell; ++f)
950  out << ' ' << (int)(signed char)cell->face(f)->boundary_id();
951  out << '\n';
952  }
953  out << "attribute \"dep\" string \"connections\"" << '\n' << '\n';
954 
956  {
957  out << "object \"face measure\" class array type float rank 0 items "
958  << n_faces << " data follows" << '\n';
959  for (cell = tria.begin_active(); cell != endc; ++cell)
960  {
961  for (unsigned int f = 0; f < GeometryInfo<dim>::faces_per_cell;
962  ++f)
963  out << ' ' << cell->face(f)->measure();
964  out << '\n';
965  }
966  out << "attribute \"dep\" string \"connections\"" << '\n' << '\n';
967  }
968 
970  {
971  out << "object \"face diameter\" class array type float rank 0 items "
972  << n_faces << " data follows" << '\n';
973  for (cell = tria.begin_active(); cell != endc; ++cell)
974  {
975  for (unsigned int f = 0; f < GeometryInfo<dim>::faces_per_cell;
976  ++f)
977  out << ' ' << cell->face(f)->diameter();
978  out << '\n';
979  }
980  out << "attribute \"dep\" string \"connections\"" << '\n' << '\n';
981  }
982  }
983 
984 
985  // Write additional face information
986 
987  if (write_faces)
988  {
989  }
990  else
991  {}
992 
993  // The wrapper
994  out << "object \"deal data\" class field" << '\n'
995  << "component \"positions\" value \"vertices\"" << '\n'
996  << "component \"connections\" value \"cells\"" << '\n';
997 
998  if (write_cells)
999  {
1000  out << "object \"cell data\" class field" << '\n'
1001  << "component \"positions\" value \"vertices\"" << '\n'
1002  << "component \"connections\" value \"cells\"" << '\n';
1003  out << "component \"material\" value \"material\"" << '\n';
1004  out << "component \"level\" value \"level\"" << '\n';
1005  if (dx_flags.write_measure)
1006  out << "component \"measure\" value \"measure\"" << '\n';
1008  out << "component \"diameter\" value \"diameter\"" << '\n';
1009  }
1010 
1011  if (write_faces)
1012  {
1013  out << "object \"face data\" class field" << '\n'
1014  << "component \"positions\" value \"vertices\"" << '\n'
1015  << "component \"connections\" value \"faces\"" << '\n';
1016  out << "component \"boundary\" value \"boundary\"" << '\n';
1017  if (dx_flags.write_measure)
1018  out << "component \"measure\" value \"face measure\"" << '\n';
1020  out << "component \"diameter\" value \"face diameter\"" << '\n';
1021  }
1022 
1023  out << '\n' << "object \"grid data\" class group" << '\n';
1024  if (write_cells)
1025  out << "member \"cells\" value \"cell data\"" << '\n';
1026  if (write_faces)
1027  out << "member \"faces\" value \"face data\"" << '\n';
1028  out << "end" << '\n';
1029 
1030  // make sure everything now gets to
1031  // disk
1032  out.flush();
1033 
1034  AssertThrow(out, ExcIO());
1035 }
1036 
1037 
1038 
1039 template <int dim, int spacedim>
1040 void
1042  std::ostream & out) const
1043 {
1044  AssertThrow(out, ExcIO());
1045 
1046  // get the positions of the
1047  // vertices and whether they are
1048  // used.
1049  const std::vector<Point<spacedim>> &vertices = tria.get_vertices();
1050  const std::vector<bool> & vertex_used = tria.get_used_vertices();
1051 
1052  const unsigned int n_vertices = tria.n_used_vertices();
1053 
1055  tria.begin_active();
1057  tria.end();
1058 
1059  // Write Header
1060  // The file format is:
1061  /*
1062 
1063 
1064  @f$NOD
1065  number-of-nodes
1066  node-number x-coord y-coord z-coord
1067  ...
1068  @f$ENDNOD
1069  @f$ELM
1070  number-of-elements
1071  elm-number elm-type reg-phys reg-elem number-of-nodes node-number-list
1072  ...
1073  @f$ENDELM
1074  */
1075  out << "@f$NOD" << '\n' << n_vertices << '\n';
1076 
1077  // actually write the vertices.
1078  // note that we shall number them
1079  // with first index 1 instead of 0
1080  for (unsigned int i = 0; i < vertices.size(); ++i)
1081  if (vertex_used[i])
1082  {
1083  out << i + 1 // vertex index
1084  << " " << vertices[i];
1085  for (unsigned int d = spacedim + 1; d <= 3; ++d)
1086  out << " 0"; // fill with zeroes
1087  out << '\n';
1088  }
1089 
1090  // Write cells preamble
1091  out << "@f$ENDNOD" << '\n'
1092  << "@f$ELM" << '\n'
1093  << tria.n_active_cells() +
1094  ((msh_flags.write_faces ? n_boundary_faces(tria) : 0) +
1095  (msh_flags.write_lines ? n_boundary_lines(tria) : 0))
1096  << '\n';
1097 
1098  /*
1099  elm-type
1100  defines the geometrical type of the n-th element:
1101  1
1102  Line (2 nodes).
1103  2
1104  Triangle (3 nodes).
1105  3
1106  Quadrangle (4 nodes).
1107  4
1108  Tetrahedron (4 nodes).
1109  5
1110  Hexahedron (8 nodes).
1111  6
1112  Prism (6 nodes).
1113  7
1114  Pyramid (5 nodes).
1115  8
1116  Second order line (3 nodes: 2 associated with the vertices and 1 with the
1117  edge).
1118  9
1119  Second order triangle (6 nodes: 3 associated with the vertices and 3 with
1120  the edges). 10 Second order quadrangle (9 nodes: 4 associated with the
1121  vertices, 4 with the edges and 1 with the face). 11 Second order tetrahedron
1122  (10 nodes: 4 associated with the vertices and 6 with the edges). 12 Second
1123  order hexahedron (27 nodes: 8 associated with the vertices, 12 with the
1124  edges, 6 with the faces and 1 with the volume). 13 Second order prism (18
1125  nodes: 6 associated with the vertices, 9 with the edges and 3 with the
1126  quadrangular faces). 14 Second order pyramid (14 nodes: 5 associated with
1127  the vertices, 8 with the edges and 1 with the quadrangular face). 15 Point
1128  (1 node).
1129  */
1130  unsigned int elm_type;
1131  switch (dim)
1132  {
1133  case 1:
1134  elm_type = 1;
1135  break;
1136  case 2:
1137  elm_type = 3;
1138  break;
1139  case 3:
1140  elm_type = 5;
1141  break;
1142  default:
1143  Assert(false, ExcNotImplemented());
1144  }
1145 
1146  // write cells. Enumerate cells
1147  // consecutively, starting with 1
1148  for (cell = tria.begin_active(); cell != endc; ++cell)
1149  {
1150  out << cell->active_cell_index() + 1 << ' ' << elm_type << ' '
1151  << static_cast<unsigned int>(cell->material_id()) << ' '
1152  << cell->subdomain_id() << ' ' << GeometryInfo<dim>::vertices_per_cell
1153  << ' ';
1154 
1155  // Vertex numbering follows UCD conventions.
1156 
1157  for (unsigned int vertex = 0;
1158  vertex < GeometryInfo<dim>::vertices_per_cell;
1159  ++vertex)
1160  out << cell->vertex_index(GeometryInfo<dim>::ucd_to_deal[vertex]) + 1
1161  << ' ';
1162  out << '\n';
1163  }
1164 
1165  // write faces and lines with non-zero boundary indicator
1166  unsigned int next_element_index = tria.n_active_cells() + 1;
1167  if (msh_flags.write_faces)
1168  {
1169  next_element_index = write_msh_faces(tria, next_element_index, out);
1170  }
1171  if (msh_flags.write_lines)
1172  {
1173  next_element_index = write_msh_lines(tria, next_element_index, out);
1174  }
1175 
1176  out << "@f$ENDELM\n";
1177 
1178  // make sure everything now gets to
1179  // disk
1180  out.flush();
1181 
1182  AssertThrow(out, ExcIO());
1183 }
1184 
1185 
1186 template <int dim, int spacedim>
1187 void
1189  std::ostream & out) const
1190 {
1191  AssertThrow(out, ExcIO());
1192 
1193  // get the positions of the
1194  // vertices and whether they are
1195  // used.
1196  const std::vector<Point<spacedim>> &vertices = tria.get_vertices();
1197  const std::vector<bool> & vertex_used = tria.get_used_vertices();
1198 
1199  const unsigned int n_vertices = tria.n_used_vertices();
1200 
1202  tria.begin_active();
1204  tria.end();
1205 
1206  // write preamble
1208  {
1209  // block this to have local
1210  // variables destroyed after
1211  // use
1212  std::time_t time1 = std::time(nullptr);
1213  std::tm * time = std::localtime(&time1);
1214  out
1215  << "# This file was generated by the deal.II library." << '\n'
1216  << "# Date = " << time->tm_year + 1900 << "/" << time->tm_mon + 1
1217  << "/" << time->tm_mday << '\n'
1218  << "# Time = " << time->tm_hour << ":" << std::setw(2) << time->tm_min
1219  << ":" << std::setw(2) << time->tm_sec << '\n'
1220  << "#" << '\n'
1221  << "# For a description of the UCD format see the AVS Developer's guide."
1222  << '\n'
1223  << "#" << '\n';
1224  }
1225 
1226  // start with ucd data
1227  out << n_vertices << ' '
1228  << tria.n_active_cells() +
1229  ((ucd_flags.write_faces ? n_boundary_faces(tria) : 0) +
1230  (ucd_flags.write_lines ? n_boundary_lines(tria) : 0))
1231  << " 0 0 0" // no data
1232  << '\n';
1233 
1234  // actually write the vertices.
1235  // note that we shall number them
1236  // with first index 1 instead of 0
1237  for (unsigned int i = 0; i < vertices.size(); ++i)
1238  if (vertex_used[i])
1239  {
1240  out << i + 1 // vertex index
1241  << " " << vertices[i];
1242  for (unsigned int d = spacedim + 1; d <= 3; ++d)
1243  out << " 0"; // fill with zeroes
1244  out << '\n';
1245  }
1246 
1247  // write cells. Enumerate cells
1248  // consecutively, starting with 1
1249  for (cell = tria.begin_active(); cell != endc; ++cell)
1250  {
1251  out << cell->active_cell_index() + 1 << ' '
1252  << static_cast<unsigned int>(cell->material_id()) << ' ';
1253  switch (dim)
1254  {
1255  case 1:
1256  out << "line ";
1257  break;
1258  case 2:
1259  out << "quad ";
1260  break;
1261  case 3:
1262  out << "hex ";
1263  break;
1264  default:
1265  Assert(false, ExcNotImplemented());
1266  }
1267 
1268  // it follows a list of the
1269  // vertices of each cell. in 1d
1270  // this is simply a list of the
1271  // two vertices, in 2d its counter
1272  // clockwise, as usual in this
1273  // library. in 3d, the same applies
1274  // (special thanks to AVS for
1275  // numbering their vertices in a
1276  // way compatible to deal.II!)
1277  //
1278  // technical reference:
1279  // AVS Developer's Guide, Release 4,
1280  // May, 1992, p. E6
1281  //
1282  // note: vertex numbers are 1-base
1283  for (unsigned int vertex = 0;
1284  vertex < GeometryInfo<dim>::vertices_per_cell;
1285  ++vertex)
1286  out << cell->vertex_index(GeometryInfo<dim>::ucd_to_deal[vertex]) + 1
1287  << ' ';
1288  out << '\n';
1289  }
1290 
1291  // write faces and lines with non-zero boundary indicator
1292  unsigned int next_element_index = tria.n_active_cells() + 1;
1293  if (ucd_flags.write_faces)
1294  {
1295  next_element_index = write_ucd_faces(tria, next_element_index, out);
1296  }
1297  if (ucd_flags.write_lines)
1298  {
1299  next_element_index = write_ucd_lines(tria, next_element_index, out);
1300  }
1301 
1302  // make sure everything now gets to
1303  // disk
1304  out.flush();
1305 
1306  AssertThrow(out, ExcIO());
1307 }
1308 
1309 
1310 
1311 template <int dim, int spacedim>
1312 void
1314  std::ostream &,
1315  const Mapping<dim, spacedim> *) const
1316 {
1317  Assert(false, ExcNotImplemented());
1318 }
1319 
1320 
1321 // TODO:[GK] Obey parameters
1322 template <>
1323 void
1325  std::ostream & out,
1326  const Mapping<2> * /*mapping*/) const
1327 {
1328  const int dim = 2;
1329  const int spacedim = 2;
1330 
1331  const unsigned int nv = GeometryInfo<dim>::vertices_per_cell;
1332  const unsigned int nf = GeometryInfo<dim>::faces_per_cell;
1333  const unsigned int nvf = GeometryInfo<dim>::vertices_per_face;
1334 
1335  // The following text was copied
1336  // from an existing XFig file.
1337  out << "#FIG 3.2\nLandscape\nCenter\nInches" << std::endl
1338  << "A4\n100.00\nSingle"
1339  << std::endl
1340  // Background is transparent
1341  << "-3" << std::endl
1342  << "# generated by deal.II GridOut class" << std::endl
1343  << "# reduce first number to scale up image" << std::endl
1344  << "1200 2" << std::endl;
1345  // Write custom palette
1346  // grey
1347  unsigned int colno = 32;
1348  out << "0 " << colno++ << " #ff0000" << std::endl;
1349  out << "0 " << colno++ << " #ff8000" << std::endl;
1350  out << "0 " << colno++ << " #ffd000" << std::endl;
1351  out << "0 " << colno++ << " #ffff00" << std::endl;
1352  out << "0 " << colno++ << " #c0ff00" << std::endl;
1353  out << "0 " << colno++ << " #80ff00" << std::endl;
1354  out << "0 " << colno++ << " #00f000" << std::endl;
1355  out << "0 " << colno++ << " #00f0c0" << std::endl;
1356  out << "0 " << colno++ << " #00f0ff" << std::endl;
1357  out << "0 " << colno++ << " #00c0ff" << std::endl;
1358  out << "0 " << colno++ << " #0080ff" << std::endl;
1359  out << "0 " << colno++ << " #0040ff" << std::endl;
1360  out << "0 " << colno++ << " #0000c0" << std::endl;
1361  out << "0 " << colno++ << " #5000ff" << std::endl;
1362  out << "0 " << colno++ << " #8000ff" << std::endl;
1363  out << "0 " << colno++ << " #b000ff" << std::endl;
1364  out << "0 " << colno++ << " #ff00ff" << std::endl;
1365  out << "0 " << colno++ << " #ff80ff" << std::endl;
1366  // grey
1367  for (unsigned int i = 0; i < 8; ++i)
1368  out << "0 " << colno++ << " #" << std::hex << 32 * i + 31 << 32 * i + 31
1369  << 32 * i + 31 << std::dec << std::endl;
1370  // green
1371  for (unsigned int i = 1; i < 16; ++i)
1372  out << "0 " << colno++ << " #00" << std::hex << 16 * i + 15 << std::dec
1373  << "00" << std::endl;
1374  // yellow
1375  for (unsigned int i = 1; i < 16; ++i)
1376  out << "0 " << colno++ << " #" << std::hex << 16 * i + 15 << 16 * i + 15
1377  << std::dec << "00" << std::endl;
1378  // red
1379  for (unsigned int i = 1; i < 16; ++i)
1380  out << "0 " << colno++ << " #" << std::hex << 16 * i + 15 << std::dec
1381  << "0000" << std::endl;
1382  // purple
1383  for (unsigned int i = 1; i < 16; ++i)
1384  out << "0 " << colno++ << " #" << std::hex << 16 * i + 15 << "00"
1385  << 16 * i + 15 << std::dec << std::endl;
1386  // blue
1387  for (unsigned int i = 1; i < 16; ++i)
1388  out << "0 " << colno++ << " #0000" << std::hex << 16 * i + 15 << std::dec
1389  << std::endl;
1390  // cyan
1391  for (unsigned int i = 1; i < 16; ++i)
1392  out << "0 " << colno++ << " #00" << std::hex << 16 * i + 15 << 16 * i + 15
1393  << std::dec << std::endl;
1394 
1395  // We write all cells and cells on
1396  // coarser levels are behind cells
1397  // on finer levels. Level 0
1398  // corresponds to a depth of 900,
1399  // each level subtracting 1
1402 
1403  for (; cell != end; ++cell)
1404  {
1405  // If depth is not encoded, write finest level only
1406  if (!xfig_flags.level_depth && !cell->active())
1407  continue;
1408  // Code for polygon
1409  out << "2 3 " << xfig_flags.line_style << ' '
1411  // with black line
1412  << " 0 ";
1413  // Fill color
1414  switch (xfig_flags.color_by)
1415  {
1416  // TODO[GK]: Simplify after deprecation period is over
1418  out << static_cast<unsigned int>(cell->material_id()) + 32;
1419  break;
1421  out << cell->level() + 8;
1422  break;
1424  out << cell->subdomain_id() + 32;
1425  break;
1427  out << cell->level_subdomain_id() + 32;
1428  break;
1429  default:
1430  Assert(false, ExcInternalError());
1431  }
1432 
1433  // Depth, unused, fill
1434  out << ' '
1435  << (xfig_flags.level_depth ? (900 - cell->level()) :
1436  (900 + cell->material_id()))
1437  << " 0 " << xfig_flags.fill_style
1438  << " 0.0 "
1439  // some style parameters
1440  << " 0 0 -1 0 0 "
1441  // number of points
1442  << nv + 1 << std::endl;
1443 
1444  // For each point, write scaled
1445  // and shifted coordinates
1446  // multiplied by 1200
1447  // (dots/inch)
1448  for (unsigned int k = 0; k <= nv; ++k)
1449  {
1450  const Point<dim> &p =
1451  cell->vertex(GeometryInfo<dim>::ucd_to_deal[k % nv]);
1452  for (unsigned int d = 0; d < static_cast<unsigned int>(dim); ++d)
1453  {
1454  int val = (int)(1200 * xfig_flags.scaling(d) *
1455  (p(d) - xfig_flags.offset(d)));
1456  out << '\t' << ((d == 0) ? val : -val);
1457  }
1458  out << std::endl;
1459  }
1460  // Now write boundary edges
1461  static const unsigned int face_reorder[4] = {2, 1, 3, 0};
1463  for (unsigned int f = 0; f < nf; ++f)
1464  {
1466  cell->face(face_reorder[f]);
1467  const types::boundary_id bi = face->boundary_id();
1469  {
1470  // Code for polyline
1471  out << "2 1 "
1472  // with line style and thickness
1473  << xfig_flags.boundary_style << ' '
1474  << xfig_flags.boundary_thickness << ' '
1475  << (1 + (unsigned int)bi);
1476  // Fill color
1477  out << " -1 ";
1478  // Depth 100 less than cells
1479  out << (xfig_flags.level_depth ? (800 - cell->level()) :
1480  800 + bi)
1481  // unused, no fill
1482  << " 0 -1 0.0 "
1483  // some style parameters
1484  << " 0 0 -1 0 0 "
1485  // number of points
1486  << nvf << std::endl;
1487 
1488  // For each point, write scaled
1489  // and shifted coordinates
1490  // multiplied by 1200
1491  // (dots/inch)
1492 
1493  for (unsigned int k = 0; k < nvf; ++k)
1494  {
1495  const Point<dim> &p = face->vertex(k % nv);
1496  for (unsigned int d = 0; d < static_cast<unsigned int>(dim);
1497  ++d)
1498  {
1499  int val = (int)(1200 * xfig_flags.scaling(d) *
1500  (p(d) - xfig_flags.offset(d)));
1501  out << '\t' << ((d == 0) ? val : -val);
1502  }
1503  out << std::endl;
1504  }
1505  }
1506  }
1507  }
1508 
1509  // make sure everything now gets to
1510  // disk
1511  out.flush();
1512 
1513  AssertThrow(out, ExcIO());
1514 }
1515 
1516 
1517 
1518 template <int dim, int spacedim>
1519 void
1521  std::ostream & /*out*/) const
1522 {
1523  Assert(false, ExcNotImplemented());
1524 }
1525 
1526 
1527 void
1528 GridOut::write_svg(const Triangulation<2, 2> &tria, std::ostream &out) const
1529 {
1530  unsigned int n_materials = 0;
1531  unsigned int n_levels = 0;
1532  unsigned int n_subdomains = 0;
1533  unsigned int n_level_subdomains = 0;
1534 
1535  unsigned int n = 0;
1536 
1537  unsigned int min_level, max_level;
1538 
1539  // Svg files require an underlying drawing grid. The size of this
1540  // grid is provided in the parameters height and width. Each of them
1541  // may be zero, such that it is computed from the other. Obviously,
1542  // both of them zero does not produce reasonable output.
1543  unsigned int height = svg_flags.height;
1544  unsigned int width = svg_flags.width;
1545  Assert(height != 0 || width != 0,
1546  ExcMessage("You have to set at least one of width and height"));
1547 
1548  unsigned int margin_in_percent = 0;
1549  if (svg_flags.margin || svg_flags.background == GridOutFlags::Svg::dealii)
1550  margin_in_percent = 8;
1551 
1552  // initial font size for cell labels
1553  unsigned int cell_label_font_size;
1554 
1555  // get date and time
1556  // time_t time_stamp;
1557  // tm *now;
1558  // time_stamp = time(0);
1559  // now = localtime(&time_stamp);
1560 
1561  // vectors and variables for the perspective view
1562  Point<3> camera_position;
1563  Point<3> camera_direction;
1564  Point<3> camera_horizontal;
1565  float camera_focus;
1566 
1567  Point<3> point;
1568  Point<2> projection_decomposition;
1569 
1570  float x_max_perspective, x_min_perspective;
1571  float y_max_perspective, y_min_perspective;
1572 
1573  float x_dimension_perspective, y_dimension_perspective;
1574 
1575 
1576  // auxiliary variables for the bounding box and the range of cell levels
1577  double x_min = tria.begin()->vertex(0)[0];
1578  double x_max = x_min;
1579  double y_min = tria.begin()->vertex(0)[1];
1580  double y_max = y_min;
1581 
1582  double x_dimension, y_dimension;
1583 
1584  min_level = max_level = tria.begin()->level();
1585 
1586  // auxiliary array for the materials being used (material ids 255 max.)
1587  unsigned int materials[256];
1588  for (unsigned int material_index = 0; material_index < 256; material_index++)
1589  materials[material_index] = 0;
1590 
1591  // auxiliary array for the levels being used (level number 255 max.)
1592  unsigned int levels[256];
1593  for (unsigned int level_index = 0; level_index < 256; level_index++)
1594  levels[level_index] = 0;
1595 
1596  // auxiliary array for the subdomains being used (subdomain id 255 max.)
1597  unsigned int subdomains[256];
1598  for (unsigned int subdomain_index = 0; subdomain_index < 256;
1599  subdomain_index++)
1600  subdomains[subdomain_index] = 0;
1601 
1602  // auxiliary array for the level subdomains being used
1603  int level_subdomains[256];
1604  for (int level_subdomain_index = 0; level_subdomain_index < 256;
1605  level_subdomain_index++)
1606  level_subdomains[level_subdomain_index] = 0;
1607 
1608  // We use an active cell iterator to determine the
1609  // bounding box of the given triangulation and check
1610  // the cells for material id, level number, subdomain id
1611  // (, and level subdomain id).
1612  for (Triangulation<2, 2>::cell_iterator cell = tria.begin();
1613  cell != tria.end();
1614  ++cell)
1615  {
1616  for (unsigned int vertex_index = 0; vertex_index < 4; vertex_index++)
1617  {
1618  if (cell->vertex(vertex_index)[0] < x_min)
1619  x_min = cell->vertex(vertex_index)[0];
1620  if (cell->vertex(vertex_index)[0] > x_max)
1621  x_max = cell->vertex(vertex_index)[0];
1622 
1623  if (cell->vertex(vertex_index)[1] < y_min)
1624  y_min = cell->vertex(vertex_index)[1];
1625  if (cell->vertex(vertex_index)[1] > y_max)
1626  y_max = cell->vertex(vertex_index)[1];
1627  }
1628 
1629  if ((unsigned int)cell->level() < min_level)
1630  min_level = cell->level();
1631  if ((unsigned int)cell->level() > max_level)
1632  max_level = cell->level();
1633 
1634  materials[(unsigned int)cell->material_id()] = 1;
1635  levels[(unsigned int)cell->level()] = 1;
1636  if (cell->active())
1637  subdomains[cell->subdomain_id() + 2] = 1;
1638  level_subdomains[cell->level_subdomain_id() + 2] = 1;
1639  }
1640 
1641  x_dimension = x_max - x_min;
1642  y_dimension = y_max - y_min;
1643 
1644  // count the materials being used
1645  for (unsigned int material_index = 0; material_index < 256; material_index++)
1646  {
1647  if (materials[material_index])
1648  n_materials++;
1649  }
1650 
1651  // count the levels being used
1652  for (unsigned int level_index = 0; level_index < 256; level_index++)
1653  {
1654  if (levels[level_index])
1655  n_levels++;
1656  }
1657 
1658  // count the subdomains being used
1659  for (unsigned int subdomain_index = 0; subdomain_index < 256;
1660  subdomain_index++)
1661  {
1662  if (subdomains[subdomain_index])
1663  n_subdomains++;
1664  }
1665 
1666  // count the level subdomains being used
1667  for (int level_subdomain_index = 0; level_subdomain_index < 256;
1668  level_subdomain_index++)
1669  {
1670  if (level_subdomains[level_subdomain_index])
1671  n_level_subdomains++;
1672  }
1673 
1674  switch (svg_flags.coloring)
1675  {
1677  n = n_materials;
1678  break;
1680  n = n_levels;
1681  break;
1683  n = n_subdomains;
1684  break;
1686  n = n_level_subdomains;
1687  break;
1688  default:
1689  break;
1690  }
1691 
1692  // set the camera position to top view, targeting at the origin
1693  camera_position[0] = 0;
1694  camera_position[1] = 0;
1695  camera_position[2] = 2. * std::max(x_dimension, y_dimension);
1696 
1697  camera_direction[0] = 0;
1698  camera_direction[1] = 0;
1699  camera_direction[2] = -1;
1700 
1701  camera_horizontal[0] = 1;
1702  camera_horizontal[1] = 0;
1703  camera_horizontal[2] = 0;
1704 
1705  camera_focus = .5 * std::max(x_dimension, y_dimension);
1706 
1707  Point<3> camera_position_temp;
1708  Point<3> camera_direction_temp;
1709  Point<3> camera_horizontal_temp;
1710 
1711  const double angle_factor = 3.14159265 / 180.;
1712 
1713  // (I) rotate the camera to the chosen polar angle
1714  camera_position_temp[1] =
1715  cos(angle_factor * svg_flags.polar_angle) * camera_position[1] -
1716  sin(angle_factor * svg_flags.polar_angle) * camera_position[2];
1717  camera_position_temp[2] =
1718  sin(angle_factor * svg_flags.polar_angle) * camera_position[1] +
1719  cos(angle_factor * svg_flags.polar_angle) * camera_position[2];
1720 
1721  camera_direction_temp[1] =
1722  cos(angle_factor * svg_flags.polar_angle) * camera_direction[1] -
1723  sin(angle_factor * svg_flags.polar_angle) * camera_direction[2];
1724  camera_direction_temp[2] =
1725  sin(angle_factor * svg_flags.polar_angle) * camera_direction[1] +
1726  cos(angle_factor * svg_flags.polar_angle) * camera_direction[2];
1727 
1728  camera_horizontal_temp[1] =
1729  cos(angle_factor * svg_flags.polar_angle) * camera_horizontal[1] -
1730  sin(angle_factor * svg_flags.polar_angle) * camera_horizontal[2];
1731  camera_horizontal_temp[2] =
1732  sin(angle_factor * svg_flags.polar_angle) * camera_horizontal[1] +
1733  cos(angle_factor * svg_flags.polar_angle) * camera_horizontal[2];
1734 
1735  camera_position[1] = camera_position_temp[1];
1736  camera_position[2] = camera_position_temp[2];
1737 
1738  camera_direction[1] = camera_direction_temp[1];
1739  camera_direction[2] = camera_direction_temp[2];
1740 
1741  camera_horizontal[1] = camera_horizontal_temp[1];
1742  camera_horizontal[2] = camera_horizontal_temp[2];
1743 
1744  // (II) rotate the camera to the chosen azimuth angle
1745  camera_position_temp[0] =
1746  cos(angle_factor * svg_flags.azimuth_angle) * camera_position[0] -
1747  sin(angle_factor * svg_flags.azimuth_angle) * camera_position[1];
1748  camera_position_temp[1] =
1749  sin(angle_factor * svg_flags.azimuth_angle) * camera_position[0] +
1750  cos(angle_factor * svg_flags.azimuth_angle) * camera_position[1];
1751 
1752  camera_direction_temp[0] =
1753  cos(angle_factor * svg_flags.azimuth_angle) * camera_direction[0] -
1754  sin(angle_factor * svg_flags.azimuth_angle) * camera_direction[1];
1755  camera_direction_temp[1] =
1756  sin(angle_factor * svg_flags.azimuth_angle) * camera_direction[0] +
1757  cos(angle_factor * svg_flags.azimuth_angle) * camera_direction[1];
1758 
1759  camera_horizontal_temp[0] =
1760  cos(angle_factor * svg_flags.azimuth_angle) * camera_horizontal[0] -
1761  sin(angle_factor * svg_flags.azimuth_angle) * camera_horizontal[1];
1762  camera_horizontal_temp[1] =
1763  sin(angle_factor * svg_flags.azimuth_angle) * camera_horizontal[0] +
1764  cos(angle_factor * svg_flags.azimuth_angle) * camera_horizontal[1];
1765 
1766  camera_position[0] = camera_position_temp[0];
1767  camera_position[1] = camera_position_temp[1];
1768 
1769  camera_direction[0] = camera_direction_temp[0];
1770  camera_direction[1] = camera_direction_temp[1];
1771 
1772  camera_horizontal[0] = camera_horizontal_temp[0];
1773  camera_horizontal[1] = camera_horizontal_temp[1];
1774 
1775  // translate the camera to the given triangulation
1776  camera_position[0] = x_min + .5 * x_dimension;
1777  camera_position[1] = y_min + .5 * y_dimension;
1778 
1779  camera_position[0] += 2. * std::max(x_dimension, y_dimension) *
1780  sin(angle_factor * svg_flags.polar_angle) *
1781  sin(angle_factor * svg_flags.azimuth_angle);
1782  camera_position[1] -= 2. * std::max(x_dimension, y_dimension) *
1783  sin(angle_factor * svg_flags.polar_angle) *
1784  cos(angle_factor * svg_flags.azimuth_angle);
1785 
1786 
1787  // determine the bounding box of the given triangulation on the projection
1788  // plane of the camera viewing system
1789  point[0] = tria.begin()->vertex(0)[0];
1790  point[1] = tria.begin()->vertex(0)[1];
1791  point[2] = 0;
1792 
1793  float min_level_min_vertex_distance = 0;
1794 
1796  {
1797  point[2] = svg_flags.level_height_factor *
1798  ((float)tria.begin()->level() / (float)n_levels) *
1799  std::max(x_dimension, y_dimension);
1800  }
1801 
1802  projection_decomposition = GridOut::svg_project_point(
1803  point, camera_position, camera_direction, camera_horizontal, camera_focus);
1804 
1805  x_max_perspective = projection_decomposition[0];
1806  x_min_perspective = projection_decomposition[0];
1807 
1808  y_max_perspective = projection_decomposition[1];
1809  y_min_perspective = projection_decomposition[1];
1810 
1811  for (Triangulation<2, 2>::cell_iterator cell = tria.begin();
1812  cell != tria.end();
1813  ++cell)
1814  {
1815  point[0] = cell->vertex(0)[0];
1816  point[1] = cell->vertex(0)[1];
1817  point[2] = 0;
1818 
1820  {
1821  point[2] = svg_flags.level_height_factor *
1822  ((float)cell->level() / (float)n_levels) *
1823  std::max(x_dimension, y_dimension);
1824  }
1825 
1826  projection_decomposition = GridOut::svg_project_point(point,
1827  camera_position,
1828  camera_direction,
1829  camera_horizontal,
1830  camera_focus);
1831 
1832  if (x_max_perspective < projection_decomposition[0])
1833  x_max_perspective = projection_decomposition[0];
1834  if (x_min_perspective > projection_decomposition[0])
1835  x_min_perspective = projection_decomposition[0];
1836 
1837  if (y_max_perspective < projection_decomposition[1])
1838  y_max_perspective = projection_decomposition[1];
1839  if (y_min_perspective > projection_decomposition[1])
1840  y_min_perspective = projection_decomposition[1];
1841 
1842  point[0] = cell->vertex(1)[0];
1843  point[1] = cell->vertex(1)[1];
1844 
1845  projection_decomposition = GridOut::svg_project_point(point,
1846  camera_position,
1847  camera_direction,
1848  camera_horizontal,
1849  camera_focus);
1850 
1851  if (x_max_perspective < projection_decomposition[0])
1852  x_max_perspective = projection_decomposition[0];
1853  if (x_min_perspective > projection_decomposition[0])
1854  x_min_perspective = projection_decomposition[0];
1855 
1856  if (y_max_perspective < projection_decomposition[1])
1857  y_max_perspective = projection_decomposition[1];
1858  if (y_min_perspective > projection_decomposition[1])
1859  y_min_perspective = projection_decomposition[1];
1860 
1861  point[0] = cell->vertex(2)[0];
1862  point[1] = cell->vertex(2)[1];
1863 
1864  projection_decomposition = GridOut::svg_project_point(point,
1865  camera_position,
1866  camera_direction,
1867  camera_horizontal,
1868  camera_focus);
1869 
1870  if (x_max_perspective < projection_decomposition[0])
1871  x_max_perspective = projection_decomposition[0];
1872  if (x_min_perspective > projection_decomposition[0])
1873  x_min_perspective = projection_decomposition[0];
1874 
1875  if (y_max_perspective < projection_decomposition[1])
1876  y_max_perspective = projection_decomposition[1];
1877  if (y_min_perspective > projection_decomposition[1])
1878  y_min_perspective = projection_decomposition[1];
1879 
1880  point[0] = cell->vertex(3)[0];
1881  point[1] = cell->vertex(3)[1];
1882 
1883  projection_decomposition = GridOut::svg_project_point(point,
1884  camera_position,
1885  camera_direction,
1886  camera_horizontal,
1887  camera_focus);
1888 
1889  if (x_max_perspective < projection_decomposition[0])
1890  x_max_perspective = projection_decomposition[0];
1891  if (x_min_perspective > projection_decomposition[0])
1892  x_min_perspective = projection_decomposition[0];
1893 
1894  if (y_max_perspective < projection_decomposition[1])
1895  y_max_perspective = projection_decomposition[1];
1896  if (y_min_perspective > projection_decomposition[1])
1897  y_min_perspective = projection_decomposition[1];
1898 
1899  if ((unsigned int)cell->level() == min_level)
1900  min_level_min_vertex_distance = cell->minimum_vertex_distance();
1901  }
1902 
1903  x_dimension_perspective = x_max_perspective - x_min_perspective;
1904  y_dimension_perspective = y_max_perspective - y_min_perspective;
1905 
1906  // create the svg file with an internal style sheet
1907  if (width == 0)
1908  width = static_cast<unsigned int>(
1909  .5 + height * (x_dimension_perspective / y_dimension_perspective));
1910  else if (height == 0)
1911  height = static_cast<unsigned int>(
1912  .5 + width * (y_dimension_perspective / x_dimension_perspective));
1913  unsigned int additional_width = 0;
1914  // font size for date, time, legend, and colorbar
1915  unsigned int font_size =
1916  static_cast<unsigned int>(.5 + (height / 100.) * 1.75);
1917  cell_label_font_size = static_cast<unsigned int>(
1918  .5 + (height * .15 * svg_flags.cell_font_scaling *
1919  min_level_min_vertex_distance / std::min(x_dimension, y_dimension)));
1920 
1921  if (svg_flags.draw_legend &&
1925  {
1926  additional_width = static_cast<unsigned int>(
1927  .5 + height * .4); // additional width for legend
1928  }
1929  else if (svg_flags.draw_colorbar && svg_flags.coloring)
1930  {
1931  additional_width = static_cast<unsigned int>(
1932  .5 + height * .175); // additional width for colorbar
1933  }
1934 
1935  // out << "<!-- deal.ii GridOut " << now->tm_mday << '/' << now->tm_mon + 1 <<
1936  // '/' << now->tm_year + 1900
1937  // << ' ' << now->tm_hour << ':';
1938  //
1939  // if (now->tm_min < 10) out << '0';
1940  //
1941  // out << now->tm_min << " -->" << '\n';
1942 
1943  // basic svg header
1944  out << "<svg width=\"" << width + additional_width << "\" height=\"" << height
1945  << "\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">" << '\n'
1946  << '\n';
1947 
1948 
1949  if (svg_flags.background == GridOutFlags::Svg::dealii)
1950  {
1951  out
1952  << " <linearGradient id=\"background_gradient\" gradientUnits=\"userSpaceOnUse\" x1=\"0\" y1=\"0\" x2=\"0\" y2=\""
1953  << height << "\">" << '\n'
1954  << " <stop offset=\"0\" style=\"stop-color:white\"/>" << '\n'
1955  << " <stop offset=\"1\" style=\"stop-color:lightsteelblue\"/>" << '\n'
1956  << " </linearGradient>" << '\n';
1957  }
1958 
1959  out << '\n';
1960 
1961  // header for the internal style sheet
1962  out << "<!-- internal style sheet -->" << '\n'
1963  << "<style type=\"text/css\"><![CDATA[" << '\n';
1964 
1965  // set the background of the output graphic
1966  if (svg_flags.background == GridOutFlags::Svg::dealii)
1967  out << " rect.background{fill:url(#background_gradient)}" << '\n';
1968  else if (svg_flags.background == GridOutFlags::Svg::white)
1969  out << " rect.background{fill:white}" << '\n';
1970  else
1971  out << " rect.background{fill:none}" << '\n';
1972 
1973  // basic svg graphic element styles
1974  out << " rect{fill:none; stroke:rgb(25,25,25); stroke-width:"
1975  << svg_flags.line_thickness << '}' << '\n'
1976  << " text{font-family:Helvetica; text-anchor:middle; fill:rgb(25,25,25)}"
1977  << '\n'
1978  << " line{stroke:rgb(25,25,25); stroke-width:"
1979  << svg_flags.boundary_line_thickness << '}' << '\n'
1980  << " path{fill:none; stroke:rgb(25,25,25); stroke-width:"
1981  << svg_flags.line_thickness << '}' << '\n'
1982  << '\n';
1983 
1984  // polygon styles with respect to the chosen cell coloring
1985  if (svg_flags.coloring)
1986  {
1987  unsigned int labeling_index = 0;
1988 
1989  for (unsigned int index = 0; index < n; index++)
1990  {
1991  double h;
1992 
1993  if (n != 1)
1994  h = .6 - (index / (n - 1.)) * .6;
1995  else
1996  h = .6;
1997 
1998  unsigned int r = 0;
1999  unsigned int g = 0;
2000  unsigned int b = 0;
2001 
2002  unsigned int i = static_cast<unsigned int>(h * 6);
2003 
2004  double f = h * 6 - i;
2005  double q = 1 - f;
2006  double t = f;
2007 
2008  switch (i % 6)
2009  {
2010  case 0:
2011  r = 255, g = static_cast<unsigned int>(.5 + 255 * t);
2012  break;
2013  case 1:
2014  r = static_cast<unsigned int>(.5 + 255 * q), g = 255;
2015  break;
2016  case 2:
2017  g = 255, b = static_cast<unsigned int>(.5 + 255 * t);
2018  break;
2019  case 3:
2020  g = static_cast<unsigned int>(.5 + 255 * q), b = 255;
2021  break;
2022  case 4:
2023  r = static_cast<unsigned int>(.5 + 255 * t), b = 255;
2024  break;
2025  case 5:
2026  r = 255, b = static_cast<unsigned int>(.5 + 255 * q);
2027  break;
2028  default:
2029  break;
2030  }
2031 
2032  switch (svg_flags.coloring)
2033  {
2035  while (!materials[labeling_index])
2036  labeling_index++;
2037  break;
2039  while (!levels[labeling_index])
2040  labeling_index++;
2041  break;
2043  while (!subdomains[labeling_index])
2044  labeling_index++;
2045  break;
2047  while (!level_subdomains[labeling_index])
2048  labeling_index++;
2049  break;
2050  default:
2051  break;
2052  }
2053 
2054  out << " path.p" << labeling_index << "{fill:rgb(" << r << ',' << g
2055  << ',' << b << "); "
2056  << "stroke:rgb(25,25,25); stroke-width:"
2057  << svg_flags.line_thickness << '}' << '\n';
2058 
2059  out << " path.ps" << labeling_index << "{fill:rgb("
2060  << static_cast<unsigned int>(.5 + .75 * r) << ','
2061  << static_cast<unsigned int>(.5 + .75 * g) << ','
2062  << static_cast<unsigned int>(.5 + .75 * b) << "); "
2063  << "stroke:rgb(20,20,20); stroke-width:"
2064  << svg_flags.line_thickness << '}' << '\n';
2065 
2066  out << " rect.r" << labeling_index << "{fill:rgb(" << r << ',' << g
2067  << ',' << b << "); "
2068  << "stroke:rgb(25,25,25); stroke-width:"
2069  << svg_flags.line_thickness << '}' << '\n';
2070 
2071  labeling_index++;
2072  }
2073  }
2074 
2075  out << "]]></style>" << '\n' << '\n';
2076 
2077  // background rectangle
2078  out << " <rect class=\"background\" width=\"" << width << "\" height=\""
2079  << height << "\"/>" << '\n';
2080 
2081  if (svg_flags.background == GridOutFlags::Svg::dealii)
2082  {
2083  unsigned int x_offset = 0;
2084 
2085  if (svg_flags.margin)
2086  x_offset = static_cast<unsigned int>(.5 + (height / 100.) *
2087  (margin_in_percent / 2.));
2088  else
2089  x_offset = static_cast<unsigned int>(.5 + height * .025);
2090 
2091  out
2092  << " <text x=\"" << x_offset << "\" y=\""
2093  << static_cast<unsigned int>(.5 + height * .0525) << '\"'
2094  << " style=\"font-weight:100; fill:lightsteelblue; text-anchor:start; font-family:Courier; font-size:"
2095  << static_cast<unsigned int>(.5 + height * .045) << "px\">"
2096  << "deal.II"
2097  << "</text>" << '\n';
2098 
2099  // out << " <text x=\"" << x_offset + static_cast<unsigned int>(.5 +
2100  // height * .045 * 4.75) << "\" y=\"" << static_cast<unsigned int>(.5 +
2101  // height * .0525) << '\"'
2102  // << " style=\"fill:lightsteelblue; text-anchor:start; font-size:" <<
2103  // font_size << "\">"
2104  // << now->tm_mday << '/' << now->tm_mon + 1 << '/' << now->tm_year +
2105  // 1900
2106  // << " - " << now->tm_hour << ':';
2107  //
2108  // if(now->tm_min < 10) out << '0';
2109  //
2110  // out << now->tm_min
2111  // << "</text>"<< '\n' << '\n';
2112  }
2113 
2114  // draw the cells, starting out from the minimal level (in order to guaranty a
2115  // correct perspective view)
2116  out << " <!-- cells -->" << '\n';
2117 
2118  for (unsigned int level_index = min_level; level_index <= max_level;
2119  level_index++)
2120  {
2121  Triangulation<2, 2>::cell_iterator cell = tria.begin(level_index),
2122  endc = tria.end(level_index);
2123 
2124  for (; cell != endc; ++cell)
2125  {
2126  if (!svg_flags.convert_level_number_to_height && !cell->active())
2127  continue;
2128 
2129  // draw the current cell
2130  out << " <path";
2131 
2132  if (svg_flags.coloring)
2133  {
2134  out << " class=\"p";
2135 
2136  if (!cell->active() && svg_flags.convert_level_number_to_height)
2137  out << 's';
2138 
2139  switch (svg_flags.coloring)
2140  {
2142  out << (unsigned int)cell->material_id();
2143  break;
2145  out << (unsigned int)cell->level();
2146  break;
2148  if (cell->active())
2149  out << cell->subdomain_id() + 2;
2150  else
2151  out << 'X';
2152  break;
2154  out << cell->level_subdomain_id() + 2;
2155  break;
2156  default:
2157  break;
2158  }
2159 
2160  out << '\"';
2161  }
2162 
2163  out << " d=\"M ";
2164 
2165  point[0] = cell->vertex(0)[0];
2166  point[1] = cell->vertex(0)[1];
2167  point[2] = 0;
2168 
2170  {
2171  point[2] = svg_flags.level_height_factor *
2172  ((float)cell->level() / (float)n_levels) *
2173  std::max(x_dimension, y_dimension);
2174  }
2175 
2176  projection_decomposition =
2178  camera_position,
2179  camera_direction,
2180  camera_horizontal,
2181  camera_focus);
2182 
2183  out << static_cast<unsigned int>(
2184  .5 +
2185  ((projection_decomposition[0] - x_min_perspective) /
2186  x_dimension_perspective) *
2187  (width - (width / 100.) * 2. * margin_in_percent) +
2188  ((width / 100.) * margin_in_percent))
2189  << ' '
2190  << static_cast<unsigned int>(
2191  .5 + height - (height / 100.) * margin_in_percent -
2192  ((projection_decomposition[1] - y_min_perspective) /
2193  y_dimension_perspective) *
2194  (height - (height / 100.) * 2. * margin_in_percent));
2195 
2196  out << " L ";
2197 
2198  point[0] = cell->vertex(1)[0];
2199  point[1] = cell->vertex(1)[1];
2200 
2201  projection_decomposition =
2203  camera_position,
2204  camera_direction,
2205  camera_horizontal,
2206  camera_focus);
2207 
2208  out << static_cast<unsigned int>(
2209  .5 +
2210  ((projection_decomposition[0] - x_min_perspective) /
2211  x_dimension_perspective) *
2212  (width - (width / 100.) * 2. * margin_in_percent) +
2213  ((width / 100.) * margin_in_percent))
2214  << ' '
2215  << static_cast<unsigned int>(
2216  .5 + height - (height / 100.) * margin_in_percent -
2217  ((projection_decomposition[1] - y_min_perspective) /
2218  y_dimension_perspective) *
2219  (height - (height / 100.) * 2. * margin_in_percent));
2220 
2221  out << " L ";
2222 
2223  point[0] = cell->vertex(3)[0];
2224  point[1] = cell->vertex(3)[1];
2225 
2226  projection_decomposition =
2228  camera_position,
2229  camera_direction,
2230  camera_horizontal,
2231  camera_focus);
2232 
2233  out << static_cast<unsigned int>(
2234  .5 +
2235  ((projection_decomposition[0] - x_min_perspective) /
2236  x_dimension_perspective) *
2237  (width - (width / 100.) * 2. * margin_in_percent) +
2238  ((width / 100.) * margin_in_percent))
2239  << ' '
2240  << static_cast<unsigned int>(
2241  .5 + height - (height / 100.) * margin_in_percent -
2242  ((projection_decomposition[1] - y_min_perspective) /
2243  y_dimension_perspective) *
2244  (height - (height / 100.) * 2. * margin_in_percent));
2245 
2246  out << " L ";
2247 
2248  point[0] = cell->vertex(2)[0];
2249  point[1] = cell->vertex(2)[1];
2250 
2251  projection_decomposition =
2253  camera_position,
2254  camera_direction,
2255  camera_horizontal,
2256  camera_focus);
2257 
2258  out << static_cast<unsigned int>(
2259  .5 +
2260  ((projection_decomposition[0] - x_min_perspective) /
2261  x_dimension_perspective) *
2262  (width - (width / 100.) * 2. * margin_in_percent) +
2263  ((width / 100.) * margin_in_percent))
2264  << ' '
2265  << static_cast<unsigned int>(
2266  .5 + height - (height / 100.) * margin_in_percent -
2267  ((projection_decomposition[1] - y_min_perspective) /
2268  y_dimension_perspective) *
2269  (height - (height / 100.) * 2. * margin_in_percent));
2270 
2271  out << " L ";
2272 
2273  point[0] = cell->vertex(0)[0];
2274  point[1] = cell->vertex(0)[1];
2275 
2276  projection_decomposition =
2278  camera_position,
2279  camera_direction,
2280  camera_horizontal,
2281  camera_focus);
2282 
2283  out << static_cast<unsigned int>(
2284  .5 +
2285  ((projection_decomposition[0] - x_min_perspective) /
2286  x_dimension_perspective) *
2287  (width - (width / 100.) * 2. * margin_in_percent) +
2288  ((width / 100.) * margin_in_percent))
2289  << ' '
2290  << static_cast<unsigned int>(
2291  .5 + height - (height / 100.) * margin_in_percent -
2292  ((projection_decomposition[1] - y_min_perspective) /
2293  y_dimension_perspective) *
2294  (height - (height / 100.) * 2. * margin_in_percent));
2295 
2296  out << "\"/>" << '\n';
2297 
2298  // label the current cell
2302  {
2303  point[0] = cell->center()[0];
2304  point[1] = cell->center()[1];
2305  point[2] = 0;
2306 
2308  {
2309  point[2] = svg_flags.level_height_factor *
2310  ((float)cell->level() / (float)n_levels) *
2311  std::max(x_dimension, y_dimension);
2312  }
2313 
2314  float distance_to_camera =
2315  sqrt(pow(point[0] - camera_position[0], 2.) +
2316  pow(point[1] - camera_position[1], 2.) +
2317  pow(point[2] - camera_position[2], 2.));
2318  float distance_factor =
2319  distance_to_camera / (2. * std::max(x_dimension, y_dimension));
2320 
2321  projection_decomposition =
2323  camera_position,
2324  camera_direction,
2325  camera_horizontal,
2326  camera_focus);
2327 
2328  const unsigned int font_size_this_cell =
2329  static_cast<unsigned int>(
2330  .5 +
2331  cell_label_font_size *
2332  pow(.5, (float)cell->level() - 4. + 3.5 * distance_factor));
2333 
2334  out << " <text"
2335  << " x=\""
2336  << static_cast<unsigned int>(
2337  .5 +
2338  ((projection_decomposition[0] - x_min_perspective) /
2339  x_dimension_perspective) *
2340  (width - (width / 100.) * 2. * margin_in_percent) +
2341  ((width / 100.) * margin_in_percent))
2342  << "\" y=\""
2343  << static_cast<unsigned int>(
2344  .5 + height - (height / 100.) * margin_in_percent -
2345  ((projection_decomposition[1] - y_min_perspective) /
2346  y_dimension_perspective) *
2347  (height - (height / 100.) * 2. * margin_in_percent) +
2348  0.5 * font_size_this_cell)
2349  << "\" style=\"font-size:" << font_size_this_cell << "px\">";
2350 
2352  {
2353  out << cell->level();
2354  }
2355 
2357  {
2359  out << ',';
2360  out << cell->index();
2361  }
2362 
2364  {
2367  out << ',';
2368  out << (int)cell->material_id();
2369  }
2370 
2372  {
2375  out << ',';
2376  if (cell->active())
2377  out << static_cast<int>(cell->subdomain_id());
2378  else
2379  out << 'X';
2380  }
2381 
2383  {
2388  out << ',';
2389  out << static_cast<int>(cell->level_subdomain_id());
2390  }
2391 
2392  out << "</text>" << '\n';
2393  }
2394 
2395  // if the current cell lies at the boundary of the triangulation, draw
2396  // the additional boundary line
2398  {
2399  for (unsigned int faceIndex = 0; faceIndex < 4; faceIndex++)
2400  {
2401  if (cell->at_boundary(faceIndex))
2402  {
2403  point[0] = cell->face(faceIndex)->vertex(0)[0];
2404  point[1] = cell->face(faceIndex)->vertex(0)[1];
2405  point[2] = 0;
2406 
2408  {
2409  point[2] = svg_flags.level_height_factor *
2410  ((float)cell->level() / (float)n_levels) *
2411  std::max(x_dimension, y_dimension);
2412  }
2413 
2414  projection_decomposition =
2416  camera_position,
2417  camera_direction,
2418  camera_horizontal,
2419  camera_focus);
2420 
2421  out << " <line x1=\""
2422  << static_cast<unsigned int>(
2423  .5 +
2424  ((projection_decomposition[0] -
2425  x_min_perspective) /
2426  x_dimension_perspective) *
2427  (width -
2428  (width / 100.) * 2. * margin_in_percent) +
2429  ((width / 100.) * margin_in_percent))
2430  << "\" y1=\""
2431  << static_cast<unsigned int>(
2432  .5 + height -
2433  (height / 100.) * margin_in_percent -
2434  ((projection_decomposition[1] -
2435  y_min_perspective) /
2436  y_dimension_perspective) *
2437  (height -
2438  (height / 100.) * 2. * margin_in_percent));
2439 
2440  point[0] = cell->face(faceIndex)->vertex(1)[0];
2441  point[1] = cell->face(faceIndex)->vertex(1)[1];
2442  point[2] = 0;
2443 
2445  {
2446  point[2] = svg_flags.level_height_factor *
2447  ((float)cell->level() / (float)n_levels) *
2448  std::max(x_dimension, y_dimension);
2449  }
2450 
2451  projection_decomposition =
2453  camera_position,
2454  camera_direction,
2455  camera_horizontal,
2456  camera_focus);
2457 
2458  out << "\" x2=\""
2459  << static_cast<unsigned int>(
2460  .5 +
2461  ((projection_decomposition[0] -
2462  x_min_perspective) /
2463  x_dimension_perspective) *
2464  (width -
2465  (width / 100.) * 2. * margin_in_percent) +
2466  ((width / 100.) * margin_in_percent))
2467  << "\" y2=\""
2468  << static_cast<unsigned int>(
2469  .5 + height -
2470  (height / 100.) * margin_in_percent -
2471  ((projection_decomposition[1] -
2472  y_min_perspective) /
2473  y_dimension_perspective) *
2474  (height -
2475  (height / 100.) * 2. * margin_in_percent))
2476  << "\"/>" << '\n';
2477  }
2478  }
2479  }
2480  }
2481  }
2482 
2483 
2484  // draw the legend
2485  if (svg_flags.draw_legend)
2486  out << '\n' << " <!-- legend -->" << '\n';
2487 
2488  additional_width = 0;
2489  if (!svg_flags.margin)
2490  additional_width = static_cast<unsigned int>(.5 + (height / 100.) * 2.5);
2491 
2492  // explanation of the cell labeling
2493  if (svg_flags.draw_legend &&
2497  {
2498  unsigned int line_offset = 0;
2499  out << " <rect x=\"" << width + additional_width << "\" y=\""
2500  << static_cast<unsigned int>(.5 + (height / 100.) * margin_in_percent)
2501  << "\" width=\""
2502  << static_cast<unsigned int>(.5 + (height / 100.) *
2503  (40. - margin_in_percent))
2504  << "\" height=\"" << static_cast<unsigned int>(.5 + height * .165)
2505  << "\"/>" << '\n';
2506 
2507  out << " <text x=\""
2508  << width + additional_width +
2509  static_cast<unsigned int>(.5 + (height / 100.) * 1.25)
2510  << "\" y=\""
2511  << static_cast<unsigned int>(.5 +
2512  (height / 100.) * margin_in_percent +
2513  (++line_offset) * 1.5 * font_size)
2514  << "\" style=\"text-anchor:start; font-weight:bold; font-size:"
2515  << font_size << "px\">"
2516  << "cell label"
2517  << "</text>" << '\n';
2518 
2520  {
2521  out << " <text x=\""
2522  << width + additional_width +
2523  static_cast<unsigned int>(.5 + (height / 100.) * 2.)
2524  << "\" y=\""
2525  << static_cast<unsigned int>(.5 +
2526  (height / 100.) * margin_in_percent +
2527  (++line_offset) * 1.5 * font_size)
2528  << "\" style=\"text-anchor:start; font-style:oblique; font-size:"
2529  << font_size << "px\">"
2530  << "level_number";
2531 
2535  out << ',';
2536 
2537  out << "</text>" << '\n';
2538  }
2539 
2541  {
2542  out << " <text x=\""
2543  << width + additional_width +
2544  static_cast<unsigned int>(.5 + (height / 100.) * 2.)
2545  << "\" y=\""
2546  << static_cast<unsigned int>(.5 +
2547  (height / 100.) * margin_in_percent +
2548  (++line_offset) * 1.5 * font_size)
2549  << "\" style=\"text-anchor:start; font-style:oblique; font-size:"
2550  << font_size << "px\">"
2551  << "cell_index";
2552 
2555  out << ',';
2556 
2557  out << "</text>" << '\n';
2558  }
2559 
2561  {
2562  out << " <text x=\""
2563  << width + additional_width +
2564  static_cast<unsigned int>(.5 + (height / 100.) * 2.)
2565  << "\" y=\""
2566  << static_cast<unsigned int>(.5 +
2567  (height / 100.) * margin_in_percent +
2568  (++line_offset) * 1.5 * font_size)
2569  << "\" style=\"text-anchor:start; font-style:oblique; font-size:"
2570  << font_size << "px\">"
2571  << "material_id";
2572 
2575  out << ',';
2576 
2577  out << "</text>" << '\n';
2578  }
2579 
2581  {
2582  out << " <text x= \""
2583  << width + additional_width +
2584  static_cast<unsigned int>(.5 + (height / 100.) * 2.)
2585  << "\" y=\""
2586  << static_cast<unsigned int>(.5 +
2587  (height / 100.) * margin_in_percent +
2588  (++line_offset) * 1.5 * font_size)
2589  << "\" style=\"text-anchor:start; font-style:oblique; font-size:"
2590  << font_size << "px\">"
2591  << "subdomain_id";
2592 
2594  out << ',';
2595 
2596  out << "</text>" << '\n';
2597  }
2598 
2600  {
2601  out << " <text x= \""
2602  << width + additional_width +
2603  static_cast<unsigned int>(.5 + (height / 100.) * 2.)
2604  << "\" y=\""
2605  << static_cast<unsigned int>(.5 +
2606  (height / 100.) * margin_in_percent +
2607  (++line_offset) * 1.5 * font_size)
2608  << "\" style=\"text-anchor:start; font-style:oblique; font-size:"
2609  << font_size << "px\">"
2610  << "level_subdomain_id"
2611  << "</text>" << '\n';
2612  }
2613  }
2614 
2615  // show azimuth angle and polar angle as text below the explanation of the
2616  // cell labeling
2617  if (svg_flags.draw_legend)
2618  {
2619  out << " <text x=\"" << width + additional_width << "\" y=\""
2620  << static_cast<unsigned int>(
2621  .5 + (height / 100.) * margin_in_percent + 10.75 * font_size)
2622  << "\" style=\"text-anchor:start; font-size:" << font_size << "px\">"
2623  << "azimuth: " << svg_flags.azimuth_angle
2624  << "°, polar: " << svg_flags.polar_angle << "°</text>" << '\n';
2625  }
2626 
2627 
2628  // draw the colorbar
2629  if (svg_flags.draw_colorbar && svg_flags.coloring)
2630  {
2631  out << '\n' << " <!-- colorbar -->" << '\n';
2632 
2633  out << " <text x=\"" << width + additional_width << "\" y=\""
2634  << static_cast<unsigned int>(
2635  .5 + (height / 100.) * (margin_in_percent + 29.) -
2636  (font_size / 1.25))
2637  << "\" style=\"text-anchor:start; font-weight:bold; font-size:"
2638  << font_size << "px\">";
2639 
2640  switch (svg_flags.coloring)
2641  {
2642  case 1:
2643  out << "material_id";
2644  break;
2645  case 2:
2646  out << "level_number";
2647  break;
2648  case 3:
2649  out << "subdomain_id";
2650  break;
2651  case 4:
2652  out << "level_subdomain_id";
2653  break;
2654  default:
2655  break;
2656  }
2657 
2658  out << "</text>" << '\n';
2659 
2660  unsigned int element_height = static_cast<unsigned int>(
2661  ((height / 100.) * (71. - 2. * margin_in_percent)) / n);
2662  unsigned int element_width =
2663  static_cast<unsigned int>(.5 + (height / 100.) * 2.5);
2664 
2665  int labeling_index = 0;
2666 
2667  for (unsigned int index = 0; index < n; index++)
2668  {
2669  switch (svg_flags.coloring)
2670  {
2672  while (!materials[labeling_index])
2673  labeling_index++;
2674  break;
2676  while (!levels[labeling_index])
2677  labeling_index++;
2678  break;
2680  while (!subdomains[labeling_index])
2681  labeling_index++;
2682  break;
2684  while (!level_subdomains[labeling_index])
2685  labeling_index++;
2686  break;
2687  default:
2688  break;
2689  }
2690 
2691  out << " <rect class=\"r" << labeling_index << "\" x=\""
2692  << width + additional_width << "\" y=\""
2693  << static_cast<unsigned int>(.5 + (height / 100.) *
2694  (margin_in_percent + 29)) +
2695  (n - index - 1) * element_height
2696  << "\" width=\"" << element_width << "\" height=\""
2697  << element_height << "\"/>" << '\n';
2698 
2699  out << " <text x=\""
2700  << width + additional_width + 1.5 * element_width << "\" y=\""
2701  << static_cast<unsigned int>(.5 + (height / 100.) *
2702  (margin_in_percent + 29)) +
2703  (n - index - 1 + .5) * element_height +
2704  static_cast<unsigned int>(.5 + font_size * .35)
2705  << "\""
2706  << " style=\"text-anchor:start; font-size:"
2707  << static_cast<unsigned int>(.5 + font_size) << "px";
2708 
2709  if (index == 0 || index == n - 1)
2710  out << "; font-weight:bold";
2711 
2712  out << "\">" << labeling_index;
2713 
2714  if (index == n - 1)
2715  out << " max";
2716  if (index == 0)
2717  out << " min";
2718 
2719  out << "</text>" << '\n';
2720 
2721  labeling_index++;
2722  }
2723  }
2724 
2725 
2726  // finalize the svg file
2727  out << '\n' << "</svg>";
2728  out.flush();
2729 }
2730 
2731 
2732 template <>
2733 void
2734 GridOut::write_mathgl(const Triangulation<1> &, std::ostream &) const
2735 {
2736  // 1d specialization not done yet
2737  Assert(false, ExcNotImplemented());
2738 }
2739 
2740 
2741 template <int dim, int spacedim>
2742 void
2744  std::ostream & out) const
2745 {
2746  AssertThrow(out, ExcIO());
2747 
2748  // (i) write header
2749  if (true)
2750  {
2751  // block this to have local variables destroyed after use
2752  const std::time_t time1 = std::time(nullptr);
2753  const std::tm * time = std::localtime(&time1);
2754 
2755  out
2756  << "\n#"
2757  << "\n# This file was generated by the deal.II library."
2758  << "\n# Date = " << time->tm_year + 1900 << "/" << std::setfill('0')
2759  << std::setw(2) << time->tm_mon + 1 << "/" << std::setfill('0')
2760  << std::setw(2) << time->tm_mday
2761  << "\n# Time = " << std::setfill('0') << std::setw(2)
2762  << time->tm_hour << ":" << std::setfill('0') << std::setw(2)
2763  << time->tm_min << ":" << std::setfill('0') << std::setw(2)
2764  << time->tm_sec << "\n#"
2765  << "\n# For a description of the MathGL script format see the MathGL manual. "
2766  << "\n#"
2767  << "\n# Note: This file is understood by MathGL v2.1 and higher only, and can "
2768  << "\n# be quickly viewed in a graphical environment using \'mglview\'. "
2769  << "\n#"
2770  << "\n";
2771  }
2772 
2773  // define a helper to keep loops approximately dim-independent
2774  // since MathGL labels axes as x, y, z
2775  const std::string axes = "xyz";
2776 
2777  // (ii) write preamble and graphing tweaks
2778  out << "\n#"
2779  << "\n# Preamble."
2780  << "\n#"
2781  << "\n";
2782 
2784  out << "\nbox";
2785 
2786  // deal with dimension dependent preamble; eg. default sizes and
2787  // views for MathGL (cf. gnuplot).
2788  switch (dim)
2789  {
2790  case 2:
2791  out << "\nsetsize 800 800";
2792  out << "\nrotate 0 0";
2793  break;
2794  case 3:
2795  out << "\nsetsize 800 800";
2796  out << "\nrotate 60 40";
2797  break;
2798  default:
2799  Assert(false, ExcNotImplemented());
2800  }
2801  out << "\n";
2802 
2803  // (iii) write vertex ordering
2804  out << "\n#"
2805  << "\n# Vertex ordering."
2806  << "\n# list <vertex order> <vertex indices>"
2807  << "\n#"
2808  << "\n";
2809 
2810  // todo: This denotes the natural ordering of vertices, but it needs
2811  // to check this is really always true for a given grid (it's not
2812  // true in @ref step_1 "step-1" grid-2 for instance).
2813  switch (dim)
2814  {
2815  case 2:
2816  out << "\nlist f 0 1 2 3"
2817  << "\n";
2818  break;
2819  case 3:
2820  out
2821  << "\nlist f 0 2 4 6 | 1 3 5 7 | 0 4 1 5 | 2 6 3 7 | 0 1 2 3 | 4 5 6 7"
2822  << "\n";
2823  break;
2824  default:
2825  Assert(false, ExcNotImplemented());
2826  }
2827 
2828  // (iv) write a list of vertices of cells
2829  out << "\n#"
2830  << "\n# List of vertices."
2831  << "\n# list <id> <vertices>"
2832  << "\n#"
2833  << "\n";
2834 
2835  // run over all active cells and write out a list of
2836  // xyz-coordinates that correspond to vertices
2837  typename ::Triangulation<dim, spacedim>::active_cell_iterator
2838  cell = tria.begin_active(),
2839  endc = tria.end();
2840 
2841  // No global indices in deal.II, so we make one up here.
2842  for (; cell != endc; ++cell)
2843  {
2844  for (unsigned int i = 0; i < dim; ++i)
2845  {
2846  // if (cell->direction_flag ()==true)
2847  // out << "\ntrue";
2848  // else
2849  // out << "\nfalse";
2850 
2851  out << "\nlist " << axes[i] << cell->active_cell_index() << " ";
2852  for (unsigned int j = 0; j < GeometryInfo<dim>::vertices_per_cell;
2853  ++j)
2854  out << cell->vertex(j)[i] << " ";
2855  }
2856  out << '\n';
2857  }
2858 
2859  // (v) write out cells to plot as quadplot objects
2860  out << "\n#"
2861  << "\n# List of cells to quadplot."
2862  << "\n# quadplot <vertex order> <id> <style>"
2863  << "\n#"
2864  << "\n";
2865  for (unsigned int i = 0; i < tria.n_active_cells(); ++i)
2866  {
2867  out << "\nquadplot f ";
2868  for (unsigned int j = 0; j < dim; ++j)
2869  out << axes[j] << i << " ";
2870  out << "\'k#\'";
2871  }
2872  out << "\n";
2873 
2874  // (vi) write footer
2875  out << "\n#"
2876  << "\n#"
2877  << "\n#"
2878  << "\n";
2879 
2880  // make sure everything now gets to the output stream
2881  out.flush();
2882  AssertThrow(out, ExcIO());
2883 }
2884 
2885 
2886 
2887 namespace
2888 {
2895  template <int dim, int spacedim, typename ITERATOR, typename END>
2896  void
2897  generate_triangulation_patches(
2898  std::vector<DataOutBase::Patch<dim, spacedim>> &patches,
2899  ITERATOR cell,
2900  END end)
2901  {
2902  // convert each of the active cells into a patch
2903  for (; cell != end; ++cell)
2904  {
2906  patch.n_subdivisions = 1;
2908 
2909  for (unsigned int v = 0; v < GeometryInfo<dim>::vertices_per_cell; ++v)
2910  {
2911  patch.vertices[v] = cell->vertex(v);
2912  patch.data(0, v) = cell->level();
2913  patch.data(1, v) = static_cast<int>(cell->manifold_id());
2914  patch.data(2, v) = cell->material_id();
2915  if (!cell->has_children())
2916  patch.data(3, v) = static_cast<int>(cell->subdomain_id());
2917  else
2918  patch.data(3, v) = -1;
2919  patch.data(4, v) = static_cast<int>(cell->level_subdomain_id());
2920  }
2921  patches.push_back(patch);
2922  }
2923  }
2924 
2925  std::vector<std::string>
2926  triangulation_patch_data_names()
2927  {
2928  std::vector<std::string> v(5);
2929  v[0] = "level";
2930  v[1] = "manifold";
2931  v[2] = "material";
2932  v[3] = "subdomain";
2933  v[4] = "level_subdomain";
2934  return v;
2935  }
2936 } // namespace
2937 
2938 
2939 
2940 template <int dim, int spacedim>
2941 void
2943  std::ostream & out) const
2944 {
2945  AssertThrow(out, ExcIO());
2946 
2947  // convert the cells of the triangulation into a set of patches
2948  // and then have them output. since there is no data attached to
2949  // the geometry, we also do not have to provide any names, identifying
2950  // information, etc.
2951  std::vector<DataOutBase::Patch<dim, spacedim>> patches;
2952  patches.reserve(tria.n_active_cells());
2953  generate_triangulation_patches(patches, tria.begin_active(), tria.end());
2955  patches,
2956  triangulation_patch_data_names(),
2957  std::vector<
2958  std::tuple<unsigned int,
2959  unsigned int,
2960  std::string,
2962  vtk_flags,
2963  out);
2964 
2965  AssertThrow(out, ExcIO());
2966 }
2967 
2968 
2969 
2970 template <int dim, int spacedim>
2971 void
2973  std::ostream & out) const
2974 {
2975  AssertThrow(out, ExcIO());
2976 
2977  // convert the cells of the triangulation into a set of patches
2978  // and then have them output. since there is no data attached to
2979  // the geometry, we also do not have to provide any names, identifying
2980  // information, etc.
2981  std::vector<DataOutBase::Patch<dim, spacedim>> patches;
2982  patches.reserve(tria.n_active_cells());
2983  generate_triangulation_patches(patches, tria.begin_active(), tria.end());
2985  patches,
2986  triangulation_patch_data_names(),
2987  std::vector<
2988  std::tuple<unsigned int,
2989  unsigned int,
2990  std::string,
2992  vtu_flags,
2993  out);
2994 
2995  AssertThrow(out, ExcIO());
2996 }
2997 
2998 
2999 
3000 template <int dim, int spacedim>
3001 void
3003  const Triangulation<dim, spacedim> &tria,
3004  const std::string & filename_without_extension,
3005  const bool view_levels,
3006  const bool include_artificial) const
3007 {
3008  std::vector<DataOutBase::Patch<dim, spacedim>> patches;
3009  const unsigned int n_datasets = 4;
3010  std::vector<std::string> data_names;
3011  data_names.emplace_back("level");
3012  data_names.emplace_back("subdomain");
3013  data_names.emplace_back("level_subdomain");
3014  data_names.emplace_back("proc_writing");
3015 
3016  const unsigned int n_q_points = GeometryInfo<dim>::vertices_per_cell;
3017 
3018  typename Triangulation<dim, spacedim>::cell_iterator cell, endc;
3019  for (cell = tria.begin(), endc = tria.end(); cell != endc; ++cell)
3020  {
3021  if (!view_levels)
3022  {
3023  if (cell->has_children())
3024  continue;
3025  if (!include_artificial &&
3026  cell->subdomain_id() == numbers::artificial_subdomain_id)
3027  continue;
3028  }
3029  else if (!include_artificial)
3030  {
3031  if (cell->has_children() &&
3032  cell->level_subdomain_id() == numbers::artificial_subdomain_id)
3033  continue;
3034  else if (!cell->has_children() &&
3035  cell->level_subdomain_id() ==
3037  cell->subdomain_id() == numbers::artificial_subdomain_id)
3038  continue;
3039  }
3040 
3042  patch.data.reinit(n_datasets, n_q_points);
3043  patch.points_are_available = false;
3044 
3045  for (unsigned int vertex = 0; vertex < n_q_points; ++vertex)
3046  {
3047  patch.vertices[vertex] = cell->vertex(vertex);
3048  patch.data(0, vertex) = cell->level();
3049  if (!cell->has_children())
3050  patch.data(1, vertex) =
3051  (double)static_cast<int>(cell->subdomain_id());
3052  else
3053  patch.data(1, vertex) = -1.0;
3054  patch.data(2, vertex) =
3055  (double)static_cast<int>(cell->level_subdomain_id());
3056  patch.data(3, vertex) = tria.locally_owned_subdomain();
3057  }
3058 
3059  for (unsigned int f = 0; f < GeometryInfo<dim>::faces_per_cell; ++f)
3061  patches.push_back(patch);
3062  }
3063 
3064  // only create .pvtu file if running in parallel
3065  // if not, just create a .vtu file with no reference
3066  // to the processor number
3067  std::string new_file = filename_without_extension + ".vtu";
3069  dynamic_cast<const parallel::Triangulation<dim, spacedim> *>(&tria))
3070  {
3071  new_file = filename_without_extension + ".proc" +
3072  Utilities::int_to_string(tr->locally_owned_subdomain(), 4) +
3073  ".vtu";
3074 
3075  // create .pvtu record
3076  if (tr->locally_owned_subdomain() == 0)
3077  {
3078  std::vector<std::string> filenames;
3079 
3080  // .pvtu needs to reference the files without a relative path because
3081  // it will be written in the same directory. For this, remove any
3082  // paths from filename.
3083  std::size_t pos = filename_without_extension.find_last_of('/');
3084  if (pos == std::string::npos)
3085  pos = 0;
3086  else
3087  pos += 1;
3088  const unsigned int n_procs =
3089  Utilities::MPI::n_mpi_processes(tr->get_communicator());
3090  for (unsigned int i = 0; i < n_procs; ++i)
3091  filenames.push_back(filename_without_extension.substr(pos) +
3092  ".proc" + Utilities::int_to_string(i, 4) +
3093  ".vtu");
3094 
3095  const std::string pvtu_master_filename =
3096  (filename_without_extension + ".pvtu");
3097  std::ofstream pvtu_master(pvtu_master_filename.c_str());
3098 
3100  data_out.attach_triangulation(*tr);
3101 
3102  // We need a dummy vector with the names of the data values in the
3103  // .vtu files in order that the .pvtu contains reference these values
3104  Vector<float> dummy_vector(tr->n_active_cells());
3105  data_out.add_data_vector(dummy_vector, "level");
3106  data_out.add_data_vector(dummy_vector, "subdomain");
3107  data_out.add_data_vector(dummy_vector, "level_subdomain");
3108  data_out.add_data_vector(dummy_vector, "proc_writing");
3109 
3110  data_out.build_patches();
3111 
3112  data_out.write_pvtu_record(pvtu_master, filenames);
3113  }
3114  }
3115 
3116  std::ofstream out(new_file.c_str());
3117  std::vector<
3118  std::tuple<unsigned int,
3119  unsigned int,
3120  std::string,
3122  vector_data_ranges;
3123  DataOutBase::VtkFlags flags;
3124  DataOutBase::write_vtu(patches, data_names, vector_data_ranges, flags, out);
3125 }
3126 
3127 
3128 
3129 unsigned int
3131 {
3132  return 0;
3133 }
3134 
3135 unsigned int
3137 {
3138  return 0;
3139 }
3140 
3141 
3142 unsigned int
3144 {
3145  return 0;
3146 }
3147 
3148 unsigned int
3150 {
3151  return 0;
3152 }
3153 
3154 unsigned int
3156 {
3157  return 0;
3158 }
3159 
3160 unsigned int
3162 {
3163  return 0;
3164 }
3165 
3166 unsigned int
3168 {
3169  return 0;
3170 }
3171 
3172 unsigned int
3174 {
3175  return 0;
3176 }
3177 
3178 
3179 
3180 template <int dim, int spacedim>
3181 unsigned int
3183 {
3185  unsigned int n_faces = 0;
3186 
3187  for (face = tria.begin_active_face(), endf = tria.end_face(); face != endf;
3188  ++face)
3189  if ((face->at_boundary()) && (face->boundary_id() != 0))
3190  n_faces++;
3191 
3192  return n_faces;
3193 }
3194 
3195 
3196 
3197 template <int dim, int spacedim>
3198 unsigned int
3200 {
3201  // save the user flags for lines so
3202  // we can use these flags to track
3203  // which ones we've already counted
3204  std::vector<bool> line_flags;
3205  const_cast<::Triangulation<dim, spacedim> &>(tria).save_user_flags_line(
3206  line_flags);
3207  const_cast<::Triangulation<dim, spacedim> &>(tria)
3208  .clear_user_flags_line();
3209 
3210  unsigned int n_lines = 0;
3211 
3213 
3214  for (cell = tria.begin_active(), endc = tria.end(); cell != endc; ++cell)
3215  for (unsigned int l = 0; l < GeometryInfo<dim>::lines_per_cell; ++l)
3216  if (cell->line(l)->at_boundary() && (cell->line(l)->boundary_id() != 0) &&
3217  (cell->line(l)->user_flag_set() == false))
3218  {
3219  ++n_lines;
3220  cell->line(l)->set_user_flag();
3221  }
3222 
3223  // at the end, restore the user
3224  // flags for the lines
3225  const_cast<::Triangulation<dim, spacedim> &>(tria).load_user_flags_line(
3226  line_flags);
3227 
3228  return n_lines;
3229 }
3230 
3231 
3232 
3233 unsigned int
3235  const unsigned int next_element_index,
3236  std::ostream &) const
3237 {
3238  return next_element_index;
3239 }
3240 
3241 
3242 unsigned int
3244  const unsigned int next_element_index,
3245  std::ostream &) const
3246 {
3247  return next_element_index;
3248 }
3249 
3250 unsigned int
3252  const unsigned int next_element_index,
3253  std::ostream &) const
3254 {
3255  return next_element_index;
3256 }
3257 
3258 
3259 unsigned int
3261  const unsigned int next_element_index,
3262  std::ostream &) const
3263 {
3264  return next_element_index;
3265 }
3266 
3267 unsigned int
3269  const unsigned int next_element_index,
3270  std::ostream &) const
3271 {
3272  return next_element_index;
3273 }
3274 
3275 
3276 unsigned int
3278  const unsigned int next_element_index,
3279  std::ostream &) const
3280 {
3281  return next_element_index;
3282 }
3283 
3284 
3285 unsigned int
3287  const unsigned int next_element_index,
3288  std::ostream &) const
3289 {
3290  return next_element_index;
3291 }
3292 
3293 unsigned int
3295  const unsigned int next_element_index,
3296  std::ostream &) const
3297 {
3298  return next_element_index;
3299 }
3300 
3301 
3302 
3303 template <int dim, int spacedim>
3304 unsigned int
3306  const unsigned int next_element_index,
3307  std::ostream & out) const
3308 {
3309  unsigned int current_element_index = next_element_index;
3311 
3312  for (face = tria.begin_active_face(), endf = tria.end_face(); face != endf;
3313  ++face)
3314  if (face->at_boundary() && (face->boundary_id() != 0))
3315  {
3316  out << current_element_index << ' ';
3317  switch (dim)
3318  {
3319  case 2:
3320  out << 1 << ' ';
3321  break;
3322  case 3:
3323  out << 3 << ' ';
3324  break;
3325  default:
3326  Assert(false, ExcNotImplemented());
3327  }
3328  out << static_cast<unsigned int>(face->boundary_id()) << ' '
3329  << static_cast<unsigned int>(face->boundary_id()) << ' '
3331  // note: vertex numbers are 1-base
3332  for (unsigned int vertex = 0;
3333  vertex < GeometryInfo<dim>::vertices_per_face;
3334  ++vertex)
3335  out << ' '
3336  << face->vertex_index(
3338  1;
3339  out << '\n';
3340 
3341  ++current_element_index;
3342  }
3343  return current_element_index;
3344 }
3345 
3346 
3347 template <int dim, int spacedim>
3348 unsigned int
3350  const unsigned int next_element_index,
3351  std::ostream & out) const
3352 {
3353  unsigned int current_element_index = next_element_index;
3354  // save the user flags for lines so
3355  // we can use these flags to track
3356  // which ones we've already taken
3357  // care of
3358  std::vector<bool> line_flags;
3359  const_cast<::Triangulation<dim, spacedim> &>(tria).save_user_flags_line(
3360  line_flags);
3361  const_cast<::Triangulation<dim, spacedim> &>(tria)
3362  .clear_user_flags_line();
3363 
3365 
3366  for (cell = tria.begin_active(), endc = tria.end(); cell != endc; ++cell)
3367  for (unsigned int l = 0; l < GeometryInfo<dim>::lines_per_cell; ++l)
3368  if (cell->line(l)->at_boundary() && (cell->line(l)->boundary_id() != 0) &&
3369  (cell->line(l)->user_flag_set() == false))
3370  {
3371  out << next_element_index << " 1 ";
3372  out << static_cast<unsigned int>(cell->line(l)->boundary_id()) << ' '
3373  << static_cast<unsigned int>(cell->line(l)->boundary_id())
3374  << " 2 ";
3375  // note: vertex numbers are 1-base
3376  for (unsigned int vertex = 0; vertex < 2; ++vertex)
3377  out << ' '
3378  << cell->line(l)->vertex_index(
3380  1;
3381  out << '\n';
3382 
3383  // move on to the next line
3384  // but mark the current one
3385  // as taken care of
3386  ++current_element_index;
3387  cell->line(l)->set_user_flag();
3388  }
3389 
3390  // at the end, restore the user
3391  // flags for the lines
3392  const_cast<::Triangulation<dim, spacedim> &>(tria).load_user_flags_line(
3393  line_flags);
3394 
3395  return current_element_index;
3396 }
3397 
3398 
3399 
3400 unsigned int
3402  const unsigned int next_element_index,
3403  std::ostream &) const
3404 {
3405  return next_element_index;
3406 }
3407 
3408 unsigned int
3410  const unsigned int next_element_index,
3411  std::ostream &) const
3412 {
3413  return next_element_index;
3414 }
3415 
3416 unsigned int
3418  const unsigned int next_element_index,
3419  std::ostream &) const
3420 {
3421  return next_element_index;
3422 }
3423 
3424 unsigned int
3426  const unsigned int next_element_index,
3427  std::ostream &) const
3428 {
3429  return next_element_index;
3430 }
3431 
3432 unsigned int
3434  const unsigned int next_element_index,
3435  std::ostream &) const
3436 {
3437  return next_element_index;
3438 }
3439 
3440 
3441 unsigned int
3443  const unsigned int next_element_index,
3444  std::ostream &) const
3445 {
3446  return next_element_index;
3447 }
3448 
3449 
3450 unsigned int
3452  const unsigned int next_element_index,
3453  std::ostream &) const
3454 {
3455  return next_element_index;
3456 }
3457 
3458 unsigned int
3460  const unsigned int next_element_index,
3461  std::ostream &) const
3462 {
3463  return next_element_index;
3464 }
3465 
3466 
3467 
3468 template <int dim, int spacedim>
3469 unsigned int
3471  const unsigned int next_element_index,
3472  std::ostream & out) const
3473 {
3474  unsigned int current_element_index = next_element_index;
3476 
3477  for (face = tria.begin_active_face(), endf = tria.end_face(); face != endf;
3478  ++face)
3479  if (face->at_boundary() && (face->boundary_id() != 0))
3480  {
3481  out << current_element_index << " "
3482  << static_cast<unsigned int>(face->boundary_id()) << " ";
3483  switch (dim)
3484  {
3485  case 2:
3486  out << "line ";
3487  break;
3488  case 3:
3489  out << "quad ";
3490  break;
3491  default:
3492  Assert(false, ExcNotImplemented());
3493  }
3494  // note: vertex numbers are 1-base
3495  for (unsigned int vertex = 0;
3496  vertex < GeometryInfo<dim>::vertices_per_face;
3497  ++vertex)
3498  out << face->vertex_index(
3500  1
3501  << ' ';
3502  out << '\n';
3503 
3504  ++current_element_index;
3505  }
3506  return current_element_index;
3507 }
3508 
3509 
3510 
3511 template <int dim, int spacedim>
3512 unsigned int
3514  const unsigned int next_element_index,
3515  std::ostream & out) const
3516 {
3517  unsigned int current_element_index = next_element_index;
3518  // save the user flags for lines so
3519  // we can use these flags to track
3520  // which ones we've already taken
3521  // care of
3522  std::vector<bool> line_flags;
3523  const_cast<::Triangulation<dim, spacedim> &>(tria).save_user_flags_line(
3524  line_flags);
3525  const_cast<::Triangulation<dim, spacedim> &>(tria)
3526  .clear_user_flags_line();
3527 
3529 
3530  for (cell = tria.begin_active(), endc = tria.end(); cell != endc; ++cell)
3531  for (unsigned int l = 0; l < GeometryInfo<dim>::lines_per_cell; ++l)
3532  if (cell->line(l)->at_boundary() && (cell->line(l)->boundary_id() != 0) &&
3533  (cell->line(l)->user_flag_set() == false))
3534  {
3535  out << current_element_index << " "
3536  << static_cast<unsigned int>(cell->line(l)->boundary_id())
3537  << " line ";
3538  // note: vertex numbers in ucd format are 1-base
3539  for (unsigned int vertex = 0; vertex < 2; ++vertex)
3540  out << cell->line(l)->vertex_index(
3542  1
3543  << ' ';
3544  out << '\n';
3545 
3546  // move on to the next line
3547  // but mark the current one
3548  // as taken care of
3549  ++current_element_index;
3550  cell->line(l)->set_user_flag();
3551  }
3552 
3553  // at the end, restore the user
3554  // flags for the lines
3555  const_cast<::Triangulation<dim, spacedim> &>(tria).load_user_flags_line(
3556  line_flags);
3557  return current_element_index;
3558 }
3559 
3560 
3562  Point<3> camera_position,
3563  Point<3> camera_direction,
3564  Point<3> camera_horizontal,
3565  float camera_focus)
3566 {
3567  // ...
3568  Point<3> camera_vertical;
3569  camera_vertical[0] = camera_horizontal[1] * camera_direction[2] -
3570  camera_horizontal[2] * camera_direction[1];
3571  camera_vertical[1] = camera_horizontal[2] * camera_direction[0] -
3572  camera_horizontal[0] * camera_direction[2];
3573  camera_vertical[2] = camera_horizontal[0] * camera_direction[1] -
3574  camera_horizontal[1] * camera_direction[0];
3575 
3576  float phi;
3577  phi = camera_focus;
3578  phi /= (point[0] - camera_position[0]) * camera_direction[0] +
3579  (point[1] - camera_position[1]) * camera_direction[1] +
3580  (point[2] - camera_position[2]) * camera_direction[2];
3581 
3582  Point<3> projection;
3583  projection[0] = camera_position[0] + phi * (point[0] - camera_position[0]);
3584  projection[1] = camera_position[1] + phi * (point[1] - camera_position[1]);
3585  projection[2] = camera_position[2] + phi * (point[2] - camera_position[2]);
3586 
3587  Point<2> projection_decomposition;
3588  projection_decomposition[0] =
3589  (projection[0] - camera_position[0] - camera_focus * camera_direction[0]) *
3590  camera_horizontal[0];
3591  projection_decomposition[0] +=
3592  (projection[1] - camera_position[1] - camera_focus * camera_direction[1]) *
3593  camera_horizontal[1];
3594  projection_decomposition[0] +=
3595  (projection[2] - camera_position[2] - camera_focus * camera_direction[2]) *
3596  camera_horizontal[2];
3597 
3598  projection_decomposition[1] =
3599  (projection[0] - camera_position[0] - camera_focus * camera_direction[0]) *
3600  camera_vertical[0];
3601  projection_decomposition[1] +=
3602  (projection[1] - camera_position[1] - camera_focus * camera_direction[1]) *
3603  camera_vertical[1];
3604  projection_decomposition[1] +=
3605  (projection[2] - camera_position[2] - camera_focus * camera_direction[2]) *
3606  camera_vertical[2];
3607 
3608  return projection_decomposition;
3609 }
3610 
3611 
3612 
3613 namespace internal
3614 {
3615  namespace
3616  {
3625  template <int spacedim>
3626  void
3627  remove_colinear_points(std::vector<Point<spacedim>> &points)
3628  {
3629  while (points.size() > 2)
3630  {
3631  Tensor<1, spacedim> first_difference = points[1] - points[0];
3632  first_difference /= first_difference.norm();
3633  Tensor<1, spacedim> second_difference = points[2] - points[1];
3634  second_difference /= second_difference.norm();
3635  // If the three points are colinear then remove the middle one.
3636  if ((first_difference - second_difference).norm() < 1e-10)
3637  points.erase(points.begin() + 1);
3638  else
3639  break;
3640  }
3641  }
3642 
3643 
3644 
3645  template <int spacedim>
3646  void
3647  write_gnuplot(const ::Triangulation<1, spacedim> &tria,
3648  std::ostream & out,
3649  const Mapping<1, spacedim> *,
3651  {
3652  AssertThrow(out, ExcIO());
3653 
3654  const int dim = 1;
3655 
3656  typename ::Triangulation<dim, spacedim>::active_cell_iterator cell =
3657  tria.begin_active();
3658  const typename ::Triangulation<dim, spacedim>::active_cell_iterator
3659  endc = tria.end();
3660  for (; cell != endc; ++cell)
3661  {
3662  if (gnuplot_flags.write_cell_numbers)
3663  out << "# cell " << cell << '\n';
3664 
3665  out << cell->vertex(0) << ' ' << cell->level() << ' '
3666  << static_cast<unsigned int>(cell->material_id()) << '\n'
3667  << cell->vertex(1) << ' ' << cell->level() << ' '
3668  << static_cast<unsigned int>(cell->material_id()) << '\n'
3669  << "\n\n";
3670  }
3671 
3672  // make sure everything now gets to
3673  // disk
3674  out.flush();
3675 
3676  AssertThrow(out, ExcIO());
3677  }
3678 
3679 
3680 
3681  template <int spacedim>
3682  void
3683  write_gnuplot(const ::Triangulation<2, spacedim> &tria,
3684  std::ostream & out,
3685  const Mapping<2, spacedim> * mapping,
3686  const GridOutFlags::Gnuplot & gnuplot_flags)
3687  {
3688  AssertThrow(out, ExcIO());
3689 
3690  const int dim = 2;
3691 
3692  const unsigned int n_additional_points =
3693  gnuplot_flags.n_boundary_face_points;
3694  const unsigned int n_points = 2 + n_additional_points;
3695 
3696  typename ::Triangulation<dim, spacedim>::active_cell_iterator cell =
3697  tria.begin_active();
3698  const typename ::Triangulation<dim, spacedim>::active_cell_iterator
3699  endc = tria.end();
3700 
3701  // If we need to plot curved lines then generate a quadrature formula to
3702  // place points via the mapping
3703  Quadrature<dim> * q_projector = nullptr;
3704  std::vector<Point<dim - 1>> boundary_points;
3705  if (mapping != nullptr)
3706  {
3707  boundary_points.resize(n_points);
3708  boundary_points[0][0] = 0;
3709  boundary_points[n_points - 1][0] = 1;
3710  for (unsigned int i = 1; i < n_points - 1; ++i)
3711  boundary_points[i](0) = 1. * i / (n_points - 1);
3712 
3713  std::vector<double> dummy_weights(n_points, 1. / n_points);
3714  Quadrature<dim - 1> quadrature(boundary_points, dummy_weights);
3715 
3716  q_projector = new Quadrature<dim>(
3718  }
3719 
3720  for (; cell != endc; ++cell)
3721  {
3722  if (gnuplot_flags.write_cell_numbers)
3723  out << "# cell " << cell << '\n';
3724 
3725  if (mapping == nullptr ||
3726  (dim == spacedim ?
3727  (!cell->at_boundary() && !gnuplot_flags.curved_inner_cells) :
3728  // ignore checking for boundary or interior cells in the codim
3729  // 1 case: 'or false' is a no-op
3730  false))
3731  {
3732  // write out the four sides of this cell by putting the four
3733  // points (+ the initial point again) in a row and lifting the
3734  // drawing pencil at the end
3735  for (unsigned int i = 0; i < GeometryInfo<dim>::vertices_per_cell;
3736  ++i)
3737  out << cell->vertex(GeometryInfo<dim>::ucd_to_deal[i]) << ' '
3738  << cell->level() << ' '
3739  << static_cast<unsigned int>(cell->material_id()) << '\n';
3740  out << cell->vertex(0) << ' ' << cell->level() << ' '
3741  << static_cast<unsigned int>(cell->material_id()) << '\n'
3742  << '\n' // double new line for gnuplot 3d plots
3743  << '\n';
3744  }
3745  else
3746  // cell is at boundary and we are to treat curved boundaries. so
3747  // loop over all faces and draw them as small pieces of lines
3748  {
3749  for (unsigned int face_no = 0;
3750  face_no < GeometryInfo<dim>::faces_per_cell;
3751  ++face_no)
3752  {
3753  const typename ::Triangulation<dim,
3754  spacedim>::face_iterator
3755  face = cell->face(face_no);
3756  if (dim != spacedim || face->at_boundary() ||
3757  gnuplot_flags.curved_inner_cells)
3758  {
3759  // Save the points on each face to a vector and then try
3760  // to remove colinear points that won't show up in the
3761  // generated plot.
3762  std::vector<Point<spacedim>> line_points;
3763  // compute offset of quadrature points within set of
3764  // projected points
3765  const unsigned int offset = face_no * n_points;
3766  for (unsigned int i = 0; i < n_points; ++i)
3767  line_points.push_back(
3768  mapping->transform_unit_to_real_cell(
3769  cell, q_projector->point(offset + i)));
3770  internal::remove_colinear_points(line_points);
3771 
3772  for (const Point<spacedim> &point : line_points)
3773  out << point << ' ' << cell->level() << ' '
3774  << static_cast<unsigned int>(cell->material_id())
3775  << '\n';
3776 
3777  out << '\n' << '\n';
3778  }
3779  else
3780  {
3781  // if, however, the face is not at the boundary and we
3782  // don't want to curve anything, then draw it as usual
3783  out << face->vertex(0) << ' ' << cell->level() << ' '
3784  << static_cast<unsigned int>(cell->material_id())
3785  << '\n'
3786  << face->vertex(1) << ' ' << cell->level() << ' '
3787  << static_cast<unsigned int>(cell->material_id())
3788  << '\n'
3789  << '\n'
3790  << '\n';
3791  }
3792  }
3793  }
3794  }
3795 
3796  if (q_projector != nullptr)
3797  delete q_projector;
3798 
3799  // make sure everything now gets to disk
3800  out.flush();
3801 
3802  AssertThrow(out, ExcIO());
3803  }
3804 
3805 
3806 
3807  template <int spacedim>
3808  void
3809  write_gnuplot(const ::Triangulation<3, spacedim> &tria,
3810  std::ostream & out,
3811  const Mapping<3, spacedim> * mapping,
3812  const GridOutFlags::Gnuplot & gnuplot_flags)
3813  {
3814  AssertThrow(out, ExcIO());
3815 
3816  const int dim = 3;
3817 
3818  const unsigned int n_additional_points =
3819  gnuplot_flags.n_boundary_face_points;
3820  const unsigned int n_points = 2 + n_additional_points;
3821 
3822  typename ::Triangulation<dim, spacedim>::active_cell_iterator cell =
3823  tria.begin_active();
3824  const typename ::Triangulation<dim, spacedim>::active_cell_iterator
3825  endc = tria.end();
3826 
3827  // If we need to plot curved lines then generate a quadrature formula to
3828  // place points via the mapping
3829  Quadrature<dim> * q_projector = nullptr;
3830  std::vector<Point<1>> boundary_points;
3831  if (mapping != nullptr)
3832  {
3833  boundary_points.resize(n_points);
3834  boundary_points[0][0] = 0;
3835  boundary_points[n_points - 1][0] = 1;
3836  for (unsigned int i = 1; i < n_points - 1; ++i)
3837  boundary_points[i](0) = 1. * i / (n_points - 1);
3838 
3839  std::vector<double> dummy_weights(n_points, 1. / n_points);
3840  Quadrature<1> quadrature1d(boundary_points, dummy_weights);
3841 
3842  // tensor product of points, only one copy
3843  QIterated<dim - 1> quadrature(quadrature1d, 1);
3844  q_projector = new Quadrature<dim>(
3846  }
3847 
3848  for (; cell != endc; ++cell)
3849  {
3850  if (gnuplot_flags.write_cell_numbers)
3851  out << "# cell " << cell << '\n';
3852 
3853  if (mapping == nullptr || n_points == 2 ||
3854  (!cell->has_boundary_lines() &&
3855  !gnuplot_flags.curved_inner_cells))
3856  {
3857  // front face
3858  out << cell->vertex(0) << ' ' << cell->level() << ' '
3859  << static_cast<unsigned int>(cell->material_id()) << '\n'
3860  << cell->vertex(1) << ' ' << cell->level() << ' '
3861  << static_cast<unsigned int>(cell->material_id()) << '\n'
3862  << cell->vertex(5) << ' ' << cell->level() << ' '
3863  << static_cast<unsigned int>(cell->material_id()) << '\n'
3864  << cell->vertex(4) << ' ' << cell->level() << ' '
3865  << static_cast<unsigned int>(cell->material_id()) << '\n'
3866  << cell->vertex(0) << ' ' << cell->level() << ' '
3867  << static_cast<unsigned int>(cell->material_id()) << '\n'
3868  << '\n';
3869  // back face
3870  out << cell->vertex(2) << ' ' << cell->level() << ' '
3871  << static_cast<unsigned int>(cell->material_id()) << '\n'
3872  << cell->vertex(3) << ' ' << cell->level() << ' '
3873  << static_cast<unsigned int>(cell->material_id()) << '\n'
3874  << cell->vertex(7) << ' ' << cell->level() << ' '
3875  << static_cast<unsigned int>(cell->material_id()) << '\n'
3876  << cell->vertex(6) << ' ' << cell->level() << ' '
3877  << static_cast<unsigned int>(cell->material_id()) << '\n'
3878  << cell->vertex(2) << ' ' << cell->level() << ' '
3879  << static_cast<unsigned int>(cell->material_id()) << '\n'
3880  << '\n';
3881 
3882  // now for the four connecting lines
3883  out << cell->vertex(0) << ' ' << cell->level() << ' '
3884  << static_cast<unsigned int>(cell->material_id()) << '\n'
3885  << cell->vertex(2) << ' ' << cell->level() << ' '
3886  << static_cast<unsigned int>(cell->material_id()) << '\n'
3887  << '\n';
3888  out << cell->vertex(1) << ' ' << cell->level() << ' '
3889  << static_cast<unsigned int>(cell->material_id()) << '\n'
3890  << cell->vertex(3) << ' ' << cell->level() << ' '
3891  << static_cast<unsigned int>(cell->material_id()) << '\n'
3892  << '\n';
3893  out << cell->vertex(5) << ' ' << cell->level() << ' '
3894  << static_cast<unsigned int>(cell->material_id()) << '\n'
3895  << cell->vertex(7) << ' ' << cell->level() << ' '
3896  << static_cast<unsigned int>(cell->material_id()) << '\n'
3897  << '\n';
3898  out << cell->vertex(4) << ' ' << cell->level() << ' '
3899  << static_cast<unsigned int>(cell->material_id()) << '\n'
3900  << cell->vertex(6) << ' ' << cell->level() << ' '
3901  << static_cast<unsigned int>(cell->material_id()) << '\n'
3902  << '\n';
3903  }
3904  else
3905  {
3906  for (unsigned int face_no = 0;
3907  face_no < GeometryInfo<dim>::faces_per_cell;
3908  ++face_no)
3909  {
3910  const typename ::Triangulation<dim,
3911  spacedim>::face_iterator
3912  face = cell->face(face_no);
3913 
3914  if (face->at_boundary() &&
3915  gnuplot_flags.write_additional_boundary_lines)
3916  {
3917  const unsigned int offset = face_no * n_points * n_points;
3918  for (unsigned int i = 0; i < n_points - 1; ++i)
3919  for (unsigned int j = 0; j < n_points - 1; ++j)
3920  {
3921  const Point<spacedim> p0 =
3922  mapping->transform_unit_to_real_cell(
3923  cell,
3924  q_projector->point(offset + i * n_points + j));
3925  out
3926  << p0 << ' ' << cell->level() << ' '
3927  << static_cast<unsigned int>(cell->material_id())
3928  << '\n';
3929  out
3930  << (mapping->transform_unit_to_real_cell(
3931  cell,
3932  q_projector->point(offset +
3933  (i + 1) * n_points + j)))
3934  << ' ' << cell->level() << ' '
3935  << static_cast<unsigned int>(cell->material_id())
3936  << '\n';
3937  out
3938  << (mapping->transform_unit_to_real_cell(
3939  cell,
3940  q_projector->point(
3941  offset + (i + 1) * n_points + j + 1)))
3942  << ' ' << cell->level() << ' '
3943  << static_cast<unsigned int>(cell->material_id())
3944  << '\n';
3945  out
3946  << (mapping->transform_unit_to_real_cell(
3947  cell,
3948  q_projector->point(offset + i * n_points +
3949  j + 1)))
3950  << ' ' << cell->level() << ' '
3951  << static_cast<unsigned int>(cell->material_id())
3952  << '\n';
3953  // and the first point again
3954  out
3955  << p0 << ' ' << cell->level() << ' '
3956  << static_cast<unsigned int>(cell->material_id())
3957  << '\n';
3958  out << '\n' << '\n';
3959  }
3960  }
3961  else
3962  {
3963  for (unsigned int l = 0;
3964  l < GeometryInfo<dim>::lines_per_face;
3965  ++l)
3966  {
3967  const typename ::Triangulation<dim, spacedim>::
3968  line_iterator line = face->line(l);
3969 
3970  const Point<spacedim> &v0 = line->vertex(0),
3971  &v1 = line->vertex(1);
3972  if (line->at_boundary() ||
3973  gnuplot_flags.curved_inner_cells)
3974  {
3975  // Save the points on each face to a vector and
3976  // then try to remove colinear points that won't
3977  // show up in the generated plot.
3978  std::vector<Point<spacedim>> line_points;
3979  // transform_real_to_unit_cell could be replaced
3980  // by using QProjector<dim>::project_to_line
3981  // which is not yet implemented
3982  const Point<spacedim>
3983  u0 = mapping->transform_real_to_unit_cell(cell,
3984  v0),
3985  u1 = mapping->transform_real_to_unit_cell(cell,
3986  v1);
3987 
3988  const Point<spacedim> center;
3989  for (unsigned int i = 0; i < n_points; ++i)
3990  line_points.push_back(
3991  mapping->transform_unit_to_real_cell(
3992  cell,
3993  (1 - boundary_points[i][0]) * u0 +
3994  boundary_points[i][0] * u1));
3995  internal::remove_colinear_points(line_points);
3996  for (const Point<spacedim> &point : line_points)
3997  out << point << ' ' << cell->level() << ' '
3998  << static_cast<unsigned int>(
3999  cell->material_id())
4000  << '\n';
4001  }
4002  else
4003  out
4004  << v0 << ' ' << cell->level() << ' '
4005  << static_cast<unsigned int>(cell->material_id())
4006  << '\n'
4007  << v1 << ' ' << cell->level() << ' '
4008  << static_cast<unsigned int>(cell->material_id())
4009  << '\n';
4010 
4011  out << '\n' << '\n';
4012  }
4013  }
4014  }
4015  }
4016  }
4017 
4018  if (q_projector != nullptr)
4019  delete q_projector;
4020 
4021 
4022  // make sure everything now gets to disk
4023  out.flush();
4024 
4025  AssertThrow(out, ExcIO());
4026  }
4027  } // namespace
4028 } // namespace internal
4029 
4030 
4031 
4032 template <int dim, int spacedim>
4033 void
4035  std::ostream & out,
4036  const Mapping<dim, spacedim> * mapping) const
4037 {
4038  internal::write_gnuplot(tria, out, mapping, gnuplot_flags);
4039 }
4040 
4041 
4042 
4043 namespace internal
4044 {
4045  namespace
4046  {
4047  struct LineEntry
4048  {
4049  Point<2> first;
4050  Point<2> second;
4051  bool colorize;
4052  unsigned int level;
4053  LineEntry(const Point<2> & f,
4054  const Point<2> & s,
4055  const bool c,
4056  const unsigned int l)
4057  : first(f)
4058  , second(s)
4059  , colorize(c)
4060  , level(l)
4061  {}
4062  };
4063 
4064 
4065  void
4066  write_eps(const ::Triangulation<1> &,
4067  std::ostream &,
4068  const Mapping<1> *,
4069  const GridOutFlags::Eps<2> &,
4070  const GridOutFlags::Eps<3> &)
4071  {
4072  Assert(false, ExcNotImplemented());
4073  }
4074 
4075  void
4076  write_eps(const ::Triangulation<1, 2> &,
4077  std::ostream &,
4078  const Mapping<1, 2> *,
4079  const GridOutFlags::Eps<2> &,
4080  const GridOutFlags::Eps<3> &)
4081  {
4082  Assert(false, ExcNotImplemented());
4083  }
4084 
4085  void
4086  write_eps(const ::Triangulation<1, 3> &,
4087  std::ostream &,
4088  const Mapping<1, 3> *,
4089  const GridOutFlags::Eps<2> &,
4090  const GridOutFlags::Eps<3> &)
4091  {
4092  Assert(false, ExcNotImplemented());
4093  }
4094 
4095  void
4096  write_eps(const ::Triangulation<2, 3> &,
4097  std::ostream &,
4098  const Mapping<2, 3> *,
4099  const GridOutFlags::Eps<2> &,
4100  const GridOutFlags::Eps<3> &)
4101  {
4102  Assert(false, ExcNotImplemented());
4103  }
4104 
4105 
4106 
4107  template <int dim, int spacedim>
4108  void
4109  write_eps(const ::Triangulation<dim, spacedim> &tria,
4110  std::ostream & out,
4111  const Mapping<dim, spacedim> * mapping,
4114  {
4115  using LineList = std::list<LineEntry>;
4116 
4117  // We should never get here in 1D since this function is overloaded for
4118  // all dim == 1 cases.
4119  Assert(dim == 2 || dim == 3, ExcInternalError());
4120 
4121  // Copy, with an object slice, something containing the flags common to
4122  // all dimensions in order to avoid the recurring distinctions between
4123  // the different eps_flags present.
4124  const GridOutFlags::EpsFlagsBase eps_flags_base =
4125  dim == 2 ?
4126  static_cast<const GridOutFlags::EpsFlagsBase &>(eps_flags_2) :
4127  static_cast<const GridOutFlags::EpsFlagsBase &>(eps_flags_3);
4128 
4129  AssertThrow(out, ExcIO());
4130  const unsigned int n_points = eps_flags_base.n_boundary_face_points;
4131 
4132  // make up a list of lines by which
4133  // we will construct the triangulation
4134  //
4135  // this part unfortunately is a bit
4136  // dimension dependent, so we have to
4137  // treat every dimension different.
4138  // however, by directly producing
4139  // the lines to be printed, i.e. their
4140  // 2d images, we can later do the
4141  // actual output dimension independent
4142  // again
4143  LineList line_list;
4144 
4145  switch (dim)
4146  {
4147  case 1:
4148  {
4149  Assert(false, ExcInternalError());
4150  break;
4151  }
4152 
4153  case 2:
4154  {
4155  for (typename ::Triangulation<dim, spacedim>::
4156  active_cell_iterator cell = tria.begin_active();
4157  cell != tria.end();
4158  ++cell)
4159  for (unsigned int line_no = 0;
4160  line_no < GeometryInfo<dim>::lines_per_cell;
4161  ++line_no)
4162  {
4163  typename ::Triangulation<dim, spacedim>::line_iterator
4164  line = cell->line(line_no);
4165 
4166  // first treat all
4167  // interior lines and
4168  // make up a list of
4169  // them. if curved
4170  // lines shall not be
4171  // supported (i.e. no
4172  // mapping is
4173  // provided), then also
4174  // treat all other
4175  // lines
4176  if (!line->has_children() &&
4177  (mapping == nullptr || !line->at_boundary()))
4178  // one would expect
4179  // make_pair(line->vertex(0),
4180  // line->vertex(1))
4181  // here, but that is
4182  // not dimension
4183  // independent, since
4184  // vertex(i) is
4185  // Point<dim>, but we
4186  // want a Point<2>.
4187  // in fact, whenever
4188  // we're here, the
4189  // vertex is a
4190  // Point<dim>, but
4191  // the compiler does
4192  // not know
4193  // this. hopefully,
4194  // the compiler will
4195  // optimize away this
4196  // little kludge
4197  line_list.emplace_back(
4198  Point<2>(line->vertex(0)(0), line->vertex(0)(1)),
4199  Point<2>(line->vertex(1)(0), line->vertex(1)(1)),
4200  line->user_flag_set(),
4201  cell->level());
4202  }
4203 
4204  // next if we are to treat
4205  // curved boundaries
4206  // specially, then add lines
4207  // to the list consisting of
4208  // pieces of the boundary
4209  // lines
4210  if (mapping != nullptr)
4211  {
4212  // to do so, first
4213  // generate a sequence of
4214  // points on a face and
4215  // project them onto the
4216  // faces of a unit cell
4217  std::vector<Point<dim - 1>> boundary_points(n_points);
4218 
4219  for (unsigned int i = 0; i < n_points; ++i)
4220  boundary_points[i](0) = 1. * (i + 1) / (n_points + 1);
4221 
4222  Quadrature<dim - 1> quadrature(boundary_points);
4223  Quadrature<dim> q_projector(
4225 
4226  // next loop over all
4227  // boundary faces and
4228  // generate the info from
4229  // them
4230  for (typename ::Triangulation<dim, spacedim>::
4231  active_cell_iterator cell = tria.begin_active();
4232  cell != tria.end();
4233  ++cell)
4234  for (unsigned int face_no = 0;
4235  face_no < GeometryInfo<dim>::faces_per_cell;
4236  ++face_no)
4237  {
4238  const typename ::Triangulation<dim, spacedim>::
4239  face_iterator face = cell->face(face_no);
4240 
4241  if (face->at_boundary())
4242  {
4243  Point<dim> p0_dim(face->vertex(0));
4244  Point<2> p0(p0_dim(0), p0_dim(1));
4245 
4246  // loop over
4247  // all pieces
4248  // of the line
4249  // and generate
4250  // line-lets
4251  const unsigned int offset = face_no * n_points;
4252  for (unsigned int i = 0; i < n_points; ++i)
4253  {
4254  const Point<dim> p1_dim(
4255  mapping->transform_unit_to_real_cell(
4256  cell, q_projector.point(offset + i)));
4257  const Point<2> p1(p1_dim(0), p1_dim(1));
4258 
4259  line_list.emplace_back(p0,
4260  p1,
4261  face->user_flag_set(),
4262  cell->level());
4263  p0 = p1;
4264  }
4265 
4266  // generate last piece
4267  const Point<dim> p1_dim(face->vertex(1));
4268  const Point<2> p1(p1_dim(0), p1_dim(1));
4269  line_list.emplace_back(p0,
4270  p1,
4271  face->user_flag_set(),
4272  cell->level());
4273  }
4274  }
4275  }
4276 
4277  break;
4278  }
4279 
4280  case 3:
4281  {
4282  // curved boundary output
4283  // presently not supported
4284  Assert(mapping == nullptr, ExcNotImplemented());
4285 
4286  typename ::Triangulation<dim,
4287  spacedim>::active_cell_iterator
4288  cell = tria.begin_active(),
4289  endc = tria.end();
4290 
4291  // loop over all lines and compute their
4292  // projection on the plane perpendicular
4293  // to the direction of sight
4294 
4295  // direction of view equals the unit
4296  // vector of the position of the
4297  // spectator to the origin.
4298  //
4299  // we chose here the viewpoint as in
4300  // gnuplot as default.
4301  //
4302  // TODO:[WB] Fix a potential problem with viewing angles in 3d Eps
4303  // GridOut
4304  // note: the following might be wrong
4305  // if one of the base vectors below
4306  // is in direction of the viewer, but
4307  // I am too tired at present to fix
4308  // this
4309  const double pi = numbers::PI;
4310  const double z_angle = eps_flags_3.azimut_angle;
4311  const double turn_angle = eps_flags_3.turn_angle;
4312  const Point<dim> view_direction(
4313  -std::sin(z_angle * 2. * pi / 360.) *
4314  std::sin(turn_angle * 2. * pi / 360.),
4315  +std::sin(z_angle * 2. * pi / 360.) *
4316  std::cos(turn_angle * 2. * pi / 360.),
4317  -std::cos(z_angle * 2. * pi / 360.));
4318 
4319  // decide about the two unit vectors
4320  // in this plane. we chose the first one
4321  // to be the projection of the z-axis
4322  // to this plane
4323  const Tensor<1, dim> vector1 =
4324  Point<dim>(0, 0, 1) -
4325  ((Point<dim>(0, 0, 1) * view_direction) * view_direction);
4326  const Tensor<1, dim> unit_vector1 = vector1 / vector1.norm();
4327 
4328  // now the third vector is fixed. we
4329  // chose the projection of a more or
4330  // less arbitrary vector to the plane
4331  // perpendicular to the first one
4332  const Tensor<1, dim> vector2 =
4333  (Point<dim>(1, 0, 0) -
4334  ((Point<dim>(1, 0, 0) * view_direction) * view_direction) -
4335  ((Point<dim>(1, 0, 0) * unit_vector1) * unit_vector1));
4336  const Tensor<1, dim> unit_vector2 = vector2 / vector2.norm();
4337 
4338 
4339  for (; cell != endc; ++cell)
4340  for (unsigned int line_no = 0;
4341  line_no < GeometryInfo<dim>::lines_per_cell;
4342  ++line_no)
4343  {
4344  typename ::Triangulation<dim, spacedim>::line_iterator
4345  line = cell->line(line_no);
4346  line_list.emplace_back(
4347  Point<2>(line->vertex(0) * unit_vector2,
4348  line->vertex(0) * unit_vector1),
4349  Point<2>(line->vertex(1) * unit_vector2,
4350  line->vertex(1) * unit_vector1),
4351  line->user_flag_set(),
4352  cell->level());
4353  }
4354 
4355  break;
4356  }
4357 
4358  default:
4359  Assert(false, ExcNotImplemented());
4360  }
4361 
4362 
4363 
4364  // find out minimum and maximum x and
4365  // y coordinates to compute offsets
4366  // and scaling factors
4367  double x_min = tria.begin_active()->vertex(0)(0);
4368  double x_max = x_min;
4369  double y_min = tria.begin_active()->vertex(0)(1);
4370  double y_max = y_min;
4371  unsigned int max_level = line_list.begin()->level;
4372 
4373  for (LineList::const_iterator line = line_list.begin();
4374  line != line_list.end();
4375  ++line)
4376  {
4377  x_min = std::min(x_min, line->first(0));
4378  x_min = std::min(x_min, line->second(0));
4379 
4380  x_max = std::max(x_max, line->first(0));
4381  x_max = std::max(x_max, line->second(0));
4382 
4383  y_min = std::min(y_min, line->first(1));
4384  y_min = std::min(y_min, line->second(1));
4385 
4386  y_max = std::max(y_max, line->first(1));
4387  y_max = std::max(y_max, line->second(1));
4388 
4389  max_level = std::max(max_level, line->level);
4390  }
4391 
4392  // scale in x-direction such that
4393  // in the output 0 <= x <= 300.
4394  // don't scale in y-direction to
4395  // preserve the shape of the
4396  // triangulation
4397  const double scale =
4398  (eps_flags_base.size /
4399  (eps_flags_base.size_type == GridOutFlags::EpsFlagsBase::width ?
4400  x_max - x_min :
4401  y_min - y_max));
4402 
4403 
4404  // now write preamble
4405  if (true)
4406  {
4407  // block this to have local
4408  // variables destroyed after
4409  // use
4410  std::time_t time1 = std::time(nullptr);
4411  std::tm * time = std::localtime(&time1);
4412  out << "%!PS-Adobe-2.0 EPSF-1.2" << '\n'
4413  << "%%Title: deal.II Output" << '\n'
4414  << "%%Creator: the deal.II library" << '\n'
4415  << "%%Creation Date: " << time->tm_year + 1900 << "/"
4416  << time->tm_mon + 1 << "/" << time->tm_mday << " - "
4417  << time->tm_hour << ":" << std::setw(2) << time->tm_min << ":"
4418  << std::setw(2) << time->tm_sec << '\n'
4419  << "%%BoundingBox: "
4420  // lower left corner
4421  << "0 0 "
4422  // upper right corner
4423  << static_cast<unsigned int>(
4424  std::floor(((x_max - x_min) * scale) + 1))
4425  << ' '
4426  << static_cast<unsigned int>(
4427  std::floor(((y_max - y_min) * scale) + 1))
4428  << '\n';
4429 
4430  // define some abbreviations to keep
4431  // the output small:
4432  // m=move turtle to
4433  // x=execute line stroke
4434  // b=black pen
4435  // r=red pen
4436  out << "/m {moveto} bind def" << '\n'
4437  << "/x {lineto stroke} bind def" << '\n'
4438  << "/b {0 0 0 setrgbcolor} def" << '\n'
4439  << "/r {1 0 0 setrgbcolor} def" << '\n';
4440 
4441  // calculate colors for level
4442  // coloring; level 0 is black,
4443  // other levels are blue
4444  // ... red
4445  if (eps_flags_base.color_lines_level)
4446  out << "/l { neg " << (max_level) << " add "
4447  << (0.66666 / std::max(1U, (max_level - 1)))
4448  << " mul 1 0.8 sethsbcolor} def" << '\n';
4449 
4450  // in 2d, we can also plot cell
4451  // and vertex numbers, but this
4452  // requires a somewhat more
4453  // lengthy preamble. please
4454  // don't ask me what most of
4455  // this means, it is reverse
4456  // engineered from what GNUPLOT
4457  // uses in its output
4458  if ((dim == 2) && (eps_flags_2.write_cell_numbers ||
4459  eps_flags_2.write_vertex_numbers))
4460  {
4461  out
4462  << ("/R {rmoveto} bind def\n"
4463  "/Symbol-Oblique /Symbol findfont [1 0 .167 1 0 0] makefont\n"
4464  "dup length dict begin {1 index /FID eq {pop pop} {def} ifelse} forall\n"
4465  "currentdict end definefont\n"
4466  "/MFshow {{dup dup 0 get findfont exch 1 get scalefont setfont\n"
4467  "[ currentpoint ] exch dup 2 get 0 exch rmoveto dup dup 5 get exch 4 get\n"
4468  "{show} {stringwidth pop 0 rmoveto}ifelse dup 3 get\n"
4469  "{2 get neg 0 exch rmoveto pop} {pop aload pop moveto}ifelse} forall} bind def\n"
4470  "/MFwidth {0 exch {dup 3 get{dup dup 0 get findfont exch 1 get scalefont setfont\n"
4471  "5 get stringwidth pop add}\n"
4472  "{pop} ifelse} forall} bind def\n"
4473  "/MCshow { currentpoint stroke m\n"
4474  "exch dup MFwidth -2 div 3 -1 roll R MFshow } def\n")
4475  << '\n';
4476  }
4477 
4478  out << "%%EndProlog" << '\n' << '\n';
4479 
4480  // set fine lines
4481  out << eps_flags_base.line_width << " setlinewidth" << '\n';
4482  }
4483 
4484  // now write the lines
4485  const Point<2> offset(x_min, y_min);
4486 
4487  for (LineList::const_iterator line = line_list.begin();
4488  line != line_list.end();
4489  ++line)
4490  if (eps_flags_base.color_lines_level && (line->level > 0))
4491  out << line->level << " l " << (line->first - offset) * scale << " m "
4492  << (line->second - offset) * scale << " x" << '\n';
4493  else
4494  out << ((line->colorize && eps_flags_base.color_lines_on_user_flag) ?
4495  "r " :
4496  "b ")
4497  << (line->first - offset) * scale << " m "
4498  << (line->second - offset) * scale << " x" << '\n';
4499 
4500  // finally write the cell numbers
4501  // in 2d, if that is desired
4502  if ((dim == 2) && (eps_flags_2.write_cell_numbers == true))
4503  {
4504  out << "(Helvetica) findfont 140 scalefont setfont" << '\n';
4505 
4506  typename ::Triangulation<dim, spacedim>::active_cell_iterator
4507  cell = tria.begin_active(),
4508  endc = tria.end();
4509  for (; cell != endc; ++cell)
4510  {
4511  out << (cell->center()(0) - offset(0)) * scale << ' '
4512  << (cell->center()(1) - offset(1)) * scale << " m" << '\n'
4513  << "[ [(Helvetica) 12.0 0.0 true true (";
4514  if (eps_flags_2.write_cell_number_level)
4515  out << cell;
4516  else
4517  out << cell->index();
4518 
4519  out << ")] "
4520  << "] -6 MCshow" << '\n';
4521  }
4522  }
4523 
4524  // and the vertex numbers
4525  if ((dim == 2) && (eps_flags_2.write_vertex_numbers == true))
4526  {
4527  out << "(Helvetica) findfont 140 scalefont setfont" << '\n';
4528 
4529  // have a list of those
4530  // vertices which we have
4531  // already tracked, to avoid
4532  // doing this multiply
4533  std::set<unsigned int> treated_vertices;
4534  typename ::Triangulation<dim, spacedim>::active_cell_iterator
4535  cell = tria.begin_active(),
4536  endc = tria.end();
4537  for (; cell != endc; ++cell)
4538  for (unsigned int vertex = 0;
4539  vertex < GeometryInfo<dim>::vertices_per_cell;
4540  ++vertex)
4541  if (treated_vertices.find(cell->vertex_index(vertex)) ==
4542  treated_vertices.end())
4543  {
4544  treated_vertices.insert(cell->vertex_index(vertex));
4545 
4546  out << (cell->vertex(vertex)(0) - offset(0)) * scale << ' '
4547  << (cell->vertex(vertex)(1) - offset(1)) * scale << " m"
4548  << '\n'
4549  << "[ [(Helvetica) 10.0 0.0 true true ("
4550  << cell->vertex_index(vertex) << ")] "
4551  << "] -6 MCshow" << '\n';
4552  }
4553  }
4554 
4555  out << "showpage" << '\n';
4556 
4557  // make sure everything now gets to
4558  // disk
4559  out.flush();
4560 
4561  AssertThrow(out, ExcIO());
4562  }
4563  } // namespace
4564 } // namespace internal
4565 
4566 
4567 template <int dim, int spacedim>
4568 void
4570  std::ostream & out,
4571  const Mapping<dim, spacedim> * mapping) const
4572 {
4573  internal::write_eps(tria, out, mapping, eps_flags_2, eps_flags_3);
4574 }
4575 
4576 
4577 template <int dim, int spacedim>
4578 void
4580  std::ostream & out,
4581  const OutputFormat output_format,
4582  const Mapping<dim, spacedim> * mapping) const
4583 {
4584  switch (output_format)
4585  {
4586  case none:
4587  return;
4588 
4589  case dx:
4590  write_dx(tria, out);
4591  return;
4592 
4593  case ucd:
4594  write_ucd(tria, out);
4595  return;
4596 
4597  case gnuplot:
4598  write_gnuplot(tria, out, mapping);
4599  return;
4600 
4601  case eps:
4602  write_eps(tria, out, mapping);
4603  return;
4604 
4605  case xfig:
4606  write_xfig(tria, out, mapping);
4607  return;
4608 
4609  case msh:
4610  write_msh(tria, out);
4611  return;
4612 
4613  case svg:
4614  write_svg(tria, out);
4615  return;
4616 
4617  case mathgl:
4618  write_mathgl(tria, out);
4619  return;
4620 
4621  case vtk:
4622  write_vtk(tria, out);
4623  return;
4624 
4625  case vtu:
4626  write_vtu(tria, out);
4627  return;
4628  }
4629 
4630  Assert(false, ExcInternalError());
4631 }
4632 
4633 
4634 template <int dim, int spacedim>
4635 void
4637  std::ostream & out,
4638  const Mapping<dim, spacedim> * mapping) const
4639 {
4640  write(tria, out, default_format, mapping);
4641 }
4642 
4643 
4644 // explicit instantiations
4645 #include "grid_out.inst"
4646 
4647 
4648 DEAL_II_NAMESPACE_CLOSE
void parse_parameters(ParameterHandler &param)
Definition: grid_out.cc:193
Use white background.
Definition: grid_out.h:694
void parse_parameters(ParameterHandler &param)
Definition: grid_out.cc:716
void write_ucd(const Triangulation< dim, spacedim > &tria, std::ostream &out) const
Definition: grid_out.cc:1188
static const unsigned int invalid_unsigned_int
Definition: types.h:173
void write_svg(const Triangulation< 2, 2 > &tria, std::ostream &out) const
Definition: grid_out.cc:1528
OutputFormat default_format
Definition: grid_out.h:1395
static void declare_parameters(ParameterHandler &prm)
DX(const bool write_cells=true, const bool write_faces=false, const bool write_diameter=false, const bool write_measure=false, const bool write_all_faces=true)
Definition: grid_out.cc:47
const std::vector< Point< spacedim > > & get_vertices() const
cell_iterator end() const
Definition: tria.cc:12004
static OutputFormat parse_output_format(const std::string &format_name)
Definition: grid_out.cc:617
void parse_parameters(ParameterHandler &param)
Definition: grid_out.cc:375
bool margin
Margin around the plotted area.
Definition: grid_out.h:684
bool write_cells
Definition: grid_out.h:58
write() calls write_dx()
Definition: grid_out.h:920
active_face_iterator begin_active_face() const
Definition: tria.cc:12117
unsigned int n_used_vertices() const
Definition: tria.cc:13091
void attach_triangulation(const Triangulation< DoFHandlerType::dimension, DoFHandlerType::space_dimension > &)
bool write_additional_boundary_lines
Definition: grid_out.h:281
static::ExceptionBase & ExcIO()
unsigned int n_boundary_face_points
Definition: grid_out.h:604
static void declare_parameters(ParameterHandler &param)
Definition: grid_out.cc:467
GridOutFlags::Eps< 2 > eps_flags_2
Definition: grid_out.h:1430
void write_vtk(const Triangulation< dim, spacedim > &tria, std::ostream &out) const
Definition: grid_out.cc:2942
unsigned int height
Definition: grid_out.h:674
OutputFormat
Definition: grid_out.h:915
GridOut()
Definition: grid_out.cc:481
void parse_parameters(ParameterHandler &param)
Definition: grid_out.cc:249
unsigned int write_ucd_faces(const Triangulation< dim, spacedim > &tria, const unsigned int next_element_index, std::ostream &out) const
Definition: grid_out.cc:3470
static void declare_parameters(ParameterHandler &param)
Definition: grid_out.cc:399
Convert the level number into the cell color.
Definition: grid_out.h:723
write() calls write_eps()
Definition: grid_out.h:924
const std::vector< bool > & get_used_vertices() const
Definition: tria.cc:13104
unsigned int line_thickness
Thickness of the lines between cells.
Definition: grid_out.h:679
void write_mesh_per_processor_as_vtu(const Triangulation< dim, spacedim > &tria, const std::string &filename_without_extension, const bool view_levels=false, const bool include_artificial=false) const
Definition: grid_out.cc:3002
bool convert_level_number_to_height
Definition: grid_out.h:734
numbers::NumberTraits< Number >::real_type norm() const
Definition: tensor.h:1301
#define AssertThrow(cond, exc)
Definition: exceptions.h:1329
bool write_diameter
Definition: grid_out.h:68
static Point< 2 > svg_project_point(Point< 3 > point, Point< 3 > camera_position, Point< 3 > camera_direction, Point< 3 > camera_horizontal, float camera_focus)
Definition: grid_out.cc:3561
virtual Point< dim > transform_real_to_unit_cell(const typename Triangulation< dim, spacedim >::cell_iterator &cell, const Point< spacedim > &p) const =0
unsigned int boundary_line_thickness
Thickness of lines at the boundary.
Definition: grid_out.h:681
Point< spacedim > vertices[GeometryInfo< dim >::vertices_per_cell]
cell_iterator begin(const unsigned int level=0) const
Definition: tria.cc:11915
unsigned int n_active_cells() const
Definition: tria.cc:12509
std::string get(const std::string &entry_string) const
const Point< dim > & point(const unsigned int i) const
void write_eps(const Triangulation< dim, spacedim > &tria, std::ostream &out, const Mapping< dim, spacedim > *mapping=nullptr) const
Definition: grid_out.cc:4569
void parse_parameters(ParameterHandler &param)
Definition: grid_out.cc:88
void parse_parameters(ParameterHandler &param)
Definition: grid_out.cc:332
unsigned int n_extra_curved_line_points
Definition: grid_out.h:250
bool write_all_faces
Definition: grid_out.h:79
write() calls write_ucd()
Definition: grid_out.h:926
void enter_subsection(const std::string &subsection)
GridOutFlags::Vtk vtk_flags
Definition: grid_out.h:1456
void write_msh(const Triangulation< dim, spacedim > &tria, std::ostream &out) const
Definition: grid_out.cc:1041
Point< 2 > scaling
Definition: grid_out.h:609
bool label_cell_index
Write cell index into each cell. Defaults to true.
Definition: grid_out.h:745
static const double PI
Definition: numbers.h:143
GridOutFlags::Gnuplot gnuplot_flags
Definition: grid_out.h:1418
Convert the global subdomain id into the cell color.
Definition: grid_out.h:588
unsigned int & n_boundary_face_points
Definition: grid_out.h:262
Convert the material id into the cell color.
Definition: grid_out.h:584
static::ExceptionBase & ExcMessage(std::string arg1)
static void declare_parameters(ParameterHandler &param)
Definition: grid_out.cc:185
GridOutFlags::MathGL mathgl_flags
Definition: grid_out.h:1451
void write_vtu(const Triangulation< dim, spacedim > &tria, std::ostream &out) const
Definition: grid_out.cc:2972
write() calls write_mathgl()
Definition: grid_out.h:934
GridOutFlags::DX dx_flags
Definition: grid_out.h:1400
GridOutFlags::Msh msh_flags
Definition: grid_out.h:1406
GridOutFlags::Eps< 1 > eps_flags_1
Definition: grid_out.h:1424
void reinit(const TableIndices< N > &new_size, const bool omit_default_initialization=false)
write() calls write_gnuplot()
Definition: grid_out.h:922
#define Assert(cond, exc)
Definition: exceptions.h:1227
void parse_parameters(const ParameterHandler &prm)
bool label_material_id
Write material id of each cell. Defaults to false.
Definition: grid_out.h:747
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 >> &nonscalar_data_ranges, const VtkFlags &flags, std::ostream &out)
EpsFlagsBase(const SizeType size_type=width, const unsigned int size=300, const double line_width=0.5, const bool color_lines_on_user_flag=false, const unsigned int n_boundary_face_points=2, const bool color_lines_level=false)
Definition: grid_out.cc:200
Abstract base class for mapping classes.
Definition: dof_tools.h:57
std::string default_suffix() const
Definition: grid_out.cc:609
GridOutFlags::XFig xfig_flags
Definition: grid_out.h:1441
bool label_subdomain_id
Write subdomain id of each cell. Defaults to false.
Definition: grid_out.h:749
Ucd(const bool write_preamble=false, const bool write_faces=false, const bool write_lines=false)
Definition: grid_out.cc:119
static void declare_parameters(ParameterHandler &param)
Definition: grid_out.cc:667
bool label_level_subdomain_id
Write level subdomain id of each cell. Defaults to false.
Definition: grid_out.h:751
static std::string get_output_format_names()
Definition: grid_out.cc:660
Convert the subdomain id into the cell color.
Definition: grid_out.h:725
Msh(const bool write_faces=false, const bool write_lines=false)
Definition: grid_out.cc:98
unsigned int n_subdivisions
GridOutFlags::Ucd ucd_flags
Definition: grid_out.h:1412
static void declare_parameters(ParameterHandler &param)
Definition: grid_out.cc:130
virtual types::subdomain_id locally_owned_subdomain() const
Definition: tria.cc:13173
std::string int_to_string(const unsigned int value, const unsigned int digits=numbers::invalid_unsigned_int)
Definition: utilities.cc:96
void write_xfig(const Triangulation< dim, spacedim > &tria, std::ostream &out, const Mapping< dim, spacedim > *mapping=nullptr) const
Definition: grid_out.cc:1313
static void declare_parameters(ParameterHandler &param)
Definition: grid_out.cc:216
Do nothing in write()
Definition: grid_out.h:918
unsigned int n_mpi_processes(const MPI_Comm &mpi_communicator)
Definition: mpi.cc:69
bool get_bool(const std::string &entry_name) const
float cell_font_scaling
Scaling of the font for cell annotations. Defaults to 1.
Definition: grid_out.h:741
Convert the level subdomain id into the cell color.
Definition: grid_out.h:590
write() calls write_xfig()
Definition: grid_out.h:928
Convert the level subdomain id into the cell color.
Definition: grid_out.h:727
static Quadrature< dim > project_to_all_faces(const SubQuadrature &quadrature)
bool write_faces
Definition: grid_out.h:63
const types::subdomain_id artificial_subdomain_id
Definition: types.h:272
Convert the level into the cell color.
Definition: grid_out.h:586
std::size_t memory_consumption() const
Definition: grid_out.cc:762
void parse_parameters(ParameterHandler &param)
Definition: grid_out.cc:112
unsigned int write_msh_lines(const Triangulation< dim, spacedim > &tria, const unsigned int next_element_index, std::ostream &out) const
Definition: grid_out.cc:3349
unsigned int write_msh_faces(const Triangulation< dim, spacedim > &tria, const unsigned int next_element_index, std::ostream &out) const
Definition: grid_out.cc:3305
unsigned int n_boundary_lines(const Triangulation< dim, spacedim > &tria) const
Definition: grid_out.cc:3199
unsigned int n_boundary_face_points
Definition: grid_out.h:384
face_iterator end_face() const
Definition: tria.cc:12138
Point< 2 > offset
Definition: grid_out.h:615
unsigned int n_boundary_faces(const Triangulation< dim, spacedim > &tria) const
Definition: grid_out.cc:3182
static void declare_parameters(ParameterHandler &param)
Definition: grid_out.cc:104
write() calls write_msh()
Definition: grid_out.h:930
write() calls write_svg()
Definition: grid_out.h:932
GridOutFlags::Svg svg_flags
Definition: grid_out.h:1446
double get_double(const std::string &entry_name) const
Svg(const unsigned int line_thickness=2, const unsigned int boundary_line_thickness=4, bool margin=true, const Background background=white, const int azimuth_angle=0, const int polar_angle=0, const Coloring coloring=level_number, const bool convert_level_number_to_height=false, const bool label_level_number=true, const bool label_cell_index=true, const bool label_material_id=false, const bool label_subdomain_id=false, const bool draw_colorbar=true, const bool draw_legend=true)
Definition: grid_out.cc:427
void parse_parameters(ParameterHandler &param)
Definition: grid_out.cc:415
void declare_entry(const std::string &entry, const std::string &default_value, const Patterns::PatternBase &pattern=Patterns::Anything(), const std::string &documentation=std::string())
bool write_measure
Definition: grid_out.h:73
static::ExceptionBase & ExcNotImplemented()
Convert the material id into the cell color (default)
Definition: grid_out.h:721
void write_mathgl(const Triangulation< dim, spacedim > &tria, std::ostream &out) const
Definition: grid_out.cc:2743
float level_height_factor
Definition: grid_out.h:738
GridOutFlags::Eps< 3 > eps_flags_3
Definition: grid_out.h:1436
static::ExceptionBase & ExcInvalidState()
void write(const Triangulation< dim, spacedim > &tria, std::ostream &out, const OutputFormat output_format, const Mapping< dim, spacedim > *mapping=nullptr) const
Definition: grid_out.cc:4579
const types::boundary_id internal_face_boundary_id
Definition: types.h:223
write() calls write_vtu()
Definition: grid_out.h:938
active_cell_iterator begin_active(const unsigned int level=0) const
Definition: tria.cc:11935
static void declare_parameters(ParameterHandler &param)
Definition: grid_out.cc:60
void set_flags(const GridOutFlags::DX &flags)
Definition: grid_out.cc:487
bool label_level_number
Write level number into each cell. Defaults to true.
Definition: grid_out.h:743
void parse_parameters(ParameterHandler &param)
Definition: grid_out.cc:139
virtual Point< spacedim > transform_unit_to_real_cell(const typename Triangulation< dim, spacedim >::cell_iterator &cell, const Point< dim > &p) const =0
unsigned int write_ucd_lines(const Triangulation< dim, spacedim > &tria, const unsigned int next_element_index, std::ostream &out) const
Definition: grid_out.cc:3513
unsigned int neighbors[dim > 0?GeometryInfo< dim >::faces_per_cell:1]
unsigned int boundary_id
Definition: types.h:111
Table< 2, float > data
Gnuplot & operator=(const Gnuplot &flags)
Definition: grid_out.cc:172
void write_gnuplot(const Triangulation< dim, spacedim > &tria, std::ostream &out, const Mapping< dim, spacedim > *mapping=nullptr) const
Definition: grid_out.cc:4034
void write_dx(const Triangulation< dim, spacedim > &tria, std::ostream &out) const
Definition: grid_out.cc:797
GridOutFlags::Vtu vtu_flags
Definition: grid_out.h:1461
unsigned int width
Definition: grid_out.h:677
write() calls write_vtk()
Definition: grid_out.h:936
void parse_parameters(ParameterHandler &param)
Definition: grid_out.cc:473
void parse_parameters(ParameterHandler &param)
Definition: grid_out.cc:283
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 >> &nonscalar_data_ranges, const VtkFlags &flags, std::ostream &out)
long int get_integer(const std::string &entry_string) const
Gnuplot(const bool write_cell_number=false, const unsigned int n_extra_curved_line_points=2, const bool curved_inner_cells=false, const bool write_additional_boundary_lines=true)
Definition: grid_out.cc:148
static::ExceptionBase & ExcInternalError()