|
| 1 | +""" |
| 2 | +Module focused on the implementation of the Radial Basis Functions interpolation |
| 3 | +technique. This technique is still based on the use of a set of parameters, the |
| 4 | +so-called control points, as for FFD, but RBF is interpolatory. Another |
| 5 | +important key point of RBF strategy relies in the way we can locate the control |
| 6 | +points: in fact, instead of FFD where control points need to be placed inside a |
| 7 | +regular lattice, with RBF we hano no more limitations. So we have the |
| 8 | +possibility to perform localized control points refiniments. |
| 9 | +The module is analogous to the freeform one. |
| 10 | +
|
| 11 | +:Theoretical Insight: |
| 12 | +
|
| 13 | + As reference please consult M.D. Buhmann, Radial Basis Functions, volume 12 |
| 14 | + of Cambridge monographs on applied and computational mathematics. Cambridge |
| 15 | + University Press, UK, 2003. This implementation follows D. Forti and G. |
| 16 | + Rozza, Efficient geometrical parametrization techniques of interfaces for |
| 17 | + reduced order modelling: application to fluid-structure interaction coupling |
| 18 | + problems, International Journal of Computational Fluid Dynamics. |
| 19 | +
|
| 20 | + RBF shape parametrization technique is based on the definition of a map, |
| 21 | + :math:`\\mathcal{M}(\\boldsymbol{x}) : \\mathbb{R}^n \\rightarrow |
| 22 | + \\mathbb{R}^n`, that allows the possibility of transferring data across |
| 23 | + non-matching grids and facing the dynamic mesh handling. The map introduced |
| 24 | + is defines as follows |
| 25 | +
|
| 26 | + .. math:: |
| 27 | + \\mathcal{M}(\\boldsymbol{x}) = p(\\boldsymbol{x}) + |
| 28 | + \\sum_{i=1}^{\\mathcal{N}_C} \\gamma_i |
| 29 | + \\varphi(\\| \\boldsymbol{x} - \\boldsymbol{x_{C_i}} \\|) |
| 30 | +
|
| 31 | + where :math:`p(\\boldsymbol{x})` is a low_degree polynomial term, |
| 32 | + :math:`\\gamma_i` is the weight, corresponding to the a-priori selected |
| 33 | + :math:`\\mathcal{N}_C` control points, associated to the :math:`i`-th basis |
| 34 | + function, and :math:`\\varphi(\\| \\boldsymbol{x} - \\boldsymbol{x_{C_i}} |
| 35 | + \\|)` a radial function based on the Euclidean distance between the control |
| 36 | + points position :math:`\\boldsymbol{x_{C_i}}` and :math:`\\boldsymbol{x}`. |
| 37 | + A radial basis function, generally, is a real-valued function whose value |
| 38 | + depends only on the distance from the origin, so that |
| 39 | + :math:`\\varphi(\\boldsymbol{x}) = \\tilde{\\varphi}(\\| \\boldsymbol{x} |
| 40 | + \\|)`. |
| 41 | +
|
| 42 | + The matrix version of the formula above is: |
| 43 | +
|
| 44 | + .. math:: |
| 45 | + \\mathcal{M}(\\boldsymbol{x}) = \\boldsymbol{c} + |
| 46 | + \\boldsymbol{Q}\\boldsymbol{x} + |
| 47 | + \\boldsymbol{W^T}\\boldsymbol{d}(\\boldsymbol{x}) |
| 48 | +
|
| 49 | + The idea is that after the computation of the weights and the polynomial |
| 50 | + terms from the coordinates of the control points before and after the |
| 51 | + deformation, we can deform all the points of the mesh accordingly. Among |
| 52 | + the most common used radial basis functions for modelling 2D and 3D shapes, |
| 53 | + we consider Gaussian splines, Multi-quadratic biharmonic splines, Inverted |
| 54 | + multi-quadratic biharmonic splines, Thin-plate splines, Beckert and |
| 55 | + Wendland :math:`C^2` basis and Polyharmonic splines all defined and |
| 56 | + implemented below. |
| 57 | +""" |
| 58 | + |
| 59 | +import numpy as np |
| 60 | +from pygem import RBF as OriginalRBF |
| 61 | +from .cad_deformation import CADDeformation |
| 62 | + |
| 63 | +class RBF(CADDeformation, OriginalRBF): |
| 64 | + """ |
| 65 | + Class that handles the Free Form Deformation on the mesh points. |
| 66 | +
|
| 67 | + :param FFDParameters ffd_parameters: parameters of the Free Form |
| 68 | + Deformation. |
| 69 | + :param numpy.ndarray original_mesh_points: coordinates of the original |
| 70 | + points of the mesh. |
| 71 | +
|
| 72 | + :param list n_control_points: number of control points in the x, y, and z |
| 73 | + direction. If not provided it is set to [2, 2, 2]. |
| 74 | +
|
| 75 | + :cvar numpy.ndarray box_length: dimension of the FFD bounding box, in the |
| 76 | + x, y and z direction (local coordinate system). |
| 77 | + :cvar numpy.ndarray box_origin: the x, y and z coordinates of the origin of |
| 78 | + the FFD bounding box. |
| 79 | + :cvar numpy.ndarray rot_angle: rotation angle around x, y and z axis of the |
| 80 | + FFD bounding box. |
| 81 | + :cvar numpy.ndarray n_control_points: the number of control points in the |
| 82 | + x, y, and z direction. |
| 83 | + :cvar numpy.ndarray array_mu_x: collects the displacements (weights) along |
| 84 | + x, normalized with the box length x. |
| 85 | + :cvar numpy.ndarray array_mu_y: collects the displacements (weights) along |
| 86 | + y, normalized with the box length y. |
| 87 | + :cvar numpy.ndarray array_mu_z: collects the displacements (weights) along |
| 88 | + z, normalized with the box length z. |
| 89 | +
|
| 90 | + :Example: |
| 91 | +
|
| 92 | + >>> from pygem.cad import RBF |
| 93 | + >>> rbf = RBF() |
| 94 | + >>> rbf.read_parameters( |
| 95 | + >>> 'tests/test_datasets/parameters_test_ffd_iges.prm') |
| 96 | + >>> input_cad_file_name = "input.iges" |
| 97 | + >>> modified_cad_file_name = "output.iges" |
| 98 | + >>> rbf(input_cad_file_name, modified_cad_file_name) |
| 99 | + """ |
| 100 | + def __init__(self, |
| 101 | + original_control_points=None, |
| 102 | + deformed_control_points=None, |
| 103 | + func='gaussian_spline', |
| 104 | + radius=0.5, |
| 105 | + extra_parameter=None, |
| 106 | + u_knots_to_add=30, |
| 107 | + v_knots_to_add=30, |
| 108 | + t_knots_to_add=30, |
| 109 | + tolerance=1e-4): |
| 110 | + OriginalRBF.__init__(self, |
| 111 | + original_control_points=original_control_points, |
| 112 | + deformed_control_points=deformed_control_points, |
| 113 | + func=func, |
| 114 | + radius=radius, |
| 115 | + extra_parameter=extra_parameter) |
| 116 | + CADDeformation.__init__(self, |
| 117 | + u_knots_to_add=u_knots_to_add, |
| 118 | + v_knots_to_add=v_knots_to_add, |
| 119 | + t_knots_to_add=t_knots_to_add, |
| 120 | + tolerance=tolerance) |
0 commit comments