Line data Source code
1 : /********************************************************************/ 2 : /* SOFTWARE COPYRIGHT NOTIFICATION */ 3 : /* Cardinal */ 4 : /* */ 5 : /* (c) 2021 UChicago Argonne, LLC */ 6 : /* ALL RIGHTS RESERVED */ 7 : /* */ 8 : /* Prepared by UChicago Argonne, LLC */ 9 : /* Under Contract No. DE-AC02-06CH11357 */ 10 : /* With the U. S. Department of Energy */ 11 : /* */ 12 : /* Prepared by Battelle Energy Alliance, LLC */ 13 : /* Under Contract No. DE-AC07-05ID14517 */ 14 : /* With the U. S. Department of Energy */ 15 : /* */ 16 : /* See LICENSE for full restrictions */ 17 : /********************************************************************/ 18 : 19 : #ifdef ENABLE_OPENMC_COUPLING 20 : 21 : #include "CellDensityAux.h" 22 : #include "CardinalEnums.h" 23 : 24 : registerMooseObject("CardinalApp", CellDensityAux); 25 : 26 : InputParameters 27 412 : CellDensityAux::validParams() 28 : { 29 412 : InputParameters params = OpenMCAuxKernel::validParams(); 30 412 : params.addClassDescription("OpenMC fluid density (kg/m$^3$), mapped to each MOOSE element"); 31 412 : return params; 32 0 : } 33 : 34 205 : CellDensityAux::CellDensityAux(const InputParameters & parameters) : OpenMCAuxKernel(parameters) {} 35 : 36 : Real 37 2967744 : CellDensityAux::computeValue() 38 : { 39 : // if the element doesn't map to an OpenMC cell, return a density of -1; otherwise, we would 40 : // get an error in the call to cellCouplingFields, since it relies on the 41 : // OpenMCCellAverageProblem::_cell_to_elem std::map that wouldn't have an entry that corresponds 42 : // to an unmapped cell 43 2967744 : if (!mappedElement()) 44 : return OpenMCCellAverageProblem::UNMAPPED; 45 : 46 : OpenMCCellAverageProblem::cellInfo cell_info = 47 2623616 : _openmc_problem->elemToCellInfo(_current_elem->id()); 48 : 49 : // we only extract the material information for density feedback cells, because otherwise we don't 50 : // need to know the material info. So, set a value of -1 for non-density feedback cells. 51 2623616 : if (!_openmc_problem->hasDensityFeedback(cell_info)) 52 : return OpenMCCellAverageProblem::UNMAPPED; 53 : 54 1292160 : int32_t index = _openmc_problem->cellToMaterialIndex(cell_info); 55 : 56 : // if the material is void, return -1 57 1292160 : if (_openmc_problem->materialID(index) == -1) 58 : return OpenMCCellAverageProblem::UNMAPPED; 59 : 60 : // Fetch the density. 61 : double density; 62 1292128 : int err = openmc_cell_get_density(cell_info.first, &cell_info.second, &density); 63 : 64 : // Rescale by the reference density, if required. 65 1292128 : const auto ref_den = _openmc_problem->getReferenceDensity(_current_elem); 66 : 67 1292128 : if (err) 68 0 : mooseError("In attempting to get the density for " + _openmc_problem->printCell(cell_info) + 69 0 : ", OpenMC reported:\n\n" + std::string(openmc_err_msg)); 70 : 71 1292128 : return ref_den * density / _openmc_problem->densityConversionFactor(); 72 : } 73 : 74 : #endif