https://mooseframework.inl.gov
FVInitialConditionTempl.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
11 #include "FEProblem.h"
12 #include "Assembly.h"
13 #include "MooseVariableFE.h"
14 #include "SystemBase.h"
15 
16 #include "libmesh/fe_interface.h"
17 #include "libmesh/quadrature.h"
18 
19 template <typename T>
21  : FVInitialConditionBase(parameters),
22  _fe_problem(*getCheckedPointerParam<FEProblemBase *>("_fe_problem_base")),
23  _tid(getParam<THREAD_ID>("_tid")),
24  _t(_fe_problem.time()),
25  _base_var(_sys.getActualFieldVariable<T>(parameters.get<THREAD_ID>("_tid"),
26  parameters.get<VariableName>("variable")))
27 {
28  if (!_base_var.isFV())
29  mooseError("A finite volume initial condition has been defined for variable '",
30  _base_var.name(),
31  "' whereas the variable itself is not a finite volume variable!");
32 }
33 
34 template <typename T>
36 {
37 }
38 
39 template <typename T>
40 void
42 {
43  _base_var.prepareIC();
44 
46  {
47  const auto system_number = _base_var.sys().number();
48  const auto var_number = _base_var.number();
49  const auto dof_id = elem_info.dofIndices()[system_number][var_number];
50  const auto dof_value = this->value(elem_info.centroid());
51 
52  _base_var.sys().solution().set(dof_id, dof_value);
53  }
54  // If we want this to work with real and array variables we can add the different cases here late
55  else
56  {
57  // This line is supposed to throw an error when the user tries to compile this function with
58  // types that are not supported. This is the reason we needed the always_false function. Hope as
59  // C++ gets nicer, we can do this in a nicer way.
60  static_assert(Moose::always_false<T>,
61  "Initial condition is not implemented for the used type!");
62  }
63 }
64 template <typename T>
67 {
68  return _base_var;
69 }
70 
71 template class FVInitialConditionTempl<Real>;
FVInitialConditionTempl(const InputParameters &parameters)
Constructor.
virtual void computeElement(const ElemInfo &elem_info) override
Workhorse method for computing the initial conditions for block-restricted initial conditions...
T * get(const std::unique_ptr< T > &u)
The MooseUtils::get() specializations are used to support making forwards-compatible code changes fro...
Definition: MooseUtils.h:1155
virtual bool isFV() const
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
This class provides an interface for common operations on field variables of both FE and FV types wit...
virtual MooseVariableFEBase & variable() override
retrieves the MOOSE variable that this initial condition acts upon
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
const Point & centroid() const
Definition: ElemInfo.h:36
const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:99
MooseVariableField< T > & _base_var
The variable that this initial condition is acting upon.
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
const std::vector< std::vector< dof_id_type > > & dofIndices() const
Definition: ElemInfo.h:39
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
Definition: MooseBase.h:267
Class used for caching additional information for elements such as the volume and centroid...
Definition: ElemInfo.h:25
This is a template class that implements the workhorse compute and computeNodal methods.
unsigned int THREAD_ID
Definition: MooseTypes.h:209