feat(cpp-object-oriented-modular-refactoring): step 5 - solver-workflow-google-style
This commit is contained in:
@@ -1,8 +1,4 @@
|
||||
#include "fesa/analysis/linear_static_analysis.hpp"
|
||||
|
||||
#include "fesa/assembly/parallel_for.hpp"
|
||||
#include "fesa/results/results_writer.hpp"
|
||||
#include "fesa/solvers/linear/mkl_pardiso_solver.h"
|
||||
#include "fesa/analysis/linear_static_analysis.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
@@ -18,49 +14,52 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "fesa/assembly/parallel_for.h"
|
||||
#include "fesa/results/results_writer.h"
|
||||
#include "fesa/solvers/linear/mkl_pardiso_solver.h"
|
||||
|
||||
namespace {
|
||||
|
||||
class TempDirectory {
|
||||
public:
|
||||
explicit TempDirectory(const std::string& label) {
|
||||
static std::atomic<unsigned long long> sequence{0U};
|
||||
const auto tick = std::chrono::steady_clock::now()
|
||||
.time_since_epoch()
|
||||
.count();
|
||||
path_ = std::filesystem::temp_directory_path() /
|
||||
("fesa-step24-analysis-" + label + "-" +
|
||||
std::to_string(tick) + "-" +
|
||||
std::to_string(sequence.fetch_add(1U)));
|
||||
std::error_code error;
|
||||
if (!std::filesystem::create_directory(path_, error) || error) {
|
||||
throw std::runtime_error{"Unable to create the Step 24 analysis fixture."};
|
||||
}
|
||||
public:
|
||||
explicit TempDirectory(const std::string& label) {
|
||||
static std::atomic<unsigned long long> sequence{0U};
|
||||
const auto tick =
|
||||
std::chrono::steady_clock::now().time_since_epoch().count();
|
||||
path_ = std::filesystem::temp_directory_path() /
|
||||
("fesa-step24-analysis-" + label + "-" + std::to_string(tick) +
|
||||
"-" + std::to_string(sequence.fetch_add(1U)));
|
||||
std::error_code error;
|
||||
if (!std::filesystem::create_directory(path_, error) || error) {
|
||||
throw std::runtime_error{
|
||||
"Unable to create the Step 24 analysis fixture."};
|
||||
}
|
||||
}
|
||||
|
||||
TempDirectory(const TempDirectory&) = delete;
|
||||
TempDirectory& operator=(const TempDirectory&) = delete;
|
||||
TempDirectory(const TempDirectory&) = delete;
|
||||
TempDirectory& operator=(const TempDirectory&) = delete;
|
||||
|
||||
~TempDirectory() {
|
||||
std::error_code ignored;
|
||||
std::filesystem::remove_all(path_, ignored);
|
||||
}
|
||||
~TempDirectory() {
|
||||
std::error_code ignored;
|
||||
std::filesystem::remove_all(path_, ignored);
|
||||
}
|
||||
|
||||
const std::filesystem::path& path() const noexcept { return path_; }
|
||||
const std::filesystem::path& Path() const noexcept { return path_; }
|
||||
|
||||
private:
|
||||
std::filesystem::path path_;
|
||||
private:
|
||||
std::filesystem::path path_;
|
||||
};
|
||||
|
||||
void writeText(const std::filesystem::path& path, const std::string& text) {
|
||||
std::ofstream stream{path, std::ios::binary | std::ios::trunc};
|
||||
stream.write(text.data(), static_cast<std::streamsize>(text.size()));
|
||||
if (!stream) {
|
||||
throw std::runtime_error{"Unable to write the Step 24 analysis input."};
|
||||
}
|
||||
void WriteText(const std::filesystem::path& path, const std::string& text) {
|
||||
std::ofstream stream{path, std::ios::binary | std::ios::trunc};
|
||||
stream.write(text.data(), static_cast<std::streamsize>(text.size()));
|
||||
if (!stream) {
|
||||
throw std::runtime_error{"Unable to write the Step 24 analysis input."};
|
||||
}
|
||||
}
|
||||
|
||||
std::string axialDeck(const double rootUx, const double tipForce) {
|
||||
return R"inp(*Part, name=BeamPart
|
||||
std::string AxialDeck(const double root_ux, const double tip_force) {
|
||||
return R"inp(*Part, name=BeamPart
|
||||
*Node
|
||||
1, 0., 0., 0.
|
||||
2, 2., 0., 0.
|
||||
@@ -84,22 +83,23 @@ std::string axialDeck(const double rootUx, const double tipForce) {
|
||||
*Elastic
|
||||
100., 0.25
|
||||
*Boundary
|
||||
Root, 1, 1, )inp" + std::to_string(rootUx) + R"inp(
|
||||
Root, 1, 1, )inp" +
|
||||
std::to_string(root_ux) + R"inp(
|
||||
Root, 2, 6
|
||||
Tip, 2, 6
|
||||
*Step, name=Load, nlgeom=NO
|
||||
*Static
|
||||
0.1, 1., 0.01, 1.
|
||||
*Cload
|
||||
Tip, 1, )inp" + std::to_string(tipForce) + R"inp(
|
||||
Tip, 1, )inp" +
|
||||
std::to_string(tip_force) + R"inp(
|
||||
*End Step
|
||||
)inp";
|
||||
}
|
||||
|
||||
std::string shellDeck(
|
||||
const std::string& boundaryBlock,
|
||||
const std::string& loadBlock = {}) {
|
||||
return std::string{R"inp(*Part, name=ShellPart
|
||||
std::string ShellDeck(const std::string& boundary_block,
|
||||
const std::string& load_block = {}) {
|
||||
return std::string{R"inp(*Part, name=ShellPart
|
||||
*Node
|
||||
1, 0., 0., 0.
|
||||
2, 1., 0., 0.
|
||||
@@ -129,19 +129,21 @@ std::string shellDeck(
|
||||
*Material, name=Steel
|
||||
*Elastic
|
||||
1000., 0.25
|
||||
)inp"} + boundaryBlock + R"inp(*Step, name=Load, nlgeom=NO
|
||||
)inp"} + boundary_block +
|
||||
R"inp(*Step, name=Load, nlgeom=NO
|
||||
*Static
|
||||
0.1, 1., 0.01, 1.
|
||||
)inp" + loadBlock + R"inp(*End Step
|
||||
)inp" + load_block +
|
||||
R"inp(*End Step
|
||||
)inp";
|
||||
}
|
||||
|
||||
std::string allConstrainedShellDeck() {
|
||||
return shellDeck("*Boundary\nAll, 1, 6\n");
|
||||
std::string AllConstrainedShellDeck() {
|
||||
return ShellDeck("*Boundary\nAll, 1, 6\n");
|
||||
}
|
||||
|
||||
std::string prescribedShellDeck() {
|
||||
return shellDeck(R"inp(*Boundary
|
||||
std::string PrescribedShellDeck() {
|
||||
return ShellDeck(R"inp(*Boundary
|
||||
N1, 1, 6
|
||||
N2, 1, 1, 0.1
|
||||
N2, 2, 6
|
||||
@@ -150,383 +152,373 @@ N4, 1, 6
|
||||
)inp");
|
||||
}
|
||||
|
||||
// The pure Template Method spy makes the eight public lifecycle hooks observable
|
||||
// without coupling the ordering assertion to any solver backend.
|
||||
// The pure Template Method spy makes the eight public lifecycle hooks
|
||||
// observable without coupling the ordering assertion to any solver backend.
|
||||
class SpyAnalysis final : public fesa::Analysis {
|
||||
public:
|
||||
const std::vector<std::string>& events() const noexcept { return events_; }
|
||||
public:
|
||||
const std::vector<std::string>& Events() const noexcept { return events_; }
|
||||
|
||||
protected:
|
||||
fesa::Status initialize(const fesa::AnalysisRequest&) override {
|
||||
return record("initialize");
|
||||
}
|
||||
fesa::Status buildAnalysisModel() override {
|
||||
return record("build-analysis-model");
|
||||
}
|
||||
fesa::Status buildDofMapAndSparsePattern() override {
|
||||
return record("build-dof-map-and-sparse-pattern");
|
||||
}
|
||||
fesa::Status assembleAndPartitionStiffness() override {
|
||||
return record("assemble-and-partition-stiffness");
|
||||
}
|
||||
fesa::Status factorize() override { return record("factorize"); }
|
||||
fesa::Status assembleLoadsAndEffectiveRhs() override {
|
||||
return record("assemble-loads-and-effective-rhs");
|
||||
}
|
||||
fesa::Status substituteAndReconstruct() override {
|
||||
return record("substitute-and-reconstruct");
|
||||
}
|
||||
fesa::Status recoverAndWriteResults() override {
|
||||
return record("recover-and-write-results");
|
||||
}
|
||||
protected:
|
||||
fesa::Status Initialize(const fesa::AnalysisRequest&) override {
|
||||
return Record("initialize");
|
||||
}
|
||||
fesa::Status BuildAnalysisModel() override {
|
||||
return Record("build-analysis-model");
|
||||
}
|
||||
fesa::Status BuildDofMapAndSparsePattern() override {
|
||||
return Record("build-dof-map-and-sparse-pattern");
|
||||
}
|
||||
fesa::Status AssembleAndPartitionStiffness() override {
|
||||
return Record("assemble-and-partition-stiffness");
|
||||
}
|
||||
fesa::Status Factorize() override { return Record("factorize"); }
|
||||
fesa::Status AssembleLoadsAndEffectiveRhs() override {
|
||||
return Record("assemble-loads-and-effective-rhs");
|
||||
}
|
||||
fesa::Status SubstituteAndReconstruct() override {
|
||||
return Record("substitute-and-reconstruct");
|
||||
}
|
||||
fesa::Status RecoverAndWriteResults() override {
|
||||
return Record("recover-and-write-results");
|
||||
}
|
||||
|
||||
private:
|
||||
fesa::Status record(const char* event) {
|
||||
events_.emplace_back(event);
|
||||
return fesa::Status::Ok();
|
||||
}
|
||||
private:
|
||||
fesa::Status Record(const char* event) {
|
||||
events_.emplace_back(event);
|
||||
return fesa::Status::Ok();
|
||||
}
|
||||
|
||||
std::vector<std::string> events_;
|
||||
std::vector<std::string> events_;
|
||||
};
|
||||
|
||||
// The solver spy records only the adapter-boundary operations. In particular,
|
||||
// solve() cannot conceal a second factorization call.
|
||||
class SpyLinearSolver final : public fesa::LinearSolver {
|
||||
public:
|
||||
explicit SpyLinearSolver(std::vector<std::string>& events)
|
||||
: events_{events} {}
|
||||
public:
|
||||
explicit SpyLinearSolver(std::vector<std::string>& events)
|
||||
: events_{events} {}
|
||||
|
||||
fesa::Status Factorize(const fesa::SparseMatrix&) override {
|
||||
++factorizeCalls_;
|
||||
events_.emplace_back("solver-factorize");
|
||||
return fesa::Status::Ok();
|
||||
fesa::Status Factorize(const fesa::SparseMatrix&) override {
|
||||
++factorize_calls_;
|
||||
events_.emplace_back("solver-factorize");
|
||||
return fesa::Status::Ok();
|
||||
}
|
||||
|
||||
fesa::Status Solve(const fesa::Vector& rhs,
|
||||
fesa::Vector& solution) const override {
|
||||
++solve_calls_;
|
||||
events_.emplace_back("solver-solve");
|
||||
for (std::size_t index = 0U; index < rhs.Size() && index < solution.Size();
|
||||
++index) {
|
||||
solution[index] = 0.0;
|
||||
}
|
||||
return fesa::Status::Ok();
|
||||
}
|
||||
|
||||
fesa::Status Solve(
|
||||
const fesa::Vector& rhs, fesa::Vector& solution) const override {
|
||||
++solveCalls_;
|
||||
events_.emplace_back("solver-solve");
|
||||
for (std::size_t index = 0U;
|
||||
index < rhs.Size() && index < solution.Size(); ++index) {
|
||||
solution[index] = 0.0;
|
||||
}
|
||||
return fesa::Status::Ok();
|
||||
}
|
||||
int FactorizeCalls() const noexcept { return factorize_calls_; }
|
||||
int SolveCalls() const noexcept { return solve_calls_; }
|
||||
|
||||
int factorizeCalls() const noexcept { return factorizeCalls_; }
|
||||
int solveCalls() const noexcept { return solveCalls_; }
|
||||
|
||||
private:
|
||||
std::vector<std::string>& events_;
|
||||
int factorizeCalls_{0};
|
||||
mutable int solveCalls_{0};
|
||||
private:
|
||||
std::vector<std::string>& events_;
|
||||
int factorize_calls_{0};
|
||||
mutable int solve_calls_{0};
|
||||
};
|
||||
|
||||
class RecordingMklSolver final : public fesa::LinearSolver {
|
||||
public:
|
||||
fesa::Status Factorize(const fesa::SparseMatrix& matrix) override {
|
||||
++factorizeCalls_;
|
||||
factorizedDimension_ = matrix.Rows();
|
||||
if (matrix.Rows() == 1U && matrix.Columns() == 1U &&
|
||||
matrix.Values().size() == 1U) {
|
||||
scalarStiffness_ = matrix.Values()[0U];
|
||||
}
|
||||
return backend_.Factorize(matrix);
|
||||
public:
|
||||
fesa::Status Factorize(const fesa::SparseMatrix& matrix) override {
|
||||
++factorize_calls_;
|
||||
factorized_dimension_ = matrix.Rows();
|
||||
if (matrix.Rows() == 1U && matrix.Columns() == 1U &&
|
||||
matrix.Values().size() == 1U) {
|
||||
scalar_stiffness_ = matrix.Values()[0U];
|
||||
}
|
||||
return backend_.Factorize(matrix);
|
||||
}
|
||||
|
||||
fesa::Status Solve(
|
||||
const fesa::Vector& rhs, fesa::Vector& solution) const override {
|
||||
++solveCalls_;
|
||||
if (rhs.Size() == 0U) {
|
||||
rhs_.clear();
|
||||
} else {
|
||||
rhs_.assign(rhs.Data(), rhs.Data() + rhs.Size());
|
||||
}
|
||||
return backend_.Solve(rhs, solution);
|
||||
fesa::Status Solve(const fesa::Vector& rhs,
|
||||
fesa::Vector& solution) const override {
|
||||
++solve_calls_;
|
||||
if (rhs.Size() == 0U) {
|
||||
rhs_.clear();
|
||||
} else {
|
||||
rhs_.assign(rhs.Data(), rhs.Data() + rhs.Size());
|
||||
}
|
||||
return backend_.Solve(rhs, solution);
|
||||
}
|
||||
|
||||
int factorizeCalls() const noexcept { return factorizeCalls_; }
|
||||
int solveCalls() const noexcept { return solveCalls_; }
|
||||
std::size_t factorizedDimension() const noexcept {
|
||||
return factorizedDimension_;
|
||||
}
|
||||
double scalarStiffness() const noexcept { return scalarStiffness_; }
|
||||
const std::vector<double>& rhs() const noexcept { return rhs_; }
|
||||
int FactorizeCalls() const noexcept { return factorize_calls_; }
|
||||
int SolveCalls() const noexcept { return solve_calls_; }
|
||||
std::size_t FactorizedDimension() const noexcept {
|
||||
return factorized_dimension_;
|
||||
}
|
||||
double ScalarStiffness() const noexcept { return scalar_stiffness_; }
|
||||
const std::vector<double>& Rhs() const noexcept { return rhs_; }
|
||||
|
||||
private:
|
||||
fesa::MklPardisoSolver backend_;
|
||||
int factorizeCalls_{0};
|
||||
mutable int solveCalls_{0};
|
||||
std::size_t factorizedDimension_{0U};
|
||||
double scalarStiffness_{0.0};
|
||||
mutable std::vector<double> rhs_;
|
||||
private:
|
||||
fesa::MklPardisoSolver backend_;
|
||||
int factorize_calls_{0};
|
||||
mutable int solve_calls_{0};
|
||||
std::size_t factorized_dimension_{0U};
|
||||
double scalar_stiffness_{0.0};
|
||||
mutable std::vector<double> rhs_;
|
||||
};
|
||||
|
||||
class NonfiniteLinearSolver final : public fesa::LinearSolver {
|
||||
public:
|
||||
fesa::Status Factorize(const fesa::SparseMatrix&) override {
|
||||
return fesa::Status::Ok();
|
||||
}
|
||||
public:
|
||||
fesa::Status Factorize(const fesa::SparseMatrix&) override {
|
||||
return fesa::Status::Ok();
|
||||
}
|
||||
|
||||
fesa::Status Solve(
|
||||
const fesa::Vector&, fesa::Vector& solution) const override {
|
||||
for (std::size_t index = 0U; index < solution.Size(); ++index) {
|
||||
solution[index] = (std::numeric_limits<double>::quiet_NaN)();
|
||||
}
|
||||
return fesa::Status::Ok();
|
||||
fesa::Status Solve(const fesa::Vector&,
|
||||
fesa::Vector& solution) const override {
|
||||
for (std::size_t index = 0U; index < solution.Size(); ++index) {
|
||||
solution[index] = (std::numeric_limits<double>::quiet_NaN)();
|
||||
}
|
||||
return fesa::Status::Ok();
|
||||
}
|
||||
};
|
||||
|
||||
class SpyResultsWriter final : public fesa::ResultsWriter {
|
||||
public:
|
||||
explicit SpyResultsWriter(std::vector<std::string>& events)
|
||||
: events_{events} {}
|
||||
public:
|
||||
explicit SpyResultsWriter(std::vector<std::string>& events)
|
||||
: events_{events} {}
|
||||
|
||||
fesa::Status write(
|
||||
const std::filesystem::path&,
|
||||
const fesa::Domain&,
|
||||
const fesa::AnalysisState&,
|
||||
const std::vector<fesa::Diagnostic>&) override {
|
||||
++writeCalls_;
|
||||
events_.emplace_back("writer-write");
|
||||
return fesa::Status::Ok();
|
||||
}
|
||||
fesa::Status Write(const std::filesystem::path&, const fesa::Domain&,
|
||||
const fesa::AnalysisState&,
|
||||
const std::vector<fesa::Diagnostic>&) override {
|
||||
++write_calls_;
|
||||
events_.emplace_back("writer-write");
|
||||
return fesa::Status::Ok();
|
||||
}
|
||||
|
||||
int writeCalls() const noexcept { return writeCalls_; }
|
||||
int WriteCalls() const noexcept { return write_calls_; }
|
||||
|
||||
private:
|
||||
std::vector<std::string>& events_;
|
||||
int writeCalls_{0};
|
||||
private:
|
||||
std::vector<std::string>& events_;
|
||||
int write_calls_{0};
|
||||
};
|
||||
|
||||
class CapturingResultsWriter final : public fesa::ResultsWriter {
|
||||
public:
|
||||
fesa::Status write(
|
||||
const std::filesystem::path& outputPath,
|
||||
const fesa::Domain& domain,
|
||||
const fesa::AnalysisState& state,
|
||||
const std::vector<fesa::Diagnostic>& diagnostics) override {
|
||||
outputPath_ = outputPath;
|
||||
nodeCount_ = domain.Nodes().size();
|
||||
shellElementCount_ = domain.ShellElements().size();
|
||||
state_ = std::make_unique<fesa::AnalysisState>(state);
|
||||
diagnostics_ = diagnostics;
|
||||
return fesa::Status::Ok();
|
||||
}
|
||||
public:
|
||||
fesa::Status Write(
|
||||
const std::filesystem::path& output_path, const fesa::Domain& domain,
|
||||
const fesa::AnalysisState& state,
|
||||
const std::vector<fesa::Diagnostic>& diagnostics) override {
|
||||
output_path_ = output_path;
|
||||
node_count_ = domain.Nodes().size();
|
||||
shell_element_count_ = domain.ShellElements().size();
|
||||
state_ = std::make_unique<fesa::AnalysisState>(state);
|
||||
diagnostics_ = diagnostics;
|
||||
return fesa::Status::Ok();
|
||||
}
|
||||
|
||||
const fesa::AnalysisState& state() const {
|
||||
if (!state_) {
|
||||
throw std::logic_error{"No AnalysisState was captured."};
|
||||
}
|
||||
return *state_;
|
||||
const fesa::AnalysisState& State() const {
|
||||
if (!state_) {
|
||||
throw std::logic_error{"No AnalysisState was captured."};
|
||||
}
|
||||
return *state_;
|
||||
}
|
||||
|
||||
const std::filesystem::path& outputPath() const noexcept {
|
||||
return outputPath_;
|
||||
}
|
||||
std::size_t nodeCount() const noexcept { return nodeCount_; }
|
||||
std::size_t shellElementCount() const noexcept {
|
||||
return shellElementCount_;
|
||||
}
|
||||
const std::vector<fesa::Diagnostic>& diagnostics() const noexcept {
|
||||
return diagnostics_;
|
||||
}
|
||||
const std::filesystem::path& OutputPath() const noexcept {
|
||||
return output_path_;
|
||||
}
|
||||
std::size_t NodeCount() const noexcept { return node_count_; }
|
||||
std::size_t ShellElementCount() const noexcept {
|
||||
return shell_element_count_;
|
||||
}
|
||||
const std::vector<fesa::Diagnostic>& Diagnostics() const noexcept {
|
||||
return diagnostics_;
|
||||
}
|
||||
|
||||
private:
|
||||
std::filesystem::path outputPath_;
|
||||
std::size_t nodeCount_{0U};
|
||||
std::size_t shellElementCount_{0U};
|
||||
std::unique_ptr<fesa::AnalysisState> state_;
|
||||
std::vector<fesa::Diagnostic> diagnostics_;
|
||||
private:
|
||||
std::filesystem::path output_path_;
|
||||
std::size_t node_count_{0U};
|
||||
std::size_t shell_element_count_{0U};
|
||||
std::unique_ptr<fesa::AnalysisState> state_;
|
||||
std::vector<fesa::Diagnostic> diagnostics_;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
TEST(LinearStaticCli, FactorizesBeforeLoadAndSolvesWithoutRefactorization) {
|
||||
SpyAnalysis lifecycle;
|
||||
const fesa::AnalysisRequest emptyRequest{};
|
||||
ASSERT_TRUE(lifecycle.run(emptyRequest).IsOk());
|
||||
EXPECT_EQ(
|
||||
lifecycle.events(),
|
||||
(std::vector<std::string>{
|
||||
"initialize",
|
||||
"build-analysis-model",
|
||||
"build-dof-map-and-sparse-pattern",
|
||||
"assemble-and-partition-stiffness",
|
||||
"factorize",
|
||||
"assemble-loads-and-effective-rhs",
|
||||
"substitute-and-reconstruct",
|
||||
"recover-and-write-results"}));
|
||||
SpyAnalysis lifecycle;
|
||||
const fesa::AnalysisRequest empty_request{};
|
||||
ASSERT_TRUE(lifecycle.Run(empty_request).IsOk());
|
||||
EXPECT_EQ(lifecycle.Events(),
|
||||
(std::vector<std::string>{
|
||||
"initialize", "build-analysis-model",
|
||||
"build-dof-map-and-sparse-pattern",
|
||||
"assemble-and-partition-stiffness", "factorize",
|
||||
"assemble-loads-and-effective-rhs",
|
||||
"substitute-and-reconstruct", "recover-and-write-results"}));
|
||||
|
||||
TempDirectory directory{"order"};
|
||||
const auto input = directory.path() / "order.inp";
|
||||
const auto output = directory.path() / "results.h5";
|
||||
writeText(input, axialDeck(0.0, 0.0));
|
||||
TempDirectory directory{"order"};
|
||||
const auto input = directory.Path() / "order.inp";
|
||||
const auto output = directory.Path() / "results.h5";
|
||||
WriteText(input, AxialDeck(0.0, 0.0));
|
||||
|
||||
std::vector<std::string> adapterEvents;
|
||||
fesa::SerialParallelFor serial;
|
||||
SpyLinearSolver solver{adapterEvents};
|
||||
SpyResultsWriter writer{adapterEvents};
|
||||
fesa::LinearStaticAnalysis analysis{serial, solver, writer};
|
||||
std::vector<std::string> adapter_events;
|
||||
fesa::SerialParallelFor serial;
|
||||
SpyLinearSolver solver{adapter_events};
|
||||
SpyResultsWriter writer{adapter_events};
|
||||
fesa::LinearStaticAnalysis analysis{serial, solver, writer};
|
||||
|
||||
ASSERT_TRUE(analysis.run({input, output}).IsOk());
|
||||
EXPECT_EQ(solver.factorizeCalls(), 1);
|
||||
EXPECT_EQ(solver.solveCalls(), 1);
|
||||
EXPECT_EQ(writer.writeCalls(), 1);
|
||||
EXPECT_EQ(
|
||||
adapterEvents,
|
||||
(std::vector<std::string>{
|
||||
"solver-factorize", "solver-solve", "writer-write"}));
|
||||
ASSERT_TRUE(analysis.Run({input, output}).IsOk());
|
||||
EXPECT_EQ(solver.FactorizeCalls(), 1);
|
||||
EXPECT_EQ(solver.SolveCalls(), 1);
|
||||
EXPECT_EQ(writer.WriteCalls(), 1);
|
||||
EXPECT_EQ(adapter_events,
|
||||
(std::vector<std::string>{"solver-factorize", "solver-solve",
|
||||
"writer-write"}));
|
||||
}
|
||||
|
||||
TEST(LinearStaticCli, RealPipelineHandlesAnalyticalAndNonzeroPrescription) {
|
||||
TempDirectory directory{"analytical"};
|
||||
const auto input = directory.path() / "prescribed-axial.inp";
|
||||
const auto output = directory.path() / "captured-results.h5";
|
||||
writeText(input, axialDeck(0.1, 10.0));
|
||||
TempDirectory directory{"analytical"};
|
||||
const auto input = directory.Path() / "prescribed-axial.inp";
|
||||
const auto output = directory.Path() / "captured-results.h5";
|
||||
WriteText(input, AxialDeck(0.1, 10.0));
|
||||
|
||||
fesa::SerialParallelFor serial;
|
||||
fesa::MklPardisoSolver solver;
|
||||
CapturingResultsWriter writer;
|
||||
fesa::LinearStaticAnalysis analysis{serial, solver, writer};
|
||||
fesa::SerialParallelFor serial;
|
||||
fesa::MklPardisoSolver solver;
|
||||
CapturingResultsWriter writer;
|
||||
fesa::LinearStaticAnalysis analysis{serial, solver, writer};
|
||||
|
||||
const auto status = analysis.run({input, output});
|
||||
ASSERT_TRUE(status.IsOk());
|
||||
EXPECT_EQ(writer.outputPath(), output);
|
||||
EXPECT_EQ(writer.nodeCount(), 2U);
|
||||
EXPECT_TRUE(writer.diagnostics().empty());
|
||||
const auto status = analysis.Run({input, output});
|
||||
ASSERT_TRUE(status.IsOk());
|
||||
EXPECT_EQ(writer.OutputPath(), output);
|
||||
EXPECT_EQ(writer.NodeCount(), 2U);
|
||||
EXPECT_TRUE(writer.Diagnostics().empty());
|
||||
|
||||
const auto& state = writer.state();
|
||||
ASSERT_EQ(state.displacement().Size(), 12U);
|
||||
EXPECT_EQ(state.identity().stepName, "Step-1");
|
||||
EXPECT_EQ(state.identity().frameIndex, 0U);
|
||||
const auto& state = writer.State();
|
||||
ASSERT_EQ(state.Displacement().Size(), 12U);
|
||||
EXPECT_EQ(state.Identity().step_name, "Step-1");
|
||||
EXPECT_EQ(state.Identity().frame_index, 0U);
|
||||
|
||||
// EA/L = 100 for this fixture, so u_tip = 0.1 + 10/100 = 0.2.
|
||||
EXPECT_NEAR(state.displacement()[0U], 0.1, 1.0e-12);
|
||||
EXPECT_NEAR(state.displacement()[6U], 0.2, 2.0e-10);
|
||||
EXPECT_NEAR(state.externalForce()[6U], 10.0, 1.0e-12);
|
||||
EXPECT_NEAR(state.internalForce()[0U], -10.0, 1.0e-9);
|
||||
EXPECT_NEAR(state.internalForce()[6U], 10.0, 1.0e-9);
|
||||
EXPECT_NEAR(state.reaction()[0U], -10.0, 1.0e-9);
|
||||
EXPECT_NEAR(state.residual()[6U], 0.0, 1.0e-9);
|
||||
EXPECT_EQ(state.endpointResults().size(), 2U);
|
||||
EXPECT_EQ(state.gaussResults().size(), 2U);
|
||||
EXPECT_EQ(state.stressResults().size(), 2U);
|
||||
// EA/L = 100 for this fixture, so u_tip = 0.1 + 10/100 = 0.2.
|
||||
EXPECT_NEAR(state.Displacement()[0U], 0.1, 1.0e-12);
|
||||
EXPECT_NEAR(state.Displacement()[6U], 0.2, 2.0e-10);
|
||||
EXPECT_NEAR(state.ExternalForce()[6U], 10.0, 1.0e-12);
|
||||
EXPECT_NEAR(state.InternalForce()[0U], -10.0, 1.0e-9);
|
||||
EXPECT_NEAR(state.InternalForce()[6U], 10.0, 1.0e-9);
|
||||
EXPECT_NEAR(state.Reaction()[0U], -10.0, 1.0e-9);
|
||||
EXPECT_NEAR(state.Residual()[6U], 0.0, 1.0e-9);
|
||||
EXPECT_EQ(state.EndpointResults().size(), 2U);
|
||||
EXPECT_EQ(state.GaussResults().size(), 2U);
|
||||
EXPECT_EQ(state.StressResults().size(), 2U);
|
||||
}
|
||||
|
||||
// MITC4-FLOW-001
|
||||
TEST(Mitc4ShellCli, UsesExistingLifecycleAndExactlyOneFactorization) {
|
||||
TempDirectory directory{"shell-order"};
|
||||
const auto input = directory.path() / "all-constrained-shell.inp";
|
||||
const auto output = directory.path() / "results.h5";
|
||||
writeText(input, allConstrainedShellDeck());
|
||||
TempDirectory directory{"shell-order"};
|
||||
const auto input = directory.Path() / "all-constrained-shell.inp";
|
||||
const auto output = directory.Path() / "results.h5";
|
||||
WriteText(input, AllConstrainedShellDeck());
|
||||
|
||||
std::vector<std::string> adapterEvents;
|
||||
fesa::SerialParallelFor serial;
|
||||
SpyLinearSolver solver{adapterEvents};
|
||||
SpyResultsWriter writer{adapterEvents};
|
||||
fesa::LinearStaticAnalysis analysis{serial, solver, writer};
|
||||
std::vector<std::string> adapter_events;
|
||||
fesa::SerialParallelFor serial;
|
||||
SpyLinearSolver solver{adapter_events};
|
||||
SpyResultsWriter writer{adapter_events};
|
||||
fesa::LinearStaticAnalysis analysis{serial, solver, writer};
|
||||
|
||||
ASSERT_TRUE(analysis.run({input, output}).IsOk());
|
||||
EXPECT_EQ(solver.factorizeCalls(), 1);
|
||||
EXPECT_EQ(solver.solveCalls(), 1);
|
||||
EXPECT_EQ(writer.writeCalls(), 1);
|
||||
EXPECT_EQ(
|
||||
adapterEvents,
|
||||
(std::vector<std::string>{
|
||||
"solver-factorize", "solver-solve", "writer-write"}));
|
||||
ASSERT_TRUE(analysis.Run({input, output}).IsOk());
|
||||
EXPECT_EQ(solver.FactorizeCalls(), 1);
|
||||
EXPECT_EQ(solver.SolveCalls(), 1);
|
||||
EXPECT_EQ(writer.WriteCalls(), 1);
|
||||
EXPECT_EQ(adapter_events,
|
||||
(std::vector<std::string>{"solver-factorize", "solver-solve",
|
||||
"writer-write"}));
|
||||
}
|
||||
|
||||
// MITC4-FLOW-002
|
||||
TEST(Mitc4ShellCli, AppliesKfcForNonzeroPrescribedDisplacement) {
|
||||
TempDirectory directory{"shell-prescribed"};
|
||||
const auto input = directory.path() / "prescribed-shell.inp";
|
||||
const auto output = directory.path() / "captured-results.h5";
|
||||
writeText(input, prescribedShellDeck());
|
||||
TempDirectory directory{"shell-prescribed"};
|
||||
const auto input = directory.Path() / "prescribed-shell.inp";
|
||||
const auto output = directory.Path() / "captured-results.h5";
|
||||
WriteText(input, PrescribedShellDeck());
|
||||
|
||||
fesa::SerialParallelFor serial;
|
||||
RecordingMklSolver solver;
|
||||
CapturingResultsWriter writer;
|
||||
fesa::LinearStaticAnalysis analysis{serial, solver, writer};
|
||||
fesa::SerialParallelFor serial;
|
||||
RecordingMklSolver solver;
|
||||
CapturingResultsWriter writer;
|
||||
fesa::LinearStaticAnalysis analysis{serial, solver, writer};
|
||||
|
||||
const auto status = analysis.run({input, output});
|
||||
for (const auto& diagnostic : status.Diagnostics()) {
|
||||
EXPECT_TRUE(status.IsOk())
|
||||
<< diagnostic.code << ": " << diagnostic.message;
|
||||
}
|
||||
ASSERT_TRUE(status.IsOk());
|
||||
ASSERT_EQ(solver.factorizeCalls(), 1);
|
||||
ASSERT_EQ(solver.solveCalls(), 1);
|
||||
ASSERT_EQ(solver.factorizedDimension(), 1U);
|
||||
ASSERT_EQ(solver.rhs().size(), 1U);
|
||||
EXPECT_NEAR(solver.scalarStiffness(), 440.0 / 9.0, 1.0e-12);
|
||||
// Ff is exactly zero, so this nonzero RHS is solely -Kfc*dc.
|
||||
EXPECT_NEAR(solver.rhs()[0U], -4.0 / 9.0, 1.0e-12);
|
||||
const auto status = analysis.Run({input, output});
|
||||
for (const auto& diagnostic : status.Diagnostics()) {
|
||||
EXPECT_TRUE(status.IsOk()) << diagnostic.code << ": " << diagnostic.message;
|
||||
}
|
||||
ASSERT_TRUE(status.IsOk());
|
||||
ASSERT_EQ(solver.FactorizeCalls(), 1);
|
||||
ASSERT_EQ(solver.SolveCalls(), 1);
|
||||
ASSERT_EQ(solver.FactorizedDimension(), 1U);
|
||||
ASSERT_EQ(solver.Rhs().size(), 1U);
|
||||
EXPECT_NEAR(solver.ScalarStiffness(), 440.0 / 9.0, 1.0e-12);
|
||||
// Ff is exactly zero, so this nonzero RHS is solely -Kfc*dc.
|
||||
EXPECT_NEAR(solver.Rhs()[0U], -4.0 / 9.0, 1.0e-12);
|
||||
|
||||
EXPECT_EQ(writer.outputPath(), output);
|
||||
EXPECT_EQ(writer.nodeCount(), 4U);
|
||||
EXPECT_EQ(writer.shellElementCount(), 1U);
|
||||
const auto& state = writer.state();
|
||||
ASSERT_EQ(state.displacement().Size(), 24U);
|
||||
EXPECT_NEAR(state.displacement()[6U], 0.1, 1.0e-12);
|
||||
EXPECT_NEAR(state.displacement()[12U], -1.0 / 110.0, 1.0e-12);
|
||||
EXPECT_NEAR(state.verificationMetrics()[0U], 0.0, 1.0e-10);
|
||||
EXPECT_EQ(state.shellResults().size(), 4U);
|
||||
EXPECT_GT(state.physicalStrainEnergy(), 0.0);
|
||||
EXPECT_EQ(writer.OutputPath(), output);
|
||||
EXPECT_EQ(writer.NodeCount(), 4U);
|
||||
EXPECT_EQ(writer.ShellElementCount(), 1U);
|
||||
const auto& state = writer.State();
|
||||
ASSERT_EQ(state.Displacement().Size(), 24U);
|
||||
EXPECT_NEAR(state.Displacement()[6U], 0.1, 1.0e-12);
|
||||
EXPECT_NEAR(state.Displacement()[12U], -1.0 / 110.0, 1.0e-12);
|
||||
EXPECT_NEAR(state.VerificationMetrics()[0U], 0.0, 1.0e-10);
|
||||
EXPECT_EQ(state.ShellResults().size(), 4U);
|
||||
EXPECT_GT(state.PhysicalStrainEnergy(), 0.0);
|
||||
}
|
||||
|
||||
// MITC4-FLOW-003
|
||||
TEST(Mitc4ShellCli, RejectsSingularAndAcceptsZeroByZeroFreeSystem) {
|
||||
TempDirectory directory{"shell-singular-all"};
|
||||
const auto singularInput = directory.path() / "singular-shell.inp";
|
||||
const auto constrainedInput = directory.path() / "constrained-shell.inp";
|
||||
writeText(singularInput, shellDeck(""));
|
||||
writeText(constrainedInput, allConstrainedShellDeck());
|
||||
TempDirectory directory{"shell-singular-all"};
|
||||
const auto singular_input = directory.Path() / "singular-shell.inp";
|
||||
const auto constrained_input = directory.Path() / "constrained-shell.inp";
|
||||
WriteText(singular_input, ShellDeck(""));
|
||||
WriteText(constrained_input, AllConstrainedShellDeck());
|
||||
|
||||
fesa::SerialParallelFor serial;
|
||||
fesa::MklPardisoSolver singularSolver;
|
||||
std::vector<std::string> singularEvents;
|
||||
SpyResultsWriter singularWriter{singularEvents};
|
||||
fesa::LinearStaticAnalysis singularAnalysis{
|
||||
serial, singularSolver, singularWriter};
|
||||
const auto singular = singularAnalysis.run(
|
||||
{singularInput, directory.path() / "singular.h5"});
|
||||
ASSERT_FALSE(singular.IsOk());
|
||||
EXPECT_EQ(singular.Category(), fesa::FailureCategory::kSolver);
|
||||
EXPECT_EQ(singularWriter.writeCalls(), 0);
|
||||
fesa::SerialParallelFor serial;
|
||||
fesa::MklPardisoSolver singular_solver;
|
||||
std::vector<std::string> singular_events;
|
||||
SpyResultsWriter singular_writer{singular_events};
|
||||
fesa::LinearStaticAnalysis singular_analysis{serial, singular_solver,
|
||||
singular_writer};
|
||||
const auto singular =
|
||||
singular_analysis.Run({singular_input, directory.Path() / "singular.h5"});
|
||||
ASSERT_FALSE(singular.IsOk());
|
||||
EXPECT_EQ(singular.Category(), fesa::FailureCategory::kSolver);
|
||||
EXPECT_EQ(singular_writer.WriteCalls(), 0);
|
||||
|
||||
RecordingMklSolver constrainedSolver;
|
||||
CapturingResultsWriter constrainedWriter;
|
||||
fesa::LinearStaticAnalysis constrainedAnalysis{
|
||||
serial, constrainedSolver, constrainedWriter};
|
||||
const auto constrained = constrainedAnalysis.run(
|
||||
{constrainedInput, directory.path() / "constrained.h5"});
|
||||
ASSERT_TRUE(constrained.IsOk());
|
||||
EXPECT_EQ(constrainedSolver.factorizeCalls(), 1);
|
||||
EXPECT_EQ(constrainedSolver.factorizedDimension(), 0U);
|
||||
EXPECT_EQ(constrainedSolver.solveCalls(), 1);
|
||||
EXPECT_TRUE(constrainedSolver.rhs().empty());
|
||||
EXPECT_EQ(constrainedWriter.state().shellResults().size(), 4U);
|
||||
RecordingMklSolver constrained_solver;
|
||||
CapturingResultsWriter constrained_writer;
|
||||
fesa::LinearStaticAnalysis constrained_analysis{serial, constrained_solver,
|
||||
constrained_writer};
|
||||
const auto constrained = constrained_analysis.Run(
|
||||
{constrained_input, directory.Path() / "constrained.h5"});
|
||||
ASSERT_TRUE(constrained.IsOk());
|
||||
EXPECT_EQ(constrained_solver.FactorizeCalls(), 1);
|
||||
EXPECT_EQ(constrained_solver.FactorizedDimension(), 0U);
|
||||
EXPECT_EQ(constrained_solver.SolveCalls(), 1);
|
||||
EXPECT_TRUE(constrained_solver.Rhs().empty());
|
||||
EXPECT_EQ(constrained_writer.State().ShellResults().size(), 4U);
|
||||
}
|
||||
|
||||
// MITC4-FLOW-004
|
||||
TEST(Mitc4ShellCli, DoesNotWriteAnInvalidRecoveryCandidate) {
|
||||
TempDirectory directory{"shell-invalid-candidate"};
|
||||
const auto input = directory.path() / "invalid-recovery-shell.inp";
|
||||
writeText(input, prescribedShellDeck());
|
||||
TempDirectory directory{"shell-invalid-candidate"};
|
||||
const auto input = directory.Path() / "invalid-recovery-shell.inp";
|
||||
WriteText(input, PrescribedShellDeck());
|
||||
|
||||
fesa::SerialParallelFor serial;
|
||||
NonfiniteLinearSolver solver;
|
||||
std::vector<std::string> adapterEvents;
|
||||
SpyResultsWriter writer{adapterEvents};
|
||||
fesa::LinearStaticAnalysis analysis{serial, solver, writer};
|
||||
const auto status = analysis.run(
|
||||
{input, directory.path() / "must-not-exist.h5"});
|
||||
fesa::SerialParallelFor serial;
|
||||
NonfiniteLinearSolver solver;
|
||||
std::vector<std::string> adapter_events;
|
||||
SpyResultsWriter writer{adapter_events};
|
||||
fesa::LinearStaticAnalysis analysis{serial, solver, writer};
|
||||
const auto status =
|
||||
analysis.Run({input, directory.Path() / "must-not-exist.h5"});
|
||||
|
||||
ASSERT_FALSE(status.IsOk());
|
||||
EXPECT_EQ(status.Category(), fesa::FailureCategory::kModel);
|
||||
ASSERT_FALSE(status.Diagnostics().empty());
|
||||
EXPECT_EQ(status.Diagnostics().front().code, "nonfinite-recovery-value");
|
||||
EXPECT_EQ(writer.writeCalls(), 0);
|
||||
EXPECT_TRUE(adapterEvents.empty());
|
||||
ASSERT_FALSE(status.IsOk());
|
||||
EXPECT_EQ(status.Category(), fesa::FailureCategory::kModel);
|
||||
ASSERT_FALSE(status.Diagnostics().empty());
|
||||
EXPECT_EQ(status.Diagnostics().front().code, "nonfinite-recovery-value");
|
||||
EXPECT_EQ(writer.WriteCalls(), 0);
|
||||
EXPECT_TRUE(adapter_events.empty());
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
#include "reference_comparison.hpp"
|
||||
|
||||
#include "fesa/analysis/analysis_model.hpp"
|
||||
#include "fesa/assembly/load_assembler.hpp"
|
||||
#include "fesa/fem/dof_manager.hpp"
|
||||
#include "fesa/analysis/analysis_model.h"
|
||||
#include "fesa/assembly/load_assembler.h"
|
||||
#include "fesa/fem/dof_manager.h"
|
||||
#include "fesa/io/abaqus/domain_mapper.hpp"
|
||||
#include "fesa/io/abaqus/input_reader.hpp"
|
||||
#include "fesa/results/result_recovery.hpp"
|
||||
#include "fesa/results/result_recovery.h"
|
||||
|
||||
#include <hdf5.h>
|
||||
|
||||
@@ -962,7 +962,7 @@ std::vector<NodeStationResultRow> normalizeStations(
|
||||
const Domain& domain,
|
||||
const HdfProjection& hdf,
|
||||
const ReferenceTable& sectionTable) {
|
||||
auto modelResult = AnalysisModel::create(domain);
|
||||
auto modelResult = AnalysisModel::Create(domain);
|
||||
if (!modelResult.HasValue()) {
|
||||
fail("schema-mismatch", "The approved input cannot create an analysis view.");
|
||||
}
|
||||
@@ -991,7 +991,7 @@ std::vector<NodeStationResultRow> normalizeStations(
|
||||
values});
|
||||
}
|
||||
}
|
||||
auto normalized = ResultRecovery::normalizeSectionResultantsToNodeStations(
|
||||
auto normalized = ResultRecovery::NormalizeSectionResultantsToNodeStations(
|
||||
model, endpoints, tolerances);
|
||||
if (!normalized.HasValue()) {
|
||||
const auto& diagnostics = normalized.GetStatus().Diagnostics();
|
||||
@@ -1079,7 +1079,7 @@ void appendSectionRows(
|
||||
for (std::size_t component = 0U; component < components.size(); ++component) {
|
||||
auto fesa = canonicalRow(
|
||||
hdf.nodes[node], ComparisonQuantity::sectionResultant,
|
||||
components[component], station.sectionResultant[component],
|
||||
components[component], station.section_resultant[component],
|
||||
units[component], "beam-local", kSectionPath);
|
||||
auto abaqus = canonicalRow(
|
||||
hdf.nodes[node], ComparisonQuantity::sectionResultant,
|
||||
@@ -1164,17 +1164,17 @@ void evaluateGroup(
|
||||
PhysicsEvidence makePhysicsEvidence(
|
||||
const Domain& domain,
|
||||
const HdfProjection& hdf) {
|
||||
auto modelResult = AnalysisModel::create(domain);
|
||||
auto modelResult = AnalysisModel::Create(domain);
|
||||
if (!modelResult.HasValue()) {
|
||||
fail("schema-mismatch", "The approved input cannot create physics evidence.");
|
||||
}
|
||||
const AnalysisModel model = std::move(modelResult.Value());
|
||||
auto dofsResult = DofManager::create(model);
|
||||
auto dofsResult = DofManager::Create(model);
|
||||
if (!dofsResult.HasValue()) {
|
||||
fail("schema-mismatch", "The approved input cannot create a DOF map.");
|
||||
}
|
||||
const DofManager dofs = std::move(dofsResult.Value());
|
||||
auto loadResult = LoadAssembler::assembleFullNodalLoad(model, dofs);
|
||||
auto loadResult = LoadAssembler::AssembleFullNodalLoad(model, dofs);
|
||||
if (!loadResult.HasValue()) {
|
||||
fail("schema-mismatch", "The approved input load cannot be assembled.");
|
||||
}
|
||||
@@ -1185,7 +1185,7 @@ PhysicsEvidence makePhysicsEvidence(
|
||||
|
||||
PhysicsEvidence evidence{};
|
||||
long double residualSquared = 0.0L;
|
||||
for (const std::size_t freeDof : dofs.freeDofs()) {
|
||||
for (const std::size_t freeDof : dofs.FreeDofs()) {
|
||||
const long double value =
|
||||
static_cast<long double>(hdf.reaction[freeDof]);
|
||||
residualSquared += value * value;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#include "reference_comparison.hpp"
|
||||
|
||||
#include "fesa/analysis/analysis_model.hpp"
|
||||
#include "fesa/analysis/analysis_state.hpp"
|
||||
#include "fesa/fem/dof_manager.hpp"
|
||||
#include "fesa/analysis/analysis_model.h"
|
||||
#include "fesa/analysis/analysis_state.h"
|
||||
#include "fesa/fem/dof_manager.h"
|
||||
#include "fesa/io/abaqus/input_reader.hpp"
|
||||
#include "fesa/io/hdf5/hdf5_results_writer.hpp"
|
||||
#include "fesa/model/domain.h"
|
||||
@@ -223,42 +223,42 @@ void writeResultsFixture(
|
||||
throw std::runtime_error{"Reference fixture Domain construction failed."};
|
||||
}
|
||||
fesa::Domain domain = std::move(domainResult.Value());
|
||||
auto modelResult = fesa::AnalysisModel::create(domain);
|
||||
auto modelResult = fesa::AnalysisModel::Create(domain);
|
||||
if (!modelResult.HasValue()) {
|
||||
throw std::runtime_error{"Reference fixture AnalysisModel construction failed."};
|
||||
}
|
||||
fesa::AnalysisModel model = std::move(modelResult.Value());
|
||||
auto dofsResult = fesa::DofManager::create(model);
|
||||
auto dofsResult = fesa::DofManager::Create(model);
|
||||
if (!dofsResult.HasValue()) {
|
||||
throw std::runtime_error{"Reference fixture DofManager construction failed."};
|
||||
}
|
||||
fesa::DofManager dofs = std::move(dofsResult.Value());
|
||||
fesa::AnalysisState state =
|
||||
fesa::AnalysisState::create(dofs, {"Step-1", 0U});
|
||||
fesa::AnalysisState::Create(dofs, {"Step-1", 0U});
|
||||
|
||||
for (std::size_t node = 0U; node < kNodeCount; ++node) {
|
||||
for (std::size_t component = 0U; component < 6U; ++component) {
|
||||
const std::size_t index = node * 6U + component;
|
||||
state.displacement()[index] = values.displacement[node][component];
|
||||
state.reaction()[index] = values.reaction[node][component];
|
||||
state.residual()[index] = values.reaction[node][component];
|
||||
state.Displacement()[index] = values.displacement[node][component];
|
||||
state.Reaction()[index] = values.reaction[node][component];
|
||||
state.Residual()[index] = values.reaction[node][component];
|
||||
}
|
||||
}
|
||||
for (std::size_t element = 0U; element < kElementCount; ++element) {
|
||||
for (std::size_t endpoint = 0U; endpoint < 2U; ++endpoint) {
|
||||
const std::size_t node = element + endpoint;
|
||||
state.endpointResults().push_back({
|
||||
state.EndpointResults().push_back({
|
||||
static_cast<fesa::EntityIndex>(element),
|
||||
static_cast<int>(endpoint),
|
||||
domain.Nodes()[node].source_id,
|
||||
{},
|
||||
values.sectionResultants[element][endpoint]});
|
||||
}
|
||||
state.gaussResults().push_back(
|
||||
state.GaussResults().push_back(
|
||||
{static_cast<fesa::EntityIndex>(element), 1, {}, {}});
|
||||
state.gaussResults().push_back(
|
||||
state.GaussResults().push_back(
|
||||
{static_cast<fesa::EntityIndex>(element), 2, {}, {}});
|
||||
state.stressResults().push_back({
|
||||
state.StressResults().push_back({
|
||||
static_cast<fesa::EntityIndex>(element),
|
||||
1,
|
||||
0U,
|
||||
@@ -266,7 +266,7 @@ void writeResultsFixture(
|
||||
0.0,
|
||||
0.0,
|
||||
"fesa-default"});
|
||||
state.stressResults().push_back({
|
||||
state.StressResults().push_back({
|
||||
static_cast<fesa::EntityIndex>(element),
|
||||
2,
|
||||
0U,
|
||||
@@ -277,7 +277,7 @@ void writeResultsFixture(
|
||||
}
|
||||
|
||||
fesa::Hdf5ResultsWriter writer;
|
||||
const fesa::Status status = writer.write(output, domain, state, {});
|
||||
const fesa::Status status = writer.Write(output, domain, state, {});
|
||||
if (!status.IsOk()) {
|
||||
throw std::runtime_error{"Reference fixture HDF5 write failed."};
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "fesa/analysis/analysis_model.hpp"
|
||||
#include "fesa/analysis/analysis_model.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
@@ -9,146 +9,154 @@
|
||||
|
||||
namespace {
|
||||
|
||||
fesa::ModelDefinition makeDefinition() {
|
||||
const std::filesystem::path source{"models/analysis-model.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"}, {1.0, 0.0, 0.0}, {source, 11U}},
|
||||
{{"Beam-1", 3, "3"}, {2.0, 0.0, 0.0}, {source, 12U}},
|
||||
{{"Beam-1", 4, "4"}, {3.0, 0.0, 0.0}, {source, 13U}},
|
||||
{{"Beam-1", 5, "5"}, {4.0, 0.0, 0.0}, {source, 14U}}};
|
||||
definition.materials = {
|
||||
{"Material-0", 100.0, 0.20, {source, 20U}},
|
||||
{"Material-1", 200.0, 0.25, {source, 21U}},
|
||||
{"Material-2", 300.0, 0.30, {source, 22U}},
|
||||
{"Unused-Material", 400.0, 0.35, {source, 23U}}};
|
||||
definition.sections = {
|
||||
{"Section-0", 1.0, 1.0, 0.0, 1.0, 1.0,
|
||||
{0.0, 1.0, 0.0}, {}, {source, 30U}},
|
||||
{"Section-1", 2.0, 2.0, 0.0, 2.0, 2.0,
|
||||
{0.0, 1.0, 0.0}, {}, {source, 31U}},
|
||||
{"Section-2", 3.0, 3.0, 0.0, 3.0, 3.0,
|
||||
{0.0, 1.0, 0.0}, {}, {source, 32U}},
|
||||
{"Unused-Section", 4.0, 4.0, 0.0, 4.0, 4.0,
|
||||
{0.0, 1.0, 0.0}, {}, {source, 33U}}};
|
||||
definition.elements = {
|
||||
{{"Beam-1", 1, "1"}, {0U, 1U}, 2U, 2U, {source, 40U}},
|
||||
{{"Beam-1", 2, "2"}, {1U, 2U}, 0U, 1U, {source, 41U}},
|
||||
{{"Beam-1", 3, "3"}, {2U, 3U}, 2U, 2U, {source, 42U}},
|
||||
{{"Beam-1", 4, "4"}, {3U, 4U}, 1U, 0U, {source, 43U}}};
|
||||
definition.steps = {{
|
||||
"Step-1",
|
||||
{{"Root", 1, 3, 0.0, {source, 51U}},
|
||||
{"Root", 4, 6, 0.0, {source, 52U}}},
|
||||
{{"Tip", 1, 10.0, {source, 53U}},
|
||||
{"Tip", 2, -20.0, {source, 54U}},
|
||||
{"Tip", 6, 30.0, {source, 55U}}},
|
||||
0.1,
|
||||
1.0,
|
||||
0.01,
|
||||
1.0,
|
||||
{source, 50U}}};
|
||||
return definition;
|
||||
fesa::ModelDefinition MakeDefinition() {
|
||||
const std::filesystem::path source{"models/analysis-model.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"}, {1.0, 0.0, 0.0}, {source, 11U}},
|
||||
{{"Beam-1", 3, "3"}, {2.0, 0.0, 0.0}, {source, 12U}},
|
||||
{{"Beam-1", 4, "4"}, {3.0, 0.0, 0.0}, {source, 13U}},
|
||||
{{"Beam-1", 5, "5"}, {4.0, 0.0, 0.0}, {source, 14U}}};
|
||||
definition.materials = {{"Material-0", 100.0, 0.20, {source, 20U}},
|
||||
{"Material-1", 200.0, 0.25, {source, 21U}},
|
||||
{"Material-2", 300.0, 0.30, {source, 22U}},
|
||||
{"Unused-Material", 400.0, 0.35, {source, 23U}}};
|
||||
definition.sections = {{"Section-0",
|
||||
1.0,
|
||||
1.0,
|
||||
0.0,
|
||||
1.0,
|
||||
1.0,
|
||||
{0.0, 1.0, 0.0},
|
||||
{},
|
||||
{source, 30U}},
|
||||
{"Section-1",
|
||||
2.0,
|
||||
2.0,
|
||||
0.0,
|
||||
2.0,
|
||||
2.0,
|
||||
{0.0, 1.0, 0.0},
|
||||
{},
|
||||
{source, 31U}},
|
||||
{"Section-2",
|
||||
3.0,
|
||||
3.0,
|
||||
0.0,
|
||||
3.0,
|
||||
3.0,
|
||||
{0.0, 1.0, 0.0},
|
||||
{},
|
||||
{source, 32U}},
|
||||
{"Unused-Section",
|
||||
4.0,
|
||||
4.0,
|
||||
0.0,
|
||||
4.0,
|
||||
4.0,
|
||||
{0.0, 1.0, 0.0},
|
||||
{},
|
||||
{source, 33U}}};
|
||||
definition.elements = {{{"Beam-1", 1, "1"}, {0U, 1U}, 2U, 2U, {source, 40U}},
|
||||
{{"Beam-1", 2, "2"}, {1U, 2U}, 0U, 1U, {source, 41U}},
|
||||
{{"Beam-1", 3, "3"}, {2U, 3U}, 2U, 2U, {source, 42U}},
|
||||
{{"Beam-1", 4, "4"}, {3U, 4U}, 1U, 0U, {source, 43U}}};
|
||||
definition.steps = {
|
||||
{"Step-1",
|
||||
{{"Root", 1, 3, 0.0, {source, 51U}}, {"Root", 4, 6, 0.0, {source, 52U}}},
|
||||
{{"Tip", 1, 10.0, {source, 53U}},
|
||||
{"Tip", 2, -20.0, {source, 54U}},
|
||||
{"Tip", 6, 30.0, {source, 55U}}},
|
||||
0.1,
|
||||
1.0,
|
||||
0.01,
|
||||
1.0,
|
||||
{source, 50U}}};
|
||||
return definition;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
TEST(AnalysisModel, ClassifiesActiveEntitiesInStableOrder) {
|
||||
auto domainResult = fesa::Domain::Create(makeDefinition());
|
||||
ASSERT_TRUE(domainResult.HasValue());
|
||||
auto domain_result = fesa::Domain::Create(MakeDefinition());
|
||||
ASSERT_TRUE(domain_result.HasValue());
|
||||
|
||||
auto modelResult = fesa::AnalysisModel::create(domainResult.Value());
|
||||
ASSERT_TRUE(modelResult.HasValue());
|
||||
const auto& model = modelResult.Value();
|
||||
auto model_result = fesa::AnalysisModel::Create(domain_result.Value());
|
||||
ASSERT_TRUE(model_result.HasValue());
|
||||
const auto& model = model_result.Value();
|
||||
|
||||
EXPECT_EQ(
|
||||
model.activeElements(),
|
||||
(std::vector<fesa::EntityIndex>{0U, 1U, 2U, 3U}));
|
||||
EXPECT_EQ(
|
||||
model.activeMaterials(),
|
||||
(std::vector<fesa::EntityIndex>{0U, 1U, 2U}));
|
||||
EXPECT_EQ(
|
||||
model.activeSections(),
|
||||
(std::vector<fesa::EntityIndex>{0U, 1U, 2U}));
|
||||
EXPECT_EQ(
|
||||
model.activeBoundaryConditions(),
|
||||
(std::vector<fesa::EntityIndex>{0U, 1U}));
|
||||
EXPECT_EQ(
|
||||
model.activeLoads(),
|
||||
(std::vector<fesa::EntityIndex>{0U, 1U, 2U}));
|
||||
EXPECT_EQ(model.ActiveElements(),
|
||||
(std::vector<fesa::EntityIndex>{0U, 1U, 2U, 3U}));
|
||||
EXPECT_EQ(model.ActiveMaterials(),
|
||||
(std::vector<fesa::EntityIndex>{0U, 1U, 2U}));
|
||||
EXPECT_EQ(model.ActiveSections(),
|
||||
(std::vector<fesa::EntityIndex>{0U, 1U, 2U}));
|
||||
EXPECT_EQ(model.ActiveBoundaryConditions(),
|
||||
(std::vector<fesa::EntityIndex>{0U, 1U}));
|
||||
EXPECT_EQ(model.ActiveLoads(), (std::vector<fesa::EntityIndex>{0U, 1U, 2U}));
|
||||
}
|
||||
|
||||
TEST(AnalysisModel, ReferencesWithoutCopyingOrMutatingDomain) {
|
||||
auto domainResult = fesa::Domain::Create(makeDefinition());
|
||||
ASSERT_TRUE(domainResult.HasValue());
|
||||
const fesa::Domain& domain = domainResult.Value();
|
||||
const auto* const elementAddress = domain.Elements().data();
|
||||
const auto* const materialAddress = domain.Materials().data();
|
||||
const auto* const sectionAddress = domain.Sections().data();
|
||||
const std::string stepName = domain.Steps()[0].name;
|
||||
const double firstLoadMagnitude = domain.Steps()[0].loads[0].magnitude;
|
||||
auto domain_result = fesa::Domain::Create(MakeDefinition());
|
||||
ASSERT_TRUE(domain_result.HasValue());
|
||||
const fesa::Domain& domain = domain_result.Value();
|
||||
const auto* const element_address = domain.Elements().data();
|
||||
const auto* const material_address = domain.Materials().data();
|
||||
const auto* const section_address = domain.Sections().data();
|
||||
const std::string step_name = domain.Steps()[0].name;
|
||||
const double first_load_magnitude = domain.Steps()[0].loads[0].magnitude;
|
||||
|
||||
auto modelResult = fesa::AnalysisModel::create(domain);
|
||||
ASSERT_TRUE(modelResult.HasValue());
|
||||
const auto& model = modelResult.Value();
|
||||
auto model_result = fesa::AnalysisModel::Create(domain);
|
||||
ASSERT_TRUE(model_result.HasValue());
|
||||
const auto& model = model_result.Value();
|
||||
|
||||
EXPECT_EQ(&model.domain(), &domain);
|
||||
EXPECT_EQ(&model.step(), &domain.Steps()[0]);
|
||||
EXPECT_EQ(model.domain().Elements().data(), elementAddress);
|
||||
EXPECT_EQ(model.domain().Materials().data(), materialAddress);
|
||||
EXPECT_EQ(model.domain().Sections().data(), sectionAddress);
|
||||
EXPECT_EQ(
|
||||
&model.domain().Elements()[model.activeElements()[1]],
|
||||
&domain.Elements()[1]);
|
||||
EXPECT_EQ(
|
||||
&model.domain().Materials()[model.activeMaterials()[2]],
|
||||
&domain.Materials()[2]);
|
||||
EXPECT_EQ(
|
||||
&model.domain().Sections()[model.activeSections()[1]],
|
||||
&domain.Sections()[1]);
|
||||
EXPECT_EQ(domain.Steps()[0].name, stepName);
|
||||
EXPECT_DOUBLE_EQ(domain.Steps()[0].loads[0].magnitude, firstLoadMagnitude);
|
||||
EXPECT_EQ(&model.GetDomain(), &domain);
|
||||
EXPECT_EQ(&model.Step(), &domain.Steps()[0]);
|
||||
EXPECT_EQ(model.GetDomain().Elements().data(), element_address);
|
||||
EXPECT_EQ(model.GetDomain().Materials().data(), material_address);
|
||||
EXPECT_EQ(model.GetDomain().Sections().data(), section_address);
|
||||
EXPECT_EQ(&model.GetDomain().Elements()[model.ActiveElements()[1]],
|
||||
&domain.Elements()[1]);
|
||||
EXPECT_EQ(&model.GetDomain().Materials()[model.ActiveMaterials()[2]],
|
||||
&domain.Materials()[2]);
|
||||
EXPECT_EQ(&model.GetDomain().Sections()[model.ActiveSections()[1]],
|
||||
&domain.Sections()[1]);
|
||||
EXPECT_EQ(domain.Steps()[0].name, step_name);
|
||||
EXPECT_DOUBLE_EQ(domain.Steps()[0].loads[0].magnitude, first_load_magnitude);
|
||||
}
|
||||
|
||||
TEST(AnalysisModel, RejectsMissingOrMultipleStep) {
|
||||
auto missingDefinition = makeDefinition();
|
||||
missingDefinition.steps.clear();
|
||||
auto missingDomain = fesa::Domain::Create(std::move(missingDefinition));
|
||||
ASSERT_TRUE(missingDomain.HasValue());
|
||||
auto missing_definition = MakeDefinition();
|
||||
missing_definition.steps.clear();
|
||||
auto missing_domain = fesa::Domain::Create(std::move(missing_definition));
|
||||
ASSERT_TRUE(missing_domain.HasValue());
|
||||
|
||||
auto missing = fesa::AnalysisModel::create(missingDomain.Value());
|
||||
ASSERT_FALSE(missing.HasValue());
|
||||
EXPECT_EQ(
|
||||
missing.GetStatus().Category(),
|
||||
fesa::FailureCategory::kInput);
|
||||
ASSERT_EQ(missing.GetStatus().Diagnostics().size(), 1U);
|
||||
EXPECT_EQ(
|
||||
missing.GetStatus().Diagnostics()[0].code,
|
||||
"invalid-model-cardinality");
|
||||
EXPECT_EQ(missing.GetStatus().Diagnostics()[0].keyword, "STEP");
|
||||
EXPECT_EQ(missing.GetStatus().Diagnostics()[0].entity_identity, "0");
|
||||
auto missing = fesa::AnalysisModel::Create(missing_domain.Value());
|
||||
ASSERT_FALSE(missing.HasValue());
|
||||
EXPECT_EQ(missing.GetStatus().Category(), fesa::FailureCategory::kInput);
|
||||
ASSERT_EQ(missing.GetStatus().Diagnostics().size(), 1U);
|
||||
EXPECT_EQ(missing.GetStatus().Diagnostics()[0].code,
|
||||
"invalid-model-cardinality");
|
||||
EXPECT_EQ(missing.GetStatus().Diagnostics()[0].keyword, "STEP");
|
||||
EXPECT_EQ(missing.GetStatus().Diagnostics()[0].entity_identity, "0");
|
||||
|
||||
auto multipleDefinition = makeDefinition();
|
||||
auto secondStep = multipleDefinition.steps.front();
|
||||
secondStep.name = "Step-2";
|
||||
secondStep.location.line = 60U;
|
||||
multipleDefinition.steps.push_back(std::move(secondStep));
|
||||
auto multipleDomain = fesa::Domain::Create(std::move(multipleDefinition));
|
||||
ASSERT_TRUE(multipleDomain.HasValue());
|
||||
auto multiple_definition = MakeDefinition();
|
||||
auto second_step = multiple_definition.steps.front();
|
||||
second_step.name = "Step-2";
|
||||
second_step.location.line = 60U;
|
||||
multiple_definition.steps.push_back(std::move(second_step));
|
||||
auto multiple_domain = fesa::Domain::Create(std::move(multiple_definition));
|
||||
ASSERT_TRUE(multiple_domain.HasValue());
|
||||
|
||||
auto multiple = fesa::AnalysisModel::create(multipleDomain.Value());
|
||||
ASSERT_FALSE(multiple.HasValue());
|
||||
EXPECT_EQ(
|
||||
multiple.GetStatus().Category(),
|
||||
fesa::FailureCategory::kInput);
|
||||
ASSERT_EQ(multiple.GetStatus().Diagnostics().size(), 1U);
|
||||
EXPECT_EQ(
|
||||
multiple.GetStatus().Diagnostics()[0].code,
|
||||
"unsupported-multiple-step");
|
||||
EXPECT_EQ(multiple.GetStatus().Diagnostics()[0].keyword, "STEP");
|
||||
EXPECT_EQ(multiple.GetStatus().Diagnostics()[0].entity_identity, "Step-2");
|
||||
EXPECT_EQ(multiple.GetStatus().Diagnostics()[0].location.line, 60U);
|
||||
auto multiple = fesa::AnalysisModel::Create(multiple_domain.Value());
|
||||
ASSERT_FALSE(multiple.HasValue());
|
||||
EXPECT_EQ(multiple.GetStatus().Category(), fesa::FailureCategory::kInput);
|
||||
ASSERT_EQ(multiple.GetStatus().Diagnostics().size(), 1U);
|
||||
EXPECT_EQ(multiple.GetStatus().Diagnostics()[0].code,
|
||||
"unsupported-multiple-step");
|
||||
EXPECT_EQ(multiple.GetStatus().Diagnostics()[0].keyword, "STEP");
|
||||
EXPECT_EQ(multiple.GetStatus().Diagnostics()[0].entity_identity, "Step-2");
|
||||
EXPECT_EQ(multiple.GetStatus().Diagnostics()[0].location.line, 60U);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "fesa/analysis/analysis_state.hpp"
|
||||
#include "fesa/analysis/analysis_state.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
@@ -9,165 +9,162 @@
|
||||
|
||||
namespace {
|
||||
|
||||
template<class T, class = void>
|
||||
template <class T, class = void>
|
||||
struct HasVelocity : std::false_type {};
|
||||
|
||||
template<class T>
|
||||
struct HasVelocity<T, std::void_t<decltype(std::declval<T&>().velocity())>>
|
||||
template <class T>
|
||||
struct HasVelocity<T, std::void_t<decltype(std::declval<T&>().Velocity())>>
|
||||
: std::true_type {};
|
||||
|
||||
template<class T, class = void>
|
||||
template <class T, class = void>
|
||||
struct HasAcceleration : std::false_type {};
|
||||
|
||||
template<class T>
|
||||
struct HasAcceleration<
|
||||
T, std::void_t<decltype(std::declval<T&>().acceleration())>>
|
||||
template <class T>
|
||||
struct HasAcceleration<T,
|
||||
std::void_t<decltype(std::declval<T&>().Acceleration())>>
|
||||
: std::true_type {};
|
||||
|
||||
template<class T, class = void>
|
||||
template <class T, class = void>
|
||||
struct HasTemperature : std::false_type {};
|
||||
|
||||
template<class T>
|
||||
struct HasTemperature<T, std::void_t<decltype(std::declval<T&>().temperature())>>
|
||||
template <class T>
|
||||
struct HasTemperature<T,
|
||||
std::void_t<decltype(std::declval<T&>().Temperature())>>
|
||||
: std::true_type {};
|
||||
|
||||
template<class T, class = void>
|
||||
template <class T, class = void>
|
||||
struct HasIterationHistory : std::false_type {};
|
||||
|
||||
template<class T>
|
||||
template <class T>
|
||||
struct HasIterationHistory<
|
||||
T, std::void_t<decltype(std::declval<T&>().iterationHistory())>>
|
||||
T, std::void_t<decltype(std::declval<T&>().IterationHistory())>>
|
||||
: std::true_type {};
|
||||
|
||||
template<class T, class = void>
|
||||
template <class T, class = void>
|
||||
struct HasNonlinearState : std::false_type {};
|
||||
|
||||
template<class T>
|
||||
template <class T>
|
||||
struct HasNonlinearState<
|
||||
T, std::void_t<decltype(std::declval<T&>().nonlinearState())>>
|
||||
T, std::void_t<decltype(std::declval<T&>().NonlinearState())>>
|
||||
: std::true_type {};
|
||||
|
||||
fesa::DofManager makeDofs() {
|
||||
fesa::ModelDefinition definition{};
|
||||
definition.source_path = "models/analysis-state.inp";
|
||||
definition.source_content_identity = "fnv1a64:0123456789abcdef";
|
||||
definition.nodes = {
|
||||
{{"Beam-1", 1, "1"}, {0.0, 0.0, 0.0}, {definition.source_path, 10U}},
|
||||
{{"Beam-1", 2, "2"}, {1.0, 0.0, 0.0}, {definition.source_path, 11U}}};
|
||||
definition.steps = {{
|
||||
"Step-1",
|
||||
{{"1", 1, 6, 0.0, {definition.source_path, 20U}}},
|
||||
{},
|
||||
0.1,
|
||||
1.0,
|
||||
0.01,
|
||||
1.0,
|
||||
{definition.source_path, 19U}}};
|
||||
fesa::DofManager MakeDofs() {
|
||||
fesa::ModelDefinition definition{};
|
||||
definition.source_path = "models/analysis-state.inp";
|
||||
definition.source_content_identity = "fnv1a64:0123456789abcdef";
|
||||
definition.nodes = {
|
||||
{{"Beam-1", 1, "1"}, {0.0, 0.0, 0.0}, {definition.source_path, 10U}},
|
||||
{{"Beam-1", 2, "2"}, {1.0, 0.0, 0.0}, {definition.source_path, 11U}}};
|
||||
definition.steps = {{"Step-1",
|
||||
{{"1", 1, 6, 0.0, {definition.source_path, 20U}}},
|
||||
{},
|
||||
0.1,
|
||||
1.0,
|
||||
0.01,
|
||||
1.0,
|
||||
{definition.source_path, 19U}}};
|
||||
|
||||
auto domain = fesa::Domain::Create(std::move(definition));
|
||||
EXPECT_TRUE(domain.HasValue());
|
||||
auto model = fesa::AnalysisModel::create(domain.Value());
|
||||
EXPECT_TRUE(model.HasValue());
|
||||
auto dofs = fesa::DofManager::create(model.Value());
|
||||
EXPECT_TRUE(dofs.HasValue());
|
||||
return std::move(dofs.Value());
|
||||
auto domain = fesa::Domain::Create(std::move(definition));
|
||||
EXPECT_TRUE(domain.HasValue());
|
||||
auto model = fesa::AnalysisModel::Create(domain.Value());
|
||||
EXPECT_TRUE(model.HasValue());
|
||||
auto dofs = fesa::DofManager::Create(model.Value());
|
||||
EXPECT_TRUE(dofs.HasValue());
|
||||
return std::move(dofs.Value());
|
||||
}
|
||||
|
||||
void expectAllZero(const fesa::Vector& vector) {
|
||||
for (std::size_t index = 0U; index < vector.Size(); ++index) {
|
||||
EXPECT_DOUBLE_EQ(vector[index], 0.0);
|
||||
}
|
||||
void ExpectAllZero(const fesa::Vector& vector) {
|
||||
for (std::size_t index = 0U; index < vector.Size(); ++index) {
|
||||
EXPECT_DOUBLE_EQ(vector[index], 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
TEST(AnalysisState, AllocatesOnlyV0FullVectors) {
|
||||
const auto dofs = makeDofs();
|
||||
ASSERT_EQ(dofs.fullDofCount(), 12U);
|
||||
ASSERT_EQ(dofs.constrainedDofCount(), 6U);
|
||||
const auto dofs = MakeDofs();
|
||||
ASSERT_EQ(dofs.FullDofCount(), 12U);
|
||||
ASSERT_EQ(dofs.ConstrainedDofCount(), 6U);
|
||||
|
||||
auto state = fesa::AnalysisState::create(dofs, {"Step-1", 0U});
|
||||
const fesa::AnalysisState& constState = state;
|
||||
const fesa::Vector* const vectors[] = {
|
||||
&constState.displacement(),
|
||||
&constState.externalForce(),
|
||||
&constState.internalForce(),
|
||||
&constState.residual(),
|
||||
&constState.reaction()};
|
||||
auto state = fesa::AnalysisState::Create(dofs, {"Step-1", 0U});
|
||||
const fesa::AnalysisState& const_state = state;
|
||||
const fesa::Vector* const vectors[] = {
|
||||
&const_state.Displacement(), &const_state.ExternalForce(),
|
||||
&const_state.InternalForce(), &const_state.Residual(),
|
||||
&const_state.Reaction()};
|
||||
|
||||
for (const auto* vector : vectors) {
|
||||
EXPECT_EQ(vector->Size(), dofs.fullDofCount());
|
||||
expectAllZero(*vector);
|
||||
}
|
||||
for (std::size_t left = 0U; left < std::size(vectors); ++left) {
|
||||
for (std::size_t right = left + 1U; right < std::size(vectors); ++right) {
|
||||
EXPECT_NE(vectors[left]->Data(), vectors[right]->Data());
|
||||
}
|
||||
for (const auto* vector : vectors) {
|
||||
EXPECT_EQ(vector->Size(), dofs.FullDofCount());
|
||||
ExpectAllZero(*vector);
|
||||
}
|
||||
for (std::size_t left = 0U; left < std::size(vectors); ++left) {
|
||||
for (std::size_t right = left + 1U; right < std::size(vectors); ++right) {
|
||||
EXPECT_NE(vectors[left]->Data(), vectors[right]->Data());
|
||||
}
|
||||
}
|
||||
|
||||
state.displacement()[0] = 4.0;
|
||||
state.reaction()[11] = -9.0;
|
||||
EXPECT_DOUBLE_EQ(state.displacement()[0], 4.0);
|
||||
EXPECT_DOUBLE_EQ(state.reaction()[11], -9.0);
|
||||
EXPECT_DOUBLE_EQ(state.externalForce()[0], 0.0);
|
||||
EXPECT_DOUBLE_EQ(state.internalForce()[0], 0.0);
|
||||
EXPECT_DOUBLE_EQ(state.residual()[0], 0.0);
|
||||
state.Displacement()[0] = 4.0;
|
||||
state.Reaction()[11] = -9.0;
|
||||
EXPECT_DOUBLE_EQ(state.Displacement()[0], 4.0);
|
||||
EXPECT_DOUBLE_EQ(state.Reaction()[11], -9.0);
|
||||
EXPECT_DOUBLE_EQ(state.ExternalForce()[0], 0.0);
|
||||
EXPECT_DOUBLE_EQ(state.InternalForce()[0], 0.0);
|
||||
EXPECT_DOUBLE_EQ(state.Residual()[0], 0.0);
|
||||
|
||||
EXPECT_FALSE(HasVelocity<fesa::AnalysisState>::value);
|
||||
EXPECT_FALSE(HasAcceleration<fesa::AnalysisState>::value);
|
||||
EXPECT_FALSE(HasTemperature<fesa::AnalysisState>::value);
|
||||
EXPECT_FALSE(HasIterationHistory<fesa::AnalysisState>::value);
|
||||
EXPECT_FALSE(HasNonlinearState<fesa::AnalysisState>::value);
|
||||
EXPECT_FALSE(HasVelocity<fesa::AnalysisState>::value);
|
||||
EXPECT_FALSE(HasAcceleration<fesa::AnalysisState>::value);
|
||||
EXPECT_FALSE(HasTemperature<fesa::AnalysisState>::value);
|
||||
EXPECT_FALSE(HasIterationHistory<fesa::AnalysisState>::value);
|
||||
EXPECT_FALSE(HasNonlinearState<fesa::AnalysisState>::value);
|
||||
}
|
||||
|
||||
TEST(AnalysisState, CopiesOrMovesWithoutAliasing) {
|
||||
static_assert(std::is_copy_constructible_v<fesa::AnalysisState>);
|
||||
static_assert(std::is_copy_assignable_v<fesa::AnalysisState>);
|
||||
static_assert(std::is_move_constructible_v<fesa::AnalysisState>);
|
||||
static_assert(std::is_move_assignable_v<fesa::AnalysisState>);
|
||||
static_assert(std::is_copy_constructible_v<fesa::AnalysisState>);
|
||||
static_assert(std::is_copy_assignable_v<fesa::AnalysisState>);
|
||||
static_assert(std::is_move_constructible_v<fesa::AnalysisState>);
|
||||
static_assert(std::is_move_assignable_v<fesa::AnalysisState>);
|
||||
|
||||
const auto dofs = makeDofs();
|
||||
auto original = fesa::AnalysisState::create(dofs, {"Step-1", 0U});
|
||||
original.displacement()[0] = 3.0;
|
||||
original.reaction()[11] = -2.0;
|
||||
original.endpointResults().push_back({
|
||||
0U,
|
||||
-1,
|
||||
{"Beam-1", 1, "1"},
|
||||
{1.0, 0.0, 0.0, 0.0, 0.0, 0.0},
|
||||
{2.0, 0.0, 0.0, 0.0}});
|
||||
original.gaussResults().push_back(
|
||||
{0U, 1, {0.1, 0.0, 0.0, 0.0}, {10.0, 0.0, 0.0, 0.0}});
|
||||
original.stressResults().push_back(
|
||||
{0U, 1, 0U, 0.0, 0.0, 10.0, "fesa-default"});
|
||||
const auto dofs = MakeDofs();
|
||||
auto original = fesa::AnalysisState::Create(dofs, {"Step-1", 0U});
|
||||
original.Displacement()[0] = 3.0;
|
||||
original.Reaction()[11] = -2.0;
|
||||
original.EndpointResults().push_back({0U,
|
||||
-1,
|
||||
{"Beam-1", 1, "1"},
|
||||
{1.0, 0.0, 0.0, 0.0, 0.0, 0.0},
|
||||
{2.0, 0.0, 0.0, 0.0}});
|
||||
original.GaussResults().push_back(
|
||||
{0U, 1, {0.1, 0.0, 0.0, 0.0}, {10.0, 0.0, 0.0, 0.0}});
|
||||
original.StressResults().push_back(
|
||||
{0U, 1, 0U, 0.0, 0.0, 10.0, "fesa-default"});
|
||||
|
||||
auto copied = original;
|
||||
EXPECT_NE(copied.displacement().Data(), original.displacement().Data());
|
||||
EXPECT_NE(copied.reaction().Data(), original.reaction().Data());
|
||||
EXPECT_NE(copied.endpointResults().data(), original.endpointResults().data());
|
||||
EXPECT_NE(copied.gaussResults().data(), original.gaussResults().data());
|
||||
EXPECT_NE(copied.stressResults().data(), original.stressResults().data());
|
||||
copied.displacement()[0] = 30.0;
|
||||
copied.endpointResults()[0].endAction[0] = 20.0;
|
||||
EXPECT_DOUBLE_EQ(original.displacement()[0], 3.0);
|
||||
EXPECT_DOUBLE_EQ(original.endpointResults()[0].endAction[0], 1.0);
|
||||
auto copied = original;
|
||||
EXPECT_NE(copied.Displacement().Data(), original.Displacement().Data());
|
||||
EXPECT_NE(copied.Reaction().Data(), original.Reaction().Data());
|
||||
EXPECT_NE(copied.EndpointResults().data(), original.EndpointResults().data());
|
||||
EXPECT_NE(copied.GaussResults().data(), original.GaussResults().data());
|
||||
EXPECT_NE(copied.StressResults().data(), original.StressResults().data());
|
||||
copied.Displacement()[0] = 30.0;
|
||||
copied.EndpointResults()[0].end_action[0] = 20.0;
|
||||
EXPECT_DOUBLE_EQ(original.Displacement()[0], 3.0);
|
||||
EXPECT_DOUBLE_EQ(original.EndpointResults()[0].end_action[0], 1.0);
|
||||
|
||||
auto moved = std::move(copied);
|
||||
EXPECT_EQ(moved.identity().stepName, "Step-1");
|
||||
EXPECT_DOUBLE_EQ(moved.displacement()[0], 30.0);
|
||||
EXPECT_DOUBLE_EQ(moved.endpointResults()[0].endAction[0], 20.0);
|
||||
EXPECT_NE(moved.displacement().Data(), original.displacement().Data());
|
||||
EXPECT_NE(moved.endpointResults().data(), original.endpointResults().data());
|
||||
auto moved = std::move(copied);
|
||||
EXPECT_EQ(moved.Identity().step_name, "Step-1");
|
||||
EXPECT_DOUBLE_EQ(moved.Displacement()[0], 30.0);
|
||||
EXPECT_DOUBLE_EQ(moved.EndpointResults()[0].end_action[0], 20.0);
|
||||
EXPECT_NE(moved.Displacement().Data(), original.Displacement().Data());
|
||||
EXPECT_NE(moved.EndpointResults().data(), original.EndpointResults().data());
|
||||
|
||||
auto copyAssigned = fesa::AnalysisState::create(dofs, {"Other", 3U});
|
||||
copyAssigned = original;
|
||||
copyAssigned.reaction()[11] = -20.0;
|
||||
EXPECT_DOUBLE_EQ(original.reaction()[11], -2.0);
|
||||
EXPECT_EQ(copyAssigned.identity().stepName, "Step-1");
|
||||
auto copy_assigned = fesa::AnalysisState::Create(dofs, {"Other", 3U});
|
||||
copy_assigned = original;
|
||||
copy_assigned.Reaction()[11] = -20.0;
|
||||
EXPECT_DOUBLE_EQ(original.Reaction()[11], -2.0);
|
||||
EXPECT_EQ(copy_assigned.Identity().step_name, "Step-1");
|
||||
|
||||
auto moveAssigned = fesa::AnalysisState::create(dofs, {"Other", 4U});
|
||||
moveAssigned = std::move(copyAssigned);
|
||||
EXPECT_EQ(moveAssigned.identity().stepName, "Step-1");
|
||||
EXPECT_DOUBLE_EQ(moveAssigned.reaction()[11], -20.0);
|
||||
EXPECT_NE(moveAssigned.reaction().Data(), original.reaction().Data());
|
||||
auto move_assigned = fesa::AnalysisState::Create(dofs, {"Other", 4U});
|
||||
move_assigned = std::move(copy_assigned);
|
||||
EXPECT_EQ(move_assigned.Identity().step_name, "Step-1");
|
||||
EXPECT_DOUBLE_EQ(move_assigned.Reaction()[11], -20.0);
|
||||
EXPECT_NE(move_assigned.Reaction().Data(), original.Reaction().Data());
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
#include "fesa/constraints/essential_constraints.hpp"
|
||||
|
||||
#include "fesa/analysis/analysis_model.hpp"
|
||||
#include "fesa/fem/dof_manager.hpp"
|
||||
#include "fesa/model/domain.h"
|
||||
#include "fesa/constraints/essential_constraints.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
@@ -13,339 +9,307 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "fesa/analysis/analysis_model.h"
|
||||
#include "fesa/fem/dof_manager.h"
|
||||
#include "fesa/model/domain.h"
|
||||
|
||||
namespace {
|
||||
|
||||
fesa::DofManager makeDofs(
|
||||
fesa::DofManager MakeDofs(std::vector<fesa::BoundaryCondition> boundaries) {
|
||||
const std::filesystem::path source{"models/essential-constraints.inp"};
|
||||
fesa::ModelDefinition definition{};
|
||||
definition.source_path = source;
|
||||
definition.source_content_identity = "fnv1a64:1234567890abcdef";
|
||||
definition.nodes = {{{"Beam-1", 1, "1"}, {0.0, 0.0, 0.0}, {source, 2U}}};
|
||||
definition.steps = {{"Step-1",
|
||||
std::move(boundaries),
|
||||
{},
|
||||
0.1,
|
||||
1.0,
|
||||
0.01,
|
||||
1.0,
|
||||
{source, 10U}}};
|
||||
|
||||
auto domain = fesa::Domain::Create(std::move(definition));
|
||||
EXPECT_TRUE(domain.HasValue());
|
||||
auto model = fesa::AnalysisModel::Create(domain.Value());
|
||||
EXPECT_TRUE(model.HasValue());
|
||||
auto dofs = fesa::DofManager::Create(model.Value());
|
||||
EXPECT_TRUE(dofs.HasValue());
|
||||
return std::move(dofs.Value());
|
||||
}
|
||||
|
||||
fesa::DofManager MakeShellSizedDofs(
|
||||
std::vector<fesa::BoundaryCondition> boundaries) {
|
||||
const std::filesystem::path source{"models/essential-constraints.inp"};
|
||||
fesa::ModelDefinition definition{};
|
||||
definition.source_path = source;
|
||||
definition.source_content_identity = "fnv1a64:1234567890abcdef";
|
||||
definition.nodes = {
|
||||
{{"Beam-1", 1, "1"}, {0.0, 0.0, 0.0}, {source, 2U}}};
|
||||
definition.steps = {{
|
||||
"Step-1",
|
||||
std::move(boundaries),
|
||||
{},
|
||||
0.1,
|
||||
1.0,
|
||||
0.01,
|
||||
1.0,
|
||||
{source, 10U}}};
|
||||
const std::filesystem::path source{"models/shell-essential-constraints.inp"};
|
||||
fesa::ModelDefinition definition{};
|
||||
definition.source_path = source;
|
||||
definition.source_content_identity = "fnv1a64:8877665544332211";
|
||||
definition.nodes = {{{"Shell-1", 1, "1"}, {0.0, 0.0, 0.0}, {source, 2U}},
|
||||
{{"Shell-1", 2, "2"}, {1.0, 0.0, 0.0}, {source, 3U}},
|
||||
{{"Shell-1", 3, "3"}, {1.0, 1.0, 0.0}, {source, 4U}},
|
||||
{{"Shell-1", 4, "4"}, {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}}};
|
||||
definition.steps = {{"Step-1",
|
||||
std::move(boundaries),
|
||||
{},
|
||||
0.1,
|
||||
1.0,
|
||||
0.01,
|
||||
1.0,
|
||||
{source, 10U}}};
|
||||
|
||||
auto domain = fesa::Domain::Create(std::move(definition));
|
||||
EXPECT_TRUE(domain.HasValue());
|
||||
auto model = fesa::AnalysisModel::create(domain.Value());
|
||||
EXPECT_TRUE(model.HasValue());
|
||||
auto dofs = fesa::DofManager::create(model.Value());
|
||||
EXPECT_TRUE(dofs.HasValue());
|
||||
return std::move(dofs.Value());
|
||||
auto domain = fesa::Domain::Create(std::move(definition));
|
||||
EXPECT_TRUE(domain.HasValue());
|
||||
auto model = fesa::AnalysisModel::Create(domain.Value());
|
||||
EXPECT_TRUE(model.HasValue());
|
||||
auto dofs = fesa::DofManager::Create(model.Value());
|
||||
EXPECT_TRUE(dofs.HasValue());
|
||||
return std::move(dofs.Value());
|
||||
}
|
||||
|
||||
fesa::DofManager makeShellSizedDofs(
|
||||
std::vector<fesa::BoundaryCondition> boundaries) {
|
||||
const std::filesystem::path source{"models/shell-essential-constraints.inp"};
|
||||
fesa::ModelDefinition definition{};
|
||||
definition.source_path = source;
|
||||
definition.source_content_identity = "fnv1a64:8877665544332211";
|
||||
definition.nodes = {
|
||||
{{"Shell-1", 1, "1"}, {0.0, 0.0, 0.0}, {source, 2U}},
|
||||
{{"Shell-1", 2, "2"}, {1.0, 0.0, 0.0}, {source, 3U}},
|
||||
{{"Shell-1", 3, "3"}, {1.0, 1.0, 0.0}, {source, 4U}},
|
||||
{{"Shell-1", 4, "4"}, {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}}};
|
||||
definition.steps = {{
|
||||
"Step-1",
|
||||
std::move(boundaries),
|
||||
{},
|
||||
0.1,
|
||||
1.0,
|
||||
0.01,
|
||||
1.0,
|
||||
{source, 10U}}};
|
||||
|
||||
auto domain = fesa::Domain::Create(std::move(definition));
|
||||
EXPECT_TRUE(domain.HasValue());
|
||||
auto model = fesa::AnalysisModel::create(domain.Value());
|
||||
EXPECT_TRUE(model.HasValue());
|
||||
auto dofs = fesa::DofManager::create(model.Value());
|
||||
EXPECT_TRUE(dofs.HasValue());
|
||||
return std::move(dofs.Value());
|
||||
}
|
||||
|
||||
fesa::SparseMatrix makeMatrix(
|
||||
const std::size_t rows,
|
||||
const std::size_t columns,
|
||||
const std::vector<double>& denseValues) {
|
||||
EXPECT_EQ(denseValues.size(), rows * columns);
|
||||
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,
|
||||
denseValues[row * columns + column],
|
||||
row,
|
||||
column});
|
||||
}
|
||||
pattern.rowOffsets.push_back(pattern.columnIndices.size());
|
||||
fesa::SparseMatrix MakeMatrix(const std::size_t rows, const std::size_t columns,
|
||||
const std::vector<double>& dense_values) {
|
||||
EXPECT_EQ(dense_values.size(), rows * columns);
|
||||
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, dense_values[row * columns + column], row, column});
|
||||
}
|
||||
pattern.row_offsets.push_back(pattern.column_indices.size());
|
||||
}
|
||||
|
||||
auto matrix = fesa::SparseMatrix::FromCoo(
|
||||
rows, columns, std::move(contributions), pattern);
|
||||
EXPECT_TRUE(matrix.HasValue());
|
||||
return std::move(matrix.Value());
|
||||
auto matrix = fesa::SparseMatrix::FromCoo(rows, columns,
|
||||
std::move(contributions), pattern);
|
||||
EXPECT_TRUE(matrix.HasValue());
|
||||
return std::move(matrix.Value());
|
||||
}
|
||||
|
||||
std::vector<double> sequentialDense(const std::size_t size) {
|
||||
std::vector<double> values(size * size);
|
||||
for (std::size_t row = 0U; row < size; ++row) {
|
||||
for (std::size_t column = 0U; column < size; ++column) {
|
||||
values[row * size + column] =
|
||||
static_cast<double>(row * 10U + column + 1U);
|
||||
}
|
||||
std::vector<double> SequentialDense(const std::size_t size) {
|
||||
std::vector<double> values(size * size);
|
||||
for (std::size_t row = 0U; row < size; ++row) {
|
||||
for (std::size_t column = 0U; column < size; ++column) {
|
||||
values[row * size + column] =
|
||||
static_cast<double>(row * 10U + column + 1U);
|
||||
}
|
||||
return values;
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
void expectShape(
|
||||
const fesa::SparseMatrix& matrix,
|
||||
const std::size_t rows,
|
||||
const std::size_t columns) {
|
||||
EXPECT_EQ(matrix.Rows(), rows);
|
||||
EXPECT_EQ(matrix.Columns(), columns);
|
||||
EXPECT_TRUE(matrix.Validate().IsOk());
|
||||
void ExpectShape(const fesa::SparseMatrix& matrix, const std::size_t rows,
|
||||
const std::size_t columns) {
|
||||
EXPECT_EQ(matrix.Rows(), rows);
|
||||
EXPECT_EQ(matrix.Columns(), columns);
|
||||
EXPECT_TRUE(matrix.Validate().IsOk());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
TEST(EssentialConstraints, ExtractsHandComputedBlocksInStableOrder) {
|
||||
const auto dofs = makeDofs({
|
||||
{"1", 2, 2, 2.5, {{}, 12U}},
|
||||
{"1", 5, 5, -3.25, {{}, 13U}}});
|
||||
auto fullValues = sequentialDense(6U);
|
||||
fullValues[2U * 6U + 4U] = 0.0;
|
||||
const auto full = makeMatrix(6U, 6U, fullValues);
|
||||
const auto dofs =
|
||||
MakeDofs({{"1", 2, 2, 2.5, {{}, 12U}}, {"1", 5, 5, -3.25, {{}, 13U}}});
|
||||
auto full_values = SequentialDense(6U);
|
||||
full_values[2U * 6U + 4U] = 0.0;
|
||||
const auto full = MakeMatrix(6U, 6U, full_values);
|
||||
|
||||
auto result = fesa::EssentialConstraints::partition(full, dofs);
|
||||
ASSERT_TRUE(result.HasValue());
|
||||
const auto& blocks = result.Value();
|
||||
auto result = fesa::EssentialConstraints::Partition(full, dofs);
|
||||
ASSERT_TRUE(result.HasValue());
|
||||
const auto& blocks = result.Value();
|
||||
|
||||
EXPECT_EQ(blocks.kff.RowOffsets(), (std::vector<std::size_t>{0U, 4U, 8U, 12U, 16U}));
|
||||
EXPECT_EQ(
|
||||
blocks.kff.ColumnIndices(),
|
||||
(std::vector<std::size_t>{
|
||||
0U, 1U, 2U, 3U, 0U, 1U, 2U, 3U,
|
||||
0U, 1U, 2U, 3U, 0U, 1U, 2U, 3U}));
|
||||
EXPECT_EQ(
|
||||
blocks.kff.Values(),
|
||||
(std::vector<double>{
|
||||
1.0, 3.0, 4.0, 6.0,
|
||||
21.0, 23.0, 24.0, 26.0,
|
||||
31.0, 33.0, 34.0, 36.0,
|
||||
51.0, 53.0, 54.0, 56.0}));
|
||||
EXPECT_EQ(blocks.kfc.RowOffsets(), (std::vector<std::size_t>{0U, 2U, 4U, 6U, 8U}));
|
||||
EXPECT_EQ(
|
||||
blocks.kfc.ColumnIndices(),
|
||||
(std::vector<std::size_t>{0U, 1U, 0U, 1U, 0U, 1U, 0U, 1U}));
|
||||
EXPECT_EQ(
|
||||
blocks.kfc.Values(),
|
||||
(std::vector<double>{2.0, 5.0, 22.0, 0.0, 32.0, 35.0, 52.0, 55.0}));
|
||||
EXPECT_EQ(blocks.kcf.RowOffsets(), (std::vector<std::size_t>{0U, 4U, 8U}));
|
||||
EXPECT_EQ(
|
||||
blocks.kcf.ColumnIndices(),
|
||||
(std::vector<std::size_t>{0U, 1U, 2U, 3U, 0U, 1U, 2U, 3U}));
|
||||
EXPECT_EQ(
|
||||
blocks.kcf.Values(),
|
||||
(std::vector<double>{11.0, 13.0, 14.0, 16.0, 41.0, 43.0, 44.0, 46.0}));
|
||||
EXPECT_EQ(blocks.kcc.RowOffsets(), (std::vector<std::size_t>{0U, 2U, 4U}));
|
||||
EXPECT_EQ(blocks.kcc.ColumnIndices(), (std::vector<std::size_t>{0U, 1U, 0U, 1U}));
|
||||
EXPECT_EQ(blocks.kcc.Values(), (std::vector<double>{12.0, 15.0, 42.0, 45.0}));
|
||||
EXPECT_EQ(blocks.kff.RowOffsets(),
|
||||
(std::vector<std::size_t>{0U, 4U, 8U, 12U, 16U}));
|
||||
EXPECT_EQ(blocks.kff.ColumnIndices(),
|
||||
(std::vector<std::size_t>{0U, 1U, 2U, 3U, 0U, 1U, 2U, 3U, 0U, 1U,
|
||||
2U, 3U, 0U, 1U, 2U, 3U}));
|
||||
EXPECT_EQ(
|
||||
blocks.kff.Values(),
|
||||
(std::vector<double>{1.0, 3.0, 4.0, 6.0, 21.0, 23.0, 24.0, 26.0, 31.0,
|
||||
33.0, 34.0, 36.0, 51.0, 53.0, 54.0, 56.0}));
|
||||
EXPECT_EQ(blocks.kfc.RowOffsets(),
|
||||
(std::vector<std::size_t>{0U, 2U, 4U, 6U, 8U}));
|
||||
EXPECT_EQ(blocks.kfc.ColumnIndices(),
|
||||
(std::vector<std::size_t>{0U, 1U, 0U, 1U, 0U, 1U, 0U, 1U}));
|
||||
EXPECT_EQ(blocks.kfc.Values(),
|
||||
(std::vector<double>{2.0, 5.0, 22.0, 0.0, 32.0, 35.0, 52.0, 55.0}));
|
||||
EXPECT_EQ(blocks.kcf.RowOffsets(), (std::vector<std::size_t>{0U, 4U, 8U}));
|
||||
EXPECT_EQ(blocks.kcf.ColumnIndices(),
|
||||
(std::vector<std::size_t>{0U, 1U, 2U, 3U, 0U, 1U, 2U, 3U}));
|
||||
EXPECT_EQ(blocks.kcf.Values(), (std::vector<double>{11.0, 13.0, 14.0, 16.0,
|
||||
41.0, 43.0, 44.0, 46.0}));
|
||||
EXPECT_EQ(blocks.kcc.RowOffsets(), (std::vector<std::size_t>{0U, 2U, 4U}));
|
||||
EXPECT_EQ(blocks.kcc.ColumnIndices(),
|
||||
(std::vector<std::size_t>{0U, 1U, 0U, 1U}));
|
||||
EXPECT_EQ(blocks.kcc.Values(), (std::vector<double>{12.0, 15.0, 42.0, 45.0}));
|
||||
|
||||
EXPECT_EQ(blocks.kfc.Values()[3U], 0.0);
|
||||
EXPECT_TRUE(blocks.kff.Validate().IsOk());
|
||||
EXPECT_TRUE(blocks.kfc.Validate().IsOk());
|
||||
EXPECT_TRUE(blocks.kcf.Validate().IsOk());
|
||||
EXPECT_TRUE(blocks.kcc.Validate().IsOk());
|
||||
EXPECT_EQ(blocks.kfc.Values()[3U], 0.0);
|
||||
EXPECT_TRUE(blocks.kff.Validate().IsOk());
|
||||
EXPECT_TRUE(blocks.kfc.Validate().IsOk());
|
||||
EXPECT_TRUE(blocks.kcf.Validate().IsOk());
|
||||
EXPECT_TRUE(blocks.kcc.Validate().IsOk());
|
||||
}
|
||||
|
||||
TEST(EssentialConstraints, HandlesNoAllAndMixedConstraints) {
|
||||
const auto full = makeMatrix(6U, 6U, sequentialDense(6U));
|
||||
const auto full = MakeMatrix(6U, 6U, SequentialDense(6U));
|
||||
|
||||
const auto noConstraints = makeDofs({});
|
||||
auto none = fesa::EssentialConstraints::partition(full, noConstraints);
|
||||
ASSERT_TRUE(none.HasValue());
|
||||
expectShape(none.Value().kff, 6U, 6U);
|
||||
expectShape(none.Value().kfc, 6U, 0U);
|
||||
expectShape(none.Value().kcf, 0U, 6U);
|
||||
expectShape(none.Value().kcc, 0U, 0U);
|
||||
EXPECT_EQ(none.Value().kff.Values(), full.Values());
|
||||
const auto no_constraints = MakeDofs({});
|
||||
auto none = fesa::EssentialConstraints::Partition(full, no_constraints);
|
||||
ASSERT_TRUE(none.HasValue());
|
||||
ExpectShape(none.Value().kff, 6U, 6U);
|
||||
ExpectShape(none.Value().kfc, 6U, 0U);
|
||||
ExpectShape(none.Value().kcf, 0U, 6U);
|
||||
ExpectShape(none.Value().kcc, 0U, 0U);
|
||||
EXPECT_EQ(none.Value().kff.Values(), full.Values());
|
||||
|
||||
const auto allConstraints = makeDofs({{"1", 1, 6, 1.0, {{}, 12U}}});
|
||||
auto all = fesa::EssentialConstraints::partition(full, allConstraints);
|
||||
ASSERT_TRUE(all.HasValue());
|
||||
expectShape(all.Value().kff, 0U, 0U);
|
||||
expectShape(all.Value().kfc, 0U, 6U);
|
||||
expectShape(all.Value().kcf, 6U, 0U);
|
||||
expectShape(all.Value().kcc, 6U, 6U);
|
||||
EXPECT_EQ(all.Value().kcc.Values(), full.Values());
|
||||
const auto all_constraints = MakeDofs({{"1", 1, 6, 1.0, {{}, 12U}}});
|
||||
auto all = fesa::EssentialConstraints::Partition(full, all_constraints);
|
||||
ASSERT_TRUE(all.HasValue());
|
||||
ExpectShape(all.Value().kff, 0U, 0U);
|
||||
ExpectShape(all.Value().kfc, 0U, 6U);
|
||||
ExpectShape(all.Value().kcf, 6U, 0U);
|
||||
ExpectShape(all.Value().kcc, 6U, 6U);
|
||||
EXPECT_EQ(all.Value().kcc.Values(), full.Values());
|
||||
|
||||
const auto mixedConstraints = makeDofs({{"1", 3, 4, 0.0, {{}, 12U}}});
|
||||
auto mixed = fesa::EssentialConstraints::partition(full, mixedConstraints);
|
||||
ASSERT_TRUE(mixed.HasValue());
|
||||
expectShape(mixed.Value().kff, 4U, 4U);
|
||||
expectShape(mixed.Value().kfc, 4U, 2U);
|
||||
expectShape(mixed.Value().kcf, 2U, 4U);
|
||||
expectShape(mixed.Value().kcc, 2U, 2U);
|
||||
const auto mixed_constraints = MakeDofs({{"1", 3, 4, 0.0, {{}, 12U}}});
|
||||
auto mixed = fesa::EssentialConstraints::Partition(full, mixed_constraints);
|
||||
ASSERT_TRUE(mixed.HasValue());
|
||||
ExpectShape(mixed.Value().kff, 4U, 4U);
|
||||
ExpectShape(mixed.Value().kfc, 4U, 2U);
|
||||
ExpectShape(mixed.Value().kcf, 2U, 4U);
|
||||
ExpectShape(mixed.Value().kcc, 2U, 2U);
|
||||
}
|
||||
|
||||
// MITC4-DOF-003
|
||||
TEST(EssentialConstraints, PreservesShellSizedNoMixedAndAllConstraintRoundTrips) {
|
||||
const auto full = makeMatrix(24U, 24U, sequentialDense(24U));
|
||||
TEST(EssentialConstraints,
|
||||
PreservesShellSizedNoMixedAndAllConstraintRoundTrips) {
|
||||
const auto full = MakeMatrix(24U, 24U, SequentialDense(24U));
|
||||
|
||||
const auto noConstraints = makeShellSizedDofs({});
|
||||
auto none = fesa::EssentialConstraints::partition(full, noConstraints);
|
||||
ASSERT_TRUE(none.HasValue());
|
||||
expectShape(none.Value().kff, 24U, 24U);
|
||||
expectShape(none.Value().kfc, 24U, 0U);
|
||||
expectShape(none.Value().kcf, 0U, 24U);
|
||||
expectShape(none.Value().kcc, 0U, 0U);
|
||||
const auto no_constraints = MakeShellSizedDofs({});
|
||||
auto none = fesa::EssentialConstraints::Partition(full, no_constraints);
|
||||
ASSERT_TRUE(none.HasValue());
|
||||
ExpectShape(none.Value().kff, 24U, 24U);
|
||||
ExpectShape(none.Value().kfc, 24U, 0U);
|
||||
ExpectShape(none.Value().kcf, 0U, 24U);
|
||||
ExpectShape(none.Value().kcc, 0U, 0U);
|
||||
|
||||
const auto mixedConstraints = makeShellSizedDofs({
|
||||
{"1", 1, 6, 0.0, {{}, 12U}},
|
||||
{"4", 2, 2, 2.5, {{}, 13U}}});
|
||||
auto mixed = fesa::EssentialConstraints::partition(full, mixedConstraints);
|
||||
ASSERT_TRUE(mixed.HasValue());
|
||||
expectShape(mixed.Value().kff, 17U, 17U);
|
||||
expectShape(mixed.Value().kfc, 17U, 7U);
|
||||
expectShape(mixed.Value().kcf, 7U, 17U);
|
||||
expectShape(mixed.Value().kcc, 7U, 7U);
|
||||
const auto mixed_constraints = MakeShellSizedDofs(
|
||||
{{"1", 1, 6, 0.0, {{}, 12U}}, {"4", 2, 2, 2.5, {{}, 13U}}});
|
||||
auto mixed = fesa::EssentialConstraints::Partition(full, mixed_constraints);
|
||||
ASSERT_TRUE(mixed.HasValue());
|
||||
ExpectShape(mixed.Value().kff, 17U, 17U);
|
||||
ExpectShape(mixed.Value().kfc, 17U, 7U);
|
||||
ExpectShape(mixed.Value().kcf, 7U, 17U);
|
||||
ExpectShape(mixed.Value().kcc, 7U, 7U);
|
||||
|
||||
fesa::Vector mixedFull{24U};
|
||||
for (std::size_t index = 0U; index < mixedFull.Size(); ++index) {
|
||||
mixedFull[index] = static_cast<double>(index) + 0.5;
|
||||
}
|
||||
for (std::size_t index = 0U;
|
||||
index < mixedConstraints.constrainedDofCount();
|
||||
++index) {
|
||||
mixedFull[mixedConstraints.constrainedDofs()[index]] =
|
||||
mixedConstraints.prescribedValues()[index];
|
||||
}
|
||||
const auto mixedFree =
|
||||
fesa::EssentialConstraints::gatherFree(mixedFull, mixedConstraints);
|
||||
const auto mixedReconstructed =
|
||||
fesa::EssentialConstraints::reconstructFull(
|
||||
mixedFree, mixedConstraints.prescribedValues(), mixedConstraints);
|
||||
ASSERT_EQ(mixedReconstructed.Size(), mixedFull.Size());
|
||||
for (std::size_t index = 0U; index < mixedFull.Size(); ++index) {
|
||||
EXPECT_DOUBLE_EQ(mixedReconstructed[index], mixedFull[index]);
|
||||
}
|
||||
|
||||
const auto allConstraints = makeShellSizedDofs({
|
||||
{"1", 1, 6, 1.0, {{}, 14U}},
|
||||
{"2", 1, 6, 2.0, {{}, 15U}},
|
||||
{"3", 1, 6, 3.0, {{}, 16U}},
|
||||
{"4", 1, 6, 4.0, {{}, 17U}}});
|
||||
auto all = fesa::EssentialConstraints::partition(full, allConstraints);
|
||||
ASSERT_TRUE(all.HasValue());
|
||||
expectShape(all.Value().kff, 0U, 0U);
|
||||
expectShape(all.Value().kfc, 0U, 24U);
|
||||
expectShape(all.Value().kcf, 24U, 0U);
|
||||
expectShape(all.Value().kcc, 24U, 24U);
|
||||
|
||||
const auto allReconstructed =
|
||||
fesa::EssentialConstraints::reconstructFull(
|
||||
fesa::Vector{0U},
|
||||
allConstraints.prescribedValues(),
|
||||
allConstraints);
|
||||
ASSERT_EQ(allReconstructed.Size(), 24U);
|
||||
for (std::size_t node = 0U; node < 4U; ++node) {
|
||||
for (std::size_t component = 0U; component < 6U; ++component) {
|
||||
EXPECT_DOUBLE_EQ(allReconstructed[node * 6U + component], node + 1.0);
|
||||
}
|
||||
fesa::Vector mixed_full{24U};
|
||||
for (std::size_t index = 0U; index < mixed_full.Size(); ++index) {
|
||||
mixed_full[index] = static_cast<double>(index) + 0.5;
|
||||
}
|
||||
for (std::size_t index = 0U; index < mixed_constraints.ConstrainedDofCount();
|
||||
++index) {
|
||||
mixed_full[mixed_constraints.ConstrainedDofs()[index]] =
|
||||
mixed_constraints.PrescribedValues()[index];
|
||||
}
|
||||
const auto mixed_free =
|
||||
fesa::EssentialConstraints::GatherFree(mixed_full, mixed_constraints);
|
||||
const auto mixed_reconstructed = fesa::EssentialConstraints::ReconstructFull(
|
||||
mixed_free, mixed_constraints.PrescribedValues(), mixed_constraints);
|
||||
ASSERT_EQ(mixed_reconstructed.Size(), mixed_full.Size());
|
||||
for (std::size_t index = 0U; index < mixed_full.Size(); ++index) {
|
||||
EXPECT_DOUBLE_EQ(mixed_reconstructed[index], mixed_full[index]);
|
||||
}
|
||||
|
||||
const auto all_constraints =
|
||||
MakeShellSizedDofs({{"1", 1, 6, 1.0, {{}, 14U}},
|
||||
{"2", 1, 6, 2.0, {{}, 15U}},
|
||||
{"3", 1, 6, 3.0, {{}, 16U}},
|
||||
{"4", 1, 6, 4.0, {{}, 17U}}});
|
||||
auto all = fesa::EssentialConstraints::Partition(full, all_constraints);
|
||||
ASSERT_TRUE(all.HasValue());
|
||||
ExpectShape(all.Value().kff, 0U, 0U);
|
||||
ExpectShape(all.Value().kfc, 0U, 24U);
|
||||
ExpectShape(all.Value().kcf, 24U, 0U);
|
||||
ExpectShape(all.Value().kcc, 24U, 24U);
|
||||
|
||||
const auto all_reconstructed = fesa::EssentialConstraints::ReconstructFull(
|
||||
fesa::Vector{0U}, all_constraints.PrescribedValues(), all_constraints);
|
||||
ASSERT_EQ(all_reconstructed.Size(), 24U);
|
||||
for (std::size_t node = 0U; node < 4U; ++node) {
|
||||
for (std::size_t component = 0U; component < 6U; ++component) {
|
||||
EXPECT_DOUBLE_EQ(all_reconstructed[node * 6U + component], node + 1.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST(EssentialConstraints, ReconstructsNonzeroPrescribedValues) {
|
||||
const auto dofs = makeDofs({
|
||||
{"1", 2, 2, 2.5, {{}, 12U}},
|
||||
{"1", 5, 5, -3.25, {{}, 13U}}});
|
||||
fesa::Vector full{6U};
|
||||
full[0U] = 10.0;
|
||||
full[1U] = 2.5;
|
||||
full[2U] = 20.0;
|
||||
full[3U] = 30.0;
|
||||
full[4U] = -3.25;
|
||||
full[5U] = 40.0;
|
||||
const auto dofs =
|
||||
MakeDofs({{"1", 2, 2, 2.5, {{}, 12U}}, {"1", 5, 5, -3.25, {{}, 13U}}});
|
||||
fesa::Vector full{6U};
|
||||
full[0U] = 10.0;
|
||||
full[1U] = 2.5;
|
||||
full[2U] = 20.0;
|
||||
full[3U] = 30.0;
|
||||
full[4U] = -3.25;
|
||||
full[5U] = 40.0;
|
||||
|
||||
const auto free = fesa::EssentialConstraints::gatherFree(full, dofs);
|
||||
const auto constrained =
|
||||
fesa::EssentialConstraints::gatherConstrained(full, dofs);
|
||||
EXPECT_EQ(free.Size(), 4U);
|
||||
EXPECT_DOUBLE_EQ(free[0U], 10.0);
|
||||
EXPECT_DOUBLE_EQ(free[1U], 20.0);
|
||||
EXPECT_DOUBLE_EQ(free[2U], 30.0);
|
||||
EXPECT_DOUBLE_EQ(free[3U], 40.0);
|
||||
EXPECT_EQ(constrained.Size(), 2U);
|
||||
EXPECT_DOUBLE_EQ(constrained[0U], 2.5);
|
||||
EXPECT_DOUBLE_EQ(constrained[1U], -3.25);
|
||||
EXPECT_EQ(constrained[0U], dofs.prescribedValues()[0U]);
|
||||
EXPECT_EQ(constrained[1U], dofs.prescribedValues()[1U]);
|
||||
const auto free = fesa::EssentialConstraints::GatherFree(full, dofs);
|
||||
const auto constrained =
|
||||
fesa::EssentialConstraints::GatherConstrained(full, dofs);
|
||||
EXPECT_EQ(free.Size(), 4U);
|
||||
EXPECT_DOUBLE_EQ(free[0U], 10.0);
|
||||
EXPECT_DOUBLE_EQ(free[1U], 20.0);
|
||||
EXPECT_DOUBLE_EQ(free[2U], 30.0);
|
||||
EXPECT_DOUBLE_EQ(free[3U], 40.0);
|
||||
EXPECT_EQ(constrained.Size(), 2U);
|
||||
EXPECT_DOUBLE_EQ(constrained[0U], 2.5);
|
||||
EXPECT_DOUBLE_EQ(constrained[1U], -3.25);
|
||||
EXPECT_EQ(constrained[0U], dofs.PrescribedValues()[0U]);
|
||||
EXPECT_EQ(constrained[1U], dofs.PrescribedValues()[1U]);
|
||||
|
||||
const auto reconstructed = fesa::EssentialConstraints::reconstructFull(
|
||||
free, dofs.prescribedValues(), dofs);
|
||||
ASSERT_EQ(reconstructed.Size(), full.Size());
|
||||
for (std::size_t index = 0U; index < full.Size(); ++index) {
|
||||
EXPECT_DOUBLE_EQ(reconstructed[index], full[index]);
|
||||
}
|
||||
const auto reconstructed = fesa::EssentialConstraints::ReconstructFull(
|
||||
free, dofs.PrescribedValues(), dofs);
|
||||
ASSERT_EQ(reconstructed.Size(), full.Size());
|
||||
for (std::size_t index = 0U; index < full.Size(); ++index) {
|
||||
EXPECT_DOUBLE_EQ(reconstructed[index], full[index]);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(EssentialConstraints, RejectsDimensionOrOrderMismatch) {
|
||||
const auto dofs = makeDofs({{"1", 2, 2, 1.0, {{}, 12U}}});
|
||||
const auto wrongSquare = makeMatrix(5U, 5U, sequentialDense(5U));
|
||||
auto wrongDimension =
|
||||
fesa::EssentialConstraints::partition(wrongSquare, dofs);
|
||||
ASSERT_FALSE(wrongDimension.HasValue());
|
||||
EXPECT_EQ(
|
||||
wrongDimension.GetStatus().Category(),
|
||||
fesa::FailureCategory::kModel);
|
||||
ASSERT_EQ(wrongDimension.GetStatus().Diagnostics().size(), 1U);
|
||||
EXPECT_EQ(
|
||||
wrongDimension.GetStatus().Diagnostics()[0U].code,
|
||||
"invalid-constraint-dimensions");
|
||||
const auto dofs = MakeDofs({{"1", 2, 2, 1.0, {{}, 12U}}});
|
||||
const auto wrong_square = MakeMatrix(5U, 5U, SequentialDense(5U));
|
||||
auto wrong_dimension =
|
||||
fesa::EssentialConstraints::Partition(wrong_square, dofs);
|
||||
ASSERT_FALSE(wrong_dimension.HasValue());
|
||||
EXPECT_EQ(wrong_dimension.GetStatus().Category(),
|
||||
fesa::FailureCategory::kModel);
|
||||
ASSERT_EQ(wrong_dimension.GetStatus().Diagnostics().size(), 1U);
|
||||
EXPECT_EQ(wrong_dimension.GetStatus().Diagnostics()[0U].code,
|
||||
"invalid-constraint-dimensions");
|
||||
|
||||
const auto rectangular = makeMatrix(
|
||||
6U, 5U, std::vector<double>(30U, 0.0));
|
||||
auto wrongOrder = fesa::EssentialConstraints::partition(rectangular, dofs);
|
||||
ASSERT_FALSE(wrongOrder.HasValue());
|
||||
EXPECT_EQ(
|
||||
wrongOrder.GetStatus().Diagnostics()[0U].code,
|
||||
"invalid-constraint-dimensions");
|
||||
const auto rectangular = MakeMatrix(6U, 5U, std::vector<double>(30U, 0.0));
|
||||
auto wrong_order = fesa::EssentialConstraints::Partition(rectangular, dofs);
|
||||
ASSERT_FALSE(wrong_order.HasValue());
|
||||
EXPECT_EQ(wrong_order.GetStatus().Diagnostics()[0U].code,
|
||||
"invalid-constraint-dimensions");
|
||||
|
||||
EXPECT_THROW(
|
||||
static_cast<void>(fesa::EssentialConstraints::gatherFree(
|
||||
fesa::Vector{5U}, dofs)),
|
||||
std::invalid_argument);
|
||||
EXPECT_THROW(
|
||||
static_cast<void>(fesa::EssentialConstraints::gatherConstrained(
|
||||
fesa::Vector{7U}, dofs)),
|
||||
std::invalid_argument);
|
||||
EXPECT_THROW(
|
||||
static_cast<void>(fesa::EssentialConstraints::reconstructFull(
|
||||
fesa::Vector{4U}, fesa::Vector{2U}, dofs)),
|
||||
std::invalid_argument);
|
||||
EXPECT_THROW(static_cast<void>(fesa::EssentialConstraints::GatherFree(
|
||||
fesa::Vector{5U}, dofs)),
|
||||
std::invalid_argument);
|
||||
EXPECT_THROW(static_cast<void>(fesa::EssentialConstraints::GatherConstrained(
|
||||
fesa::Vector{7U}, dofs)),
|
||||
std::invalid_argument);
|
||||
EXPECT_THROW(static_cast<void>(fesa::EssentialConstraints::ReconstructFull(
|
||||
fesa::Vector{4U}, fesa::Vector{2U}, dofs)),
|
||||
std::invalid_argument);
|
||||
}
|
||||
|
||||
+184
-200
@@ -1,4 +1,4 @@
|
||||
#include "fesa/fem/dof_manager.hpp"
|
||||
#include "fesa/fem/dof_manager.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
@@ -11,243 +11,227 @@
|
||||
|
||||
namespace {
|
||||
|
||||
fesa::ModelDefinition makeDefinition() {
|
||||
const std::filesystem::path source{"models/dof-manager.inp"};
|
||||
fesa::ModelDefinition definition{};
|
||||
definition.source_path = source;
|
||||
definition.source_content_identity = "fnv1a64:0123456789abcdef";
|
||||
definition.nodes = {
|
||||
{{"Beam-1", 10, "10"}, {0.0, 0.0, 0.0}, {source, 10U}},
|
||||
{{"Beam-1", 20, "20"}, {1.0, 0.0, 0.0}, {source, 11U}},
|
||||
{{"Beam-1", 30, "30"}, {2.0, 0.0, 0.0}, {source, 12U}}};
|
||||
definition.materials = {
|
||||
{"Material", 1000.0, 0.25, {source, 20U}}};
|
||||
definition.sections = {{
|
||||
"Section", 1.0, 1.0, 0.0, 1.0, 1.0,
|
||||
{0.0, 1.0, 0.0}, {}, {source, 30U}}};
|
||||
definition.elements = {
|
||||
{{"Beam-1", 100, "100"}, {0U, 1U}, 0U, 0U, {source, 40U}},
|
||||
{{"Beam-1", 200, "200"}, {1U, 2U}, 0U, 0U, {source, 41U}}};
|
||||
definition.node_sets = {
|
||||
{"Root", std::optional<std::string>{"Beam-1"}, {0U}, {source, 50U}},
|
||||
{"Ends", std::optional<std::string>{"Beam-1"}, {0U, 2U}, {source, 51U}}};
|
||||
definition.steps = {{
|
||||
"Step-1",
|
||||
{{"Root", 1, 2, 0.0, {source, 60U}},
|
||||
{"ends", 3, 3, 0.25, {source, 61U}},
|
||||
{"20", 6, 6, -0.5, {source, 62U}},
|
||||
{"Root", 1, 1, 0.0, {source, 63U}}},
|
||||
{},
|
||||
0.1,
|
||||
1.0,
|
||||
0.01,
|
||||
1.0,
|
||||
{source, 59U}}};
|
||||
return definition;
|
||||
fesa::ModelDefinition MakeDefinition() {
|
||||
const std::filesystem::path source{"models/dof-manager.inp"};
|
||||
fesa::ModelDefinition definition{};
|
||||
definition.source_path = source;
|
||||
definition.source_content_identity = "fnv1a64:0123456789abcdef";
|
||||
definition.nodes = {{{"Beam-1", 10, "10"}, {0.0, 0.0, 0.0}, {source, 10U}},
|
||||
{{"Beam-1", 20, "20"}, {1.0, 0.0, 0.0}, {source, 11U}},
|
||||
{{"Beam-1", 30, "30"}, {2.0, 0.0, 0.0}, {source, 12U}}};
|
||||
definition.materials = {{"Material", 1000.0, 0.25, {source, 20U}}};
|
||||
definition.sections = {
|
||||
{"Section", 1.0, 1.0, 0.0, 1.0, 1.0, {0.0, 1.0, 0.0}, {}, {source, 30U}}};
|
||||
definition.elements = {
|
||||
{{"Beam-1", 100, "100"}, {0U, 1U}, 0U, 0U, {source, 40U}},
|
||||
{{"Beam-1", 200, "200"}, {1U, 2U}, 0U, 0U, {source, 41U}}};
|
||||
definition.node_sets = {
|
||||
{"Root", std::optional<std::string>{"Beam-1"}, {0U}, {source, 50U}},
|
||||
{"Ends", std::optional<std::string>{"Beam-1"}, {0U, 2U}, {source, 51U}}};
|
||||
definition.steps = {{"Step-1",
|
||||
{{"Root", 1, 2, 0.0, {source, 60U}},
|
||||
{"ends", 3, 3, 0.25, {source, 61U}},
|
||||
{"20", 6, 6, -0.5, {source, 62U}},
|
||||
{"Root", 1, 1, 0.0, {source, 63U}}},
|
||||
{},
|
||||
0.1,
|
||||
1.0,
|
||||
0.01,
|
||||
1.0,
|
||||
{source, 59U}}};
|
||||
return definition;
|
||||
}
|
||||
|
||||
fesa::ModelDefinition makeShellDefinition() {
|
||||
const std::filesystem::path source{"models/shell-dof-manager.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, 10U}},
|
||||
{{"Shell-1", 20, "20"}, {1.0, 0.0, 0.0}, {source, 11U}},
|
||||
{{"Shell-1", 30, "30"}, {1.0, 1.0, 0.0}, {source, 12U}},
|
||||
{{"Shell-1", 40, "40"}, {0.0, 1.0, 0.0}, {source, 13U}}};
|
||||
definition.materials = {
|
||||
{"Material", 1000.0, 0.25, {source, 20U}}};
|
||||
definition.shell_sections = {
|
||||
{"ShellSection", 0.1, 0U, {source, 30U}}};
|
||||
definition.shell_elements = {{
|
||||
{"Shell-1", 100, "100"},
|
||||
fesa::ShellSourceElementType::kS4,
|
||||
{2U, 0U, 3U, 1U},
|
||||
0U,
|
||||
0U,
|
||||
{source, 40U}}};
|
||||
definition.steps = {{
|
||||
"Step-1", {}, {}, 0.1, 1.0, 0.01, 1.0, {source, 50U}}};
|
||||
return definition;
|
||||
fesa::ModelDefinition MakeShellDefinition() {
|
||||
const std::filesystem::path source{"models/shell-dof-manager.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, 10U}},
|
||||
{{"Shell-1", 20, "20"}, {1.0, 0.0, 0.0}, {source, 11U}},
|
||||
{{"Shell-1", 30, "30"}, {1.0, 1.0, 0.0}, {source, 12U}},
|
||||
{{"Shell-1", 40, "40"}, {0.0, 1.0, 0.0}, {source, 13U}}};
|
||||
definition.materials = {{"Material", 1000.0, 0.25, {source, 20U}}};
|
||||
definition.shell_sections = {{"ShellSection", 0.1, 0U, {source, 30U}}};
|
||||
definition.shell_elements = {{{"Shell-1", 100, "100"},
|
||||
fesa::ShellSourceElementType::kS4,
|
||||
{2U, 0U, 3U, 1U},
|
||||
0U,
|
||||
0U,
|
||||
{source, 40U}}};
|
||||
definition.steps = {{"Step-1", {}, {}, 0.1, 1.0, 0.01, 1.0, {source, 50U}}};
|
||||
return definition;
|
||||
}
|
||||
|
||||
struct DofFixture {
|
||||
fesa::DofManager dofs;
|
||||
fesa::DofManager dofs;
|
||||
};
|
||||
|
||||
DofFixture makeDofFixture(fesa::ModelDefinition definition = makeDefinition()) {
|
||||
auto domain = fesa::Domain::Create(std::move(definition));
|
||||
EXPECT_TRUE(domain.HasValue());
|
||||
auto model = fesa::AnalysisModel::create(domain.Value());
|
||||
EXPECT_TRUE(model.HasValue());
|
||||
auto dofs = fesa::DofManager::create(model.Value());
|
||||
EXPECT_TRUE(dofs.HasValue());
|
||||
return {std::move(dofs.Value())};
|
||||
DofFixture MakeDofFixture(fesa::ModelDefinition definition = MakeDefinition()) {
|
||||
auto domain = fesa::Domain::Create(std::move(definition));
|
||||
EXPECT_TRUE(domain.HasValue());
|
||||
auto model = fesa::AnalysisModel::Create(domain.Value());
|
||||
EXPECT_TRUE(model.HasValue());
|
||||
auto dofs = fesa::DofManager::Create(model.Value());
|
||||
EXPECT_TRUE(dofs.HasValue());
|
||||
return {std::move(dofs.Value())};
|
||||
}
|
||||
|
||||
std::vector<std::size_t> rowColumns(
|
||||
const fesa::SparsePattern& pattern, std::size_t row) {
|
||||
return {
|
||||
pattern.columnIndices.begin() + pattern.rowOffsets[row],
|
||||
pattern.columnIndices.begin() + pattern.rowOffsets[row + 1U]};
|
||||
std::vector<std::size_t> RowColumns(const fesa::SparsePattern& pattern,
|
||||
std::size_t row) {
|
||||
return {pattern.column_indices.begin() + pattern.row_offsets[row],
|
||||
pattern.column_indices.begin() + pattern.row_offsets[row + 1U]};
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
TEST(DofManager, NumbersSixDofsAndFreeEquationsStably) {
|
||||
const auto fixture = makeDofFixture();
|
||||
const auto& dofs = fixture.dofs;
|
||||
const auto fixture = MakeDofFixture();
|
||||
const auto& dofs = fixture.dofs;
|
||||
|
||||
EXPECT_EQ(dofs.fullDofCount(), 18U);
|
||||
EXPECT_EQ(dofs.freeDofCount(), 13U);
|
||||
EXPECT_EQ(dofs.constrainedDofCount(), 5U);
|
||||
EXPECT_EQ(dofs.fullDof(0U, fesa::DofComponent::ux), 0U);
|
||||
EXPECT_EQ(dofs.fullDof(0U, fesa::DofComponent::urz), 5U);
|
||||
EXPECT_EQ(dofs.fullDof(1U, fesa::DofComponent::ux), 6U);
|
||||
EXPECT_EQ(dofs.fullDof(2U, fesa::DofComponent::urz), 17U);
|
||||
EXPECT_EQ(
|
||||
dofs.freeDofs(),
|
||||
(std::vector<std::size_t>{
|
||||
3U, 4U, 5U, 6U, 7U, 8U, 9U, 10U, 12U, 13U, 15U, 16U, 17U}));
|
||||
EXPECT_EQ(
|
||||
dofs.constrainedDofs(),
|
||||
(std::vector<std::size_t>{0U, 1U, 2U, 11U, 14U}));
|
||||
EXPECT_EQ(dofs.freeEquation(0U), std::nullopt);
|
||||
EXPECT_EQ(dofs.freeEquation(3U), std::optional<std::size_t>{0U});
|
||||
EXPECT_EQ(dofs.freeEquation(10U), std::optional<std::size_t>{7U});
|
||||
EXPECT_EQ(dofs.freeEquation(17U), std::optional<std::size_t>{12U});
|
||||
EXPECT_EQ(dofs.FullDofCount(), 18U);
|
||||
EXPECT_EQ(dofs.FreeDofCount(), 13U);
|
||||
EXPECT_EQ(dofs.ConstrainedDofCount(), 5U);
|
||||
EXPECT_EQ(dofs.FullDof(0U, fesa::DofComponent::kUx), 0U);
|
||||
EXPECT_EQ(dofs.FullDof(0U, fesa::DofComponent::kUrz), 5U);
|
||||
EXPECT_EQ(dofs.FullDof(1U, fesa::DofComponent::kUx), 6U);
|
||||
EXPECT_EQ(dofs.FullDof(2U, fesa::DofComponent::kUrz), 17U);
|
||||
EXPECT_EQ(dofs.FreeDofs(),
|
||||
(std::vector<std::size_t>{3U, 4U, 5U, 6U, 7U, 8U, 9U, 10U, 12U, 13U,
|
||||
15U, 16U, 17U}));
|
||||
EXPECT_EQ(dofs.ConstrainedDofs(),
|
||||
(std::vector<std::size_t>{0U, 1U, 2U, 11U, 14U}));
|
||||
EXPECT_EQ(dofs.FreeEquation(0U), std::nullopt);
|
||||
EXPECT_EQ(dofs.FreeEquation(3U), std::optional<std::size_t>{0U});
|
||||
EXPECT_EQ(dofs.FreeEquation(10U), std::optional<std::size_t>{7U});
|
||||
EXPECT_EQ(dofs.FreeEquation(17U), std::optional<std::size_t>{12U});
|
||||
}
|
||||
|
||||
TEST(DofManager, ExpandsAndValidatesPrescribedValues) {
|
||||
const auto fixture = makeDofFixture();
|
||||
const auto& values = fixture.dofs.prescribedValues();
|
||||
ASSERT_EQ(values.Size(), 5U);
|
||||
EXPECT_DOUBLE_EQ(values[0], 0.0);
|
||||
EXPECT_DOUBLE_EQ(values[1], 0.0);
|
||||
EXPECT_DOUBLE_EQ(values[2], 0.25);
|
||||
EXPECT_DOUBLE_EQ(values[3], -0.5);
|
||||
EXPECT_DOUBLE_EQ(values[4], 0.25);
|
||||
const auto fixture = MakeDofFixture();
|
||||
const auto& values = fixture.dofs.PrescribedValues();
|
||||
ASSERT_EQ(values.Size(), 5U);
|
||||
EXPECT_DOUBLE_EQ(values[0], 0.0);
|
||||
EXPECT_DOUBLE_EQ(values[1], 0.0);
|
||||
EXPECT_DOUBLE_EQ(values[2], 0.25);
|
||||
EXPECT_DOUBLE_EQ(values[3], -0.5);
|
||||
EXPECT_DOUBLE_EQ(values[4], 0.25);
|
||||
|
||||
auto conflictingDefinition = makeDefinition();
|
||||
conflictingDefinition.steps[0].boundaries.push_back(
|
||||
{"root", 1, 1, 1.0, {conflictingDefinition.source_path, 77U}});
|
||||
auto domain = fesa::Domain::Create(std::move(conflictingDefinition));
|
||||
ASSERT_TRUE(domain.HasValue());
|
||||
auto model = fesa::AnalysisModel::create(domain.Value());
|
||||
ASSERT_TRUE(model.HasValue());
|
||||
auto conflicting_definition = MakeDefinition();
|
||||
conflicting_definition.steps[0].boundaries.push_back(
|
||||
{"root", 1, 1, 1.0, {conflicting_definition.source_path, 77U}});
|
||||
auto domain = fesa::Domain::Create(std::move(conflicting_definition));
|
||||
ASSERT_TRUE(domain.HasValue());
|
||||
auto model = fesa::AnalysisModel::Create(domain.Value());
|
||||
ASSERT_TRUE(model.HasValue());
|
||||
|
||||
auto conflict = fesa::DofManager::create(model.Value());
|
||||
ASSERT_FALSE(conflict.HasValue());
|
||||
EXPECT_EQ(conflict.GetStatus().Category(), fesa::FailureCategory::kInput);
|
||||
ASSERT_EQ(conflict.GetStatus().Diagnostics().size(), 1U);
|
||||
const auto& diagnostic = conflict.GetStatus().Diagnostics()[0];
|
||||
EXPECT_EQ(diagnostic.code, "conflicting-boundary-condition");
|
||||
EXPECT_EQ(diagnostic.keyword, "BOUNDARY");
|
||||
EXPECT_EQ(diagnostic.entity_identity, "root");
|
||||
EXPECT_EQ(diagnostic.location.file, std::filesystem::path{"models/dof-manager.inp"});
|
||||
EXPECT_EQ(diagnostic.location.line, 77U);
|
||||
auto conflict = fesa::DofManager::Create(model.Value());
|
||||
ASSERT_FALSE(conflict.HasValue());
|
||||
EXPECT_EQ(conflict.GetStatus().Category(), fesa::FailureCategory::kInput);
|
||||
ASSERT_EQ(conflict.GetStatus().Diagnostics().size(), 1U);
|
||||
const auto& diagnostic = conflict.GetStatus().Diagnostics()[0];
|
||||
EXPECT_EQ(diagnostic.code, "conflicting-boundary-condition");
|
||||
EXPECT_EQ(diagnostic.keyword, "BOUNDARY");
|
||||
EXPECT_EQ(diagnostic.entity_identity, "root");
|
||||
EXPECT_EQ(diagnostic.location.file,
|
||||
std::filesystem::path{"models/dof-manager.inp"});
|
||||
EXPECT_EQ(diagnostic.location.line, 77U);
|
||||
}
|
||||
|
||||
TEST(DofManager, BuildsTwelveDofScatterAndSortedUniquePattern) {
|
||||
const auto fixture = makeDofFixture();
|
||||
const auto& dofs = fixture.dofs;
|
||||
const auto fixture = MakeDofFixture();
|
||||
const auto& dofs = fixture.dofs;
|
||||
|
||||
EXPECT_EQ(
|
||||
dofs.elementScatter(0U),
|
||||
(std::array<std::size_t, 12>{
|
||||
0U, 1U, 2U, 3U, 4U, 5U, 6U, 7U, 8U, 9U, 10U, 11U}));
|
||||
EXPECT_EQ(
|
||||
dofs.elementScatter(1U),
|
||||
(std::array<std::size_t, 12>{
|
||||
6U, 7U, 8U, 9U, 10U, 11U,
|
||||
12U, 13U, 14U, 15U, 16U, 17U}));
|
||||
EXPECT_EQ(dofs.ElementScatter(0U),
|
||||
(std::array<std::size_t, 12>{0U, 1U, 2U, 3U, 4U, 5U, 6U, 7U, 8U, 9U,
|
||||
10U, 11U}));
|
||||
EXPECT_EQ(dofs.ElementScatter(1U),
|
||||
(std::array<std::size_t, 12>{6U, 7U, 8U, 9U, 10U, 11U, 12U, 13U,
|
||||
14U, 15U, 16U, 17U}));
|
||||
|
||||
const auto& pattern = dofs.sparsePattern();
|
||||
EXPECT_EQ(
|
||||
pattern.rowOffsets,
|
||||
(std::vector<std::size_t>{
|
||||
0U, 12U, 24U, 36U, 48U, 60U, 72U,
|
||||
90U, 108U, 126U, 144U, 162U, 180U,
|
||||
192U, 204U, 216U, 228U, 240U, 252U}));
|
||||
const std::vector<std::size_t> firstBlock{
|
||||
0U, 1U, 2U, 3U, 4U, 5U, 6U, 7U, 8U, 9U, 10U, 11U};
|
||||
const std::vector<std::size_t> sharedBlock{
|
||||
0U, 1U, 2U, 3U, 4U, 5U, 6U, 7U, 8U,
|
||||
9U, 10U, 11U, 12U, 13U, 14U, 15U, 16U, 17U};
|
||||
const std::vector<std::size_t> lastBlock{
|
||||
6U, 7U, 8U, 9U, 10U, 11U, 12U, 13U, 14U, 15U, 16U, 17U};
|
||||
EXPECT_EQ(rowColumns(pattern, 0U), firstBlock);
|
||||
EXPECT_EQ(rowColumns(pattern, 7U), sharedBlock);
|
||||
EXPECT_EQ(rowColumns(pattern, 17U), lastBlock);
|
||||
for (std::size_t row = 0U; row < dofs.fullDofCount(); ++row) {
|
||||
const auto columns = rowColumns(pattern, row);
|
||||
EXPECT_TRUE(std::is_sorted(columns.begin(), columns.end()));
|
||||
EXPECT_EQ(std::adjacent_find(columns.begin(), columns.end()), columns.end());
|
||||
}
|
||||
const auto& pattern = dofs.GetSparsePattern();
|
||||
EXPECT_EQ(pattern.row_offsets,
|
||||
(std::vector<std::size_t>{0U, 12U, 24U, 36U, 48U, 60U, 72U, 90U,
|
||||
108U, 126U, 144U, 162U, 180U, 192U, 204U,
|
||||
216U, 228U, 240U, 252U}));
|
||||
const std::vector<std::size_t> first_block{0U, 1U, 2U, 3U, 4U, 5U,
|
||||
6U, 7U, 8U, 9U, 10U, 11U};
|
||||
const std::vector<std::size_t> shared_block{0U, 1U, 2U, 3U, 4U, 5U,
|
||||
6U, 7U, 8U, 9U, 10U, 11U,
|
||||
12U, 13U, 14U, 15U, 16U, 17U};
|
||||
const std::vector<std::size_t> last_block{6U, 7U, 8U, 9U, 10U, 11U,
|
||||
12U, 13U, 14U, 15U, 16U, 17U};
|
||||
EXPECT_EQ(RowColumns(pattern, 0U), first_block);
|
||||
EXPECT_EQ(RowColumns(pattern, 7U), shared_block);
|
||||
EXPECT_EQ(RowColumns(pattern, 17U), last_block);
|
||||
for (std::size_t row = 0U; row < dofs.FullDofCount(); ++row) {
|
||||
const auto columns = RowColumns(pattern, row);
|
||||
EXPECT_TRUE(std::is_sorted(columns.begin(), columns.end()));
|
||||
EXPECT_EQ(std::adjacent_find(columns.begin(), columns.end()),
|
||||
columns.end());
|
||||
}
|
||||
}
|
||||
|
||||
// MITC4-DOF-001
|
||||
TEST(DofManager, BuildsShellScatterInSourceNodeAndComponentOrder) {
|
||||
const auto fixture = makeDofFixture(makeShellDefinition());
|
||||
const auto& dofs = fixture.dofs;
|
||||
const auto fixture = MakeDofFixture(MakeShellDefinition());
|
||||
const auto& dofs = fixture.dofs;
|
||||
|
||||
EXPECT_EQ(dofs.fullDofCount(), 24U);
|
||||
EXPECT_EQ(
|
||||
dofs.shellElementScatter(0U),
|
||||
(std::array<std::size_t, 24>{
|
||||
12U, 13U, 14U, 15U, 16U, 17U,
|
||||
0U, 1U, 2U, 3U, 4U, 5U,
|
||||
18U, 19U, 20U, 21U, 22U, 23U,
|
||||
6U, 7U, 8U, 9U, 10U, 11U}));
|
||||
EXPECT_EQ(dofs.FullDofCount(), 24U);
|
||||
EXPECT_EQ(dofs.ShellElementScatter(0U),
|
||||
(std::array<std::size_t, 24>{
|
||||
12U, 13U, 14U, 15U, 16U, 17U, 0U, 1U, 2U, 3U, 4U, 5U,
|
||||
18U, 19U, 20U, 21U, 22U, 23U, 6U, 7U, 8U, 9U, 10U, 11U}));
|
||||
}
|
||||
|
||||
// MITC4-DOF-002
|
||||
TEST(DofManager, IncludesShellConnectivityInSortedUniqueSparsePattern) {
|
||||
const auto fixture = makeDofFixture(makeShellDefinition());
|
||||
const auto& dofs = fixture.dofs;
|
||||
const auto& pattern = dofs.sparsePattern();
|
||||
const auto fixture = MakeDofFixture(MakeShellDefinition());
|
||||
const auto& dofs = fixture.dofs;
|
||||
const auto& pattern = dofs.GetSparsePattern();
|
||||
|
||||
ASSERT_EQ(pattern.rowOffsets.size(), 25U);
|
||||
ASSERT_EQ(pattern.columnIndices.size(), 24U * 24U);
|
||||
for (std::size_t row = 0U; row < dofs.fullDofCount(); ++row) {
|
||||
EXPECT_EQ(pattern.rowOffsets[row], row * 24U);
|
||||
EXPECT_EQ(pattern.rowOffsets[row + 1U], (row + 1U) * 24U);
|
||||
const auto columns = rowColumns(pattern, row);
|
||||
ASSERT_EQ(columns.size(), 24U);
|
||||
for (std::size_t column = 0U; column < columns.size(); ++column) {
|
||||
EXPECT_EQ(columns[column], column);
|
||||
}
|
||||
EXPECT_TRUE(std::binary_search(columns.begin(), columns.end(), row));
|
||||
EXPECT_EQ(std::adjacent_find(columns.begin(), columns.end()), columns.end());
|
||||
ASSERT_EQ(pattern.row_offsets.size(), 25U);
|
||||
ASSERT_EQ(pattern.column_indices.size(), 24U * 24U);
|
||||
for (std::size_t row = 0U; row < dofs.FullDofCount(); ++row) {
|
||||
EXPECT_EQ(pattern.row_offsets[row], row * 24U);
|
||||
EXPECT_EQ(pattern.row_offsets[row + 1U], (row + 1U) * 24U);
|
||||
const auto columns = RowColumns(pattern, row);
|
||||
ASSERT_EQ(columns.size(), 24U);
|
||||
for (std::size_t column = 0U; column < columns.size(); ++column) {
|
||||
EXPECT_EQ(columns[column], column);
|
||||
}
|
||||
EXPECT_TRUE(std::binary_search(columns.begin(), columns.end(), row));
|
||||
EXPECT_EQ(std::adjacent_find(columns.begin(), columns.end()),
|
||||
columns.end());
|
||||
}
|
||||
}
|
||||
|
||||
TEST(DofManager, ReconstructsFullReducedRoundTrip) {
|
||||
const auto fixture = makeDofFixture();
|
||||
const auto& dofs = fixture.dofs;
|
||||
fesa::Vector full{dofs.fullDofCount()};
|
||||
for (std::size_t index = 0U; index < full.Size(); ++index) {
|
||||
full[index] = static_cast<double>(index) + 0.5;
|
||||
}
|
||||
for (std::size_t index = 0U; index < dofs.constrainedDofCount(); ++index) {
|
||||
full[dofs.constrainedDofs()[index]] = dofs.prescribedValues()[index];
|
||||
}
|
||||
const auto fixture = MakeDofFixture();
|
||||
const auto& dofs = fixture.dofs;
|
||||
fesa::Vector full{dofs.FullDofCount()};
|
||||
for (std::size_t index = 0U; index < full.Size(); ++index) {
|
||||
full[index] = static_cast<double>(index) + 0.5;
|
||||
}
|
||||
for (std::size_t index = 0U; index < dofs.ConstrainedDofCount(); ++index) {
|
||||
full[dofs.ConstrainedDofs()[index]] = dofs.PrescribedValues()[index];
|
||||
}
|
||||
|
||||
fesa::Vector reduced{dofs.freeDofCount()};
|
||||
for (std::size_t equation = 0U; equation < reduced.Size(); ++equation) {
|
||||
reduced[equation] = full[dofs.freeDofs()[equation]];
|
||||
}
|
||||
fesa::Vector reconstructed{dofs.fullDofCount()};
|
||||
for (std::size_t equation = 0U; equation < reduced.Size(); ++equation) {
|
||||
reconstructed[dofs.freeDofs()[equation]] = reduced[equation];
|
||||
}
|
||||
for (std::size_t index = 0U; index < dofs.constrainedDofCount(); ++index) {
|
||||
reconstructed[dofs.constrainedDofs()[index]] = dofs.prescribedValues()[index];
|
||||
}
|
||||
fesa::Vector reduced{dofs.FreeDofCount()};
|
||||
for (std::size_t equation = 0U; equation < reduced.Size(); ++equation) {
|
||||
reduced[equation] = full[dofs.FreeDofs()[equation]];
|
||||
}
|
||||
fesa::Vector reconstructed{dofs.FullDofCount()};
|
||||
for (std::size_t equation = 0U; equation < reduced.Size(); ++equation) {
|
||||
reconstructed[dofs.FreeDofs()[equation]] = reduced[equation];
|
||||
}
|
||||
for (std::size_t index = 0U; index < dofs.ConstrainedDofCount(); ++index) {
|
||||
reconstructed[dofs.ConstrainedDofs()[index]] =
|
||||
dofs.PrescribedValues()[index];
|
||||
}
|
||||
|
||||
ASSERT_EQ(reconstructed.Size(), full.Size());
|
||||
for (std::size_t index = 0U; index < full.Size(); ++index) {
|
||||
EXPECT_DOUBLE_EQ(reconstructed[index], full[index]);
|
||||
}
|
||||
ASSERT_EQ(reconstructed.Size(), full.Size());
|
||||
for (std::size_t index = 0U; index < full.Size(); ++index) {
|
||||
EXPECT_DOUBLE_EQ(reconstructed[index], full[index]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
|
||||
#include "fesa/io/hdf5/hdf5_results_writer.hpp"
|
||||
|
||||
#include "fesa/analysis/analysis_model.hpp"
|
||||
#include "fesa/analysis/analysis_state.hpp"
|
||||
#include "fesa/analysis/analysis_model.h"
|
||||
#include "fesa/analysis/analysis_state.h"
|
||||
#include "fesa/build_info.h"
|
||||
#include "fesa/fem/dof_manager.hpp"
|
||||
#include "fesa/fem/dof_manager.h"
|
||||
#include "fesa/model/domain.h"
|
||||
|
||||
#include <hdf5.h>
|
||||
@@ -164,30 +164,30 @@ WriterFixture makeFixture(
|
||||
auto domain = std::make_unique<fesa::Domain>(
|
||||
std::move(domainResult.Value()));
|
||||
|
||||
auto modelResult = fesa::AnalysisModel::create(*domain);
|
||||
auto modelResult = fesa::AnalysisModel::Create(*domain);
|
||||
if (!modelResult.HasValue()) {
|
||||
throw std::runtime_error{"Writer fixture AnalysisModel construction failed."};
|
||||
}
|
||||
const fesa::AnalysisModel model = std::move(modelResult.Value());
|
||||
auto dofsResult = fesa::DofManager::create(model);
|
||||
auto dofsResult = fesa::DofManager::Create(model);
|
||||
if (!dofsResult.HasValue()) {
|
||||
throw std::runtime_error{"Writer fixture DofManager construction failed."};
|
||||
}
|
||||
auto dofs = std::make_unique<fesa::DofManager>(
|
||||
std::move(dofsResult.Value()));
|
||||
auto state = std::make_unique<fesa::AnalysisState>(
|
||||
fesa::AnalysisState::create(*dofs, {"Step-1", 0U}));
|
||||
fesa::AnalysisState::Create(*dofs, {"Step-1", 0U}));
|
||||
|
||||
for (std::size_t index = 0U; index < state->displacement().Size(); ++index) {
|
||||
state->displacement()[index] = 0.25 + static_cast<double>(index);
|
||||
state->externalForce()[index] = 100.0 + static_cast<double>(index);
|
||||
state->internalForce()[index] = 200.0 + 2.0 * static_cast<double>(index);
|
||||
state->residual()[index] = 100.0 + static_cast<double>(index);
|
||||
state->reaction()[index] = 100.0 + static_cast<double>(index);
|
||||
for (std::size_t index = 0U; index < state->Displacement().Size(); ++index) {
|
||||
state->Displacement()[index] = 0.25 + static_cast<double>(index);
|
||||
state->ExternalForce()[index] = 100.0 + static_cast<double>(index);
|
||||
state->InternalForce()[index] = 200.0 + 2.0 * static_cast<double>(index);
|
||||
state->Residual()[index] = 100.0 + static_cast<double>(index);
|
||||
state->Reaction()[index] = 100.0 + static_cast<double>(index);
|
||||
}
|
||||
|
||||
const auto& nodes = domain->Nodes();
|
||||
state->endpointResults() = {
|
||||
state->EndpointResults() = {
|
||||
{0U,
|
||||
0,
|
||||
nodes[0U].source_id,
|
||||
@@ -198,15 +198,15 @@ WriterFixture makeFixture(
|
||||
nodes[1U].source_id,
|
||||
{7.0, 8.0, 9.0, 10.0, 11.0, 12.0},
|
||||
{15.0, 16.0, 17.0, 18.0}}};
|
||||
state->gaussResults() = {
|
||||
state->GaussResults() = {
|
||||
{0U, 1, {0.01, 0.02, 0.03, 0.04}, {21.0, 22.0, 23.0, 24.0}},
|
||||
{0U, 2, {0.05, 0.06, 0.07, 0.08}, {25.0, 26.0, 27.0, 28.0}}};
|
||||
if (useDefaultCentroid) {
|
||||
state->stressResults() = {
|
||||
state->StressResults() = {
|
||||
{0U, 1, 0U, 0.0, 0.0, 31.0, "fesa-default"},
|
||||
{0U, 2, 0U, 0.0, 0.0, 32.0, "fesa-default"}};
|
||||
} else {
|
||||
state->stressResults() = {
|
||||
state->StressResults() = {
|
||||
{0U, 1, 1U, -0.1, 0.2, 31.0, "input"},
|
||||
{0U, 1, 2U, 0.3, -0.4, 32.0, "input"},
|
||||
{0U, 2, 1U, -0.1, 0.2, 33.0, "input"},
|
||||
@@ -264,25 +264,25 @@ WriterFixture makeShellFixture(const std::filesystem::path& source) {
|
||||
}
|
||||
auto domain = std::make_unique<fesa::Domain>(
|
||||
std::move(domainResult.Value()));
|
||||
auto modelResult = fesa::AnalysisModel::create(*domain);
|
||||
auto modelResult = fesa::AnalysisModel::Create(*domain);
|
||||
if (!modelResult.HasValue()) {
|
||||
throw std::runtime_error{"Shell writer fixture AnalysisModel construction failed."};
|
||||
}
|
||||
const fesa::AnalysisModel model = std::move(modelResult.Value());
|
||||
auto dofsResult = fesa::DofManager::create(model);
|
||||
auto dofsResult = fesa::DofManager::Create(model);
|
||||
if (!dofsResult.HasValue()) {
|
||||
throw std::runtime_error{"Shell writer fixture DofManager construction failed."};
|
||||
}
|
||||
auto dofs = std::make_unique<fesa::DofManager>(
|
||||
std::move(dofsResult.Value()));
|
||||
auto state = std::make_unique<fesa::AnalysisState>(
|
||||
fesa::AnalysisState::create(*dofs, {"Step-1", 0U}));
|
||||
for (std::size_t index = 0U; index < state->displacement().Size(); ++index) {
|
||||
state->displacement()[index] = 0.01 * static_cast<double>(index + 1U);
|
||||
state->externalForce()[index] = 10.0 + static_cast<double>(index);
|
||||
state->internalForce()[index] = 20.0 + static_cast<double>(index);
|
||||
state->residual()[index] = 30.0 + static_cast<double>(index);
|
||||
state->reaction()[index] = 40.0 + static_cast<double>(index);
|
||||
fesa::AnalysisState::Create(*dofs, {"Step-1", 0U}));
|
||||
for (std::size_t index = 0U; index < state->Displacement().Size(); ++index) {
|
||||
state->Displacement()[index] = 0.01 * static_cast<double>(index + 1U);
|
||||
state->ExternalForce()[index] = 10.0 + static_cast<double>(index);
|
||||
state->InternalForce()[index] = 20.0 + static_cast<double>(index);
|
||||
state->Residual()[index] = 30.0 + static_cast<double>(index);
|
||||
state->Reaction()[index] = 40.0 + static_cast<double>(index);
|
||||
}
|
||||
|
||||
const double gauss = 1.0 / std::sqrt(3.0);
|
||||
@@ -292,10 +292,10 @@ WriterFixture makeShellFixture(const std::filesystem::path& source) {
|
||||
{gauss, gauss},
|
||||
{-gauss, gauss}}};
|
||||
const std::array<fesa::ShellMidsurfaceLocation, 4> locations{
|
||||
fesa::ShellMidsurfaceLocation::gp1,
|
||||
fesa::ShellMidsurfaceLocation::gp2,
|
||||
fesa::ShellMidsurfaceLocation::gp3,
|
||||
fesa::ShellMidsurfaceLocation::gp4};
|
||||
fesa::ShellMidsurfaceLocation::kGp1,
|
||||
fesa::ShellMidsurfaceLocation::kGp2,
|
||||
fesa::ShellMidsurfaceLocation::kGp3,
|
||||
fesa::ShellMidsurfaceLocation::kGp4};
|
||||
fesa::ShellStateCandidate candidate{};
|
||||
for (std::size_t point = 0U; point < locations.size(); ++point) {
|
||||
const double base = 100.0 * static_cast<double>(point + 1U);
|
||||
@@ -310,20 +310,20 @@ WriterFixture makeShellFixture(const std::filesystem::path& source) {
|
||||
base + 5.0, base + 6.0, base + 7.0, base + 8.0},
|
||||
{base + 11.0, base + 12.0, base + 13.0, base + 14.0,
|
||||
base + 15.0, base + 16.0, base + 17.0, base + 18.0},
|
||||
{{{fesa::ShellSectionPosition::bottom,
|
||||
{{{fesa::ShellSectionPosition::kBottom,
|
||||
-1.0,
|
||||
{base + 21.0, base + 22.0, base + 23.0}},
|
||||
{fesa::ShellSectionPosition::middle,
|
||||
{fesa::ShellSectionPosition::kMiddle,
|
||||
0.0,
|
||||
{base + 24.0, base + 25.0, base + 26.0}},
|
||||
{fesa::ShellSectionPosition::top,
|
||||
{fesa::ShellSectionPosition::kTop,
|
||||
1.0,
|
||||
{base + 27.0, base + 28.0, base + 29.0}}}}});
|
||||
}
|
||||
candidate.physicalStrainEnergy = 123.5;
|
||||
candidate.physical_strain_energy = 123.5;
|
||||
candidate.equilibrium = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0};
|
||||
candidate.verificationMetrics = {1.0e-13, 2.0e-13, 3.0e-13};
|
||||
const fesa::Status commit = state->commitShellResults(
|
||||
candidate.verification_metrics = {1.0e-13, 2.0e-13, 3.0e-13};
|
||||
const fesa::Status commit = state->CommitShellResults(
|
||||
{0U}, std::move(candidate));
|
||||
if (!commit.IsOk()) {
|
||||
throw std::runtime_error{"Shell writer fixture state commit failed."};
|
||||
@@ -846,7 +846,7 @@ TEST(Hdf5ResultsWriter, WritesExactSchemaShapesAttributesAndIdentity) {
|
||||
const auto output = directory.path() / "results.h5";
|
||||
|
||||
fesa::Hdf5ResultsWriter writer;
|
||||
ASSERT_TRUE(writer.write(output, *fixture.domain, *fixture.state, {}).IsOk());
|
||||
ASSERT_TRUE(writer.Write(output, *fixture.domain, *fixture.state, {}).IsOk());
|
||||
ASSERT_GT(H5Fis_hdf5(output.string().c_str()), 0);
|
||||
|
||||
const auto file = openFile(output);
|
||||
@@ -1041,7 +1041,7 @@ TEST(Hdf5ResultsWriter, WritesMandatoryOutputsDespiteOutputRequests) {
|
||||
|
||||
fesa::Hdf5ResultsWriter writer;
|
||||
ASSERT_TRUE(
|
||||
writer.write(output, *fixture.domain, *fixture.state, {ignoredRequest})
|
||||
writer.Write(output, *fixture.domain, *fixture.state, {ignoredRequest})
|
||||
.IsOk());
|
||||
const auto file = openFile(output);
|
||||
for (const char* suffix : {
|
||||
@@ -1078,7 +1078,7 @@ TEST(Hdf5ResultsWriter, WritesWarningsAndDefaultCentroid) {
|
||||
const auto output = directory.path() / "results.h5";
|
||||
|
||||
fesa::Hdf5ResultsWriter writer;
|
||||
ASSERT_TRUE(writer.write(output, *fixture.domain, *fixture.state, diagnostics).IsOk());
|
||||
ASSERT_TRUE(writer.Write(output, *fixture.domain, *fixture.state, diagnostics).IsOk());
|
||||
const auto file = openFile(output);
|
||||
auto stressRows = readStressRows(file.get());
|
||||
ASSERT_EQ(stressRows.size(), 2U);
|
||||
@@ -1116,15 +1116,15 @@ TEST(Hdf5ResultsWriter, FailureLeavesNoPartialAndPreservesExistingFinal) {
|
||||
auto fixture = makeFixture(directory.path() / "failure.inp");
|
||||
fesa::Hdf5ResultsWriter writer;
|
||||
|
||||
fixture.state->displacement()[0U] =
|
||||
fixture.state->Displacement()[0U] =
|
||||
std::numeric_limits<double>::quiet_NaN();
|
||||
const auto invalidOutput = directory.path() / "invalid-results.h5";
|
||||
expectOutputFailure(
|
||||
writer.write(invalidOutput, *fixture.domain, *fixture.state, {}),
|
||||
writer.Write(invalidOutput, *fixture.domain, *fixture.state, {}),
|
||||
"invalid-result-state");
|
||||
EXPECT_FALSE(std::filesystem::exists(invalidOutput));
|
||||
EXPECT_EQ(entryCount(directory.path()), 0U);
|
||||
fixture.state->displacement()[0U] = 0.25;
|
||||
fixture.state->Displacement()[0U] = 0.25;
|
||||
|
||||
const auto final = directory.path() / "results.h5";
|
||||
const std::vector<char> sentinel = {'p', 'r', 'e', 'v', 'i', 'o', 'u', 's'};
|
||||
@@ -1140,7 +1140,7 @@ TEST(Hdf5ResultsWriter, FailureLeavesNoPartialAndPreservesExistingFinal) {
|
||||
ASSERT_NE(lock.get(), INVALID_HANDLE_VALUE);
|
||||
|
||||
expectOutputFailure(
|
||||
writer.write(final, *fixture.domain, *fixture.state, {}),
|
||||
writer.Write(final, *fixture.domain, *fixture.state, {}),
|
||||
"hdf5-finalization-failure");
|
||||
EXPECT_EQ(readBytes(final), sentinel);
|
||||
EXPECT_EQ(entryCount(directory.path()), 1U);
|
||||
@@ -1153,7 +1153,7 @@ TEST(Hdf5ResultsWriter, SuccessfullyReplacesExistingFinal) {
|
||||
writeBytes(final, {'o', 'l', 'd'});
|
||||
|
||||
fesa::Hdf5ResultsWriter writer;
|
||||
ASSERT_TRUE(writer.write(final, *fixture.domain, *fixture.state, {}).IsOk());
|
||||
ASSERT_TRUE(writer.Write(final, *fixture.domain, *fixture.state, {}).IsOk());
|
||||
EXPECT_GT(H5Fis_hdf5(final.string().c_str()), 0);
|
||||
EXPECT_EQ(entryCount(directory.path()), 1U);
|
||||
const auto file = openFile(final);
|
||||
@@ -1171,7 +1171,7 @@ TEST(Hdf5ResultsWriter, WritesExactShellMetadataAndModelIdentity) {
|
||||
const auto output = directory.path() / "results.h5";
|
||||
|
||||
fesa::Hdf5ResultsWriter writer;
|
||||
ASSERT_TRUE(writer.write(output, *fixture.domain, *fixture.state, {}).IsOk());
|
||||
ASSERT_TRUE(writer.Write(output, *fixture.domain, *fixture.state, {}).IsOk());
|
||||
const auto file = openFile(output);
|
||||
|
||||
Hdf5Handle metadata{
|
||||
@@ -1261,7 +1261,7 @@ TEST(Hdf5ResultsWriter, WritesExactMandatoryShellResultInventory) {
|
||||
const auto output = directory.path() / "results.h5";
|
||||
|
||||
fesa::Hdf5ResultsWriter writer;
|
||||
ASSERT_TRUE(writer.write(output, *fixture.domain, *fixture.state, {}).IsOk());
|
||||
ASSERT_TRUE(writer.Write(output, *fixture.domain, *fixture.state, {}).IsOk());
|
||||
const auto file = openFile(output);
|
||||
const std::string shellRoot = std::string{kStepRoot} + "/element/shell";
|
||||
expectNumericDataset(
|
||||
@@ -1329,7 +1329,7 @@ TEST(Hdf5ResultsWriter, WritesShellInventoryDespiteRequestsAndOmitsForbiddenPath
|
||||
|
||||
fesa::Hdf5ResultsWriter writer;
|
||||
ASSERT_TRUE(
|
||||
writer.write(output, *fixture.domain, *fixture.state, {ignoredRequest})
|
||||
writer.Write(output, *fixture.domain, *fixture.state, {ignoredRequest})
|
||||
.IsOk());
|
||||
const auto file = openFile(output);
|
||||
for (const char* suffix : {
|
||||
@@ -1359,7 +1359,7 @@ TEST(Hdf5ResultsWriter, WritesShellInventoryDespiteRequestsAndOmitsForbiddenPath
|
||||
TEST(Hdf5ResultsWriter, InvalidShellInventoryPreservesExistingFinal) {
|
||||
TempDirectory directory{"shell-atomic"};
|
||||
auto fixture = makeShellFixture(directory.path() / "shell.inp");
|
||||
auto invalidState = fesa::AnalysisState::create(
|
||||
auto invalidState = fesa::AnalysisState::Create(
|
||||
*fixture.dofs, {"Step-1", 0U});
|
||||
const auto final = directory.path() / "results.h5";
|
||||
const std::vector<char> sentinel = {'s', 'h', 'e', 'l', 'l'};
|
||||
@@ -1367,7 +1367,7 @@ TEST(Hdf5ResultsWriter, InvalidShellInventoryPreservesExistingFinal) {
|
||||
|
||||
fesa::Hdf5ResultsWriter writer;
|
||||
expectOutputFailure(
|
||||
writer.write(final, *fixture.domain, invalidState, {}),
|
||||
writer.Write(final, *fixture.domain, invalidState, {}),
|
||||
"invalid-result-rows");
|
||||
EXPECT_EQ(readBytes(final), sentinel);
|
||||
EXPECT_EQ(entryCount(directory.path()), 1U);
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "fesa/fem/dof_manager.hpp"
|
||||
#include "fesa/fem/dof_manager.h"
|
||||
#include "fesa/math/matrix.h"
|
||||
|
||||
namespace {
|
||||
@@ -37,8 +37,8 @@ TEST(SparseAssembly, ValidatesKnownCsrAndMultiply) {
|
||||
|
||||
EXPECT_EQ(matrix.Rows(), 4U);
|
||||
EXPECT_EQ(matrix.Columns(), 4U);
|
||||
EXPECT_EQ(matrix.RowOffsets(), pattern.rowOffsets);
|
||||
EXPECT_EQ(matrix.ColumnIndices(), pattern.columnIndices);
|
||||
EXPECT_EQ(matrix.RowOffsets(), pattern.row_offsets);
|
||||
EXPECT_EQ(matrix.ColumnIndices(), pattern.column_indices);
|
||||
EXPECT_EQ(matrix.Values(), (std::vector<double>{1.0, 2.0, 3.0, 4.0, 5.0}));
|
||||
EXPECT_TRUE(matrix.Validate().IsOk());
|
||||
|
||||
@@ -122,8 +122,8 @@ TEST(SparseAssembly, PreservesExpectedStructuralZeros) {
|
||||
auto result =
|
||||
SparseMatrix::FromCoo(3U, 3U, std::move(contributions), pattern);
|
||||
ASSERT_TRUE(result.HasValue());
|
||||
EXPECT_EQ(result.Value().RowOffsets(), pattern.rowOffsets);
|
||||
EXPECT_EQ(result.Value().ColumnIndices(), pattern.columnIndices);
|
||||
EXPECT_EQ(result.Value().RowOffsets(), pattern.row_offsets);
|
||||
EXPECT_EQ(result.Value().ColumnIndices(), pattern.column_indices);
|
||||
EXPECT_EQ(result.Value().Values(),
|
||||
(std::vector<double>{2.0, 0.0, 0.0, 0.0, 0.0}));
|
||||
EXPECT_EQ(std::count(result.Value().Values().begin(),
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#include "fesa/analysis/analysis_state.hpp"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <array>
|
||||
@@ -9,329 +7,281 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "fesa/analysis/analysis_state.h"
|
||||
|
||||
namespace {
|
||||
|
||||
fesa::DofManager makeEmptyDofs() {
|
||||
fesa::ModelDefinition definition{};
|
||||
definition.source_path = "models/result-records.inp";
|
||||
definition.source_content_identity = "fnv1a64:0123456789abcdef";
|
||||
definition.steps = {{
|
||||
"Step-1", {}, {}, 0.1, 1.0, 0.01, 1.0,
|
||||
{definition.source_path, 10U}}};
|
||||
fesa::DofManager MakeEmptyDofs() {
|
||||
fesa::ModelDefinition definition{};
|
||||
definition.source_path = "models/result-records.inp";
|
||||
definition.source_content_identity = "fnv1a64:0123456789abcdef";
|
||||
definition.steps = {
|
||||
{"Step-1", {}, {}, 0.1, 1.0, 0.01, 1.0, {definition.source_path, 10U}}};
|
||||
|
||||
auto domain = fesa::Domain::Create(std::move(definition));
|
||||
EXPECT_TRUE(domain.HasValue());
|
||||
auto model = fesa::AnalysisModel::create(domain.Value());
|
||||
EXPECT_TRUE(model.HasValue());
|
||||
auto dofs = fesa::DofManager::create(model.Value());
|
||||
EXPECT_TRUE(dofs.HasValue());
|
||||
return std::move(dofs.Value());
|
||||
auto domain = fesa::Domain::Create(std::move(definition));
|
||||
EXPECT_TRUE(domain.HasValue());
|
||||
auto model = fesa::AnalysisModel::Create(domain.Value());
|
||||
EXPECT_TRUE(model.HasValue());
|
||||
auto dofs = fesa::DofManager::Create(model.Value());
|
||||
EXPECT_TRUE(dofs.HasValue());
|
||||
return std::move(dofs.Value());
|
||||
}
|
||||
|
||||
fesa::ShellResultRow makeShellRow(
|
||||
fesa::EntityIndex element,
|
||||
fesa::ShellMidsurfaceLocation location,
|
||||
std::array<double, 2> naturalCoordinates,
|
||||
double seed) {
|
||||
return {
|
||||
element,
|
||||
location,
|
||||
naturalCoordinates,
|
||||
{{{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}},
|
||||
{seed + 1.0,
|
||||
seed + 2.0,
|
||||
seed + 3.0,
|
||||
seed + 4.0,
|
||||
seed + 5.0,
|
||||
seed + 6.0,
|
||||
seed + 7.0,
|
||||
seed + 8.0},
|
||||
{seed + 11.0,
|
||||
seed + 12.0,
|
||||
seed + 13.0,
|
||||
seed + 14.0,
|
||||
seed + 15.0,
|
||||
seed + 16.0,
|
||||
seed + 17.0,
|
||||
seed + 18.0},
|
||||
{{{fesa::ShellSectionPosition::bottom,
|
||||
-1.0,
|
||||
{seed + 21.0, seed + 22.0, seed + 23.0}},
|
||||
{fesa::ShellSectionPosition::middle,
|
||||
0.0,
|
||||
{seed + 24.0, seed + 25.0, seed + 26.0}},
|
||||
{fesa::ShellSectionPosition::top,
|
||||
1.0,
|
||||
{seed + 27.0, seed + 28.0, seed + 29.0}}}}};
|
||||
fesa::ShellResultRow MakeShellRow(fesa::EntityIndex element,
|
||||
fesa::ShellMidsurfaceLocation location,
|
||||
std::array<double, 2> natural_coordinates,
|
||||
double seed) {
|
||||
return {element,
|
||||
location,
|
||||
natural_coordinates,
|
||||
{{{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}},
|
||||
{seed + 1.0, seed + 2.0, seed + 3.0, seed + 4.0, seed + 5.0,
|
||||
seed + 6.0, seed + 7.0, seed + 8.0},
|
||||
{seed + 11.0, seed + 12.0, seed + 13.0, seed + 14.0, seed + 15.0,
|
||||
seed + 16.0, seed + 17.0, seed + 18.0},
|
||||
{{{fesa::ShellSectionPosition::kBottom,
|
||||
-1.0,
|
||||
{seed + 21.0, seed + 22.0, seed + 23.0}},
|
||||
{fesa::ShellSectionPosition::kMiddle,
|
||||
0.0,
|
||||
{seed + 24.0, seed + 25.0, seed + 26.0}},
|
||||
{fesa::ShellSectionPosition::kTop,
|
||||
1.0,
|
||||
{seed + 27.0, seed + 28.0, seed + 29.0}}}}};
|
||||
}
|
||||
|
||||
fesa::ShellStateCandidate makeShellCandidate(
|
||||
fesa::ShellStateCandidate MakeShellCandidate(
|
||||
const std::vector<fesa::EntityIndex>& elements) {
|
||||
const double gauss = 1.0 / std::sqrt(3.0);
|
||||
const std::array<fesa::ShellMidsurfaceLocation, 4> locations{
|
||||
fesa::ShellMidsurfaceLocation::gp1,
|
||||
fesa::ShellMidsurfaceLocation::gp2,
|
||||
fesa::ShellMidsurfaceLocation::gp3,
|
||||
fesa::ShellMidsurfaceLocation::gp4};
|
||||
const std::array<std::array<double, 2>, 4> coordinates{
|
||||
std::array<double, 2>{-gauss, -gauss},
|
||||
std::array<double, 2>{gauss, -gauss},
|
||||
std::array<double, 2>{gauss, gauss},
|
||||
std::array<double, 2>{-gauss, gauss}};
|
||||
const double gauss = 1.0 / std::sqrt(3.0);
|
||||
const std::array<fesa::ShellMidsurfaceLocation, 4> locations{
|
||||
fesa::ShellMidsurfaceLocation::kGp1, fesa::ShellMidsurfaceLocation::kGp2,
|
||||
fesa::ShellMidsurfaceLocation::kGp3, fesa::ShellMidsurfaceLocation::kGp4};
|
||||
const std::array<std::array<double, 2>, 4> coordinates{
|
||||
std::array<double, 2>{-gauss, -gauss},
|
||||
std::array<double, 2>{gauss, -gauss}, std::array<double, 2>{gauss, gauss},
|
||||
std::array<double, 2>{-gauss, gauss}};
|
||||
|
||||
fesa::ShellStateCandidate candidate{};
|
||||
for (const auto element : elements) {
|
||||
for (std::size_t point = 0U; point < locations.size(); ++point) {
|
||||
candidate.rows.push_back(makeShellRow(
|
||||
element,
|
||||
locations[point],
|
||||
coordinates[point],
|
||||
100.0 * static_cast<double>(element) +
|
||||
10.0 * static_cast<double>(point)));
|
||||
}
|
||||
fesa::ShellStateCandidate candidate{};
|
||||
for (const auto element : elements) {
|
||||
for (std::size_t point = 0U; point < locations.size(); ++point) {
|
||||
candidate.rows.push_back(
|
||||
MakeShellRow(element, locations[point], coordinates[point],
|
||||
100.0 * static_cast<double>(element) +
|
||||
10.0 * static_cast<double>(point)));
|
||||
}
|
||||
candidate.physicalStrainEnergy = 35.5;
|
||||
candidate.equilibrium = {1.0, -2.0, 3.0, -4.0, 5.0, -6.0};
|
||||
candidate.verificationMetrics = {1.0e-11, 2.0e-11, 3.0e-11};
|
||||
return candidate;
|
||||
}
|
||||
candidate.physical_strain_energy = 35.5;
|
||||
candidate.equilibrium = {1.0, -2.0, 3.0, -4.0, 5.0, -6.0};
|
||||
candidate.verification_metrics = {1.0e-11, 2.0e-11, 3.0e-11};
|
||||
return candidate;
|
||||
}
|
||||
|
||||
void expectShellStateEquals(
|
||||
const fesa::AnalysisState& state,
|
||||
const std::vector<fesa::ShellResultRow>& rows,
|
||||
double physicalStrainEnergy,
|
||||
const std::array<double, 6>& equilibrium,
|
||||
const std::array<double, 3>& verificationMetrics) {
|
||||
ASSERT_EQ(state.shellResults().size(), rows.size());
|
||||
for (std::size_t row = 0U; row < rows.size(); ++row) {
|
||||
EXPECT_EQ(state.shellResults()[row].element, rows[row].element);
|
||||
EXPECT_EQ(state.shellResults()[row].location, rows[row].location);
|
||||
EXPECT_EQ(
|
||||
state.shellResults()[row].naturalCoordinates,
|
||||
rows[row].naturalCoordinates);
|
||||
EXPECT_EQ(state.shellResults()[row].localFrame, rows[row].localFrame);
|
||||
EXPECT_EQ(
|
||||
state.shellResults()[row].generalizedStrain,
|
||||
rows[row].generalizedStrain);
|
||||
EXPECT_EQ(
|
||||
state.shellResults()[row].sectionResultant,
|
||||
rows[row].sectionResultant);
|
||||
for (std::size_t position = 0U;
|
||||
position < rows[row].stress.size();
|
||||
++position) {
|
||||
EXPECT_EQ(
|
||||
state.shellResults()[row].stress[position].position,
|
||||
void ExpectShellStateEquals(const fesa::AnalysisState& state,
|
||||
const std::vector<fesa::ShellResultRow>& rows,
|
||||
double physical_strain_energy,
|
||||
const std::array<double, 6>& equilibrium,
|
||||
const std::array<double, 3>& verification_metrics) {
|
||||
ASSERT_EQ(state.ShellResults().size(), rows.size());
|
||||
for (std::size_t row = 0U; row < rows.size(); ++row) {
|
||||
EXPECT_EQ(state.ShellResults()[row].element, rows[row].element);
|
||||
EXPECT_EQ(state.ShellResults()[row].location, rows[row].location);
|
||||
EXPECT_EQ(state.ShellResults()[row].natural_coordinates,
|
||||
rows[row].natural_coordinates);
|
||||
EXPECT_EQ(state.ShellResults()[row].local_frame, rows[row].local_frame);
|
||||
EXPECT_EQ(state.ShellResults()[row].generalized_strain,
|
||||
rows[row].generalized_strain);
|
||||
EXPECT_EQ(state.ShellResults()[row].section_resultant,
|
||||
rows[row].section_resultant);
|
||||
for (std::size_t position = 0U; position < rows[row].stress.size();
|
||||
++position) {
|
||||
EXPECT_EQ(state.ShellResults()[row].stress[position].position,
|
||||
rows[row].stress[position].position);
|
||||
EXPECT_DOUBLE_EQ(
|
||||
state.shellResults()[row].stress[position].zeta,
|
||||
rows[row].stress[position].zeta);
|
||||
EXPECT_EQ(
|
||||
state.shellResults()[row].stress[position].components,
|
||||
EXPECT_DOUBLE_EQ(state.ShellResults()[row].stress[position].zeta,
|
||||
rows[row].stress[position].zeta);
|
||||
EXPECT_EQ(state.ShellResults()[row].stress[position].components,
|
||||
rows[row].stress[position].components);
|
||||
}
|
||||
}
|
||||
EXPECT_DOUBLE_EQ(state.physicalStrainEnergy(), physicalStrainEnergy);
|
||||
EXPECT_EQ(state.equilibrium(), equilibrium);
|
||||
EXPECT_EQ(state.verificationMetrics(), verificationMetrics);
|
||||
}
|
||||
EXPECT_DOUBLE_EQ(state.PhysicalStrainEnergy(), physical_strain_energy);
|
||||
EXPECT_EQ(state.Equilibrium(), equilibrium);
|
||||
EXPECT_EQ(state.VerificationMetrics(), verification_metrics);
|
||||
}
|
||||
|
||||
void expectShellCandidateRejectedWithoutMutation(
|
||||
void ExpectShellCandidateRejectedWithoutMutation(
|
||||
fesa::AnalysisState& state,
|
||||
const std::vector<fesa::EntityIndex>& expectedElements,
|
||||
const std::vector<fesa::EntityIndex>& expected_elements,
|
||||
const fesa::ShellStateCandidate& candidate,
|
||||
const fesa::ShellStateCandidate& committed) {
|
||||
const auto status = state.commitShellResults(expectedElements, candidate);
|
||||
EXPECT_FALSE(status.IsOk());
|
||||
EXPECT_EQ(status.Category(), fesa::FailureCategory::kModel);
|
||||
expectShellStateEquals(
|
||||
state,
|
||||
committed.rows,
|
||||
committed.physicalStrainEnergy,
|
||||
committed.equilibrium,
|
||||
committed.verificationMetrics);
|
||||
ASSERT_TRUE(state.commitShellResults(expectedElements, committed).IsOk());
|
||||
const auto status = state.CommitShellResults(expected_elements, candidate);
|
||||
EXPECT_FALSE(status.IsOk());
|
||||
EXPECT_EQ(status.Category(), fesa::FailureCategory::kModel);
|
||||
ExpectShellStateEquals(state, committed.rows,
|
||||
committed.physical_strain_energy,
|
||||
committed.equilibrium, committed.verification_metrics);
|
||||
ASSERT_TRUE(state.CommitShellResults(expected_elements, committed).IsOk());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
TEST(AnalysisState, PreservesStepFrameAndStableRowOrder) {
|
||||
const auto dofs = makeEmptyDofs();
|
||||
auto state = fesa::AnalysisState::create(dofs, {"Step-1", 0U});
|
||||
const auto dofs = MakeEmptyDofs();
|
||||
auto state = fesa::AnalysisState::Create(dofs, {"Step-1", 0U});
|
||||
|
||||
const fesa::EndpointResultRow firstEndpoint{
|
||||
2U,
|
||||
-1,
|
||||
{"Beam-1", 10, "010"},
|
||||
{1.0, 2.0, 3.0, 4.0, 5.0, 6.0},
|
||||
{7.0, 8.0, 9.0, 10.0}};
|
||||
const fesa::EndpointResultRow secondEndpoint{
|
||||
2U,
|
||||
1,
|
||||
{"Beam-1", 20, "020"},
|
||||
{11.0, 12.0, 13.0, 14.0, 15.0, 16.0},
|
||||
{17.0, 18.0, 19.0, 20.0}};
|
||||
const fesa::GaussResultRow firstGauss{
|
||||
2U, 1, {0.1, 0.2, 0.3, 0.4}, {1.1, 1.2, 1.3, 1.4}};
|
||||
const fesa::GaussResultRow secondGauss{
|
||||
2U, 2, {0.5, 0.6, 0.7, 0.8}, {1.5, 1.6, 1.7, 1.8}};
|
||||
const fesa::StressS11Row firstStress{
|
||||
2U, 1, 1U, -0.25, 0.5, 12.5, "input"};
|
||||
const fesa::StressS11Row secondStress{
|
||||
2U, 1, 2U, 0.25, -0.5, -7.5, "input"};
|
||||
const fesa::EndpointResultRow first_endpoint{2U,
|
||||
-1,
|
||||
{"Beam-1", 10, "010"},
|
||||
{1.0, 2.0, 3.0, 4.0, 5.0, 6.0},
|
||||
{7.0, 8.0, 9.0, 10.0}};
|
||||
const fesa::EndpointResultRow second_endpoint{
|
||||
2U,
|
||||
1,
|
||||
{"Beam-1", 20, "020"},
|
||||
{11.0, 12.0, 13.0, 14.0, 15.0, 16.0},
|
||||
{17.0, 18.0, 19.0, 20.0}};
|
||||
const fesa::GaussResultRow first_gauss{
|
||||
2U, 1, {0.1, 0.2, 0.3, 0.4}, {1.1, 1.2, 1.3, 1.4}};
|
||||
const fesa::GaussResultRow second_gauss{
|
||||
2U, 2, {0.5, 0.6, 0.7, 0.8}, {1.5, 1.6, 1.7, 1.8}};
|
||||
const fesa::StressS11Row first_stress{2U, 1, 1U, -0.25, 0.5, 12.5, "input"};
|
||||
const fesa::StressS11Row second_stress{2U, 1, 2U, 0.25, -0.5, -7.5, "input"};
|
||||
|
||||
state.endpointResults().push_back(firstEndpoint);
|
||||
state.endpointResults().push_back(secondEndpoint);
|
||||
state.gaussResults().push_back(firstGauss);
|
||||
state.gaussResults().push_back(secondGauss);
|
||||
state.stressResults().push_back(firstStress);
|
||||
state.stressResults().push_back(secondStress);
|
||||
state.EndpointResults().push_back(first_endpoint);
|
||||
state.EndpointResults().push_back(second_endpoint);
|
||||
state.GaussResults().push_back(first_gauss);
|
||||
state.GaussResults().push_back(second_gauss);
|
||||
state.StressResults().push_back(first_stress);
|
||||
state.StressResults().push_back(second_stress);
|
||||
|
||||
const auto* const endpointStorage = state.endpointResults().data();
|
||||
const auto* const gaussStorage = state.gaussResults().data();
|
||||
const auto* const stressStorage = state.stressResults().data();
|
||||
const fesa::AnalysisState& constState = state;
|
||||
const auto* const endpoint_storage = state.EndpointResults().data();
|
||||
const auto* const gauss_storage = state.GaussResults().data();
|
||||
const auto* const stress_storage = state.StressResults().data();
|
||||
const fesa::AnalysisState& const_state = state;
|
||||
|
||||
EXPECT_EQ(constState.identity().stepName, "Step-1");
|
||||
EXPECT_EQ(constState.identity().frameIndex, 0U);
|
||||
ASSERT_EQ(constState.endpointResults().size(), 2U);
|
||||
EXPECT_EQ(constState.endpointResults().data(), endpointStorage);
|
||||
EXPECT_EQ(constState.endpointResults()[0].element, 2U);
|
||||
EXPECT_EQ(constState.endpointResults()[0].endpoint, -1);
|
||||
EXPECT_EQ(constState.endpointResults()[0].node.instance_name, "Beam-1");
|
||||
EXPECT_EQ(constState.endpointResults()[0].node.source_label, 10);
|
||||
EXPECT_EQ(constState.endpointResults()[0].node.source_label_text, "010");
|
||||
EXPECT_EQ(
|
||||
constState.endpointResults()[0].endAction,
|
||||
(std::array<double, 6>{1.0, 2.0, 3.0, 4.0, 5.0, 6.0}));
|
||||
EXPECT_EQ(
|
||||
constState.endpointResults()[1].sectionResultant,
|
||||
(std::array<double, 4>{17.0, 18.0, 19.0, 20.0}));
|
||||
EXPECT_EQ(const_state.Identity().step_name, "Step-1");
|
||||
EXPECT_EQ(const_state.Identity().frame_index, 0U);
|
||||
ASSERT_EQ(const_state.EndpointResults().size(), 2U);
|
||||
EXPECT_EQ(const_state.EndpointResults().data(), endpoint_storage);
|
||||
EXPECT_EQ(const_state.EndpointResults()[0].element, 2U);
|
||||
EXPECT_EQ(const_state.EndpointResults()[0].endpoint, -1);
|
||||
EXPECT_EQ(const_state.EndpointResults()[0].node.instance_name, "Beam-1");
|
||||
EXPECT_EQ(const_state.EndpointResults()[0].node.source_label, 10);
|
||||
EXPECT_EQ(const_state.EndpointResults()[0].node.source_label_text, "010");
|
||||
EXPECT_EQ(const_state.EndpointResults()[0].end_action,
|
||||
(std::array<double, 6>{1.0, 2.0, 3.0, 4.0, 5.0, 6.0}));
|
||||
EXPECT_EQ(const_state.EndpointResults()[1].section_resultant,
|
||||
(std::array<double, 4>{17.0, 18.0, 19.0, 20.0}));
|
||||
|
||||
ASSERT_EQ(constState.gaussResults().size(), 2U);
|
||||
EXPECT_EQ(constState.gaussResults().data(), gaussStorage);
|
||||
EXPECT_EQ(constState.gaussResults()[0].gaussPoint, 1);
|
||||
EXPECT_EQ(constState.gaussResults()[1].gaussPoint, 2);
|
||||
EXPECT_EQ(
|
||||
constState.gaussResults()[0].generalizedStrain,
|
||||
(std::array<double, 4>{0.1, 0.2, 0.3, 0.4}));
|
||||
EXPECT_EQ(
|
||||
constState.gaussResults()[1].generalizedResultant,
|
||||
(std::array<double, 4>{1.5, 1.6, 1.7, 1.8}));
|
||||
ASSERT_EQ(const_state.GaussResults().size(), 2U);
|
||||
EXPECT_EQ(const_state.GaussResults().data(), gauss_storage);
|
||||
EXPECT_EQ(const_state.GaussResults()[0].gauss_point, 1);
|
||||
EXPECT_EQ(const_state.GaussResults()[1].gauss_point, 2);
|
||||
EXPECT_EQ(const_state.GaussResults()[0].generalized_strain,
|
||||
(std::array<double, 4>{0.1, 0.2, 0.3, 0.4}));
|
||||
EXPECT_EQ(const_state.GaussResults()[1].generalized_resultant,
|
||||
(std::array<double, 4>{1.5, 1.6, 1.7, 1.8}));
|
||||
|
||||
ASSERT_EQ(constState.stressResults().size(), 2U);
|
||||
EXPECT_EQ(constState.stressResults().data(), stressStorage);
|
||||
EXPECT_EQ(constState.stressResults()[0].sectionPoint, 1U);
|
||||
EXPECT_DOUBLE_EQ(constState.stressResults()[0].x1, -0.25);
|
||||
EXPECT_DOUBLE_EQ(constState.stressResults()[0].x2, 0.5);
|
||||
EXPECT_DOUBLE_EQ(constState.stressResults()[0].s11, 12.5);
|
||||
EXPECT_EQ(constState.stressResults()[0].source, "input");
|
||||
EXPECT_EQ(constState.stressResults()[1].sectionPoint, 2U);
|
||||
ASSERT_EQ(const_state.StressResults().size(), 2U);
|
||||
EXPECT_EQ(const_state.StressResults().data(), stress_storage);
|
||||
EXPECT_EQ(const_state.StressResults()[0].section_point, 1U);
|
||||
EXPECT_DOUBLE_EQ(const_state.StressResults()[0].x1, -0.25);
|
||||
EXPECT_DOUBLE_EQ(const_state.StressResults()[0].x2, 0.5);
|
||||
EXPECT_DOUBLE_EQ(const_state.StressResults()[0].s11, 12.5);
|
||||
EXPECT_EQ(const_state.StressResults()[0].source, "input");
|
||||
EXPECT_EQ(const_state.StressResults()[1].section_point, 2U);
|
||||
}
|
||||
|
||||
// MITC4-STATE-001
|
||||
TEST(AnalysisState, OwnsExactShellRowsInStableElementAndLocationOrder) {
|
||||
const auto dofs = makeEmptyDofs();
|
||||
auto state = fesa::AnalysisState::create(dofs, {"Step-1", 0U});
|
||||
const std::vector<fesa::EntityIndex> expectedElements{3U, 7U};
|
||||
auto candidate = makeShellCandidate(expectedElements);
|
||||
const auto dofs = MakeEmptyDofs();
|
||||
auto state = fesa::AnalysisState::Create(dofs, {"Step-1", 0U});
|
||||
const std::vector<fesa::EntityIndex> expected_elements{3U, 7U};
|
||||
auto candidate = MakeShellCandidate(expected_elements);
|
||||
|
||||
const auto status = state.commitShellResults(expectedElements, candidate);
|
||||
const auto status = state.CommitShellResults(expected_elements, candidate);
|
||||
|
||||
ASSERT_TRUE(status.IsOk());
|
||||
const fesa::AnalysisState& constState = state;
|
||||
ASSERT_EQ(constState.shellResults().size(), 8U);
|
||||
EXPECT_EQ(constState.shellResults()[0].element, 3U);
|
||||
EXPECT_EQ(
|
||||
constState.shellResults()[0].location,
|
||||
fesa::ShellMidsurfaceLocation::gp1);
|
||||
EXPECT_EQ(
|
||||
constState.shellResults()[3].location,
|
||||
fesa::ShellMidsurfaceLocation::gp4);
|
||||
EXPECT_EQ(constState.shellResults()[4].element, 7U);
|
||||
EXPECT_EQ(
|
||||
constState.shellResults()[4].location,
|
||||
fesa::ShellMidsurfaceLocation::gp1);
|
||||
EXPECT_EQ(
|
||||
constState.shellResults()[0].naturalCoordinates,
|
||||
(std::array<double, 2>{
|
||||
-1.0 / std::sqrt(3.0), -1.0 / std::sqrt(3.0)}));
|
||||
EXPECT_EQ(
|
||||
constState.shellResults()[2].generalizedStrain,
|
||||
(std::array<double, 8>{
|
||||
321.0, 322.0, 323.0, 324.0,
|
||||
325.0, 326.0, 327.0, 328.0}));
|
||||
EXPECT_EQ(
|
||||
constState.shellResults()[7].sectionResultant,
|
||||
(std::array<double, 8>{
|
||||
741.0, 742.0, 743.0, 744.0,
|
||||
745.0, 746.0, 747.0, 748.0}));
|
||||
EXPECT_EQ(
|
||||
constState.shellResults()[7].stress[0].position,
|
||||
fesa::ShellSectionPosition::bottom);
|
||||
EXPECT_DOUBLE_EQ(constState.shellResults()[7].stress[0].zeta, -1.0);
|
||||
EXPECT_EQ(
|
||||
constState.shellResults()[7].stress[2].components,
|
||||
(std::array<double, 3>{757.0, 758.0, 759.0}));
|
||||
ASSERT_TRUE(status.IsOk());
|
||||
const fesa::AnalysisState& const_state = state;
|
||||
ASSERT_EQ(const_state.ShellResults().size(), 8U);
|
||||
EXPECT_EQ(const_state.ShellResults()[0].element, 3U);
|
||||
EXPECT_EQ(const_state.ShellResults()[0].location,
|
||||
fesa::ShellMidsurfaceLocation::kGp1);
|
||||
EXPECT_EQ(const_state.ShellResults()[3].location,
|
||||
fesa::ShellMidsurfaceLocation::kGp4);
|
||||
EXPECT_EQ(const_state.ShellResults()[4].element, 7U);
|
||||
EXPECT_EQ(const_state.ShellResults()[4].location,
|
||||
fesa::ShellMidsurfaceLocation::kGp1);
|
||||
EXPECT_EQ(
|
||||
const_state.ShellResults()[0].natural_coordinates,
|
||||
(std::array<double, 2>{-1.0 / std::sqrt(3.0), -1.0 / std::sqrt(3.0)}));
|
||||
EXPECT_EQ(const_state.ShellResults()[2].generalized_strain,
|
||||
(std::array<double, 8>{321.0, 322.0, 323.0, 324.0, 325.0, 326.0,
|
||||
327.0, 328.0}));
|
||||
EXPECT_EQ(const_state.ShellResults()[7].section_resultant,
|
||||
(std::array<double, 8>{741.0, 742.0, 743.0, 744.0, 745.0, 746.0,
|
||||
747.0, 748.0}));
|
||||
EXPECT_EQ(const_state.ShellResults()[7].stress[0].position,
|
||||
fesa::ShellSectionPosition::kBottom);
|
||||
EXPECT_DOUBLE_EQ(const_state.ShellResults()[7].stress[0].zeta, -1.0);
|
||||
EXPECT_EQ(const_state.ShellResults()[7].stress[2].components,
|
||||
(std::array<double, 3>{757.0, 758.0, 759.0}));
|
||||
}
|
||||
|
||||
// MITC4-STATE-002
|
||||
TEST(AnalysisState, CommitsFiniteShellGlobalEvidence) {
|
||||
const auto dofs = makeEmptyDofs();
|
||||
auto state = fesa::AnalysisState::create(dofs, {"Step-1", 0U});
|
||||
const std::vector<fesa::EntityIndex> expectedElements{5U};
|
||||
const auto candidate = makeShellCandidate(expectedElements);
|
||||
const auto dofs = MakeEmptyDofs();
|
||||
auto state = fesa::AnalysisState::Create(dofs, {"Step-1", 0U});
|
||||
const std::vector<fesa::EntityIndex> expected_elements{5U};
|
||||
const auto candidate = MakeShellCandidate(expected_elements);
|
||||
|
||||
const auto status = state.commitShellResults(expectedElements, candidate);
|
||||
const auto status = state.CommitShellResults(expected_elements, candidate);
|
||||
|
||||
ASSERT_TRUE(status.IsOk());
|
||||
EXPECT_DOUBLE_EQ(state.physicalStrainEnergy(), 35.5);
|
||||
EXPECT_EQ(
|
||||
state.equilibrium(),
|
||||
(std::array<double, 6>{1.0, -2.0, 3.0, -4.0, 5.0, -6.0}));
|
||||
EXPECT_EQ(
|
||||
state.verificationMetrics(),
|
||||
(std::array<double, 3>{1.0e-11, 2.0e-11, 3.0e-11}));
|
||||
ASSERT_TRUE(status.IsOk());
|
||||
EXPECT_DOUBLE_EQ(state.PhysicalStrainEnergy(), 35.5);
|
||||
EXPECT_EQ(state.Equilibrium(),
|
||||
(std::array<double, 6>{1.0, -2.0, 3.0, -4.0, 5.0, -6.0}));
|
||||
EXPECT_EQ(state.VerificationMetrics(),
|
||||
(std::array<double, 3>{1.0e-11, 2.0e-11, 3.0e-11}));
|
||||
}
|
||||
|
||||
// MITC4-STATE-003
|
||||
TEST(AnalysisState, InvalidShellCandidatesLeavePriorStateUnchanged) {
|
||||
const auto dofs = makeEmptyDofs();
|
||||
auto state = fesa::AnalysisState::create(dofs, {"Step-1", 0U});
|
||||
const std::vector<fesa::EntityIndex> expectedElements{5U};
|
||||
const auto committed = makeShellCandidate(expectedElements);
|
||||
ASSERT_TRUE(state.commitShellResults(expectedElements, committed).IsOk());
|
||||
const auto dofs = MakeEmptyDofs();
|
||||
auto state = fesa::AnalysisState::Create(dofs, {"Step-1", 0U});
|
||||
const std::vector<fesa::EntityIndex> expected_elements{5U};
|
||||
const auto committed = MakeShellCandidate(expected_elements);
|
||||
ASSERT_TRUE(state.CommitShellResults(expected_elements, committed).IsOk());
|
||||
|
||||
auto invalidLocation = makeShellCandidate(expectedElements);
|
||||
invalidLocation.rows[0].location = fesa::ShellMidsurfaceLocation::gp2;
|
||||
expectShellCandidateRejectedWithoutMutation(
|
||||
state, expectedElements, invalidLocation, committed);
|
||||
auto invalid_location = MakeShellCandidate(expected_elements);
|
||||
invalid_location.rows[0].location = fesa::ShellMidsurfaceLocation::kGp2;
|
||||
ExpectShellCandidateRejectedWithoutMutation(state, expected_elements,
|
||||
invalid_location, committed);
|
||||
|
||||
auto nonfinite = makeShellCandidate(expectedElements);
|
||||
nonfinite.rows[2].generalizedStrain[6] =
|
||||
(std::numeric_limits<double>::quiet_NaN)();
|
||||
expectShellCandidateRejectedWithoutMutation(
|
||||
state, expectedElements, nonfinite, committed);
|
||||
auto nonfinite = MakeShellCandidate(expected_elements);
|
||||
nonfinite.rows[2].generalized_strain[6] =
|
||||
(std::numeric_limits<double>::quiet_NaN)();
|
||||
ExpectShellCandidateRejectedWithoutMutation(state, expected_elements,
|
||||
nonfinite, committed);
|
||||
|
||||
auto nonfiniteFrame = makeShellCandidate(expectedElements);
|
||||
nonfiniteFrame.rows[1].localFrame[2][0] =
|
||||
(std::numeric_limits<double>::infinity)();
|
||||
expectShellCandidateRejectedWithoutMutation(
|
||||
state, expectedElements, nonfiniteFrame, committed);
|
||||
auto nonfinite_frame = MakeShellCandidate(expected_elements);
|
||||
nonfinite_frame.rows[1].local_frame[2][0] =
|
||||
(std::numeric_limits<double>::infinity)();
|
||||
ExpectShellCandidateRejectedWithoutMutation(state, expected_elements,
|
||||
nonfinite_frame, committed);
|
||||
|
||||
auto invalidSectionPosition = makeShellCandidate(expectedElements);
|
||||
invalidSectionPosition.rows[3].stress[0].position =
|
||||
fesa::ShellSectionPosition::top;
|
||||
expectShellCandidateRejectedWithoutMutation(
|
||||
state, expectedElements, invalidSectionPosition, committed);
|
||||
auto invalid_section_position = MakeShellCandidate(expected_elements);
|
||||
invalid_section_position.rows[3].stress[0].position =
|
||||
fesa::ShellSectionPosition::kTop;
|
||||
ExpectShellCandidateRejectedWithoutMutation(
|
||||
state, expected_elements, invalid_section_position, committed);
|
||||
|
||||
auto nonfiniteGlobalEvidence = makeShellCandidate(expectedElements);
|
||||
nonfiniteGlobalEvidence.verificationMetrics[1] =
|
||||
(std::numeric_limits<double>::infinity)();
|
||||
expectShellCandidateRejectedWithoutMutation(
|
||||
state, expectedElements, nonfiniteGlobalEvidence, committed);
|
||||
auto nonfinite_global_evidence = MakeShellCandidate(expected_elements);
|
||||
nonfinite_global_evidence.verification_metrics[1] =
|
||||
(std::numeric_limits<double>::infinity)();
|
||||
ExpectShellCandidateRejectedWithoutMutation(
|
||||
state, expected_elements, nonfinite_global_evidence, committed);
|
||||
|
||||
auto incompleteInventory = makeShellCandidate(expectedElements);
|
||||
incompleteInventory.rows.pop_back();
|
||||
expectShellCandidateRejectedWithoutMutation(
|
||||
state, expectedElements, incompleteInventory, committed);
|
||||
auto incomplete_inventory = MakeShellCandidate(expected_elements);
|
||||
incomplete_inventory.rows.pop_back();
|
||||
ExpectShellCandidateRejectedWithoutMutation(state, expected_elements,
|
||||
incomplete_inventory, committed);
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,24 +1,23 @@
|
||||
#include "fesa/results/results_writer.hpp"
|
||||
|
||||
#include "fesa/analysis/analysis_state.hpp"
|
||||
#include "fesa/core/diagnostic.h"
|
||||
#include "fesa/core/status.h"
|
||||
#include "fesa/model/domain.h"
|
||||
#include "fesa/results/results_writer.h"
|
||||
|
||||
#include <filesystem>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
|
||||
#include "fesa/analysis/analysis_state.h"
|
||||
#include "fesa/core/diagnostic.h"
|
||||
#include "fesa/core/status.h"
|
||||
#include "fesa/model/domain.h"
|
||||
|
||||
namespace {
|
||||
|
||||
using WriteSignature = fesa::Status (fesa::ResultsWriter::*)(
|
||||
const std::filesystem::path&,
|
||||
const fesa::Domain&,
|
||||
const fesa::AnalysisState&,
|
||||
const std::vector<fesa::Diagnostic>&);
|
||||
const std::filesystem::path&, const fesa::Domain&,
|
||||
const fesa::AnalysisState&, const std::vector<fesa::Diagnostic>&);
|
||||
|
||||
static_assert(std::has_virtual_destructor_v<fesa::ResultsWriter>);
|
||||
static_assert(std::is_abstract_v<fesa::ResultsWriter>);
|
||||
static_assert(std::is_same_v<decltype(&fesa::ResultsWriter::write), WriteSignature>);
|
||||
static_assert(
|
||||
std::is_same_v<decltype(&fesa::ResultsWriter::Write), WriteSignature>);
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "fesa/fem/dof_manager.hpp"
|
||||
#include "fesa/fem/dof_manager.h"
|
||||
#include "fesa/math/sparse_matrix.h"
|
||||
#include "fesa/solvers/linear/mkl_pardiso_solver.h"
|
||||
|
||||
@@ -19,15 +19,15 @@ fesa::SparseMatrix MakeDenseCsr(const std::size_t rows,
|
||||
|
||||
fesa::SparsePattern pattern;
|
||||
std::vector<fesa::CooContribution> contributions;
|
||||
pattern.rowOffsets.reserve(rows + 1U);
|
||||
pattern.rowOffsets.push_back(0U);
|
||||
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.columnIndices.push_back(column);
|
||||
pattern.column_indices.push_back(column);
|
||||
contributions.push_back(
|
||||
{row, column, values[row * columns + column], row, column});
|
||||
}
|
||||
pattern.rowOffsets.push_back(pattern.columnIndices.size());
|
||||
pattern.row_offsets.push_back(pattern.column_indices.size());
|
||||
}
|
||||
|
||||
auto matrix = fesa::SparseMatrix::FromCoo(rows, columns,
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "fesa/fem/dof_manager.hpp"
|
||||
#include "fesa/fem/dof_manager.h"
|
||||
#include "fesa/math/sparse_matrix.h"
|
||||
|
||||
namespace {
|
||||
@@ -20,15 +20,15 @@ fesa::SparseMatrix MakeDenseCsr(const std::size_t size,
|
||||
|
||||
fesa::SparsePattern pattern;
|
||||
std::vector<fesa::CooContribution> contributions;
|
||||
pattern.rowOffsets.reserve(size + 1U);
|
||||
pattern.rowOffsets.push_back(0U);
|
||||
pattern.row_offsets.reserve(size + 1U);
|
||||
pattern.row_offsets.push_back(0U);
|
||||
for (std::size_t row = 0U; row < size; ++row) {
|
||||
for (std::size_t column = 0U; column < size; ++column) {
|
||||
pattern.columnIndices.push_back(column);
|
||||
pattern.column_indices.push_back(column);
|
||||
contributions.push_back(
|
||||
{row, column, values[row * size + column], row, column});
|
||||
}
|
||||
pattern.rowOffsets.push_back(pattern.columnIndices.size());
|
||||
pattern.row_offsets.push_back(pattern.column_indices.size());
|
||||
}
|
||||
|
||||
auto matrix = fesa::SparseMatrix::FromCoo(size, size,
|
||||
|
||||
Reference in New Issue
Block a user