<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Transient MMS Verification for Levelset Equation
Computes the forcing function for a transient MMS test, the selected solution is designed to reach steady-state rapidly.
Load the necessary python libraries.
Step1:  Define the Manufactured solution
Define the assumed (exact) solution as a fuction of x, y, and t that converges rapidly in time.
Step2:  Compute the forcing function.
Step3:  Build a string of the exact and forcing function to be copied to the input file (levelset_mms.i). 
The only syntax that needs to change to make this string work with MOOSE ParsedFunction is the exponent operator.
Step4:  Demonstrate how the solution reaches stead-state.
Verification of Computed Solution
Comparision of exact and compute solution at a point.
Read results files.
Step5:  Compute the exact solution at a point (0.1).
Step6:  Show the compute results with the exact solution.
Step7:  Convergence Plot
Extract error and number of dofs.
Step8:  Fit line to data.
<ASSISTANT_TASK:>
Python Code:
%matplotlib inline
import glob
from sympy import *
import numpy
import matplotlib.pyplot as plt
import pandas
init_printing()
Explanation: Transient MMS Verification for Levelset Equation
Computes the forcing function for a transient MMS test, the selected solution is designed to reach steady-state rapidly.
Load the necessary python libraries.
End of explanation
x,t,a,b= symbols('x t a b')
u = 1+a*exp(1/(10*t))*sin(2*pi/b*x)
u
Explanation: Define the Manufactured solution
Define the assumed (exact) solution as a fuction of x, y, and t that converges rapidly in time.
End of explanation
f = diff(u, t) + diff(u, x)
f
Explanation: Compute the forcing function.
End of explanation
str(u).replace('**', '^') 
str(f).replace('**', '^')
Explanation: Build a string of the exact and forcing function to be copied to the input file (levelset_mms.i). 
The only syntax that needs to change to make this string work with MOOSE ParsedFunction is the exponent operator.
End of explanation
filenames = glob.glob('level_set_mms_0*.csv')
print filenames
results = []
for fname in filenames:
    results.append(pandas.DataFrame(pandas.read_csv(fname, index_col='time')))
Explanation: Demonstrate how the solution reaches stead-state.
Verification of Computed Solution
Comparision of exact and compute solution at a point.
Read results files.
End of explanation
times = results[-1]['point'].keys()
pfunc = Lambda(t, u.subs([(x, 0.1), (a, 1), (b, 8)]))
exact = pandas.Series([pfunc(i).evalf() for i in times], index=times)
Explanation: Compute the exact solution at a point (0.1).
End of explanation
fig = plt.figure(figsize=(18,9))
axes = fig.add_subplot(111)
axes.plot(exact.keys(), exact.values, '-k', linewidth=3, label='exact') # pandas.Series plot method not working
for i in range(len(results)):
    x = results[i]['point'].keys()
    y = results[i]['point'].values
    axes.plot(x, y, label='Level ' + str(i))
plt.legend(loc='lower left')
Explanation: Show the compute results with the exact solution.
End of explanation
n = len(results)
error = numpy.zeros(n)
h = numpy.zeros(n)
for i in range(n):
    error[i] = results[i]['error'].iloc[-1]
    h[i] = 1./results[i]['h'].iloc[-1]
Explanation: Convergence Plot
Extract error and number of dofs.
End of explanation
coefficients = numpy.polyfit(numpy.log10(h), numpy.log10(error), 1)
coefficients
fig = plt.figure(figsize=(18,9))
axes = fig.add_subplot(111)
axes.plot(h, error, 'sk')
axes.set(xscale='log', yscale='log', xlabel='1/h', ylabel='L2 Error',)
polynomial = numpy.poly1d(coefficients)
axes.plot(h, pow(10, polynomial(numpy.log10(h))))
axes.grid(True, which='both')
plt.text(h[0], error[-1], 'Slope: ' + str(coefficients[0]), fontsize=14)
Explanation: Fit line to data.
End of explanation
<END_TASK>