From: Guido Kanschat Date: Thu, 5 Jan 2006 10:09:15 +0000 (+0000) Subject: change implementation for binary dx output; binary output not tested yet X-Git-Tag: v8.0.0~12707 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7747aaa2b65ef7f71ae896a2e06e7c0a58eb1019;p=dealii.git change implementation for binary dx output; binary output not tested yet git-svn-id: https://svn.dealii.org/trunk@11952 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/base/include/base/data_out_base.h b/deal.II/base/include/base/data_out_base.h index 0ab096c09d..311e985345 100644 --- a/deal.II/base/include/base/data_out_base.h +++ b/deal.II/base/include/base/data_out_base.h @@ -2,7 +2,7 @@ // $Id$ // Version: $Name$ // -// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005 by the deal.II authors +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 by the deal.II authors // // This file is subject to QPL and may not be distributed // without copyright and license information. Please refer @@ -412,11 +412,52 @@ class DataOutBase * end at cell boundaries. */ bool write_neighbors; - + /** + * Write integer values of + * the Triangulation in + * binary format. + */ + bool int_binary; + /** + * Write coordinate vectors in + * binary format. + */ + bool coordinates_binary; + + /** + * Write data vectors in + * binary format. + */ + bool data_binary; + + /** + * Write binary integer + * values with 64 bit + * accuracy instead of 32. + */ + bool int_64; + + /** + * Write binary coordinate + * vectors as double (64 bit) + * numbers instead of float (32 bit). + */ + bool coordinates_double; + + /** + * Write binary coordinate + * vectors as double (64 bit) + * numbers instead of float (32 bit). + */ + bool data_double; + /** * Constructor. */ - DXFlags (const bool write_neighbors = false); + DXFlags (const bool write_neighbors = false, + const bool int_binary = false, + const bool coordinates_binary = false, + const bool data_binary = false); /** * Declare all flags with name @@ -1727,6 +1768,37 @@ class DataOutBase //@} private: + /** + * Write the coordinates of nodes + * in the desired format. + */ + template + static void write_dx_nodes (const std::vector >& patches, + const bool binary, + const bool double_precision, + std::ostream& out); + + /** + * Write the node numbers of a + * cell in the desired format. + */ + template + static void write_dx_cells (const std::vector >& patches, + const bool binary, + const bool int_64, + std::ostream& out); + + /** + * Write data in the desired + * format. + */ + template + static void write_dx_data (const std::vector >& patches, + const unsigned int n_data_sets, + const bool binary, + const bool double_precision, + std::ostream& out); + /** * Class holding the data of one * cell of a patch in two space diff --git a/deal.II/base/source/data_out_base.cc b/deal.II/base/source/data_out_base.cc index e8ddf277ce..3b811c78ba 100644 --- a/deal.II/base/source/data_out_base.cc +++ b/deal.II/base/source/data_out_base.cc @@ -2,7 +2,7 @@ // $Id$ // Version: $Name$ // -// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005 by the deal.II authors +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 by the deal.II authors // // This file is subject to QPL and may not be distributed // without copyright and license information. Please refer @@ -22,6 +22,7 @@ #include #include #include +#include #ifdef HAVE_STD_STRINGSTREAM # include @@ -134,9 +135,18 @@ DataOutBase::PovrayFlags::PovrayFlags (const bool smooth, {} -DataOutBase::DXFlags::DXFlags (const bool write_neighbors) +DataOutBase::DXFlags::DXFlags (const bool write_neighbors, + const bool int_binary, + const bool coordinates_binary, + const bool data_binary) : - write_neighbors(write_neighbors) + write_neighbors(write_neighbors), + int_binary(int_binary), + coordinates_binary(coordinates_binary), + data_binary(data_binary), + int_64(false), + coordinates_double(false), + data_double(false) {} @@ -147,6 +157,21 @@ void DataOutBase::DXFlags::declare_parameters (ParameterHandler &prm) "A boolean field indicating whether neighborship " "information between cells is to be written to the " "OpenDX output file"); + prm.declare_entry ("Integer format", "ascii", + Patterns::Selection("ascii|32|64"), + "Output format of integer numbers, which is " + "either a text representation (ascii) or binary integer " + "values of 32 or 64 bits length"); + prm.declare_entry ("Coordinates format", "ascii", + Patterns::Selection("ascii|32|64"), + "Output format of vertex coordinates, which is " + "either a text representation (ascii) or binary " + "floating point values of 32 or 64 bits length"); + prm.declare_entry ("Data format", "ascii", + Patterns::Selection("ascii|32|64"), + "Output format of data values, which is " + "either a text representation (ascii) or binary " + "floating point values of 32 or 64 bits length"); } @@ -154,6 +179,7 @@ void DataOutBase::DXFlags::declare_parameters (ParameterHandler &prm) void DataOutBase::DXFlags::parse_parameters (ParameterHandler &prm) { write_neighbors = prm.get_bool ("Write neighbors"); +//TODO:[GK] Read the new parameters } @@ -1102,6 +1128,371 @@ void DataOutBase::write_ucd (const std::vector > &patches, } +// Write a node in binary format, either with float or double numbers +template +void write_dx_node(const Point& node, + type* data, + std::ostream& out) +{ + for (unsigned int i=0; i(data), + spacedim * sizeof(*data)); +} + + +template +void +DataOutBase::write_dx_nodes ( + const std::vector >& patches, + const bool binary, + const bool double_precision, + std::ostream& out) +{ + for (typename std::vector >::const_iterator patch=patches.begin(); + patch!=patches.end(); ++patch) + { + const unsigned int n_subdivisions = patch->n_subdivisions; + + // if we have nonzero values for + // this coordinate + float floats[spacedim]; + double doubles[spacedim]; + switch (dim) + { + case 1: + for (unsigned int i=0; i + node = ((patch->vertices[1] * i / n_subdivisions) + + (patch->vertices[0] * (n_subdivisions-i) / n_subdivisions)); + + // write out coordinates + if (binary) + { + if (double_precision) + write_dx_node(node, doubles, out); + else + write_dx_node(node, floats, out); + } + else + { + for (unsigned int i=0; i + node = (((patch->vertices[1] * x_frac) + + (patch->vertices[0] * (1-x_frac))) * (1-y_frac) + + ((patch->vertices[2] * x_frac) + + (patch->vertices[3] * (1-x_frac))) * y_frac); + + // write out coordinates + if (binary) + { + if (double_precision) + write_dx_node(node, doubles, out); + else + write_dx_node(node, floats, out); + } + else + { + for (unsigned int i=0; i + node = ((((patch->vertices[1] * x_frac) + + (patch->vertices[0] * (1-x_frac))) * (1-y_frac) + + ((patch->vertices[2] * x_frac) + + (patch->vertices[3] * (1-x_frac))) * y_frac) * (1-z_frac) + + (((patch->vertices[5] * x_frac) + + (patch->vertices[4] * (1-x_frac))) * (1-y_frac) + + ((patch->vertices[6] * x_frac) + + (patch->vertices[7] * (1-x_frac))) * y_frac) * z_frac); + + // write out coordinates + if (binary) + { + if (double_precision) + write_dx_node(node, doubles, out); + else + write_dx_node(node, floats, out); + } + else + { + for (unsigned int i=0; i +inline +void +write_dx_cell (unsigned int dim, + data* nodes, + const bool binary, + std::ostream& out) +{ + if (binary) + out.write(reinterpret_cast(nodes), + (1< +void DataOutBase::write_dx_cells( + const std::vector >& patches, + const bool binary, + const bool int_64, + std::ostream& out) +{ + unsigned int first_vertex_of_patch = 0; + + // Array to hold all the node + // numbers of a cell. 8 is + // sufficient for 3D + unsigned int ints[8]; + unsigned long longs[8]; + + for (typename std::vector >::const_iterator patch=patches.begin(); + patch!=patches.end(); ++patch) + { + const unsigned int n_subdivisions = patch->n_subdivisions; + + // write out the cells making + // up this patch + switch (dim) + { + case 1: + for (unsigned int i=0; i +inline +void +write_dx_dataset(const std::vector& values, + const bool binary, + std::ostream& out) +{ + if (binary) + { + out.write(reinterpret_cast(&values[0]), + values.size()*sizeof(data)); + } + else + { + for (unsigned int i=0;i +void +DataOutBase::write_dx_data ( + const std::vector >& patches, + unsigned int n_data_sets, + const bool binary, + const bool double_precision, + std::ostream& out) +{ + Assert (dim<=3, ExcNotImplemented()); + + for (typename std::vector >::const_iterator patch + = patches.begin(); + patch != patches.end(); ++patch) + { + const unsigned int n_subdivisions = patch->n_subdivisions; + const unsigned int n = n_subdivisions+1; + + Assert (patch->data.n_rows() == n_data_sets, + ExcDimensionMismatch (patch->data.n_rows(), n_data_sets)); + Assert (patch->data.n_cols() == (dim==1 ? + n : + (dim==2 ? + n*n : + (dim==3 ? + n*n*n : + 0))), + ExcInvalidDatasetSize (patch->data.n_cols(), n)); + + std::vector floats(n_data_sets); + std::vector doubles(n_data_sets); + + const unsigned int n1 = (dim>0) ? n : 1; + const unsigned int n2 = (dim>1) ? n : 1; + const unsigned int n3 = (dim>2) ? n : 1; + + for (unsigned int i3=0; i3data(data_set,(i3*n+i2)*n+i1); + write_dx_dataset(doubles, binary, out); + } + else + { + for (unsigned int data_set=0; data_setdata(data_set,(i3*n+i2)*n+i1); + write_dx_dataset(floats, binary, out); + } + } + } +} + template void DataOutBase::write_dx (const std::vector > &patches, @@ -1113,6 +1504,10 @@ void DataOutBase::write_dx (const std::vector > &patches, Assert (patches.size() > 0, ExcNoPatches()); + // Variable counting the offset of + // binary data. + unsigned int offset = 0; + const unsigned int n_data_sets = data_names.size(); // first count the number of cells @@ -1148,198 +1543,47 @@ void DataOutBase::write_dx (const std::vector > &patches, // start with vertices order is // lexicographical, x varying // fastest - out << "object \"vertices\" class array type float rank 1 shape " << spacedim - << " items " << n_nodes << " data follows" << '\n'; + out << "object \"vertices\" class array type " + << ((flags.coordinates_double) ? "double" : "float") + << " rank 1 shape " << spacedim + << " items " << n_nodes; - /////////////////////////////// - // first write the coordinates of all vertices - if (true) + if (flags.coordinates_binary) { - for (typename std::vector >::const_iterator patch=patches.begin(); - patch!=patches.end(); ++patch) - { - const unsigned int n_subdivisions = patch->n_subdivisions; - - // if we have nonzero values for - // this coordinate - switch (dim) - { - case 1: - { - for (unsigned int i=0; i - node = ((patch->vertices[1] * i / n_subdivisions) + - (patch->vertices[0] * (n_subdivisions-i) / n_subdivisions)); - - // write out coordinates - for (unsigned int i=0; i - node = (((patch->vertices[1] * x_frac) + - (patch->vertices[0] * (1-x_frac))) * (1-y_frac) + - ((patch->vertices[2] * x_frac) + - (patch->vertices[3] * (1-x_frac))) * y_frac); - - // write out coordinates - for (unsigned int i=0; i - node = ((((patch->vertices[1] * x_frac) + - (patch->vertices[0] * (1-x_frac))) * (1-y_frac) + - ((patch->vertices[2] * x_frac) + - (patch->vertices[3] * (1-x_frac))) * y_frac) * (1-z_frac) + - (((patch->vertices[5] * x_frac) + - (patch->vertices[4] * (1-x_frac))) * (1-y_frac) + - ((patch->vertices[6] * x_frac) + - (patch->vertices[7] * (1-x_frac))) * y_frac) * z_frac); - - // write out coordinates - for (unsigned int i=0; i::vertices_per_cell - << " items " << n_cells << " data follows" - << '\n'; - - if (true) - { - unsigned int first_vertex_of_patch = 0; - - for (typename std::vector >::const_iterator patch=patches.begin(); - patch!=patches.end(); ++patch) - { - const unsigned int n_subdivisions = patch->n_subdivisions; - - // write out the cells making - // up this patch - switch (dim) - { - case 1: - if (true) - { - for (unsigned int i=0; i::vertices_per_cell + << " items " << n_cells; - - // finally update the number - // of the first vertex of this patch - switch (dim) - { - case 1: - first_vertex_of_patch += n_subdivisions+1; - break; - case 2: - first_vertex_of_patch += (n_subdivisions+1) * - (n_subdivisions+1); - break; - case 3: - first_vertex_of_patch += (n_subdivisions+1) * - (n_subdivisions+1) * - (n_subdivisions+1); - break; - default: - Assert (false, ExcNotImplemented()); - } - } - out << '\n'; + if (flags.int_binary) + { + out << " lsb binary data " << offset << '\n'; + offset += n_cells * (1< > &patches, { out << "object \"data\" class array type float rank 1 shape " << n_data_sets - << " items " << n_nodes << " data follows" << '\n'; + << " items " << n_nodes; - // loop over all patches - for (typename std::vector >::const_iterator patch=patches.begin(); - patch != patches.end(); ++patch) + if (flags.data_binary) { - const unsigned int n_subdivisions = patch->n_subdivisions; - - Assert (patch->data.n_rows() == n_data_sets, - ExcDimensionMismatch (patch->data.n_rows(), n_data_sets)); - Assert (patch->data.n_cols() == (dim==1 ? - n_subdivisions+1 : - (dim==2 ? - (n_subdivisions+1)*(n_subdivisions+1) : - (dim==3 ? - (n_subdivisions+1)*(n_subdivisions+1)*(n_subdivisions+1) : - 0))), - ExcInvalidDatasetSize (patch->data.n_cols(), n_subdivisions+1)); - - switch (dim) - { - case 1: - { - for (unsigned int i=0; idata(data_set,i) << '\t'; - out << '\n'; - } - - break; - } - - case 2: - { - for (unsigned int i=0; idata(data_set,i*(n_subdivisions+1) + j) << '\t'; - out << '\n'; - } - - break; - } - - case 3: - { - for (unsigned int i=0; idata(data_set, - (i*(n_subdivisions+1)+j)*(n_subdivisions+1)+k) - << '\t'; - out << '\n'; - } - - break; - } - - default: - Assert (false, ExcNotImplemented()); - } + out << " lsb ieee data " << offset << '\n'; + offset += n_data_sets * n_nodes * ((flags.data_double) + ? sizeof(double) + : sizeof(float)); } + else + { + out << " data follows" << '\n'; + write_dx_data(patches, n_data_sets, false, flags.data_double, out); + } + + // loop over all patches out << "attribute \"dep\" string \"positions\"" << '\n'; } else { out << "object \"data\" class constantarray type float rank 0 items " << n_nodes << " data follows" @@ -1585,6 +1779,14 @@ void DataOutBase::write_dx (const std::vector > &patches, } out << "end" << '\n'; + // Write all binary data now + if (flags.coordinates_binary) + write_dx_nodes(patches, true, flags.coordinates_double, out); + if (flags.int_binary) + write_dx_cells(patches, true, flags.int_64, out); + if (flags.data_binary) + write_dx_data(patches, n_data_sets, true, flags.data_double, out); + // make sure everything now gets to // disk out.flush ();