Next Article in Journal
Reclaiming XAI as an Innovation in Healthcare: Bridging Rule-Based Systems
Previous Article in Journal
PISI: Physical Information Based Solver-Interactive Network Structure Reconstruction
 
 
Font Type:
Arial Georgia Verdana
Font Size:
Aa Aa Aa
Line Spacing:
Column Width:
Background:
Article

2D/3D Pattern Formation Comparison Using Spectral Methods to Solve Nonlinear Partial Differential Equations of Condensed and Soft Matter

by
Marco A. Morales
1,*,
Dania A. Pérez-Muñoz
1,
J. Alejandro Hernández-González
1,
Miguel Alvarado-Flores
1 and
Sinuhé Ruiz-Salgado
2
1
Facultad de Ingeniería Química, Benemérita Universidad Autónoma de Puebla, Av. San Claudio y 18 sur C. U. Col. San Manuel, Puebla 72570, Mexico
2
Área Académica de Ciencias de la Tierra y Materiales, Instituto de Ciencias Básicas e Ingeniería, Universidad Autónoma del Estado de Hidalgo, Pachuca 42184, Mexico
*
Author to whom correspondence should be addressed.
Algorithms 2025, 18(9), 585; https://doi.org/10.3390/a18090585
Submission received: 6 August 2025 / Revised: 6 September 2025 / Accepted: 6 September 2025 / Published: 16 September 2025
(This article belongs to the Section Algorithms for Multidisciplinary Applications)

Abstract

It is well known that nonlinear partial differential equations (NLPDEs) can only be solved numerically and that fourth-order NLPDEs in their derivatives require unconventional methods. This paper explains spectral numerical methods for obtaining a numerical solution by Fast Fourier Transform (FFT), implemented under Python in tis version 3.1 and their libraries (NumPy, Tkinter). Examples of NLPDEs typical of Condensed Matter Physics to be solved numerically are the conserved Cahn–Hilliard, Swift–Hohenberg and conserved Swift–Hohenberg equations. The last two equations are solved by the first- and second-order exponential integrator method, while the first of these equations is solved by the conventional FFT method. The Cahn–Hilliard equation, a phase-field model with an extended Ginzburg–Landau-like functional, is solved in two-dimensional (2D) to reproduce the evolution of the microstructure of an amorphous alloy Ce75Al25 − xGax, which is compared with the experimental micrography of the literature. Finally, three-dimensional (3D) simulations were performed using numerical solutions by FFT. The second-order exponential integrator method algorithm for the Swift–Hohenberg equation implementation is successfully obtained under Python by FFT to simulate different 3D patterns that cannot be obtained with the conventional FFT method. All these 2D/3D simulations have applications in Materials Science and Engineering.

1. Introduction

It is of paramount importance to find the numerical solutions of different nonlinear partial differential equations (NLPDEs). These are ubiquitous in various areas of science, such as nonlinear physics, nonlinear chemistry, mathematical biology and computational science, and engineering in materials. The numerical solution of an NLPDE is an essential ingredient of two-dimensional (2D) and three-dimensional (3D) computational simulation. There are several methods for finding a numerical approximation of these equations. Pseudo-spectral methods are based on replacing NLPDEs with an equation of ordinary difference [1,2,3,4]. These types of procedures are challenging to implement in a high-level programming language. Nevertheless, the spectral methods of implementation are easy under Python and their libraries [5,6,7,8,9] to develop numerical 2D and 3D solutions, because it reduces the calculation time of the numerical solution compared to Euler’s and finite difference methods, which are based on derivative approximation [10,11]. In this sense, new libraries under Python have been developed to facilitate 3D computational simulation such as Mayavi [12], PyVista [13], or FiPy, which uses the finite volume method to reduce the NLPDE to a form tractable to linear solvers [14], or libraries such as FEniCS [15,16] that use more general theoretical schemes such as the Finite Element Method for the same purpose.
There is also extensive use of FFT both directly and indirectly as a component in other algorithms for microstructure simulation of various materials [10,17]. Specifically, the microstructure evolution was simulated due to the substitution of Ga in the amorphous alloy Ce75Al25 − xGax in 2D [4] and 3D systems using the phase-field method based on the Cahn–Hilliard equation by the conventional FFT method. This algorithm is described in detail, and was used as the basis for the development and implementation under Python, and the conserved and not conserved Swift–Hohenberg equations by the first- and second-order exponential integrative method were also used, respectively.

2. Materials Mathematical Models and Their Integration Rules

Cahn–Hilliard equation: As an example, a phase-field model based on the Cahn–Hilliard equation is used to understand the evolution of the microstructure due to the substitution of Ga in the amorphous alloy Ce75Al25 − xGax [4,17]. The spatial–temporal evolution is expressed for the Cahn–Hilliard equation (CHE):
c t = 𝛻 2 M δ F δ c ,
Another requirement for any problem to be modeled by any phase-field model is that a free energy function must be defined (for isothermal cases and non-isothermal cases, functional free entropy) depending on the order parameter [4]. The general expression of the free energy functional is shown in Equation (2) [4,10]:
F [ c ] = V f c + 1 2 k 𝛻 c 2 + α 2 𝛻 2 c 2 d r
The first term on the left side of the equation is a free energy density of the global phase as a function of concentration, the second term denotes the energy of the interface due to the gradient present in the concentration, and the last term represents a lowest-order correction to free energy due to compositional gradients [18,19]. Note that in this section, α = 0 for simplicity and as a first approximation and κ is the energy coefficient of the gradient. The chemical energy f(c) is described for example, as a single, double-well potential:
f c = A c 2 1 c 2 α 2 c 2
where A is a positive constant, which controls the magnitude of the energy barrier between two phases of equilibrium. It is well known that the numerical iteration equation from the conventional FFT method for Equation (1) is as [10,20]:
c q n + 1 = c q n t k 2 M δ f δ c q n 1 + t q 4 M k ,
where q is a mode in Fourier space. The parameters used were obtained from the literature [4], and others were modified. In Appendix A, Table A1, each of them is shown. Section 4.1 presents the source code that solves the Cahn–Hilliard phase-field equation with the FFT method following the algorithm in ref. [4] to understand the nature of the evolution of the microstructure due to the substitution of Ga in the amorphous alloy Ce75Al25 − xGax. The 2D simulation is used with the Python 3.9.1 program (and libraries: NumPy, math, Tkinter) [5,6,7,8,9].
Swift–Hohenberg equation: The first-order exponential integrative method [21,22] is based on the exact integration of the linear part of the initial value problem because the linear part is integrated exactly. This can help mitigate the rigidity of a differential equation. Exponential integrators can be constructed to be explicit or implicit for numerical ordinary differential equations or serve as time integrators for numerical partial differential equations. An advantage of this method is the ability to solve Swift–Hohenberg type equations [18,23]:
ψ t = γ 2 ψ + g ψ 2 ψ 3 λ 1 + 𝛻 2 2 ψ   + η ( r , t )
This cannot be solved using the method described in Section 4.1 and has recently been used to obtain porous polymeric materials, such as in Ref. [20]. If Equation (5) is to be used following the 3D printing technique, it would not be possible to obtain porous polymeric materials.
The Swift–Hohenberg equation has now been solved by exponential integrator methods [21,22], such as the second-order implicit pseudo-spectral method developed in reference [2,18,24,25]. The iteration numerical discretization equation is as follows:
ψ ~ t + t = e x p b t ψ ~ t + N ~ 0   e x p b t 1 b + N ~ 1 e x p b t 1 + b t b 2 t
where b ( γ ,   q ) = ( γ 2 λ )   1 q 2 2 d t , and N ~ 0 and N ~ 1 are the nonlinear terms such that
N 0 ~ = g ϕ 2 ~ q , t 0 ϕ 3 ~ q ,   t 0 , N ~ 1 = g ϕ 2 ~ t e m p ϕ 3 ~ t e m p q , t 0 + t g ϕ 2 ~ ϕ 3 ~ q , t 0
where again q represents a mode in Fourier space. In Python simulation, this method has been widely used to simulate grain boundaries of crystal lattices [24,25], ferrofluids [18], and deblock copolymer grain boundary dynamics [3], but they are complicated methods to implement in 2D and 3D in programming languages of high level such as Fortran to obtain a numerical solution of the Swift–Hohenberg equation (SHE).
Conserved Swift–Hohenberg equation: The conserved Swift–Hohenberg equation is perhaps the simplest example of a 3D pattern-forming system used in crystal phase-field models [26] (see Equation (8) with g = 0). Moreover, when using the Swift–Hohenberg equation with a conserved order parameter, one can achieve the simplest microscopic description of the thermodynamic transition from a fluid state to a crystalline state [26,27]. Dissipative dynamics models are commonly associated with a proposed functional that has a conserved [26] or non-conserved order parameter [28]. The nonlinear partial differential model of a Swift–Hohenberg with a conserved order parameter is such as [26,29]:
ψ t = M ψ 𝛻 2 ɛ ψ g ψ 2 + ψ 3 λ 1 + 𝛻 2 2 ψ  
The method used to obtain the numerical solution was the FFT based on the implicit pseudo-spectral way [2]. The iteration numerical discretization equation is similar to Equation (6), but with the modification b ( ɛ ,   q ) = q 2 ( ɛ λ )   1 q 2 2 d t ,
N 0 ~ = q 2 g ϕ 2 ~ q , t 0 ϕ 3 ~ q ,   t 0 , N ~ 1 = q 2 g ϕ 2 ~ t e m p ϕ 2 ~ t e m p q , t 0 + t g ϕ 2 ~ ϕ 3 ~ q , t 0
The reader can see a detailed description of Equations (6) and (9) in Refs. [2,20].
On the other hand, in a recent study [30], a model like Equation (8) can be seen, but with g = 0 and with term γ   ψ 2   being added to this equation. So, the conserved Swift–Hohenberg equation is transformed into a non-potential equation, and due to that, there is no functional associated with Equation (8). Therefore, the non-potential conserved Swift–Hohenberg equation is written as
ψ t = M ψ 𝛻 2 ɛ ψ + ψ 3 λ 1 + 𝛻 2 2 ψ + γ   ψ 2  
where γ   is a parameter control such as can be selected conveniently to demonstrate the equivalence between Equations (9) and (10) in Fourier space as follows. Equation (10) in this space takes the form:
d   ψ ~ d   t = q 2 M ψ ε ψ ~ +   ψ 3 ~ λ 1 q 2 2 + γ q 2 2 ψ 2 ~ ,
where the non-potential term in the Fourier space is such that
| 𝛻 ψ | 2 = 𝛻 ψ · 𝛻   ψ = 𝛻 2 ψ 2 2 ψ 2 ψ     𝛻 ψ 2 = q 2 2 ~ ψ 2 ~ 2 π   ψ ~ 2 ψ ~ = q 2 2 ψ 2 ~
While Equation (8) in Fourier space is
d   ψ ~ d   t = q 2 M ψ ε ψ ~ + ψ 3 ~ λ 1 q 2 2 + g   q 2 M ψ   ψ 2 ~
So, equating (11) and (12) and simplifying similar terms, we obtain that
γ q 2 2 ψ 2 ~ = g   q 2 M ψ   ψ 2 ~
Hence, γ = 2   g   M ψ . It is the equivalent control parameter in Fourier space. Thus, the 2D/3D numerical solutions obtained for the conserved Swift–Hohenberg equation are similar to its associated equation in the non-potential form according to the scaling determined by the value of the γ = 2   g   M ψ parameter.

