state_space Derived Type

type, public :: state_space

Defines a state-space representation of a dynamic system. This implementation takes the form:

Where:

  • denotes time.

  • is the state vector.

  • is the input vector.

  • is the output vector.


Contents


Components

Type Visibility Attributes Name Initial
real(kind=real64), public, allocatable, dimension(:,:) :: A

The N-by-N dynamics matrix, where N is the number of state variables.

real(kind=real64), public, allocatable, dimension(:,:) :: B

The N-by-M input matrix, where M is the number of inputs.

real(kind=real64), public, allocatable, dimension(:,:) :: C

The P-by-N output matrix, where P is the number of outputs.

real(kind=real64), public, allocatable, dimension(:,:) :: D

The P-by-M feedthrough matrix.


Constructor

public interface state_space

  • private pure function state_space_init(m, b, k, n_out) result(rst)

    Initializes the state space model.

    The output matrix is initialized to one, and the feedthrough matrix is initialized to zero.

    Arguments

    Type IntentOptional Attributes Name
    real(kind=real64), intent(in), dimension(:,:) :: m

    The N-by-N mass matrix.

    real(kind=real64), intent(in), dimension(size(m, 1), size(m, 2)) :: b

    The N-by-N damping matrix.

    real(kind=real64), intent(in), dimension(size(m, 1), size(m, 2)) :: k

    The N-by-N stiffness matrix.

    integer(kind=int32), intent(in), optional :: n_out

    The number of outputs. The default is 1.

    Return Value type(state_space)

    The [[state_space]] model.

  • private pure function state_space_init_scalar(m, b, k) result(rst)

    Initializes the state space model.

    The output matrix is initialized to one, and the feedthrough matrix is initialized to zero.

    Arguments

    Type IntentOptional Attributes Name
    real(kind=real64), intent(in) :: m

    The mass.

    real(kind=real64), intent(in) :: b

    The damping.

    real(kind=real64), intent(in) :: k

    The stiffness.

    Return Value type(state_space)

    The [[state_space]] model.

  • private pure function state_space_init_matrices(a, b, c, d) result(rst)

    Initializes the state space model.

    Arguments

    Type IntentOptional Attributes Name
    real(kind=real64), intent(in), dimension(:,:) :: a

    The N-by-N dynamics matrix.

    real(kind=real64), intent(in), dimension(:,:) :: b

    The N-by-M input matrix.

    real(kind=real64), intent(in), dimension(:,:) :: c

    The P-by-N output matrix.

    real(kind=real64), intent(in), dimension(:,:) :: d

    The P-by-M feedthrough matrix.

    Return Value type(state_space)

    The resulting [[state_space]] object.

  • private pure function state_space_init_pid(kp, ki, kd, tau, a, b, c, d) result(rst)

    Initializes a state-space model that employs a closed-loop PID controller.

    The PID model is augmented into the plant model as follows.

    Where the augmented matrices are as follows.

    Arguments

    Type IntentOptional Attributes Name
    real(kind=real64), intent(in) :: kp

    The proportional gain term.

    real(kind=real64), intent(in) :: ki

    The integral gain term.

    real(kind=real64), intent(in) :: kd

    The derivative gain term.

    real(kind=real64), intent(in) :: tau

    The time constant of the first order derivative filter .

    real(kind=real64), intent(in), dimension(:,:) :: a

    The N-by-N dynamics matrix for the plant.

    real(kind=real64), intent(in), dimension(size(a, 1), 1) :: b

    The N-by-1 input matrix for the plant.

    real(kind=real64), intent(in), dimension(1, size(a, 1)) :: c

    The 1-by-N output matrix for the plant.

    real(kind=real64), intent(in), dimension(1, 1) :: d

    The 1-by-1 feedthrough matrix for the plant.

    Return Value type(state_space)

    The resulting [[state_space]] object.

  • private pure function state_space_init_pid_plant(kp, ki, kd, tau, plant) result(rst)

    Initializes a state-space model that employs a closed-loop PID controller.

    The PID model is augmented into the plant model as follows.

    Where the augmented matrices are as follows.

    Arguments

    Type IntentOptional Attributes Name
    real(kind=real64), intent(in) :: kp

    The proportional gain term.

    real(kind=real64), intent(in) :: ki

    The integral gain term.

    real(kind=real64), intent(in) :: kd

    The derivative gain term.

    real(kind=real64), intent(in) :: tau

    The time constant of the first order derivative filter .

    class(state_space), intent(in) :: plant

    The plant model.

    Return Value type(state_space)

    The resulting [[state_space]] object.


