def newGridView(): return leafGridView([-1, -1], [1, 1], [4, 4])
# vector valued discrete function $u$ which describes the displacement # field: # <codecell> import matplotlib matplotlib.rc('image', cmap='jet') from matplotlib import pyplot from dune.fem.plotting import plotPointData as plot from dune.grid import structuredGrid as leafGridView from dune.fem.space import lagrange as solutionSpace from dune.fem.scheme import galerkin as solutionScheme from ufl import * import dune.ufl gridView = leafGridView([0, 0], [1, 0.15], [100, 15]) space = solutionSpace(gridView, dimRange=2, order=2, storage="istl") displacement = space.interpolate([0, 0], name="displacement") # <markdowncell> # We want clamped boundary conditions on the left, i.e., zero displacement # <codecell> x = SpatialCoordinate(space) dbc = dune.ufl.DirichletBC(space, as_vector([0, 0]), x[0] < 1e-10) # <markdowncell> # Next we define the variational problem starting with a few constants # describing material properties ($\mu,\lambda,\rho$) and the gravitational # force
def newGridView(N=4): return leafGridView([-1, -1], [1, 1], [N, N]) ctor = cartesianDomain([-1, -1], [1, 1], [N, N]) return leafGridView(ctor)
# model by the Galerkin method # <codecell> import time, numpy, math, sys import dune.plotting dune.plotting.block = True import matplotlib matplotlib.rc( 'image', cmap='jet' ) from matplotlib import pyplot # <markdowncell> # ## Setting up the Mesh # <codecell> from dune.grid import structuredGrid as leafGridView gridView = leafGridView([0, 0], [1, 1], [4, 4]) # <markdowncell> # ## Grid Functions # We can integrate grid function # <codecell> from ufl import SpatialCoordinate, triangle x = SpatialCoordinate(triangle) exact = 1/2*(x[0]**2+x[1]**2) - 1/3*(x[0]**3 - x[1]**3) + 1 from dune.fem.function import integrate mass = integrate(gridView, exact, order=5) print(mass)
#!/usr/bin/env python3 from dune.fem.space import finiteVolume as solSpace from dune.grid import cartesianDomain from dune.grid import yaspGrid as leafGridView domain = cartesianDomain([0, 0], [1, 1], [10, 10]) grid = leafGridView(domain) grid.hierarchicalGrid.globalRefine(2) views = [grid.hierarchicalGrid.levelView(i) for i in range(3)] spaces = [solSpace(view) for view in views] spc0 = solSpace(views[0]) spc1 = solSpace(views[1]) u = spc0.DiscreteFunction(spc0, 'u') assert u.space.size == u.as_numpy.size, f"size of u {u.space.size} and dofvec {u.as_numpy.size} do not match" assert u.space.size == spc0.size, f"size of u {u.space.size} and space {spc0.size} do not match" # works and has the correct sizes for space in spaces: assert (space.size == space.gridView.size(0)) # does not work, sizes are mixed up for space in spaces: u = space.function(name='u') assert u.as_numpy.size == space.size, f"Size of space {space.size} and function {u.as_numpy.size} differs" assert u.space.size == space.size, f"Size of space {space.size} and function {u.space.size} differs"