Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions include/ceed-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ struct Ceed_private {
bool cuda_compile_with_clang;
char **jit_defines;
CeedInt num_jit_defines, max_jit_defines, num_jit_defines_readers;
CeedInt num_tabs; /* Viewing offset */
int (*Error)(Ceed, const char *, int, const char *, int, const char *, va_list *);
int (*SetStream)(Ceed, void *);
int (*GetPreferredMemType)(CeedMemType *);
Expand Down Expand Up @@ -160,6 +161,7 @@ struct CeedVector_private {
CeedSize length;
uint64_t state;
uint64_t num_readers;
CeedInt num_tabs; /* Viewing offset */
void *data;
};

Expand Down Expand Up @@ -192,6 +194,7 @@ struct CeedElemRestriction_private {
CeedRestrictionType
rstr_type; /* initialized in element restriction constructor for default, oriented, curl-oriented, or strided element restriction */
uint64_t num_readers; /* number of instances of offset read only access */
CeedInt num_tabs; /* Viewing offset */
void *data; /* place for the backend to store any data */
};

Expand Down Expand Up @@ -225,6 +228,7 @@ struct CeedBasis_private {
quadrature points for H(curl) discretizations */
CeedVector vec_chebyshev;
CeedBasis basis_chebyshev; /* basis interpolating from nodes to Chebyshev polynomial coefficients */
CeedInt num_tabs; /* Viewing offset */
void *data; /* place for the backend to store any data */
};

Expand All @@ -251,6 +255,7 @@ struct CeedQFunction_private {
int (*Destroy)(CeedQFunction);
int ref_count;
CeedInt vec_length; /* Number of quadrature points must be padded to a multiple of vec_length */
CeedInt num_tabs; /* Viewing offset */
CeedQFunctionField *input_fields;
CeedQFunctionField *output_fields;
CeedInt num_input_fields, num_output_fields;
Expand Down Expand Up @@ -286,6 +291,7 @@ struct CeedQFunctionContext_private {
CeedMemType data_destroy_mem_type;
CeedInt num_fields;
CeedInt max_fields;
CeedInt num_tabs; /* Viewing offset */
CeedContextFieldLabel *field_labels;
uint64_t state;
uint64_t num_readers;
Expand Down
10 changes: 10 additions & 0 deletions include/ceed/backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@
#define CeedPragmaCritical(x) CeedPragmaOMP(critical(x))
#endif

/// This macro provides the tab width for viewing Ceed objects.
/// @ingroup Ceed
#define CEED_TAB_WIDTH 2

/**
This enum supplies common colors for CeedDebug256 debugging output.
Set the environment variable `CEED_DEBUG = 1` to activate debugging output.
Expand Down Expand Up @@ -248,6 +252,7 @@ CEED_EXTERN int CeedGetObjectDelegate(Ceed ceed, Ceed *delegate, const char *obj
CEED_EXTERN int CeedSetObjectDelegate(Ceed ceed, Ceed delegate, const char *obj_name);
CEED_EXTERN int CeedGetOperatorFallbackCeed(Ceed ceed, Ceed *fallback_ceed);
CEED_EXTERN int CeedSetOperatorFallbackCeed(Ceed ceed, Ceed fallback_ceed);
CEED_EXTERN int CeedGetNumViewTabs(Ceed ceed, CeedInt *num_tabs);
CEED_EXTERN int CeedSetDeterministic(Ceed ceed, bool is_deterministic);
CEED_EXTERN int CeedSetBackendFunctionImpl(Ceed ceed, const char *type, void *object, const char *func_name, void (*f)(void));
CEED_EXTERN int CeedGetData(Ceed ceed, void *data);
Expand All @@ -264,6 +269,7 @@ CEED_EXTERN int CeedRestoreRustSourceRoots(Ceed ceed, const char ***rust_source_
CEED_EXTERN int CeedGetJitDefines(Ceed ceed, CeedInt *num_defines, const char ***jit_defines);
CEED_EXTERN int CeedRestoreJitDefines(Ceed ceed, const char ***jit_defines);

CEED_EXTERN int CeedVectorGetNumViewTabs(CeedVector vec, CeedInt *num_tabs);
CEED_EXTERN int CeedVectorHasValidArray(CeedVector vec, bool *has_valid_array);
CEED_EXTERN int CeedVectorHasBorrowedArrayOfType(CeedVector vec, CeedMemType mem_type, bool *has_borrowed_array_of_type);
CEED_EXTERN int CeedVectorHasValidArray(CeedVector vec, bool *has_valid_array);
Expand Down Expand Up @@ -292,6 +298,7 @@ typedef enum {
} CeedRestrictionType;

CEED_EXTERN int CeedElemRestrictionGetType(CeedElemRestriction rstr, CeedRestrictionType *rstr_type);
CEED_EXTERN int CeedElemRestrictionGetNumViewTabs(CeedElemRestriction rstr, CeedInt *num_tabs);
CEED_EXTERN int CeedElemRestrictionIsStrided(CeedElemRestriction rstr, bool *is_strided);
CEED_EXTERN int CeedElemRestrictionIsAtPoints(CeedElemRestriction rstr, bool *is_points);
CEED_EXTERN int CeedElemRestrictionAtPointsAreCompatible(CeedElemRestriction rstr_a, CeedElemRestriction rstr_b, bool *are_compatible);
Expand Down Expand Up @@ -332,6 +339,7 @@ CEED_EXTERN const char *const CeedFESpaces[];

CEED_EXTERN int CeedBasisGetCollocatedGrad(CeedBasis basis, CeedScalar *colo_grad_1d);
CEED_EXTERN int CeedBasisGetChebyshevInterp1D(CeedBasis basis, CeedScalar *chebyshev_interp_1d);
CEED_EXTERN int CeedBasisGetNumViewTabs(CeedBasis basis, CeedInt *num_tabs);
CEED_EXTERN int CeedBasisIsTensor(CeedBasis basis, bool *is_tensor);
CEED_EXTERN int CeedBasisIsCollocated(CeedBasis basis, bool *is_collocated);
CEED_EXTERN int CeedBasisGetData(CeedBasis basis, void *data);
Expand Down Expand Up @@ -372,6 +380,7 @@ CEED_EXTERN int CeedQFunctionGetName(CeedQFunction qf, const char **name);
CEED_EXTERN int CeedQFunctionGetSourcePath(CeedQFunction qf, const char **source_path);
CEED_EXTERN int CeedQFunctionLoadSourceToBuffer(CeedQFunction qf, const char **source_buffer);
CEED_EXTERN int CeedQFunctionGetUserFunction(CeedQFunction qf, CeedQFunctionUser *f);
CEED_EXTERN int CeedQFunctionGetNumViewTabs(CeedQFunction qf, CeedInt *num_tabs);
CEED_EXTERN int CeedQFunctionGetContext(CeedQFunction qf, CeedQFunctionContext *ctx);
CEED_EXTERN int CeedQFunctionGetContextData(CeedQFunction qf, CeedMemType mem_type, void *data);
CEED_EXTERN int CeedQFunctionRestoreContextData(CeedQFunction qf, void *data);
Expand All @@ -389,6 +398,7 @@ CEED_EXTERN int CeedQFunctionGetFlopsEstimate(CeedQFunction qf, CeedSize *flops)

CEED_EXTERN int CeedQFunctionContextGetCeed(CeedQFunctionContext ctx, Ceed *ceed);
CEED_EXTERN Ceed CeedQFunctionContextReturnCeed(CeedQFunctionContext ctx);
CEED_EXTERN int CeedQFunctionContextGetNumViewTabs(CeedQFunctionContext ctx, CeedInt *num_tabs);
CEED_EXTERN int CeedQFunctionContextHasValidData(CeedQFunctionContext ctx, bool *has_valid_data);
CEED_EXTERN int CeedQFunctionContextHasBorrowedDataOfType(CeedQFunctionContext ctx, CeedMemType mem_type, bool *has_borrowed_data_of_type);
CEED_EXTERN int CeedQFunctionContextGetState(CeedQFunctionContext ctx, uint64_t *state);
Expand Down
6 changes: 6 additions & 0 deletions include/ceed/ceed.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ CEED_EXTERN int CeedIsDeterministic(Ceed ceed, bool *is_deterministic);
CEED_EXTERN int CeedAddJitSourceRoot(Ceed ceed, const char *jit_source_root);
CEED_EXTERN int CeedAddRustSourceRoot(Ceed ceed, const char *rust_source_root);
CEED_EXTERN int CeedAddJitDefine(Ceed ceed, const char *jit_define);
CEED_EXTERN int CeedSetNumViewTabs(Ceed ceed, CeedInt num_tabs);
CEED_EXTERN int CeedView(Ceed ceed, FILE *stream);
CEED_EXTERN int CeedDestroy(Ceed *ceed);
CEED_EXTERN int CeedErrorImpl(Ceed ceed, const char *filename, int lineno, const char *func, int ecode, const char *format, ...);
Expand Down Expand Up @@ -204,6 +205,7 @@ CEED_EXTERN int CeedVectorAXPY(CeedVector y, CeedScalar alpha, CeedVector x);
CEED_EXTERN int CeedVectorAXPBY(CeedVector y, CeedScalar alpha, CeedScalar beta, CeedVector x);
CEED_EXTERN int CeedVectorPointwiseMult(CeedVector w, CeedVector x, CeedVector y);
CEED_EXTERN int CeedVectorReciprocal(CeedVector vec);
CEED_EXTERN int CeedVectorSetNumViewTabs(CeedVector vec, CeedInt num_tabs);
CEED_EXTERN int CeedVectorViewRange(CeedVector vec, CeedSize start, CeedSize stop, CeedInt step, const char *fp_fmt, FILE *stream);
CEED_EXTERN int CeedVectorView(CeedVector vec, const char *fp_fmt, FILE *stream);
CEED_EXTERN int CeedVectorGetCeed(CeedVector vec, Ceed *ceed);
Expand Down Expand Up @@ -293,6 +295,7 @@ CEED_EXTERN int CeedElemRestrictionGetNumComponents(CeedElemRestriction rstr, C
CEED_EXTERN int CeedElemRestrictionGetNumBlocks(CeedElemRestriction rstr, CeedInt *num_block);
CEED_EXTERN int CeedElemRestrictionGetBlockSize(CeedElemRestriction rstr, CeedInt *block_size);
CEED_EXTERN int CeedElemRestrictionGetMultiplicity(CeedElemRestriction rstr, CeedVector mult);
CEED_EXTERN int CeedElemRestrictionSetNumViewTabs(CeedElemRestriction rstr, CeedInt num_tabs);
CEED_EXTERN int CeedElemRestrictionView(CeedElemRestriction rstr, FILE *stream);
CEED_EXTERN int CeedElemRestrictionDestroy(CeedElemRestriction *rstr);

Expand All @@ -312,6 +315,7 @@ CEED_EXTERN int CeedBasisCreateHcurl(Ceed ceed, CeedElemTopology topo, CeedInt n
const CeedScalar *curl, const CeedScalar *q_ref, const CeedScalar *q_weights, CeedBasis *basis);
CEED_EXTERN int CeedBasisCreateProjection(CeedBasis basis_from, CeedBasis basis_to, CeedBasis *basis_project);
CEED_EXTERN int CeedBasisReferenceCopy(CeedBasis basis, CeedBasis *basis_copy);
CEED_EXTERN int CeedBasisSetNumViewTabs(CeedBasis basis, CeedInt num_tabs);
CEED_EXTERN int CeedBasisView(CeedBasis basis, FILE *stream);
CEED_EXTERN int CeedBasisApply(CeedBasis basis, CeedInt num_elem, CeedTransposeMode t_mode, CeedEvalMode eval_mode, CeedVector u, CeedVector v);
CEED_EXTERN int CeedBasisApplyAdd(CeedBasis basis, CeedInt num_elem, CeedTransposeMode t_mode, CeedEvalMode eval_mode, CeedVector u, CeedVector v);
Expand Down Expand Up @@ -368,6 +372,7 @@ CEED_EXTERN int CeedQFunctionGetFields(CeedQFunction qf, CeedInt *num_input_fie
CEED_EXTERN int CeedQFunctionSetContext(CeedQFunction qf, CeedQFunctionContext ctx);
CEED_EXTERN int CeedQFunctionSetContextWritable(CeedQFunction qf, bool is_writable);
CEED_EXTERN int CeedQFunctionSetUserFlopsEstimate(CeedQFunction qf, CeedSize flops);
CEED_EXTERN int CeedQFunctionSetNumViewTabs(CeedQFunction qf, CeedInt num_tabs);
CEED_EXTERN int CeedQFunctionView(CeedQFunction qf, FILE *stream);
CEED_EXTERN int CeedQFunctionGetCeed(CeedQFunction qf, Ceed *ceed);
CEED_EXTERN Ceed CeedQFunctionReturnCeed(CeedQFunction qf);
Expand Down Expand Up @@ -406,6 +411,7 @@ CEED_EXTERN int CeedQFunctionContextGetAllFieldLabels(CeedQFunctionContext ctx,
CEED_EXTERN int CeedContextFieldLabelGetDescription(CeedContextFieldLabel label, const char **field_name, size_t *field_offset, size_t *num_values,
const char **field_description, CeedContextFieldType *field_type);
CEED_EXTERN int CeedQFunctionContextGetContextSize(CeedQFunctionContext ctx, size_t *ctx_size);
CEED_EXTERN int CeedQFunctionContextSetNumViewTabs(CeedQFunctionContext ctx, CeedInt num_tabs);
CEED_EXTERN int CeedQFunctionContextView(CeedQFunctionContext ctx, FILE *stream);
CEED_EXTERN int CeedQFunctionContextSetDataDestroy(CeedQFunctionContext ctx, CeedMemType f_mem_type, CeedQFunctionContextDataDestroyUser f);
CEED_EXTERN int CeedQFunctionContextDestroy(CeedQFunctionContext *ctx);
Expand Down
78 changes: 60 additions & 18 deletions interface/ceed-basis.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,23 +153,24 @@ static int CeedGivensRotation(CeedScalar *A, CeedScalar c, CeedScalar s, CeedTra
@param[in] m Number of rows in array
@param[in] n Number of columns in array
@param[in] a Array to be viewed
@param[in] tabs Tabs to append before each new line
@param[in] stream Stream to view to, e.g., `stdout`

@return An error code: 0 - success, otherwise - failure

@ref Developer
**/
static int CeedScalarView(const char *name, const char *fp_fmt, CeedInt m, CeedInt n, const CeedScalar *a, FILE *stream) {
static int CeedScalarView(const char *name, const char *fp_fmt, CeedInt m, CeedInt n, const CeedScalar *a, const char *tabs, FILE *stream) {
if (m > 1) {
fprintf(stream, " %s:\n", name);
fprintf(stream, "%s %s:\n", tabs, name);
} else {
char padded_name[12];

snprintf(padded_name, 11, "%s:", name);
fprintf(stream, " %-10s", padded_name);
fprintf(stream, "%s %-10s", tabs, padded_name);
}
for (CeedInt i = 0; i < m; i++) {
if (m > 1) fprintf(stream, " [%" CeedInt_FMT "]", i);
if (m > 1) fprintf(stream, "%s [%" CeedInt_FMT "]", tabs, i);
for (CeedInt j = 0; j < n; j++) fprintf(stream, fp_fmt, fabs(a[i * n + j]) > 1E-14 ? a[i * n + j] : 0);
fputs("\n", stream);
}
Expand Down Expand Up @@ -723,6 +724,21 @@ int CeedBasisGetCollocatedGrad(CeedBasis basis, CeedScalar *collo_grad_1d) {
return CEED_ERROR_SUCCESS;
}

/**
@brief Get the number of tabs to indent for @ref CeedBasisView() output

@param[in] basis `CeedBasis` to get the number of view tabs
@param[out] num_tabs Number of view tabs

@return Error code: 0 - success, otherwise - failure

@ref Backend
**/
int CeedBasisGetNumViewTabs(CeedBasis basis, CeedInt *num_tabs) {
*num_tabs = basis->num_tabs;
return CEED_ERROR_SUCCESS;
}

/**
@brief Return 1D interpolation matrix to Chebyshev polynomial coefficients on quadrature space

Expand Down Expand Up @@ -1892,6 +1908,22 @@ int CeedBasisReferenceCopy(CeedBasis basis, CeedBasis *basis_copy) {
return CEED_ERROR_SUCCESS;
}

/**
@brief Set the number of tabs to indent for @ref CeedBasisView() output

@param[in] basis `CeedBasis` to set the number of view tabs
@param[in] num_tabs Number of view tabs to set

@return Error code: 0 - success, otherwise - failure

@ref User
**/
int CeedBasisSetNumViewTabs(CeedBasis basis, CeedInt num_tabs) {
CeedCheck(num_tabs >= 0, CeedBasisReturnCeed(basis), CEED_ERROR_MINOR, "Number of view tabs must be non-negative");
basis->num_tabs = num_tabs;
return CEED_ERROR_SUCCESS;
}

/**
@brief View a `CeedBasis`

Expand All @@ -1904,6 +1936,7 @@ int CeedBasisReferenceCopy(CeedBasis basis, CeedBasis *basis_copy) {
**/
int CeedBasisView(CeedBasis basis, FILE *stream) {
bool is_tensor_basis;
char *tabs = NULL;
CeedElemTopology topo;
CeedFESpace fe_space;

Expand All @@ -1912,14 +1945,22 @@ int CeedBasisView(CeedBasis basis, FILE *stream) {
CeedCall(CeedBasisGetTopology(basis, &topo));
CeedCall(CeedBasisGetFESpace(basis, &fe_space));

{
CeedInt num_tabs = 0;

CeedCall(CeedBasisGetNumViewTabs(basis, &num_tabs));
CeedCall(CeedCalloc(CEED_TAB_WIDTH * num_tabs + 1, &tabs));
for (CeedInt i = 0; i < CEED_TAB_WIDTH * num_tabs; i++) tabs[i] = ' ';
}

// Print FE space and element topology of the basis
fprintf(stream, "CeedBasis in a %s on a %s element\n", CeedFESpaces[fe_space], CeedElemTopologies[topo]);
fprintf(stream, "%sCeedBasis in a %s on a %s element\n", tabs, CeedFESpaces[fe_space], CeedElemTopologies[topo]);
if (is_tensor_basis) {
fprintf(stream, " P: %" CeedInt_FMT "\n Q: %" CeedInt_FMT "\n", basis->P_1d, basis->Q_1d);
fprintf(stream, "%s P: %" CeedInt_FMT "\n%s Q: %" CeedInt_FMT "\n", tabs, basis->P_1d, tabs, basis->Q_1d);
} else {
fprintf(stream, " P: %" CeedInt_FMT "\n Q: %" CeedInt_FMT "\n", basis->P, basis->Q);
fprintf(stream, "%s P: %" CeedInt_FMT "\n%s Q: %" CeedInt_FMT "\n", tabs, basis->P, tabs, basis->Q);
}
fprintf(stream, " dimension: %" CeedInt_FMT "\n field components: %" CeedInt_FMT "\n", basis->dim, basis->num_comp);
fprintf(stream, "%s dimension: %" CeedInt_FMT "\n%s field components: %" CeedInt_FMT "\n", tabs, basis->dim, tabs, basis->num_comp);
// Print quadrature data, interpolation/gradient/divergence/curl of the basis
if (is_tensor_basis) { // tensor basis
CeedInt P_1d, Q_1d;
Expand All @@ -1932,10 +1973,10 @@ int CeedBasisView(CeedBasis basis, FILE *stream) {
CeedCall(CeedBasisGetInterp1D(basis, &interp_1d));
CeedCall(CeedBasisGetGrad1D(basis, &grad_1d));

CeedCall(CeedScalarView("qref1d", "\t% 12.8f", 1, Q_1d, q_ref_1d, stream));
CeedCall(CeedScalarView("qweight1d", "\t% 12.8f", 1, Q_1d, q_weight_1d, stream));
CeedCall(CeedScalarView("interp1d", "\t% 12.8f", Q_1d, P_1d, interp_1d, stream));
CeedCall(CeedScalarView("grad1d", "\t% 12.8f", Q_1d, P_1d, grad_1d, stream));
CeedCall(CeedScalarView("qref1d", "\t% 12.8f", 1, Q_1d, q_ref_1d, tabs, stream));
CeedCall(CeedScalarView("qweight1d", "\t% 12.8f", 1, Q_1d, q_weight_1d, tabs, stream));
CeedCall(CeedScalarView("interp1d", "\t% 12.8f", Q_1d, P_1d, interp_1d, tabs, stream));
CeedCall(CeedScalarView("grad1d", "\t% 12.8f", Q_1d, P_1d, grad_1d, tabs, stream));
} else { // non-tensor basis
CeedInt P, Q, dim, q_comp;
const CeedScalar *q_ref, *q_weight, *interp, *grad, *div, *curl;
Expand All @@ -1950,23 +1991,24 @@ int CeedBasisView(CeedBasis basis, FILE *stream) {
CeedCall(CeedBasisGetDiv(basis, &div));
CeedCall(CeedBasisGetCurl(basis, &curl));

CeedCall(CeedScalarView("qref", "\t% 12.8f", 1, Q * dim, q_ref, stream));
CeedCall(CeedScalarView("qweight", "\t% 12.8f", 1, Q, q_weight, stream));
CeedCall(CeedScalarView("qref", "\t% 12.8f", 1, Q * dim, q_ref, tabs, stream));
CeedCall(CeedScalarView("qweight", "\t% 12.8f", 1, Q, q_weight, tabs, stream));
CeedCall(CeedBasisGetNumQuadratureComponents(basis, CEED_EVAL_INTERP, &q_comp));
CeedCall(CeedScalarView("interp", "\t% 12.8f", q_comp * Q, P, interp, stream));
CeedCall(CeedScalarView("interp", "\t% 12.8f", q_comp * Q, P, interp, tabs, stream));
if (grad) {
CeedCall(CeedBasisGetNumQuadratureComponents(basis, CEED_EVAL_GRAD, &q_comp));
CeedCall(CeedScalarView("grad", "\t% 12.8f", q_comp * Q, P, grad, stream));
CeedCall(CeedScalarView("grad", "\t% 12.8f", q_comp * Q, P, grad, tabs, stream));
}
if (div) {
CeedCall(CeedBasisGetNumQuadratureComponents(basis, CEED_EVAL_DIV, &q_comp));
CeedCall(CeedScalarView("div", "\t% 12.8f", q_comp * Q, P, div, stream));
CeedCall(CeedScalarView("div", "\t% 12.8f", q_comp * Q, P, div, tabs, stream));
}
if (curl) {
CeedCall(CeedBasisGetNumQuadratureComponents(basis, CEED_EVAL_CURL, &q_comp));
CeedCall(CeedScalarView("curl", "\t% 12.8f", q_comp * Q, P, curl, stream));
CeedCall(CeedScalarView("curl", "\t% 12.8f", q_comp * Q, P, curl, tabs, stream));
}
}
CeedCall(CeedFree(&tabs));
return CEED_ERROR_SUCCESS;
}

Expand Down
Loading