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

graphics/matlabBinaryMeshGraphics.hh
Go to the documentation of this file.
00001 #ifndef MATLAB_BINARY_MESH_GRAPHICS_HH
00002 #define MATLAB_BINARY_MESH_GRAPHICS_HH
00003 
00004 #include "matrixBasis.hh"
00005 #include "basics/outputMatlab.hh"
00006 #include "basics/vectorsMatrices.hh"
00007 #include "basics/vectorsMatricesForward.hh"
00008 
00009 
00010 namespace graphics {
00011 /*
00012  * matlabBinaryMeshGraphics.hh
00013  *
00014  *  Created on: 2011
00015  *  Author:  Robert Gruhlke und Christian Heier
00016  */
00017 
00018 class MatlabBinaryMeshGraphics {
00019 public:
00020 
00024   MatlabBinaryMeshGraphics() {
00025   }
00026   ;
00027 
00029   virtual ~MatlabBinaryMeshGraphics() {
00030   }
00031   ;
00032 
00042   template<class G>
00043   static void writeMesh(const concepts::Cell& cell,
00044       MatrixBaseOutputCell<G>* bdc, const concepts::Array<uint>& np,
00045       bool boundary = false, bool coord = true);
00046 
00051   template<class G>
00052   static void writeAttributes(const concepts::Connector& cntr,
00053       MatrixBaseOutputCell<G>& bdc);
00054 
00055 private:
00056 
00061   template<class G>
00062   static void writeMesh_(const concepts::Quad2d& quad, const concepts::Array<
00063       uint>& np, std::map<std::string, concepts::DenseMatrix<G>*> map,
00064       MatrixBaseOutputCell<G>*& bdc, bool& boundary, bool& coord);
00065 
00070   template<class G>
00071   static void writeMesh_(const concepts::InfiniteQuad2d& quad,
00072       const concepts::Array<uint>& np, std::map<std::string,
00073           concepts::DenseMatrix<G>*> map,
00074       MatrixBaseOutputCell<G>*& bdc, bool& boundary, bool& coord);
00075 
00076   //writes the coords in data
00077   template<class G>
00078   static void writeCoord_(concepts::Real2d, MatrixBaseOutputCell<G>* bdc,
00079       uint dim = 2);
00080 
00081 };
00082 
00083 /*******************************************************
00084  * Here we start implementing the static class members *
00085  * that are used in base Quad Graphics, to store those *
00086  * attributes that do not need information about the   *
00087  * art of elements used in the space (mesh information)*
00088  * *****************************************************/
00089 
00090 template<class G>
00091 void MatlabBinaryMeshGraphics::writeCoord_(concepts::Real2d point,
00092     MatrixBaseOutputCell<G>* bdc, uint dim) {
00093 
00094   (bdc->getMapping())["x"]->operator()(0, bdc->indexOfPoints) = point[0];
00095   if (dim > 1)
00096     (bdc->getMapping())["y"]->operator()(0, bdc->indexOfPoints) = point[1];
00097   if (dim > 2)
00098     (bdc->getMapping())["z"]->operator()(0, bdc->indexOfPoints) = point[2];
00099   ++bdc->indexOfPoints;
00100 }
00101 
00102 /*First: implementation of writeAttributes*/
00103 
00107 template<class G>
00108 void MatlabBinaryMeshGraphics::writeAttributes(const concepts::Connector& cntr,
00109     MatrixBaseOutputCell<G>& bdc) {
00110   //Attribute of Cell
00111   bdc.getMapping()["Attr"]->operator()(0, bdc.indexOfAttributes++)
00112       = cntr.attrib().attrib();
00113 
00114   if(bdc.getMapping().find("vtxAttr")==bdc.getMapping().end()) return;
00115 
00116   const concepts::Connector2* cntr2 =
00117       dynamic_cast<const concepts::Connector2*> (&cntr);
00118   if (cntr2) {
00119     // Attributes of vertices
00120     if (bdc.getMapping()["vtxAttr"]) {
00121       const concepts::Connector0* vtx = 0;
00122       for (uint i = 0; (vtx = cntr2->vertex(i)); ++i)
00123         bdc.getMapping()["vtxAttr"]->operator()(0, bdc.indexOfVtxAttr++)
00124             = vtx->attrib().attrib();
00125     }
00126     return;
00127   }
00128 }
00129 
00130 /*Second: implementation of writeMesh*/
00131 
00132 template<class G>
00133 void MatlabBinaryMeshGraphics::writeMesh(const concepts::Cell& cell,
00134     MatrixBaseOutputCell<G>* bdc, const concepts::Array<uint>& np,
00135     bool boundary, bool coord) {
00136 
00137   // 2D quadrilaterial
00138   const concepts::Quad2d* cellQ =
00139       dynamic_cast<const concepts::Quad2d*> (&cell);
00140   if (cellQ) {
00141     writeMesh_(*cellQ, np, bdc->getMapping(), bdc, boundary, coord);
00142     return;
00143   }
00144 
00145   // 2D infinite quadrilaterial
00146   const concepts::InfiniteQuad2d* cellIQ =
00147       dynamic_cast<const concepts::InfiniteQuad2d*> (&cell);
00148   if (cellIQ) {
00149     writeMesh_(*cellIQ, np, bdc->getMapping(), bdc, boundary, coord);
00150     return;
00151   }
00152 
00153   throw conceptsException(concepts::MissingFeature("cell not supported"));
00154 }//end writeMesh
00155 
00161 template<class G>
00162 void MatlabBinaryMeshGraphics::writeMesh_(const concepts::Quad2d& quad,
00163     const concepts::Array<uint>& np, std::map<std::string,
00164         concepts::DenseMatrix<G>*> map,
00165     MatrixBaseOutputCell<G>*& bdc, bool& boundary, bool& coord) {
00166 
00167   if (coord) {
00168     conceptsAssert((bool)map["x"] && (bool)map["y"], concepts::Assertion());
00169 
00170     if (boundary) {
00171       // only coordinates lying on the edges
00172       for (uint i = 0; i < np[0] - 1; ++i)
00173         writeCoord_(quad.chi((Real) i / (np[0] - 1), 0), bdc);
00174       for (uint i = 0; i < np[1] - 1; ++i)
00175         writeCoord_(quad.chi(1., (Real) i / (np[1] - 1)), bdc);
00176       for (uint i = np[0] - 1; i > 0; --i)
00177         writeCoord_(quad.chi((Real) i / (np[0] - 1), 1.), bdc);
00178       for (uint i = np[1] - 1; i > 0; --i)
00179         writeCoord_(quad.chi(0, Real(i) / (np[1] - 1)), bdc);
00180     } else {
00181       for (uint j = 0; j < np[1]; ++j) {
00182         Real px = (Real) j / (np[1] - 1);
00183         for (uint i = 0; i < np[0]; ++i)
00184           writeCoord_(quad.chi((Real) i / (np[0] - 1), px), bdc);
00185       } // for j
00186     } // boundary
00187   } // coord
00188 
00189 
00190   //catch case that some matrices aren't initialized
00191   conceptsAssert((bool)map["edgemsh"], concepts::Assertion());
00192   conceptsAssert((bool)map["vtxmsh"], concepts::Assertion());
00193   conceptsAssert(boundary || (bool)map["msh"], concepts::Assertion());
00194 
00195   uint n;
00196 
00197   //bdc->counter = num of points before talking about this quad
00198   if (boundary) {
00199     n = 2 * (np[0] + np[1]) - 4;
00200 
00201     // FE mesh (represented by edges)
00202     for (uint i = 1; i < n; ++i) {
00203       map["edgemsh"]-> operator()(0, bdc->indexOfEdgeMesh) = bdc->counter
00204           + i;
00205       map["edgemsh"]-> operator()(1, bdc->indexOfEdgeMesh++)
00206           = bdc->counter + i + 1;
00207     }
00208     map["edgemsh"]-> operator()(0, bdc->indexOfEdgeMesh) = bdc->counter + n;
00209     map["edgemsh"]-> operator()(1, bdc->indexOfEdgeMesh++) = bdc->counter
00210         + 1;
00211 
00212     // FE mesh (represented by vertices)
00213     map["vtxmsh"]->operator()(0, bdc->indexOfVertexMesh) = bdc->counter + 1;
00214     map["vtxmsh"]->operator()(1, bdc->indexOfVertexMesh) = bdc->counter
00215         + np[0];
00216     map["vtxmsh"]->operator()(2, bdc->indexOfVertexMesh) = bdc->counter
00217         + np[0] + np[1] - 1;
00218     map["vtxmsh"]->operator()(3, bdc->indexOfVertexMesh) = bdc->counter + 2
00219         * np[1] + np[1] - 2;
00220     map["vtxmsh"]->operator()(4, bdc->indexOfVertexMesh++) = bdc->counter
00221         + 1;
00222   } else {
00223     n = np[0] * np[1];
00224     // write full Mesh (5 points, first and last the same)
00225     for (uint i = 1; i < np[0]; ++i)
00226       for (uint j = 1; j < np[1]; ++j) {
00227         map["msh"]->operator()(0, bdc->indexOfMesh) = bdc->counter + i
00228             + (j - 1) * np[0];
00229         map["msh"]->operator()(1, bdc->indexOfMesh) = bdc->counter + i
00230             + 1 + (j - 1) * np[0];
00231         map["msh"]->operator()(2, bdc->indexOfMesh) = bdc->counter + i
00232             + 1 + j * np[0];
00233         map["msh"]->operator()(3, bdc->indexOfMesh) = bdc->counter + i
00234             + j * np[0];
00235         map["msh"]->operator()(4, bdc->indexOfMesh++) = bdc->counter
00236             + i + (j - 1) * np[0];
00237       }
00238 
00239     //Write Edge Mesh
00240     for (uint i = 1; i < np[0]; ++i) {
00241       map["edgemsh"]->operator()(0, bdc->indexOfEdgeMesh) = bdc->counter
00242           + i;
00243       map["edgemsh"]->operator()(1, bdc->indexOfEdgeMesh++)
00244           = bdc->counter + i + 1;
00245     }
00246 
00247     for (uint i = 1; i < np[1]; ++i) {
00248       map["edgemsh"]->operator()(0, bdc->indexOfEdgeMesh) = bdc->counter
00249           + i * np[0];
00250       map["edgemsh"]->operator()(1, bdc->indexOfEdgeMesh++)
00251           = bdc->counter + (i + 1) * np[0];
00252     }
00253 
00254     for (uint i = 1; i < np[0]; ++i) {
00255       map["edgemsh"]->operator()(0, bdc->indexOfEdgeMesh) = bdc->counter
00256           + np[0] * np[1] - i + 1;
00257       map["edgemsh"]->operator()(1, bdc->indexOfEdgeMesh++)
00258           = bdc->counter + np[0] * np[1] - 1 - i + 1;
00259     }
00260 
00261     for (uint i = 1; i < np[1]; ++i) {
00262       map["edgemsh"]->operator()(0, bdc->indexOfEdgeMesh) = bdc->counter
00263           + np[0] * (np[1] - i) + 1;
00264       map["edgemsh"]->operator()(1, bdc->indexOfEdgeMesh++)
00265           = bdc->counter + np[0] * (np[1] - 1 - i) + 1;
00266     }
00267 
00268     //write vertexmesh not so many integrations point for plotting
00269     map["vtxmsh"]->operator()(0, bdc->indexOfVertexMesh) = bdc->counter + 1;
00270     map["vtxmsh"]->operator()(1, bdc->indexOfVertexMesh) = bdc->counter
00271         + np[0];
00272     map["vtxmsh"]->operator()(2, bdc->indexOfVertexMesh) = bdc->counter
00273         + np[0] * np[1];
00274     map["vtxmsh"]->operator()(3, bdc->indexOfVertexMesh) = bdc->counter
00275         + np[0] * (np[1] - 1) + 1;
00276     map["vtxmsh"]->operator()(4, bdc->indexOfVertexMesh++) = bdc->counter
00277         + 1;
00278 
00279     //FIXME EdgeAttribute testen?
00280   }
00281   if (map["edgAttr"])
00282     for (uint i = 0; i < (np[0] - 1); ++i) {
00283       map["edgAttr"]->operator()(0, bdc->indexOfEdgAttr + i)
00284           = quad.connector().edge(0)->attrib().attrib();
00285       map["edgAttr"]->operator()(0, bdc->indexOfEdgAttr + (np[0] - 1) + i)
00286           = quad.connector().edge(1)->attrib().attrib();
00287       map["edgAttr"]->operator()(0, bdc->indexOfEdgAttr + 2 * (np[0] - 1)
00288           + i) = quad.connector().edge(2)->attrib().attrib();
00289       map["edgAttr"]->operator()(0, bdc->indexOfEdgAttr + 3 * (np[0] - 1)
00290           + i) = quad.connector().edge(3)->attrib().attrib();
00291     }
00292   bdc->indexOfEdgAttr += (np[0] - 1) * 4;
00293 
00294   //counter should be increase for next quad
00295   bdc->counter += n;
00296 }
00297 
00301 template<class G>
00302 void MatlabBinaryMeshGraphics::writeMesh_(const concepts::InfiniteQuad2d& quad,
00303     const concepts::Array<uint>& np, std::map<std::string,
00304         concepts::DenseMatrix<G>*> map,
00305     MatrixBaseOutputCell<G>*& bdc, bool& boundary, bool& coord) {
00306   std::cout << "in Infinite Quad"<<std::endl;
00307 
00308   if (coord) {
00309     conceptsAssert((bool)map["x"] && (bool)map["y"], concepts::Assertion());
00310 
00311     if (boundary) {
00312       // left infinite edge, takes points with eta in [0,2]
00313       for (uint i = np[1] - 1; i > 0; --i)
00314         writeCoord_(quad.chi(0, Real(i) / (np[1] - 1) * 2), bdc);
00315       // finite edge
00316       for (uint i = 0; i < np[0] - 1; ++i)
00317         writeCoord_(quad.chi((Real) i / (np[0] - 1), 0), bdc);
00318       // right infinite edge
00319       for (uint i = 0; i < np[1]; ++i)
00320         writeCoord_(quad.chi(1., (Real) i / (np[1] - 1) * 2), bdc);
00321     } else {
00322       for (uint j = 0; j < np[1]; ++j) {
00323         Real py = (Real) j / (np[1] - 1) * 2;
00324         for (uint i = 0; i < np[0]; ++i)
00325           writeCoord_(quad.chi((Real) i / (np[0] - 1), py), bdc);
00326       } // for j
00327     } // boundary
00328   } // coord
00329 
00330   conceptsAssert((bool)map["edgemsh"], concepts::Assertion());
00331   conceptsAssert((bool)map["vtxmsh"], concepts::Assertion());
00332   conceptsAssert(boundary || (bool)map["msh"], concepts::Assertion());
00333 
00334   uint n;
00335 
00336   if (boundary) {
00337     //bdc->counter = num of points before talking about this quad
00338     if (boundary) {
00339       n = 2 * np[1] + np[0] - 2;
00340 
00341       //TODO TEST BOUNDARY CASE
00342       // FE mesh (represented by edges)
00343       for (uint i = 1; i < n - 1; ++i) {
00344         map["edgemsh"]-> operator()(0, bdc->indexOfEdgeMesh)
00345             = bdc->counter + i;
00346         map["edgemsh"]-> operator()(0, bdc->indexOfEdgeMesh++)
00347             = bdc->counter + i + 1;
00348       }
00349 
00350       //TODO TEST BOUNDARY CASE
00351       // FE mesh (represented by vertices)
00352       map["vtxmsh"]->operator()(0, bdc->indexOfVertexMesh) = bdc->counter
00353           + 1;
00354       map["vtxmsh"]->operator()(1, bdc->indexOfVertexMesh) = bdc->counter
00355           + np[1];
00356       map["vtxmsh"]->operator()(2, bdc->indexOfVertexMesh) = bdc->counter
00357           + np[0] + np[1] - 1;
00358       map["vtxmsh"]->operator()(3, bdc->indexOfVertexMesh) = bdc->counter
00359           + 2 * np[1] + np[0] - 2;
00360       map["vtxmsh"]->operator()(4, bdc->indexOfVertexMesh++)
00361           = bdc->counter + 2 * np[1] + np[0] - 2;
00362     }
00363 
00364   } else {
00365     n = np[0] * np[1];
00366     // write full Mesh (5 points, first and last the same)
00367     for (uint i = 1; i < np[0]; ++i)
00368       for (uint j = 1; j < np[1]; ++j) {
00369         map["msh"]->operator()(0, bdc->indexOfMesh) = bdc->counter + i
00370             + (j - 1) * np[0];
00371         map["msh"]->operator()(1, bdc->indexOfMesh) = bdc->counter + i
00372             + 1 + (j - 1) * np[0];
00373         map["msh"]->operator()(2, bdc->indexOfMesh) = bdc->counter + i
00374             + 1 + j * np[0];
00375         map["msh"]->operator()(3, bdc->indexOfMesh) = bdc->counter + i
00376             + j * np[0];
00377         map["msh"]->operator()(4, bdc->indexOfMesh++) = bdc->counter
00378             + i + (j - 1) * np[0];
00379       }
00380 
00381     //Write Edge Mesh
00382 
00383     // left infinite edge
00384     for (uint i = 1; i < np[0]; ++i) {
00385       map["edgemsh"]->operator()(0, bdc->indexOfEdgeMesh) = bdc->counter
00386           + np[0] * (np[1] - i) + 1;
00387       map["edgemsh"]->operator()(1, bdc->indexOfEdgeMesh++)
00388           = bdc->counter + np[0] * (np[1] - 1 - i) + 1;
00389     }
00390 
00391     // finite edge
00392     for (uint i = 1; i < np[1]; ++i) {
00393       map["edgemsh"]->operator()(0, bdc->indexOfEdgeMesh) = bdc->counter
00394           + i;
00395       map["edgemsh"]->operator()(1, bdc->indexOfEdgeMesh++)
00396           = bdc->counter + i + 1;
00397     }
00398 
00399     // right infinite edge
00400     for (uint i = 1; i < np[0]; ++i) {
00401       map["edgemsh"]->operator()(0, bdc->indexOfEdgeMesh) = bdc->counter
00402           + np[0] * i;
00403       map["edgemsh"]->operator()(1, bdc->indexOfEdgeMesh++)
00404           = bdc->counter + np[0] * (i + 1);
00405     }
00406     //write vertexmesh not so many integrations point for plotting
00407     map["vtxmsh"]->operator()(0, bdc->indexOfVertexMesh) = bdc->counter
00408         + np[0] * (np[1] - 1) + 1;
00409     map["vtxmsh"]->operator()(1, bdc->indexOfVertexMesh) = bdc->counter + 1
00410         + np[0];
00411     map["vtxmsh"]->operator()(2, bdc->indexOfVertexMesh) = bdc->counter
00412         + np[0];
00413     map["vtxmsh"]->operator()(3, bdc->indexOfVertexMesh) = bdc->counter
00414         + np[0] * np[1];
00415     map["vtxmsh"]->operator()(4, bdc->indexOfVertexMesh++) = bdc->counter
00416         + np[0] * (np[1] - 1) + 1;
00417 
00418   }//else
00419 
00420   //counter should be increase for next quad
00421   bdc->counter += n;
00422 }
00423 
00424 }//END namespace graphics
00425 
00426 #endif //MATLAB_BINARY_MESH_GRAPHICS_HH

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