Skip to content

Commit

Permalink
Merge pull request #25825 from grmnptr/fvic-25824
Browse files Browse the repository at this point in the history
Add initial conditions for FV variables
  • Loading branch information
grmnptr authored Nov 7, 2023
2 parents 0bd241a + f8bd104 commit 1c87d63
Show file tree
Hide file tree
Showing 81 changed files with 1,747 additions and 131 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# AddFVInitialConditionAction

!syntax description /FVICs/AddFVInitialConditionAction

Initial conditions for finite volume variables are specified as an object inside the `[FVICs]` block.
This action adds them to the [Problem](syntax/Problem/index.md).

More information about setting finite colume variable initial conditions can be found on the
[FVICs syntax documentation](syntax/FVICs/index.md).

!syntax parameters /FVICs/AddFVInitialConditionAction
18 changes: 18 additions & 0 deletions framework/doc/content/source/fvics/FVConstantIC.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# FVConstantIC

!syntax description /FVICs/FVConstantIC

Sets a constant initial condition described by parameter [!param](/FVICs/FVConstantIC/value). It can be restricted to particular blocks using the [!param](/FVICs/FVConstantIC/block) parameter.

## Example input syntax

In this example, a blockwise constant initial condition is set for variable `u`.
Block 1 and 2 are set differently by two `FVConstantIC` objects.

!listing test/tests/fvics/constant_ic/subdomain_constant_ic.i block=FVICs

!syntax parameters /FVICs/FVConstantIC

!syntax inputs /FVICs/FVConstantIC

!syntax children /FVICs/FVConstantIC
17 changes: 17 additions & 0 deletions framework/doc/content/source/fvics/FVFunctionIC.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# FVFunctionIC

!syntax description /FVICs/FVFunctionIC

Sets an initial condition via a [Function](syntax/Functions/index.md) described by parameter [!param](/FVICs/FVFunctionIC/function). It can be restricted to particular blocks using the [!param](/FVICs/FVFunctionIC/block) parameter.

## Example input syntax

In this example, we set the initial value of variable `u` using a [MooseParsedFunction.md].

!listing test/tests/fvics/function_ic/parsed_function.i block=FVICs Functions

!syntax parameters /FVICs/FVFunctionIC

!syntax inputs /FVICs/FVFunctionIC

!syntax children /FVICs/FVFunctionIC
33 changes: 33 additions & 0 deletions framework/doc/content/syntax/FVICs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# FVICs System

## Description

The `FVICs` block within an input file is used to define the initial (starting) conditions for
the finite volume variables within your simulation. Initial conditions may be applied to both the "unknowns"
(nonlinear) or auxiliary variables.
It computes the values of the variable at the cell centroids.

## FVICs Block

The preferred syntax is to create a top-level "FVICs" block with subblocks defining the initial
conditions for one or more variables.

!listing fvics/function_ic/parsed_function.i block=FVICs

## FVICs from an Exodus File

MOOSE contains a shortcut syntax for reading solutions from an Exodus file for the initial
condition from right within the [Variables](Variables/index.html). The name of the variable and the time step from which to read the solution must be supplied.

!listing fvics/file_ic/file_restart.i block=Variables

## Sanity checks on FVICs

- Multiple FV initial conditions may not be applied to the same variable on the same block
- Global initial conditions will conflict with subdomain or boundary restricted ICs on the same variable

!syntax list /FVICs objects=True actions=False subsystems=False

!syntax list /FVICs objects=False actions=False subsystems=True

!syntax list /FVICs objects=False actions=True subsystems=False
2 changes: 1 addition & 1 deletion framework/doc/content/syntax/ICs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ derivatives at that point (e.g. Gradient, Second).
The preferred syntax is to create a top-level "ICs" block with subblocks defining the initial
conditions for one or more variables.

!listing function_ic/parsed_function.i block=ICs
!listing tests/ics/function_ic/parsed_function.i block=ICs

## ICs from an Exodus File

Expand Down
2 changes: 2 additions & 0 deletions framework/doc/remove.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
- /Variables/InitialCondition
- /AuxVariables/InitialCondition
- /Variables/FVInitialCondition
- /AuxVariables/FVInitialCondition
- /AuxVariables/AuxKernel
22 changes: 22 additions & 0 deletions framework/include/actions/AddFVICAction.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#pragma once

