CeedVector
A CeedVector constitutes the main data structure and serves as input/output for the CeedOperators.
Basic vector operations
-
typedef struct CeedVector_private *CeedVector
Handle for vectors over the field CeedScalar.
-
const CeedVector CEED_VECTOR_ACTIVE = &ceed_vector_active
Indicate that vector will be provided as an explicit argument to CeedOperatorApply().
-
const CeedVector CEED_VECTOR_NONE = &ceed_vector_none
Indicate that no vector is applicable (i.e., for CEED_EVAL_WEIGHT).
-
int CeedVectorCreate(Ceed ceed, CeedSize length, CeedVector *vec)
Create a
CeedVectorof the specified length (does not allocate memory)User Functions
- Parameters:
ceed – [in]
Ceedobject used to create theCeedVectorlength – [in] Length of vector
vec – [out] Address of the variable where the newly created
CeedVectorwill be stored
- Returns:
An error code: 0 - success, otherwise - failure
-
int CeedVectorReferenceCopy(CeedVector vec, CeedVector *vec_copy)
Copy the pointer to a
CeedVector.Both pointers should be destroyed with CeedVectorDestroy().
Note: If the value of
*vec_copypassed to this function is non-NULL, then it is assumed that*vec_copyis a pointer to aCeedVector. ThisCeedVectorwill be destroyed if*vec_copyis the only reference to thisCeedVector.User Functions
- Parameters:
vec – [in]
CeedVectorto copy reference tovec_copy – [inout] Variable to store copied reference
- Returns:
An error code: 0 - success, otherwise - failure
-
int CeedVectorCopy(CeedVector vec, CeedVector vec_copy)
Copy a
CeedVectorinto a differentCeedVector.User Functions
- Parameters:
vec – [in]
CeedVectorto copyvec_copy – [inout]
CeedVectorto copy array into
- Returns:
An error code: 0 - success, otherwise - failure
-
int CeedVectorCopyStrided(CeedVector vec, CeedSize start, CeedSize stop, CeedSize step, CeedVector vec_copy)
Copy a strided portion of
CeedVectorcontents into a differentCeedVectorUser Functions
- Parameters:
vec – [in]
CeedVectorto copystart – [in] First index to copy in the range
[start, stop)stop – [in] One past the last element to copy in the range, or
-1forlengthstep – [in] Stride between indices to copy
vec_copy – [inout]
CeedVectorto copy values to
- Returns:
An error code: 0 - success, otherwise - failure
-
int CeedVectorSetArray(CeedVector vec, CeedMemType mem_type, CeedCopyMode copy_mode, CeedScalar *array)
Set the array used by a
CeedVector, freeing any previously allocated array if applicable.The backend may copy values to a different CeedMemType, such as during CeedOperatorApply(). See also CeedVectorSyncArray() and CeedVectorTakeArray().
User Functions
- Parameters:
vec – [inout]
CeedVectormem_type – [in] Memory type of the array being passed
copy_mode – [in] Copy mode for the array
array – [in] Array to be used, or
NULLwith CEED_COPY_VALUES to have the library allocate
- Returns:
An error code: 0 - success, otherwise - failure
-
int CeedVectorSetValue(CeedVector vec, CeedScalar value)
Set the
CeedVectorto a constant value.User Functions
- Parameters:
vec – [inout]
CeedVectorvalue – [in] Value to be used
- Returns:
An error code: 0 - success, otherwise - failure
-
int CeedVectorSetValueStrided(CeedVector vec, CeedSize start, CeedSize stop, CeedSize step, CeedScalar value)
Set a portion of a
CeedVectorto a constant value.Note: The
CeedVectormust already have valid data set via CeedVectorSetArray() or similar.User Functions
- Parameters:
vec – [inout]
CeedVectorstart – [in] First index to set in range
[start, stop)stop – [in] One past the last element to set in the range, or
-1forlengthstep – [in] Stride between indices to set
value – [in] Value to be used
- Returns:
An error code: 0 - success, otherwise - failure
-
int CeedVectorSyncArray(CeedVector vec, CeedMemType mem_type)
Sync the
CeedVectorto a specifiedmem_type.This function is used to force synchronization of arrays set with CeedVectorSetArray(). If the requested
mem_typeis already synchronized, this function results in a no-op.User Functions
- Parameters:
vec – [inout]
CeedVectormem_type – [in] CeedMemType to be synced
- Returns:
An error code: 0 - success, otherwise - failure
-
int CeedVectorTakeArray(CeedVector vec, CeedMemType mem_type, CeedScalar **array)
Take ownership of the
CeedVectorarray set by CeedVectorSetArray() with CEED_USE_POINTER and remove the array from theCeedVector.The caller is responsible for managing and freeing the array. This function will error if CeedVectorSetArray() was not previously called with CEED_USE_POINTER for the corresponding mem_type.
User Functions
- Parameters:
vec – [inout]
CeedVectormem_type – [in] Memory type on which to take the array. If the backend uses a different memory type, this will perform a copy.
array – [out] Array on memory type
mem_type, orNULLif array pointer is not required
- Returns:
An error code: 0 - success, otherwise - failure
-
int CeedVectorGetArray(CeedVector vec, CeedMemType mem_type, CeedScalar **array)
Get read/write access to a
CeedVectorvia the specified memory type.Restore access with CeedVectorRestoreArray().
User Functions
Note
The CeedVectorGetArray() and CeedVectorRestoreArray() functions provide access to array pointers in the desired memory space. Pairing get/restore allows the
CeedVectorto track access, thus knowing if norms or other operations may need to be recomputed.- Parameters:
vec – [inout]
CeedVectorto accessmem_type – [in] Memory type on which to access the array. If the backend uses a different memory type, this will perform a copy.
array – [out] Array on memory type
mem_type
- Returns:
An error code: 0 - success, otherwise - failure
-
int CeedVectorGetArrayRead(CeedVector vec, CeedMemType mem_type, const CeedScalar **array)
Get read-only access to a
CeedVectorvia the specified memory type.Restore access with CeedVectorRestoreArrayRead().
User Functions
- Parameters:
vec – [in]
CeedVectorto accessmem_type – [in] Memory type on which to access the array. If the backend uses a different memory type, this will perform a copy (possibly cached).
array – [out] Array on memory type
mem_type
- Returns:
An error code: 0 - success, otherwise - failure
-
int CeedVectorGetArrayWrite(CeedVector vec, CeedMemType mem_type, CeedScalar **array)
Get write access to a
CeedVectorvia the specified memory type.Restore access with CeedVectorRestoreArray(). All old values should be assumed to be invalid.
User Functions
- Parameters:
vec – [inout]
CeedVectorto accessmem_type – [in] Memory type on which to access the array.
array – [out] Array on memory type
mem_type
- Returns:
An error code: 0 - success, otherwise - failure
-
int CeedVectorRestoreArray(CeedVector vec, CeedScalar **array)
Restore an array obtained using CeedVectorGetArray() or CeedVectorGetArrayWrite()
User Functions
- Parameters:
vec – [inout]
CeedVectorto restorearray – [inout] Array of vector data
- Returns:
An error code: 0 - success, otherwise - failure
-
int CeedVectorRestoreArrayRead(CeedVector vec, const CeedScalar **array)
Restore an array obtained using CeedVectorGetArrayRead()
User Functions
- Parameters:
vec – [in]
CeedVectorto restorearray – [inout] Array of vector data
- Returns:
An error code: 0 - success, otherwise - failure
-
int CeedVectorNorm(CeedVector vec, CeedNormType norm_type, CeedScalar *norm)
Get the norm of a
CeedVector.Note: This operation is local to the
CeedVector. This function will likely not provide the desired results for the norm of the libCEED portion of a parallel vector or aCeedVectorwith duplicated or hanging nodes.User Functions
- Parameters:
vec – [in]
CeedVectorto retrieve maximum valuenorm_type – [in] Norm type CEED_NORM_1, CEED_NORM_2, or CEED_NORM_MAX
norm – [out] Variable to store norm value
- Returns:
An error code: 0 - success, otherwise - failure
-
int CeedVectorScale(CeedVector x, CeedScalar alpha)
Compute
x = alpha xUser Functions
- Parameters:
x – [inout]
CeedVectorfor scalingalpha – [in] scaling factor
- Returns:
An error code: 0 - success, otherwise - failure
-
int CeedVectorAXPY(CeedVector y, CeedScalar alpha, CeedVector x)
Compute
y = alpha x + yUser Functions
- Parameters:
y – [inout] target
CeedVectorfor sumalpha – [in] scaling factor
x – [in] second
CeedVector, must be different thany
- Returns:
An error code: 0 - success, otherwise - failure
-
int CeedVectorAXPBY(CeedVector y, CeedScalar alpha, CeedScalar beta, CeedVector x)
Compute
y = alpha x + beta yUser Functions
- Parameters:
y – [inout] target
CeedVectorfor sumalpha – [in] first scaling factor
beta – [in] second scaling factor
x – [in] second
CeedVector, must be different thany
- Returns:
An error code: 0 - success, otherwise - failure
-
int CeedVectorPointwiseMult(CeedVector w, CeedVector x, CeedVector y)
Compute the pointwise multiplication \(w = x .* y\).
Any subset of
x,y, andwmay be the sameCeedVector.User Functions
- Parameters:
w – [out] target
CeedVectorfor the productx – [in] first
CeedVectorfor producty – [in] second
CeedVectorfor the product
- Returns:
An error code: 0 - success, otherwise - failure
-
int CeedVectorReciprocal(CeedVector vec)
Take the reciprocal of a
CeedVector.User Functions
- Parameters:
vec – [inout]
CeedVectorto take reciprocal
- Returns:
An error code: 0 - success, otherwise - failure
-
int CeedVectorSetNumViewTabs(CeedVector vec, CeedInt num_tabs)
Set the number of tabs to indent for CeedVectorView() output.
User Functions
- Parameters:
vec – [in]
CeedVectorto set the number of view tabsnum_tabs – [in] Number of view tabs to set
- Returns:
Error code: 0 - success, otherwise - failure
-
int CeedVectorGetNumViewTabs(CeedVector vec, CeedInt *num_tabs)
Get the number of tabs to indent for CeedVectorView() output.
User Functions
- Parameters:
vec – [in]
CeedVectorto get the number of view tabsnum_tabs – [out] Number of view tabs
- Returns:
Error code: 0 - success, otherwise - failure
-
int CeedVectorViewRange(CeedVector vec, CeedSize start, CeedSize stop, CeedInt step, const char *fp_fmt, FILE *stream)
View a
CeedVectorNote: It is safe to use any unsigned values for
startorstopand any nonzero integer forstep. Any portion of the provided range that is outside the range of valid indices for theCeedVectorwill be ignored.User Functions
- Parameters:
vec – [in]
CeedVectorto viewstart – [in] Index of first
CeedVectorentry to view in the range[start, stop)stop – [in] One past the last element to view in the range, or
-1forlengthstep – [in] Step between
CeedVectorentries to viewfp_fmt – [in] Printing format
stream – [in] Filestream to write to
- Returns:
An error code: 0 - success, otherwise - failure
-
int CeedVectorView(CeedVector vec, const char *fp_fmt, FILE *stream)
View a
CeedVectorUser Functions
- Parameters:
vec – [in]
CeedVectorto viewfp_fmt – [in] Printing format
stream – [in] Filestream to write to
- Returns:
An error code: 0 - success, otherwise - failure
-
int CeedVectorGetCeed(CeedVector vec, Ceed *ceed)
Get the
Ceedassociated with aCeedVectorAdvanced Functions
- Parameters:
vec – [in]
CeedVectorto retrieve stateceed – [out] Variable to store
Ceed
- Returns:
An error code: 0 - success, otherwise - failure
-
Ceed CeedVectorReturnCeed(CeedVector vec)
Return the
Ceedassociated with aCeedVectorAdvanced Functions
- Parameters:
vec – [in]
CeedVectorto retrieve state
- Returns:
Ceedassociated with thevec
-
int CeedVectorGetLength(CeedVector vec, CeedSize *length)
Get the length of a
CeedVectorUser Functions
- Parameters:
vec – [in]
CeedVectorto retrieve lengthlength – [out] Variable to store length
- Returns:
An error code: 0 - success, otherwise - failure
-
int CeedVectorDestroy(CeedVector *vec)
Destroy a
CeedVectorUser Functions
- Parameters:
vec – [inout]
CeedVectorto destroy
- Returns:
An error code: 0 - success, otherwise - failure
Typedefs and Enumerations
-
typedef int32_t CeedInt
Integer type, used for indexing.
-
typedef float CeedScalar
-
enum CeedCopyMode
Conveys ownership status of arrays passed to Ceed interfaces.
Values:
-
enumerator CEED_COPY_VALUES
Implementation will copy the values and not store the passed pointer.
-
enumerator CEED_USE_POINTER
Implementation can use and modify the data provided by the user, but does not take ownership.
-
enumerator CEED_OWN_POINTER
Implementation takes ownership of the pointer and will free using CeedFree() when done using it.
The user should not assume that the pointer remains valid after ownership has been transferred. Note that arrays allocated using C++ operator new or other allocators cannot generally be freed using CeedFree(). CeedFree() is capable of freeing any memory that can be freed using free().
-
enumerator CEED_COPY_VALUES