I am working on a computational fluid dynamics code, and most of the primary design of the code is already written in Fortran.
I intend to switch the linear algebra solver to use some PETSc utilities, instead.
The problem is that PETSc's vectors/matrices are PETSc's own type of data structure (I don't mean datatype; one could potentially ask Fortran to make an N-dimensional array of a particular datatype.)
Is there a way that I could have a subroutine that takes Fortran-like arrays, but somehow casts/converts them to be passed to PETSc's functions?
The code extensively relies on Fortran's array operations, and going back to switch everything to accommodate PETSc is not an option.
Any ideas?
Edit 1:
To provide some details, the code runs on Fortran's allocatable arrays; meanwhile, PETSc uses its own types (C-like typedef structs) as follows:
type(Vec) a_petsc_vector
type(Mat) a_petsc_matrix
For example, to set values, the user is to call MatSetValues() and VecSetValues() interfaces.
Regarding the type of my matrix, it is sparse. Right now, the code uses LSQR iterative solver to solve for AX=B.
My hope is to encapsulate PETSc-like definitions and functions calls in a single subroutine, or maximally a module, without the rest of the code being affected by it. As you can see, I need to efficiently pass Fortran-like allocatable arrays to what PETSc subtoutines/functions accepts as proper inputs. I guess I can write my subroutine in a way that it re-creates and re-populates PETSc-like vectors/matrices from a given fortran array, but this seems to be a horrible idea in terms of overhead and efficinecy because this process repeats at every timestep (i.e., I will be calling this subroutine to solve my LA equations tens of thousands of times, and re-creating and distroying huge vectors/matrices makes me worse off than not use PETSc at all).