From 14d1b066b9b8e8fd73a1e1d001b33c591beb7108 Mon Sep 17 00:00:00 2001 From: eschnett <> Date: Mon, 5 Mar 2001 13:31:00 +0000 Subject: Created a generic routine for ASCII output. This should reduce code size. darcs-hash:20010305133103-f6438-b07009b56bf38b955fb2ca8476292ab2e47fdac2.gz --- Carpet/CarpetLib/src/data.cc | 95 ++++--------------------------------------- Carpet/CarpetLib/src/data.hh | 35 +++------------- Carpet/CarpetLib/src/gdata.cc | 93 +++++++++++++++++++++++++++++++++++++++++- Carpet/CarpetLib/src/gdata.hh | 46 +++++---------------- 4 files changed, 116 insertions(+), 153 deletions(-) (limited to 'Carpet') 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::interpolate_from (const generic_data* gsrc, } } + + // Output template -template -void data::write_ascii (const string name, const double time, - const vect& dirs, - const int tl, const int rl, - const int c, const int ml) +void data::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 lo = extent().lower()[dirs]; - const vect up = extent().upper()[dirs]; - const vect str = extent().stride()[dirs]; - const bbox 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::iterator it=ext.begin(); it!=ext.end(); ++it) { - ivect index(0); - for (int d=0; dcopy_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::out (ostream& os) const { #if defined(TMPL_EXPLICIT) -#define INSTANTIATE(T) \ - \ -template data; \ -template void data::write_ascii (const string name, const double time, \ - const vect& dirs, \ - const int tl, const int rl, \ - const int c, const int ml) const; \ - \ -template data; \ -template void data::write_ascii (const string name, const double time, \ - const vect& dirs, \ - const int tl, const int rl, \ - const int c, const int ml) const; \ -template void data::write_ascii (const string name, const double time, \ - const vect& dirs, \ - const int tl, const int rl, \ - const int c, const int ml) const; \ - \ -template data; \ -template void data::write_ascii (const string name, const double time, \ - const vect& dirs, \ - const int tl, const int rl, \ - const int c, const int ml) const; \ -template void data::write_ascii (const string name, const double time, \ - const vect& dirs, \ - const int tl, const int rl, \ - const int c, const int ml) const; \ -template void data::write_ascii (const string name, const double time, \ - const vect& dirs, \ - const int tl, const int rl, \ - const int c, const int ml) const; +#define INSTANTIATE(T) \ +template data; \ +template data; \ +template data; #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 - void write_ascii (const string name, const double time, - const vect& 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& 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& 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& 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 $ ***************************************************************************/ @@ -45,6 +45,70 @@ generic_data::~generic_data () { } // Output +template +template +void generic_data::write_ascii (const string name, const int time, + const vect& org, + const vect& 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 lo = extent().lower()[dirs]; + const vect up = extent().upper()[dirs]; + const vect str = extent().stride()[dirs]; + const bbox ext(lo,up,str); + + for (bbox::iterator it=ext.begin(); it!=ext.end(); ++it) { + ivect index(org); + for (int d=0; dcopy_from (this, _extent); + tmp->write_ascii (name, time, org, dirs, tl, rl, c, ml); + delete tmp; + + } +} + + + template ostream& operator<< (ostream& os, const generic_data& 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& org, const vect& 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& org, const vect& 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& org, const vect& 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& org, const vect& 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& org, const vect& 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& org, const vect& 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 #include +#include #include #include @@ -137,49 +138,22 @@ public: // Output template - void write_ascii (const string name, const double time, - const vect& dirs, + void write_ascii (const string name, const int time, + const vect& org, const vect& 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*)&dirs, tl, rl, c, ml); - break; - case 2: - write_ascii_2 (name, time, *(const vect*)&dirs, tl, rl, c, ml); - break; - case 3: - write_ascii_3 (name, time, *(const vect*)&dirs, tl, rl, c, ml); - break; - default: - abort(); - } - } + const; protected: - virtual void write_ascii_1 (const string name, const double time, - const vect& 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& 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& 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: -- cgit v1.2.3