From 7d092677f5162d3a321a1a4e4053780d60f80921 Mon Sep 17 00:00:00 2001 From: David Wells Date: Sun, 17 Jan 2016 18:56:17 -0500 Subject: [PATCH] Also assign unique numbers to UCD elements. Same as the previous commit. Closes #814. --- include/deal.II/grid/grid_out.h | 102 +++++---- source/grid/grid_out.cc | 115 +++++----- tests/grid/grid_out_03.output | 2 +- tests/grid/grid_out_05.output | 2 +- tests/grid/grid_output_input.output | 320 ++++++++++++++-------------- 5 files changed, 291 insertions(+), 250 deletions(-) diff --git a/include/deal.II/grid/grid_out.h b/include/deal.II/grid/grid_out.h index 79a6648965..57bbb61e84 100644 --- a/include/deal.II/grid/grid_out.h +++ b/include/deal.II/grid/grid_out.h @@ -1422,8 +1422,18 @@ private: * printed which are on the boundary and which have a boundary indicator not * equal to zero, since the latter is the default for boundary faces. * - * Since cells and faces are continuously numbered, the @p starting_index - * for the numbering of the faces is passed also. + * Since (in the UCD format) geometric elements are continuously numbered, + * this function requires a parameter @p next_element_index providing the + * next geometric element number. This index should have a numerical value + * equal to one more than the index previously used to write a geometric + * element to @p out. + * + * @returns The next unused geometric element index. + * + * @warning @p next_element_index should be (at least) one larger than the + * current number of triangulation elements (lines, cells, faces) that have + * been written to @p out. Visualization programs may not load the saved + * file correctly if there are repeated indices. * * This function unfortunately can not be included in the regular @p * write_ucd function, since it needs special treatment for the case @@ -1432,30 +1442,32 @@ private: * call these functions, but the compiler would complain anyway when * compiling the function for dim==1. Bad luck. */ - - template - void write_ucd_faces (const Triangulation &tria, - const unsigned int starting_index, - std::ostream &out) const; + unsigned int + write_ucd_faces (const Triangulation &tria, + const unsigned int next_element_index, + std::ostream &out) const; /** * Declaration of the specialization of above function for 1d. Does nothing. */ - void write_ucd_faces (const Triangulation<1,1> &tria, - const unsigned int starting_index, - std::ostream &out) const; + unsigned int + write_ucd_faces (const Triangulation<1,1> &tria, + const unsigned int next_element_index, + std::ostream &out) const; /** * Declaration of the specialization of above function for 1d, 2sd. Does * nothing. */ - void write_ucd_faces (const Triangulation<1,2> &tria, - const unsigned int starting_index, - std::ostream &out) const; - void write_ucd_faces (const Triangulation<1,3> &tria, - const unsigned int starting_index, - std::ostream &out) const; + unsigned int + write_ucd_faces (const Triangulation<1,2> &tria, + const unsigned int next_element_index, + std::ostream &out) const; + unsigned int + write_ucd_faces (const Triangulation<1,3> &tria, + const unsigned int next_element_index, + std::ostream &out) const; /** @@ -1463,8 +1475,18 @@ private: * printed which are on the boundary and which have a boundary indicator not * equal to zero, since the latter is the default for boundary lines. * - * Since cells, faces and lines are continuously numbered, the @p - * starting_index for the numbering of the faces is passed also. + * Since (in the UCD format) geometric elements are continuously numbered, + * this function requires a parameter @p next_element_index providing the + * next geometric element number. This index should have a numerical value + * equal to one more than the index previously used to write a geometric + * element to @p out. + * + * @returns The next unused geometric element index. + * + * @warning @p next_element_index should be (at least) one larger than the + * current number of triangulation elements (lines, cells, faces) that have + * been written to @p out. Visualization programs may not load the saved + * file correctly if there are repeated indices. * * This function unfortunately can not be included in the regular @p * write_ucd function, since it needs special treatment for the case @@ -1473,44 +1495,48 @@ private: * call these functions, but the compiler would complain anyway when * compiling the function for dim==1/2. Bad luck. */ - - template - void write_ucd_lines (const Triangulation &tria, - const unsigned int starting_index, - std::ostream &out) const; + unsigned int + write_ucd_lines (const Triangulation &tria, + const unsigned int next_element_index, + std::ostream &out) const; /** * Declaration of the specialization of above function for 1d. Does nothing. */ - void write_ucd_lines (const Triangulation<1,1> &tria, - const unsigned int starting_index, - std::ostream &out) const; + unsigned int + write_ucd_lines (const Triangulation<1,1> &tria, + const unsigned int next_element_index, + std::ostream &out) const; /** * Declaration of the specialization of above function for 1d, 2sd. Does * nothing. */ - void write_ucd_lines (const Triangulation<1,2> &tria, - const unsigned int starting_index, - std::ostream &out) const; - void write_ucd_lines (const Triangulation<1,3> &tria, - const unsigned int starting_index, - std::ostream &out) const; + unsigned int + write_ucd_lines (const Triangulation<1,2> &tria, + const unsigned int next_element_index, + std::ostream &out) const; + unsigned int + write_ucd_lines (const Triangulation<1,3> &tria, + const unsigned int next_element_index, + std::ostream &out) const; /** * Declaration of the specialization of above function for 2d. Does nothing. */ - void write_ucd_lines (const Triangulation<2,2> &tria, - const unsigned int starting_index, - std::ostream &out) const; + unsigned int + write_ucd_lines (const Triangulation<2,2> &tria, + const unsigned int next_element_index, + std::ostream &out) const; /** * Declaration of the specialization of above function for 2d, 3sd. Does * nothing. */ - void write_ucd_lines (const Triangulation<2,3> &tria, - const unsigned int starting_index, - std::ostream &out) const; + unsigned int + write_ucd_lines (const Triangulation<2,3> &tria, + const unsigned int next_element_index, + std::ostream &out) const; /** diff --git a/source/grid/grid_out.cc b/source/grid/grid_out.cc index 280558767e..8034377432 100644 --- a/source/grid/grid_out.cc +++ b/source/grid/grid_out.cc @@ -1190,13 +1190,16 @@ void GridOut::write_ucd (const Triangulation &tria, out << '\n'; } - // write faces and lines with - // non-zero boundary indicator - unsigned int next_index = tria.n_active_cells()+1; + // write faces and lines with non-zero boundary indicator + unsigned int next_element_index = tria.n_active_cells()+1; if (ucd_flags.write_faces) - write_ucd_faces (tria, next_index, out); + { + next_element_index = write_ucd_faces (tria, next_element_index, out); + } if (ucd_flags.write_lines) - write_ucd_lines (tria, next_index, out); + { + next_element_index = write_ucd_lines (tria, next_element_index, out); + } // make sure everything now gets to // disk @@ -2764,7 +2767,7 @@ GridOut::write_msh_lines (const Triangulation &tria, && (cell->line(l)->user_flag_set() == false)) { - out << current_element_index << " 1 "; + out << next_element_index << " 1 "; out << static_cast(cell->line(l)->boundary_id()) << ' ' << static_cast(cell->line(l)->boundary_id()) @@ -2793,80 +2796,89 @@ GridOut::write_msh_lines (const Triangulation &tria, -void GridOut::write_ucd_faces (const Triangulation<1> &, - const unsigned int, - std::ostream &) const +unsigned int +GridOut::write_ucd_faces (const Triangulation<1> &, + const unsigned int next_element_index, + std::ostream &) const { - return; + return next_element_index; } -void GridOut::write_ucd_faces (const Triangulation<1,2> &, - const unsigned int, - std::ostream &) const +unsigned int +GridOut::write_ucd_faces (const Triangulation<1,2> &, + const unsigned int next_element_index, + std::ostream &) const { - return; + return next_element_index; } -void GridOut::write_ucd_faces (const Triangulation<1,3> &, - const unsigned int, - std::ostream &) const +unsigned int +GridOut::write_ucd_faces (const Triangulation<1,3> &, + const unsigned int next_element_index, + std::ostream &) const { - return; + return next_element_index; } -void GridOut::write_ucd_lines (const Triangulation<1> &, - const unsigned int, - std::ostream &) const +unsigned int +GridOut::write_ucd_lines (const Triangulation<1> &, + const unsigned int next_element_index, + std::ostream &) const { - return; + return next_element_index; } -void GridOut::write_ucd_lines (const Triangulation<1,2> &, - const unsigned int, - std::ostream &) const +unsigned int +GridOut::write_ucd_lines (const Triangulation<1,2> &, + const unsigned int next_element_index, + std::ostream &) const { - return; + return next_element_index; } -void GridOut::write_ucd_lines (const Triangulation<1,3> &, - const unsigned int, - std::ostream &) const +unsigned int +GridOut::write_ucd_lines (const Triangulation<1,3> &, + const unsigned int next_element_index, + std::ostream &) const { - return; + return next_element_index; } -void GridOut::write_ucd_lines (const Triangulation<2> &, - const unsigned int, - std::ostream &) const +unsigned int +GridOut::write_ucd_lines (const Triangulation<2> &, + const unsigned int next_element_index, + std::ostream &) const { - return; + return next_element_index; } -void GridOut::write_ucd_lines (const Triangulation<2,3> &, - const unsigned int, - std::ostream &) const +unsigned int +GridOut::write_ucd_lines (const Triangulation<2,3> &, + const unsigned int next_element_index, + std::ostream &) const { - return; + return next_element_index; } template -void GridOut::write_ucd_faces (const Triangulation &tria, - const unsigned int starting_index, - std::ostream &out) const +unsigned int +GridOut::write_ucd_faces (const Triangulation &tria, + const unsigned int next_element_index, + std::ostream &out) const { + unsigned int current_element_index = next_element_index; typename Triangulation::active_face_iterator face, endf; - unsigned int index=starting_index; for (face=tria.begin_active_face(), endf=tria.end_face(); face != endf; ++face) if (face->at_boundary() && (face->boundary_id() != 0)) { - out << index << " " + out << current_element_index << " " << static_cast(face->boundary_id()) << " "; switch (dim) @@ -2885,17 +2897,20 @@ void GridOut::write_ucd_faces (const Triangulation &tria, out << face->vertex_index(GeometryInfo::ucd_to_deal[vertex])+1 << ' '; out << '\n'; - ++index; + ++current_element_index; } + return current_element_index; } template -void GridOut::write_ucd_lines (const Triangulation &tria, - const unsigned int starting_index, - std::ostream &out) const +unsigned int +GridOut::write_ucd_lines(const Triangulation &tria, + const unsigned int next_element_index, + std::ostream &out) const { + unsigned int current_element_index = next_element_index; // save the user flags for lines so // we can use these flags to track // which ones we've already taken @@ -2907,7 +2922,6 @@ void GridOut::write_ucd_lines (const Triangulation &tria, .clear_user_flags_line (); typename Triangulation::active_cell_iterator cell, endc; - unsigned int index=starting_index; for (cell=tria.begin_active(), endc=tria.end(); cell != endc; ++cell) @@ -2918,7 +2932,7 @@ void GridOut::write_ucd_lines (const Triangulation &tria, && (cell->line(l)->user_flag_set() == false)) { - out << index << " " + out << current_element_index << " " << static_cast(cell->line(l)->boundary_id()) << " line "; // note: vertex numbers in ucd format are 1-base @@ -2930,7 +2944,7 @@ void GridOut::write_ucd_lines (const Triangulation &tria, // move on to the next line // but mark the current one // as taken care of - ++index; + ++current_element_index; cell->line(l)->set_user_flag(); } @@ -2938,6 +2952,7 @@ void GridOut::write_ucd_lines (const Triangulation &tria, // flags for the lines const_cast&>(tria) .load_user_flags_line (line_flags); + return current_element_index; } diff --git a/tests/grid/grid_out_03.output b/tests/grid/grid_out_03.output index 53428aa5d2..c8d636be9f 100644 --- a/tests/grid/grid_out_03.output +++ b/tests/grid/grid_out_03.output @@ -18,4 +18,4 @@ 8 1.0 1.0 1.0 1 0 hex 1 2 6 5 3 4 8 7 2 2 quad 5 6 8 7 -2 1 line 1 3 +3 1 line 1 3 diff --git a/tests/grid/grid_out_05.output b/tests/grid/grid_out_05.output index 53428aa5d2..c8d636be9f 100644 --- a/tests/grid/grid_out_05.output +++ b/tests/grid/grid_out_05.output @@ -18,4 +18,4 @@ 8 1.0 1.0 1.0 1 0 hex 1 2 6 5 3 4 8 7 2 2 quad 5 6 8 7 -2 1 line 1 3 +3 1 line 1 3 diff --git a/tests/grid/grid_output_input.output b/tests/grid/grid_output_input.output index 4987eee082..e2e02c0aff 100644 --- a/tests/grid/grid_output_input.output +++ b/tests/grid/grid_output_input.output @@ -241,86 +241,86 @@ DEAL:3d::Writing refined from constructor 94 1 quad 96 25 81 136 95 1 quad 95 136 56 16 96 1 quad 136 81 9 56 -65 1 line 25 81 -66 1 line 82 129 -67 1 line 25 82 -68 1 line 81 129 -69 1 line 26 83 -70 1 line 82 26 -71 1 line 129 83 -72 1 line 81 9 -73 1 line 129 49 -74 1 line 9 49 -75 1 line 83 10 -76 1 line 49 10 -77 1 line 84 130 -78 1 line 26 84 -79 1 line 83 130 -80 1 line 27 85 -81 1 line 84 27 -82 1 line 130 85 -83 1 line 130 50 -84 1 line 10 50 -85 1 line 85 11 -86 1 line 50 11 -87 1 line 86 131 -88 1 line 27 86 -89 1 line 85 131 -90 1 line 28 87 -91 1 line 86 28 -92 1 line 131 87 -93 1 line 131 51 -94 1 line 11 51 -95 1 line 87 12 -96 1 line 51 12 -97 1 line 88 132 -98 1 line 28 88 -99 1 line 87 132 -100 1 line 29 89 -101 1 line 88 29 -102 1 line 132 89 -103 1 line 132 52 -104 1 line 12 52 -105 1 line 89 13 -106 1 line 52 13 -107 1 line 90 133 -108 1 line 29 90 -109 1 line 89 133 -110 1 line 30 91 -111 1 line 90 30 -112 1 line 133 91 -113 1 line 133 53 -114 1 line 13 53 -115 1 line 91 14 -116 1 line 53 14 -117 1 line 92 134 -118 1 line 30 92 -119 1 line 91 134 -120 1 line 31 93 -121 1 line 92 31 -122 1 line 134 93 -123 1 line 134 54 -124 1 line 14 54 -125 1 line 93 15 -126 1 line 54 15 -127 1 line 94 135 -128 1 line 31 94 -129 1 line 93 135 -130 1 line 32 95 -131 1 line 94 32 -132 1 line 135 95 -133 1 line 135 55 -134 1 line 15 55 -135 1 line 95 16 -136 1 line 55 16 -137 1 line 96 136 -138 1 line 32 96 -139 1 line 95 136 -140 1 line 96 25 -141 1 line 136 81 -142 1 line 136 56 -143 1 line 16 56 -144 1 line 56 9 +97 1 line 25 81 +98 1 line 82 129 +99 1 line 25 82 +100 1 line 81 129 +101 1 line 26 83 +102 1 line 82 26 +103 1 line 129 83 +104 1 line 81 9 +105 1 line 129 49 +106 1 line 9 49 +107 1 line 83 10 +108 1 line 49 10 +109 1 line 84 130 +110 1 line 26 84 +111 1 line 83 130 +112 1 line 27 85 +113 1 line 84 27 +114 1 line 130 85 +115 1 line 130 50 +116 1 line 10 50 +117 1 line 85 11 +118 1 line 50 11 +119 1 line 86 131 +120 1 line 27 86 +121 1 line 85 131 +122 1 line 28 87 +123 1 line 86 28 +124 1 line 131 87 +125 1 line 131 51 +126 1 line 11 51 +127 1 line 87 12 +128 1 line 51 12 +129 1 line 88 132 +130 1 line 28 88 +131 1 line 87 132 +132 1 line 29 89 +133 1 line 88 29 +134 1 line 132 89 +135 1 line 132 52 +136 1 line 12 52 +137 1 line 89 13 +138 1 line 52 13 +139 1 line 90 133 +140 1 line 29 90 +141 1 line 89 133 +142 1 line 30 91 +143 1 line 90 30 +144 1 line 133 91 +145 1 line 133 53 +146 1 line 13 53 +147 1 line 91 14 +148 1 line 53 14 +149 1 line 92 134 +150 1 line 30 92 +151 1 line 91 134 +152 1 line 31 93 +153 1 line 92 31 +154 1 line 134 93 +155 1 line 134 54 +156 1 line 14 54 +157 1 line 93 15 +158 1 line 54 15 +159 1 line 94 135 +160 1 line 31 94 +161 1 line 93 135 +162 1 line 32 95 +163 1 line 94 32 +164 1 line 135 95 +165 1 line 135 55 +166 1 line 15 55 +167 1 line 95 16 +168 1 line 55 16 +169 1 line 96 136 +170 1 line 32 96 +171 1 line 95 136 +172 1 line 96 25 +173 1 line 136 81 +174 1 line 136 56 +175 1 line 16 56 +176 1 line 56 9 DEAL:3d::Read coarse grid DEAL:3d::Writing refined from file 144 176 0 0 0 @@ -564,83 +564,83 @@ DEAL:3d::Writing refined from file 94 1 quad 96 25 81 136 95 1 quad 95 136 56 16 96 1 quad 136 81 9 56 -65 1 line 25 81 -66 1 line 82 129 -67 1 line 25 82 -68 1 line 81 129 -69 1 line 26 83 -70 1 line 82 26 -71 1 line 129 83 -72 1 line 81 9 -73 1 line 129 49 -74 1 line 9 49 -75 1 line 83 10 -76 1 line 49 10 -77 1 line 84 130 -78 1 line 26 84 -79 1 line 83 130 -80 1 line 27 85 -81 1 line 84 27 -82 1 line 130 85 -83 1 line 130 50 -84 1 line 10 50 -85 1 line 85 11 -86 1 line 50 11 -87 1 line 86 131 -88 1 line 27 86 -89 1 line 85 131 -90 1 line 28 87 -91 1 line 86 28 -92 1 line 131 87 -93 1 line 131 51 -94 1 line 11 51 -95 1 line 87 12 -96 1 line 51 12 -97 1 line 88 132 -98 1 line 28 88 -99 1 line 87 132 -100 1 line 29 89 -101 1 line 88 29 -102 1 line 132 89 -103 1 line 132 52 -104 1 line 12 52 -105 1 line 89 13 -106 1 line 52 13 -107 1 line 90 133 -108 1 line 29 90 -109 1 line 89 133 -110 1 line 30 91 -111 1 line 90 30 -112 1 line 133 91 -113 1 line 133 53 -114 1 line 13 53 -115 1 line 91 14 -116 1 line 53 14 -117 1 line 92 134 -118 1 line 30 92 -119 1 line 91 134 -120 1 line 31 93 -121 1 line 92 31 -122 1 line 134 93 -123 1 line 134 54 -124 1 line 14 54 -125 1 line 93 15 -126 1 line 54 15 -127 1 line 94 135 -128 1 line 31 94 -129 1 line 93 135 -130 1 line 32 95 -131 1 line 94 32 -132 1 line 135 95 -133 1 line 135 55 -134 1 line 15 55 -135 1 line 95 16 -136 1 line 55 16 -137 1 line 96 136 -138 1 line 32 96 -139 1 line 95 136 -140 1 line 96 25 -141 1 line 136 81 -142 1 line 136 56 -143 1 line 16 56 -144 1 line 56 9 +97 1 line 25 81 +98 1 line 82 129 +99 1 line 25 82 +100 1 line 81 129 +101 1 line 26 83 +102 1 line 82 26 +103 1 line 129 83 +104 1 line 81 9 +105 1 line 129 49 +106 1 line 9 49 +107 1 line 83 10 +108 1 line 49 10 +109 1 line 84 130 +110 1 line 26 84 +111 1 line 83 130 +112 1 line 27 85 +113 1 line 84 27 +114 1 line 130 85 +115 1 line 130 50 +116 1 line 10 50 +117 1 line 85 11 +118 1 line 50 11 +119 1 line 86 131 +120 1 line 27 86 +121 1 line 85 131 +122 1 line 28 87 +123 1 line 86 28 +124 1 line 131 87 +125 1 line 131 51 +126 1 line 11 51 +127 1 line 87 12 +128 1 line 51 12 +129 1 line 88 132 +130 1 line 28 88 +131 1 line 87 132 +132 1 line 29 89 +133 1 line 88 29 +134 1 line 132 89 +135 1 line 132 52 +136 1 line 12 52 +137 1 line 89 13 +138 1 line 52 13 +139 1 line 90 133 +140 1 line 29 90 +141 1 line 89 133 +142 1 line 30 91 +143 1 line 90 30 +144 1 line 133 91 +145 1 line 133 53 +146 1 line 13 53 +147 1 line 91 14 +148 1 line 53 14 +149 1 line 92 134 +150 1 line 30 92 +151 1 line 91 134 +152 1 line 31 93 +153 1 line 92 31 +154 1 line 134 93 +155 1 line 134 54 +156 1 line 14 54 +157 1 line 93 15 +158 1 line 54 15 +159 1 line 94 135 +160 1 line 31 94 +161 1 line 93 135 +162 1 line 32 95 +163 1 line 94 32 +164 1 line 135 95 +165 1 line 135 55 +166 1 line 15 55 +167 1 line 95 16 +168 1 line 55 16 +169 1 line 96 136 +170 1 line 32 96 +171 1 line 95 136 +172 1 line 96 25 +173 1 line 136 81 +174 1 line 136 56 +175 1 line 16 56 +176 1 line 56 9 -- 2.39.5