ceed-operator.c (0614b1d0ba5591db85fb98bda6c08c2e102a1bc7) ceed-operator.c (5107b09fcb4710dffb8bf2363d6d7d4be3d24cc9)
1// Copyright (c) 2017, Lawrence Livermore National Security, LLC. Produced at
2// the Lawrence Livermore National Laboratory. LLNL-CODE-734707. All Rights
3// 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.

--- 44 unchanged lines hidden (view full) ---

53 // LCOV_EXCL_START
54 return CeedError(ceed, 1, "Backend does not support OperatorCreate");
55 // LCOV_EXCL_STOP
56
57 ierr = CeedOperatorCreate(delegate, qf, dqf, dqfT, op); CeedChk(ierr);
58 return 0;
59 }
60
1// Copyright (c) 2017, Lawrence Livermore National Security, LLC. Produced at
2// the Lawrence Livermore National Laboratory. LLNL-CODE-734707. All Rights
3// 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.

--- 44 unchanged lines hidden (view full) ---

53 // LCOV_EXCL_START
54 return CeedError(ceed, 1, "Backend does not support OperatorCreate");
55 // LCOV_EXCL_STOP
56
57 ierr = CeedOperatorCreate(delegate, qf, dqf, dqfT, op); CeedChk(ierr);
58 return 0;
59 }
60
61 ierr = CeedCalloc(1,op); CeedChk(ierr);
61 ierr = CeedCalloc(1, op); CeedChk(ierr);
62 (*op)->ceed = ceed;
63 ceed->refcount++;
64 (*op)->refcount = 1;
65 if (qf == CEED_QFUNCTION_NONE)
66 // LCOV_EXCL_START
67 return CeedError(ceed, 1, "Operator must have a valid QFunction.");
68 // LCOV_EXCL_STOP
69 (*op)->qf = qf;

--- 182 unchanged lines hidden (view full) ---

