@@ -34,52 +34,51 @@ class CFFD(FFD):
3434 y, normalized with the box length y.
3535 :cvar numpy.ndarray array_mu_z: collects the displacements (weights) along
3636 z, normalized with the box length z.
37- :cvar callable fun: it defines the F of the constraint F(x)=c.
38- :cvar numpy.ndarray fixval: it defines the c of the constraint F(x)=c.
39- :cvar list indices: it defines the indices of the control points
40- that are moved to enforce the constraint. The control index is obtained by doing:
41- all_indices=np.arange(n_x*n_y*n_z*3).reshape(n_x,n_y,n_z,3).tolist().
42- :cvar numpy.ndarray M: a SDP weigth matrix. It must be of size len(indices) x len(indices).
37+ :cvar callable fun: it defines the F of the constraint F(x)=c. Default is the constant 1 function.
38+ :cvar numpy.ndarray fixval: it defines the c of the constraint F(x)=c. Default is 1.
39+ :cvar numpy.ndarray mask: a boolean tensor that tells to the class
40+ which control points can be moved, and in what direction, to enforce the constraint.
41+ The tensor has shape (n_x,n_y,n_z,3), where the last dimension indicates movement
42+ on x,y,z respectively. Default is all true.
43+ :cvar numpy.ndarray weight_matrix: a symmetric positive definite weigth matrix.
44+ It must be of row and column size the number of trues in the mask.
45+ It weights the movemement of the control points which have a true flag in the mask.
46+ Default is identity.
4347
4448 :Example:
4549
4650 >>> from pygem import CFFD
4751 >>> import numpy as np
48- >>> cffd = CFFD()
49- >>> cffd.read_parameters('tests/test_datasets/parameters_test_ffd_sphere.prm')
5052 >>> original_mesh_points = np.load('tests/test_datasets/meshpoints_sphere_orig.npy')
51- >>> A=np.random.rand(3,original_mesh_points.reshape(-1).shape[0])
52- >>> def fun(x):
53- >>> x=x.reshape(-1)
54- >>> return A@x
55- >>> b=fun(original_mesh_points)
56- >>> cffd.fun=fun
57- >>> cffd.fixval=b
58- >>> cffd.indices=np.arange(np.prod(cffd.n_control_points)*3).tolist()
59- >>> cffd.M=np.eye(len(cffd.indices))
60- >>> new_mesh_points = cffd(original_mesh_points)
61- >>> assert np.isclose(np.linalg.norm(fun(new_mesh_points)-b),np.array([0.]))
53+ >>> A=np.random.rand(3,original_mesh_points[:-4].reshape(-1).shape[0])
54+ >>> fun=lambda x: [email protected] (-1) 55+ >>> b=np.random.rand(3)
56+ >>> cffd = CFFD([2,2,2],fun,b)
57+ >>> cffd.read_parameters('tests/test_datasets/parameters_test_ffd_sphere.prm')
58+ >>> cffd.adjust_control_points(original_mesh_points[:-4])
59+ >>> assert np.isclose(np.linalg.norm(fun(cffd.ffd(original_mesh_points[:-4]))-b),np.array([0.]),atol=1e-06)
60+ >>> new_mesh_points = cffd.ffd(original_mesh_points)
6261 """
6362 def __init__ (self , n_control_points = None , fun = None , fixval = None , weight_matrix = None , mask = None ):
6463 super ().__init__ (n_control_points )
6564
66- if mask == None :
65+ if mask is None :
6766 self .mask = np .full ((* self .n_control_points ,3 ), True , dtype = bool )
6867 else :
6968 self .mask = mask
7069
71- if fixval == None :
70+ if fixval is None :
7271 self .fixval = np .array ([1. ])
7372 else :
7473 self .fixval = fixval
7574
76- if fun == None :
75+ if fun is None :
7776 self .fun = lambda x : self .fixval
7877
7978 else :
8079 self .fun = fun
8180
82- if weight_matrix == None :
81+ if weight_matrix is None :
8382 self .weight_matrix = np .eye (np .sum (self .mask .astype (int )))
8483
8584 def adjust_control_points (self ,src_pts ):
@@ -164,6 +163,4 @@ def _compute_linear_map(self, src_pts, saved_parameters,indices):
164163 rcond = None ) #computation of the linear map
165164 A = sol [0 ].T [:, :- 1 ] #coefficient
166165 b = sol [0 ].T [:, - 1 ] #intercept
167- return A , b
168-
169-
166+ return A , b
0 commit comments