LoopStructural.interpolators.FiniteDifferenceInterpolator#
- class LoopStructural.interpolators.FiniteDifferenceInterpolator(grid, data={})#
Bases:
DiscreteInterpolator
Finite difference interpolation on a regular cartesian grid
- Parameters:
grid (StructuredGrid) –
- __init__(grid, data={})#
Finite difference interpolation on a regular cartesian grid
- Parameters:
grid (StructuredGrid) –
Methods
__init__
(grid[, data])Finite difference interpolation on a regular cartesian grid
add_constraints_to_least_squares
(A, B, idc)Adds constraints to the least squares system.
add_equality_constraints
(node_idx, values[, ...])Adds hard constraints to the least squares system.
- param w:
add_gradient_orthogonal_constraints
(points, ...)constraints scalar field to be orthogonal to a given vector
add inequality constraints to the interpolator only works if using osqp solver.
Adds a constraint that defines all points with the same 'id' to be the same value Sets all P1-P2 = 0 for all pairs of points
add_norm_constraints
([w])Add constraints to control the norm of the gradient of the scalar field
add_regularisation
(operator[, w])- param operator:
Adds the constraints \(f(X)\cdotT=0\)
- param w:
assemble_inner
(operator, w)- param operator:
build_matrix
([square, damp, ie])Assemble constraints into interpolation matrix.
Calculates Ax-B for all constraints added to the interpolator This could be a proxy to identify which constraints are controlling the model
check_array
(array)clean
()Removes all of the data from an interpolator
copy
()Create a new identical interpolator
debug
()Helper function for debugging when the interpolator isn't working
evaluate_gradient
(locations)Evaluate the gradient of the scalar field at the evaluation points :param evaluation_points: xyz locations to evaluate the gradient :type evaluation_points: np.array
evaluate_value
(locations)Evaluate the value of the interpolator at location
Get the location of all data points
- returns:
numpy array
get_inequality_constraints
()Get the location of interface constraints
- returns:
numpy array
- returns:
numpy array
- returns:
numpy array
Remove constraints from the least squares system using the constraint ids which corresponds to the rows in the interpolation matrix.
reset
()Reset the interpolation constraints
set_gradient_constraints
(points)- param points:
array containing the value constraints usually 7-8 columns.
set_inequality_pairs_constraints
(pointsa, ...)set_interface_constraints
(points)set_interpolation_weights
(weights)Set the interpolation weights dictionary
set_normal_constraints
(points)- param points:
array containing the value constraints usually 7-8 columns.
set_region
([region])Set the region of the support the interpolator is working on
set_tangent_constraints
(points)- param points:
array containing the value constraints usually 7-8 columns.
set_value_constraints
(points)- param points:
array containing the value constraints usually 4-5 columns.
set_value_inequality_constraints
(points)setup
(**kwargs)Runs all of the required setting up stuff
setup_interpolator
(**kwargs)- param kwargs:
possible kwargs are weights for the different masks and masks.
solve_system
([solver])Main entry point to run the solver and update the node value attribute for the discreteinterpolator class
to_dict
()to_json
()Returns a json representation of the geological interpolator
update
()Check if the solver is up to date, if not rerun interpolation using the previously used solver.
Attributes
data
Number of degrees of freedom for the interpolator
The active region of the interpolator.
region_map
- add_constraints_to_least_squares(A, B, idc, w=1.0, name='undefined')#
Adds constraints to the least squares system. Automatically works out the row index given the shape of the input arrays
- Parameters:
A (numpy array / list) – RxC numpy array of constraints where C is number of columns,R rows
B (numpy array /list) – B values array length R
idc (numpy array/list) – RxC column index
- Returns:
list of constraint ids
- add_equality_constraints(node_idx, values, name='undefined')#
Adds hard constraints to the least squares system. For now this just sets the node values to be fixed using a lagrangian.
- Parameters:
node_idx (numpy array/list) – int array of node indexes
values (numpy array/list) – array of node values
- add_gradient_constraints(w=1.0)#
- Parameters:
w (double / numpy array) –
- add_gradient_orthogonal_constraints(points: ndarray, vectors: ndarray, w: float = 1.0, B: float = 0, name='gradient orthogonal')#
constraints scalar field to be orthogonal to a given vector
- Parameters:
points (np.darray) – location to add gradient orthogonal constraint
vector (np.darray) – vector to be orthogonal to, should be the same shape as points
w (double) –
B (np.array) –
- add_inequality_constraints(w=1.0)#
add inequality constraints to the interpolator only works if using osqp solver.
- Parameters:
w (float, optional) – weight of constraint in lsqr system, by default 1.0
- add_interface_constraints(w=1.0)#
Adds a constraint that defines all points with the same ‘id’ to be the same value Sets all P1-P2 = 0 for all pairs of points
- Parameters:
w (double) – weight
- add_norm_constraints(w=1.0)#
Add constraints to control the norm of the gradient of the scalar field
- Parameters:
w (double) – weighting of this constraint (double)
- add_regularisation(operator, w=0.1)#
- Parameters:
operator –
w –
- add_tangent_constraints(w=1.0)#
Adds the constraints \(f(X)\cdotT=0\)
- Parameters:
w (double) –
- add_value_constraints(w=1.0)#
- Parameters:
w (double or numpy array) –
- assemble_inner(operator, w)#
- Parameters:
operator (Operator) –
w (double) –
- build_matrix(square=True, damp=0.0, ie=False)#
Assemble constraints into interpolation matrix. Adds equaltiy constraints using lagrange modifiers if necessary
- Parameters:
damp (bool) – Flag whether damping should be added to the diagonal of the matrix
- Returns:
Interpolation matrix and B
- calculate_residual_for_constraints()#
Calculates Ax-B for all constraints added to the interpolator This could be a proxy to identify which constraints are controlling the model
- Returns:
np.ndarray – vector of Ax-B
- clean()#
Removes all of the data from an interpolator
- copy()#
Create a new identical interpolator
- Returns:
returns a new empy interpolator from the same support
- debug()#
Helper function for debugging when the interpolator isn’t working
- evaluate_gradient(locations: ndarray) ndarray #
Evaluate the gradient of the scalar field at the evaluation points :param evaluation_points: xyz locations to evaluate the gradient :type evaluation_points: np.array
- evaluate_value(locations: ndarray) ndarray #
Evaluate the value of the interpolator at location
- Parameters:
evaluation_points (np.ndarray) – location to evaluate the interpolator
- Returns:
np.ndarray – value of the interpolator
- get_data_locations()#
Get the location of all data points
- Returns:
numpy array – Nx3 - X,Y,Z location of all data points
- get_gradient_constraints()#
- Returns:
numpy array
- get_interface_constraints()#
Get the location of interface constraints
- Returns:
numpy array – Nx4 - X,Y,Z,id location of all interface constraints
- get_norm_constraints()#
- Returns:
numpy array
- get_tangent_constraints()#
- Returns:
numpy array
- get_value_constraints()#
- Returns:
numpy array
- property nx: int#
Number of degrees of freedom for the interpolator
- Returns:
int – number of degrees of freedom, positve
- property region: ndarray#
The active region of the interpolator. A boolean mask for all elements that are interpolated
- Returns:
np.ndarray
- remove_constraints_from_least_squares(name='undefined', constraint_ids=None)#
Remove constraints from the least squares system using the constraint ids which corresponds to the rows in the interpolation matrix.
- Parameters:
constraint_ids (np.array(dtype=int)) – id of constraints to remove
- reset()#
Reset the interpolation constraints
- set_gradient_constraints(points: ndarray)#
- Parameters:
points (np.ndarray) – array containing the value constraints usually 7-8 columns. X,Y,Z,gx,gy,gz,weight
- set_interpolation_weights(weights)#
Set the interpolation weights dictionary
- Parameters:
dictionary (weights -) – Entry of new weights to assign to self.interpolation_weights
- set_normal_constraints(points: ndarray)#
- Parameters:
points (np.ndarray) – array containing the value constraints usually 7-8 columns. X,Y,Z,nx,ny,nz,weight
- set_region(region=None)#
Set the region of the support the interpolator is working on
- Parameters:
function(position) (region -) – return true when in region, false when out
- set_tangent_constraints(points: ndarray)#
- Parameters:
points (np.ndarray) – array containing the value constraints usually 7-8 columns. X,Y,Z,nx,ny,nz,weight
- set_value_constraints(points: ndarray)#
- Parameters:
points (np.ndarray) – array containing the value constraints usually 4-5 columns. X,Y,Z,val,weight
- setup(**kwargs)#
Runs all of the required setting up stuff
- setup_interpolator(**kwargs)#
- Parameters:
kwargs – possible kwargs are weights for the different masks and masks.
Notes
Default masks are the second derivative in x,y,z direction and the second derivative of x wrt y and y wrt z and z wrt x. Custom masks can be used by specifying the operator as a 3d numpy array e.g. [ [ [ 0 0 0 ]
[ 0 1 0 ] [ 0 0 0 ] ] [ [ 1 1 1 ] [ 1 1 1 ] [ 1 1 1 ] ] [ [ 0 0 0 ] [ 0 1 0 ] [ 0 0 0 ] ]
- solve_system(solver='cg', **kwargs)#
Main entry point to run the solver and update the node value attribute for the discreteinterpolator class
- Parameters:
solver (string) – solver e.g. cg, lu, chol, custom
kwargs – kwargs for solver e.g. maxiter, preconditioner etc, damping for
- Returns:
bool – True if the interpolation is run
- to_json()#
Returns a json representation of the geological interpolator
- Returns:
json (dict) – json representation of the geological interpolator
- update()#
Check if the solver is up to date, if not rerun interpolation using the previously used solver. If the interpolation has not been run before it will return False
- Returns:
bool