Skip to content

Commit 15e1ad1

Browse files
authored
Merge pull request #1764 from CEED/zach/restriction-min-points
Add `CeedElemRestrictionGetMinPointsInElement` and `CeedElemRestrictionGetMinMaxPointsInElement`
2 parents 7d38c03 + 4ed2b27 commit 15e1ad1

File tree

4 files changed

+68
-11
lines changed

4 files changed

+68
-11
lines changed

include/ceed/ceed.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,8 @@ CEED_EXTERN int CeedElemRestrictionGetElementSize(CeedElemRestriction rstr, Cee
279279
CEED_EXTERN int CeedElemRestrictionGetNumPoints(CeedElemRestriction rstr, CeedInt *num_points);
280280
CEED_EXTERN int CeedElemRestrictionGetNumPointsInElement(CeedElemRestriction rstr, CeedInt elem, CeedInt *num_points);
281281
CEED_EXTERN int CeedElemRestrictionGetMaxPointsInElement(CeedElemRestriction rstr, CeedInt *max_points);
282+
CEED_EXTERN int CeedElemRestrictionGetMinPointsInElement(CeedElemRestriction rstr, CeedInt *min_points);
283+
CEED_EXTERN int CeedElemRestrictionGetMinMaxPointsInElement(CeedElemRestriction rstr, CeedInt *min_points, CeedInt *max_points);
282284
CEED_EXTERN int CeedElemRestrictionGetLVectorSize(CeedElemRestriction rstr, CeedSize *l_size);
283285
CEED_EXTERN int CeedElemRestrictionGetEVectorSize(CeedElemRestriction rstr, CeedSize *e_size);
284286
CEED_EXTERN int CeedElemRestrictionGetNumComponents(CeedElemRestriction rstr, CeedInt *num_comp);

interface/ceed-elemrestriction.c

Lines changed: 52 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1548,34 +1548,77 @@ int CeedElemRestrictionGetNumPointsInElement(CeedElemRestriction rstr, CeedInt e
15481548
}
15491549

15501550
/**
1551-
@brief Get the maximum number of points in an element for a `CeedElemRestriction` at points
1551+
@brief Get the minimum and/or maximum number of points in an element for a `CeedElemRestriction` at points
15521552
15531553
@param[in] rstr `CeedElemRestriction`
1554-
@param[out] max_points Variable to store size of elements
1554+
@param[out] min_points Variable to minimum number of points in an element, or `NULL`
1555+
@param[out] max_points Variable to maximum number of points in an element, or `NULL`
15551556
15561557
@return An error code: 0 - success, otherwise - failure
15571558
15581559
@ref Advanced
15591560
**/
1560-
int CeedElemRestrictionGetMaxPointsInElement(CeedElemRestriction rstr, CeedInt *max_points) {
1561-
CeedInt num_elem;
1561+
int CeedElemRestrictionGetMinMaxPointsInElement(CeedElemRestriction rstr, CeedInt *min_points, CeedInt *max_points) {
1562+
CeedInt num_elem, num_points;
15621563
CeedRestrictionType rstr_type;
15631564

15641565
CeedCall(CeedElemRestrictionGetType(rstr, &rstr_type));
15651566
CeedCheck(rstr_type == CEED_RESTRICTION_POINTS, CeedElemRestrictionReturnCeed(rstr), CEED_ERROR_INCOMPATIBLE,
1566-
"Cannot compute max points for a CeedElemRestriction that does not use points");
1567+
"Cannot compute min/max points for a CeedElemRestriction that does not use points");
15671568

15681569
CeedCall(CeedElemRestrictionGetNumElements(rstr, &num_elem));
1569-
*max_points = 0;
1570-
for (CeedInt e = 0; e < num_elem; e++) {
1571-
CeedInt num_points;
15721570

1571+
// Exit early if there are no elements
1572+
if (num_elem == 0) {
1573+
if (min_points) *min_points = 0;
1574+
if (max_points) *max_points = 0;
1575+
return CEED_ERROR_SUCCESS;
1576+
}
1577+
1578+
// Initialize to the number of points in the first element
1579+
CeedCall(CeedElemRestrictionGetNumPointsInElement(rstr, 0, &num_points));
1580+
if (min_points) *min_points = num_points;
1581+
if (max_points) *max_points = num_points;
1582+
for (CeedInt e = 1; e < num_elem; e++) {
15731583
CeedCall(CeedElemRestrictionGetNumPointsInElement(rstr, e, &num_points));
1574-
*max_points = CeedIntMax(num_points, *max_points);
1584+
if (min_points) *min_points = CeedIntMin(num_points, *min_points);
1585+
if (max_points) *max_points = CeedIntMax(num_points, *max_points);
15751586
}
15761587
return CEED_ERROR_SUCCESS;
15771588
}
15781589

1590+
/**
1591+
@brief Get the maximum number of points in an element for a `CeedElemRestriction` at points
1592+
1593+
@param[in] rstr `CeedElemRestriction`
1594+
@param[out] max_points Variable to store maximum number of points in an element
1595+
1596+
@return An error code: 0 - success, otherwise - failure
1597+
1598+
@ref User
1599+
1600+
@see CeedElemRestrictionGetMinMaxPointsInElement()
1601+
**/
1602+
int CeedElemRestrictionGetMaxPointsInElement(CeedElemRestriction rstr, CeedInt *max_points) {
1603+
return CeedElemRestrictionGetMinMaxPointsInElement(rstr, NULL, max_points);
1604+
}
1605+
1606+
/**
1607+
@brief Get the minimum number of points in an element for a `CeedElemRestriction` at points
1608+
1609+
@param[in] rstr `CeedElemRestriction`
1610+
@param[out] min_points Variable to store minimum number of points in an element
1611+
1612+
@return An error code: 0 - success, otherwise - failure
1613+
1614+
@ref User
1615+
1616+
@see CeedElemRestrictionGetMinMaxPointsInElement()
1617+
**/
1618+
int CeedElemRestrictionGetMinPointsInElement(CeedElemRestriction rstr, CeedInt *min_points) {
1619+
return CeedElemRestrictionGetMinMaxPointsInElement(rstr, min_points, NULL);
1620+
}
1621+
15791622
/**
15801623
@brief Get the size of the l-vector for a `CeedElemRestriction`
15811624

tests/t233-elemrestriction.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,15 @@ int main(int argc, char **argv) {
4848
}
4949

5050
{
51-
CeedInt max_points;
51+
CeedInt min_points, max_points;
5252

53+
CeedElemRestrictionGetMinPointsInElement(elem_restriction, &min_points);
5354
CeedElemRestrictionGetMaxPointsInElement(elem_restriction, &max_points);
55+
if (min_points != 1 || max_points != num_elem) {
56+
// LCOV_EXCL_START
57+
printf("Error in min/max points: min %" CeedInt_FMT " max %" CeedInt_FMT "\n", min_points, max_points);
58+
// LCOV_EXCL_STOP
59+
}
5460
CeedVectorCreate(ceed, max_points, &y);
5561
}
5662

tests/t234-elemrestriction.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,15 @@ int main(int argc, char **argv) {
3535
CeedElemRestrictionCreateVector(elem_restriction, &x, NULL);
3636
CeedVectorSetValue(x, 0.0);
3737
{
38-
CeedInt max_points;
38+
CeedInt min_points, max_points;
3939

40+
CeedElemRestrictionGetMinPointsInElement(elem_restriction, &min_points);
4041
CeedElemRestrictionGetMaxPointsInElement(elem_restriction, &max_points);
42+
if (min_points != 1 || max_points != num_elem) {
43+
// LCOV_EXCL_START
44+
printf("Error in min/max points: min %" CeedInt_FMT " max %" CeedInt_FMT "\n", min_points, max_points);
45+
// LCOV_EXCL_STOP
46+
}
4147
CeedVectorCreate(ceed, max_points, &y);
4248
CeedVectorSetValue(y, 1.0);
4349
}

0 commit comments

Comments
 (0)