15aed82e4SJeremy L Thompson // Copyright (c) 2017-2024, Lawrence Livermore National Security, LLC and other CEED contributors. 23d8e8822SJeremy L Thompson // All Rights Reserved. See the top-level LICENSE and NOTICE files for details. 3d7b241e6Sjeremylt // 43d8e8822SJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause 5d7b241e6Sjeremylt // 63d8e8822SJeremy L Thompson // This file is part of CEED: http://github.com/ceed 7d7b241e6Sjeremylt 83d576824SJeremy L Thompson #include <ceed-impl.h> 949aac155SJeremy L Thompson #include <ceed.h> 102b730f8bSJeremy L Thompson #include <ceed/backend.h> 113d576824SJeremy L Thompson #include <stdbool.h> 123d576824SJeremy L Thompson #include <stdio.h> 13c17ec2beSJeremy L Thompson #include <string.h> 14d7b241e6Sjeremylt 157a982d89SJeremy L. Thompson /// @file 167a982d89SJeremy L. Thompson /// Implementation of CeedElemRestriction interfaces 177a982d89SJeremy L. Thompson 187a982d89SJeremy L. Thompson /// ---------------------------------------------------------------------------- 197a982d89SJeremy L. Thompson /// CeedElemRestriction Library Internal Functions 207a982d89SJeremy L. Thompson /// ---------------------------------------------------------------------------- 217a982d89SJeremy L. Thompson /// @addtogroup CeedElemRestrictionDeveloper 227a982d89SJeremy L. Thompson /// @{ 237a982d89SJeremy L. Thompson 247a982d89SJeremy L. Thompson /** 25ca94c3ddSJeremy L Thompson @brief Permute and pad offsets for a blocked `CeedElemRestriction` 267a982d89SJeremy L. Thompson 27ca94c3ddSJeremy L Thompson @param[in] offsets Array of shape `[num_elem, elem_size]` 28ca94c3ddSJeremy L Thompson @param[out] block_offsets Array of permuted and padded array values of shape `[num_block, elem_size, block_size]` 29e7f679fcSJeremy L Thompson @param[in] num_block Number of blocks 30ea61e9acSJeremy L Thompson @param[in] num_elem Number of elements 31e7f679fcSJeremy L Thompson @param[in] block_size Number of elements in a block 32ea61e9acSJeremy L Thompson @param[in] elem_size Size of each element 337a982d89SJeremy L. Thompson 347a982d89SJeremy L. Thompson @return An error code: 0 - success, otherwise - failure 357a982d89SJeremy L. Thompson 367a982d89SJeremy L. Thompson @ref Utility 377a982d89SJeremy L. Thompson **/ 38e7f679fcSJeremy L Thompson int CeedPermutePadOffsets(const CeedInt *offsets, CeedInt *block_offsets, CeedInt num_block, CeedInt num_elem, CeedInt block_size, 39e7f679fcSJeremy L Thompson CeedInt elem_size) { 40e7f679fcSJeremy L Thompson for (CeedInt e = 0; e < num_block * block_size; e += block_size) { 41e7f679fcSJeremy L Thompson for (CeedInt j = 0; j < block_size; j++) { 422b730f8bSJeremy L Thompson for (CeedInt k = 0; k < elem_size; k++) { 43e7f679fcSJeremy L Thompson block_offsets[e * elem_size + k * block_size + j] = offsets[CeedIntMin(e + j, num_elem - 1) * elem_size + k]; 442b730f8bSJeremy L Thompson } 452b730f8bSJeremy L Thompson } 462b730f8bSJeremy L Thompson } 47e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 487a982d89SJeremy L. Thompson } 497a982d89SJeremy L. Thompson 5077d1c127SSebastian Grimberg /** 51ca94c3ddSJeremy L Thompson @brief Permute and pad orientations for a blocked `CeedElemRestriction` 5277d1c127SSebastian Grimberg 53ca94c3ddSJeremy L Thompson @param[in] orients Array of shape `[num_elem, elem_size]` 54ca94c3ddSJeremy L Thompson @param[out] block_orients Array of permuted and padded array values of shape `[num_block, elem_size, block_size]` 55e7f679fcSJeremy L Thompson @param[in] num_block Number of blocks 5677d1c127SSebastian Grimberg @param[in] num_elem Number of elements 57e7f679fcSJeremy L Thompson @param[in] block_size Number of elements in a block 5877d1c127SSebastian Grimberg @param[in] elem_size Size of each element 5977d1c127SSebastian Grimberg 6077d1c127SSebastian Grimberg @return An error code: 0 - success, otherwise - failure 6177d1c127SSebastian Grimberg 6277d1c127SSebastian Grimberg @ref Utility 6377d1c127SSebastian Grimberg **/ 64e7f679fcSJeremy L Thompson int CeedPermutePadOrients(const bool *orients, bool *block_orients, CeedInt num_block, CeedInt num_elem, CeedInt block_size, CeedInt elem_size) { 65e7f679fcSJeremy L Thompson for (CeedInt e = 0; e < num_block * block_size; e += block_size) { 66e7f679fcSJeremy L Thompson for (CeedInt j = 0; j < block_size; j++) { 6777d1c127SSebastian Grimberg for (CeedInt k = 0; k < elem_size; k++) { 68e7f679fcSJeremy L Thompson block_orients[e * elem_size + k * block_size + j] = orients[CeedIntMin(e + j, num_elem - 1) * elem_size + k]; 6977d1c127SSebastian Grimberg } 7077d1c127SSebastian Grimberg } 7177d1c127SSebastian Grimberg } 7277d1c127SSebastian Grimberg return CEED_ERROR_SUCCESS; 7377d1c127SSebastian Grimberg } 7477d1c127SSebastian Grimberg 750c73c039SSebastian Grimberg /** 76ca94c3ddSJeremy L Thompson @brief Permute and pad curl-conforming orientations for a blocked `CeedElemRestriction` 770c73c039SSebastian Grimberg 785c7e0f51SSebastian Grimberg @param[in] curl_orients Array of shape `[num_elem, elem_size]` 79ca94c3ddSJeremy L Thompson @param[out] block_curl_orients Array of permuted and padded array values of shape `[num_block, elem_size, block_size]` 80e7f679fcSJeremy L Thompson @param[in] num_block Number of blocks 810c73c039SSebastian Grimberg @param[in] num_elem Number of elements 82e7f679fcSJeremy L Thompson @param[in] block_size Number of elements in a block 830c73c039SSebastian Grimberg @param[in] elem_size Size of each element 840c73c039SSebastian Grimberg 850c73c039SSebastian Grimberg @return An error code: 0 - success, otherwise - failure 860c73c039SSebastian Grimberg 870c73c039SSebastian Grimberg @ref Utility 880c73c039SSebastian Grimberg **/ 89e7f679fcSJeremy L Thompson int CeedPermutePadCurlOrients(const CeedInt8 *curl_orients, CeedInt8 *block_curl_orients, CeedInt num_block, CeedInt num_elem, CeedInt block_size, 900c73c039SSebastian Grimberg CeedInt elem_size) { 91e7f679fcSJeremy L Thompson for (CeedInt e = 0; e < num_block * block_size; e += block_size) { 92e7f679fcSJeremy L Thompson for (CeedInt j = 0; j < block_size; j++) { 930c73c039SSebastian Grimberg for (CeedInt k = 0; k < elem_size; k++) { 94e7f679fcSJeremy L Thompson block_curl_orients[e * elem_size + k * block_size + j] = curl_orients[CeedIntMin(e + j, num_elem - 1) * elem_size + k]; 950c73c039SSebastian Grimberg } 960c73c039SSebastian Grimberg } 970c73c039SSebastian Grimberg } 980c73c039SSebastian Grimberg return CEED_ERROR_SUCCESS; 990c73c039SSebastian Grimberg } 1000c73c039SSebastian Grimberg 1017a982d89SJeremy L. Thompson /// @} 1027a982d89SJeremy L. Thompson 1037a982d89SJeremy L. Thompson /// ---------------------------------------------------------------------------- 1047a982d89SJeremy L. Thompson /// CeedElemRestriction Backend API 1057a982d89SJeremy L. Thompson /// ---------------------------------------------------------------------------- 1067a982d89SJeremy L. Thompson /// @addtogroup CeedElemRestrictionBackend 1077a982d89SJeremy L. Thompson /// @{ 1087a982d89SJeremy L. Thompson 1097a982d89SJeremy L. Thompson /** 110ca94c3ddSJeremy L Thompson @brief Get the type of a `CeedElemRestriction` 111a681ae63Sjeremylt 112ca94c3ddSJeremy L Thompson @param[in] rstr `CeedElemRestriction` 113fcbe8c06SSebastian Grimberg @param[out] rstr_type Variable to store restriction type 114fcbe8c06SSebastian Grimberg 115fcbe8c06SSebastian Grimberg @return An error code: 0 - success, otherwise - failure 116fcbe8c06SSebastian Grimberg 117fcbe8c06SSebastian Grimberg @ref Backend 118fcbe8c06SSebastian Grimberg **/ 119fcbe8c06SSebastian Grimberg int CeedElemRestrictionGetType(CeedElemRestriction rstr, CeedRestrictionType *rstr_type) { 120fcbe8c06SSebastian Grimberg *rstr_type = rstr->rstr_type; 121fcbe8c06SSebastian Grimberg return CEED_ERROR_SUCCESS; 122fcbe8c06SSebastian Grimberg } 123fcbe8c06SSebastian Grimberg 124fcbe8c06SSebastian Grimberg /** 125ca94c3ddSJeremy L Thompson @brief Get the strided status of a `CeedElemRestriction` 126fcbe8c06SSebastian Grimberg 127ca94c3ddSJeremy L Thompson @param[in] rstr `CeedElemRestriction` 128ca94c3ddSJeremy L Thompson @param[out] is_strided Variable to store strided status 129ca94c3ddSJeremy L Thompson 130ca94c3ddSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 131ca94c3ddSJeremy L Thompson 132ca94c3ddSJeremy L Thompson @ref Backend 133fcbe8c06SSebastian Grimberg **/ 134fcbe8c06SSebastian Grimberg int CeedElemRestrictionIsStrided(CeedElemRestriction rstr, bool *is_strided) { 135fcbe8c06SSebastian Grimberg *is_strided = (rstr->rstr_type == CEED_RESTRICTION_STRIDED); 136fcbe8c06SSebastian Grimberg return CEED_ERROR_SUCCESS; 137fcbe8c06SSebastian Grimberg } 138fcbe8c06SSebastian Grimberg 139fcbe8c06SSebastian Grimberg /** 140ca94c3ddSJeremy L Thompson @brief Get the points status of a `CeedElemRestriction` 1413ac8f562SJeremy L Thompson 142ca94c3ddSJeremy L Thompson @param[in] rstr `CeedElemRestriction` 143ca94c3ddSJeremy L Thompson @param[out] is_points Variable to store points status 144ca94c3ddSJeremy L Thompson 145ca94c3ddSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 146ca94c3ddSJeremy L Thompson 147ca94c3ddSJeremy L Thompson @ref Backend 1483ac8f562SJeremy L Thompson **/ 149637baffdSJeremy L Thompson int CeedElemRestrictionIsAtPoints(CeedElemRestriction rstr, bool *is_points) { 1503ac8f562SJeremy L Thompson *is_points = (rstr->rstr_type == CEED_RESTRICTION_POINTS); 1513ac8f562SJeremy L Thompson return CEED_ERROR_SUCCESS; 1523ac8f562SJeremy L Thompson } 1533ac8f562SJeremy L Thompson 1543ac8f562SJeremy L Thompson /** 155ca94c3ddSJeremy L Thompson @brief Check if two `CeedElemRestriction` created with @ref CeedElemRestrictionCreateAtPoints() and use the same points per element 15648acf710SJeremy L Thompson 157ca94c3ddSJeremy L Thompson @param[in] rstr_a First `CeedElemRestriction` 158ca94c3ddSJeremy L Thompson @param[in] rstr_b Second `CeedElemRestriction` 15948acf710SJeremy L Thompson @param[out] are_compatible Variable to store compatibility status 160ca94c3ddSJeremy L Thompson 161ca94c3ddSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 162ca94c3ddSJeremy L Thompson 163ca94c3ddSJeremy L Thompson @ref Backend 16448acf710SJeremy L Thompson **/ 16548acf710SJeremy L Thompson int CeedElemRestrictionAtPointsAreCompatible(CeedElemRestriction rstr_a, CeedElemRestriction rstr_b, bool *are_compatible) { 16648acf710SJeremy L Thompson CeedInt num_elem_a, num_elem_b, num_points_a, num_points_b; 1671203703bSJeremy L Thompson Ceed ceed; 1681203703bSJeremy L Thompson 1691203703bSJeremy L Thompson CeedCall(CeedElemRestrictionGetCeed(rstr_a, &ceed)); 17048acf710SJeremy L Thompson 17148acf710SJeremy L Thompson // Cannot compare non-points restrictions 1721203703bSJeremy L Thompson CeedCheck(rstr_a->rstr_type == CEED_RESTRICTION_POINTS, ceed, CEED_ERROR_UNSUPPORTED, "First CeedElemRestriction must be AtPoints"); 1731203703bSJeremy L Thompson CeedCheck(rstr_b->rstr_type == CEED_RESTRICTION_POINTS, ceed, CEED_ERROR_UNSUPPORTED, "Second CeedElemRestriction must be AtPoints"); 17448acf710SJeremy L Thompson 17548acf710SJeremy L Thompson CeedCall(CeedElemRestrictionGetNumElements(rstr_a, &num_elem_a)); 17648acf710SJeremy L Thompson CeedCall(CeedElemRestrictionGetNumElements(rstr_b, &num_elem_b)); 17748acf710SJeremy L Thompson CeedCall(CeedElemRestrictionGetNumPoints(rstr_a, &num_points_a)); 17848acf710SJeremy L Thompson CeedCall(CeedElemRestrictionGetNumPoints(rstr_b, &num_points_b)); 17948acf710SJeremy L Thompson 18048acf710SJeremy L Thompson // Check size and contents of offsets arrays 18148acf710SJeremy L Thompson *are_compatible = true; 18248acf710SJeremy L Thompson if (num_elem_a != num_elem_b) *are_compatible = false; 18348acf710SJeremy L Thompson if (num_points_a != num_points_b) *are_compatible = false; 18448acf710SJeremy L Thompson if (*are_compatible) { 18548acf710SJeremy L Thompson const CeedInt *offsets_a, *offsets_b; 18648acf710SJeremy L Thompson 18748acf710SJeremy L Thompson CeedCall(CeedElemRestrictionGetOffsets(rstr_a, CEED_MEM_HOST, &offsets_a)); 18848acf710SJeremy L Thompson CeedCall(CeedElemRestrictionGetOffsets(rstr_b, CEED_MEM_HOST, &offsets_b)); 18948acf710SJeremy L Thompson for (CeedInt i = 0; i < num_elem_a + 1 + num_points_a; i++) *are_compatible &= offsets_a[i] == offsets_b[i]; 19048acf710SJeremy L Thompson CeedCall(CeedElemRestrictionRestoreOffsets(rstr_a, &offsets_a)); 19148acf710SJeremy L Thompson CeedCall(CeedElemRestrictionRestoreOffsets(rstr_b, &offsets_b)); 19248acf710SJeremy L Thompson } 19348acf710SJeremy L Thompson return CEED_ERROR_SUCCESS; 19448acf710SJeremy L Thompson } 19548acf710SJeremy L Thompson 19648acf710SJeremy L Thompson /** 197ca94c3ddSJeremy L Thompson @brief Get the strides of a strided `CeedElemRestriction` 1987a982d89SJeremy L. Thompson 199ca94c3ddSJeremy L Thompson @param[in] rstr `CeedElemRestriction` 200a681ae63Sjeremylt @param[out] strides Variable to store strides array 2017a982d89SJeremy L. Thompson 2027a982d89SJeremy L. Thompson @return An error code: 0 - success, otherwise - failure 2037a982d89SJeremy L. Thompson 2047a982d89SJeremy L. Thompson @ref Backend 2057a982d89SJeremy L. Thompson **/ 20656c48462SJeremy L Thompson int CeedElemRestrictionGetStrides(CeedElemRestriction rstr, CeedInt strides[3]) { 2076e536b99SJeremy L Thompson CeedCheck(rstr->strides, CeedElemRestrictionReturnCeed(rstr), CEED_ERROR_MINOR, "CeedElemRestriction has no stride data"); 20856c48462SJeremy L Thompson for (CeedInt i = 0; i < 3; i++) strides[i] = rstr->strides[i]; 209e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 2107a982d89SJeremy L. Thompson } 2117a982d89SJeremy L. Thompson 2127a982d89SJeremy L. Thompson /** 213ca94c3ddSJeremy L Thompson @brief Get the backend stride status of a `CeedElemRestriction` 21477d1c127SSebastian Grimberg 215ca94c3ddSJeremy L Thompson @param[in] rstr `CeedElemRestriction` 21677d1c127SSebastian Grimberg @param[out] has_backend_strides Variable to store stride status 21777d1c127SSebastian Grimberg 21877d1c127SSebastian Grimberg @return An error code: 0 - success, otherwise - failure 21977d1c127SSebastian Grimberg 22077d1c127SSebastian Grimberg @ref Backend 22177d1c127SSebastian Grimberg **/ 22277d1c127SSebastian Grimberg int CeedElemRestrictionHasBackendStrides(CeedElemRestriction rstr, bool *has_backend_strides) { 2236e536b99SJeremy L Thompson CeedCheck(rstr->strides, CeedElemRestrictionReturnCeed(rstr), CEED_ERROR_MINOR, "CeedElemRestriction has no stride data"); 22477d1c127SSebastian Grimberg *has_backend_strides = ((rstr->strides[0] == CEED_STRIDES_BACKEND[0]) && (rstr->strides[1] == CEED_STRIDES_BACKEND[1]) && 22577d1c127SSebastian Grimberg (rstr->strides[2] == CEED_STRIDES_BACKEND[2])); 22677d1c127SSebastian Grimberg return CEED_ERROR_SUCCESS; 22777d1c127SSebastian Grimberg } 22877d1c127SSebastian Grimberg 22977d1c127SSebastian Grimberg /** 230ca94c3ddSJeremy L Thompson @brief Get read-only access to a `CeedElemRestriction` offsets array by @ref CeedMemType 231bd33150aSjeremylt 232ca94c3ddSJeremy L Thompson @param[in] rstr `CeedElemRestriction` to retrieve offsets 233fcbe8c06SSebastian Grimberg @param[in] mem_type Memory type on which to access the array. 234fcbe8c06SSebastian Grimberg If the backend uses a different memory type, this will perform a copy (possibly cached). 235ca94c3ddSJeremy L Thompson @param[out] offsets Array on memory type `mem_type` 236bd33150aSjeremylt 237bd33150aSjeremylt @return An error code: 0 - success, otherwise - failure 238bd33150aSjeremylt 239bd33150aSjeremylt @ref User 240bd33150aSjeremylt **/ 2412b730f8bSJeremy L Thompson int CeedElemRestrictionGetOffsets(CeedElemRestriction rstr, CeedMemType mem_type, const CeedInt **offsets) { 2427c1dbaffSSebastian Grimberg if (rstr->rstr_base) { 2437c1dbaffSSebastian Grimberg CeedCall(CeedElemRestrictionGetOffsets(rstr->rstr_base, mem_type, offsets)); 244c17ec2beSJeremy L Thompson } else { 2456e536b99SJeremy L Thompson CeedCheck(rstr->GetOffsets, CeedElemRestrictionReturnCeed(rstr), CEED_ERROR_UNSUPPORTED, 2461ef3a2a9SJeremy L Thompson "Backend does not implement CeedElemRestrictionGetOffsets"); 2472b730f8bSJeremy L Thompson CeedCall(rstr->GetOffsets(rstr, mem_type, offsets)); 248d1d35e2fSjeremylt rstr->num_readers++; 249c17ec2beSJeremy L Thompson } 250e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 251430758c8SJeremy L Thompson } 252430758c8SJeremy L Thompson 253430758c8SJeremy L Thompson /** 254ca94c3ddSJeremy L Thompson @brief Restore an offsets array obtained using @ref CeedElemRestrictionGetOffsets() 255430758c8SJeremy L Thompson 256ca94c3ddSJeremy L Thompson @param[in] rstr `CeedElemRestriction` to restore 257ea61e9acSJeremy L Thompson @param[in] offsets Array of offset data 258430758c8SJeremy L Thompson 259430758c8SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 260430758c8SJeremy L Thompson 261430758c8SJeremy L Thompson @ref User 262430758c8SJeremy L Thompson **/ 2632b730f8bSJeremy L Thompson int CeedElemRestrictionRestoreOffsets(CeedElemRestriction rstr, const CeedInt **offsets) { 2647c1dbaffSSebastian Grimberg if (rstr->rstr_base) { 2657c1dbaffSSebastian Grimberg CeedCall(CeedElemRestrictionRestoreOffsets(rstr->rstr_base, offsets)); 266c17ec2beSJeremy L Thompson } else { 267430758c8SJeremy L Thompson *offsets = NULL; 268d1d35e2fSjeremylt rstr->num_readers--; 269c17ec2beSJeremy L Thompson } 270e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 271bd33150aSjeremylt } 272bd33150aSjeremylt 273bd33150aSjeremylt /** 274ca94c3ddSJeremy L Thompson @brief Get read-only access to a `CeedElemRestriction` orientations array by @ref CeedMemType 2753ac43b2cSJeremy L Thompson 276ca94c3ddSJeremy L Thompson @param[in] rstr `CeedElemRestriction` to retrieve orientations 277fcbe8c06SSebastian Grimberg @param[in] mem_type Memory type on which to access the array. 278fcbe8c06SSebastian Grimberg If the backend uses a different memory type, this will perform a copy (possibly cached). 279ca94c3ddSJeremy L Thompson @param[out] orients Array on memory type `mem_type` 2803ac43b2cSJeremy L Thompson 2813ac43b2cSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 2823ac43b2cSJeremy L Thompson 28377d1c127SSebastian Grimberg @ref User 2843ac43b2cSJeremy L Thompson **/ 28577d1c127SSebastian Grimberg int CeedElemRestrictionGetOrientations(CeedElemRestriction rstr, CeedMemType mem_type, const bool **orients) { 2866e536b99SJeremy L Thompson CeedCheck(rstr->GetOrientations, CeedElemRestrictionReturnCeed(rstr), CEED_ERROR_UNSUPPORTED, 2871ef3a2a9SJeremy L Thompson "Backend does not implement CeedElemRestrictionGetOrientations"); 28877d1c127SSebastian Grimberg CeedCall(rstr->GetOrientations(rstr, mem_type, orients)); 28977d1c127SSebastian Grimberg rstr->num_readers++; 290e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 2913ac43b2cSJeremy L Thompson } 2923ac43b2cSJeremy L Thompson 2933ac43b2cSJeremy L Thompson /** 294ca94c3ddSJeremy L Thompson @brief Restore an orientations array obtained using @ref CeedElemRestrictionGetOrientations() 295b435c5a6Srezgarshakeri 296ca94c3ddSJeremy L Thompson @param[in] rstr `CeedElemRestriction` to restore 29777d1c127SSebastian Grimberg @param[in] orients Array of orientation data 298b435c5a6Srezgarshakeri 299b435c5a6Srezgarshakeri @return An error code: 0 - success, otherwise - failure 300b435c5a6Srezgarshakeri 30177d1c127SSebastian Grimberg @ref User 302b435c5a6Srezgarshakeri **/ 30377d1c127SSebastian Grimberg int CeedElemRestrictionRestoreOrientations(CeedElemRestriction rstr, const bool **orients) { 30477d1c127SSebastian Grimberg *orients = NULL; 30577d1c127SSebastian Grimberg rstr->num_readers--; 306b435c5a6Srezgarshakeri return CEED_ERROR_SUCCESS; 307b435c5a6Srezgarshakeri } 308b435c5a6Srezgarshakeri 309b435c5a6Srezgarshakeri /** 310ca94c3ddSJeremy L Thompson @brief Get read-only access to a `CeedElemRestriction` curl-conforming orientations array by @ref CeedMemType 3117a982d89SJeremy L. Thompson 312ca94c3ddSJeremy L Thompson @param[in] rstr `CeedElemRestriction` to retrieve curl-conforming orientations 313fcbe8c06SSebastian Grimberg @param[in] mem_type Memory type on which to access the array. 314fcbe8c06SSebastian Grimberg If the backend uses a different memory type, this will perform a copy (possibly cached). 315ca94c3ddSJeremy L Thompson @param[out] curl_orients Array on memory type `mem_type` 3167a982d89SJeremy L. Thompson 3177a982d89SJeremy L. Thompson @return An error code: 0 - success, otherwise - failure 3187a982d89SJeremy L. Thompson 31977d1c127SSebastian Grimberg @ref User 3207a982d89SJeremy L. Thompson **/ 3210c73c039SSebastian Grimberg int CeedElemRestrictionGetCurlOrientations(CeedElemRestriction rstr, CeedMemType mem_type, const CeedInt8 **curl_orients) { 3226e536b99SJeremy L Thompson CeedCheck(rstr->GetCurlOrientations, CeedElemRestrictionReturnCeed(rstr), CEED_ERROR_UNSUPPORTED, 3231ef3a2a9SJeremy L Thompson "Backend does not implement CeedElemRestrictionGetCurlOrientations"); 32477d1c127SSebastian Grimberg CeedCall(rstr->GetCurlOrientations(rstr, mem_type, curl_orients)); 32577d1c127SSebastian Grimberg rstr->num_readers++; 32677d1c127SSebastian Grimberg return CEED_ERROR_SUCCESS; 32777d1c127SSebastian Grimberg } 32877d1c127SSebastian Grimberg 32977d1c127SSebastian Grimberg /** 330ca94c3ddSJeremy L Thompson @brief Restore an orientations array obtained using @ref CeedElemRestrictionGetCurlOrientations() 33177d1c127SSebastian Grimberg 332ca94c3ddSJeremy L Thompson @param[in] rstr `CeedElemRestriction` to restore 33377d1c127SSebastian Grimberg @param[in] curl_orients Array of orientation data 33477d1c127SSebastian Grimberg 33577d1c127SSebastian Grimberg @return An error code: 0 - success, otherwise - failure 33677d1c127SSebastian Grimberg 33777d1c127SSebastian Grimberg @ref User 33877d1c127SSebastian Grimberg **/ 3390c73c039SSebastian Grimberg int CeedElemRestrictionRestoreCurlOrientations(CeedElemRestriction rstr, const CeedInt8 **curl_orients) { 34077d1c127SSebastian Grimberg *curl_orients = NULL; 34177d1c127SSebastian Grimberg rstr->num_readers--; 342e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 3437a982d89SJeremy L. Thompson } 3447a982d89SJeremy L. Thompson 3457a982d89SJeremy L. Thompson /** 34649fd234cSJeremy L Thompson 34722eb1385SJeremy L Thompson @brief Get the L-vector layout of a strided `CeedElemRestriction` 34822eb1385SJeremy L Thompson 34922eb1385SJeremy L Thompson @param[in] rstr `CeedElemRestriction` 35022eb1385SJeremy L Thompson @param[out] layout Variable to store layout array, stored as `[nodes, components, elements]`. 35122eb1385SJeremy L Thompson The data for node `i`, component `j`, element `k` in the E-vector is given by `i*layout[0] + j*layout[1] + k*layout[2]`. 35222eb1385SJeremy L Thompson 35322eb1385SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 35422eb1385SJeremy L Thompson 35522eb1385SJeremy L Thompson @ref Backend 35622eb1385SJeremy L Thompson **/ 35756c48462SJeremy L Thompson int CeedElemRestrictionGetLLayout(CeedElemRestriction rstr, CeedInt layout[3]) { 35822eb1385SJeremy L Thompson bool has_backend_strides; 35922eb1385SJeremy L Thompson CeedRestrictionType rstr_type; 3601203703bSJeremy L Thompson Ceed ceed; 36122eb1385SJeremy L Thompson 3621203703bSJeremy L Thompson CeedCall(CeedElemRestrictionGetCeed(rstr, &ceed)); 36322eb1385SJeremy L Thompson CeedCall(CeedElemRestrictionGetType(rstr, &rstr_type)); 3641203703bSJeremy L Thompson CeedCheck(rstr_type == CEED_RESTRICTION_STRIDED, ceed, CEED_ERROR_MINOR, "Only strided CeedElemRestriction have strided L-vector layout"); 36522eb1385SJeremy L Thompson CeedCall(CeedElemRestrictionHasBackendStrides(rstr, &has_backend_strides)); 36622eb1385SJeremy L Thompson if (has_backend_strides) { 3671203703bSJeremy L Thompson CeedCheck(rstr->l_layout[0], ceed, CEED_ERROR_MINOR, "CeedElemRestriction has no L-vector layout data"); 36856c48462SJeremy L Thompson for (CeedInt i = 0; i < 3; i++) layout[i] = rstr->l_layout[i]; 36922eb1385SJeremy L Thompson } else { 37022eb1385SJeremy L Thompson CeedCall(CeedElemRestrictionGetStrides(rstr, layout)); 37122eb1385SJeremy L Thompson } 37222eb1385SJeremy L Thompson return CEED_ERROR_SUCCESS; 37322eb1385SJeremy L Thompson } 37422eb1385SJeremy L Thompson 37522eb1385SJeremy L Thompson /** 37622eb1385SJeremy L Thompson 37722eb1385SJeremy L Thompson @brief Set the L-vector layout of a strided `CeedElemRestriction` 37822eb1385SJeremy L Thompson 37922eb1385SJeremy L Thompson @param[in] rstr `CeedElemRestriction` 38022eb1385SJeremy L Thompson @param[in] layout Variable to containing layout array, stored as `[nodes, components, elements]`. 38122eb1385SJeremy L Thompson The data for node `i`, component `j`, element `k` in the E-vector is given by `i*layout[0] + j*layout[1] + k*layout[2]`. 38222eb1385SJeremy L Thompson 38322eb1385SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 38422eb1385SJeremy L Thompson 38522eb1385SJeremy L Thompson @ref Backend 38622eb1385SJeremy L Thompson **/ 38722eb1385SJeremy L Thompson int CeedElemRestrictionSetLLayout(CeedElemRestriction rstr, CeedInt layout[3]) { 38822eb1385SJeremy L Thompson CeedRestrictionType rstr_type; 38922eb1385SJeremy L Thompson 39022eb1385SJeremy L Thompson CeedCall(CeedElemRestrictionGetType(rstr, &rstr_type)); 3916e536b99SJeremy L Thompson CeedCheck(rstr_type == CEED_RESTRICTION_STRIDED, CeedElemRestrictionReturnCeed(rstr), CEED_ERROR_MINOR, 3926e536b99SJeremy L Thompson "Only strided CeedElemRestriction have strided L-vector layout"); 39322eb1385SJeremy L Thompson for (CeedInt i = 0; i < 3; i++) rstr->l_layout[i] = layout[i]; 39422eb1385SJeremy L Thompson return CEED_ERROR_SUCCESS; 39522eb1385SJeremy L Thompson } 39622eb1385SJeremy L Thompson 39722eb1385SJeremy L Thompson /** 39822eb1385SJeremy L Thompson 399ca94c3ddSJeremy L Thompson @brief Get the E-vector layout of a `CeedElemRestriction` 40049fd234cSJeremy L Thompson 401ca94c3ddSJeremy L Thompson @param[in] rstr `CeedElemRestriction` 402ca94c3ddSJeremy L Thompson @param[out] layout Variable to store layout array, stored as `[nodes, components, elements]`. 403ca94c3ddSJeremy L Thompson The data for node `i`, component `j`, element `k` in the E-vector is given by `i*layout[0] + j*layout[1] + k*layout[2]`. 40449fd234cSJeremy L Thompson 40549fd234cSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 40649fd234cSJeremy L Thompson 40749fd234cSJeremy L Thompson @ref Backend 40849fd234cSJeremy L Thompson **/ 40956c48462SJeremy L Thompson int CeedElemRestrictionGetELayout(CeedElemRestriction rstr, CeedInt layout[3]) { 4106e536b99SJeremy L Thompson CeedCheck(rstr->e_layout[0], CeedElemRestrictionReturnCeed(rstr), CEED_ERROR_MINOR, "CeedElemRestriction has no E-vector layout data"); 41156c48462SJeremy L Thompson for (CeedInt i = 0; i < 3; i++) layout[i] = rstr->e_layout[i]; 412e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 41349fd234cSJeremy L Thompson } 41449fd234cSJeremy L Thompson 41549fd234cSJeremy L Thompson /** 41649fd234cSJeremy L Thompson 417ca94c3ddSJeremy L Thompson @brief Set the E-vector layout of a `CeedElemRestriction` 41849fd234cSJeremy L Thompson 419ca94c3ddSJeremy L Thompson @param[in] rstr `CeedElemRestriction` 420ca94c3ddSJeremy L Thompson @param[in] layout Variable to containing layout array, stored as `[nodes, components, elements]`. 421ca94c3ddSJeremy L Thompson The data for node `i`, component `j`, element `k` in the E-vector is given by `i*layout[0] + j*layout[1] + k*layout[2]`. 42249fd234cSJeremy L Thompson 42349fd234cSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 42449fd234cSJeremy L Thompson 42549fd234cSJeremy L Thompson @ref Backend 42649fd234cSJeremy L Thompson **/ 4272b730f8bSJeremy L Thompson int CeedElemRestrictionSetELayout(CeedElemRestriction rstr, CeedInt layout[3]) { 42822eb1385SJeremy L Thompson for (CeedInt i = 0; i < 3; i++) rstr->e_layout[i] = layout[i]; 429e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 43049fd234cSJeremy L Thompson } 43149fd234cSJeremy L Thompson 43249fd234cSJeremy L Thompson /** 43319605835SJeremy L Thompson 43419605835SJeremy L Thompson @brief Get the E-vector element offset of a `CeedElemRestriction` at points 43519605835SJeremy L Thompson 43619605835SJeremy L Thompson @param[in] rstr `CeedElemRestriction` 43719605835SJeremy L Thompson @param[in] elem Element number index into E-vector for 43819605835SJeremy L Thompson @param[out] elem_offset Offset for element `elem` in the E-vector. 43919605835SJeremy L Thompson The data for point `i`, component `j`, element `elem` in the E-vector is given by `i*e_layout[0] + j*e_layout[1] + elem_offset`. 44019605835SJeremy L Thompson 44119605835SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 44219605835SJeremy L Thompson 44319605835SJeremy L Thompson @ref Backend 44419605835SJeremy L Thompson **/ 44519605835SJeremy L Thompson int CeedElemRestrictionGetAtPointsElementOffset(CeedElemRestriction rstr, CeedInt elem, CeedSize *elem_offset) { 44619605835SJeremy L Thompson CeedInt num_comp; 44719605835SJeremy L Thompson CeedRestrictionType rstr_type; 44819605835SJeremy L Thompson 44919605835SJeremy L Thompson CeedCall(CeedElemRestrictionGetType(rstr, &rstr_type)); 45019605835SJeremy L Thompson CeedCheck(rstr_type == CEED_RESTRICTION_POINTS, CeedElemRestrictionReturnCeed(rstr), CEED_ERROR_INCOMPATIBLE, 45119605835SJeremy L Thompson "Can only compute offset for a points CeedElemRestriction"); 45219605835SJeremy L Thompson 45319605835SJeremy L Thompson // Backend method 45419605835SJeremy L Thompson if (rstr->GetAtPointsElementOffset) { 45519605835SJeremy L Thompson CeedCall(rstr->GetAtPointsElementOffset(rstr, elem, elem_offset)); 45619605835SJeremy L Thompson return CEED_ERROR_SUCCESS; 45719605835SJeremy L Thompson } 45819605835SJeremy L Thompson 45919605835SJeremy L Thompson // Default layout (CPU) 46019605835SJeremy L Thompson *elem_offset = 0; 46119605835SJeremy L Thompson CeedCall(CeedElemRestrictionGetNumComponents(rstr, &num_comp)); 46219605835SJeremy L Thompson for (CeedInt i = 0; i < elem; i++) { 46319605835SJeremy L Thompson CeedInt num_points; 46419605835SJeremy L Thompson 46519605835SJeremy L Thompson CeedCall(CeedElemRestrictionGetNumPointsInElement(rstr, i, &num_points)); 46619605835SJeremy L Thompson *elem_offset += num_points * num_comp; 46719605835SJeremy L Thompson } 46819605835SJeremy L Thompson return CEED_ERROR_SUCCESS; 46919605835SJeremy L Thompson } 47019605835SJeremy L Thompson 47119605835SJeremy L Thompson /** 472ff1bc20eSJeremy L Thompson 473ff1bc20eSJeremy L Thompson @brief Set the E-vector size of a `CeedElemRestriction` at points 474ff1bc20eSJeremy L Thompson 475ff1bc20eSJeremy L Thompson @param[in,out] rstr `CeedElemRestriction` 476ff1bc20eSJeremy L Thompson @param[in] e_size New E-vector size; must be longer than the current E-vector size 477ff1bc20eSJeremy L Thompson 478ff1bc20eSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 479ff1bc20eSJeremy L Thompson 480ff1bc20eSJeremy L Thompson @ref Backend 481ff1bc20eSJeremy L Thompson **/ 482ff1bc20eSJeremy L Thompson int CeedElemRestrictionSetAtPointsEVectorSize(CeedElemRestriction rstr, CeedSize e_size) { 483ff1bc20eSJeremy L Thompson CeedRestrictionType rstr_type; 484ff1bc20eSJeremy L Thompson Ceed ceed; 485ff1bc20eSJeremy L Thompson 486ff1bc20eSJeremy L Thompson CeedCall(CeedElemRestrictionGetCeed(rstr, &ceed)); 487ff1bc20eSJeremy L Thompson CeedCall(CeedElemRestrictionGetType(rstr, &rstr_type)); 488ff1bc20eSJeremy L Thompson CeedCheck(rstr_type == CEED_RESTRICTION_POINTS, ceed, CEED_ERROR_INCOMPATIBLE, "Can only compute offset for a points CeedElemRestriction"); 489*3f08121cSJeremy L Thompson CeedCheck(e_size >= rstr->e_size, ceed, CEED_ERROR_INCOMPATIBLE, 490*3f08121cSJeremy L Thompson "Can only increase the size of the E-vector for the CeedElemRestriction." 491*3f08121cSJeremy L Thompson " Current size: %" CeedSize_FMT " New size: %" CeedSize_FMT, 492*3f08121cSJeremy L Thompson rstr->e_size, e_size); 493ff1bc20eSJeremy L Thompson rstr->e_size = e_size; 494ff1bc20eSJeremy L Thompson return CEED_ERROR_SUCCESS; 495ff1bc20eSJeremy L Thompson } 496ff1bc20eSJeremy L Thompson 497ff1bc20eSJeremy L Thompson /** 498ca94c3ddSJeremy L Thompson @brief Get the backend data of a `CeedElemRestriction` 4997a982d89SJeremy L. Thompson 500ca94c3ddSJeremy L Thompson @param[in] rstr `CeedElemRestriction` 5017a982d89SJeremy L. Thompson @param[out] data Variable to store data 5027a982d89SJeremy L. Thompson 5037a982d89SJeremy L. Thompson @return An error code: 0 - success, otherwise - failure 5047a982d89SJeremy L. Thompson 5057a982d89SJeremy L. Thompson @ref Backend 5067a982d89SJeremy L. Thompson **/ 507777ff853SJeremy L Thompson int CeedElemRestrictionGetData(CeedElemRestriction rstr, void *data) { 508777ff853SJeremy L Thompson *(void **)data = rstr->data; 509e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 5107a982d89SJeremy L. Thompson } 5117a982d89SJeremy L. Thompson 5127a982d89SJeremy L. Thompson /** 513ca94c3ddSJeremy L Thompson @brief Set the backend data of a `CeedElemRestriction` 5147a982d89SJeremy L. Thompson 515ca94c3ddSJeremy L Thompson @param[in,out] rstr `CeedElemRestriction` 516ea61e9acSJeremy L Thompson @param[in] data Data to set 5177a982d89SJeremy L. Thompson 5187a982d89SJeremy L. Thompson @return An error code: 0 - success, otherwise - failure 5197a982d89SJeremy L. Thompson 5207a982d89SJeremy L. Thompson @ref Backend 5217a982d89SJeremy L. Thompson **/ 522777ff853SJeremy L Thompson int CeedElemRestrictionSetData(CeedElemRestriction rstr, void *data) { 523777ff853SJeremy L Thompson rstr->data = data; 524e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 5257a982d89SJeremy L. Thompson } 5267a982d89SJeremy L. Thompson 52734359f16Sjeremylt /** 528ca94c3ddSJeremy L Thompson @brief Increment the reference counter for a `CeedElemRestriction` 52934359f16Sjeremylt 530ca94c3ddSJeremy L Thompson @param[in,out] rstr `CeedElemRestriction` to increment the reference counter 53134359f16Sjeremylt 53234359f16Sjeremylt @return An error code: 0 - success, otherwise - failure 53334359f16Sjeremylt 53434359f16Sjeremylt @ref Backend 53534359f16Sjeremylt **/ 5369560d06aSjeremylt int CeedElemRestrictionReference(CeedElemRestriction rstr) { 53734359f16Sjeremylt rstr->ref_count++; 53834359f16Sjeremylt return CEED_ERROR_SUCCESS; 53934359f16Sjeremylt } 54034359f16Sjeremylt 5416e15d496SJeremy L Thompson /** 542ca94c3ddSJeremy L Thompson @brief Estimate number of FLOPs required to apply `CeedElemRestriction` in `t_mode` 5436e15d496SJeremy L Thompson 544ca94c3ddSJeremy L Thompson @param[in] rstr `CeedElemRestriction` to estimate FLOPs for 545ea61e9acSJeremy L Thompson @param[in] t_mode Apply restriction or transpose 546ea61e9acSJeremy L Thompson @param[out] flops Address of variable to hold FLOPs estimate 5476e15d496SJeremy L Thompson 5486e15d496SJeremy L Thompson @ref Backend 5496e15d496SJeremy L Thompson **/ 5502b730f8bSJeremy L Thompson int CeedElemRestrictionGetFlopsEstimate(CeedElemRestriction rstr, CeedTransposeMode t_mode, CeedSize *flops) { 5511203703bSJeremy L Thompson CeedSize e_size, scale = 0; 55289edb9e3SSebastian Grimberg CeedRestrictionType rstr_type; 5531c66c397SJeremy L Thompson 5541203703bSJeremy L Thompson CeedCall(CeedElemRestrictionGetEVectorSize(rstr, &e_size)); 55589edb9e3SSebastian Grimberg CeedCall(CeedElemRestrictionGetType(rstr, &rstr_type)); 55677d1c127SSebastian Grimberg if (t_mode == CEED_TRANSPOSE) { 55789edb9e3SSebastian Grimberg switch (rstr_type) { 5583ac8f562SJeremy L Thompson case CEED_RESTRICTION_POINTS: 5593ac8f562SJeremy L Thompson scale = 0; 5603ac8f562SJeremy L Thompson break; 56189edb9e3SSebastian Grimberg case CEED_RESTRICTION_STRIDED: 56289edb9e3SSebastian Grimberg case CEED_RESTRICTION_STANDARD: 56377d1c127SSebastian Grimberg scale = 1; 56489edb9e3SSebastian Grimberg break; 56589edb9e3SSebastian Grimberg case CEED_RESTRICTION_ORIENTED: 56677d1c127SSebastian Grimberg scale = 2; 56789edb9e3SSebastian Grimberg break; 56889edb9e3SSebastian Grimberg case CEED_RESTRICTION_CURL_ORIENTED: 56977d1c127SSebastian Grimberg scale = 6; 57089edb9e3SSebastian Grimberg break; 5716e15d496SJeremy L Thompson } 57277d1c127SSebastian Grimberg } else { 57389edb9e3SSebastian Grimberg switch (rstr_type) { 57489edb9e3SSebastian Grimberg case CEED_RESTRICTION_STRIDED: 57589edb9e3SSebastian Grimberg case CEED_RESTRICTION_STANDARD: 5763ac8f562SJeremy L Thompson case CEED_RESTRICTION_POINTS: 57777d1c127SSebastian Grimberg scale = 0; 57889edb9e3SSebastian Grimberg break; 57989edb9e3SSebastian Grimberg case CEED_RESTRICTION_ORIENTED: 58077d1c127SSebastian Grimberg scale = 1; 58189edb9e3SSebastian Grimberg break; 58289edb9e3SSebastian Grimberg case CEED_RESTRICTION_CURL_ORIENTED: 58377d1c127SSebastian Grimberg scale = 5; 58489edb9e3SSebastian Grimberg break; 58577d1c127SSebastian Grimberg } 58677d1c127SSebastian Grimberg } 5876e15d496SJeremy L Thompson *flops = e_size * scale; 5886e15d496SJeremy L Thompson return CEED_ERROR_SUCCESS; 5896e15d496SJeremy L Thompson } 5906e15d496SJeremy L Thompson 5917a982d89SJeremy L. Thompson /// @} 5927a982d89SJeremy L. Thompson 59315910d16Sjeremylt /// @cond DOXYGEN_SKIP 59415910d16Sjeremylt static struct CeedElemRestriction_private ceed_elemrestriction_none; 59515910d16Sjeremylt /// @endcond 59615910d16Sjeremylt 5977a982d89SJeremy L. Thompson /// ---------------------------------------------------------------------------- 5987a982d89SJeremy L. Thompson /// CeedElemRestriction Public API 5997a982d89SJeremy L. Thompson /// ---------------------------------------------------------------------------- 6007a982d89SJeremy L. Thompson /// @addtogroup CeedElemRestrictionUser 601d7b241e6Sjeremylt /// @{ 602d7b241e6Sjeremylt 6037a982d89SJeremy L. Thompson /// Indicate that the stride is determined by the backend 60445f1e315Sjeremylt const CeedInt CEED_STRIDES_BACKEND[3] = {0}; 6057a982d89SJeremy L. Thompson 606ca94c3ddSJeremy L Thompson /// Argument for @ref CeedOperatorSetField() indicating that the field does not require a `CeedElemRestriction` 6072b730f8bSJeremy L Thompson const CeedElemRestriction CEED_ELEMRESTRICTION_NONE = &ceed_elemrestriction_none; 6087a982d89SJeremy L. Thompson 609d7b241e6Sjeremylt /** 610ca94c3ddSJeremy L Thompson @brief Create a `CeedElemRestriction` 611d7b241e6Sjeremylt 612ca94c3ddSJeremy L Thompson @param[in] ceed `Ceed` context used to create the `CeedElemRestriction` 613ca94c3ddSJeremy L Thompson @param[in] num_elem Number of elements described in the `offsets` array 614ea61e9acSJeremy L Thompson @param[in] elem_size Size (number of "nodes") per element 615ea61e9acSJeremy L Thompson @param[in] num_comp Number of field components per interpolation node (1 for scalar fields) 616fcbe8c06SSebastian Grimberg @param[in] comp_stride Stride between components for the same L-vector "node". 617ca94c3ddSJeremy L Thompson Data for node `i`, component `j`, element `k` can be found in the L-vector at index `offsets[i + k*elem_size] + j*comp_stride`. 618fcbe8c06SSebastian Grimberg @param[in] l_size The size of the L-vector. 619fcbe8c06SSebastian Grimberg This vector may be larger than the elements and fields given by this restriction. 620ca94c3ddSJeremy L Thompson @param[in] mem_type Memory type of the `offsets` array, see @ref CeedMemType 621ca94c3ddSJeremy L Thompson @param[in] copy_mode Copy mode for the `offsets` array, see @ref CeedCopyMode 622ca94c3ddSJeremy L Thompson @param[in] offsets Array of shape `[num_elem, elem_size]`. 623ca94c3ddSJeremy L Thompson Row `i` holds the ordered list of the offsets (into the input `CeedVector`) for the unknowns corresponding to element `i`, where 0 <= i < @a num_elem. 624ca94c3ddSJeremy L Thompson All offsets must be in the range `[0, l_size - 1]`. 625ca94c3ddSJeremy L Thompson @param[out] rstr Address of the variable where the newly created `CeedElemRestriction` will be stored 626d7b241e6Sjeremylt 627b11c1e72Sjeremylt @return An error code: 0 - success, otherwise - failure 628dfdf5a53Sjeremylt 6297a982d89SJeremy L. Thompson @ref User 630b11c1e72Sjeremylt **/ 6312b730f8bSJeremy L Thompson int CeedElemRestrictionCreate(Ceed ceed, CeedInt num_elem, CeedInt elem_size, CeedInt num_comp, CeedInt comp_stride, CeedSize l_size, 6322b730f8bSJeremy L Thompson CeedMemType mem_type, CeedCopyMode copy_mode, const CeedInt *offsets, CeedElemRestriction *rstr) { 6335fe0d4faSjeremylt if (!ceed->ElemRestrictionCreate) { 6345fe0d4faSjeremylt Ceed delegate; 6356574a04fSJeremy L Thompson 6362b730f8bSJeremy L Thompson CeedCall(CeedGetObjectDelegate(ceed, &delegate, "ElemRestriction")); 637ca94c3ddSJeremy L Thompson CeedCheck(delegate, ceed, CEED_ERROR_UNSUPPORTED, "Backend does not implement CeedElemRestrictionCreate"); 6382b730f8bSJeremy L Thompson CeedCall(CeedElemRestrictionCreate(delegate, num_elem, elem_size, num_comp, comp_stride, l_size, mem_type, copy_mode, offsets, rstr)); 639e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 6405fe0d4faSjeremylt } 6415fe0d4faSjeremylt 642e7f679fcSJeremy L Thompson CeedCheck(num_elem >= 0, ceed, CEED_ERROR_DIMENSION, "Number of elements must be non-negative"); 6436574a04fSJeremy L Thompson CeedCheck(elem_size > 0, ceed, CEED_ERROR_DIMENSION, "Element size must be at least 1"); 644ca94c3ddSJeremy L Thompson CeedCheck(num_comp > 0, ceed, CEED_ERROR_DIMENSION, "CeedElemRestriction must have at least 1 component"); 645ca94c3ddSJeremy L Thompson CeedCheck(num_comp == 1 || comp_stride > 0, ceed, CEED_ERROR_DIMENSION, "CeedElemRestriction component stride must be at least 1"); 646e022e1f8SJeremy L Thompson 6472b730f8bSJeremy L Thompson CeedCall(CeedCalloc(1, rstr)); 648db002c03SJeremy L Thompson CeedCall(CeedReferenceCopy(ceed, &(*rstr)->ceed)); 649d1d35e2fSjeremylt (*rstr)->ref_count = 1; 650d1d35e2fSjeremylt (*rstr)->num_elem = num_elem; 651d1d35e2fSjeremylt (*rstr)->elem_size = elem_size; 652d1d35e2fSjeremylt (*rstr)->num_comp = num_comp; 653d1d35e2fSjeremylt (*rstr)->comp_stride = comp_stride; 654d1d35e2fSjeremylt (*rstr)->l_size = l_size; 6551203703bSJeremy L Thompson (*rstr)->e_size = (CeedSize)num_elem * (CeedSize)elem_size * (CeedSize)num_comp; 656e7f679fcSJeremy L Thompson (*rstr)->num_block = num_elem; 657e7f679fcSJeremy L Thompson (*rstr)->block_size = 1; 65861a27d74SSebastian Grimberg (*rstr)->rstr_type = CEED_RESTRICTION_STANDARD; 659fcbe8c06SSebastian Grimberg CeedCall(ceed->ElemRestrictionCreate(mem_type, copy_mode, offsets, NULL, NULL, *rstr)); 660e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 661d7b241e6Sjeremylt } 662d7b241e6Sjeremylt 663d7b241e6Sjeremylt /** 664ca94c3ddSJeremy L Thompson @brief Create a `CeedElemRestriction` with orientation signs 665fc0567d9Srezgarshakeri 666ca94c3ddSJeremy L Thompson @param[in] ceed `Ceed` context used to create the `CeedElemRestriction` 667ca94c3ddSJeremy L Thompson @param[in] num_elem Number of elements described in the `offsets` array 668ea61e9acSJeremy L Thompson @param[in] elem_size Size (number of "nodes") per element 669ea61e9acSJeremy L Thompson @param[in] num_comp Number of field components per interpolation node (1 for scalar fields) 670fcbe8c06SSebastian Grimberg @param[in] comp_stride Stride between components for the same L-vector "node". 671ca94c3ddSJeremy L Thompson Data for node `i`, component `j`, element `k` can be found in the L-vector at index `offsets[i + k*elem_size] + j*comp_stride`. 672fcbe8c06SSebastian Grimberg @param[in] l_size The size of the L-vector. 673fcbe8c06SSebastian Grimberg This vector may be larger than the elements and fields given by this restriction. 674ca94c3ddSJeremy L Thompson @param[in] mem_type Memory type of the `offsets` array, see @ref CeedMemType 675ca94c3ddSJeremy L Thompson @param[in] copy_mode Copy mode for the `offsets` array, see @ref CeedCopyMode 676ca94c3ddSJeremy L Thompson @param[in] offsets Array of shape `[num_elem, elem_size]`. 677ca94c3ddSJeremy L Thompson Row i holds the ordered list of the offsets (into the input `CeedVector`) for the unknowns corresponding to element `i`, where `0 <= i < num_elem`. 678ca94c3ddSJeremy L Thompson All offsets must be in the range `[0, l_size - 1]`. 679ca94c3ddSJeremy L Thompson @param[in] orients Boolean array of shape `[num_elem, elem_size]` with `false` for positively oriented and `true` to flip the orientation 680ca94c3ddSJeremy L Thompson @param[out] rstr Address of the variable where the newly created `CeedElemRestriction` will be stored 681fc0567d9Srezgarshakeri 682fc0567d9Srezgarshakeri @return An error code: 0 - success, otherwise - failure 683fc0567d9Srezgarshakeri 684fc0567d9Srezgarshakeri @ref User 685fc0567d9Srezgarshakeri **/ 6862b730f8bSJeremy L Thompson int CeedElemRestrictionCreateOriented(Ceed ceed, CeedInt num_elem, CeedInt elem_size, CeedInt num_comp, CeedInt comp_stride, CeedSize l_size, 68777d1c127SSebastian Grimberg CeedMemType mem_type, CeedCopyMode copy_mode, const CeedInt *offsets, const bool *orients, 688fc0567d9Srezgarshakeri CeedElemRestriction *rstr) { 689fcbe8c06SSebastian Grimberg if (!ceed->ElemRestrictionCreate) { 690fc0567d9Srezgarshakeri Ceed delegate; 6916574a04fSJeremy L Thompson 6922b730f8bSJeremy L Thompson CeedCall(CeedGetObjectDelegate(ceed, &delegate, "ElemRestriction")); 693ca94c3ddSJeremy L Thompson CeedCheck(delegate, ceed, CEED_ERROR_UNSUPPORTED, "Backend does not implement CeedElemRestrictionCreateOriented"); 6942b730f8bSJeremy L Thompson CeedCall( 69577d1c127SSebastian Grimberg CeedElemRestrictionCreateOriented(delegate, num_elem, elem_size, num_comp, comp_stride, l_size, mem_type, copy_mode, offsets, orients, rstr)); 696fc0567d9Srezgarshakeri return CEED_ERROR_SUCCESS; 697fc0567d9Srezgarshakeri } 698fc0567d9Srezgarshakeri 699e7f679fcSJeremy L Thompson CeedCheck(num_elem >= 0, ceed, CEED_ERROR_DIMENSION, "Number of elements must be non-negative"); 7006574a04fSJeremy L Thompson CeedCheck(elem_size > 0, ceed, CEED_ERROR_DIMENSION, "Element size must be at least 1"); 701ca94c3ddSJeremy L Thompson CeedCheck(num_comp > 0, ceed, CEED_ERROR_DIMENSION, "CeedElemRestriction must have at least 1 component"); 702ca94c3ddSJeremy L Thompson CeedCheck(num_comp == 1 || comp_stride > 0, ceed, CEED_ERROR_DIMENSION, "CeedElemRestriction component stride must be at least 1"); 703e022e1f8SJeremy L Thompson 7042b730f8bSJeremy L Thompson CeedCall(CeedCalloc(1, rstr)); 705db002c03SJeremy L Thompson CeedCall(CeedReferenceCopy(ceed, &(*rstr)->ceed)); 706fc0567d9Srezgarshakeri (*rstr)->ref_count = 1; 707fc0567d9Srezgarshakeri (*rstr)->num_elem = num_elem; 708fc0567d9Srezgarshakeri (*rstr)->elem_size = elem_size; 709fc0567d9Srezgarshakeri (*rstr)->num_comp = num_comp; 710fc0567d9Srezgarshakeri (*rstr)->comp_stride = comp_stride; 711fc0567d9Srezgarshakeri (*rstr)->l_size = l_size; 7121203703bSJeremy L Thompson (*rstr)->e_size = (CeedSize)num_elem * (CeedSize)elem_size * (CeedSize)num_comp; 713e7f679fcSJeremy L Thompson (*rstr)->num_block = num_elem; 714e7f679fcSJeremy L Thompson (*rstr)->block_size = 1; 715fcbe8c06SSebastian Grimberg (*rstr)->rstr_type = CEED_RESTRICTION_ORIENTED; 716fcbe8c06SSebastian Grimberg CeedCall(ceed->ElemRestrictionCreate(mem_type, copy_mode, offsets, orients, NULL, *rstr)); 71777d1c127SSebastian Grimberg return CEED_ERROR_SUCCESS; 71877d1c127SSebastian Grimberg } 71977d1c127SSebastian Grimberg 72077d1c127SSebastian Grimberg /** 721ca94c3ddSJeremy L Thompson @brief Create a `CeedElemRestriction` with a general tridiagonal transformation matrix for curl-conforming elements 72277d1c127SSebastian Grimberg 723ca94c3ddSJeremy L Thompson @param[in] ceed `Ceed` context used to create the `CeedElemRestriction` 724ca94c3ddSJeremy L Thompson @param[in] num_elem Number of elements described in the `offsets` array 72577d1c127SSebastian Grimberg @param[in] elem_size Size (number of "nodes") per element 72677d1c127SSebastian Grimberg @param[in] num_comp Number of field components per interpolation node (1 for scalar fields) 727fcbe8c06SSebastian Grimberg @param[in] comp_stride Stride between components for the same L-vector "node". 728ca94c3ddSJeremy L Thompson Data for node `i`, component `j`, element `k` can be found in the L-vector at index `offsets[i + k*elem_size] + j*comp_stride`. 729fcbe8c06SSebastian Grimberg @param[in] l_size The size of the L-vector. 730fcbe8c06SSebastian Grimberg This vector may be larger than the elements and fields given by this restriction. 731ca94c3ddSJeremy L Thompson @param[in] mem_type Memory type of the `offsets` array, see @ref CeedMemType 732ca94c3ddSJeremy L Thompson @param[in] copy_mode Copy mode for the `offsets` array, see @ref CeedCopyMode 733ca94c3ddSJeremy L Thompson @param[in] offsets Array of shape `[num_elem, elem_size]`. 734ca94c3ddSJeremy L Thompson Row `i` holds the ordered list of the offsets (into the input `CeedVector`) for the unknowns corresponding to element `i`, where `0 <= i < num_elem`. 735ca94c3ddSJeremy L Thompson All offsets must be in the range `[0, l_size - 1]`. 736ca94c3ddSJeremy L Thompson @param[in] curl_orients Array of shape `[num_elem, 3 * elem_size]` representing a row-major tridiagonal matrix (`curl_orients[i * 3 * elem_size] = curl_orients[(i + 1) * 3 * elem_size - 1] = 0`, where `0 <= i < num_elem`) which is applied to the element unknowns upon restriction. 737ca94c3ddSJeremy L Thompson This orientation matrix allows for pairs of face degrees of freedom on elements for \f$H(\mathrm{curl})\f$ spaces to be coupled in the element restriction operation, which is a way to resolve face orientation issues for 3D meshes (https://dl.acm.org/doi/pdf/10.1145/3524456). 738ca94c3ddSJeremy L Thompson @param[out] rstr Address of the variable where the newly created `CeedElemRestriction` will be stored 73977d1c127SSebastian Grimberg 74077d1c127SSebastian Grimberg @return An error code: 0 - success, otherwise - failure 74177d1c127SSebastian Grimberg 74277d1c127SSebastian Grimberg @ref User 74377d1c127SSebastian Grimberg **/ 74477d1c127SSebastian Grimberg int CeedElemRestrictionCreateCurlOriented(Ceed ceed, CeedInt num_elem, CeedInt elem_size, CeedInt num_comp, CeedInt comp_stride, CeedSize l_size, 7450c73c039SSebastian Grimberg CeedMemType mem_type, CeedCopyMode copy_mode, const CeedInt *offsets, const CeedInt8 *curl_orients, 74677d1c127SSebastian Grimberg CeedElemRestriction *rstr) { 747fcbe8c06SSebastian Grimberg if (!ceed->ElemRestrictionCreate) { 74877d1c127SSebastian Grimberg Ceed delegate; 74977d1c127SSebastian Grimberg 75077d1c127SSebastian Grimberg CeedCall(CeedGetObjectDelegate(ceed, &delegate, "ElemRestriction")); 751ca94c3ddSJeremy L Thompson CeedCheck(delegate, ceed, CEED_ERROR_UNSUPPORTED, "Backend does not implement CeedElemRestrictionCreateCurlOriented"); 75277d1c127SSebastian Grimberg CeedCall(CeedElemRestrictionCreateCurlOriented(delegate, num_elem, elem_size, num_comp, comp_stride, l_size, mem_type, copy_mode, offsets, 75377d1c127SSebastian Grimberg curl_orients, rstr)); 75477d1c127SSebastian Grimberg return CEED_ERROR_SUCCESS; 75577d1c127SSebastian Grimberg } 75677d1c127SSebastian Grimberg 757e7f679fcSJeremy L Thompson CeedCheck(num_elem >= 0, ceed, CEED_ERROR_DIMENSION, "Number of elements must be non-negative"); 75877d1c127SSebastian Grimberg CeedCheck(elem_size > 0, ceed, CEED_ERROR_DIMENSION, "Element size must be at least 1"); 759ca94c3ddSJeremy L Thompson CeedCheck(num_comp > 0, ceed, CEED_ERROR_DIMENSION, "CeedElemRestriction must have at least 1 component"); 760ca94c3ddSJeremy L Thompson CeedCheck(num_comp == 1 || comp_stride > 0, ceed, CEED_ERROR_DIMENSION, "CeedElemRestriction component stride must be at least 1"); 76177d1c127SSebastian Grimberg 76277d1c127SSebastian Grimberg CeedCall(CeedCalloc(1, rstr)); 763fcbe8c06SSebastian Grimberg CeedCall(CeedReferenceCopy(ceed, &(*rstr)->ceed)); 76477d1c127SSebastian Grimberg (*rstr)->ref_count = 1; 76577d1c127SSebastian Grimberg (*rstr)->num_elem = num_elem; 76677d1c127SSebastian Grimberg (*rstr)->elem_size = elem_size; 76777d1c127SSebastian Grimberg (*rstr)->num_comp = num_comp; 76877d1c127SSebastian Grimberg (*rstr)->comp_stride = comp_stride; 76977d1c127SSebastian Grimberg (*rstr)->l_size = l_size; 7701203703bSJeremy L Thompson (*rstr)->e_size = (CeedSize)num_elem * (CeedSize)elem_size * (CeedSize)num_comp; 771e7f679fcSJeremy L Thompson (*rstr)->num_block = num_elem; 772e7f679fcSJeremy L Thompson (*rstr)->block_size = 1; 773fcbe8c06SSebastian Grimberg (*rstr)->rstr_type = CEED_RESTRICTION_CURL_ORIENTED; 774fcbe8c06SSebastian Grimberg CeedCall(ceed->ElemRestrictionCreate(mem_type, copy_mode, offsets, NULL, curl_orients, *rstr)); 775fc0567d9Srezgarshakeri return CEED_ERROR_SUCCESS; 776fc0567d9Srezgarshakeri } 777fc0567d9Srezgarshakeri 778fc0567d9Srezgarshakeri /** 779ca94c3ddSJeremy L Thompson @brief Create a strided `CeedElemRestriction` 780d7b241e6Sjeremylt 781ca94c3ddSJeremy L Thompson @param[in] ceed `Ceed` context used to create the `CeedElemRestriction` 782ea61e9acSJeremy L Thompson @param[in] num_elem Number of elements described by the restriction 783ea61e9acSJeremy L Thompson @param[in] elem_size Size (number of "nodes") per element 784ea61e9acSJeremy L Thompson @param[in] num_comp Number of field components per interpolation "node" (1 for scalar fields) 785fcbe8c06SSebastian Grimberg @param[in] l_size The size of the L-vector. 786fcbe8c06SSebastian Grimberg This vector may be larger than the elements and fields given by this restriction. 787ca94c3ddSJeremy L Thompson @param[in] strides Array for strides between `[nodes, components, elements]`. 788ca94c3ddSJeremy L Thompson Data for node `i`, component `j`, element `k` can be found in the L-vector at index `i*strides[0] + j*strides[1] + k*strides[2]`. 789ca94c3ddSJeremy L Thompson @ref CEED_STRIDES_BACKEND may be used for `CeedVector` ordered by the same `Ceed` backend. 790972f909dSJeremy L Thompson `CEED_STRIDES_BACKEND` should only be used pass data between `CeedOperator` created with the same `Ceed` backend. 791972f909dSJeremy L Thompson The L-vector layout will, in general, be different between `Ceed` backends. 792ca94c3ddSJeremy L Thompson @param[out] rstr Address of the variable where the newly created `CeedElemRestriction` will be stored 793d7b241e6Sjeremylt 794b11c1e72Sjeremylt @return An error code: 0 - success, otherwise - failure 795dfdf5a53Sjeremylt 7967a982d89SJeremy L. Thompson @ref User 797b11c1e72Sjeremylt **/ 7982b730f8bSJeremy L Thompson int CeedElemRestrictionCreateStrided(Ceed ceed, CeedInt num_elem, CeedInt elem_size, CeedInt num_comp, CeedSize l_size, const CeedInt strides[3], 799f90c8643Sjeremylt CeedElemRestriction *rstr) { 8005fe0d4faSjeremylt if (!ceed->ElemRestrictionCreate) { 8015fe0d4faSjeremylt Ceed delegate; 802b04eb3d9SSebastian Grimberg 8032b730f8bSJeremy L Thompson CeedCall(CeedGetObjectDelegate(ceed, &delegate, "ElemRestriction")); 804ca94c3ddSJeremy L Thompson CeedCheck(delegate, ceed, CEED_ERROR_UNSUPPORTED, "Backend does not implement CeedElemRestrictionCreateStrided"); 8052b730f8bSJeremy L Thompson CeedCall(CeedElemRestrictionCreateStrided(delegate, num_elem, elem_size, num_comp, l_size, strides, rstr)); 806e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 8075fe0d4faSjeremylt } 8085fe0d4faSjeremylt 809e7f679fcSJeremy L Thompson CeedCheck(num_elem >= 0, ceed, CEED_ERROR_DIMENSION, "Number of elements must be non-negative"); 8106574a04fSJeremy L Thompson CeedCheck(elem_size > 0, ceed, CEED_ERROR_DIMENSION, "Element size must be at least 1"); 811ca94c3ddSJeremy L Thompson CeedCheck(num_comp > 0, ceed, CEED_ERROR_DIMENSION, "CeedElemRestriction must have at least 1 component"); 81281670346SSebastian Grimberg CeedCheck(l_size >= (CeedSize)num_elem * elem_size * num_comp, ceed, CEED_ERROR_DIMENSION, 81381670346SSebastian Grimberg "L-vector size must be at least num_elem * elem_size * num_comp"); 814e022e1f8SJeremy L Thompson 8152b730f8bSJeremy L Thompson CeedCall(CeedCalloc(1, rstr)); 816db002c03SJeremy L Thompson CeedCall(CeedReferenceCopy(ceed, &(*rstr)->ceed)); 817d1d35e2fSjeremylt (*rstr)->ref_count = 1; 818d1d35e2fSjeremylt (*rstr)->num_elem = num_elem; 819d1d35e2fSjeremylt (*rstr)->elem_size = elem_size; 820d1d35e2fSjeremylt (*rstr)->num_comp = num_comp; 821d1d35e2fSjeremylt (*rstr)->l_size = l_size; 8221203703bSJeremy L Thompson (*rstr)->e_size = (CeedSize)num_elem * (CeedSize)elem_size * (CeedSize)num_comp; 823e7f679fcSJeremy L Thompson (*rstr)->num_block = num_elem; 824e7f679fcSJeremy L Thompson (*rstr)->block_size = 1; 825fcbe8c06SSebastian Grimberg (*rstr)->rstr_type = CEED_RESTRICTION_STRIDED; 8262b730f8bSJeremy L Thompson CeedCall(CeedMalloc(3, &(*rstr)->strides)); 8272b730f8bSJeremy L Thompson for (CeedInt i = 0; i < 3; i++) (*rstr)->strides[i] = strides[i]; 828fcbe8c06SSebastian Grimberg CeedCall(ceed->ElemRestrictionCreate(CEED_MEM_HOST, CEED_OWN_POINTER, NULL, NULL, NULL, *rstr)); 829e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 830d7b241e6Sjeremylt } 831d7b241e6Sjeremylt 832d7b241e6Sjeremylt /** 833ca94c3ddSJeremy L Thompson @brief Create a points `CeedElemRestriction`, for restricting for restricting from a all local points to the current element in which they are located. 8343ac8f562SJeremy L Thompson 8353ac8f562SJeremy L Thompson The offsets array is arranged as 8363ac8f562SJeremy L Thompson 8373ac8f562SJeremy L Thompson element_0_start_index 8383ac8f562SJeremy L Thompson element_1_start_index 8393ac8f562SJeremy L Thompson ... 8403ac8f562SJeremy L Thompson element_n_start_index 8413ac8f562SJeremy L Thompson element_n_stop_index 8423ac8f562SJeremy L Thompson element_0_point_0 8433ac8f562SJeremy L Thompson element_0_point_1 8443ac8f562SJeremy L Thompson ... 8453ac8f562SJeremy L Thompson 846ca94c3ddSJeremy L Thompson @param[in] ceed `Ceed` context used to create the `CeedElemRestriction` 847ca94c3ddSJeremy L Thompson @param[in] num_elem Number of elements described in the `offsets` array 848ca94c3ddSJeremy L Thompson @param[in] num_points Number of points described in the `offsets` array 8493ac8f562SJeremy L Thompson @param[in] num_comp Number of field components per interpolation node (1 for scalar fields). 8503ac8f562SJeremy L Thompson Components are assumed to be contiguous by point. 8513ac8f562SJeremy L Thompson @param[in] l_size The size of the L-vector. 8523ac8f562SJeremy L Thompson This vector may be larger than the elements and fields given by this restriction. 853ca94c3ddSJeremy L Thompson @param[in] mem_type Memory type of the `offsets` array, see @ref CeedMemType 854ca94c3ddSJeremy L Thompson @param[in] copy_mode Copy mode for the `offsets` array, see @ref CeedCopyMode 855ca94c3ddSJeremy L Thompson @param[in] offsets Array of size `num_elem + 1 + num_points`. 8563ac8f562SJeremy L Thompson The first portion of the offsets array holds the ranges of indices corresponding to each element. 8573ac8f562SJeremy L Thompson The second portion holds the indices for each element. 858ca94c3ddSJeremy L Thompson @param[out] rstr Address of the variable where the newly created `CeedElemRestriction` will be stored 8593ac8f562SJeremy L Thompson 8603ac8f562SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 8613ac8f562SJeremy L Thompson 8623ac8f562SJeremy L Thompson @ref Backend 8633ac8f562SJeremy L Thompson **/ 8643ac8f562SJeremy L Thompson int CeedElemRestrictionCreateAtPoints(Ceed ceed, CeedInt num_elem, CeedInt num_points, CeedInt num_comp, CeedSize l_size, CeedMemType mem_type, 8653ac8f562SJeremy L Thompson CeedCopyMode copy_mode, const CeedInt *offsets, CeedElemRestriction *rstr) { 8663ac8f562SJeremy L Thompson if (!ceed->ElemRestrictionCreateAtPoints) { 8673ac8f562SJeremy L Thompson Ceed delegate; 8683ac8f562SJeremy L Thompson 8693ac8f562SJeremy L Thompson CeedCall(CeedGetObjectDelegate(ceed, &delegate, "ElemRestriction")); 870ca94c3ddSJeremy L Thompson CeedCheck(delegate, ceed, CEED_ERROR_UNSUPPORTED, "Backend does not implement CeedElemRestrictionCreateAtPoints"); 8713ac8f562SJeremy L Thompson CeedCall(CeedElemRestrictionCreateAtPoints(delegate, num_elem, num_points, num_comp, l_size, mem_type, copy_mode, offsets, rstr)); 8723ac8f562SJeremy L Thompson return CEED_ERROR_SUCCESS; 8733ac8f562SJeremy L Thompson } 8743ac8f562SJeremy L Thompson 8753ac8f562SJeremy L Thompson CeedCheck(num_elem >= 0, ceed, CEED_ERROR_DIMENSION, "Number of elements must be non-negative"); 8763ac8f562SJeremy L Thompson CeedCheck(num_points >= 0, ceed, CEED_ERROR_DIMENSION, "Number of points must be non-negative"); 877ca94c3ddSJeremy L Thompson CeedCheck(num_comp > 0, ceed, CEED_ERROR_DIMENSION, "CeedElemRestriction must have at least 1 component"); 87881670346SSebastian Grimberg CeedCheck(l_size >= (CeedSize)num_points * num_comp, ceed, CEED_ERROR_DIMENSION, "L-vector must be at least num_points * num_comp"); 8793ac8f562SJeremy L Thompson 8803ac8f562SJeremy L Thompson CeedCall(CeedCalloc(1, rstr)); 8813ac8f562SJeremy L Thompson CeedCall(CeedReferenceCopy(ceed, &(*rstr)->ceed)); 8823ac8f562SJeremy L Thompson (*rstr)->ref_count = 1; 8833ac8f562SJeremy L Thompson (*rstr)->num_elem = num_elem; 8843ac8f562SJeremy L Thompson (*rstr)->num_points = num_points; 8853ac8f562SJeremy L Thompson (*rstr)->num_comp = num_comp; 8862c2c926cSJeremy L Thompson (*rstr)->comp_stride = 1; 8873ac8f562SJeremy L Thompson (*rstr)->l_size = l_size; 8881203703bSJeremy L Thompson (*rstr)->e_size = (CeedSize)num_points * (CeedSize)num_comp; 88905fa913cSJeremy L Thompson (*rstr)->num_block = num_elem; 8903ac8f562SJeremy L Thompson (*rstr)->block_size = 1; 8913ac8f562SJeremy L Thompson (*rstr)->rstr_type = CEED_RESTRICTION_POINTS; 8923ac8f562SJeremy L Thompson CeedCall(ceed->ElemRestrictionCreateAtPoints(mem_type, copy_mode, offsets, NULL, NULL, *rstr)); 8933ac8f562SJeremy L Thompson return CEED_ERROR_SUCCESS; 8943ac8f562SJeremy L Thompson } 8953ac8f562SJeremy L Thompson 8963ac8f562SJeremy L Thompson /** 897ca94c3ddSJeremy L Thompson @brief Create a blocked `CeedElemRestriction`, typically only used by backends 898d7b241e6Sjeremylt 899ca94c3ddSJeremy L Thompson @param[in] ceed `Ceed` context used to create the `CeedElemRestriction` 900ca94c3ddSJeremy L Thompson @param[in] num_elem Number of elements described in the `offsets` array 901ea61e9acSJeremy L Thompson @param[in] elem_size Size (number of unknowns) per element 902e7f679fcSJeremy L Thompson @param[in] block_size Number of elements in a block 903ea61e9acSJeremy L Thompson @param[in] num_comp Number of field components per interpolation node (1 for scalar fields) 904fcbe8c06SSebastian Grimberg @param[in] comp_stride Stride between components for the same L-vector "node". 905ca94c3ddSJeremy L Thompson Data for node `i`, component `j`, element `k` can be found in the L-vector at index `offsets[i + k*elem_size] + j*comp_stride`. 906fcbe8c06SSebastian Grimberg @param[in] l_size The size of the L-vector. 907fcbe8c06SSebastian Grimberg This vector may be larger than the elements and fields given by this restriction. 908ca94c3ddSJeremy L Thompson @param[in] mem_type Memory type of the `offsets` array, see @ref CeedMemType 909ca94c3ddSJeremy L Thompson @param[in] copy_mode Copy mode for the `offsets` array, see @ref CeedCopyMode 910ca94c3ddSJeremy L Thompson @param[in] offsets Array of shape `[num_elem, elem_size]`. 911ca94c3ddSJeremy L Thompson Row `i` holds the ordered list of the offsets (into the input `CeedVector`) for the unknowns corresponding to element `i`, where `0 <= i < num_elem`. 912ca94c3ddSJeremy L Thompson All offsets must be in the range `[0, l_size - 1]`. 913ca94c3ddSJeremy L Thompson The backend will permute and pad this array to the desired ordering for the blocksize, which is typically given by the backend. 914ca94c3ddSJeremy L Thompson The default reordering is to interlace elements. 915ca94c3ddSJeremy L Thompson @param[out] rstr Address of the variable where the newly created `CeedElemRestriction` will be stored 916d7b241e6Sjeremylt 917b11c1e72Sjeremylt @return An error code: 0 - success, otherwise - failure 918dfdf5a53Sjeremylt 9197a982d89SJeremy L. Thompson @ref Backend 920b11c1e72Sjeremylt **/ 921e7f679fcSJeremy L Thompson int CeedElemRestrictionCreateBlocked(Ceed ceed, CeedInt num_elem, CeedInt elem_size, CeedInt block_size, CeedInt num_comp, CeedInt comp_stride, 9222b730f8bSJeremy L Thompson CeedSize l_size, CeedMemType mem_type, CeedCopyMode copy_mode, const CeedInt *offsets, 9234ce2993fSjeremylt CeedElemRestriction *rstr) { 9241c66c397SJeremy L Thompson CeedInt *block_offsets, num_block = (num_elem / block_size) + !!(num_elem % block_size); 925d7b241e6Sjeremylt 9265fe0d4faSjeremylt if (!ceed->ElemRestrictionCreateBlocked) { 9275fe0d4faSjeremylt Ceed delegate; 9286574a04fSJeremy L Thompson 9292b730f8bSJeremy L Thompson CeedCall(CeedGetObjectDelegate(ceed, &delegate, "ElemRestriction")); 930ca94c3ddSJeremy L Thompson CeedCheck(delegate, ceed, CEED_ERROR_UNSUPPORTED, "Backend does not implement CeedElemRestrictionCreateBlocked"); 931e7f679fcSJeremy L Thompson CeedCall(CeedElemRestrictionCreateBlocked(delegate, num_elem, elem_size, block_size, num_comp, comp_stride, l_size, mem_type, copy_mode, offsets, 932e7f679fcSJeremy L Thompson rstr)); 933e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 9345fe0d4faSjeremylt } 935d7b241e6Sjeremylt 936e7f679fcSJeremy L Thompson CeedCheck(num_elem >= 0, ceed, CEED_ERROR_DIMENSION, "Number of elements must be non-negative"); 9376574a04fSJeremy L Thompson CeedCheck(elem_size > 0, ceed, CEED_ERROR_DIMENSION, "Element size must be at least 1"); 938e7f679fcSJeremy L Thompson CeedCheck(block_size > 0, ceed, CEED_ERROR_DIMENSION, "Block size must be at least 1"); 939ca94c3ddSJeremy L Thompson CeedCheck(num_comp > 0, ceed, CEED_ERROR_DIMENSION, "CeedElemRestriction must have at least 1 component"); 940ca94c3ddSJeremy L Thompson CeedCheck(num_comp == 1 || comp_stride > 0, ceed, CEED_ERROR_DIMENSION, "CeedElemRestriction component stride must be at least 1"); 941e022e1f8SJeremy L Thompson 942e7f679fcSJeremy L Thompson CeedCall(CeedCalloc(num_block * block_size * elem_size, &block_offsets)); 943e7f679fcSJeremy L Thompson CeedCall(CeedPermutePadOffsets(offsets, block_offsets, num_block, num_elem, block_size, elem_size)); 944d7b241e6Sjeremylt 945db002c03SJeremy L Thompson CeedCall(CeedCalloc(1, rstr)); 946db002c03SJeremy L Thompson CeedCall(CeedReferenceCopy(ceed, &(*rstr)->ceed)); 947d1d35e2fSjeremylt (*rstr)->ref_count = 1; 948d1d35e2fSjeremylt (*rstr)->num_elem = num_elem; 949d1d35e2fSjeremylt (*rstr)->elem_size = elem_size; 950d1d35e2fSjeremylt (*rstr)->num_comp = num_comp; 951d1d35e2fSjeremylt (*rstr)->comp_stride = comp_stride; 952d1d35e2fSjeremylt (*rstr)->l_size = l_size; 9531203703bSJeremy L Thompson (*rstr)->e_size = (CeedSize)num_block * (CeedSize)block_size * (CeedSize)elem_size * (CeedSize)num_comp; 954e7f679fcSJeremy L Thompson (*rstr)->num_block = num_block; 955e7f679fcSJeremy L Thompson (*rstr)->block_size = block_size; 95661a27d74SSebastian Grimberg (*rstr)->rstr_type = CEED_RESTRICTION_STANDARD; 957e7f679fcSJeremy L Thompson CeedCall(ceed->ElemRestrictionCreateBlocked(CEED_MEM_HOST, CEED_OWN_POINTER, (const CeedInt *)block_offsets, NULL, NULL, *rstr)); 9581c66c397SJeremy L Thompson if (copy_mode == CEED_OWN_POINTER) CeedCall(CeedFree(&offsets)); 959e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 960d7b241e6Sjeremylt } 961d7b241e6Sjeremylt 962b11c1e72Sjeremylt /** 963ca94c3ddSJeremy L Thompson @brief Create a blocked oriented `CeedElemRestriction`, typically only used by backends 96477d1c127SSebastian Grimberg 965ca94c3ddSJeremy L Thompson @param[in] ceed `Ceed` context used to create the `CeedElemRestriction` 966ca94c3ddSJeremy L Thompson @param[in] num_elem Number of elements described in the `offsets` array. 96777d1c127SSebastian Grimberg @param[in] elem_size Size (number of unknowns) per element 968e7f679fcSJeremy L Thompson @param[in] block_size Number of elements in a block 96977d1c127SSebastian Grimberg @param[in] num_comp Number of field components per interpolation node (1 for scalar fields) 970fcbe8c06SSebastian Grimberg @param[in] comp_stride Stride between components for the same L-vector "node". 971ca94c3ddSJeremy L Thompson Data for node `i`, component `j`, element `k` can be found in the L-vector at index `offsets[i + k*elem_size] + j*comp_stride`. 972fcbe8c06SSebastian Grimberg @param[in] l_size The size of the L-vector. 973fcbe8c06SSebastian Grimberg This vector may be larger than the elements and fields given by this restriction. 974ca94c3ddSJeremy L Thompson @param[in] mem_type Memory type of the `offsets` array, see @ref CeedMemType 975ca94c3ddSJeremy L Thompson @param[in] copy_mode Copy mode for the `offsets` array, see @ref CeedCopyMode 976ca94c3ddSJeremy L Thompson @param[in] offsets Array of shape `[num_elem, elem_size]`. 977ca94c3ddSJeremy L Thompson Row `i` holds the ordered list of the offsets (into the input `CeedVector`) for the unknowns corresponding to element `i`, where `0 <= i < num_elem`. 978ca94c3ddSJeremy L Thompson All offsets must be in the range `[0, l_size - 1]`. 979ca94c3ddSJeremy L Thompson The backend will permute and pad this array to the desired ordering for the blocksize, which is typically given by the backend. 980ca94c3ddSJeremy L Thompson The default reordering is to interlace elements. 981ca94c3ddSJeremy L Thompson @param[in] orients Boolean array of shape `[num_elem, elem_size]` with `false` for positively oriented and `true` to flip the orientation. 982ca94c3ddSJeremy L Thompson Will also be permuted and padded similarly to `offsets`. 983ca94c3ddSJeremy L Thompson @param[out] rstr Address of the variable where the newly created `CeedElemRestriction` will be stored 98477d1c127SSebastian Grimberg 98577d1c127SSebastian Grimberg @return An error code: 0 - success, otherwise - failure 98677d1c127SSebastian Grimberg 98777d1c127SSebastian Grimberg @ref Backend 98877d1c127SSebastian Grimberg **/ 989e7f679fcSJeremy L Thompson int CeedElemRestrictionCreateBlockedOriented(Ceed ceed, CeedInt num_elem, CeedInt elem_size, CeedInt block_size, CeedInt num_comp, 990e7f679fcSJeremy L Thompson CeedInt comp_stride, CeedSize l_size, CeedMemType mem_type, CeedCopyMode copy_mode, 991e7f679fcSJeremy L Thompson const CeedInt *offsets, const bool *orients, CeedElemRestriction *rstr) { 992e7f679fcSJeremy L Thompson bool *block_orients; 9931c66c397SJeremy L Thompson CeedInt *block_offsets, num_block = (num_elem / block_size) + !!(num_elem % block_size); 99477d1c127SSebastian Grimberg 995fcbe8c06SSebastian Grimberg if (!ceed->ElemRestrictionCreateBlocked) { 99677d1c127SSebastian Grimberg Ceed delegate; 99777d1c127SSebastian Grimberg 99877d1c127SSebastian Grimberg CeedCall(CeedGetObjectDelegate(ceed, &delegate, "ElemRestriction")); 999ca94c3ddSJeremy L Thompson CeedCheck(delegate, ceed, CEED_ERROR_UNSUPPORTED, "Backend does not implement CeedElemRestrictionCreateBlockedOriented"); 1000e7f679fcSJeremy L Thompson CeedCall(CeedElemRestrictionCreateBlockedOriented(delegate, num_elem, elem_size, block_size, num_comp, comp_stride, l_size, mem_type, copy_mode, 100177d1c127SSebastian Grimberg offsets, orients, rstr)); 100277d1c127SSebastian Grimberg return CEED_ERROR_SUCCESS; 100377d1c127SSebastian Grimberg } 100477d1c127SSebastian Grimberg 100577d1c127SSebastian Grimberg CeedCheck(elem_size > 0, ceed, CEED_ERROR_DIMENSION, "Element size must be at least 1"); 1006e7f679fcSJeremy L Thompson CeedCheck(block_size > 0, ceed, CEED_ERROR_DIMENSION, "Block size must be at least 1"); 1007ca94c3ddSJeremy L Thompson CeedCheck(num_comp > 0, ceed, CEED_ERROR_DIMENSION, "CeedElemRestriction must have at least 1 component"); 1008ca94c3ddSJeremy L Thompson CeedCheck(num_comp == 1 || comp_stride > 0, ceed, CEED_ERROR_DIMENSION, "CeedElemRestriction component stride must be at least 1"); 100977d1c127SSebastian Grimberg 1010e7f679fcSJeremy L Thompson CeedCall(CeedCalloc(num_block * block_size * elem_size, &block_offsets)); 1011e7f679fcSJeremy L Thompson CeedCall(CeedCalloc(num_block * block_size * elem_size, &block_orients)); 1012e7f679fcSJeremy L Thompson CeedCall(CeedPermutePadOffsets(offsets, block_offsets, num_block, num_elem, block_size, elem_size)); 1013e7f679fcSJeremy L Thompson CeedCall(CeedPermutePadOrients(orients, block_orients, num_block, num_elem, block_size, elem_size)); 101477d1c127SSebastian Grimberg 1015fcbe8c06SSebastian Grimberg CeedCall(CeedCalloc(1, rstr)); 1016fcbe8c06SSebastian Grimberg CeedCall(CeedReferenceCopy(ceed, &(*rstr)->ceed)); 101777d1c127SSebastian Grimberg (*rstr)->ref_count = 1; 101877d1c127SSebastian Grimberg (*rstr)->num_elem = num_elem; 101977d1c127SSebastian Grimberg (*rstr)->elem_size = elem_size; 102077d1c127SSebastian Grimberg (*rstr)->num_comp = num_comp; 102177d1c127SSebastian Grimberg (*rstr)->comp_stride = comp_stride; 102277d1c127SSebastian Grimberg (*rstr)->l_size = l_size; 10231203703bSJeremy L Thompson (*rstr)->e_size = (CeedSize)num_block * (CeedSize)block_size * (CeedSize)elem_size * (CeedSize)num_comp; 1024e7f679fcSJeremy L Thompson (*rstr)->num_block = num_block; 1025e7f679fcSJeremy L Thompson (*rstr)->block_size = block_size; 1026fcbe8c06SSebastian Grimberg (*rstr)->rstr_type = CEED_RESTRICTION_ORIENTED; 1027e7f679fcSJeremy L Thompson CeedCall( 1028e7f679fcSJeremy L Thompson ceed->ElemRestrictionCreateBlocked(CEED_MEM_HOST, CEED_OWN_POINTER, (const CeedInt *)block_offsets, (const bool *)block_orients, NULL, *rstr)); 10291c66c397SJeremy L Thompson if (copy_mode == CEED_OWN_POINTER) CeedCall(CeedFree(&offsets)); 103077d1c127SSebastian Grimberg return CEED_ERROR_SUCCESS; 103177d1c127SSebastian Grimberg } 103277d1c127SSebastian Grimberg 103377d1c127SSebastian Grimberg /** 1034ca94c3ddSJeremy L Thompson @brief Create a blocked curl-oriented `CeedElemRestriction`, typically only used by backends 103577d1c127SSebastian Grimberg 1036ca94c3ddSJeremy L Thompson @param[in] ceed `Ceed` context used to create the `CeedElemRestriction` 1037ca94c3ddSJeremy L Thompson @param[in] num_elem Number of elements described in the `offsets` array. 103877d1c127SSebastian Grimberg @param[in] elem_size Size (number of unknowns) per element 1039e7f679fcSJeremy L Thompson @param[in] block_size Number of elements in a block 104077d1c127SSebastian Grimberg @param[in] num_comp Number of field components per interpolation node (1 for scalar fields) 1041fcbe8c06SSebastian Grimberg @param[in] comp_stride Stride between components for the same L-vector "node". 1042ca94c3ddSJeremy L Thompson Data for node `i`, component `j`, element `k` can be found in the L-vector at index `offsets[i + k*elem_size] + j*comp_stride`. 1043fcbe8c06SSebastian Grimberg @param[in] l_size The size of the L-vector. 1044fcbe8c06SSebastian Grimberg This vector may be larger than the elements and fields given by this restriction. 1045ca94c3ddSJeremy L Thompson @param[in] mem_type Memory type of the `offsets` array, see @ref CeedMemType 1046ca94c3ddSJeremy L Thompson @param[in] copy_mode Copy mode for the `offsets` array, see @ref CeedCopyMode 1047ca94c3ddSJeremy L Thompson @param[in] offsets Array of shape `[num_elem, elem_size]`. 1048ca94c3ddSJeremy L Thompson Row `i` holds the ordered list of the offsets (into the input `CeedVector`) for the unknowns corresponding to element `i`, where `0 <= i < num_elem`. 1049ca94c3ddSJeremy L Thompson All offsets must be in the range `[0, l_size - 1]`. 1050ca94c3ddSJeremy L Thompson The backend will permute and pad this array to the desired ordering for the blocksize, which is typically given by the backend. 1051ca94c3ddSJeremy L Thompson The default reordering is to interlace elements. 1052ca94c3ddSJeremy L Thompson @param[in] curl_orients Array of shape `[num_elem, 3 * elem_size]` representing a row-major tridiagonal matrix (`curl_orients[i * 3 * elem_size] = curl_orients[(i + 1) * 3 * elem_size - 1] = 0`, where `0 <= i < num_elem`) which is applied to the element unknowns upon restriction. 1053ca94c3ddSJeremy L Thompson This orientation matrix allows for pairs of face degrees of freedom on elements for \f$H(\mathrm{curl})\f$ spaces to be coupled in the element restriction operation, which is a way to resolve face orientation issues for 3D meshes (https://dl.acm.org/doi/pdf/10.1145/3524456). 1054ca94c3ddSJeremy L Thompson Will also be permuted and padded similarly to offsets. 1055ca94c3ddSJeremy L Thompson @param[out] rstr Address of the variable where the newly created `CeedElemRestriction` will be stored 105677d1c127SSebastian Grimberg 105777d1c127SSebastian Grimberg @return An error code: 0 - success, otherwise - failure 105877d1c127SSebastian Grimberg 105977d1c127SSebastian Grimberg @ref Backend 106077d1c127SSebastian Grimberg **/ 1061e7f679fcSJeremy L Thompson int CeedElemRestrictionCreateBlockedCurlOriented(Ceed ceed, CeedInt num_elem, CeedInt elem_size, CeedInt block_size, CeedInt num_comp, 106277d1c127SSebastian Grimberg CeedInt comp_stride, CeedSize l_size, CeedMemType mem_type, CeedCopyMode copy_mode, 10630c73c039SSebastian Grimberg const CeedInt *offsets, const CeedInt8 *curl_orients, CeedElemRestriction *rstr) { 1064e7f679fcSJeremy L Thompson CeedInt8 *block_curl_orients; 10651c66c397SJeremy L Thompson CeedInt *block_offsets, num_block = (num_elem / block_size) + !!(num_elem % block_size); 106677d1c127SSebastian Grimberg 1067fcbe8c06SSebastian Grimberg if (!ceed->ElemRestrictionCreateBlocked) { 106877d1c127SSebastian Grimberg Ceed delegate; 106977d1c127SSebastian Grimberg 107077d1c127SSebastian Grimberg CeedCall(CeedGetObjectDelegate(ceed, &delegate, "ElemRestriction")); 1071ca94c3ddSJeremy L Thompson CeedCheck(delegate, ceed, CEED_ERROR_UNSUPPORTED, "Backend does not implement CeedElemRestrictionCreateBlockedCurlOriented"); 1072e7f679fcSJeremy L Thompson CeedCall(CeedElemRestrictionCreateBlockedCurlOriented(delegate, num_elem, elem_size, block_size, num_comp, comp_stride, l_size, mem_type, 1073e7f679fcSJeremy L Thompson copy_mode, offsets, curl_orients, rstr)); 107477d1c127SSebastian Grimberg return CEED_ERROR_SUCCESS; 107577d1c127SSebastian Grimberg } 107677d1c127SSebastian Grimberg 1077e7f679fcSJeremy L Thompson CeedCheck(num_elem >= 0, ceed, CEED_ERROR_DIMENSION, "Number of elements must be non-negative"); 107877d1c127SSebastian Grimberg CeedCheck(elem_size > 0, ceed, CEED_ERROR_DIMENSION, "Element size must be at least 1"); 1079e7f679fcSJeremy L Thompson CeedCheck(block_size > 0, ceed, CEED_ERROR_DIMENSION, "Block size must be at least 1"); 1080ca94c3ddSJeremy L Thompson CeedCheck(num_comp > 0, ceed, CEED_ERROR_DIMENSION, "CeedElemRestriction must have at least 1 component"); 1081ca94c3ddSJeremy L Thompson CeedCheck(num_comp == 1 || comp_stride > 0, ceed, CEED_ERROR_DIMENSION, "CeedElemRestriction component stride must be at least 1"); 108277d1c127SSebastian Grimberg 1083e7f679fcSJeremy L Thompson CeedCall(CeedCalloc(num_block * block_size * elem_size, &block_offsets)); 1084e7f679fcSJeremy L Thompson CeedCall(CeedCalloc(num_block * block_size * 3 * elem_size, &block_curl_orients)); 1085e7f679fcSJeremy L Thompson CeedCall(CeedPermutePadOffsets(offsets, block_offsets, num_block, num_elem, block_size, elem_size)); 1086e7f679fcSJeremy L Thompson CeedCall(CeedPermutePadCurlOrients(curl_orients, block_curl_orients, num_block, num_elem, block_size, 3 * elem_size)); 108777d1c127SSebastian Grimberg 1088fcbe8c06SSebastian Grimberg CeedCall(CeedCalloc(1, rstr)); 1089fcbe8c06SSebastian Grimberg CeedCall(CeedReferenceCopy(ceed, &(*rstr)->ceed)); 109077d1c127SSebastian Grimberg (*rstr)->ref_count = 1; 109177d1c127SSebastian Grimberg (*rstr)->num_elem = num_elem; 109277d1c127SSebastian Grimberg (*rstr)->elem_size = elem_size; 109377d1c127SSebastian Grimberg (*rstr)->num_comp = num_comp; 109477d1c127SSebastian Grimberg (*rstr)->comp_stride = comp_stride; 109577d1c127SSebastian Grimberg (*rstr)->l_size = l_size; 10961203703bSJeremy L Thompson (*rstr)->e_size = (CeedSize)num_block * (CeedSize)block_size * (CeedSize)elem_size * (CeedSize)num_comp; 1097e7f679fcSJeremy L Thompson (*rstr)->num_block = num_block; 1098e7f679fcSJeremy L Thompson (*rstr)->block_size = block_size; 1099fcbe8c06SSebastian Grimberg (*rstr)->rstr_type = CEED_RESTRICTION_CURL_ORIENTED; 1100e7f679fcSJeremy L Thompson CeedCall(ceed->ElemRestrictionCreateBlocked(CEED_MEM_HOST, CEED_OWN_POINTER, (const CeedInt *)block_offsets, NULL, 1101e7f679fcSJeremy L Thompson (const CeedInt8 *)block_curl_orients, *rstr)); 11021c66c397SJeremy L Thompson if (copy_mode == CEED_OWN_POINTER) CeedCall(CeedFree(&offsets)); 110377d1c127SSebastian Grimberg return CEED_ERROR_SUCCESS; 110477d1c127SSebastian Grimberg } 110577d1c127SSebastian Grimberg 110677d1c127SSebastian Grimberg /** 1107ca94c3ddSJeremy L Thompson @brief Create a blocked strided `CeedElemRestriction`, typically only used by backends 11087509a596Sjeremylt 1109ca94c3ddSJeremy L Thompson @param[in] ceed `Ceed` context used to create the `CeedElemRestriction` 1110ea61e9acSJeremy L Thompson @param[in] num_elem Number of elements described by the restriction 1111ea61e9acSJeremy L Thompson @param[in] elem_size Size (number of "nodes") per element 1112e7f679fcSJeremy L Thompson @param[in] block_size Number of elements in a block 1113ea61e9acSJeremy L Thompson @param[in] num_comp Number of field components per interpolation node (1 for scalar fields) 1114fcbe8c06SSebastian Grimberg @param[in] l_size The size of the L-vector. 1115fcbe8c06SSebastian Grimberg This vector may be larger than the elements and fields given by this restriction. 1116ca94c3ddSJeremy L Thompson @param[in] strides Array for strides between `[nodes, components, elements]`. 1117ca94c3ddSJeremy L Thompson Data for node `i`, component `j`, element `k` can be found in the L-vector at index `i*strides[0] + j*strides[1] +k*strides[2]`. 1118ca94c3ddSJeremy L Thompson @ref CEED_STRIDES_BACKEND may be used for `CeedVector` ordered by the same `Ceed` backend. 1119ca94c3ddSJeremy L Thompson @param[out] rstr Address of the variable where the newly created `CeedElemRestriction` will be stored 11207509a596Sjeremylt 11217509a596Sjeremylt @return An error code: 0 - success, otherwise - failure 11227509a596Sjeremylt 11237a982d89SJeremy L. Thompson @ref User 11247509a596Sjeremylt **/ 1125e7f679fcSJeremy L Thompson int CeedElemRestrictionCreateBlockedStrided(Ceed ceed, CeedInt num_elem, CeedInt elem_size, CeedInt block_size, CeedInt num_comp, CeedSize l_size, 11268621c6c6SJeremy L Thompson const CeedInt strides[3], CeedElemRestriction *rstr) { 1127e7f679fcSJeremy L Thompson CeedInt num_block = (num_elem / block_size) + !!(num_elem % block_size); 11287509a596Sjeremylt 11297509a596Sjeremylt if (!ceed->ElemRestrictionCreateBlocked) { 11307509a596Sjeremylt Ceed delegate; 11316574a04fSJeremy L Thompson 11322b730f8bSJeremy L Thompson CeedCall(CeedGetObjectDelegate(ceed, &delegate, "ElemRestriction")); 1133ca94c3ddSJeremy L Thompson CeedCheck(delegate, ceed, CEED_ERROR_UNSUPPORTED, "Backend does not implement CeedElemRestrictionCreateBlockedStrided"); 1134e7f679fcSJeremy L Thompson CeedCall(CeedElemRestrictionCreateBlockedStrided(delegate, num_elem, elem_size, block_size, num_comp, l_size, strides, rstr)); 1135e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 11367509a596Sjeremylt } 11377509a596Sjeremylt 1138e7f679fcSJeremy L Thompson CeedCheck(num_elem >= 0, ceed, CEED_ERROR_DIMENSION, "Number of elements must be non-negative"); 11396574a04fSJeremy L Thompson CeedCheck(elem_size > 0, ceed, CEED_ERROR_DIMENSION, "Element size must be at least 1"); 1140e7f679fcSJeremy L Thompson CeedCheck(block_size > 0, ceed, CEED_ERROR_DIMENSION, "Block size must be at least 1"); 1141ca94c3ddSJeremy L Thompson CeedCheck(num_comp > 0, ceed, CEED_ERROR_DIMENSION, "CeedElemRestriction must have at least 1 component"); 114281670346SSebastian Grimberg CeedCheck(l_size >= (CeedSize)num_elem * elem_size * num_comp, ceed, CEED_ERROR_DIMENSION, 114381670346SSebastian Grimberg "L-vector size must be at least num_elem * elem_size * num_comp"); 1144e022e1f8SJeremy L Thompson 11452b730f8bSJeremy L Thompson CeedCall(CeedCalloc(1, rstr)); 1146db002c03SJeremy L Thompson CeedCall(CeedReferenceCopy(ceed, &(*rstr)->ceed)); 1147d1d35e2fSjeremylt (*rstr)->ref_count = 1; 1148d1d35e2fSjeremylt (*rstr)->num_elem = num_elem; 1149d1d35e2fSjeremylt (*rstr)->elem_size = elem_size; 1150d1d35e2fSjeremylt (*rstr)->num_comp = num_comp; 1151d1d35e2fSjeremylt (*rstr)->l_size = l_size; 11521203703bSJeremy L Thompson (*rstr)->e_size = (CeedSize)num_block * (CeedSize)block_size * (CeedSize)elem_size * (CeedSize)num_comp; 1153e7f679fcSJeremy L Thompson (*rstr)->num_block = num_block; 1154e7f679fcSJeremy L Thompson (*rstr)->block_size = block_size; 1155fcbe8c06SSebastian Grimberg (*rstr)->rstr_type = CEED_RESTRICTION_STRIDED; 11562b730f8bSJeremy L Thompson CeedCall(CeedMalloc(3, &(*rstr)->strides)); 11572b730f8bSJeremy L Thompson for (CeedInt i = 0; i < 3; i++) (*rstr)->strides[i] = strides[i]; 1158fcbe8c06SSebastian Grimberg CeedCall(ceed->ElemRestrictionCreateBlocked(CEED_MEM_HOST, CEED_OWN_POINTER, NULL, NULL, NULL, *rstr)); 1159e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 11607509a596Sjeremylt } 11617509a596Sjeremylt 11627509a596Sjeremylt /** 1163ca94c3ddSJeremy L Thompson @brief Copy the pointer to a `CeedElemRestriction` and set @ref CeedElemRestrictionApply() implementation to use the unsigned version. 1164c17ec2beSJeremy L Thompson 1165ca94c3ddSJeremy L Thompson Both pointers should be destroyed with @ref CeedElemRestrictionDestroy(). 1166c17ec2beSJeremy L Thompson 1167ca94c3ddSJeremy L Thompson @param[in] rstr `CeedElemRestriction` to create unsigned reference to 1168ca94c3ddSJeremy L Thompson @param[in,out] rstr_unsigned Variable to store unsigned `CeedElemRestriction` 1169c17ec2beSJeremy L Thompson 1170c17ec2beSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 1171c17ec2beSJeremy L Thompson 1172c17ec2beSJeremy L Thompson @ref User 1173c17ec2beSJeremy L Thompson **/ 1174c17ec2beSJeremy L Thompson int CeedElemRestrictionCreateUnsignedCopy(CeedElemRestriction rstr, CeedElemRestriction *rstr_unsigned) { 1175c17ec2beSJeremy L Thompson CeedCall(CeedCalloc(1, rstr_unsigned)); 1176c17ec2beSJeremy L Thompson 1177c17ec2beSJeremy L Thompson // Copy old rstr 1178c17ec2beSJeremy L Thompson memcpy(*rstr_unsigned, rstr, sizeof(struct CeedElemRestriction_private)); 1179c17ec2beSJeremy L Thompson (*rstr_unsigned)->ceed = NULL; 1180c17ec2beSJeremy L Thompson CeedCall(CeedReferenceCopy(rstr->ceed, &(*rstr_unsigned)->ceed)); 1181c17ec2beSJeremy L Thompson (*rstr_unsigned)->ref_count = 1; 1182c17ec2beSJeremy L Thompson (*rstr_unsigned)->strides = NULL; 1183c17ec2beSJeremy L Thompson if (rstr->strides) { 1184c17ec2beSJeremy L Thompson CeedCall(CeedMalloc(3, &(*rstr_unsigned)->strides)); 1185c17ec2beSJeremy L Thompson for (CeedInt i = 0; i < 3; i++) (*rstr_unsigned)->strides[i] = rstr->strides[i]; 1186c17ec2beSJeremy L Thompson } 11877c1dbaffSSebastian Grimberg CeedCall(CeedElemRestrictionReferenceCopy(rstr, &(*rstr_unsigned)->rstr_base)); 1188c17ec2beSJeremy L Thompson 1189c17ec2beSJeremy L Thompson // Override Apply 1190c17ec2beSJeremy L Thompson (*rstr_unsigned)->Apply = rstr->ApplyUnsigned; 1191c17ec2beSJeremy L Thompson return CEED_ERROR_SUCCESS; 1192c17ec2beSJeremy L Thompson } 1193c17ec2beSJeremy L Thompson 1194c17ec2beSJeremy L Thompson /** 1195ca94c3ddSJeremy L Thompson @brief Copy the pointer to a `CeedElemRestriction` and set @ref CeedElemRestrictionApply() implementation to use the unoriented version. 11967c1dbaffSSebastian Grimberg 1197ca94c3ddSJeremy L Thompson Both pointers should be destroyed with @ref CeedElemRestrictionDestroy(). 11987c1dbaffSSebastian Grimberg 1199ca94c3ddSJeremy L Thompson @param[in] rstr `CeedElemRestriction` to create unoriented reference to 1200ca94c3ddSJeremy L Thompson @param[in,out] rstr_unoriented Variable to store unoriented `CeedElemRestriction` 12017c1dbaffSSebastian Grimberg 12027c1dbaffSSebastian Grimberg @return An error code: 0 - success, otherwise - failure 12037c1dbaffSSebastian Grimberg 12047c1dbaffSSebastian Grimberg @ref User 12057c1dbaffSSebastian Grimberg **/ 12067c1dbaffSSebastian Grimberg int CeedElemRestrictionCreateUnorientedCopy(CeedElemRestriction rstr, CeedElemRestriction *rstr_unoriented) { 12077c1dbaffSSebastian Grimberg CeedCall(CeedCalloc(1, rstr_unoriented)); 12087c1dbaffSSebastian Grimberg 12097c1dbaffSSebastian Grimberg // Copy old rstr 12107c1dbaffSSebastian Grimberg memcpy(*rstr_unoriented, rstr, sizeof(struct CeedElemRestriction_private)); 12117c1dbaffSSebastian Grimberg (*rstr_unoriented)->ceed = NULL; 12127c1dbaffSSebastian Grimberg CeedCall(CeedReferenceCopy(rstr->ceed, &(*rstr_unoriented)->ceed)); 12137c1dbaffSSebastian Grimberg (*rstr_unoriented)->ref_count = 1; 12147c1dbaffSSebastian Grimberg (*rstr_unoriented)->strides = NULL; 12157c1dbaffSSebastian Grimberg if (rstr->strides) { 12167c1dbaffSSebastian Grimberg CeedCall(CeedMalloc(3, &(*rstr_unoriented)->strides)); 12177c1dbaffSSebastian Grimberg for (CeedInt i = 0; i < 3; i++) (*rstr_unoriented)->strides[i] = rstr->strides[i]; 12187c1dbaffSSebastian Grimberg } 12197c1dbaffSSebastian Grimberg CeedCall(CeedElemRestrictionReferenceCopy(rstr, &(*rstr_unoriented)->rstr_base)); 12207c1dbaffSSebastian Grimberg 12217c1dbaffSSebastian Grimberg // Override Apply 12227c1dbaffSSebastian Grimberg (*rstr_unoriented)->Apply = rstr->ApplyUnoriented; 12237c1dbaffSSebastian Grimberg return CEED_ERROR_SUCCESS; 12247c1dbaffSSebastian Grimberg } 12257c1dbaffSSebastian Grimberg 12267c1dbaffSSebastian Grimberg /** 1227ca94c3ddSJeremy L Thompson @brief Copy the pointer to a `CeedElemRestriction`. 12289fd66db6SSebastian Grimberg 1229ca94c3ddSJeremy L Thompson Both pointers should be destroyed with @ref CeedElemRestrictionDestroy(). 12309560d06aSjeremylt 1231ca94c3ddSJeremy L Thompson Note: If the value of `*rstr_copy` passed into this function is non-`NULL`, then it is assumed that `*rstr_copy` is a pointer to a `CeedElemRestriction`. 1232ca94c3ddSJeremy L Thompson This `CeedElemRestriction` will be destroyed if `*rstr_copy` is the only reference to this `CeedElemRestriction`. 1233ea61e9acSJeremy L Thompson 1234ca94c3ddSJeremy L Thompson @param[in] rstr `CeedElemRestriction` to copy reference to 1235ea61e9acSJeremy L Thompson @param[in,out] rstr_copy Variable to store copied reference 12369560d06aSjeremylt 12379560d06aSjeremylt @return An error code: 0 - success, otherwise - failure 12389560d06aSjeremylt 12399560d06aSjeremylt @ref User 12409560d06aSjeremylt **/ 12412b730f8bSJeremy L Thompson int CeedElemRestrictionReferenceCopy(CeedElemRestriction rstr, CeedElemRestriction *rstr_copy) { 1242393ac2cdSJeremy L Thompson if (rstr != CEED_ELEMRESTRICTION_NONE) CeedCall(CeedElemRestrictionReference(rstr)); 12432b730f8bSJeremy L Thompson CeedCall(CeedElemRestrictionDestroy(rstr_copy)); 12449560d06aSjeremylt *rstr_copy = rstr; 12459560d06aSjeremylt return CEED_ERROR_SUCCESS; 12469560d06aSjeremylt } 12479560d06aSjeremylt 12489560d06aSjeremylt /** 1249ca94c3ddSJeremy L Thompson @brief Create `CeedVector` associated with a `CeedElemRestriction` 1250b11c1e72Sjeremylt 1251ca94c3ddSJeremy L Thompson @param[in] rstr `CeedElemRestriction` 1252ca94c3ddSJeremy L Thompson @param[out] l_vec The address of the L-vector to be created, or `NULL` 1253ca94c3ddSJeremy L Thompson @param[out] e_vec The address of the E-vector to be created, or `NULL` 1254b11c1e72Sjeremylt 1255b11c1e72Sjeremylt @return An error code: 0 - success, otherwise - failure 1256dfdf5a53Sjeremylt 12577a982d89SJeremy L. Thompson @ref User 1258b11c1e72Sjeremylt **/ 12592b730f8bSJeremy L Thompson int CeedElemRestrictionCreateVector(CeedElemRestriction rstr, CeedVector *l_vec, CeedVector *e_vec) { 1260d2643443SJeremy L Thompson CeedSize e_size, l_size; 12611203703bSJeremy L Thompson Ceed ceed; 126248acf710SJeremy L Thompson 12631203703bSJeremy L Thompson CeedCall(CeedElemRestrictionGetCeed(rstr, &ceed)); 12641203703bSJeremy L Thompson CeedCall(CeedElemRestrictionGetLVectorSize(rstr, &l_size)); 12651203703bSJeremy L Thompson CeedCall(CeedElemRestrictionGetEVectorSize(rstr, &e_size)); 12661203703bSJeremy L Thompson if (l_vec) CeedCall(CeedVectorCreate(ceed, l_size, l_vec)); 12671203703bSJeremy L Thompson if (e_vec) CeedCall(CeedVectorCreate(ceed, e_size, e_vec)); 1268e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 1269d7b241e6Sjeremylt } 1270d7b241e6Sjeremylt 1271d7b241e6Sjeremylt /** 1272d9e1f99aSValeria Barra @brief Restrict an L-vector to an E-vector or apply its transpose 1273d7b241e6Sjeremylt 1274ca94c3ddSJeremy L Thompson @param[in] rstr `CeedElemRestriction` 1275ea61e9acSJeremy L Thompson @param[in] t_mode Apply restriction or transpose 1276ca94c3ddSJeremy L Thompson @param[in] u Input vector (of size `l_size` when `t_mode` = @ref CEED_NOTRANSPOSE) 1277ca94c3ddSJeremy L Thompson @param[out] ru Output vector (of shape `[num_elem * elem_size]` when `t_mode` = @ref CEED_NOTRANSPOSE). 1278fcbe8c06SSebastian Grimberg Ordering of the e-vector is decided by the backend. 1279ea61e9acSJeremy L Thompson @param[in] request Request or @ref CEED_REQUEST_IMMEDIATE 1280b11c1e72Sjeremylt 1281b11c1e72Sjeremylt @return An error code: 0 - success, otherwise - failure 1282dfdf5a53Sjeremylt 12837a982d89SJeremy L. Thompson @ref User 1284b11c1e72Sjeremylt **/ 12852b730f8bSJeremy L Thompson int CeedElemRestrictionApply(CeedElemRestriction rstr, CeedTransposeMode t_mode, CeedVector u, CeedVector ru, CeedRequest *request) { 1286701e7d35SJeremy L Thompson CeedSize min_u_len, min_ru_len, len; 1287701e7d35SJeremy L Thompson CeedInt num_elem; 12881203703bSJeremy L Thompson Ceed ceed; 1289d7b241e6Sjeremylt 12901203703bSJeremy L Thompson CeedCall(CeedElemRestrictionGetCeed(rstr, &ceed)); 1291d1d35e2fSjeremylt if (t_mode == CEED_NOTRANSPOSE) { 1292701e7d35SJeremy L Thompson CeedCall(CeedElemRestrictionGetEVectorSize(rstr, &min_ru_len)); 1293701e7d35SJeremy L Thompson CeedCall(CeedElemRestrictionGetLVectorSize(rstr, &min_u_len)); 1294d7b241e6Sjeremylt } else { 1295701e7d35SJeremy L Thompson CeedCall(CeedElemRestrictionGetEVectorSize(rstr, &min_u_len)); 1296701e7d35SJeremy L Thompson CeedCall(CeedElemRestrictionGetLVectorSize(rstr, &min_ru_len)); 1297d7b241e6Sjeremylt } 1298701e7d35SJeremy L Thompson CeedCall(CeedVectorGetLength(u, &len)); 12991203703bSJeremy L Thompson CeedCheck(min_u_len <= len, ceed, CEED_ERROR_DIMENSION, 1300701e7d35SJeremy L Thompson "Input vector size %" CeedInt_FMT " not compatible with element restriction (%" CeedInt_FMT ", %" CeedInt_FMT ")", len, min_ru_len, 1301701e7d35SJeremy L Thompson min_u_len); 1302701e7d35SJeremy L Thompson CeedCall(CeedVectorGetLength(ru, &len)); 13031203703bSJeremy L Thompson CeedCheck(min_ru_len <= len, ceed, CEED_ERROR_DIMENSION, 1304701e7d35SJeremy L Thompson "Output vector size %" CeedInt_FMT " not compatible with element restriction (%" CeedInt_FMT ", %" CeedInt_FMT ")", len, min_u_len, 1305701e7d35SJeremy L Thompson min_ru_len); 1306701e7d35SJeremy L Thompson CeedCall(CeedElemRestrictionGetNumElements(rstr, &num_elem)); 1307701e7d35SJeremy L Thompson if (num_elem > 0) CeedCall(rstr->Apply(rstr, t_mode, u, ru, request)); 1308e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 1309d7b241e6Sjeremylt } 1310d7b241e6Sjeremylt 1311d7b241e6Sjeremylt /** 13123ac8f562SJeremy L Thompson @brief Restrict an L-vector of points to a single element or apply its transpose 13133ac8f562SJeremy L Thompson 1314ca94c3ddSJeremy L Thompson @param[in] rstr `CeedElemRestriction` 1315ca94c3ddSJeremy L Thompson @param[in] elem Element number in range `[0, num_elem)` 13163ac8f562SJeremy L Thompson @param[in] t_mode Apply restriction or transpose 1317ca94c3ddSJeremy L Thompson @param[in] u Input vector (of size `l_size` when `t_mode` = @ref CEED_NOTRANSPOSE) 1318ca94c3ddSJeremy L Thompson @param[out] ru Output vector (of shape [`num_points * num_comp]` when `t_mode` = @ref CEED_NOTRANSPOSE). 13193ac8f562SJeremy L Thompson Ordering of the e-vector is decided by the backend. 13203ac8f562SJeremy L Thompson @param[in] request Request or @ref CEED_REQUEST_IMMEDIATE 13213ac8f562SJeremy L Thompson 13223ac8f562SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 13233ac8f562SJeremy L Thompson 13243ac8f562SJeremy L Thompson @ref User 13253ac8f562SJeremy L Thompson **/ 132605fa913cSJeremy L Thompson int CeedElemRestrictionApplyAtPointsInElement(CeedElemRestriction rstr, CeedInt elem, CeedTransposeMode t_mode, CeedVector u, CeedVector ru, 13273ac8f562SJeremy L Thompson CeedRequest *request) { 1328701e7d35SJeremy L Thompson CeedSize min_u_len, min_ru_len, len; 1329701e7d35SJeremy L Thompson CeedInt num_elem; 13301203703bSJeremy L Thompson Ceed ceed; 13313ac8f562SJeremy L Thompson 13321203703bSJeremy L Thompson CeedCall(CeedElemRestrictionGetCeed(rstr, &ceed)); 13331ef3a2a9SJeremy L Thompson CeedCheck(rstr->ApplyAtPointsInElement, ceed, CEED_ERROR_UNSUPPORTED, "Backend does not implement CeedElemRestrictionApplyAtPointsInElement"); 13341ef3a2a9SJeremy L Thompson 13353ac8f562SJeremy L Thompson if (t_mode == CEED_NOTRANSPOSE) { 1336701e7d35SJeremy L Thompson CeedInt num_points, num_comp; 1337701e7d35SJeremy L Thompson 1338701e7d35SJeremy L Thompson CeedCall(CeedElemRestrictionGetLVectorSize(rstr, &min_u_len)); 1339701e7d35SJeremy L Thompson CeedCall(CeedElemRestrictionGetNumPointsInElement(rstr, elem, &num_points)); 1340701e7d35SJeremy L Thompson CeedCall(CeedElemRestrictionGetNumComponents(rstr, &num_comp)); 1341701e7d35SJeremy L Thompson min_ru_len = (CeedSize)num_points * (CeedSize)num_comp; 13423ac8f562SJeremy L Thompson } else { 1343701e7d35SJeremy L Thompson CeedInt num_points, num_comp; 1344701e7d35SJeremy L Thompson 1345701e7d35SJeremy L Thompson CeedCall(CeedElemRestrictionGetNumPointsInElement(rstr, elem, &num_points)); 1346701e7d35SJeremy L Thompson CeedCall(CeedElemRestrictionGetNumComponents(rstr, &num_comp)); 1347701e7d35SJeremy L Thompson min_u_len = (CeedSize)num_points * (CeedSize)num_comp; 1348701e7d35SJeremy L Thompson CeedCall(CeedElemRestrictionGetLVectorSize(rstr, &min_ru_len)); 13493ac8f562SJeremy L Thompson } 1350701e7d35SJeremy L Thompson CeedCall(CeedVectorGetLength(u, &len)); 13511203703bSJeremy L Thompson CeedCheck(min_u_len <= len, ceed, CEED_ERROR_DIMENSION, 13523ac8f562SJeremy L Thompson "Input vector size %" CeedInt_FMT " not compatible with element restriction (%" CeedInt_FMT ", %" CeedInt_FMT 13533ac8f562SJeremy L Thompson ") for element %" CeedInt_FMT, 1354701e7d35SJeremy L Thompson len, min_ru_len, min_u_len, elem); 1355701e7d35SJeremy L Thompson CeedCall(CeedVectorGetLength(ru, &len)); 13561203703bSJeremy L Thompson CeedCheck(min_ru_len <= len, ceed, CEED_ERROR_DIMENSION, 13573ac8f562SJeremy L Thompson "Output vector size %" CeedInt_FMT " not compatible with element restriction (%" CeedInt_FMT ", %" CeedInt_FMT 13583ac8f562SJeremy L Thompson ") for element %" CeedInt_FMT, 1359701e7d35SJeremy L Thompson len, min_ru_len, min_u_len, elem); 1360701e7d35SJeremy L Thompson CeedCall(CeedElemRestrictionGetNumElements(rstr, &num_elem)); 13611203703bSJeremy L Thompson CeedCheck(elem < num_elem, ceed, CEED_ERROR_DIMENSION, 1362701e7d35SJeremy L Thompson "Cannot retrieve element %" CeedInt_FMT ", element %" CeedInt_FMT " > total elements %" CeedInt_FMT "", elem, elem, num_elem); 1363701e7d35SJeremy L Thompson if (num_elem > 0) CeedCall(rstr->ApplyAtPointsInElement(rstr, elem, t_mode, u, ru, request)); 13643ac8f562SJeremy L Thompson return CEED_ERROR_SUCCESS; 13653ac8f562SJeremy L Thompson } 13663ac8f562SJeremy L Thompson 13673ac8f562SJeremy L Thompson /** 1368d9e1f99aSValeria Barra @brief Restrict an L-vector to a block of an E-vector or apply its transpose 1369be9261b7Sjeremylt 1370ca94c3ddSJeremy L Thompson @param[in] rstr `CeedElemRestriction` 1371ca94c3ddSJeremy L Thompson @param[in] block Block number to restrict to/from, i.e. `block = 0` will handle elements `[0 : block_size]` and `block = 3` will handle elements `[3*block_size : 4*block_size]` 1372ea61e9acSJeremy L Thompson @param[in] t_mode Apply restriction or transpose 1373ca94c3ddSJeremy L Thompson @param[in] u Input vector (of size `l_size` when `t_mode` = @ref CEED_NOTRANSPOSE) 1374ca94c3ddSJeremy L Thompson @param[out] ru Output vector (of shape `[block_size * elem_size]` when `t_mode` = @ref CEED_NOTRANSPOSE). 1375fcbe8c06SSebastian Grimberg Ordering of the e-vector is decided by the backend. 1376ea61e9acSJeremy L Thompson @param[in] request Request or @ref CEED_REQUEST_IMMEDIATE 1377be9261b7Sjeremylt 1378be9261b7Sjeremylt @return An error code: 0 - success, otherwise - failure 1379be9261b7Sjeremylt 13807a982d89SJeremy L. Thompson @ref Backend 1381be9261b7Sjeremylt **/ 13822b730f8bSJeremy L Thompson int CeedElemRestrictionApplyBlock(CeedElemRestriction rstr, CeedInt block, CeedTransposeMode t_mode, CeedVector u, CeedVector ru, 13832b730f8bSJeremy L Thompson CeedRequest *request) { 1384701e7d35SJeremy L Thompson CeedSize min_u_len, min_ru_len, len; 1385701e7d35SJeremy L Thompson CeedInt block_size, num_elem; 13861203703bSJeremy L Thompson Ceed ceed; 1387be9261b7Sjeremylt 13881203703bSJeremy L Thompson CeedCall(CeedElemRestrictionGetCeed(rstr, &ceed)); 13891203703bSJeremy L Thompson CeedCheck(rstr->ApplyBlock, ceed, CEED_ERROR_UNSUPPORTED, "Backend does not implement CeedElemRestrictionApplyBlock"); 13906402da51SJeremy L Thompson 1391701e7d35SJeremy L Thompson CeedCall(CeedElemRestrictionGetBlockSize(rstr, &block_size)); 1392d1d35e2fSjeremylt if (t_mode == CEED_NOTRANSPOSE) { 1393701e7d35SJeremy L Thompson CeedInt elem_size, num_comp; 1394701e7d35SJeremy L Thompson 1395701e7d35SJeremy L Thompson CeedCall(CeedElemRestrictionGetElementSize(rstr, &elem_size)); 1396701e7d35SJeremy L Thompson CeedCall(CeedElemRestrictionGetNumComponents(rstr, &num_comp)); 1397701e7d35SJeremy L Thompson CeedCall(CeedElemRestrictionGetLVectorSize(rstr, &min_u_len)); 1398701e7d35SJeremy L Thompson min_ru_len = (CeedSize)block_size * (CeedSize)elem_size * (CeedSize)num_comp; 1399be9261b7Sjeremylt } else { 1400701e7d35SJeremy L Thompson CeedInt elem_size, num_comp; 1401701e7d35SJeremy L Thompson 1402701e7d35SJeremy L Thompson CeedCall(CeedElemRestrictionGetElementSize(rstr, &elem_size)); 1403701e7d35SJeremy L Thompson CeedCall(CeedElemRestrictionGetNumComponents(rstr, &num_comp)); 1404701e7d35SJeremy L Thompson CeedCall(CeedElemRestrictionGetLVectorSize(rstr, &min_ru_len)); 1405701e7d35SJeremy L Thompson min_u_len = (CeedSize)block_size * (CeedSize)elem_size * (CeedSize)num_comp; 1406be9261b7Sjeremylt } 1407701e7d35SJeremy L Thompson CeedCall(CeedVectorGetLength(u, &len)); 14081203703bSJeremy L Thompson CeedCheck(min_u_len == len, ceed, CEED_ERROR_DIMENSION, 1409701e7d35SJeremy L Thompson "Input vector size %" CeedInt_FMT " not compatible with element restriction (%" CeedInt_FMT ", %" CeedInt_FMT ")", len, min_u_len, 1410701e7d35SJeremy L Thompson min_ru_len); 1411701e7d35SJeremy L Thompson CeedCall(CeedVectorGetLength(ru, &len)); 14121203703bSJeremy L Thompson CeedCheck(min_ru_len == len, ceed, CEED_ERROR_DIMENSION, 1413701e7d35SJeremy L Thompson "Output vector size %" CeedInt_FMT " not compatible with element restriction (%" CeedInt_FMT ", %" CeedInt_FMT ")", len, min_ru_len, 1414701e7d35SJeremy L Thompson min_u_len); 1415701e7d35SJeremy L Thompson CeedCall(CeedElemRestrictionGetNumElements(rstr, &num_elem)); 14161203703bSJeremy L Thompson CeedCheck(block_size * block <= num_elem, ceed, CEED_ERROR_DIMENSION, 1417701e7d35SJeremy L Thompson "Cannot retrieve block %" CeedInt_FMT ", element %" CeedInt_FMT " > total elements %" CeedInt_FMT "", block, block_size * block, 1418701e7d35SJeremy L Thompson num_elem); 14192b730f8bSJeremy L Thompson CeedCall(rstr->ApplyBlock(rstr, block, t_mode, u, ru, request)); 1420e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 1421be9261b7Sjeremylt } 1422be9261b7Sjeremylt 1423be9261b7Sjeremylt /** 1424ca94c3ddSJeremy L Thompson @brief Get the `Ceed` associated with a `CeedElemRestriction` 1425b7c9bbdaSJeremy L Thompson 1426ca94c3ddSJeremy L Thompson @param[in] rstr `CeedElemRestriction` 1427ca94c3ddSJeremy L Thompson @param[out] ceed Variable to store `Ceed` 1428b7c9bbdaSJeremy L Thompson 1429b7c9bbdaSJeremy L Thompson @return An error code: 0 - success, otherwise - failure 1430b7c9bbdaSJeremy L Thompson 1431b7c9bbdaSJeremy L Thompson @ref Advanced 1432b7c9bbdaSJeremy L Thompson **/ 1433b7c9bbdaSJeremy L Thompson int CeedElemRestrictionGetCeed(CeedElemRestriction rstr, Ceed *ceed) { 14346e536b99SJeremy L Thompson *ceed = CeedElemRestrictionReturnCeed(rstr); 1435b7c9bbdaSJeremy L Thompson return CEED_ERROR_SUCCESS; 1436b7c9bbdaSJeremy L Thompson } 1437b7c9bbdaSJeremy L Thompson 1438b7c9bbdaSJeremy L Thompson /** 14396e536b99SJeremy L Thompson @brief Return the `Ceed` associated with a `CeedElemRestriction` 14406e536b99SJeremy L Thompson 14416e536b99SJeremy L Thompson @param[in] rstr `CeedElemRestriction` 14426e536b99SJeremy L Thompson 14436e536b99SJeremy L Thompson @return `Ceed` associated with the `rstr` 14446e536b99SJeremy L Thompson 14456e536b99SJeremy L Thompson @ref Advanced 14466e536b99SJeremy L Thompson **/ 14476e536b99SJeremy L Thompson Ceed CeedElemRestrictionReturnCeed(CeedElemRestriction rstr) { return rstr->ceed; } 14486e536b99SJeremy L Thompson 14496e536b99SJeremy L Thompson /** 1450d979a051Sjeremylt @brief Get the L-vector component stride 1451a681ae63Sjeremylt 1452ca94c3ddSJeremy L Thompson @param[in] rstr `CeedElemRestriction` 1453d1d35e2fSjeremylt @param[out] comp_stride Variable to store component stride 1454a681ae63Sjeremylt 1455a681ae63Sjeremylt @return An error code: 0 - success, otherwise - failure 1456a681ae63Sjeremylt 1457b7c9bbdaSJeremy L Thompson @ref Advanced 1458a681ae63Sjeremylt **/ 14592b730f8bSJeremy L Thompson int CeedElemRestrictionGetCompStride(CeedElemRestriction rstr, CeedInt *comp_stride) { 1460d1d35e2fSjeremylt *comp_stride = rstr->comp_stride; 1461e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 1462a681ae63Sjeremylt } 1463a681ae63Sjeremylt 1464a681ae63Sjeremylt /** 1465ca94c3ddSJeremy L Thompson @brief Get the total number of elements in the range of a `CeedElemRestriction` 1466a681ae63Sjeremylt 1467ca94c3ddSJeremy L Thompson @param[in] rstr `CeedElemRestriction` 1468d1d35e2fSjeremylt @param[out] num_elem Variable to store number of elements 1469a681ae63Sjeremylt 1470a681ae63Sjeremylt @return An error code: 0 - success, otherwise - failure 1471a681ae63Sjeremylt 1472b7c9bbdaSJeremy L Thompson @ref Advanced 1473a681ae63Sjeremylt **/ 14742b730f8bSJeremy L Thompson int CeedElemRestrictionGetNumElements(CeedElemRestriction rstr, CeedInt *num_elem) { 1475d1d35e2fSjeremylt *num_elem = rstr->num_elem; 1476e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 1477a681ae63Sjeremylt } 1478a681ae63Sjeremylt 1479a681ae63Sjeremylt /** 1480ca94c3ddSJeremy L Thompson @brief Get the size of elements in the `CeedElemRestriction` 1481a681ae63Sjeremylt 1482ca94c3ddSJeremy L Thompson @param[in] rstr `CeedElemRestriction` 1483d1d35e2fSjeremylt @param[out] elem_size Variable to store size of elements 1484a681ae63Sjeremylt 1485a681ae63Sjeremylt @return An error code: 0 - success, otherwise - failure 1486a681ae63Sjeremylt 1487b7c9bbdaSJeremy L Thompson @ref Advanced 1488a681ae63Sjeremylt **/ 14892b730f8bSJeremy L Thompson int CeedElemRestrictionGetElementSize(CeedElemRestriction rstr, CeedInt *elem_size) { 1490d1d35e2fSjeremylt *elem_size = rstr->elem_size; 14912c7e7413SJeremy L Thompson return CEED_ERROR_SUCCESS; 14922c7e7413SJeremy L Thompson } 14932c7e7413SJeremy L Thompson 14942c7e7413SJeremy L Thompson /** 149507d5dec1SJeremy L Thompson 1496725a297dSZach Atkins @brief Get the number of points in the offsets array for a points `CeedElemRestriction` 149707d5dec1SJeremy L Thompson 1498ca94c3ddSJeremy L Thompson @param[in] rstr `CeedElemRestriction` 1499725a297dSZach Atkins @param[out] num_points The number of points in the offsets array 150007d5dec1SJeremy L Thompson 150107d5dec1SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 150207d5dec1SJeremy L Thompson 1503c63574e3SJeremy L Thompson @ref User 150407d5dec1SJeremy L Thompson **/ 150507d5dec1SJeremy L Thompson int CeedElemRestrictionGetNumPoints(CeedElemRestriction rstr, CeedInt *num_points) { 15061203703bSJeremy L Thompson CeedRestrictionType rstr_type; 150707d5dec1SJeremy L Thompson 15081203703bSJeremy L Thompson CeedCall(CeedElemRestrictionGetType(rstr, &rstr_type)); 15096e536b99SJeremy L Thompson CeedCheck(rstr_type == CEED_RESTRICTION_POINTS, CeedElemRestrictionReturnCeed(rstr), CEED_ERROR_INCOMPATIBLE, 151007d5dec1SJeremy L Thompson "Can only retrieve the number of points for a points CeedElemRestriction"); 151107d5dec1SJeremy L Thompson 151207d5dec1SJeremy L Thompson *num_points = rstr->num_points; 151307d5dec1SJeremy L Thompson return CEED_ERROR_SUCCESS; 151407d5dec1SJeremy L Thompson } 151507d5dec1SJeremy L Thompson 151607d5dec1SJeremy L Thompson /** 151707d5dec1SJeremy L Thompson 1518ca94c3ddSJeremy L Thompson @brief Get the number of points in an element of a `CeedElemRestriction` at points 151907d5dec1SJeremy L Thompson 1520ca94c3ddSJeremy L Thompson @param[in] rstr `CeedElemRestriction` 152107d5dec1SJeremy L Thompson @param[in] elem Index number of element to retrieve the number of points for 152207d5dec1SJeremy L Thompson @param[out] num_points The number of points in the element at index elem 152307d5dec1SJeremy L Thompson 152407d5dec1SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 152507d5dec1SJeremy L Thompson 1526c63574e3SJeremy L Thompson @ref User 152707d5dec1SJeremy L Thompson **/ 152807d5dec1SJeremy L Thompson int CeedElemRestrictionGetNumPointsInElement(CeedElemRestriction rstr, CeedInt elem, CeedInt *num_points) { 15291203703bSJeremy L Thompson CeedRestrictionType rstr_type; 153007d5dec1SJeremy L Thompson const CeedInt *offsets; 153107d5dec1SJeremy L Thompson 15321203703bSJeremy L Thompson CeedCall(CeedElemRestrictionGetType(rstr, &rstr_type)); 15336e536b99SJeremy L Thompson CeedCheck(rstr_type == CEED_RESTRICTION_POINTS, CeedElemRestrictionReturnCeed(rstr), CEED_ERROR_INCOMPATIBLE, 153407d5dec1SJeremy L Thompson "Can only retrieve the number of points for a points CeedElemRestriction"); 153507d5dec1SJeremy L Thompson 153607d5dec1SJeremy L Thompson CeedCall(CeedElemRestrictionGetOffsets(rstr, CEED_MEM_HOST, &offsets)); 153707d5dec1SJeremy L Thompson *num_points = offsets[elem + 1] - offsets[elem]; 153807d5dec1SJeremy L Thompson CeedCall(CeedElemRestrictionRestoreOffsets(rstr, &offsets)); 153907d5dec1SJeremy L Thompson return CEED_ERROR_SUCCESS; 154007d5dec1SJeremy L Thompson } 154107d5dec1SJeremy L Thompson 154207d5dec1SJeremy L Thompson /** 1543ca94c3ddSJeremy L Thompson @brief Get the maximum number of points in an element for a `CeedElemRestriction` at points 15442c7e7413SJeremy L Thompson 1545ca94c3ddSJeremy L Thompson @param[in] rstr `CeedElemRestriction` 15462c7e7413SJeremy L Thompson @param[out] max_points Variable to store size of elements 15472c7e7413SJeremy L Thompson 15482c7e7413SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 15492c7e7413SJeremy L Thompson 15502c7e7413SJeremy L Thompson @ref Advanced 15512c7e7413SJeremy L Thompson **/ 15522c7e7413SJeremy L Thompson int CeedElemRestrictionGetMaxPointsInElement(CeedElemRestriction rstr, CeedInt *max_points) { 15532c7e7413SJeremy L Thompson CeedInt num_elem; 15542c7e7413SJeremy L Thompson CeedRestrictionType rstr_type; 15552c7e7413SJeremy L Thompson 15562c7e7413SJeremy L Thompson CeedCall(CeedElemRestrictionGetType(rstr, &rstr_type)); 15576e536b99SJeremy L Thompson CeedCheck(rstr_type == CEED_RESTRICTION_POINTS, CeedElemRestrictionReturnCeed(rstr), CEED_ERROR_INCOMPATIBLE, 15582c7e7413SJeremy L Thompson "Cannot compute max points for a CeedElemRestriction that does not use points"); 15592c7e7413SJeremy L Thompson 15602c7e7413SJeremy L Thompson CeedCall(CeedElemRestrictionGetNumElements(rstr, &num_elem)); 15612c7e7413SJeremy L Thompson *max_points = 0; 15622c7e7413SJeremy L Thompson for (CeedInt e = 0; e < num_elem; e++) { 15632c7e7413SJeremy L Thompson CeedInt num_points; 15642c7e7413SJeremy L Thompson 15652c7e7413SJeremy L Thompson CeedCall(CeedElemRestrictionGetNumPointsInElement(rstr, e, &num_points)); 15662c7e7413SJeremy L Thompson *max_points = CeedIntMax(num_points, *max_points); 15672c7e7413SJeremy L Thompson } 1568e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 1569a681ae63Sjeremylt } 1570a681ae63Sjeremylt 1571a681ae63Sjeremylt /** 1572ca94c3ddSJeremy L Thompson @brief Get the size of the l-vector for a `CeedElemRestriction` 1573a681ae63Sjeremylt 1574ca94c3ddSJeremy L Thompson @param[in] rstr `CeedElemRestriction` 1575701e7d35SJeremy L Thompson @param[out] l_size Variable to store l-vector size 1576a681ae63Sjeremylt 1577a681ae63Sjeremylt @return An error code: 0 - success, otherwise - failure 1578a681ae63Sjeremylt 1579b7c9bbdaSJeremy L Thompson @ref Advanced 1580a681ae63Sjeremylt **/ 15812b730f8bSJeremy L Thompson int CeedElemRestrictionGetLVectorSize(CeedElemRestriction rstr, CeedSize *l_size) { 1582d1d35e2fSjeremylt *l_size = rstr->l_size; 1583e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 1584a681ae63Sjeremylt } 1585a681ae63Sjeremylt 1586a681ae63Sjeremylt /** 1587701e7d35SJeremy L Thompson @brief Get the size of the e-vector for a `CeedElemRestriction` 1588701e7d35SJeremy L Thompson 1589701e7d35SJeremy L Thompson @param[in] rstr `CeedElemRestriction` 1590701e7d35SJeremy L Thompson @param[out] e_size Variable to store e-vector size 1591701e7d35SJeremy L Thompson 1592701e7d35SJeremy L Thompson @return An error code: 0 - success, otherwise - failure 1593701e7d35SJeremy L Thompson 1594701e7d35SJeremy L Thompson @ref Advanced 1595701e7d35SJeremy L Thompson **/ 1596701e7d35SJeremy L Thompson int CeedElemRestrictionGetEVectorSize(CeedElemRestriction rstr, CeedSize *e_size) { 1597701e7d35SJeremy L Thompson *e_size = rstr->e_size; 1598701e7d35SJeremy L Thompson return CEED_ERROR_SUCCESS; 1599701e7d35SJeremy L Thompson } 1600701e7d35SJeremy L Thompson 1601701e7d35SJeremy L Thompson /** 1602ca94c3ddSJeremy L Thompson @brief Get the number of components in the elements of a `CeedElemRestriction` 1603a681ae63Sjeremylt 1604ca94c3ddSJeremy L Thompson @param[in] rstr `CeedElemRestriction` 1605d1d35e2fSjeremylt @param[out] num_comp Variable to store number of components 1606a681ae63Sjeremylt 1607a681ae63Sjeremylt @return An error code: 0 - success, otherwise - failure 1608a681ae63Sjeremylt 1609b7c9bbdaSJeremy L Thompson @ref Advanced 1610a681ae63Sjeremylt **/ 16112b730f8bSJeremy L Thompson int CeedElemRestrictionGetNumComponents(CeedElemRestriction rstr, CeedInt *num_comp) { 1612d1d35e2fSjeremylt *num_comp = rstr->num_comp; 1613e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 1614a681ae63Sjeremylt } 1615a681ae63Sjeremylt 1616a681ae63Sjeremylt /** 1617ca94c3ddSJeremy L Thompson @brief Get the number of blocks in a `CeedElemRestriction` 1618a681ae63Sjeremylt 1619ca94c3ddSJeremy L Thompson @param[in] rstr `CeedElemRestriction` 1620d1d35e2fSjeremylt @param[out] num_block Variable to store number of blocks 1621a681ae63Sjeremylt 1622a681ae63Sjeremylt @return An error code: 0 - success, otherwise - failure 1623a681ae63Sjeremylt 1624b7c9bbdaSJeremy L Thompson @ref Advanced 1625a681ae63Sjeremylt **/ 16262b730f8bSJeremy L Thompson int CeedElemRestrictionGetNumBlocks(CeedElemRestriction rstr, CeedInt *num_block) { 1627e7f679fcSJeremy L Thompson *num_block = rstr->num_block; 1628e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 1629a681ae63Sjeremylt } 1630a681ae63Sjeremylt 1631a681ae63Sjeremylt /** 1632ca94c3ddSJeremy L Thompson @brief Get the size of blocks in the `CeedElemRestriction` 1633a681ae63Sjeremylt 1634ca94c3ddSJeremy L Thompson @param[in] rstr `CeedElemRestriction` 1635e7f679fcSJeremy L Thompson @param[out] block_size Variable to store size of blocks 1636a681ae63Sjeremylt 1637a681ae63Sjeremylt @return An error code: 0 - success, otherwise - failure 1638a681ae63Sjeremylt 1639b7c9bbdaSJeremy L Thompson @ref Advanced 1640a681ae63Sjeremylt **/ 1641e7f679fcSJeremy L Thompson int CeedElemRestrictionGetBlockSize(CeedElemRestriction rstr, CeedInt *block_size) { 1642e7f679fcSJeremy L Thompson *block_size = rstr->block_size; 1643e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 1644a681ae63Sjeremylt } 1645a681ae63Sjeremylt 1646a681ae63Sjeremylt /** 1647ca94c3ddSJeremy L Thompson @brief Get the multiplicity of nodes in a `CeedElemRestriction` 16481469ee4dSjeremylt 1649ca94c3ddSJeremy L Thompson @param[in] rstr `CeedElemRestriction` 1650ca94c3ddSJeremy L Thompson @param[out] mult Vector to store multiplicity (of size `l_size`) 16511469ee4dSjeremylt 16521469ee4dSjeremylt @return An error code: 0 - success, otherwise - failure 16531469ee4dSjeremylt 16547a982d89SJeremy L. Thompson @ref User 16551469ee4dSjeremylt **/ 16562b730f8bSJeremy L Thompson int CeedElemRestrictionGetMultiplicity(CeedElemRestriction rstr, CeedVector mult) { 1657d1d35e2fSjeremylt CeedVector e_vec; 16581469ee4dSjeremylt 165925509ebbSRezgar Shakeri // Create e_vec to hold intermediate computation in E^T (E 1) 16602b730f8bSJeremy L Thompson CeedCall(CeedElemRestrictionCreateVector(rstr, NULL, &e_vec)); 16611469ee4dSjeremylt 166225509ebbSRezgar Shakeri // Compute e_vec = E * 1 16632b730f8bSJeremy L Thompson CeedCall(CeedVectorSetValue(mult, 1.0)); 16642b730f8bSJeremy L Thompson CeedCall(CeedElemRestrictionApply(rstr, CEED_NOTRANSPOSE, mult, e_vec, CEED_REQUEST_IMMEDIATE)); 166525509ebbSRezgar Shakeri // Compute multiplicity, mult = E^T * e_vec = E^T (E 1) 16662b730f8bSJeremy L Thompson CeedCall(CeedVectorSetValue(mult, 0.0)); 16672b730f8bSJeremy L Thompson CeedCall(CeedElemRestrictionApply(rstr, CEED_TRANSPOSE, e_vec, mult, CEED_REQUEST_IMMEDIATE)); 16681469ee4dSjeremylt // Cleanup 16692b730f8bSJeremy L Thompson CeedCall(CeedVectorDestroy(&e_vec)); 1670e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 16711469ee4dSjeremylt } 16721469ee4dSjeremylt 16731469ee4dSjeremylt /** 1674ca94c3ddSJeremy L Thompson @brief View a `CeedElemRestriction` 1675f02ca4a2SJed Brown 1676ca94c3ddSJeremy L Thompson @param[in] rstr `CeedElemRestriction` to view 1677ca94c3ddSJeremy L Thompson @param[in] stream Stream to write; typically `stdout` or a file 1678f02ca4a2SJed Brown 1679f02ca4a2SJed Brown @return Error code: 0 - success, otherwise - failure 1680f02ca4a2SJed Brown 16817a982d89SJeremy L. Thompson @ref User 1682f02ca4a2SJed Brown **/ 1683f02ca4a2SJed Brown int CeedElemRestrictionView(CeedElemRestriction rstr, FILE *stream) { 16840930e4e7SJeremy L Thompson CeedRestrictionType rstr_type; 16850930e4e7SJeremy L Thompson 16860930e4e7SJeremy L Thompson CeedCall(CeedElemRestrictionGetType(rstr, &rstr_type)); 16870930e4e7SJeremy L Thompson if (rstr_type == CEED_RESTRICTION_POINTS) { 16880930e4e7SJeremy L Thompson CeedInt max_points; 16890930e4e7SJeremy L Thompson 16900930e4e7SJeremy L Thompson CeedCall(CeedElemRestrictionGetMaxPointsInElement(rstr, &max_points)); 16910930e4e7SJeremy L Thompson fprintf(stream, 1692249f8407SJeremy L Thompson "CeedElemRestriction at points from (%" CeedSize_FMT ", %" CeedInt_FMT ") to %" CeedInt_FMT " elements with a maximum of %" CeedInt_FMT 16930930e4e7SJeremy L Thompson " points on an element\n", 16940930e4e7SJeremy L Thompson rstr->l_size, rstr->num_comp, rstr->num_elem, max_points); 16950930e4e7SJeremy L Thompson } else { 1696249f8407SJeremy L Thompson char strides_str[500]; 16971c66c397SJeremy L Thompson 16982b730f8bSJeremy L Thompson if (rstr->strides) { 1699249f8407SJeremy L Thompson sprintf(strides_str, "[%" CeedInt_FMT ", %" CeedInt_FMT ", %" CeedInt_FMT "]", rstr->strides[0], rstr->strides[1], rstr->strides[2]); 17002b730f8bSJeremy L Thompson } else { 1701249f8407SJeremy L Thompson sprintf(strides_str, "%" CeedInt_FMT, rstr->comp_stride); 17022b730f8bSJeremy L Thompson } 1703249f8407SJeremy L Thompson fprintf(stream, 1704249f8407SJeremy L Thompson "%sCeedElemRestriction from (%" CeedSize_FMT ", %" CeedInt_FMT ") to %" CeedInt_FMT " elements with %" CeedInt_FMT 1705249f8407SJeremy L Thompson " nodes each and %s %s\n", 1706e7f679fcSJeremy L Thompson rstr->block_size > 1 ? "Blocked " : "", rstr->l_size, rstr->num_comp, rstr->num_elem, rstr->elem_size, 1707249f8407SJeremy L Thompson rstr->strides ? "strides" : "component stride", strides_str); 17080930e4e7SJeremy L Thompson } 1709e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 1710f02ca4a2SJed Brown } 1711f02ca4a2SJed Brown 1712f02ca4a2SJed Brown /** 1713ca94c3ddSJeremy L Thompson @brief Destroy a `CeedElemRestriction` 1714b11c1e72Sjeremylt 1715ca94c3ddSJeremy L Thompson @param[in,out] rstr `CeedElemRestriction` to destroy 1716b11c1e72Sjeremylt 1717b11c1e72Sjeremylt @return An error code: 0 - success, otherwise - failure 1718dfdf5a53Sjeremylt 17197a982d89SJeremy L. Thompson @ref User 1720b11c1e72Sjeremylt **/ 17214ce2993fSjeremylt int CeedElemRestrictionDestroy(CeedElemRestriction *rstr) { 1722393ac2cdSJeremy L Thompson if (!*rstr || *rstr == CEED_ELEMRESTRICTION_NONE || --(*rstr)->ref_count > 0) { 1723ad6481ceSJeremy L Thompson *rstr = NULL; 1724ad6481ceSJeremy L Thompson return CEED_ERROR_SUCCESS; 1725ad6481ceSJeremy L Thompson } 17266574a04fSJeremy L Thompson CeedCheck((*rstr)->num_readers == 0, (*rstr)->ceed, CEED_ERROR_ACCESS, 17276574a04fSJeremy L Thompson "Cannot destroy CeedElemRestriction, a process has read access to the offset data"); 1728c17ec2beSJeremy L Thompson 1729c17ec2beSJeremy L Thompson // Only destroy backend data once between rstr and unsigned copy 17307c1dbaffSSebastian Grimberg if ((*rstr)->rstr_base) CeedCall(CeedElemRestrictionDestroy(&(*rstr)->rstr_base)); 1731c17ec2beSJeremy L Thompson else if ((*rstr)->Destroy) CeedCall((*rstr)->Destroy(*rstr)); 1732c17ec2beSJeremy L Thompson 17332b730f8bSJeremy L Thompson CeedCall(CeedFree(&(*rstr)->strides)); 17342b730f8bSJeremy L Thompson CeedCall(CeedDestroy(&(*rstr)->ceed)); 17352b730f8bSJeremy L Thompson CeedCall(CeedFree(rstr)); 1736e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 1737d7b241e6Sjeremylt } 1738d7b241e6Sjeremylt 1739d7b241e6Sjeremylt /// @} 1740