3. Materials and Methods

The Equations (4), (6), (7), and (9) were solved with the algorithm present in Figure 1, whose pseudo-code is shown in Algorithm 1. In this case, the programming language used takes on importance because it is an intermediate language, which allows for better use of the RAM memory of the computer equipment used to implement a specific numerical method. Furthermore, it is well known that the numerical methods implemented in our research are more efficient than finite difference methods. This implies that the combination of the algorithm and intermediate programming language has a computational efficiency greater than or equal to that of high-level programming languages.
Algorithm 1 was implemented under Python by means of the implicit pseudo-spectral method described in Ref. [2], which is extended easily to 3D space. A spatial domain is discretized by a mesh of Nx × Ny × Nz nodes for any of these equations and is an approach that applies the discrete Fourier transform to obtain the solution of the corresponding scalar field. This method provides optimal accuracy in the rate of convergence for smooth solutions. The nonlinear terms calculus is integrated using an exponential propagation procedure described in detail in Refs. [3,18,31] with the nonlinear terms being handled explicitly in Equation (6) by means of a fully implicit procedure, while the conventional spectral method used to solve Equation (4) is implemented in analogous form to the way followed in Equation (6), but without employing an exponential propagator. For a better approximation, nonlinear terms can be treated as a linear system of differential equations modified by a nonlinear forcing term. These terms are integrated by a predictor–corrector method to second-order. It can be shown that the overall technique is second-order accurate in a time step bigger than with the finite difference methods [27]. The implicit pseudo-spectral method is extended to array algorithms as follows. It is well known that the Fourier transform changes to a gridded cubic space (GCS) with a mesh of Nx × Ny × Nz nodes in a Fourier transformed (FTS) with (qx)i × (qy)j × (qz)k node numbers such that
N x 2 1 i N x / 2 , N y 2 1 i N y / 2   and N z 2 1 i N z / 2 .
The equations that define the coordinates of each point on the GCS mesh are
x i = i 1 L x N x ,   i = 1 ,   , N x ,   y j = j 1 L y N y ,   j = 1 , , N y , z k = k 1 L z N z ,   k = 1 , , N z
where L x ,   L y , and L z are the dimensions of the spatial region in the x, y, and z directions. Furthermore, the points on the FTS mesh are such that q x i = 2 π i L x ,   q y j = 2 π j L y , q z k = 2 π k / L z . To solve the SHE [Equation (6)] a random initial conditions array from GCS was developed and then the numerical method was applied under the array of FTS of q x i × q y j × q z k nodes. The “NumPy” library [9] for Python distribution allows us to evaluate simultaneously the implicit pseudo-spectral algorithm method in the FTS matrix utilizing an initial conditions matrix seed, in which the discrete Fourier transform is applied. The NumPy library contains the FFT.py module that is a simple interface to the FFTPACK, FORTRAN library, which is a powerful standard library for conducting Fast Fourier Transforms of real and complex data sets. This implies a higher computational efficiency, for example to calculate the nonlinear terms in Fourier space at all the time steps: the GCS array is taken to calculate the nonlinear terms given in Equation (5), for which 7 arithmetic operations need to be performed. The GCS array has a dimension of 128 × 128 and 16,384 nodes (in the 2D case) or a dimension of 128 × 128 × 128 and 2,097,152 nodes (in the 3D case), where the number of nodes is multiplied by 7 in each case. That is, for the 2D case, it is required to perform 16,384 × 7 = 114,688 operations, while for the 3D case, 2,097,152 × 7 = 14,680,064 operations. All these operations are performed using the GCS array given by the variable Ar and the function F(Ar), which are then transformed into an equal number of additional operations using the FTS array (see Figure 1: boxes connected by blue and yellow circles and lines 6, 7, 12, and 13). In total, 114,688 × 2 = 229,376 (in the 2D case or 29,360,128 operations for the 3D case) are the number of operations needed to simultaneously calculate the nonlinear terms in Fourier space for all time steps. The reader can calculate the number of operations to be performed in the case of meshes with dimensions of 256 × 256 nodes. In high-level programming languages, this computation process is serial and there is no simultaneous computation process. This is the main difference between Python with its libraries (NumPy [9], Tkinter [8], and Mayavi [12]) and conventional languages such as Fortran, C, Mathlab, and Mathematica, to name a few. Thus, the proposed algorithm is characterized by being modular, where each module establishes an array containing the information necessary to complete thousands of simultaneous operations (see lines 1 to 8 of the Algorithm and their scheme version of Figure 1). Furthermore, the efficiency of the calculation of operations is repeated for every time step and extends to the iterations necessary to complete any of the three numerical methods developed in this research work (see lines 10 to 19 of the Algorithm 1 and Figure 1): conventional FFT method, first-order exponential approximation (FOEI), and second-order exponential integration (SOEI), which are derived from the exponential time differentiation scheme with second-order Runge–Kutta approximation ETD2RK (see Section 4.4 and Appendix A, Table A5). In the subsequent results sections, each of these methods and their implementation under Python and its libraries (NumPy [9], Tkinter [8], and Mayavi [12]) are described in detail. In the case of the numerical implementation of Equation (6), it is similar to the one described to solve Equations (8)–(12).
Algorithm 1: Pseudo-code of spectral methods to solve nonlinear partial differential equation.
1: Declaration of NPDE control parameters: k, A, M, c0, γ, g, λ, ε
2: Declaration of parameters for discretizing space-time: dx, dy, lx, ly, q0, dim = (lx,ly), dt, tf, tintervalo
3: Declaration of the coordinate in Fourier space as a function: qx(i)
4: Declaration of the coordinate in Fourier space as a function: qy(i)
5: Declaration of the Fourier mesh as an array of dimension dim: malla
6: Declaring nonlinear terms as a function: F(X)
7: Declaring initial conditions as an array: Ar
8: Obtaining initial conditions with discrete FFT as an array: Ap
9: Initialize time counter: t ← 0
10: While t < tf:
11:      t ← t + 1
12:      Nonlinear function call: NA = F(Ar)
13:      Obtaining of NA with discrete FFT: NAp
14:      Integration rule given for Equations (4), (6) and (7) or (6)(9): Ap
15:      Obtaining of the discrete FFT inverse: Ar
16:      Nonlinear function call second: NA2 = F(Ar)
17:      Obtaining of NA with discrete FFT for the second time: NA2p
18:      Second-order correction of the integration rule: Ap
19:      Obtaining of the discrete FFT inverse for the second time: Ar
20:      if t % tintervalo 0:
21:          Graph numerical solution: Ar
22:      Updates the counter by an order of magnitude: tintervalo
23: end while

