Hyperelasticity - How to add displacement to original reference configuration? Best practice?

9 days ago by
I have a function that calculates and returns a displacement function for a structure:
def CalculateDisplacements(ForcingFunction):
    # do stuff here
    return u​

Sometimes I need to to know the displacements, other times I would also like to know the current material configuration (X + u). So I have, with V being an appropriate function space:

def CalculatePosition(ForcingFunction):
    u = CalculateDisplacements(ForcingFunction)
    position = project(Position(degree=1), V)
    position.vector()[:] += u.vector()[:]
    return position​

class Position(UserExpression):
    def __init__(self, degree, **kwargs):
        self.degree = degree
    def eval(self, value, x):
        value[0] = x[0]
        value[1] = x[1]

    def value_shape(self):
        return (2,)

This Position Expression works, but seems needlessly complicated/inelegant and slow. Can anyone point me to a better solution? Thanks in advance!

Community: FEniCS Project

1 Answer

9 days ago by
Hi, try with
position = Function(V)
position.interpolate(Expression(("x[0]", "x[1]"), degree=1))​
position.vector()[:] += u.vector()[:]
Is it better ?
Hi, thanks for the response. Is Expression faster/more efficient than UserExpression?
Also I came across something called SpatialCoordinates() - could that offer a cleaner way?
written 1 day ago by Alexander Niewiarowski  
Please login to add an answer/comment or follow this question.

Similar posts:
Search »