Numerical differentiation module for computing the Jacobian matrix
(the derivative matrix of m
functions w.r.t. n
variables) using
finite differences.
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
real(kind=wp), | private, | parameter | :: | zero | = | 0.0_wp |
constructor
Constructor for a finite_diff_method.
Note
factors are input as integers for convenience, but are converted to reals for the actual computations. (note: this means we can't currently define methods that have non-integer factors).
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in) | :: | id |
unique ID for the method |
||
character(len=*), | intent(in) | :: | name |
the name of the method |
||
integer, | intent(in) | :: | class |
2=backward diffs, 3=central diffs, etc... |
||
integer, | intent(in), | dimension(:) | :: | dx_factors |
multiplicative factors for dx perturbation |
|
integer, | intent(in), | dimension(:) | :: | df_factors |
multiplicative factors for accumulating function evaluations |
|
integer, | intent(in) | :: | df_den_factor |
denominator factor for finite difference equation (times dx) |
The function (vector array of output functions f
, computed
from a vector of input variables x
).
This must be defined for all computations.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(numdiff_type), | intent(inout) | :: | me | |||
real(kind=wp), | intent(in), | dimension(:) | :: | x |
array of variables (size |
|
real(kind=wp), | intent(out), | dimension(:) | :: | f |
array of functions (size |
|
integer, | intent(in), | dimension(:) | :: | funcs_to_compute |
the elements of the function vector that need to be computed (the other are ignored) |
The function to compute the sparsity pattern.
It populates the irow
and icol
variables in the class.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(numdiff_type), | intent(inout) | :: | me | |||
real(kind=wp), | intent(in), | dimension(:) | :: | x |
vector of variables (size |
User-defined info function (optional). Informs user what is being done during Jacobian computation. It can be used to perform any setup operations that need to done on the user's end.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(numdiff_type), | intent(inout) | :: | me | |||
integer, | intent(in), | dimension(:) | :: | column |
the columns being computed. |
|
integer, | intent(in) | :: | i |
perturbing these columns for the |
||
real(kind=wp), | intent(in), | dimension(:) | :: | x |
the nominal variable vector |
Actual function for computing the Jacobian called by compute_jacobian.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(numdiff_type), | intent(inout) | :: | me | |||
real(kind=wp), | intent(in), | dimension(:) | :: | x |
vector of variables (size |
|
real(kind=wp), | intent(in), | dimension(me%n) | :: | dx |
absolute perturbation (>0) for each variable |
|
real(kind=wp), | intent(out), | dimension(:) | :: | jac |
sparse jacobian vector (size |
defines the finite difference method used to compute the Jacobian.
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
integer, | private | :: | id | = | 0 |
unique ID for the method |
|
character(len=:), | private, | allocatable | :: | name |
the name of the method |
||
integer, | private | :: | class | = | 0 |
2=backward diffs, 3=central diffs, etc... |
|
real(kind=wp), | private, | dimension(:), allocatable | :: | dx_factors |
multiplicative factors for |
||
real(kind=wp), | private, | dimension(:), allocatable | :: | df_factors |
multiplicative factors for accumulating function evaluations |
||
real(kind=wp), | private | :: | df_den_factor | = | zero |
denominator factor for finite difference equation (times |
constructor
private function initialize_finite_difference_method (id, name, class, dx_factors, df_factors, df_den_factor) | Constructor for a finite_diff_method. |
procedure, public :: get_formula | |
procedure, public :: print => print_finite_difference_method |
to store an array of finite_diff_method types
this is used when the mode=2
option is used
in numdiff_type
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
type(finite_diff_method), | private, | dimension(:), allocatable | :: | meth |
A sparsity pattern
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
logical, | private | :: | sparsity_computed | = | .false. |
has the sparsity pattern already been computed? |
|
integer, | private | :: | num_nonzero_elements | = | 0 |
number of nonzero elements in the jacobian
(will be the dimension of |
|
integer, | private, | dimension(:), allocatable | :: | irow |
sparsity pattern - rows of non-zero elements |
||
integer, | private, | dimension(:), allocatable | :: | icol |
sparsity pattern - columns of non-zero elements |
||
logical, | private | :: | linear_sparsity_computed | = | .false. |
if the linear pattern has been populated |
|
integer, | private | :: | num_nonzero_linear_elements | = | 0 |
number of constant elements in the jacobian |
|
integer, | private, | dimension(:), allocatable | :: | linear_irow |
linear sparsity pattern - rows of non-zero elements |
||
integer, | private, | dimension(:), allocatable | :: | linear_icol |
linear sparsity pattern - columns of non-zero elements |
||
real(kind=wp), | private, | dimension(:), allocatable | :: | linear_vals |
linear elements of the jacobian |
||
integer, | private, | dimension(:), allocatable | :: | indices |
index vector
|
||
integer, | private | :: | maxgrp | = | 0 |
the number of groups in the partition
of the columns of |
|
integer, | private, | dimension(:), allocatable | :: | ngrp |
specifies the partition of the columns of |
procedure, private :: dsm_wrapper | |
procedure, private :: compute_indices | |
procedure, public :: destroy => destroy_sparsity | |
procedure, public :: print => print_sparsity | |
procedure, public :: columns_in_partition_group |
base type for sparsity and Jacobian computations.
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
logical, | private | :: | exception_raised | = | .false. |
if true, an exception has been raised |
|
integer, | private | :: | istat | = | 0 |
a non-zero value will cause all routine to exit.
this can be set to |
|
character(len=:), | private, | allocatable | :: | error_msg |
error message (if |
||
integer, | private | :: | n | = | 0 |
number of |
|
integer, | private | :: | m | = | 0 |
number of |
|
real(kind=wp), | private, | dimension(:), allocatable | :: | xlow |
lower bounds on |
||
real(kind=wp), | private, | dimension(:), allocatable | :: | xhigh |
upper bounds on |
||
logical, | private | :: | print_messages | = | .true. |
if true, warning messages are printed
to the |
|
integer, | private | :: | chunk_size | = | 100 |
chuck size for allocating the arrays (>0) |
|
integer, | private | :: | perturb_mode | = | 1 |
perturbation mode: |
|
real(kind=wp), | private, | dimension(:), allocatable | :: | dpert |
perturbation vector for |
||
logical, | private | :: | partition_sparsity_pattern | = | .false. |
to partition the sparsity pattern using dsm |
|
type(sparsity_pattern), | private | :: | sparsity |
the sparsity pattern |
|||
real(kind=wp), | private, | dimension(:), allocatable | :: | xlow_for_sparsity |
lower bounds on |
||
real(kind=wp), | private, | dimension(:), allocatable | :: | xhigh_for_sparsity |
upper bounds on |
||
real(kind=wp), | private, | dimension(:), allocatable | :: | dpert_for_sparsity |
perturbation vector for |
||
integer, | private | :: | num_sparsity_points | = | 3 |
for |
|
integer, | private | :: | sparsity_perturb_mode | = | 1 |
perturbation mode (if |
|
logical, | private | :: | compute_linear_sparsity_pattern | = | .false. |
to also compute the linear sparsity pattern |
|
real(kind=wp), | private | :: | linear_sparsity_tol | = | epsilon(1.0_wp) |
the equality tolerance for derivatives to indicate a constant jacobian element (linear sparsity) |
|
real(kind=wp), | private | :: | function_precision_tol | = | epsilon(1.0_wp) |
the function precision. two functions values
that are the within this tolerance are
considered the same value. This is used
when estimating the sparsity pattern when
|
|
integer, | private | :: | mode | = | 1 |
1 = use |
|
type(finite_diff_method), | private, | dimension(:), allocatable | :: | meth |
the finite difference method to use
compute the |
||
integer, | private, | dimension(:), allocatable | :: | class |
the class of method to use to
compute the |
||
type(meth_array), | private, | dimension(:), allocatable | :: | class_meths |
array of methods for the specified classes.
used with |
||
real(kind=wp), | private | :: | eps | = | 1.0e-9_wp |
tolerance parameter for diff |
|
real(kind=wp), | private | :: | acc | = | 0.0_wp |
tolerance parameter for diff |
|
type(function_cache), | private | :: | cache |
if using the function cache |
|||
logical, | private | :: | use_diff | = | .false. |
if we are using the Neville's process method, rather than finite differences |
|
procedure(func), | private, | pointer | :: | problem_func | => | null() |
the user-defined function |
procedure(func), | private, | pointer | :: | compute_function | => | null() |
compute the user-defined function
this can point to the |
procedure(spars_f), | private, | pointer | :: | compute_sparsity | => | null() |
for computing the sparsity pattern |
procedure(info_f), | private, | pointer | :: | info_function | => | null() |
an optional function the user can define which is called when each column of the jacobian is computed. It can be used to perform any setup operations. |
procedure(jacobian_f), | private, | pointer | :: | jacobian_function | => | null() |
the low-level function called by compute_jacobian that actually computes the jacobian. |
procedure, public :: initialize => initialize_numdiff | ../../ initialize the class |
procedure, public :: diff_initialize => initialize_numdiff_for_diff | ../../ initialize the class |
procedure, public :: compute_jacobian | ../../ main routine to compute the Jacobian using the selected options. It returns the sparse (vector) form. |
procedure, public :: compute_jacobian_dense | ../../ return the dense |
procedure, public :: compute_jacobian_times_vector | ../../ returns the product of the Jacobian matrix and an input vector |
procedure, public :: destroy => destroy_numdiff_type | ../../ destroy the class |
procedure, public :: print_sparsity_pattern | ../../ print the sparsity pattern in vector form to a file |
procedure, public :: print_sparsity_matrix | ../../ print the sparsity pattern in matrix form to a file |
procedure, public :: set_sparsity_pattern | ../../ manually set the sparsity pattern |
procedure, public :: select_finite_diff_method | ../../ select a method in a specified class so that the variable bounds are not violated when by the perturbations. |
procedure, public :: select_finite_diff_method_for_partition_group | version of select_finite_diff_method for partitioned sparsity pattern. |
procedure, public :: set_numdiff_bounds | ../../ can be called to change the variable bounds. |
procedure, public :: compute_sparsity_pattern | ../../ if the user needs to compute the sparsity pattern manually. (otherwise it will be done the first time the Jacobian is computed) |
procedure, public :: get_sparsity_pattern | ../../ returns the sparsity pattern (if it is allocated) |
procedure, public :: terminate | ../../ can be called by user to stop the computation |
procedure, public :: failed | ../../ to check if an exception was raised. |
procedure, public :: get_error_status | ../../ the status of error condition |
procedure, public :: set_dpert | ../../ change the |
procedure, private :: destroy_sparsity_pattern | ../../ destroy the sparsity pattern |
procedure, private :: compute_perturb_vector | |
procedure, private :: compute_perturbation_vector | ../../ computes the variable perturbation factor |
procedure, private :: compute_sparsity_perturbation_vector | |
procedure, private :: perturb_x_and_compute_f | |
procedure, private :: perturb_x_and_compute_f_partitioned | |
procedure, private :: set_numdiff_sparsity_bounds | |
procedure, private :: set_sparsity_mode | |
procedure, private :: generate_dense_sparsity_partition | |
procedure, private :: compute_jacobian_for_sparsity | |
procedure, private :: resize_sparsity_vectors | |
procedure, private :: raise_exception | |
procedure, private :: clear_exceptions |
Constructor for a finite_diff_method.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in) | :: | id |
unique ID for the method |
||
character(len=*), | intent(in) | :: | name |
the name of the method |
||
integer, | intent(in) | :: | class |
2=backward diffs, 3=central diffs, etc... |
||
integer, | intent(in), | dimension(:) | :: | dx_factors |
multiplicative factors for dx perturbation |
|
integer, | intent(in), | dimension(:) | :: | df_factors |
multiplicative factors for accumulating function evaluations |
|
integer, | intent(in) | :: | df_den_factor |
denominator factor for finite difference equation (times dx) |
Returns all the methods with the given class
(i.e., number of points in the formula).
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in) | :: | class |
the |
all the methods with the specified class
Returns True if an exception has been raised.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(numdiff_type), | intent(in) | :: | me |
Convert an integer to a string.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in) | :: | i |
the integer |
||
logical, | intent(in), | optional | :: | with_sign |
also include the sign (default is False) |
integer converted to a string
Print the contents of a finite_diff_method. Used for debugging.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(finite_diff_method), | intent(in) | :: | me | |||
integer, | intent(in) | :: | iunit |
file unit for printing (assumed to be opened) |
Wrapper for computing the function, using the cache.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(numdiff_type), | intent(inout) | :: | me | |||
real(kind=wp), | intent(in), | dimension(:) | :: | x |
array of variables (size |
|
real(kind=wp), | intent(out), | dimension(:) | :: | f |
array of functions (size |
|
integer, | intent(in), | dimension(:) | :: | funcs_to_compute |
the elements of the function vector that need to be computed (the other are ignored) |
Return a string with the finite difference formula.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(finite_diff_method), | intent(in) | :: | me | |||
character(len=:), | intent(out), | allocatable | :: | formula |
Return a string with the finite difference formula.
Input is the method id
code.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in) | :: | id |
the id code for the method |
||
character(len=:), | intent(out), | allocatable | :: | formula |
the formula string |
|
character(len=:), | intent(out), | optional, | allocatable | :: | name |
Return a finite_diff_method given the id
code.
(the id
codes begin at 1, are sequential, and uniquely define the method).
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in) | :: | id |
the id code for the method |
||
type(finite_diff_method), | intent(out) | :: | fd |
this method (can be used in compute_jacobian) |
||
logical, | intent(out) | :: | found |
true if it was found |
Select a finite diff method of a given class
so that the perturbations
of x
will not violate the variable bounds.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(numdiff_type), | intent(inout) | :: | me | |||
real(kind=wp), | intent(in) | :: | x |
the variable value |
||
real(kind=wp), | intent(in) | :: | xlow |
the variable lower bound |
||
real(kind=wp), | intent(in) | :: | xhigh |
the variable upper bound |
||
real(kind=wp), | intent(in) | :: | dx |
the perturbation value (>0) |
||
type(meth_array), | intent(in) | :: | list_of_methods |
list of available methods to choose from |
||
type(finite_diff_method), | intent(out) | :: | fd |
this method can be used |
||
logical, | intent(out) | :: | status_ok |
true if it really doesn't violate the bounds
(say, the bounds are very close to each other)
if |
Select a finite diff method of a given class
so that the perturbations
of x
will not violate the variable bounds for any variable in the group.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(numdiff_type), | intent(inout) | :: | me | |||
real(kind=wp), | intent(in), | dimension(:) | :: | x |
the variable values |
|
real(kind=wp), | intent(in), | dimension(:) | :: | xlow |
the variable lower bounds |
|
real(kind=wp), | intent(in), | dimension(:) | :: | xhigh |
the variable upper bounds |
|
real(kind=wp), | intent(in), | dimension(:) | :: | dx |
the perturbation values (>0) |
|
type(meth_array), | intent(in) | :: | list_of_methods |
list of available methods to choose from |
||
type(finite_diff_method), | intent(out) | :: | fd |
this method can be used |
||
logical, | intent(out) | :: | status_ok |
true if it really doesn't violate the bounds
(say, the bounds are very close to each other)
if |
Alternate version of initialize_numdiff routine when using diff to compute the Jacobian.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(numdiff_type), | intent(inout) | :: | me | |||
integer, | intent(in) | :: | n |
number of |
||
integer, | intent(in) | :: | m |
number of |
||
real(kind=wp), | intent(in), | dimension(n) | :: | xlow |
lower bounds on |
|
real(kind=wp), | intent(in), | dimension(n) | :: | xhigh |
upper bounds on |
|
procedure(func) | :: | problem_func |
the user function that defines the problem
(returns |
|||
integer, | intent(in) | :: | sparsity_mode |
the sparsity computation method: |
||
procedure(info_f), | optional | :: | info |
a function the user can define which is called when each column of the jacobian is computed. It can be used to perform any setup operations. |
||
integer, | intent(in), | optional | :: | chunk_size |
chunk size for allocating the arrays (must be >0) [default is 100] |
|
real(kind=wp), | intent(in), | optional | :: | eps |
tolerance parameter for diff
if not present, default is |
|
real(kind=wp), | intent(in), | optional | :: | acc |
tolerance parameter for diff
if not present, default is |
|
integer, | intent(in), | optional | :: | cache_size |
if present, this is the cache size for the function cache (default is not to enable cache) |
|
real(kind=wp), | intent(in), | optional, | dimension(n) | :: | xlow_for_sparsity |
lower bounds on |
real(kind=wp), | intent(in), | optional, | dimension(n) | :: | xhigh_for_sparsity |
upper bounds on |
real(kind=wp), | intent(in), | optional, | dimension(n) | :: | dpert_for_sparsity |
required if |
integer, | intent(in), | optional | :: | sparsity_perturb_mode |
perturbation mode (required if |
|
real(kind=wp), | intent(in), | optional | :: | linear_sparsity_tol |
the equality tolerance for derivatives to indicate a constant jacobian element (linear sparsity) |
|
real(kind=wp), | intent(in), | optional | :: | function_precision_tol |
the function precision. two functions values
that are the within this tolerance are
considered the same value. This is used
when estimating the sparsity pattern when
|
|
integer, | intent(in), | optional | :: | num_sparsity_points |
for |
|
logical, | intent(in), | optional | :: | print_messages |
if true, print error messages to |
Change the variable bounds in a numdiff_type.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(numdiff_type), | intent(inout) | :: | me | |||
real(kind=wp), | intent(in), | dimension(:) | :: | xlow |
lower bounds on |
|
real(kind=wp), | intent(in), | dimension(:) | :: | xhigh |
upper bounds on |
Set sparsity mode.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(numdiff_type), | intent(inout) | :: | me | |||
integer, | intent(in) | :: | sparsity_mode |
the sparsity computation method:
1 - assume dense,
2 - three-point simple method,
3 - will be specified by the user in
a subsequent call to set_sparsity_pattern.
4 - computes a two-point jacobian
at |
||
real(kind=wp), | intent(in), | optional, | dimension(:) | :: | xlow_for_sparsity |
lower bounds on |
real(kind=wp), | intent(in), | optional, | dimension(:) | :: | xhigh_for_sparsity |
upper bounds on |
Sets the variable bounds for sparsity in a numdiff_type.
These are only used for sparsity_mode=2
.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(numdiff_type), | intent(inout) | :: | me | |||
real(kind=wp), | intent(in), | optional, | dimension(:) | :: | xlow |
lower bounds on |
real(kind=wp), | intent(in), | optional, | dimension(:) | :: | xhigh |
upper bounds on |
Change the dpert
vector. Can be used after the class has been initialized
to change the perturbation step sizes (e.g., after an iteration).
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(numdiff_type), | intent(inout) | :: | me | |||
real(kind=wp), | intent(in), | dimension(:) | :: | dpert |
perturbation vector for |
Initialize a numdiff_type class. This must be called first.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(numdiff_type), | intent(inout) | :: | me | |||
integer, | intent(in) | :: | n |
number of |
||
integer, | intent(in) | :: | m |
number of |
||
real(kind=wp), | intent(in), | dimension(n) | :: | xlow |
lower bounds on |
|
real(kind=wp), | intent(in), | dimension(n) | :: | xhigh |
upper bounds on |
|
integer, | intent(in) | :: | perturb_mode |
perturbation mode:
1 - perturbation is |
||
real(kind=wp), | intent(in), | dimension(n) | :: | dpert |
perturbation vector for |
|
procedure(func) | :: | problem_func |
the user function that defines the problem
(returns |
|||
integer, | intent(in) | :: | sparsity_mode |
the sparsity computation method:
1 - assume dense,
2 - three-point simple method,
3 - will be specified by the user in
a subsequent call to set_sparsity_pattern.
4 - computes a two-point jacobian
at |
||
integer, | intent(in), | optional | :: | jacobian_method |
|
|
integer, | intent(in), | optional, | dimension(n) | :: | jacobian_methods |
|
integer, | intent(in), | optional | :: | class |
method class for the finite difference method
to use for all |
|
integer, | intent(in), | optional, | dimension(n) | :: | classes |
method class for the finite difference methods to use for each variable. see get_finite_difference_method |
procedure(info_f), | optional | :: | info |
a function the user can define which is called when each column of the jacobian is computed. It can be used to perform any setup operations. |
||
integer, | intent(in), | optional | :: | chunk_size |
chunk size for allocating the arrays (must be >0) [default is 100] |
|
logical, | intent(in), | optional | :: | partition_sparsity_pattern |
if the sparisty pattern is to be partitioned using DSM [default is False] |
|
integer, | intent(in), | optional | :: | cache_size |
if present, this is the cache size for the function cache (default is not to enable cache) |
|
real(kind=wp), | intent(in), | optional, | dimension(n) | :: | xlow_for_sparsity |
lower bounds on |
real(kind=wp), | intent(in), | optional, | dimension(n) | :: | xhigh_for_sparsity |
upper bounds on |
real(kind=wp), | intent(in), | optional, | dimension(n) | :: | dpert_for_sparsity |
for |
integer, | intent(in), | optional | :: | sparsity_perturb_mode |
perturbation mode (required if |
|
real(kind=wp), | intent(in), | optional | :: | linear_sparsity_tol |
the equality tolerance for derivatives to indicate a constant jacobian element (linear sparsity) |
|
real(kind=wp), | intent(in), | optional | :: | function_precision_tol |
the function precision. two functions values
that are the within this tolerance are
considered the same value. This is used
when estimating the sparsity pattern when
|
|
integer, | intent(in), | optional | :: | num_sparsity_points |
for |
destroy the numdiff_type class.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(numdiff_type), | intent(out) | :: | me |
destroy a sparsity_pattern type.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(sparsity_pattern), | intent(out) | :: | me |
Wrapper for dsm to compute the sparsity pattern partition.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(sparsity_pattern), | intent(inout) | :: | me | |||
integer, | intent(in) | :: | n |
number of columns of jacobian matrix |
||
integer, | intent(in) | :: | m |
number of rows of jacobian matrix |
||
integer, | intent(out) | :: | info |
status output from dsm |
Returns the columns in a sparsity partition group.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(sparsity_pattern), | intent(in) | :: | me | |||
integer, | intent(in) | :: | igroup |
group number. Should be |
||
integer, | intent(out) | :: | n_cols |
number of columns in the |
||
integer, | intent(out), | dimension(:), allocatable | :: | cols |
the column numbers in the |
|
integer, | intent(out), | dimension(:), allocatable | :: | nonzero_rows |
the row numbers of all the nonzero Jacobian elements in this group |
|
integer, | intent(out), | dimension(:), allocatable | :: | indices |
nonzero indices in |
|
logical, | intent(out) | :: | status_ok |
true if the partition is valid |
Destroy the sparsity pattern in the class.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(numdiff_type), | intent(inout) | :: | me |
Computes the indices
vector in the class.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(sparsity_pattern), | intent(inout) | :: | me |
To specify the sparsity pattern directly if it is already known.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(numdiff_type), | intent(inout) | :: | me | |||
integer, | intent(in), | dimension(:) | :: | irow |
sparsity pattern nonzero elements row indices |
|
integer, | intent(in), | dimension(:) | :: | icol |
sparsity pattern nonzero elements column indices |
|
integer, | intent(in), | optional, | dimension(:) | :: | linear_irow |
linear sparsity pattern nonzero elements row indices |
integer, | intent(in), | optional, | dimension(:) | :: | linear_icol |
linear sparsity pattern nonzero elements column indices |
real(kind=wp), | intent(in), | optional, | dimension(:) | :: | linear_vals |
linear sparsity values (constant elements of the Jacobian) |
integer, | intent(in), | optional | :: | maxgrp |
DSM sparsity partition
[only used if |
|
integer, | intent(in), | optional, | dimension(:) | :: | ngrp |
DSM sparsity partition (size |
assume all elements of Jacobian are non-zero.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(numdiff_type), | intent(inout) | :: | me | |||
real(kind=wp), | intent(in), | dimension(:) | :: | x |
vector of variables (size |
Generate a "dense" sparsity partition.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(numdiff_type), | intent(inout) | :: | me |
Compute the sparsity pattern by computing the function at three
"random" points in the [xlow_for_sparsity
, xhigh_for_sparsity
] interval
and checking if the function values are the same.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(numdiff_type), | intent(inout) | :: | me | |||
real(kind=wp), | intent(in), | dimension(:) | :: | x |
vector of variables (size |
Resize the sparsity arrays after accumulating them.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(numdiff_type), | intent(inout) | :: | me | |||
integer, | intent(inout) | :: | n_icol | |||
integer, | intent(inout) | :: | n_irow | |||
integer, | intent(inout) | :: | n_linear_icol | |||
integer, | intent(inout) | :: | n_linear_irow | |||
integer, | intent(inout) | :: | n_linear_vals |
Compute the sparsity pattern by computing a 2-point jacobian at a specified
number of "random" points (num_sparsity_points
) in the
[xlow_for_sparsity
, xhigh_for_sparsity
] interval and checking if
they are the same.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(numdiff_type), | intent(inout) | :: | me | |||
real(kind=wp), | intent(in), | dimension(:) | :: | x |
vector of variables (size |
Computes the sparsity pattern and return it. Uses the settings currently in the class.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(numdiff_type), | intent(inout) | :: | me | |||
real(kind=wp), | intent(in), | dimension(:) | :: | x |
vector of variables (size |
|
integer, | intent(out), | dimension(:), allocatable | :: | irow |
sparsity pattern nonzero elements row indices |
|
integer, | intent(out), | dimension(:), allocatable | :: | icol |
sparsity pattern nonzero elements column indices |
|
integer, | intent(out), | optional, | dimension(:), allocatable | :: | linear_irow |
linear sparsity pattern nonzero elements row indices |
integer, | intent(out), | optional, | dimension(:), allocatable | :: | linear_icol |
linear sparsity pattern nonzero elements column indices |
real(kind=wp), | intent(out), | optional, | dimension(:), allocatable | :: | linear_vals |
linear sparsity values (constant elements of the Jacobian) |
Returns the sparsity pattern from the class. If it hasn't been computed, the output arrays will not be allocated.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(numdiff_type), | intent(inout) | :: | me | |||
integer, | intent(out), | dimension(:), allocatable | :: | irow |
sparsity pattern nonzero elements row indices |
|
integer, | intent(out), | dimension(:), allocatable | :: | icol |
sparsity pattern nonzero elements column indices |
|
integer, | intent(out), | optional, | dimension(:), allocatable | :: | linear_irow |
linear sparsity pattern nonzero elements row indices |
integer, | intent(out), | optional, | dimension(:), allocatable | :: | linear_icol |
linear sparsity pattern nonzero elements column indices |
real(kind=wp), | intent(out), | optional, | dimension(:), allocatable | :: | linear_vals |
linear sparsity values (constant elements of the Jacobian) |
integer, | intent(out), | optional | :: | maxgrp |
DSM sparsity partition |
|
integer, | intent(out), | optional, | dimension(:), allocatable | :: | ngrp |
DSM sparsity partition |
just a wrapper for compute_jacobian, that returns a dense (m x n
) matrix.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(numdiff_type), | intent(inout) | :: | me | |||
real(kind=wp), | intent(in), | dimension(:) | :: | x |
vector of variables (size |
|
real(kind=wp), | intent(out), | dimension(:,:), allocatable | :: | jac |
the jacobian matrix |
Perturb the specified optimization variable, and compute the function.
This routine is designed so that df
is accumulated as each function
evaluation is done, to avoid having to allocate more temporary storage.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(numdiff_type), | intent(inout) | :: | me | |||
real(kind=wp), | intent(in), | dimension(:) | :: | x |
nominal variable vector |
|
real(kind=wp), | intent(in) | :: | dx_factor |
factor to multiply |
||
real(kind=wp), | intent(in), | dimension(:) | :: | dx |
the perturbation value for this column |
|
real(kind=wp), | intent(in) | :: | df_factor |
factor to multiply function value |
||
integer, | intent(in) | :: | column |
the variable to perturb |
||
integer, | intent(in), | dimension(:) | :: | idx |
the elements in this column of the Jacobian to compute (passed to function) |
|
real(kind=wp), | intent(inout), | dimension(me%m) | :: | df |
the accumulated function value note: for the first call, this should be set to zero |
Returns the product J*v
, where J
is the m x n
Jacobian matrix
and v
is an n x 1
vector.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(numdiff_type), | intent(inout) | :: | me | |||
real(kind=wp), | intent(in), | dimension(:) | :: | x |
vector of variables (size |
|
real(kind=wp), | intent(in), | dimension(:) | :: | v |
vector (size |
|
real(kind=wp), | intent(out), | dimension(:) | :: | z |
The product |
Compute the Jacobian.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(numdiff_type), | intent(inout) | :: | me | |||
real(kind=wp), | intent(in), | dimension(:) | :: | x |
vector of variables (size |
|
real(kind=wp), | intent(out), | dimension(:), allocatable | :: | jac |
sparse jacobian vector |
A separate version of compute_jacobian to be used only when
computing the sparsity pattern in compute_sparsity_random_2.
It uses class_meths
and the sparsity dperts and bounds.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(numdiff_type), | intent(inout) | :: | me | |||
integer, | intent(in) | :: | i |
the column being computed |
||
type(meth_array), | intent(in) | :: | class_meths |
set of finite diff methods to use |
||
real(kind=wp), | intent(in), | dimension(:) | :: | x |
vector of variables (size |
|
real(kind=wp), | intent(out), | dimension(:), allocatable | :: | jac |
sparse jacobian vector |
Compute the Jacobian using finite differences. (one column at a time)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(numdiff_type), | intent(inout) | :: | me | |||
real(kind=wp), | intent(in), | dimension(:) | :: | x |
vector of variables (size |
|
real(kind=wp), | intent(in), | dimension(me%n) | :: | dx |
absolute perturbation (>0) for each variable |
|
real(kind=wp), | intent(out), | dimension(:) | :: | jac |
sparse jacobian vector (size
|
Compute the Jacobian one element at a time using the Neville's process algorithm diff. This takes a very large number of function evaluations, but should give a very accurate answer.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(numdiff_type), | intent(inout) | :: | me | |||
real(kind=wp), | intent(in), | dimension(:) | :: | x |
vector of variables (size |
|
real(kind=wp), | intent(in), | dimension(me%n) | :: | dx |
absolute perturbation (>0) for each variable |
|
real(kind=wp), | intent(out), | dimension(:) | :: | jac |
sparse jacobian vector (size
|
Compute the Jacobian using finite differences, (using the partitioned sparsity pattern to compute multiple columns at a time).
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(numdiff_type), | intent(inout) | :: | me | |||
real(kind=wp), | intent(in), | dimension(:) | :: | x |
vector of variables (size |
|
real(kind=wp), | intent(in), | dimension(me%n) | :: | dx |
absolute perturbation (>0) for each variable |
|
real(kind=wp), | intent(out), | dimension(:) | :: | jac |
sparse jacobian vector |
Perturb the specified optimization variable, and compute the function.
This routine is designed so that df
is accumulated as each function
evaluation is done, to avoid having to allocate more temporary storage.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(numdiff_type), | intent(inout) | :: | me | |||
real(kind=wp), | intent(in), | dimension(:) | :: | x |
nominal variable vector |
|
real(kind=wp), | intent(in) | :: | dx_factor |
factor to multiply |
||
real(kind=wp), | intent(in), | dimension(:) | :: | dx |
the perturbation value for this column |
|
real(kind=wp), | intent(in) | :: | df_factor |
factor to multiply function value |
||
integer, | intent(in), | dimension(:) | :: | columns |
the variables to perturb |
|
integer, | intent(in), | dimension(:) | :: | idx |
the elements in this column of the Jacobian to compute (passed to function) |
|
real(kind=wp), | intent(inout), | dimension(me%m) | :: | df |
the accumulated function value note: for the first call, this should be set to zero |
Compute dx
, the perturbation vector for x
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(numdiff_type), | intent(inout) | :: | me | |||
real(kind=wp), | intent(in), | dimension(me%n) | :: | x |
vector of variables (size |
|
real(kind=wp), | intent(in), | dimension(me%n) | :: | dpert | ||
integer, | intent(in) | :: | perturb_mode | |||
real(kind=wp), | intent(out), | dimension(me%n) | :: | dx |
absolute perturbation (>0) for each variable |
Compute dx
, the perturbation vector for x
used
when computing the gradients.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(numdiff_type), | intent(inout) | :: | me | |||
real(kind=wp), | intent(in), | dimension(me%n) | :: | x |
vector of variables (size |
|
real(kind=wp), | intent(out), | dimension(me%n) | :: | dx |
absolute perturbation (>0) for each variable |
Compute dx
, the perturbation vector for x
used
when computing the sparsity pattern.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(numdiff_type), | intent(inout) | :: | me | |||
real(kind=wp), | intent(in), | dimension(me%n) | :: | x |
vector of variables (size |
|
real(kind=wp), | intent(out), | dimension(me%n) | :: | dx |
absolute perturbation (>0) for each variable |
Print the sparsity pattern.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(sparsity_pattern), | intent(in) | :: | me | |||
integer, | intent(in) | :: | n |
number of variables (columns of jacobian) |
||
integer, | intent(in) | :: | m |
number of functions (rows of jacobian) |
||
integer, | intent(in) | :: | iunit |
file unit to write to. (assumed to be already opened) |
||
logical, | intent(in), | optional | :: | dense |
if present and true, the matrix form of the sparsity pattern is printed (default is vector form) |
Print the sparsity pattern in vector form (irow
, icol
).
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(numdiff_type), | intent(inout) | :: | me | |||
integer, | intent(in) | :: | iunit |
file unit to write to. (assumed to be already opened) |
Print the sparsity pattern in matrix form.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(numdiff_type), | intent(inout) | :: | me | |||
integer, | intent(in) | :: | iunit |
file unit to write to. (assumed to be already opened) |
A user-callable routine. When called, it will terminate
all computations and return. The istat
return code will be
set to -1
. This can be called in the function or the info function.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(numdiff_type), | intent(inout) | :: | me |
Raise an exception.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(numdiff_type), | intent(inout) | :: | me | |||
integer, | intent(in) | :: | istat |
error code. |
||
character(len=*), | intent(in) | :: | routine |
the routine where the error was raised. |
||
character(len=*), | intent(in) | :: | error_msg |
error message string. |
Clear all exceptions.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(numdiff_type), | intent(inout) | :: | me |
Returns the current error code and message.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(numdiff_type), | intent(in) | :: | me | |||
integer, | intent(out), | optional | :: | istat |
error code ( |
|
character(len=:), | intent(out), | optional, | allocatable | :: | error_msg |
error message string. |