00001
00002
00003
00004 #ifndef graphTecplot_hh
00005 #define graphTecplot_hh
00006
00007 #include <vector>
00008 #include "basis.hh"
00009 #include "basics/outputTecplot.hh"
00010 #include "basics/output.hh"
00011 #include "basics/vectorsMatricesForward.hh"
00012 #include "geometry/arrays.hh"
00013
00014 #define TecplotGraphConstr_D 0
00015 #define TecplotMeshWriteFormula_D 0
00016
00017 namespace concepts {
00018
00019
00020 template<class F>
00021 class Formula;
00022 }
00023
00024 namespace graphics {
00025
00026 using concepts::Real;
00027 using concepts::Real2d;
00028
00029
00030
00032 std::string tecplotEnding(const std::string& filename);
00033
00034
00035
00040 class TecplotGraphics : public OutputBase {
00041 public:
00042 enum elementTypes {TRIANGLE, QUADRILATERAL, TETRAHEDRON , BRICK,
00043 MAX_TYPE };
00050 template<class G>
00051 TecplotGraphics(const concepts::Space<G>& spc, const std::string filename,
00052 const std::string title,
00053 const enum elementTypes type = QUADRILATERAL);
00060 TecplotGraphics(concepts::Mesh& msh, const std::string filename,
00061 const std::string title,
00062 const enum elementTypes type = QUADRILATERAL,
00063 const uint points = noPoints);
00064
00073 template<class F, class G>
00074 TecplotGraphics(const concepts::Space<G>& spc, const std::string filename,
00075 const std::string title,
00076 const concepts::Vector<F>& sol,
00077 const enum elementTypes type = QUADRILATERAL,
00078 const concepts::ElementFunction<F,G>* fun = 0,
00079 const bool append = false);
00080
00088 template<class F, class G>
00089 TecplotGraphics(const concepts::Space<G>& spc, const std::string filename,
00090 const std::string title,
00091 const concepts::Formula<F>& frm,
00092 const enum elementTypes type = QUADRILATERAL);
00099 template<class F, class G>
00100 TecplotGraphics(const concepts::Space<G>& spc, const std::string filename,
00101 const std::string title,
00102 const concepts::ElementFormula<F,G>& frm,
00103 const enum elementTypes type = QUADRILATERAL);
00111 template<class F>
00112 TecplotGraphics(concepts::Mesh& msh, const std::string filename,
00113 const std::string title,
00114 const concepts::Formula<F>& frm,
00115 const enum elementTypes type = QUADRILATERAL,
00116 const uint points = noPoints);
00117
00118 virtual ~TecplotGraphics() {}
00119
00120 static uint noPoints;
00121 protected:
00122 virtual std::ostream& info(std::ostream& os) const;
00123 private:
00127 template<class F, class G>
00128 void write_(concepts::GlobalPostprocess<G>& postProcess,
00129 BaseOutputCell<G>& tecplot, const F v);
00131 void createStreams_();
00133 void closeStreams_(const std::vector<uint>& cnt);
00135 const uint dim_() const;
00137 const std::string typeStr_() const;
00138
00140 std::map<std::string, std::ostream*> s_ptr_;
00142 const std::string title_;
00144 const enum elementTypes type_;
00145 };
00146
00147 template<class G>
00148 TecplotGraphics::TecplotGraphics(const concepts::Space<G>& spc,
00149 const std::string filename,
00150 const std::string title,
00151 const enum elementTypes type)
00152 : OutputBase(tecplotEnding(filename)), title_(title), type_(type)
00153 {
00154
00155 concepts::GlobalPostprocess<G> postProcess(spc);
00156
00157 BaseMeshCell tecplot(s_ptr_, dim_(),
00158 concepts::ElementGraphicsBase::TECPLOT, noPoints);
00159
00160
00161 write_(postProcess, tecplot, 0);
00162 }
00163
00164 template<class F, class G>
00165 TecplotGraphics::TecplotGraphics(const concepts::Space<G>& spc,
00166 const std::string filename,
00167 const std::string title,
00168 const concepts::Vector<F>& sol,
00169 const enum elementTypes type,
00170 const concepts::ElementFunction<F,G>* fun,
00171 const bool append)
00172 : OutputBase(tecplotEnding(filename), append), title_(title), type_(type)
00173 {
00174
00175 concepts::GlobalPostprocess<G> postProcess(spc);
00176
00177 BaseDataCell<F,G> tecplot(s_ptr_, dim_(),
00178 concepts::ElementGraphicsBase::TECPLOT,
00179 sol, fun);
00180
00181
00182
00183 write_(postProcess, tecplot, (F)0);
00184 }
00185
00186 template<class F, class G>
00187 TecplotGraphics::TecplotGraphics(const concepts::Space<G>& spc,
00188 const std::string filename,
00189 const std::string title,
00190 const concepts::Formula<F>& frm,
00191 const enum elementTypes type)
00192 : OutputBase(tecplotEnding(filename)),
00193 title_(title), type_(type) {
00194
00195 concepts::GlobalPostprocess<G> postProcess(spc);
00196
00197 BaseFormulaCell<F,G> tecplot(s_ptr_, dim_(),
00198 concepts::ElementGraphicsBase::TECPLOT, frm,
00199 noPoints);
00200
00201
00202 write_(postProcess, tecplot, true);
00203 }
00204
00205 template<class F, class G>
00206 TecplotGraphics::TecplotGraphics(const concepts::Space<G>& spc,
00207 const std::string filename,
00208 const std::string title,
00209 const concepts::ElementFormula<F,G>& frm,
00210 const enum elementTypes type)
00211 : OutputBase(tecplotEnding(filename)), title_(title), type_(type)
00212 {
00213
00214 concepts::GlobalPostprocess<G> postProcess(spc);
00215
00216 BaseElementFormulaCell<F,G> tecplot
00217 (s_ptr_, dim_(), concepts::ElementGraphicsBase::TECPLOT, frm);
00218
00219
00220 write_(postProcess, tecplot, (F)0);
00221 }
00222
00223 template<class F>
00224 TecplotGraphics::TecplotGraphics(concepts::Mesh& msh,
00225 const std::string filename,
00226 const std::string title,
00227 const concepts::Formula<F>& frm,
00228 const enum elementTypes type,
00229 const uint points)
00230 : OutputBase(tecplotEnding(filename)), title_(title ), type_(type)
00231 {
00232
00233 concepts::GlobalPostprocess<Real> postProcess(msh);
00234
00235 BaseFormulaCell<F,Real> tecplot(s_ptr_, dim_(),
00236 concepts::ElementGraphicsBase::TECPLOT,
00237 frm, points);
00238
00239
00240 write_(postProcess, tecplot, F(1));
00241 }
00242
00243 template<class F, class G>
00244 void TecplotGraphics::write_(concepts::GlobalPostprocess<G>& postProcess,
00245 BaseOutputCell<G>& tecplot, const F v) {
00246
00247 createStreams_();
00248 if (v != F(0)) {
00249 concepts::OutputTecplot<F>(v).header(*ofs_ << ", ", "v");
00250 *ofs_ << std::endl;
00251 }
00252
00253 tecplot.count().assign(2, 0);
00254
00255 DEBUGL(TecplotGraphConstr_D, tecplot);
00256
00257 postProcess(tecplot);
00258
00259 closeStreams_(tecplot.count());
00260 }
00261
00262
00263
00269 class TecplotMesh : public concepts::OutputOperator {
00270 public:
00281 static void writeMesh(const concepts::Cell& cell,
00282 std::map<std::string, std::ostream*>& os,
00283 const concepts::Array<uint>& np,
00284 std::vector<uint>& cnt);
00294 template<class F>
00295 static void writeFormula(const concepts::Cell& cell,
00296 std::map<std::string, std::ostream*>& os,
00297 const concepts::Array<uint>& np,
00298 std::vector<uint>& cnt,
00299 const concepts::PiecewiseFormulaBase<F>* frm);
00306 template<int dim, class F>
00307 static void writeData
00308 (const concepts::Array<concepts::Point<Real, dim> >& coord,
00309 std::ostream& os, const F* values = 0);
00315 static void writeConnect(const concepts::Quad2d& quad, std::ostream& os,
00316 const concepts::Array<uint>& np,
00317 std::vector<uint>& cnt);
00318 protected:
00319 virtual std::ostream& info(std::ostream& os) const;
00320 private:
00321
00327 template<int dim>
00328 static void writeCoord_(concepts::Point<Real, dim> x, std::ostream& os);
00329
00330 };
00331
00332 template<class F>
00333 void TecplotMesh::writeFormula(const concepts::Cell& cell,
00334 std::map<std::string, std::ostream*>& os,
00335 const concepts::Array<uint>& np,
00336 std::vector<uint>& cnt,
00337 const concepts::PiecewiseFormulaBase<F>* frm)
00338 {
00339 DEBUGL(TecplotMeshWriteFormula_D, "cell = " << cell);
00340
00341
00342 const concepts::Quad2d* cellQ =
00343 dynamic_cast<const concepts::Quad2d*>(&cell);
00344 if (cellQ) {
00345
00346 const concepts::ArrayCoord<2> X
00347 (*cellQ,
00348 concepts::Array<Real>(np[0], 0, 1./(np[0]-1)),
00349 concepts::Array<Real>(np[1], 0, 1./(np[1]-1)));
00350 const concepts::Real2d* x = (const concepts::Real2d*)X;
00351
00352 concepts::Array<F> V(X.size()); F* v = (F*)V;
00353 for (uint i = X.size(); i--; )
00354 *v++ = (*frm)(cell.connector(), *x++);
00355 writeData(X, *os["data"], (const F*)V);
00356 writeConnect(*cellQ, *os["connect"], np, cnt);
00357 }
00358 }
00359
00360 template<int dim, class F>
00361 void TecplotMesh::writeData
00362 (const concepts::Array<concepts::Point<Real, dim> >& coord,
00363 std::ostream& os, const F* v) {
00364 const concepts::Point<Real, dim>* x =
00365 (const concepts::Point<Real, dim>*)coord;
00366 bool values = v != 0;
00367 for(uint i = coord.size(); i--; ) {
00368 writeCoord_(*x++, os);
00369 if (values) os << " " << concepts::OutputTecplot<F>(*v++);
00370 os << std::endl;
00371 }
00372 }
00373
00374 template<int dim>
00375 void TecplotMesh::writeCoord_(concepts::Point<Real, dim> x, std::ostream& os)
00376 {
00377 os << x[0] << " ";
00378 if (dim > 1) {
00379 os << x[1] << " ";
00380 if (dim > 2)
00381 os << x[2] << " ";
00382 }
00383 }
00384
00385 }
00386
00387 #endif // graphTecplot_hh
00388