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 "AuxScalarKernel.h" 11 : #include "Assembly.h" 12 : #include "MooseVariableScalar.h" 13 : #include "Problem.h" 14 : #include "SubProblem.h" 15 : #include "SystemBase.h" 16 : 17 : InputParameters 18 115126 : AuxScalarKernel::validParams() 19 : { 20 115126 : InputParameters params = MooseObject::validParams(); 21 115126 : params += SetupInterface::validParams(); 22 115126 : params += MeshChangedInterface::validParams(); 23 : 24 115126 : params.addRequiredParam<AuxVariableName>("variable", 25 : "The name of the variable that this kernel operates on"); 26 345378 : params.addParam<bool>("use_displaced_mesh", 27 230252 : false, 28 : "Whether or not this object should use the " 29 : "displaced mesh for computation. Note that " 30 : "in the case this is true but no " 31 : "displacements are provided in the Mesh block " 32 : "the undisplaced mesh will still be used."); 33 115126 : params.addParamNamesToGroup("use_displaced_mesh", "Advanced"); 34 : 35 115126 : params.declareControllable("enable"); // allows Control to enable/disable this type of object 36 115126 : params.registerBase("AuxScalarKernel"); 37 : 38 115126 : return params; 39 0 : } 40 : 41 524 : AuxScalarKernel::AuxScalarKernel(const InputParameters & parameters) 42 : : MooseObject(parameters), 43 : ScalarCoupleable(this), 44 : SetupInterface(this), 45 : FunctionInterface(this), 46 : UserObjectInterface(this), 47 : PostprocessorInterface(this), 48 : DependencyResolverInterface(), 49 : TransientInterface(this), 50 : MeshChangedInterface(parameters), 51 524 : _subproblem(*getCheckedPointerParam<SubProblem *>("_subproblem")), 52 524 : _sys(*getCheckedPointerParam<SystemBase *>("_sys")), 53 524 : _tid(parameters.get<THREAD_ID>("_tid")), 54 524 : _assembly(_subproblem.assembly(_tid, 0)), 55 524 : _var(_sys.getScalarVariable(_tid, parameters.get<AuxVariableName>("variable"))), 56 520 : _mesh(_subproblem.mesh()), 57 1044 : _u(_var.sln()) 58 : { 59 520 : _supplied_vars.insert(parameters.get<AuxVariableName>("variable")); 60 : 61 520 : const std::vector<MooseVariableScalar *> & coupled_vars = getCoupledMooseScalarVars(); 62 600 : for (const auto & var : coupled_vars) 63 80 : _depend_vars.insert(var->name()); 64 520 : } 65 : 66 520 : AuxScalarKernel::~AuxScalarKernel() {} 67 : 68 : void 69 12519 : AuxScalarKernel::compute() 70 : { 71 : // In general, we want to compute AuxScalarKernel values 72 : // redundantly, on every processor, to avoid communication. 73 : // 74 : // However, in rare cases not all processors will have access to a 75 : // particular scalar variable, in which case we skip computation 76 : // there. 77 12519 : if (_var.dofIndices().empty() || !_var.dofMap().all_semilocal_indices(_var.dofIndices())) 78 0 : return; 79 : 80 26272 : for (_i = 0; _i < _var.order(); ++_i) 81 : { 82 13753 : Real value = computeValue(); 83 13753 : _var.setValue(_i, value); // update variable data, which is referenced by other kernels, so the 84 : // value is up-to-date 85 : } 86 : } 87 : 88 : const std::set<std::string> & 89 151 : AuxScalarKernel::getRequestedItems() 90 : { 91 151 : return _depend_vars; 92 : } 93 : 94 : const std::set<std::string> & 95 151 : AuxScalarKernel::getSuppliedItems() 96 : { 97 151 : return _supplied_vars; 98 : } 99 : 100 : bool 101 0 : AuxScalarKernel::isActive() 102 : { 103 0 : return true; 104 : } 105 : 106 : const VariableValue & 107 13 : AuxScalarKernel::uOld() const 108 : { 109 13 : if (_sys.solutionStatesInitialized()) 110 0 : mooseError("The solution states have already been initialized when calling ", 111 0 : type(), 112 : "::uOld().\n\n", 113 : "Make sure to call uOld() within the object constructor."); 114 : 115 13 : return _var.slnOld(); 116 : }