Physics-Informed Neural Network Method for Solving One-Dimensional Advection Equation Using PyTorch

Numerical solutions to the equation for advection are determined using different finite-difference approximations and physics-informed neural networks (PINNs) under conditions that allow an analytical solution. Their accuracy is examined by comparing them to the analytical solution. We used a machine learning framework like PyTorch to implement PINNs. PINNs approach allows training neural networks while respecting the PDEs as a strong constraint in the optimization as apposed to making them part of the loss function. In standard small-scale circulation simulations, it is shown that the conventional approach incorporates a pseudo diffusive effect that is almost as large as the effect of the turbulent diffusion model; hence the numerical solution is rendered inconsistent with the PDEs. This oscillation causes inaccuracy and computational uncertainty. Of all the schemes tested, only the PINNs approximation accurately predicted the outcome. We assume that the PINNs approach can transform the physics simulation area by allowing real-time physics simulation and geometry optimization without costly and time-consuming simulations on large supercomputers.


Introductions
Partially differential equations (PDEs), whose states exist in infinite-dimensional spaces, are often used to model physical science and engineering processes [1]. Due to the lack of computational methods in most situations, finite-dimensional approximations are used instead, which are based on conventional numerical techniques that have been developed and improved over the years. Traditional numerical solvers, on the other hand, frequently necessitate considerable computational effort, particularly for complex systems with multiscale/multiphysics features, and may not be feasible in real-time or many-query applications, such as optimization, inverse problem, and uncertainty quantification (UQ), which necessitate many repeated simulations [2]. Solving PDE structures for the best possible combination between precision and reliability is always a problem [3]. Some data-driven approaches to solve PDEs with deep neural networks (DNNs) exist nowadays. The benefits of using DNNs to approximate PDE solutions [4]. DNNs can Identify nonlinear interactions, which are confirmed mathematically by universal approximation theorems.
Forward assessments of trained DNNs are quick, which is ideal for real-time or multiple-query applications. DNN models are analytically differentiable; derivative information can be easily derived for optimization and control problems using automatic differentiation [5]. Recently, researchers have attempted to use DNNs in numerous sectors, including education [6], media [7], power [8], and healthcare [9]. There are several problems in various fields for which there is no analytical approach. Since certain constants are believed to be fixed, even problems with analytical solutions have them. The analytical solution to a simplistic dilemma, on the other hand, teaches us a lot about the system's actions. On the other hand, if no analytical solution approach is available, numerical methods can be used to investigate problems rapidly. However, extreme caution must be exercised to ensure that a converged solution is achieved. This means we need to figure out if the step sizes are minimal enough to discover the solutions to the equations we are trying to understand. The numerical method FEM is an excellent tool to solve complicated geometrical shapes with a boundary and load condition that is difficult to describe with analytical expressions available. There are generally three approaches by which scientific problems/equations are solved: Analytical, Numerical, and Experimental. However, we cannot perform the experimental method every time because of cost and time constraints. The traditional approaches for solving problems are analytical methods. However, we cannot solve equations analytically due to limitations imposed by complex geometry, boundary conditions, and other factors.
Consequently, we have been pushing towards numerical methods for several years because they can produce almost reliable results in addition to analytical methods, and they can do so in a much shorter and easier period. The famous Navier-Stoke equation has never been solved analytically, but it can be solved quickly using Numerical Schemes. The disadvantages of traditional Numerical Schemes are they are challenging in representing irregular boundaries, not optimized for unstructured meshes, and momentum, energy, and mass are not conserved [10]. Lastly, they are not well suited for turbulent flow slow for significant problems, and they tend to be biased towards edges and one-dimensional physics.
To solve the drawbacks of traditional methods, we investigate the use of physics-informed neural networks (PINNs) as a solution approximation for PDEs in this paper. PINNsneural networks trained to solve supervised learning tasks while respecting any given physics law described by general nonlinear PDEs Fig. 1 and Eq. (1) summarizes the PINNs [11]. We will talk about PyTorch as a Python implementation for PINNs. We assume these PINNs would affect real-world applications where reduced-order physics models are possible and widely used. The numerical efficiency of reduced-order models usually comes at the expense of physical consistency. We illustrate how PINNs can be used in reduced-order models to reduce epistemic (model-form) ambiguity for the advection equation. PINNs architectures can help close the distance between forecasts and observable results. Our method begins with an abstract formulation and then moves on to numerical integration methods before arriving at a neural network implementation.

