https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
22static 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)
43 ": ParaviewComponentAnnotationMap can only be used with THM-based simulation.");
44}
45
46void
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
86std::string
const ExecFlagType EXEC_INITIAL
static const std::vector< Real > kaams_colors
KAAMS color profile from paraview.
registerMooseObject("ThermalHydraulicsApp", ParaviewComponentAnnotationMap)
static InputParameters validParams()
std::string _file_base
T & set(const std::string &name, bool quiet_mode=false)
const std::string & name() const
void mooseError(Args &&... args) const
SubdomainID getSubdomainID(const SubdomainName &subdomain_name) const
FEProblemBase * _problem_ptr
MooseMesh * _mesh_ptr
Output annotation map for paraview.
ParaviewComponentAnnotationMap(const InputParameters &parameters)
const std::vector< std::shared_ptr< Component > > & getComponents() const
Return list of components available in the simulation.
Definition Simulation.h:117
Specialization of FEProblem to run with component subsystem.
Definition THMProblem.h:19
processor_id_type processor_id() const
ExecFlagEnum getDefaultExecFlagEnum()
std::string stringify(const T &t)