feat: add analysis model objects
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
int run_boundary_condition_tests();
|
||||
int run_domain_model_object_tests();
|
||||
int run_domain_storage_tests();
|
||||
int run_element_definition_tests();
|
||||
int run_load_definition_tests();
|
||||
@@ -27,6 +28,9 @@ int main() {
|
||||
if (const int result = run_boundary_condition_tests(); result != 0) {
|
||||
return result;
|
||||
}
|
||||
if (const int result = run_domain_model_object_tests(); result != 0) {
|
||||
return result;
|
||||
}
|
||||
if (const int result = run_load_definition_tests(); result != 0) {
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,169 @@
|
||||
#include "fesa/boundary/SinglePointConstraint.hpp"
|
||||
#include "fesa/core/Domain.hpp"
|
||||
#include "fesa/element/Mitc4Element.hpp"
|
||||
#include "fesa/load/NodalLoad.hpp"
|
||||
#include "fesa/material/LinearElasticMaterial.hpp"
|
||||
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace {
|
||||
|
||||
int require(bool condition) {
|
||||
return condition ? 0 : 1;
|
||||
}
|
||||
|
||||
template <typename Exception, typename Function>
|
||||
int require_throws(Function&& function) {
|
||||
try {
|
||||
function();
|
||||
} catch (const Exception&) {
|
||||
return 0;
|
||||
} catch (...) {
|
||||
return 1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
fesa::core::Domain populated_domain() {
|
||||
fesa::core::Domain domain;
|
||||
domain.addNode(fesa::core::Node{1, 0.0, 0.0, 0.0});
|
||||
domain.addNode(fesa::core::Node{2, 1.0, 0.0, 0.0});
|
||||
domain.addNode(fesa::core::Node{3, 1.0, 1.0, 0.0});
|
||||
domain.addNode(fesa::core::Node{4, 0.0, 1.0, 0.0});
|
||||
return domain;
|
||||
}
|
||||
|
||||
int domain_owns_element_and_material_objects() {
|
||||
fesa::core::Domain domain = populated_domain();
|
||||
|
||||
domain.addElementObject(std::make_unique<fesa::element::Mitc4Element>(
|
||||
100,
|
||||
std::array<fesa::core::NodeId, 4>{1, 2, 3, 4},
|
||||
500));
|
||||
domain.addMaterialObject(std::make_unique<fesa::material::LinearElasticMaterial>(700, 210.0, 0.3));
|
||||
|
||||
const fesa::element::Element* element = domain.findElementObject(100);
|
||||
if (const int result = require(element != nullptr); result != 0) {
|
||||
return result;
|
||||
}
|
||||
if (const int result = require(element->type() == fesa::core::ElementType::Mitc4); result != 0) {
|
||||
return result;
|
||||
}
|
||||
if (const int result = require(domain.elementObject(100).propertyId() == 500); result != 0) {
|
||||
return result;
|
||||
}
|
||||
|
||||
const fesa::material::Material* material = domain.findMaterialObject(700);
|
||||
if (const int result = require(material != nullptr); result != 0) {
|
||||
return result;
|
||||
}
|
||||
return require(domain.materialObject(700).id() == 700);
|
||||
}
|
||||
|
||||
int duplicate_element_and_material_object_ids_throw() {
|
||||
fesa::core::Domain domain = populated_domain();
|
||||
domain.addElementObject(std::make_unique<fesa::element::Mitc4Element>(
|
||||
100,
|
||||
std::array<fesa::core::NodeId, 4>{1, 2, 3, 4},
|
||||
500));
|
||||
domain.addMaterialObject(std::make_unique<fesa::material::LinearElasticMaterial>(700, 210.0, 0.3));
|
||||
|
||||
if (const int result = require_throws<std::invalid_argument>([&domain]() {
|
||||
domain.addElementObject(std::make_unique<fesa::element::Mitc4Element>(
|
||||
100,
|
||||
std::array<fesa::core::NodeId, 4>{1, 2, 3, 4},
|
||||
500));
|
||||
});
|
||||
result != 0) {
|
||||
return result;
|
||||
}
|
||||
return require_throws<std::invalid_argument>([&domain]() {
|
||||
domain.addMaterialObject(std::make_unique<fesa::material::LinearElasticMaterial>(700, 100.0, 0.25));
|
||||
});
|
||||
}
|
||||
|
||||
int missing_model_object_direct_lookup_throws() {
|
||||
const fesa::core::Domain domain;
|
||||
|
||||
if (const int result = require(domain.findElementObject(404) == nullptr); result != 0) {
|
||||
return result;
|
||||
}
|
||||
if (const int result = require(domain.findMaterialObject(404) == nullptr); result != 0) {
|
||||
return result;
|
||||
}
|
||||
if (const int result = require_throws<std::out_of_range>([&domain]() {
|
||||
(void)domain.elementObject(404);
|
||||
});
|
||||
result != 0) {
|
||||
return result;
|
||||
}
|
||||
return require_throws<std::out_of_range>([&domain]() {
|
||||
(void)domain.materialObject(404);
|
||||
});
|
||||
}
|
||||
|
||||
int domain_owns_load_and_boundary_objects_by_index() {
|
||||
fesa::core::Domain domain = populated_domain();
|
||||
|
||||
const std::size_t load_index = domain.addLoadObject(
|
||||
std::make_unique<fesa::load::NodalLoad>(1, fesa::core::Dof::U3, -100.0));
|
||||
const std::size_t boundary_index = domain.addBoundaryObject(
|
||||
std::make_unique<fesa::boundary::SinglePointConstraint>(1, fesa::core::Dof::U1, 0.0));
|
||||
|
||||
if (const int result = require(load_index == 0); result != 0) {
|
||||
return result;
|
||||
}
|
||||
if (const int result = require(boundary_index == 0); result != 0) {
|
||||
return result;
|
||||
}
|
||||
if (const int result = require(domain.findLoadObject(load_index) != nullptr); result != 0) {
|
||||
return result;
|
||||
}
|
||||
if (const int result = require(domain.findBoundaryObject(boundary_index) != nullptr); result != 0) {
|
||||
return result;
|
||||
}
|
||||
if (const int result = require(domain.loadObject(load_index).kind() == fesa::load::LoadKind::Nodal); result != 0) {
|
||||
return result;
|
||||
}
|
||||
return require(
|
||||
domain.boundaryObject(boundary_index).kind() ==
|
||||
fesa::boundary::BoundaryConditionKind::SinglePointConstraint);
|
||||
}
|
||||
|
||||
int duplicate_load_and_boundary_keys_throw() {
|
||||
fesa::core::Domain domain = populated_domain();
|
||||
domain.addLoadObject(std::make_unique<fesa::load::NodalLoad>(1, fesa::core::Dof::U3, -100.0));
|
||||
domain.addBoundaryObject(std::make_unique<fesa::boundary::SinglePointConstraint>(1, fesa::core::Dof::U1, 0.0));
|
||||
|
||||
if (const int result = require_throws<std::invalid_argument>([&domain]() {
|
||||
domain.addLoadObject(std::make_unique<fesa::load::NodalLoad>(1, fesa::core::Dof::U3, -200.0));
|
||||
});
|
||||
result != 0) {
|
||||
return result;
|
||||
}
|
||||
return require_throws<std::invalid_argument>([&domain]() {
|
||||
domain.addBoundaryObject(std::make_unique<fesa::boundary::SinglePointConstraint>(1, fesa::core::Dof::U1, 1.0));
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int run_domain_model_object_tests() {
|
||||
if (const int result = domain_owns_element_and_material_objects(); result != 0) {
|
||||
return result;
|
||||
}
|
||||
if (const int result = duplicate_element_and_material_object_ids_throw(); result != 0) {
|
||||
return result;
|
||||
}
|
||||
if (const int result = missing_model_object_direct_lookup_throws(); result != 0) {
|
||||
return result;
|
||||
}
|
||||
if (const int result = domain_owns_load_and_boundary_objects_by_index(); result != 0) {
|
||||
return result;
|
||||
}
|
||||
if (const int result = duplicate_load_and_boundary_keys_throw(); result != 0) {
|
||||
return result;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
#include "fesa/core/Node.hpp"
|
||||
|
||||
#include <array>
|
||||
#include <type_traits>
|
||||
|
||||
namespace {
|
||||
|
||||
int require(bool condition) {
|
||||
@@ -11,6 +14,9 @@ int require(bool condition) {
|
||||
int run_node_tests() {
|
||||
const fesa::core::Node node{42, 1.0, 2.0, 3.0};
|
||||
|
||||
if (const int result = require(fesa::core::Node::dofCount() == 6); result != 0) {
|
||||
return result;
|
||||
}
|
||||
if (const int result = require(node.id() == 42); result != 0) {
|
||||
return result;
|
||||
}
|
||||
@@ -32,6 +38,10 @@ int run_node_tests() {
|
||||
if (const int result = require(node.coordinates()[2] == 3.0); result != 0) {
|
||||
return result;
|
||||
}
|
||||
if (const int result = require((std::is_same<decltype(node.coordinates()), const std::array<double, 3>&>::value));
|
||||
result != 0) {
|
||||
return result;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user