Hello FEniCS folks,
I have been playing around with manual adaptivity using cell markers. While
things work fine in 2D, I encounter an error in 1D.
Below is the relevant piece of code which might give people who know the
routine some direction, and I have also listed subsequently the error
message. Attached are files with complete codes.
To emphasize again, the code works fine in 2D.
Any help will be appreciated.
###################
import numpy as np
import dolfin as dfa
cell_markers = df.CellFunction("bool",mesh)
cell_markers.set_all(False)
for cell in df.cells(mesh):
xc = df.MeshEntity.midpoint(cell).x()
urv = np.random.rand(1,1)
if xc > urv:
cell_markers[cell] = True
refMesh_nonUniform = df.refine(mesh,cell_markers)
###################
***
-------------------------------------------------------------------------
*** Error: Unable to add cell using mesh editor.
*** Reason: Vertex index (18) out of range [0, 18).
*** Where: This error was encountered inside MeshEditor.cpp.
*** Process: unknown
***
*** DOLFIN version: 1.5.0
*** Git changeset: unknown
***
-------------------------------------------------------------------------
Thanks
Jayanth
--
Jayanth Jagalur Mohan
Postdoctoral Research Associate
Department of Aeronautics and Astronautics, MIT
77 Massachusetts Ave, Room 37-427
Cambridge, MA 02139 USA
Phone: 617-253-3549
EMail: [email protected] <[email protected]>
#========================================================================================================================
import os, sys, time
import numpy as np
import scipy as sp
import dolfin as df
#========================================================================================================================
if __name__ == '__main__':
## Define source
source = df.Expression("10*exp(-pow(x[0] - 0.5, 2)/0.2)",degree=1)
## Define mesh, function space, and BC
mesh = df.UnitIntervalMesh(10)
V = df.FunctionSpace(mesh, "CG", 1)
u = df.TrialFunction(V)
v = df.TestFunction(V)
u0 = df.Function(V)
bc = df.DirichletBC(V, u0, "x[0] < DOLFIN_EPS || x[0] > 1.0 - DOLFIN_EPS")
## Define weak form
bForm = df.inner(df.grad(u), df.grad(v))*df.dx
lFunc = source*v*df.dx
## Compute solution on initial mesh
u = df.Function(V)
df.solve(bForm==lFunc,u,bc)
## Plot solution resulting from initial mesh
df.plot(u, interactive=True)
## refine mesh
cell_markers = df.CellFunction("bool",mesh)
cell_markers.set_all(False)
for cell in df.cells(mesh):
xc = df.MeshEntity.midpoint(cell).x()
urv = np.random.rand(1,1)
if xc > urv:
cell_markers[cell] = True
## print to stdout cells that have been marked for refinement
print [cell_markers[i] for i in df.cells(mesh)]
refMesh_uniform = df.refine(mesh)
refMesh_nonUniform = df.refine(mesh,cell_markers)
#=========================================================================================================================
#========================================================================================================================
import os, sys, time
import numpy as np
import scipy as sp
import dolfin as df
#========================================================================================================================
if __name__ == '__main__':
## Define source
source = df.Expression("10*exp(-(pow(x[0] - 0.5, 2) + pow(x[1] - 0.5, 2)) / 0.02)",degree=1)
## Define mesh, function space, and BC
mesh = df.UnitSquareMesh(10,10)
V = df.FunctionSpace(mesh, "CG", 1)
u = df.TrialFunction(V)
v = df.TestFunction(V)
u0 = df.Function(V)
bc = df.DirichletBC(V, u0, "x[0] < DOLFIN_EPS || x[0] > 1.0 - DOLFIN_EPS || x[1] < DOLFIN_EPS || x[1] > 1.0 - DOLFIN_EPS")
## Define weak form
bForm = df.inner(df.grad(u), df.grad(v))*df.dx()
lFunc = source*v*df.dx()
## Compute solution on initial mesh
u = df.Function(V)
df.solve(bForm==lFunc,u,bc)
## Plot solution resulting from initial mesh
df.plot(u, interactive=True)
## refine mesh
cell_markers = df.CellFunction("bool",mesh)
cell_markers.set_all(False)
for cell in df.cells(mesh):
xc = df.MeshEntity.midpoint(cell).x()
urv = np.random.rand(1,1)
if xc > urv:
cell_markers[cell] = True
## print to stdout cells that have been marked for refinement
print [cell_markers[i] for i in df.cells(mesh)]
refMesh_uniform = df.refine(mesh)
refMesh_nonUniform = df.refine(mesh,cell_markers)
#=========================================================================================================================
_______________________________________________
fenics mailing list
[email protected]
http://fenicsproject.org/mailman/listinfo/fenics