Home | Doxygen Documentation | Tutorials | Developer Tools (restricted)

basics/outputTecplot.hh
Go to the documentation of this file.
00001 /* tecplot output function
00002  */
00003 
00004 #ifndef OutputTecplot_hh
00005 #define OutputTecplot_hh
00006 
00007 #include <iostream>
00008 #include <complex>
00009 #include <vector>
00010 #include "outputOperator.hh"
00011 #include "vectorsMatrices.hh"
00012 #include "toolbox/array.hh"
00013 
00014 namespace concepts {
00015 
00016   // ********************************************************* OutputTecplot **
00017 
00023   template<typename F>
00024   class OutputTecplot : public OutputOperator {
00025   public:
00026     OutputTecplot(const F& val) : val_(val) {}
00031     void header(std::ostream& os, std::string name, uint cnt = 0);
00032   protected:
00034     std::ostream& info(std::ostream& os) const {
00035       return os << val_;
00036     }
00037   private:
00038     const F& val_;
00039   };
00040 
00041   template<typename F>
00042   void OutputTecplot<F>::header(std::ostream& os, std::string name, uint cnt) {
00043     os << name << cnt;
00044   }
00045 
00046   // *************************************** OutputTecplot<std::complex<F> > **
00047 
00048   template<typename F>
00049   class OutputTecplot<std::complex<F> > : public OutputOperator {
00050   public:
00051     OutputTecplot(const std::complex<F>& val) : val_(val) {}
00056     void header(std::ostream& os, std::string name, uint cnt = 0);
00057   protected:
00059     std::ostream& info(std::ostream& os) const {
00060       return os << OutputTecplot<F>(std::real(val_)) << " "
00061     << OutputTecplot<F>(std::imag(val_));
00062     }
00063   private:
00064     const std::complex<F>& val_;
00065   };
00066 
00067   template<>
00068   template<typename F>
00069   void OutputTecplot<std::complex<F> >::header
00070   (std::ostream& os, std::string name, uint cnt) {
00071     os << name << cnt << "r, " << name << cnt << "i";
00072   }
00073 
00074   // ********************************************** OutputTecplot<Array<F> > **
00075 
00076   template<typename F>
00077   class OutputTecplot<Array<F> > : public OutputOperator {
00078   public:
00079     OutputTecplot(const Array<F>& val) : val_(val) {}
00084     void header(std::ostream& os, std::string name, uint cnt = 0);
00085   protected:
00087     std::ostream& info(std::ostream& os) const {
00088       for(uint i = 0; i < val_.size(); ++i)
00089   os << OutputTecplot<F>(val_[i]) << " ";
00090       return os;
00091     }
00092   private:
00093     const Array<F>& val_;
00094   };
00095 
00096   template<>
00097   template<typename F>
00098   void OutputTecplot<Array<F> >::header
00099   (std::ostream& os, std::string name, uint cnt) {
00100     OutputTecplot<F> o(val_[0]);
00101     for(uint i = 0; i < val_.size(); ) {
00102       o.header(os, name, cnt+i);
00103       if (++i < val_.size()) os << ", ";
00104     }
00105   }
00106 
00107   // ****************************************** OutputTecplot<Point<F,dim> > **
00108 
00110   template<typename F, int dim>
00111   class OutputTecplot<Point<F,dim> > : public OutputOperator {
00112   public:
00113     OutputTecplot(const Point<F,dim>& val) : val_(val) {}
00118     void header(std::ostream& os, std::string name, uint cnt = 0);
00119   protected:
00121     std::ostream& info(std::ostream& os) const {
00122       for(uint i = 0; i < dim; ++i)
00123   os << OutputTecplot<F>(val_[i]) << " ";
00124       return os;
00125     }
00126   private:
00127     const Point<F,dim>& val_;
00128   };
00129 
00130   template<>
00131   template<typename F, int dim>
00132   void OutputTecplot<Point<F,dim> >::header
00133   (std::ostream& os, std::string name, uint cnt) {
00134     if (dim == 1)
00135       os << name << cnt;
00136     else {
00137       OutputTecplot<F> o(val_[0]);
00138       for(uint i = 0; i < dim; ) {
00139   o.header(os, name, cnt+i);
00140   if (++i < dim) os << ", ";
00141       }
00142     }
00143   }
00144 
00145 } // namespace concepts
00146 
00147 #endif // OutputTecplot_hh

Home | Doxygen Documentation | Tutorials | Developer Tools (restricted)