#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 "fesa/property/ShellProperty.hpp" #include #include namespace { int require(bool condition) { return condition ? 0 : 1; } template 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}); domain.addMaterial(std::make_unique(700, 210.0, 0.3)); domain.addShellProperty(std::make_unique(500, 700, 0.01)); return domain; } int domain_owns_element_and_material_objects() { fesa::core::Domain domain = populated_domain(); domain.addElement(std::make_unique( 100, std::array{1, 2, 3, 4}, 500)); const fesa::element::Element* element = domain.findElement(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.element(100).propertyId() == 500); result != 0) { return result; } const fesa::material::Material* material = domain.findMaterial(700); if (const int result = require(material != nullptr); result != 0) { return result; } return require(domain.material(700).id() == 700); } int duplicate_element_and_material_object_ids_throw() { fesa::core::Domain domain = populated_domain(); domain.addElement(std::make_unique( 100, std::array{1, 2, 3, 4}, 500)); if (const int result = require_throws([&domain]() { domain.addElement(std::make_unique( 100, std::array{1, 2, 3, 4}, 500)); }); result != 0) { return result; } return require_throws([&domain]() { domain.addMaterial(std::make_unique(700, 100.0, 0.25)); }); } int missing_model_object_direct_lookup_throws() { const fesa::core::Domain domain; if (const int result = require(domain.findElement(404) == nullptr); result != 0) { return result; } if (const int result = require(domain.findMaterial(404) == nullptr); result != 0) { return result; } if (const int result = require_throws([&domain]() { (void)domain.element(404); }); result != 0) { return result; } return require_throws([&domain]() { (void)domain.material(404); }); } int domain_owns_load_and_boundary_objects_by_index() { fesa::core::Domain domain = populated_domain(); const std::size_t load_index = domain.addLoad( std::make_unique(1, fesa::core::Dof::U3, -100.0)); const std::size_t boundary_index = domain.addBoundaryCondition( std::make_unique(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.findLoad(load_index) != nullptr); result != 0) { return result; } if (const int result = require(domain.findBoundaryCondition(boundary_index) != nullptr); result != 0) { return result; } if (const int result = require(domain.load(load_index).kind() == fesa::load::LoadKind::Nodal); result != 0) { return result; } return require( domain.boundaryCondition(boundary_index).kind() == fesa::boundary::BoundaryConditionKind::SinglePointConstraint); } int duplicate_load_and_boundary_keys_throw() { fesa::core::Domain domain = populated_domain(); domain.addLoad(std::make_unique(1, fesa::core::Dof::U3, -100.0)); domain.addBoundaryCondition(std::make_unique(1, fesa::core::Dof::U1, 0.0)); if (const int result = require_throws([&domain]() { domain.addLoad(std::make_unique(1, fesa::core::Dof::U3, -200.0)); }); result != 0) { return result; } return require_throws([&domain]() { domain.addBoundaryCondition(std::make_unique(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; }