00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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
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);
00067 const std::string mesh_dir = "ConvergenceMesh";
00068 OutputFileHandler output_file_handler(mesh_dir);
00069
00070
00071 unsigned mesh_size = (unsigned) pow(2, meshNum+2);
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