PINNs = Data + Neural Networks + Physical Laws
Eq. (1) ⁄ ) The rest of the paper is structured in the following way. Section 2 background of advection equation, section 3.1 specifies the implementation choices in terms of language and libraries, and public repositories (needed for replicating results). Section 3.2 presents the formulation and implementation for integrating the first-order ordinary differential equation with the simple Euler's forward method. Section 4 presents results, and section 5 closes conclusions and future work. Finally, Appendix summarizes concepts about neural networks used in this paper.

Background
Whether it is waves on a lake, sound waves, or an earthquake, everybody has seen traveling waves. Writing down a reasonable-looking finite difference approximation to a wave equation is not complicated. Most of the time is spent attempting to decide if the process succeeds. Since numerical wave propagation has its own set of complexities, we will start with one of the most basic mathematical equations for generating moving waves [12]. The advection equation is written as The convenient feature of model Eq.
(2) is that it has an analytical solution in Eq. (3): Which represents a wave propagating with a constant velocity a with unchanged shape. When a>0, the wave propagating in the positive x-direction, whereas for a<0, the wave propagates in the negative x-direction. Equation (2) is significant in various applications should not be overlooked due to its mathematical simplicity. The momentum equation for gas motion, for example, is an inhomogeneous version of equation (2), that is dependent on u. Therefore, in the physical model of interstellar gas and its motion due to the solar wind, a nonlinear version of the advection equation occurs [13]. Another application is in analyzing traffic flow along a highway [14]. The density of cars along the road is represented by u (x, t). Their speed is represented by a. Equation PDEs are equations that contain unknown multivariate functions and their partial derivatives in Eq. (4).
is the nabla operator, u = ( , , ) is the velocity, and Γ is the diffusivity.
The independent variables are space, x = ( , , ), and time, t. Equation (4) is known as the convection-diffusion equation. Diffusion and convection are two mechanisms that explain how particles, electricity, and other physical quantities are transported within a physical structure. Concerning diffusion, • ( ∅), The concentration of a chemical can be assumed by ∅. As concentration is minimal in one region relative to the surrounding areas (e.g., a local minimum of concentration), the substance diffuses from the surrounding areas, increasing concentration. The net diffusion is proportional to the Laplacian (or second derivative) of concentration. if the diffusivity is a constant, 2 ∅. On the other hand, concerning convection, • ( • ∅), Assume the chemical is being carried down a canal, and we are calculating the concentration of the water per second. Someone spills a barrel of the chemical into the river upstream. The concentration will suddenly rise and fall as the field with the elevated chemicals passes. The problems presented in this study as examples will consist of finding the function ∅( , ) that, for a given geometry, original, and boundary conditions, satisfies the PDE. In a typical approach such as finite volume, we divide the statistical domain into small regions and consider the average volume size ∅ at a given moment Eq. (5).
Where denotes the volume of the i ℎ discretized element in the computational domain. The global solution can then be obtained by combining the different solutions for all volumes Eq. (6).
This function is piecewise constant and cannot be deduced, demonstrating one of the first drawbacks of conventional numerical methods. Many applications need derivable PDE solutions.
Specific exciting effects, such as heat fluxes and mass transfer, are computed with derivatives; a derivable solution would be more reliable than a derivatives approximation using piecewise functions. We discretize the various operators in equation one and use a time integration scheme to change the time. In its most basic form, the first-order Euler algorithm Eq. (7), where ∆ is the time step, is the flux ∅ across the face f of the volume and is the area of the face. Additional computational schemes to calculate these unknown values are used to calculate the fluxes at the faces. Some popular choices are central difference or upwind methods. Two more aspects are required to complete the problem: the original and boundary conditions. To begin, keep in mind that an initial state is simply a time-dimensional boundary condition. This is important because initial and boundary conditions are typically considered independently, but they will be treated similarly in our approach. The initial condition sets the value for ∅( , = 0) and functions as the first values to start the computation in the previously described time-marching algorithm. Boundary conditions set the value for ∅( ∈ , > 0) where D is the total number of points on the domain's boundaries. We must specify a specific set of rules to change these points, not to see values outside the scope. There are many boundary conditions, but the ones used in our examples are as follows: • Periodic: The domain folds itself to bind boundaries when periodic conditions are assumed.
• Dirichlet: For this type of boundary condition, we will fix ∅ it at boundaries.
• Newmann: For this type of boundary condition, we will fix ∇∅ at boundaries.
For the treatment of walls, inflows, and outflows, specific boundaries may be needed. In the temporal dimension, an initial state is a Dirichlet boundary condition. The approach used for other conventional approaches such as finite difference or finite elements differs slightly. The basic principle remains the same: discretize the computational domain into small regions where the solution is assumed and bring them back together to retrieve the global solution. Therefore, there are no derivable piecewise alternatives. Furthermore, since we use time-marching algorithms, new computations are needed once the free-parameters, current, or boundary conditions are changed.

