# <codecell> from dune.ufl import expression2GF indicator = expression2GF(gridView, dot(grad(u_h[0]), grad(u_h[0])), 0, name="indicator") # <markdowncell> # We do the initial refinement of the grid. # <codecell> maxLevel = 9 startLevel = 4 hgrid = gridView.hierarchicalGrid hgrid.globalRefine(startLevel) for i in range(startLevel, maxLevel): fem.mark(indicator, 1.4, 1.2, 0, maxLevel) fem.adapt(u_h) fem.loadBalance(u_h) u_h.interpolate(initial_gf) # <markdowncell> # Let us start by plotting the initial state of the material, which is just a small circle in the centre. # <codecell> from dune.fem.plotting import plotComponents import matplotlib.pyplot as pyplot from dune.fem.function import levelFunction, partitionFunction import matplotlib vtk = gridView.sequencedVTK( "crystal", pointdata=[u_h],
polOrder = space.localOrder(element) newPolOrder = polOrder if estP < pTol: newPolOrder = polOrder - 1 if polOrder > 2 else polOrder elif estP > 100 * pTol: newPolOrder = polOrder + 1 if polOrder < maxOrder else polOrder pMarked[polOrder - 1] += 1 return polOrder while True: estimator(solution, estimate) eta2 = sum(estimate.dofVector) vtk() print("estimate:", eta2, tolerance) if eta2 < tolerance * tolerance * 2: break hMarked = mark(estimate, math.sqrt(eta2) / grid.size(0)) # globalRefine(1,solution,solution) adapt(solution) print("h-adapted:", hMarked) estimator(solution, estimate) spaceAdapt(spacePm, markPm, [solutionPm]) solutionPm.interpolate(solution) estimator(solutionPm, estimatePm) spaceAdapt(space, markp, [solution]) print("p-adapted:", pMarked) scheme.solve(target=solution)
plot(uh, figure=(fig, 131 + count // 9), colorbar=False) pointFunctional.clear() error = computeFunctional(point, pointFunctional, eh) dual.solve(target=z, rhs=pointFunctional) zh.interpolate(z) estimator(uh, estimate) eta = sum(estimate.dofVector) dofs += [uh.space.size] errorVector += [error] estimateVector += [eta] if count % 3 == 2: print(count, ": size=", uh.space.grid.size(0), "estimate=", eta, "error=", error) if eta < tolerance: break marked = fem.mark(estimate, eta / uh.space.grid.size(0)) fem.adapt( uh) # can also be a list or tuple of function to prolong/restrict fem.loadBalance(uh) count += 1 plot(uh, figure=(fig, 131 + 2), colorbar=False) pyplot.show() pyplot.close('all') # <markdowncell> # Let's take a close up look of the refined region around the point of # interest and the origin: # <codecell> fig = pyplot.figure(figsize=(30, 20)) plot(uh,
# <codecell> from dune.ufl import expression2GF indicator = expression2GF(gridView, dot(grad(u_h[0]), grad(u_h[0])), 0, name="indicator") # <markdowncell> # We do the initial refinement of the grid. # <codecell> maxLevel = 8 startLevel = 3 gridView.hierarchicalGrid.globalRefine(startLevel) u_h.interpolate(initial_gf) for i in range(startLevel, maxLevel): marked = fem.mark(indicator, 1.4, 1.2, 0, maxLevel) # print("marked:",marked,"from elements",gridView.size(0)) fem.adapt(gridView.hierarchicalGrid) fem.loadBalance(gridView.hierarchicalGrid) # print(gridView.size(0), end="\n") u_h.interpolate(initial_gf) # print() # <markdowncell> # Let us start by plotting the initial state of the material, which is just a small circle in the centre. # <codecell> from dune.fem.plotting import plotComponents import matplotlib.pyplot as pyplot from dune.fem.function import levelFunction, partitionFunction import matplotlib