Model Derived Type

type, public, extends(ModelSurrogate) :: Model

Object storing, evaluating, and manipulating various term objects, with terms categorized as either implicit (MatrixTerm objects) or general (Term objects).


Components

Type Visibility Attributes Name Initial
logical, public :: userDefined = .false.

True only if user explicitly sets it to true

integer(kind=ik), private :: numAddedMatrixTerms

Tracker for number of allocated matrix terms

integer(kind=ik), private :: numAddedGeneralTerms

Tracker for number of allocated general terms

type(IntArray), private, allocatable, dimension(:) :: implicitTermGroup

Groups of matrix terms used to identify terms for evaluation/manipulation

type(IntArray), private, allocatable, dimension(:) :: generalTermGroup

Groups of general terms used to identify terms for evaluation/manipulation

logical, private, allocatable, dimension(:) :: implicitGroupMixed

True for each implicit group that is either empty or contains terms that evolve/evaluate more than one variable - used to forbid explicit evaluation of such terms

logical, private, allocatable, dimension(:) :: generalGroupMixed

True for each general group that that is either empty or contains terms that evolve/evaluate more than one variable - used to forbid explicit evaluation of such terms

type(MatTermContainer), private, allocatable, dimension(:) :: implicitTerms

Container for MatrixTerm objects living in this model

type(TermContainer), private, allocatable, dimension(:) :: generalTerms

Container for general Term objects living in this model

logical, private :: assembled

True if the model is assembled and ready for use

logical, private, dimension(4) :: setupCounter

All true if the model is ready to accept terms

class(ModelboundData), private, allocatable :: modelData

Optional model data that can be used by contained terms

type(StringArray), private, allocatable, dimension(:) :: implicitTermNames

Names of implicit terms

type(StringArray), private, allocatable, dimension(:) :: generalTermNames

Names of general terms

logical, private, allocatable, dimension(:) :: skipPattern

Flag to skip pattern of particular implicit term when adding (for performance on startup)


Type-Bound Procedures

procedure, public :: isDefined => isDefinedObject

  • interface

    private pure module function isDefinedObject(this) result(defined)

    Getter for userDefined

    Arguments

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

    Return Value logical

procedure, public :: makeDefined => makeDefinedObject

  • interface

    private pure module subroutine makeDefinedObject(this)

    Set userDefined to .true.

    Arguments

    Type IntentOptional Attributes Name
    class(Object), intent(inout) :: this

procedure, public :: makeUndefined => makeUndefinedObject

  • interface

    private pure module subroutine makeUndefinedObject(this)

    Set userDefined to .false.

    Arguments

    Type IntentOptional Attributes Name
    class(Object), intent(inout) :: this

procedure, public :: isAssembled

  • interface

    private pure module function isAssembled(this) result(assembled)

    Check if model is assembled and ready to use

    Arguments

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

    Return Value logical

procedure, public :: addImplicitTerm

  • interface

    private pure module subroutine addImplicitTerm(this, impTerm, implicitGroups, generalGroups, termName, skipPattern)

    Add a MatrixTerm object to the model (deallocating the source!), and specify which implicit and general groups it belongs to

    Arguments

    Type IntentOptional Attributes Name
    class(Model), intent(inout) :: this
    class(MatrixTerm), intent(inout), allocatable :: impTerm

    MatrixTerm object to be reallocated to this model

    integer(kind=ik), intent(in), dimension(:) :: implicitGroups

    Implicit groups the added term should belong to

    integer(kind=ik), intent(in), dimension(:) :: generalGroups

    General groups the added term should belong to

    character(len=*), intent(in) :: termName

    Name of added term for indexing purposes

    logical, intent(in), optional :: skipPattern

    True if the matrix term pattern should not be added to PETSc preallocation

procedure, public :: addGeneralTerm

  • interface

    private pure module subroutine addGeneralTerm(this, genTerm, generalGroups, termName)

    Add a Term object to the model (deallocating the source!), and specify which general groups it belongs to

    Arguments

    Type IntentOptional Attributes Name
    class(Model), intent(inout) :: this
    class(Term), intent(inout), allocatable :: genTerm

    General Term object to be reallocated to this model

    integer(kind=ik), intent(in), dimension(:) :: generalGroups

    General groups the added term should belong to

    character(len=*), intent(in) :: termName

    Name of added term for indexing purposes

procedure, public :: updateTermGroup

  • interface

    private module subroutine updateTermGroup(this, groupIndex, varCont)

    Update a term group - if groupIndex > size(implicitGroup) it is taken to be in the general group

    Arguments

    Type IntentOptional Attributes Name
    class(Model), intent(inout) :: this
    integer(kind=ik), intent(in) :: groupIndex

    Group index to be updated

    type(VariableContainer), intent(in) :: varCont

    Variable container used to update this group

