MATLAB Examples

Interpolation from a scattered grid

This is an example of application where the grid where the values are known is a scattered distribution of points. The geometry used comes from the example #1 of EABE_v34_p30. For the purposes of the example, the points on which the interpolation is computed is the integration grid. The integration is computed from this value.


Creation of the grid where the function is known

% Definition of the geometry
obj = obj_AFP_V1_00;
obj.file_geom_definition = 'R_fcts_geom\Files_geom_definition\EABE_v34_p30_ex1_w_scattered_grid'; % Shape of the geometry

% Analysis of the geometry
obj = Analyse_geometry_definition(obj);

% Definition of the grid points
obj.Pts_mean_distance_expr = {[] [.25 .25 Inf]}; % This parameter will be used in the interpolation process to determine the size
% of the ponderation functions. We set it as the average distance between the points (we know this value from the generation
% of the points distribution).
obj = calc_pts_distr(obj,'geometry_file'); % The points distribution ("grid") in the geometry file is loaded in |Pts_coord|
Pts_coord_grid = obj.Pts_coord;

Specifications of the points where the values are to be interpolated

% Function to interpolate
fct_to_interp = inline('sin(x).*cos(y)','x','y','z');
values_to_interp = fct_to_interp(Pts_coord_grid(:,1),Pts_coord_grid(:,2),Pts_coord_grid(:,3)); % These values represent the
% function known on the grid points.

% Interpolation parameters to use in |integration_AFP|
stc_specs_interp_1.V_fct_to_interp = values_to_interp;
stc_specs_interp_1.SolOrder = 2;
stc_specs_interp_1.Kernel_technique = 'FC_variable';
stc_specs_interp_1.LargKernel = 1.17*[1 1 1];
stc_specs_interp_1.F_use_pts_mean_distance_in_kernel = true;
stc_specs_interp_1.F_waitbar = true;

% Integration points determination
[obj,integral_value_1] = integration_AFP(obj,stc_specs_interp_1); % The output contains the validated integration points and
% weights in |obj|. This method |integration_AFP| is written with an optional second argument where the interpolation
% parameters could be specified. For the purpose of this demonstration about interpolation, this interpolation process will
% be done also outside this method.
integral_value_1 % Value obtained through |integration_AFP|. The exact value of the integral on this geometry is |0.808324|.
Pts_coord_interp = obj.Pts_coord_integration;
integral_value_1 =


Specifications of the interpolation parameters

stc_specs.SolOrder = 2;
stc_specs.Kernel_technique = 'FC_variable';
stc_specs.F_Kronecker_enforcement = false;
stc_specs.LargKernel = 1.17*[1 1 1];
stc_specs.Value_points_outside_domain = 'Extrapolation';
stc_specs.L_check_status_inside = false; % We know that all the points are inside the geometry
stc_specs.L_output_C_NZphih = false;
stc_specs.L_output_C_NZdNh = false;
stc_specs.L_output_C_dNh = true;
stc_specs.L_output_V_interp = false;
stc_specs.L_output_stc_kernel = false;
stc_specs.F_compact_output_cells = false;
stc_specs.L_derivatives_interp_to_compute = true(1,10);
stc_specs.F_use_pts_mean_distance_in_kernel = true;
stc_specs.V_fct_to_interp = [];
stc_specs.F_waitbar = true;

Computation of the interpolation matrix

C_dNh = interp_AFP(obj,Pts_coord_interp,stc_specs);
M_G1_to_G2_1 = C_dNh{1}; % Direct interpolation matrix
M_G1_to_G2_x = C_dNh{2}; % "x" derivative
M_G1_to_G2_y = C_dNh{3}; % "y" derivative
M_G1_to_G2_z = C_dNh{4}; % "z" derivative: empty in 2D
M_G1_to_G2_x2 = C_dNh{5}; % "x^2" derivative
M_G1_to_G2_xy = C_dNh{6}; % "x^y" derivative
M_G1_to_G2_xz = C_dNh{7}; % "x^z" derivative: empty in 2D
M_G1_to_G2_y2 = C_dNh{8}; % "y^2" derivative
M_G1_to_G2_yz = C_dNh{9}; % "y^z" derivative: empty in 2D
M_G1_to_G2_z2 = C_dNh{10}; % "z^2" derivative: empty in 2D

Interpolated values

% See above for |values_to_interp|

values_on_G2_1 = M_G1_to_G2_1*values_to_interp; % Direct interpolation on G2
values_on_G2_x = M_G1_to_G2_x*values_to_interp; % Interpolation on G2 of df/dx
values_on_G2_y = M_G1_to_G2_y*values_to_interp; % Interpolation on G2 of df/dy
values_on_G2_x2 = M_G1_to_G2_x2*values_to_interp; % Interpolation on G2 of d2f/dx2
values_on_G2_xy = M_G1_to_G2_xy*values_to_interp; % Interpolation on G2 of d2f/dxdy
values_on_G2_y2 = M_G1_to_G2_y2*values_to_interp; % Interpolation on G2 of d2f/dy2

Computation of the integral

V_weights_integration = obj.V_weights_integration;
integral_value = V_weights_integration'*values_on_G2_1 % The exact value of the integral on this geometry is |0.808324|.
integral_value =


Copyright 2013 Mathieu Gendron