ceed-qfunction.c (7af48cf9dcfc376eb44438498992419314d973a5) ceed-qfunction.c (75affc3b27ef4afd9e0b71275e32fb85c1a00c79)
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.

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

143 @return An error code: 0 - success, otherwise - failure
144
145 @ref Basic
146**/
147int CeedQFunctionCreateInteriorByName(Ceed ceed, const char *name,
148 CeedQFunction *qf) {
149 int ierr;
150 size_t matchlen = 0, matchidx = UINT_MAX;
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.

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

143 @return An error code: 0 - success, otherwise - failure
144
145 @ref Basic
146**/
147int CeedQFunctionCreateInteriorByName(Ceed ceed, const char *name,
148 CeedQFunction *qf) {
149 int ierr;
150 size_t matchlen = 0, matchidx = UINT_MAX;
151 char *name_copy;
151
152 // Find matching backend
153 if (!name) return CeedError(NULL, 1, "No QFunction name provided");
154 for (size_t i=0; i<num_qfunctions; i++) {
155 size_t n;
156 const char *currname = qfunctions[i].name;
157 for (n = 0; currname[n] && currname[n] == name[n]; n++) {}
158 if (n > matchlen) {

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

169 ierr = CeedQFunctionCreateInterior(ceed, qfunctions[matchidx].vlength,
170 qfunctions[matchidx].f,
171 qfunctions[matchidx].source, qf);
172 CeedChk(ierr);
173
174 // QFunction specific setup
175 ierr = qfunctions[matchidx].init(ceed, name, *qf); CeedChk(ierr);
176
152
153 // Find matching backend
154 if (!name) return CeedError(NULL, 1, "No QFunction name provided");
155 for (size_t i=0; i<num_qfunctions; i++) {
156 size_t n;
157 const char *currname = qfunctions[i].name;
158 for (n = 0; currname[n] && currname[n] == name[n]; n++) {}
159 if (n > matchlen) {

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

170 ierr = CeedQFunctionCreateInterior(ceed, qfunctions[matchidx].vlength,
171 qfunctions[matchidx].f,
172 qfunctions[matchidx].source, qf);
173 CeedChk(ierr);
174
175 // QFunction specific setup
176 ierr = qfunctions[matchidx].init(ceed, name, *qf); CeedChk(ierr);
177
178 // Copy name
179 size_t slen = strlen(name) + 1;
180 ierr = CeedMalloc(slen, &name_copy); CeedChk(ierr);
181 memcpy(name_copy, name, slen);
182 (*qf)->qfname = name_copy;
183
177 return 0;
178}
179
180/**
181 @brief Create an identity CeedQFunction. Inputs are written into outputs in
182 the order given. This is useful for CeedOperators that can be
183 represented with only the action of a CeedRestriction and CeedBasis,
184 such as restriction and prolongation operators for p-multigrid.

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

528**/
529int CeedQFunctionSetContext(CeedQFunction qf, void *ctx, size_t ctxsize) {
530 qf->ctx = ctx;
531 qf->ctxsize = ctxsize;
532 return 0;
533}
534
535/**
184 return 0;
185}
186
187/**
188 @brief Create an identity CeedQFunction. Inputs are written into outputs in
189 the order given. This is useful for CeedOperators that can be
190 represented with only the action of a CeedRestriction and CeedBasis,
191 such as restriction and prolongation operators for p-multigrid.

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

535**/
536int CeedQFunctionSetContext(CeedQFunction qf, void *ctx, size_t ctxsize) {
537 qf->ctx = ctx;
538 qf->ctxsize = ctxsize;
539 return 0;
540}
541
542/**
543 @brief View a field of a CeedQFunction
544
545 @param[in] field QFunction field to view
546 @param[in] fieldnum Number of field being viewed
547 @param[in] stream Stream to view to, e.g., stdout
548
549 @return An error code: 0 - success, otherwise - failure
550
551 @ref Utility
552**/
553static int CeedQFunctionFieldView(CeedQFunctionField field, CeedInt fieldnumber,
554 FILE *stream) {
555 fprintf(stream, " [%d] QFunction Field \"%s\"\n"
556 " Size %d\n"
557 " EvalMode \"%s\"\n",
558 fieldnumber, field->fieldname, field->size,
559 CeedEvalModes[field->emode]);
560
561 return 0;
562}
563
564/**
565 @brief View a CeedQFunction
566
567 @param[in] qf CeedQFunction to view
568 @param[in] stream Stream to write; typically stdout/stderr or a file
569
570 @return Error code: 0 - success, otherwise - failure
571
572 @ref Utility
573**/
574int CeedQFunctionView(CeedQFunction qf, FILE *stream) {
575 int ierr;
576
577 fprintf(stream, "%sCeedQFunction %s\n",
578 qf->qfname ? "Gallery " : "User ", qf->qfname ? qf->qfname : "");
579
580
581 fprintf(stream, "%d Input Field%s\n", qf->numinputfields,
582 qf->numinputfields>1 ? "s" : "");
583 for (CeedInt i=0; i<qf->numinputfields; i++) {
584 ierr = CeedQFunctionFieldView(qf->inputfields[i], i, stream); CeedChk(ierr);
585 }
586
587 fprintf(stream, "%d Output Field%s\n", qf->numoutputfields,
588 qf->numoutputfields>1 ? "s" : "");
589 for (CeedInt i=0; i<qf->numoutputfields; i++) {
590 ierr = CeedQFunctionFieldView(qf->outputfields[i], i, stream);
591 CeedChk(ierr);
592 }
593 return 0;
594}
595
596/**
536 @brief Apply the action of a CeedQFunction
537
538 @param qf CeedQFunction
539 @param Q Number of quadrature points
540 @param[in] u Array of input data arrays
541 @param[out] v Array of output data arrays
542
543 @return An error code: 0 - success, otherwise - failure

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

660 ierr = CeedFree(&(*qf)->inputfields); CeedChk(ierr);
661 ierr = CeedFree(&(*qf)->outputfields); CeedChk(ierr);
662 // Free ctx if identity
663 if ((*qf)->identity) {
664 ierr = CeedFree(&(*qf)->ctx); CeedChk(ierr);
665 }
666
667 ierr = CeedFree(&(*qf)->sourcepath); CeedChk(ierr);
597 @brief Apply the action of a CeedQFunction
598
599 @param qf CeedQFunction
600 @param Q Number of quadrature points
601 @param[in] u Array of input data arrays
602 @param[out] v Array of output data arrays
603
604 @return An error code: 0 - success, otherwise - failure

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

721 ierr = CeedFree(&(*qf)->inputfields); CeedChk(ierr);
722 ierr = CeedFree(&(*qf)->outputfields); CeedChk(ierr);
723 // Free ctx if identity
724 if ((*qf)->identity) {
725 ierr = CeedFree(&(*qf)->ctx); CeedChk(ierr);
726 }
727
728 ierr = CeedFree(&(*qf)->sourcepath); CeedChk(ierr);
729 ierr = CeedFree(&(*qf)->qfname); CeedChk(ierr);
668 ierr = CeedDestroy(&(*qf)->ceed); CeedChk(ierr);
669 ierr = CeedFree(qf); CeedChk(ierr);
670 return 0;
671}
672
673/// @cond DOXYGEN_SKIP
674// Indicate that no QFunction is provided by the user
675CeedQFunction CEED_QFUNCTION_NONE = &ceed_qfunction_none;
676/// @endcond
677/// @}
730 ierr = CeedDestroy(&(*qf)->ceed); CeedChk(ierr);
731 ierr = CeedFree(qf); CeedChk(ierr);
732 return 0;
733}
734
735/// @cond DOXYGEN_SKIP
736// Indicate that no QFunction is provided by the user
737CeedQFunction CEED_QFUNCTION_NONE = &ceed_qfunction_none;
738/// @endcond
739/// @}