Advection-Diffusion with a Gaussian Source Term

In this tutorial, we address an advection-diffusion problem in a one-dimensional domain with a Gaussian source term. This is a fundamental transport phenomenon that occurs in many fields including fluid dynamics, heat transfer, and contaminant transport, where both diffusion and advection mechanisms are important.

Mathematical Formulation

The advection-diffusion equation is a partial differential equation that describes physical phenomena where particles, energy, or other physical quantities are transferred inside a physical system due to two processes: diffusion and advection. In one dimension, the steady-state equation is given by:

\(\frac{d^2u}{dx^2} - 10 \frac{du}{dx} = 10 \cdot e^{-200 \cdot (x - 0.5)^2}\)

This can be rewritten in the general form: \(\frac{d}{dx}\left(A(x)\frac{du}{dx}\right) + B(x)\frac{du}{dx} + C(x)u = D(x)\)

Where for our specific problem:

We apply Dirichlet boundary condition at the left end: \(u(0) = 1\) and Neumann boundary condition (zero gradient) at the right end: \(\frac{du}{dx}(1) = 0\). These conditions represent a fixed concentration at the inlet and free outflow at the outlet of our domain. The Gaussian source term acts as a localized input at the center of the domain. The balance between diffusion (spreading) and advection (directed transport) will determine how the solution behaves.

Solving with FEAScript

Below is a demonstration of how to use the FEAScript library to solve this advection-diffusion problem in your web browser. You only need a simple HTML page to run this example where the following code snippets should be included. First, load the required external libraries:

<head>
  <!-- ...head region... -->
  <script src="https://cdnjs.cloudflare.com/ajax/libs/mathjs/11.12.0/math.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/plotly.js/2.35.3/plotly.min.js"></script>
  <!-- ...rest of head region... -->
</head>

We should then define the problem parameters, such as the solver type, the geometry configuration, and the boundary conditions. This is performed using JavaScript objects directly in the HTML file:

<body>
  <!-- ...body region... -->
  <script type="module">
    // Import FEAScript library
    import { FEAScriptModel, plotSolution, printVersion } from "https://core.feascript.com/dist/feascript.esm.js";
    
    window.addEventListener("DOMContentLoaded", (event) => {
      // Print FEAScript version in the console
      printVersion();

      // Create and configure model
      const model = new FEAScriptModel();
      
      // Set solver configuration with coefficient functions
      model.setSolverConfig("generalFormPDEScript", {
        coefficientFunctions: {
          // Equation d²u/dx² - 10 du/dx = 10 * exp(-200 * (x - 0.5)²)
          A: (x) => 1, // Diffusion coefficient
          B: (x) => -10, // Advection coefficient
          C: (x) => 0,  // Reaction coefficient
          D: (x) => 10 * Math.exp(-200 * Math.pow(x - 0.5, 2)), // Source term
        },
      });

      // Define mesh configuration
      model.setMeshConfig({
        meshDimension: "1D",
        elementOrder: "quadratic",
        numElementsX: 20,
        maxX: 1.0,
      });

      // Define boundary conditions
      model.addBoundaryCondition("0", ["constantValue", 1]); // Left boundary, u(0) = 1
      model.addBoundaryCondition("1", "zeroGradient"); // Right boundary, zero gradient (du/dx = 0)

      // Solve
      model.setSolverMethod("lusolve");
      const { solutionVector, nodesCoordinates } = model.solve();

      // Plot results
      plotSolution(
        solutionVector,
        nodesCoordinates,
        model.solverConfig,
        model.meshConfig.meshDimension,
        "line",
        "resultsCanvas"
      );
    });
  </script>
  <!-- ...rest of body region... -->
</body>

After solving the case, the results appear as a line plot. To visualize it, include an HTML container where the plot will render:

<body>
  <!-- ...body region... -->
  <div id="resultsCanvas"></div>
  <!-- ...rest of body region... -->
</body>

The "resultsCanvas" is the id of the div where the plot will be rendered. This id is passed as an argument to the plotSolution function to specify the target div for the plot.

Results

Below is the 1D line plot of the computed solution to the advection-diffusion equation. This plot is generated in real time using FEAScript. You can find a Node.js implementation of this tutorial in the example directory.

Cannot draw the results. Please rotate your phone to landscape orientation and refresh the page to see the results.

The solution shows the characteristic behavior of advection-diffusion problems. The magnitude and spread of the solution are determined by the balance between diffusion and advection.