refactor: store runtime objects in domain
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include "fesa/element/Mitc4Element.hpp"
|
||||
#include "fesa/load/NodalLoad.hpp"
|
||||
#include "fesa/material/LinearElasticMaterial.hpp"
|
||||
#include "fesa/property/ShellProperty.hpp"
|
||||
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
@@ -31,46 +32,46 @@ fesa::core::Domain populated_domain() {
|
||||
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<fesa::material::LinearElasticMaterial>(700, 210.0, 0.3));
|
||||
domain.addShellProperty(fesa::property::ShellProperty{500, 700, 0.01});
|
||||
return domain;
|
||||
}
|
||||
|
||||
int domain_owns_element_and_material_objects() {
|
||||
fesa::core::Domain domain = populated_domain();
|
||||
|
||||
domain.addElementObject(std::make_unique<fesa::element::Mitc4Element>(
|
||||
domain.addElement(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);
|
||||
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.elementObject(100).propertyId() == 500); result != 0) {
|
||||
if (const int result = require(domain.element(100).propertyId() == 500); result != 0) {
|
||||
return result;
|
||||
}
|
||||
|
||||
const fesa::material::Material* material = domain.findMaterialObject(700);
|
||||
const fesa::material::Material* material = domain.findMaterial(700);
|
||||
if (const int result = require(material != nullptr); result != 0) {
|
||||
return result;
|
||||
}
|
||||
return require(domain.materialObject(700).id() == 700);
|
||||
return require(domain.material(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>(
|
||||
domain.addElement(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>(
|
||||
domain.addElement(std::make_unique<fesa::element::Mitc4Element>(
|
||||
100,
|
||||
std::array<fesa::core::NodeId, 4>{1, 2, 3, 4},
|
||||
500));
|
||||
@@ -79,36 +80,36 @@ int duplicate_element_and_material_object_ids_throw() {
|
||||
return result;
|
||||
}
|
||||
return require_throws<std::invalid_argument>([&domain]() {
|
||||
domain.addMaterialObject(std::make_unique<fesa::material::LinearElasticMaterial>(700, 100.0, 0.25));
|
||||
domain.addMaterial(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) {
|
||||
if (const int result = require(domain.findElement(404) == nullptr); result != 0) {
|
||||
return result;
|
||||
}
|
||||
if (const int result = require(domain.findMaterialObject(404) == nullptr); result != 0) {
|
||||
if (const int result = require(domain.findMaterial(404) == nullptr); result != 0) {
|
||||
return result;
|
||||
}
|
||||
if (const int result = require_throws<std::out_of_range>([&domain]() {
|
||||
(void)domain.elementObject(404);
|
||||
(void)domain.element(404);
|
||||
});
|
||||
result != 0) {
|
||||
return result;
|
||||
}
|
||||
return require_throws<std::out_of_range>([&domain]() {
|
||||
(void)domain.materialObject(404);
|
||||
(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.addLoadObject(
|
||||
const std::size_t load_index = domain.addLoad(
|
||||
std::make_unique<fesa::load::NodalLoad>(1, fesa::core::Dof::U3, -100.0));
|
||||
const std::size_t boundary_index = domain.addBoundaryObject(
|
||||
const std::size_t boundary_index = domain.addBoundaryCondition(
|
||||
std::make_unique<fesa::boundary::SinglePointConstraint>(1, fesa::core::Dof::U1, 0.0));
|
||||
|
||||
if (const int result = require(load_index == 0); result != 0) {
|
||||
@@ -117,33 +118,33 @@ int domain_owns_load_and_boundary_objects_by_index() {
|
||||
if (const int result = require(boundary_index == 0); result != 0) {
|
||||
return result;
|
||||
}
|
||||
if (const int result = require(domain.findLoadObject(load_index) != nullptr); result != 0) {
|
||||
if (const int result = require(domain.findLoad(load_index) != nullptr); result != 0) {
|
||||
return result;
|
||||
}
|
||||
if (const int result = require(domain.findBoundaryObject(boundary_index) != nullptr); result != 0) {
|
||||
if (const int result = require(domain.findBoundaryCondition(boundary_index) != nullptr); result != 0) {
|
||||
return result;
|
||||
}
|
||||
if (const int result = require(domain.loadObject(load_index).kind() == fesa::load::LoadKind::Nodal); result != 0) {
|
||||
if (const int result = require(domain.load(load_index).kind() == fesa::load::LoadKind::Nodal); result != 0) {
|
||||
return result;
|
||||
}
|
||||
return require(
|
||||
domain.boundaryObject(boundary_index).kind() ==
|
||||
domain.boundaryCondition(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));
|
||||
domain.addLoad(std::make_unique<fesa::load::NodalLoad>(1, fesa::core::Dof::U3, -100.0));
|
||||
domain.addBoundaryCondition(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));
|
||||
domain.addLoad(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));
|
||||
domain.addBoundaryCondition(std::make_unique<fesa::boundary::SinglePointConstraint>(1, fesa::core::Dof::U1, 1.0));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user