def test_interface(self, triangulation): """ check if the interface between interior and exterior matches the faces of the base case """ def get_faces(reference, elements): """ return surface-faces of elements not intersecting a face of the reference element """ faces = [GeomObject(element.dim-1, face, self.generator.geometry_type) for element in elements for face in element.faces()] faces = [x for x in faces if faces.count(x) != 2] for (i,ref_face) in ((i,GeomObject(reference.dim-1, x, self.generator.geometry_type)) for (i,x) in enumerate(reference.faces())): faces = [x for x in faces if not ref_face.containsIfFace(i,x)] return faces def compare(first, second): """ returns true if first and second contain the same elements """ return len(first) == len(second) and sum(1 for x in first if x not in second) == 0 interface_base = [GeomObject(self.generator.dim-1, x, self.generator.geometry_type) for x in triangulation.faces if len(x)>0] # remove those faces from interface_base intersecting reference element reference = GeomObject(self.generator.dim, range(len(self.generator.ref_elem)), self.generator.geometry_type) for (i,ref_face) in ((i,GeomObject(reference.dim-1, x, self.generator.geometry_type)) for (i,x) in enumerate(reference.faces())): interface_base = [x for x in interface_base if not ref_face.containsIfFace(i,x)] for data in (triangulation.interior, triangulation.exterior): elements = (GeomObject(self.generator.dim, x, self.generator.geometry_type) for x in data if len(x)>0) interface = get_faces(reference, elements) if not compare(interface, interface_base): LOGGER.error("interface: {0}\n" "base.faces: {1}".format(interface, interface_base)) errormsg = "interface of {0} does not match" if data == triangulation.interior: LOGGER.error(errormsg.format('interior')) else: LOGGER.error(errormsg.format('exterior')) return False return True
def test_surface(self, triangulation): """ compare the surface of the union of interior and exterior with the surface of the reference element """ elements = [GeomObject(self.generator.dim, x, self.generator.geometry_type) for x in triangulation.interior + triangulation.exterior if len(x)>0] reference = GeomObject(self.generator.dim, range(len(self.generator.ref_elem)), self.generator.geometry_type) if not reference.matches(elements): LOGGER.error("elements do not match reference element:" "reference : {0}" "elements: {1}".format(self.generator.ref_elem.type, elements)) return 0 return 1
def test_consistency(self, triangulation, case_number, test_results): """ check if the decomposition of the reference-faces based on the interior/exterior matches the decomposition in lower dimension test_results: face-number-->test-result 0 equals left, ie outside, 1 equals right, ie inside """ def rename_vertices(tri, vertices): def rvertex(v): if type(v) is tuple: return tuple(sorted([rvertex(v[0]), rvertex(v[1])])) else: return vertices[v] """ rename the vertices in triangulation tri (i --> vertices[i]) """ for elem in tri: nel = [] for vertex in elem: nel.append(rvertex(vertex)) yield GeomObject(self.generator.dim-1, nel, self.generator.geometry_type) interior_faces = [GeomObject(self.generator.dim-1, x, self.generator.geometry_type) for element in triangulation.interior for x in GeomObject(self.generator.dim, element, self.generator.geometry_type).faces()] exterior_faces = [GeomObject(self.generator.dim-1, x, self.generator.geometry_type) for element in triangulation.exterior for x in GeomObject(self.generator.dim, element, self.generator.geometry_type).faces()] reference_faces = self.generator.ref_elem.faces for (faceid,ref_face) in enumerate(reference_faces): ref_face_element = GeomObject(self.generator.dim-1, ref_face, self.generator.geometry_type) # ignore cases where a face of the interface intersects the ref_face if sum(1 for x in triangulation.faces if GeomObject(self.generator.dim-1, x, self.generator.geometry_type) in ref_face_element) > 0: continue # now get the dim-1 dimensional decomposition of ref_face lower_case_number = tuple(case_number[i] for i in ref_face) lower_generator = LookupGenerators[ref_face_element.reference.type]['standard'] lower_case = next((case for case in lower_generator.all_cases if case.case == lower_case_number), None) assert(lower_case!=None) if len(lower_case.mc33) == 0: lower_triangulation = lower_case else: test_result = test_results[reference_faces.index(ref_face)] if test_result < 0: continue if type(lower_case.tests[2-test_result]) is TestRegular: lower_triangulation = lower_case else: lower_triangulation = \ lower_case.mc33[lower_case.tests[2-test_result]] face_interior_low = PolygonList([x.polygon() for x in rename_vertices(lower_triangulation.interior, ref_face)]) face_exterior_low = PolygonList([x.polygon() for x in rename_vertices(lower_triangulation.exterior, ref_face)]) # retrieve the decomposition of ref_face based on triangulation face_interior_high = PolygonList([x.polygon() for x in interior_faces if ref_face_element.containsIfFace(faceid,x)]) face_exterior_high = PolygonList([x.polygon() for x in exterior_faces if ref_face_element.containsIfFace(faceid,x)]) # compare higher dimensional decomposition with # lower dimensional one errormsg = 'face {0} ({1}) {2} does not match' if not face_interior_low == face_interior_high : LOGGER.error(errormsg.format(reference_faces.index(ref_face), lower_case_number, 'interior')) LOGGER.error('high:{0} vs low:{1}'.format(face_interior_high, face_interior_low)) return 0 if not face_exterior_low == face_exterior_high: LOGGER.error(errormsg.format(reference_faces.index(ref_face), lower_case_number, 'exterior')) LOGGER.error('high:{0} vs low:{1}'.format(face_interior_high, face_interior_low)) return 0 # all reference faces passed return 1