def setup_cubemodel(self): # load the box model and build the box model csmFile = os.path.join(self.input_path, "../input_files/esp/box.csm") DVGeo = DVGeometryESP(csmFile) self.assertIsNotNone(DVGeo) # add a point set on the surface vertex1 = np.array([-2.0, -2.0, -2.0]) vertex2 = np.array([1.5, 1.5, 1.5]) left = np.array([-2.0, -1.1, -1.1]) right = np.array([1.5, -1.2, -0.1]) front = np.array([0.25, 1.5, 0.3]) back = np.array([1.2, -2.0, -0.3]) top = np.array([0.0, 0.1, 1.5]) bottom = np.array([-1.9, -1.1, -2.0]) initpts = np.vstack([vertex1, vertex2, left, right, front, back, top, bottom, left, right]) distglobal = DVGeo.addPointSet(initpts, "mypts", cache_projections=False) self.assertAlmostEqual(distglobal, 0.0, 8) # evaluate the points and check that they match DVGeo._updateModel() DVGeo._updateProjectedPts() self.assertTrue(DVGeo.pointSetUpToDate) self.assertAlmostEqual(np.linalg.norm(initpts - DVGeo.pointSets["mypts"].proj_pts), 0.0, 10) return DVGeo, initpts
def setup_airfoilmodel(self, kulfan=False, projtol=0.01): # load the csm file and pointset file if kulfan: csmFile = os.path.join(self.input_path, "../input_files/esp/naca0012_kulfan.csm") max_dist_tol = 2 else: csmFile = os.path.join(self.input_path, "../input_files/esp/naca0012.csm") max_dist_tol = 3 stlFile = os.path.join(self.input_path, "../input_files/esp/naca0012_esp.stl") DVGeo = DVGeometryESP(csmFile, projTol=projtol) self.assertIsNotNone(DVGeo) testobj = mesh.Mesh.from_file(stlFile) # test mesh dim 0 is triangle index # dim 1 is each vertex of the triangle # dim 2 is x, y, z dimension p0 = testobj.vectors[:, 0, :] p1 = testobj.vectors[:, 1, :] p2 = testobj.vectors[:, 2, :] distglobal1 = DVGeo.addPointSet(p0, "airfoil_p0") distglobal2 = DVGeo.addPointSet(p1, "airfoil_p1") distglobal3 = DVGeo.addPointSet(p2, "airfoil_p2") distglobal = np.max(np.array([distglobal1, distglobal2, distglobal3])) self.assertAlmostEqual(distglobal, 0.0, max_dist_tol) # evaluate the points and check that they match DVGeo._updateModel() DVGeo._updateProjectedPts() self.assertTrue(DVGeo.pointSetUpToDate) updated_dist_max = np.max(np.sqrt(np.sum((p0 - DVGeo.pointSets["airfoil_p0"].proj_pts) ** 2, axis=1))) self.assertAlmostEqual(updated_dist_max, 0.0, max_dist_tol) updated_dist_max = np.max(np.sqrt(np.sum((p1 - DVGeo.pointSets["airfoil_p1"].proj_pts) ** 2, axis=1))) self.assertAlmostEqual(updated_dist_max, 0.0, max_dist_tol) updated_dist_max = np.max(np.sqrt(np.sum((p2 - DVGeo.pointSets["airfoil_p2"].proj_pts) ** 2, axis=1))) self.assertAlmostEqual(updated_dist_max, 0.0, max_dist_tol) return DVGeo, [p0, p1, p2]