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 "ArrayNodalBC.h" 11 : 12 : #include "Assembly.h" 13 : #include "MooseVariableFE.h" 14 : #include "SystemBase.h" 15 : #include "NonlinearSystemBase.h" 16 : #include "FEProblemBase.h" 17 : 18 : InputParameters 19 30070 : ArrayNodalBC::validParams() 20 : { 21 30070 : InputParameters params = NodalBCBase::validParams(); 22 30070 : return params; 23 : } 24 : 25 820 : ArrayNodalBC::ArrayNodalBC(const InputParameters & parameters) 26 : : NodalBCBase(parameters), 27 : MooseVariableInterface<RealEigenVector>(this, 28 : true, 29 : "variable", 30 : Moose::VarKindType::VAR_SOLVER, 31 : Moose::VarFieldType::VAR_FIELD_ARRAY), 32 1640 : _var(*mooseVariable()), 33 820 : _current_node(_var.node()), 34 820 : _u(_var.nodalValue()), 35 820 : _count(_var.count()), 36 1640 : _work_vector(_count) 37 : { 38 820 : addMooseVariableDependency(mooseVariable()); 39 820 : } 40 : 41 : void 42 275872 : ArrayNodalBC::computeResidual() 43 : { 44 275872 : if (_var.isNodalDefined()) 45 : { 46 275872 : _work_vector.setZero(); 47 275872 : computeQpResidual(_work_vector); 48 : mooseAssert(_work_vector.size() == _count, 49 : "Size of local residual is not equal to the number of array variable components"); 50 : 51 275872 : setResidual(_sys, _work_vector, _var); 52 : } 53 275872 : } 54 : 55 : void 56 0 : ArrayNodalBC::computeJacobian() 57 : { 58 0 : if (_var.isNodalDefined()) 59 : { 60 0 : const RealEigenVector cached_val = computeQpJacobian(); 61 0 : const dof_id_type cached_row = _var.nodalDofIndex(); 62 : 63 0 : for (const auto i : make_range(_var.count())) 64 0 : addJacobianElement(_fe_problem.assembly(0, _sys.number()), 65 0 : cached_val(i), 66 0 : cached_row + i, 67 0 : cached_row + i, 68 : /*scaling_factor=*/1); 69 0 : } 70 0 : } 71 : 72 : void 73 49288 : ArrayNodalBC::computeOffDiagJacobian(const unsigned int jvar_num) 74 : { 75 49288 : if (!_var.isNodalDefined()) 76 0 : return; 77 : 78 49288 : const auto & jvar = getVariable(jvar_num); 79 : 80 : const RealEigenMatrix cached_val = 81 49288 : computeQpOffDiagJacobian(const_cast<MooseVariableFieldBase &>(jvar)); 82 49288 : const dof_id_type cached_row = _var.nodalDofIndex(); 83 : // Note: this only works for Lagrange variables... 84 49288 : const dof_id_type cached_col = _current_node->dof_number(_sys.number(), jvar_num, 0); 85 : 86 : // Cache the user's computeQpJacobian() value for later use. 87 173464 : for (const auto i : make_range(_var.count())) 88 474928 : for (const auto j : make_range(jvar.count())) 89 350752 : addJacobianElement(_fe_problem.assembly(0, _sys.number()), 90 350752 : cached_val(i, j), 91 350752 : cached_row + i, 92 350752 : cached_col + j, 93 : /*scaling_factor=*/1); 94 49288 : } 95 : 96 : RealEigenVector 97 0 : ArrayNodalBC::computeQpJacobian() 98 : { 99 0 : return RealEigenVector::Ones(_var.count()); 100 : ; 101 : } 102 : 103 : RealEigenMatrix 104 46872 : ArrayNodalBC::computeQpOffDiagJacobian(MooseVariableFEBase & jvar) 105 : { 106 46872 : if (jvar.number() == _var.number()) 107 93744 : return RealEigenMatrix::Identity(_var.count(), jvar.count()); 108 : else 109 0 : return RealEigenMatrix::Zero(_var.count(), jvar.count()); 110 : }