# <markdowncell> # We can directly plot the magnitude of the displacement field and the stress # <codecell> fig = pyplot.figure(figsize=(20, 10)) displacement.plot(gridLines=None, figure=(fig, 121), colorbar="horizontal") s = sigma(displacement) - (1. / 3) * tr(sigma(displacement)) * Identity(2) von_Mises = sqrt(3. / 2 * inner(s, s)) plot(von_Mises, grid=gridView, gridLines=None, figure=(fig, 122), colorbar="horizontal") pyplot.show() # <markdowncell> # Finally we can plot the actual displaced beam using a grid view that # allows us to add a transformation of the geometry of each entity in the # grid by prociding a grid function to the constructor. Note that this also # allows for higher order transformation like in this case where the # transformation is given by a second order Lagrange discrete function. # We will highlight the flexibility of the # `GeometryGridView` in further # examples: # <codecell> from dune.fem.view import geometryGridView position = space.interpolate(x + displacement, name="position") beam = geometryGridView(position) beam.plot()
order = 3 storage = "istl" # setup reference surface referenceView = leafGridView("sphere.dgf", dimgrid=2, dimworld=3) space = solutionSpace(referenceView, dimRange=referenceView.dimWorld, order=order, storage=storage) # setup deformed surface x = ufl.SpatialCoordinate(space) # positions = space.interpolate(x, name="position") positions = space.interpolate( x * (1 + 0.5 * sin(2 * pi * (x[0] + x[1])) * cos(0.25 * pi * x[2])), name="position") gridView = geometryGridView(positions) space = solutionSpace(gridView, dimRange=gridView.dimWorld, order=order, storage=storage) u = ufl.TrialFunction(space) phi = ufl.TestFunction(space) dt = dune.ufl.Constant(0.01, "timeStep") t = dune.ufl.Constant(0.0, "time") # define storage for discrete solutions uh = space.interpolate(x, name="uh") uh_old = uh.copy() # problem definition
# <markdowncell> # We begin by setting up reference domain $\Gamma_0$ (```grid```), and the space on $\Gamma_0$ that describes $\Gamma(t)$ (```space```). From this we interpolate the non-spherical initial surface ```positions```, and, then reconstruct ```space``` for the discrete solution on $\Gamma(t)$. # <codecell> from dune.fem.view import geometryGridView from dune.fem.space import lagrange as solutionSpace from dune.alugrid import aluConformGrid as leafGridView gridView = leafGridView("sphere.dgf", dimgrid=2, dimworld=3) space = solutionSpace(gridView, dimRange=gridView.dimWorld, order=order) u = TrialFunction(space) v = TestFunction(space) x = SpatialCoordinate(space) # positions = space.interpolate(x * (1 + 0.5*sin(2*pi*x[0]*x[1])* cos(pi*x[2])), name="position") positions = space.interpolate(x * (1 + 0.5*sin(2*pi*(x[0]+x[1]))*cos(0.25*pi*x[2])), name="position") surface = geometryGridView(positions) space = solutionSpace(surface, dimRange=surface.dimWorld, order=order) solution = space.interpolate(x, name="solution") # <markdowncell> # We set up the theta scheme with $\theta = 0.5$ (Crank-Nicholson). # <codecell> from dune.fem.scheme import galerkin as solutionScheme theta = 0.5 I = Identity(3) dt = Constant(0, "dt") a = (inner(u - x, v) + dt * inner(theta*grad(u) + (1 - theta)*I, grad(v))) * dx