CuboidMeshConstructor.cpp

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 #include "CuboidMeshConstructor.hpp"
00031 
00032 
00034 // Implementation
00036 
00037 
00038 template<unsigned DIM>
00039 void CuboidMeshConstructor<DIM>::ConstructHyperCube(TetrahedralMesh<1,1>& rMesh, unsigned width)
00040 {
00041     rMesh.ConstructLinearMesh(width);
00042 }
00043 
00044 template<unsigned DIM>
00045 void CuboidMeshConstructor<DIM>::ConstructHyperCube(TetrahedralMesh<2,2>& rMesh, unsigned width)
00046 {
00047     rMesh.ConstructRectangularMesh(width, width);
00048 }
00049 
00050 template<unsigned DIM>
00051 void CuboidMeshConstructor<DIM>::ConstructHyperCube(TetrahedralMesh<3,3>& rMesh, unsigned width)
00052 {
00053     rMesh.ConstructCuboid(width, width, width);
00054 }
00055 
00056 template<unsigned DIM>
00057 std::string CuboidMeshConstructor<DIM>::Construct(unsigned meshNum, double meshWidth)
00058 {
00059     mMeshWidth = meshWidth;
00060     assert(meshNum < 30); //Sanity
00061     const std::string mesh_dir = "ConvergenceMesh";
00062     OutputFileHandler output_file_handler(mesh_dir);
00063 
00064     // Create the mesh
00065     unsigned mesh_size = (unsigned) pow(2, meshNum+2); // number of elements in each dimension
00066     double scaling = mMeshWidth/(double) mesh_size;
00067     TetrahedralMesh<DIM,DIM> mesh;
00068     ConstructHyperCube(mesh, mesh_size);
00069     mesh.Scale(scaling, scaling, scaling);
00070     NumElements = mesh.GetNumElements();
00071     NumNodes = mesh.GetNumNodes();
00072     std::stringstream file_name_stream;
00073     file_name_stream << "cube_" << DIM << "D_2mm_" << NumElements << "_elements";
00074     std::string mesh_filename = file_name_stream.str();
00075 
00076     if (output_file_handler.IsMaster())
00077     {
00078         TrianglesMeshWriter<DIM,DIM> mesh_writer(mesh_dir, mesh_filename, false);
00079         mesh_writer.WriteFilesUsingMesh(mesh);
00080     }
00081     PetscTools::Barrier();
00082 
00083     std::string mesh_pathname = output_file_handler.GetOutputDirectoryFullPath() + mesh_filename;
00084 
00085     return mesh_pathname;
00086 }
00087 
00088 template<unsigned DIM>
00089 double CuboidMeshConstructor<DIM>::GetWidth()
00090 {
00091     return mMeshWidth;
00092 }
00093 
00094 
00096 // Explicit instantiation
00098 
00099 template class CuboidMeshConstructor<1>;
00100 template class CuboidMeshConstructor<2>;
00101 template class CuboidMeshConstructor<3>;

Generated on Tue Aug 4 16:10:22 2009 for Chaste by  doxygen 1.5.5