252
253 compositeop->suboperators[compositeop->numsub] = subop;
254 subop->refcount++;
255 compositeop->numsub++;
256 return 0;
257}
258
259/**
62 (*op)->ceed = ceed;
63 ceed->refcount++;
64 (*op)->refcount = 1;
65 if (qf == CEED_QFUNCTION_NONE)
66 // LCOV_EXCL_START
67 return CeedError(ceed, 1, "Operator must have a valid QFunction.");
68 // LCOV_EXCL_STOP
69 (*op)->qf = qf;

--- 182 unchanged lines hidden (view full) ---

252
253 compositeop->suboperators[compositeop->numsub] = subop;
254 subop->refcount++;
255 compositeop->numsub++;
256 return 0;
257}
258
259/**
260 @brief Duplicate a CeedOperator with a reference Ceed to fallback for advanced
261 CeedOperator functionality
262
263 @param op CeedOperator to create fallback for
264
265 @return An error code: 0 - success, otherwise - failure
266
267 @ref Developer
268**/
269int CeedOperatorCreateFallback(CeedOperator op) {
270 int ierr;
271
272 // Fallback Ceed
273 const char *resource, *fallbackresource;
274 ierr = CeedGetResource(op->ceed, &resource); CeedChk(ierr);
275 ierr = CeedGetOperatorFallbackResource(op->ceed, &fallbackresource);
276 CeedChk(ierr);
277 if (!strcmp(resource, fallbackresource))
278 // LCOV_EXCL_START
279 return CeedError(op->ceed, 1, "Backend %s cannot create an operator"
280 "fallback to resource %s", resource, fallbackresource);
281 // LCOV_EXCL_STOP
282
283 Ceed ceedref;
284 ierr = CeedInit(fallbackresource, &ceedref); CeedChk(ierr);
285 ceedref->opfallbackparent = op->ceed;
286 op->ceed->opfallbackceed = ceedref;
287
288 // Clone Op
289 CeedOperator opref;
290 ierr = CeedCalloc(1, &opref); CeedChk(ierr);
291 memcpy(opref, op, sizeof(*opref)); CeedChk(ierr);
292 opref->data = NULL;
293 opref->setupdone = 0;
294 opref->ceed = ceedref;
295 ierr = ceedref->OperatorCreate(opref); CeedChk(ierr);
296 op->opfallback = opref;
297
298 // Clone QF
299 CeedQFunction qfref;
300 ierr = CeedCalloc(1, &qfref); CeedChk(ierr);
301 memcpy(qfref, (op->qf), sizeof(*qfref)); CeedChk(ierr);
302 qfref->data = NULL;
303 qfref->ceed = ceedref;
304 ierr = ceedref->QFunctionCreate(qfref); CeedChk(ierr);
305 opref->qf = qfref;
306 op->qffallback = qfref;
307
308 return 0;
309}
310
311/**
260 @brief Assemble a linear CeedQFunction associated with a CeedOperator
261
262 This returns a CeedVector containing a matrix at each quadrature point
263 providing the action of the CeedQFunction associated with the CeedOperator.
264 The vector 'assembled' is of shape
265 [num_elements, num_input_fields, num_output_fields, num_quad_points]
266 and contains column-major matrices representing the action of the
267 CeedQFunction for a corresponding quadrature point on an element. Inputs and

--- 39 unchanged lines hidden (view full) ---

307 // LCOV_EXCL_START
308 return CeedError(ceed, 1, "At least one restriction required");
309 // LCOV_EXCL_STOP
310 if (op->numqpoints == 0)
311 // LCOV_EXCL_START
312 return CeedError(ceed, 1, "At least one non-collocated basis required");
313 // LCOV_EXCL_STOP
314 }
312 @brief Assemble a linear CeedQFunction associated with a CeedOperator
313
314 This returns a CeedVector containing a matrix at each quadrature point
315 providing the action of the CeedQFunction associated with the CeedOperator.
316 The vector 'assembled' is of shape
317 [num_elements, num_input_fields, num_output_fields, num_quad_points]
318 and contains column-major matrices representing the action of the
319 CeedQFunction for a corresponding quadrature point on an element. Inputs and

--- 39 unchanged lines hidden (view full) ---

359 // LCOV_EXCL_START
360 return CeedError(ceed, 1, "At least one restriction required");
361 // LCOV_EXCL_STOP
362 if (op->numqpoints == 0)
363 // LCOV_EXCL_START
364 return CeedError(ceed, 1, "At least one non-collocated basis required");
365 // LCOV_EXCL_STOP
366 }
315 ierr = op->AssembleLinearQFunction(op, assembled, rstr, request);
316 CeedChk(ierr);
367 if (op->AssembleLinearQFunction) {
368 ierr = op->AssembleLinearQFunction(op, assembled, rstr, request);
369 CeedChk(ierr);
370 } else {
371 // Fallback to reference Ceed
372 if (!op->opfallback) {
373 ierr = CeedOperatorCreateFallback(op); CeedChk(ierr);
374 }
375 // Assemble
376 ierr = op->opfallback->AssembleLinearQFunction(op->opfallback, assembled,
377 rstr, request); CeedChk(ierr);
378 }
317 return 0;
318}
319
320/**
321 @brief Assemble the diagonal of a square linear Operator
322
323 This returns a CeedVector containing the diagonal of a linear CeedOperator.
324

--- 685 unchanged lines hidden (view full) ---

1010 for (int i=0; i<(*op)->numsub; i++)
1011 if ((*op)->suboperators[i]) {
1012 ierr = CeedOperatorDestroy(&(*op)->suboperators[i]); CeedChk(ierr);
1013 }
1014 ierr = CeedQFunctionDestroy(&(*op)->qf); CeedChk(ierr);
1015 ierr = CeedQFunctionDestroy(&(*op)->dqf); CeedChk(ierr);
1016 ierr = CeedQFunctionDestroy(&(*op)->dqfT); CeedChk(ierr);
1017
379 return 0;
380}
381
382/**
383 @brief Assemble the diagonal of a square linear Operator
384
385 This returns a CeedVector containing the diagonal of a linear CeedOperator.
386

--- 685 unchanged lines hidden (view full) ---

1072 for (int i=0; i<(*op)->numsub; i++)
1073 if ((*op)->suboperators[i]) {
1074 ierr = CeedOperatorDestroy(&(*op)->suboperators[i]); CeedChk(ierr);
1075 }
1076 ierr = CeedQFunctionDestroy(&(*op)->qf); CeedChk(ierr);
1077 ierr = CeedQFunctionDestroy(&(*op)->dqf); CeedChk(ierr);
1078 ierr = CeedQFunctionDestroy(&(*op)->dqfT); CeedChk(ierr);
1079
1080 // Destroy fallback
1081 if ((*op)->opfallback) {
1082 ierr = (*op)->qffallback->Destroy((*op)->qffallback); CeedChk(ierr);
1083 ierr = CeedFree(&(*op)->qffallback); CeedChk(ierr);
1084 ierr = (*op)->opfallback->Destroy((*op)->opfallback); CeedChk(ierr);
1085 ierr = CeedFree(&(*op)->opfallback); CeedChk(ierr);
1086 }
1087
1018 ierr = CeedFree(&(*op)->inputfields); CeedChk(ierr);
1019 ierr = CeedFree(&(*op)->outputfields); CeedChk(ierr);
1020 ierr = CeedFree(&(*op)->suboperators); CeedChk(ierr);
1021 ierr = CeedFree(op); CeedChk(ierr);
1022 return 0;
1023}
1024
1025/// @}
1088 ierr = CeedFree(&(*op)->inputfields); CeedChk(ierr);
1089 ierr = CeedFree(&(*op)->outputfields); CeedChk(ierr);
1090 ierr = CeedFree(&(*op)->suboperators); CeedChk(ierr);
1091 ierr = CeedFree(op); CeedChk(ierr);
1092 return 0;
1093}
1094
1095/// @}