property_list = [0, 2, 1]
store_step = 20

meta_data = outdir_base + "meta_data.txt"
conservation_data = outdir_base + "conservation_data.csv"

# Helper vectors
ex = as_vector([1.0, 0.0])
ey = as_vector([0.0, 1.0])

mesh = RectangleMesh(MPI.comm_world, Point(xmin, ymin), Point(xmax, ymax), nx,
                     ny)
n = FacetNormal(mesh)

# xdmf output
xdmf_u = XDMFFile(mesh.mpi_comm(), outdir_base + "u.xdmf")
xdmf_p = XDMFFile(mesh.mpi_comm(), outdir_base + "p.xdmf")
xdmf_rho = XDMFFile(mesh.mpi_comm(), outdir_base + "rho.xdmf")

# Function Spaces density tracking/pressure
T_1 = FunctionSpace(mesh, 'DG', 0)
Q_E_Rho = FiniteElement("DG", mesh.ufl_cell(), k)

# Vector valued function spaces for specific momentum tracking
W_E_2 = VectorElement("DG", mesh.ufl_cell(), k)
T_E_2 = VectorElement("DG", mesh.ufl_cell(), 0)
Wbar_E_2 = VectorElement("DGT", mesh.ufl_cell(), kbar)
Wbar_E_2_H12 = VectorElement("CG", mesh.ufl_cell(), kbar)["facet"]

# Function spaces for Stokes
Q_E = FiniteElement("DG", mesh.ufl_cell(), 0)
dt = Constant(0.025)
num_steps = int(np.rint(T_end / float(dt)))
xmin, ymin = 0., 0.
xmax, ymax = 1., 1.
xc, yc = 0.25, 0.5
nx, ny = 32, 32
pres = 400
k = 1

# Directory for output
outdir_base = './../../results/MovingMesh/'

mesh = RectangleMesh(Point(xmin, ymin), Point(xmax, ymax), nx, ny)
n = FacetNormal(mesh)

outfile = File(mesh.mpi_comm(), outdir_base+"psi_h.pvd")

V = VectorFunctionSpace(mesh, 'DG', 2)
Vcg = VectorFunctionSpace(mesh, 'CG', 1)

boundaries = MeshFunction("size_t", mesh, mesh.topology().dim()-1)
boundaries.set_all(0)
ds = Measure('ds', domain=mesh, subdomain_data=boundaries)

# Create function spaces
Q_E_Rho = FiniteElement("DG", mesh.ufl_cell(), k)
T_1 = FunctionSpace(mesh, 'DG', 0)
Qbar_E = FiniteElement("DGT", mesh.ufl_cell(), k)

Q_Rho = FunctionSpace(mesh, Q_E_Rho)
Qbar = FunctionSpace(mesh, Qbar_E)
        #- inner(f, w)*dx(1) \


    a, L = lhs(F), rhs(F)

    # Assemble rhs (once)
    A = assemble(a)

    # Create GMRES Krylov solver
    solver = KrylovSolver(A, "gmres")

    # Create solution function
    S = Function(W)

    # Solving loop
    xdmf_file = XDMFFile(mesh.mpi_comm(), "output/elastodynamics.xdmf")

    if record:
        pvd  = File("paraview/{}.pvd".format(file_name))
        pvd << (u0, t)


    # =========== TIME TO PML =========== #
    #n = 100
    #u_s_0 = parametrized_initial_u_and_times(u0, Lx, Ly, n)
    #time_array_x = p.zeros(n)
    #time_array_y = p.zeros(n)

    # =================== EXPERIMEnT InFO ==================== #
    txt_file =  open(r"surface_2layers_animations_and_info/{}_info.txt".format(file_name),"w+") 
    if experiment != "12":