def test_read_parameters_filename_default(self): params = RBFParameters() params.read_parameters() outfilename = 'parameters_rbf.prm' outfilename_expected = 'tests/test_datasets/parameters_rbf_default.prm' self.assertTrue(filecmp.cmp(outfilename, outfilename_expected)) os.remove(outfilename)
def test_write_parameters_filename_default(self): params = RBFParameters() params.basis = 'gaussian_spline' params.radius = 0.5 params.power = 2 params.original_control_points = unit_cube params.deformed_control_points = unit_cube outfilename = 'test.prm' params.write_parameters(outfilename) outfilename_expected = 'tests/test_datasets/parameters_rbf_default.prm' print(filecmp.cmp(outfilename, outfilename_expected)) self.assertTrue(filecmp.cmp(outfilename, outfilename_expected)) os.remove(outfilename)
def test_write_parameters_filename_default_existance(self): params = RBFParameters() params.basis = 'inv_multi_quadratic_biharmonic_spline' params.radius = 0.1 params.original_control_points = np.array( [0., 0., 0., 0., 0., 1., 0., 1., 0.]).reshape((3, 3)) params.deformed_control_points = np.array( [0., 0., 0., 0., 0., 1., 0., 1., 0.]).reshape((3, 3)) params.write_parameters() outfilename = 'parameters_rbf.prm' assert os.path.isfile(outfilename) os.remove(outfilename)
def test_save_points_deformed(self): params = RBFParameters() params.read_parameters( filename='tests/test_datasets/parameters_rbf_cube.prm') outfilename = 'tests/test_datasets/box_test_cube_deformed_out.vtk' outfilename_expected = 'tests/test_datasets/box_test_cube_deformed.vtk' params.save_points(outfilename, True) self.assertTrue(filecmp.cmp(outfilename, outfilename_expected)) os.remove(outfilename)
def test_write_parameters(self): params = RBFParameters() params.read_parameters('tests/test_datasets/parameters_rbf_cube.prm') outfilename = 'tests/test_datasets/parameters_rbf_cube_out.prm' outfilename_expected = 'tests/test_datasets/parameters_rbf_cube_out_true.prm' params.write_parameters(outfilename) self.assertTrue(filecmp.cmp(outfilename, outfilename_expected)) os.remove(outfilename)
def test_save_points_deformed(self): params = RBFParameters() params.read_parameters( filename='tests/test_datasets/parameters_rbf_cube.prm') outfilename = 'tests/test_datasets/box_test_cube_deformed_out.vtk' outfilename_expected = 'tests/test_datasets/box_test_cube_deformed.vtk' params.save_points(outfilename, True) with open(outfilename, 'r') as out, open(outfilename_expected, 'r') as exp: self.assertTrue(out.readlines()[1:] == exp.readlines()[1:]) os.remove(outfilename)
def test_class_members_default_radius(self): params = RBFParameters() assert params.radius == 0.5
def test_read_parameters_failing_number_deformed_control_points(self): params = RBFParameters() with self.assertRaises(TypeError): params.read_parameters( 'tests/test_datasets/parameters_rbf_bugged_01.prm')
def test_read_parameters_deformed_control_points(self): params = RBFParameters() params.read_parameters('tests/test_datasets/parameters_rbf_default.prm') np.testing.assert_array_almost_equal(params.deformed_control_points, unit_cube)
def test_read_parameters_n_control_points(self): params = RBFParameters() params.read_parameters('tests/test_datasets/parameters_rbf_default.prm') assert params.n_control_points == 8
def test_read_parameters_radius(self): params = RBFParameters() params.read_parameters('tests/test_datasets/parameters_rbf_default.prm') assert params.radius == 0.5
def test_read_parameters_basis(self): params = RBFParameters() params.read_parameters('tests/test_datasets/parameters_rbf_default.prm') assert params.basis == 'gaussian_spline'
from pygem import RBFParameters, RBF import numpy as np import matplotlib.pyplot as plt ############### params = RBFParameters() params.read_parameters( filename='PyGem/tests/test_datasets/parameters_rbf_cube.prm') ############### # the definition of the mesh it has to be # a 3-D mesh nx, ny, nz = (10, 10, 10) mesh = np.zeros((nx * ny * nz, 3)) xv = np.linspace(0, 1, nx) yv = np.linspace(0, 1, ny) zv = np.linspace(0, 1, nz) z, y, x = np.meshgrid(zv, yv, xv) mesh = np.array([x.ravel(), y.ravel(), z.ravel()]) mesh = mesh.T fig = plt.figure(1) ax = fig.add_subplot(111, projection='3d') ax.scatter(mesh[:, 0], mesh[:, 1], mesh[:, 2], c='blue', marker='o') ax.set_xlabel('X axis') ax.set_ylabel('Y axis') ax.set_zlabel('Z axis') plt.show() params.plot_points()
x, y, z = line.split() mesh[i] = [float(x), float(y), float(z)] i += 1 # fig = plt.figure(1) ax = fig.add_subplot(111, projection='3d') ax.scatter(mesh[:, 0], mesh[:, 1], mesh[:, 2], c='blue', marker='o') ax.set_xlabel('X axis') ax.set_ylabel('Y axis') ax.set_zlabel('Z axis') plt.show() # modified 2-D mesh # read the RBF parameters params = RBFParameters() params.read_parameters(filename='turn_airfoil.prm') params.plot_points() params.save_points(filename='point.vtk') # rbf = RBF(params, mesh) rbf.perform() new_mesh_points = rbf.modified_mesh_points # fig = plt.figure(2) ax = fig.add_subplot(111, projection='3d') ax.scatter(new_mesh_points[:, 0], new_mesh_points[:, 1],
def test_write_parameters_failing_filename_type(self): params = RBFParameters() with self.assertRaises(TypeError): params.write_parameters(5)
def test_print_info(self): params = RBFParameters() print(params)
def test_class_members_default_basis(self): params = RBFParameters() assert params.basis == 'gaussian_spline'
from pygem import RBFParameters, RBF import numpy as np import matplotlib.pyplot as plt # read the RBF parameters params = RBFParameters() params.read_parameters( filename='cartesian_test.prm') nx, ny, nz = (50, 10, 10) mesh = np.zeros((nx * ny * nz, 3)) xv = np.linspace(0, 5, nx) yv = np.linspace(0, 1, ny) zv = np.linspace(0, 1, nz) # vectors z, y, x = np.meshgrid(zv, yv, xv) mesh = np.array([x.ravel(), y.ravel(), z.ravel()]) mesh = mesh.T fig = plt.figure(1) ax = fig.add_subplot(111, projection='3d') ax.scatter(mesh[:, 0], mesh[:, 1], mesh[:, 2], c='blue', marker='o') ax.set_xlabel('X axis') ax.set_ylabel('Y axis') ax.set_zlabel('Z axis') plt.show() params.plot_points()
def test_class_members_default_n_control_points(self): params = RBFParameters() assert params.n_control_points == 8
def test_class_members_default_deformed_control_points(self): params = RBFParameters() np.testing.assert_array_equal(params.deformed_control_points, unit_cube)
mesh_file_path = args.m output_morphed_vtk_path = args.output print("GENERATING MORPHED VTK"); cwd = os.getcwd() full_path = os.path.realpath(__file__) path, filename = os.path.split(full_path) # In[2]: params = RBFParameters() params.read_parameters(parameter_file_path) # In[2]: vtk_handler = VtkHandler() mesh = vtk_handler.parse(mesh_file_path) # In[4]: rbf = RBF(params, mesh) rbf.perform()
# coding: utf-8 # In[1]: #get_ipython().run_line_magic('matplotlib', 'inline') from pygem import RBFParameters, RBF, StlHandler, VtkHandler import numpy as np import matplotlib.pyplot as plt import os cwd = os.getcwd() full_path = os.path.realpath(__file__) path, filename = os.path.split(full_path) # In[2]: params = RBFParameters() params.read_parameters('../tests/test_datasets/parameters.prm') # In[2]: vtk_handler = VtkHandler() mesh = vtk_handler.parse('../tests/test_datasets/fine_mesh.vtk') # In[4]: rbf = RBF(params, mesh) rbf.perform() new_mesh_points = rbf.modified_mesh_points vtk_handler.write(new_mesh_points, "fine_mesh_morphed.vtk")