Line data Source code
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 : 10 : #include "FVInitialConditionTempl.h" 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> 20 2595 : FVInitialConditionTempl<T>::FVInitialConditionTempl(const InputParameters & parameters) 21 : : FVInitialConditionBase(parameters), 22 2595 : _fe_problem(*getCheckedPointerParam<FEProblemBase *>("_fe_problem_base")), 23 2595 : _tid(getParam<THREAD_ID>("_tid")), 24 2595 : _t(_fe_problem.time()), 25 2595 : _base_var(_sys.getActualFieldVariable<T>(parameters.get<THREAD_ID>("_tid"), 26 5190 : parameters.get<VariableName>("variable"))) 27 : { 28 2595 : if (!_base_var.isFV()) 29 0 : mooseError("A finite volume initial condition has been defined for variable '", 30 0 : _base_var.name(), 31 : "' whereas the variable itself is not a finite volume variable!"); 32 2595 : } 33 : 34 : template <typename T> 35 2590 : FVInitialConditionTempl<T>::~FVInitialConditionTempl() 36 : { 37 2590 : } 38 : 39 : template <typename T> 40 : void 41 424864 : FVInitialConditionTempl<T>::computeElement(const ElemInfo & elem_info) 42 : { 43 424864 : _base_var.prepareIC(); 44 : 45 : if constexpr (libMesh::TensorTools::TensorTraits<T>::rank == 0) 46 : { 47 424864 : const auto system_number = _base_var.sys().number(); 48 424864 : const auto var_number = _base_var.number(); 49 424864 : const auto dof_id = elem_info.dofIndices()[system_number][var_number]; 50 424864 : const auto dof_value = this->value(elem_info.centroid()); 51 : 52 424864 : _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 424864 : } 64 : template <typename T> 65 : MooseVariableFEBase & 66 2595 : FVInitialConditionTempl<T>::variable() 67 : { 68 2595 : return _base_var; 69 : } 70 : 71 : template class FVInitialConditionTempl<Real>;