Skip to content

Commit

Permalink
add function array IC idaholab#6881
Browse files Browse the repository at this point in the history
  • Loading branch information
YaqiWang committed Jul 7, 2019
1 parent f11a3a2 commit 972701a
Show file tree
Hide file tree
Showing 5 changed files with 185 additions and 0 deletions.
38 changes: 38 additions & 0 deletions framework/include/ics/ArrayFunctionIC.h
@@ -0,0 +1,38 @@
//* 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 "ArrayInitialCondition.h"

// Forward Declarations
class ArrayFunctionIC;
class Function;

template <>
InputParameters validParams<ArrayFunctionIC>();

class ArrayFunctionIC : public ArrayInitialCondition
{
public:
ArrayFunctionIC(const InputParameters & parameters);

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

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

std::vector<Function *> _func;
};
58 changes: 58 additions & 0 deletions framework/src/ics/ArrayFunctionIC.C
@@ -0,0 +1,58 @@
//* 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

#include "ArrayFunctionIC.h"
#include "Function.h"

registerMooseObject("MooseApp", ArrayFunctionIC);

template <>
InputParameters
validParams<ArrayFunctionIC>()
{
InputParameters params = validParams<ArrayInitialCondition>();
params.addRequiredParam<std::vector<FunctionName>>("function",
"The initial condition functions.");

params.addClassDescription("An initial condition that uses a normal function of x, y, z to "
"produce values (and optionally gradients) for a field variable.");
return params;
}

ArrayFunctionIC::ArrayFunctionIC(const InputParameters & parameters)
: ArrayInitialCondition(parameters)
{
auto & funcs = getParam<std::vector<FunctionName>>("function");
if (_var.count() != funcs.size())
mooseError("Number of functions does not agree with the number of array variable components");
for (auto & func : funcs)
_func.push_back(&getFunctionByName(func));
}

RealArrayValue
ArrayFunctionIC::value(const Point & p)
{
RealArrayValue v(_var.count());
for (unsigned int i = 0; i < _var.count(); ++i)
v(i) = _func[i]->value(_t, p);
return v;
}

RealVectorArrayValue
ArrayFunctionIC::gradient(const Point & p)
{
RealVectorArrayValue v(_var.count(), LIBMESH_DIM);
for (unsigned int i = 0; i < _var.count(); ++i)
{
auto gd = _func[i]->gradient(_t, p);
for (unsigned int j = 0; j < LIBMESH_DIM; ++j)
v(i, j) = gd(j);
}
return v;
}
79 changes: 79 additions & 0 deletions test/tests/ics/array_function_ic/array_function_ic_test.i
@@ -0,0 +1,79 @@
[Mesh]
type = GeneratedMesh
dim = 2
nx = 10
ny = 8
[]

[Problem]
kernel_coverage_check = false
solve = false
[]

[Variables]
[u]
component = 2
[]
[u0]
[]
[u1]
[]
[]

[Functions]
[sinx]
type = ParsedFunction
value = sin(x)
[]
[siny]
type = ParsedFunction
value = sin(y)
[]
[]

[ICs]
[uic]
type = ArrayFunctionIC
variable = u
function = 'sinx siny'
[]
[u0ic]
type = FunctionIC
variable = u0
function = sinx
[]
[u1ic]
type = FunctionIC
variable = u1
function = siny
[]
[]

[Postprocessors]
[uint0]
type = ElementIntegralArrayVariablePostprocessor
variable = u
component = 0
[]
[uint1]
type = ElementIntegralArrayVariablePostprocessor
variable = u
component = 1
[]
[u0int]
type = ElementIntegralVariablePostprocessor
variable = u0
[]
[u1int]
type = ElementIntegralVariablePostprocessor
variable = u1
[]
[]

[Executioner]
type = Steady
[]

[Outputs]
exodus = true
[]
Binary file not shown.
10 changes: 10 additions & 0 deletions test/tests/ics/array_function_ic/tests
@@ -0,0 +1,10 @@
[Tests]
[./vector_constant_ic]
type = 'Exodiff'
input = 'array_function_ic_test.i'
exodiff = 'array_function_ic_test_out.e'
design = 'ArrayFunctionIC.md'
requirement = 'The system shall allow to set initial conditions for an array variable based on functions.'
issues = '#6881'
[../]
[]

0 comments on commit 972701a

Please sign in to comment.