File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -27,19 +27,30 @@ namespace ceed {
2727
2828 Basis::~Basis () {}
2929
30- Basis* Basis::from (CeedBasis basis) {
30+ Basis* Basis::getBasis (CeedBasis basis,
31+ const bool assertValid) {
3132 if (!basis) {
3233 return NULL ;
3334 }
3435
3536 int ierr;
36- Basis *basis_;
37+ Basis *basis_ = NULL ;
38+
39+ ierr = CeedBasisGetData (basis, &basis_);
40+ if (assertValid) {
41+ CeedOccaFromChk (ierr);
42+ }
43+
44+ return basis_;
45+ }
3746
38- ierr = CeedBasisGetData (basis, &basis_); CeedOccaFromChk (ierr);
47+ Basis* Basis::from (CeedBasis basis) {
48+ Basis *basis_ = getBasis (basis);
3949 if (!basis_) {
4050 return NULL ;
4151 }
4252
53+ int ierr;
4354 ierr = basis_->setCeedFields (basis); CeedOccaFromChk (ierr);
4455
4556 return basis_;
@@ -86,7 +97,7 @@ namespace ceed {
8697 }
8798
8899 int Basis::ceedDestroy (CeedBasis basis) {
89- delete Basis::from (basis);
100+ delete getBasis (basis, false );
90101 return CEED_ERROR_SUCCESS;
91102 }
92103 }
Original file line number Diff line number Diff line change @@ -36,6 +36,9 @@ namespace ceed {
3636
3737 virtual ~Basis ();
3838
39+ static Basis* getBasis (CeedBasis basis,
40+ const bool assertValid = true );
41+
3942 static Basis* from (CeedBasis basis);
4043 static Basis* from (CeedOperatorField operatorField);
4144
Original file line number Diff line number Diff line change @@ -194,17 +194,30 @@ namespace ceed {
194194 );
195195 }
196196
197- ElemRestriction* ElemRestriction::from (CeedElemRestriction r) {
197+ ElemRestriction* ElemRestriction::getElemRestriction (CeedElemRestriction r,
198+ const bool assertValid) {
198199 if (!r || r == CEED_ELEMRESTRICTION_NONE) {
199200 return NULL ;
200201 }
201202
202203 int ierr;
203- ElemRestriction *elemRestriction;
204+ ElemRestriction *elemRestriction = NULL ;
204205
205206 ierr = CeedElemRestrictionGetData (r, (void **) &elemRestriction);
206- CeedOccaFromChk (ierr);
207+ if (assertValid) {
208+ CeedOccaFromChk (ierr);
209+ }
210+
211+ return elemRestriction;
212+ }
207213
214+ ElemRestriction* ElemRestriction::from (CeedElemRestriction r) {
215+ ElemRestriction *elemRestriction = getElemRestriction (r);
216+ if (!elemRestriction) {
217+ return NULL ;
218+ }
219+
220+ int ierr;
208221 ierr = CeedElemRestrictionGetCeed (r, &elemRestriction->ceed );
209222 CeedOccaFromChk (ierr);
210223
@@ -429,7 +442,7 @@ namespace ceed {
429442 }
430443
431444 int ElemRestriction::ceedDestroy (CeedElemRestriction r) {
432- delete ElemRestriction::from (r );
445+ delete getElemRestriction (r, false );
433446 return CEED_ERROR_SUCCESS;
434447 }
435448 }
Original file line number Diff line number Diff line change @@ -76,6 +76,9 @@ namespace ceed {
7676
7777 void setupKernelBuilders ();
7878
79+ static ElemRestriction* getElemRestriction (CeedElemRestriction r,
80+ const bool assertValid = true );
81+
7982 static ElemRestriction* from (CeedElemRestriction r);
8083 static ElemRestriction* from (CeedOperatorField operatorField);
8184 ElemRestriction* setupFrom (CeedElemRestriction r);
Original file line number Diff line number Diff line change @@ -31,15 +31,30 @@ namespace ceed {
3131
3232 Operator::~Operator () {}
3333
34- Operator* Operator::from (CeedOperator op) {
34+ Operator* Operator::getOperator (CeedOperator op,
35+ const bool assertValid) {
3536 if (!op) {
3637 return NULL ;
3738 }
3839
3940 int ierr;
40- Operator *operator_;
41+ Operator *operator_ = NULL ;
42+
43+ ierr = CeedOperatorGetData (op, (void **) &operator_);
44+ if (assertValid) {
45+ CeedOccaFromChk (ierr);
46+ }
47+
48+ return operator_;
49+ }
4150
42- ierr = CeedOperatorGetData (op, (void **) &operator_); CeedOccaFromChk (ierr);
51+ Operator* Operator::from (CeedOperator op) {
52+ Operator *operator_ = getOperator (op);
53+ if (!operator_) {
54+ return NULL ;
55+ }
56+
57+ int ierr;
4358 ierr = CeedOperatorGetCeed (op, &operator_->ceed ); CeedOccaFromChk (ierr);
4459
4560 operator_->qfunction = QFunction::from (op);
@@ -154,7 +169,7 @@ namespace ceed {
154169 }
155170
156171 int Operator::ceedDestroy (CeedOperator op) {
157- delete Operator::from (op);
172+ delete getOperator (op, false );
158173 return CEED_ERROR_SUCCESS;
159174 }
160175 }
Original file line number Diff line number Diff line change @@ -46,6 +46,9 @@ namespace ceed {
4646 Operator ();
4747 virtual ~Operator ();
4848
49+ static Operator* getOperator (CeedOperator op,
50+ const bool assertValid = true );
51+
4952 static Operator* from (CeedOperator op);
5053
5154 bool isApplyingIdentityFunction ();
Original file line number Diff line number Diff line change @@ -30,17 +30,28 @@ namespace ceed {
3030 qFunctionName = source.substr (colonIndex + 1 );
3131 }
3232
33- QFunction* QFunction::from (CeedQFunction qf) {
33+ QFunction* QFunction::getQFunction (CeedQFunction qf,
34+ const bool assertValid) {
3435 if (!qf) {
3536 return NULL ;
3637 }
3738
3839 int ierr;
39- QFunction *qFunction;
40+ QFunction *qFunction = NULL ;
4041
4142 ierr = CeedQFunctionGetData (qf, &qFunction);
4243 CeedOccaFromChk (ierr);
4344
45+ return qFunction;
46+ }
47+
48+ QFunction* QFunction::from (CeedQFunction qf) {
49+ QFunction *qFunction = getQFunction (qf);
50+ if (!qFunction) {
51+ return NULL ;
52+ }
53+
54+ int ierr;
4455 ierr = CeedQFunctionGetCeed (qf, &qFunction->ceed );
4556 CeedOccaFromChk (ierr);
4657
@@ -252,7 +263,7 @@ namespace ceed {
252263 }
253264
254265 int QFunction::ceedDestroy (CeedQFunction qf) {
255- delete QFunction::from (qf);
266+ delete getQFunction (qf, false );
256267 return CEED_ERROR_SUCCESS;
257268 }
258269 }
Original file line number Diff line number Diff line change @@ -36,6 +36,9 @@ namespace ceed {
3636
3737 QFunction (const std::string &source);
3838
39+ static QFunction* getQFunction (CeedQFunction qf,
40+ const bool assertValid = true );
41+
3942 static QFunction* from (CeedQFunction qf);
4043 static QFunction* from (CeedOperator op);
4144
Original file line number Diff line number Diff line change @@ -29,16 +29,30 @@ namespace ceed {
2929 freeHostCtxBuffer ();
3030 }
3131
32- QFunctionContext* QFunctionContext::from (CeedQFunctionContext ctx) {
32+ QFunctionContext* QFunctionContext::getQFunctionContext (CeedQFunctionContext ctx,
33+ const bool assertValid) {
3334 if (!ctx) {
3435 return NULL ;
3536 }
3637
3738 int ierr;
38-
3939 QFunctionContext *ctx_ = NULL ;
40- ierr = CeedQFunctionContextGetBackendData (ctx, &ctx_); CeedOccaFromChk (ierr);
4140
41+ ierr = CeedQFunctionContextGetBackendData (ctx, &ctx_);
42+ if (assertValid) {
43+ CeedOccaFromChk (ierr);
44+ }
45+
46+ return ctx_;
47+ }
48+
49+ QFunctionContext* QFunctionContext::from (CeedQFunctionContext ctx) {
50+ QFunctionContext *ctx_ = getQFunctionContext (ctx);
51+ if (!ctx_) {
52+ return NULL ;
53+ }
54+
55+ int ierr;
4256 ierr = CeedQFunctionContextGetContextSize (ctx, &ctx_->ctxSize );
4357 CeedOccaFromChk (ierr);
4458
@@ -283,7 +297,7 @@ namespace ceed {
283297 }
284298
285299 int QFunctionContext::ceedDestroy (CeedQFunctionContext ctx) {
286- delete QFunctionContext::from (ctx);
300+ delete getQFunctionContext (ctx, false );
287301 return CEED_ERROR_SUCCESS;
288302 }
289303 }
Original file line number Diff line number Diff line change @@ -39,6 +39,9 @@ namespace ceed {
3939
4040 ~QFunctionContext ();
4141
42+ static QFunctionContext* getQFunctionContext (CeedQFunctionContext ctx,
43+ const bool assertValid = true );
44+
4245 static QFunctionContext* from (CeedQFunctionContext ctx);
4346
4447 ::occa::memory dataToMemory (const void *data) {
You can’t perform that action at this time.
0 commit comments