Skip to content
Snippets Groups Projects
Commit 74c1c7fe authored by Philipp Wissmann's avatar Philipp Wissmann
Browse files

Elements: Add ConsistentMassMatrix concept

parent e0594001
Branches 87-condensation-accuracy-decreases-with-resolution
No related tags found
No related merge requests found
......@@ -30,7 +30,7 @@ DEFINE_CONST_ASSEMBLER_PLUGIN(AssembleConsistentMassMatrixPlugin,
std::vector<value_type> outputBuffer;
for (const auto &meshElement : this->assembler().meshElements()) {
const auto matrix = compute_consistent_mass_matrix(meshElement.instance());
const auto matrix = meshElement.instance().computeConsistentMassMatrix();
outputBuffer.resize(matrix.rows() * matrix.cols());
utilities::serialize(matrix, outputBuffer.begin());
......
......@@ -19,13 +19,11 @@ cmake_minimum_required(VERSION 3.12 FATAL_ERROR)
add_library(${PROJECT_NAME}-elements
Bar.cc
ComputeConsistentMassMatrixTrait.cc
CoreElement.cc
ElementWithMass.cc
ForceElement.cc
Minimal.cc
TimoshenkoBeamElement.cc
compute_consistent_mass_matrix.cc
embedding/AutomaticJacobianTrait.cc
embedding/EmbedTrait.cc
embedding/EmbeddingBase.cc
......
// © 2022 ETH Zurich, Mechanics and Materials Lab
//
// This file is part of ae108.
//
// ae108 is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or any
// later version.
//
// ae108 is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with ae108. If not, see <https://www.gnu.org/licenses/>.
// NOLINTNEXTLINE(misc-include-cleaner)
#include "ae108/elements/ComputeConsistentMassMatrixTrait.h"
\ No newline at end of file
// © 2022 ETH Zurich, Mechanics and Materials Lab
//
// This file is part of ae108.
//
// ae108 is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or any
// later version.
//
// ae108 is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with ae108. If not, see <https://www.gnu.org/licenses/>.
// NOLINTNEXTLINE(misc-include-cleaner)
#include "ae108/elements/compute_consistent_mass_matrix.h"
// © 2022 ETH Zurich, Mechanics and Materials Lab
//
// This file is part of ae108.
//
// ae108 is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or any
// later version.
//
// ae108 is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with ae108. If not, see <https://www.gnu.org/licenses/>.
#pragma once
namespace ae108::elements {
template <class Element> struct ComputeConsistentMassMatrixTrait;
} // namespace ae108::elements
\ No newline at end of file
......@@ -17,7 +17,6 @@
#pragma once
#include "ae108/elements/ComputeConsistentMassMatrixTrait.h"
#include "ae108/elements/ElementConcept.h"
#include "ae108/elements/integrator/compute_volume.h"
#include "ae108/elements/integrator/integrate.h"
......@@ -206,42 +205,24 @@ struct CoreElement final {
return ae108::elements::integrator::volume(integrator) / kSize *
Element::StiffnessMatrix::Identity();
}
};
template <class MaterialModel_, class Integrator_, class ValueType_,
class RealType_>
struct ComputeConsistentMassMatrixTrait<
CoreElement<MaterialModel_, Integrator_, ValueType_, RealType_>> {
template <ElementConcept Element>
typename Element::StiffnessMatrix
operator()(const Element &element) const noexcept {
using size_type = typename Element::Size;
return integrator::integrate_shape<Integrator_>(
element.integrator,
[&](auto &&, const auto &value) {
auto result = Element::StiffnessMatrix::Zero().eval();
const auto mass =
(tensor::as_vector(value) * tensor::as_vector(value).transpose())
.eval();
for (auto i = size_type{0}; i < element.kDegreesOfFreedom; ++i) {
ResultSlice<Element>(&result(i, i)) = mass;
}
return result;
},
Element::StiffnessMatrix::Zero().eval());
[[nodiscard]] StiffnessMatrix computeConsistentMassMatrix() const noexcept {
return integrator::integrate_shape<Integrator>(
integrator,
[&](auto &&, const auto &value) {
auto result = StiffnessMatrix::Zero().eval();
const auto mass =
(tensor::as_vector(value) * tensor::as_vector(value).transpose())
.eval();
for (auto i = Size{0}; i < kDegreesOfFreedom; ++i) {
ResultSlice(&result(i, i)) = mass;
}
return result;
},
StiffnessMatrix::Zero().eval());
}
private:
template <ElementConcept Element>
using ResultSlice = Eigen::Map<
Eigen::Matrix<typename Element::Value, Element::kSize, Element::kSize,
Eigen::RowMajor>,
0,
Eigen::Stride<Eigen::Index{Element::kSize * Element::kDegreesOfFreedom *
Element::kDegreesOfFreedom},
Eigen::Index{Element::kDegreesOfFreedom}>>;
};
} // namespace ae108::elements
......@@ -116,4 +116,11 @@ concept MassConcept = ElementConcept<T> && requires(const T a) {
} -> std::convertible_to<typename T::MassMatrix>;
};
template <typename T>
concept ConsistentMassConcept = ElementConcept<T> && requires(const T a) {
{
a.computeConsistentMassMatrix()
} -> std::convertible_to<typename T::StiffnessMatrix>;
};
} // namespace ae108::elements
\ No newline at end of file
// © 2022 ETH Zurich, Mechanics and Materials Lab
//
// This file is part of ae108.
//
// ae108 is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or any
// later version.
//
// ae108 is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with ae108. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include "ae108/elements/ComputeConsistentMassMatrixTrait.h"
namespace ae108::elements {
template <class Element>
typename Element::StiffnessMatrix
compute_consistent_mass_matrix(const Element &element) {
return ComputeConsistentMassMatrixTrait<Element>()(element);
}
} // namespace ae108::elements
\ No newline at end of file
......@@ -18,7 +18,6 @@
#include "Element_Test.h"
#include "ae108/elements/CoreElement.h"
#include "ae108/elements/ElementConcept.h"
#include "ae108/elements/compute_consistent_mass_matrix.h"
#include "ae108/elements/integrator/IsoparametricIntegrator.h"
#include "ae108/elements/materialmodels/AutomaticStressTrait.h"
#include "ae108/elements/materialmodels/AutomaticTangentMatrixTrait.h"
......@@ -113,7 +112,7 @@ TEST_F(CoreElement_Seg2_Test, computes_energy_with_displacements_2) {
}
TEST_F(CoreElement_Seg2_Test, computes_correct_consistent_mass_matrix) {
const auto mass = compute_consistent_mass_matrix(element);
const auto mass = element.computeLumpedMassMatrix();
ASSERT_THAT(mass.rows(), Eq(2));
ASSERT_THAT(mass.cols(), Eq(2));
......@@ -211,7 +210,7 @@ TEST_F(CoreElement_Quad4_Test, computes_correct_energy_with_displacements_2) {
TEST_F(CoreElement_Quad4_Test,
computes_correct_uppper_block_diagonal_of_consistent_mass_matrix) {
const auto mass = compute_consistent_mass_matrix(element);
const auto mass = element.computeLumpedMassMatrix();
ASSERT_THAT(mass.rows(), Eq(4 * 2));
ASSERT_THAT(mass.cols(), Eq(4 * 2));
......@@ -268,7 +267,7 @@ TEST_F(CoreElement_Quad4_Test,
}
TEST_F(CoreElement_Quad4_Test, consistent_mass_matrix_is_symmetric) {
const auto mass = compute_consistent_mass_matrix(element);
const auto mass = element.computeLumpedMassMatrix();
EXPECT_THAT((mass - mass.transpose()).norm(), DoubleEq(0.));
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment