## 5 Examples
### Allen-Cahn Equation
Instead, we encounter an additional indirection through a cell-vertex list, where we gather all DoFs associated with the currently visited cell. We furthermore cannot construct the global linear system at once, but need to go through the cell-wise assembly process which effectively leads to most of the nonzero matrix entries being visited multiple times. This is in sharp contrast to the FDM where the global system is only present implicitly through functions that apply the Laplacian stencil. As a consequence, memory requirements are greatly reduced. ```
1 structFETtriangulationV,C>:Triangulation vertices:V connectivity:C dim:Int
5 end
6
7 structFiniteElement{C:ElementType, P<:Primitive,BC:AbstractMatrix, Q<:AbstractVector,Q<:AbstractArray} primitive:P
8 element_type:E
9 order:Int
10 ndofs:Int basis_coeffs:B
11 quadrature_nodes::B
12 quadrature_weights::Q
13 basis_at_quad::B
14 grad_basis_at_quad::G
15 grad_monomial_basis::G
16 end
17 structAssemblyCache{T<:AbstractVecOmMat}
18 coeffs::T
19 loc::T
20 glob::T
21 end
22 structCOProblem{T<:Triangulation,J,P,C}
23E<:FiniteElement,M<:AbstractMatrix, V<:AbstractVector,F<:Function}
24 triangulation::T
25 referenceElements::E
26 detJ::J
27 bilinearForm::M
28 linearForm::V
29i:V
30 nassMatrix::Union{M,Nothing}
31 parameters::P
32 rhs::F
33 cache::C
34
35 end
36 function(a::COProblem)(du,u,p,t)
37 mesh=a.triangulation, element=a.referenceElements
38K=a.bilinearForm
39F=a.linearForm
40 detJ=a.detJparams=a.parameters
41 cache,rhs=a.cache,rhs
42M=a.massMatrix
43
44 mull(du,K,u,-1,0.) 45#f(u)changes,thusweressemble
46 assemble_Ff(F,cache,u,element, mesh,detJ,params,rhs,M)
47 du.+=F
48
49 end
50
51 structFDTtriangulation{V,D}<:Triangulation vertices:D
52h:V#dziseachdim
53 dim::Int
54 dim::Int
55 end
56
57 structFDProblem{T<:FDTtriangulation, B<:Function,L<:Function}
58V<:AbstractArray,P,BC:Function}
59 triangulation::T
60 order:Int
61 bilinearForm::B
62 linearForm::L
63u:V
64 parameters::P
65 boundaryCondition::BC
66 end
66 function(a::FDProblem)(du,u,p,t)
67 apply_bilinear!=a.bilinearForm
68 apply_bcl=a.boundaryCondition
69h=a.grid.h
70 params=a.parameters
71
72
73
74
75
76
77
78
79a.bilinearForm(du,u,h)
90
91a.bilinearForm(du,u,h)
92
93a.bilinearForm(du,u,h)
94
95a.linearForm(du,u,a.parameters)
96a.boundaryCondition(du)
97 end
98 For transient problems, one needs to additionally make a suitable choice for the temporal discretization, that is, the choice of method as well as the time step. Here, we make use of the well-optimized Julia library DifferentialEquations.jl[73]. As an exemplary implementation of modern, high-performance codes for the solution of ordinary differential equations (ODEs), this package offers various algorithms that are capable of adaptive time stepping such that an application expert does not need to provide any input regarding temporal discretization. Here, in particular, we can even make use of built-in heuristics that automatically select a suitable integration scheme, based on the supplied ODE problem [74]. The resulting effort for the end user can be condensed to selecting a suitable numerical scheme for the spatial discretization, as outlined by Figure 5, and leave the problem of tuning the spatial discretization aside entirely, as it is not required for the application expert in the formulation of the ODE given above. For this particular problem, we prescribe the use of an adaptive, implicit, fourth-order Rosenbrock method for the temporal evolution of both FD and CG-FE systems to achieve a fair comparison between both solutions. This solver is stable and third-order accurate when used on nonlinear parabolic problems [73]. The spatially discretized, nonlinear problems at each time step are solved explicitly according to the timestep update functions given in Listing 1. Before comparing both schemes regarding computational efficiency, we first verify that the FD and collocated CG-FE schemes produce identical results.