Advance V5 core capabilities and planning
This commit is contained in:
@@ -51,6 +51,9 @@ int main(void)
|
||||
int linsol_preconditioner = -1;
|
||||
int linsol_iteration = -1;
|
||||
int linsol_status = -999;
|
||||
int linsol_backend = -1;
|
||||
int linsol_available = -1;
|
||||
int linsol_capabilities = -1;
|
||||
int shell_sample_count = -1;
|
||||
int shell_last_element = -1;
|
||||
int node_ids[1] = {2};
|
||||
@@ -79,9 +82,13 @@ int main(void)
|
||||
double contact_friction_work_total = -1.0;
|
||||
double contact_max_slip = -1.0;
|
||||
int contact_history_slots = -1;
|
||||
int contact_multiplier_slots = -1;
|
||||
int contact_multiplier_active = -1;
|
||||
double max_slot_slip = -1.0;
|
||||
double max_slot_work = -1.0;
|
||||
double max_tangent_force = -1.0;
|
||||
double max_multiplier_lambda = -1.0;
|
||||
double max_multiplier_gap = -1.0;
|
||||
double contact_search_time = -1.0;
|
||||
double contact_force_time = -1.0;
|
||||
double contact_tangent_time = -1.0;
|
||||
@@ -130,6 +137,30 @@ int main(void)
|
||||
if (linsol_method != 1 || linsol_preconditioner != 1 ||
|
||||
linsol_iteration != 0 || linsol_residual != 0.0 ||
|
||||
linsol_status != 0) return 47;
|
||||
ierr = femlite_get_linear_solver_external_info(&linsol_backend,
|
||||
&linsol_available,
|
||||
&linsol_capabilities);
|
||||
if (ierr != 0) return check_ierr(ierr, 4701);
|
||||
if (linsol_backend != FEMLITE_LS_EXT_BACKEND_REF_DIRECT) return 4702;
|
||||
if (linsol_available != 1) return 4703;
|
||||
if ((linsol_capabilities & FEMLITE_LS_EXT_CAP_DIRECT) == 0 ||
|
||||
(linsol_capabilities & FEMLITE_LS_EXT_CAP_GENERAL) == 0 ||
|
||||
(linsol_capabilities & FEMLITE_LS_EXT_CAP_SPD) == 0 ||
|
||||
(linsol_capabilities & FEMLITE_LS_EXT_CAP_INDEFINITE) == 0) {
|
||||
return 47031;
|
||||
}
|
||||
ierr = femlite_set_linear_solver_external_backend(
|
||||
FEMLITE_LS_EXT_BACKEND_SUPERLU);
|
||||
if (ierr != 0) return check_ierr(ierr, 4704);
|
||||
ierr = femlite_get_linear_solver_external_info(&linsol_backend,
|
||||
&linsol_available,
|
||||
&linsol_capabilities);
|
||||
if (ierr != 0) return check_ierr(ierr, 4705);
|
||||
if (linsol_backend != FEMLITE_LS_EXT_BACKEND_SUPERLU) return 4706;
|
||||
if (linsol_available != 0 || linsol_capabilities != 0) return 4707;
|
||||
ierr = femlite_set_linear_solver_external_backend(
|
||||
FEMLITE_LS_EXT_BACKEND_REF_DIRECT);
|
||||
if (ierr != 0) return check_ierr(ierr, 4708);
|
||||
ierr = femlite_set_linear_solver(2, 0);
|
||||
if (ierr != 0) return check_ierr(ierr, 48);
|
||||
ierr = femlite_get_linear_solver_settings(&linsol_method,
|
||||
@@ -236,6 +267,14 @@ int main(void)
|
||||
if (contact_history_slots != 0 || max_slot_slip != 0.0 ||
|
||||
max_slot_work != 0.0 || max_tangent_force != 0.0) return 31;
|
||||
|
||||
ierr = femlite_get_contact_multiplier_stats(&contact_multiplier_slots,
|
||||
&contact_multiplier_active,
|
||||
&max_multiplier_lambda,
|
||||
&max_multiplier_gap);
|
||||
if (ierr != 0) return check_ierr(ierr, 3101);
|
||||
if (contact_multiplier_slots != 0 || contact_multiplier_active != 0 ||
|
||||
max_multiplier_lambda != 0.0 || max_multiplier_gap != 0.0) return 3102;
|
||||
|
||||
ierr = femlite_get_contact_search_stats(&contact_search_facets,
|
||||
&contact_search_masters,
|
||||
&contact_search_broad,
|
||||
|
||||
@@ -0,0 +1,199 @@
|
||||
#include "femlite_c_api.h"
|
||||
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
static int check_ierr(int ierr, int code)
|
||||
{
|
||||
int err_code = 0;
|
||||
char message[256];
|
||||
|
||||
if (ierr == 0) {
|
||||
return 0;
|
||||
}
|
||||
(void)femlite_get_last_error(&err_code, message, (int)sizeof(message));
|
||||
fprintf(stderr, "test_external_diag_c_api failed at %d: ierr=%d code=%d %s\n",
|
||||
code, ierr, err_code, message);
|
||||
return code;
|
||||
}
|
||||
|
||||
static int check_close(double actual, double expected, int code)
|
||||
{
|
||||
double scale = fmax(1.0, fabs(expected));
|
||||
|
||||
if (fabs(actual - expected) > 1.0e-12 * scale) {
|
||||
fprintf(stderr,
|
||||
"test_external_diag_c_api mismatch at %d: %.17g vs %.17g\n",
|
||||
code, actual, expected);
|
||||
return code;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int read_diag(int *valid,
|
||||
int *nrow,
|
||||
int *ncol,
|
||||
int *nnz,
|
||||
int *class_id,
|
||||
int *sym_pat,
|
||||
int *sym_val,
|
||||
int *status,
|
||||
double *matrix_norm,
|
||||
double *rhs_norm,
|
||||
double *initial_resid,
|
||||
double *initial_rel)
|
||||
{
|
||||
return femlite_get_linear_solver_external_diag(
|
||||
valid, nrow, ncol, nnz, class_id, sym_pat, sym_val, status,
|
||||
matrix_norm, rhs_norm, initial_resid, initial_rel);
|
||||
}
|
||||
|
||||
static int check_default_diag(void)
|
||||
{
|
||||
int ierr = 0;
|
||||
int valid = -1;
|
||||
int nrow = -1;
|
||||
int ncol = -1;
|
||||
int nnz = -1;
|
||||
int class_id = -1;
|
||||
int sym_pat = -1;
|
||||
int sym_val = -1;
|
||||
int status = -99;
|
||||
double matrix_norm = -1.0;
|
||||
double rhs_norm = -1.0;
|
||||
double initial_resid = -1.0;
|
||||
double initial_rel = -1.0;
|
||||
int failed = 0;
|
||||
|
||||
ierr = read_diag(&valid, &nrow, &ncol, &nnz, &class_id, &sym_pat,
|
||||
&sym_val, &status, &matrix_norm, &rhs_norm,
|
||||
&initial_resid, &initial_rel);
|
||||
if (ierr != 0) return check_ierr(ierr, 10);
|
||||
if (valid != 0) return 11;
|
||||
if (nrow != 0 || ncol != 0 || nnz != 0) return 12;
|
||||
if (class_id != FEMLITE_CSR_CLASS_GENERAL) return 13;
|
||||
if (sym_pat != 0 || sym_val != 0) return 14;
|
||||
if (status != 0) return 15;
|
||||
failed = check_close(matrix_norm, 0.0, 16);
|
||||
if (failed != 0) return failed;
|
||||
failed = check_close(rhs_norm, 0.0, 17);
|
||||
if (failed != 0) return failed;
|
||||
failed = check_close(initial_resid, 0.0, 18);
|
||||
if (failed != 0) return failed;
|
||||
return check_close(initial_rel, 0.0, 19);
|
||||
}
|
||||
|
||||
static int check_backend_config(void)
|
||||
{
|
||||
int ierr = 0;
|
||||
int backend = -1;
|
||||
int available = -1;
|
||||
int capabilities = -1;
|
||||
int prepared = -1;
|
||||
int command_ran = -1;
|
||||
int command_exit = -1;
|
||||
int finish_status = -1;
|
||||
double residual = -1.0;
|
||||
double relative = -1.0;
|
||||
double backward = -1.0;
|
||||
|
||||
ierr = femlite_set_linear_solver_external_backend(
|
||||
FEMLITE_LS_EXT_BACKEND_SUPERLU);
|
||||
if (ierr != 0) return check_ierr(ierr, 30);
|
||||
ierr = femlite_get_linear_solver_external_info(&backend, &available,
|
||||
&capabilities);
|
||||
if (ierr != 0) return check_ierr(ierr, 31);
|
||||
if (backend != FEMLITE_LS_EXT_BACKEND_SUPERLU) return 32;
|
||||
if (available != 0 || capabilities != 0) return 33;
|
||||
|
||||
ierr = femlite_configure_linear_solver_external_file(
|
||||
"capi_ext_file", "", 0, 1, 0, 1);
|
||||
if (ierr != 0) return check_ierr(ierr, 35);
|
||||
ierr = femlite_set_linear_solver_external_backend(
|
||||
FEMLITE_LS_EXT_BACKEND_FILE);
|
||||
if (ierr != 0) return check_ierr(ierr, 36);
|
||||
ierr = femlite_get_linear_solver_external_info(&backend, &available,
|
||||
&capabilities);
|
||||
if (ierr != 0) return check_ierr(ierr, 37);
|
||||
if (backend != FEMLITE_LS_EXT_BACKEND_FILE) return 38;
|
||||
if (available != 1) return 39;
|
||||
if ((capabilities & FEMLITE_LS_EXT_CAP_DIRECT) == 0 ||
|
||||
(capabilities & FEMLITE_LS_EXT_CAP_GENERAL) == 0) {
|
||||
return 40;
|
||||
}
|
||||
ierr = femlite_get_linear_solver_external_file_diag(
|
||||
&prepared, &command_ran, &command_exit, &finish_status,
|
||||
&residual, &relative, &backward);
|
||||
if (ierr != 0) return check_ierr(ierr, 41);
|
||||
if (prepared != 0 || command_ran != 0 || command_exit != 0) return 42;
|
||||
|
||||
ierr = femlite_set_linear_solver_external_backend(
|
||||
FEMLITE_LS_EXT_BACKEND_NONE);
|
||||
if (ierr != 0) return check_ierr(ierr, 34);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int check_null_guards(void)
|
||||
{
|
||||
int valid = 0;
|
||||
int nrow = 0;
|
||||
int ncol = 0;
|
||||
int nnz = 0;
|
||||
int class_id = 0;
|
||||
int sym_pat = 0;
|
||||
int sym_val = 0;
|
||||
int status = 0;
|
||||
double matrix_norm = 0.0;
|
||||
double rhs_norm = 0.0;
|
||||
double initial_resid = 0.0;
|
||||
double initial_rel = 0.0;
|
||||
char path[128];
|
||||
int ierr = 0;
|
||||
|
||||
ierr = read_diag(NULL, &nrow, &ncol, &nnz, &class_id, &sym_pat,
|
||||
&sym_val, &status, &matrix_norm, &rhs_norm,
|
||||
&initial_resid, &initial_rel);
|
||||
if (ierr != -1) return 50;
|
||||
ierr = read_diag(&valid, &nrow, &ncol, &nnz, &class_id, &sym_pat,
|
||||
&sym_val, &status, NULL, &rhs_norm, &initial_resid,
|
||||
&initial_rel);
|
||||
if (ierr != -1) return 51;
|
||||
if (femlite_configure_linear_solver_external_file(
|
||||
NULL, "", 0, 1, 0, 1) != -1) return 52;
|
||||
if (femlite_get_linear_solver_external_file_diag(
|
||||
NULL, &status, &status, &status, &matrix_norm, &rhs_norm,
|
||||
&initial_resid) != -1) return 53;
|
||||
if (femlite_get_linear_solver_external_file_paths(
|
||||
NULL, (int)sizeof(path), path, (int)sizeof(path),
|
||||
path, (int)sizeof(path), path, (int)sizeof(path),
|
||||
path, (int)sizeof(path), path, (int)sizeof(path)) != -1) {
|
||||
return 54;
|
||||
}
|
||||
if (femlite_get_linear_solver_external_file_paths(
|
||||
path, 0, path, (int)sizeof(path), path, (int)sizeof(path),
|
||||
path, (int)sizeof(path), path, (int)sizeof(path),
|
||||
path, (int)sizeof(path)) != -1) {
|
||||
return 55;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int ierr = 0;
|
||||
int failed = 0;
|
||||
|
||||
ierr = femlite_initialize();
|
||||
if (ierr != 0) return check_ierr(ierr, 1);
|
||||
|
||||
failed = check_default_diag();
|
||||
if (failed != 0) return failed;
|
||||
failed = check_backend_config();
|
||||
if (failed != 0) return failed;
|
||||
failed = check_null_guards();
|
||||
if (failed != 0) return failed;
|
||||
|
||||
ierr = femlite_finalize();
|
||||
if (ierr != 0) return check_ierr(ierr, 2);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,226 @@
|
||||
#include "femlite_c_api.h"
|
||||
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define MAXF 16
|
||||
#define MAXN 8
|
||||
#define NDIM 3
|
||||
|
||||
static int check_ierr(int ierr, int code)
|
||||
{
|
||||
int err_code = 0;
|
||||
char message[256];
|
||||
|
||||
if (ierr == 0) {
|
||||
return 0;
|
||||
}
|
||||
(void)femlite_get_last_error(&err_code, message, (int)sizeof(message));
|
||||
fprintf(stderr, "test_facet_nodal_c_api failed at %d: ierr=%d code=%d %s\n",
|
||||
code, ierr, err_code, message);
|
||||
return code;
|
||||
}
|
||||
|
||||
static int check_close(double actual, double expected, int code)
|
||||
{
|
||||
double scale = fmax(1.0, fabs(expected));
|
||||
|
||||
if (fabs(actual - expected) > 1.0e-9 * scale) {
|
||||
fprintf(stderr,
|
||||
"test_facet_nodal_c_api mismatch at %d: %.17g vs %.17g\n",
|
||||
code, actual, expected);
|
||||
return code;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int check_vec(const double actual[NDIM],
|
||||
const double expected[NDIM],
|
||||
int code)
|
||||
{
|
||||
int idir = 0;
|
||||
int failed = 0;
|
||||
|
||||
for (idir = 0; idir < NDIM; ++idir) {
|
||||
failed = check_close(actual[idir], expected[idir], code + idir);
|
||||
if (failed != 0) {
|
||||
return failed;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int f_index3(int idir, int inode, int ifacet, int max_nodes)
|
||||
{
|
||||
return idir + NDIM * (inode + max_nodes * ifacet);
|
||||
}
|
||||
|
||||
static int find_down_facet(const double normal[NDIM * MAXF], int nfacet)
|
||||
{
|
||||
int facet = 0;
|
||||
|
||||
for (facet = 0; facet < nfacet; ++facet) {
|
||||
if (normal[f_index3(2, 0, facet, 1)] < -0.5) {
|
||||
return facet;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void fill_uniform_load(double node_loads[NDIM * MAXN],
|
||||
int nnode,
|
||||
const double load[NDIM])
|
||||
{
|
||||
int node = 0;
|
||||
int idir = 0;
|
||||
|
||||
for (node = 0; node < MAXN; ++node) {
|
||||
for (idir = 0; idir < NDIM; ++idir) {
|
||||
node_loads[f_index3(idir, node, 0, MAXN)] = 0.0;
|
||||
}
|
||||
}
|
||||
for (node = 0; node < nnode; ++node) {
|
||||
for (idir = 0; idir < NDIM; ++idir) {
|
||||
node_loads[f_index3(idir, node, 0, MAXN)] = load[idir];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int setup_model(int *nfacet,
|
||||
int *max_nodes,
|
||||
int facet_id[MAXF],
|
||||
int elem_id[MAXF],
|
||||
int face_id[MAXF],
|
||||
int facet_nnode[MAXF],
|
||||
int facet_conn[MAXN * MAXF],
|
||||
double x[NDIM * MAXN * MAXF],
|
||||
double vnod[NDIM * MAXN * MAXF],
|
||||
double normal[NDIM * MAXF],
|
||||
double area[MAXF])
|
||||
{
|
||||
int ierr = 0;
|
||||
|
||||
ierr = femlite_initialize();
|
||||
if (ierr != 0) return check_ierr(ierr, 100);
|
||||
ierr = femlite_read_inp("examples/c3d4_one_element.inp");
|
||||
if (ierr != 0) return check_ierr(ierr, 101);
|
||||
ierr = femlite_build_model();
|
||||
if (ierr != 0) return check_ierr(ierr, 102);
|
||||
ierr = femlite_get_boundary_facet_count(nfacet, max_nodes);
|
||||
if (ierr != 0) return check_ierr(ierr, 103);
|
||||
if (*nfacet != 4 || *max_nodes != 3) return 104;
|
||||
|
||||
ierr = femlite_get_boundary_facets(MAXF, MAXN, facet_id, elem_id, face_id,
|
||||
facet_nnode, facet_conn, x, vnod,
|
||||
normal, area);
|
||||
if (ierr != 0) return check_ierr(ierr, 105);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int run_valid_load_case(void)
|
||||
{
|
||||
int ierr = 0;
|
||||
int failed = 0;
|
||||
int nfacet = 0;
|
||||
int max_nodes = 0;
|
||||
int bottom = -1;
|
||||
int one_id[1] = {0};
|
||||
int one_nnode[1] = {0};
|
||||
int facet_id[MAXF] = {0};
|
||||
int elem_id[MAXF] = {0};
|
||||
int face_id[MAXF] = {0};
|
||||
int facet_nnode[MAXF] = {0};
|
||||
int facet_conn[MAXN * MAXF] = {0};
|
||||
double x[NDIM * MAXN * MAXF] = {0.0};
|
||||
double vnod[NDIM * MAXN * MAXF] = {0.0};
|
||||
double normal[NDIM * MAXF] = {0.0};
|
||||
double area[MAXF] = {0.0};
|
||||
double node_loads[NDIM * MAXN] = {0.0};
|
||||
double total_force[NDIM] = {0.0};
|
||||
double load[NDIM] = {2.0, -3.0, 4.0};
|
||||
double expected[NDIM] = {0.0, 0.0, 0.0};
|
||||
|
||||
failed = setup_model(&nfacet, &max_nodes, facet_id, elem_id, face_id,
|
||||
facet_nnode, facet_conn, x, vnod, normal, area);
|
||||
if (failed != 0) return failed;
|
||||
bottom = find_down_facet(normal, nfacet);
|
||||
if (bottom < 0) return 110;
|
||||
|
||||
one_id[0] = facet_id[bottom];
|
||||
one_nnode[0] = facet_nnode[bottom];
|
||||
fill_uniform_load(node_loads, one_nnode[0], load);
|
||||
|
||||
ierr = femlite_clear_sph_forces();
|
||||
if (ierr != 0) return check_ierr(ierr, 111);
|
||||
ierr = femlite_apply_sph_facet_nodal_loads(1, MAXN, one_id, one_nnode,
|
||||
node_loads);
|
||||
if (ierr != 0) return check_ierr(ierr, 112);
|
||||
ierr = femlite_get_sph_force_summary(total_force);
|
||||
if (ierr != 0) return check_ierr(ierr, 113);
|
||||
|
||||
expected[0] = load[0] * one_nnode[0];
|
||||
expected[1] = load[1] * one_nnode[0];
|
||||
expected[2] = load[2] * one_nnode[0];
|
||||
failed = check_vec(total_force, expected, 114);
|
||||
if (failed != 0) return failed;
|
||||
|
||||
ierr = femlite_finalize();
|
||||
if (ierr != 0) return check_ierr(ierr, 120);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int run_error_case(void)
|
||||
{
|
||||
int ierr = 0;
|
||||
int failed = 0;
|
||||
int nfacet = 0;
|
||||
int max_nodes = 0;
|
||||
int bottom = -1;
|
||||
int one_id[1] = {0};
|
||||
int one_nnode[1] = {0};
|
||||
int facet_id[MAXF] = {0};
|
||||
int elem_id[MAXF] = {0};
|
||||
int face_id[MAXF] = {0};
|
||||
int facet_nnode[MAXF] = {0};
|
||||
int facet_conn[MAXN * MAXF] = {0};
|
||||
double x[NDIM * MAXN * MAXF] = {0.0};
|
||||
double vnod[NDIM * MAXN * MAXF] = {0.0};
|
||||
double normal[NDIM * MAXF] = {0.0};
|
||||
double area[MAXF] = {0.0};
|
||||
double node_loads[NDIM * MAXN] = {0.0};
|
||||
double load[NDIM] = {1.0, 0.0, 0.0};
|
||||
|
||||
failed = setup_model(&nfacet, &max_nodes, facet_id, elem_id, face_id,
|
||||
facet_nnode, facet_conn, x, vnod, normal, area);
|
||||
if (failed != 0) return failed;
|
||||
bottom = find_down_facet(normal, nfacet);
|
||||
if (bottom < 0) return 200;
|
||||
|
||||
one_id[0] = facet_id[bottom];
|
||||
one_nnode[0] = facet_nnode[bottom] + 1;
|
||||
fill_uniform_load(node_loads, facet_nnode[bottom], load);
|
||||
|
||||
ierr = femlite_apply_sph_facet_nodal_loads(1, MAXN, one_id, one_nnode,
|
||||
node_loads);
|
||||
if (ierr == 0) return 201;
|
||||
ierr = femlite_apply_sph_facet_nodal_loads(1, MAXN, NULL, one_nnode,
|
||||
node_loads);
|
||||
if (ierr != -1) return 202;
|
||||
ierr = femlite_get_sph_force_summary(NULL);
|
||||
if (ierr != -1) return 203;
|
||||
|
||||
ierr = femlite_finalize();
|
||||
if (ierr != 0) return check_ierr(ierr, 204);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int failed = 0;
|
||||
|
||||
failed = run_valid_load_case();
|
||||
if (failed != 0) return failed;
|
||||
failed = run_error_case();
|
||||
if (failed != 0) return failed;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user