Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
OperationIf.cpp
Go to the documentation of this file.
1// -------------------------------------------------------//
2//
3// SHAMROCK code for hydrodynamics
4// Copyright (c) 2021-2026 Timothée David--Cléris <tim.shamrock@proton.me>
5// SPDX-License-Identifier: CeCILL Free Software License Agreement v2.1
6// Shamrock is licensed under the CeCILL 2.1 License, see LICENSE for more information
7//
8// -------------------------------------------------------//
9
16
18#include <sstream>
19
20namespace shamrock::solvergraph {
21
23 if (get_edges().condition.data) {
24 if (then_node) {
25 then_node->evaluate();
26 }
27 } else if (else_node) {
28 else_node->evaluate();
29 }
30 }
31
33
34 std::stringstream ss;
35
36 ss << "subgraph cluster_" + std::to_string(get_uuid()) + " {\n";
37 ss << sham::format("n_{} [label=\"{}\", shape=diamond];\n", get_uuid(), _impl_get_label());
38
39 if (then_node) {
40 ss << then_node->get_dot_graph_partial();
41 ss << sham::format(
42 "n_{} -> {} [label=\"true\"];\n",
43 get_uuid(),
44 then_node->get_dot_graph_node_start());
45 ss << then_node->get_dot_graph_node_end() << " -> "
46 << sham::format("n_{}_end", get_uuid()) << ";\n";
47 } else {
48 ss << sham::format(
49 "n_{} -> n_{}_end [label=\"true\", style=dashed];\n", get_uuid(), get_uuid());
50 }
51
52 if (else_node) {
53 ss << else_node->get_dot_graph_partial();
54 ss << sham::format(
55 "n_{} -> {} [label=\"false\"];\n",
56 get_uuid(),
57 else_node->get_dot_graph_node_start());
58 ss << else_node->get_dot_graph_node_end() << " -> "
59 << sham::format("n_{}_end", get_uuid()) << ";\n";
60 } else {
61 ss << sham::format(
62 "n_{} -> n_{}_end [label=\"false\", style=dashed];\n", get_uuid(), get_uuid());
63 }
64
65 ss << sham::format("n_{}_end [label=\"\", shape=point, width=0.15];\n", get_uuid());
66 ss << sham::format("label = \"{}\";\n", _impl_get_label());
67 ss << "}\n";
68
69 auto &cond = get_ro_edge_base(0);
70 ss << sham::format(
71 "e_{} -> n_{} [style=\"dashed\", color=green];\n", cond.get_uuid(), get_uuid());
72 ss << sham::format(
73 "e_{} [label=\"{}\",shape=rect, style=filled];\n", cond.get_uuid(), cond.get_label());
74
75 return ss.str();
76 }
77
78 std::string OperationIf::_impl_get_tex() const {
79 std::stringstream ss;
80 ss << "Start : " << _impl_get_label() << "\n";
81 if (then_node) {
82 ss << "Then :\n" << then_node->get_tex_partial() << "\n";
83 }
84 if (else_node) {
85 ss << "Else :\n" << else_node->get_tex_partial() << "\n";
86 }
87 ss << "End : " << _impl_get_label() << "\n";
88 return ss.str();
89 }
90
91} // namespace shamrock::solvergraph
Meta node that evaluates an optional then-node when a bool edge is true, and an optional else-node wh...
u64 get_uuid() const
Get the UUID of the node.
Definition INode.hpp:55
const IEdge & get_ro_edge_base(int slot)
Get a reference to a read only edge.
Definition INode.hpp:138
std::string _impl_get_dot_graph_partial() const
get the dot graph of the node partial
std::string _impl_get_label() const
get the label of the node
void _impl_evaluate_internal()
evaluate the node
std::string _impl_get_tex() const
get the tex of the node