PACMAN 0.1.0
Portable Algorithms for Coupling, Mapping, and Adaptive iNterpolation
Loading...
Searching...
No Matches
pacman_fortran.f90
Go to the documentation of this file.
1!
2! This file is subject to the terms and conditions defined in
3! file 'LICENSE', which is part of this source code package.
4!
5
28 use iso_c_binding
29 implicit none
30 private
31
32 ! -----------------------------------------------------------------
33 ! Public procedures
34 ! -----------------------------------------------------------------
37 public :: pacman_best_execspace
39 public :: pacman_fe_interpolate
42 public :: pacman_vtk_cell_dim
43
44 ! -----------------------------------------------------------------
45 ! Execution space constants (match PACMAN::ExecSpaces)
46 ! -----------------------------------------------------------------
47 integer(c_int), parameter, public :: pacman_serial = 0
48 integer(c_int), parameter, public :: pacman_openmp = 1
49 integer(c_int), parameter, public :: pacman_threads = 2
50 integer(c_int), parameter, public :: pacman_cuda = 3
51 integer(c_int), parameter, public :: pacman_hip = 4
52 integer(c_int), parameter, public :: pacman_sycl = 5
53
54 ! -----------------------------------------------------------------
55 ! RBF function constants (match PACMAN::RbfFunctions)
56 ! 0x10 = 16, 0x11 = 17, 0x12 = 18, 0x13 = 19, 0x14 = 20
57 ! -----------------------------------------------------------------
58 integer(c_int), parameter, public :: pacman_wendlandc0 = 16
59 integer(c_int), parameter, public :: pacman_wendlandc2 = 17
60 integer(c_int), parameter, public :: pacman_wendlandc4 = 18
61 integer(c_int), parameter, public :: pacman_wendlandc6 = 19
62 integer(c_int), parameter, public :: pacman_wendlandc8 = 20
63
64 ! -----------------------------------------------------------------
65 ! FE method constants (match PACMAN::TransferMethods)
66 ! 0xF0 = 240, 0xF1 = 241, ..., 0xF4 = 244
67 ! -----------------------------------------------------------------
68 integer(c_int), parameter, public :: pacman_fe_nearest_nearest = 240
69 integer(c_int), parameter, public :: pacman_fe_interp_clamp = 241
70 integer(c_int), parameter, public :: pacman_fe_interp_nearest = 242
71 integer(c_int), parameter, public :: pacman_fe_interp_zerofill = 243
72 integer(c_int), parameter, public :: pacman_fe_interp_extrap = 244
73
74 ! -----------------------------------------------------------------
75 ! MLS constant (match PACMAN::TransferMethods::MLS = 0xF6 = 246)
76 ! -----------------------------------------------------------------
77 integer(c_int), parameter, public :: pacman_mls = 246
78
79 ! -----------------------------------------------------------------
80 ! ISO C interfaces to the plain-C shim (fortran_interface.cpp)
81 ! -----------------------------------------------------------------
82 interface
83 subroutine pacman_kokkos_initialize_c() &
84 bind(c, name='pacman_kokkos_initialize_c')
85 end subroutine
86
87 subroutine pacman_kokkos_finalize_c() &
88 bind(c, name='pacman_kokkos_finalize_c')
89 end subroutine
90
91 function pacman_best_execspace_c() result(es) &
92 bind(c, name='pacman_best_execspace_c')
93 import :: c_int
94 integer(c_int) :: es
95 end function
96
97 function pacman_rbf_interpolate_c( &
98 spaceDimension, execSpace, rbfFunction, &
99 sourcePoints, nSourcePoints, sourceValues, &
100 targetPoints, nTargetPoints, targetValues) result(ierr) &
101 bind(c, name='pacman_rbf_interpolate_c')
102 import :: c_int, c_ptr
103 integer(c_int), value :: spacedimension
104 integer(c_int), value :: execspace
105 integer(c_int), value :: rbffunction
106 type(c_ptr), value :: sourcepoints
107 integer(c_int), value :: nsourcepoints
108 type(c_ptr), value :: sourcevalues
109 type(c_ptr), value :: targetpoints
110 integer(c_int), value :: ntargetpoints
111 type(c_ptr), value :: targetvalues
112 integer(c_int) :: ierr
113 end function
114
115 function pacman_fe_interpolate_c( &
116 spaceDimension, execSpace, method, &
117 sourcePoints, nSourcePoints, sourceValues, &
118 connVal, connValSize, connOff, connOffSize, cellTypes, &
119 targetPoints, nTargetPoints, targetValues, targetStatus) result(ierr) &
120 bind(c, name='pacman_fe_interpolate_c')
121 import :: c_int, c_ptr
122 integer(c_int), value :: spacedimension
123 integer(c_int), value :: execspace
124 integer(c_int), value :: method
125 type(c_ptr), value :: sourcepoints
126 integer(c_int), value :: nsourcepoints
127 type(c_ptr), value :: sourcevalues
128 type(c_ptr), value :: connval
129 integer(c_int), value :: connvalsize
130 type(c_ptr), value :: connoff
131 integer(c_int), value :: connoffsize
132 type(c_ptr), value :: celltypes
133 type(c_ptr), value :: targetpoints
134 integer(c_int), value :: ntargetpoints
135 type(c_ptr), value :: targetvalues
136 type(c_ptr), value :: targetstatus
137 integer(c_int) :: ierr
138 end function
139
140 function pacman_mls_interpolate_c( &
141 spaceDimension, execSpace, &
142 sourcePoints, nSourcePoints, sourceValues, &
143 targetPoints, nTargetPoints, targetValues) result(ierr) &
144 bind(c, name='pacman_mls_interpolate_c')
145 import :: c_int, c_ptr
146 integer(c_int), value :: spacedimension
147 integer(c_int), value :: execspace
148 type(c_ptr), value :: sourcepoints
149 integer(c_int), value :: nsourcepoints
150 type(c_ptr), value :: sourcevalues
151 type(c_ptr), value :: targetpoints
152 integer(c_int), value :: ntargetpoints
153 type(c_ptr), value :: targetvalues
154 integer(c_int) :: ierr
155 end function
156
157 function pacman_vtk_to_pacman_cell_type_c(vtkTypes, pacmanTypes, n) &
158 result(ierr) bind(c, name='pacman_vtk_to_pacman_cell_type_c')
159 import :: c_int, c_ptr
160 type(c_ptr), value :: vtktypes
161 type(c_ptr), value :: pacmantypes
162 integer(c_int), value :: n
163 integer(c_int) :: ierr
164 end function
165
166 function pacman_vtk_cell_dim_c(vtkCellType) result(dim) &
167 bind(c, name='pacman_vtk_cell_dim_c')
168 import :: c_int
169 integer(c_int), value, intent(in) :: vtkcelltype
170 integer(c_int) :: dim
171 end function
172 end interface
173
174contains
175
176 ! -----------------------------------------------------------------
177 ! Kokkos lifecycle wrappers
178 ! -----------------------------------------------------------------
179
184 end subroutine
185
190 end subroutine
191
194 function pacman_best_execspace() result(es)
195 integer(c_int) :: es
197 end function
198
199 ! -----------------------------------------------------------------
200 ! RBF-PUM interpolation
201 ! -----------------------------------------------------------------
202
215 subroutine pacman_rbf_interpolate(spaceDimension, execSpace, rbfFunction, &
216 sourcePoints, sourceValues, targetPoints, targetValues, ierr)
217 integer, intent(in) :: spacedimension
218 integer(c_int), intent(in) :: execspace
219 integer(c_int), intent(in) :: rbffunction
220 real(c_double), intent(in), contiguous, target :: sourcepoints(:,:)
221 real(c_double), intent(in), contiguous, target :: sourcevalues(:)
222 real(c_double), intent(in), contiguous, target :: targetpoints(:,:)
223 real(c_double), intent(out), contiguous, target :: targetvalues(:)
224 integer(c_int), intent(out), optional :: ierr
225
226 integer(c_int) :: ret, nsrc, ntgt
227
228 nsrc = int(size(sourcevalues), c_int)
229 ntgt = int(size(targetvalues), c_int)
231 int(spacedimension, c_int), execspace, rbffunction, &
232 c_loc(sourcepoints), nsrc, c_loc(sourcevalues), &
233 c_loc(targetpoints), ntgt, c_loc(targetvalues))
234 if (present(ierr)) ierr = ret
235 end subroutine
236
237 ! -----------------------------------------------------------------
238 ! FE interpolation
239 ! -----------------------------------------------------------------
240
256 subroutine pacman_fe_interpolate(spaceDimension, execSpace, method, &
257 sourcePoints, sourceValues, connVal, connOff, cellTypes, &
258 targetPoints, targetValues, targetStatus, ierr)
259 integer, intent(in) :: spacedimension
260 integer(c_int), intent(in) :: execspace
261 integer(c_int), intent(in) :: method
262 real(c_double), intent(in), contiguous, target :: sourcepoints(:,:)
263 real(c_double), intent(in), contiguous, target :: sourcevalues(:)
264 integer(c_int), intent(in), contiguous, target :: connval(:)
265 integer(c_int), intent(in), contiguous, target :: connoff(:)
266 integer(c_int), intent(in), contiguous, target :: celltypes(:)
267 real(c_double), intent(in), contiguous, target :: targetpoints(:,:)
268 real(c_double), intent(out), contiguous, target :: targetvalues(:)
269 integer(c_int), intent(out), contiguous, target :: targetstatus(:)
270 integer(c_int), intent(out), optional :: ierr
271
272 integer(c_int) :: ret, nsrc, ntgt, nconnval, nconnoff
273 integer :: i
274
275 nsrc = int(size(sourcevalues), c_int)
276 ntgt = int(size(targetvalues), c_int)
277 nconnval = int(size(connval), c_int)
278 nconnoff = int(size(connoff), c_int)
279 write(*,*) 'DEBUG: nsrc=', nsrc, ' ntgt=', ntgt, ' nconnval=', nconnval, ' nconnoff=', nconnoff, &
280 ' size(connVal)=', size(connval), ' size(connOff)=', size(connoff)
281 do i = 1, size(connval)
282 if (connval(i) < 0) then
283 write(*,'(A,I0,A,I0)') 'ERROR: connVal(', i, ') = ', connval(i)
284 if (present(ierr)) ierr = -1
285 return
286 end if
287 end do
289 int(spacedimension, c_int), execspace, method, &
290 c_loc(sourcepoints), nsrc, c_loc(sourcevalues), &
291 c_loc(connval), nconnval, c_loc(connoff), nconnoff, c_loc(celltypes), &
292 c_loc(targetpoints), ntgt, c_loc(targetvalues), c_loc(targetstatus))
293 if (present(ierr)) ierr = ret
294 end subroutine
295
296 ! -----------------------------------------------------------------
297 ! MLS interpolation
298 ! -----------------------------------------------------------------
299
311 subroutine pacman_mls_interpolate(spaceDimension, execSpace, &
312 sourcePoints, sourceValues, targetPoints, targetValues, ierr)
313 integer, intent(in) :: spacedimension
314 integer(c_int), intent(in) :: execspace
315 real(c_double), intent(in), contiguous, target :: sourcepoints(:,:)
316 real(c_double), intent(in), contiguous, target :: sourcevalues(:)
317 real(c_double), intent(in), contiguous, target :: targetpoints(:,:)
318 real(c_double), intent(out), contiguous, target :: targetvalues(:)
319 integer(c_int), intent(out), optional :: ierr
320
321 integer(c_int) :: ret, nsrc, ntgt
322
323 nsrc = int(size(sourcevalues), c_int)
324 ntgt = int(size(targetvalues), c_int)
326 int(spacedimension, c_int), execspace, &
327 c_loc(sourcepoints), nsrc, c_loc(sourcevalues), &
328 c_loc(targetpoints), ntgt, c_loc(targetvalues))
329 if (present(ierr)) ierr = ret
330 end subroutine
331
332 ! -----------------------------------------------------------------
333 ! VTK cell-type helpers
334 ! -----------------------------------------------------------------
335
341 subroutine pacman_vtk_to_pacman_cell_type(vtkTypes, pacmanTypes, ierr)
342 integer(c_int), intent(in), contiguous, target :: vtktypes(:)
343 integer(c_int), intent(out), contiguous, target :: pacmantypes(:)
344 integer(c_int), intent(out), optional :: ierr
345 integer(c_int) :: ret, n
346 n = int(size(vtktypes), c_int)
347 ret = pacman_vtk_to_pacman_cell_type_c(c_loc(vtktypes), c_loc(pacmantypes), n)
348 if (present(ierr)) ierr = ret
349 end subroutine
350
355 function pacman_vtk_cell_dim(vtkCellType) result(dim)
356 integer(c_int), intent(in) :: vtkcelltype
357 integer(c_int) :: dim
358 dim = pacman_vtk_cell_dim_c(vtkcelltype)
359 end function
360
361end module pacman_mod
void pacman_kokkos_initialize_c(void)
Initialize Kokkos with default settings.
int pacman_rbf_interpolate_c(int spaceDimension, int execSpace, int rbfFunction, const double *sourcePoints, int nSourcePoints, const double *sourceValues, const double *targetPoints, int nTargetPoints, double *targetValues)
C shim for PACMAN::rbf_interpolate.
int pacman_mls_interpolate_c(int spaceDimension, int execSpace, const double *sourcePoints, int nSourcePoints, const double *sourceValues, const double *targetPoints, int nTargetPoints, double *targetValues)
C shim for PACMAN::mls_interpolate.
int pacman_best_execspace_c(void)
Return the best execution space available in the current build.
int pacman_fe_interpolate_c(int spaceDimension, int execSpace, int method, const double *sourcePoints, int nSourcePoints, const double *sourceValues, const int *connVal, int connValSize, const int *connOff, int connOffSize, const int *cellTypes, const double *targetPoints, int nTargetPoints, double *targetValues, int *targetStatus)
C shim for PACMAN::fe_interpolate.
void pacman_kokkos_finalize_c(void)
Finalize Kokkos.
int pacman_vtk_to_pacman_cell_type_c(const int *vtkTypes, int *pacmanTypes, int n)
Convert an array of VTK cell-type IDs to PACMAN CellType values.
int pacman_vtk_cell_dim_c(int vtkCellType)
Return the topological dimension for a VTK cell-type ID.
Fortran module providing a high-level interface to the PACMAN interpolation library via ISO C binding...
integer(c_int), parameter, public pacman_openmp
integer(c_int), parameter, public pacman_sycl
integer(c_int) function, public pacman_vtk_cell_dim(vtkcelltype)
Return the topological dimension for a VTK cell-type ID.
subroutine, public pacman_mls_interpolate(spacedimension, execspace, sourcepoints, sourcevalues, targetpoints, targetvalues, ierr)
Interpolate scalar values from source to target points using Moving Least Squares (no mesh connectivi...
integer(c_int), parameter, public pacman_wendlandc8
integer(c_int), parameter, public pacman_threads
integer(c_int), parameter, public pacman_wendlandc6
integer(c_int), parameter, public pacman_mls
integer(c_int) function, public pacman_best_execspace()
Return the best execution space available in the current build.
integer(c_int), parameter, public pacman_hip
subroutine, public pacman_vtk_to_pacman_cell_type(vtktypes, pacmantypes, ierr)
Convert VTK cell-type IDs to PACMAN CellType codes.
integer(c_int), parameter, public pacman_fe_nearest_nearest
integer(c_int), parameter, public pacman_fe_interp_clamp
integer(c_int), parameter, public pacman_fe_interp_extrap
subroutine, public pacman_kokkos_initialize()
Initialize Kokkos with default settings.
subroutine, public pacman_kokkos_finalize()
Finalize Kokkos.
integer(c_int), parameter, public pacman_cuda
integer(c_int), parameter, public pacman_wendlandc0
integer(c_int), parameter, public pacman_wendlandc4
integer(c_int), parameter, public pacman_fe_interp_zerofill
integer(c_int), parameter, public pacman_serial
integer(c_int), parameter, public pacman_wendlandc2
integer(c_int), parameter, public pacman_fe_interp_nearest
subroutine, public pacman_rbf_interpolate(spacedimension, execspace, rbffunction, sourcepoints, sourcevalues, targetpoints, targetvalues, ierr)
Interpolate scalar values from source to target points using RBF-PUM (no mesh connectivity required).
subroutine, public pacman_fe_interpolate(spacedimension, execspace, method, sourcepoints, sourcevalues, connval, connoff, celltypes, targetpoints, targetvalues, targetstatus, ierr)
Interpolate scalar values from a source mesh to target points using finite-element transfer methods.