4. Results of the 2D and 3D Simulations

4.1. Python Implementation of the Cahn–Hilliard Equation: Source Code

In the following lines 1 to 59, the source code in Python programming language to solve the Cahn–Hilliard equation [see Equation (1)] employing its iteration equation, Equation (4), is presented. Table 1 interprets the lines of the FFT algorithm and its source code.
1from math import *
2from numpy import *
3from numpy.fft import *
4
5k = 1.0
6M = 1.0 #movilidad
7A = 1.0 #barrera de energía
8c0 = 0.5
9print (“M=“, M, “c0=“, c0)
10t0 = 0
11tf = 150,000
12dt = 0.01 (0.001 for 3D pattern)
13dx = 0.5
14dy = dx
15q0 = 1.0 * dx
16q02 = q0 * q0
17lx = 128
18ly = lx
19dim = (lx, ly)
20tintervalo = 100
21
22def qx(i):
23  if (i < lx/2):
24    qxi = 2.0 * pi * float(i − 1)/(float(lx) * dx)
25  else:
26    qxi = −2.0 * pi * float(lx – i + 1)/(float(lx) * dx)
27  return qxi
28def qy(j):
29  qyi = ((2.0 * pi) * float(j − 1))/(float(ly) * dy)
30  return qyi
31
32malla = array([[qx(i) * qx(i) + qy(j) * qy(j) for j in range(1, int((ly + 2)/2 + 1))] for i in range(1, int(lx + 1))])
33p2 = malla/q02
34print (‘q02’, malla.shape)
35
36def F(x):
37  s = 2 * A * x * (1 − x)*(1 − 2 * x)
38  return s
39
40noise_str = 0.5 * 10**(−3)
41A = uniform((c0 − noise_str), (c0 + noise_str), dim)
42Ap = rfft2(A, dim, (−2, −1))
43print (Ap.shape)
44import numpy as np
45import matplotlib.pyplot as plt
46t = t0
47while t < tf:
48  t = t + 1
49  NA = F(A)
50  Nap = rfft2(NA, dim, (−2, −1))
51  Ap = (Ap − dt * (p2 * M) * (NAp))/(1 + dt * (p2 * p2) * (M * k))
52  A = irfft2(Ap, dim, (−2, −1))
53  if t % tintervalo == 0:
54    plt.imshow(A, cmap =‘bwr’)
55    plt.imshow(A, cmap = ‘bwr’)
56    plt.title(“Cahn–Hilliard equation”)
57    plt.show()
58  if t == tintervalo * 10:
59      tintervalo = 10 * tintervalo
The source code includes functions for differential operations with boundary conditions, statistics, and other complementary functions to simplify the programming solutions of spatiotemporal PDENL. One feature is that the functions excluded in all operations to modify rows and columns on the edge of the matrix remain as periodic boundary conditions with line 43: Ap = rfft2(A, dim, (−2, −1)) and A = irfft2(Ap, dim, (−2, −1)) and their inverse. We can calculate the two-dimensional FFT of the random initial condition array in the Fourier space. A: the input array. Dim: the sequence of integers that form the FFT. Axes: the sequence of integers, axes on which to calculate the FFT.
The 2D simulation was performed for a square simulation cell with lx = 128, ly = 128 nodes with mesh cell size: dx = dy = 0.5. All parameters used in these simulations were with a mobility of M = 1.0, an energy barrier of A = 1.0, an energy coefficient of the gradient of k = 0.01, and α = 0, to reproduce phase separation patterns with initial average concentrations (0.5 and 0.75) during the time steps of 1000, without considering the fluid flow. The red and blue regions show the phases rich in Al and rich in Ga, respectively. The patterns generated are shown in Figure 2a,c.
The numerical microstructure simulated in this work with an initial composition of c_0 = 0.5 was compared with the experimental microstructure of the alloy Ce75Al21Ga4 by micrograph of Ref. [4]. Both microstructures have approximately the same characteristics as the spinodal decomposition phases [see Figure 2a,b]. Comparing the experimental image, it can be noticed that the microstructures match, even more closely resembling the one we achieved than the 2D pattern of the literature simulation [17].
The 3D simulation was performed in a cell of mesh with 128 × 128 × 128 nodes with an initial concentration of 0.5, and for the concentration of 0.75, with a three-dimensional cell of mesh with 64 × 64 × 64 nodes and 128 × 128 × 128 nodes. In Figure 3, it is observed that when the initial concentration of the Ga phase is at 0.75, the microstructure is like droplets. In this case, lines 23–33 must be replaced by the next lines that extend the mesh to 3D:
  • 23 def qx(i):
  • 24  if (i < lx/2):
  • 25       qxi = 2.0 * pi * float(i − 1)/(float(lx) * dx)
  • 26        else:
  • 27       qxi = −2.0 * pi * float(lx – i + 1)/(float(lx) * dx)
  • 28        return qxi
  • 29 def qy(j):
  • 30        if (j < ly/2):
  • 31      qyi = 2.0 * pi * float(j − 1)/(float(ly) * dy)
  • 32        else:
  • 33      qyi = −2.0*pi*float(ly − j + 1)/(float(ly) * dy)
  • 34        return qyi
  • 35 def qz(k):
  • 36     qzi = ((2.0 * pi) * float(k − 1))/(float(lz) * dz)
  • 37     return qzi
  • 38 malla = array([[[qx(i) * qx(i) + qy(j) * qy(j) + qz(k) * qz(k) for k in range(1, int((lz + 2)/2 + 1))] for j in range(1, int(ly + 1))] for i in range(1, int(lx + 1))])
Also, lines 57 and 58 should be replaced in code of pages 6 to 8 by
  • 57      print(A [64, 64, 64], “t=”, t * dt, “n=”, t)
  • 58      G.display(A [32, :, :])
  • 59      G.time(t * dt)
  • 60      archive = open(“test3DFFT”+str(t)+“.pkl”,“wb”)
  • 61      pickle.dump (A, archive)
  • 62      archive.close()
  • 63 if t == tintervalo * 10
  • 64      tintervalo = 10 * tintervalo
