Example #1
0
def setup():
    vertices = numpy.zeros((8, 2))
    vertices[0] = [0, 0]
    for i in range(0, 7):
        vertices[i + 1] = [
            math.cos(cornerAngle / 6 * math.pi / 180 * i),
            math.sin(cornerAngle / 6 * math.pi / 180 * i)
        ]
    triangles = numpy.array([[2, 1, 0], [0, 3, 2], [4, 3, 0], [0, 5, 4],
                             [6, 5, 0], [0, 7, 6]])
    domain = {"vertices": vertices, "simplices": triangles}
    gridView = adaptiveGridView(leafGridView(domain))
    gridView.hierarchicalGrid.globalRefine(2)
    space = solutionSpace(gridView, order=order)

    from dune.fem.scheme import galerkin as solutionScheme
    u = TrialFunction(space)
    v = TestFunction(space)
    x = SpatialCoordinate(space.cell())

    # exact solution for this angle
    Phi = cornerAngle / 180 * pi
    phi = atan_2(x[1], x[0]) + conditional(x[1] < 0, 2 * pi, 0)
    exact = dot(x, x)**(pi / 2 / Phi) * sin(pi / Phi * phi)
    a = dot(grad(u), grad(v)) * dx

    # set up the scheme
    laplace = solutionScheme(
        [a == 0, DirichletBC(space, exact, 1)],
        solver="cg",
        parameters={"newton.linear.preconditioning.method": "jacobi"})
    uh = space.interpolate(0, name="solution")
    return uh, exact, laplace
Example #2
0
# <codecell>
import time
import dune.fem as fem
from dune.grid import cartesianDomain
from dune.alugrid import aluConformGrid as leafGridView
from dune.fem.view import adaptiveLeafGridView as adaptiveGridView
from dune.fem.space import lagrange as solutionSpace

fem.parameter.append({"fem.verboserank": -1})

order = 1
dimDomain = 2  # we are solving this in 2D
dimRange = 2  # we have a system with two unknowns
domain = cartesianDomain(
    [4, 4], [8, 8], [40, 40])  # fails with 20x20 in adapt due to petsc error
gridView = adaptiveGridView(leafGridView(domain, dimgrid=dimDomain))
space = solutionSpace(gridView,
                      dimRange=dimRange,
                      order=order,
                      storage="petscadapt")

# <markdowncell>
# We want to solve the following system of equations of variables $\phi$ (phase field) and $T$ (temperature field)
#
# \begin{gather*}
# \tau \frac{\partial \phi}{\partial t} = \nabla \cdot D \nabla \phi + \phi(1-\phi)m(\phi, T), \\
# \frac{\partial T}{\partial t} = D_T \nabla^2 T + \frac{\partial \phi}{\partial t},
# \end{gather*}
#
# where $D_T$ = 2.25, m is given by
#
Example #3
0
from ufl import *

from dune.fem import spaceAdapt, adapt
from dune.grid import cartesianDomain, gridFunction
from dune.alugrid import aluConformGrid as leafGridView
from dune.fem.view import adaptiveLeafGridView as adaptiveGridView
from dune.fem import parameter, doerflerMark, globalRefine
from dune.fem.function import levelFunction
from dune.ufl import Space

import dune.create as create

parameter.append({"fem.verboserank": 0})

domain = cartesianDomain([0, 0], [1, 1], [16, 16])
grid = adaptiveGridView(leafGridView(domain))
space = create.space("lagrangehp", grid, maxOrder=4, storage="istl")

u = TrialFunction(space)
v = TestFunction(space)
x = SpatialCoordinate(space)
n = FacetNormal(space)
mu = 20 * 16
hT = MaxCellEdgeLength(space)
hS = avg(MaxFacetEdgeLength(space))
hs = MaxFacetEdgeLength(space)('+')

diffusiveFlux = lambda w, d: d
source = -sin(pi * x[0]) * sin(6 * pi * x[1])

a = (inner(diffusiveFlux(u, grad(u)), grad(v)) + source * v) * dx