Line data Source code
1 : //* This file is part of SALAMANDER: Software for Advanced Large-scale Analysis of MAgnetic confinement for Numerical Design, Engineering & Research, 2 : //* A multiphysics application for modeling plasma facing components 3 : //* https://github.com/idaholab/salamander 4 : //* https://mooseframework.inl.gov/salamander 5 : //* 6 : //* SALAMANDER is powered by the MOOSE Framework 7 : //* https://www.mooseframework.inl.gov 8 : //* 9 : //* Licensed under LGPL 2.1, please see LICENSE for details 10 : //* https://www.gnu.org/licenses/lgpl-2.1.html 11 : //* 12 : //* Copyright 2025, Battelle Energy Alliance, LLC 13 : //* ALL RIGHTS RESERVED 14 : //* 15 : 16 : #include "AuxAccumulator.h" 17 : 18 : #include "FEProblemBase.h" 19 : #include "AuxiliarySystem.h" 20 : #include "MooseVariableFE.h" 21 : #include "MooseMesh.h" 22 : 23 : namespace SALAMANDER 24 : { 25 85 : AuxAccumulator::AuxAccumulator(FEProblemBase & problem, const AuxVariableName & variable) 26 : : AccumulatorBase(problem), 27 85 : _dim(_problem.mesh().dimension()), 28 85 : _aux(_problem.getAuxiliarySystem()), 29 85 : _var(_aux.getFieldVariable<Real>(0, variable)), 30 85 : _fe(FEGenericBase<Real>::build(_dim, _var.feType())), 31 170 : _fe_map(FEMap::build(_var.feType())) 32 : { 33 85 : _fe->request_phi(); 34 : 35 : // Zero the solution before we accumulate 36 : std::vector<libMesh::dof_id_type> di; 37 1389 : for (const auto & elem : *_problem.mesh().getActiveLocalElementRange()) 38 : { 39 1304 : _aux.dofMap().dof_indices(elem, di, _var.number()); 40 10680 : for (const auto i : di) 41 9376 : _aux.solution().set(i, 0); 42 : } 43 85 : _aux.solution().close(); 44 85 : } 45 : 46 : void 47 18472 : AuxAccumulator::add(const Elem & elem, const Point & point, const Real & value) 48 : { 49 18472 : const std::vector<Point> master_points = {_fe_map->inverse_map(_dim, &elem, point)}; 50 18472 : _fe->reinit(&elem, &master_points); 51 : 52 : // Need to reinit first so that we can get a size for _phi 53 18472 : prepare(elem); 54 : 55 : const auto & phi = _fe->get_phi(); 56 : mooseAssert(_current_accumulation.size() == phi.size(), "Not sized properly"); 57 165608 : for (const auto i : index_range(phi)) 58 147136 : _current_accumulation[i] += phi[i][0] * value; 59 18472 : } 60 : 61 : void 62 84 : AuxAccumulator::finalize() 63 : { 64 84 : AccumulatorBase::finalize(); 65 84 : _aux.solution().close(); 66 84 : } 67 : 68 : void 69 2223 : AuxAccumulator::addCachedValues() 70 : { 71 : std::vector<libMesh::dof_id_type> di; 72 2223 : _aux.dofMap().dof_indices(¤tElem(), di, _var.number()); 73 : 74 : mooseAssert(_current_accumulation.size() == di.size(), "Inconsistent size"); 75 19655 : for (const auto i : index_range(di)) 76 17432 : _aux.solution().add(di[i], _current_accumulation[i]); 77 : 78 : std::fill(_current_accumulation.begin(), _current_accumulation.end(), 0); 79 2223 : } 80 : 81 : void 82 2224 : AuxAccumulator::initCachedValues() 83 : { 84 : mooseAssert(std::find_if(_current_accumulation.begin(), 85 : _current_accumulation.end(), 86 : [](const auto & val) 87 : { return val != 0; }) == _current_accumulation.end(), 88 : "Values not zeroed"); 89 : 90 : mooseAssert(_fe->get_phi().size(), "Test function not sized"); 91 2224 : _current_accumulation.resize(_fe->get_phi().size(), 0); 92 2224 : } 93 : }