feat(cpp-object-oriented-modular-refactoring): step 5 - solver-workflow-google-style
This commit is contained in:
@@ -1,8 +1,4 @@
|
||||
#include "fesa/assembly/load_assembler.hpp"
|
||||
|
||||
#include "fesa/analysis/analysis_model.hpp"
|
||||
#include "fesa/fem/dof_manager.hpp"
|
||||
#include "fesa/model/domain.h"
|
||||
#include "fesa/assembly/load_assembler.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
@@ -18,489 +14,410 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "fesa/analysis/analysis_model.h"
|
||||
#include "fesa/fem/dof_manager.h"
|
||||
#include "fesa/model/domain.h"
|
||||
|
||||
namespace {
|
||||
|
||||
struct LoadFixture {
|
||||
std::unique_ptr<fesa::Domain> domain;
|
||||
std::unique_ptr<fesa::AnalysisModel> model;
|
||||
std::unique_ptr<fesa::DofManager> dofs;
|
||||
std::unique_ptr<fesa::Domain> domain;
|
||||
std::unique_ptr<fesa::AnalysisModel> model;
|
||||
std::unique_ptr<fesa::DofManager> dofs;
|
||||
};
|
||||
|
||||
LoadFixture makeFixture(
|
||||
const std::size_t nodeCount,
|
||||
std::vector<fesa::NodeSet> nodeSets,
|
||||
std::vector<fesa::BoundaryCondition> boundaries,
|
||||
std::vector<fesa::NodalLoad> loads) {
|
||||
const std::filesystem::path source{"models/load-assembly.inp"};
|
||||
fesa::ModelDefinition definition{};
|
||||
definition.source_path = source;
|
||||
definition.source_content_identity = "fnv1a64:abcdef0123456789";
|
||||
for (std::size_t index = 0U; index < nodeCount; ++index) {
|
||||
const auto label = static_cast<std::int64_t>((index + 1U) * 10U);
|
||||
definition.nodes.push_back({
|
||||
{"Beam-1", label, std::to_string(label)},
|
||||
{static_cast<double>(index), 0.0, 0.0},
|
||||
{source, index + 2U}});
|
||||
}
|
||||
definition.node_sets = std::move(nodeSets);
|
||||
definition.steps = {{
|
||||
"Step-1",
|
||||
std::move(boundaries),
|
||||
std::move(loads),
|
||||
0.1,
|
||||
1.0,
|
||||
0.01,
|
||||
1.0,
|
||||
{source, 20U}}};
|
||||
LoadFixture MakeFixture(const std::size_t node_count,
|
||||
std::vector<fesa::NodeSet> node_sets,
|
||||
std::vector<fesa::BoundaryCondition> boundaries,
|
||||
std::vector<fesa::NodalLoad> loads) {
|
||||
const std::filesystem::path source{"models/load-assembly.inp"};
|
||||
fesa::ModelDefinition definition{};
|
||||
definition.source_path = source;
|
||||
definition.source_content_identity = "fnv1a64:abcdef0123456789";
|
||||
for (std::size_t index = 0U; index < node_count; ++index) {
|
||||
const auto label = static_cast<std::int64_t>((index + 1U) * 10U);
|
||||
definition.nodes.push_back({{"Beam-1", label, std::to_string(label)},
|
||||
{static_cast<double>(index), 0.0, 0.0},
|
||||
{source, index + 2U}});
|
||||
}
|
||||
definition.node_sets = std::move(node_sets);
|
||||
definition.steps = {{"Step-1",
|
||||
std::move(boundaries),
|
||||
std::move(loads),
|
||||
0.1,
|
||||
1.0,
|
||||
0.01,
|
||||
1.0,
|
||||
{source, 20U}}};
|
||||
|
||||
auto domainResult = fesa::Domain::Create(std::move(definition));
|
||||
if (!domainResult.HasValue()) {
|
||||
throw std::runtime_error{"Load fixture Domain construction failed."};
|
||||
}
|
||||
auto domain = std::make_unique<fesa::Domain>(
|
||||
std::move(domainResult.Value()));
|
||||
auto domain_result = fesa::Domain::Create(std::move(definition));
|
||||
if (!domain_result.HasValue()) {
|
||||
throw std::runtime_error{"Load fixture Domain construction failed."};
|
||||
}
|
||||
auto domain =
|
||||
std::make_unique<fesa::Domain>(std::move(domain_result.Value()));
|
||||
|
||||
auto modelResult = fesa::AnalysisModel::create(*domain);
|
||||
if (!modelResult.HasValue()) {
|
||||
throw std::runtime_error{"Load fixture AnalysisModel construction failed."};
|
||||
}
|
||||
auto model = std::make_unique<fesa::AnalysisModel>(
|
||||
std::move(modelResult.Value()));
|
||||
auto model_result = fesa::AnalysisModel::Create(*domain);
|
||||
if (!model_result.HasValue()) {
|
||||
throw std::runtime_error{"Load fixture AnalysisModel construction failed."};
|
||||
}
|
||||
auto model =
|
||||
std::make_unique<fesa::AnalysisModel>(std::move(model_result.Value()));
|
||||
|
||||
auto dofResult = fesa::DofManager::create(*model);
|
||||
if (!dofResult.HasValue()) {
|
||||
throw std::runtime_error{"Load fixture DofManager construction failed."};
|
||||
}
|
||||
auto dofs = std::make_unique<fesa::DofManager>(
|
||||
std::move(dofResult.Value()));
|
||||
return {std::move(domain), std::move(model), std::move(dofs)};
|
||||
auto dof_result = fesa::DofManager::Create(*model);
|
||||
if (!dof_result.HasValue()) {
|
||||
throw std::runtime_error{"Load fixture DofManager construction failed."};
|
||||
}
|
||||
auto dofs = std::make_unique<fesa::DofManager>(std::move(dof_result.Value()));
|
||||
return {std::move(domain), std::move(model), std::move(dofs)};
|
||||
}
|
||||
|
||||
LoadFixture makeShellFixture(
|
||||
std::vector<fesa::BoundaryCondition> boundaries,
|
||||
std::vector<fesa::NodalLoad> loads) {
|
||||
const std::filesystem::path source{"models/shell-load-assembly.inp"};
|
||||
fesa::ModelDefinition definition{};
|
||||
definition.source_path = source;
|
||||
definition.source_content_identity = "fnv1a64:1122334455667788";
|
||||
definition.nodes = {
|
||||
{{"Shell-1", 10, "10"}, {0.0, 0.0, 0.0}, {source, 2U}},
|
||||
{{"Shell-1", 20, "20"}, {1.0, 0.0, 0.0}, {source, 3U}},
|
||||
{{"Shell-1", 30, "30"}, {1.0, 1.0, 0.0}, {source, 4U}},
|
||||
{{"Shell-1", 40, "40"}, {0.0, 1.0, 0.0}, {source, 5U}}};
|
||||
definition.materials = {
|
||||
{"Material", 1000.0, 0.25, {source, 6U}}};
|
||||
definition.shell_sections = {
|
||||
{"ShellSection", 0.1, 0U, {source, 7U}}};
|
||||
definition.shell_elements = {{
|
||||
{"Shell-1", 1, "1"},
|
||||
fesa::ShellSourceElementType::kS4,
|
||||
{0U, 1U, 2U, 3U},
|
||||
0U,
|
||||
0U,
|
||||
{source, 8U}}};
|
||||
for (std::size_t node = 0U; node < definition.nodes.size(); ++node) {
|
||||
definition.shell_node_initial_frames.push_back({
|
||||
static_cast<fesa::EntityIndex>(node),
|
||||
{0.0, 0.0, 1.0},
|
||||
{1.0, 0.0, 0.0},
|
||||
{0.0, 1.0, 0.0}});
|
||||
}
|
||||
definition.steps = {{
|
||||
"Step-1",
|
||||
std::move(boundaries),
|
||||
std::move(loads),
|
||||
0.1,
|
||||
1.0,
|
||||
0.01,
|
||||
1.0,
|
||||
{source, 20U}}};
|
||||
LoadFixture MakeShellFixture(std::vector<fesa::BoundaryCondition> boundaries,
|
||||
std::vector<fesa::NodalLoad> loads) {
|
||||
const std::filesystem::path source{"models/shell-load-assembly.inp"};
|
||||
fesa::ModelDefinition definition{};
|
||||
definition.source_path = source;
|
||||
definition.source_content_identity = "fnv1a64:1122334455667788";
|
||||
definition.nodes = {{{"Shell-1", 10, "10"}, {0.0, 0.0, 0.0}, {source, 2U}},
|
||||
{{"Shell-1", 20, "20"}, {1.0, 0.0, 0.0}, {source, 3U}},
|
||||
{{"Shell-1", 30, "30"}, {1.0, 1.0, 0.0}, {source, 4U}},
|
||||
{{"Shell-1", 40, "40"}, {0.0, 1.0, 0.0}, {source, 5U}}};
|
||||
definition.materials = {{"Material", 1000.0, 0.25, {source, 6U}}};
|
||||
definition.shell_sections = {{"ShellSection", 0.1, 0U, {source, 7U}}};
|
||||
definition.shell_elements = {{{"Shell-1", 1, "1"},
|
||||
fesa::ShellSourceElementType::kS4,
|
||||
{0U, 1U, 2U, 3U},
|
||||
0U,
|
||||
0U,
|
||||
{source, 8U}}};
|
||||
for (std::size_t node = 0U; node < definition.nodes.size(); ++node) {
|
||||
definition.shell_node_initial_frames.push_back(
|
||||
{static_cast<fesa::EntityIndex>(node),
|
||||
{0.0, 0.0, 1.0},
|
||||
{1.0, 0.0, 0.0},
|
||||
{0.0, 1.0, 0.0}});
|
||||
}
|
||||
definition.steps = {{"Step-1",
|
||||
std::move(boundaries),
|
||||
std::move(loads),
|
||||
0.1,
|
||||
1.0,
|
||||
0.01,
|
||||
1.0,
|
||||
{source, 20U}}};
|
||||
|
||||
auto domainResult = fesa::Domain::Create(std::move(definition));
|
||||
if (!domainResult.HasValue()) {
|
||||
throw std::runtime_error{"Shell load fixture Domain construction failed."};
|
||||
}
|
||||
auto domain = std::make_unique<fesa::Domain>(
|
||||
std::move(domainResult.Value()));
|
||||
auto domain_result = fesa::Domain::Create(std::move(definition));
|
||||
if (!domain_result.HasValue()) {
|
||||
throw std::runtime_error{"Shell load fixture Domain construction failed."};
|
||||
}
|
||||
auto domain =
|
||||
std::make_unique<fesa::Domain>(std::move(domain_result.Value()));
|
||||
|
||||
auto modelResult = fesa::AnalysisModel::create(*domain);
|
||||
if (!modelResult.HasValue()) {
|
||||
throw std::runtime_error{"Shell load fixture AnalysisModel construction failed."};
|
||||
}
|
||||
auto model = std::make_unique<fesa::AnalysisModel>(
|
||||
std::move(modelResult.Value()));
|
||||
auto model_result = fesa::AnalysisModel::Create(*domain);
|
||||
if (!model_result.HasValue()) {
|
||||
throw std::runtime_error{
|
||||
"Shell load fixture AnalysisModel construction failed."};
|
||||
}
|
||||
auto model =
|
||||
std::make_unique<fesa::AnalysisModel>(std::move(model_result.Value()));
|
||||
|
||||
auto dofResult = fesa::DofManager::create(*model);
|
||||
if (!dofResult.HasValue()) {
|
||||
throw std::runtime_error{"Shell load fixture DofManager construction failed."};
|
||||
}
|
||||
auto dofs = std::make_unique<fesa::DofManager>(
|
||||
std::move(dofResult.Value()));
|
||||
return {std::move(domain), std::move(model), std::move(dofs)};
|
||||
auto dof_result = fesa::DofManager::Create(*model);
|
||||
if (!dof_result.HasValue()) {
|
||||
throw std::runtime_error{
|
||||
"Shell load fixture DofManager construction failed."};
|
||||
}
|
||||
auto dofs = std::make_unique<fesa::DofManager>(std::move(dof_result.Value()));
|
||||
return {std::move(domain), std::move(model), std::move(dofs)};
|
||||
}
|
||||
|
||||
fesa::SparseMatrix makeDenseSparse(
|
||||
const std::size_t rows,
|
||||
const std::size_t columns,
|
||||
const std::vector<double>& values) {
|
||||
if (values.size() != rows * columns) {
|
||||
throw std::invalid_argument{"Dense sparse fixture has the wrong value count."};
|
||||
}
|
||||
fesa::SparseMatrix MakeDenseSparse(const std::size_t rows,
|
||||
const std::size_t columns,
|
||||
const std::vector<double>& values) {
|
||||
if (values.size() != rows * columns) {
|
||||
throw std::invalid_argument{
|
||||
"Dense sparse fixture has the wrong value count."};
|
||||
}
|
||||
|
||||
fesa::SparsePattern pattern;
|
||||
std::vector<fesa::CooContribution> contributions;
|
||||
pattern.rowOffsets.reserve(rows + 1U);
|
||||
pattern.rowOffsets.push_back(0U);
|
||||
for (std::size_t row = 0U; row < rows; ++row) {
|
||||
for (std::size_t column = 0U; column < columns; ++column) {
|
||||
pattern.columnIndices.push_back(column);
|
||||
contributions.push_back({
|
||||
row,
|
||||
column,
|
||||
values[row * columns + column],
|
||||
row,
|
||||
column});
|
||||
}
|
||||
pattern.rowOffsets.push_back(pattern.columnIndices.size());
|
||||
fesa::SparsePattern pattern;
|
||||
std::vector<fesa::CooContribution> contributions;
|
||||
pattern.row_offsets.reserve(rows + 1U);
|
||||
pattern.row_offsets.push_back(0U);
|
||||
for (std::size_t row = 0U; row < rows; ++row) {
|
||||
for (std::size_t column = 0U; column < columns; ++column) {
|
||||
pattern.column_indices.push_back(column);
|
||||
contributions.push_back(
|
||||
{row, column, values[row * columns + column], row, column});
|
||||
}
|
||||
pattern.row_offsets.push_back(pattern.column_indices.size());
|
||||
}
|
||||
|
||||
auto result = fesa::SparseMatrix::FromCoo(
|
||||
rows, columns, std::move(contributions), pattern);
|
||||
if (!result.HasValue()) {
|
||||
throw std::runtime_error{"Sparse fixture construction failed."};
|
||||
}
|
||||
return std::move(result.Value());
|
||||
auto result = fesa::SparseMatrix::FromCoo(rows, columns,
|
||||
std::move(contributions), pattern);
|
||||
if (!result.HasValue()) {
|
||||
throw std::runtime_error{"Sparse fixture construction failed."};
|
||||
}
|
||||
return std::move(result.Value());
|
||||
}
|
||||
|
||||
void expectFailureCode(
|
||||
const fesa::Result<fesa::Vector>& result,
|
||||
const std::string& code) {
|
||||
ASSERT_FALSE(result.HasValue());
|
||||
EXPECT_EQ(result.GetStatus().Category(), fesa::FailureCategory::kModel);
|
||||
ASSERT_EQ(result.GetStatus().Diagnostics().size(), 1U);
|
||||
EXPECT_EQ(result.GetStatus().Diagnostics()[0U].code, code);
|
||||
void ExpectFailureCode(const fesa::Result<fesa::Vector>& result,
|
||||
const std::string& code) {
|
||||
ASSERT_FALSE(result.HasValue());
|
||||
EXPECT_EQ(result.GetStatus().Category(), fesa::FailureCategory::kModel);
|
||||
ASSERT_EQ(result.GetStatus().Diagnostics().size(), 1U);
|
||||
EXPECT_EQ(result.GetStatus().Diagnostics()[0U].code, code);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
TEST(LoadAssembly, AssemblesNodeSetAndSixComponentLoads) {
|
||||
const std::filesystem::path source{"models/load-assembly.inp"};
|
||||
auto fixture = makeFixture(
|
||||
2U,
|
||||
{{"Pair", std::nullopt, {0U, 1U}, {source, 10U}}},
|
||||
{{"10", 1, 1, 0.0, {source, 21U}}},
|
||||
{{"pair", 1, 1.0, {source, 30U}},
|
||||
{"10", 2, 2.0, {source, 31U}},
|
||||
{"20", 3, 3.0, {source, 32U}},
|
||||
{"10", 4, -4.0, {source, 33U}},
|
||||
{"PAIR", 5, 5.0, {source, 34U}},
|
||||
{"20", 6, 6.0, {source, 35U}}});
|
||||
const std::filesystem::path source{"models/load-assembly.inp"};
|
||||
auto fixture =
|
||||
MakeFixture(2U, {{"Pair", std::nullopt, {0U, 1U}, {source, 10U}}},
|
||||
{{"10", 1, 1, 0.0, {source, 21U}}},
|
||||
{{"pair", 1, 1.0, {source, 30U}},
|
||||
{"10", 2, 2.0, {source, 31U}},
|
||||
{"20", 3, 3.0, {source, 32U}},
|
||||
{"10", 4, -4.0, {source, 33U}},
|
||||
{"PAIR", 5, 5.0, {source, 34U}},
|
||||
{"20", 6, 6.0, {source, 35U}}});
|
||||
|
||||
auto result = fesa::LoadAssembler::assembleFullNodalLoad(
|
||||
*fixture.model, *fixture.dofs);
|
||||
ASSERT_TRUE(result.HasValue());
|
||||
ASSERT_EQ(result.Value().Size(), 12U);
|
||||
EXPECT_EQ(
|
||||
std::vector<double>(result.Value().Data(), result.Value().Data() + 12U),
|
||||
(std::vector<double>{
|
||||
1.0, 2.0, 0.0, -4.0, 5.0, 0.0,
|
||||
1.0, 0.0, 3.0, 0.0, 5.0, 6.0}));
|
||||
EXPECT_EQ(fixture.dofs->constrainedDofs(),
|
||||
(std::vector<std::size_t>{0U}));
|
||||
EXPECT_DOUBLE_EQ(result.Value()[0U], 1.0);
|
||||
auto result =
|
||||
fesa::LoadAssembler::AssembleFullNodalLoad(*fixture.model, *fixture.dofs);
|
||||
ASSERT_TRUE(result.HasValue());
|
||||
ASSERT_EQ(result.Value().Size(), 12U);
|
||||
EXPECT_EQ(
|
||||
std::vector<double>(result.Value().Data(), result.Value().Data() + 12U),
|
||||
(std::vector<double>{1.0, 2.0, 0.0, -4.0, 5.0, 0.0, 1.0, 0.0, 3.0, 0.0,
|
||||
5.0, 6.0}));
|
||||
EXPECT_EQ(fixture.dofs->ConstrainedDofs(), (std::vector<std::size_t>{0U}));
|
||||
EXPECT_DOUBLE_EQ(result.Value()[0U], 1.0);
|
||||
}
|
||||
|
||||
TEST(LoadAssembly, AccumulatesSignedLoadsInSourceOrder) {
|
||||
const std::filesystem::path source{"models/load-assembly.inp"};
|
||||
auto firstOrder = makeFixture(
|
||||
1U,
|
||||
{},
|
||||
{},
|
||||
{{"10", 1, 1.0e16, {source, 30U}},
|
||||
{"10", 1, -1.0e16, {source, 31U}},
|
||||
{"10", 1, 1.0, {source, 32U}}});
|
||||
auto secondOrder = makeFixture(
|
||||
1U,
|
||||
{},
|
||||
{},
|
||||
{{"10", 1, 1.0e16, {source, 30U}},
|
||||
{"10", 1, 1.0, {source, 31U}},
|
||||
{"10", 1, -1.0e16, {source, 32U}}});
|
||||
const std::filesystem::path source{"models/load-assembly.inp"};
|
||||
auto first_order = MakeFixture(1U, {}, {},
|
||||
{{"10", 1, 1.0e16, {source, 30U}},
|
||||
{"10", 1, -1.0e16, {source, 31U}},
|
||||
{"10", 1, 1.0, {source, 32U}}});
|
||||
auto second_order = MakeFixture(1U, {}, {},
|
||||
{{"10", 1, 1.0e16, {source, 30U}},
|
||||
{"10", 1, 1.0, {source, 31U}},
|
||||
{"10", 1, -1.0e16, {source, 32U}}});
|
||||
|
||||
auto first = fesa::LoadAssembler::assembleFullNodalLoad(
|
||||
*firstOrder.model, *firstOrder.dofs);
|
||||
auto second = fesa::LoadAssembler::assembleFullNodalLoad(
|
||||
*secondOrder.model, *secondOrder.dofs);
|
||||
ASSERT_TRUE(first.HasValue());
|
||||
ASSERT_TRUE(second.HasValue());
|
||||
EXPECT_DOUBLE_EQ(first.Value()[0U], 1.0);
|
||||
EXPECT_DOUBLE_EQ(second.Value()[0U], 0.0);
|
||||
auto first = fesa::LoadAssembler::AssembleFullNodalLoad(*first_order.model,
|
||||
*first_order.dofs);
|
||||
auto second = fesa::LoadAssembler::AssembleFullNodalLoad(*second_order.model,
|
||||
*second_order.dofs);
|
||||
ASSERT_TRUE(first.HasValue());
|
||||
ASSERT_TRUE(second.HasValue());
|
||||
EXPECT_DOUBLE_EQ(first.Value()[0U], 1.0);
|
||||
EXPECT_DOUBLE_EQ(second.Value()[0U], 0.0);
|
||||
}
|
||||
|
||||
// MITC4-LOAD-001
|
||||
TEST(LoadAssembly, AggregatesAllSixGlobalShellLoadComponentsInSourceOrder) {
|
||||
const std::filesystem::path source{"models/shell-load-assembly.inp"};
|
||||
auto fixture = makeShellFixture(
|
||||
{},
|
||||
{{"10", 1, 1.0e16, {source, 30U}},
|
||||
{"10", 1, -1.0e16, {source, 31U}},
|
||||
{"10", 1, 1.0, {source, 32U}},
|
||||
{"10", 2, 2.0, {source, 33U}},
|
||||
{"10", 3, 3.0, {source, 34U}},
|
||||
{"10", 4, 1.0e16, {source, 35U}},
|
||||
{"10", 4, -1.0e16, {source, 36U}},
|
||||
{"10", 4, 4.0, {source, 37U}},
|
||||
{"10", 5, 5.0, {source, 38U}},
|
||||
{"10", 6, 6.0, {source, 39U}},
|
||||
{"10", 6, -6.0, {source, 40U}}});
|
||||
const std::filesystem::path source{"models/shell-load-assembly.inp"};
|
||||
auto fixture = MakeShellFixture({}, {{"10", 1, 1.0e16, {source, 30U}},
|
||||
{"10", 1, -1.0e16, {source, 31U}},
|
||||
{"10", 1, 1.0, {source, 32U}},
|
||||
{"10", 2, 2.0, {source, 33U}},
|
||||
{"10", 3, 3.0, {source, 34U}},
|
||||
{"10", 4, 1.0e16, {source, 35U}},
|
||||
{"10", 4, -1.0e16, {source, 36U}},
|
||||
{"10", 4, 4.0, {source, 37U}},
|
||||
{"10", 5, 5.0, {source, 38U}},
|
||||
{"10", 6, 6.0, {source, 39U}},
|
||||
{"10", 6, -6.0, {source, 40U}}});
|
||||
|
||||
const auto result = fesa::LoadAssembler::assembleFullNodalLoad(
|
||||
*fixture.model, *fixture.dofs);
|
||||
const auto result =
|
||||
fesa::LoadAssembler::AssembleFullNodalLoad(*fixture.model, *fixture.dofs);
|
||||
|
||||
ASSERT_TRUE(result.HasValue());
|
||||
ASSERT_EQ(result.Value().Size(), 24U);
|
||||
EXPECT_EQ(
|
||||
std::vector<double>(result.Value().Data(), result.Value().Data() + 6U),
|
||||
(std::vector<double>{1.0, 2.0, 3.0, 4.0, 5.0, 0.0}));
|
||||
ASSERT_TRUE(result.HasValue());
|
||||
ASSERT_EQ(result.Value().Size(), 24U);
|
||||
EXPECT_EQ(
|
||||
std::vector<double>(result.Value().Data(), result.Value().Data() + 6U),
|
||||
(std::vector<double>{1.0, 2.0, 3.0, 4.0, 5.0, 0.0}));
|
||||
}
|
||||
|
||||
// MITC4-LOAD-002
|
||||
TEST(LoadAssembly, AcceptsExactlyZeroAggregateShellMoment) {
|
||||
const std::filesystem::path source{"models/shell-load-assembly.inp"};
|
||||
auto fixture = makeShellFixture(
|
||||
{},
|
||||
{{"10", 4, 3.0, {source, 30U}},
|
||||
{"10", 4, -3.0, {source, 31U}},
|
||||
{"10", 5, 4.0, {source, 32U}},
|
||||
{"10", 5, -4.0, {source, 33U}},
|
||||
{"10", 6, 5.0, {source, 34U}},
|
||||
{"10", 6, -5.0, {source, 35U}}});
|
||||
const std::filesystem::path source{"models/shell-load-assembly.inp"};
|
||||
auto fixture = MakeShellFixture({}, {{"10", 4, 3.0, {source, 30U}},
|
||||
{"10", 4, -3.0, {source, 31U}},
|
||||
{"10", 5, 4.0, {source, 32U}},
|
||||
{"10", 5, -4.0, {source, 33U}},
|
||||
{"10", 6, 5.0, {source, 34U}},
|
||||
{"10", 6, -5.0, {source, 35U}}});
|
||||
|
||||
const auto result = fesa::LoadAssembler::assembleFullNodalLoad(
|
||||
*fixture.model, *fixture.dofs);
|
||||
const auto result =
|
||||
fesa::LoadAssembler::AssembleFullNodalLoad(*fixture.model, *fixture.dofs);
|
||||
|
||||
ASSERT_TRUE(result.HasValue());
|
||||
EXPECT_DOUBLE_EQ(result.Value()[3U], 0.0);
|
||||
EXPECT_DOUBLE_EQ(result.Value()[4U], 0.0);
|
||||
EXPECT_DOUBLE_EQ(result.Value()[5U], 0.0);
|
||||
ASSERT_TRUE(result.HasValue());
|
||||
EXPECT_DOUBLE_EQ(result.Value()[3U], 0.0);
|
||||
EXPECT_DOUBLE_EQ(result.Value()[4U], 0.0);
|
||||
EXPECT_DOUBLE_EQ(result.Value()[5U], 0.0);
|
||||
}
|
||||
|
||||
// MITC4-LOAD-003
|
||||
TEST(LoadAssembly, EnforcesAggregateShellMomentDirectorProjectionThreshold) {
|
||||
const std::filesystem::path source{"models/shell-load-assembly.inp"};
|
||||
auto acceptedFixture = makeShellFixture(
|
||||
{},
|
||||
{{"10", 4, 1.0, {source, 30U}},
|
||||
{"10", 6, 1.0e-12, {source, 31U}}});
|
||||
auto rejectedFixture = makeShellFixture(
|
||||
{},
|
||||
{{"10", 4, 1.0, {source, 30U}},
|
||||
{"10", 6, 2.0e-12, {source, 31U}}});
|
||||
const std::filesystem::path source{"models/shell-load-assembly.inp"};
|
||||
auto accepted_fixture = MakeShellFixture(
|
||||
{}, {{"10", 4, 1.0, {source, 30U}}, {"10", 6, 1.0e-12, {source, 31U}}});
|
||||
auto rejected_fixture = MakeShellFixture(
|
||||
{}, {{"10", 4, 1.0, {source, 30U}}, {"10", 6, 2.0e-12, {source, 31U}}});
|
||||
|
||||
const auto accepted = fesa::LoadAssembler::assembleFullNodalLoad(
|
||||
*acceptedFixture.model, *acceptedFixture.dofs);
|
||||
const auto rejected = fesa::LoadAssembler::assembleFullNodalLoad(
|
||||
*rejectedFixture.model, *rejectedFixture.dofs);
|
||||
const auto accepted = fesa::LoadAssembler::AssembleFullNodalLoad(
|
||||
*accepted_fixture.model, *accepted_fixture.dofs);
|
||||
const auto rejected = fesa::LoadAssembler::AssembleFullNodalLoad(
|
||||
*rejected_fixture.model, *rejected_fixture.dofs);
|
||||
|
||||
ASSERT_TRUE(accepted.HasValue());
|
||||
ASSERT_FALSE(rejected.HasValue());
|
||||
EXPECT_EQ(rejected.GetStatus().Category(), fesa::FailureCategory::kModel);
|
||||
ASSERT_EQ(rejected.GetStatus().Diagnostics().size(), 1U);
|
||||
EXPECT_EQ(
|
||||
rejected.GetStatus().Diagnostics()[0U].code,
|
||||
"unsupported-drilling-load");
|
||||
EXPECT_EQ(rejected.GetStatus().Diagnostics()[0U].keyword, "CLOAD");
|
||||
EXPECT_EQ(rejected.GetStatus().Diagnostics()[0U].entity_identity, "10");
|
||||
ASSERT_TRUE(accepted.HasValue());
|
||||
ASSERT_FALSE(rejected.HasValue());
|
||||
EXPECT_EQ(rejected.GetStatus().Category(), fesa::FailureCategory::kModel);
|
||||
ASSERT_EQ(rejected.GetStatus().Diagnostics().size(), 1U);
|
||||
EXPECT_EQ(rejected.GetStatus().Diagnostics()[0U].code,
|
||||
"unsupported-drilling-load");
|
||||
EXPECT_EQ(rejected.GetStatus().Diagnostics()[0U].keyword, "CLOAD");
|
||||
EXPECT_EQ(rejected.GetStatus().Diagnostics()[0U].entity_identity, "10");
|
||||
}
|
||||
|
||||
// MITC4-LOAD-004
|
||||
TEST(LoadAssembly, RejectsDrillingMomentBeforeEffectiveRhsCanBeFormed) {
|
||||
const std::filesystem::path source{"models/shell-load-assembly.inp"};
|
||||
auto fixture = makeShellFixture(
|
||||
{{"10", 1, 1, 2.0, {source, 21U}}},
|
||||
{{"10", 6, 1.0, {source, 30U}}});
|
||||
const std::filesystem::path source{"models/shell-load-assembly.inp"};
|
||||
auto fixture = MakeShellFixture({{"10", 1, 1, 2.0, {source, 21U}}},
|
||||
{{"10", 6, 1.0, {source, 30U}}});
|
||||
|
||||
const auto rejected = fesa::LoadAssembler::assembleFullNodalLoad(
|
||||
*fixture.model, *fixture.dofs);
|
||||
const auto rejected =
|
||||
fesa::LoadAssembler::AssembleFullNodalLoad(*fixture.model, *fixture.dofs);
|
||||
|
||||
ASSERT_FALSE(rejected.HasValue());
|
||||
EXPECT_EQ(rejected.GetStatus().Category(), fesa::FailureCategory::kModel);
|
||||
ASSERT_EQ(rejected.GetStatus().Diagnostics().size(), 1U);
|
||||
EXPECT_EQ(
|
||||
rejected.GetStatus().Diagnostics()[0U].code,
|
||||
"unsupported-drilling-load");
|
||||
ASSERT_FALSE(rejected.HasValue());
|
||||
EXPECT_EQ(rejected.GetStatus().Category(), fesa::FailureCategory::kModel);
|
||||
ASSERT_EQ(rejected.GetStatus().Diagnostics().size(), 1U);
|
||||
EXPECT_EQ(rejected.GetStatus().Diagnostics()[0U].code,
|
||||
"unsupported-drilling-load");
|
||||
}
|
||||
|
||||
TEST(LoadAssembly, FormsNonzeroPrescribedEffectiveRhs) {
|
||||
const std::filesystem::path source{"models/load-assembly.inp"};
|
||||
auto fixture = makeFixture(
|
||||
1U,
|
||||
{},
|
||||
{{"10", 2, 2, 2.0, {source, 21U}},
|
||||
{"10", 5, 5, -1.0, {source, 22U}}},
|
||||
{{"10", 1, 10.0, {source, 30U}},
|
||||
{"10", 2, 900.0, {source, 31U}},
|
||||
{"10", 3, 20.0, {source, 32U}},
|
||||
{"10", 4, 30.0, {source, 33U}},
|
||||
{"10", 5, 800.0, {source, 34U}},
|
||||
{"10", 6, 40.0, {source, 35U}}});
|
||||
auto full = fesa::LoadAssembler::assembleFullNodalLoad(
|
||||
*fixture.model, *fixture.dofs);
|
||||
ASSERT_TRUE(full.HasValue());
|
||||
const auto kfc = makeDenseSparse(
|
||||
4U,
|
||||
2U,
|
||||
{1.0, 2.0,
|
||||
3.0, 4.0,
|
||||
-2.0, 5.0,
|
||||
0.5, -1.0});
|
||||
const std::filesystem::path source{"models/load-assembly.inp"};
|
||||
auto fixture = MakeFixture(
|
||||
1U, {},
|
||||
{{"10", 2, 2, 2.0, {source, 21U}}, {"10", 5, 5, -1.0, {source, 22U}}},
|
||||
{{"10", 1, 10.0, {source, 30U}},
|
||||
{"10", 2, 900.0, {source, 31U}},
|
||||
{"10", 3, 20.0, {source, 32U}},
|
||||
{"10", 4, 30.0, {source, 33U}},
|
||||
{"10", 5, 800.0, {source, 34U}},
|
||||
{"10", 6, 40.0, {source, 35U}}});
|
||||
auto full =
|
||||
fesa::LoadAssembler::AssembleFullNodalLoad(*fixture.model, *fixture.dofs);
|
||||
ASSERT_TRUE(full.HasValue());
|
||||
const auto kfc =
|
||||
MakeDenseSparse(4U, 2U, {1.0, 2.0, 3.0, 4.0, -2.0, 5.0, 0.5, -1.0});
|
||||
|
||||
auto rhs = fesa::LoadAssembler::effectiveFreeRhs(
|
||||
full.Value(), kfc, fixture.dofs->prescribedValues(), *fixture.dofs);
|
||||
ASSERT_TRUE(rhs.HasValue());
|
||||
ASSERT_EQ(rhs.Value().Size(), 4U);
|
||||
EXPECT_EQ(
|
||||
std::vector<double>(rhs.Value().Data(), rhs.Value().Data() + 4U),
|
||||
(std::vector<double>{10.0, 18.0, 39.0, 38.0}));
|
||||
auto rhs = fesa::LoadAssembler::EffectiveFreeRhs(
|
||||
full.Value(), kfc, fixture.dofs->PrescribedValues(), *fixture.dofs);
|
||||
ASSERT_TRUE(rhs.HasValue());
|
||||
ASSERT_EQ(rhs.Value().Size(), 4U);
|
||||
EXPECT_EQ(std::vector<double>(rhs.Value().Data(), rhs.Value().Data() + 4U),
|
||||
(std::vector<double>{10.0, 18.0, 39.0, 38.0}));
|
||||
}
|
||||
|
||||
TEST(LoadAssembly, RejectsNonfiniteOrDimensionMismatch) {
|
||||
const std::filesystem::path source{"models/load-assembly.inp"};
|
||||
const double maximum = (std::numeric_limits<double>::max)();
|
||||
auto nonfinite = makeFixture(
|
||||
1U,
|
||||
{},
|
||||
{},
|
||||
{{"10", 1, std::numeric_limits<double>::quiet_NaN(), {source, 30U}}});
|
||||
expectFailureCode(
|
||||
fesa::LoadAssembler::assembleFullNodalLoad(
|
||||
*nonfinite.model, *nonfinite.dofs),
|
||||
"nonfinite-load-value");
|
||||
const std::filesystem::path source{"models/load-assembly.inp"};
|
||||
const double maximum = (std::numeric_limits<double>::max)();
|
||||
auto nonfinite = MakeFixture(
|
||||
1U, {}, {},
|
||||
{{"10", 1, std::numeric_limits<double>::quiet_NaN(), {source, 30U}}});
|
||||
ExpectFailureCode(fesa::LoadAssembler::AssembleFullNodalLoad(*nonfinite.model,
|
||||
*nonfinite.dofs),
|
||||
"nonfinite-load-value");
|
||||
|
||||
auto overflow = makeFixture(
|
||||
1U,
|
||||
{},
|
||||
{},
|
||||
{{"10", 1, maximum, {source, 30U}},
|
||||
{"10", 1, maximum, {source, 31U}}});
|
||||
expectFailureCode(
|
||||
fesa::LoadAssembler::assembleFullNodalLoad(
|
||||
*overflow.model, *overflow.dofs),
|
||||
"nonfinite-load-accumulation");
|
||||
auto overflow = MakeFixture(
|
||||
1U, {}, {},
|
||||
{{"10", 1, maximum, {source, 30U}}, {"10", 1, maximum, {source, 31U}}});
|
||||
ExpectFailureCode(fesa::LoadAssembler::AssembleFullNodalLoad(*overflow.model,
|
||||
*overflow.dofs),
|
||||
"nonfinite-load-accumulation");
|
||||
|
||||
auto oneNode = makeFixture(
|
||||
1U,
|
||||
{},
|
||||
{{"10", 2, 2, 2.0, {source, 21U}},
|
||||
{"10", 5, 5, -1.0, {source, 22U}}},
|
||||
{});
|
||||
auto twoNodes = makeFixture(2U, {}, {}, {});
|
||||
expectFailureCode(
|
||||
fesa::LoadAssembler::assembleFullNodalLoad(
|
||||
*twoNodes.model, *oneNode.dofs),
|
||||
"invalid-load-dimensions");
|
||||
auto one_node = MakeFixture(
|
||||
1U, {},
|
||||
{{"10", 2, 2, 2.0, {source, 21U}}, {"10", 5, 5, -1.0, {source, 22U}}},
|
||||
{});
|
||||
auto two_nodes = MakeFixture(2U, {}, {}, {});
|
||||
ExpectFailureCode(fesa::LoadAssembler::AssembleFullNodalLoad(*two_nodes.model,
|
||||
*one_node.dofs),
|
||||
"invalid-load-dimensions");
|
||||
|
||||
const auto validKfc = makeDenseSparse(4U, 2U, std::vector<double>(8U, 0.0));
|
||||
expectFailureCode(
|
||||
fesa::LoadAssembler::effectiveFreeRhs(
|
||||
fesa::Vector{5U},
|
||||
validKfc,
|
||||
oneNode.dofs->prescribedValues(),
|
||||
*oneNode.dofs),
|
||||
"invalid-load-dimensions");
|
||||
expectFailureCode(
|
||||
fesa::LoadAssembler::effectiveFreeRhs(
|
||||
fesa::Vector{6U},
|
||||
makeDenseSparse(3U, 2U, std::vector<double>(6U, 0.0)),
|
||||
oneNode.dofs->prescribedValues(),
|
||||
*oneNode.dofs),
|
||||
"invalid-load-dimensions");
|
||||
expectFailureCode(
|
||||
fesa::LoadAssembler::effectiveFreeRhs(
|
||||
fesa::Vector{6U},
|
||||
makeDenseSparse(4U, 1U, std::vector<double>(4U, 0.0)),
|
||||
oneNode.dofs->prescribedValues(),
|
||||
*oneNode.dofs),
|
||||
"invalid-load-dimensions");
|
||||
expectFailureCode(
|
||||
fesa::LoadAssembler::effectiveFreeRhs(
|
||||
fesa::Vector{6U}, validKfc, fesa::Vector{1U}, *oneNode.dofs),
|
||||
"invalid-load-dimensions");
|
||||
const auto valid_kfc = MakeDenseSparse(4U, 2U, std::vector<double>(8U, 0.0));
|
||||
ExpectFailureCode(fesa::LoadAssembler::EffectiveFreeRhs(
|
||||
fesa::Vector{5U}, valid_kfc,
|
||||
one_node.dofs->PrescribedValues(), *one_node.dofs),
|
||||
"invalid-load-dimensions");
|
||||
ExpectFailureCode(fesa::LoadAssembler::EffectiveFreeRhs(
|
||||
fesa::Vector{6U},
|
||||
MakeDenseSparse(3U, 2U, std::vector<double>(6U, 0.0)),
|
||||
one_node.dofs->PrescribedValues(), *one_node.dofs),
|
||||
"invalid-load-dimensions");
|
||||
ExpectFailureCode(fesa::LoadAssembler::EffectiveFreeRhs(
|
||||
fesa::Vector{6U},
|
||||
MakeDenseSparse(4U, 1U, std::vector<double>(4U, 0.0)),
|
||||
one_node.dofs->PrescribedValues(), *one_node.dofs),
|
||||
"invalid-load-dimensions");
|
||||
ExpectFailureCode(
|
||||
fesa::LoadAssembler::EffectiveFreeRhs(fesa::Vector{6U}, valid_kfc,
|
||||
fesa::Vector{1U}, *one_node.dofs),
|
||||
"invalid-load-dimensions");
|
||||
|
||||
fesa::Vector nonfiniteFull{6U};
|
||||
nonfiniteFull[0U] = std::numeric_limits<double>::infinity();
|
||||
expectFailureCode(
|
||||
fesa::LoadAssembler::effectiveFreeRhs(
|
||||
nonfiniteFull,
|
||||
validKfc,
|
||||
oneNode.dofs->prescribedValues(),
|
||||
*oneNode.dofs),
|
||||
"nonfinite-load-value");
|
||||
fesa::Vector nonfinite_full{6U};
|
||||
nonfinite_full[0U] = std::numeric_limits<double>::infinity();
|
||||
ExpectFailureCode(fesa::LoadAssembler::EffectiveFreeRhs(
|
||||
nonfinite_full, valid_kfc,
|
||||
one_node.dofs->PrescribedValues(), *one_node.dofs),
|
||||
"nonfinite-load-value");
|
||||
|
||||
fesa::Vector nonfinitePrescribed{2U};
|
||||
nonfinitePrescribed[0U] = std::numeric_limits<double>::quiet_NaN();
|
||||
expectFailureCode(
|
||||
fesa::LoadAssembler::effectiveFreeRhs(
|
||||
fesa::Vector{6U}, validKfc, nonfinitePrescribed, *oneNode.dofs),
|
||||
"nonfinite-load-value");
|
||||
fesa::Vector nonfinite_prescribed{2U};
|
||||
nonfinite_prescribed[0U] = std::numeric_limits<double>::quiet_NaN();
|
||||
ExpectFailureCode(
|
||||
fesa::LoadAssembler::EffectiveFreeRhs(
|
||||
fesa::Vector{6U}, valid_kfc, nonfinite_prescribed, *one_node.dofs),
|
||||
"nonfinite-load-value");
|
||||
|
||||
const auto overflowingKfc = makeDenseSparse(
|
||||
4U,
|
||||
2U,
|
||||
{maximum, 0.0,
|
||||
0.0, 0.0,
|
||||
0.0, 0.0,
|
||||
0.0, 0.0});
|
||||
expectFailureCode(
|
||||
fesa::LoadAssembler::effectiveFreeRhs(
|
||||
fesa::Vector{6U},
|
||||
overflowingKfc,
|
||||
oneNode.dofs->prescribedValues(),
|
||||
*oneNode.dofs),
|
||||
"nonfinite-load-accumulation");
|
||||
const auto overflowing_kfc =
|
||||
MakeDenseSparse(4U, 2U, {maximum, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0});
|
||||
ExpectFailureCode(fesa::LoadAssembler::EffectiveFreeRhs(
|
||||
fesa::Vector{6U}, overflowing_kfc,
|
||||
one_node.dofs->PrescribedValues(), *one_node.dofs),
|
||||
"nonfinite-load-accumulation");
|
||||
}
|
||||
|
||||
TEST(LoadAssembly, ZeroLoadsRemainZero) {
|
||||
const std::filesystem::path source{"models/load-assembly.inp"};
|
||||
auto freeFixture = makeFixture(
|
||||
1U,
|
||||
{},
|
||||
{},
|
||||
{{"10", 3, 0.0, {source, 30U}}});
|
||||
auto full = fesa::LoadAssembler::assembleFullNodalLoad(
|
||||
*freeFixture.model, *freeFixture.dofs);
|
||||
ASSERT_TRUE(full.HasValue());
|
||||
EXPECT_TRUE(std::all_of(
|
||||
full.Value().Data(),
|
||||
full.Value().Data() + full.Value().Size(),
|
||||
[](const double value) { return value == 0.0; }));
|
||||
const auto noConstrainedColumns = makeDenseSparse(6U, 0U, {});
|
||||
auto freeRhs = fesa::LoadAssembler::effectiveFreeRhs(
|
||||
full.Value(),
|
||||
noConstrainedColumns,
|
||||
freeFixture.dofs->prescribedValues(),
|
||||
*freeFixture.dofs);
|
||||
ASSERT_TRUE(freeRhs.HasValue());
|
||||
EXPECT_EQ(freeRhs.Value().Size(), 6U);
|
||||
EXPECT_TRUE(std::all_of(
|
||||
freeRhs.Value().Data(),
|
||||
freeRhs.Value().Data() + freeRhs.Value().Size(),
|
||||
[](const double value) { return value == 0.0; }));
|
||||
const std::filesystem::path source{"models/load-assembly.inp"};
|
||||
auto free_fixture = MakeFixture(1U, {}, {}, {{"10", 3, 0.0, {source, 30U}}});
|
||||
auto full = fesa::LoadAssembler::AssembleFullNodalLoad(*free_fixture.model,
|
||||
*free_fixture.dofs);
|
||||
ASSERT_TRUE(full.HasValue());
|
||||
EXPECT_TRUE(std::all_of(full.Value().Data(),
|
||||
full.Value().Data() + full.Value().Size(),
|
||||
[](const double value) { return value == 0.0; }));
|
||||
const auto no_constrained_columns = MakeDenseSparse(6U, 0U, {});
|
||||
auto free_rhs = fesa::LoadAssembler::EffectiveFreeRhs(
|
||||
full.Value(), no_constrained_columns,
|
||||
free_fixture.dofs->PrescribedValues(), *free_fixture.dofs);
|
||||
ASSERT_TRUE(free_rhs.HasValue());
|
||||
EXPECT_EQ(free_rhs.Value().Size(), 6U);
|
||||
EXPECT_TRUE(std::all_of(free_rhs.Value().Data(),
|
||||
free_rhs.Value().Data() + free_rhs.Value().Size(),
|
||||
[](const double value) { return value == 0.0; }));
|
||||
|
||||
auto constrainedFixture = makeFixture(
|
||||
1U,
|
||||
{},
|
||||
{{"10", 1, 6, 0.0, {source, 21U}}},
|
||||
{});
|
||||
auto constrainedFull = fesa::LoadAssembler::assembleFullNodalLoad(
|
||||
*constrainedFixture.model, *constrainedFixture.dofs);
|
||||
ASSERT_TRUE(constrainedFull.HasValue());
|
||||
const auto noFreeRows = makeDenseSparse(0U, 6U, {});
|
||||
auto constrainedRhs = fesa::LoadAssembler::effectiveFreeRhs(
|
||||
constrainedFull.Value(),
|
||||
noFreeRows,
|
||||
constrainedFixture.dofs->prescribedValues(),
|
||||
*constrainedFixture.dofs);
|
||||
ASSERT_TRUE(constrainedRhs.HasValue());
|
||||
EXPECT_EQ(constrainedRhs.Value().Size(), 0U);
|
||||
auto constrained_fixture =
|
||||
MakeFixture(1U, {}, {{"10", 1, 6, 0.0, {source, 21U}}}, {});
|
||||
auto constrained_full = fesa::LoadAssembler::AssembleFullNodalLoad(
|
||||
*constrained_fixture.model, *constrained_fixture.dofs);
|
||||
ASSERT_TRUE(constrained_full.HasValue());
|
||||
const auto no_free_rows = MakeDenseSparse(0U, 6U, {});
|
||||
auto constrained_rhs = fesa::LoadAssembler::EffectiveFreeRhs(
|
||||
constrained_full.Value(), no_free_rows,
|
||||
constrained_fixture.dofs->PrescribedValues(), *constrained_fixture.dofs);
|
||||
ASSERT_TRUE(constrained_rhs.HasValue());
|
||||
EXPECT_EQ(constrained_rhs.Value().Size(), 0U);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "fesa/assembly/parallel_for.hpp"
|
||||
#include "fesa/assembly/parallel_for.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
@@ -14,101 +14,101 @@ namespace fesa {
|
||||
namespace {
|
||||
|
||||
class ParallelForBodyError final : public std::runtime_error {
|
||||
public:
|
||||
using std::runtime_error::runtime_error;
|
||||
public:
|
||||
using std::runtime_error::runtime_error;
|
||||
};
|
||||
|
||||
std::array<std::reference_wrapper<const ParallelFor>, 2> parallelForBackends(
|
||||
const SerialParallelFor& serial,
|
||||
const TbbParallelFor& tbb) {
|
||||
return {std::cref(serial), std::cref(tbb)};
|
||||
std::array<std::reference_wrapper<const ParallelFor>, 2> ParallelForBackends(
|
||||
const SerialParallelFor& serial, const TbbParallelFor& tbb) {
|
||||
return {std::cref(serial), std::cref(tbb)};
|
||||
}
|
||||
|
||||
TEST(ParallelFor, ZeroOneManyExecuteExactlyOnce) {
|
||||
const SerialParallelFor serial;
|
||||
const TbbParallelFor tbb;
|
||||
const SerialParallelFor serial;
|
||||
const TbbParallelFor tbb;
|
||||
|
||||
for (const ParallelFor& parallelFor : parallelForBackends(serial, tbb)) {
|
||||
std::atomic<std::size_t> zeroVisits{0U};
|
||||
parallelFor.execute(0U, [&zeroVisits](std::size_t) {
|
||||
zeroVisits.fetch_add(1U, std::memory_order_relaxed);
|
||||
});
|
||||
EXPECT_EQ(zeroVisits.load(std::memory_order_relaxed), 0U);
|
||||
for (const ParallelFor& parallel_for : ParallelForBackends(serial, tbb)) {
|
||||
std::atomic<std::size_t> zero_visits{0U};
|
||||
parallel_for.Execute(0U, [&zero_visits](std::size_t) {
|
||||
zero_visits.fetch_add(1U, std::memory_order_relaxed);
|
||||
});
|
||||
EXPECT_EQ(zero_visits.load(std::memory_order_relaxed), 0U);
|
||||
|
||||
for (const std::size_t count : {1U, 257U}) {
|
||||
std::vector<std::atomic<std::size_t>> visits(count);
|
||||
for (auto& visit : visits) {
|
||||
visit.store(0U, std::memory_order_relaxed);
|
||||
}
|
||||
parallelFor.execute(count, [&visits](std::size_t index) {
|
||||
visits[index].fetch_add(1U, std::memory_order_relaxed);
|
||||
});
|
||||
for (std::size_t index = 0; index < count; ++index) {
|
||||
EXPECT_EQ(visits[index].load(std::memory_order_relaxed), 1U);
|
||||
}
|
||||
}
|
||||
for (const std::size_t count : {1U, 257U}) {
|
||||
std::vector<std::atomic<std::size_t>> visits(count);
|
||||
for (auto& visit : visits) {
|
||||
visit.store(0U, std::memory_order_relaxed);
|
||||
}
|
||||
parallel_for.Execute(count, [&visits](std::size_t index) {
|
||||
visits[index].fetch_add(1U, std::memory_order_relaxed);
|
||||
});
|
||||
for (std::size_t index = 0; index < count; ++index) {
|
||||
EXPECT_EQ(visits[index].load(std::memory_order_relaxed), 1U);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST(ParallelFor, SerialAndTbbProduceStableIndexedOutput) {
|
||||
constexpr std::size_t count = 1024U;
|
||||
std::vector<std::atomic<std::size_t>> serialOutput(count);
|
||||
std::vector<std::atomic<std::size_t>> tbbOutput(count);
|
||||
std::vector<std::atomic<std::size_t>> serialVisits(count);
|
||||
std::vector<std::atomic<std::size_t>> tbbVisits(count);
|
||||
for (std::size_t index = 0; index < count; ++index) {
|
||||
serialOutput[index].store(0U, std::memory_order_relaxed);
|
||||
tbbOutput[index].store(0U, std::memory_order_relaxed);
|
||||
serialVisits[index].store(0U, std::memory_order_relaxed);
|
||||
tbbVisits[index].store(0U, std::memory_order_relaxed);
|
||||
}
|
||||
const auto valueForIndex = [](std::size_t index) {
|
||||
return (index + 17U) * (index + 3U);
|
||||
};
|
||||
constexpr std::size_t count = 1024U;
|
||||
std::vector<std::atomic<std::size_t>> serial_output(count);
|
||||
std::vector<std::atomic<std::size_t>> tbb_output(count);
|
||||
std::vector<std::atomic<std::size_t>> serial_visits(count);
|
||||
std::vector<std::atomic<std::size_t>> tbb_visits(count);
|
||||
for (std::size_t index = 0; index < count; ++index) {
|
||||
serial_output[index].store(0U, std::memory_order_relaxed);
|
||||
tbb_output[index].store(0U, std::memory_order_relaxed);
|
||||
serial_visits[index].store(0U, std::memory_order_relaxed);
|
||||
tbb_visits[index].store(0U, std::memory_order_relaxed);
|
||||
}
|
||||
const auto value_for_index = [](std::size_t index) {
|
||||
return (index + 17U) * (index + 3U);
|
||||
};
|
||||
|
||||
const SerialParallelFor serial;
|
||||
serial.execute(count, [&serialOutput, &serialVisits, &valueForIndex](std::size_t index) {
|
||||
serialOutput[index].store(valueForIndex(index), std::memory_order_relaxed);
|
||||
serialVisits[index].fetch_add(1U, std::memory_order_relaxed);
|
||||
});
|
||||
const SerialParallelFor serial;
|
||||
serial.Execute(count, [&serial_output, &serial_visits,
|
||||
&value_for_index](std::size_t index) {
|
||||
serial_output[index].store(value_for_index(index),
|
||||
std::memory_order_relaxed);
|
||||
serial_visits[index].fetch_add(1U, std::memory_order_relaxed);
|
||||
});
|
||||
|
||||
const TbbParallelFor tbb;
|
||||
tbb.execute(count, [&tbbOutput, &tbbVisits, &valueForIndex](std::size_t index) {
|
||||
tbbOutput[index].store(valueForIndex(index), std::memory_order_relaxed);
|
||||
tbbVisits[index].fetch_add(1U, std::memory_order_relaxed);
|
||||
});
|
||||
const TbbParallelFor tbb;
|
||||
tbb.Execute(count, [&tbb_output, &tbb_visits,
|
||||
&value_for_index](std::size_t index) {
|
||||
tbb_output[index].store(value_for_index(index), std::memory_order_relaxed);
|
||||
tbb_visits[index].fetch_add(1U, std::memory_order_relaxed);
|
||||
});
|
||||
|
||||
for (std::size_t index = 0; index < count; ++index) {
|
||||
EXPECT_EQ(serialVisits[index].load(std::memory_order_relaxed), 1U);
|
||||
EXPECT_EQ(tbbVisits[index].load(std::memory_order_relaxed), 1U);
|
||||
EXPECT_EQ(
|
||||
tbbOutput[index].load(std::memory_order_relaxed),
|
||||
serialOutput[index].load(std::memory_order_relaxed));
|
||||
EXPECT_EQ(
|
||||
tbbOutput[index].load(std::memory_order_relaxed),
|
||||
valueForIndex(index));
|
||||
}
|
||||
for (std::size_t index = 0; index < count; ++index) {
|
||||
EXPECT_EQ(serial_visits[index].load(std::memory_order_relaxed), 1U);
|
||||
EXPECT_EQ(tbb_visits[index].load(std::memory_order_relaxed), 1U);
|
||||
EXPECT_EQ(tbb_output[index].load(std::memory_order_relaxed),
|
||||
serial_output[index].load(std::memory_order_relaxed));
|
||||
EXPECT_EQ(tbb_output[index].load(std::memory_order_relaxed),
|
||||
value_for_index(index));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(ParallelFor, PropagatesBodyExceptionByContract) {
|
||||
const SerialParallelFor serial;
|
||||
const TbbParallelFor tbb;
|
||||
const SerialParallelFor serial;
|
||||
const TbbParallelFor tbb;
|
||||
|
||||
for (const ParallelFor& parallelFor : parallelForBackends(serial, tbb)) {
|
||||
try {
|
||||
// Every iteration throws the same value so the assertion is independent
|
||||
// of which oneTBB task reports the cancellation-triggering exception.
|
||||
parallelFor.execute(64U, [](std::size_t) {
|
||||
throw ParallelForBodyError{"parallel-for-body-failure"};
|
||||
});
|
||||
ADD_FAILURE() << "ParallelFor swallowed the body exception.";
|
||||
} catch (const ParallelForBodyError& error) {
|
||||
EXPECT_EQ(std::string{error.what()}, "parallel-for-body-failure");
|
||||
} catch (...) {
|
||||
ADD_FAILURE() << "ParallelFor changed the body exception type.";
|
||||
}
|
||||
for (const ParallelFor& parallel_for : ParallelForBackends(serial, tbb)) {
|
||||
try {
|
||||
// Every iteration throws the same value so the assertion is independent
|
||||
// of which oneTBB task reports the cancellation-triggering exception.
|
||||
parallel_for.Execute(64U, [](std::size_t) {
|
||||
throw ParallelForBodyError{"parallel-for-body-failure"};
|
||||
});
|
||||
ADD_FAILURE() << "ParallelFor swallowed the body exception.";
|
||||
} catch (const ParallelForBodyError& error) {
|
||||
EXPECT_EQ(std::string{error.what()}, "parallel-for-body-failure");
|
||||
} catch (...) {
|
||||
ADD_FAILURE() << "ParallelFor changed the body exception type.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace fesa
|
||||
} // namespace
|
||||
} // namespace fesa
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
#include "fesa/analysis/analysis_model.hpp"
|
||||
#include "fesa/assembly/parallel_for.hpp"
|
||||
#include "fesa/assembly/sparse_assembler.hpp"
|
||||
#include "fesa/elements/mitc4_shell.h"
|
||||
#include "fesa/fem/dof_manager.hpp"
|
||||
#include "fesa/model/domain.h"
|
||||
#include "fesa/assembly/sparse_assembler.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
@@ -14,326 +9,311 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "fesa/analysis/analysis_model.h"
|
||||
#include "fesa/assembly/parallel_for.h"
|
||||
#include "fesa/elements/mitc4_shell.h"
|
||||
#include "fesa/fem/dof_manager.h"
|
||||
#include "fesa/model/domain.h"
|
||||
|
||||
namespace {
|
||||
|
||||
fesa::ModelDefinition makeDefinition() {
|
||||
const std::filesystem::path source{"models/sparse-assembly.inp"};
|
||||
fesa::ModelDefinition definition{};
|
||||
definition.source_path = source;
|
||||
definition.source_content_identity = "fnv1a64:0123456789abcdef";
|
||||
definition.nodes = {
|
||||
{{"Beam-1", 1, "1"}, {0.0, 0.0, 0.0}, {source, 10U}},
|
||||
{{"Beam-1", 2, "2"}, {2.0, 0.0, 0.0}, {source, 11U}},
|
||||
{{"Beam-1", 3, "3"}, {5.0, 0.0, 0.0}, {source, 12U}}};
|
||||
definition.materials = {
|
||||
{"Material", 120.0, 0.25, {source, 20U}}};
|
||||
definition.sections = {{
|
||||
"Section",
|
||||
2.0,
|
||||
1.5,
|
||||
0.0,
|
||||
0.75,
|
||||
0.5,
|
||||
{0.0, 1.0, 0.0},
|
||||
{},
|
||||
{source, 30U}}};
|
||||
definition.elements = {
|
||||
{{"Beam-1", 10, "10"}, {0U, 1U}, 0U, 0U, {source, 40U}},
|
||||
{{"Beam-1", 20, "20"}, {1U, 2U}, 0U, 0U, {source, 41U}}};
|
||||
definition.steps = {{
|
||||
"Step-1", {}, {}, 0.1, 1.0, 0.01, 1.0, {source, 50U}}};
|
||||
return definition;
|
||||
fesa::ModelDefinition MakeDefinition() {
|
||||
const std::filesystem::path source{"models/sparse-assembly.inp"};
|
||||
fesa::ModelDefinition definition{};
|
||||
definition.source_path = source;
|
||||
definition.source_content_identity = "fnv1a64:0123456789abcdef";
|
||||
definition.nodes = {{{"Beam-1", 1, "1"}, {0.0, 0.0, 0.0}, {source, 10U}},
|
||||
{{"Beam-1", 2, "2"}, {2.0, 0.0, 0.0}, {source, 11U}},
|
||||
{{"Beam-1", 3, "3"}, {5.0, 0.0, 0.0}, {source, 12U}}};
|
||||
definition.materials = {{"Material", 120.0, 0.25, {source, 20U}}};
|
||||
definition.sections = {{"Section",
|
||||
2.0,
|
||||
1.5,
|
||||
0.0,
|
||||
0.75,
|
||||
0.5,
|
||||
{0.0, 1.0, 0.0},
|
||||
{},
|
||||
{source, 30U}}};
|
||||
definition.elements = {
|
||||
{{"Beam-1", 10, "10"}, {0U, 1U}, 0U, 0U, {source, 40U}},
|
||||
{{"Beam-1", 20, "20"}, {1U, 2U}, 0U, 0U, {source, 41U}}};
|
||||
definition.steps = {{"Step-1", {}, {}, 0.1, 1.0, 0.01, 1.0, {source, 50U}}};
|
||||
return definition;
|
||||
}
|
||||
|
||||
fesa::ModelDefinition makeShellDefinition(
|
||||
const fesa::ShellSourceElementType sourceType,
|
||||
const bool twoElements = false) {
|
||||
const std::filesystem::path source{"models/shell-sparse-assembly.inp"};
|
||||
fesa::ModelDefinition definition{};
|
||||
definition.source_path = source;
|
||||
definition.source_content_identity = "fnv1a64:fedcba9876543210";
|
||||
if (twoElements) {
|
||||
definition.nodes = {
|
||||
{{"Shell-1", 1, "1"}, {0.0, 0.0, 0.0}, {source, 10U}},
|
||||
{{"Shell-1", 2, "2"}, {1.0, 0.0, 0.0}, {source, 11U}},
|
||||
{{"Shell-1", 3, "3"}, {2.0, 0.0, 0.0}, {source, 12U}},
|
||||
{{"Shell-1", 4, "4"}, {0.0, 1.0, 0.0}, {source, 13U}},
|
||||
{{"Shell-1", 5, "5"}, {1.0, 1.0, 0.0}, {source, 14U}},
|
||||
{{"Shell-1", 6, "6"}, {2.0, 1.0, 0.0}, {source, 15U}}};
|
||||
for (std::size_t node = 0U; node < definition.nodes.size(); ++node) {
|
||||
definition.shell_node_initial_frames.push_back({
|
||||
static_cast<fesa::EntityIndex>(node),
|
||||
{0.0, 0.0, 1.0},
|
||||
{1.0, 0.0, 0.0},
|
||||
{0.0, 1.0, 0.0}});
|
||||
}
|
||||
definition.shell_elements = {
|
||||
{{"Shell-1", 10, "10"}, sourceType, {0U, 1U, 4U, 3U},
|
||||
0U, 0U, {source, 40U}},
|
||||
{{"Shell-1", 20, "20"}, sourceType, {1U, 2U, 5U, 4U},
|
||||
0U, 0U, {source, 41U}}};
|
||||
} else {
|
||||
// A YZ-plane fixture catches any accidental global-Z director assumption.
|
||||
definition.nodes = {
|
||||
{{"Shell-1", 1, "1"}, {0.0, 0.0, 0.0}, {source, 10U}},
|
||||
{{"Shell-1", 2, "2"}, {0.0, 1.0, 0.0}, {source, 11U}},
|
||||
{{"Shell-1", 3, "3"}, {0.0, 1.0, 1.0}, {source, 12U}},
|
||||
{{"Shell-1", 4, "4"}, {0.0, 0.0, 1.0}, {source, 13U}}};
|
||||
for (std::size_t node = 0U; node < definition.nodes.size(); ++node) {
|
||||
definition.shell_node_initial_frames.push_back({
|
||||
static_cast<fesa::EntityIndex>(node),
|
||||
{1.0, 0.0, 0.0},
|
||||
{0.0, 1.0, 0.0},
|
||||
{0.0, 0.0, 1.0}});
|
||||
}
|
||||
definition.shell_elements = {{
|
||||
{"Shell-1", 10, "10"}, sourceType, {0U, 1U, 2U, 3U},
|
||||
0U, 0U, {source, 40U}}};
|
||||
fesa::ModelDefinition MakeShellDefinition(
|
||||
const fesa::ShellSourceElementType source_type,
|
||||
const bool two_elements = false) {
|
||||
const std::filesystem::path source{"models/shell-sparse-assembly.inp"};
|
||||
fesa::ModelDefinition definition{};
|
||||
definition.source_path = source;
|
||||
definition.source_content_identity = "fnv1a64:fedcba9876543210";
|
||||
if (two_elements) {
|
||||
definition.nodes = {{{"Shell-1", 1, "1"}, {0.0, 0.0, 0.0}, {source, 10U}},
|
||||
{{"Shell-1", 2, "2"}, {1.0, 0.0, 0.0}, {source, 11U}},
|
||||
{{"Shell-1", 3, "3"}, {2.0, 0.0, 0.0}, {source, 12U}},
|
||||
{{"Shell-1", 4, "4"}, {0.0, 1.0, 0.0}, {source, 13U}},
|
||||
{{"Shell-1", 5, "5"}, {1.0, 1.0, 0.0}, {source, 14U}},
|
||||
{{"Shell-1", 6, "6"}, {2.0, 1.0, 0.0}, {source, 15U}}};
|
||||
for (std::size_t node = 0U; node < definition.nodes.size(); ++node) {
|
||||
definition.shell_node_initial_frames.push_back(
|
||||
{static_cast<fesa::EntityIndex>(node),
|
||||
{0.0, 0.0, 1.0},
|
||||
{1.0, 0.0, 0.0},
|
||||
{0.0, 1.0, 0.0}});
|
||||
}
|
||||
definition.materials = {
|
||||
{"Material", 120.0, 0.25, {source, 20U}}};
|
||||
definition.shell_sections = {
|
||||
{"ShellSection", 0.2, 0U, {source, 30U}}};
|
||||
definition.steps = {{
|
||||
"Step-1", {}, {}, 0.1, 1.0, 0.01, 1.0, {source, 50U}}};
|
||||
return definition;
|
||||
definition.shell_elements = {{{"Shell-1", 10, "10"},
|
||||
source_type,
|
||||
{0U, 1U, 4U, 3U},
|
||||
0U,
|
||||
0U,
|
||||
{source, 40U}},
|
||||
{{"Shell-1", 20, "20"},
|
||||
source_type,
|
||||
{1U, 2U, 5U, 4U},
|
||||
0U,
|
||||
0U,
|
||||
{source, 41U}}};
|
||||
} else {
|
||||
// A YZ-plane fixture catches any accidental global-Z director assumption.
|
||||
definition.nodes = {{{"Shell-1", 1, "1"}, {0.0, 0.0, 0.0}, {source, 10U}},
|
||||
{{"Shell-1", 2, "2"}, {0.0, 1.0, 0.0}, {source, 11U}},
|
||||
{{"Shell-1", 3, "3"}, {0.0, 1.0, 1.0}, {source, 12U}},
|
||||
{{"Shell-1", 4, "4"}, {0.0, 0.0, 1.0}, {source, 13U}}};
|
||||
for (std::size_t node = 0U; node < definition.nodes.size(); ++node) {
|
||||
definition.shell_node_initial_frames.push_back(
|
||||
{static_cast<fesa::EntityIndex>(node),
|
||||
{1.0, 0.0, 0.0},
|
||||
{0.0, 1.0, 0.0},
|
||||
{0.0, 0.0, 1.0}});
|
||||
}
|
||||
definition.shell_elements = {{{"Shell-1", 10, "10"},
|
||||
source_type,
|
||||
{0U, 1U, 2U, 3U},
|
||||
0U,
|
||||
0U,
|
||||
{source, 40U}}};
|
||||
}
|
||||
definition.materials = {{"Material", 120.0, 0.25, {source, 20U}}};
|
||||
definition.shell_sections = {{"ShellSection", 0.2, 0U, {source, 30U}}};
|
||||
definition.steps = {{"Step-1", {}, {}, 0.1, 1.0, 0.01, 1.0, {source, 50U}}};
|
||||
return definition;
|
||||
}
|
||||
|
||||
fesa::Result<fesa::Mitc4Stiffness> directShellStiffness(
|
||||
const fesa::Domain& domain,
|
||||
const fesa::EntityIndex elementIndex) {
|
||||
const auto& definition = domain.ShellElements().at(elementIndex);
|
||||
std::array<const fesa::Node*, 4> nodes{};
|
||||
std::array<std::array<double, 3>, 4> directors{};
|
||||
for (std::size_t node = 0U; node < definition.node_indices.size(); ++node) {
|
||||
const fesa::EntityIndex nodeIndex = definition.node_indices[node];
|
||||
nodes[node] = &domain.Nodes().at(nodeIndex);
|
||||
directors[node] = domain.ShellNodeInitialFrames().at(nodeIndex).director;
|
||||
}
|
||||
auto shell = fesa::Mitc4Shell::Create(
|
||||
nodes,
|
||||
directors,
|
||||
domain.ShellSections().at(definition.section_index),
|
||||
domain.Materials().at(definition.material_index));
|
||||
if (!shell.HasValue()) {
|
||||
return fesa::Result<fesa::Mitc4Stiffness>::Failure(shell.GetStatus());
|
||||
}
|
||||
return shell.Value().Stiffness();
|
||||
fesa::Result<fesa::Mitc4Stiffness> DirectShellStiffness(
|
||||
const fesa::Domain& domain, const fesa::EntityIndex element_index) {
|
||||
const auto& definition = domain.ShellElements().at(element_index);
|
||||
std::array<const fesa::Node*, 4> nodes{};
|
||||
std::array<std::array<double, 3>, 4> directors{};
|
||||
for (std::size_t node = 0U; node < definition.node_indices.size(); ++node) {
|
||||
const fesa::EntityIndex node_index = definition.node_indices[node];
|
||||
nodes[node] = &domain.Nodes().at(node_index);
|
||||
directors[node] = domain.ShellNodeInitialFrames().at(node_index).director;
|
||||
}
|
||||
auto shell = fesa::Mitc4Shell::Create(
|
||||
nodes, directors, domain.ShellSections().at(definition.section_index),
|
||||
domain.Materials().at(definition.material_index));
|
||||
if (!shell.HasValue()) {
|
||||
return fesa::Result<fesa::Mitc4Stiffness>::Failure(shell.GetStatus());
|
||||
}
|
||||
return shell.Value().Stiffness();
|
||||
}
|
||||
|
||||
fesa::Result<fesa::SparseMatrix> assembleShell(
|
||||
const fesa::ShellSourceElementType sourceType,
|
||||
const fesa::ParallelFor& parallelFor,
|
||||
const bool twoElements = false) {
|
||||
auto domain = fesa::Domain::Create(
|
||||
makeShellDefinition(sourceType, twoElements));
|
||||
if (!domain.HasValue()) {
|
||||
return fesa::Result<fesa::SparseMatrix>::Failure(domain.GetStatus());
|
||||
}
|
||||
auto model = fesa::AnalysisModel::create(domain.Value());
|
||||
if (!model.HasValue()) {
|
||||
return fesa::Result<fesa::SparseMatrix>::Failure(model.GetStatus());
|
||||
}
|
||||
auto dofs = fesa::DofManager::create(model.Value());
|
||||
if (!dofs.HasValue()) {
|
||||
return fesa::Result<fesa::SparseMatrix>::Failure(dofs.GetStatus());
|
||||
}
|
||||
return fesa::SparseAssembler::assembleStiffness(
|
||||
model.Value(), dofs.Value(), parallelFor);
|
||||
fesa::Result<fesa::SparseMatrix> AssembleShell(
|
||||
const fesa::ShellSourceElementType source_type,
|
||||
const fesa::ParallelFor& parallel_for, const bool two_elements = false) {
|
||||
auto domain =
|
||||
fesa::Domain::Create(MakeShellDefinition(source_type, two_elements));
|
||||
if (!domain.HasValue()) {
|
||||
return fesa::Result<fesa::SparseMatrix>::Failure(domain.GetStatus());
|
||||
}
|
||||
auto model = fesa::AnalysisModel::Create(domain.Value());
|
||||
if (!model.HasValue()) {
|
||||
return fesa::Result<fesa::SparseMatrix>::Failure(model.GetStatus());
|
||||
}
|
||||
auto dofs = fesa::DofManager::Create(model.Value());
|
||||
if (!dofs.HasValue()) {
|
||||
return fesa::Result<fesa::SparseMatrix>::Failure(dofs.GetStatus());
|
||||
}
|
||||
return fesa::SparseAssembler::AssembleStiffness(model.Value(), dofs.Value(),
|
||||
parallel_for);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
bool byteIdentical(const std::vector<T>& left, const std::vector<T>& right) {
|
||||
return left.size() == right.size() &&
|
||||
(left.empty() ||
|
||||
std::memcmp(
|
||||
left.data(), right.data(), left.size() * sizeof(T)) == 0);
|
||||
template <class T>
|
||||
bool ByteIdentical(const std::vector<T>& left, const std::vector<T>& right) {
|
||||
return left.size() == right.size() &&
|
||||
(left.empty() ||
|
||||
std::memcmp(left.data(), right.data(), left.size() * sizeof(T)) == 0);
|
||||
}
|
||||
|
||||
double entry(
|
||||
const fesa::SparseMatrix& matrix,
|
||||
const std::size_t row,
|
||||
const std::size_t column) {
|
||||
const auto begin = matrix.ColumnIndices().begin() + matrix.RowOffsets()[row];
|
||||
const auto end = matrix.ColumnIndices().begin() + matrix.RowOffsets()[row + 1U];
|
||||
const auto found = std::lower_bound(begin, end, column);
|
||||
if (found == end || *found != column) {
|
||||
return 0.0;
|
||||
}
|
||||
return matrix.Values()[static_cast<std::size_t>(
|
||||
std::distance(matrix.ColumnIndices().begin(), found))];
|
||||
double Entry(const fesa::SparseMatrix& matrix, const std::size_t row,
|
||||
const std::size_t column) {
|
||||
const auto begin = matrix.ColumnIndices().begin() + matrix.RowOffsets()[row];
|
||||
const auto end =
|
||||
matrix.ColumnIndices().begin() + matrix.RowOffsets()[row + 1U];
|
||||
const auto found = std::lower_bound(begin, end, column);
|
||||
if (found == end || *found != column) {
|
||||
return 0.0;
|
||||
}
|
||||
return matrix.Values()[static_cast<std::size_t>(
|
||||
std::distance(matrix.ColumnIndices().begin(), found))];
|
||||
}
|
||||
|
||||
class ReverseParallelFor final : public fesa::ParallelFor {
|
||||
public:
|
||||
void execute(
|
||||
const std::size_t count,
|
||||
const std::function<void(std::size_t)>& body) const override {
|
||||
++calls_;
|
||||
observedCount_ = count;
|
||||
for (std::size_t index = count; index > 0U; --index) {
|
||||
body(index - 1U);
|
||||
}
|
||||
public:
|
||||
void Execute(const std::size_t count,
|
||||
const std::function<void(std::size_t)>& body) const override {
|
||||
++calls_;
|
||||
observed_count_ = count;
|
||||
for (std::size_t index = count; index > 0U; --index) {
|
||||
body(index - 1U);
|
||||
}
|
||||
}
|
||||
|
||||
std::size_t calls() const noexcept {
|
||||
return calls_;
|
||||
}
|
||||
std::size_t Calls() const noexcept { return calls_; }
|
||||
|
||||
std::size_t observedCount() const noexcept {
|
||||
return observedCount_;
|
||||
}
|
||||
std::size_t ObservedCount() const noexcept { return observed_count_; }
|
||||
|
||||
private:
|
||||
mutable std::size_t calls_{0U};
|
||||
mutable std::size_t observedCount_{0U};
|
||||
private:
|
||||
mutable std::size_t calls_{0U};
|
||||
mutable std::size_t observed_count_{0U};
|
||||
};
|
||||
|
||||
void expectByteIdentical(
|
||||
const fesa::SparseMatrix& actual,
|
||||
const fesa::SparseMatrix& expected) {
|
||||
EXPECT_TRUE(byteIdentical(actual.RowOffsets(), expected.RowOffsets()));
|
||||
EXPECT_TRUE(byteIdentical(actual.ColumnIndices(), expected.ColumnIndices()));
|
||||
EXPECT_TRUE(byteIdentical(actual.Values(), expected.Values()));
|
||||
void ExpectByteIdentical(const fesa::SparseMatrix& actual,
|
||||
const fesa::SparseMatrix& expected) {
|
||||
EXPECT_TRUE(ByteIdentical(actual.RowOffsets(), expected.RowOffsets()));
|
||||
EXPECT_TRUE(ByteIdentical(actual.ColumnIndices(), expected.ColumnIndices()));
|
||||
EXPECT_TRUE(ByteIdentical(actual.Values(), expected.Values()));
|
||||
}
|
||||
|
||||
TEST(SparseAssembly, SerialTbbAndRepeatedRunsAreByteIdentical) {
|
||||
auto domainResult = fesa::Domain::Create(makeDefinition());
|
||||
ASSERT_TRUE(domainResult.HasValue());
|
||||
auto modelResult = fesa::AnalysisModel::create(domainResult.Value());
|
||||
ASSERT_TRUE(modelResult.HasValue());
|
||||
auto dofsResult = fesa::DofManager::create(modelResult.Value());
|
||||
ASSERT_TRUE(dofsResult.HasValue());
|
||||
auto domain_result = fesa::Domain::Create(MakeDefinition());
|
||||
ASSERT_TRUE(domain_result.HasValue());
|
||||
auto model_result = fesa::AnalysisModel::Create(domain_result.Value());
|
||||
ASSERT_TRUE(model_result.HasValue());
|
||||
auto dofs_result = fesa::DofManager::Create(model_result.Value());
|
||||
ASSERT_TRUE(dofs_result.HasValue());
|
||||
|
||||
fesa::SerialParallelFor serialExecutor;
|
||||
fesa::TbbParallelFor tbbExecutor;
|
||||
ReverseParallelFor reverseExecutor;
|
||||
auto serial = fesa::SparseAssembler::assembleStiffness(
|
||||
modelResult.Value(), dofsResult.Value(), serialExecutor);
|
||||
auto tbb = fesa::SparseAssembler::assembleStiffness(
|
||||
modelResult.Value(), dofsResult.Value(), tbbExecutor);
|
||||
auto reversed = fesa::SparseAssembler::assembleStiffness(
|
||||
modelResult.Value(), dofsResult.Value(), reverseExecutor);
|
||||
ASSERT_TRUE(serial.HasValue());
|
||||
ASSERT_TRUE(tbb.HasValue());
|
||||
ASSERT_TRUE(reversed.HasValue());
|
||||
fesa::SerialParallelFor serial_executor;
|
||||
fesa::TbbParallelFor tbb_executor;
|
||||
ReverseParallelFor reverse_executor;
|
||||
auto serial = fesa::SparseAssembler::AssembleStiffness(
|
||||
model_result.Value(), dofs_result.Value(), serial_executor);
|
||||
auto tbb = fesa::SparseAssembler::AssembleStiffness(
|
||||
model_result.Value(), dofs_result.Value(), tbb_executor);
|
||||
auto reversed = fesa::SparseAssembler::AssembleStiffness(
|
||||
model_result.Value(), dofs_result.Value(), reverse_executor);
|
||||
ASSERT_TRUE(serial.HasValue());
|
||||
ASSERT_TRUE(tbb.HasValue());
|
||||
ASSERT_TRUE(reversed.HasValue());
|
||||
|
||||
EXPECT_EQ(reverseExecutor.calls(), 1U);
|
||||
EXPECT_EQ(reverseExecutor.observedCount(), 2U);
|
||||
EXPECT_EQ(serial.Value().Rows(), 18U);
|
||||
EXPECT_EQ(serial.Value().Columns(), 18U);
|
||||
EXPECT_EQ(serial.Value().RowOffsets(), dofsResult.Value().sparsePattern().rowOffsets);
|
||||
EXPECT_EQ(
|
||||
serial.Value().ColumnIndices(),
|
||||
dofsResult.Value().sparsePattern().columnIndices);
|
||||
EXPECT_TRUE(serial.Value().Validate().IsOk());
|
||||
expectByteIdentical(tbb.Value(), serial.Value());
|
||||
expectByteIdentical(reversed.Value(), serial.Value());
|
||||
EXPECT_EQ(reverse_executor.Calls(), 1U);
|
||||
EXPECT_EQ(reverse_executor.ObservedCount(), 2U);
|
||||
EXPECT_EQ(serial.Value().Rows(), 18U);
|
||||
EXPECT_EQ(serial.Value().Columns(), 18U);
|
||||
EXPECT_EQ(serial.Value().RowOffsets(),
|
||||
dofs_result.Value().GetSparsePattern().row_offsets);
|
||||
EXPECT_EQ(serial.Value().ColumnIndices(),
|
||||
dofs_result.Value().GetSparsePattern().column_indices);
|
||||
EXPECT_TRUE(serial.Value().Validate().IsOk());
|
||||
ExpectByteIdentical(tbb.Value(), serial.Value());
|
||||
ExpectByteIdentical(reversed.Value(), serial.Value());
|
||||
|
||||
for (std::size_t repetition = 0U; repetition < 8U; ++repetition) {
|
||||
auto repeated = fesa::SparseAssembler::assembleStiffness(
|
||||
modelResult.Value(), dofsResult.Value(), tbbExecutor);
|
||||
ASSERT_TRUE(repeated.HasValue());
|
||||
expectByteIdentical(repeated.Value(), serial.Value());
|
||||
for (std::size_t repetition = 0U; repetition < 8U; ++repetition) {
|
||||
auto repeated = fesa::SparseAssembler::AssembleStiffness(
|
||||
model_result.Value(), dofs_result.Value(), tbb_executor);
|
||||
ASSERT_TRUE(repeated.HasValue());
|
||||
ExpectByteIdentical(repeated.Value(), serial.Value());
|
||||
}
|
||||
|
||||
for (std::size_t row = 0U; row < serial.Value().Rows(); ++row) {
|
||||
for (std::size_t column = 0U; column < serial.Value().Columns(); ++column) {
|
||||
EXPECT_DOUBLE_EQ(Entry(serial.Value(), row, column),
|
||||
Entry(serial.Value(), column, row));
|
||||
}
|
||||
}
|
||||
|
||||
for (std::size_t row = 0U; row < serial.Value().Rows(); ++row) {
|
||||
for (std::size_t column = 0U;
|
||||
column < serial.Value().Columns();
|
||||
++column) {
|
||||
EXPECT_DOUBLE_EQ(
|
||||
entry(serial.Value(), row, column),
|
||||
entry(serial.Value(), column, row));
|
||||
}
|
||||
}
|
||||
|
||||
EXPECT_NEAR(entry(serial.Value(), 0U, 0U), 120.0, 1.0e-12);
|
||||
EXPECT_NEAR(entry(serial.Value(), 0U, 6U), -120.0, 1.0e-12);
|
||||
EXPECT_NEAR(entry(serial.Value(), 6U, 6U), 200.0, 1.0e-12);
|
||||
EXPECT_NEAR(entry(serial.Value(), 6U, 12U), -80.0, 1.0e-12);
|
||||
EXPECT_NEAR(entry(serial.Value(), 12U, 12U), 80.0, 1.0e-12);
|
||||
EXPECT_NEAR(Entry(serial.Value(), 0U, 0U), 120.0, 1.0e-12);
|
||||
EXPECT_NEAR(Entry(serial.Value(), 0U, 6U), -120.0, 1.0e-12);
|
||||
EXPECT_NEAR(Entry(serial.Value(), 6U, 6U), 200.0, 1.0e-12);
|
||||
EXPECT_NEAR(Entry(serial.Value(), 6U, 12U), -80.0, 1.0e-12);
|
||||
EXPECT_NEAR(Entry(serial.Value(), 12U, 12U), 80.0, 1.0e-12);
|
||||
}
|
||||
|
||||
TEST(
|
||||
SparseAssembly,
|
||||
AssemblesFourNodeTwentyFourDofKernelAndPreservesDiagonalSlots) {
|
||||
auto domain = fesa::Domain::Create(
|
||||
makeShellDefinition(fesa::ShellSourceElementType::kS4));
|
||||
ASSERT_TRUE(domain.HasValue());
|
||||
auto model = fesa::AnalysisModel::create(domain.Value());
|
||||
ASSERT_TRUE(model.HasValue());
|
||||
auto dofs = fesa::DofManager::create(model.Value());
|
||||
ASSERT_TRUE(dofs.HasValue());
|
||||
fesa::SerialParallelFor serialExecutor;
|
||||
TEST(SparseAssembly,
|
||||
AssemblesFourNodeTwentyFourDofKernelAndPreservesDiagonalSlots) {
|
||||
auto domain = fesa::Domain::Create(
|
||||
MakeShellDefinition(fesa::ShellSourceElementType::kS4));
|
||||
ASSERT_TRUE(domain.HasValue());
|
||||
auto model = fesa::AnalysisModel::Create(domain.Value());
|
||||
ASSERT_TRUE(model.HasValue());
|
||||
auto dofs = fesa::DofManager::Create(model.Value());
|
||||
ASSERT_TRUE(dofs.HasValue());
|
||||
fesa::SerialParallelFor serial_executor;
|
||||
|
||||
auto assembled = fesa::SparseAssembler::assembleStiffness(
|
||||
model.Value(), dofs.Value(), serialExecutor);
|
||||
auto expected = directShellStiffness(domain.Value(), 0U);
|
||||
ASSERT_TRUE(assembled.HasValue());
|
||||
ASSERT_TRUE(expected.HasValue());
|
||||
auto assembled = fesa::SparseAssembler::AssembleStiffness(
|
||||
model.Value(), dofs.Value(), serial_executor);
|
||||
auto expected = DirectShellStiffness(domain.Value(), 0U);
|
||||
ASSERT_TRUE(assembled.HasValue());
|
||||
ASSERT_TRUE(expected.HasValue());
|
||||
|
||||
EXPECT_EQ(assembled.Value().Rows(), 24U);
|
||||
EXPECT_EQ(assembled.Value().Columns(), 24U);
|
||||
EXPECT_EQ(assembled.Value().Values().size(), 24U * 24U);
|
||||
EXPECT_EQ(
|
||||
assembled.Value().RowOffsets(),
|
||||
dofs.Value().sparsePattern().rowOffsets);
|
||||
EXPECT_EQ(
|
||||
assembled.Value().ColumnIndices(),
|
||||
dofs.Value().sparsePattern().columnIndices);
|
||||
for (std::size_t row = 0U; row < 24U; ++row) {
|
||||
const auto begin = assembled.Value().ColumnIndices().begin() +
|
||||
assembled.Value().RowOffsets()[row];
|
||||
const auto end = assembled.Value().ColumnIndices().begin() +
|
||||
assembled.Value().RowOffsets()[row + 1U];
|
||||
EXPECT_NE(std::lower_bound(begin, end, row), end);
|
||||
for (std::size_t column = 0U; column < 24U; ++column) {
|
||||
EXPECT_DOUBLE_EQ(
|
||||
entry(assembled.Value(), row, column),
|
||||
expected.Value().stabilized_global24(row, column));
|
||||
}
|
||||
EXPECT_EQ(assembled.Value().Rows(), 24U);
|
||||
EXPECT_EQ(assembled.Value().Columns(), 24U);
|
||||
EXPECT_EQ(assembled.Value().Values().size(), 24U * 24U);
|
||||
EXPECT_EQ(assembled.Value().RowOffsets(),
|
||||
dofs.Value().GetSparsePattern().row_offsets);
|
||||
EXPECT_EQ(assembled.Value().ColumnIndices(),
|
||||
dofs.Value().GetSparsePattern().column_indices);
|
||||
for (std::size_t row = 0U; row < 24U; ++row) {
|
||||
const auto begin = assembled.Value().ColumnIndices().begin() +
|
||||
assembled.Value().RowOffsets()[row];
|
||||
const auto end = assembled.Value().ColumnIndices().begin() +
|
||||
assembled.Value().RowOffsets()[row + 1U];
|
||||
EXPECT_NE(std::lower_bound(begin, end, row), end);
|
||||
for (std::size_t column = 0U; column < 24U; ++column) {
|
||||
EXPECT_DOUBLE_EQ(Entry(assembled.Value(), row, column),
|
||||
expected.Value().stabilized_global24(row, column));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST(SparseAssembly, ShellSerialTbbReverseAndRepeatedRunsAreByteIdentical) {
|
||||
fesa::SerialParallelFor serialExecutor;
|
||||
fesa::TbbParallelFor tbbExecutor;
|
||||
ReverseParallelFor reverseExecutor;
|
||||
auto serial = assembleShell(
|
||||
fesa::ShellSourceElementType::kS4, serialExecutor, true);
|
||||
auto tbb = assembleShell(
|
||||
fesa::ShellSourceElementType::kS4, tbbExecutor, true);
|
||||
auto reversed = assembleShell(
|
||||
fesa::ShellSourceElementType::kS4, reverseExecutor, true);
|
||||
ASSERT_TRUE(serial.HasValue());
|
||||
ASSERT_TRUE(tbb.HasValue());
|
||||
ASSERT_TRUE(reversed.HasValue());
|
||||
fesa::SerialParallelFor serial_executor;
|
||||
fesa::TbbParallelFor tbb_executor;
|
||||
ReverseParallelFor reverse_executor;
|
||||
auto serial =
|
||||
AssembleShell(fesa::ShellSourceElementType::kS4, serial_executor, true);
|
||||
auto tbb =
|
||||
AssembleShell(fesa::ShellSourceElementType::kS4, tbb_executor, true);
|
||||
auto reversed =
|
||||
AssembleShell(fesa::ShellSourceElementType::kS4, reverse_executor, true);
|
||||
ASSERT_TRUE(serial.HasValue());
|
||||
ASSERT_TRUE(tbb.HasValue());
|
||||
ASSERT_TRUE(reversed.HasValue());
|
||||
|
||||
EXPECT_EQ(reverseExecutor.calls(), 1U);
|
||||
EXPECT_EQ(reverseExecutor.observedCount(), 2U);
|
||||
expectByteIdentical(tbb.Value(), serial.Value());
|
||||
expectByteIdentical(reversed.Value(), serial.Value());
|
||||
for (std::size_t repetition = 0U; repetition < 8U; ++repetition) {
|
||||
auto repeated = assembleShell(
|
||||
fesa::ShellSourceElementType::kS4, tbbExecutor, true);
|
||||
ASSERT_TRUE(repeated.HasValue());
|
||||
expectByteIdentical(repeated.Value(), serial.Value());
|
||||
}
|
||||
EXPECT_EQ(reverse_executor.Calls(), 1U);
|
||||
EXPECT_EQ(reverse_executor.ObservedCount(), 2U);
|
||||
ExpectByteIdentical(tbb.Value(), serial.Value());
|
||||
ExpectByteIdentical(reversed.Value(), serial.Value());
|
||||
for (std::size_t repetition = 0U; repetition < 8U; ++repetition) {
|
||||
auto repeated =
|
||||
AssembleShell(fesa::ShellSourceElementType::kS4, tbb_executor, true);
|
||||
ASSERT_TRUE(repeated.HasValue());
|
||||
ExpectByteIdentical(repeated.Value(), serial.Value());
|
||||
}
|
||||
}
|
||||
|
||||
TEST(SparseAssembly, S4AndS4rSemanticFixturesAssembleIdenticalStiffness) {
|
||||
fesa::SerialParallelFor serialExecutor;
|
||||
auto s4 = assembleShell(
|
||||
fesa::ShellSourceElementType::kS4, serialExecutor);
|
||||
auto s4r = assembleShell(
|
||||
fesa::ShellSourceElementType::kS4r, serialExecutor);
|
||||
ASSERT_TRUE(s4.HasValue());
|
||||
ASSERT_TRUE(s4r.HasValue());
|
||||
EXPECT_TRUE(std::any_of(
|
||||
s4.Value().Values().begin(),
|
||||
s4.Value().Values().end(),
|
||||
[](const double value) { return value != 0.0; }));
|
||||
expectByteIdentical(s4r.Value(), s4.Value());
|
||||
fesa::SerialParallelFor serial_executor;
|
||||
auto s4 = AssembleShell(fesa::ShellSourceElementType::kS4, serial_executor);
|
||||
auto s4r = AssembleShell(fesa::ShellSourceElementType::kS4r, serial_executor);
|
||||
ASSERT_TRUE(s4.HasValue());
|
||||
ASSERT_TRUE(s4r.HasValue());
|
||||
EXPECT_TRUE(std::any_of(s4.Value().Values().begin(),
|
||||
s4.Value().Values().end(),
|
||||
[](const double value) { return value != 0.0; }));
|
||||
ExpectByteIdentical(s4r.Value(), s4.Value());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user