Simulation Examples 2 S. A. Silber and M. Karttunen, “SymPhas —General Purpose Software for Phase- Field, Phase-Field Crystal, and Reaction- Diffusion Simulations,” Adv. Theory Simul., vol. 5, Art. no. 1, Dec. 2021.
solutions to phase-field problems • P.F. Model → system of PDEs (1st order in time) • Symbolic algebra manipulation of phase-field models • User-defined P.F. Model → solver-enabled representation 3
3 dimensions • Any number of order parameters • Real-, complex- or vector- valued order parameters • Phase-field, phase-field crystal or reaction-diffusion • I.e. User-defined P.F. Models 4
→ io → datatypes → sol → conf • Module selection and compilation process: → CMake build process allows the user to: → Select modules & compilation parameters for SymPhas → Install SymPhas library to OS → Import SymPhas to other CMake projects SymPhas API & Implementation 7
User-defined driver file using SymPhas API (as few as 22 lines) Phase-field models implemented via macro-based grammar User-implemented solvers simplified with C++ macros • Included in software: • Driver files (including a “smallest working” implementation) • Model definitions (phase-field & phase-field crystal) • Solvers (forward Euler + semi-implicit Fourier spectral) 8
maintenance-friendly techniques → Reducing coupling/increasing cohesion → Single responsibility principle → Common namespaces → Informative function names → Data groups → API specific type aliases + Extensive documentation (using Doxygen) Object design User facing functionality 9
→ Parallelization with OpenMP & C++ execution header → Layered object design to streamline & minimize data passing → Minimal branching for all P.F. model simulations → Template metaprogramming 10
Generic programming AKA template metaprogramming → Everything is a type …As opposed to inheritance and virtual dispatch → C++ templates and generics → “Template argument deduction” 12
Data Working Data System System System Uniform Grid Uniform Grid Uniform Grid Equation of Motion Equation of Motion Equation of Motion 𝐸(𝜓1 , 𝜓2 , 𝜓3 ) 𝜓1 𝜓2 𝜓3 Solver 19
Data Working Data System Uniform Grid System Uniform Grid System Uniform Grid Equation of Motion Equation of Motion Equation of Motion 𝐸(𝜓1 , 𝜓2 , 𝜓3 ) 𝜓1 𝜓2 𝜓3 Solver 20
Working Data System Uniform Grid System Uniform Grid System Uniform Grid Equation of Motion Equation of Motion Working Data Equation of Motion 𝐸(𝜓1 , 𝜓2 , 𝜓3 ) 𝜓1 𝜓2 𝜓3 Solver 21
(incl. user-defined solvers) • Different System specializations based on Solver type • Different Grid specializations based on System type • Different Model types for phase-field and phase-field crystal problems 22
the form… • How the equation will be used: → Evaluated multiple times (e.g., each solver loop) → Modified to fit the design of a given numerical solver 25
→ virtual dispatch deterministic control flow → Deterministic control ⇨ object types are fixed • Deterministic control flow via expression templates → ⇓ Runtime ⇑ Compile Time Since: C++ is a compiled language, Then: Types must be known at point of invocation … notion of “compile-time constant” expression trees 27
→ Defines an interface that every specialization must implement • Basic terms: Node term → OpExpression Variable term → Data instance (i.e. order parameter) Literal term → A number Binary term → An operation 28
: OpExpression<OpLVariable<T, G>> { T value; G data; OpLVariable(T value, G data) : value{ value }, data{ data } {} auto eval(iter_type n) const { return value * BaseData<G>::evaluate(data, n); } ... 32
OpLVariable : OpExpression<OpLVariable<T, G>> { T value; G data; OpLVariable(T value, G data) : value{ value }, data{ data } {} auto eval(iter_type n) const { return value * BaseData<G>::evaluate(data, n); } ... 33
function with arguments → Factoring to cancel terms in a division → Transmuting terms → “Pretty printing” of expressions → Custom symbolic algebra terms 36
(K_t), expr::is_K_type<K_t>::value, K<order_K_type<K_t>::value>) template<size_t O> template<typename T, size_t D> struct K<O>::WaveVectorData : Grid<T, D>, K<O> { ... }; “Type identity” of the object: → i.e. the “class” or “identity” of the object in the symbolic algebra
• Model C (coupled A & B) • PFC (conserved dynamics) • Validate dynamics of A & B using Porod’s Law • Structure Factor ⇨ measures the amount of “solidification” 𝑆 𝑘 ~ 𝑘𝑑+1 −1 Solved using spectral solver 42
2D & 3D 43 S. A. Silber and M. Karttunen, “SymPhas —General Purpose Software for Phase-Field, Phase-Field Crystal, and Reaction-Diffusion Simulations,” Adv. Theory Simul., vol. 5, Art. no. 1, Dec. 2021.
difference stencil → A linear combination of grid elements around a given point → Stencil is characterized by: Dimension of the system Order of accuracy of the approximation Derivative order that is approximated (Also number of grid points in the stencil) ∇2𝜓 2D uniform grid 𝒪(ℎ4) 𝒪(ℎ2) 𝚫𝒙 𝚫𝒚 𝚫𝐱 = 𝚫𝐲 = 𝒉 67
is determined in Fourier space → Forms a natural basis set for computational domain (FFT & grids) • Apply the Fourier transform and solve as a linear ODE 71