From 4989e08b2947be26ef27788a8c1e9f134091f536 Mon Sep 17 00:00:00 2001 From: wolf Date: Mon, 15 Mar 1999 12:58:35 +0000 Subject: [PATCH] Add support for cell data. git-svn-id: https://svn.dealii.org/trunk@1010 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/deal.II/include/numerics/data_io.h | 42 +++-- deal.II/deal.II/source/numerics/data_io.cc | 178 ++++++++++++++------- 2 files changed, 151 insertions(+), 69 deletions(-) diff --git a/deal.II/deal.II/include/numerics/data_io.h b/deal.II/deal.II/include/numerics/data_io.h index ea3a1ceed9..e0e9c1dff7 100644 --- a/deal.II/deal.II/include/numerics/data_io.h +++ b/deal.II/deal.II/include/numerics/data_io.h @@ -189,7 +189,8 @@ class DataIn { * This class implements an output mechanism for grid and simulation data * in several formats. * At present it supports output in UCD (unstructured cell data) and - * partly in GNUPLOT format. + * GNUPLOT format. Partly supported are POVRAY and encapsulated postscript. + * The latter two allow for only one data set and do not support cell data. * * It allows the user to attach a degree of freedom handler object * (#DoFHandler#) which also gives access to the geometry data of the @@ -211,8 +212,9 @@ class DataIn { * limitations in the present format, only node based data can be output, * so higher order elements are only written with their node values, no * interior or line values are used. No use is made of the possibility - * to give cell and model data since these are not supported by all - * UCD aware programs. + * to give model data since these are not supported by all + * UCD aware programs. You may give cell data, but that is not supported by + * all programs. * * The ASCII UCD format is used. In future versions, a binary version may * follow up. @@ -343,9 +345,12 @@ class DataOut { * * It is assumed that the vector has the * same number of components as there are - * degrees of freedom in the dof handler. - * Therefore, no block vectors are allowed - * at present. + * degrees of freedom in the dof handler, + * in which case it is assumed to be a + * vector storing nodal data; or the size + * may be the number of active cells on + * the present grid, in which case it is + * assumed to be a cell data vector. * * The name and unit of a data vector shall * only contain characters which are @@ -396,18 +401,21 @@ class DataOut { /** * Write data of first vector and grid - * in POVRAY format. + * in POVRAY format. Further data vectors + * as well as cell data is ignored. */ void write_povray_mesh (ostream &out) const; /** * Write data of first vector and grid in * Encapsulated postscript format. + * Further data vectors + * as well as cell data is ignored. */ void write_eps (ostream &out) const; /** - *Write grid in Encapsulated + * Write grid in Encapsulated * postscript format. */ void write_epsgrid (ostream &out) const; @@ -488,11 +496,12 @@ class DataOut { /** * Exception */ - DeclException2 (ExcInvalidVectorSize, - int, int, + DeclException3 (ExcInvalidVectorSize, + int, int, int, << "The vector has size " << arg1 << " but the DoFHandler objects says there are " << arg2 - << " degrees of freedom."); + << " degrees of freedom and there are " << arg3 + << " active cells."); /** * Exception */ @@ -552,9 +561,16 @@ class DataOut { const DoFHandler *dofs; /** - * List of data elements. + * List of data elements with vectors of + * values for each degree of freedom. + */ + vector dof_data; + + /** + * List of data elements with vectors of + * values for each cell. */ - vector data; + vector cell_data; /** diff --git a/deal.II/deal.II/source/numerics/data_io.cc b/deal.II/deal.II/source/numerics/data_io.cc index 02f359eccb..e286f45a1c 100644 --- a/deal.II/deal.II/source/numerics/data_io.cc +++ b/deal.II/deal.II/source/numerics/data_io.cc @@ -207,8 +207,6 @@ void DataOut::add_data_vector (const Vector &vec, const string &name, const string &units) { Assert (dofs != 0, ExcNoDoFHandlerSelected ()); - Assert (vec.size() == dofs->n_dofs(), - ExcInvalidVectorSize (vec.size(), dofs->n_dofs())); Assert (name.find_first_not_of("abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "0123456789_<>()") == string::npos, @@ -219,14 +217,24 @@ void DataOut::add_data_vector (const Vector &vec, ExcInvalidCharacter (units)); DataEntry new_entry (&vec, name, units); - data.push_back (new_entry); + if (vec.size() == dofs->n_dofs()) + dof_data.push_back (new_entry); + else + if (vec.size() == dofs->get_tria().n_active_cells()) + cell_data.push_back (new_entry); + else + Assert (false, + ExcInvalidVectorSize (vec.size(), + dofs->n_dofs(), + dofs->get_tria().n_active_cells())); }; template void DataOut::clear_data_vectors () { - data.erase (data.begin(), data.end()); + dof_data.erase (dof_data.begin(), dof_data.end()); + cell_data.erase (cell_data.begin(), cell_data.end()); }; @@ -291,8 +299,8 @@ void DataOut::write_ucd (ostream &out) const { // start with ucd data out << n_vertex_dofs << ' ' << dofs->get_tria().n_active_cells() + n_boundary_faces() << ' ' - << data.size() << ' ' - << 0 << ' ' // no cell data + << dof_data.size() << ' ' + << cell_data.size() << ' ' << 0 // no model data << endl; @@ -364,16 +372,16 @@ void DataOut::write_ucd (ostream &out) const { // if data given: write data, else // only write grid - if (data.size() != 0) + if (dof_data.size() != 0) { - out << data.size() << " "; // number of vectors - for (unsigned int i=0; i!=data.size(); ++i) + out << dof_data.size() << " "; // number of vectors + for (unsigned int i=0; i!=dof_data.size(); ++i) out << 1 << ' '; // number of components; // only 1 supported presently out << endl; - for (unsigned int i=0; i::write_ucd (ostream &out) const { { out << cell->vertex_dof_index(vertex,0) // vertex index << " "; - for (unsigned int i=0; i!=data.size(); ++i) - out << (*data[i].data)(cell->vertex_dof_index(vertex,0)) << ' '; + for (unsigned int i=0; i!=dof_data.size(); ++i) + out << (*dof_data[i].data)(cell->vertex_dof_index(vertex,0)) << ' '; out << endl; already_written[cell->vertex_dof_index(vertex,0)] = true; }; }; - // no cell data + + if (cell_data.size() != 0) + { + out << cell_data.size() << " "; // number of vectors + for (unsigned int i=0; i!=cell_data.size(); ++i) + out << 1 << ' '; // number of components; + // only 1 supported presently + out << endl; + + for (unsigned int i=0; ibegin_active(), index=0; cell!=endc; ++cell, ++index) + { + out << index << " "; + for (unsigned int i=0; i!=cell_data.size(); ++i) + out << (*cell_data[i].data)(index) << ' '; + out << endl; + }; + }; + // no model data // assert the stream is still ok @@ -527,9 +556,13 @@ void DataOut::write_gnuplot (ostream &out, unsigned int accuracy) const default: Assert (false, ExcNotImplemented()); }; - for (unsigned int i=0; i!=data.size(); ++i) + for (unsigned int i=0; i!=dof_data.size(); ++i) + out << '<' + << dof_data[i].name << ':' << dof_data[i].units + << "> "; + for (unsigned int i=0; i!=cell_data.size(); ++i) out << '<' - << data[i].name << ':' << data[i].units + << cell_data[i].name << ':' << cell_data[i].units << "> "; out << endl; @@ -544,20 +577,18 @@ void DataOut::write_gnuplot (ostream &out, unsigned int accuracy) const FEValues fe(dofs->get_fe(), points, UpdateFlags(update_q_points)); const StraightBoundary boundary; vector< vector > > - values (data.size(), + values (dof_data.size(), vector< Vector >(points.n_quadrature_points, Vector(dofs->get_fe().n_components ))); - for (cell=dofs->begin_active(); cell!=endc; ++cell) + unsigned int cell_index=0; + for (cell=dofs->begin_active(); cell!=endc; ++cell, ++cell_index) { fe.reinit(cell, boundary); - for (unsigned i=0; i::write_gnuplot (ostream &out, unsigned int accuracy) const { Point pt = fe.quadrature_point(supp_pt); out << pt << " "; - for (unsigned int i=0; i!=data.size(); ++i) + for (unsigned int i=0; i!=dof_data.size(); ++i) for (unsigned int j=0; j < dofs->get_fe().n_components; ++j) out << values[i][supp_pt](j) << ' '; + for (unsigned int i=0; i::write_gnuplot (ostream &out, unsigned int accuracy) const Point pt = fe.quadrature_point(supp_pt); out << pt << " "; - for (unsigned int i=0; i!=data.size(); ++i) + for (unsigned int i=0; i!=dof_data.size(); ++i) for (unsigned int j=0; j < dofs->get_fe().n_components; ++j) out << values[i][supp_pt](j) << ' '; + for (unsigned int i=0; i::write_gnuplot (ostream &out, unsigned int accuracy) const Point pt = fe.quadrature_point(supp_pt); out << pt << " "; - for (unsigned int i=0; i!=data.size(); ++i) + for (unsigned int i=0; i!=dof_data.size(); ++i) for (unsigned int j=0; j < dofs->get_fe().n_components; ++j) out << values[i][supp_pt](j) << ' '; + for (unsigned int i=0; i::write_gnuplot_draft (ostream &out) const default: Assert (false, ExcNotImplemented()); }; - for (unsigned int i=0; i!=data.size(); ++i) + for (unsigned int i=0; i!=dof_data.size(); ++i) out << '<' - << data[i].name << ':' << data[i].units + << dof_data[i].name << ':' << dof_data[i].units << "> "; out << endl; @@ -709,7 +750,8 @@ void DataOut::write_gnuplot_draft (ostream &out) const DoFHandler::active_cell_iterator cell; DoFHandler::active_cell_iterator endc = dofs->end(); - for (cell=dofs->begin_active(); cell!=endc; ++cell) + unsigned int cell_index=0; + for (cell=dofs->begin_active(); cell!=endc; ++cell, ++cell_index) { switch (dim) { @@ -721,8 +763,11 @@ void DataOut::write_gnuplot_draft (ostream &out) const { out << cell->vertex(vertex) << " "; - for (unsigned int i=0; i!=data.size(); ++i) - out << (*data[i].data)(cell->vertex_dof_index(vertex,0)) + for (unsigned int i=0; i!=dof_data.size(); ++i) + out << (*dof_data[i].data)(cell->vertex_dof_index(vertex,0)) + << ' '; + for (unsigned int i=0; i::write_gnuplot_draft (ostream &out) const for (unsigned int vertex=0; vertex<4; ++vertex) { out << cell->vertex(vertex) << " "; - for (unsigned int i=0; i!=data.size(); ++i) - out << (*data[i].data)(cell->vertex_dof_index(vertex,0)) + for (unsigned int i=0; i!=dof_data.size(); ++i) + out << (*dof_data[i].data)(cell->vertex_dof_index(vertex,0)) + << ' '; + for (unsigned int i=0; ivertex(0) << " "; - for (unsigned int i=0; i!=data.size(); ++i) - out << (*data[i].data)(cell->vertex_dof_index(0,0)) + for (unsigned int i=0; i!=dof_data.size(); ++i) + out << (*dof_data[i].data)(cell->vertex_dof_index(0,0)) + << ' '; + for (unsigned int i=0; i::write_gnuplot_draft (ostream &out) const for (unsigned int vertex=0; vertex<4; ++vertex) { out << cell->vertex(vertex) << " "; - for (unsigned int i=0; i!=data.size(); ++i) - out << (*data[i].data)(cell->vertex_dof_index(vertex,0)) + for (unsigned int i=0; i!=dof_data.size(); ++i) + out << (*dof_data[i].data)(cell->vertex_dof_index(vertex,0)) + << ' '; + for (unsigned int i=0; ivertex(0) << " "; - for (unsigned int i=0; i!=data.size(); ++i) - out << (*data[i].data)(cell->vertex_dof_index(0,0)) + for (unsigned int i=0; i!=dof_data.size(); ++i) + out << (*dof_data[i].data)(cell->vertex_dof_index(0,0)) + << ' '; + for (unsigned int i=0; i::write_gnuplot_draft (ostream &out) const for (unsigned int vertex=4; vertex<8; ++vertex) { out << cell->vertex(vertex) << " "; - for (unsigned int i=0; i!=data.size(); ++i) - out << (*data[i].data)(cell->vertex_dof_index(vertex,0)) + for (unsigned int i=0; i!=dof_data.size(); ++i) + out << (*dof_data[i].data)(cell->vertex_dof_index(vertex,0)) + << ' '; + for (unsigned int i=0; ivertex(4) << " "; - for (unsigned int i=0; i!=data.size(); ++i) - out << (*data[i].data)(cell->vertex_dof_index(4,0)) + for (unsigned int i=0; i!=dof_data.size(); ++i) + out << (*dof_data[i].data)(cell->vertex_dof_index(4,0)) + << ' '; + for (unsigned int i=0; i::write_gnuplot_draft (ostream &out) const = { 0, 4, 7, 3, 2, 6, 5, 1 }; out << cell->vertex(vertex_list[vertex]) << " "; - for (unsigned int i=0; i!=data.size(); ++i) - out << (*data[i].data)(cell->vertex_dof_index(vertex_list[vertex],0)) + for (unsigned int i=0; i!=dof_data.size(); ++i) + out << (*dof_data[i].data)(cell->vertex_dof_index(vertex_list[vertex],0)) + << ' '; + for (unsigned int i=0; i::write_povray_mesh (ostream &out) const { // y and z coordinates are switched out << " triangle { "; out << '<' << cell->vertex(0)(0) << ',' - << (*data[0].data)(cell->vertex_dof_index(0,0)) << ',' + << (*dof_data[0].data)(cell->vertex_dof_index(0,0)) << ',' << cell->vertex(0)(1) << '>' << ", " << '<' << cell->vertex(1)(0) << ',' - << (*data[0].data)(cell->vertex_dof_index(1,0)) << ',' + << (*dof_data[0].data)(cell->vertex_dof_index(1,0)) << ',' << cell->vertex(1)(1) << '>' << ", " << '<' << cell->vertex(2)(0) << ',' - << (*data[0].data)(cell->vertex_dof_index(2,0)) << ',' + << (*dof_data[0].data)(cell->vertex_dof_index(2,0)) << ',' << cell->vertex(2)(1) << '>' << endl << " texture { default_texture }" << endl @@ -914,15 +980,15 @@ void DataOut<2>::write_povray_mesh (ostream &out) const { << endl; out << " triangle { "; out << '<' << cell->vertex(0)(0) << ',' - << (*data[0].data)(cell->vertex_dof_index(0,0)) << ',' + << (*dof_data[0].data)(cell->vertex_dof_index(0,0)) << ',' << cell->vertex(0)(1) << '>' << ", " << '<' << cell->vertex(2)(0) << ',' - << (*data[0].data)(cell->vertex_dof_index(2,0)) << ',' + << (*dof_data[0].data)(cell->vertex_dof_index(2,0)) << ',' << cell->vertex(2)(1) << '>' << ", " << '<' << cell->vertex(3)(0) << ',' - << (*data[0].data)(cell->vertex_dof_index(3,0)) << ',' + << (*dof_data[0].data)(cell->vertex_dof_index(3,0)) << ',' << cell->vertex(3)(1) << '>' << endl << " texture { default_texture }" << endl @@ -1063,7 +1129,7 @@ void DataOut<2>::write_eps (ostream &out) const { { x=cell->vertex(i)(0); y=cell->vertex(i)(1); - z=(*data[0].data)(cell->vertex_dof_index(i,0)); + z=(*dof_data[0].data)(cell->vertex_dof_index(i,0)); xmin = ( x < xmin ? x : xmin ); xmax = ( x > xmax ? x : xmax ); ymin = ( y < ymin ? y : ymin ); @@ -1083,10 +1149,10 @@ void DataOut<2>::write_eps (ostream &out) const { for (cell=dofs->begin_active(); cell!=endc; ++cell) { - cx[0]=cell->vertex(0)(0); cy[0]=cell->vertex(0)(1); cz[0]=(*data[0].data)(cell->vertex_dof_index(0,0))*zscale; - cx[1]=cell->vertex(1)(0); cy[1]=cell->vertex(1)(1); cz[1]=(*data[0].data)(cell->vertex_dof_index(1,0))*zscale;; - cx[2]=cell->vertex(2)(0); cy[2]=cell->vertex(2)(1); cz[2]=(*data[0].data)(cell->vertex_dof_index(2,0))*zscale;; - cx[3]=cell->vertex(3)(0); cy[3]=cell->vertex(3)(1); cz[3]=(*data[0].data)(cell->vertex_dof_index(3,0))*zscale;; + cx[0]=cell->vertex(0)(0); cy[0]=cell->vertex(0)(1); cz[0]=(*dof_data[0].data)(cell->vertex_dof_index(0,0))*zscale; + cx[1]=cell->vertex(1)(0); cy[1]=cell->vertex(1)(1); cz[1]=(*dof_data[0].data)(cell->vertex_dof_index(1,0))*zscale;; + cx[2]=cell->vertex(2)(0); cy[2]=cell->vertex(2)(1); cz[2]=(*dof_data[0].data)(cell->vertex_dof_index(2,0))*zscale;; + cx[3]=cell->vertex(3)(0); cy[3]=cell->vertex(3)(1); cz[3]=(*dof_data[0].data)(cell->vertex_dof_index(3,0))*zscale;; // Turn and scale -- 2.39.5