Skip to content

Commit

Permalink
Add BCs (idaholab#12903)
Browse files Browse the repository at this point in the history
  • Loading branch information
dschwen committed Feb 12, 2019
1 parent a8acd0b commit 654e2ce
Show file tree
Hide file tree
Showing 17 changed files with 382 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -200,6 +200,7 @@ python/MooseDocs/test/output
!python/MooseDocs/test/gold/**/*.json
!python/MooseDocs/test/gold/**/*.html
!python/MooseDocs/test/gold/**/*.tex
.ruby-version

# Chigger
!python/chigger/tests/**/gold/*.png
Expand Down
4 changes: 4 additions & 0 deletions framework/include/base/MooseObject.h
Expand Up @@ -17,6 +17,10 @@

#include "libmesh/parallel_object.h"

#define usingMooseObjectMembers \
using MooseObject::isParamValid; \
using MooseObject::paramError

class MooseApp;
class MooseObject;

Expand Down
44 changes: 44 additions & 0 deletions framework/include/bcs/ADFunctionPresetBC.h
@@ -0,0 +1,44 @@
//* 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

#ifndef ADFUNCTIONPRESETBC_H
#define ADFUNCTIONPRESETBC_H

#include "ADPresetNodalBC.h"

// Forward Declarations
template <ComputeStage>
class ADFunctionPresetBC;
class Function;

declareADValidParams(ADFunctionPresetBC);

/**
* Defines a boundary condition that forces the value to be a user specified
* function at the boundary.
*/
template <ComputeStage compute_stage>
class ADFunctionPresetBC : public ADPresetNodalBC<compute_stage>
{
public:
ADFunctionPresetBC(const InputParameters & parameters);

protected:
/**
* Evaluate the function at the current quadrature point and timestep.
*/
virtual ADReal computeQpValue() override;

/// Function being used for evaluation of this BC
Function & _func;

usingPresetNodalBCMembers;
};

#endif // ADFUNCTIONPRESETBC_H
2 changes: 2 additions & 0 deletions framework/include/bcs/ADIntegratedBC.h
Expand Up @@ -69,6 +69,8 @@ declareADValidParams(ADIntegratedBC);
declareADValidParams(ADVectorIntegratedBC);

#define usingTemplIntegratedBCMembers(type) \
usingMooseObjectMembers; \
usingCoupleableMembers; \
using ADIntegratedBCTempl<type, compute_stage>::_test; \
using ADIntegratedBCTempl<type, compute_stage>::_qp; \
using ADIntegratedBCTempl<type, compute_stage>::_i; \
Expand Down
8 changes: 5 additions & 3 deletions framework/include/bcs/ADNodalBC.h
Expand Up @@ -53,14 +53,16 @@ declareADValidParams(ADNodalBC);
declareADValidParams(ADVectorNodalBC);

#define usingTemplNodalBCMembers(type) \
usingMooseObjectMembers; \
using ADNodalBCTempl<type, compute_stage>::_u; \
using ADNodalBCTempl<type, compute_stage>::_var; \
using ADNodalBCTempl<type, compute_stage>::_current_node; \
using ADNodalBCTempl<type, compute_stage>::_t; \
using ADNodalBCTempl<type, compute_stage>::computeResidual; \
using ADNodalBCTempl<type, compute_stage>::computeJacobian; \
using ADNodalBCTempl<type, compute_stage>::computeOffDiagJacobian; \
using ADNodalBCTempl<type, compute_stage>::getFunction; \
using ADNodalBCTempl<type, compute_stage>::variable; \
using ADNodalBCTempl<type, compute_stage>::paramError; \
using ADNodalBCTempl<type, compute_stage>::isParamValid
using ADNodalBCTempl<type, compute_stage>::variable

#define usingNodalBCMembers usingTemplNodalBCMembers(Real)
#define usingVectorNodalBCMembers usingTemplNodalBCMembers(RealVectorValue)
Expand Down
37 changes: 37 additions & 0 deletions framework/include/bcs/ADPresetBC.h
@@ -0,0 +1,37 @@
//* 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

#ifndef ADPRESETBC_H
#define ADPRESETBC_H

#include "ADPresetNodalBC.h"

template <ComputeStage>
class ADPresetBC;

declareADValidParams(ADPresetBC);

/**
* TODO:
*/
template <ComputeStage compute_stage>
class ADPresetBC : public ADPresetNodalBC<compute_stage>
{
public:
ADPresetBC(const InputParameters & parameters);

protected:
virtual ADReal computeQpValue() override;

const Real & _value;

usingPresetNodalBCMembers;
};

#endif // ADPRESETBC_H
43 changes: 43 additions & 0 deletions framework/include/bcs/ADPresetNodalBC.h
@@ -0,0 +1,43 @@
//* 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

#ifndef ADPRESETNODALBC_H
#define ADPRESETNODALBC_H

#include "ADNodalBC.h"

#define usingPresetNodalBCMembers \
usingNodalBCMembers; \
using ADPresetNodalBC<compute_stage>::computeQpValue

template <ComputeStage>
class ADPresetNodalBC;

declareADValidParams(ADPresetNodalBC);

/**
* Base class for automatic differentiation nodal BCs that (pre)set the solution
* vector entries.
*/
template <ComputeStage compute_stage>
class ADPresetNodalBC : public ADNodalBC<compute_stage>
{
public:
ADPresetNodalBC(const InputParameters & parameters);

void computeValue(NumericVector<Number> & current_solution);

protected:
virtual ADResidual computeQpResidual() override;
virtual ADReal computeQpValue() = 0;

usingNodalBCMembers;
};

#endif // ADPRESETNODALBC_H
3 changes: 1 addition & 2 deletions framework/include/kernels/ADKernel.h
Expand Up @@ -16,6 +16,7 @@
#include "metaphysicl/dualnumber.h"

#define usingTemplKernelMembers(type) \
usingMooseObjectMembers; \
usingCoupleableMembers; \
using ADKernelTempl<type, compute_stage>::_test; \
using ADKernelTempl<type, compute_stage>::_qp; \
Expand Down Expand Up @@ -48,8 +49,6 @@
using ADKernelTempl<type, compute_stage>::accumulateTaggedLocalResidual; \
using ADKernelTempl<type, compute_stage>::accumulateTaggedLocalMatrix; \
using ADKernelTempl<type, compute_stage>::variable; \
using ADKernelTempl<type, compute_stage>::paramError; \
using ADKernelTempl<type, compute_stage>::isParamValid; \
using ADKernelTempl<type, compute_stage>::getFunction

#define usingKernelMembers usingTemplKernelMembers(Real)
Expand Down
3 changes: 1 addition & 2 deletions framework/include/materials/ADMaterial.h
Expand Up @@ -17,6 +17,7 @@
#include "metaphysicl/dualnumber.h"

#define usingMaterialMembers \
usingMooseObjectMembers; \
usingCoupleableMembers; \
usingTransientInterfaceMembers; \
using ConsoleStreamInterface::_console; \
Expand All @@ -29,8 +30,6 @@
using ADMaterial<compute_stage>::_fe_problem; \
using ADMaterial<compute_stage>::_assembly; \
using ADMaterial<compute_stage>::_mesh; \
using ADMaterial<compute_stage>::isParamValid; \
using ADMaterial<compute_stage>::paramError; \
using ADMaterial<compute_stage>::copyDualNumbersToValues; \
using ADMaterial<compute_stage>::getBlockCoordSystem

Expand Down
33 changes: 33 additions & 0 deletions framework/src/bcs/ADFunctionPresetBC.C
@@ -0,0 +1,33 @@
//* 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 "ADFunctionPresetBC.h"
#include "Function.h"

registerADMooseObject("MooseApp", ADFunctionPresetBC);

defineADValidParams(
ADFunctionPresetBC,
ADPresetNodalBC,
params.addRequiredParam<FunctionName>("function", "The forcing function.");
params.addClassDescription(
"The same as FunctionDirichletBC except the value is applied before the solve begins"););

template <ComputeStage compute_stage>
ADFunctionPresetBC<compute_stage>::ADFunctionPresetBC(const InputParameters & parameters)
: ADPresetNodalBC<compute_stage>(parameters), _func(getFunction("function"))
{
}

template <ComputeStage compute_stage>
ADReal
ADFunctionPresetBC<compute_stage>::computeQpValue()
{
return _func.value(_t, *_current_node);
}
31 changes: 31 additions & 0 deletions framework/src/bcs/ADPresetBC.C
@@ -0,0 +1,31 @@
//* 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 "ADPresetBC.h"

registerADMooseObject("MooseApp", ADPresetBC);

defineADValidParams(
ADPresetBC, ADPresetNodalBC, params.addRequiredParam<Real>("value", "Value of the BC");
params.declareControllable("value");
params.addClassDescription(
"Similar to DirichletBC except the value is applied before the solve begins"););

template <ComputeStage compute_stage>
ADPresetBC<compute_stage>::ADPresetBC(const InputParameters & parameters)
: ADPresetNodalBC<compute_stage>(parameters), _value(adGetParam<Real>("value"))
{
}

template <ComputeStage compute_stage>
ADReal
ADPresetBC<compute_stage>::computeQpValue()
{
return _value;
}
44 changes: 44 additions & 0 deletions framework/src/bcs/ADPresetNodalBC.C
@@ -0,0 +1,44 @@
//* 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 "ADPresetNodalBC.h"

// MOOSE includes
#include "MooseVariableFE.h"

#include "libmesh/numeric_vector.h"

defineADValidParams(ADPresetNodalBC,
ADNodalBC,
params.addClassDescription(
"Nodal boundary condition base class with preset solution vector values."));

template <ComputeStage compute_stage>
ADPresetNodalBC<compute_stage>::ADPresetNodalBC(const InputParameters & parameters)
: ADNodalBC<compute_stage>(parameters)
{
}

template <ComputeStage compute_stage>
void
ADPresetNodalBC<compute_stage>::computeValue(NumericVector<Number> & current_solution)
{
dof_id_type & dof_idx = _var.nodalDofIndex();
current_solution.set(dof_idx, MetaPhysicL::raw_value(computeQpValue()));
}

template <ComputeStage compute_stage>
ADResidual
ADPresetNodalBC<compute_stage>::computeQpResidual()
{
return _u - computeQpValue();
}

// explicit instantiation is required for AD base classes
adBaseClass(ADPresetBC);
24 changes: 24 additions & 0 deletions modules/tensor_mechanics/doc/content/source/bcs/ADPressure.md
@@ -0,0 +1,24 @@
# ADPressure

!syntax description /ADBCs/ADPressure<RESIDUAL>

## Description

The boundary condition, `ADPressure` applies a force to a mesh boundary in the
magnitude specified by the user. A `component` of the normal vector to the mesh
surface (0, 1, or 2 corresponding to the $\hat{x}$, $\hat{y}$, and $\hat{z}$
vector components) is used to determine the direction in which to apply the
traction. The boundary condition is always applied to the displaced mesh and
uses forward mode automatic differentiation to compute an exact Jacobian
contribution (this is contingent on coupling only AD enabled objects in the
parameters).

The magnitude of the `ADPressure` boundary condition can be specified as either
a constant scalar factor (use the input parameter `constant`), a factor from a
`function`, a factor from a `postprocessor`, or any combination thereof.

!syntax parameters /ADBCs/ADPressure<RESIDUAL>

!syntax inputs /ADBCs/ADPressure<RESIDUAL>

!syntax children /ADBCs/ADPressure<RESIDUAL>
49 changes: 49 additions & 0 deletions modules/tensor_mechanics/include/bcs/ADPressure.h
@@ -0,0 +1,49 @@
//* 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

#ifndef ADPRESSURE_H
#define ADPRESSURE_H

#include "ADIntegratedBC.h"

class Function;

template <ComputeStage>
class ADPressure;

declareADValidParams(ADPressure);

/**
* ADPressure applies a pressure on a given boundary in the direction defined by component
*/
template <ComputeStage compute_stage>
class ADPressure : public ADIntegratedBC<compute_stage>
{
public:
ADPressure(const InputParameters & parameters);

protected:
ADResidual computeQpResidual() override;

/// displacement component to apply the kernel to
const int _component;

///@{ Pressure value constant factor, function factor, and postprocessor factor
const Real _constant;
Function * const _function;
const PostprocessorValue * const _postprocessor;
///@}

/// _alpha Parameter for HHT time integration scheme
const Real _alpha;

usingIntegratedBCMembers;
};

#endif // ADPRESSURE_H

0 comments on commit 654e2ce

Please sign in to comment.