Files
SPHLite/tests/interface/test_cpp_api.cpp
T
2026-07-03 12:32:14 +08:00

99 lines
3.0 KiB
C++

#include "sphlite.hpp"
#include <cstdlib>
int main()
{
if (sphlite::PhaseSolid != SPHLITE_PHASE_SOLID ||
sphlite::PhaseWater != SPHLITE_PHASE_WATER ||
sphlite::StatusActive != SPHLITE_STATUS_ACTIVE ||
sphlite::StatusFailed != SPHLITE_STATUS_FAILED) {
return 1;
}
{
sphlite::Session session;
sphlite::Version version = sphlite::version();
if (version.major != 0 || version.minor != 4 || version.patch != 0) {
return 1;
}
std::string input = std::string(SPHLITE_TEST_DATA_DIR) + "/minimal_particles_011.inp";
sphlite::read_inp(input);
sphlite::build_model();
if (sphlite::particle_count() != 4) {
return 1;
}
sphlite::ParticleState state = sphlite::particle_state();
if (state.particle_id_ext.size() != 4 || state.phase[0] != sphlite::PhaseSolid) {
return 1;
}
}
try {
(void)sphlite::particle_count();
return 1;
} catch (const sphlite::Error &) {
}
sphlite::Session water_session;
std::string water_input = std::string(SPHLITE_TEST_DATA_DIR) + "/water_minimal_020.inp";
sphlite::read_inp(water_input);
sphlite::build_model();
sphlite::WaterSummary summary = sphlite::water_summary();
if (summary.mass <= 0.0 || summary.min_density <= 0.0 ||
summary.max_density < summary.min_density) {
return 1;
}
sphlite::WaterDtLimits limits = sphlite::water_dt_limits();
if (limits.cfl <= 0.0 || limits.acceleration <= 0.0 || limits.viscous <= 0.0) {
return 1;
}
water_session.close();
sphlite::Session gas_session;
std::string gas_input = std::string(SPHLITE_TEST_DATA_DIR) + "/gas_ideal_minimal_030.inp";
sphlite::read_inp(gas_input);
sphlite::build_model();
sphlite::GasSummary gas_summary = sphlite::gas_summary();
if (gas_summary.volume <= 0.0 || gas_summary.max_pressure <= 0.0) {
return 1;
}
sphlite::GasBubbleMetrics bubble = sphlite::gas_bubble_metrics();
if (bubble.equivalent_radius <= 0.0) {
return 1;
}
sphlite::GasDtLimits gas_limits = sphlite::gas_dt_limits();
if (gas_limits.cfl <= 0.0 || gas_limits.dtcrit <= 0.0) {
return 1;
}
sphlite::GasExtendedSummary extended = sphlite::gas_extended_summary();
if (extended.mass <= 0.0 || extended.density_range[1] < extended.density_range[0]) {
return 1;
}
sphlite::GasSourceSummary source = sphlite::gas_source_summary();
if (source.mass_source != 0.0 || source.energy_source != 0.0) {
return 1;
}
gas_session.close();
sphlite::Session explosive_session;
std::string explosive_input =
std::string(SPHLITE_TEST_DATA_DIR) + "/explosive_conversion_phase_040.inp";
sphlite::read_inp(explosive_input);
sphlite::set_ignition_point(0.0, 0.0, 0.0, 0.0);
sphlite::build_model();
sphlite::run_explicit();
sphlite::ExplosiveSummary explosive = sphlite::explosive_summary();
if (explosive.particle_count <= 0 || explosive.reacted_count <= 0) {
return 1;
}
if (explosive.lambda_range[1] <= 0.0 || explosive.released_totals[1] <= 0.0) {
return 1;
}
explosive_session.close();
return 0;
}