-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25272 from lindsayad/ad-vector-preset-25271
Add ability to preset AD vector Dirichlet BCs
- Loading branch information
Showing
14 changed files
with
200 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
//* 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 "ADDirichletBCBase.h" | ||
#include "ADNodalBC.h" | ||
|
||
/** | ||
* Base class for automatic differentiation Dirichlet BCs | ||
*/ | ||
template <typename T> | ||
class ADDirichletBCBaseTempl : public ADNodalBCTempl<T, ADDirichletBCBase> | ||
{ | ||
public: | ||
ADDirichletBCBaseTempl(const InputParameters & parameters); | ||
|
||
/** | ||
* Method to preset the nodal value if applicable | ||
*/ | ||
virtual void computeValue(NumericVector<Number> & current_solution) override; | ||
|
||
static InputParameters validParams(); | ||
|
||
protected: | ||
virtual typename Moose::ADType<T>::type computeQpResidual() override; | ||
|
||
/** | ||
* Compute the value of the Dirichlet BC at the current quadrature point | ||
*/ | ||
virtual typename Moose::ADType<T>::type computeQpValue() = 0; | ||
|
||
using ADNodalBCTempl<T, ADDirichletBCBase>::_var; | ||
using ADNodalBCTempl<T, ADDirichletBCBase>::_sys; | ||
using ADNodalBCTempl<T, ADDirichletBCBase>::_current_node; | ||
using ADNodalBCTempl<T, ADDirichletBCBase>::_u; | ||
using ADNodalBCTempl<T, ADDirichletBCBase>::_t; | ||
using ADNodalBCTempl<T, ADDirichletBCBase>::shouldSetComp; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
//* 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 "ADDirichletBCBaseTempl.h" | ||
#include "MooseVariableFE.h" | ||
#include "SystemBase.h" | ||
#include "libmesh/node.h" | ||
|
||
template <typename T> | ||
InputParameters | ||
ADDirichletBCBaseTempl<T>::validParams() | ||
{ | ||
InputParameters params = ADNodalBCTempl<T, ADDirichletBCBase>::validParams(); | ||
params.addParam<bool>( | ||
"preset", true, "Whether or not to preset the BC (apply the value before the solve begins)."); | ||
return params; | ||
} | ||
|
||
template <typename T> | ||
ADDirichletBCBaseTempl<T>::ADDirichletBCBaseTempl(const InputParameters & parameters) | ||
: ADNodalBCTempl<T, ADDirichletBCBase>(parameters) | ||
{ | ||
} | ||
|
||
template <typename T> | ||
void | ||
ADDirichletBCBaseTempl<T>::computeValue(NumericVector<Number> & current_solution) | ||
{ | ||
mooseAssert(this->_preset, "BC is not preset"); | ||
|
||
if (_var.isNodalDefined()) | ||
{ | ||
const auto n_comp = _current_node->n_comp(_sys.number(), _var.number()); | ||
const auto value = MetaPhysicL::raw_value(computeQpValue()); | ||
for (const auto i : make_range(n_comp)) | ||
{ | ||
const auto dof_idx = _current_node->dof_number(_sys.number(), _var.number(), i); | ||
if constexpr (std::is_same<T, Real>::value) | ||
{ | ||
mooseAssert(n_comp == 1, "This should only be unity"); | ||
current_solution.set(dof_idx, value); | ||
} | ||
else | ||
{ | ||
if (shouldSetComp(i)) | ||
current_solution.set(dof_idx, value(i)); | ||
} | ||
} | ||
} | ||
} | ||
|
||
template <typename T> | ||
typename Moose::ADType<T>::type | ||
ADDirichletBCBaseTempl<T>::computeQpResidual() | ||
{ | ||
return _u - computeQpValue(); | ||
} | ||
|
||
template class ADDirichletBCBaseTempl<Real>; | ||
template class ADDirichletBCBaseTempl<RealVectorValue>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.