145 lines
5.8 KiB
C
145 lines
5.8 KiB
C
#include "sphlite_c_api.h"
|
|
|
|
#include <math.h>
|
|
#include <stdio.h>
|
|
|
|
static int fail(const char *message)
|
|
{
|
|
fprintf(stderr, "%s\n", message);
|
|
return 1;
|
|
}
|
|
|
|
static int check_close(double actual, double expected, const char *message)
|
|
{
|
|
if (fabs(actual - expected) > fmax(1.0e-10, fabs(expected) * 1.0e-8)) {
|
|
return fail(message);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
char path[1024];
|
|
int ierr;
|
|
int load_mode = 0;
|
|
int distribution_mode = 0;
|
|
int contact_state_mode = 0;
|
|
int ids[1] = {1};
|
|
double pressures[1] = {13.0};
|
|
double vectors[3] = {1.0, 2.0, 3.0};
|
|
double normals[3] = {0.0, 0.0, 1.0};
|
|
double gaps[1] = {2.0e-4};
|
|
double penetrations[1] = {5.0e-3};
|
|
double contact_pressures[1] = {8.0};
|
|
double input_force[3] = {0.0, 0.0, 0.0};
|
|
double distributed_force[3] = {0.0, 0.0, 0.0};
|
|
double input_moment[3] = {0.0, 0.0, 0.0};
|
|
double distributed_moment[3] = {0.0, 0.0, 0.0};
|
|
double force_error = 0.0;
|
|
double moment_error = 0.0;
|
|
double diagnostics[SPHLITE_COUPLING_DIAGNOSTIC_VALUE_COUNT] = {0.0};
|
|
double contact_values[SPHLITE_COUPLING_CONTACT_DIAGNOSTIC_VALUE_COUNT] = {0.0};
|
|
int counts[SPHLITE_COUPLING_DIAGNOSTIC_COUNT_COUNT] = {0};
|
|
int contact_counts[SPHLITE_COUPLING_CONTACT_DIAGNOSTIC_COUNT_COUNT] = {0};
|
|
|
|
if (sphlite_coupling_get_region_modes(1, NULL, &distribution_mode,
|
|
&contact_state_mode) != -1) {
|
|
return fail("C API 081 null mode pointer did not fail");
|
|
}
|
|
if (sphlite_coupling_get_load_balance(NULL, distributed_force, &force_error,
|
|
input_moment, distributed_moment, &moment_error) != -1) {
|
|
return fail("C API 081 null load balance pointer did not fail");
|
|
}
|
|
if (sphlite_coupling_get_contact_diagnostics(contact_counts, 1,
|
|
contact_values, SPHLITE_COUPLING_CONTACT_DIAGNOSTIC_VALUE_COUNT) != -1) {
|
|
return fail("C API 081 small contact diagnostics buffer did not fail");
|
|
}
|
|
pressures[0] = HUGE_VAL;
|
|
if (sphlite_coupling_apply_facet_pressures(1, 1, ids, pressures,
|
|
SPHLITE_COUPLING_DISTRIBUTION_AREA, 1) != -1) {
|
|
return fail("C API 081 nonfinite pressure did not fail");
|
|
}
|
|
pressures[0] = 13.0;
|
|
|
|
ierr = sphlite_initialize();
|
|
if (ierr != 0) return fail("C API 081 initialize failed");
|
|
snprintf(path, sizeof(path), "%s/coupling_load_mode_081.inp",
|
|
SPHLITE_TEST_DATA_DIR);
|
|
ierr = sphlite_read_inp(path);
|
|
if (ierr != 0) return fail("C API 081 read input failed");
|
|
ierr = sphlite_build_model();
|
|
if (ierr != 0) return fail("C API 081 build model failed");
|
|
|
|
ierr = sphlite_coupling_get_region_modes(1, &load_mode, &distribution_mode,
|
|
&contact_state_mode);
|
|
if (ierr != 0) return fail("C API 081 region mode query failed");
|
|
if (load_mode != SPHLITE_COUPLING_LOAD_PRESSURE ||
|
|
distribution_mode != SPHLITE_COUPLING_DISTRIBUTION_AREA ||
|
|
contact_state_mode != SPHLITE_COUPLING_CONTACT_STATE_IMPORT) {
|
|
return fail("C API 081 region mode mismatch");
|
|
}
|
|
ierr = sphlite_coupling_get_region_modes(99, &load_mode, &distribution_mode,
|
|
&contact_state_mode);
|
|
if (ierr == 0) return fail("C API 081 invalid region did not fail");
|
|
|
|
ierr = sphlite_coupling_apply_facet_resultants(1, 1, ids, vectors,
|
|
SPHLITE_COUPLING_DISTRIBUTION_UNIFORM, 101);
|
|
if (ierr != 0) return fail("C API 081 resultant import failed");
|
|
ierr = sphlite_coupling_get_load_balance(input_force, distributed_force,
|
|
&force_error, input_moment, distributed_moment, &moment_error);
|
|
if (ierr != 0) return fail("C API 081 load balance failed");
|
|
if (check_close(force_error, 0.0, "C API 081 force error mismatch") != 0) {
|
|
return 1;
|
|
}
|
|
vectors[0] = 0.0;
|
|
vectors[1] = 4.0;
|
|
vectors[2] = 0.0;
|
|
ierr = sphlite_coupling_apply_facet_pressures(1, 1, ids, pressures,
|
|
SPHLITE_COUPLING_DISTRIBUTION_AREA, 102);
|
|
if (ierr != 0) return fail("C API 081 pressure import failed");
|
|
ierr = sphlite_coupling_apply_facet_tractions(2, 1, ids, vectors,
|
|
SPHLITE_COUPLING_DISTRIBUTION_MASS, 102);
|
|
if (ierr != 0) return fail("C API 081 traction import failed");
|
|
ierr = sphlite_coupling_apply_contact_state(1, 1, ids, normals, gaps,
|
|
penetrations, contact_pressures, 102);
|
|
if (ierr != 0) return fail("C API 081 contact import failed");
|
|
|
|
ierr = sphlite_coupling_get_contact_diagnostics(contact_counts,
|
|
SPHLITE_COUPLING_CONTACT_DIAGNOSTIC_COUNT_COUNT, contact_values,
|
|
SPHLITE_COUPLING_CONTACT_DIAGNOSTIC_VALUE_COUNT);
|
|
if (ierr != 0) return fail("C API 081 contact diagnostics failed");
|
|
if (contact_counts[0] != 1 || contact_counts[1] != 0) {
|
|
return fail("C API 081 contact count mismatch");
|
|
}
|
|
if (check_close(contact_values[0], 5.0e-3,
|
|
"C API 081 contact penetration mismatch") != 0) {
|
|
return 1;
|
|
}
|
|
ierr = sphlite_coupling_get_diagnostics(diagnostics,
|
|
SPHLITE_COUPLING_DIAGNOSTIC_VALUE_COUNT, counts,
|
|
SPHLITE_COUPLING_DIAGNOSTIC_COUNT_COUNT);
|
|
if (ierr != 0) return fail("C API 081 diagnostics failed");
|
|
if (counts[8] != 1) return fail("C API 081 diagnostics contact mismatch");
|
|
if (check_close(diagnostics[24], 13.0,
|
|
"C API 081 diagnostics pressure mismatch") != 0) {
|
|
return 1;
|
|
}
|
|
if (check_close(diagnostics[25], 4.0,
|
|
"C API 081 diagnostics traction mismatch") != 0) {
|
|
return 1;
|
|
}
|
|
if (sphlite_coupling_apply_facet_tractions(2, 1, NULL, vectors,
|
|
SPHLITE_COUPLING_DISTRIBUTION_MASS, 103) != -1) {
|
|
return fail("C API 081 null traction id buffer did not fail");
|
|
}
|
|
vectors[0] = HUGE_VAL;
|
|
if (sphlite_coupling_apply_facet_resultants(1, 1, ids, vectors,
|
|
SPHLITE_COUPLING_DISTRIBUTION_UNIFORM, 103) != -1) {
|
|
return fail("C API 081 nonfinite resultant did not fail");
|
|
}
|
|
|
|
ierr = sphlite_finalize();
|
|
if (ierr != 0) return fail("C API 081 finalize failed");
|
|
return 0;
|
|
}
|