218
views
0
4 months ago by
Hollo everyone!
I am solving the oriented-goal adaptive solve.
The test code is following

from dolfin import *
#encoding=utf-8
# Define mesh

mesh = UnitSquareMesh(8, 8)

# Create classes for defining parts of the boundaries
class Left(SubDomain):
def inside(self, x, on_boundary):
return near(x[0], 0.0)

class Right(SubDomain):
def inside(self, x, on_boundary):
return near(x[0], 1.0)

class Bottom(SubDomain):
def inside(self, x, on_boundary):
return near(x[1], 0.0)

class Top(SubDomain):
def inside(self, x, on_boundary):
return near(x[1], 1.0)

# Initialize sub-domain instances
left = Left()
top = Top()
right = Right()
bottom = Bottom()

# Initialize mesh function for boundary domains
boundaries = FacetFunction("size_t", mesh)
boundaries.set_all(0)
left.mark(boundaries, 1)
top.mark(boundaries, 2)
right.mark(boundaries, 3)
bottom.mark(boundaries, 4)

# Define function space and basis functions
V = FunctionSpace(mesh, "CG", 2)
u = TrialFunction(V)
v = TestFunction(V)

# Define input data
a0 = Constant(1.0)
a1 = Constant(0.01)
g_L = Expression("- 10*exp(- pow(x[1] - 0.5, 2))")
g_R = Constant("1.0")
f = Constant(1.0)

# Initialize mesh function for interior domains
class Obstacle(SubDomain):
def inside(self, x, on_boundary):
return (between(x[1], (0.5, 0.7)) and between(x[0], (0.2, 1.0)))

obstacle = Obstacle()
domains = CellFunction("size_t", mesh)
domains.set_all(0)

obstacle.mark(domains, 1)

# Define Dirichlet boundary conditions at top and bottom boundaries
bcs = [DirichletBC(V, 5.0, boundaries, 2),
DirichletBC(V, 0.0, boundaries, 4)]

# Define new measures associated with the interior domains and
# exterior boundaries
dx = Measure("dx")[domains]
ds = Measure("ds")[boundaries]

# Define variational form
- g_L*v*ds(1) - g_R*v*ds(3)
- f*v*dx(0) - f*v*dx(1))

# Separate left and right hand sides of equation
a, L = lhs(F), rhs(F)
tol=1e-4

# Solve problem
u = Function(V)
M=u*dx(1)
problem=LinearVariationalProblem(a,L,u,bcs)
solver.solve(tol)
solver.summary()

# Plot solution
plot(u, title="u")
interactive()

why is the code  running wrong?

Generating forms required for error control, this may take some time...
Solving linear variational problem.
Value of goal functional is 1.71367.
Solving linear variational problem.
5 cells out of 128 marked for refinement (3.9%).
Number of cells increased from 128 to 169 (32.0% increase).
Traceback (most recent call last):
File "b.py", line 97, in <module>
solver.solve(tol)
File "/usr/lib/python2.7/dist-packages/dolfin/fem/adaptivesolving.py", line 80, in solve
RuntimeError:

*** -------------------------------------------------------------------------
*** DOLFIN encountered an error. If you are not able to resolve this issue
*** using the information listed below, you can ask for help at
***
*** fenics@fenicsproject.org

How should i solve it?

Best wishes!
Community: FEniCS Project
Could you please include the whole error message (you just omitted the last bit with the actual information about the error)?
written 4 months ago by Marie E. Rognes
When I run it, I get
*** Error:   Unable to adapt mesh function.
*** Reason:  Unable to extract information about parent mesh entities.
*** Where:   This error was encountered inside adapt.cpp.
​

It works using the solution posted here: https://fenicsproject.org/qa/6719/using-adapt-on-a-meshfunction-looking-for-a-working-example

written 4 months ago by Adam Janecka