#include "MooseObjectAction.h"

class AddFVICAction : public MooseObjectAction
{
public:
static InputParameters validParams();

AddFVICAction(const InputParameters & params);

virtual void act() override;
};
22 changes: 22 additions & 0 deletions framework/include/actions/AddFVInitialConditionAction.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#pragma once

#include "MooseObjectAction.h"

class AddFVInitialConditionAction : public MooseObjectAction
{
public:
static InputParameters validParams();

AddFVInitialConditionAction(const InputParameters & params);

virtual void act() override;
};
3 changes: 3 additions & 0 deletions framework/include/actions/AddVariableAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ class AddVariableAction : public MooseObjectAction
/// True if the variable being created is a scalar
bool _scalar_var;

/// True if the variable being created is finite volume
bool _fv_var;

/// Number of components for an array variable
unsigned int _components;

Expand Down
35 changes: 35 additions & 0 deletions framework/include/fvics/FVConstantIC.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#pragma once

#include "FVInitialConditionTempl.h"

class InputParameters;

namespace libMesh
{
class Point;
}

/**
* FVConstantIC just returns a constant value for a finite volume variable.
*/
class FVConstantIC : public FVInitialCondition
{
public:
static InputParameters validParams();

FVConstantIC(const InputParameters & parameters);

virtual Real value(const Point & p) override;

protected:
const Real _value;
};
54 changes: 54 additions & 0 deletions framework/include/fvics/FVFunctionIC.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#pragma once

#include "FVInitialConditionTempl.h"

#include <string>

class Function;
class InputParameters;

template <typename T>
InputParameters validParams();

/**
* Defines a boundary condition that forces the value to be a user specified
* function at the boundary.
*/
class FVFunctionIC : public FVInitialCondition
{
public:
static InputParameters validParams();

FVFunctionIC(const InputParameters & parameters);

/**
* @returns The function name
*/
const FunctionName functionName() const;

protected:
/**
* Evaluate the function at the current quadrature point and time step.
*/
Real f();

/**
* The value of the variable at a point.
*/
virtual Real value(const Point & p) override;

/// Function to evaluate to form the initial condition
const Function & _func;

/// Scaling factor, to be able to use a function with multiple ICs
const Real _scaling;
};
83 changes: 83 additions & 0 deletions framework/include/fvics/FVInitialConditionBase.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#pragma once

#include "MooseObject.h"
#include "FunctionInterface.h"
#include "UserObjectInterface.h"
#include "PostprocessorInterface.h"
#include "Restartable.h"
#include "BlockRestrictable.h"
#include "DependencyResolverInterface.h"
#include "MooseTypes.h"
#include "NonADFunctorInterface.h"

class SystemBase;
class MooseVariableFieldBase;
namespace libMesh
{
class Point;
}

/**
* description
*/
class FVInitialConditionBase : public MooseObject,
public BlockRestrictable,
public FunctionInterface,
public Restartable,
public DependencyResolverInterface,
public NonADFunctorInterface
{
public:
/**
* Constructor
*
* @param parameters The parameters object holding data for the class to use.
*/
FVInitialConditionBase(const InputParameters & parameters);

virtual ~FVInitialConditionBase();

static InputParameters validParams();

/**
* retrieves the MOOSE variable that this initial condition acts upon
*/
virtual MooseVariableFieldBase & variable() = 0;

/**
* Workhorse method for computing the initial conditions for block-restricted initial
* conditions
*/
virtual void computeElement(const ElemInfo & elem_info) = 0;

/**
* Gets called at the beginning of the simulation before this object is asked to do its job.
* Note: This method is normally inherited from SetupInterface. However in this case it makes
* no sense to inherit the other virtuals available in that class so we are adding this virtual
* directly to this class without the extra inheritance.
*/
virtual void initialSetup() {}

virtual const std::set<std::string> & getRequestedItems() override { return _depend_vars; }

virtual const std::set<std::string> & getSuppliedItems() override { return _supplied_vars; }

protected:
/// The system object
SystemBase & _sys;

private:
/// Dependent variables
std::set<std::string> _depend_vars;
/// Supplied variables
std::set<std::string> _supplied_vars;
};
Loading

0 comments on commit 1c87d63

Please sign in to comment.