Implementation
This part will teach you how to solve equation (2) using a neural network. Python is being used to solve the PDEs. Python, a programming language, has grown in popularity in recent years. For the following reasons: Since there is no need for an explicit declaration of variables or a separate compilation period, it is quick and simple to code and use for small "prototyping" tasks. It is available for free on most computing systems and has a vast repository of packages covering a wide range of applications. Python also has features that make developing and documenting massive, well-structured program structures easier. Python is not appropriate for running extended computational computations since it is an interpreted language. However, calls to precompiled library routines are often used in the code for such computations. Many of these routines are available directly from Python using the PyTorch [15], NumPy [16], and SciPy[17] packages. Most operating systems (OS), including Linux, OSX, and MSWindows, have these kits available for free.
The aim is to achieve a trained multilayer perceptron (MLP) that can give the output φ(x, t), where x and t are set as inputs that satisfy equation 1. The basic principle is that a forward transfer on the network using the independent variables as PINN inputs gives one the value of the dependent variables evaluated. Since PINNs are derivable, we can compute the dependent variables (outputs). The dependent variables (inputs) to calculate the different derivatives that appear in the original PDEs. We create a loss function that fits the PDEs with this derivative, and we use it throughout the training phase. We will assume that our PINNs are a solution to the PDEs if the loss function approaches a near-zero value. The teaching is done in an unsupervised setting. There are continuous and derivable solutions that can be applied throughout the whole domain. PINNs also have the advantage of allowing one to use the PDEs-free parameters in the solution. Therefore, a solution trained for various values of these parameters will generalize to different conditions rather than a single scenario, eliminating the need for new calculations any time a parameter is modified. This property is of particular interest in optimization studies. In more depth, we describe a collection of points within our domain in the same way as standard approaches would. These points are divided into two categories: preparation and validation after training. We also differentiate between internal and external points. This will be dealt with in compliance with the boundary conditions that have been established. Then, we define the MLP architecture: several layers and a number of hidden units in each layer. The number of inputs would be the same as the number of independent variables in the PDEs with any free parameters we want to add. The number of outputs would be the same as the number of unknowns that need to be solved. Table 1 summarizes the PINNs algorithm. Once we have training data and the PINNs defined, follows the steps: • We compute the network's outputs at all points, ∅( , ) and the derivatives concerning the inputs: ∅ , ∅ , ∅ . • We use a loss function that fits our PDE for internal points. This is the role we'd like to improve: ∅ + • ( • ∅) − • ( ∅) = 0 • We can create an MSE loss function to fulfill the given condition for boundary points since we fix values. • Update the parameters of the PINNs for each loss function.
• Specify the two training sets and for the equation and boundary/intial conditions. • Define dynamics on augmented state.
• Specify a loss function for PDE equation and boundary condition.
• Train the PINNs to find the best parameters ∅ by minimizing the loss function.
We aim to create a qualified multilayer perceptron (MLP) that can output (x, t) when given x and t as inputs and satisfy equation (2). Consider the one-dimensional advection Eq. (8), which is a simplification of equation (1) for a 1D, Where ∅( , ) is the unknown function, x and t are the independent variables, u is a constant parameter and ∅ and ∅ are the derivatives of ∅ concerning t and x, respectively. This PDE has an analytical solution, which is ∅( , ) = ∅( , − ). We may assume that the initial condition was physical ∅( , = 0) moves in x at speed u. In the case that ∅( , = 0) = Defining a ∆ and ∆ allows us to build a uniform grid of points in the entire domain used in the discretized Eq. (9). We describe internal and boundary points, each of which would have a separate loss function associated with it. When t = 0, the initial condition will use a Mean Square Error (MSE) loss function, which will equate the known initial condition with the PINNs output. For the spatial boundary condition, we use a periodic condition that compares the solutions using an MSE loss function at x = 0 and x = L for any t and forces them to be equal. As seen in Fig. 4, we characterize our solution as an MLP with two inputs (number of independent variables), hidden layers, and one output. Fig. 4 shows a general scheme's flowchart for converting a differential equation into the PINNs structure. • Update the PINNs parameters for the other losses.
MLP with two inputs, x and t, one output ∅( , ), sigmoid activation function, and five hidden layers with 32 neurons shown in Fig. 5. Moreover, we here assume that t is a function of ∅( , ), the first derivative of ∅( , ) concerning the set of inputs and physical parameters, θ. The training points are randomly uniformly drawn from their corresponding domains. { , , , } corresponding to data at Euler scheme equation (7) now allows us to infer the latent solution u(t, x) in a sequential method. Starting from initial data { , , , } at time and data at the domain boundaries x = 0 and x = 2 shown in Fig. 5, we can use the loss function to train the networks and predict the solution at the time +1 . A Euler time-stepping scheme would then use this prediction as initial data for the next step and proceed to train again and predict. We use an optimization algorithm to perform well in applying the PINNs method for parameter estimation. The Adam optimizer with a learning rate of 0.001 is used until the optimization problem's solution converges with the prescribed tolerance. We set the maximum number of Adam's epoch to be 10,000 and use the mini-batch training; the PINNs weights are randomly initialized using the Xavier scheme [18]. These steps are usually small in the classical numerical analysis due to stability constraints for explicit schemes or computational complexity constraints for implicit formulations. If the number of Euler scheme stages increases, these restrictions become more serious. Thousands to millions of such measures are needed for most realistic interest problems before the solution is resolved up to a desired final period. In comparison to conventional approaches, we can use an implicit Euler scheme with an infinitely large number of stages at no added expense. This helps one to overcome the entire Spatio-temporal solution in a single step while ensuring consistency and high predictive precision. Table 2 shows the parameters and constants used implementation of PINNs and different hyperbolic schemes.

