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 : #pragma once 20 : 21 : #include "TallyBase.h" 22 : #include "OpenMCCellAverageProblem.h" 23 : 24 : #include "openmc/tallies/filter_mesh.h" 25 : 26 : namespace libMesh 27 : { 28 : class ReplicatedMesh; 29 : } 30 : 31 : class MeshTally : public TallyBase 32 : { 33 : public: 34 : static InputParameters validParams(); 35 : 36 : MeshTally(const InputParameters & parameters); 37 : 38 : /** 39 : * A function to generate the mesh filter needed by this object. 40 : * @return a pair where the first entry is the filter index in the global filter array and the 41 : * second entry is an OpenMC unstructured mesh filter 42 : */ 43 : virtual std::pair<unsigned int, openmc::Filter *> spatialFilter() override; 44 : 45 : /// A function to reset the tally. MeshTally overrides this function to delete the OpenMC mesh. 46 : virtual void resetTally() override; 47 : 48 : /** 49 : * A function which gathers the sums and means from all tallies linked to this tally. MeshTally 50 : * overrides this function to gather global tallies for distributed mesh tallies. 51 : */ 52 : virtual void gatherLinkedSum() override; 53 : 54 : /** 55 : * A function to return if this object is adding a global tally. MeshTally modifies this behavior 56 : * to add a single global tally for distributed mesh tallies (which then communicate with 57 : * tally linkages). 58 : */ 59 4462 : virtual bool addingGlobalTally() const override { return _needs_global_tally && _instance == 0; } 60 : 61 : protected: 62 : /** 63 : * A function which stores the results of this tally into the created 64 : * auxvariables. This implements the copy transfer between the tally mesh and the MOOSE mesh. 65 : * @param[in] var_numbers variables which the tally will store results in 66 : * @param[in] local_score index into the tally's local array of scores which represents the 67 : * current score being stored 68 : * @param[in] tally_vals the tally values to store 69 : * @param[in] norm_by_src_rate whether or not tally_vals should be normalized by the source rate 70 : * @return the sum of the tally over all bins. 71 : */ 72 : virtual Real storeResultsInner(const std::vector<unsigned int> & var_numbers, 73 : unsigned int local_score, 74 : const std::vector<OMCTensor> & tally_vals, 75 : bool norm_by_src_rate = true) override; 76 : /** 77 : * Check the setup of the mesh template and translations. Because a simple copy transfer 78 : * is used to write a mesh tally onto the [Mesh], we require that the 79 : * meshes are identical - both in terms of the element ordering and the actual dimensions of 80 : * each element. This function performs as many checks as possible to ensure that the meshes 81 : * are indeed identical. 82 : */ 83 : void checkMeshTemplateAndTranslations(); 84 : 85 : /** 86 : * Mesh template file to use for creating mesh tallies in OpenMC; currently, this mesh 87 : * must be identical to the mesh used in the [Mesh] block because a simple copy transfer 88 : * is used to extract the tallies and put on the application's mesh in preparation for 89 : * a transfer to another MOOSE app. If not set, this indicates that tallying will be 90 : * performed directly on the [Mesh]. 91 : * TODO: allow the mesh to not be identical, both in terms of using different units 92 : * and more general differences like not having a particular phase present 93 : */ 94 : const std::string * _mesh_template_filename = nullptr; 95 : 96 : /// The translation to apply to the mesh template. 97 : Point _mesh_translation; 98 : 99 : /// The index into an array of mesh translations. 100 : const unsigned int _instance; 101 : 102 : /// The index of the mesh added by this tally. 103 : unsigned int _mesh_index; 104 : 105 : /// OpenMC mesh filter for this unstructured mesh tally. 106 : openmc::MeshFilter * _mesh_filter; 107 : 108 : /// OpenMC unstructured mesh instance for use with mesh tallies 109 : openmc::UnstructuredMesh * _mesh_template; 110 : 111 : /// Whether we're using an indirection layer to map between the OpenMC mesh tally and the MOOSE mesh. 112 : const bool _use_dof_map; 113 : 114 : /** 115 : * For use with block restriction only. A copy of the mesh is made which only contains elements in 116 : * the blocks the user wishes to tally on. This is necessary at the moment as the point locators 117 : * used in OpenMC to find collision sites are not passed a set of block IDs to filter elements. 118 : * TODO: Fix this in OpenMC 119 : */ 120 : std::unique_ptr<libMesh::ReplicatedMesh> _libmesh_mesh_copy; 121 : /// A mapping between the OpenMC bins (active block restricted elements) and all elements. 122 : std::vector<unsigned int> _bin_to_element_mapping; 123 : };