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 #include "CuboidMeshConstructor.hpp"
00031
00032
00034
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);
00061 const std::string mesh_dir = "ConvergenceMesh";
00062 OutputFileHandler output_file_handler(mesh_dir);
00063
00064
00065 unsigned mesh_size = (unsigned) pow(2, meshNum+2);
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
00098
00099 template class CuboidMeshConstructor<1>;
00100 template class CuboidMeshConstructor<2>;
00101 template class CuboidMeshConstructor<3>;