Type-Bound Procedures

procedure, public :: evaluate_derivatives => ss_eval_deriv

  • private pure function ss_eval_deriv(this, u, x) result(rst)

    Evaluates the state time derivative .

    Arguments

    Type IntentOptional Attributes Name
    class(state_space), intent(in) :: this

    The state_space object.

    real(kind=real64), intent(in), dimension(:) :: u

    The M-element input array.

    real(kind=real64), intent(in), dimension(:) :: x

    The N-element state array.

    Return Value real(kind=real64), allocatable, dimension(:)

    The N-element state time derivative vector.

procedure, public :: evaluate_output => ss_eval_output

  • private pure function ss_eval_output(this, u, x) result(rst)

    Evaluates the output vector .

    Arguments

    Type IntentOptional Attributes Name
    class(state_space), intent(in) :: this

    The state_space object.

    real(kind=real64), intent(in), dimension(:) :: u

    The M-element input array.

    real(kind=real64), intent(in), dimension(:) :: x

    The N-element state array.

    Return Value real(kind=real64), allocatable, dimension(:)

    The P-element output array.

procedure, public :: poles => ss_poles

  • private function ss_poles(this, err) result(rst)

    Computes the poles of the state space model.

    Arguments

    Type IntentOptional Attributes Name
    class(state_space), intent(in) :: this

    The state_space object.

    class(errors), intent(inout), optional, target :: err

    An error handling object.

    Return Value complex(kind=real64), allocatable, dimension(:)

    The poles of the model.

generic, public :: transfer_function => ss_transfer_fcn, ss_transfer_fcn_omega, ss_transfer_fcn_array, ss_transfer_fcn_omega_array

  • private pure function ss_transfer_fcn(this, s) result(rst)

    Evaluates the transfer functions for the model at the parameter .

    Arguments

    Type IntentOptional Attributes Name
    class(state_space), intent(in) :: this

    The state_space object.

    complex(kind=real64), intent(in) :: s

    The frequency at which to evaluate the transfer functions.

    Return Value complex(kind=real64), allocatable, dimension(:,:)

    The resulting transfer functions.

  • private pure function ss_transfer_fcn_omega(this, omega) result(rst)

    Evaluates the transfer functions for the model at frequency .

    Arguments

    Type IntentOptional Attributes Name
    class(state_space), intent(in) :: this

    The state_space object.

    real(kind=real64), intent(in) :: omega

    The frequency at which to evaluate the transfer functions.

    Return Value complex(kind=real64), allocatable, dimension(:,:)

    The resulting transfer functions.

  • private pure function ss_transfer_fcn_array(this, s) result(rst)

    Evaluates the transfer functions for the model at the frequencies given in the array .

    Arguments

    Type IntentOptional Attributes Name
    class(state_space), intent(in) :: this

    The state_space object.

    complex(kind=real64), intent(in), dimension(:) :: s

    The frequencies at which to evaluate the transfer functions.

    Return Value complex(kind=real64), allocatable, dimension(:,:,:)

    The resulting transfer functions, with each page of the array containing the transfer functions for a specific frequency.

  • private pure function ss_transfer_fcn_omega_array(this, omega) result(rst)

    Evaluates the transfer functions for the model at the frequencies given in the array .

    Arguments

    Type IntentOptional Attributes Name
    class(state_space), intent(in) :: this

    The state_space object.

    real(kind=real64), intent(in), dimension(:) :: omega

    The frequencies at which to evaluate the transfer functions.

    Return Value complex(kind=real64), allocatable, dimension(:,:,:)

    The resulting transfer functions, with each page of the array containing the transfer functions for a specific frequency.

procedure, public :: zeros => ss_zeros

  • private function ss_zeros(this, err) result(rst)

    Computes the zeros of the state space model.

    Arguments

    Type IntentOptional Attributes Name
    class(state_space), intent(in) :: this

    The state_space object.

    class(errors), intent(inout), optional, target :: err

    An error handling object.

    Return Value complex(kind=real64), allocatable, dimension(:)

    The zeros of the model.