@@ -291,6 +291,60 @@ static int CeedBasisCreateProjectionMatrices(CeedBasis basis_from, CeedBasis bas
291291 return CEED_ERROR_SUCCESS ;
292292}
293293
294+ /**
295+ @brief Check input vector dimensions for CeedBasisApply[Add]
296+
297+ @param[in] basis `CeedBasis` to evaluate
298+ @param[in] num_elem The number of elements to apply the basis evaluation to;
299+ the backend will specify the ordering in @ref CeedElemRestrictionCreate()
300+ @param[in] t_mode @ref CEED_NOTRANSPOSE to evaluate from nodes to quadrature points;
301+ @ref CEED_TRANSPOSE to apply the transpose, mapping from quadrature points to nodes
302+ @param[in] eval_mode @ref CEED_EVAL_NONE to use values directly,
303+ @ref CEED_EVAL_INTERP to use interpolated values,
304+ @ref CEED_EVAL_GRAD to use gradients,
305+ @ref CEED_EVAL_DIV to use divergence,
306+ @ref CEED_EVAL_CURL to use curl,
307+ @ref CEED_EVAL_WEIGHT to use quadrature weights
308+ @param[in] u Input `CeedVector`
309+ @param[out] v Output `CeedVector`
310+
311+ @return An error code: 0 - success, otherwise - failure
312+
313+ @ref Developer
314+ **/
315+ static int CeedBasisApplyCheckDims (CeedBasis basis , CeedInt num_elem , CeedTransposeMode t_mode , CeedEvalMode eval_mode , CeedVector u , CeedVector v ) {
316+ CeedInt dim , num_comp , q_comp , num_nodes , num_qpts ;
317+ CeedSize u_length = 0 , v_length ;
318+
319+ CeedCall (CeedBasisGetDimension (basis , & dim ));
320+ CeedCall (CeedBasisGetNumComponents (basis , & num_comp ));
321+ CeedCall (CeedBasisGetNumQuadratureComponents (basis , eval_mode , & q_comp ));
322+ CeedCall (CeedBasisGetNumNodes (basis , & num_nodes ));
323+ CeedCall (CeedBasisGetNumQuadraturePoints (basis , & num_qpts ));
324+ CeedCall (CeedVectorGetLength (v , & v_length ));
325+ if (u ) CeedCall (CeedVectorGetLength (u , & u_length ));
326+
327+ // Check vector lengths to prevent out of bounds issues
328+ bool has_good_dims = true;
329+ switch (eval_mode ) {
330+ case CEED_EVAL_NONE :
331+ case CEED_EVAL_INTERP :
332+ case CEED_EVAL_GRAD :
333+ case CEED_EVAL_DIV :
334+ case CEED_EVAL_CURL :
335+ has_good_dims = ((t_mode == CEED_TRANSPOSE && u_length >= (CeedSize )num_elem * (CeedSize )num_comp * (CeedSize )num_qpts * (CeedSize )q_comp &&
336+ v_length >= (CeedSize )num_elem * (CeedSize )num_comp * (CeedSize )num_nodes ) ||
337+ (t_mode == CEED_NOTRANSPOSE && v_length >= (CeedSize )num_elem * (CeedSize )num_qpts * (CeedSize )num_comp * (CeedSize )q_comp &&
338+ u_length >= (CeedSize )num_elem * (CeedSize )num_comp * (CeedSize )num_nodes ));
339+ break ;
340+ case CEED_EVAL_WEIGHT :
341+ has_good_dims = v_length >= (CeedSize )num_elem * (CeedSize )num_qpts ;
342+ break ;
343+ }
344+ CeedCheck (has_good_dims , CeedBasisReturnCeed (basis ), CEED_ERROR_DIMENSION , "Input/output vectors too short for basis and evaluation mode" );
345+ return CEED_ERROR_SUCCESS ;
346+ }
347+
294348/**
295349 @brief Check input vector dimensions for CeedBasisApply[Add]AtPoints
296350
@@ -1866,60 +1920,6 @@ int CeedBasisView(CeedBasis basis, FILE *stream) {
18661920 return CEED_ERROR_SUCCESS ;
18671921}
18681922
1869- /**
1870- @brief Check input vector dimensions for CeedBasisApply[Add]
1871-
1872- @param[in] basis `CeedBasis` to evaluate
1873- @param[in] num_elem The number of elements to apply the basis evaluation to;
1874- the backend will specify the ordering in @ref CeedElemRestrictionCreate()
1875- @param[in] t_mode @ref CEED_NOTRANSPOSE to evaluate from nodes to quadrature points;
1876- @ref CEED_TRANSPOSE to apply the transpose, mapping from quadrature points to nodes
1877- @param[in] eval_mode @ref CEED_EVAL_NONE to use values directly,
1878- @ref CEED_EVAL_INTERP to use interpolated values,
1879- @ref CEED_EVAL_GRAD to use gradients,
1880- @ref CEED_EVAL_DIV to use divergence,
1881- @ref CEED_EVAL_CURL to use curl,
1882- @ref CEED_EVAL_WEIGHT to use quadrature weights
1883- @param[in] u Input `CeedVector`
1884- @param[out] v Output `CeedVector`
1885-
1886- @return An error code: 0 - success, otherwise - failure
1887-
1888- @ref Developer
1889- **/
1890- static int CeedBasisApplyCheckDims (CeedBasis basis , CeedInt num_elem , CeedTransposeMode t_mode , CeedEvalMode eval_mode , CeedVector u , CeedVector v ) {
1891- CeedInt dim , num_comp , q_comp , num_nodes , num_qpts ;
1892- CeedSize u_length = 0 , v_length ;
1893-
1894- CeedCall (CeedBasisGetDimension (basis , & dim ));
1895- CeedCall (CeedBasisGetNumComponents (basis , & num_comp ));
1896- CeedCall (CeedBasisGetNumQuadratureComponents (basis , eval_mode , & q_comp ));
1897- CeedCall (CeedBasisGetNumNodes (basis , & num_nodes ));
1898- CeedCall (CeedBasisGetNumQuadraturePoints (basis , & num_qpts ));
1899- CeedCall (CeedVectorGetLength (v , & v_length ));
1900- if (u ) CeedCall (CeedVectorGetLength (u , & u_length ));
1901-
1902- // Check vector lengths to prevent out of bounds issues
1903- bool has_good_dims = true;
1904- switch (eval_mode ) {
1905- case CEED_EVAL_NONE :
1906- case CEED_EVAL_INTERP :
1907- case CEED_EVAL_GRAD :
1908- case CEED_EVAL_DIV :
1909- case CEED_EVAL_CURL :
1910- has_good_dims = ((t_mode == CEED_TRANSPOSE && u_length >= (CeedSize )num_elem * (CeedSize )num_comp * (CeedSize )num_qpts * (CeedSize )q_comp &&
1911- v_length >= (CeedSize )num_elem * (CeedSize )num_comp * (CeedSize )num_nodes ) ||
1912- (t_mode == CEED_NOTRANSPOSE && v_length >= (CeedSize )num_elem * (CeedSize )num_qpts * (CeedSize )num_comp * (CeedSize )q_comp &&
1913- u_length >= (CeedSize )num_elem * (CeedSize )num_comp * (CeedSize )num_nodes ));
1914- break ;
1915- case CEED_EVAL_WEIGHT :
1916- has_good_dims = v_length >= (CeedSize )num_elem * (CeedSize )num_qpts ;
1917- break ;
1918- }
1919- CeedCheck (has_good_dims , CeedBasisReturnCeed (basis ), CEED_ERROR_DIMENSION , "Input/output vectors too short for basis and evaluation mode" );
1920- return CEED_ERROR_SUCCESS ;
1921- }
1922-
19231923/**
19241924 @brief Apply basis evaluation from nodes to quadrature points or vice versa
19251925
0 commit comments