Files
FESADev/tests/unit/analysis_model_view_test.cpp
T
2026-06-12 02:25:07 +09:00

74 lines
2.1 KiB
C++

#include <fesa/analysis/analysis_model.hpp>
#include <stdexcept>
namespace {
fesa::model::Domain make_domain()
{
fesa::model::Domain domain;
domain.add_node({fesa::core::NodeId{1}, {0.0, 0.0, 0.0}});
domain.add_node({fesa::core::NodeId{2}, {1.0, 0.0, 0.0}});
domain.add_material({fesa::core::MaterialId{3}, "steel"});
domain.add_property({fesa::core::PropertyId{4}, "bar", fesa::core::MaterialId{3}});
domain.add_element({
fesa::core::ElementId{5},
fesa::model::ElementTopology::truss2,
{fesa::core::NodeId{1}, fesa::core::NodeId{2}},
fesa::core::PropertyId{4}
});
fesa::model::AnalysisStep step{fesa::core::StepId{6}, "static"};
step.add_boundary_condition({fesa::core::NodeId{1}, fesa::model::DofComponent::ux, 0.0});
step.add_load({fesa::core::NodeId{2}, fesa::model::DofComponent::ux, 10.0});
domain.add_step(step);
return domain;
}
int fail()
{
return 1;
}
} // namespace
int main()
{
const auto domain = make_domain();
const fesa::analysis::AnalysisModel model{domain, fesa::core::StepId{6}};
if (&model.domain() != &domain) {
return fail();
}
if (&model.step() != domain.find_step(fesa::core::StepId{6})) {
return fail();
}
if (model.active_elements().size() != 1 ||
model.active_elements()[0] != domain.find_element(fesa::core::ElementId{5})) {
return fail();
}
if (model.active_boundary_conditions().size() != 1 ||
model.active_loads().size() != 1) {
return fail();
}
const auto* property = model.property_for(*model.active_elements()[0]);
if (property == nullptr || property != domain.find_property(fesa::core::PropertyId{4})) {
return fail();
}
const auto* material = model.material_for(*property);
if (material == nullptr || material != domain.find_material(fesa::core::MaterialId{3})) {
return fail();
}
try {
const fesa::analysis::AnalysisModel missing{domain, fesa::core::StepId{99}};
(void)missing;
return fail();
} catch (const std::invalid_argument&) {
}
return 0;
}