From c07b87a95e0c670c18033b650f631dbe7e6ca786 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Thu, 9 Apr 1998 09:23:06 +0000 Subject: [PATCH] Add support to write material ids and boundary indicators. git-svn-id: https://svn.dealii.org/trunk@164 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/deal.II/include/numerics/data_io.h | 48 ++++++++++++ deal.II/deal.II/source/numerics/data_io.cc | 86 +++++++++++++++++++--- 2 files changed, 125 insertions(+), 9 deletions(-) diff --git a/deal.II/deal.II/include/numerics/data_io.h b/deal.II/deal.II/include/numerics/data_io.h index 5900fe744e..1a31d95efc 100644 --- a/deal.II/deal.II/include/numerics/data_io.h +++ b/deal.II/deal.II/include/numerics/data_io.h @@ -437,6 +437,54 @@ class DataOut { * List of data elements. */ vector data; + + + /** + * Return the number of faces in the + * triangulation which have a boundary + * indicator not equal to zero. Only + * these faces are explicitely printed + * in the #write_*# functions; + * all faces with indicator 255 are + * interior ones and an indicator with + * value zero for faces at the boundary + * are considered default. + * + * This function always returns an empty + * list in one dimension. + * + * The reason for this function is the + * same as for #write_ucd_faces#. See + * there for more information. + */ + unsigned int n_boundary_faces () const; + + /** + * Write the grid information about + * faces to #out#. Only those faces + * are 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 #starting_index# for + * the numbering of the faces is passed + * also. + * + * This function unfortunately can not + * be included in the regular #write_ucd# + * function, since it needs special + * treatment for the case #dim==1#, in + * which case the face iterators are + * #void*#'s and lack the member functions + * which are called. We would not actually + * call these functions, but the compiler + * would complain anyway when compiling + * the function for #dim==1#. Bad luck. + */ + void write_ucd_faces (ostream &out, + const unsigned int starting_index) const; }; diff --git a/deal.II/deal.II/source/numerics/data_io.cc b/deal.II/deal.II/source/numerics/data_io.cc index f56716c4a5..bd57400312 100644 --- a/deal.II/deal.II/source/numerics/data_io.cc +++ b/deal.II/deal.II/source/numerics/data_io.cc @@ -231,7 +231,7 @@ void DataOut::write_ucd (ostream &out) const { DoFHandler::active_cell_iterator cell, endc = dofs->end(); unsigned int n_vertex_dofs; - + // first loop over all cells to // find out how many degrees of // freedom there are located on @@ -275,7 +275,7 @@ void DataOut::write_ucd (ostream &out) const { // start with ucd data out << n_vertex_dofs << ' ' - << dofs->get_tria().n_active_cells() << ' ' + << dofs->get_tria().n_active_cells() + n_boundary_faces() << ' ' << data.size() << ' ' << 0 << ' ' // no cell data << 0 // no model data @@ -309,21 +309,26 @@ void DataOut::write_ucd (ostream &out) const { // we do not use cell data) if (true) { - unsigned int c; - for (cell=dofs->begin_active(), c=0; cell!=endc; ++cell, ++c) + unsigned int index; + for (cell=dofs->begin_active(), index=0; cell!=endc; ++cell, ++index) { - out << c << ' ' - << 1 << " "; // material id (unused) + out << index << ' ' + << static_cast(cell->material_id()) + << " "; switch (dim) { - case 1: out << "line "; break; - case 2: out << "quad "; break; - case 3: out << "hex "; break; + case 1: out << "line "; break; + case 2: out << "quad "; break; + case 3: out << "hex "; break; + default: + Assert (false, ExcNotImplemented()); }; for (unsigned int vertex=0; vertex<(1<vertex_dof_index(vertex,0) << ' '; out << endl; }; + + write_ucd_faces (out, index); }; // if data given: write data, else @@ -354,6 +359,69 @@ void DataOut::write_ucd (ostream &out) const { +template <> +unsigned int DataOut<1>::n_boundary_faces () const { + return 0; +}; + + + +template +unsigned int DataOut::n_boundary_faces () const { + typename DoFHandler::active_face_iterator face, endf; + unsigned long int n_faces = 0; + + for (face=dofs->begin_active_face(), endf=dofs->end_face(); + face != endf; ++face) + if ((face->boundary_indicator() != 0) && + (face->boundary_indicator() != 255)) + n_faces++; + + return n_faces; +}; + + + +template <> +void DataOut<1>::write_ucd_faces (ostream &, const unsigned int) const { + return; +}; + + + +template +void DataOut::write_ucd_faces (ostream &out, + const unsigned int starting_index) const { + typename DoFHandler::active_face_iterator face, endf; + unsigned int index=starting_index; + + for (face=dofs->begin_active_face(), endf=dofs->end_face(); + face != endf; ++face) + if ((face->boundary_indicator() != 0) && + (face->boundary_indicator() != 255)) + { + out << index << " " + << static_cast(face->boundary_indicator()) + << " "; + switch (dim) + { + case 2: out << "line "; break; + case 3: out << "quad "; break; + default: + Assert (false, ExcNotImplemented()); + }; + for (unsigned int vertex=0; vertex<(1<<(dim-1)); ++vertex) + out << face->vertex_dof_index(vertex,0) << ' '; + out << endl; + + ++index; + }; +}; + + + + + template void DataOut::write_gnuplot (ostream &out) const { Assert (dofs != 0, ExcNoDoFHandlerSelected()); -- 2.39.5