Hey Guys,
I hope you are great. I am completely new to Fenics and this is my first time posting to the group. I appreciate that if you can help me.
I am working on some phase field problem. For start, I need to solve a time-dependent Ginzburg-Landau equation with a highly nonlinear source term:
(1/lmda) du/dt = lmbdabettagrad^2(u) - 2Almbda*(u+2u3-3u2)+12lmbdadelG*(u2 - u3)
where all the coefficients are given below in the code. In fact, the RHS is the driving force for propagation of interface. u is in fact a scalar parameter. The initial condition for u is pow(1+exp(x[0] - 0.5), -1).
I have started from Cahn-Hilliard equation, then try the nonlinear time-dependent burgers equation, However I was not able to solve the problem. The latest code that I have written is given below for your consideration:
from fenics import *
Class for interfacing with the Newton solver
class GinzburgLandau(NonlinearProblem):
def init(self, a, L):
NonlinearProblem.init(self)
self.L = L
self.a = a
def F(self, b, x):
assemble(self.L, tensor=b)
def J(self, A, x):
assemble(self.a, tensor=A)
Create mesh and build function space
mesh = UnitSquareMesh(80, 80)
V = FunctionSpace(mesh, âPâ, 2)
Define trial and test functions
du = TrialFunction(V)
v = TestFunction(V)
Define functions and initial condition
u = Function(V) # current solution
u_n = Function(V) # solution from previous converged step
u_init = Expression(âpow((1+exp((x[0] - 0.5) / 2.95e-9)), -1)â, degree=2)
u.interpolate(u_init)
u_n.interpolate(u_init)
Weak statement of the equations
lmbda = 2600.0
betta = 2.59e-10
delG = -1073.3e6
A = 7924.0e6
dt = 0.1e-14
k = Constant(dt)
L0 = uvdx - u_nvdx + lmbdabettakdot(grad(u), grad(v))dx
L1 = (2kAlmbda(u + 2u**3 - 3u2) + 12klmbdadelG(u2 - u**3))vdx
L = L0 + L1
Compute directional derivative about u in the direction of du (Jacobian)
a = derivative(L, u, du)
Create nonlinear problem and Newton solver
problem = GinzburgLandau(a, L)
solver = NewtonSolver()
solver.parameters[âlinear_solverâ] = âluâ
solver.parameters[âpreconditionerâ] = âiluâ
solver.parameters[âconvergence_criterionâ] = âincrementalâ
solver.parameters[ârelative_toleranceâ] = 1e-12
solver.parameters[âabsolute_toleranceâ] = 1e-13
solver.parameters[âmaximum_iterationsâ] = 25
solver.parameters[ârelaxation_parameterâ] = 1.2
file_u = File(âginzburglandau/u.pvdâ)
num_steps = 500
t = 0.0
for n in range(num_steps):
# Update current time
t += dt
print('t = ', t)
solver.solve(problem, u.vector())
file_u << u
# Update the previous solution
u_n.assign(u)
Unfortunately, the interface does not propagate with time and it stops in the middle of the square. I appreciate that if you can show me a start point that I can get to the solution of my problem.
I know you are really busy, but it would be very kind of you if you can respond it.
Looking forward to hearing form you.
Bests,
Benhour