Figure 3. (a) Three-dimensional structure using 64 × 64 × 64 nodes, dt = 0.0001, c = 0.75 to 10,000 iterations; (b) 3D structure using 128 × 128 × 128 nodes, dt = 0.001, c = 0.75 and 3000 iterations; (c) evolution of the microstructure based on an average initial concentration of 0.75, using 128 × 128 nodes, and dt = 0.001 with a total of 3000 iterations (see Table A1). The droplet-like morphologies observed at high Ga concentrations are consistent with previous reports in Ref. [17].
Figure 3. (a) Three-dimensional structure using 64 × 64 × 64 nodes, dt = 0.0001, c = 0.75 to 10,000 iterations; (b) 3D structure using 128 × 128 × 128 nodes, dt = 0.001, c = 0.75 and 3000 iterations; (c) evolution of the microstructure based on an average initial concentration of 0.75, using 128 × 128 nodes, and dt = 0.001 with a total of 3000 iterations (see Table A1). The droplet-like morphologies observed at high Ga concentrations are consistent with previous reports in Ref. [17].
Algorithms 18 00585 g003
Lines 57 to 59 plot the slices of the array solution “A”, while lines 60 to 61 are saved to a data file in pkl format, which can be plotted with library Mayavi. Finally, do not forget to add the pickle library using the command: import pickle.

4.2. Implementation Under Python for Numerically Solving the Swift–Hohenberg Equation

