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