File size: 3,912 Bytes
fdd9b49 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | """ Define Poisson problem """
from dolfin import *
from ..tools import AdaptableLinearProblem, LinearPDE, poisson_indicator
from .params_physical import *
parameters["allow_extrapolation"] = True
parameters["refinement_algorithm"] = "plaza_with_parent_facets"
__all__ = ["PoissonProblem", "Poisson", "PoissonProblemAxisym", "PoissonProblemPureNeumannAxisym"]
class PoissonProblem(AdaptableLinearProblem):
k = 1
method = dict(
reuse = True,
iterative = True,
lusolver = ("superlu_dist" if has_lu_solver_method("superlu_dist") else "default"),
luparams = dict(
symmetric = True,
same_nonzero_pattern = True,
reuse_factorization = True,),
ks = "cg",
kp = "amg",
kparams = dict(
maximum_iterations = 200,
monitor_convergence = False,
relative_tolerance = 1e-4,
error_on_nonconvergence = False,
preconditioner = dict(
ilu = dict(fill_level = 1)))
)
@staticmethod
def space(mesh):
return FunctionSpace(mesh, 'CG', PoissonProblem.k)
@staticmethod
def forms(V, geo, f):
u = TrialFunction(V)
v = TestFunction(V)
dx = geo.dx()
grad = geo.physics.grad
lscale = geo.physics.lscale
eps = geo.pwconst('permittivity')
a = inner(eps*grad(u), grad(v))*dx
L = f*v*dx + geo.linearRHS(v, "volcharge") + lscale*geo.NeumannRHS(v, "surfcharge")
return (a, L)
def __init__(self, geo, phys=None, bcs=None, f=None, u=None):
mesh = geo.mesh
V = self.space(mesh)
C0 = Constant(0.0)
if f is None:
f = C0
if u is None:
u = Function(V)
if bcs is None:
try:
if phys.bV is None:
bcs = [geo.BC(V, C0, "ground")]
else:
bcs = [geo.BC(V, phys.bV, "bV"),
geo.BC(V, C0, "ground")]
except:
warning("No boundary conditions have been assigned to %s" %type(self).__name__)
a, L = self.forms(V, geo, f)
AdaptableLinearProblem.__init__(self, a, L, u, bcs, geo.boundaries)
class PoissonProblemPureNeumannAxisym(PoissonProblem):
method = PoissonProblem.method
method["ks"] = "bicgstab"
@staticmethod
def space(mesh):
V = FunctionSpace(mesh, "CG", PoissonProblemPureNeumannAxisym.k)
R = FunctionSpace(mesh, "R", 0)
return V * R
@staticmethod
def forms(V, geo, f):
(u,b) = TrialFunctions(V)
(v,c) = TestFunctions(V)
dx = geo.dx()
grad = geo.physics.grad
lscale = geo.physics.lscale
r = Expression("2*pi*x[0]")
eps = geo.pwconst('permittivity')
a = inner(eps*grad(u), grad(v))*r*dx + (b*v + c*u)*r*dx
L = f*v*r*dx + geo.linearRHS(v*r, "volcharge")
L = L + lscale*geo.NeumannRHS(v*r, "surfcharge")
return (a, L)
class PoissonProblemAxisym(PoissonProblem):
@staticmethod
def forms(V, geo, f):
u = TrialFunction(V)
v = TestFunction(V)
dx = geo.dx()
grad = geo.physics.grad
lscale = geo.physics.lscale
r = Expression("2*pi*x[0]")
eps = geo.pwconst('permittivity')
a = inner(eps*grad(u), grad(v))*r*dx
L = f*v*r*dx + geo.linearRHS(v*r, "volcharge")
L = L + lscale*geo.NeumannRHS(v*r, "surfcharge")
return (a, L)
class Poisson(LinearPDE):
def __init__(self, geo, **params):
LinearPDE.__init__(self, geo, PoissonProblem, **params)
def estimate(self):
return poisson_indicator(self.geo, self.functions.values()[0])
|