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