-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1510 from CEED/jrwrigh/fluids_matceed
fluids: Add MatCeed
- Loading branch information
Showing
17 changed files
with
1,646 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#ifndef MAT_CEED_IMPL_H | ||
#define MAT_CEED_IMPL_H | ||
|
||
#include <ceed.h> | ||
#include <petscdm.h> | ||
#include <petscmat.h> | ||
|
||
#if defined(__clang_analyzer__) | ||
#define MATCEED_EXTERN extern | ||
#elif defined(__cplusplus) | ||
#define MATCEED_EXTERN extern "C" | ||
#else | ||
#define MATCEED_EXTERN extern | ||
#endif | ||
|
||
#if defined(__clang_analyzer__) | ||
#define MATCEED_INTERN | ||
#else | ||
#define MATCEED_INTERN MATCEED_EXTERN __attribute__((visibility("hidden"))) | ||
#endif | ||
|
||
/** | ||
@brief Calls a libCEED function and then checks the resulting error code. | ||
If the error code is non-zero, then a PETSc error is set with the libCEED error message. | ||
**/ | ||
#define PetscCallCeed(ceed_, ...) \ | ||
do { \ | ||
int ierr_q_ = __VA_ARGS__; \ | ||
if (ierr_q_ != CEED_ERROR_SUCCESS) { \ | ||
const char *error_message; \ | ||
CeedGetErrorMessage(ceed_, &error_message); \ | ||
SETERRQ(PETSC_COMM_SELF, PETSC_ERR_LIB, "%s", error_message); \ | ||
} \ | ||
} while (0) | ||
|
||
// MatCeed context for applying composite CeedOperator on a DM | ||
typedef struct MatCeedContext_private *MatCeedContext; | ||
struct MatCeedContext_private { | ||
Ceed ceed; | ||
char *name, *internal_mat_type; | ||
PetscMemType mem_type; | ||
PetscInt ref_count, num_mats_assembled_full, num_mats_assembled_pbd; | ||
PetscBool is_destroyed, is_ceed_pbd_valid, is_ceed_vpbd_valid; | ||
PetscLogEvent log_event_mult, log_event_mult_transpose; | ||
DM dm_x, dm_y; | ||
Mat *mats_assembled_full, *mats_assembled_pbd, mat_assembled_full_internal, mat_assembled_pbd_internal; | ||
Vec X_loc, Y_loc_transpose; | ||
CeedVector x_loc, y_loc, coo_values_full, coo_values_pbd; | ||
CeedOperator op_mult, op_mult_transpose; | ||
PetscLogDouble flops_mult, flops_mult_transpose; | ||
}; | ||
|
||
// Context data | ||
MATCEED_INTERN PetscErrorCode MatCeedContextCreate(DM dm_x, DM dm_y, Vec X_loc, Vec Y_loc_transpose, CeedOperator op_mult, | ||
CeedOperator op_mult_transpose, PetscLogEvent log_event_mult, | ||
PetscLogEvent log_event_mult_transpose, MatCeedContext *ctx); | ||
MATCEED_INTERN PetscErrorCode MatCeedContextReference(MatCeedContext ctx); | ||
MATCEED_INTERN PetscErrorCode MatCeedContextReferenceCopy(MatCeedContext ctx, MatCeedContext *ctx_copy); | ||
MATCEED_INTERN PetscErrorCode MatCeedContextDestroy(MatCeedContext ctx); | ||
|
||
// Mat Ceed | ||
MATCEED_INTERN PetscErrorCode MatGetDiagonal_Ceed(Mat A, Vec D); | ||
MATCEED_INTERN PetscErrorCode MatMult_Ceed(Mat A, Vec X, Vec Y); | ||
MATCEED_INTERN PetscErrorCode MatMultTranspose_Ceed(Mat A, Vec Y, Vec X); | ||
|
||
extern PetscClassId MATCEED_CLASSID; | ||
extern PetscLogEvent MATCEED_MULT, MATCEED_MULT_TRANSPOSE; | ||
|
||
#endif // MAT_CEED_IMPL_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#ifndef MAT_CEED_H | ||
#define MAT_CEED_H | ||
|
||
#include <ceed.h> | ||
#include <petscdm.h> | ||
#include <petscmat.h> | ||
|
||
#define MATCEED "ceed" | ||
|
||
#if defined(__clang_analyzer__) | ||
#define MATCEED_EXTERN extern | ||
#elif defined(__cplusplus) | ||
#define MATCEED_EXTERN extern "C" | ||
#else | ||
#define MATCEED_EXTERN extern | ||
#endif | ||
|
||
#if defined(__clang_analyzer__) | ||
#define MATCEED_INTERN | ||
#else | ||
#define MATCEED_INTERN MATCEED_EXTERN __attribute__((visibility("hidden"))) | ||
#endif | ||
|
||
// Context data | ||
MATCEED_INTERN PetscErrorCode MatCeedCreate(DM dm_x, DM dm_y, CeedOperator op_mult, CeedOperator op_mult_transpose, Mat *mat); | ||
MATCEED_INTERN PetscErrorCode MatCeedCopy(Mat mat_ceed, Mat mat_other); | ||
MATCEED_INTERN PetscErrorCode MatCeedAssembleCOO(Mat mat_ceed, Mat mat_coo); | ||
MATCEED_INTERN PetscErrorCode MatCeedSetContext(Mat mat, PetscErrorCode (*f)(void *), void *ctx); | ||
MATCEED_INTERN PetscErrorCode MatCeedGetContext(Mat mat, void *ctx); | ||
MATCEED_INTERN PetscErrorCode MatCeedSetInnerMatType(Mat mat, MatType type); | ||
MATCEED_INTERN PetscErrorCode MatCeedGetInnerMatType(Mat mat, MatType *type); | ||
MATCEED_INTERN PetscErrorCode MatCeedSetOperation(Mat mat, MatOperation op, void (*g)(void)); | ||
MATCEED_INTERN PetscErrorCode MatCeedSetLocalVectors(Mat mat, Vec X_loc, Vec Y_loc_transpose); | ||
MATCEED_INTERN PetscErrorCode MatCeedGetLocalVectors(Mat mat, Vec *X_loc, Vec *Y_loc_transpose); | ||
MATCEED_INTERN PetscErrorCode MatCeedRestoreLocalVectors(Mat mat, Vec *X_loc, Vec *Y_loc_transpose); | ||
MATCEED_INTERN PetscErrorCode MatCeedGetCeedOperators(Mat mat, CeedOperator *op_mult, CeedOperator *op_mult_transpose); | ||
MATCEED_INTERN PetscErrorCode MatCeedRestoreCeedOperators(Mat mat, CeedOperator *op_mult, CeedOperator *op_mult_transpose); | ||
MATCEED_INTERN PetscErrorCode MatCeedSetLogEvents(Mat mat, PetscLogEvent log_event_mult, PetscLogEvent log_event_mult_transpose); | ||
MATCEED_INTERN PetscErrorCode MatCeedGetLogEvents(Mat mat, PetscLogEvent *log_event_mult, PetscLogEvent *log_event_mult_transpose); | ||
|
||
#endif // MAT_CEED_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.