Line data Source code
1 : /**********************************************************************/ 2 : /* DO NOT MODIFY THIS HEADER */ 3 : /* MAGPIE - Mesoscale Atomistic Glue Program for Integrated Execution */ 4 : /* */ 5 : /* Copyright 2017 Battelle Energy Alliance, LLC */ 6 : /* ALL RIGHTS RESERVED */ 7 : /**********************************************************************/ 8 : 9 : #include "MyTRIMPKAStatistics.h" 10 : #include "MyTRIMRasterizer.h" 11 : #include "mytrim/ion.h" 12 : 13 : registerMooseObject("MagpieApp", MyTRIMPKAStatistics); 14 : 15 : InputParameters 16 32 : MyTRIMPKAStatistics::validParams() 17 : { 18 32 : InputParameters params = GeneralVectorPostprocessor::validParams(); 19 32 : params.addClassDescription("Compile a table of the number of PKA with the same value of a chosen " 20 : "property (e.g. a mass histogram)"); 21 64 : params.addRequiredParam<UserObjectName>( 22 : "rasterizer", "Name of the MyTRIMRasterizer userobject to pull data from"); 23 64 : MooseEnum value_type_options("MASS=0 ZAID"); 24 64 : params.addParam<MooseEnum>( 25 : "value_type", value_type_options, "The common property to bin the PKA set according to"); 26 32 : return params; 27 32 : } 28 : 29 16 : MyTRIMPKAStatistics::MyTRIMPKAStatistics(const InputParameters & params) 30 : : GeneralVectorPostprocessor(params), 31 16 : _rasterizer(getUserObject<MyTRIMRasterizer>("rasterizer")), 32 32 : _value_type(getParam<MooseEnum>("value_type").getEnum<ValueType>()), 33 32 : _property(declareVector(getParam<MooseEnum>("value_type"))), 34 32 : _count(declareVector("n")) 35 : { 36 16 : } 37 : 38 : void 39 8 : MyTRIMPKAStatistics::initialize() 40 : { 41 : _count_map.clear(); 42 8 : _property.clear(); 43 8 : _count.clear(); 44 8 : } 45 : 46 : void 47 8 : MyTRIMPKAStatistics::execute() 48 : { 49 8 : const std::vector<MyTRIM_NS::IonBase> & pka_list = _rasterizer.getPKAList(); 50 : 51 : unsigned int prop; 52 1200008 : for (auto & pka : pka_list) 53 : { 54 1200000 : const unsigned int Z = pka._Z; 55 1200000 : const unsigned int M = std::round(pka._m); 56 : ; 57 : 58 1200000 : switch (_value_type) 59 : { 60 600000 : case MASS: 61 600000 : prop = M; 62 600000 : break; 63 : 64 600000 : case ZAID: 65 600000 : prop = Z * 1000 + M; 66 600000 : break; 67 : 68 0 : default: 69 0 : mooseError("Internal error"); 70 : } 71 : 72 : auto i = _count_map.lower_bound(prop); 73 1200000 : if (i == _count_map.end() || i->first != prop) 74 860 : _count_map.emplace_hint(i, prop, 1); 75 : else 76 1199140 : i->second++; 77 : } 78 8 : } 79 : 80 : void 81 8 : MyTRIMPKAStatistics::finalize() 82 : { 83 : // for single processor runs we do not need to do anything here 84 8 : if (_app.n_processors() > 1) 85 : { 86 : // flatten the map 87 4 : std::vector<std::pair<unsigned int, Real>> count_flat(_count_map.begin(), _count_map.end()); 88 : 89 : // allgather the flattend maps 90 4 : _communicator.allgather(count_flat); 91 : 92 : // reconstitute the map 93 : _count_map.clear(); 94 852 : for (auto & count_pair : count_flat) 95 : { 96 848 : auto i = _count_map.find(count_pair.first); 97 848 : if (i == _count_map.end()) 98 436 : i = _count_map.insert(_count_map.begin(), count_pair); 99 : else 100 412 : i->second += count_pair.second; 101 : } 102 : } 103 : 104 : // copy count map into count vector (ordering according to key is guaranteed) 105 8 : _property.reserve(_count_map.size()); 106 8 : _count.reserve(_count_map.size()); 107 880 : for (auto & count_pair : _count_map) 108 : { 109 872 : _property.push_back(count_pair.first); 110 872 : _count.push_back(count_pair.second); 111 : } 112 8 : }