def _build_regular_mesh_dict(self, maxArea=1000, is_segments=True, save=False, geo=None): # make a normalised mesh # pretty regular size, with some segments thrown in. # don't pass in the geo ref. # it is applied in domain m = Mesh() #geo_reference=geo) m.addUserVertex(0, 0) m.addUserVertex(1.0, 0) m.addUserVertex(0, 1.0) m.addUserVertex(1.0, 1.0) m.auto_segment(alpha=100) if is_segments: dict = {} dict['points'] = [[.10, .10], [.90, .20]] dict['segments'] = [[0, 1]] dict['segment_tags'] = ['wall1'] m.addVertsSegs(dict) dict = {} dict['points'] = [[.10, .90], [.40, .20]] dict['segments'] = [[0, 1]] dict['segment_tags'] = ['wall2'] m.addVertsSegs(dict) dict = {} dict['points'] = [[.20, .90], [.60, .60]] dict['segments'] = [[0, 1]] dict['segment_tags'] = ['wall3'] m.addVertsSegs(dict) dict = {} dict['points'] = [[.60, .20], [.90, .90]] dict['segments'] = [[0, 1]] dict['segment_tags'] = ['wall4'] m.addVertsSegs(dict) m.generateMesh(mode="Q", maxArea=maxArea, minAngle=20.0) if save is True: m.export_mesh_file("aaaa.tsh") mesh_dict = m.Mesh2IOTriangulationDict() #Add vert attribute info to the mesh mesh_dict['vertex_attributes'] = [] # There has to be a better way of doing this.. for vertex in mesh_dict['vertices']: mesh_dict['vertex_attributes'].append([10.0]) return mesh_dict
def _build_regular_mesh_dict(self, maxArea=1000, is_segments=True, save=False, geo=None): # make a normalised mesh # pretty regular size, with some segments thrown in. # don't pass in the geo ref. # it is applied in domain m = Mesh() #geo_reference=geo) m.addUserVertex(0,0) m.addUserVertex(1.0,0) m.addUserVertex(0,1.0) m.addUserVertex(1.0,1.0) m.auto_segment(alpha = 100 ) if is_segments: dict = {} dict['points'] = [[.10,.10],[.90,.20]] dict['segments'] = [[0,1]] dict['segment_tags'] = ['wall1'] m.addVertsSegs(dict) dict = {} dict['points'] = [[.10,.90],[.40,.20]] dict['segments'] = [[0,1]] dict['segment_tags'] = ['wall2'] m.addVertsSegs(dict) dict = {} dict['points'] = [[.20,.90],[.60,.60]] dict['segments'] = [[0,1]] dict['segment_tags'] = ['wall3'] m.addVertsSegs(dict) dict = {} dict['points'] = [[.60,.20],[.90,.90]] dict['segments'] = [[0,1]] dict['segment_tags'] = ['wall4'] m.addVertsSegs(dict) m.generateMesh(mode = "Q", maxArea = maxArea, minAngle=20.0) if save is True: m.export_mesh_file("aaaa.tsh") mesh_dict = m.Mesh2IOTriangulationDict() #Add vert attribute info to the mesh mesh_dict['vertex_attributes'] = [] # There has to be a better way of doing this.. for vertex in mesh_dict['vertices']: mesh_dict['vertex_attributes'].append([10.0]) return mesh_dict
def test_ungenerateFileLoading(self): fileName = tempfile.mktemp(".txt") file = open(fileName,"w") file.write(" 1 ?? ??\n\ 0.0 0.0\n\ 1.0 0.0\n\ 1.0 1.0\n\ 0.0 1.0\n\ 0.0 0.0\n\ END\n\ 2 ?? ??\n\ 10.0 10.0\n\ 10.0 20.0\n\ 20.0 20.0\n\ 10.0 10.0\n\ END\n\ END\n") file.close() a = Vertex (0.0, 0.0) #, attributes = [1.1]) b = Vertex (0.0, 40.0) #, attributes = [1.2]) c = Vertex (40.0,40.0) #, attributes = [1.3]) d = Vertex (40.0,0.0) #, attributes = [1.4]) s1 = Segment(a,b) s2 = Segment(b,c) s3 = Segment(c,d) s4 = Segment(d,a) m = Mesh(userVertices=[a,b,c,d], userSegments=[s1,s2,s3,s4]) dict = load_ungenerate(fileName) #os.remove(fileName) tag = "DSG" Segment.set_default_tag(tag) m.addVertsSegs(dict) # have to reset this , since it's a class attribute Segment.set_default_tag("") self.assertTrue(len(m.userSegments) ==11, 'Wrong segment list length.') self.assertTrue(len(m.userVertices) == 11, 'Wrong vertex list length.') self.assertTrue(m.userSegments[10].vertices[0] == m.userVertices[10], 'bad vertex on segment.') self.assertTrue(m.userSegments[10].vertices[1] == m.userVertices[8], 'Bad segment.') self.assertTrue(m.userSegments[10].tag == tag, 'wrong tag.') ## let's test the method a = Vertex (0.0, 0.0) #, attributes = [1.1]) b = Vertex (0.0, 40.0) #, attributes = [1.2]) c = Vertex (40.0,40.0) #, attributes = [1.3]) d = Vertex (40.0,0.0) #, attributes = [1.4]) s1 = Segment(a,b) s2 = Segment(b,c) s3 = Segment(c,d) s4 = Segment(d,a) m = Mesh(userVertices=[a,b,c,d], userSegments=[s1,s2,s3,s4]) tag = "DSG" initial_tag = "PIG" Segment.set_default_tag(initial_tag) m.import_ungenerate_file(fileName, tag=tag) os.remove(fileName) self.assertTrue(Segment.get_default_tag() == initial_tag, 'Wrong segment list length.') # have to reset this , since it's a class attribute Segment.set_default_tag("") self.assertTrue(len(m.userSegments) ==11, 'Wrong segment list length.') self.assertTrue(len(m.userVertices) == 11, 'Wrong vertex list length.') self.assertTrue(m.userSegments[10].vertices[0] == m.userVertices[10], 'bad vertex on segment.') self.assertTrue(m.userSegments[10].vertices[1] == m.userVertices[8], 'Bad segment.') self.assertTrue(m.userSegments[10].tag == tag, 'wrong tag.')
def test_import_ungenerate_file_different_region_tags(self): fileName = tempfile.mktemp(".txt") file = open(fileName,"w") file.write(" 1 ?? ??\n\ 10.0 10.0\n\ 11.0 10.0\n\ 11.0 11.0\n\ 10.0 11.0\n\ 10.0 10.0\n\ END\n\ 2 ?? ??\n\ 20.0 20.0\n\ 20.0 30.0\n\ 30.0 30.0\n\ END\n\ END\n") file.close() a = Vertex (0.0, 0.0) #, attributes = [1.1]) b = Vertex (0.0, 40.0) #, attributes = [1.2]) c = Vertex (40.0,40.0) #, attributes = [1.3]) d = Vertex (40.0,0.0) #, attributes = [1.4]) s1 = Segment(a,b) s2 = Segment(b,c) s3 = Segment(c,d) s4 = Segment(d,a) m = Mesh(userVertices=[a,b,c,d], userSegments=[s1,s2,s3,s4]) dict = load_ungenerate(fileName) #os.remove(fileName) tag = "DSG" Segment.set_default_tag(tag) m.addVertsSegs(dict) self.assertTrue(len(m.userSegments) ==11, 'Wrong segment list length.') self.assertTrue(len(m.userVertices) == 11, 'Wrong vertex list length.') # Test the method a = Vertex (0.0, 0.0) #, attributes = [1.1]) b = Vertex (0.0, 40.0) #, attributes = [1.2]) c = Vertex (40.0,40.0) #, attributes = [1.3]) d = Vertex (40.0,0.0) #, attributes = [1.4]) s1 = Segment(a,b) s2 = Segment(b,c) s3 = Segment(c,d) s4 = Segment(d,a) m = Mesh(userVertices=[a,b,c,d], userSegments=[s1,s2,s3,s4]) tag = "DSG" initial_tag = "PIG" Segment.set_default_tag(initial_tag) m.import_ungenerate_file(fileName, tag=tag, region_tag=["swamp","coastalp"]) os.remove(fileName) self.assertTrue(Segment.get_default_tag() == initial_tag, 'Wrong segment list length.') m.export_mesh_file("swamp.tsh") #print "m.userSegments",m.userSegments self.assertTrue(len(m.userSegments) ==11, 'Wrong segment list length.') self.assertTrue(len(m.userVertices) == 11, 'Wrong vertex list length.') self.assertTrue(len(m.regions) == 2, 'Wrong regions list length.') self.assertTrue(m.regions[0].getTag() == "swamp", 'Wrong regions tag.') self.assertTrue(m.regions[1].getTag() == "coastalp", 'Wrong regions 1 tag.') # have to reset this , since it's a class attribute Segment.set_default_tag("")
def test_ungenerateFileLoading(self): fileName = tempfile.mktemp(".txt") file = open(fileName, "w") file.write(" 1 ?? ??\n\ 0.0 0.0\n\ 1.0 0.0\n\ 1.0 1.0\n\ 0.0 1.0\n\ 0.0 0.0\n\ END\n\ 2 ?? ??\n\ 10.0 10.0\n\ 10.0 20.0\n\ 20.0 20.0\n\ 10.0 10.0\n\ END\n\ END\n") file.close() a = Vertex(0.0, 0.0) #, attributes = [1.1]) b = Vertex(0.0, 40.0) #, attributes = [1.2]) c = Vertex(40.0, 40.0) #, attributes = [1.3]) d = Vertex(40.0, 0.0) #, attributes = [1.4]) s1 = Segment(a, b) s2 = Segment(b, c) s3 = Segment(c, d) s4 = Segment(d, a) m = Mesh(userVertices=[a, b, c, d], userSegments=[s1, s2, s3, s4]) dict = load_ungenerate(fileName) #os.remove(fileName) tag = "DSG" Segment.set_default_tag(tag) m.addVertsSegs(dict) # have to reset this , since it's a class attribute Segment.set_default_tag("") self.assertTrue( len(m.userSegments) == 11, 'Wrong segment list length.') self.assertTrue(len(m.userVertices) == 11, 'Wrong vertex list length.') self.assertTrue(m.userSegments[10].vertices[0] == m.userVertices[10], 'bad vertex on segment.') self.assertTrue(m.userSegments[10].vertices[1] == m.userVertices[8], 'Bad segment.') self.assertTrue(m.userSegments[10].tag == tag, 'wrong tag.') ## let's test the method a = Vertex(0.0, 0.0) #, attributes = [1.1]) b = Vertex(0.0, 40.0) #, attributes = [1.2]) c = Vertex(40.0, 40.0) #, attributes = [1.3]) d = Vertex(40.0, 0.0) #, attributes = [1.4]) s1 = Segment(a, b) s2 = Segment(b, c) s3 = Segment(c, d) s4 = Segment(d, a) m = Mesh(userVertices=[a, b, c, d], userSegments=[s1, s2, s3, s4]) tag = "DSG" initial_tag = "PIG" Segment.set_default_tag(initial_tag) m.import_ungenerate_file(fileName, tag=tag) os.remove(fileName) self.assertTrue(Segment.get_default_tag() == initial_tag, 'Wrong segment list length.') # have to reset this , since it's a class attribute Segment.set_default_tag("") self.assertTrue( len(m.userSegments) == 11, 'Wrong segment list length.') self.assertTrue(len(m.userVertices) == 11, 'Wrong vertex list length.') self.assertTrue(m.userSegments[10].vertices[0] == m.userVertices[10], 'bad vertex on segment.') self.assertTrue(m.userSegments[10].vertices[1] == m.userVertices[8], 'Bad segment.') self.assertTrue(m.userSegments[10].tag == tag, 'wrong tag.')
def test_import_ungenerate_file_different_region_tags(self): fileName = tempfile.mktemp(".txt") file = open(fileName, "w") file.write(" 1 ?? ??\n\ 10.0 10.0\n\ 11.0 10.0\n\ 11.0 11.0\n\ 10.0 11.0\n\ 10.0 10.0\n\ END\n\ 2 ?? ??\n\ 20.0 20.0\n\ 20.0 30.0\n\ 30.0 30.0\n\ END\n\ END\n") file.close() a = Vertex(0.0, 0.0) #, attributes = [1.1]) b = Vertex(0.0, 40.0) #, attributes = [1.2]) c = Vertex(40.0, 40.0) #, attributes = [1.3]) d = Vertex(40.0, 0.0) #, attributes = [1.4]) s1 = Segment(a, b) s2 = Segment(b, c) s3 = Segment(c, d) s4 = Segment(d, a) m = Mesh(userVertices=[a, b, c, d], userSegments=[s1, s2, s3, s4]) dict = load_ungenerate(fileName) #os.remove(fileName) tag = "DSG" Segment.set_default_tag(tag) m.addVertsSegs(dict) self.assertTrue( len(m.userSegments) == 11, 'Wrong segment list length.') self.assertTrue(len(m.userVertices) == 11, 'Wrong vertex list length.') # Test the method a = Vertex(0.0, 0.0) #, attributes = [1.1]) b = Vertex(0.0, 40.0) #, attributes = [1.2]) c = Vertex(40.0, 40.0) #, attributes = [1.3]) d = Vertex(40.0, 0.0) #, attributes = [1.4]) s1 = Segment(a, b) s2 = Segment(b, c) s3 = Segment(c, d) s4 = Segment(d, a) m = Mesh(userVertices=[a, b, c, d], userSegments=[s1, s2, s3, s4]) tag = "DSG" initial_tag = "PIG" Segment.set_default_tag(initial_tag) m.import_ungenerate_file(fileName, tag=tag, region_tag=["swamp", "coastalp"]) os.remove(fileName) self.assertTrue(Segment.get_default_tag() == initial_tag, 'Wrong segment list length.') m.export_mesh_file("swamp.tsh") #print "m.userSegments",m.userSegments self.assertTrue( len(m.userSegments) == 11, 'Wrong segment list length.') self.assertTrue(len(m.userVertices) == 11, 'Wrong vertex list length.') self.assertTrue(len(m.regions) == 2, 'Wrong regions list length.') self.assertTrue(m.regions[0].getTag() == "swamp", 'Wrong regions tag.') self.assertTrue(m.regions[1].getTag() == "coastalp", 'Wrong regions 1 tag.') # have to reset this , since it's a class attribute Segment.set_default_tag("")