Line data Source code
1 : //* This file is part of the MOOSE framework 2 : //* https://mooseframework.inl.gov 3 : //* 4 : //* All rights reserved, see COPYRIGHT for full restrictions 5 : //* https://github.com/idaholab/moose/blob/master/COPYRIGHT 6 : //* 7 : //* Licensed under LGPL 2.1, please see LICENSE for details 8 : //* https://www.gnu.org/licenses/lgpl-2.1.html 9 : 10 : #include "ExtraIDIntegralReporter.h" 11 : 12 : registerMooseObject("MooseApp", ExtraIDIntegralReporter); 13 : 14 : InputParameters 15 14325 : ExtraIDIntegralReporter::validParams() 16 : { 17 14325 : InputParameters params = GeneralReporter::validParams(); 18 14325 : params.addRequiredParam<std::vector<VariableName>>( 19 : "variable", "The names of the variables that this ExtraIDIntegralReporter operates on"); 20 14325 : params.addRequiredParam<std::vector<ExtraElementIDName>>( 21 : "id_name", "The list of extra ids name by which to separate integrals."); 22 14325 : params.addParam<std::vector<SubdomainName>>( 23 : "block", "The list of blocks (ids or names) that this object will be applied"); 24 14325 : params.addClassDescription("This ExtraIDIntegralReporter source code is to integrate variables " 25 : "based on parsed extra IDs based on reporter system."); 26 14325 : return params; 27 0 : } 28 : 29 30 : ExtraIDIntegralReporter::ExtraIDIntegralReporter(const InputParameters & parameters) 30 : : GeneralReporter(parameters), 31 30 : _extra_id_data(declareValueByName<ExtraIDData>("extra_id_data", REPORTER_MODE_REPLICATED)) 32 : { 33 : // add Extra ID Integral VPP 34 30 : auto var_names = getParam<std::vector<VariableName>>("variable"); 35 30 : auto extra_id_names = getParam<std::vector<ExtraElementIDName>>("id_name"); 36 : InputParameters vpp_params = 37 30 : _app.getFactory().getValidParams("ExtraIDIntegralVectorPostprocessor"); 38 60 : vpp_params.set<std::vector<VariableName>>("variable") 39 30 : .insert(vpp_params.set<std::vector<VariableName>>("variable").end(), 40 : var_names.begin(), 41 : var_names.end()); 42 90 : vpp_params.set<std::vector<ExtraElementIDName>>("id_name").insert( 43 60 : vpp_params.set<std::vector<ExtraElementIDName>>("id_name").end(), 44 : extra_id_names.begin(), 45 : extra_id_names.end()); 46 30 : if (isParamValid("block")) 47 : { 48 0 : auto blocks = getParam<std::vector<SubdomainName>>("block"); 49 0 : vpp_params.set<std::vector<SubdomainName>>("block").insert( 50 0 : vpp_params.set<std::vector<SubdomainName>>("block").end(), blocks.begin(), blocks.end()); 51 0 : } 52 30 : if (isParamValid("execute_on")) 53 30 : vpp_params.set<ExecFlagEnum>("execute_on") = getParam<ExecFlagEnum>("execute_on"); 54 30 : const VectorPostprocessorName vpp_name = _name + "_extra_id_vpp"; 55 30 : _fe_problem.addVectorPostprocessor("ExtraIDIntegralVectorPostprocessor", vpp_name, vpp_params); 56 30 : _vpp_object = &_fe_problem.getUserObject<ExtraIDIntegralVectorPostprocessor>(vpp_name); 57 : 58 : // fill out exta_id_info; 59 60 : _extra_id_data.names.insert( 60 30 : _extra_id_data.names.end(), extra_id_names.begin(), extra_id_names.end()); 61 : 62 30 : const auto & unique_extra_ids = _vpp_object->getUniqueExtraIds(); 63 30 : _extra_id_data.unique_ids.resize(unique_extra_ids.size()); 64 80 : for (unsigned int i = 0; i < unique_extra_ids.size(); ++i) 65 150 : _extra_id_data.unique_ids[i].insert(_extra_id_data.unique_ids[i].end(), 66 50 : (*unique_extra_ids[i]).begin(), 67 50 : (*unique_extra_ids[i]).end()); 68 : 69 30 : _extra_id_data.integrals = _vpp_object->getIntegrals(); 70 60 : _extra_id_data.variables.insert( 71 30 : _extra_id_data.variables.end(), var_names.begin(), var_names.end()); 72 30 : } 73 : 74 : void 75 21 : to_json(nlohmann::json & json, const ExtraIDIntegralReporter::ExtraIDData & extra_id_data) 76 : { 77 21 : auto & info = json["extra_id_data"]; 78 21 : info["num_id_name"] = extra_id_data.names.size(); 79 21 : info["id_name"] = extra_id_data.names; 80 21 : info["num_values_per_integral"] = extra_id_data.integrals.size(); 81 21 : info["map_id_to_value"] = extra_id_data.unique_ids; 82 : 83 21 : auto & integrals = json["integrals"]; 84 21 : integrals["num_variables"] = extra_id_data.variables.size(); 85 21 : integrals["variable_names"] = extra_id_data.variables; 86 49 : for (unsigned int i = 0; i < extra_id_data.variables.size(); ++i) 87 : { 88 28 : std::string name = extra_id_data.variables[i] + "_integral"; 89 28 : integrals[name] = (*extra_id_data.integrals[i]); 90 28 : } 91 21 : } 92 : void 93 0 : dataStore(std::ostream &, ExtraIDIntegralReporter::ExtraIDData &, void *) 94 : { 95 0 : } 96 : 97 : void 98 0 : dataLoad(std::istream &, ExtraIDIntegralReporter::ExtraIDData &, void *) 99 : { 100 0 : }