From 0bc0303383d65bb03ac7cd1b88d7cf4e5f5301b8 Mon Sep 17 00:00:00 2001 From: wolf Date: Wed, 5 Jun 2002 06:46:29 +0000 Subject: [PATCH] Add support for writing the numbers of cells to 2d eps grid output. Add testcase. git-svn-id: https://svn.dealii.org/trunk@5988 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/deal.II/include/grid/grid_out.h | 18 +++++- .../source/grid/grid_out.all_dimensions.cc | 6 +- deal.II/deal.II/source/grid/grid_out.cc | 45 ++++++++++++++ deal.II/doc/news/2002/c-3-4.html | 9 ++- tests/deal.II/Makefile | 3 +- tests/deal.II/grid_out.cc | 60 +++++++++++++++++++ 6 files changed, 134 insertions(+), 7 deletions(-) create mode 100644 tests/deal.II/grid_out.cc diff --git a/deal.II/deal.II/include/grid/grid_out.h b/deal.II/deal.II/include/grid/grid_out.h index f09832192b..f3b286b606 100644 --- a/deal.II/deal.II/include/grid/grid_out.h +++ b/deal.II/deal.II/include/grid/grid_out.h @@ -29,8 +29,6 @@ template 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); }; /** diff --git a/deal.II/deal.II/source/grid/grid_out.all_dimensions.cc b/deal.II/deal.II/source/grid/grid_out.all_dimensions.cc index b98eab480c..7e5840d275 100644 --- a/deal.II/deal.II/source/grid/grid_out.all_dimensions.cc +++ b/deal.II/deal.II/source/grid/grid_out.all_dimensions.cc @@ -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) {}; diff --git a/deal.II/deal.II/source/grid/grid_out.cc b/deal.II/deal.II/source/grid/grid_out.cc index 03d40a5f52..7f4fb29d03 100644 --- a/deal.II/deal.II/source/grid/grid_out.cc +++ b/deal.II/deal.II/source/grid/grid_out.cc @@ -1002,6 +1002,32 @@ void GridOut::write_eps (const Triangulation &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 &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::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()); diff --git a/deal.II/doc/news/2002/c-3-4.html b/deal.II/doc/news/2002/c-3-4.html index 3e56b7c08b..2053acb6ac 100644 --- a/deal.II/doc/news/2002/c-3-4.html +++ b/deal.II/doc/news/2002/c-3-4.html @@ -15,7 +15,7 @@

This is the list of changes made after the release of -deal.II version 3.3. It is subdivided into changes +deal.II version 3.4. It is subdivided into changes made to the three sub-libraries base, lac, and deal.II, as well as changes to the general infrastructure, @@ -57,6 +57,13 @@ contributor's names are abbreviated by WB (Wolfgang Bangerth), GK

deal.II

    +
  1. + New: For encapsulated postscript of 2d grids, it is now + possible to tell the GridOut to + write the cell numbers into each cell. +
    + (WB 2002/06/04) +


diff --git a/tests/deal.II/Makefile b/tests/deal.II/Makefile index cea682b769..4111b8b0a3 100644 --- a/tests/deal.II/Makefile +++ b/tests/deal.II/Makefile @@ -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 index 0000000000..ddaeef8840 --- /dev/null +++ b/tests/deal.II/grid_out.cc @@ -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 +#include +#include +#include +#include +#include +#include + +#include + + +std::ofstream logfile("grid_out.output"); + + +template +void test () +{ + Triangulation tria; + if (dim == 2) + { + static const HyperBallBoundary 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> (); +}; + -- 2.39.5