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 *lmode, 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], *lmode, *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 *lmode, 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], *lmode, *nelements, 246 *esize, *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 *lmode, 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], *lmode, *nelements, 270 *esize, *blocksize, *nnodes, *ncomp, 271 *mtype, *cmode, blkindices, 272 elemrestriction_); 273 274 if (*err == 0) { 275 *elemrestriction = CeedElemRestriction_count++; 276 CeedElemRestriction_n++; 277 } 278 } 279 280 static CeedRequest *CeedRequest_dict = NULL; 281 static int CeedRequest_count = 0; 282 static int CeedRequest_n = 0; 283 static int CeedRequest_count_max = 0; 284 285 #define fCeedElemRestrictionApply \ 286 FORTRAN_NAME(ceedelemrestrictionapply,CEEDELEMRESTRICTIONAPPLY) 287 void fCeedElemRestrictionApply(int *elemr, int *tmode, int *uvec, int *ruvec, 288 int *rqst, int *err) { 289 int createRequest = 1; 290 // Check if input is CEED_REQUEST_ORDERED(-2) or CEED_REQUEST_IMMEDIATE(-1) 291 if (*rqst == FORTRAN_REQUEST_IMMEDIATE || *rqst == FORTRAN_REQUEST_ORDERED) 292 createRequest = 0; 293 294 if (createRequest && CeedRequest_count == CeedRequest_count_max) { 295 CeedRequest_count_max += CeedRequest_count_max/2 + 1; 296 CeedRealloc(CeedRequest_count_max, &CeedRequest_dict); 297 } 298 299 CeedRequest *rqst_; 300 if (*rqst == FORTRAN_REQUEST_IMMEDIATE) rqst_ = CEED_REQUEST_IMMEDIATE; 301 else if (*rqst == FORTRAN_REQUEST_ORDERED ) rqst_ = CEED_REQUEST_ORDERED; 302 else rqst_ = &CeedRequest_dict[CeedRequest_count]; 303 304 *err = CeedElemRestrictionApply(CeedElemRestriction_dict[*elemr], *tmode, 305 CeedVector_dict[*uvec], 306 CeedVector_dict[*ruvec], rqst_); 307 308 if (*err == 0 && createRequest) { 309 *rqst = CeedRequest_count++; 310 CeedRequest_n++; 311 } 312 } 313 314 #define fCeedElemRestrictionApplyBlock \ 315 FORTRAN_NAME(ceedelemrestrictionapplyblock,CEEDELEMRESTRICTIONAPPLYBLOCK) 316 void fCeedElemRestrictionApplyBlock(int *elemr, int *block, int *tmode, 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, 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 *mult, int *err) { 346 *err = CeedElemRestrictionGetMultiplicity(CeedElemRestriction_dict[*elemr], 347 CeedVector_dict[*mult]); 348 } 349 350 #define fCeedElemRestrictionView \ 351 FORTRAN_NAME(ceedelemrestrictionview,CEEDELEMRESTRICTIONVIEW) 352 void fCeedElemRestrictionView(int *elemr, int *err) { 353 *err = CeedElemRestrictionView(CeedElemRestriction_dict[*elemr], stdout); 354 } 355 356 #define fCeedRequestWait FORTRAN_NAME(ceedrequestwait, CEEDREQUESTWAIT) 357 void fCeedRequestWait(int *rqst, int *err) { 358 // TODO Uncomment this once CeedRequestWait is implemented 359 //*err = CeedRequestWait(&CeedRequest_dict[*rqst]); 360 361 if (*err == 0) { 362 CeedRequest_n--; 363 if (CeedRequest_n == 0) { 364 CeedFree(&CeedRequest_dict); 365 CeedRequest_count = 0; 366 CeedRequest_count_max = 0; 367 } 368 } 369 } 370 371 #define fCeedElemRestrictionDestroy \ 372 FORTRAN_NAME(ceedelemrestrictiondestroy,CEEDELEMRESTRICTIONDESTROY) 373 void fCeedElemRestrictionDestroy(int *elem, int *err) { 374 *err = CeedElemRestrictionDestroy(&CeedElemRestriction_dict[*elem]); 375 376 if (*err == 0) { 377 CeedElemRestriction_n--; 378 if (CeedElemRestriction_n == 0) { 379 CeedFree(&CeedElemRestriction_dict); 380 CeedElemRestriction_count = 0; 381 CeedElemRestriction_count_max = 0; 382 } 383 } 384 } 385 386 static CeedBasis *CeedBasis_dict = NULL; 387 static int CeedBasis_count = 0; 388 static int CeedBasis_n = 0; 389 static int CeedBasis_count_max = 0; 390 391 #define fCeedBasisCreateTensorH1Lagrange \ 392 FORTRAN_NAME(ceedbasiscreatetensorh1lagrange, CEEDBASISCREATETENSORH1LAGRANGE) 393 void fCeedBasisCreateTensorH1Lagrange(int *ceed, int *dim, 394 int *ncomp, int *P, int *Q, int *quadmode, 395 int *basis, int *err) { 396 if (CeedBasis_count == CeedBasis_count_max) { 397 CeedBasis_count_max += CeedBasis_count_max/2 + 1; 398 CeedRealloc(CeedBasis_count_max, &CeedBasis_dict); 399 } 400 401 *err = CeedBasisCreateTensorH1Lagrange(Ceed_dict[*ceed], *dim, *ncomp, *P, *Q, 402 *quadmode, 403 &CeedBasis_dict[CeedBasis_count]); 404 405 if (*err == 0) { 406 *basis = CeedBasis_count++; 407 CeedBasis_n++; 408 } 409 } 410 411 #define fCeedBasisCreateTensorH1 \ 412 FORTRAN_NAME(ceedbasiscreatetensorh1, CEEDBASISCREATETENSORH1) 413 void fCeedBasisCreateTensorH1(int *ceed, int *dim, int *ncomp, int *P1d, 414 int *Q1d, const CeedScalar *interp1d, 415 const CeedScalar *grad1d, 416 const CeedScalar *qref1d, 417 const CeedScalar *qweight1d, int *basis, 418 int *err) { 419 if (CeedBasis_count == CeedBasis_count_max) { 420 CeedBasis_count_max += CeedBasis_count_max/2 + 1; 421 CeedRealloc(CeedBasis_count_max, &CeedBasis_dict); 422 } 423 424 *err = CeedBasisCreateTensorH1(Ceed_dict[*ceed], *dim, *ncomp, *P1d, *Q1d, 425 interp1d, grad1d, qref1d, qweight1d, 426 &CeedBasis_dict[CeedBasis_count]); 427 428 if (*err == 0) { 429 *basis = CeedBasis_count++; 430 CeedBasis_n++; 431 } 432 } 433 434 #define fCeedBasisCreateH1 \ 435 FORTRAN_NAME(ceedbasiscreateh1, CEEDBASISCREATEH1) 436 void fCeedBasisCreateH1(int *ceed, int *topo, int *ncomp, int *nnodes, 437 int *nqpts, const CeedScalar *interp, 438 const CeedScalar *grad, const CeedScalar *qref, 439 const CeedScalar *qweight, int *basis, int *err) { 440 if (CeedBasis_count == CeedBasis_count_max) { 441 CeedBasis_count_max += CeedBasis_count_max/2 + 1; 442 CeedRealloc(CeedBasis_count_max, &CeedBasis_dict); 443 } 444 445 *err = CeedBasisCreateH1(Ceed_dict[*ceed], *topo, *ncomp, *nnodes, *nqpts, 446 interp, grad, qref, qweight, 447 &CeedBasis_dict[CeedBasis_count]); 448 449 if (*err == 0) { 450 *basis = CeedBasis_count++; 451 CeedBasis_n++; 452 } 453 } 454 455 #define fCeedBasisView FORTRAN_NAME(ceedbasisview, CEEDBASISVIEW) 456 void fCeedBasisView(int *basis, int *err) { 457 *err = CeedBasisView(CeedBasis_dict[*basis], stdout); 458 } 459 460 #define fCeedQRFactorization \ 461 FORTRAN_NAME(ceedqrfactorization, CEEDQRFACTORIZATION) 462 void fCeedQRFactorization(int *ceed, CeedScalar *mat, CeedScalar *tau, int *m, 463 int *n, int *err) { 464 *err = CeedQRFactorization(Ceed_dict[*ceed], mat, tau, *m, *n); 465 } 466 467 #define fCeedSymmetricSchurDecomposition \ 468 FORTRAN_NAME(ceedsymmetricschurdecomposition, CEEDSYMMETRICSCHURDECOMPOSITION) 469 void fCeedSymmetricSchurDecomposition(int *ceed, CeedScalar *mat, 470 CeedScalar *lambda, int *n, int *err) { 471 *err = CeedSymmetricSchurDecomposition(Ceed_dict[*ceed], mat, lambda, *n); 472 } 473 474 #define fCeedSimultaneousDiagonalization \ 475 FORTRAN_NAME(ceedsimultaneousdiagonalization, CEEDSIMULTANEOUSDIAGONALIZATION) 476 void fCeedSimultaneousDiagonalization(int *ceed, CeedScalar *matA, 477 CeedScalar *matB, CeedScalar *x, 478 CeedScalar *lambda, int *n, int *err) { 479 *err = CeedSimultaneousDiagonalization(Ceed_dict[*ceed], matA, matB, x, 480 lambda, *n); 481 } 482 483 #define fCeedBasisGetCollocatedGrad \ 484 FORTRAN_NAME(ceedbasisgetcollocatedgrad, CEEDBASISGETCOLLOCATEDGRAD) 485 void fCeedBasisGetCollocatedGrad(int *basis, CeedScalar *colograd1d, 486 int *err) { 487 *err = CeedBasisGetCollocatedGrad(CeedBasis_dict[*basis], colograd1d); 488 } 489 490 #define fCeedBasisApply FORTRAN_NAME(ceedbasisapply, CEEDBASISAPPLY) 491 void fCeedBasisApply(int *basis, int *nelem, int *tmode, int *emode, 492 int *u, int *v, int *err) { 493 *err = CeedBasisApply(CeedBasis_dict[*basis], *nelem, *tmode, *emode, 494 *u==FORTRAN_VECTOR_NONE? 495 CEED_VECTOR_NONE:CeedVector_dict[*u], 496 CeedVector_dict[*v]); 497 } 498 499 #define fCeedBasisGetNumNodes \ 500 FORTRAN_NAME(ceedbasisgetnumnodes, CEEDBASISGETNUMNODES) 501 void fCeedBasisGetNumNodes(int *basis, int *P, int *err) { 502 *err = CeedBasisGetNumNodes(CeedBasis_dict[*basis], P); 503 } 504 505 #define fCeedBasisGetNumQuadraturePoints \ 506 FORTRAN_NAME(ceedbasisgetnumquadraturepoints, CEEDBASISGETNUMQUADRATUREPOINTS) 507 void fCeedBasisGetNumQuadraturePoints(int *basis, int *Q, int *err) { 508 *err = CeedBasisGetNumQuadraturePoints(CeedBasis_dict[*basis], Q); 509 } 510 511 #define fCeedBasisDestroy FORTRAN_NAME(ceedbasisdestroy,CEEDBASISDESTROY) 512 void fCeedBasisDestroy(int *basis, int *err) { 513 *err = CeedBasisDestroy(&CeedBasis_dict[*basis]); 514 515 if (*err == 0) { 516 CeedBasis_n--; 517 if (CeedBasis_n == 0) { 518 CeedFree(&CeedBasis_dict); 519 CeedBasis_count = 0; 520 CeedBasis_count_max = 0; 521 } 522 } 523 } 524 525 #define fCeedGaussQuadrature FORTRAN_NAME(ceedgaussquadrature, CEEDGAUSSQUADRATURE) 526 void fCeedGaussQuadrature(int *Q, CeedScalar *qref1d, CeedScalar *qweight1d, 527 int *err) { 528 *err = CeedGaussQuadrature(*Q, qref1d, qweight1d); 529 } 530 531 #define fCeedLobattoQuadrature \ 532 FORTRAN_NAME(ceedlobattoquadrature, CEEDLOBATTOQUADRATURE) 533 void fCeedLobattoQuadrature(int *Q, CeedScalar *qref1d, CeedScalar *qweight1d, 534 int *err) { 535 *err = CeedLobattoQuadrature(*Q, qref1d, qweight1d); 536 } 537 538 static CeedQFunction *CeedQFunction_dict = NULL; 539 static int CeedQFunction_count = 0; 540 static int CeedQFunction_n = 0; 541 static int CeedQFunction_count_max = 0; 542 543 static int CeedQFunctionFortranStub(void *ctx, int nq, 544 const CeedScalar *const *u, 545 CeedScalar *const *v) { 546 fContext *fctx = ctx; 547 int ierr; 548 549 CeedScalar *ctx_ = (CeedScalar *) fctx->innerctx; 550 fctx->f((void *)ctx_,&nq,u[0],u[1],u[2],u[3],u[4],u[5],u[6], 551 u[7],u[8],u[9],u[10],u[11],u[12],u[13],u[14],u[15], 552 v[0],v[1],v[2],v[3],v[4],v[5],v[6],v[7],v[8],v[9], 553 v[10],v[11],v[12],v[13],v[14],v[15],&ierr); 554 return ierr; 555 } 556 557 #define fCeedQFunctionCreateInterior \ 558 FORTRAN_NAME(ceedqfunctioncreateinterior, CEEDQFUNCTIONCREATEINTERIOR) 559 void fCeedQFunctionCreateInterior(int *ceed, int *vlength, 560 void (*f)(void *ctx, int *nq, 561 const CeedScalar *u,const CeedScalar *u1, 562 const CeedScalar *u2,const CeedScalar *u3, 563 const CeedScalar *u4,const CeedScalar *u5, 564 const CeedScalar *u6,const CeedScalar *u7, 565 const CeedScalar *u8,const CeedScalar *u9, 566 const CeedScalar *u10,const CeedScalar *u11, 567 const CeedScalar *u12,const CeedScalar *u13, 568 const CeedScalar *u14,const CeedScalar *u15, 569 CeedScalar *v,CeedScalar *v1,CeedScalar *v2, 570 CeedScalar *v3,CeedScalar *v4, 571 CeedScalar *v5,CeedScalar *v6, 572 CeedScalar *v7,CeedScalar *v8, 573 CeedScalar *v9,CeedScalar *v10, 574 CeedScalar *v11,CeedScalar *v12, 575 CeedScalar *v13,CeedScalar *v14, 576 CeedScalar *v15,int *err), 577 const char *source, int *qf, int *err, 578 fortran_charlen_t source_len) { 579 FIX_STRING(source); 580 if (CeedQFunction_count == CeedQFunction_count_max) { 581 CeedQFunction_count_max += CeedQFunction_count_max/2 + 1; 582 CeedRealloc(CeedQFunction_count_max, &CeedQFunction_dict); 583 } 584 585 CeedQFunction *qf_ = &CeedQFunction_dict[CeedQFunction_count]; 586 *err = CeedQFunctionCreateInterior(Ceed_dict[*ceed], *vlength, 587 CeedQFunctionFortranStub, source_c, qf_); 588 589 if (*err == 0) { 590 *qf = CeedQFunction_count++; 591 CeedQFunction_n++; 592 } 593 594 fContext *fctx; 595 *err = CeedMalloc(1, &fctx); 596 if (*err) return; 597 fctx->f = f; fctx->innerctx = NULL; fctx->innerctxsize = 0; 598 599 *err = CeedQFunctionSetContext(*qf_, fctx, sizeof(fContext)); 600 601 (*qf_)->fortranstatus = true; 602 } 603 604 #define fCeedQFunctionCreateInteriorByName \ 605 FORTRAN_NAME(ceedqfunctioncreateinteriorbyname, CEEDQFUNCTIONCREATEINTERIORBYNAME) 606 void fCeedQFunctionCreateInteriorByName(int *ceed, const char *name, int *qf, 607 int *err, fortran_charlen_t name_len) { 608 FIX_STRING(name); 609 if (CeedQFunction_count == CeedQFunction_count_max) { 610 CeedQFunction_count_max += CeedQFunction_count_max/2 + 1; 611 CeedRealloc(CeedQFunction_count_max, &CeedQFunction_dict); 612 } 613 614 CeedQFunction *qf_ = &CeedQFunction_dict[CeedQFunction_count]; 615 *err = CeedQFunctionCreateInteriorByName(Ceed_dict[*ceed], name_c, qf_); 616 617 if (*err == 0) { 618 *qf = CeedQFunction_count++; 619 CeedQFunction_n++; 620 } 621 } 622 623 #define fCeedQFunctionCreateIdentity \ 624 FORTRAN_NAME(ceedqfunctioncreateidentity, CEEDQFUNCTIONCREATEIDENTITY) 625 void fCeedQFunctionCreateIdentity(int *ceed, int *size, int *inmode, 626 int *outmode, int *qf, int *err) { 627 if (CeedQFunction_count == CeedQFunction_count_max) { 628 CeedQFunction_count_max += CeedQFunction_count_max/2 + 1; 629 CeedRealloc(CeedQFunction_count_max, &CeedQFunction_dict); 630 } 631 632 CeedQFunction *qf_ = &CeedQFunction_dict[CeedQFunction_count]; 633 *err = CeedQFunctionCreateIdentity(Ceed_dict[*ceed], *size, *inmode, 634 *outmode, qf_); 635 636 if (*err == 0) { 637 *qf = CeedQFunction_count++; 638 CeedQFunction_n++; 639 } 640 } 641 642 #define fCeedQFunctionAddInput \ 643 FORTRAN_NAME(ceedqfunctionaddinput,CEEDQFUNCTIONADDINPUT) 644 void fCeedQFunctionAddInput(int *qf, const char *fieldname, 645 CeedInt *ncomp, CeedEvalMode *emode, int *err, 646 fortran_charlen_t fieldname_len) { 647 FIX_STRING(fieldname); 648 CeedQFunction qf_ = CeedQFunction_dict[*qf]; 649 650 *err = CeedQFunctionAddInput(qf_, fieldname_c, *ncomp, *emode); 651 } 652 653 #define fCeedQFunctionAddOutput \ 654 FORTRAN_NAME(ceedqfunctionaddoutput,CEEDQFUNCTIONADDOUTPUT) 655 void fCeedQFunctionAddOutput(int *qf, const char *fieldname, 656 CeedInt *ncomp, CeedEvalMode *emode, int *err, 657 fortran_charlen_t fieldname_len) { 658 FIX_STRING(fieldname); 659 CeedQFunction qf_ = CeedQFunction_dict[*qf]; 660 661 *err = CeedQFunctionAddOutput(qf_, fieldname_c, *ncomp, *emode); 662 } 663 664 #define fCeedQFunctionSetContext \ 665 FORTRAN_NAME(ceedqfunctionsetcontext,CEEDQFUNCTIONSETCONTEXT) 666 void fCeedQFunctionSetContext(int *qf, CeedScalar *ctx, CeedInt *n, int *err) { 667 CeedQFunction qf_ = CeedQFunction_dict[*qf]; 668 669 fContext *fctx = qf_->ctx; 670 fctx->innerctx = ctx; 671 fctx->innerctxsize = ((size_t) *n)*sizeof(CeedScalar); 672 } 673 674 #define fCeedQFunctionView \ 675 FORTRAN_NAME(ceedqfunctionview,CEEDQFUNCTIONVIEW) 676 void fCeedQFunctionView(int *qf, int *err) { 677 CeedQFunction qf_ = CeedQFunction_dict[*qf]; 678 679 *err = CeedQFunctionView(qf_, stdout); 680 } 681 682 #define fCeedQFunctionApply \ 683 FORTRAN_NAME(ceedqfunctionapply,CEEDQFUNCTIONAPPLY) 684 //TODO Need Fixing, double pointer 685 void fCeedQFunctionApply(int *qf, int *Q, 686 int *u, int *u1, int *u2, int *u3, 687 int *u4, int *u5, int *u6, int *u7, 688 int *u8, int *u9, int *u10, int *u11, 689 int *u12, int *u13, int *u14, int *u15, 690 int *v, int *v1, int *v2, int *v3, 691 int *v4, int *v5, int *v6, int *v7, 692 int *v8, int *v9, int *v10, int *v11, 693 int *v12, int *v13, int *v14, int *v15, int *err) { 694 CeedQFunction qf_ = CeedQFunction_dict[*qf]; 695 CeedVector *in; 696 *err = CeedCalloc(16, &in); 697 if (*err) return; 698 in[0] = *u==FORTRAN_NULL?NULL:CeedVector_dict[*u]; 699 in[1] = *u1==FORTRAN_NULL?NULL:CeedVector_dict[*u1]; 700 in[2] = *u2==FORTRAN_NULL?NULL:CeedVector_dict[*u2]; 701 in[3] = *u3==FORTRAN_NULL?NULL:CeedVector_dict[*u3]; 702 in[4] = *u4==FORTRAN_NULL?NULL:CeedVector_dict[*u4]; 703 in[5] = *u5==FORTRAN_NULL?NULL:CeedVector_dict[*u5]; 704 in[6] = *u6==FORTRAN_NULL?NULL:CeedVector_dict[*u6]; 705 in[7] = *u7==FORTRAN_NULL?NULL:CeedVector_dict[*u7]; 706 in[8] = *u8==FORTRAN_NULL?NULL:CeedVector_dict[*u8]; 707 in[9] = *u9==FORTRAN_NULL?NULL:CeedVector_dict[*u9]; 708 in[10] = *u10==FORTRAN_NULL?NULL:CeedVector_dict[*u10]; 709 in[11] = *u11==FORTRAN_NULL?NULL:CeedVector_dict[*u11]; 710 in[12] = *u12==FORTRAN_NULL?NULL:CeedVector_dict[*u12]; 711 in[13] = *u13==FORTRAN_NULL?NULL:CeedVector_dict[*u13]; 712 in[14] = *u14==FORTRAN_NULL?NULL:CeedVector_dict[*u14]; 713 in[15] = *u15==FORTRAN_NULL?NULL:CeedVector_dict[*u15]; 714 CeedVector *out; 715 *err = CeedCalloc(16, &out); 716 if (*err) return; 717 out[0] = *v==FORTRAN_NULL?NULL:CeedVector_dict[*v]; 718 out[1] = *v1==FORTRAN_NULL?NULL:CeedVector_dict[*v1]; 719 out[2] = *v2==FORTRAN_NULL?NULL:CeedVector_dict[*v2]; 720 out[3] = *v3==FORTRAN_NULL?NULL:CeedVector_dict[*v3]; 721 out[4] = *v4==FORTRAN_NULL?NULL:CeedVector_dict[*v4]; 722 out[5] = *v5==FORTRAN_NULL?NULL:CeedVector_dict[*v5]; 723 out[6] = *v6==FORTRAN_NULL?NULL:CeedVector_dict[*v6]; 724 out[7] = *v7==FORTRAN_NULL?NULL:CeedVector_dict[*v7]; 725 out[8] = *v8==FORTRAN_NULL?NULL:CeedVector_dict[*v8]; 726 out[9] = *v9==FORTRAN_NULL?NULL:CeedVector_dict[*v9]; 727 out[10] = *v10==FORTRAN_NULL?NULL:CeedVector_dict[*v10]; 728 out[11] = *v11==FORTRAN_NULL?NULL:CeedVector_dict[*v11]; 729 out[12] = *v12==FORTRAN_NULL?NULL:CeedVector_dict[*v12]; 730 out[13] = *v13==FORTRAN_NULL?NULL:CeedVector_dict[*v13]; 731 out[14] = *v14==FORTRAN_NULL?NULL:CeedVector_dict[*v14]; 732 out[15] = *v15==FORTRAN_NULL?NULL:CeedVector_dict[*v15]; 733 *err = CeedQFunctionApply(qf_, *Q, in, out); 734 if (*err) return; 735 736 *err = CeedFree(&in); 737 if (*err) return; 738 *err = CeedFree(&out); 739 } 740 741 #define fCeedQFunctionDestroy \ 742 FORTRAN_NAME(ceedqfunctiondestroy,CEEDQFUNCTIONDESTROY) 743 void fCeedQFunctionDestroy(int *qf, int *err) { 744 bool fstatus; 745 *err = CeedQFunctionGetFortranStatus(CeedQFunction_dict[*qf], &fstatus); 746 if (*err) return; 747 if (fstatus) { 748 fContext *fctx = CeedQFunction_dict[*qf]->ctx; 749 *err = CeedFree(&fctx); 750 if (*err) return; 751 } 752 753 *err = CeedQFunctionDestroy(&CeedQFunction_dict[*qf]); 754 if (*err) return; 755 756 CeedQFunction_n--; 757 if (CeedQFunction_n == 0) { 758 *err = CeedFree(&CeedQFunction_dict); 759 CeedQFunction_count = 0; 760 CeedQFunction_count_max = 0; 761 } 762 } 763 764 static CeedOperator *CeedOperator_dict = NULL; 765 static int CeedOperator_count = 0; 766 static int CeedOperator_n = 0; 767 static int CeedOperator_count_max = 0; 768 769 #define fCeedOperatorCreate \ 770 FORTRAN_NAME(ceedoperatorcreate, CEEDOPERATORCREATE) 771 void fCeedOperatorCreate(int *ceed, 772 int *qf, int *dqf, int *dqfT, int *op, int *err) { 773 if (CeedOperator_count == CeedOperator_count_max) 774 CeedOperator_count_max += CeedOperator_count_max/2 + 1, 775 CeedOperator_dict = realloc(CeedOperator_dict, 776 sizeof(CeedOperator)*CeedOperator_count_max); 777 778 CeedOperator *op_ = &CeedOperator_dict[CeedOperator_count]; 779 780 CeedQFunction dqf_ = CEED_QFUNCTION_NONE, dqfT_ = CEED_QFUNCTION_NONE; 781 if (*dqf != FORTRAN_QFUNCTION_NONE) dqf_ = CeedQFunction_dict[*dqf ]; 782 if (*dqfT != FORTRAN_QFUNCTION_NONE) dqfT_ = CeedQFunction_dict[*dqfT]; 783 784 *err = CeedOperatorCreate(Ceed_dict[*ceed], CeedQFunction_dict[*qf], dqf_, 785 dqfT_, op_); 786 if (*err) return; 787 *op = CeedOperator_count++; 788 CeedOperator_n++; 789 } 790 791 #define fCeedCompositeOperatorCreate \ 792 FORTRAN_NAME(ceedcompositeoperatorcreate, CEEDCOMPOSITEOPERATORCREATE) 793 void fCeedCompositeOperatorCreate(int *ceed, int *op, int *err) { 794 if (CeedOperator_count == CeedOperator_count_max) 795 CeedOperator_count_max += CeedOperator_count_max/2 + 1, 796 CeedOperator_dict = realloc(CeedOperator_dict, 797 sizeof(CeedOperator)*CeedOperator_count_max); 798 799 CeedOperator *op_ = &CeedOperator_dict[CeedOperator_count]; 800 801 *err = CeedCompositeOperatorCreate(Ceed_dict[*ceed], op_); 802 if (*err) return; 803 *op = CeedOperator_count++; 804 CeedOperator_n++; 805 } 806 807 #define fCeedOperatorSetField \ 808 FORTRAN_NAME(ceedoperatorsetfield,CEEDOPERATORSETFIELD) 809 void fCeedOperatorSetField(int *op, const char *fieldname, int *r, int *b, 810 int *v, int *err, fortran_charlen_t fieldname_len) { 811 FIX_STRING(fieldname); 812 CeedElemRestriction r_; 813 CeedBasis b_; 814 CeedVector v_; 815 816 CeedOperator op_ = CeedOperator_dict[*op]; 817 818 if (*r == FORTRAN_NULL) { 819 r_ = NULL; 820 } else { 821 r_ = CeedElemRestriction_dict[*r]; 822 } 823 824 if (*b == FORTRAN_NULL) { 825 b_ = NULL; 826 } else if (*b == FORTRAN_BASIS_COLLOCATED) { 827 b_ = CEED_BASIS_COLLOCATED; 828 } else { 829 b_ = CeedBasis_dict[*b]; 830 } 831 if (*v == FORTRAN_NULL) { 832 v_ = NULL; 833 } else if (*v == FORTRAN_VECTOR_ACTIVE) { 834 v_ = CEED_VECTOR_ACTIVE; 835 } else if (*v == FORTRAN_VECTOR_NONE) { 836 v_ = CEED_VECTOR_NONE; 837 } else { 838 v_ = CeedVector_dict[*v]; 839 } 840 841 *err = CeedOperatorSetField(op_, fieldname_c, r_, b_, v_); 842 } 843 844 #define fCeedCompositeOperatorAddSub \ 845 FORTRAN_NAME(ceedcompositeoperatoraddsub, CEEDCOMPOSITEOPERATORADDSUB) 846 void fCeedCompositeOperatorAddSub(int *compositeop, int *subop, int *err) { 847 CeedOperator compositeop_ = CeedOperator_dict[*compositeop]; 848 CeedOperator subop_ = CeedOperator_dict[*subop]; 849 850 *err = CeedCompositeOperatorAddSub(compositeop_, subop_); 851 if (*err) return; 852 } 853 854 #define fCeedOperatorAssembleLinearQFunction FORTRAN_NAME(ceedoperatorassemblelinearqfunction, CEEDOPERATORASSEMBLELINEARQFUNCTION) 855 void fCeedOperatorAssembleLinearQFunction(int *op, int *assembledvec, 856 int *assembledrstr, int *rqst, int *err) { 857 // Vector 858 if (CeedVector_count == CeedVector_count_max) { 859 CeedVector_count_max += CeedVector_count_max/2 + 1; 860 CeedRealloc(CeedVector_count_max, &CeedVector_dict); 861 } 862 CeedVector *assembledvec_ = &CeedVector_dict[CeedVector_count]; 863 864 // Restriction 865 if (CeedElemRestriction_count == CeedElemRestriction_count_max) { 866 CeedElemRestriction_count_max += CeedElemRestriction_count_max/2 + 1; 867 CeedRealloc(CeedElemRestriction_count_max, &CeedElemRestriction_dict); 868 } 869 CeedElemRestriction *rstr_ = 870 &CeedElemRestriction_dict[CeedElemRestriction_count]; 871 872 int createRequest = 1; 873 // Check if input is CEED_REQUEST_ORDERED(-2) or CEED_REQUEST_IMMEDIATE(-1) 874 if (*rqst == -1 || *rqst == -2) { 875 createRequest = 0; 876 } 877 878 if (createRequest && CeedRequest_count == CeedRequest_count_max) { 879 CeedRequest_count_max += CeedRequest_count_max/2 + 1; 880 CeedRealloc(CeedRequest_count_max, &CeedRequest_dict); 881 } 882 883 CeedRequest *rqst_; 884 if (*rqst == -1) rqst_ = CEED_REQUEST_IMMEDIATE; 885 else if (*rqst == -2) rqst_ = CEED_REQUEST_ORDERED; 886 else rqst_ = &CeedRequest_dict[CeedRequest_count]; 887 888 *err = CeedOperatorAssembleLinearQFunction(CeedOperator_dict[*op], 889 assembledvec_, rstr_, rqst_); 890 if (*err) return; 891 if (createRequest) { 892 *rqst = CeedRequest_count++; 893 CeedRequest_n++; 894 } 895 896 if (*err == 0) { 897 *assembledrstr = CeedElemRestriction_count++; 898 CeedElemRestriction_n++; 899 *assembledvec = CeedVector_count++; 900 CeedVector_n++; 901 } 902 } 903 904 #define fCeedOperatorAssembleLinearDiagonal FORTRAN_NAME(ceedoperatorassemblelineardiagonal, CEEDOPERATORASSEMBLELINEARDIAGONAL) 905 void fCeedOperatorAssembleLinearDiagonal(int *op, int *assembledvec, 906 int *rqst, int *err) { 907 // Vector 908 if (CeedVector_count == CeedVector_count_max) { 909 CeedVector_count_max += CeedVector_count_max/2 + 1; 910 CeedRealloc(CeedVector_count_max, &CeedVector_dict); 911 } 912 CeedVector *assembledvec_ = &CeedVector_dict[CeedVector_count]; 913 914 int createRequest = 1; 915 // Check if input is CEED_REQUEST_ORDERED(-2) or CEED_REQUEST_IMMEDIATE(-1) 916 if (*rqst == -1 || *rqst == -2) { 917 createRequest = 0; 918 } 919 920 if (createRequest && CeedRequest_count == CeedRequest_count_max) { 921 CeedRequest_count_max += CeedRequest_count_max/2 + 1; 922 CeedRealloc(CeedRequest_count_max, &CeedRequest_dict); 923 } 924 925 CeedRequest *rqst_; 926 if (*rqst == -1) rqst_ = CEED_REQUEST_IMMEDIATE; 927 else if (*rqst == -2) rqst_ = CEED_REQUEST_ORDERED; 928 else rqst_ = &CeedRequest_dict[CeedRequest_count]; 929 930 *err = CeedOperatorAssembleLinearDiagonal(CeedOperator_dict[*op], 931 assembledvec_, rqst_); 932 if (*err) return; 933 if (createRequest) { 934 *rqst = CeedRequest_count++; 935 CeedRequest_n++; 936 } 937 938 if (*err == 0) { 939 *assembledvec = CeedVector_count++; 940 CeedVector_n++; 941 } 942 } 943 944 #define fCeedOperatorView \ 945 FORTRAN_NAME(ceedoperatorview,CEEDOPERATORVIEW) 946 void fCeedOperatorView(int *op, int *err) { 947 CeedOperator op_ = CeedOperator_dict[*op]; 948 949 *err = CeedOperatorView(op_, stdout); 950 } 951 952 #define fCeedOperatorCreateFDMElementInverse FORTRAN_NAME(ceedoperatorcreatefdmelementinverse, CEEDOPERATORCREATEFDMELEMENTINVERSE) 953 void fCeedOperatorCreateFDMElementInverse(int *op, int *fdminv, 954 int *rqst, int *err) { 955 // Operator 956 if (CeedOperator_count == CeedOperator_count_max) { 957 CeedOperator_count_max += CeedOperator_count_max/2 + 1; 958 CeedRealloc(CeedOperator_count_max, &CeedOperator_dict); 959 } 960 CeedOperator *fdminv_ = 961 &CeedOperator_dict[CeedOperator_count]; 962 963 int createRequest = 1; 964 // Check if input is CEED_REQUEST_ORDERED(-2) or CEED_REQUEST_IMMEDIATE(-1) 965 if (*rqst == -1 || *rqst == -2) { 966 createRequest = 0; 967 } 968 969 if (createRequest && CeedRequest_count == CeedRequest_count_max) { 970 CeedRequest_count_max += CeedRequest_count_max/2 + 1; 971 CeedRealloc(CeedRequest_count_max, &CeedRequest_dict); 972 } 973 974 CeedRequest *rqst_; 975 if (*rqst == -1) rqst_ = CEED_REQUEST_IMMEDIATE; 976 else if (*rqst == -2) rqst_ = CEED_REQUEST_ORDERED; 977 else rqst_ = &CeedRequest_dict[CeedRequest_count]; 978 979 *err = CeedOperatorCreateFDMElementInverse(CeedOperator_dict[*op], 980 fdminv_, rqst_); 981 if (*err) return; 982 if (createRequest) { 983 *rqst = CeedRequest_count++; 984 CeedRequest_n++; 985 } 986 987 if (*err == 0) { 988 *fdminv = CeedOperator_count++; 989 CeedOperator_n++; 990 } 991 } 992 993 #define fCeedOperatorApply FORTRAN_NAME(ceedoperatorapply, CEEDOPERATORAPPLY) 994 void fCeedOperatorApply(int *op, int *ustatevec, 995 int *resvec, int *rqst, int *err) { 996 CeedVector ustatevec_ = (*ustatevec == FORTRAN_NULL) ? 997 NULL : (*ustatevec == FORTRAN_VECTOR_NONE ? 998 CEED_VECTOR_NONE : CeedVector_dict[*ustatevec]); 999 CeedVector resvec_ = (*resvec == FORTRAN_NULL) ? 1000 NULL : (*resvec == FORTRAN_VECTOR_NONE ? 1001 CEED_VECTOR_NONE : CeedVector_dict[*resvec]); 1002 1003 int createRequest = 1; 1004 // Check if input is CEED_REQUEST_ORDERED(-2) or CEED_REQUEST_IMMEDIATE(-1) 1005 if (*rqst == -1 || *rqst == -2) { 1006 createRequest = 0; 1007 } 1008 1009 if (createRequest && CeedRequest_count == CeedRequest_count_max) { 1010 CeedRequest_count_max += CeedRequest_count_max/2 + 1; 1011 CeedRealloc(CeedRequest_count_max, &CeedRequest_dict); 1012 } 1013 1014 CeedRequest *rqst_; 1015 if (*rqst == -1) rqst_ = CEED_REQUEST_IMMEDIATE; 1016 else if (*rqst == -2) rqst_ = CEED_REQUEST_ORDERED; 1017 else rqst_ = &CeedRequest_dict[CeedRequest_count]; 1018 1019 *err = CeedOperatorApply(CeedOperator_dict[*op], 1020 ustatevec_, resvec_, rqst_); 1021 if (*err) return; 1022 if (createRequest) { 1023 *rqst = CeedRequest_count++; 1024 CeedRequest_n++; 1025 } 1026 } 1027 1028 #define fCeedOperatorApplyAdd FORTRAN_NAME(ceedoperatorapplyadd, CEEDOPERATORAPPLYADD) 1029 void fCeedOperatorApplyAdd(int *op, int *ustatevec, 1030 int *resvec, int *rqst, int *err) { 1031 CeedVector ustatevec_ = *ustatevec == FORTRAN_NULL 1032 ? NULL : CeedVector_dict[*ustatevec]; 1033 CeedVector resvec_ = *resvec == FORTRAN_NULL 1034 ? NULL : CeedVector_dict[*resvec]; 1035 1036 int createRequest = 1; 1037 // Check if input is CEED_REQUEST_ORDERED(-2) or CEED_REQUEST_IMMEDIATE(-1) 1038 if (*rqst == -1 || *rqst == -2) { 1039 createRequest = 0; 1040 } 1041 1042 if (createRequest && CeedRequest_count == CeedRequest_count_max) { 1043 CeedRequest_count_max += CeedRequest_count_max/2 + 1; 1044 CeedRealloc(CeedRequest_count_max, &CeedRequest_dict); 1045 } 1046 1047 CeedRequest *rqst_; 1048 if (*rqst == -1) rqst_ = CEED_REQUEST_IMMEDIATE; 1049 else if (*rqst == -2) rqst_ = CEED_REQUEST_ORDERED; 1050 else rqst_ = &CeedRequest_dict[CeedRequest_count]; 1051 1052 *err = CeedOperatorApplyAdd(CeedOperator_dict[*op], 1053 ustatevec_, resvec_, rqst_); 1054 if (*err) return; 1055 if (createRequest) { 1056 *rqst = CeedRequest_count++; 1057 CeedRequest_n++; 1058 } 1059 } 1060 1061 #define fCeedOperatorApplyJacobian \ 1062 FORTRAN_NAME(ceedoperatorapplyjacobian, CEEDOPERATORAPPLYJACOBIAN) 1063 void fCeedOperatorApplyJacobian(int *op, int *qdatavec, int *ustatevec, 1064 int *dustatevec, int *dresvec, int *rqst, 1065 int *err) { 1066 // TODO Uncomment this when CeedOperatorApplyJacobian is implemented 1067 // *err = CeedOperatorApplyJacobian(CeedOperator_dict[*op], CeedVector_dict[*qdatavec], 1068 // CeedVector_dict[*ustatevec], CeedVector_dict[*dustatevec], 1069 // CeedVector_dict[*dresvec], &CeedRequest_dict[*rqst]); 1070 } 1071 1072 #define fCeedOperatorDestroy \ 1073 FORTRAN_NAME(ceedoperatordestroy, CEEDOPERATORDESTROY) 1074 void fCeedOperatorDestroy(int *op, int *err) { 1075 *err = CeedOperatorDestroy(&CeedOperator_dict[*op]); 1076 if (*err) return; 1077 CeedOperator_n--; 1078 if (CeedOperator_n == 0) { 1079 *err = CeedFree(&CeedOperator_dict); 1080 CeedOperator_count = 0; 1081 CeedOperator_count_max = 0; 1082 } 1083 } 1084