Reference documentation for deal.II version 8.5.1
grid_out.cc
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 1999 - 2017 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 (0);
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 (0);
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_cxx11::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_cxx11::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.push_back("level");
2541  data_names.push_back("subdomain");
2542  data_names.push_back("level_subdomain");
2543  data_names.push_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  const std::string new_file = (filename_without_extension + ".proc" +
2595  ".vtu");
2596  std::ofstream out(new_file.c_str());
2597  std::vector<std_cxx1x::tuple<unsigned int, unsigned int, std::string> > vector_data_ranges;
2598  DataOutBase::VtkFlags flags;
2599  DataOutBase::write_vtu (patches,
2600  data_names,
2601  vector_data_ranges,
2602  flags,
2603  out);
2604  //create .pvtu record
2605  if (tria.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  for (unsigned int i=0; i<Utilities::MPI::n_mpi_processes(MPI_COMM_WORLD); ++i)
2617  filenames.push_back (filename_without_extension.substr(pos) +
2618  ".proc" + Utilities::int_to_string(i, 4) +
2619  ".vtu");
2620 
2621  const std::string pvtu_master_filename = (filename_without_extension + ".pvtu");
2622  std::ofstream pvtu_master (pvtu_master_filename.c_str());
2623 
2625  data_out.attach_triangulation (tria);
2626 
2627  //We need a dummy vector with the names of the data values in the .vtu files
2628  //in order that the .pvtu contains reference these values
2629  Vector<float> dummy_vector (tria.n_active_cells());
2630  data_out.add_data_vector (dummy_vector, "level");
2631  data_out.add_data_vector (dummy_vector, "subdomain");
2632  data_out.add_data_vector (dummy_vector, "level_subdomain");
2633  data_out.add_data_vector (dummy_vector, "proc_writing");
2634 
2635  data_out.build_patches ();
2636 
2637  data_out.write_pvtu_record (pvtu_master, filenames);
2638  }
2639 }
2640 
2641 
2642 
2643 unsigned int GridOut::n_boundary_faces (const Triangulation<1> &) const
2644 {
2645  return 0;
2646 }
2647 
2648 unsigned int GridOut::n_boundary_lines (const Triangulation<1> &) const
2649 {
2650  return 0;
2651 }
2652 
2653 
2654 unsigned int GridOut::n_boundary_faces (const Triangulation<1,2> &) const
2655 {
2656  return 0;
2657 }
2658 
2659 unsigned int GridOut::n_boundary_lines (const Triangulation<1,2> &) const
2660 {
2661  return 0;
2662 }
2663 
2664 unsigned int GridOut::n_boundary_faces (const Triangulation<1,3> &) const
2665 {
2666  return 0;
2667 }
2668 
2669 unsigned int GridOut::n_boundary_lines (const Triangulation<1,3> &) const
2670 {
2671  return 0;
2672 }
2673 
2674 unsigned int GridOut::n_boundary_lines (const Triangulation<2,2> &) const
2675 {
2676  return 0;
2677 }
2678 
2679 unsigned int GridOut::n_boundary_lines (const Triangulation<2,3> &) const
2680 {
2681  return 0;
2682 }
2683 
2684 
2685 
2686 template <int dim, int spacedim>
2688 {
2690  unsigned int n_faces = 0;
2691 
2692  for (face=tria.begin_active_face(), endf=tria.end_face();
2693  face != endf; ++face)
2694  if ((face->at_boundary()) &&
2695  (face->boundary_id() != 0))
2696  n_faces++;
2697 
2698  return n_faces;
2699 }
2700 
2701 
2702 
2703 template <int dim, int spacedim>
2705 {
2706  // save the user flags for lines so
2707  // we can use these flags to track
2708  // which ones we've already counted
2709  std::vector<bool> line_flags;
2710  const_cast<::Triangulation<dim,spacedim>&>(tria)
2711  .save_user_flags_line (line_flags);
2712  const_cast<::Triangulation<dim,spacedim>&>(tria)
2713  .clear_user_flags_line ();
2714 
2715  unsigned int n_lines = 0;
2716 
2718 
2719  for (cell=tria.begin_active(), endc=tria.end();
2720  cell != endc; ++cell)
2721  for (unsigned int l=0; l<GeometryInfo<dim>::lines_per_cell; ++l)
2722  if (cell->line(l)->at_boundary()
2723  &&
2724  (cell->line(l)->boundary_id() != 0)
2725  &&
2726  (cell->line(l)->user_flag_set() == false))
2727  {
2728  ++n_lines;
2729  cell->line(l)->set_user_flag();
2730  }
2731 
2732  // at the end, restore the user
2733  // flags for the lines
2734  const_cast<::Triangulation<dim,spacedim>&>(tria)
2735  .load_user_flags_line (line_flags);
2736 
2737  return n_lines;
2738 }
2739 
2740 
2741 
2742 
2743 unsigned int
2745  const unsigned int next_element_index,
2746  std::ostream &) const
2747 {
2748  return next_element_index;
2749 }
2750 
2751 
2752 unsigned int
2754  const unsigned int next_element_index,
2755  std::ostream &) const
2756 {
2757  return next_element_index;
2758 }
2759 
2760 unsigned int
2762  const unsigned int next_element_index,
2763  std::ostream &) const
2764 {
2765  return next_element_index;
2766 }
2767 
2768 
2769 unsigned int
2771  const unsigned int next_element_index,
2772  std::ostream &) const
2773 {
2774  return next_element_index;
2775 }
2776 
2777 unsigned int
2779  const unsigned int next_element_index,
2780  std::ostream &) const
2781 {
2782  return next_element_index;
2783 }
2784 
2785 
2786 unsigned int
2788  const unsigned int next_element_index,
2789  std::ostream &) const
2790 {
2791  return next_element_index;
2792 }
2793 
2794 
2795 unsigned int
2797  const unsigned int next_element_index,
2798  std::ostream &) const
2799 {
2800  return next_element_index;
2801 }
2802 
2803 unsigned int
2805  const unsigned int next_element_index,
2806  std::ostream &) const
2807 {
2808  return next_element_index;
2809 }
2810 
2811 
2812 
2813 
2814 template <int dim, int spacedim>
2815 unsigned int
2817  const unsigned int next_element_index,
2818  std::ostream &out) const
2819 {
2820  unsigned int current_element_index = next_element_index;
2822 
2823  for (face=tria.begin_active_face(), endf=tria.end_face();
2824  face != endf; ++face)
2825  if (face->at_boundary() &&
2826  (face->boundary_id() != 0))
2827  {
2828  out << current_element_index << ' ';
2829  switch (dim)
2830  {
2831  case 2:
2832  out << 1 << ' ';
2833  break;
2834  case 3:
2835  out << 3 << ' ';
2836  break;
2837  default:
2838  Assert (false, ExcNotImplemented());
2839  }
2840  out << static_cast<unsigned int>(face->boundary_id())
2841  << ' '
2842  << static_cast<unsigned int>(face->boundary_id())
2844  // note: vertex numbers are 1-base
2845  for (unsigned int vertex=0; vertex<GeometryInfo<dim>::vertices_per_face; ++vertex)
2846  out << ' '
2847  << face->vertex_index(GeometryInfo<dim-1>::ucd_to_deal[vertex])+1;
2848  out << '\n';
2849 
2850  ++current_element_index;
2851  }
2852  return current_element_index;
2853 }
2854 
2855 
2856 template <int dim, int spacedim>
2857 unsigned int
2859  const unsigned int next_element_index,
2860  std::ostream &out) const
2861 {
2862  unsigned int current_element_index = next_element_index;
2863  // save the user flags for lines so
2864  // we can use these flags to track
2865  // which ones we've already taken
2866  // care of
2867  std::vector<bool> line_flags;
2868  const_cast<::Triangulation<dim,spacedim>&>(tria)
2869  .save_user_flags_line (line_flags);
2870  const_cast<::Triangulation<dim,spacedim>&>(tria)
2871  .clear_user_flags_line ();
2872 
2874 
2875  for (cell=tria.begin_active(), endc=tria.end();
2876  cell != endc; ++cell)
2877  for (unsigned int l=0; l<GeometryInfo<dim>::lines_per_cell; ++l)
2878  if (cell->line(l)->at_boundary()
2879  &&
2880  (cell->line(l)->boundary_id() != 0)
2881  &&
2882  (cell->line(l)->user_flag_set() == false))
2883  {
2884  out << next_element_index << " 1 ";
2885  out << static_cast<unsigned int>(cell->line(l)->boundary_id())
2886  << ' '
2887  << static_cast<unsigned int>(cell->line(l)->boundary_id())
2888  << " 2 ";
2889  // note: vertex numbers are 1-base
2890  for (unsigned int vertex=0; vertex<2; ++vertex)
2891  out << ' '
2892  << cell->line(l)->vertex_index(GeometryInfo<dim-2>::ucd_to_deal[vertex])+1;
2893  out << '\n';
2894 
2895  // move on to the next line
2896  // but mark the current one
2897  // as taken care of
2898  ++current_element_index;
2899  cell->line(l)->set_user_flag();
2900  }
2901 
2902  // at the end, restore the user
2903  // flags for the lines
2904  const_cast<::Triangulation<dim,spacedim>&>(tria)
2905  .load_user_flags_line (line_flags);
2906 
2907  return current_element_index;
2908 }
2909 
2910 
2911 
2912 
2913 unsigned int
2915  const unsigned int next_element_index,
2916  std::ostream &) const
2917 {
2918  return next_element_index;
2919 }
2920 
2921 unsigned int
2923  const unsigned int next_element_index,
2924  std::ostream &) const
2925 {
2926  return next_element_index;
2927 }
2928 
2929 unsigned int
2931  const unsigned int next_element_index,
2932  std::ostream &) const
2933 {
2934  return next_element_index;
2935 }
2936 
2937 unsigned int
2939  const unsigned int next_element_index,
2940  std::ostream &) const
2941 {
2942  return next_element_index;
2943 }
2944 
2945 unsigned int
2947  const unsigned int next_element_index,
2948  std::ostream &) const
2949 {
2950  return next_element_index;
2951 }
2952 
2953 
2954 unsigned int
2956  const unsigned int next_element_index,
2957  std::ostream &) const
2958 {
2959  return next_element_index;
2960 }
2961 
2962 
2963 unsigned int
2965  const unsigned int next_element_index,
2966  std::ostream &) const
2967 {
2968  return next_element_index;
2969 }
2970 
2971 unsigned int
2973  const unsigned int next_element_index,
2974  std::ostream &) const
2975 {
2976  return next_element_index;
2977 }
2978 
2979 
2980 
2981 template <int dim, int spacedim>
2982 unsigned int
2984  const unsigned int next_element_index,
2985  std::ostream &out) const
2986 {
2987  unsigned int current_element_index = next_element_index;
2989 
2990  for (face=tria.begin_active_face(), endf=tria.end_face();
2991  face != endf; ++face)
2992  if (face->at_boundary() &&
2993  (face->boundary_id() != 0))
2994  {
2995  out << current_element_index << " "
2996  << static_cast<unsigned int>(face->boundary_id())
2997  << " ";
2998  switch (dim)
2999  {
3000  case 2:
3001  out << "line ";
3002  break;
3003  case 3:
3004  out << "quad ";
3005  break;
3006  default:
3007  Assert (false, ExcNotImplemented());
3008  }
3009  // note: vertex numbers are 1-base
3010  for (unsigned int vertex=0; vertex<GeometryInfo<dim>::vertices_per_face; ++vertex)
3011  out << face->vertex_index(GeometryInfo<dim-1>::ucd_to_deal[vertex])+1 << ' ';
3012  out << '\n';
3013 
3014  ++current_element_index;
3015  }
3016  return current_element_index;
3017 }
3018 
3019 
3020 
3021 template <int dim, int spacedim>
3022 unsigned int
3024  const unsigned int next_element_index,
3025  std::ostream &out) const
3026 {
3027  unsigned int current_element_index = next_element_index;
3028  // save the user flags for lines so
3029  // we can use these flags to track
3030  // which ones we've already taken
3031  // care of
3032  std::vector<bool> line_flags;
3033  const_cast<::Triangulation<dim,spacedim>&>(tria)
3034  .save_user_flags_line (line_flags);
3035  const_cast<::Triangulation<dim,spacedim>&>(tria)
3036  .clear_user_flags_line ();
3037 
3039 
3040  for (cell=tria.begin_active(), endc=tria.end();
3041  cell != endc; ++cell)
3042  for (unsigned int l=0; l<GeometryInfo<dim>::lines_per_cell; ++l)
3043  if (cell->line(l)->at_boundary()
3044  &&
3045  (cell->line(l)->boundary_id() != 0)
3046  &&
3047  (cell->line(l)->user_flag_set() == false))
3048  {
3049  out << current_element_index << " "
3050  << static_cast<unsigned int>(cell->line(l)->boundary_id())
3051  << " line ";
3052  // note: vertex numbers in ucd format are 1-base
3053  for (unsigned int vertex=0; vertex<2; ++vertex)
3054  out << cell->line(l)->vertex_index(GeometryInfo<dim-2>::ucd_to_deal[vertex])+1
3055  << ' ';
3056  out << '\n';
3057 
3058  // move on to the next line
3059  // but mark the current one
3060  // as taken care of
3061  ++current_element_index;
3062  cell->line(l)->set_user_flag();
3063  }
3064 
3065  // at the end, restore the user
3066  // flags for the lines
3067  const_cast<::Triangulation<dim,spacedim>&>(tria)
3068  .load_user_flags_line (line_flags);
3069  return current_element_index;
3070 }
3071 
3072 
3073 Point<2> GridOut::svg_project_point(Point<3> point, Point<3> camera_position, Point<3> camera_direction, Point<3> camera_horizontal, float camera_focus)
3074 {
3075  // ...
3076  Point<3> camera_vertical;
3077  camera_vertical[0] = camera_horizontal[1] * camera_direction[2] - camera_horizontal[2] * camera_direction[1];
3078  camera_vertical[1] = camera_horizontal[2] * camera_direction[0] - camera_horizontal[0] * camera_direction[2];
3079  camera_vertical[2] = camera_horizontal[0] * camera_direction[1] - camera_horizontal[1] * camera_direction[0];
3080 
3081  float phi;
3082  phi = camera_focus;
3083  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];
3084 
3085  Point<3> projection;
3086  projection[0] = camera_position[0] + phi * (point[0] - camera_position[0]);
3087  projection[1] = camera_position[1] + phi * (point[1] - camera_position[1]);
3088  projection[2] = camera_position[2] + phi * (point[2] - camera_position[2]);
3089 
3090  Point<2> projection_decomposition;
3091  projection_decomposition[0] = (projection[0] - camera_position[0] - camera_focus * camera_direction[0]) * camera_horizontal[0];
3092  projection_decomposition[0] += (projection[1] - camera_position[1] - camera_focus * camera_direction[1]) * camera_horizontal[1];
3093  projection_decomposition[0] += (projection[2] - camera_position[2] - camera_focus * camera_direction[2]) * camera_horizontal[2];
3094 
3095  projection_decomposition[1] = (projection[0] - camera_position[0] - camera_focus * camera_direction[0]) * camera_vertical[0];
3096  projection_decomposition[1] += (projection[1] - camera_position[1] - camera_focus * camera_direction[1]) * camera_vertical[1];
3097  projection_decomposition[1] += (projection[2] - camera_position[2] - camera_focus * camera_direction[2]) * camera_vertical[2];
3098 
3099  return projection_decomposition;
3100 }
3101 
3102 
3103 
3104 namespace internal
3105 {
3106  namespace
3107  {
3108  template <int spacedim>
3109  void write_gnuplot (const ::Triangulation<1,spacedim> &tria,
3110  std::ostream &out,
3111  const Mapping<1,spacedim> *,
3112  const GridOutFlags::Gnuplot &gnuplot_flags)
3113  {
3114  AssertThrow (out, ExcIO());
3115 
3116  const int dim = 1;
3117 
3118  typename ::Triangulation<dim,spacedim>::active_cell_iterator
3119  cell=tria.begin_active();
3120  const typename ::Triangulation<dim,spacedim>::active_cell_iterator
3121  endc=tria.end();
3122  for (; cell!=endc; ++cell)
3123  {
3124  if (gnuplot_flags.write_cell_numbers)
3125  out << "# cell " << cell << '\n';
3126 
3127  out << cell->vertex(0)
3128  << ' ' << cell->level()
3129  << ' ' << static_cast<unsigned int>(cell->material_id()) << '\n'
3130  << cell->vertex(1)
3131  << ' ' << cell->level()
3132  << ' ' << static_cast<unsigned int>(cell->material_id()) << '\n'
3133  << "\n\n";
3134  }
3135 
3136  // make sure everything now gets to
3137  // disk
3138  out.flush ();
3139 
3140  AssertThrow (out, ExcIO());
3141  }
3142 
3143 
3144 
3145  template <int spacedim>
3146  void write_gnuplot (const ::Triangulation<2,spacedim> &tria,
3147  std::ostream &out,
3148  const Mapping<2,spacedim> *mapping,
3149  const GridOutFlags::Gnuplot &gnuplot_flags)
3150  {
3151  AssertThrow (out, ExcIO());
3152 
3153  const int dim = 2;
3154 
3155  const unsigned int n_additional_points=
3156  gnuplot_flags.n_boundary_face_points;
3157  const unsigned int n_points=2+n_additional_points;
3158 
3159  typename ::Triangulation<dim,spacedim>::active_cell_iterator
3160  cell=tria.begin_active();
3161  const typename ::Triangulation<dim,spacedim>::active_cell_iterator
3162  endc=tria.end();
3163 
3164  // if we are to treat curved
3165  // boundaries, then generate a
3166  // quadrature formula which will be
3167  // used to probe boundary points at
3168  // curved faces
3169  Quadrature<dim> *q_projector=0;
3170  std::vector<Point<dim-1> > boundary_points;
3171  if (mapping!=0)
3172  {
3173  boundary_points.resize(n_points);
3174  boundary_points[0][0]=0;
3175  boundary_points[n_points-1][0]=1;
3176  for (unsigned int i=1; i<n_points-1; ++i)
3177  boundary_points[i](0)= 1.*i/(n_points-1);
3178 
3179  std::vector<double> dummy_weights(n_points, 1./n_points);
3180  Quadrature<dim-1> quadrature(boundary_points, dummy_weights);
3181 
3182  q_projector = new Quadrature<dim> (QProjector<dim>::project_to_all_faces(quadrature));
3183  }
3184 
3185  for (; cell!=endc; ++cell)
3186  {
3187  if (gnuplot_flags.write_cell_numbers)
3188  out << "# cell " << cell << '\n';
3189 
3190  if (mapping==0 ||
3191  (!cell->at_boundary() && !gnuplot_flags.curved_inner_cells))
3192  {
3193  // write out the four sides
3194  // of this cell by putting
3195  // the four points (+ the
3196  // initial point again) in
3197  // a row and lifting the
3198  // drawing pencil at the
3199  // end
3200  for (unsigned int i=0; i<GeometryInfo<dim>::vertices_per_cell; ++i)
3201  out << cell->vertex(GeometryInfo<dim>::ucd_to_deal[i])
3202  << ' ' << cell->level()
3203  << ' ' << static_cast<unsigned int>(cell->material_id()) << '\n';
3204  out << cell->vertex(0)
3205  << ' ' << cell->level()
3206  << ' ' << static_cast<unsigned int>(cell->material_id()) << '\n'
3207  << '\n' // double new line for gnuplot 3d plots
3208  << '\n';
3209  }
3210  else
3211  // cell is at boundary and we
3212  // are to treat curved
3213  // boundaries. so loop over
3214  // all faces and draw them as
3215  // small pieces of lines
3216  {
3217  for (unsigned int face_no=0;
3218  face_no<GeometryInfo<dim>::faces_per_cell; ++face_no)
3219  {
3220  const typename ::Triangulation<dim,spacedim>::face_iterator
3221  face = cell->face(face_no);
3222  if (face->at_boundary() || gnuplot_flags.curved_inner_cells)
3223  {
3224  // compute offset
3225  // of quadrature
3226  // points within
3227  // set of projected
3228  // points
3229  const unsigned int offset=face_no*n_points;
3230  for (unsigned int i=0; i<n_points; ++i)
3231  out << (mapping->transform_unit_to_real_cell
3232  (cell, q_projector->point(offset+i)))
3233  << ' ' << cell->level()
3234  << ' ' << static_cast<unsigned int>(cell->material_id())
3235  << '\n';
3236 
3237  out << '\n'
3238  << '\n';
3239  }
3240  else
3241  {
3242  // if, however, the
3243  // face is not at
3244  // the boundary,
3245  // then draw it as
3246  // usual
3247  out << face->vertex(0)
3248  << ' ' << cell->level()
3249  << ' ' << static_cast<unsigned int>(cell->material_id())
3250  << '\n'
3251  << face->vertex(1)
3252  << ' ' << cell->level()
3253  << ' ' << static_cast<unsigned int>(cell->material_id())
3254  << '\n'
3255  << '\n'
3256  << '\n';
3257  }
3258  }
3259  }
3260  }
3261 
3262  if (q_projector != 0)
3263  delete q_projector;
3264 
3265  // make sure everything now gets to
3266  // disk
3267  out.flush ();
3268 
3269  AssertThrow (out, ExcIO());
3270  }
3271 
3272 
3273 
3274  template <int spacedim>
3275  void write_gnuplot (const ::Triangulation<3,spacedim> &tria,
3276  std::ostream &out,
3277  const Mapping<3,spacedim> *mapping,
3278  const GridOutFlags::Gnuplot &gnuplot_flags)
3279  {
3280  AssertThrow (out, ExcIO());
3281 
3282  const int dim = 3;
3283 
3284  const unsigned int n_additional_points=
3285  gnuplot_flags.n_boundary_face_points;
3286  const unsigned int n_points=2+n_additional_points;
3287 
3288  typename ::Triangulation<dim,spacedim>::active_cell_iterator
3289  cell=tria.begin_active();
3290  const typename ::Triangulation<dim,spacedim>::active_cell_iterator
3291  endc=tria.end();
3292 
3293  // if we are to treat curved
3294  // boundaries, then generate a
3295  // quadrature formula which will be
3296  // used to probe boundary points at
3297  // curved faces
3298  Quadrature<dim> *q_projector=0;
3299  std::vector<Point<1> > boundary_points;
3300  if (mapping!=0)
3301  {
3302  boundary_points.resize(n_points);
3303  boundary_points[0][0]=0;
3304  boundary_points[n_points-1][0]=1;
3305  for (unsigned int i=1; i<n_points-1; ++i)
3306  boundary_points[i](0)= 1.*i/(n_points-1);
3307 
3308  std::vector<double> dummy_weights(n_points, 1./n_points);
3309  Quadrature<1> quadrature1d(boundary_points, dummy_weights);
3310 
3311  // tensor product of points,
3312  // only one copy
3313  QIterated<dim-1> quadrature(quadrature1d, 1);
3314  q_projector = new Quadrature<dim> (QProjector<dim>::project_to_all_faces(quadrature));
3315  }
3316 
3317  for (; cell!=endc; ++cell)
3318  {
3319  if (gnuplot_flags.write_cell_numbers)
3320  out << "# cell " << cell << '\n';
3321 
3322  if (mapping==0 || n_points==2 ||
3323  (!cell->has_boundary_lines() && !gnuplot_flags.curved_inner_cells))
3324  {
3325  // front face
3326  out << cell->vertex(0)
3327  << ' ' << cell->level()
3328  << ' ' << static_cast<unsigned int>(cell->material_id()) << '\n'
3329  << cell->vertex(1)
3330  << ' ' << cell->level()
3331  << ' ' << static_cast<unsigned int>(cell->material_id()) << '\n'
3332  << cell->vertex(5)
3333  << ' ' << cell->level()
3334  << ' ' << static_cast<unsigned int>(cell->material_id()) << '\n'
3335  << cell->vertex(4)
3336  << ' ' << cell->level()
3337  << ' ' << static_cast<unsigned int>(cell->material_id()) << '\n'
3338  << cell->vertex(0)
3339  << ' ' << cell->level()
3340  << ' ' << static_cast<unsigned int>(cell->material_id()) << '\n'
3341  << '\n';
3342  // back face
3343  out << cell->vertex(2)
3344  << ' ' << cell->level()
3345  << ' ' << static_cast<unsigned int>(cell->material_id()) << '\n'
3346  << cell->vertex(3)
3347  << ' ' << cell->level()
3348  << ' ' << static_cast<unsigned int>(cell->material_id()) << '\n'
3349  << cell->vertex(7)
3350  << ' ' << cell->level()
3351  << ' ' << static_cast<unsigned int>(cell->material_id()) << '\n'
3352  << cell->vertex(6)
3353  << ' ' << cell->level()
3354  << ' ' << static_cast<unsigned int>(cell->material_id()) << '\n'
3355  << cell->vertex(2)
3356  << ' ' << cell->level()
3357  << ' ' << static_cast<unsigned int>(cell->material_id()) << '\n'
3358  << '\n';
3359 
3360  // now for the four connecting lines
3361  out << cell->vertex(0)
3362  << ' ' << cell->level()
3363  << ' ' << static_cast<unsigned int>(cell->material_id()) << '\n'
3364  << cell->vertex(2)
3365  << ' ' << cell->level()
3366  << ' ' << static_cast<unsigned int>(cell->material_id()) << '\n'
3367  << '\n';
3368  out << cell->vertex(1)
3369  << ' ' << cell->level()
3370  << ' ' << static_cast<unsigned int>(cell->material_id()) << '\n'
3371  << cell->vertex(3)
3372  << ' ' << cell->level()
3373  << ' ' << static_cast<unsigned int>(cell->material_id()) << '\n'
3374  << '\n';
3375  out << cell->vertex(5)
3376  << ' ' << cell->level()
3377  << ' ' << static_cast<unsigned int>(cell->material_id()) << '\n'
3378  << cell->vertex(7)
3379  << ' ' << cell->level()
3380  << ' ' << static_cast<unsigned int>(cell->material_id()) << '\n'
3381  << '\n';
3382  out << cell->vertex(4)
3383  << ' ' << cell->level()
3384  << ' ' << static_cast<unsigned int>(cell->material_id()) << '\n'
3385  << cell->vertex(6)
3386  << ' ' << cell->level()
3387  << ' ' << static_cast<unsigned int>(cell->material_id()) << '\n'
3388  << '\n';
3389  }
3390  else
3391  {
3392  for (unsigned int face_no=0; face_no<GeometryInfo<dim>::faces_per_cell; ++face_no)
3393  {
3394  const typename ::Triangulation<dim,spacedim>::face_iterator
3395  face = cell->face(face_no);
3396 
3397  if (face->at_boundary())
3398  {
3399  const unsigned int offset=face_no*n_points*n_points;
3400  for (unsigned int i=0; i<n_points-1; ++i)
3401  for (unsigned int j=0; j<n_points-1; ++j)
3402  {
3403  const Point<spacedim> p0=mapping->transform_unit_to_real_cell(
3404  cell, q_projector->point(offset+i*n_points+j));
3405  out << p0
3406  << ' ' << cell->level()
3407  << ' ' << static_cast<unsigned int>(cell->material_id()) << '\n';
3408  out << (mapping->transform_unit_to_real_cell(
3409  cell, q_projector->point(offset+(i+1)*n_points+j)))
3410  << ' ' << cell->level()
3411  << ' ' << static_cast<unsigned int>(cell->material_id()) << '\n';
3412  out << (mapping->transform_unit_to_real_cell(
3413  cell, q_projector->point(offset+(i+1)*n_points+j+1)))
3414  << ' ' << cell->level()
3415  << ' ' << static_cast<unsigned int>(cell->material_id()) << '\n';
3416  out << (mapping->transform_unit_to_real_cell(
3417  cell, q_projector->point(offset+i*n_points+j+1)))
3418  << ' ' << cell->level()
3419  << ' ' << static_cast<unsigned int>(cell->material_id()) << '\n';
3420  // and the
3421  // first
3422  // point
3423  // again
3424  out << p0
3425  << ' ' << cell->level()
3426  << ' ' << static_cast<unsigned int>(cell->material_id()) << '\n';
3427  out << '\n' << '\n';
3428  }
3429  }
3430  else
3431  {
3432  for (unsigned int l=0; l<GeometryInfo<dim>::lines_per_face; ++l)
3433  {
3434  const typename ::Triangulation<dim,spacedim>::line_iterator
3435  line=face->line(l);
3436 
3437  const Point<spacedim> &v0=line->vertex(0),
3438  &v1=line->vertex(1);
3439  if (line->at_boundary() || gnuplot_flags.curved_inner_cells)
3440  {
3441  // transform_real_to_unit_cell
3442  // could be
3443  // replaced
3444  // by using
3445  // QProjector<dim>::project_to_line
3446  // which is
3447  // not yet
3448  // implemented
3449  const Point<spacedim> u0=mapping->transform_real_to_unit_cell(cell, v0),
3450  u1=mapping->transform_real_to_unit_cell(cell, v1);
3451 
3452  for (unsigned int i=0; i<n_points; ++i)
3453  out << (mapping->transform_unit_to_real_cell
3454  (cell, (1-boundary_points[i][0])*u0+boundary_points[i][0]*u1))
3455  << ' ' << cell->level()
3456  << ' ' << static_cast<unsigned int>(cell->material_id()) << '\n';
3457  }
3458  else
3459  out << v0
3460  << ' ' << cell->level()
3461  << ' ' << static_cast<unsigned int>(cell->material_id()) << '\n'
3462  << v1
3463  << ' ' << cell->level()
3464  << ' ' << static_cast<unsigned int>(cell->material_id()) << '\n';
3465 
3466  out << '\n' << '\n';
3467  }
3468  }
3469  }
3470  }
3471  }
3472 
3473  if (q_projector != 0)
3474  delete q_projector;
3475 
3476 
3477  // make sure everything now gets to
3478  // disk
3479  out.flush ();
3480 
3481  AssertThrow (out, ExcIO());
3482  }
3483  }
3484 }
3485 
3486 
3487 
3488 template <int dim, int spacedim>
3490  const Triangulation<dim,spacedim> &tria,
3491  std::ostream &out,
3492  const Mapping<dim,spacedim> *mapping) const
3493 {
3494  internal::write_gnuplot (tria, out, mapping, gnuplot_flags);
3495 }
3496 
3497 
3498 
3499 namespace internal
3500 {
3501  namespace
3502  {
3503  struct LineEntry
3504  {
3505  Point<2> first;
3506  Point<2> second;
3507  bool colorize;
3508  unsigned int level;
3509  LineEntry (const Point<2> &f,
3510  const Point<2> &s,
3511  const bool c,
3512  const unsigned int l)
3513  :
3514  first(f), second(s),
3515  colorize(c), level(l)
3516  {}
3517  };
3518 
3519 
3520  void write_eps (const ::Triangulation<1> &,
3521  std::ostream &,
3522  const Mapping<1> *,
3523  const GridOutFlags::Eps<2> &,
3524  const GridOutFlags::Eps<3> &)
3525  {
3526  Assert(false, ExcNotImplemented());
3527  }
3528 
3529  void write_eps (const ::Triangulation<1,2> &,
3530  std::ostream &,
3531  const Mapping<1,2> *,
3532  const GridOutFlags::Eps<2> &,
3533  const GridOutFlags::Eps<3> &)
3534  {
3535  Assert(false, ExcNotImplemented());
3536  }
3537 
3538  void write_eps (const ::Triangulation<1,3> &,
3539  std::ostream &,
3540  const Mapping<1,3> *,
3541  const GridOutFlags::Eps<2> &,
3542  const GridOutFlags::Eps<3> &)
3543  {
3544  Assert(false, ExcNotImplemented());
3545  }
3546 
3547  void write_eps (const ::Triangulation<2,3> &,
3548  std::ostream &,
3549  const Mapping<2,3> *,
3550  const GridOutFlags::Eps<2> &,
3551  const GridOutFlags::Eps<3> &)
3552  {
3553  Assert(false, ExcNotImplemented());
3554  }
3555 
3556 
3557 
3558  template <int dim, int spacedim>
3559  void write_eps (const ::Triangulation<dim, spacedim> &tria,
3560  std::ostream &out,
3561  const Mapping<dim,spacedim> *mapping,
3562  const GridOutFlags::Eps<2> &eps_flags_2,
3563  const GridOutFlags::Eps<3> &eps_flags_3)
3564  {
3565  typedef std::list<LineEntry> LineList;
3566 
3567  // We should never get here in 1D since this function is overloaded for
3568  // all dim == 1 cases.
3569  Assert(dim == 2 || dim == 3, ExcInternalError());
3570 
3571  // Copy, with an object slice, something containing the flags common to
3572  // all dimensions in order to avoid the recurring distinctions between
3573  // the different eps_flags present.
3574  const GridOutFlags::EpsFlagsBase eps_flags_base =
3575  dim == 2 ?
3576  static_cast<const GridOutFlags::EpsFlagsBase &>(eps_flags_2) :
3577  static_cast<const GridOutFlags::EpsFlagsBase &>(eps_flags_3);
3578 
3579  AssertThrow (out, ExcIO());
3580  const unsigned int n_points = eps_flags_base.n_boundary_face_points;
3581 
3582  // make up a list of lines by which
3583  // we will construct the triangulation
3584  //
3585  // this part unfortunately is a bit
3586  // dimension dependent, so we have to
3587  // treat every dimension different.
3588  // however, by directly producing
3589  // the lines to be printed, i.e. their
3590  // 2d images, we can later do the
3591  // actual output dimension independent
3592  // again
3593  LineList line_list;
3594 
3595  switch (dim)
3596  {
3597  case 1:
3598  {
3599  Assert(false, ExcInternalError());
3600  break;
3601  }
3602 
3603  case 2:
3604  {
3605  for (typename ::Triangulation<dim, spacedim>::active_cell_iterator
3606  cell=tria.begin_active();
3607  cell!=tria.end(); ++cell)
3608  for (unsigned int line_no=0;
3609  line_no<GeometryInfo<dim>::lines_per_cell; ++line_no)
3610  {
3611  typename ::Triangulation<dim, spacedim>::line_iterator
3612  line=cell->line(line_no);
3613 
3614  // first treat all
3615  // interior lines and
3616  // make up a list of
3617  // them. if curved
3618  // lines shall not be
3619  // supported (i.e. no
3620  // mapping is
3621  // provided), then also
3622  // treat all other
3623  // lines
3624  if (!line->has_children() &&
3625  (mapping==0 || !line->at_boundary()))
3626  // one would expect
3627  // make_pair(line->vertex(0),
3628  // line->vertex(1))
3629  // here, but that is
3630  // not dimension
3631  // independent, since
3632  // vertex(i) is
3633  // Point<dim>, but we
3634  // want a Point<2>.
3635  // in fact, whenever
3636  // we're here, the
3637  // vertex is a
3638  // Point<dim>, but
3639  // the compiler does
3640  // not know
3641  // this. hopefully,
3642  // the compiler will
3643  // optimize away this
3644  // little kludge
3645  line_list.push_back (LineEntry(Point<2>(line->vertex(0)(0),
3646  line->vertex(0)(1)),
3647  Point<2>(line->vertex(1)(0),
3648  line->vertex(1)(1)),
3649  line->user_flag_set(),
3650  cell->level()));
3651  }
3652 
3653  // next if we are to treat
3654  // curved boundaries
3655  // specially, then add lines
3656  // to the list consisting of
3657  // pieces of the boundary
3658  // lines
3659  if (mapping!=0)
3660  {
3661  // to do so, first
3662  // generate a sequence of
3663  // points on a face and
3664  // project them onto the
3665  // faces of a unit cell
3666  std::vector<Point<dim-1> > boundary_points (n_points);
3667 
3668  for (unsigned int i=0; i<n_points; ++i)
3669  boundary_points[i](0) = 1.*(i+1)/(n_points+1);
3670 
3671  Quadrature<dim-1> quadrature (boundary_points);
3672  Quadrature<dim> q_projector (QProjector<dim>::project_to_all_faces(quadrature));
3673 
3674  // next loop over all
3675  // boundary faces and
3676  // generate the info from
3677  // them
3678  for (typename ::Triangulation<dim, spacedim>::active_cell_iterator
3679  cell=tria.begin_active();
3680  cell!=tria.end(); ++cell)
3681  for (unsigned int face_no=0; face_no<GeometryInfo<dim>::faces_per_cell; ++face_no)
3682  {
3683  const typename ::Triangulation<dim, spacedim>::face_iterator
3684  face = cell->face(face_no);
3685 
3686  if (face->at_boundary())
3687  {
3688  Point<dim> p0_dim(face->vertex(0));
3689  Point<2> p0 (p0_dim(0), p0_dim(1));
3690 
3691  // loop over
3692  // all pieces
3693  // of the line
3694  // and generate
3695  // line-lets
3696  const unsigned int offset=face_no*n_points;
3697  for (unsigned int i=0; i<n_points; ++i)
3698  {
3699  const Point<dim> p1_dim (mapping->transform_unit_to_real_cell
3700  (cell, q_projector.point(offset+i)));
3701  const Point<2> p1 (p1_dim(0), p1_dim(1));
3702 
3703  line_list.push_back (LineEntry(p0, p1,
3704  face->user_flag_set(),
3705  cell->level() ));
3706  p0=p1;
3707  }
3708 
3709  // generate last piece
3710  const Point<dim> p1_dim (face->vertex(1));
3711  const Point<2> p1 (p1_dim(0), p1_dim(1));
3712  line_list.push_back (LineEntry(p0, p1,
3713  face->user_flag_set(),
3714  cell->level()));
3715  }
3716  }
3717  }
3718 
3719  break;
3720  }
3721 
3722  case 3:
3723  {
3724  // curved boundary output
3725  // presently not supported
3726  Assert (mapping == 0, ExcNotImplemented());
3727 
3728  typename ::Triangulation<dim, spacedim>::active_cell_iterator
3729  cell=tria.begin_active(),
3730  endc=tria.end();
3731 
3732  // loop over all lines and compute their
3733  // projection on the plane perpendicular
3734  // to the direction of sight
3735 
3736  // direction of view equals the unit
3737  // vector of the position of the
3738  // spectator to the origin.
3739  //
3740  // we chose here the viewpoint as in
3741  // gnuplot as default.
3742  //
3743  //TODO:[WB] Fix a potential problem with viewing angles in 3d Eps GridOut
3744  // note: the following might be wrong
3745  // if one of the base vectors below
3746  // is in direction of the viewer, but
3747  // I am too tired at present to fix
3748  // this
3749  const double pi = numbers::PI;
3750  const double z_angle = eps_flags_3.azimut_angle;
3751  const double turn_angle = eps_flags_3.turn_angle;
3752  const Point<dim> view_direction(-std::sin(z_angle * 2.*pi / 360.) * std::sin(turn_angle * 2.*pi / 360.),
3753  +std::sin(z_angle * 2.*pi / 360.) * std::cos(turn_angle * 2.*pi / 360.),
3754  -std::cos(z_angle * 2.*pi / 360.));
3755 
3756  // decide about the two unit vectors
3757  // in this plane. we chose the first one
3758  // to be the projection of the z-axis
3759  // to this plane
3760  const Tensor<1,dim> vector1
3761  = Point<dim>(0,0,1) - ((Point<dim>(0,0,1) * view_direction) * view_direction);
3762  const Tensor<1,dim> unit_vector1 = vector1 / vector1.norm();
3763 
3764  // now the third vector is fixed. we
3765  // chose the projection of a more or
3766  // less arbitrary vector to the plane
3767  // perpendicular to the first one
3768  const Tensor<1,dim> vector2
3769  = (Point<dim>(1,0,0)
3770  - ((Point<dim>(1,0,0) * view_direction) * view_direction)
3771  - ((Point<dim>(1,0,0) * unit_vector1) * unit_vector1));
3772  const Tensor<1,dim> unit_vector2 = vector2 / vector2.norm();
3773 
3774 
3775  for (; cell!=endc; ++cell)
3776  for (unsigned int line_no=0;
3777  line_no<GeometryInfo<dim>::lines_per_cell; ++line_no)
3778  {
3779  typename ::Triangulation<dim, spacedim>::line_iterator
3780  line=cell->line(line_no);
3781  line_list.push_back (LineEntry(Point<2>(line->vertex(0) * unit_vector2,
3782  line->vertex(0) * unit_vector1),
3783  Point<2>(line->vertex(1) * unit_vector2,
3784  line->vertex(1) * unit_vector1),
3785  line->user_flag_set(),
3786  cell->level()));
3787  }
3788 
3789  break;
3790  }
3791 
3792  default:
3793  Assert (false, ExcNotImplemented());
3794  }
3795 
3796 
3797 
3798  // find out minimum and maximum x and
3799  // y coordinates to compute offsets
3800  // and scaling factors
3801  double x_min = tria.begin_active()->vertex(0)(0);
3802  double x_max = x_min;
3803  double y_min = tria.begin_active()->vertex(0)(1);
3804  double y_max = y_min;
3805  unsigned int max_level = line_list.begin()->level;
3806 
3807  for (LineList::const_iterator line=line_list.begin();
3808  line!=line_list.end(); ++line)
3809  {
3810  x_min = std::min (x_min, line->first(0));
3811  x_min = std::min (x_min, line->second(0));
3812 
3813  x_max = std::max (x_max, line->first(0));
3814  x_max = std::max (x_max, line->second(0));
3815 
3816  y_min = std::min (y_min, line->first(1));
3817  y_min = std::min (y_min, line->second(1));
3818 
3819  y_max = std::max (y_max, line->first(1));
3820  y_max = std::max (y_max, line->second(1));
3821 
3822  max_level = std::max (max_level, line->level);
3823  }
3824 
3825  // scale in x-direction such that
3826  // in the output 0 <= x <= 300.
3827  // don't scale in y-direction to
3828  // preserve the shape of the
3829  // triangulation
3830  const double scale = (eps_flags_base.size /
3831  (eps_flags_base.size_type==GridOutFlags::EpsFlagsBase::width ?
3832  x_max - x_min :
3833  y_min - y_max));
3834 
3835 
3836  // now write preamble
3837  if (true)
3838  {
3839  // block this to have local
3840  // variables destroyed after
3841  // use
3842  std::time_t time1= std::time (0);
3843  std::tm *time = std::localtime(&time1);
3844  out << "%!PS-Adobe-2.0 EPSF-1.2" << '\n'
3845  << "%%Title: deal.II Output" << '\n'
3846  << "%%Creator: the deal.II library" << '\n'
3847  << "%%Creation Date: "
3848  << time->tm_year+1900 << "/"
3849  << time->tm_mon+1 << "/"
3850  << time->tm_mday << " - "
3851  << time->tm_hour << ":"
3852  << std::setw(2) << time->tm_min << ":"
3853  << std::setw(2) << time->tm_sec << '\n'
3854  << "%%BoundingBox: "
3855  // lower left corner
3856  << "0 0 "
3857  // upper right corner
3858  << static_cast<unsigned int>(std::floor(( (x_max-x_min) * scale )+1))
3859  << ' '
3860  << static_cast<unsigned int>(std::floor(( (y_max-y_min) * scale )+1))
3861  << '\n';
3862 
3863  // define some abbreviations to keep
3864  // the output small:
3865  // m=move turtle to
3866  // x=execute line stroke
3867  // b=black pen
3868  // r=red pen
3869  out << "/m {moveto} bind def" << '\n'
3870  << "/x {lineto stroke} bind def" << '\n'
3871  << "/b {0 0 0 setrgbcolor} def" << '\n'
3872  << "/r {1 0 0 setrgbcolor} def" << '\n';
3873 
3874  // calculate colors for level
3875  // coloring; level 0 is black,
3876  // other levels are blue
3877  // ... red
3878  if (eps_flags_base.color_lines_level)
3879  out << "/l { neg "
3880  << (max_level)
3881  << " add "
3882  << (0.66666/std::max(1U,(max_level-1)))
3883  << " mul 1 0.8 sethsbcolor} def" << '\n';
3884 
3885  // in 2d, we can also plot cell
3886  // and vertex numbers, but this
3887  // requires a somewhat more
3888  // lengthy preamble. please
3889  // don't ask me what most of
3890  // this means, it is reverse
3891  // engineered from what GNUPLOT
3892  // uses in its output
3893  if ((dim == 2) && (eps_flags_2.write_cell_numbers ||
3894  eps_flags_2.write_vertex_numbers))
3895  {
3896  out << ("/R {rmoveto} bind def\n"
3897  "/Symbol-Oblique /Symbol findfont [1 0 .167 1 0 0] makefont\n"
3898  "dup length dict begin {1 index /FID eq {pop pop} {def} ifelse} forall\n"
3899  "currentdict end definefont\n"
3900  "/MFshow {{dup dup 0 get findfont exch 1 get scalefont setfont\n"
3901  "[ currentpoint ] exch dup 2 get 0 exch rmoveto dup dup 5 get exch 4 get\n"
3902  "{show} {stringwidth pop 0 rmoveto}ifelse dup 3 get\n"
3903  "{2 get neg 0 exch rmoveto pop} {pop aload pop moveto}ifelse} forall} bind def\n"
3904  "/MFwidth {0 exch {dup 3 get{dup dup 0 get findfont exch 1 get scalefont setfont\n"
3905  "5 get stringwidth pop add}\n"
3906  "{pop} ifelse} forall} bind def\n"
3907  "/MCshow { currentpoint stroke m\n"
3908  "exch dup MFwidth -2 div 3 -1 roll R MFshow } def\n")
3909  << '\n';
3910  }
3911 
3912  out << "%%EndProlog" << '\n'
3913  << '\n';
3914 
3915  // set fine lines
3916  out << eps_flags_base.line_width << " setlinewidth" << '\n';
3917  }
3918 
3919  // now write the lines
3920  const Point<2> offset(x_min, y_min);
3921 
3922  for (LineList::const_iterator line=line_list.begin();
3923  line!=line_list.end(); ++line)
3924  if (eps_flags_base.color_lines_level && (line->level > 0))
3925  // lines colored according to
3926  // refinement level,
3927  // contributed by J�rg
3928  // R. Weimar
3929  out << line->level
3930  << " l "
3931  << (line->first - offset) * scale << " m "
3932  << (line->second - offset) * scale << " x" << '\n';
3933  else
3934  out << ((line->colorize && eps_flags_base.color_lines_on_user_flag) ? "r " : "b ")
3935  << (line->first - offset) * scale << " m "
3936  << (line->second - offset) * scale << " x" << '\n';
3937 
3938  // finally write the cell numbers
3939  // in 2d, if that is desired
3940  if ((dim == 2) && (eps_flags_2.write_cell_numbers == true))
3941  {
3942  out << "(Helvetica) findfont 140 scalefont setfont"
3943  << '\n';
3944 
3945  typename ::Triangulation<dim, spacedim>::active_cell_iterator
3946  cell = tria.begin_active (),
3947  endc = tria.end ();
3948  for (; cell!=endc; ++cell)
3949  {
3950  out << (cell->center()(0)-offset(0))*scale << ' '
3951  << (cell->center()(1)-offset(1))*scale
3952  << " m" << '\n'
3953  << "[ [(Helvetica) 12.0 0.0 true true (";
3954  if (eps_flags_2.write_cell_number_level)
3955  out << cell;
3956  else
3957  out << cell->index();
3958 
3959  out << ")] "
3960  << "] -6 MCshow"
3961  << '\n';
3962  }
3963  }
3964 
3965  // and the vertex numbers
3966  if ((dim == 2) && (eps_flags_2.write_vertex_numbers == true))
3967  {
3968  out << "(Helvetica) findfont 140 scalefont setfont"
3969  << '\n';
3970 
3971  // have a list of those
3972  // vertices which we have
3973  // already tracked, to avoid
3974  // doing this multiply
3975  std::set<unsigned int> treated_vertices;
3976  typename ::Triangulation<dim, spacedim>::active_cell_iterator
3977  cell = tria.begin_active (),
3978  endc = tria.end ();
3979  for (; cell!=endc; ++cell)
3980  for (unsigned int vertex=0;
3981  vertex<GeometryInfo<dim>::vertices_per_cell;
3982  ++vertex)
3983  if (treated_vertices.find(cell->vertex_index(vertex))
3984  ==
3985  treated_vertices.end())
3986  {
3987  treated_vertices.insert (cell->vertex_index(vertex));
3988 
3989  out << (cell->vertex(vertex)(0)-offset(0))*scale << ' '
3990  << (cell->vertex(vertex)(1)-offset(1))*scale
3991  << " m" << '\n'
3992  << "[ [(Helvetica) 10.0 0.0 true true ("
3993  << cell->vertex_index(vertex)
3994  << ")] "
3995  << "] -6 MCshow"
3996  << '\n';
3997  }
3998  }
3999 
4000  out << "showpage" << '\n';
4001 
4002  // make sure everything now gets to
4003  // disk
4004  out.flush ();
4005 
4006  AssertThrow (out, ExcIO());
4007  }
4008  }
4009 }
4010 
4011 
4012 template <int dim, int spacedim>
4014  std::ostream &out,
4015  const Mapping<dim,spacedim> *mapping) const
4016 {
4017  internal::write_eps (tria, out, mapping,
4019 }
4020 
4021 
4022 template <int dim, int spacedim>
4024  std::ostream &out,
4025  const OutputFormat output_format,
4026  const Mapping<dim,spacedim> *mapping) const
4027 {
4028  switch (output_format)
4029  {
4030  case none:
4031  return;
4032 
4033  case dx:
4034  write_dx (tria, out);
4035  return;
4036 
4037  case ucd:
4038  write_ucd (tria, out);
4039  return;
4040 
4041  case gnuplot:
4042  write_gnuplot (tria, out, mapping);
4043  return;
4044 
4045  case eps:
4046  write_eps (tria, out, mapping);
4047  return;
4048 
4049  case xfig:
4050  write_xfig (tria, out, mapping);
4051  return;
4052 
4053  case msh:
4054  write_msh (tria, out);
4055  return;
4056 
4057  case svg:
4058  write_svg (tria, out);
4059  return;
4060 
4061  case mathgl:
4062  write_mathgl (tria, out);
4063  return;
4064 
4065  case vtk:
4066  write_vtk (tria, out);
4067  return;
4068 
4069  case vtu:
4070  write_vtu (tria, out);
4071  return;
4072  }
4073 
4074  Assert (false, ExcInternalError());
4075 }
4076 
4077 
4078 template <int dim, int spacedim>
4080  std::ostream &out,
4081  const Mapping<dim,spacedim> *mapping) const
4082 {
4083  write(tria, out, default_format, mapping);
4084 }
4085 
4086 
4087 // explicit instantiations
4088 #include "grid_out.inst"
4089 
4090 
4091 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:2687
unsigned int n_active_cells() const
Definition: tria.cc:11244
long int get_integer(const std::string &entry_string) const
unsigned int n_used_vertices() const
Definition: tria.cc:11772
static const unsigned int invalid_unsigned_int
Definition: types.h:170
OutputFormat default_format
Definition: grid_out.h:1270
static void declare_parameters(ParameterHandler &prm)
DX(const bool write_cells=true, const bool write_faces=false, const bool write_diameter=false, const bool write_measure=false, const bool write_all_faces=true)
Definition: grid_out.cc:44
active_face_iterator begin_active_face() const
Definition: tria.cc:10848
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 > &)
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:1305
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:653
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
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:10668
unsigned int line_thickness
Thickness of the lines between cells.
Definition: grid_out.h:618
void write_eps(const Triangulation< dim, spacedim > &tria, std::ostream &out, const Mapping< dim, spacedim > *mapping=0) const
Definition: grid_out.cc:4013
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:369
bool write_diameter
Definition: grid_out.h:65
numbers::NumberTraits< Number >::real_type norm() const
Definition: tensor.h:991
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:3073
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:10648
unsigned int write_msh_faces(const Triangulation< dim, spacedim > &tria, const unsigned int next_element_index, std::ostream &out) const
Definition: grid_out.cc:2816
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
cell_iterator end() const
Definition: tria.cc:10736
unsigned int n_boundary_lines(const Triangulation< dim, spacedim > &tria) const
Definition: grid_out.cc:2704
void enter_subsection(const std::string &subsection)
GridOutFlags::Vtk vtk_flags
Definition: grid_out.h:1331
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:94
GridOutFlags::Gnuplot gnuplot_flags
Definition: grid_out.h:1293
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)
void write_gnuplot(const Triangulation< dim, spacedim > &tria, std::ostream &out, const Mapping< dim, spacedim > *mapping=0) const
Definition: grid_out.cc:3489
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:1326
write() calls write_mathgl()
Definition: grid_out.h:864
GridOutFlags::DX dx_flags
Definition: grid_out.h:1275
GridOutFlags::Msh msh_flags
Definition: grid_out.h:1281
GridOutFlags::Eps< 1 > eps_flags_1
Definition: grid_out.h:1299
void reinit(const TableIndices< N > &new_size, const bool omit_default_initialization=false)
void write_eps(const std::vector< Patch< 2, spacedim > > &patches, const std::vector< std::string > &data_names, const std::vector< std_cxx11::tuple< unsigned int, unsigned int, std::string > > &vector_data_ranges, const EpsFlags &flags, std::ostream &out)
write() calls write_gnuplot()
Definition: grid_out.h:852
#define Assert(cond, exc)
Definition: exceptions.h:313
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:1316
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:1287
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:85
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:63
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
void write_vtk(const std::vector< Patch< dim, spacedim > > &patches, const std::vector< std::string > &data_names, const std::vector< std_cxx11::tuple< unsigned int, unsigned int, std::string > > &vector_data_ranges, const VtkFlags &flags, std::ostream &out)
write() calls write_xfig()
Definition: grid_out.h:858
void write_vtu(const std::vector< Patch< dim, spacedim > > &patches, const std::vector< std::string > &data_names, const std::vector< std_cxx11::tuple< unsigned int, unsigned int, std::string > > &vector_data_ranges, const VtkFlags &flags, std::ostream &out)
Convert the level subdomain id into the cell color.
Definition: grid_out.h:664
static Quadrature< dim > project_to_all_faces(const SubQuadrature &quadrature)
void write(const Triangulation< dim, spacedim > &tria, std::ostream &out, const OutputFormat output_format, const Mapping< dim, spacedim > *mapping=0) const
Definition: grid_out.cc:4023
bool write_faces
Definition: grid_out.h:60
const types::subdomain_id artificial_subdomain_id
Definition: types.h:261
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:2983
write() calls write_msh()
Definition: grid_out.h:860
const std::vector< bool > & get_used_vertices() const
Definition: tria.cc:11782
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:3023
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:2858
GridOutFlags::Svg svg_flags
Definition: grid_out.h:1321
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 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
unsigned char boundary_id
Definition: types.h:110
GridOutFlags::Eps< 3 > eps_flags_3
Definition: grid_out.h:1311
face_iterator end_face() const
Definition: tria.cc:10869
static ::ExceptionBase & ExcInvalidState()
const types::boundary_id internal_face_boundary_id
Definition: types.h:216
write() calls write_vtu()
Definition: grid_out.h:868
void write_gnuplot(const std::vector< Patch< dim, spacedim > > &patches, const std::vector< std::string > &data_names, const std::vector< std_cxx11::tuple< unsigned int, unsigned int, std::string > > &vector_data_ranges, const GnuplotFlags &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
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:1336
unsigned int width
The width of the plot. Computed automatically from height if zero (default)
Definition: grid_out.h:616
void write_xfig(const Triangulation< dim, spacedim > &tria, std::ostream &out, const Mapping< dim, spacedim > *mapping=0) const
Definition: grid_out.cc:1217
Table< 2, float > data
write() calls write_vtk()
Definition: grid_out.h:866
virtual types::subdomain_id locally_owned_subdomain() const
Definition: tria.cc:11846
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