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

try out: simplify automatic forces trait

parent b7327259
Branches 87-condensation-accuracy-decreases-with-resolution
No related tags found
No related merge requests found
......@@ -27,12 +27,11 @@ namespace ae108::elements {
/**
* @brief Computes the forces by differentiation of the energy.
*/
template <class Element_> struct AutomaticForcesTrait {
template <class Element>
typename Element::Forces
operator()(const Element &element,
template <class Element> struct AutomaticForcesTrait {
static typename Element::Forces
compute(const Element &element,
const typename Element::NodalDisplacements &u,
const typename Element::Time &time) const {
const typename Element::Time &time) {
auto result = typename Element::Forces();
auto result_matrix = tensor::as_matrix_of_rows(result);
......
......@@ -95,7 +95,7 @@ concept ElementConcept = requires(const T a) {
template <ElementConcept ElementImpl> struct Element : ElementImpl {
using Energy = typename ElementImpl::Energy;
using Time = typename ElementImpl::Energy;
using NodalDisplacements = typename ElementImpl::NodalDisplacement;
using NodalDisplacements = typename ElementImpl::NodalDisplacements;
static constexpr auto size() { return ElementImpl::size_; }
Energy ComputeEnergy(const NodalDisplacements &displacements,
......
......@@ -55,8 +55,15 @@ struct ComputeEnergyTrait<Minimal<Size_, Dimension_, DegreesOfFreedom_>> {
*/
template <std::size_t Size_, std::size_t Dimension_,
std::size_t DegreesOfFreedom_>
struct ComputeForcesTrait<Minimal<Size_, Dimension_, DegreesOfFreedom_>>
: AutomaticForcesTrait<Minimal<Size_, Dimension_, DegreesOfFreedom_>> {};
struct ComputeForcesTrait<Minimal<Size_, Dimension_, DegreesOfFreedom_>>{
template <class Element>
typename Element::Forces
operator()(const Element &element,
const typename Element::NodalDisplacements &u,
const typename Element::Time &time) const noexcept {
return AutomaticForcesTrait<Minimal<Size_, Dimension_, DegreesOfFreedom_>>::compute(element, u, time);
}
};
/**
* @brief Computes the stiffness matrix by differentiating the forces.
......
......@@ -29,7 +29,7 @@ typename Element::Forces
automatic_forces(const Element &element,
const typename Element::NodalDisplacements &displacements,
const typename Element::Time &time) {
return AutomaticForcesTrait<Element>()(element, displacements, time);
return AutomaticForcesTrait<Element>::compute(element, displacements, time);
}
} // namespace ae108::elements
\ No newline at end of file
......@@ -27,11 +27,7 @@ typename Element::Forces
compute_forces(const Element &element,
const typename Element::NodalDisplacements &displacements,
const typename Element::Time &time) {
if constexpr (ElementConcept<Element>) {
return element.computeForces(displacements, time);
} else {
return ComputeForcesTrait<Element>()(element, displacements, time);
}
return ComputeForcesTrait<Element>()(element, displacements, time);
}
} // namespace ae108::elements
\ No newline at end of file
......@@ -43,8 +43,7 @@ template <class Element> typename Element::Force create_test_force() noexcept {
template <class Element_> struct Configuration {
using Element = Element_;
static Element create_element() noexcept {
return {// .force =
create_test_force<Element_>()};
return { .force = create_test_force<Element_>()};
}
static typename Element::Time create_time() noexcept {
......@@ -60,7 +59,7 @@ struct ForceElement_Test : Test {
static constexpr auto dimension = 2;
using Element = ForceElement<dimension>;
const Element element = {// .force =
const Element element = {.force =
create_test_force<Element>()};
};
......
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