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 364 : CellDensityAux::validParams() 28 : { 29 364 : InputParameters params = OpenMCAuxKernel::validParams(); 30 364 : params.addClassDescription("OpenMC fluid density (kg/m$^3$), mapped to each MOOSE element"); 31 364 : return params; 32 0 : } 33 : 34 181 : CellDensityAux::CellDensityAux(const InputParameters & parameters) : OpenMCAuxKernel(parameters) {} 35 : 36 : Real 37 4378240 : 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 4378240 : if (!mappedElement()) 44 : return OpenMCCellAverageProblem::UNMAPPED; 45 : 46 : OpenMCCellAverageProblem::cellInfo cell_info = 47 4035744 : _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 4035744 : if (!_openmc_problem->hasDensityFeedback(cell_info)) 52 : return OpenMCCellAverageProblem::UNMAPPED; 53 : 54 1507392 : int32_t index = _openmc_problem->cellToMaterialIndex(cell_info); 55 : 56 : // if the material is void, return -1 57 1507392 : if (_openmc_problem->materialID(index) == -1) 58 : return OpenMCCellAverageProblem::UNMAPPED; 59 : 60 : double density; 61 1507360 : int err = openmc_material_get_density(index, &density); 62 : 63 1507360 : if (err) 64 0 : mooseError("In attempting to get density for " + _openmc_problem->printMaterial(index) + 65 0 : ", OpenMC reported:\n\n" + std::string(openmc_err_msg)); 66 : 67 1507360 : return density / _openmc_problem->densityConversionFactor(); 68 : } 69 : 70 : #endif