Skip to content

Commit

Permalink
Update Julia/Python/Rust/Fortran bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastiangrimberg committed Mar 4, 2023
1 parent 9a9c0ce commit 772e26c
Show file tree
Hide file tree
Showing 6 changed files with 542 additions and 17 deletions.
96 changes: 93 additions & 3 deletions interface/ceed-fortran.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,49 @@ CEED_EXTERN void fCeedElemRestrictionCreate(int *ceed, int *nelements, int *esiz
}
}

#define fCeedElemRestrictionCreateOriented FORTRAN_NAME(ceedelemrestrictioncreateoriented, CEEDELEMRESTRICTIONCREATEORIENTED)
CEED_EXTERN void fCeedElemRestrictionCreateOriented(int *ceed, int *nelements, int *esize, int *num_comp, int *comp_stride, int *lsize, int *memtype,
int *copymode, const int *offsets, const bool *orients, int *elemrestriction, int *err) {
if (CeedElemRestriction_count == CeedElemRestriction_count_max) {
CeedElemRestriction_count_max += CeedElemRestriction_count_max / 2 + 1;
CeedRealloc(CeedElemRestriction_count_max, &CeedElemRestriction_dict);
}

const int *offsets_ = offsets;
const bool *orients_ = orients;

CeedElemRestriction *elemrestriction_ = &CeedElemRestriction_dict[CeedElemRestriction_count];
*err = CeedElemRestrictionCreateOriented(Ceed_dict[*ceed], *nelements, *esize, *num_comp, *comp_stride, *lsize, (CeedMemType)*memtype,
(CeedCopyMode)*copymode, offsets_, orients_, elemrestriction_);

if (*err == 0) {
*elemrestriction = CeedElemRestriction_count++;
CeedElemRestriction_n++;
}
}

#define fCeedElemRestrictionCreateCurlOriented FORTRAN_NAME(ceedelemrestrictioncreatecurloriented, CEEDELEMRESTRICTIONCREATECURLORIENTED)
CEED_EXTERN void fCeedElemRestrictionCreateCurlOriented(int *ceed, int *nelements, int *esize, int *num_comp, int *comp_stride, int *lsize,
int *memtype, int *copymode, const int *offsets, const int *curlorients, int *elemrestriction,
int *err) {
if (CeedElemRestriction_count == CeedElemRestriction_count_max) {
CeedElemRestriction_count_max += CeedElemRestriction_count_max / 2 + 1;
CeedRealloc(CeedElemRestriction_count_max, &CeedElemRestriction_dict);
}

const int *offsets_ = offsets;
const int *curlorients_ = curlorients;

CeedElemRestriction *elemrestriction_ = &CeedElemRestriction_dict[CeedElemRestriction_count];
*err = CeedElemRestrictionCreateCurlOriented(Ceed_dict[*ceed], *nelements, *esize, *num_comp, *comp_stride, *lsize, (CeedMemType)*memtype,
(CeedCopyMode)*copymode, offsets_, curlorients_, elemrestriction_);

if (*err == 0) {
*elemrestriction = CeedElemRestriction_count++;
CeedElemRestriction_n++;
}
}

