precice icon indicating copy to clipboard operation
precice copied to clipboard

Multiple SolverInterfaces using the C and Fortran bindings

Open fsimonis opened this issue 2 years ago • 3 comments

Describe your setup

preCICE Version: 2.3.0

Describe the problem

The C++ API allows multiple instances of the precice::SolverInterface. While not supported in the back-end yet #655, this is possible use-case of preCICE and it is allowed by the API.

The C and Fortran APIs follow a singleton style. There exists only a single SolverInterface. This is not consistent with the C++ interface.

Expected behaviour

The C/Fortran interfaces should allow to create multiple instances of the SolverInterface.

fsimonis avatar Mar 10 '22 11:03 fsimonis

Historic remark: we had the "Fastest Fortran bindings" at some point, which implemented sth like this already. At least for two instances. https://github.com/precice/precice/blob/v1.6.1/src/precice/bindings/fortran/SolverInterfaceFASTEST.cpp

uekerman avatar Mar 16 '22 09:03 uekerman

This should be easy to fix with a new "Participant" API which stores it's own heap-allocated Participant instance.

type :: participant
    private
    type(c_ptr) :: ptr = c_null_ptr     !  Participant *
contains

    ! Steering Methods
    procedure :: initialize
    procedure :: advance
    procedure :: finalize

    ! Implicit Coupling
    procedure :: requiresWritingCheckpoint
    procedure :: requiresReadingCheckpoint

    ! Status queries
    procedure :: getMeshDimensions
    procedure :: getDataDimensions
    procedure :: isCouplingOngoing
    procedure :: isTimeWindowComplete
    procedure :: getMaxTimeStepSize

    ! Mesh Access
    procedure :: requiresMeshConnectivityFor
    procedure :: setMeshVertex
    procedure :: getMeshVertexSize
    procedure :: setMeshVertices
    ! procedure :: setMeshEdge
    ! procedure :: setMeshEdges
    ! procedure :: setMeshTriangle
    ! procedure :: setMeshTriangles
    ! procedure :: setMeshQuad
    ! procedure :: setMeshQuads
    ! procedure :: setMeshTetrahedron
    ! procedure :: setMeshTetrahedra

    ! Data Access
    procedure :: requiresInitialData
    procedure :: writeData
    procedure :: readData

    ! Direct Access
    procedure :: setMeshAccessRegion
    procedure :: getMeshVertexIDsAndCoordinates

    ! Gradient Data (Experimental)
    procedure :: requiresGradientDataFor
    procedure :: writeGradientData

    ! Finalizer
    final :: destroy_participant

end type

https://github.com/ivan-pi/fortran-module/blob/participant/src/precice_participant_api.F90

ivan-pi avatar Mar 22 '24 08:03 ivan-pi