1 // Copyright (c) 2017-2018, Lawrence Livermore National Security, LLC. 2 // Produced at the Lawrence Livermore National Laboratory. LLNL-CODE-734707. 3 // All Rights reserved. See files LICENSE and NOTICE for details. 4 // 5 // This file is part of CEED, a collection of benchmarks, miniapps, software 6 // libraries and APIs for efficient high-order finite element and spectral 7 // element discretizations for exascale applications. For more information and 8 // source code availability see http://github.com/ceed. 9 // 10 // The CEED research is supported by the Exascale Computing Project 17-SC-20-SC, 11 // a collaborative effort of two U.S. Department of Energy organizations (Office 12 // of Science and the National Nuclear Security Administration) responsible for 13 // the planning and preparation of a capable exascale ecosystem, including 14 // software, applications, hardware, advanced system engineering and early 15 // testbed platforms, in support of the nation's exascale computing imperative. 16 17 // Fortran interface 18 #include <ceed.h> 19 #include <ceed-impl.h> 20 #include <ceed-backend.h> 21 #include <ceed-fortran-name.h> 22 #include <stdlib.h> 23 #include <string.h> 24 25 #define FORTRAN_REQUEST_IMMEDIATE -1 26 #define FORTRAN_REQUEST_ORDERED -2 27 #define FORTRAN_NULL -3 28 #define FORTRAN_BASIS_COLLOCATED -1 29 #define FORTRAN_VECTOR_ACTIVE -1 30 #define FORTRAN_VECTOR_NONE -2 31 #define FORTRAN_QFUNCTION_NONE -1 32 33 static Ceed *Ceed_dict = NULL; 34 static int Ceed_count = 0; 35 static int Ceed_n = 0; 36 static int Ceed_count_max = 0; 37 38 // This test should actually be for the gfortran version, but we don't currently 39 // have a configure system to determine that (TODO). At present, this will use 40 // the smaller integer when run with clang+gfortran=8, for example. (That is 41 // sketchy, but will likely work for users that don't have huge character 42 // strings.) 43 #if __GNUC__ >= 8 44 typedef size_t fortran_charlen_t; 45 #else 46 typedef int fortran_charlen_t; 47 #endif 48 49 #define Splice(a, b) a ## b 50 51 // Fortran strings are generally unterminated and the length is passed as an 52 // extra argument after all the normal arguments. Some compilers (I only know 53 // of Windows) place the length argument immediately after the string parameter 54 // (TODO). 55 // 56 // We can't just NULL-terminate the string in-place because that could overwrite 57 // other strings or attempt to write to read-only memory. This macro allocates 58 // a string to hold the null-terminated version of the string that C expects. 59 #define FIX_STRING(stringname) \ 60 char Splice(stringname, _c)[1024]; \ 61 if (Splice(stringname, _len) > 1023) \ 62 CeedError(NULL, 1, "Fortran string length too long %zd", (size_t)Splice(stringname, _len)); \ 63 strncpy(Splice(stringname, _c), stringname, Splice(stringname, _len)); \ 64 Splice(stringname, _c)[Splice(stringname, _len)] = 0; \ 65 66 #define fCeedInit FORTRAN_NAME(ceedinit,CEEDINIT) 67 void fCeedInit(const char *resource, int *ceed, int *err, 68 fortran_charlen_t resource_len) { 69 FIX_STRING(resource); 70 if (Ceed_count == Ceed_count_max) { 71 Ceed_count_max += Ceed_count_max/2 + 1; 72 CeedRealloc(Ceed_count_max, &Ceed_dict); 73 } 74 75 Ceed *ceed_ = &Ceed_dict[Ceed_count]; 76 *err = CeedInit(resource_c, ceed_); 77 78 if (*err == 0) { 79 *ceed = Ceed_count++; 80 Ceed_n++; 81 } 82 } 83 84 #define fCeedGetPreferredMemType \ 85 FORTRAN_NAME(ceedgetpreferredmemtype,CEEDGETPREFERREDMEMTYPE) 86 void fCeedGetPreferredMemType(int *ceed, int *type, int *err) { 87 *err = CeedGetPreferredMemType(Ceed_dict[*ceed], (CeedMemType *)type); 88 } 89 90 #define fCeedDestroy FORTRAN_NAME(ceeddestroy,CEEDDESTROY) 91 void fCeedDestroy(int *ceed, int *err) { 92 *err = CeedDestroy(&Ceed_dict[*ceed]); 93 94 if (*err == 0) { 95 Ceed_n--; 96 if (Ceed_n == 0) { 97 CeedFree(&Ceed_dict); 98 Ceed_count = 0; 99 Ceed_count_max = 0; 100 } 101 } 102 } 103 104 static CeedVector *CeedVector_dict = NULL; 105 static int CeedVector_count = 0; 106 static int CeedVector_n = 0; 107 static int CeedVector_count_max = 0; 108 109 #define fCeedVectorCreate FORTRAN_NAME(ceedvectorcreate,CEEDVECTORCREATE) 110 void fCeedVectorCreate(int *ceed, int *length, int *vec, int *err) { 111 if (CeedVector_count == CeedVector_count_max) { 112 CeedVector_count_max += CeedVector_count_max/2 + 1; 113 CeedRealloc(CeedVector_count_max, &CeedVector_dict); 114 } 115 116 CeedVector *vec_ = &CeedVector_dict[CeedVector_count]; 117 *err = CeedVectorCreate(Ceed_dict[*ceed], *length, vec_); 118 119 if (*err == 0) { 120 *vec = CeedVector_count++; 121 CeedVector_n++; 122 } 123 } 124 125 #define fCeedVectorSetArray FORTRAN_NAME(ceedvectorsetarray,CEEDVECTORSETARRAY) 126 void fCeedVectorSetArray(int *vec, int *memtype, int *copymode, 127 CeedScalar *array, int64_t *offset, int *err) { 128 *err = CeedVectorSetArray(CeedVector_dict[*vec], *memtype, *copymode, 129 (CeedScalar *)(array + *offset)); 130 } 131 132 #define fCeedVectorSyncArray FORTRAN_NAME(ceedvectorsyncarray,CEEDVECTORSYNCARRAY) 133 void fCeedVectorSyncArray(int *vec, int *memtype, int *err) { 134 *err = CeedVectorSyncArray(CeedVector_dict[*vec], *memtype); 135 } 136 137 #define fCeedVectorSetValue FORTRAN_NAME(ceedvectorsetvalue,CEEDVECTORSETVALUE) 138 void fCeedVectorSetValue(int *vec, CeedScalar *value, int *err) { 139 *err = CeedVectorSetValue(CeedVector_dict[*vec], *value); 140 } 141 142 #define fCeedVectorGetArray FORTRAN_NAME(ceedvectorgetarray,CEEDVECTORGETARRAY) 143 void fCeedVectorGetArray(int *vec, int *memtype, CeedScalar *array, 144 int64_t *offset, 145 int *err) { 146 CeedScalar *b; 147 CeedVector vec_ = CeedVector_dict[*vec]; 148 *err = CeedVectorGetArray(vec_, *memtype, &b); 149 *offset = b - array; 150 } 151 152 #define fCeedVectorGetArrayRead \ 153 FORTRAN_NAME(ceedvectorgetarrayread,CEEDVECTORGETARRAYREAD) 154 void fCeedVectorGetArrayRead(int *vec, int *memtype, CeedScalar *array, 155 int64_t *offset, int *err) { 156 const CeedScalar *b; 157 CeedVector vec_ = CeedVector_dict[*vec]; 158 *err = CeedVectorGetArrayRead(vec_, *memtype, &b); 159 *offset = b - array; 160 } 161 162 #define fCeedVectorRestoreArray \ 163 FORTRAN_NAME(ceedvectorrestorearray,CEEDVECTORRESTOREARRAY) 164 void fCeedVectorRestoreArray(int *vec, CeedScalar *array, 165 int64_t *offset, int *err) { 166 *err = CeedVectorRestoreArray(CeedVector_dict[*vec], &array); 167 *offset = 0; 168 } 169 170 #define fCeedVectorRestoreArrayRead \ 171 FORTRAN_NAME(ceedvectorrestorearrayread,CEEDVECTORRESTOREARRAYREAD) 172 void fCeedVectorRestoreArrayRead(int *vec, const CeedScalar *array, 173 int64_t *offset, int *err) { 174 *err = CeedVectorRestoreArrayRead(CeedVector_dict[*vec], &array); 175 *offset = 0; 176 } 177 178 #define fCeedVectorNorm \ 179 FORTRAN_NAME(ceedvectornorm,CEEDVECTORNORM) 180 void fCeedVectorNorm(int *vec, int *type, CeedScalar *norm, int *err) { 181 *err = CeedVectorNorm(CeedVector_dict[*vec], *type, norm); 182 } 183 184 #define fCeedVectorView FORTRAN_NAME(ceedvectorview,CEEDVECTORVIEW) 185 void fCeedVectorView(int *vec, int *err) { 186 *err = CeedVectorView(CeedVector_dict[*vec], "%12.8f", stdout); 187 } 188 189 #define fCeedVectorDestroy FORTRAN_NAME(ceedvectordestroy,CEEDVECTORDESTROY) 190 void fCeedVectorDestroy(int *vec, int *err) { 191 *err = CeedVectorDestroy(&CeedVector_dict[*vec]); 192 193 if (*err == 0) { 194 CeedVector_n--; 195 if (CeedVector_n == 0) { 196 CeedFree(&CeedVector_dict); 197 CeedVector_count = 0; 198 CeedVector_count_max = 0; 199 } 200 } 201 } 202 203 static CeedElemRestriction *CeedElemRestriction_dict = NULL; 204 static int CeedElemRestriction_count = 0; 205 static int CeedElemRestriction_n = 0; 206 static int CeedElemRestriction_count_max = 0; 207 208 #define fCeedElemRestrictionCreate \ 209 FORTRAN_NAME(ceedelemrestrictioncreate, CEEDELEMRESTRICTIONCREATE) 210 void fCeedElemRestrictionCreate(int *ceed, int *nelements, 211 int *esize, int *nnodes, int *ncomp, 212 int *memtype, int *copymode, const int *indices, 213 int *elemrestriction, int *err) { 214 if (CeedElemRestriction_count == CeedElemRestriction_count_max) { 215 CeedElemRestriction_count_max += CeedElemRestriction_count_max/2 + 1; 216 CeedRealloc(CeedElemRestriction_count_max, &CeedElemRestriction_dict); 217 } 218 219 const int *indices_ = indices; 220 221 CeedElemRestriction *elemrestriction_ = 222 &CeedElemRestriction_dict[CeedElemRestriction_count]; 223 *err = CeedElemRestrictionCreate(Ceed_dict[*ceed], *nelements, *esize, 224 *nnodes, *ncomp, *memtype, *copymode, 225 indices_, elemrestriction_); 226 227 if (*err == 0) { 228 *elemrestriction = CeedElemRestriction_count++; 229 CeedElemRestriction_n++; 230 } 231 } 232 233 #define fCeedElemRestrictionCreateIdentity \ 234 FORTRAN_NAME(ceedelemrestrictioncreateidentity, CEEDELEMRESTRICTIONCREATEIDENTITY) 235 void fCeedElemRestrictionCreateIdentity(int *ceed, int *nelements, 236 int *esize, int *nnodes, int *ncomp, 237 int *elemrestriction, int *err) { 238 if (CeedElemRestriction_count == CeedElemRestriction_count_max) { 239 CeedElemRestriction_count_max += CeedElemRestriction_count_max/2 + 1; 240 CeedRealloc(CeedElemRestriction_count_max, &CeedElemRestriction_dict); 241 } 242 243 CeedElemRestriction *elemrestriction_ = 244 &CeedElemRestriction_dict[CeedElemRestriction_count]; 245 *err = CeedElemRestrictionCreateIdentity(Ceed_dict[*ceed], *nelements, *esize, 246 *nnodes, *ncomp, elemrestriction_); 247 248 if (*err == 0) { 249 *elemrestriction = CeedElemRestriction_count++; 250 CeedElemRestriction_n++; 251 } 252 } 253 254 #define fCeedElemRestrictionCreateBlocked \ 255 FORTRAN_NAME(ceedelemrestrictioncreateblocked,CEEDELEMRESTRICTIONCREATEBLOCKED) 256 void fCeedElemRestrictionCreateBlocked(int *ceed, int *nelements, 257 int *esize, int *blocksize, int *nnodes, 258 int *ncomp, int *mtype, int *cmode, 259 int *blkindices, int *elemrestriction, 260 int *err) { 261 262 if (CeedElemRestriction_count == CeedElemRestriction_count_max) { 263 CeedElemRestriction_count_max += CeedElemRestriction_count_max/2 + 1; 264 CeedRealloc(CeedElemRestriction_count_max, &CeedElemRestriction_dict); 265 } 266 267 CeedElemRestriction *elemrestriction_ = 268 &CeedElemRestriction_dict[CeedElemRestriction_count]; 269 *err = CeedElemRestrictionCreateBlocked(Ceed_dict[*ceed], *nelements, *esize, 270 *blocksize, *nnodes, *ncomp, *mtype, 271 *cmode, blkindices, elemrestriction_); 272 273 if (*err == 0) { 274 *elemrestriction = CeedElemRestriction_count++; 275 CeedElemRestriction_n++; 276 } 277 } 278 279 static CeedRequest *CeedRequest_dict = NULL; 280 static int CeedRequest_count = 0; 281 static int CeedRequest_n = 0; 282 static int CeedRequest_count_max = 0; 283 284 #define fCeedElemRestrictionApply \ 285 FORTRAN_NAME(ceedelemrestrictionapply,CEEDELEMRESTRICTIONAPPLY) 286 void fCeedElemRestrictionApply(int *elemr, int *tmode, int *lmode, 287 int *uvec, int *ruvec, int *rqst, int *err) { 288 int createRequest = 1; 289 // Check if input is CEED_REQUEST_ORDERED(-2) or CEED_REQUEST_IMMEDIATE(-1) 290 if (*rqst == FORTRAN_REQUEST_IMMEDIATE || *rqst == FORTRAN_REQUEST_ORDERED) 291 createRequest = 0; 292 293 if (createRequest && CeedRequest_count == CeedRequest_count_max) { 294 CeedRequest_count_max += CeedRequest_count_max/2 + 1; 295 CeedRealloc(CeedRequest_count_max, &CeedRequest_dict); 296 } 297 298 CeedRequest *rqst_; 299 if (*rqst == FORTRAN_REQUEST_IMMEDIATE) rqst_ = CEED_REQUEST_IMMEDIATE; 300 else if (*rqst == FORTRAN_REQUEST_ORDERED ) rqst_ = CEED_REQUEST_ORDERED; 301 else rqst_ = &CeedRequest_dict[CeedRequest_count]; 302 303 *err = CeedElemRestrictionApply(CeedElemRestriction_dict[*elemr], *tmode, 304 *lmode, CeedVector_dict[*uvec], 305 CeedVector_dict[*ruvec], rqst_); 306 307 if (*err == 0 && createRequest) { 308 *rqst = CeedRequest_count++; 309 CeedRequest_n++; 310 } 311 } 312 313 #define fCeedElemRestrictionApplyBlock \ 314 FORTRAN_NAME(ceedelemrestrictionapplyblock,CEEDELEMRESTRICTIONAPPLYBLOCK) 315 void fCeedElemRestrictionApplyBlock(int *elemr, int *block, int *tmode, 316 int *lmode, 317 int *uvec, int *ruvec, int *rqst, int *err) { 318 int createRequest = 1; 319 // Check if input is CEED_REQUEST_ORDERED(-2) or CEED_REQUEST_IMMEDIATE(-1) 320 if (*rqst == FORTRAN_REQUEST_IMMEDIATE || *rqst == FORTRAN_REQUEST_ORDERED) 321 createRequest = 0; 322 323 if (createRequest && CeedRequest_count == CeedRequest_count_max) { 324 CeedRequest_count_max += CeedRequest_count_max/2 + 1; 325 CeedRealloc(CeedRequest_count_max, &CeedRequest_dict); 326 } 327 328 CeedRequest *rqst_; 329 if (*rqst == FORTRAN_REQUEST_IMMEDIATE) rqst_ = CEED_REQUEST_IMMEDIATE; 330 else if (*rqst == FORTRAN_REQUEST_ORDERED ) rqst_ = CEED_REQUEST_ORDERED; 331 else rqst_ = &CeedRequest_dict[CeedRequest_count]; 332 333 *err = CeedElemRestrictionApplyBlock(CeedElemRestriction_dict[*elemr], *block, 334 *tmode, *lmode, CeedVector_dict[*uvec], 335 CeedVector_dict[*ruvec], rqst_); 336 337 if (*err == 0 && createRequest) { 338 *rqst = CeedRequest_count++; 339 CeedRequest_n++; 340 } 341 } 342 343 #define fCeedElemRestrictionGetMultiplicity \ 344 FORTRAN_NAME(ceedelemrestrictiongetmultiplicity,CEEDELEMRESTRICTIONGETMULTIPLICITY) 345 void fCeedElemRestrictionGetMultiplicity(int *elemr, int *lmode, int *mult, 346 int *err) { 347 *err = CeedElemRestrictionGetMultiplicity(CeedElemRestriction_dict[*elemr], 348 *lmode, CeedVector_dict[*mult]); 349 } 350 351 #define fCeedElemRestrictionView \ 352 FORTRAN_NAME(ceedelemrestrictionview,CEEDELEMRESTRICTIONVIEW) 353 void fCeedElemRestrictionView(int *elemr, int *err) { 354 *err = CeedElemRestrictionView(CeedElemRestriction_dict[*elemr], stdout); 355 } 356 357 #define fCeedRequestWait FORTRAN_NAME(ceedrequestwait, CEEDREQUESTWAIT) 358 void fCeedRequestWait(int *rqst, int *err) { 359 // TODO Uncomment this once CeedRequestWait is implemented 360 //*err = CeedRequestWait(&CeedRequest_dict[*rqst]); 361 362 if (*err == 0) { 363 CeedRequest_n--; 364 if (CeedRequest_n == 0) { 365 CeedFree(&CeedRequest_dict); 366 CeedRequest_count = 0; 367 CeedRequest_count_max = 0; 368 } 369 } 370 } 371 372 #define fCeedElemRestrictionDestroy \ 373 FORTRAN_NAME(ceedelemrestrictiondestroy,CEEDELEMRESTRICTIONDESTROY) 374 void fCeedElemRestrictionDestroy(int *elem, int *err) { 375 *err = CeedElemRestrictionDestroy(&CeedElemRestriction_dict[*elem]); 376 377 if (*err == 0) { 378 CeedElemRestriction_n--; 379 if (CeedElemRestriction_n == 0) { 380 CeedFree(&CeedElemRestriction_dict); 381 CeedElemRestriction_count = 0; 382 CeedElemRestriction_count_max = 0; 383 } 384 } 385 } 386 387 static CeedBasis *CeedBasis_dict = NULL; 388 static int CeedBasis_count = 0; 389 static int CeedBasis_n = 0; 390 static int CeedBasis_count_max = 0; 391 392 #define fCeedBasisCreateTensorH1Lagrange \ 393 FORTRAN_NAME(ceedbasiscreatetensorh1lagrange, CEEDBASISCREATETENSORH1LAGRANGE) 394 void fCeedBasisCreateTensorH1Lagrange(int *ceed, int *dim, 395 int *ncomp, int *P, int *Q, int *quadmode, 396 int *basis, int *err) { 397 if (CeedBasis_count == CeedBasis_count_max) { 398 CeedBasis_count_max += CeedBasis_count_max/2 + 1; 399 CeedRealloc(CeedBasis_count_max, &CeedBasis_dict); 400 } 401 402 *err = CeedBasisCreateTensorH1Lagrange(Ceed_dict[*ceed], *dim, *ncomp, *P, *Q, 403 *quadmode, 404 &CeedBasis_dict[CeedBasis_count]); 405 406 if (*err == 0) { 407 *basis = CeedBasis_count++; 408 CeedBasis_n++; 409 } 410 } 411 412 #define fCeedBasisCreateTensorH1 \ 413 FORTRAN_NAME(ceedbasiscreatetensorh1, CEEDBASISCREATETENSORH1) 414 void fCeedBasisCreateTensorH1(int *ceed, int *dim, int *ncomp, int *P1d, 415 int *Q1d, const CeedScalar *interp1d, 416 const CeedScalar *grad1d, 417 const CeedScalar *qref1d, 418 const CeedScalar *qweight1d, int *basis, 419 int *err) { 420 if (CeedBasis_count == CeedBasis_count_max) { 421 CeedBasis_count_max += CeedBasis_count_max/2 + 1; 422 CeedRealloc(CeedBasis_count_max, &CeedBasis_dict); 423 } 424 425 *err = CeedBasisCreateTensorH1(Ceed_dict[*ceed], *dim, *ncomp, *P1d, *Q1d, 426 interp1d, grad1d, qref1d, qweight1d, 427 &CeedBasis_dict[CeedBasis_count]); 428 429 if (*err == 0) { 430 *basis = CeedBasis_count++; 431 CeedBasis_n++; 432 } 433 } 434 435 #define fCeedBasisCreateH1 \ 436 FORTRAN_NAME(ceedbasiscreateh1, CEEDBASISCREATEH1) 437 void fCeedBasisCreateH1(int *ceed, int *topo, int *ncomp, int *nnodes, 438 int *nqpts, const CeedScalar *interp, 439 const CeedScalar *grad, const CeedScalar *qref, 440 const CeedScalar *qweight, int *basis, int *err) { 441 if (CeedBasis_count == CeedBasis_count_max) { 442 CeedBasis_count_max += CeedBasis_count_max/2 + 1; 443 CeedRealloc(CeedBasis_count_max, &CeedBasis_dict); 444 } 445 446 *err = CeedBasisCreateH1(Ceed_dict[*ceed], *topo, *ncomp, *nnodes, *nqpts, 447 interp, grad, qref, qweight, 448 &CeedBasis_dict[CeedBasis_count]); 449 450 if (*err == 0) { 451 *basis = CeedBasis_count++; 452 CeedBasis_n++; 453 } 454 } 455 456 #define fCeedBasisView FORTRAN_NAME(ceedbasisview, CEEDBASISVIEW) 457 void fCeedBasisView(int *basis, int *err) { 458 *err = CeedBasisView(CeedBasis_dict[*basis], stdout); 459 } 460 461 #define fCeedQRFactorization \ 462 FORTRAN_NAME(ceedqrfactorization, CEEDQRFACTORIZATION) 463 void fCeedQRFactorization(int *ceed, CeedScalar *mat, CeedScalar *tau, int *m, 464 int *n, int *err) { 465 *err = CeedQRFactorization(Ceed_dict[*ceed], mat, tau, *m, *n); 466 } 467 468 #define fCeedSymmetricSchurDecomposition \ 469 FORTRAN_NAME(ceedsymmetricschurdecomposition, CEEDSYMMETRICSCHURDECOMPOSITION) 470 void fCeedSymmetricSchurDecomposition(int *ceed, CeedScalar *mat, 471 CeedScalar *lambda, int *n, int *err) { 472 *err = CeedSymmetricSchurDecomposition(Ceed_dict[*ceed], mat, lambda, *n); 473 } 474 475 #define fCeedSimultaneousDiagonalization \ 476 FORTRAN_NAME(ceedsimultaneousdiagonalization, CEEDSIMULTANEOUSDIAGONALIZATION) 477 void fCeedSimultaneousDiagonalization(int *ceed, CeedScalar *matA, 478 CeedScalar *matB, CeedScalar *x, 479 CeedScalar *lambda, int *n, int *err) { 480 *err = CeedSimultaneousDiagonalization(Ceed_dict[*ceed], matA, matB, x, 481 lambda, *n); 482 } 483 484 #define fCeedBasisGetCollocatedGrad \ 485 FORTRAN_NAME(ceedbasisgetcollocatedgrad, CEEDBASISGETCOLLOCATEDGRAD) 486 void fCeedBasisGetCollocatedGrad(int *basis, CeedScalar *colograd1d, 487 int *err) { 488 *err = CeedBasisGetCollocatedGrad(CeedBasis_dict[*basis], colograd1d); 489 } 490 491 #define fCeedBasisApply FORTRAN_NAME(ceedbasisapply, CEEDBASISAPPLY) 492 void fCeedBasisApply(int *basis, int *nelem, int *tmode, int *emode, 493 int *u, int *v, int *err) { 494 *err = CeedBasisApply(CeedBasis_dict[*basis], *nelem, *tmode, *emode, 495 *u==FORTRAN_VECTOR_NONE? 496 CEED_VECTOR_NONE:CeedVector_dict[*u], 497 CeedVector_dict[*v]); 498 } 499 500 #define fCeedBasisGetNumNodes \ 501 FORTRAN_NAME(ceedbasisgetnumnodes, CEEDBASISGETNUMNODES) 502 void fCeedBasisGetNumNodes(int *basis, int *P, int *err) { 503 *err = CeedBasisGetNumNodes(CeedBasis_dict[*basis], P); 504 } 505 506 #define fCeedBasisGetNumQuadraturePoints \ 507 FORTRAN_NAME(ceedbasisgetnumquadraturepoints, CEEDBASISGETNUMQUADRATUREPOINTS) 508 void fCeedBasisGetNumQuadraturePoints(int *basis, int *Q, int *err) { 509 *err = CeedBasisGetNumQuadraturePoints(CeedBasis_dict[*basis], Q); 510 } 511 512 #define fCeedBasisDestroy FORTRAN_NAME(ceedbasisdestroy,CEEDBASISDESTROY) 513 void fCeedBasisDestroy(int *basis, int *err) { 514 *err = CeedBasisDestroy(&CeedBasis_dict[*basis]); 515 516 if (*err == 0) { 517 CeedBasis_n--; 518 if (CeedBasis_n == 0) { 519 CeedFree(&CeedBasis_dict); 520 CeedBasis_count = 0; 521 CeedBasis_count_max = 0; 522 } 523 } 524 } 525 526 #define fCeedGaussQuadrature FORTRAN_NAME(ceedgaussquadrature, CEEDGAUSSQUADRATURE) 527 void fCeedGaussQuadrature(int *Q, CeedScalar *qref1d, CeedScalar *qweight1d, 528 int *err) { 529 *err = CeedGaussQuadrature(*Q, qref1d, qweight1d); 530 } 531 532 #define fCeedLobattoQuadrature \ 533 FORTRAN_NAME(ceedlobattoquadrature, CEEDLOBATTOQUADRATURE) 534 void fCeedLobattoQuadrature(int *Q, CeedScalar *qref1d, CeedScalar *qweight1d, 535 int *err) { 536 *err = CeedLobattoQuadrature(*Q, qref1d, qweight1d); 537 } 538 539 static CeedQFunction *CeedQFunction_dict = NULL; 540 static int CeedQFunction_count = 0; 541 static int CeedQFunction_n = 0; 542 static int CeedQFunction_count_max = 0; 543 544 static int CeedQFunctionFortranStub(void *ctx, int nq, 545 const CeedScalar *const *u, 546 CeedScalar *const *v) { 547 fContext *fctx = ctx; 548 int ierr; 549 550 CeedScalar *ctx_ = (CeedScalar *) fctx->innerctx; 551 fctx->f((void *)ctx_,&nq,u[0],u[1],u[2],u[3],u[4],u[5],u[6], 552 u[7],u[8],u[9],u[10],u[11],u[12],u[13],u[14],u[15], 553 v[0],v[1],v[2],v[3],v[4],v[5],v[6],v[7],v[8],v[9], 554 v[10],v[11],v[12],v[13],v[14],v[15],&ierr); 555 return ierr; 556 } 557 558 #define fCeedQFunctionCreateInterior \ 559 FORTRAN_NAME(ceedqfunctioncreateinterior, CEEDQFUNCTIONCREATEINTERIOR) 560 void fCeedQFunctionCreateInterior(int *ceed, int *vlength, 561 void (*f)(void *ctx, int *nq, 562 const CeedScalar *u,const CeedScalar *u1, 563 const CeedScalar *u2,const CeedScalar *u3, 564 const CeedScalar *u4,const CeedScalar *u5, 565 const CeedScalar *u6,const CeedScalar *u7, 566 const CeedScalar *u8,const CeedScalar *u9, 567 const CeedScalar *u10,const CeedScalar *u11, 568 const CeedScalar *u12,const CeedScalar *u13, 569 const CeedScalar *u14,const CeedScalar *u15, 570 CeedScalar *v,CeedScalar *v1,CeedScalar *v2, 571 CeedScalar *v3,CeedScalar *v4, 572 CeedScalar *v5,CeedScalar *v6, 573 CeedScalar *v7,CeedScalar *v8, 574 CeedScalar *v9,CeedScalar *v10, 575 CeedScalar *v11,CeedScalar *v12, 576 CeedScalar *v13,CeedScalar *v14, 577 CeedScalar *v15,int *err), 578 const char *source, int *qf, int *err, 579 fortran_charlen_t source_len) { 580 FIX_STRING(source); 581 if (CeedQFunction_count == CeedQFunction_count_max) { 582 CeedQFunction_count_max += CeedQFunction_count_max/2 + 1; 583 CeedRealloc(CeedQFunction_count_max, &CeedQFunction_dict); 584 } 585 586 CeedQFunction *qf_ = &CeedQFunction_dict[CeedQFunction_count]; 587 *err = CeedQFunctionCreateInterior(Ceed_dict[*ceed], *vlength, 588 CeedQFunctionFortranStub, source_c, qf_); 589 590 if (*err == 0) { 591 *qf = CeedQFunction_count++; 592 CeedQFunction_n++; 593 } 594 595 fContext *fctx; 596 *err = CeedMalloc(1, &fctx); 597 if (*err) return; 598 fctx->f = f; fctx->innerctx = NULL; fctx->innerctxsize = 0; 599 600 *err = CeedQFunctionSetContext(*qf_, fctx, sizeof(fContext)); 601 602 (*qf_)->fortranstatus = true; 603 } 604 605 #define fCeedQFunctionCreateInteriorByName \ 606 FORTRAN_NAME(ceedqfunctioncreateinteriorbyname, CEEDQFUNCTIONCREATEINTERIORBYNAME) 607 void fCeedQFunctionCreateInteriorByName(int *ceed, const char *name, int *qf, 608 int *err, fortran_charlen_t name_len) { 609 FIX_STRING(name); 610 if (CeedQFunction_count == CeedQFunction_count_max) { 611 CeedQFunction_count_max += CeedQFunction_count_max/2 + 1; 612 CeedRealloc(CeedQFunction_count_max, &CeedQFunction_dict); 613 } 614 615 CeedQFunction *qf_ = &CeedQFunction_dict[CeedQFunction_count]; 616 *err = CeedQFunctionCreateInteriorByName(Ceed_dict[*ceed], name_c, qf_); 617 618 if (*err == 0) { 619 *qf = CeedQFunction_count++; 620 CeedQFunction_n++; 621 } 622 } 623 624 #define fCeedQFunctionCreateIdentity \ 625 FORTRAN_NAME(ceedqfunctioncreateidentity, CEEDQFUNCTIONCREATEIDENTITY) 626 void fCeedQFunctionCreateIdentity(int *ceed, int *size, int *inmode, 627 int *outmode, int *qf, int *err) { 628 if (CeedQFunction_count == CeedQFunction_count_max) { 629 CeedQFunction_count_max += CeedQFunction_count_max/2 + 1; 630 CeedRealloc(CeedQFunction_count_max, &CeedQFunction_dict); 631 } 632 633 CeedQFunction *qf_ = &CeedQFunction_dict[CeedQFunction_count]; 634 *err = CeedQFunctionCreateIdentity(Ceed_dict[*ceed], *size, *inmode, 635 *outmode, qf_); 636 637 if (*err == 0) { 638 *qf = CeedQFunction_count++; 639 CeedQFunction_n++; 640 } 641 } 642 643 #define fCeedQFunctionAddInput \ 644 FORTRAN_NAME(ceedqfunctionaddinput,CEEDQFUNCTIONADDINPUT) 645 void fCeedQFunctionAddInput(int *qf, const char *fieldname, 646 CeedInt *ncomp, CeedEvalMode *emode, int *err, 647 fortran_charlen_t fieldname_len) { 648 FIX_STRING(fieldname); 649 CeedQFunction qf_ = CeedQFunction_dict[*qf]; 650 651 *err = CeedQFunctionAddInput(qf_, fieldname_c, *ncomp, *emode); 652 } 653 654 #define fCeedQFunctionAddOutput \ 655 FORTRAN_NAME(ceedqfunctionaddoutput,CEEDQFUNCTIONADDOUTPUT) 656 void fCeedQFunctionAddOutput(int *qf, const char *fieldname, 657 CeedInt *ncomp, CeedEvalMode *emode, int *err, 658 fortran_charlen_t fieldname_len) { 659 FIX_STRING(fieldname); 660 CeedQFunction qf_ = CeedQFunction_dict[*qf]; 661 662 *err = CeedQFunctionAddOutput(qf_, fieldname_c, *ncomp, *emode); 663 } 664 665 #define fCeedQFunctionSetContext \ 666 FORTRAN_NAME(ceedqfunctionsetcontext,CEEDQFUNCTIONSETCONTEXT) 667 void fCeedQFunctionSetContext(int *qf, CeedScalar *ctx, CeedInt *n, int *err) { 668 CeedQFunction qf_ = CeedQFunction_dict[*qf]; 669 670 fContext *fctx = qf_->ctx; 671 fctx->innerctx = ctx; 672 fctx->innerctxsize = ((size_t) *n)*sizeof(CeedScalar); 673 } 674 675 #define fCeedQFunctionView \ 676 FORTRAN_NAME(ceedqfunctionview,CEEDQFUNCTIONVIEW) 677 void fCeedQFunctionView(int *qf, int *err) { 678 CeedQFunction qf_ = CeedQFunction_dict[*qf]; 679 680 *err = CeedQFunctionView(qf_, stdout); 681 } 682 683 #define fCeedQFunctionApply \ 684 FORTRAN_NAME(ceedqfunctionapply,CEEDQFUNCTIONAPPLY) 685 //TODO Need Fixing, double pointer 686 void fCeedQFunctionApply(int *qf, int *Q, 687 int *u, int *u1, int *u2, int *u3, 688 int *u4, int *u5, int *u6, int *u7, 689 int *u8, int *u9, int *u10, int *u11, 690 int *u12, int *u13, int *u14, int *u15, 691 int *v, int *v1, int *v2, int *v3, 692 int *v4, int *v5, int *v6, int *v7, 693 int *v8, int *v9, int *v10, int *v11, 694 int *v12, int *v13, int *v14, int *v15, int *err) { 695 CeedQFunction qf_ = CeedQFunction_dict[*qf]; 696 CeedVector *in; 697 *err = CeedCalloc(16, &in); 698 if (*err) return; 699 in[0] = *u==FORTRAN_NULL?NULL:CeedVector_dict[*u]; 700 in[1] = *u1==FORTRAN_NULL?NULL:CeedVector_dict[*u1]; 701 in[2] = *u2==FORTRAN_NULL?NULL:CeedVector_dict[*u2]; 702 in[3] = *u3==FORTRAN_NULL?NULL:CeedVector_dict[*u3]; 703 in[4] = *u4==FORTRAN_NULL?NULL:CeedVector_dict[*u4]; 704 in[5] = *u5==FORTRAN_NULL?NULL:CeedVector_dict[*u5]; 705 in[6] = *u6==FORTRAN_NULL?NULL:CeedVector_dict[*u6]; 706 in[7] = *u7==FORTRAN_NULL?NULL:CeedVector_dict[*u7]; 707 in[8] = *u8==FORTRAN_NULL?NULL:CeedVector_dict[*u8]; 708 in[9] = *u9==FORTRAN_NULL?NULL:CeedVector_dict[*u9]; 709 in[10] = *u10==FORTRAN_NULL?NULL:CeedVector_dict[*u10]; 710 in[11] = *u11==FORTRAN_NULL?NULL:CeedVector_dict[*u11]; 711 in[12] = *u12==FORTRAN_NULL?NULL:CeedVector_dict[*u12]; 712 in[13] = *u13==FORTRAN_NULL?NULL:CeedVector_dict[*u13]; 713 in[14] = *u14==FORTRAN_NULL?NULL:CeedVector_dict[*u14]; 714 in[15] = *u15==FORTRAN_NULL?NULL:CeedVector_dict[*u15]; 715 CeedVector *out; 716 *err = CeedCalloc(16, &out); 717 if (*err) return; 718 out[0] = *v==FORTRAN_NULL?NULL:CeedVector_dict[*v]; 719 out[1] = *v1==FORTRAN_NULL?NULL:CeedVector_dict[*v1]; 720 out[2] = *v2==FORTRAN_NULL?NULL:CeedVector_dict[*v2]; 721 out[3] = *v3==FORTRAN_NULL?NULL:CeedVector_dict[*v3]; 722 out[4] = *v4==FORTRAN_NULL?NULL:CeedVector_dict[*v4]; 723 out[5] = *v5==FORTRAN_NULL?NULL:CeedVector_dict[*v5]; 724 out[6] = *v6==FORTRAN_NULL?NULL:CeedVector_dict[*v6]; 725 out[7] = *v7==FORTRAN_NULL?NULL:CeedVector_dict[*v7]; 726 out[8] = *v8==FORTRAN_NULL?NULL:CeedVector_dict[*v8]; 727 out[9] = *v9==FORTRAN_NULL?NULL:CeedVector_dict[*v9]; 728 out[10] = *v10==FORTRAN_NULL?NULL:CeedVector_dict[*v10]; 729 out[11] = *v11==FORTRAN_NULL?NULL:CeedVector_dict[*v11]; 730 out[12] = *v12==FORTRAN_NULL?NULL:CeedVector_dict[*v12]; 731 out[13] = *v13==FORTRAN_NULL?NULL:CeedVector_dict[*v13]; 732 out[14] = *v14==FORTRAN_NULL?NULL:CeedVector_dict[*v14]; 733 out[15] = *v15==FORTRAN_NULL?NULL:CeedVector_dict[*v15]; 734 *err = CeedQFunctionApply(qf_, *Q, in, out); 735 if (*err) return; 736 737 *err = CeedFree(&in); 738 if (*err) return; 739 *err = CeedFree(&out); 740 } 741 742 #define fCeedQFunctionDestroy \ 743 FORTRAN_NAME(ceedqfunctiondestroy,CEEDQFUNCTIONDESTROY) 744 void fCeedQFunctionDestroy(int *qf, int *err) { 745 bool fstatus; 746 *err = CeedQFunctionGetFortranStatus(CeedQFunction_dict[*qf], &fstatus); 747 if (*err) return; 748 if (fstatus) { 749 fContext *fctx = CeedQFunction_dict[*qf]->ctx; 750 *err = CeedFree(&fctx); 751 if (*err) return; 752 } 753 754 *err = CeedQFunctionDestroy(&CeedQFunction_dict[*qf]); 755 if (*err) return; 756 757 CeedQFunction_n--; 758 if (CeedQFunction_n == 0) { 759 *err = CeedFree(&CeedQFunction_dict); 760 CeedQFunction_count = 0; 761 CeedQFunction_count_max = 0; 762 } 763 } 764 765 static CeedOperator *CeedOperator_dict = NULL; 766 static int CeedOperator_count = 0; 767 static int CeedOperator_n = 0; 768 static int CeedOperator_count_max = 0; 769 770 #define fCeedOperatorCreate \ 771 FORTRAN_NAME(ceedoperatorcreate, CEEDOPERATORCREATE) 772 void fCeedOperatorCreate(int *ceed, 773 int *qf, int *dqf, int *dqfT, int *op, int *err) { 774 if (CeedOperator_count == CeedOperator_count_max) 775 CeedOperator_count_max += CeedOperator_count_max/2 + 1, 776 CeedOperator_dict = realloc(CeedOperator_dict, 777 sizeof(CeedOperator)*CeedOperator_count_max); 778 779 CeedOperator *op_ = &CeedOperator_dict[CeedOperator_count]; 780 781 CeedQFunction dqf_ = CEED_QFUNCTION_NONE, dqfT_ = CEED_QFUNCTION_NONE; 782 if (*dqf != FORTRAN_QFUNCTION_NONE) dqf_ = CeedQFunction_dict[*dqf ]; 783 if (*dqfT != FORTRAN_QFUNCTION_NONE) dqfT_ = CeedQFunction_dict[*dqfT]; 784 785 *err = CeedOperatorCreate(Ceed_dict[*ceed], CeedQFunction_dict[*qf], dqf_, 786 dqfT_, op_); 787 if (*err) return; 788 *op = CeedOperator_count++; 789 CeedOperator_n++; 790 } 791 792 #define fCeedCompositeOperatorCreate \ 793 FORTRAN_NAME(ceedcompositeoperatorcreate, CEEDCOMPOSITEOPERATORCREATE) 794 void fCeedCompositeOperatorCreate(int *ceed, int *op, int *err) { 795 if (CeedOperator_count == CeedOperator_count_max) 796 CeedOperator_count_max += CeedOperator_count_max/2 + 1, 797 CeedOperator_dict = realloc(CeedOperator_dict, 798 sizeof(CeedOperator)*CeedOperator_count_max); 799 800 CeedOperator *op_ = &CeedOperator_dict[CeedOperator_count]; 801 802 *err = CeedCompositeOperatorCreate(Ceed_dict[*ceed], op_); 803 if (*err) return; 804 *op = CeedOperator_count++; 805 CeedOperator_n++; 806 } 807 808 #define fCeedOperatorSetField \ 809 FORTRAN_NAME(ceedoperatorsetfield,CEEDOPERATORSETFIELD) 810 void fCeedOperatorSetField(int *op, const char *fieldname, 811 int *r, int *lmode, int *b, int *v, int *err, 812 fortran_charlen_t fieldname_len) { 813 FIX_STRING(fieldname); 814 CeedElemRestriction r_; 815 CeedBasis b_; 816 CeedVector v_; 817 818 CeedOperator op_ = CeedOperator_dict[*op]; 819 820 if (*r == FORTRAN_NULL) { 821 r_ = NULL; 822 } else { 823 r_ = CeedElemRestriction_dict[*r]; 824 } 825 826 if (*b == FORTRAN_NULL) { 827 b_ = NULL; 828 } else if (*b == FORTRAN_BASIS_COLLOCATED) { 829 b_ = CEED_BASIS_COLLOCATED; 830 } else { 831 b_ = CeedBasis_dict[*b]; 832 } 833 if (*v == FORTRAN_NULL) { 834 v_ = NULL; 835 } else if (*v == FORTRAN_VECTOR_ACTIVE) { 836 v_ = CEED_VECTOR_ACTIVE; 837 } else if (*v == FORTRAN_VECTOR_NONE) { 838 v_ = CEED_VECTOR_NONE; 839 } else { 840 v_ = CeedVector_dict[*v]; 841 } 842 843 *err = CeedOperatorSetField(op_, fieldname_c, r_, *lmode, b_, v_); 844 } 845 846 #define fCeedCompositeOperatorAddSub \ 847 FORTRAN_NAME(ceedcompositeoperatoraddsub, CEEDCOMPOSITEOPERATORADDSUB) 848 void fCeedCompositeOperatorAddSub(int *compositeop, int *subop, int *err) { 849 CeedOperator compositeop_ = CeedOperator_dict[*compositeop]; 850 CeedOperator subop_ = CeedOperator_dict[*subop]; 851 852 *err = CeedCompositeOperatorAddSub(compositeop_, subop_); 853 if (*err) return; 854 } 855 856 #define fCeedOperatorAssembleLinearQFunction FORTRAN_NAME(ceedoperatorassemblelinearqfunction, CEEDOPERATORASSEMBLELINEARQFUNCTION) 857 void fCeedOperatorAssembleLinearQFunction(int *op, int *assembledvec, 858 int *assembledrstr, int *rqst, int *err) { 859 // Vector 860 if (CeedVector_count == CeedVector_count_max) { 861 CeedVector_count_max += CeedVector_count_max/2 + 1; 862 CeedRealloc(CeedVector_count_max, &CeedVector_dict); 863 } 864 CeedVector *assembledvec_ = &CeedVector_dict[CeedVector_count]; 865 866 // Restriction 867 if (CeedElemRestriction_count == CeedElemRestriction_count_max) { 868 CeedElemRestriction_count_max += CeedElemRestriction_count_max/2 + 1; 869 CeedRealloc(CeedElemRestriction_count_max, &CeedElemRestriction_dict); 870 } 871 CeedElemRestriction *rstr_ = 872 &CeedElemRestriction_dict[CeedElemRestriction_count]; 873 874 int createRequest = 1; 875 // Check if input is CEED_REQUEST_ORDERED(-2) or CEED_REQUEST_IMMEDIATE(-1) 876 if (*rqst == -1 || *rqst == -2) { 877 createRequest = 0; 878 } 879 880 if (createRequest && CeedRequest_count == CeedRequest_count_max) { 881 CeedRequest_count_max += CeedRequest_count_max/2 + 1; 882 CeedRealloc(CeedRequest_count_max, &CeedRequest_dict); 883 } 884 885 CeedRequest *rqst_; 886 if (*rqst == -1) rqst_ = CEED_REQUEST_IMMEDIATE; 887 else if (*rqst == -2) rqst_ = CEED_REQUEST_ORDERED; 888 else rqst_ = &CeedRequest_dict[CeedRequest_count]; 889 890 *err = CeedOperatorAssembleLinearQFunction(CeedOperator_dict[*op], 891 assembledvec_, rstr_, rqst_); 892 if (*err) return; 893 if (createRequest) { 894 *rqst = CeedRequest_count++; 895 CeedRequest_n++; 896 } 897 898 if (*err == 0) { 899 *assembledrstr = CeedElemRestriction_count++; 900 CeedElemRestriction_n++; 901 *assembledvec = CeedVector_count++; 902 CeedVector_n++; 903 } 904 } 905 906 #define fCeedOperatorAssembleLinearDiagonal FORTRAN_NAME(ceedoperatorassemblelineardiagonal, CEEDOPERATORASSEMBLELINEARDIAGONAL) 907 void fCeedOperatorAssembleLinearDiagonal(int *op, int *assembledvec, 908 int *rqst, int *err) { 909 // Vector 910 if (CeedVector_count == CeedVector_count_max) { 911 CeedVector_count_max += CeedVector_count_max/2 + 1; 912 CeedRealloc(CeedVector_count_max, &CeedVector_dict); 913 } 914 CeedVector *assembledvec_ = &CeedVector_dict[CeedVector_count]; 915 916 int createRequest = 1; 917 // Check if input is CEED_REQUEST_ORDERED(-2) or CEED_REQUEST_IMMEDIATE(-1) 918 if (*rqst == -1 || *rqst == -2) { 919 createRequest = 0; 920 } 921 922 if (createRequest && CeedRequest_count == CeedRequest_count_max) { 923 CeedRequest_count_max += CeedRequest_count_max/2 + 1; 924 CeedRealloc(CeedRequest_count_max, &CeedRequest_dict); 925 } 926 927 CeedRequest *rqst_; 928 if (*rqst == -1) rqst_ = CEED_REQUEST_IMMEDIATE; 929 else if (*rqst == -2) rqst_ = CEED_REQUEST_ORDERED; 930 else rqst_ = &CeedRequest_dict[CeedRequest_count]; 931 932 *err = CeedOperatorAssembleLinearDiagonal(CeedOperator_dict[*op], 933 assembledvec_, rqst_); 934 if (*err) return; 935 if (createRequest) { 936 *rqst = CeedRequest_count++; 937 CeedRequest_n++; 938 } 939 940 if (*err == 0) { 941 *assembledvec = CeedVector_count++; 942 CeedVector_n++; 943 } 944 } 945 946 #define fCeedOperatorView \ 947 FORTRAN_NAME(ceedoperatorview,CEEDOPERATORVIEW) 948 void fCeedOperatorView(int *op, int *err) { 949 CeedOperator op_ = CeedOperator_dict[*op]; 950 951 *err = CeedOperatorView(op_, stdout); 952 } 953 954 #define fCeedOperatorCreateFDMElementInverse FORTRAN_NAME(ceedoperatorcreatefdmelementinverse, CEEDOPERATORCREATEFDMELEMENTINVERSE) 955 void fCeedOperatorCreateFDMElementInverse(int *op, int *fdminv, 956 int *rqst, int *err) { 957 // Operator 958 if (CeedOperator_count == CeedOperator_count_max) { 959 CeedOperator_count_max += CeedOperator_count_max/2 + 1; 960 CeedRealloc(CeedOperator_count_max, &CeedOperator_dict); 961 } 962 CeedOperator *fdminv_ = 963 &CeedOperator_dict[CeedOperator_count]; 964 965 int createRequest = 1; 966 // Check if input is CEED_REQUEST_ORDERED(-2) or CEED_REQUEST_IMMEDIATE(-1) 967 if (*rqst == -1 || *rqst == -2) { 968 createRequest = 0; 969 } 970 971 if (createRequest && CeedRequest_count == CeedRequest_count_max) { 972 CeedRequest_count_max += CeedRequest_count_max/2 + 1; 973 CeedRealloc(CeedRequest_count_max, &CeedRequest_dict); 974 } 975 976 CeedRequest *rqst_; 977 if (*rqst == -1) rqst_ = CEED_REQUEST_IMMEDIATE; 978 else if (*rqst == -2) rqst_ = CEED_REQUEST_ORDERED; 979 else rqst_ = &CeedRequest_dict[CeedRequest_count]; 980 981 *err = CeedOperatorCreateFDMElementInverse(CeedOperator_dict[*op], 982 fdminv_, rqst_); 983 if (*err) return; 984 if (createRequest) { 985 *rqst = CeedRequest_count++; 986 CeedRequest_n++; 987 } 988 989 if (*err == 0) { 990 *fdminv = CeedOperator_count++; 991 CeedOperator_n++; 992 } 993 } 994 995 #define fCeedOperatorApply FORTRAN_NAME(ceedoperatorapply, CEEDOPERATORAPPLY) 996 void fCeedOperatorApply(int *op, int *ustatevec, 997 int *resvec, int *rqst, int *err) { 998 CeedVector ustatevec_ = (*ustatevec == FORTRAN_NULL) ? 999 NULL : (*ustatevec == FORTRAN_VECTOR_NONE ? 1000 CEED_VECTOR_NONE : CeedVector_dict[*ustatevec]); 1001 CeedVector resvec_ = (*resvec == FORTRAN_NULL) ? 1002 NULL : (*resvec == FORTRAN_VECTOR_NONE ? 1003 CEED_VECTOR_NONE : CeedVector_dict[*resvec]); 1004 1005 int createRequest = 1; 1006 // Check if input is CEED_REQUEST_ORDERED(-2) or CEED_REQUEST_IMMEDIATE(-1) 1007 if (*rqst == -1 || *rqst == -2) { 1008 createRequest = 0; 1009 } 1010 1011 if (createRequest && CeedRequest_count == CeedRequest_count_max) { 1012 CeedRequest_count_max += CeedRequest_count_max/2 + 1; 1013 CeedRealloc(CeedRequest_count_max, &CeedRequest_dict); 1014 } 1015 1016 CeedRequest *rqst_; 1017 if (*rqst == -1) rqst_ = CEED_REQUEST_IMMEDIATE; 1018 else if (*rqst == -2) rqst_ = CEED_REQUEST_ORDERED; 1019 else rqst_ = &CeedRequest_dict[CeedRequest_count]; 1020 1021 *err = CeedOperatorApply(CeedOperator_dict[*op], 1022 ustatevec_, resvec_, rqst_); 1023 if (*err) return; 1024 if (createRequest) { 1025 *rqst = CeedRequest_count++; 1026 CeedRequest_n++; 1027 } 1028 } 1029 1030 #define fCeedOperatorApplyAdd FORTRAN_NAME(ceedoperatorapplyadd, CEEDOPERATORAPPLYADD) 1031 void fCeedOperatorApplyAdd(int *op, int *ustatevec, 1032 int *resvec, int *rqst, int *err) { 1033 CeedVector ustatevec_ = *ustatevec == FORTRAN_NULL 1034 ? NULL : CeedVector_dict[*ustatevec]; 1035 CeedVector resvec_ = *resvec == FORTRAN_NULL 1036 ? NULL : CeedVector_dict[*resvec]; 1037 1038 int createRequest = 1; 1039 // Check if input is CEED_REQUEST_ORDERED(-2) or CEED_REQUEST_IMMEDIATE(-1) 1040 if (*rqst == -1 || *rqst == -2) { 1041 createRequest = 0; 1042 } 1043 1044 if (createRequest && CeedRequest_count == CeedRequest_count_max) { 1045 CeedRequest_count_max += CeedRequest_count_max/2 + 1; 1046 CeedRealloc(CeedRequest_count_max, &CeedRequest_dict); 1047 } 1048 1049 CeedRequest *rqst_; 1050 if (*rqst == -1) rqst_ = CEED_REQUEST_IMMEDIATE; 1051 else if (*rqst == -2) rqst_ = CEED_REQUEST_ORDERED; 1052 else rqst_ = &CeedRequest_dict[CeedRequest_count]; 1053 1054 *err = CeedOperatorApplyAdd(CeedOperator_dict[*op], 1055 ustatevec_, resvec_, rqst_); 1056 if (*err) return; 1057 if (createRequest) { 1058 *rqst = CeedRequest_count++; 1059 CeedRequest_n++; 1060 } 1061 } 1062 1063 #define fCeedOperatorApplyJacobian \ 1064 FORTRAN_NAME(ceedoperatorapplyjacobian, CEEDOPERATORAPPLYJACOBIAN) 1065 void fCeedOperatorApplyJacobian(int *op, int *qdatavec, int *ustatevec, 1066 int *dustatevec, int *dresvec, int *rqst, 1067 int *err) { 1068 // TODO Uncomment this when CeedOperatorApplyJacobian is implemented 1069 // *err = CeedOperatorApplyJacobian(CeedOperator_dict[*op], CeedVector_dict[*qdatavec], 1070 // CeedVector_dict[*ustatevec], CeedVector_dict[*dustatevec], 1071 // CeedVector_dict[*dresvec], &CeedRequest_dict[*rqst]); 1072 } 1073 1074 #define fCeedOperatorDestroy \ 1075 FORTRAN_NAME(ceedoperatordestroy, CEEDOPERATORDESTROY) 1076 void fCeedOperatorDestroy(int *op, int *err) { 1077 *err = CeedOperatorDestroy(&CeedOperator_dict[*op]); 1078 if (*err) return; 1079 CeedOperator_n--; 1080 if (CeedOperator_n == 0) { 1081 *err = CeedFree(&CeedOperator_dict); 1082 CeedOperator_count = 0; 1083 CeedOperator_count_max = 0; 1084 } 1085 } 1086