procedure, public :: evaluateTermGroup

  • interface

    private pure module function evaluateTermGroup(this, groupIndex, varCont) result(res)

    Evaluate a term group, returning the sum of all explicit results from the term group - if groupIndex > size(implicitGroup) it is taken to be in the general group

    Arguments

    Type IntentOptional Attributes Name
    class(Model), intent(in) :: this
    integer(kind=ik), intent(in) :: groupIndex

    Group index to evaluate

    type(VariableContainer), intent(in) :: varCont

    Variable container used to evaluate this group

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

procedure, public :: evaluateTermByName

  • interface

    private pure module function evaluateTermByName(this, name, varCont) result(res)

    Evaluate a term by name

    Arguments

    Type IntentOptional Attributes Name
    class(Model), intent(in) :: this
    character(len=*), intent(in) :: name
    type(VariableContainer), intent(in) :: varCont

    Variable container used to evaluate this term

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

procedure, public :: calculateMatGroupValues

  • interface

    private pure module subroutine calculateMatGroupValues(this, groupIndex, varCont)

    Calculate matrix value in implicit term group given by groupIndex

    Arguments

    Type IntentOptional Attributes Name
    class(Model), intent(inout) :: this
    integer(kind=ik), intent(in) :: groupIndex

    Group index of terms whose matrices should be calculated

    type(VariableContainer), intent(in) :: varCont

    Variable container used for the calculation

procedure, public :: addMatGroupValsToPETSc

  • interface

    private module subroutine addMatGroupValsToPETSc(this, groupIndex, petscCont, mult, petscGroup)

    Send off matrix values of given term group to the PETSc controller, multiplied by mult

    Arguments

    Type IntentOptional Attributes Name
    class(Model), intent(in) :: this
    integer(kind=ik), intent(in) :: groupIndex

    Group index of terms whose matrices should be sent to PETSc

    type(PETScController), intent(inout) :: petscCont

    PETScController object housing PETSc matrices

    real(kind=rk), intent(in) :: mult

    Multiplier used when adding matrices to PETSc - usually -dt

    integer(kind=ik), intent(in), optional :: petscGroup

procedure, public :: assemble

  • interface

    private module subroutine assemble(this, petscCont)

    Assemble all of the matrix terms, preallocate PETScController objects and make sure model is ready for use

    Arguments

    Type IntentOptional Attributes Name
    class(Model), intent(inout) :: this
    type(PETScController), intent(inout), optional :: petscCont

    Optional PETScController - should be present if the model has any implicitly evaluated terms

procedure, public :: isGroupMixed

  • interface

    private pure module function isGroupMixed(this, groupIndex) result(mixed)

    Return true if group with given index is mixed

    Arguments

    Type IntentOptional Attributes Name
    class(Model), intent(in) :: this
    integer(kind=ik), intent(in) :: groupIndex

    Return Value logical

procedure, public :: getGroupVarName

  • interface

    private pure module function getGroupVarName(this, groupIndex) result(name)

    Return evolved variable name for given group index - works only for groups that are not mixed

    Arguments

    Type IntentOptional Attributes Name
    class(Model), intent(in) :: this
    integer(kind=ik), intent(in) :: groupIndex

    Return Value character(len=:), allocatable

procedure, public :: setModelData

  • interface

    private module subroutine setModelData(this, modelData)

    Setter for modelData

    Arguments

    Type IntentOptional Attributes Name
    class(Model), intent(inout) :: this
    class(ModelboundData), intent(in) :: modelData

procedure, public :: copyModelData

  • interface

    private module subroutine copyModelData(this, modelData)

    Copy model data from this model into modelData

    Arguments

    Type IntentOptional Attributes Name
    class(Model), intent(in) :: this
    class(ModelboundData), intent(inout), allocatable :: modelData

procedure, public :: updateModelData

  • interface

    private module subroutine updateModelData(this, varCont, updatePriority)

    Update this model's modelbound data if allocated

    Arguments

    Type IntentOptional Attributes Name
    class(Model), intent(inout) :: this
    type(VariableContainer), intent(in) :: varCont

    Variable container used in the update

    integer(kind=ik), intent(in), optional :: updatePriority

    Priority for this update call