Results
A one-dimensional advection equation is solved to understand the main process of solving a PDE with a PINNs. Compared PINNs with a traditional FTBS [19], Lax Wendroff [20], and Lax Friedrich [21] all time-integrated with an Euler scheme. Our trained PINNs, unlike the FVM solution, are continuous and derivable over the entire domain. Since physical effects do not limit PINNs, our experiments demonstrate that a much larger mesh will provide better results in this specific case. In comparison to conventional methods, we find that PINNs are capable of minimizing error. Our findings are summarized in table 3 below. The PINNs were tested with points that did not participate in the training. Fig. 5 shows the MSE of the trained network as a function of the number of testing points. It can be observed that the averaged error is stable for an increasing number of testing points, which indicates that the solution found is a good approximation of the real solution not only for the training points but also over the whole domain of the problem.   Table 4 for the prediction in 0 < t < 2. The FTBS, Lax Wendroff, and Lax Friedrich approximation produced a less accurate solution and have more intense oscillation than PINNs. As can be seen, training the PINNs requires optimization concerning many loss functions (as many as PDEs and different boundary conditions), challenging complex problems. We see that PINNs more sharply resolve discontinuities at the cost of adding oscillations, which leads to a net reduction in error. We can use this result to hypothesize that PINNs will further improve the solution when the discontinuity is more significant. We verify our hypothesis by plotting the error ratio against discontinuity width in 0 < t < 2 and demonstrating that more significant discontinuities lead to lower error ratios. In the solutions obtained with Lax Friedrich, FTBS, and Lax Wendroff, an anomalous oscillation is present when the grid spacing is too large to follow the quantity's variations advected closely. Lax Friedrich, FTBS, and Lax Wendroff results converge faster and produce more significant predictive errors than PINNs at almost all training data points. The accuracy of the predictions Lax Friedrich, FTBS, and Lax Wendroff is very good at the initial conditions t=0, and the boundary conditions are controlled or well known, but they struggle at t=2. MSE indicates that the PINNs loss can produce an excellent approximation to the solution (0 < t < 2) without explicit regularization. ). The colored lines with a marker "*" denote different hyperbolic schemes. The solid black line denotes the exact solution.

Conclusions:
By comparing numerical solutions of advection equation with known analytic solutions and PINNs have been demonstrated. The FTBS, Lax Wendroff, and Lax Friedrich introduced a pseudo diffusion effect that led to a large error in t=2 and would make accurate turbulent diffusion modeling impossible. In those cases where the value of the property being advected varied rapidly in the space of a few grid intervals, variations which seem to be typical in many models, the Lax Friedrich, FTBS, and Lax Wendroff introduced an anomalous oscillation into the distribution of the quality being advected at t=2. The oscillations grew steadily with time and could easily introduce instability into a numerical model. Of the methods investigated, Only the PINNs approximation moved the advected field correctly at 0 < t < 2. Traditional numerical methods to find a consistent solution with more straightforward and faster methods led to inaccurate results. Only the PINNs method produces an accurate and consistent approximation with the PDEs. Traditional numerical methods also require a large amount of computer core storage. PINNs approach can transform the physics simulation area by allowing real-time physics simulation and geometry optimization without costly and time-consuming simulations on large supercomputers.