Example 07 : Custom Initial Conditions

MOOSE provides several ways to specify initial conditions (ICs) for transient problems. The same functionality can be used to specify initial guesses for steady-state problems. Custom methods can be created in addition to using any of many built-in methods for specifying initial conditions. Detailed information for all the built-in initial conditions available can be found on the Initial Condition System Documentation

This example demonstrates creating and using a custom class+object for setting the following initial condition:


where is a user-chosen coefficient. To accomplish this, we will need to create our own subclass of MOOSE's InitialCondition class and then specify the IC in our input file.

Creating a Custom IC

We create a header file and subclass the InitialCondition class and add a Real (i.e. floating point number) member variable to hold the user-specified coefficient - see ExampleIC.h for details. The .C file defines an input parameter named coefficient, stores its value in a member variable in the constructor, and uses that value to compute the IC.

#include "ExampleIC.h"

registerMooseObject("ExampleApp", ExampleIC);

template <>
  InputParameters params = validParams<InitialCondition>();
  params.addRequiredParam<Real>("coefficient", "The value of the initial condition");
  return params;

ExampleIC::ExampleIC(const InputParameters & parameters)
  : InitialCondition(parameters), _coefficient(getParam<Real>("coefficient"))

// This is the primary function custom ICs must implement.
ExampleIC::value(const Point & p)
  // The Point class is defined in libMesh.  The spatial coordinates x,y,z can be accessed
  // individually using the parenthesis operator and a numeric index from 0..2
  return 2. * _coefficient * std::abs(p(0));

Using ICs in an Input File

The input file transient.i sets up a simple transient diffusion problem with initial conditions specified in the Variables block:

    order = FIRST
    family = LAGRANGE

    # Use the initial Condition block underneath the variable
    # for which we want to apply this initial condition
      type = ExampleIC
      coefficient = 2.0

We can also use the initial condition when running steady-state problems (i.e. with the Steady Executioner); this effectively functions as an initial guess for the solver - usually not necesary, but occasionally useful. For steady cases, the IC is specified in exactly the same way - see e.g. steady.i.


These results are from running the transient.i file. At , we can see that the initial condition defines the solution to be zero at (along the rear surface of the half-cylinder) and increasing linearly toward us (out of the page). At the final time, we see that diffusion has overcome our IC and our Dirichlet BCs have dictated the solution along the top and bottom surfaces.

Initial state (t = 0)

Intermediate diffused state (t = .1)

Final equilibrium state (t = 1 )

Complete Source Files