Hello,
I am trying to solve the Allen-Cahn equation. My formulation is complex, and I am a bit lost on how to implement it.
First, I have an energy functional E, which has the form:
in which Eta and c_s are both functions, but c_s is a known function, evaluated in the previous time step. For now, it can be considered as a constant function.
Then I have my strong form:
The operator on the right-hand side is a variational differential operator. It can be considered as a differential operator for a functional. So basically, after evaluating E with the first formula, I need to differentiate it with respect to Eta.
My weak form looks like:
with v as the test function, Eta_{n+1} as the trial function and Eta_n is known from previous time step.
My question is: How do I implement this?
First, I need to evaluate the energy functional E over the domain by integration, but maintain Eta as a function. This is where I am lost. I thought of using the assemble()
function to evaluate the integral, but this gives me a single scalar. I believe E might be different for each cell and thus can not be a single scalar.
Second, how can I differentiate this functional E with respect to Eta and apply it in the weak form.
I would like to know, how I could construct the variational formulation for my problem and implement it in the solve()
function. I have attached my code, but I apologize, I have not been able to make much progress.
Any help is greatly appreciated.
Code:
from fenics import *
import numpy as np
import matplotlib.pyplot as plt
tol = 1e-4
def main():
T = 150
num_steps = 10
dt = T / num_steps
# Create mesh and define function space
# mesh = dolfin.Mesh()
mesh = UnitSquareMesh(8, 8)
V = FunctionSpace(mesh, 'Lagrange', 1)
eta = Function(V)
eta = interpolate(Constant(1.0), V)
c_s = Function(V)
c_s = interpolate(Constant(1.0), V)
i = assemble(-2*eta**3*c_s*dx)
print(i)
if __name__ == '__main__':
main()