From 3c04979f366f64d55dc36b2faa1ea2f6db211d72 Mon Sep 17 00:00:00 2001 From: guido Date: Sat, 24 Nov 2001 18:48:00 +0000 Subject: [PATCH] first version of OpenDX output git-svn-id: https://svn.dealii.org/trunk@5264 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/base/include/base/data_out_base.h | 95 ++++- .../source/data_out_base.all_dimensions.cc | 21 + deal.II/base/source/data_out_base.cc | 388 +++++++++++++++++- 3 files changed, 502 insertions(+), 2 deletions(-) diff --git a/deal.II/base/include/base/data_out_base.h b/deal.II/base/include/base/data_out_base.h index 73ebdabd3b..0dffae2d8c 100644 --- a/deal.II/base/include/base/data_out_base.h +++ b/deal.II/base/include/base/data_out_base.h @@ -103,6 +103,17 @@ class ParameterHandler; * * @sect2{Supported output formats} * + * @sect3{OpenDX (IBM Open Visualization Data Explorer} + * + * Since Data Explorer (DX) is distributed as OpenSource, there is a + * well-accessible visualization tool for all (at least Unix-based) + * platforms. Therefore, output in its natural file format is + * included. Right now, this output is very basic, since the + * functionality of @p{DataOutBase} and derived classes has to be + * enhanced to use all of its features. Still, using some + * sophisticated networks, most can be recovered. + * + * * @sect3{UCD format} * * The UCD format is described in the AVS developer's guide. Due to @@ -456,6 +467,52 @@ class DataOutBase }; + /** + * Flags describing the details of + * output in OpenDX format. At + * present no flags are implemented. + */ + struct DXFlags + { + private: + /** + * Dummy entry to suppress compiler + * warnings when copying an empty + * structure. Remove this member + * when adding the first flag to + * this structure (and remove the + * @p{private} as well). + */ + int dummy; + + public: + /** + * Declare all flags with name + * and type as offered by this + * class, for use in input files. + */ + static void declare_parameters (ParameterHandler &prm); + + /** + * Read the parameters declared in + * @p{declare_parameters} and set the + * flags for this output format + * accordingly. + * + * The flags thus obtained overwrite + * all previous contents of this object. + */ + void parse_parameters (ParameterHandler &prm); + + /** + * Determine an estimate for + * the memory consumption (in + * bytes) of this + * object. + */ + unsigned int memory_consumption () const; + }; + /** * Flags describing the details of * output in UCD format. @@ -1079,6 +1136,19 @@ class DataOutBase unsigned int memory_consumption () const; }; + /** + * Write the given list of patches + * to the output stream in OpenDX + * format. See the general + * documentation for more information + * on the parameters. + */ + template + static void write_dx (const typename std::vector > &patches, + const std::vector &data_names, + const DXFlags &flags, + std::ostream &out); + /** * Write the given list of patches * to the output stream in ucd @@ -1406,7 +1476,15 @@ class DataOutInterface : private DataOutBase * the presently supported output * formats. */ - enum OutputFormat { default_format, ucd, gnuplot, povray, eps, gmv, vtk }; + enum OutputFormat { default_format, dx, ucd, gnuplot, povray, eps, gmv, vtk }; + + /** + * Obtain data through the + * @p{get_patches} function and + * write it to @p{out} in OpenDX + * format. + */ + void write_dx (std::ostream &out) const; /** * Obtain data through the @@ -1482,6 +1560,12 @@ class DataOutInterface : private DataOutBase */ void set_default_format (const OutputFormat default_format); + /** + * Set the flags to be used for + * output in OpenDX format. + */ + void set_flags (const DXFlags &dx_flags); + /** * Set the flags to be used for * output in UCD format. @@ -1525,6 +1609,7 @@ class DataOutInterface : private DataOutBase * usually has. At present the following * formats are defined: * @begin{itemize} + * @item @p{dx}: @p{.dx} * @item @p{ucd}: @p{.inp} * @item @p{gnuplot}: @p{.gnuplot} * @item @p{povray}: @p{.pov} @@ -1683,6 +1768,14 @@ class DataOutInterface : private DataOutBase */ OutputFormat default_fmt; + /** + * Flags to be used upon output + * of OpenDX data. Can be changed by + * using the @p{set_flags} + * function. + */ + DXFlags dx_flags; + /** * Flags to be used upon output * of UCD data. Can be changed by diff --git a/deal.II/base/source/data_out_base.all_dimensions.cc b/deal.II/base/source/data_out_base.all_dimensions.cc index ab989cc4c9..35be247473 100644 --- a/deal.II/base/source/data_out_base.all_dimensions.cc +++ b/deal.II/base/source/data_out_base.all_dimensions.cc @@ -33,6 +33,27 @@ DataOutBase::PovrayFlags::PovrayFlags (const bool smooth, +void DataOutBase::DXFlags::declare_parameters (ParameterHandler &/*prm*/) +{}; + + + +void DataOutBase::DXFlags::parse_parameters (ParameterHandler &/*prm*/) +{}; + + + +unsigned int +DataOutBase::DXFlags::memory_consumption () const +{ + // only simple data elements, so + // use sizeof operator + return sizeof (*this); +}; + + + + void DataOutBase::UcdFlags::declare_parameters (ParameterHandler &prm) { prm.declare_entry ("Write preamble", "true", Patterns::Bool()); diff --git a/deal.II/base/source/data_out_base.cc b/deal.II/base/source/data_out_base.cc index e7357a7531..3d936636bf 100644 --- a/deal.II/base/source/data_out_base.cc +++ b/deal.II/base/source/data_out_base.cc @@ -466,6 +466,356 @@ void DataOutBase::write_ucd (const typename std::vector > &p +template +void DataOutBase::write_dx (const typename std::vector > &patches, + const std::vector &data_names, + const DXFlags &flags, + std::ostream &out) +{ + AssertThrow (out, ExcIO()); + + Assert (patches.size() > 0, ExcNoPatches()); + + const unsigned int n_data_sets = data_names.size(); + + // first count the number of cells + // and cells for later use + unsigned int n_cells = 0, + n_nodes = 0; + for (typename std::vector >::const_iterator patch=patches.begin(); + patch!=patches.end(); ++patch) + switch (dim) + { + case 1: + n_cells += patch->n_subdivisions; + n_nodes += patch->n_subdivisions+1; + break; + case 2: + n_cells += patch->n_subdivisions * + patch->n_subdivisions; + n_nodes += (patch->n_subdivisions+1) * + (patch->n_subdivisions+1); + break; + case 3: + n_cells += patch->n_subdivisions * + patch->n_subdivisions * + patch->n_subdivisions; + n_nodes += (patch->n_subdivisions+1) * + (patch->n_subdivisions+1) * + (patch->n_subdivisions+1); + break; + default: + Assert (false, ExcNotImplemented()); + }; + + /////////////////////// + // preamble +//TODO:[GK] Fill in preamble later + if (false) + { + std::time_t time1= std::time (0); + std::tm *time = std::localtime(&time1); + out << "# This file was generated by the deal.II library." << std::endl + << "# Date = " + << time->tm_year+1900 << "/" + << time->tm_mon+1 << "/" + << time->tm_mday << std::endl + << "# Time = " + << time->tm_hour << ":" + << std::setw(2) << time->tm_min << ":" + << std::setw(2) << time->tm_sec << std::endl + << "#" << std::endl + << "# For a description of the UCD format see the AVS Developer's guide." + << std::endl + << "#" << std::endl; + }; + + // start with vertices + out << "object 1 class array type float rank 1 shape " << spacedim << " items " << n_nodes << " data follows" + << std::endl; + + /////////////////////////////// + // first write the coordinates of all vertices + if (true) + { + 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" + << std::endl; + + 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: + { + for (unsigned int i=0; i >::const_iterator patch=patches.begin(); + patch != patches.end(); ++patch) + { + const unsigned int n_subdivisions = patch->n_subdivisions; + + Assert (patch->data.n_rows() == n_data_sets, + ExcUnexpectedNumberOfDatasets (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 << std::endl; + }; + + break; + }; + + case 2: + { + for (unsigned int i=0; idata(data_set,i*(n_subdivisions+1) + j) << '\t'; + out << std::endl; + }; + + break; + }; + + case 3: + { + for (unsigned int i=0; idata(data_set, + (i*(n_subdivisions+1)+j)*(n_subdivisions+1)+k) + << '\t'; + out << std::endl; + }; + + break; + }; + + default: + Assert (false, ExcNotImplemented()); + }; + }; + out << "attribute \"dep\" string \"positions\"" << std::endl; + } else { + out << "object 3 class constantarray type float rank 0 items " << n_nodes << " data follows" + << std::endl << '0' << std::endl; + } + + // no model data + + out << "object \"deal data\" class field" << std::endl + << "component \"positions\" value 1" << std::endl + << "component \"connections\" value 2" << std::endl + << "component \"data\" value 3" << std::endl; + + out << "end" << std::endl; + // assert the stream is still ok + AssertThrow (out, ExcIO()); +}; + + + template void DataOutBase::write_gnuplot (const typename std::vector > &patches, const std::vector &data_names, @@ -2216,6 +2566,15 @@ DataOutBase::write_gmv_reorder_data_vectors (const typename std::vector +void DataOutInterface::write_dx (std::ostream &out) const +{ + DataOutBase::write_dx (get_patches(), get_dataset_names(), + dx_flags, out); +}; + + + template void DataOutInterface::write_ucd (std::ostream &out) const { @@ -2281,6 +2640,10 @@ DataOutInterface::write (std::ostream &out, switch (output_format) { + case dx: + write_dx (out); + break; + case ucd: write_ucd (out); break; @@ -2321,6 +2684,14 @@ void DataOutInterface::set_default_format(const OutputFormat fmt) +template +void DataOutInterface::set_flags (const DXFlags &flags) +{ + dx_flags = flags; +}; + + + template void DataOutInterface::set_flags (const UcdFlags &flags) { @@ -2379,6 +2750,9 @@ DataOutInterface::default_suffix (const OutputFormat output_format switch (output_format) { + case dx: + return ".dx"; + case ucd: return ".inp"; @@ -2409,6 +2783,9 @@ template typename DataOutInterface::OutputFormat DataOutInterface::parse_output_format (const std::string &format_name) { + if (format_name == "dx") + return dx; + if (format_name == "ucd") return ucd; @@ -2438,7 +2815,7 @@ DataOutInterface::parse_output_format (const std::string &format_n template std::string DataOutInterface::get_output_format_names () { - return "ucd|gnuplot|povray|eps|gmv|vtk"; + return "dx|ucd|gnuplot|povray|eps|gmv|vtk"; } @@ -2449,6 +2826,10 @@ void DataOutInterface::declare_parameters (ParameterHandler &prm) prm.declare_entry ("Output format", "gnuplot", Patterns::Selection (get_output_format_names ())); + prm.enter_subsection ("DX output parameters"); + DXFlags::declare_parameters (prm); + prm.leave_subsection (); + prm.enter_subsection ("UCD output parameters"); UcdFlags::declare_parameters (prm); prm.leave_subsection (); @@ -2482,6 +2863,10 @@ void DataOutInterface::parse_parameters (ParameterHandler &prm) const std::string& output_name = prm.get ("Output format"); default_fmt = parse_output_format (output_name); + prm.enter_subsection ("DX output parameters"); + dx_flags.parse_parameters (prm); + prm.leave_subsection (); + prm.enter_subsection ("UCD output parameters"); ucd_flags.parse_parameters (prm); prm.leave_subsection (); @@ -2513,6 +2898,7 @@ unsigned int DataOutInterface::memory_consumption () const { return (sizeof (default_fmt) + + MemoryConsumption::memory_consumption (dx_flags) + MemoryConsumption::memory_consumption (ucd_flags) + MemoryConsumption::memory_consumption (gnuplot_flags) + MemoryConsumption::memory_consumption (povray_flags) + -- 2.39.5