#define fCeedElemRestrictionCreateStrided FORTRAN_NAME(ceedelemrestrictioncreatestrided, CEEDELEMRESTRICTIONCREATESTRIDED)
CEED_EXTERN void fCeedElemRestrictionCreateStrided(int *ceed, int *nelements, int *esize, int *num_comp, int *lsize, int *strides,
int *elemrestriction, int *err) {
Expand All @@ -258,15 +301,62 @@ CEED_EXTERN void fCeedElemRestrictionCreateStrided(int *ceed, int *nelements, in

#define fCeedElemRestrictionCreateBlocked FORTRAN_NAME(ceedelemrestrictioncreateblocked, CEEDELEMRESTRICTIONCREATEBLOCKED)
CEED_EXTERN void fCeedElemRestrictionCreateBlocked(int *ceed, int *nelements, int *esize, int *blocksize, int *num_comp, int *comp_stride, int *lsize,
int *mtype, int *cmode, int *blkindices, int *elemrestriction, int *err) {
int *memtype, int *copymode, const int *offsets, int *elemrestriction, int *err) {
if (CeedElemRestriction_count == CeedElemRestriction_count_max) {
CeedElemRestriction_count_max += CeedElemRestriction_count_max / 2 + 1;
CeedRealloc(CeedElemRestriction_count_max, &CeedElemRestriction_dict);
}

const int *offsets_ = offsets;

CeedElemRestriction *elemrestriction_ = &CeedElemRestriction_dict[CeedElemRestriction_count];
*err = CeedElemRestrictionCreateBlocked(Ceed_dict[*ceed], *nelements, *esize, *blocksize, *num_comp, *comp_stride, *lsize, (CeedMemType)*memtype,
(CeedCopyMode)*copymode, offsets_, elemrestriction_);

if (*err == 0) {
*elemrestriction = CeedElemRestriction_count++;
CeedElemRestriction_n++;
}
}

#define fCeedElemRestrictionCreateBlockedOriented FORTRAN_NAME(ceedelemrestrictioncreateblockedoriented, CEEDELEMRESTRICTIONCREATEBLOCKEDORIENTED)
CEED_EXTERN void fCeedElemRestrictionCreateBlockedOriented(int *ceed, int *nelements, int *esize, int *blocksize, int *num_comp, int *comp_stride,
int *lsize, int *memtype, int *copymode, const int *offsets, const bool *orients,
int *elemrestriction, int *err) {
if (CeedElemRestriction_count == CeedElemRestriction_count_max) {
CeedElemRestriction_count_max += CeedElemRestriction_count_max / 2 + 1;
CeedRealloc(CeedElemRestriction_count_max, &CeedElemRestriction_dict);
}

const int *offsets_ = offsets;
const bool *orients_ = orients;

CeedElemRestriction *elemrestriction_ = &CeedElemRestriction_dict[CeedElemRestriction_count];
*err = CeedElemRestrictionCreateBlockedOriented(Ceed_dict[*ceed], *nelements, *esize, *blocksize, *num_comp, *comp_stride, *lsize,
(CeedMemType)*memtype, (CeedCopyMode)*copymode, offsets_, orients_, elemrestriction_);

if (*err == 0) {
*elemrestriction = CeedElemRestriction_count++;
CeedElemRestriction_n++;
}
}

#define fCeedElemRestrictionCreateBlockedCurlOriented \
FORTRAN_NAME(ceedelemrestrictioncreateblockedcurloriented, CEEDELEMRESTRICTIONCREATEBLOCKEDCURLORIENTED)
CEED_EXTERN void fCeedElemRestrictionCreateBlockedCurlOriented(int *ceed, int *nelements, int *esize, int *blocksize, int *num_comp, int *comp_stride,
int *lsize, int *memtype, int *copymode, const int *offsets, const int *curlorients,
int *elemrestriction, int *err) {
if (CeedElemRestriction_count == CeedElemRestriction_count_max) {
CeedElemRestriction_count_max += CeedElemRestriction_count_max / 2 + 1;
CeedRealloc(CeedElemRestriction_count_max, &CeedElemRestriction_dict);
}

const int *offsets_ = offsets;
const int *curlorients_ = curlorients;

CeedElemRestriction *elemrestriction_ = &CeedElemRestriction_dict[CeedElemRestriction_count];
*err = CeedElemRestrictionCreateBlocked(Ceed_dict[*ceed], *nelements, *esize, *blocksize, *num_comp, *comp_stride, *lsize, (CeedMemType)*mtype,
(CeedCopyMode)*cmode, blkindices, elemrestriction_);
*err = CeedElemRestrictionCreateBlockedCurlOriented(Ceed_dict[*ceed], *nelements, *esize, *blocksize, *num_comp, *comp_stride, *lsize,
(CeedMemType)*memtype, (CeedCopyMode)*copymode, offsets_, curlorients_, elemrestriction_);

if (*err == 0) {
*elemrestriction = CeedElemRestriction_count++;
Expand Down
138 changes: 138 additions & 0 deletions julia/LibCEED.jl/src/ElemRestriction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,144 @@ function create_elem_restriction(
ElemRestriction(ref)
end

@doc raw"""
create_elem_restriction_oriented(
ceed::Ceed,
nelem,
elemsize,
ncomp,
compstride,
lsize,
offsets::AbstractArray{CeedInt},
orients::AbstractArray{Bool},
mtype::MemType=MEM_HOST,
cmode::CopyMode=COPY_VALUES,
)
Create an oriented `CeedElemRestriction`.
!!! warning "Zero-based indexing"
In the below notation, we are using **0-based indexing**. libCEED expects the offset
indices to be 0-based.
# Arguments:
- `ceed`: The [`Ceed`](@ref) object
- `nelem`: Number of elements described in the `offsets` array
- `elemsize`: Size (number of "nodes") per element
- `ncomp`: Number of field components per interpolation node (1 for scalar fields)
- `compstride`: Stride between components for the same L-vector "node". Data for node $i$,
component $j$, element $k$ can be found in the L-vector at index `offsets[i
+ k*elemsize] + j*compstride`.
- `lsize`: The size of the L-vector. This vector may be larger than the elements and
fields given by this restriction.
- `offsets`: Array of shape `(elemsize, nelem)`. Column $i$ holds the ordered list of the
offsets (into the input [`CeedVector`](@ref)) for the unknowns corresponding
to element $i$, where $0 \leq i < \textit{nelem}$. All offsets must be in
the range $[0, \textit{lsize} - 1]$.
- `orients`: Array of shape `(elemsize, nelem)` with bool false for positively oriented
and true to flip the orientation.
- `mtype`: Memory type of the `offsets` array, see [`MemType`](@ref)
- `cmode`: Copy mode for the `offsets` array, see [`CopyMode`](@ref)
"""
function create_elem_restriction(
c::Ceed,
nelem,
elemsize,
ncomp,
compstride,
lsize,
offsets::AbstractArray{CeedInt},
orients::AbstractArray{Bool};
mtype::MemType=MEM_HOST,
cmode::CopyMode=COPY_VALUES,
)
ref = Ref{C.CeedElemRestriction}()
C.CeedElemRestrictionCreateOriented(
c[],
nelem,
elemsize,
ncomp,
compstride,
lsize,
mtype,
cmode,
offsets,
orients,
ref,
)
ElemRestriction(ref)
end

@doc raw"""
create_elem_restriction_curl_oriented(
ceed::Ceed,
nelem,
elemsize,
ncomp,
compstride,
lsize,
offsets::AbstractArray{CeedInt},
curl_orients::AbstractArray{CeedInt},
mtype::MemType=MEM_HOST,
cmode::CopyMode=COPY_VALUES,
)
Create an curl-oriented `CeedElemRestriction`.
!!! warning "Zero-based indexing"
In the below notation, we are using **0-based indexing**. libCEED expects the offset
indices to be 0-based.
# Arguments:
- `ceed`: The [`Ceed`](@ref) object
- `nelem`: Number of elements described in the `offsets` array
- `elemsize`: Size (number of "nodes") per element
- `ncomp`: Number of field components per interpolation node (1 for scalar fields)
- `compstride`: Stride between components for the same L-vector "node". Data for node $i$,
component $j$, element $k$ can be found in the L-vector at index `offsets[i
+ k*elemsize] + j*compstride`.
- `lsize`: The size of the L-vector. This vector may be larger than the elements and
fields given by this restriction.
- `offsets`: Array of shape `(elemsize, nelem)`. Column $i$ holds the ordered list of
the offsets (into the input [`CeedVector`](@ref)) for the unknowns
corresponding to element $i$, where $0 \leq i < \textit{nelem}$. All
offsets must be in the range $[0, \textit{lsize} - 1]$.
- `curlorients`: Array of shape `(3 * elemsize, nelem)` representing a row-major tridiagonal
matrix (`curlorients[0] = curlorients[(i + 1) * 3 * elemsize - 1] = 0`,
where `0 <= i < nelem`) which is applied to the element unknowns upon
restriction.
- `mtype`: Memory type of the `offsets` array, see [`MemType`](@ref)
- `cmode`: Copy mode for the `offsets` array, see [`CopyMode`](@ref)
"""
function create_elem_restriction(
c::Ceed,
nelem,
elemsize,
ncomp,
compstride,
lsize,
offsets::AbstractArray{CeedInt},
curlorients::AbstractArray{CeedInt};
mtype::MemType=MEM_HOST,
cmode::CopyMode=COPY_VALUES,
)
ref = Ref{C.CeedElemRestriction}()
C.CeedElemRestrictionCreateCurlOriented(
c[],
nelem,
elemsize,
ncomp,
compstride,
lsize,
mtype,
cmode,
offsets,
curlorients,
ref,
)
ElemRestriction(ref)
end

@doc raw"""
create_elem_restriction_strided(ceed::Ceed, nelem, elemsize, ncomp, lsize, strides)
Expand Down

0 comments on commit 772e26c

Please sign in to comment.