LCOV - code coverage report
Current view: top level - src/reporters - ExtraIDIntegralReporter.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 419b9d Lines: 48 57 84.2 %
Date: 2025-08-08 20:01:16 Functions: 3 5 60.0 %
Legend: Lines: hit not hit

          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       14331 : ExtraIDIntegralReporter::validParams()
      16             : {
      17       14331 :   InputParameters params = GeneralReporter::validParams();
      18       14331 :   params.addRequiredParam<std::vector<VariableName>>(
      19             :       "variable", "The names of the variables that this ExtraIDIntegralReporter operates on");
      20       14331 :   params.addRequiredParam<std::vector<ExtraElementIDName>>(
      21             :       "id_name", "The list of extra ids name by which to separate integrals.");
      22       14331 :   params.addParam<std::vector<SubdomainName>>(
      23             :       "block", "The list of blocks (ids or names) that this object will be applied");
      24       14331 :   params.addClassDescription("This ExtraIDIntegralReporter source code is to integrate variables "
      25             :                              "based on parsed extra IDs based on reporter system.");
      26       14331 :   return params;
      27           0 : }
      28             : 
      29          33 : ExtraIDIntegralReporter::ExtraIDIntegralReporter(const InputParameters & parameters)
      30             :   : GeneralReporter(parameters),
      31          33 :     _extra_id_data(declareValueByName<ExtraIDData>("extra_id_data", REPORTER_MODE_REPLICATED))
      32             : {
      33             :   // add Extra ID Integral VPP
      34          33 :   auto var_names = getParam<std::vector<VariableName>>("variable");
      35          33 :   auto extra_id_names = getParam<std::vector<ExtraElementIDName>>("id_name");
      36             :   InputParameters vpp_params =
      37          33 :       _app.getFactory().getValidParams("ExtraIDIntegralVectorPostprocessor");
      38          66 :   vpp_params.set<std::vector<VariableName>>("variable")
      39          33 :       .insert(vpp_params.set<std::vector<VariableName>>("variable").end(),
      40             :               var_names.begin(),
      41             :               var_names.end());
      42          99 :   vpp_params.set<std::vector<ExtraElementIDName>>("id_name").insert(
      43          66 :       vpp_params.set<std::vector<ExtraElementIDName>>("id_name").end(),
      44             :       extra_id_names.begin(),
      45             :       extra_id_names.end());
      46          33 :   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          33 :   if (isParamValid("execute_on"))
      53          33 :     vpp_params.set<ExecFlagEnum>("execute_on") = getParam<ExecFlagEnum>("execute_on");
      54          33 :   const VectorPostprocessorName vpp_name = _name + "_extra_id_vpp";
      55          33 :   _fe_problem.addVectorPostprocessor("ExtraIDIntegralVectorPostprocessor", vpp_name, vpp_params);
      56          33 :   _vpp_object = &_fe_problem.getUserObject<ExtraIDIntegralVectorPostprocessor>(vpp_name);
      57             : 
      58             :   // fill out exta_id_info;
      59          66 :   _extra_id_data.names.insert(
      60          33 :       _extra_id_data.names.end(), extra_id_names.begin(), extra_id_names.end());
      61             : 
      62          33 :   const auto & unique_extra_ids = _vpp_object->getUniqueExtraIds();
      63          33 :   _extra_id_data.unique_ids.resize(unique_extra_ids.size());
      64          88 :   for (unsigned int i = 0; i < unique_extra_ids.size(); ++i)
      65         165 :     _extra_id_data.unique_ids[i].insert(_extra_id_data.unique_ids[i].end(),
      66          55 :                                         (*unique_extra_ids[i]).begin(),
      67          55 :                                         (*unique_extra_ids[i]).end());
      68             : 
      69          33 :   _extra_id_data.integrals = _vpp_object->getIntegrals();
      70          66 :   _extra_id_data.variables.insert(
      71          33 :       _extra_id_data.variables.end(), var_names.begin(), var_names.end());
      72          33 : }
      73             : 
      74             : void
      75          24 : to_json(nlohmann::json & json, const ExtraIDIntegralReporter::ExtraIDData & extra_id_data)
      76             : {
      77          24 :   auto & info = json["extra_id_data"];
      78          24 :   info["num_id_name"] = extra_id_data.names.size();
      79          24 :   info["id_name"] = extra_id_data.names;
      80          24 :   info["num_values_per_integral"] = extra_id_data.integrals.size();
      81          24 :   info["map_id_to_value"] = extra_id_data.unique_ids;
      82             : 
      83          24 :   auto & integrals = json["integrals"];
      84          24 :   integrals["num_variables"] = extra_id_data.variables.size();
      85          24 :   integrals["variable_names"] = extra_id_data.variables;
      86          56 :   for (unsigned int i = 0; i < extra_id_data.variables.size(); ++i)
      87             :   {
      88          32 :     std::string name = extra_id_data.variables[i] + "_integral";
      89          32 :     integrals[name] = (*extra_id_data.integrals[i]);
      90          32 :   }
      91          24 : }
      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 : }

Generated by: LCOV version 1.14