pub mod internal_variables;
use crate::{
constitutive::solid::hyperelastic::Hyperelastic,
fem::{
ElementModelError, NodalCoordinates,
block::{
Block,
element::{
FiniteElementError, planar::PlanarHyperelasticFiniteElement,
solid::hyperelastic::HyperelasticFiniteElement,
},
},
solid::{
NodalStiffnessesSolidSymmetric, elastic::ElasticElements,
hyperelastic::HyperelasticElements,
},
},
math::{HessianAccumulate, Quantity},
units::Energy,
};
impl<C, F, const G: usize, const M: usize, const N: usize, const P: usize> HyperelasticElements<3>
for Block<C, F, G, M, N, P>
where
C: Hyperelastic,
F: HyperelasticFiniteElement<C, G, M, N, P>,
Self: ElasticElements<3>,
{
fn helmholtz_free_energy(
&self,
nodal_coordinates: &NodalCoordinates<3>,
) -> Result<Quantity<Energy>, ElementModelError> {
self.elements()
.iter()
.zip(self.connectivity())
.map(|(element, nodes)| {
element.helmholtz_free_energy(
self.constitutive_model(),
&Self::element_coordinates(nodal_coordinates, nodes),
)
})
.sum::<Result<_, FiniteElementError>>()
.map_err(|error| ElementModelError::upstream(error, self))
}
fn nodal_stiffnesses_symmetric_into(
&self,
nodal_coordinates: &NodalCoordinates<3>,
nodal_stiffnesses: &mut NodalStiffnessesSolidSymmetric<3>,
) -> Result<(), ElementModelError> {
self.elements()
.iter()
.zip(self.connectivity())
.try_for_each(|(element, nodes)| {
element
.nodal_stiffnesses(
self.constitutive_model(),
&Self::element_coordinates(nodal_coordinates, nodes),
)?
.into_iter()
.zip(nodes)
.for_each(|(object, &node_a)| {
object
.into_iter()
.zip(nodes)
.for_each(|(nodal_stiffness, &node_b)| {
if node_a <= node_b {
nodal_stiffnesses.accumulate(node_a, node_b, nodal_stiffness)
}
})
});
Ok::<(), FiniteElementError>(())
})
.map_err(|error| ElementModelError::upstream(error, self))
}
}
impl<C, F, const G: usize, const N: usize, const P: usize> HyperelasticElements<2>
for Block<C, F, G, 2, N, P>
where
C: Hyperelastic,
F: PlanarHyperelasticFiniteElement<C, G, N, P>,
Self: ElasticElements<2>,
{
fn helmholtz_free_energy(
&self,
nodal_coordinates: &NodalCoordinates<2>,
) -> Result<Quantity<Energy>, ElementModelError> {
self.elements()
.iter()
.zip(self.connectivity())
.map(|(element, nodes)| {
element.helmholtz_free_energy(
self.constitutive_model(),
&Self::element_coordinates(nodal_coordinates, nodes),
)
})
.sum::<Result<_, FiniteElementError>>()
.map_err(|error| ElementModelError::upstream(error, self))
}
fn nodal_stiffnesses_symmetric_into(
&self,
nodal_coordinates: &NodalCoordinates<2>,
nodal_stiffnesses: &mut NodalStiffnessesSolidSymmetric<2>,
) -> Result<(), ElementModelError> {
self.elements()
.iter()
.zip(self.connectivity())
.try_for_each(|(element, nodes)| {
element
.nodal_stiffnesses(
self.constitutive_model(),
&Self::element_coordinates(nodal_coordinates, nodes),
)?
.into_iter()
.zip(nodes)
.for_each(|(object, &node_a)| {
object
.into_iter()
.zip(nodes)
.for_each(|(nodal_stiffness, &node_b)| {
if node_a <= node_b {
nodal_stiffnesses.accumulate(node_a, node_b, nodal_stiffness)
}
})
});
Ok::<(), FiniteElementError>(())
})
.map_err(|error| ElementModelError::upstream(error, self))
}
}