Example 2 : Adding a Custom Kernel


This example builds on Example 1 and introduces how to create a custom Kernel, which is the mechanism for adding custom physics into MOOSE.

Problem Statement

We consider the steady-state advection-diffusion equation for the 3-D domain shown in Fig. 1: find such that , on the bottom, on the top and with on the remaining boundaries. The velocity, is a known constant (1 in the vertical (z) direction and zero otherwise).

The weak form of this equation, in inner-product notation, is given by:


where are the test functions and is the finite element solution.

Create Advection Kernel

The advection component of the problem is defined by creating a C++ object that inherits from an existing MOOSE object.

In general, adding a new object to MOOSE requires only two steps :

  • Create a C++ object that inherits from the appropriate MOOSE object, in this case a Kernel.

  • Register this new object in your application, in this case ExampleApp.C.

Create object



Register object

Within your application, which was generated using Stork, the newly created object must be registered. For this example, the application source code is /src/base/ExampleApp.C. To add the Kernel created above, simply include the header and register it within the registerObjects method.


Input File Syntax

The only difference between this example and Example 1 is that the custom Kernel object created above must be included. Since this new object was registered, it is available and accessed using similar syntax to the Diffusion kernel. Thus, the [Kernels] block in the input file becomes:

    type = Diffusion
    variable = convected
    type = ExampleConvection
    variable = convected
    velocity = '0.0 0.0 1.0'

Note, the variable name was also changed in this example to convected.

Running the Problem

This example may be run using Peacock or by running the following commands form the command line.

cd ~/projects/moose/examples/ex02_kernel
make -j8
./ex02-opt -i ex02.i

This will generate the results file, out.e, as shown in Figure 2. This file may be viewed using Peacock or an external application that supports the Exodus II format (e.g., Paraview).

Example 02 Results

Complete Source Files