Hi everyone,
I am new to Fenics/Python and have a problem concerning the AdaptiveLinearVariationalSolver. In the code below a Poisson equation is solved adaptively with respect to the energy norm as goal function and a summary of the adaptive interation process is printed out by solver.summary(). I would like to access the data in this summary (like functional values in each step etc.) and write it in a variable for further processing. So far I haven’t figured yet how to access the data in the summary and also haven’t found anything useful by researching that topic.
Thanks in advance.
from dolfin import *
import numpy as np
Create mesh and define function space
mesh = UnitSquareMesh(4, 4)
V = FunctionSpace(mesh, “Lagrange”, 1)
Define boundary condition
u0 = Function(V)
bc = DirichletBC(V, u0, “x[0] < DOLFIN_EPS || x[0] > 1.0 - DOLFIN_EPS”)
Define test-/trial functions, source term and Neumann boundary conditions
u = TrialFunction(V)
v = TestFunction(V)
f = Expression(“10exp(-(pow(x[0] - 0.5, 2) + pow(x[1] - 0.5, 2)) / 0.02)",
degree=1)
g = Expression("sin(5x[0])”, degree=1)
Define variational problem
a = inner(grad(u), grad(v))dx()
L = fvdx() + gv*ds()
Define function for the solution
u = Function(V)
Define goal functional (quantity of interest)
M =inner(grad(u),grad(u))*dx()
Define error tolerance
tol = 1.e-3
Solve adaptively
problem = LinearVariationalProblem(a, L, u, bc)
solver = AdaptiveLinearVariationalSolver(problem, M)
solver.solve(tol)
solver.summary()