diff options
author | eschnett <> | 2001-03-05 13:31:00 +0000 |
---|---|---|
committer | eschnett <> | 2001-03-05 13:31:00 +0000 |
commit | 14d1b066b9b8e8fd73a1e1d001b33c591beb7108 (patch) | |
tree | 1eba407fbcebe065a42f4d1df6934b2f686e2eff /Carpet | |
parent | c1869f7b5dbda3abbe60b9335d0f24e0ce44b189 (diff) |
Created a generic routine for ASCII output. This should reduce code size.
darcs-hash:20010305133103-f6438-b07009b56bf38b955fb2ca8476292ab2e47fdac2.gz
Diffstat (limited to 'Carpet')
-rw-r--r-- | Carpet/CarpetLib/src/data.cc | 95 | ||||
-rw-r--r-- | Carpet/CarpetLib/src/data.hh | 35 | ||||
-rw-r--r-- | Carpet/CarpetLib/src/gdata.cc | 93 | ||||
-rw-r--r-- | Carpet/CarpetLib/src/gdata.hh | 46 |
4 files changed, 116 insertions, 153 deletions
diff --git a/Carpet/CarpetLib/src/data.cc b/Carpet/CarpetLib/src/data.cc index 18fb2ac98..c9ffb623a 100644 --- a/Carpet/CarpetLib/src/data.cc +++ b/Carpet/CarpetLib/src/data.cc @@ -5,7 +5,7 @@ copyright : (C) 2000 by Erik Schnetter email : schnetter@astro.psu.edu - $Header: /home/eschnett/C/carpet/Carpet/Carpet/CarpetLib/src/data.cc,v 1.1 2001/03/01 13:40:10 eschnett Exp $ + $Header: /home/eschnett/C/carpet/Carpet/Carpet/CarpetLib/src/data.cc,v 1.2 2001/03/05 14:31:03 eschnett Exp $ ***************************************************************************/ @@ -311,64 +311,14 @@ void data<T,D>::interpolate_from (const generic_data<D>* gsrc, } } + + // Output template<class T, int D> -template<int DD> -void data<T,D>::write_ascii (const string name, const double time, - const vect<int,DD>& dirs, - const int tl, const int rl, - const int c, const int ml) +void data<T,D>::write_ascii_output_element (ofstream& file, const ivect& index) const { - assert (_has_storage); - - if (_proc==0) { - // output on processor 0 - - int rank; - MPI_Comm_rank (dist::comm, &rank); - if (rank == 0) { - - const vect<int,DD> lo = extent().lower()[dirs]; - const vect<int,DD> up = extent().upper()[dirs]; - const vect<int,DD> str = extent().stride()[dirs]; - const bbox<int,DD> ext(lo,up,str); - - ofstream file(name.c_str(), ios::app); - assert (file.good()); - - file << "# time=" << time << " tl=" << tl << " rl=" << rl - << " c=" << c << " ml=" << ml << " "; - assert (DD<=3); - for (int d=0; d<DD; ++d) file << "xyz"[d] << " "; - file << "data" << endl; - - for (bbox<int,DD>::iterator it=ext.begin(); it!=ext.end(); ++it) { - ivect index(0); - for (int d=0; d<DD; ++d) index[dirs[d]] = (*it)[d]; - file << time << " " << tl << " " << rl << " " << c << " " << ml << " "; - for (int d=0; d<D; ++d) file << index[d] << " "; - file << (*this)[index] << endl; - for (int d=0; d<D; ++d) { - if (index[d]!=extent().upper()[d]) break; - file << endl; - } - } - - file.close(); - assert (file.good()); - - } - - } else { - // copy to processor 0 and output there - - data* tmp = new data(_extent, 0); - tmp->copy_from (this, _extent); - tmp->write_ascii (name, time, dirs, tl, rl, c, ml); - delete tmp; - - } + file << (*this)[index] << endl; } @@ -386,37 +336,10 @@ ostream& data<T,D>::out (ostream& os) const { #if defined(TMPL_EXPLICIT) -#define INSTANTIATE(T) \ - \ -template data<T,1>; \ -template void data<T,1>::write_ascii (const string name, const double time, \ - const vect<int,1>& dirs, \ - const int tl, const int rl, \ - const int c, const int ml) const; \ - \ -template data<T,2>; \ -template void data<T,2>::write_ascii (const string name, const double time, \ - const vect<int,1>& dirs, \ - const int tl, const int rl, \ - const int c, const int ml) const; \ -template void data<T,2>::write_ascii (const string name, const double time, \ - const vect<int,2>& dirs, \ - const int tl, const int rl, \ - const int c, const int ml) const; \ - \ -template data<T,3>; \ -template void data<T,3>::write_ascii (const string name, const double time, \ - const vect<int,1>& dirs, \ - const int tl, const int rl, \ - const int c, const int ml) const; \ -template void data<T,3>::write_ascii (const string name, const double time, \ - const vect<int,2>& dirs, \ - const int tl, const int rl, \ - const int c, const int ml) const; \ -template void data<T,3>::write_ascii (const string name, const double time, \ - const vect<int,3>& dirs, \ - const int tl, const int rl, \ - const int c, const int ml) const; +#define INSTANTIATE(T) \ +template data<T,1>; \ +template data<T,2>; \ +template data<T,3>; #include "instantiate" diff --git a/Carpet/CarpetLib/src/data.hh b/Carpet/CarpetLib/src/data.hh index c528833e1..7b4336b97 100644 --- a/Carpet/CarpetLib/src/data.hh +++ b/Carpet/CarpetLib/src/data.hh @@ -5,7 +5,7 @@ copyright : (C) 2000 by Erik Schnetter email : schnetter@astro.psu.edu - $Header: /home/eschnett/C/carpet/Carpet/Carpet/CarpetLib/src/data.hh,v 1.1 2001/03/01 13:40:10 eschnett Exp $ + $Header: /home/eschnett/C/carpet/Carpet/Carpet/CarpetLib/src/data.hh,v 1.2 2001/03/05 14:31:03 eschnett Exp $ ***************************************************************************/ @@ -106,39 +106,14 @@ public: const double tfact, const ibbox& box); - // Output - template<int DD> - void write_ascii (const string name, const double time, - const vect<int,DD>& dirs, - const int tl, const int rl, - const int c, const int ml) - const; -protected: - virtual void write_ascii_1 (const string name, const double time, - const vect<int,1>& dirs, - const int tl, const int rl, - const int c, const int ml) const { - write_ascii (name, time, dirs, tl, rl, c, ml); - } - virtual void write_ascii_2 (const string name, const double time, - const vect<int,2>& dirs, - const int tl, const int rl, - const int c, const int ml) const { - write_ascii (name, time, dirs, tl, rl, c, ml); - } - virtual void write_ascii_3 (const string name, const double time, - const vect<int,3>& dirs, - const int tl, const int rl, - const int c, const int ml) const { - write_ascii (name, time, dirs, tl, rl, c, ml); - } -// void write_ieee (const string name, const double time, + void write_ascii_output_element (ofstream& file, const ivect& index) const; +// void write_ieee (const string name, const int time, // const int tl, const int rl, const int c, const int ml) // const; -// void write_hdf (const string name, const double time, +// void write_hdf (const string name, const int time, // const int tl, const int rl, const int c, const int ml) // const; -// void write_h5 (const string name, const double time, +// void write_h5 (const string name, const int time, // const int tl, const int rl, const int c, const int ml) // const; public: diff --git a/Carpet/CarpetLib/src/gdata.cc b/Carpet/CarpetLib/src/gdata.cc index 0123b96a1..9e0784df9 100644 --- a/Carpet/CarpetLib/src/gdata.cc +++ b/Carpet/CarpetLib/src/gdata.cc @@ -5,7 +5,7 @@ copyright : (C) 2000 by Erik Schnetter email : schnetter@astro.psu.edu - $Header: /home/eschnett/C/carpet/Carpet/Carpet/CarpetLib/src/gdata.cc,v 1.1 2001/03/01 13:40:10 eschnett Exp $ + $Header: /home/eschnett/C/carpet/Carpet/Carpet/CarpetLib/src/gdata.cc,v 1.2 2001/03/05 14:31:03 eschnett Exp $ ***************************************************************************/ @@ -46,6 +46,70 @@ generic_data<D>::~generic_data () { } // Output template<int D> +template<int DD> +void generic_data<D>::write_ascii (const string name, const int time, + const vect<int,D>& org, + const vect<int,DD>& dirs, + const int tl, const int rl, + const int c, const int ml) + const +{ + assert (_has_storage); + + if (_proc==0) { + // output on processor 0 + + int rank; + MPI_Comm_rank (dist::comm, &rank); + if (rank == 0) { + + ofstream file(name.c_str(), ios::app); + assert (file.good()); + + file << "# iteration " << time << endl + << "# time level " << tl << " refinement level " << rl + << " component " << c << " multigrid level " << ml << endl + << "# column format: it tl rl c ml"; + assert (D<=3); + for (int d=0; d<D; ++d) file << " " << "xyz"[d]; + file << " data" << endl; + + const vect<int,DD> lo = extent().lower()[dirs]; + const vect<int,DD> up = extent().upper()[dirs]; + const vect<int,DD> str = extent().stride()[dirs]; + const bbox<int,DD> ext(lo,up,str); + + for (bbox<int,DD>::iterator it=ext.begin(); it!=ext.end(); ++it) { + ivect index(org); + for (int d=0; d<DD; ++d) index[dirs[d]] = (*it)[d]; + file << time << " " << tl << " " << rl << " " << c << " " << ml << " "; + for (int d=0; d<D; ++d) file << index[d] << " "; + write_ascii_output_element (file, index); + for (int d=0; d<D; ++d) { + if (index[d]!=extent().upper()[d]) break; + file << endl; + } + } + + file.close(); + assert (file.good()); + + } + + } else { + // copy to processor 0 and output there + + generic_data* tmp = make_typed(_extent, 0); + tmp->copy_from (this, _extent); + tmp->write_ascii (name, time, org, dirs, tl, rl, c, ml); + delete tmp; + + } +} + + + +template<int D> ostream& operator<< (ostream& os, const generic_data<D>& f) { return f.out(os); } @@ -61,4 +125,31 @@ template ostream& operator<< (ostream& os, const generic_data<2>& d); template class generic_data<3>; template ostream& operator<< (ostream& os, const generic_data<3>& d); + +template void generic_data<1>::write_ascii +(const string name, const int time, + const vect<int,1>& org, const vect<int,1>& dirs, + const int tl, const int rl, const int c, const int ml) const; + +template void generic_data<2>::write_ascii +(const string name, const int time, + const vect<int,2>& org, const vect<int,1>& dirs, + const int tl, const int rl, const int c, const int ml) const; +template void generic_data<2>::write_ascii +(const string name, const int time, + const vect<int,2>& org, const vect<int,2>& dirs, + const int tl, const int rl, const int c, const int ml) const; + +template void generic_data<3>::write_ascii + (const string name, const int time, + const vect<int,3>& org, const vect<int,1>& dirs, + const int tl, const int rl, const int c, const int ml) const; +template void generic_data<3>::write_ascii +(const string name, const int time, + const vect<int,3>& org, const vect<int,2>& dirs, + const int tl, const int rl, const int c, const int ml) const; +template void generic_data<3>::write_ascii +(const string name, const int time, + const vect<int,3>& org, const vect<int,3>& dirs, + const int tl, const int rl, const int c, const int ml) const; #endif diff --git a/Carpet/CarpetLib/src/gdata.hh b/Carpet/CarpetLib/src/gdata.hh index 423916e3d..1d245be7c 100644 --- a/Carpet/CarpetLib/src/gdata.hh +++ b/Carpet/CarpetLib/src/gdata.hh @@ -5,7 +5,7 @@ copyright : (C) 2000 by Erik Schnetter email : schnetter@astro.psu.edu - $Header: /home/eschnett/C/carpet/Carpet/Carpet/CarpetLib/src/gdata.hh,v 1.1 2001/03/01 13:40:10 eschnett Exp $ + $Header: /home/eschnett/C/carpet/Carpet/Carpet/CarpetLib/src/gdata.hh,v 1.2 2001/03/05 14:31:03 eschnett Exp $ ***************************************************************************/ @@ -23,6 +23,7 @@ #include <cassert> #include <cstdlib> +#include <fstream> #include <iostream> #include <string> @@ -137,49 +138,22 @@ public: // Output template<int DD> - void write_ascii (const string name, const double time, - const vect<int,DD>& dirs, + void write_ascii (const string name, const int time, + const vect<int,D>& org, const vect<int,DD>& dirs, const int tl, const int rl, const int c, const int ml) - const - { - switch (DD) { - case 1: - write_ascii_1 (name, time, *(const vect<int,1>*)&dirs, tl, rl, c, ml); - break; - case 2: - write_ascii_2 (name, time, *(const vect<int,2>*)&dirs, tl, rl, c, ml); - break; - case 3: - write_ascii_3 (name, time, *(const vect<int,3>*)&dirs, tl, rl, c, ml); - break; - default: - abort(); - } - } + const; protected: - virtual void write_ascii_1 (const string name, const double time, - const vect<int,1>& dirs, - const int tl, const int rl, - const int c, const int ml) - const = 0; - virtual void write_ascii_2 (const string name, const double time, - const vect<int,2>& dirs, - const int tl, const int rl, - const int c, const int ml) + virtual void write_ascii_output_element (ofstream& file, const ivect& index) const = 0; - virtual void write_ascii_3 (const string name, const double time, - const vect<int,3>& dirs, - const int tl, const int rl, - const int c, const int ml) - const = 0; -// void write_ieee (const string name, const double time, +public: +// void write_ieee (const string name, const int time, // const int tl, const int rl, const int c, const int ml) // const; -// void write_hdf (const string name, const double time, +// void write_hdf (const string name, const int time, // const int tl, const int rl, const int c, const int ml) // const; -// void write_h5 (const string name, const double time, +// void write_h5 (const string name, const int time, // const int tl, const int rl, const int c, const int ml) // const; public: |