The implementation in Python of a simulation algorithm for the Swift–Hohenberg equation (SHE) using the first-order exponential method takes, as its basis, the algorithm described in Section 4.1. The origin of this numerical method is the exponential time differencing (ETD) scheme, which involves exact integration of the governing equations followed by an approximation of an integral involving the nonlinear terms [21,31]. In our case, the simplest method used to solve the SHE numerically is named ETD1, modifying the energy gradient coefficient parameters of lines 6, 7, and 8 of the code by λ, γ, and g. However, lines 41 and 42 were removed and substituted by initial condition A = uniform (−sqrt (gamma**2), sqrt (gamma**2, dim). Line 38 of the code is modified by the nonlinear terms of the Equations (6) and (7) as follows: s = g * x**2 − x**3, while for line 53, it is replaced by the following line:
Ap = exp(−(gama**2 − lamda * (1 − p2)**2) * dt) * Ap + (1 − exp(−(gama**2 lamda * (1p2)**2) * dt))  * Nap/(gama**2 − lamda * (1 − p2)**2),
which refers to the iteration rule of the first-order exponential method. In addition, the following lines corresponding to additive noise are added to the time counterpart (between lines 50 and 51): ruido = eta*uniform(−1.0, 1.0, dim) and their inverse transform: ruidop = rfft2(ruido, dim, (−2, −1)). Two-dimensional patterns were performed for a square simulation cell with mesh of lx = 128 and ly = 128 nodes and mesh step size of dx = dy = 0.05. All parameters used in these simulations were with a time interval dt = 0.01, a maximum grid separation size limited by q0 = 2π/λ0, and where the control parameters κ, λ, γ, and g are given in Table A2 of Appendix A. For the 3D simulations, the same parameters were used. In Figure 4, the patterns obtained are shown. The extension to the 3D case is conducted in a similar way to the Cahn–Hilliard equation in Section 4.1, using 23 to 38 and 57 to 64.
Typically, the Swift–Hohenberg equation is used in 2D pattern formation simulations of deblock copolymers phase transitions [23,28], grain boundaries of crystal lattice [3,24,25], chaotic domain flows [2], and ferrofluid phases and alloy microstructures [20]. However, here, 2D patterns are presented of the Swift–Hohenberg equation applied to some biological systems as follows. In the pattern obtained with the parameters ε = 0, γ = 0.5, g = −3 at 5000 iterations, as shown in Figure 4d, we observed a couple of random dots that resemble the complex patterns found on the skin of the Potamotrygon motoro manta ray shown in Figure 4a.
In Figure 4e pattern with the same parameters as above, but at 20,000 iterations, a gut-like morphology is obtained in blue color in a homogeneous red phase. We can attribute it to the similarity it has with the bacterium Bacillus subtilis with a Gram-positive morphology with oval or cylindrical ellipsoidal spores shown in Figure 4b. Concerning the pattern with parameters = 1.0, γ = 0.13, and g = −1; (see Figure 4f), a series of ordered points is obtained, simulating an ordering of the atoms as in a crystal or with the morphology of a honeycomb as shown in Figure 4c.

4.3. Python Implementation for Numerically Solving the Cahn–Hilliard–Swift–Hohenberg Equation

The simplicity and ease of the implementation under Python of the previously explained mathematical models allow a special contribution to the creation of new mathematical models such as the Cahn–Hilliard–Swift–Hohenberg equation. This type of equation can be understood as a lowest-order correction of the free energy due to the composition of gradients in the Cahn–Hilliard equation. The derivation of the Cahn–Hilliard equation with the spatial terms of the Swift–Hohenberg equation from Equations (1) to (3) is presented in Appendix C. Similarly, based on the code described in Section 4.1 (FFT conventional method), line 53 is replaced by the following line:
Ap = (Ap − dt * (p2 * M) * (NAp))/(1 + dt * (p2 * (1 − p2)**2) * (M * k)).
Thus, obtaining the numerical algorithm that solves a Cahn–Hilliard–Swift–Hohenberg type given by the Equations (1)–(4) with α = k/2, the 2D simulations were performed for a square cell with a mesh of 256 × 256 nodes and with mesh step dx = dy = 0.5. All parameters used in these simulations were with a mobility M = 1.0, an energy barrier of A = 1.0, and an energy coefficient of k = 0.01. Figure 4 shows the temporal evolution of the 2D patterns due to the phase separation with different initial average concentrations (0.45, 0.65, and 0.75). We note that this numerical algorithm improves the solution and reproduces exactly the patterns with the numerical method used in Section 4.1. These patterns have similarities with different microstructures of some alloys. Figure 4a,d shows similarity with the experimental microstructure of Ce75Al21Ga4 alloy [17] [see Figure 5g], Figure 5c,f with the microstructure of a Ti-6Al.4V alloy [32] [see Figure 5h], and Figure 5b,e with the microstructure of an A356 aluminum alloy [33] with a globular morphology [see Figure 5i].
A significant change was performed at line 42 of the algorithm, and modifying the initial concentration to 0.3 yields an interesting pattern at 800,000 iterations, as shown in Figure 4. We note that it shows a globular morphology similar to that of Ref. [33]. Therefore, an initial structure similar to that of a drop is successfully shown, and as the volume fraction of the Ga-rich phase increases, it forms an interconnected structure in the initial stage. As the microstructure increases, it changes, managing to observe that when an average concentration of 0.5 is used, it resembles the experimental microstructure of the literature with the 2D patterns obtained from the numerical solutions of conventional FFT methods [1].

4.4. Implementation of the Algorithm ETD2RK for Numerically Solving the Conserved SHE

Finally, to implement the second-order exponential integrator algorithm to solve the conserved SHE, a modification is made to the algorithm described in Section 4.1. Again, the origin of this numerical method is the exponential time differencing (ETD) scheme, which is analogous to the improved Euler method but with a Runge–Kutta-type approximation [21,31]. This method is commonly known as ETD2RK [31]. The code is modified to implement Equations (8) and (9) in a similar way to the previous code in Section 4.2. This section will be presented below the routine for the 3D case of the conserved SHE. The reader can implement this routine for the 2D case, deleting a dimension here. If the reader wishes to see a detailed description of this method, they can review Refs. [2,18,26,34] and even for an extended system of two EDPNLs, Refs. [22,35].
In what follows, the numerical results obtained by the three different algorithms are compared. We compared the FFT conventional algorithm for solving the Cahn–Hilliard equation and the algorithm of the first- and second-order exponential method for solving the conserved SHE given by Equation (8). It is observed that the only one that generates 2D patterns with parameters ε = −0.2, −1, −2; λ = 1 and g = 0, −2 is the second-order exponential integrator algorithm (SOEI) [see Figure 6a–c].
It is observed that when ε takes values are greater than −1, the mazes begin to form increasingly complex patterns. These 2D patterns reproduce those presented in Refs. [11,18,23,24,27,28] while the other two algorithms are not able to reproduce the numerical solutions presented in the literature. Figure 6d–f shows the patterns obtained with the algorithm to solve the Cahn–Hilliard equation, and Figure 6g–i shows the patterns produced by the first-order exponential integrator (FOEI) method. This is because these numerical methods do not allow the finding of numerical solutions by initially generating a 2D pattern with stripes, labyrinths, and hexagonal-point morphologies, i.e., it is not possible to visualize a 2D pattern.
On the other hand, Figure 6j–l shows 3D patterns of different phases obtained with the numerical algorithm to solve the conserved SHE. The extension of source code to the 3D case is carried out in a way like the routines presented in Section 4.1, lines 23 to 38, but it is necessary to substitute lines 53 to 60 by the following:
Source code extension routines for the 3D case:
  • 53 b = −q2 * (gamma-lambda(1 − q2)**2) * dt
  • 54 Ap = exp(b * dt) − p2 * NAp * (exp(b * dt) − 1)/b
  • 55 A = ifft(Ap, dim, (−3, −2, −1))
  • 56 NA2 = F(A)
  • 57 NAp2 = rfft(NA2, dim, (−3, −2, −1))
  • 58 Ap = Ap − p2 * (NAp2 − NAp) * (exp(b * dt) − (1 + b * dt))/(b * dt**2)
  • 59 A = ifft(Ap, dim, (−3, −2, −1))
  • 60    if t % tintervalo == 0:
  • 61        print(A [64, 64, 64], “t=”,t * dt, “n=”, t)
  • 62        archive = open(“test3DFFT”+str(t)+ “.pkl”, ”wb”)
  • 63        pickle.dump(A, archive)
  • 64        archive.close()
  • 65    if t == tintervalo * 10:
  • 66      tintervalo = 10 * tintervalo
The first one shows a hexagonal–tubular morphology as in Refs. [22,36,37], and in the upper part, the pattern is observed in a droplet-like shape in a hexagonal phase, while in Figure 5k, it is observed in a morphology with an asymmetric gyroid phase as in Refs. [36,38], and finally Figure 6l shows a spheres morphology or nodular phase similar to that reported in Refs. [22,27,39].
A final numerical experiment was performed to compare computational performance times between the conventional FFT algorithm for solving the Cahn–Hilliard equation and the second-order exponential algorithm. The results are shown in Table A5 of Appendix A, from which it is inferred that the SOEI algorithm has a lower computational calculation time than the other algorithm. Another important result is the size of the domains that form the morphology of the pattern. Figure 6g–i shows the patterns with morphologies of guts, labyrinths and points obtained by solving the conserved SHE equation using the conventional FFT algorithm (see Table A5). In this algorithm, it is used with a different Fourier mode than the one used in the patterns of Figure 6a–c.

5. Discussion

In recent years, the development of different programming languages of type open sources to solve nonlinear PDE [1,2,21,31] has had an exponential boom. For example, the enormous work based on Matlap software (in its version R2024a), although it requires a license to be used, is currently found in countless universities to develop programming codes that solve phase-field models [10]. Furthermore, the development of the intermediate language Python [8] has positioned itself internationally as a flexible language, easy to understand and for programming by scientists and technologists. Python is an open-source language that has the property of developing in an easy and fast way, scientific computing libraries such as NumPy [6,7,9], and 3D visualization software such as Mayavi in its version 2.0 [12] or PyVista in its version 2.7 [13] with the importance of promoting scientific research. This is the case of the libraries FiPy [14], FEniCS [15], and DOLFIN [16] that solve the functionals associated with mathematical models of the PFC type [26] by changing the geometry of the solution domain in a very simple and pleasant way (FiPy). In all these ways to solve nonlinear PDE, the code and the algorithm interpenetrate almost to the point of becoming one, due to their interrelation and simplicity. This implies the implementation in Python and its libraries (NumPy, Sipy, Tkinter, etc.) of algorithms such as the Discrete Fast Fourier Transform, which are difficult to implement in older programming languages (such as FORTRAN or C), and is a numerical tool that has been widely used to obtain numerical approximations to problems in Condensed Matter Physics and Materials Science and Engineering.
Examples of this are the study of 2D crystal lattices [24], the behavior of ternary mixtures [27], the pigmentation of vertebrate animals [35], the study of polymeric phase transitions [22], the morphology of microstructures of two-component alloys [18,32,33], and superconductivity [30] (the 2D pattern of Figure 5a–c are very similar to Abrikosov vortices of superconductive phases obtained of non-potential conserved SHE). Even the implementation of spectral algorithms to solve nonlinear PDE has generated a new type of technology to obtain polymeric materials with controlled porosity, using 3D printing technology by Foundry Filament Modeling [20,34].

6. Conclusions

The phase-field model manages to describe the microstructure with compositional domains to observe the spinodal decomposition of the alloy. The microstructure was obtained after solving the Cahn–Hilliard phase separation equation using phase-field modeling. It has been found that both the drop-shaped structure and the interconnected structure appearing in the phase-field modeling resemble the one reported in the literature and the experimental one.
An algorithm was created that manages to simulate the spatial–temporal dynamics of a Cahn–Hillard-Swift–Hohenberg type equation, similarly reproducing the patterns generated with the Cahn–Hilliard solving algorithm, and even improving the solution of the patterns. Moreover, this model has not been published in the literature cited in this paper.
The implementation of the Swift–Hohenberg equation algorithm by the first-order exponential integrator method and the Cahn–Hilliard equation algorithm diverges with control parameter values that the second-order exponential integrator method (SOEI) has for solving the conserved Swift–Hohenberg equation if it succeeds in forming patterns. Even more, the SOEI method has been successful in solving EDPN when the conventional FFT method has failed. For example, in Refs. [1,10,20], the conventional FFT method has been implemented for solving equations of the Cahn–Hilliard type, but our results show that this method cannot obtain a numerical solution to the Swift–Hohenberg equation.
Finally, three different algorithms were successfully implemented for the 3D case employing the Fast Fourier Transform under the Python programming language and its NumPy, Tkinter, and Mayavi libraries. The conventional FFT method has been solved in 2D and 3D equations of the Cahn–Hilliard type, inclusive with a functional Swift–Hohenberg type. At the same time, the exponential integrator method of first- and second-order has been solved successfully in 2D and 3D equations of the non-potential, non-conserved, and conserved Swift–Hohenberg type.

Author Contributions

Conceptualization, M.A.M. and M.A.-F.; methodology, M.A.M. and S.R.-S.; software, M.A.M., D.A.P.-M. and J.A.H.-G.; validation, D.A.P.-M., S.R.-S. and J.A.H.-G.; formal analysis, M.A.M. and D.A.P.-M.; investigation, M.A.M., S.R.-S. and D.A.P.-M.; resources, M.A.M. and D.A.P.-M.; data curation, M.A.M., D.A.P.-M. and J.A.H.-G.; writing—original draft preparation, M.A.M. and D.A.P.-M.; writing—review and editing, S.R.-S.; visualization, M.A.-F. and S.R.-S.; supervision, M.A.M. and M.A.-F.; project administration, M.A.M.; funding acquisition, M.A.M. All authors have read and agreed to the published version of the manuscript.

Funding

Benemérita Universidad Autónoma, Vicerrectoría de Investigación y Estudios de Postgrado, No. assigned project 00065–PVG/2025.

Data Availability Statement

Data are contained within the article or Appendix A, Appendix B and Appendix C.

Acknowledgments

The authors thankfully acknowledge the computer resources, technical expertise, and support provided by the Laboratorio Nacional de Supercomputo del Sureste de México, CONAHCYT member of the network of national laboratories. No. assigned project 202201034C.

Conflicts of Interest

The authors declare that they have no known competing financial interests or personal relationships that could have appeared to influence the work reported in this paper.

Abbreviations

The following abbreviations are used in this manuscript:
MAMMarco A. Morales
DAPMDiana A. Pérez-Muñoz
JAHGJ. Aejandro. Hernández-González
MAFMiguel Alvarado-Flores
SRSSinuhé Ruiz-Salgado

Appendix A

Table A1. Control parameter values of Figure 2 and Figure 3 in code source for the CHE.
Table A1. Control parameter values of Figure 2 and Figure 3 in code source for the CHE.
ParameterFigure 2aFigure 2cFigure 3aFigure 3bFigure 3c
L × L1282128364312831282
C00.50.50.750.750.75
K0.010.0010.0010.0010.001
M1.01.01.01.01.0
A1.01.01.01.01.0
T1.00.11.03.01.0
dx0.50.50.50.50.5
Dt0.0010.0010.00010.0010.001
Iterations100010010,00030001000
Table A2. Control parameter values of Figure 4 for the implementation under Python of the SHE.
Table A2. Control parameter values of Figure 4 for the implementation under Python of the SHE.
ParameterFigure 4dFigure 4eFigure 4fFigure 4gFigure 4hFigure 4i
L × L128212821282128312831283
T5.0200.0015.0200.001
ε 0.00.01.00.00.01.0
γ 0.50.50.130.50.50.13
G−3−3−1−3−3−1
Dt0.010.010.010.010.010.01
Iterations5002000100,00055002000100,000
Table A3. Control parameter values of Figure 5. Python implementation of the Cahn–Hilliard–Swift–Hohenberg equation.
Table A3. Control parameter values of Figure 5. Python implementation of the Cahn–Hilliard–Swift–Hohenberg equation.
ParameterFigure 5
Figure 5aFigure 5bFigure 5cFigure 5dFigure 5eFigure 5fFigure 5jFigure 5kFigure 5l
L × L256225622562128212821282128312831283
C00.450.650.750.450.650.750.450.30.75
K0.010.010.010.010.010.010.0010.0010.001
M1.01.01.01.01.01.01.01.01.0
A1.01.01.01.01.01.01.01.01.0
T6.05.08.01.01.01.00.120.03.0
dx0.50.50.50.50.50.50.50.50.5
dt0.0010.0010.0010.0010.0010.0010.0010.0010.001
Iterations80006000110004000300050001100200003000
Table A4. Control parameter values of Figure 5. Second-order exponential algorithm under Python for conserved SHE.
Table A4. Control parameter values of Figure 5. Second-order exponential algorithm under Python for conserved SHE.
ParameterFigure 6
Figure 6aFigure 6bFigure 6cFigure 6dFigure 6eFigure 6fFigure 6gFigure 6hFigure 6iFigure 6jFigure 6kFigure 6l
L × L128212821282128212821282128212821282128212821282
ε −0.2−1−2−0.21−2−0.21−2−0.2−1−0.4
λ 1.01.01.01.01.01.01.01.01.01.01.01.8
G001.0000000001.0
M ψ 1.01.01.01.01.01.01.01.01.01.01.01.0
T90,00090,00040,0001.01.00.41.070.010.0104104104
Dx0.50.50.50.50.50.50.50.50.50.50.50.5
Dt0.10.10.10.10.10.10.10.10.10.10.10.1
Iterations9 × 1059 × 105400,00010104107001002 × 1051052 × 105
Table A5. Comparison of computational time efficiency of the three different FFT methods where dx = 0.5, and with a mesh of 128 × 128 nodes.
Table A5. Comparison of computational time efficiency of the three different FFT methods where dx = 0.5, and with a mesh of 128 × 128 nodes.
Algorithm TypeTime
(u. a.)
Time StepComputational Time (s)Iteration Number q 0 Morphology
Conventional FFT14,0000.012345.8251400,0005 dxLamellar
Phase
Exponential of 1rt. order3700.001728.485360,000
Exponential of 2° order90,0000.11804.712900,000
Conventional FFT20000.01333.719200,0001.0Lamellar
Phase
Exponential of 1rt. order1000.001196.663100,000
Exponential of 2° order20000.143.28720,000
Conventional FFT150,0000.01265.03515,0005 dxLabyrinths
Exponential of 1rt. order----0.001--------
Exponential of 2° order90,0000.1188.3529000
Conventional FFT26,0000.01467.210260,0005 dxLabyrinths
Exponential of 1rt. order----0.001--------
Exponential of 2° order80000.1164.24880,000
Conventional FFT16000.01281.799160,0001.0Dots and
stripes
Exponential of 1rt. order----0.001--------
Exponential of 2° order30000.160.48530,000
Conventional FFT10,0000.01190.490100,0005 dxDots and stripes
Exponential of 1rt. order----0.001--------
Exponential of 2° order30000.163.37730,000

Appendix B. Source Code for Plot 3D Patterns

  • 1 from mayavi.mlab import *
  • 2 from numpy import *
  • 3 import pickle
  • 4 mode = 1
  • 5 name = “file_name.pkl”
  • 6 out = open(name+“.pkl”, “rb”)
  • 7 array_n = load(out, allow_pickle = True)
  • 8 out.close()
  • 9      if mode == 1:
  • 10   patron3d = contour3d(n, colormap = “blue-red”)
  • 11 elif mode == 2:
  • 12   iso_superficie = contour3d(n, contours=10, transparent = True)
  • 13 elif mode == 3:
  • 14   for i in range(0, lz):
  • 15          patron2D = imshow(n[i], colormap = “blue-red”)

Appendix C. Deduction of the Cahn–Hilliard–Swift–Hohenberg Equation

Obtaining the Lagrange equations from Equations (2) and (3), we have
δ F δ ψ = A ψ 1 ψ 1 2 ψ α ψ · k ψ + α 2 ψ ,
To simplify Equation (A1), take α = k / 2 and through substituting this in Equation (1), it obtains
c t = 𝛻 2 M A ψ 1 ψ 1 2 ψ k 2 1 2 2 4 ψ .
Simplify terms in Equation (A2) and notice that 1 2 𝛻 2 4 ψ = 1 + 2 2 ψ is obtained, therefore
c t = 2 M A ψ 1 ψ 1 2 ψ λ 1 + 2 2 ψ .

References

  1. Yoon, S.; Jeong, D.; Lee, C.; Kim, H.; Kim, S.; Lee, H.G.; Kim, J. Fourier-spectral method for the phase-field equations. Mathematics 2020, 8, 1385. [Google Scholar] [CrossRef]
  2. Cross, M.C.; Meiron, D.; Tu, Y. Chaotic domains: A numerical investigation. Chaos Interdiscip. J. Nonlinear Sci. 1994, 4, 607–619. [Google Scholar] [CrossRef]
  3. Boyer, D.; Romeu, D. Modeling grain boundaries in solids using a combined nonlinear and geometrical method. Int. J. Mod. Phys. B 2005, 19, 4047–4056. [Google Scholar] [CrossRef]
  4. Singh, D.; Mor, K.; Singh, D.; Tiwari, R.S. Phase separation in Ce-based metallic glasses. In Metallic Glasses; IntechOpen: London, UK, 2019; pp. 1–18. [Google Scholar] [CrossRef]
  5. Oliphant, T.E. Python for scientific computing. Comput. Sci. Eng. 2007, 9, 10–20. [Google Scholar] [CrossRef]
  6. Johansson, R.; Johansson, R.; John, S. Numerical Python; Apress: Berkeley, CA, USA, 2019; Volume 1. [Google Scholar] [CrossRef]
  7. Ascher, D.; Dubois, P.F.; Hinsen, K.; Hugunin, J.; Oliphant, T. An Open Source Project: Numerical Python; Lawrence Livermore National Laboratory, The University of California: Livermore, CA, USA, 2001. [Google Scholar]
  8. Millman, K.J.; Aivazis, M. Python for scientists and engineers. Comput. Sci. Eng. 2011, 13, 9–12. [Google Scholar] [CrossRef]
  9. Dubois, P.F.; Hinsen, K.; Hugunin, J. Numerical python. Comput. Phys. 1996, 10, 262–267. [Google Scholar] [CrossRef]
  10. Bulent Biner, S. Programming Phase-Field Modeling; Springer: Cham, Switzerland, 2017. [Google Scholar] [CrossRef]
  11. Sánchez Pérez-Moreno, S.; Ruiz Chavarría, S.; Ruiz Chavarría, G. Numerical Solution of the Swift–Hohenberg Equation. In Experimental and Computational Fluid Mechanics; Klapp, J., Medina, A., Eds.; Environmental Science and Engineering Series; Springer: Cham, Switzerland, 2014. [Google Scholar] [CrossRef]
  12. Ramachandran, P.; Varoquaux, G. Mayavi: 3D visualization of scientific data. Comput. Sci. Eng. 2011, 13, 40–51. [Google Scholar] [CrossRef]
  13. Sullivan, C.; Kaszynski, A. PyVista: 3D plotting and mesh analysis through a streamlined interface for the Visualization Toolkit (VTK). J. Open Source Softw. 2019, 4, 1450. [Google Scholar] [CrossRef]
  14. Guyer, J.E.; Wheeler, D.; Warren, J.A. FiPy: Partial differential equations with Python. Comput. Sci. Eng. 2009, 11, 6–15. [Google Scholar] [CrossRef]
  15. Langtangen, H.P.; Logg, A. Solving PDEs in Python: The FEniCS Tutorial I; Springer Nature: Cham, Switzerland, 2017. [Google Scholar] [CrossRef]
  16. Logg, W.; Wells, G.N.; Bengzon, F. DOLFIN User Manual. 2010. Available online: https://www.csc.kth.se/utbildning/kth/kurser/DN1240/numfcl10/kursmaterial10/dolfin-user-manual-2010-11-04.pdf (accessed on 1 September 2025).
  17. Kim Doochul, H.; Kim, W.T.; Park, E.S.; Mattern, N.; Eckert, J. Phase separation in metallic glasses. Prog. Mater. Sci. 2013, 58, 1103–1172. [Google Scholar] [CrossRef]
  18. Morales, M.A.; Fernández-Cervantes, I.; Agustín-Serrano, R.; Anzo, A.; Sampedro, M.P. Patterns formation in ferrofluids and solid dissolutions using stochastic models with dissipative dynamics. Eur. Phys. J. B 2016, 89, 182. [Google Scholar] [CrossRef]
  19. Nauman, E.B.; He, D.Q. Nonlinear diffusion and phase separation. Chem. Eng. Sci. 2001, 56, 1999–2018. [Google Scholar] [CrossRef]
  20. Lee, C.; Jeong, D.; Yoon, S.; Kim, J. Porous three-dimensional scaffold generation for 3D printing. Mathematics 2020, 8, 94. [Google Scholar] [CrossRef]
  21. Permyakova, E.V.; Goldobin, D.S. Exponential Time Differencing for Stiff Systems with Nondiagonal Linear Part. J. Appl. Mech. Tech. Phys. 2020, 61, 1227–1237. [Google Scholar] [CrossRef]
  22. Martínez-Agustín, F.; Ruiz-Salgado, S.; Zenteno-Mateo, B.; Rubio, E.; Morales, M.A. 3D pattern formation from coupled Cahn-Hilliard and Swift-Hohenberg equations: Morphological phases transitions of polymers, block and diblock copolymers. Comput. Mater. Sci. 2022, 210, 111431. [Google Scholar] [CrossRef]
  23. Elder, K.R.; Vinals, J.; Grant, M. Ordering dynamics in the two-dimensional stochastic Swift-Hohenberg equation. Phys. Rev. Lett. 1992, 68, 3024. [Google Scholar] [CrossRef]
  24. Boyer, D.; Viñals, J. Weakly Nonlinear Theory of Grain Boundary Motion in Patterns with Crystalline Symmetry. Phys. Rev. Lett. 2002, 89, 055501. [Google Scholar] [CrossRef]
  25. Boyer, D.; Vinals, J. Grain-boundary motion in layered phases. Phys. Rev. E 2001, 63, 061704. [Google Scholar] [CrossRef]
  26. Uwe, T.; Andrew, A.; Mark, R.; Hector, G.; Edgar, K. Localized states in the conserved Swift-Hohenberg equation with cubic nonlinearity. Phys. Rev. E 2013, 87, 042915. [Google Scholar] [CrossRef]
  27. Morales, M.A.; Rojas, J.F.; Torres, I.; Rubio, E. Modeling ternary mixtures by mean-field theory of polyelectrolytes: Coupled Ginzburg–Landau and Swift–Hohenberg equations. Phys. A Stat. Mech. Appl. 2012, 391, 779–791. [Google Scholar] [CrossRef]
  28. Boyer, D.; Viñals, J. Grain boundary pinning and glassy dynamics in stripe phases. Phys. Rev. E 2002, 65, 046119. [Google Scholar] [CrossRef] [PubMed]
  29. van Teeffelen, S.; Backofen, R.; Voigt, A.; Löwen, H. Derivation of the phase field crystal model for colloidal solidification. Phys. Rev. E 2009, 79, 051404. [Google Scholar] [CrossRef] [PubMed]
  30. Morales, M.A.; Ruiz-Salgado, S.; Vázquez-Montiel, R.H.; Agustín-Serrano, R.; Zenteno-Mateo, B. Superconductive phases simulation from a PFC models approach using the non-potential conserved Swift-Hohenberg equation. Commun. Nonlinear Sci. Numer. Simul. 2025, 144, 108667. [Google Scholar] [CrossRef]
  31. Cox Steven, M.; Paul, C. Matthews. Exponential time differencing for stiff systems. J. Comput. Phys. 2002, 176, 430–455. [Google Scholar] [CrossRef]
  32. Reis, D.A.P.; de Moura Neto, C.; Couto, A.A.; Silva, C.R.M.; Neto, F.P.; Barboza, M.J.R. A Comparison between CoNiCrAlY Bond Coat and Zirconia Plasma Sprayed Coatings on Creep Tests. Mater. Sci. Forum 2008, 591–593, 30–35. [Google Scholar] [CrossRef]
  33. García, M.; Martínez, V.; Ortiz, A. Fabricación de Componentes Metálicos Mediante Reoforjado. Supl. Rev. Latinoam. Metal. Mater. 2009, S1, 1297–1308. [Google Scholar] [CrossRef]
  34. Morales, M.A.; Ruiz-Salgado, S.; Agustín-Serrano, R.; Zenteno-Mateo, B.; Rodríguez-Mora, J.I. Design and mathematical modeling of polymers phases to obtain controlled microporosity materials by 3D printing. Prog. Manuf. Addit. 2021, 8, 1701–7010. [Google Scholar] [CrossRef]
  35. Morales, M.A.; Rojas, J.F.; Oliveros, J. A new mechanochemical model: Coupled Ginzburg–Landau and Swift–Hohenberg equations in biological patterns of marine animals. J. Theor. Biol. 2015, 368, 37–54. [Google Scholar] [CrossRef]
  36. Pinna, M.; Zvelindovsky, A.V. Kinetic pathways of gyroid-to-cylinder transitions in diblock copolymers under external fields: Cell dynamics simulation. Soft Matter 2008, 4, 316–327. [Google Scholar] [CrossRef] [PubMed]
  37. Nikoubashman, A.; Register, R.A.; Panagiotopoulos, A.Z. Simulations of shear-induced morphological transitions in block copolymers. Soft Matter 2013, 9, 9960–9971. [Google Scholar] [CrossRef]
  38. Nicolaides, D. Mesoscale modeling. Mol. Simul. 2001, 26, 51–72. [Google Scholar] [CrossRef]
  39. Pinna, M.; Zvelindovsky, A.V.; Todd, S.; Goldbeck-Wood, G. Cubic phases of block copolymers under shear and electric fields by cell dynamics simulation. I. Spherical phase. J. Chem. Phys. 2006, 125, 154905. [Google Scholar] [CrossRef] [PubMed]
Figure 1. Algorithm flowchart of spectral methods to solve nonlinear partial differential equation.
Figure 1. Algorithm flowchart of spectral methods to solve nonlinear partial differential equation.
Algorithms 18 00585 g001
Figure 2. (a) Two-dimensional microstructure simulated with the Cahn–Hilliard equation; (b) experimental micrograph of the Ce75Al21Ga4 alloy similar to that reported in Ref. [4]; (c) 3D simulated microstructure obtained with FFT with a mesh of 128 × 128 × 128 (parameters in Table A1). The comparison highlights the agreement between our simulation and experimental results reported in the literature (see Ref. [4]).
Figure 2. (a) Two-dimensional microstructure simulated with the Cahn–Hilliard equation; (b) experimental micrograph of the Ce75Al21Ga4 alloy similar to that reported in Ref. [4]; (c) 3D simulated microstructure obtained with FFT with a mesh of 128 × 128 × 128 (parameters in Table A1). The comparison highlights the agreement between our simulation and experimental results reported in the literature (see Ref. [4]).
Algorithms 18 00585 g002
Figure 4. Natural images of (a) Potamotrygon motoro skin, (b) Bacillus subtilis morphology, and (c) honeycomb structure; (df) 2D simulated patterns obtained from the Swift–Hohenberg equation using the ETD1 scheme; and (gi) corresponding 3D simulated patterns (obtained with the same control parameters values that are in (df), see Table A2). In the inset of each image (gi) is presented the front face of each 3D pattern. The similarities with patterns described in Refs. [18,23,24,27] confirm the ability of our algorithm to reproduce complex morphologies reported in the literature.
Figure 4. Natural images of (a) Potamotrygon motoro skin, (b) Bacillus subtilis morphology, and (c) honeycomb structure; (df) 2D simulated patterns obtained from the Swift–Hohenberg equation using the ETD1 scheme; and (gi) corresponding 3D simulated patterns (obtained with the same control parameters values that are in (df), see Table A2). In the inset of each image (gi) is presented the front face of each 3D pattern. The similarities with patterns described in Refs. [18,23,24,27] confirm the ability of our algorithm to reproduce complex morphologies reported in the literature.
Algorithms 18 00585 g004
Figure 5. (ac) shows the temporal evolution of 2D patterns of the numerical solution of the Cahn–Hilliard–Swift–Hohenberg (CHSH) equation. In the inset of (c) is a 2D pattern zoom of a CHSH equation with a mesh of 64 × 64 nodes. (df,j,k) shows the temporal evolution of the 2D and 3D patterns of the numerical solution of the Cahn–Hilliard equation, respectively. In all these cases, we used a square cell of mesh with 128 × 128 nodes and dt = 0.001 for 1000 iterations. The microstructures are shown in the following micrographs: (g) Ce75Al21Ga4 alloy, (h) Ti-6Al.4V alloy, and (i) Al-Si alloy in the nodular phases. (jl) respectively Three-dimensional patterns of the numerical solution of (CHSH) equations (see Table A3).
Figure 5. (ac) shows the temporal evolution of 2D patterns of the numerical solution of the Cahn–Hilliard–Swift–Hohenberg (CHSH) equation. In the inset of (c) is a 2D pattern zoom of a CHSH equation with a mesh of 64 × 64 nodes. (df,j,k) shows the temporal evolution of the 2D and 3D patterns of the numerical solution of the Cahn–Hilliard equation, respectively. In all these cases, we used a square cell of mesh with 128 × 128 nodes and dt = 0.001 for 1000 iterations. The microstructures are shown in the following micrographs: (g) Ce75Al21Ga4 alloy, (h) Ti-6Al.4V alloy, and (i) Al-Si alloy in the nodular phases. (jl) respectively Three-dimensional patterns of the numerical solution of (CHSH) equations (see Table A3).
Algorithms 18 00585 g005
Figure 6. Comparison between the 2D patterns obtained by the three different algorithms: (ac) obtained from source code to solve conserved SHE by source code when implementing second-order exponential method; (df) obtained from source code to solve Cahn–Hilliard equation by conventional FFT method; (gi) obtained from source code when implementing first-order exponential method. Three-dimensional computational simulation obtained by the algorithm of second-order exponential method to solve conserved SHE: (j) lamellar phase, (k) asymmetric gyroid–tubular phase, and (l) cylindrical phase (see Table A4).
Figure 6. Comparison between the 2D patterns obtained by the three different algorithms: (ac) obtained from source code to solve conserved SHE by source code when implementing second-order exponential method; (df) obtained from source code to solve Cahn–Hilliard equation by conventional FFT method; (gi) obtained from source code when implementing first-order exponential method. Three-dimensional computational simulation obtained by the algorithm of second-order exponential method to solve conserved SHE: (j) lamellar phase, (k) asymmetric gyroid–tubular phase, and (l) cylindrical phase (see Table A4).
Algorithms 18 00585 g006
Table 1. Interpretation of each of the code lines.
Table 1. Interpretation of each of the code lines.
Number LineInterpretation
1–4Libraries used.
5–9Simulation-specific material parameters.
7Gradient energy coefficient.
10Print the value of the control parameters on the screen.
8Energy barrier value.
11–13Time integration parameters.
14–15Parameters of the simulation cell for the mesh. Distance between nodes in “x” and “y” directions.
16Fourier mode of mesh.
18Number of grid points in the x-direction.
19Number of grid points in the y-direction.
20Mesh size or total number of simulation grid points.
21Iteration interval for plotting a 2D (or 3D) pattern.
23–31Discretization of the Fourier space from −2π to 2π and from 0 to 2π.
33Definition of the discretized Fourier Space.
34Array forming the normalized Fourier space.
35Print the dimension of the Fourier space array.
37–39Fretché’s functional derivative statement.
41–43Statement of random initial conditions from 3D space to the Fourier space.
44Print FFT array dimension of initial condition.
45–47Graphical part call with PyLab to display the numerical solution.
48–54FFT algorithm.
47Initialize variable t.
49Cycle over time.
50Counter.
51Call the function of the nonlinear terms.
52Transformation of nonlinear terms to Fourier space.
53Modified Euler’s rule in Fourier space, Equation (4).
54Inverse transforms the solution to real space.
55–57Lines of code to display the solution at iteration t or at dimensionless time t dt.
58–59Counter update for real-time display for a variable interval.
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content.

Share and Cite

MDPI and ACS Style

Morales, M.A.; Pérez-Muñoz, D.A.; Hernández-González, J.A.; Alvarado-Flores, M.; Ruiz-Salgado, S. 2D/3D Pattern Formation Comparison Using Spectral Methods to Solve Nonlinear Partial Differential Equations of Condensed and Soft Matter. Algorithms 2025, 18, 585. https://doi.org/10.3390/a18090585

AMA Style

Morales MA, Pérez-Muñoz DA, Hernández-González JA, Alvarado-Flores M, Ruiz-Salgado S. 2D/3D Pattern Formation Comparison Using Spectral Methods to Solve Nonlinear Partial Differential Equations of Condensed and Soft Matter. Algorithms. 2025; 18(9):585. https://doi.org/10.3390/a18090585

Chicago/Turabian Style

Morales, Marco A., Dania A. Pérez-Muñoz, J. Alejandro Hernández-González, Miguel Alvarado-Flores, and Sinuhé Ruiz-Salgado. 2025. "2D/3D Pattern Formation Comparison Using Spectral Methods to Solve Nonlinear Partial Differential Equations of Condensed and Soft Matter" Algorithms 18, no. 9: 585. https://doi.org/10.3390/a18090585

APA Style

Morales, M. A., Pérez-Muñoz, D. A., Hernández-González, J. A., Alvarado-Flores, M., & Ruiz-Salgado, S. (2025). 2D/3D Pattern Formation Comparison Using Spectral Methods to Solve Nonlinear Partial Differential Equations of Condensed and Soft Matter. Algorithms, 18(9), 585. https://doi.org/10.3390/a18090585

Note that from the first issue of 2016, this journal uses article numbers instead of page numbers. See further details here.

Article Metrics

Back to TopTop