This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

create circle mesh, use of "Circle()" results in non convergence

+2 votes

Hey,
wanted to use the function circle = Circle (0,0,1) and mesh = Mesh(circle,20) to solve the simple parabolic PDE $\partial_t u - \Delta u = 0$ with initial condition $u(0,x_1, x_2) = x_1 + 3$, but the NewtonSolver is not converging.
However, for mesh = UnitSquareMesh(20, 20) or mesh = UnitCircle(20) everything is fine and I get the expected steady state solution $u = 3.5$, respectively $u = 3.0$. What is going on, do I make some stupid mistake while using Circle()?
Thanks in advance for your help.

from __future__ import division

from dolfin import *
import numpy as np

import matplotlib as mpl
mpl.use( "agg" )
import matplotlib.pyplot as plt
from matplotlib import animation
from math import exp
from math import sin
from math import cos
from math import pow
from math import tanh

# to shut off the output
set_log_level(WARNING)

nx = 20
circle = Circle (0.0,0.0,1)
mesh = Mesh(circle,20)
#mesh = UnitSquareMesh(nx, nx)
#mesh = UnitCircle(20)


plot(mesh,axes=True)
interactive()

# definition of solving method
V = FunctionSpace(mesh, 'CG', 1)

T = 10
dt = 1/(80)

# ------------------- RHS, exact solution
# RHS
def rhs(u):
  return 0

u_start = Expression("x[0] + 3")
# ------------------- RHS, exact solution

# ------------------- boundary conditions
# Define boundary segments
class outer_boundary(SubDomain):
    def inside(self, x, on_boundary):
        tol = 1E-13   # tolerance for coordinate comparisons
        return on_boundary and  abs( x[0]*x[0] + x[1]*x[1] - 9) < tol
class left(SubDomain):
    def inside(self, x, on_boundary):
        tol = 1E-13   # tolerance for coordinate comparisons
        return on_boundary and abs(x[0]) < tol


z_old = Function(V)
z_old = interpolate(u_start,V)
z = Function(V)
z = interpolate(u_start,V)
dz = TrialFunction(V)
w = TestFunction(V)
# - dt*g_N*w*dssE(2)
F_N = inner(z-z_old,w)*dx + dt*dot(grad(z), grad(w))*dx - inner(dt*rhs(z),w)*dx 
dF_N = derivative(F_N, z, dz)

problem = NonlinearVariationalProblem(F_N, z, J = dF_N)
pdesys_Euler = NonlinearVariationalSolver(problem)

plot(z, title='impl Euler',axes=True)
interactive()

# ---------- update of time dependent data
t = dt

# ---------- time steps
while t <= T+dt:

    # ---------- Newton
    # Euler
    pdesys_Euler.solve()

    # ---------- assigning of solution from previous time step
    z_old.assign(z)

    if (t >0.99 and t < 1.01):
      plot(z)
      interactive()

    if (t >1.99 and t < 2.01):
      plot(z)
      interactive()
    t += dt
asked Feb 27, 2014 by bobby53 FEniCS User (1,260 points)

Hi, I'd just like to add that the solver works fine for Mesh(circle, n) with n in [1, 8] and with n larger the results start to go wrong.

As a follow up to this question, is it somehow possible to extract some parts of the mesh created by mesh = UnitCircle(20)?
I need a mesh with a whole in it, something like

big_C = Circle (0, 0, 1)
small_c  = Circle (0,0,0.5)
g2d = big_C - small_c
mesh = Mesh(g2d, 25)

but, as Circle() doesn't seem to work I need to find some kind of workaround.
If there is none, I would have to generate a mesh outside of Fenics and import it.

Isn't the issue caused by [this bug][https://bitbucket.org/fenics-project/dolfin/issue/224/cgal-produces-degenerate-cells]? You can test it by similar example as in description of the bug. If it is the case, try development version - it should fix the problem.

You're correct Jan, the code runs fine with the development version.

Yepp, the mesh defined by

 circle = Circle (0.0,0.0,1)
 mesh = Mesh(circle,20)

is degenerated. I didn't already get the development version to run, but I trust MiroK ;-)
Thanks Jan for your comment, it's nice to know what exactly isn't working.

1 Answer

+1 vote
 
Best answer

To get a good quality circle mesh, use

mesh = CircleMesh(Point(0, 0), 1.0, 0.05)

You'll need to have DOLFIN configured with CGAL.

answered Mar 10, 2014 by Garth N. Wells FEniCS Expert (35,930 points)
selected Mar 10, 2014 by bobby53

Hey Garth,
thank you for your answer. My intention by using Mesh(circle,20) was to generate a mesh with a hole in it, which I can't do with a mesh generated by mesh = CircleMesh(Point(0, 0), 1.0, 0.05), so I'm going to use the developers version.

...