| ceed-operator.c (b36f2af8eb4e779074f4d92faffbc034a6db4539) | ceed-operator.c (3668ca4b583f336c0c2dcc810e26e2ac50a514b8) |
|---|---|
| 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. --- 258 unchanged lines hidden (view full) --- 267/** 268 @brief Set QFunctionContext field value of the specified type. 269 For composite operators, the value is set in all 270 sub-operator QFunctionContexts that have a matching `field_name`. 271 A non-zero error code is returned for single operators 272 that do not have a matching field of the same type or composite 273 operators that do not have any field of a matching type. 274 | 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. --- 258 unchanged lines hidden (view full) --- 267/** 268 @brief Set QFunctionContext field value of the specified type. 269 For composite operators, the value is set in all 270 sub-operator QFunctionContexts that have a matching `field_name`. 271 A non-zero error code is returned for single operators 272 that do not have a matching field of the same type or composite 273 operators that do not have any field of a matching type. 274 |
| 275 @param op CeedOperator 276 @param field_name Name of field to set 277 @param field_type Type of field to set 278 @param value Value to set | 275 @param op CeedOperator 276 @param field_label Label of field to set 277 @param field_type Type of field to set 278 @param value Value to set |
| 279 280 @return An error code: 0 - success, otherwise - failure 281 282 @ref User 283**/ 284static int CeedOperatorContextSetGeneric(CeedOperator op, | 279 280 @return An error code: 0 - success, otherwise - failure 281 282 @ref User 283**/ 284static int CeedOperatorContextSetGeneric(CeedOperator op, |
| 285 const char *field_name, CeedContextFieldType field_type, void *value) { | 285 CeedContextFieldLabel field_label, CeedContextFieldType field_type, 286 void *value) { |
| 286 int ierr; | 287 int ierr; |
| 287 bool is_set = false, is_composite = false; | |
| 288 | 288 |
| 289 ierr = CeedOperatorIsComposite(op, &is_composite); CeedChk(ierr); | 289 if (!field_label) 290 // LCOV_EXCL_START 291 return CeedError(op->ceed, CEED_ERROR_UNSUPPORTED, 292 "Invalid field label"); 293 // LCOV_EXCL_STOP |
| 290 | 294 |
| 295 bool is_composite = false; 296 ierr = CeedOperatorIsComposite(op, &is_composite); CeedChk(ierr); |
|
| 291 if (is_composite) { 292 CeedInt num_sub; 293 CeedOperator *sub_operators; 294 295 ierr = CeedOperatorGetNumSub(op, &num_sub); CeedChk(ierr); 296 ierr = CeedOperatorGetSubList(op, &sub_operators); CeedChk(ierr); | 297 if (is_composite) { 298 CeedInt num_sub; 299 CeedOperator *sub_operators; 300 301 ierr = CeedOperatorGetNumSub(op, &num_sub); CeedChk(ierr); 302 ierr = CeedOperatorGetSubList(op, &sub_operators); CeedChk(ierr); |
| 303 if (num_sub != field_label->num_sub_labels) 304 // LCOV_EXCL_START 305 return CeedError(op->ceed, CEED_ERROR_UNSUPPORTED, 306 "ContextLabel does not correspond to composite operator.\n" 307 "Use CeedOperatorGetContextFieldLabel()."); 308 // LCOV_EXCL_STOP |
|
| 297 298 for (CeedInt i = 0; i < num_sub; i++) { 299 // Try every sub-operator, ok if some sub-operators do not have field | 309 310 for (CeedInt i = 0; i < num_sub; i++) { 311 // Try every sub-operator, ok if some sub-operators do not have field |
| 300 if (sub_operators[i]->qf->ctx) { 301 bool is_set_i = false; 302 ierr = CeedQFunctionContextSetGeneric(sub_operators[i]->qf->ctx, field_name, 303 field_type, &is_set_i, value); 304 CeedChk(ierr); 305 is_set = is_set || is_set_i; | 312 if (field_label->sub_labels[i] && sub_operators[i]->qf->ctx) { 313 ierr = CeedQFunctionContextSetGeneric(sub_operators[i]->qf->ctx, 314 field_label->sub_labels[i], 315 field_type, value); CeedChk(ierr); |
| 306 } 307 } 308 } else { 309 if (!op->qf->ctx) 310 // LCOV_EXCL_START 311 return CeedError(op->ceed, CEED_ERROR_UNSUPPORTED, 312 "QFunction does not have context data"); 313 // LCOV_EXCL_STOP 314 | 316 } 317 } 318 } else { 319 if (!op->qf->ctx) 320 // LCOV_EXCL_START 321 return CeedError(op->ceed, CEED_ERROR_UNSUPPORTED, 322 "QFunction does not have context data"); 323 // LCOV_EXCL_STOP 324 |
| 315 ierr = CeedQFunctionContextSetGeneric(op->qf->ctx, field_name, 316 field_type, &is_set, value); CeedChk(ierr); | 325 ierr = CeedQFunctionContextSetGeneric(op->qf->ctx, field_label, 326 field_type, value); CeedChk(ierr); |
| 317 } 318 | 327 } 328 |
| 319 if (!is_set) 320 // LCOV_EXCL_START 321 return CeedError(op->ceed, CEED_ERROR_UNSUPPORTED, 322 "QFunctionContext field with name \"%s\" not registered", 323 field_name); 324 // LCOV_EXCL_STOP 325 | |
| 326 return CEED_ERROR_SUCCESS; 327} 328 329/// @} 330 331/// ---------------------------------------------------------------------------- 332/// CeedOperator Backend API 333/// ---------------------------------------------------------------------------- --- 751 unchanged lines hidden (view full) --- 1085 "Not defined for composite operator"); 1086 // LCOV_EXCL_STOP 1087 1088 *num_qpts = op->num_qpts; 1089 return CEED_ERROR_SUCCESS; 1090} 1091 1092/** | 329 return CEED_ERROR_SUCCESS; 330} 331 332/// @} 333 334/// ---------------------------------------------------------------------------- 335/// CeedOperator Backend API 336/// ---------------------------------------------------------------------------- --- 751 unchanged lines hidden (view full) --- 1088 "Not defined for composite operator"); 1089 // LCOV_EXCL_STOP 1090 1091 *num_qpts = op->num_qpts; 1092 return CEED_ERROR_SUCCESS; 1093} 1094 1095/** |
| 1096 @brief Get label for a registered QFunctionContext field, or `NULL` if no 1097 field has been registered with this `field_name`. 1098 1099 @param[in] op CeedOperator 1100 @param[in] field_name Name of field to retrieve label 1101 @param[out] field_label Variable to field label 1102 1103 @return An error code: 0 - success, otherwise - failure 1104 1105 @ref User 1106**/ 1107int CeedOperatorContextGetFieldLabel(CeedOperator op, 1108 const char *field_name, 1109 CeedContextFieldLabel *field_label) { 1110 int ierr; 1111 1112 bool is_composite; 1113 ierr = CeedOperatorIsComposite(op, &is_composite); CeedChk(ierr); 1114 if (is_composite) { 1115 // Check if composite label already created 1116 for (CeedInt i=0; i<op->num_context_labels; i++) { 1117 if (!strcmp(op->context_labels[i]->name, field_name)) { 1118 *field_label = op->context_labels[i]; 1119 return CEED_ERROR_SUCCESS; 1120 } 1121 } 1122 1123 // Create composite label if needed 1124 CeedInt num_sub; 1125 CeedOperator *sub_operators; 1126 CeedContextFieldLabel new_field_label; 1127 1128 ierr = CeedCalloc(1, &new_field_label); CeedChk(ierr); 1129 ierr = CeedOperatorGetNumSub(op, &num_sub); CeedChk(ierr); 1130 ierr = CeedOperatorGetSubList(op, &sub_operators); CeedChk(ierr); 1131 ierr = CeedCalloc(num_sub, &new_field_label->sub_labels); CeedChk(ierr); 1132 new_field_label->num_sub_labels = num_sub; 1133 1134 bool label_found = false; 1135 for (CeedInt i=0; i<num_sub; i++) { 1136 if (sub_operators[i]->qf->ctx) { 1137 CeedContextFieldLabel new_field_label_i; 1138 ierr = CeedQFunctionContextGetFieldLabel(sub_operators[i]->qf->ctx, field_name, 1139 &new_field_label_i); CeedChk(ierr); 1140 if (new_field_label_i) { 1141 label_found = true; 1142 new_field_label->sub_labels[i] = new_field_label_i; 1143 new_field_label->name = new_field_label_i->name; 1144 new_field_label->description = new_field_label_i->description; 1145 } 1146 } 1147 } 1148 if (!label_found) { 1149 // LCOV_EXCL_START 1150 ierr = CeedFree(&new_field_label); CeedChk(ierr); 1151 *field_label = NULL; 1152 // LCOV_EXCL_STOP 1153 } else { 1154 // Move new composite label to operator 1155 if (op->num_context_labels == 0) { 1156 ierr = CeedCalloc(1, &op->context_labels); CeedChk(ierr); 1157 op->max_context_labels = 1; 1158 } else if (op->num_context_labels == op->max_context_labels) { 1159 ierr = CeedRealloc(2*op->num_context_labels, &op->context_labels); 1160 CeedChk(ierr); 1161 op->max_context_labels *= 2; 1162 } 1163 op->context_labels[op->num_context_labels] = new_field_label; 1164 *field_label = new_field_label; 1165 op->num_context_labels++; 1166 } 1167 1168 return CEED_ERROR_SUCCESS; 1169 } else { 1170 return CeedQFunctionContextGetFieldLabel(op->qf->ctx, field_name, field_label); 1171 } 1172} 1173 1174/** |
|
| 1093 @brief Set QFunctionContext field holding a double precision value. 1094 For composite operators, the value is set in all 1095 sub-operator QFunctionContexts that have a matching `field_name`. 1096 | 1175 @brief Set QFunctionContext field holding a double precision value. 1176 For composite operators, the value is set in all 1177 sub-operator QFunctionContexts that have a matching `field_name`. 1178 |
| 1097 @param op CeedOperator 1098 @param field_name Name of field to register 1099 @param value Value to set | 1179 @param op CeedOperator 1180 @param field_label Label of field to register 1181 @param value Value to set |
| 1100 1101 @return An error code: 0 - success, otherwise - failure 1102 1103 @ref User 1104**/ | 1182 1183 @return An error code: 0 - success, otherwise - failure 1184 1185 @ref User 1186**/ |
| 1105int CeedOperatorContextSetDouble(CeedOperator op, const char *field_name, | 1187int CeedOperatorContextSetDouble(CeedOperator op, 1188 CeedContextFieldLabel field_label, |
| 1106 double value) { | 1189 double value) { |
| 1107 return CeedOperatorContextSetGeneric(op, field_name, CEED_CONTEXT_FIELD_DOUBLE, | 1190 return CeedOperatorContextSetGeneric(op, field_label, CEED_CONTEXT_FIELD_DOUBLE, |
| 1108 &value); 1109} 1110 1111/** 1112 @brief Set QFunctionContext field holding an int32 value. 1113 For composite operators, the value is set in all 1114 sub-operator QFunctionContexts that have a matching `field_name`. 1115 | 1191 &value); 1192} 1193 1194/** 1195 @brief Set QFunctionContext field holding an int32 value. 1196 For composite operators, the value is set in all 1197 sub-operator QFunctionContexts that have a matching `field_name`. 1198 |
| 1116 @param op CeedOperator 1117 @param field_name Name of field to set 1118 @param value Value to set | 1199 @param op CeedOperator 1200 @param field_label Label of field to set 1201 @param value Value to set |
| 1119 1120 @return An error code: 0 - success, otherwise - failure 1121 1122 @ref User 1123**/ | 1202 1203 @return An error code: 0 - success, otherwise - failure 1204 1205 @ref User 1206**/ |
| 1124int CeedOperatorContextSetInt32(CeedOperator op, const char *field_name, | 1207int CeedOperatorContextSetInt32(CeedOperator op, 1208 CeedContextFieldLabel field_label, |
| 1125 int value) { | 1209 int value) { |
| 1126 return CeedOperatorContextSetGeneric(op, field_name, CEED_CONTEXT_FIELD_INT32, | 1210 return CeedOperatorContextSetGeneric(op, field_label, CEED_CONTEXT_FIELD_INT32, |
| 1127 &value); | 1211 &value); |
| 1128 return CEED_ERROR_SUCCESS; | |
| 1129} 1130 1131/** 1132 @brief Apply CeedOperator to a vector 1133 1134 This computes the action of the operator on the specified (active) input, 1135 yielding its (active) output. All inputs and outputs must be specified using 1136 CeedOperatorSetField(). --- 128 unchanged lines hidden (view full) --- 1265 int ierr; 1266 1267 if (!*op || --(*op)->ref_count > 0) return CEED_ERROR_SUCCESS; 1268 if ((*op)->Destroy) { 1269 ierr = (*op)->Destroy(*op); CeedChk(ierr); 1270 } 1271 ierr = CeedDestroy(&(*op)->ceed); CeedChk(ierr); 1272 // Free fields | 1212} 1213 1214/** 1215 @brief Apply CeedOperator to a vector 1216 1217 This computes the action of the operator on the specified (active) input, 1218 yielding its (active) output. All inputs and outputs must be specified using 1219 CeedOperatorSetField(). --- 128 unchanged lines hidden (view full) --- 1348 int ierr; 1349 1350 if (!*op || --(*op)->ref_count > 0) return CEED_ERROR_SUCCESS; 1351 if ((*op)->Destroy) { 1352 ierr = (*op)->Destroy(*op); CeedChk(ierr); 1353 } 1354 ierr = CeedDestroy(&(*op)->ceed); CeedChk(ierr); 1355 // Free fields |
| 1273 for (int i=0; i<(*op)->num_fields; i++) | 1356 for (CeedInt i=0; i<(*op)->num_fields; i++) |
| 1274 if ((*op)->input_fields[i]) { 1275 if ((*op)->input_fields[i]->elem_restr != CEED_ELEMRESTRICTION_NONE) { 1276 ierr = CeedElemRestrictionDestroy(&(*op)->input_fields[i]->elem_restr); 1277 CeedChk(ierr); 1278 } 1279 if ((*op)->input_fields[i]->basis != CEED_BASIS_COLLOCATED) { 1280 ierr = CeedBasisDestroy(&(*op)->input_fields[i]->basis); CeedChk(ierr); 1281 } 1282 if ((*op)->input_fields[i]->vec != CEED_VECTOR_ACTIVE && 1283 (*op)->input_fields[i]->vec != CEED_VECTOR_NONE ) { 1284 ierr = CeedVectorDestroy(&(*op)->input_fields[i]->vec); CeedChk(ierr); 1285 } 1286 ierr = CeedFree(&(*op)->input_fields[i]->field_name); CeedChk(ierr); 1287 ierr = CeedFree(&(*op)->input_fields[i]); CeedChk(ierr); 1288 } | 1357 if ((*op)->input_fields[i]) { 1358 if ((*op)->input_fields[i]->elem_restr != CEED_ELEMRESTRICTION_NONE) { 1359 ierr = CeedElemRestrictionDestroy(&(*op)->input_fields[i]->elem_restr); 1360 CeedChk(ierr); 1361 } 1362 if ((*op)->input_fields[i]->basis != CEED_BASIS_COLLOCATED) { 1363 ierr = CeedBasisDestroy(&(*op)->input_fields[i]->basis); CeedChk(ierr); 1364 } 1365 if ((*op)->input_fields[i]->vec != CEED_VECTOR_ACTIVE && 1366 (*op)->input_fields[i]->vec != CEED_VECTOR_NONE ) { 1367 ierr = CeedVectorDestroy(&(*op)->input_fields[i]->vec); CeedChk(ierr); 1368 } 1369 ierr = CeedFree(&(*op)->input_fields[i]->field_name); CeedChk(ierr); 1370 ierr = CeedFree(&(*op)->input_fields[i]); CeedChk(ierr); 1371 } |
| 1289 for (int i=0; i<(*op)->num_fields; i++) | 1372 for (CeedInt i=0; i<(*op)->num_fields; i++) |
| 1290 if ((*op)->output_fields[i]) { 1291 ierr = CeedElemRestrictionDestroy(&(*op)->output_fields[i]->elem_restr); 1292 CeedChk(ierr); 1293 if ((*op)->output_fields[i]->basis != CEED_BASIS_COLLOCATED) { 1294 ierr = CeedBasisDestroy(&(*op)->output_fields[i]->basis); CeedChk(ierr); 1295 } 1296 if ((*op)->output_fields[i]->vec != CEED_VECTOR_ACTIVE && 1297 (*op)->output_fields[i]->vec != CEED_VECTOR_NONE ) { 1298 ierr = CeedVectorDestroy(&(*op)->output_fields[i]->vec); CeedChk(ierr); 1299 } 1300 ierr = CeedFree(&(*op)->output_fields[i]->field_name); CeedChk(ierr); 1301 ierr = CeedFree(&(*op)->output_fields[i]); CeedChk(ierr); 1302 } 1303 // Destroy sub_operators | 1373 if ((*op)->output_fields[i]) { 1374 ierr = CeedElemRestrictionDestroy(&(*op)->output_fields[i]->elem_restr); 1375 CeedChk(ierr); 1376 if ((*op)->output_fields[i]->basis != CEED_BASIS_COLLOCATED) { 1377 ierr = CeedBasisDestroy(&(*op)->output_fields[i]->basis); CeedChk(ierr); 1378 } 1379 if ((*op)->output_fields[i]->vec != CEED_VECTOR_ACTIVE && 1380 (*op)->output_fields[i]->vec != CEED_VECTOR_NONE ) { 1381 ierr = CeedVectorDestroy(&(*op)->output_fields[i]->vec); CeedChk(ierr); 1382 } 1383 ierr = CeedFree(&(*op)->output_fields[i]->field_name); CeedChk(ierr); 1384 ierr = CeedFree(&(*op)->output_fields[i]); CeedChk(ierr); 1385 } 1386 // Destroy sub_operators |
| 1304 for (int i=0; i<(*op)->num_suboperators; i++) | 1387 for (CeedInt i=0; i<(*op)->num_suboperators; i++) |
| 1305 if ((*op)->sub_operators[i]) { 1306 ierr = CeedOperatorDestroy(&(*op)->sub_operators[i]); CeedChk(ierr); 1307 } 1308 ierr = CeedQFunctionDestroy(&(*op)->qf); CeedChk(ierr); 1309 ierr = CeedQFunctionDestroy(&(*op)->dqf); CeedChk(ierr); 1310 ierr = CeedQFunctionDestroy(&(*op)->dqfT); CeedChk(ierr); | 1388 if ((*op)->sub_operators[i]) { 1389 ierr = CeedOperatorDestroy(&(*op)->sub_operators[i]); CeedChk(ierr); 1390 } 1391 ierr = CeedQFunctionDestroy(&(*op)->qf); CeedChk(ierr); 1392 ierr = CeedQFunctionDestroy(&(*op)->dqf); CeedChk(ierr); 1393 ierr = CeedQFunctionDestroy(&(*op)->dqfT); CeedChk(ierr); |
| 1394 // Destroy any composite labels 1395 for (CeedInt i=0; i<(*op)->num_context_labels; i++) { 1396 ierr = CeedFree(&(*op)->context_labels[i]->sub_labels); CeedChk(ierr); 1397 ierr = CeedFree(&(*op)->context_labels[i]); CeedChk(ierr); 1398 } 1399 ierr = CeedFree(&(*op)->context_labels); CeedChk(ierr); |
|
| 1311 1312 // Destroy fallback 1313 if ((*op)->op_fallback) { 1314 ierr = (*op)->qf_fallback->Destroy((*op)->qf_fallback); CeedChk(ierr); 1315 ierr = CeedFree(&(*op)->qf_fallback); CeedChk(ierr); 1316 ierr = CeedVectorDestroy(&(*op)->op_fallback->qf_assembled); CeedChk(ierr); 1317 ierr = CeedElemRestrictionDestroy(&(*op)->op_fallback->qf_assembled_rstr); 1318 CeedChk(ierr); --- 16 unchanged lines hidden --- | 1400 1401 // Destroy fallback 1402 if ((*op)->op_fallback) { 1403 ierr = (*op)->qf_fallback->Destroy((*op)->qf_fallback); CeedChk(ierr); 1404 ierr = CeedFree(&(*op)->qf_fallback); CeedChk(ierr); 1405 ierr = CeedVectorDestroy(&(*op)->op_fallback->qf_assembled); CeedChk(ierr); 1406 ierr = CeedElemRestrictionDestroy(&(*op)->op_fallback->qf_assembled_rstr); 1407 CeedChk(ierr); --- 16 unchanged lines hidden --- |