procedure, public :: copyModelboundDataEntry

  • interface

    private module subroutine copyModelboundDataEntry(this, varName, container)

    Copy modelbound variable data with given name. Will throw error if no modelbound data is found

    Arguments

    Type IntentOptional Attributes Name
    class(Model), intent(in) :: this
    character(len=*), intent(in) :: varName

    Name of data

    real(kind=rk), intent(inout), allocatable, dimension(..) :: container

    Container to copy into

procedure, public :: setNumImplicitTerms

  • interface

    private pure module subroutine setNumImplicitTerms(this, numImplicitTerms)

    Set number of implicit terms and perform allocation

    Arguments

    Type IntentOptional Attributes Name
    class(Model), intent(inout) :: this
    integer(kind=ik), intent(in) :: numImplicitTerms

    Number of MatrixTerm objects this model expects to be added

procedure, public :: setNumGeneralTerms

  • interface

    private pure module subroutine setNumGeneralTerms(this, numGeneralTerms)

    Set number of general terms and perform allocation

    Arguments

    Type IntentOptional Attributes Name
    class(Model), intent(inout) :: this
    integer(kind=ik), intent(in) :: numGeneralTerms

    Number of general Term objects this model expects to be added

procedure, public :: setNumImplicitGroups

  • interface

    private pure module subroutine setNumImplicitGroups(this, numImplicitGroups)

    Set number of implicit groups and perform allocation

    Arguments

    Type IntentOptional Attributes Name
    class(Model), intent(inout) :: this
    integer(kind=ik), intent(in) :: numImplicitGroups

    Number of implicit/matrix term groups registered with this model

procedure, public :: setNumGeneralGroups

  • interface

    private pure module subroutine setNumGeneralGroups(this, numGeneralGroups)

    Set number of general groups and perform allocation

    Arguments

    Type IntentOptional Attributes Name
    class(Model), intent(inout) :: this
    integer(kind=ik), intent(in) :: numGeneralGroups

    Number of general term groups registered with this model

procedure, public :: init => initModel

  • interface

    private pure module subroutine initModel(this, numImplicitTerms, numGeneralTerms, numImplicitGroups, numGeneralGroups)

    Model initialization routine

    Arguments

    Type IntentOptional Attributes Name
    class(Model), intent(inout) :: this
    integer(kind=ik), intent(in), optional :: numImplicitTerms

    Number of MatrixTerm objects this model expects to be added

    integer(kind=ik), intent(in), optional :: numGeneralTerms

    Number of general Term objects this model expects to be added

    integer(kind=ik), intent(in), optional :: numImplicitGroups

    Number of implicit/matrix term groups registered with this model

    integer(kind=ik), intent(in), optional :: numGeneralGroups

    Number of general term groups registered with this model

procedure, public :: getImplicitTermRowData

  • interface

    private pure module function getImplicitTermRowData(this, termIndex) result(rowData)

    Return row data of implicit term with given term index

    Arguments

    Type IntentOptional Attributes Name
    class(Model), intent(in) :: this
    integer(kind=ik), intent(in) :: termIndex

    Return Value type(SparseRowData)

procedure, public :: getImplicitTermIndexingData

  • interface

    private pure module function getImplicitTermIndexingData(this, termIndex) result(indexingData)

    Return indexing data of implicit term with given term index

    Arguments

    Type IntentOptional Attributes Name
    class(Model), intent(in) :: this
    integer(kind=ik), intent(in) :: termIndex

    Return Value type(MatrixTermIndexingData)

procedure, public :: isTermNameRegistered

  • interface

    private pure module function isTermNameRegistered(this, name) result(reg)

    Check whether term with given name is registered

    Arguments

    Type IntentOptional Attributes Name
    class(Model), intent(in) :: this
    character(len=*), intent(in) :: name

    Return Value logical

procedure, public :: isTermNameImplicit

  • interface

    private pure module function isTermNameImplicit(this, name) result(reg)

    Check whether term with given name is implicit

    Arguments

    Type IntentOptional Attributes Name
    class(Model), intent(in) :: this
    character(len=*), intent(in) :: name

    Return Value logical

procedure, public :: getImplicitTermIndex

  • interface

    private pure module function getImplicitTermIndex(this, name) result(ind)

    Get index of implicit term with given name

    Arguments

    Type IntentOptional Attributes Name
    class(Model), intent(in) :: this
    character(len=*), intent(in) :: name

    Return Value integer(kind=ik)

procedure, public :: getGeneralTermIndex

  • interface

    private pure module function getGeneralTermIndex(this, name) result(ind)

    Get index of general term with given name

    Arguments

    Type IntentOptional Attributes Name
    class(Model), intent(in) :: this
    character(len=*), intent(in) :: name

    Return Value integer(kind=ik)