Add coupling output restart and APIs
This commit is contained in:
@@ -144,6 +144,41 @@ struct SolidReferenceQuality {
|
||||
int correction_status;
|
||||
};
|
||||
|
||||
struct CouplingRegionInfo {
|
||||
std::string name;
|
||||
int region_type;
|
||||
int export_mode;
|
||||
int import_mode;
|
||||
int enabled;
|
||||
int particle_count;
|
||||
int facet_count;
|
||||
};
|
||||
|
||||
struct CouplingParticleExport {
|
||||
std::vector<int> ext_ids;
|
||||
std::vector<int> internal_indices;
|
||||
std::vector<int> phases;
|
||||
std::vector<int> statuses;
|
||||
std::vector<int> materials;
|
||||
std::vector<int> sections;
|
||||
std::vector<double> scalar_values;
|
||||
std::vector<double> vector_values;
|
||||
};
|
||||
|
||||
struct CouplingFacetExport {
|
||||
std::vector<int> facet_ids;
|
||||
std::vector<int> particle_ids;
|
||||
std::vector<int> materials;
|
||||
std::vector<int> sections;
|
||||
std::vector<double> vector_values;
|
||||
std::vector<double> area_values;
|
||||
};
|
||||
|
||||
struct CouplingDiagnostics {
|
||||
std::vector<double> values;
|
||||
std::vector<int> counts;
|
||||
};
|
||||
|
||||
class Error : public std::runtime_error {
|
||||
public:
|
||||
explicit Error(const std::string &message) : std::runtime_error(message) {}
|
||||
@@ -397,6 +432,129 @@ inline void read_restart(const std::string &filename)
|
||||
check(sphlite_read_restart(filename.c_str()));
|
||||
}
|
||||
|
||||
inline int coupling_region_count()
|
||||
{
|
||||
int count = 0;
|
||||
check(sphlite_coupling_get_region_count(&count));
|
||||
return count;
|
||||
}
|
||||
|
||||
inline CouplingRegionInfo coupling_region_info(int region_index)
|
||||
{
|
||||
char name[128];
|
||||
CouplingRegionInfo info = {"", 0, 0, 0, 0, 0, 0};
|
||||
check(sphlite_coupling_get_region_info(region_index, name,
|
||||
static_cast<int>(sizeof(name)), &info.region_type, &info.export_mode,
|
||||
&info.import_mode, &info.enabled, &info.particle_count,
|
||||
&info.facet_count));
|
||||
info.name = std::string(name);
|
||||
return info;
|
||||
}
|
||||
|
||||
inline CouplingParticleExport coupling_export_particles(int region_index)
|
||||
{
|
||||
CouplingRegionInfo info = coupling_region_info(region_index);
|
||||
int capacity = info.particle_count > 0 ? info.particle_count : 1;
|
||||
CouplingParticleExport result;
|
||||
result.ext_ids.resize(capacity);
|
||||
result.internal_indices.resize(capacity);
|
||||
result.phases.resize(capacity);
|
||||
result.statuses.resize(capacity);
|
||||
result.materials.resize(capacity);
|
||||
result.sections.resize(capacity);
|
||||
result.scalar_values.resize(SPHLITE_COUPLING_PARTICLE_SCALAR_COUNT * capacity);
|
||||
result.vector_values.resize(3 * SPHLITE_COUPLING_PARTICLE_VECTOR_COUNT * capacity);
|
||||
int count = 0;
|
||||
check(sphlite_coupling_export_particles(region_index, capacity, &count,
|
||||
result.ext_ids.data(), result.internal_indices.data(),
|
||||
result.phases.data(), result.statuses.data(), result.materials.data(),
|
||||
result.sections.data(), result.scalar_values.data(),
|
||||
result.vector_values.data()));
|
||||
result.ext_ids.resize(count);
|
||||
result.internal_indices.resize(count);
|
||||
result.phases.resize(count);
|
||||
result.statuses.resize(count);
|
||||
result.materials.resize(count);
|
||||
result.sections.resize(count);
|
||||
result.scalar_values.resize(SPHLITE_COUPLING_PARTICLE_SCALAR_COUNT * count);
|
||||
result.vector_values.resize(3 * SPHLITE_COUPLING_PARTICLE_VECTOR_COUNT * count);
|
||||
return result;
|
||||
}
|
||||
|
||||
inline CouplingFacetExport coupling_export_facets(int region_index)
|
||||
{
|
||||
CouplingRegionInfo info = coupling_region_info(region_index);
|
||||
int capacity = info.facet_count > 0 ? info.facet_count : 1;
|
||||
CouplingFacetExport result;
|
||||
result.facet_ids.resize(capacity);
|
||||
result.particle_ids.resize(capacity);
|
||||
result.materials.resize(capacity);
|
||||
result.sections.resize(capacity);
|
||||
result.vector_values.resize(3 * SPHLITE_COUPLING_FACET_VECTOR_COUNT * capacity);
|
||||
result.area_values.resize(capacity);
|
||||
int count = 0;
|
||||
check(sphlite_coupling_export_facets(region_index, capacity, &count,
|
||||
result.facet_ids.data(), result.particle_ids.data(),
|
||||
result.materials.data(), result.sections.data(),
|
||||
result.vector_values.data(), result.area_values.data()));
|
||||
result.facet_ids.resize(count);
|
||||
result.particle_ids.resize(count);
|
||||
result.materials.resize(count);
|
||||
result.sections.resize(count);
|
||||
result.vector_values.resize(3 * SPHLITE_COUPLING_FACET_VECTOR_COUNT * count);
|
||||
result.area_values.resize(count);
|
||||
return result;
|
||||
}
|
||||
|
||||
inline void coupling_apply_particle_forces(int region_index,
|
||||
const std::vector<int> &export_indices,
|
||||
const std::vector<double> &forces)
|
||||
{
|
||||
if (forces.size() != 3 * export_indices.size()) {
|
||||
throw Error("coupling force vector size mismatch");
|
||||
}
|
||||
check(sphlite_coupling_apply_particle_forces(region_index,
|
||||
static_cast<int>(export_indices.size()), export_indices.data(),
|
||||
forces.data()));
|
||||
}
|
||||
|
||||
inline void coupling_apply_facet_loads(int region_index,
|
||||
const std::vector<int> &facet_ids,
|
||||
const std::vector<double> &loads)
|
||||
{
|
||||
if (loads.size() != 3 * facet_ids.size()) {
|
||||
throw Error("coupling facet load vector size mismatch");
|
||||
}
|
||||
check(sphlite_coupling_apply_facet_loads(region_index,
|
||||
static_cast<int>(facet_ids.size()), facet_ids.data(), loads.data()));
|
||||
}
|
||||
|
||||
inline void coupling_apply_motion_boundary(int region_index,
|
||||
int export_index,
|
||||
int target_kind,
|
||||
int mode,
|
||||
const double target[3])
|
||||
{
|
||||
check(sphlite_coupling_apply_motion_boundary(region_index, export_index,
|
||||
target_kind, mode, target));
|
||||
}
|
||||
|
||||
inline void coupling_clear_imports()
|
||||
{
|
||||
check(sphlite_coupling_clear_imports());
|
||||
}
|
||||
|
||||
inline CouplingDiagnostics coupling_diagnostics()
|
||||
{
|
||||
CouplingDiagnostics diagnostics;
|
||||
diagnostics.values.resize(SPHLITE_COUPLING_DIAGNOSTIC_VALUE_COUNT);
|
||||
diagnostics.counts.resize(SPHLITE_COUPLING_DIAGNOSTIC_COUNT_COUNT);
|
||||
check(sphlite_coupling_get_diagnostics(diagnostics.values.data(),
|
||||
static_cast<int>(diagnostics.values.size()), diagnostics.counts.data(),
|
||||
static_cast<int>(diagnostics.counts.size())));
|
||||
return diagnostics;
|
||||
}
|
||||
|
||||
class Session {
|
||||
public:
|
||||
Session() : active_(true) { initialize(); }
|
||||
|
||||
@@ -35,6 +35,29 @@ extern "C" {
|
||||
#define SPHLITE_SOLID_DIAGNOSTIC_VALUE_COUNT 3
|
||||
#define SPHLITE_SOLID_REFERENCE_VALUE_COUNT 1
|
||||
|
||||
#define SPHLITE_COUPLING_REGION_CONTACT 1
|
||||
#define SPHLITE_COUPLING_REGION_CONTINUUM 2
|
||||
|
||||
#define SPHLITE_COUPLING_EXPORT_PARTICLE 1
|
||||
#define SPHLITE_COUPLING_EXPORT_FACET 2
|
||||
#define SPHLITE_COUPLING_EXPORT_BOTH 3
|
||||
|
||||
#define SPHLITE_COUPLING_IMPORT_FORCE 1
|
||||
#define SPHLITE_COUPLING_IMPORT_FACET_LOAD 2
|
||||
#define SPHLITE_COUPLING_IMPORT_MOTION 3
|
||||
|
||||
#define SPHLITE_COUPLING_MOTION_NONE 0
|
||||
#define SPHLITE_COUPLING_MOTION_VELOCITY 1
|
||||
#define SPHLITE_COUPLING_MOTION_POSITION 2
|
||||
#define SPHLITE_COUPLING_MOTION_DIRECT 1
|
||||
#define SPHLITE_COUPLING_MOTION_PENALTY 2
|
||||
|
||||
#define SPHLITE_COUPLING_PARTICLE_SCALAR_COUNT 7
|
||||
#define SPHLITE_COUPLING_PARTICLE_VECTOR_COUNT 3
|
||||
#define SPHLITE_COUPLING_FACET_VECTOR_COUNT 3
|
||||
#define SPHLITE_COUPLING_DIAGNOSTIC_VALUE_COUNT 22
|
||||
#define SPHLITE_COUPLING_DIAGNOSTIC_COUNT_COUNT 5
|
||||
|
||||
SPHLITE_API int sphlite_initialize(void);
|
||||
SPHLITE_API int sphlite_finalize(void);
|
||||
SPHLITE_API int sphlite_get_version(int *major, int *minor, int *patch);
|
||||
@@ -120,6 +143,54 @@ SPHLITE_API int sphlite_get_solid_reference_quality(int *reference_neighbor_min,
|
||||
int *correction_status,
|
||||
double *values,
|
||||
int value_capacity);
|
||||
SPHLITE_API int sphlite_coupling_get_region_count(int *count);
|
||||
SPHLITE_API int sphlite_coupling_get_region_info(int region_index,
|
||||
char *name,
|
||||
int name_capacity,
|
||||
int *region_type,
|
||||
int *export_mode,
|
||||
int *import_mode,
|
||||
int *enabled,
|
||||
int *particle_count,
|
||||
int *facet_count);
|
||||
SPHLITE_API int sphlite_coupling_export_particles(int region_index,
|
||||
int capacity,
|
||||
int *count,
|
||||
int *ext_ids,
|
||||
int *internal_indices,
|
||||
int *phases,
|
||||
int *statuses,
|
||||
int *materials,
|
||||
int *sections,
|
||||
double *scalar_values,
|
||||
double *vector_values);
|
||||
SPHLITE_API int sphlite_coupling_export_facets(int region_index,
|
||||
int capacity,
|
||||
int *count,
|
||||
int *facet_ids,
|
||||
int *particle_ids,
|
||||
int *materials,
|
||||
int *sections,
|
||||
double *vector_values,
|
||||
double *area_values);
|
||||
SPHLITE_API int sphlite_coupling_apply_particle_forces(int region_index,
|
||||
int force_count,
|
||||
const int *export_indices,
|
||||
const double *forces);
|
||||
SPHLITE_API int sphlite_coupling_apply_facet_loads(int region_index,
|
||||
int load_count,
|
||||
const int *facet_ids,
|
||||
const double *loads);
|
||||
SPHLITE_API int sphlite_coupling_apply_motion_boundary(int region_index,
|
||||
int export_index,
|
||||
int target_kind,
|
||||
int mode,
|
||||
const double *target);
|
||||
SPHLITE_API int sphlite_coupling_clear_imports(void);
|
||||
SPHLITE_API int sphlite_coupling_get_diagnostics(double *values,
|
||||
int value_capacity,
|
||||
int *counts,
|
||||
int count_capacity);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user