]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Add support for writing the numbers of cells to 2d eps grid output. Add testcase.
authorwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 5 Jun 2002 06:46:29 +0000 (06:46 +0000)
committerwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 5 Jun 2002 06:46:29 +0000 (06:46 +0000)
git-svn-id: https://svn.dealii.org/trunk@5988 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/deal.II/include/grid/grid_out.h
deal.II/deal.II/source/grid/grid_out.all_dimensions.cc
deal.II/deal.II/source/grid/grid_out.cc
deal.II/doc/news/2002/c-3-4.html
tests/deal.II/Makefile
tests/deal.II/grid_out.cc [new file with mode: 0644]

index f09832192bb623e5e4fd04011cf017fd5c59cb92..f3b286b6061b424d0782a644480959165feeef36 100644 (file)
@@ -29,8 +29,6 @@ template <int dim> class Mapping;
  * modify the default outfit of the grids written into a file. See the
  * different subclasses and the documentation of the @ref{GridOut}
  * class for more details.
- *
- * @author Wolfgang Bangerth, 1998, 2001
  */
 namespace GridOutFlags
 {
@@ -282,6 +280,19 @@ namespace GridOutFlags
   template <>
   struct Eps<2> : public EpsFlagsBase 
   {
+                                      /**
+                                       * If this flag is set, then we
+                                       * place the number of the cell
+                                       * into the middle of each
+                                       * cell. The default value is
+                                       * to not do this.
+                                       *
+                                       * The format of the cell
+                                       * number written is
+                                       * @p{level.index}.
+                                       */
+      bool plot_cell_numbers;
+      
                                       /**
                                        * Constructor.
                                        */
@@ -289,7 +300,8 @@ namespace GridOutFlags
           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 unsigned int n_boundary_face_points = 2,
+          const bool         plot_cell_numbers = false);
   };
   
                                   /**
index b98eab480cdb28bc9ac6ec89e1a79bbad07545aa..7e5840d2752fd1f46ba7d7625dcf016bf3d69dd8 100644 (file)
@@ -78,11 +78,13 @@ namespace GridOutFlags
               const unsigned int size,
               const double       line_width,
               const bool color_lines_on_user_flag,
-              const unsigned int n_boundary_face_points)
+              const unsigned int n_boundary_face_points,
+              const bool         plot_cell_numbers)
                  :
                  EpsFlagsBase(size_type, size, line_width,
                               color_lines_on_user_flag,
-                              n_boundary_face_points)
+                              n_boundary_face_points),
+                 plot_cell_numbers (plot_cell_numbers)
   {};
 
 
index 03d40a5f52e38f98296d8e1ed0250fea2aea540d..7f4fb29d03c92e0e429365b6dfb721750fde8d89 100644 (file)
@@ -1002,6 +1002,32 @@ void GridOut::write_eps (const Triangulation<dim> &tria,
          << "/x {lineto stroke} bind def" << std::endl
          << "/b {0 0 0 setrgbcolor} def" << std::endl
          << "/r {1 0 0 setrgbcolor} def" << std::endl;
+
+                                      // in 2d, we can also plot cell
+                                      // numbers, but this requires a
+                                      // somewhat more lengthy
+                                      // preamble. please don't ask
+                                      // me what most of this means,
+                                      // it is reverse engineered
+                                      // from what GNUPLOT uses in
+                                      // its output
+      if ((dim == 2) && (eps_flags_2.plot_cell_numbers == true))
+       {
+         out << ("/R {rmoveto} bind def\n"
+                 "/Symbol-Oblique /Symbol findfont [1 0 .167 1 0 0] makefont\n"
+                 "dup length dict begin {1 index /FID eq {pop pop} {def} ifelse} forall\n"
+                 "currentdict end definefont\n"
+                 "/MFshow {{dup dup 0 get findfont exch 1 get scalefont setfont\n"
+                 "[ currentpoint ] exch dup 2 get 0 exch rmoveto dup dup 5 get exch 4 get\n"
+                 "{show} {stringwidth pop 0 rmoveto}ifelse dup 3 get\n"
+                 "{2 get neg 0 exch rmoveto pop} {pop aload pop moveto}ifelse} forall} bind def\n"
+                 "/MFwidth {0 exch {dup 3 get{dup dup 0 get findfont exch 1 get scalefont setfont\n"
+                 "5 get stringwidth pop add}\n"
+                 "{pop} ifelse} forall} bind def\n"
+                 "/MCshow { currentpoint stroke m\n"
+                 "exch dup MFwidth -2 div 3 -1 roll R MFshow } def\n")
+             << std::endl;
+       };
       
       out << "%%EndProlog" << std::endl
          << std::endl;
@@ -1019,6 +1045,25 @@ void GridOut::write_eps (const Triangulation<dim> &tria,
        << (line->first  - offset) * scale << " m "
        << (line->second - offset) * scale << " x" << std::endl;
 
+                                  // finally write the cell numbers
+                                  // in 2d, if that is desired
+  if ((dim == 2) && (eps_flags_2.plot_cell_numbers == true))
+    {
+      out << "(Helvetica) findfont 140 scalefont setfont"
+         << std::endl;
+      
+      typename Triangulation<dim>::active_cell_iterator
+       cell = tria.begin_active (),
+       endc = tria.end ();
+      for (; cell!=endc; ++cell)
+       out << (cell->center()(0)-offset(0))*scale << ' '
+           << (cell->center()(1)-offset(1))*scale
+           << " m" << std::endl
+           << "[ [(Helvetica) 12.0 0.0 true true (" << cell << " )] "
+           << "] -6 MCshow"
+           << std::endl;
+    };
+
   out << "showpage" << std::endl;
   
   AssertThrow (out, ExcIO());
index 3e56b7c08bc12cf8be04f55fd7e15f6ec5ed30ba..2053acb6acf3c1ae0382fa34903dff3e8b15db8a 100644 (file)
@@ -15,7 +15,7 @@
 
 <p>
 This is the list of changes made after the release of 
-<acronym>deal.II</acronym> version 3.3. It is subdivided into changes
+<acronym>deal.II</acronym> version 3.4. It is subdivided into changes
 made to the three sub-libraries <a href="#base">base</a>, 
 <a href="#lac">lac</a>, and <a href="#deal.II">deal.II</a>, as well as
 changes to the <a href="#general">general infrastructure,
@@ -57,6 +57,13 @@ contributor's names are abbreviated by WB (Wolfgang Bangerth), GK
 <h3>deal.II</h3>
 
 <ol>
+  <li> <p> 
+       New: For encapsulated postscript of 2d grids, it is now
+       possible to tell the <code class="class">GridOut</code> to
+       write the cell numbers into each cell.
+       <br>
+       (WB 2002/06/04)
+       </p>
 </ol>
 
 <hr>
index cea682b76933f11dc3a4cb19c67c480799632e8c..4111b8b0a3733323a6ae59a1231c8a2e806fd4a5 100644 (file)
@@ -31,6 +31,7 @@ dof_test.exe                 : dof_test.go                           $(lib-2d) $
 dof_renumbering.exe          : dof_renumbering.go          $(lib-1d) $(lib-2d) $(lib-3d) $(libraries)
 error_estimator.exe          : error_estimator.go          $(lib-1d) $(lib-2d) $(lib-3d) $(libraries)
 gradients.exe                : gradients.go                          $(lib-2d)           $(libraries)
+grid_out.exe                 : grid_out.go                 $(lib-1d) $(lib-2d) $(lib-3d) $(libraries)
 grid_test.exe                : grid_test.go                          $(lib-2d) $(lib-3d) $(libraries)
 grid_transform.exe           : grid_transform.go                     $(lib-2d) $(lib-3d) $(libraries)
 intergrid_constraints.exe    : intergrid_constraints.go    $(lib-1d) $(lib-2d) $(lib-3d) $(libraries)
@@ -54,7 +55,7 @@ tests = grid_test grid_transform dof_test data_out derivatives gradients \
         matrices error_estimator intergrid_constraints intergrid_map \
         wave-test-3 dof_renumbering support_point_map filtered_matrix \
        boundaries sparsity_pattern grid_tools subdomain_ids \
-       filtered_iterator
+       filtered_iterator grid_out
 
 ############################################################
 
diff --git a/tests/deal.II/grid_out.cc b/tests/deal.II/grid_out.cc
new file mode 100644 (file)
index 0000000..ddaeef8
--- /dev/null
@@ -0,0 +1,60 @@
+//----------------------------  constraints.cc  ---------------------------
+//    $Id$
+//    Version: $Name$
+//
+//    Copyright (C) 2002 by the deal.II authors
+//
+//    This file is subject to QPL and may not be  distributed
+//    without copyright and license information. Please refer
+//    to the file deal.II/doc/license.html for the  text  and
+//    further information on this license.
+//
+//----------------------------  constraints.cc  ---------------------------
+
+
+#include <dofs/dof_handler.h>
+#include <grid/tria.h>
+#include <grid/tria_boundary.h>
+#include <grid/tria_boundary_lib.h>
+#include <grid/grid_out.h>
+#include <grid/grid_generator.h>
+#include <base/logstream.h>
+
+#include <fstream>
+
+
+std::ofstream logfile("grid_out.output");
+
+
+template <int dim>
+void test ()
+{  
+  Triangulation<dim> tria;
+  if (dim == 2)
+    {
+      static const HyperBallBoundary<dim> x;
+      tria.set_boundary (0, x);
+      GridGenerator::hyper_ball (tria);
+    }
+  else
+    GridGenerator::hyper_cube (tria);
+  tria.refine_global(1);
+  
+  GridOut grid_out;
+  GridOutFlags::Eps<2> eps2(GridOutFlags::EpsFlagsBase::width,
+                           300, .5, false, 5, true);
+  grid_out.set_flags (eps2);
+  std::ofstream x("x.eps");
+  grid_out.write_eps (tria, x);
+};
+
+
+int main ()
+{
+  logfile.precision (2);
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+
+  test<2> ();
+};
+

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.