#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 #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}); return domain; } int domain_owns_element_and_material_objects() { fesa::core::Domain domain = populated_domain(); domain.addElementObject(std::make_unique( 100, std::array{1, 2, 3, 4}, 500)); domain.addMaterialObject(std::make_unique(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( 100, std::array{1, 2, 3, 4}, 500)); domain.addMaterialObject(std::make_unique(700, 210.0, 0.3)); if (const int result = require_throws([&domain]() { domain.addElementObject(std::make_unique( 100, std::array{1, 2, 3, 4}, 500)); }); result != 0) { return result; } return require_throws([&domain]() { domain.addMaterialObject(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.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([&domain]() { (void)domain.elementObject(404); }); result != 0) { return result; } return require_throws([&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(1, fesa::core::Dof::U3, -100.0)); const std::size_t boundary_index = domain.addBoundaryObject( 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.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(1, fesa::core::Dof::U3, -100.0)); domain.addBoundaryObject(std::make_unique(1, fesa::core::Dof::U1, 0.0)); if (const int result = require_throws([&domain]() { domain.addLoadObject(std::make_unique(1, fesa::core::Dof::U3, -200.0)); }); result != 0) { return result; } return require_throws([&domain]() { domain.addBoundaryObject(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; }