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

graphics/matlabBinaryGraphics.hh
Go to the documentation of this file.
00001 #ifndef MATLAB_BINARY_HH
00002 #define MATLAB_BINARY_HH
00003 
00004 #include "matrixBasis.hh"
00005 #include "matfile/matfileOutput.hh"
00006 #include "basics/outputMatlab.hh"
00007 #include "basics/vectorsMatrices.hh"
00008 #include "basics/vectorsMatricesForward.hh"
00009 
00010 //namespace concepts {  
00011 //  // forward declaration
00012 //  template<class F>
00013 //  class Formula;
00014 //}
00015 
00016 
00017 namespace graphics {
00018 
00019   class MatlabBinaryGraphics {
00020 
00021   public:
00022 
00023     static uint noPoints;
00024 
00028     MatlabBinaryGraphics() {
00029     };
00030 
00036     template<class G>
00037     MatlabBinaryGraphics(const concepts::Space<G>& spc,
00038         const std::string filename, const uint dim = 2);
00039 
00045     MatlabBinaryGraphics(concepts::Mesh& msh, const std::string filename,
00046         const uint dim = 2, const uint points = noPoints);
00047 
00055     template<class G, class F>
00056     MatlabBinaryGraphics(const concepts::Space<G>& spc,
00057         const std::string filename, const concepts::Vector<F>& sol,
00058         const concepts::ElementFunction<F, G>* fun = 0, const uint dim = 2);
00059 
00067     template<class G, class F>
00068     MatlabBinaryGraphics(const concepts::Space<G>& spc,
00069         const std::string filename, std::vector<concepts::Vector<F> >& sol,
00070         int numberOfSolution, const concepts::ElementFunction<F, G>* fun = 0,
00071         const uint dim = 2);
00072 
00079     template<class G, class F>
00080     MatlabBinaryGraphics(const concepts::Space<G>& spc,
00081         const std::string filename, const concepts::ElementFormula<F, G>& frm,
00082         const uint dim = 2);
00083 
00084     virtual ~MatlabBinaryGraphics() {
00085     }
00086     ;
00087 
00093     template<class G>
00094     inline void clearMapping(
00095         std::map<std::string, concepts::DenseMatrix<G>*>& dense_ptr_) {
00096 
00097       delete (dense_ptr_["x"]);
00098 
00099       if (dim_ > 1)
00100         delete (dense_ptr_["y"]);
00101       if (dim_ > 2)
00102         delete (dense_ptr_["z"]);
00103 
00104       //FIXME DIMENSION 3: add deleting FaceMesh
00105 
00106       if (dim_ > 1) {
00107         delete (dense_ptr_["edgemsh"]);
00108         delete (dense_ptr_["vtxmsh"]);
00109       }
00110       delete (dense_ptr_["Attr"]);
00111       delete (dense_ptr_["edgAttr"]);
00112 
00113       //store informations to plot solution
00114       if (data_) {
00115         delete (dense_ptr_["p"]);
00116         delete (dense_ptr_["u"]);
00117         // Cell attribute on each quadrature points
00118         delete (dense_ptr_["pattr"]);
00119         delete (dense_ptr_["w"]);
00120         delete (dense_ptr_["msh"]);
00121       }
00122       dense_ptr_.clear();
00123     }
00124     ;
00125 
00131     template<class G, class F>
00132     void operator()(const concepts::Space<G>& spc,
00133         const concepts::Vector<F>& sol,
00134         const concepts::ElementFunction<F, G>* fun = 0);
00135 
00140     template<class G, class F>
00141     void operator()(const concepts::Space<G>& spc,
00142         const concepts::Formula<F>& frm);
00143 
00148     template<class F>
00149     void operator()(concepts::Mesh& msh, const concepts::Formula<F>& frm,
00150         const uint points = 5) {
00151     }
00152     ;
00153 
00154   private:
00155 
00162     template<class G>
00163     void createMatrices_(bool data, uint count[], std::map<std::string,
00164         concepts::DenseMatrix<G>*>& dense_ptr_);
00165 
00172     template<class G, class F>
00173     void storeData_(bool data, std::string filename, std::map<std::string,
00174         concepts::DenseMatrix<G>*>& dense_ptr_,
00175         concepts::DenseMatrix<F>* functionValue = 0,
00176         concepts::DenseMatrix<F>** function_ptr_ = 0, int numOfFunction = 0);
00177 
00179     uint data_;
00180 
00182     uint dim_;
00183 
00185     uint outputDimension_;
00186   };
00187 
00188   template<class G, class F>
00189   MatlabBinaryGraphics::MatlabBinaryGraphics(const concepts::Space<G>& spc,
00190       const std::string filename, const concepts::Vector<F>& sol,
00191       const concepts::ElementFunction<F, G>* fun, const uint dim) {
00192 
00193     dim_ = dim;
00194     // Post processor (global)
00195     concepts::GlobalPostprocess<G> postProcess(spc);
00196 
00197     //output dimension for ex. n = 1 if fun = Value or n = 2 if fun = Grad
00198     if (fun)
00199       outputDimension_ = fun->n();
00200     else
00201       outputDimension_ = 1;
00202 
00203     //declare mapping
00204     std::map<std::string, concepts::DenseMatrix<G>*> dense_ptr_;
00205 
00206     //declare FunctionValues u
00207     concepts::DenseMatrix<F>* functionValue;
00208 
00209     // Post processor on cell
00210     MatrixBaseDataCell<F, G> bdc(dense_ptr_, functionValue, sol, fun);
00211 
00212     //calculate size of the matrices / size of data
00213     postProcess(bdc);
00214 
00215     //Now the we know the size of the matrices, so create them.
00216     createMatrices_(true, bdc.dimensionsOfMatrices, dense_ptr_);
00217 
00218     //Now the we know the number of evaluations of the function, so create the valuevector.
00219     functionValue = new concepts::DenseMatrix<F>(outputDimension_,
00220         bdc.dimensionsOfMatrices[0]);
00221 
00222     //the MatrixBaseDataCell should know that everything is counted i.e. it can read data in the matrices
00223     bdc.counted = true;
00224 
00225     //run GlobalPostprocess with bdc to fill the concepts::DenseMatrix<> with mesh/solution informations.
00226     postProcess(bdc);
00227 
00228     //store the matrices
00229     storeData_(true, filename, dense_ptr_, functionValue);
00230 
00231     //deletes dense matrix pointer
00232     delete (functionValue);
00233 
00234     //Deletes the Dense matrices in the mapping
00235     clearMapping(dense_ptr_);
00236   }
00237   //TODO
00238   template<class G, class F>
00239   MatlabBinaryGraphics::MatlabBinaryGraphics(const concepts::Space<G>& spc,
00240       const std::string filename, std::vector<concepts::Vector<F> >& sol,
00241       int numOfFunction, const concepts::ElementFunction<F, G>* fun,
00242       const uint dim) {
00243 
00244     dim_ = dim;
00245 
00246     // Post processor (global)
00247     concepts::GlobalPostprocess<G> postProcess(spc);
00248 
00249     //output dimension for ex. n = 1 if fun = Value or n = 2 if fun = Grad
00250     if (fun)
00251       outputDimension_ = fun->n();
00252     else
00253       outputDimension_ = 1;
00254 
00255     //declare mapping
00256     std::map<std::string, concepts::DenseMatrix<G>*> dense_ptr_;
00257 
00258     //declare mapping
00259     concepts::DenseMatrix<F>* function_ptr[numOfFunction];
00260 
00261     // Post processor on cell
00262     MatrixBaseDataCell<F, G> bdc(dense_ptr_, function_ptr[0], sol[0], fun);
00263 
00264     //calculate size of the matrices / size of data
00265     postProcess(bdc);
00266 
00267 
00268     //Now the we know the size of the matrices, so create them.
00269     createMatrices_(true, bdc.dimensionsOfMatrices, dense_ptr_);
00270 
00271     //Now the we know the number of evaluations of the function, so create the valuevectors.
00272     for (int i = 0; i < numOfFunction; ++i)
00273       function_ptr[i] = new concepts::DenseMatrix<F>(outputDimension_,
00274           bdc.dimensionsOfMatrices[0]);
00275 
00276 
00277     //the MatrixBaseDataCell should know that everything is counted i.e. it can read data in the matrices
00278     bdc.counted = true;
00279 
00280     MatrixSolutionEvaluationCell<F, G> sec(dense_ptr_, function_ptr[0],
00281         &(sol[0]), fun);
00282 
00283     for (uint i = 0; i < 4; ++i)
00284       sec.dimensionsOfMatrices[i] = bdc.dimensionsOfMatrices[i];
00285     sec.counted = true;
00286 
00287     //run GlobalPostprocess with bdc to fill the concepts::DenseMatrix<> with solution informations.
00288     postProcess(bdc);
00289 
00290     for (int i = 0; i < numOfFunction; i++) {
00291       sec.setSolVec(&sol[i]);
00292       sec.setFunValue(function_ptr[i]);
00293       postProcess(sec);
00294       sec.resetCounter();
00295     }
00296 
00297     //store the matrices
00298     storeData_<G, F> (true, filename, dense_ptr_, 0, function_ptr,
00299         numOfFunction);
00300 
00301     //deletes dense matrix pointer
00302     for (int i = 0; i < numOfFunction; ++i)
00303       delete (function_ptr[i]);
00304 
00305     //Deletes the Dense matrices in the mapping
00306     clearMapping(dense_ptr_);
00307   }
00308 
00309   template<class G>
00310   MatlabBinaryGraphics::MatlabBinaryGraphics(const concepts::Space<G>& spc,
00311       const std::string filename, const uint dim) {
00312 
00313     dim_ = dim;
00314     // Post processor (global)
00315     concepts::GlobalPostprocess<G> postProcess(spc);
00316 
00317     //declare mapping
00318     std::map<std::string, concepts::DenseMatrix<G>*> dense_ptr_;
00319 
00320     // Post processor on cell
00321     MatrixBaseMeshCell bdc(dense_ptr_, dim_);
00322 
00323     //calculate size of the matrices / size of data
00324     postProcess(bdc);
00325 
00326     //Now we know the size of the matrices, so create them.
00327     createMatrices_(false, bdc.dimensionsOfMatrices, dense_ptr_);
00328 
00329     //the MatrixBaseMeshCell should know that everything is counted i.e. it can read data in the matrices
00330     bdc.counted = true;
00331 
00332     //run GlobalPostprocess with bdc to fill the concepts::DenseMatrix<> with mesh/solution informations.
00333     postProcess(bdc);
00334 
00335     //store the matrices
00336     storeData_<G, Real> (true, filename, dense_ptr_);
00337 
00338     //Deletes the Dense matrices in the mapping
00339     clearMapping(dense_ptr_);
00340   }
00341 
00342   template<class G, class F>
00343   MatlabBinaryGraphics::MatlabBinaryGraphics(const concepts::Space<G>& spc,
00344       const std::string filename, const concepts::ElementFormula<F, G>& frm,
00345       const uint dim) {
00346 
00347     //save dimension
00348     dim_ = dim;
00349 
00350     //output dimension for ex. n = 1 if fun = Value or n = 2 if fun = Grad
00351     outputDimension_ = Size<F>::n();
00352 
00353     // Post processor (global)
00354     concepts::GlobalPostprocess<G> postProcess(spc);
00355 
00356     //declare mapping
00357     std::map<std::string, concepts::DenseMatrix<G>*> dense_ptr_;
00358 
00359     //declare FunctionValues u
00360     concepts::DenseMatrix<F>* functionValue;
00361 
00362     // Post processor on cell
00363     MatrixBaseElementFormulaCell<F, G>
00364         bdc(dense_ptr_, functionValue, dim_, frm);
00365 
00366     //calculate size of the matrices / size of data
00367     postProcess(bdc);
00368 
00369     //Now we know the size of the matrices, so lets inatialize them.
00370     createMatrices_(true, bdc.dimensionsOfMatrices, dense_ptr_);
00371 
00372     //Now the we know the number of evaluations of the function, so create the valuevector.
00373     functionValue = new concepts::DenseMatrix<F>(outputDimension_,
00374         bdc.dimensionsOfMatrices[0]);
00375 
00376     //the MatrixBaseMeshCell should know that everything is counted i.e. it can read data in the matrices
00377     bdc.counted = true;
00378 
00379     //run GlobalPostprocess with bdc to fill the concepts::DenseMatrix<> with mesh/solution informations.
00380     postProcess(bdc);
00381 
00382     //store the matrices
00383     storeData_(true, filename, dense_ptr_, functionValue);
00384 
00385     //Delete the Dense matrices in the mapping and function value
00386     delete (functionValue);
00387     clearMapping(dense_ptr_);
00388   }
00389 
00390   template<class G, class F>
00391   void MatlabBinaryGraphics::operator()(const concepts::Space<G>& spc,
00392       const concepts::Vector<F>& sol,
00393       const concepts::ElementFunction<F, G>* fun) {
00394   }
00395 
00396   template<class G, class F>
00397   void MatlabBinaryGraphics::operator()(const concepts::Space<G>& spc,
00398       const concepts::Formula<F>& frm) {
00399   }
00400 
00401   template<class G>
00402   void MatlabBinaryGraphics::createMatrices_(bool data, uint count[], std::map<
00403       std::string, concepts::DenseMatrix<G>*>& dense_ptr_) {
00404 
00405     data_ = data;
00406     // coordinates
00407 
00408     dense_ptr_.insert(std::pair<std::string, concepts::DenseMatrix<G>*>("x",
00409         new concepts::DenseMatrix<G>(1, count[0])));
00410     if (dim_ > 1)
00411       dense_ptr_.insert(std::pair<std::string, concepts::DenseMatrix<G>*>("y",
00412           new concepts::DenseMatrix<G>(1, count[0])));
00413     if (dim_ > 2)
00414       dense_ptr_.insert(std::pair<std::string, concepts::DenseMatrix<G>*>("z",
00415           new concepts::DenseMatrix<G>(1, count[0])));
00416 
00417     //FIXME DIMENSION 3: add FaceMesh
00418 
00419     dense_ptr_.insert(std::pair<std::string, concepts::DenseMatrix<G>*>(
00420         "edgAttr", new concepts::DenseMatrix<G>(1, count[2])));
00421 
00422     if (dim_ > 1) {
00423       dense_ptr_.insert(std::pair<std::string, concepts::DenseMatrix<G>*>(
00424           "edgemsh", new concepts::DenseMatrix<G>(2, count[2])));
00425       dense_ptr_.insert(std::pair<std::string, concepts::DenseMatrix<G>*>(
00426           "vtxmsh", new concepts::DenseMatrix<G>(5, count[3])));
00427     }
00428     dense_ptr_.insert(std::pair<std::string, concepts::DenseMatrix<G>*>("Attr",
00429         new concepts::DenseMatrix<G>(1, count[3])));
00430 
00431     //store informations to plot solution
00432     if (data) {
00433       dense_ptr_.insert(std::pair<std::string, concepts::DenseMatrix<G>*>("p",
00434           new concepts::DenseMatrix<G>(2, count[3])));
00435       dense_ptr_.insert(std::pair<std::string, concepts::DenseMatrix<G>*>("u",
00436           new concepts::DenseMatrix<G>(outputDimension_, count[0])));
00437       // Cell attribute on each quadrature points
00438       dense_ptr_.insert(std::pair<std::string, concepts::DenseMatrix<G>*>(
00439           "pattr", new concepts::DenseMatrix<G>(1, count[0])));
00440       dense_ptr_.insert(std::pair<std::string, concepts::DenseMatrix<G>*>("w",
00441           new concepts::DenseMatrix<G>(1, count[0])));
00442       dense_ptr_.insert(std::pair<std::string, concepts::DenseMatrix<G>*>(
00443           "msh", new concepts::DenseMatrix<G>(5, count[1])));
00444     }
00445 
00446   }//end Create matrices
00447 
00448 
00449   //Save the matrices that hold informations
00450   template<class G, class F>
00451   void MatlabBinaryGraphics::storeData_(bool data, std::string filename,
00452       std::map<std::string, concepts::DenseMatrix<G>*>& dense_ptr_,
00453       concepts::DenseMatrix<F>* functionValue,
00454       concepts::DenseMatrix<F>** function_ptr_, int numOfFunction) {
00455 
00456     concepts::MatfileOutput mo(filename);
00457 
00458     //Save coord
00459     mo.addDense(dense_ptr_["x"], "x");
00460     if (dim_ > 1)
00461       mo.addDense(dense_ptr_["y"], "y");
00462     if (dim_ > 2)
00463       mo.addDense(dense_ptr_["z"], "z");
00464 
00465     //FIXME DIMENSION 3: add FaceMesh
00466 
00467     mo.addDense(dense_ptr_["edgAttr"], "edgAttr");
00468     mo.addDense(dense_ptr_["Attr"], "Attr");
00469 
00470     if (dim_ > 1) {
00471       mo.addDense(dense_ptr_["edgemsh"], "edgemsh");
00472       mo.addDense(dense_ptr_["vtxmsh"], "vtxmsh");
00473 
00474     }
00475 
00476     //store informations to plot solution
00477     if (data_) {
00478       mo.addDense(dense_ptr_["p"], "p");
00479       if (functionValue) {
00480         mo.addDense(functionValue, "u");
00481       }
00482       mo.addDense(dense_ptr_["pattr"], "pattr");
00483       mo.addDense(dense_ptr_["w"], "w");
00484       mo.addDense(dense_ptr_["msh"], "msh");
00485     }//ENDIF
00486 
00487     if (numOfFunction)
00488       for (int i = 0; i < numOfFunction; ++i) {
00489         stringstream streamName;
00490         streamName << "u" << i;
00491         mo.addDense(function_ptr_[i], streamName.str());
00492       }
00493 
00494     //close file
00495     mo.closeMatfile();
00496 
00497   }//end store data
00498 
00499 
00500 } // namespace graphics
00501 
00502 
00503 #endif // graphBinMatlab_hh

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