From: Wolfgang Bangerth Date: Tue, 5 Apr 2005 20:54:56 +0000 (+0000) Subject: Add the DataOutReader class and assorted infrastructure. X-Git-Tag: v8.0.0~14184 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ac79e9978ae81b259ae752d1a128023c58e74139;p=dealii.git Add the DataOutReader class and assorted infrastructure. git-svn-id: https://svn.dealii.org/trunk@10363 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 127702b7c9..f11f2e0d52 100644 --- a/deal.II/base/include/base/data_out_base.h +++ b/deal.II/base/include/base/data_out_base.h @@ -532,6 +532,15 @@ class DataOutBase */ Patch (); + /** + * Compare the present patch + * for equality with another + * one. This is used in a few + * of the automated tests in + * our testsuite. + */ + bool operator == (const Patch &patch) const; + /** * Determine an estimate for * the memory consumption (in @@ -2228,6 +2237,59 @@ class DataOutInterface : private DataOutBase +template +class DataOutReader : public DataOutInterface +{ + public: + /** + * Read a sequence of patches as + * written previously by + * DataOutBase::write_deal_II_intermediate + * and store them in the present + * object. This overwrites any + * previous content. + */ + void read (std::istream &in); + + protected: + /** + * This is the function + * through which this class + * propagates preprocessed data in + * the form of Patch + * structures (declared in the + * base class DataOutBase) to + * the actual output + * function. + * + * It returns the patches as read + * the last time a stream was + * given to the read() function. + */ + virtual const std::vector > & + get_patches () const; + + /** + * Abstract virtual function + * through which the names of + * data sets are obtained by the + * output functions of the base + * class. + * + * Return the names of the + * variables as read the last + * time we read a file. + */ + virtual std::vector get_dataset_names () const; + + private: + std::vector > patches; + std::vector dataset_names; +}; + + + + /* -------------------- inline functions ------------------- */ inline @@ -2256,4 +2318,19 @@ operator << (std::ostream &out, +/** + * Input operator for an object of type + * DataOutBase::Patch. This operator reads the intermediate + * graphics format represented by the patch data structure, using the + * format in which it was written using the operator<<. + * + * @author Wolfgang Bangerth, 2005 + */ +template +std::istream & +operator >> (std::istream &in, + DataOutBase::Patch &patch); + + + #endif diff --git a/deal.II/base/source/data_out_base.cc b/deal.II/base/source/data_out_base.cc index 0f940c4ad8..bc21bb4f2b 100644 --- a/deal.II/base/source/data_out_base.cc +++ b/deal.II/base/source/data_out_base.cc @@ -23,6 +23,21 @@ #include #include +#ifdef HAVE_STD_STRINGSTREAM +# include +#else +# include +#endif + + +DeclException2(ExcUnexpectedInput, + std::string, std::string, + << "Unexpected input: expected line\n <" + << arg1 + << ">\nbut got\n <" + << arg2 << ">"); + + template const unsigned int DataOutBase::Patch::no_neighbor; @@ -47,6 +62,40 @@ DataOutBase::Patch::Patch () +template +bool +DataOutBase::Patch::operator == (const Patch &patch) const +{ + for (unsigned int i=0; i::vertices_per_cell; ++i) + if (vertices[i] != patch.vertices[i]) + return false; + + for (unsigned int i=0; i::faces_per_cell; ++i) + if (neighbors[i] != patch.neighbors[i]) + return false; + + if (patch_index != patch.patch_index) + return false; + + if (n_subdivisions != patch.n_subdivisions) + return false; + + if (data.n_rows() != patch.data.n_rows()) + return false; + + if (data.n_cols() != patch.data.n_cols()) + return false; + + for (unsigned int i=0; i unsigned int DataOutBase::Patch::memory_consumption () const @@ -4468,6 +4517,103 @@ DataOutInterface::memory_consumption () const + +template +void +DataOutReader::read (std::istream &in) +{ + Assert (in, ExcIO()); + + // first empty previous content + { + std::vector > + tmp; + tmp.swap (patches); + } + { + std::vector tmp; + tmp.swap (dataset_names); + } + + // then check that we have the + // correct header of this + // file. both the first and second + // lines have to match + { + std::string header; + getline (in, header); + +#ifdef HAVE_STD_STRINGSTREAM + std::ostringstream s; +#else + std::ostrstream s; +#endif + + s << "[deal.II intermediate format graphics data]"; + +#ifndef HAVE_STD_STRINGSTREAM + s << std::ends; +#endif + + Assert (header == s.str(), ExcUnexpectedInput(s.str(),header)); + } + { + std::string header; + getline (in, header); + +#ifdef HAVE_STD_STRINGSTREAM + std::ostringstream s; +#else + std::ostrstream s; +#endif + + s << "[written by deal.II version " + << DEAL_II_MAJOR << '.' << DEAL_II_MINOR << "]"; + +#ifndef HAVE_STD_STRINGSTREAM + s << std::ends; +#endif + + Assert (header == s.str(), ExcUnexpectedInput(s.str(),header)); + } + + // then read the rest of the data + unsigned int n_datasets; + in >> n_datasets; + dataset_names.resize (n_datasets); + for (unsigned int i=0; i> dataset_names[i]; + + unsigned int n_patches; + in >> n_patches; + patches.resize (n_patches); + for (unsigned int i=0; i> patches[i]; + + Assert (in, ExcIO()); +} + + + +template +const std::vector > & +DataOutReader::get_patches () const +{ + return patches; +} + + + +template +std::vector +DataOutReader::get_dataset_names () const +{ + return dataset_names; +} + + + + template std::ostream & operator << (std::ostream &out, @@ -4502,58 +4648,89 @@ operator << (std::ostream &out, +template +std::istream & +operator >> (std::istream &in, + DataOutBase::Patch &patch) +{ + Assert (in, ExcIO()); -// explicit instantiations -template class DataOutInterface<1,1>; -template class DataOutBase::Patch<1,1>; + // read a header line and compare + // it to what we usually + // write. skip all lines that + // contain only blanks at the start + { + std::string header; + do + { + getline (in, header); + while ((header.size() != 0) && + (header[header.size()-1] == ' ')) + header.erase(header.size()-1); + } + while ((header == "") && in); -template class DataOutInterface<2,2>; -template class DataOutBase::Patch<2,2>; +#ifdef HAVE_STD_STRINGSTREAM + std::ostringstream s; +#else + std::ostrstream s; +#endif -template class DataOutInterface<3,3>; -template class DataOutBase::Patch<3,3>; + s << "[deal.II intermediate Patch<" << dim << ',' << spacedim << ">]"; -template class DataOutInterface<4,4>; -template class DataOutBase::Patch<4,4>; +#ifndef HAVE_STD_STRINGSTREAM + s << std::ends; +#endif + + Assert (header == s.str(), ExcUnexpectedInput(s.str(),header)); + } + -// plotting surfaces -template class DataOutInterface<1,2>; -template class DataOutBase::Patch<1,2>; + // then read all the data that is + // in this patch + for (unsigned int i=0; i::vertices_per_cell; ++i) + in >> patch.vertices[i]; -template class DataOutInterface<2,3>; -template class DataOutBase::Patch<2,3>; + for (unsigned int i=0; i::faces_per_cell; ++i) + in >> patch.neighbors[i]; -template class DataOutInterface<3,4>; -template class DataOutBase::Patch<3,4>; + in >> patch.patch_index >> patch.n_subdivisions; -// output operators -template -std::ostream & -operator << (std::ostream &out, - const DataOutBase::Patch<1,1> &patch); -template -std::ostream & -operator << (std::ostream &out, - const DataOutBase::Patch<2,2> &patch); -template -std::ostream & -operator << (std::ostream &out, - const DataOutBase::Patch<3,3> &patch); -template -std::ostream & -operator << (std::ostream &out, - const DataOutBase::Patch<4,4> &patch); -template -std::ostream & -operator << (std::ostream &out, - const DataOutBase::Patch<1,2> &patch); -template -std::ostream & -operator << (std::ostream &out, - const DataOutBase::Patch<2,3> &patch); -template -std::ostream & -operator << (std::ostream &out, - const DataOutBase::Patch<3,4> &patch); + unsigned int n_rows, n_cols; + in >> n_rows >> n_cols; + patch.data.reinit (n_rows, n_cols); + for (unsigned int i=0; i> patch.data[i][j]; + + Assert (in, ExcIO()); + + return in; +} + + + + +// explicit instantiations +#define INSTANTIATE(dim,spacedim) \ + template class DataOutInterface; \ + template class DataOutReader; \ + template class DataOutBase::Patch; \ + template \ + std::ostream & \ + operator << (std::ostream &out, \ + const DataOutBase::Patch &patch); \ + template \ + std::istream & \ + operator >> (std::istream &in, \ + DataOutBase::Patch &patch) + +INSTANTIATE(1,1); +INSTANTIATE(2,2); +INSTANTIATE(3,3); +INSTANTIATE(4,4); +INSTANTIATE(1,2); +INSTANTIATE(2,3); +INSTANTIATE(3,4);