CuboidMeshConstructor.hpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2009
00004 
00005 University of Oxford means the Chancellor, Masters and Scholars of the
00006 University of Oxford, having an administrative office at Wellington
00007 Square, Oxford OX1 2JD, UK.
00008 
00009 This file is part of Chaste.
00010 
00011 Chaste is free software: you can redistribute it and/or modify it
00012 under the terms of the GNU Lesser General Public License as published
00013 by the Free Software Foundation, either version 2.1 of the License, or
00014 (at your option) any later version.
00015 
00016 Chaste is distributed in the hope that it will be useful, but WITHOUT
00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
00019 License for more details. The offer of Chaste under the terms of the
00020 License is subject to the License being interpreted in accordance with
00021 English Law and subject to any action against the University of Oxford
00022 being under the jurisdiction of the English Courts.
00023 
00024 You should have received a copy of the GNU Lesser General Public License
00025 along with Chaste. If not, see <http://www.gnu.org/licenses/>.
00026 
00027 */
00028 
00029 
00030 #ifndef CUBOIDMESHCONSTRUCTOR_HPP_
00031 #define CUBOIDMESHCONSTRUCTOR_HPP_
00032 
00033 #include "TrianglesMeshWriter.hpp"
00034 #include "OutputFileHandler.hpp"
00035 #include "PetscTools.hpp"
00036 #include "TetrahedralMesh.hpp"
00037 
00038 //const double mesh_width = 0.2; // cm
00039 
00040 template<unsigned DIM>
00041 class CuboidMeshConstructor
00042 {
00043 private:
00044 
00045     void ConstructHyperCube(TetrahedralMesh<1,1> &rMesh, unsigned width)
00046     {
00047         rMesh.ConstructLinearMesh(width);
00048     }
00049     void ConstructHyperCube(TetrahedralMesh<2,2> &rMesh, unsigned width)
00050     {
00051         rMesh.ConstructRectangularMesh(width, width);
00052     }
00053     void ConstructHyperCube(TetrahedralMesh<3,3> &rMesh, unsigned width)
00054     {
00055         rMesh.ConstructCuboid(width, width, width);
00056     }
00057 
00058 public:
00059     double mMeshWidth;
00060     unsigned NumElements;
00061     unsigned NumNodes;
00062 
00063     std::string Construct(unsigned meshNum, double meshWidth)
00064     {
00065         mMeshWidth=meshWidth;
00066         assert(meshNum < 30); //Sanity
00067         const std::string mesh_dir = "ConvergenceMesh";
00068         OutputFileHandler output_file_handler(mesh_dir);
00069 
00070         // create the mesh
00071         unsigned mesh_size = (unsigned) pow(2, meshNum+2); // number of elements in each dimension
00072         double scaling = mMeshWidth/(double) mesh_size;
00073         TetrahedralMesh<DIM,DIM> mesh;
00074         ConstructHyperCube(mesh, mesh_size);
00075         mesh.Scale(scaling, scaling, scaling);
00076         NumElements = mesh.GetNumElements();
00077         NumNodes = mesh.GetNumNodes();
00078         std::stringstream file_name_stream;
00079         file_name_stream<< "cube_" << DIM << "D_2mm_"<< NumElements <<"_elements";
00080         std::string mesh_filename = file_name_stream.str();
00081 
00082         if (output_file_handler.IsMaster())
00083         {
00084             TrianglesMeshWriter<DIM,DIM> mesh_writer(mesh_dir, mesh_filename, false);
00085             mesh_writer.WriteFilesUsingMesh(mesh);
00086         }
00087         PetscTools::Barrier();
00088 
00089         std::string mesh_pathname = output_file_handler.GetOutputDirectoryFullPath()
00090                                   + mesh_filename;
00091 
00092         return mesh_pathname;
00093     }
00094 
00095     double GetWidth()
00096     {
00097         return mMeshWidth;
00098     }
00099 
00100 };
00101 
00102 #endif /*CUBOIDMESHCONSTRUCTOR_HPP_*/

Generated on Wed Mar 18 12:51:52 2009 for Chaste by  doxygen 1.5.5