https://mooseframework.inl.gov
ParaviewComponentAnnotationMap.C
Go to the documentation of this file.
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 
11 
12 #include "nlohmann/json.h"
13 #include "LockFile.h"
14 #include "JsonIO.h"
15 #include "THMProblem.h"
16 #include "Component.h"
17 #include <fstream>
18 
20 
22 static const std::vector<Real> kaams_colors = {1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0,
23  0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0,
24  0.0, 1.0, 1.0, 0.63, 0.63, 1.0, 0.67, 0.5, 0.33,
25  1.0, 0.5, 0.75, 0.53, 0.35, 0.7, 1.0, 0.75, 0.5};
26 
29 {
32  execute_options = {EXEC_INITIAL};
33  params.set<ExecFlagEnum>("execute_on") = execute_options;
34  return params;
35 }
36 
38  : FileOutput(parameters)
39 {
40  THMProblem * thm_problem = dynamic_cast<THMProblem *>(_problem_ptr);
41  if (!thm_problem)
42  mooseError(name(),
43  ": ParaviewComponentAnnotationMap can only be used with THM-based simulation.");
44 }
45 
46 void
48 {
49  if (processor_id() == 0)
50  {
51  THMProblem * thm_problem = dynamic_cast<THMProblem *>(_problem_ptr);
52  const std::vector<std::shared_ptr<Component>> & comps = thm_problem->getComponents();
53 
54  std::vector<Real> clrs;
55  unsigned int clr_idx = 0;
56 
57  std::vector<std::string> anns;
58  for (auto & comp : comps)
59  {
60  const auto & subdomains = comp->getSubdomainNames();
61  for (auto & sn : subdomains)
62  {
64 
65  anns.push_back(Moose::stringify(sid));
66  anns.push_back(sn);
67 
68  clrs.push_back(kaams_colors[clr_idx++]);
69  clrs.push_back(kaams_colors[clr_idx++]);
70  clrs.push_back(kaams_colors[clr_idx++]);
71  // 12 colors with RGB values
72  clr_idx = clr_idx % (12 * 3);
73  }
74  }
75 
76  nlohmann::json json;
77  json[0]["Annotations"] = anns;
78  json[0]["IndexedColors"] = clrs;
79  json[0]["Name"] = _file_base;
80 
81  std::ofstream out(filename().c_str());
82  out << std::setw(4) << json << std::endl;
83  }
84 }
85 
86 std::string
88 {
89  return _file_base + ".json";
90 }
Specialization of FEProblem to run with component subsystem.
Definition: THMProblem.h:18
T & set(const std::string &name, bool quiet_mode=false)
registerMooseObject("ThermalHydraulicsApp", ParaviewComponentAnnotationMap)
std::string _file_base
virtual const std::string & name() const
ExecFlagEnum getDefaultExecFlagEnum()
static const std::vector< Real > kaams_colors
KAAMS color profile from paraview.
FEProblemBase * _problem_ptr
static InputParameters validParams()
ParaviewComponentAnnotationMap(const InputParameters &parameters)
std::string stringify(const T &t)
OStreamProxy out
MooseMesh * _mesh_ptr
void mooseError(Args &&... args) const
const std::vector< std::shared_ptr< Component > > & getComponents()
Return list of components available in the simulation.
Definition: Simulation.h:117
processor_id_type processor_id() const
Output annotation map for paraview.
SubdomainID getSubdomainID(const SubdomainName &subdomain_name) const
const ExecFlagType EXEC_INITIAL