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 "ComputeJacobianThread.h" 11 : 12 : #include "DGKernelBase.h" 13 : #include "FEProblem.h" 14 : #include "IntegratedBCBase.h" 15 : #include "InterfaceKernelBase.h" 16 : #include "HDGKernel.h" 17 : #include "MooseVariableFE.h" 18 : #include "NonlinearSystem.h" 19 : #include "SwapBackSentinel.h" 20 : #include "TimeDerivative.h" 21 : #include "FVElementalKernel.h" 22 : #include "MaterialBase.h" 23 : #include "ConsoleUtils.h" 24 : #include "Assembly.h" 25 : 26 : #include "libmesh/threads.h" 27 : 28 517825 : ComputeJacobianThread::ComputeJacobianThread(FEProblemBase & fe_problem, 29 517825 : const std::set<TagID> & tags) 30 517825 : : NonlinearThread(fe_problem), _tags(tags) 31 : { 32 517825 : } 33 : 34 : // Splitting Constructor 35 46233 : ComputeJacobianThread::ComputeJacobianThread(ComputeJacobianThread & x, Threads::split split) 36 46233 : : NonlinearThread(x, split), _tags(x._tags) 37 : { 38 46233 : } 39 : 40 603995 : ComputeJacobianThread::~ComputeJacobianThread() {} 41 : 42 : void 43 87505423 : ComputeJacobianThread::compute(KernelBase & kernel) 44 : { 45 87505423 : if (kernel.isImplicit()) 46 : { 47 87371735 : kernel.prepareShapes(kernel.variable().number()); 48 87371735 : kernel.computeJacobian(); 49 87371714 : if (_fe_problem.checkNonlocalCouplingRequirement() && !_fe_problem.computingScalingJacobian()) 50 4 : mooseError("Nonlocal kernels only supported for non-diagonal coupling. Please specify an SMP " 51 : "preconditioner, with appropriate row-column coupling or specify full = true."); 52 : } 53 87505398 : } 54 : 55 : void 56 0 : ComputeJacobianThread::compute(FVElementalKernel & fvkernel) 57 : { 58 0 : if (fvkernel.isImplicit()) 59 0 : fvkernel.computeJacobian(); 60 0 : } 61 : 62 : void 63 136996 : ComputeJacobianThread::compute(IntegratedBCBase & bc) 64 : { 65 136996 : if (bc.shouldApply() && bc.isImplicit()) 66 : { 67 136996 : bc.prepareShapes(bc.variable().number()); 68 136996 : bc.computeJacobian(); 69 136996 : if (_fe_problem.checkNonlocalCouplingRequirement() && !_fe_problem.computingScalingJacobian()) 70 4 : mooseError("Nonlocal boundary conditions only supported for non-diagonal coupling. Please " 71 : "specify an SMP preconditioner, with appropriate row-column coupling or specify " 72 : "full = true."); 73 : } 74 136992 : } 75 : 76 : void 77 103638 : ComputeJacobianThread::compute(DGKernelBase & dg, const Elem * neighbor) 78 : { 79 103638 : if (dg.isImplicit()) 80 : { 81 103638 : dg.prepareShapes(dg.variable().number()); 82 103638 : dg.prepareNeighborShapes(dg.variable().number()); 83 103638 : if (dg.hasBlocks(neighbor->subdomain_id())) 84 103638 : dg.computeJacobian(); 85 : } 86 103638 : } 87 : 88 : void 89 2958 : ComputeJacobianThread::compute(InterfaceKernelBase & intk) 90 : { 91 2958 : if (intk.isImplicit()) 92 : { 93 2958 : intk.prepareShapes(intk.variable().number()); 94 2958 : intk.prepareNeighborShapes(intk.neighborVariable().number()); 95 2958 : intk.computeJacobian(); 96 : } 97 2958 : } 98 : 99 : void 100 648838 : ComputeJacobianThread::determineObjectWarehouses() 101 : { 102 : // If users pass a empty vector or a full size of vector, 103 : // we take all kernels 104 648838 : if (!_tags.size() || _tags.size() == _fe_problem.numMatrixTags()) 105 : { 106 633649 : _tag_kernels = &_kernels; 107 633649 : _dg_warehouse = &_dg_kernels; 108 633649 : _ibc_warehouse = &_integrated_bcs; 109 633649 : _ik_warehouse = &_interface_kernels; 110 633649 : _hdg_warehouse = &_hdg_kernels; 111 : } 112 : // If we have one tag only, 113 : // We call tag based storage 114 15189 : else if (_tags.size() == 1) 115 : { 116 13873 : _tag_kernels = &(_kernels.getMatrixTagObjectWarehouse(*(_tags.begin()), _tid)); 117 13873 : _dg_warehouse = &(_dg_kernels.getMatrixTagObjectWarehouse(*(_tags.begin()), _tid)); 118 13873 : _ibc_warehouse = &(_integrated_bcs.getMatrixTagObjectWarehouse(*(_tags.begin()), _tid)); 119 13873 : _ik_warehouse = &(_interface_kernels.getMatrixTagObjectWarehouse(*(_tags.begin()), _tid)); 120 13873 : _hdg_warehouse = &(_hdg_kernels.getMatrixTagObjectWarehouse(*(_tags.begin()), _tid)); 121 : } 122 : // This one may be expensive, and hopefully we do not use it so often 123 : else 124 : { 125 1316 : _tag_kernels = &(_kernels.getMatrixTagsObjectWarehouse(_tags, _tid)); 126 1316 : _dg_warehouse = &(_dg_kernels.getMatrixTagsObjectWarehouse(_tags, _tid)); 127 1316 : _ibc_warehouse = &(_integrated_bcs.getMatrixTagsObjectWarehouse(_tags, _tid)); 128 1316 : _ik_warehouse = &(_interface_kernels.getMatrixTagsObjectWarehouse(_tags, _tid)); 129 1316 : _hdg_warehouse = &(_hdg_kernels.getMatrixTagsObjectWarehouse(_tags, _tid)); 130 : } 131 648838 : } 132 : 133 : void 134 4950 : ComputeJacobianThread::accumulateLower() 135 : { 136 4950 : _fe_problem.addJacobianLowerD(_tid); 137 4950 : } 138 : 139 : void 140 122882 : ComputeJacobianThread::accumulateNeighborLower() 141 : { 142 122882 : _fe_problem.addJacobianNeighborLowerD(_tid); 143 122882 : } 144 : 145 : void 146 8964 : ComputeJacobianThread::accumulateNeighbor() 147 : { 148 8964 : _fe_problem.addJacobianNeighbor(_tid); 149 8964 : } 150 : 151 : void 152 55038939 : ComputeJacobianThread::postElement(const Elem * /*elem*/) 153 : { 154 55038939 : _fe_problem.cacheJacobian(_tid); 155 55038939 : _num_cached++; 156 : 157 55038939 : if (_num_cached % 20 == 0 || _fe_problem.assembly(_tid, _nl.number()).hasStaticCondensation()) 158 2818154 : _fe_problem.addCachedJacobian(_tid); 159 55038939 : } 160 : 161 : void 162 39945 : ComputeJacobianThread::join(const ComputeJacobianThread & /*y*/) 163 : { 164 39945 : } 165 : 166 : void 167 0 : ComputeJacobianThread::computeOnInternalFace() 168 : { 169 : mooseAssert(_hdg_warehouse->hasActiveBlockObjects(_subdomain, _tid), 170 : "We should not be called if we have no active HDG kernels"); 171 : mooseAssert(false, "HDGKernels must compute the full Jacobian"); 172 0 : }