Coverage for pyrc \ validation \ plate \ model.py: 0%
49 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-13 16:59 +0200
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-13 16:59 +0200
1# -------------------------------------------------------------------------------
2# Copyright (C) 2026 Joel Kimmich, Tim Jourdan
3# ------------------------------------------------------------------------------
4# License
5# This file is part of PyRC, distributed under GPL-3.0-or-later.
6# ------------------------------------------------------------------------------
8# Script for validation
9#
10# Calculation of the dynamic solution of a semi-infinite plate
11#
12# Model solution
13#
14import numpy as np
16from pyrc.core.inputs import FluidBoundaryConditionGeometric
17from pyrc.core.nodes import Node
18from pyrc.core.resistors import CombinedResistor
19from pyrc.visualization.plot import LinePlot
20from pyrc.validation.network import NetworkTemplate, Block
21from pyrc.validation.plate import setup
24class PlateNetwork(NetworkTemplate):
25 def __init__(self, blocks: list[Block], new_temperature):
26 super().__init__()
27 self.settings.save_all_x_seconds = 0.1
28 self.blocks = blocks
29 self.new_temperature = new_temperature
31 self.x_major_points = np.cumsum([0, *[b.width for b in self.blocks]])
33 def _create_network(self):
34 block_nodes = []
35 block: Block
36 for i, block in enumerate(self.blocks):
37 x_start = sum([b.width for b in self.blocks[:i]])
38 start_vector = np.array([x_start, 0, 0])
39 for increment in range(block.increments):
40 block_nodes.append(
41 Node(
42 material=block.material,
43 temperature=block.initial_temperature,
44 position=block.increment_positions[increment] + start_vector,
45 delta=(block.width / block.increments, 1, 1),
46 rc_objects=self.rc_objects,
47 rc_solution=self.rc_solution,
48 )
49 )
51 # add resistors between the nodes
52 all_resistors = []
53 for i, node in enumerate(block_nodes[:-1]):
54 all_resistors.append(CombinedResistor())
55 all_resistors[-1].double_connect(block_nodes[i], block_nodes[i + 1])
57 # add Boundary to x=0 side
58 bc = FluidBoundaryConditionGeometric(
59 temperature=self.new_temperature,
60 position=np.array([-1, 0, 0]),
61 rc_objects=self.rc_objects,
62 rc_solution=self.rc_solution,
63 settings=self.settings,
64 )
65 conduction_resistor = CombinedResistor()
66 convective_resistor = CombinedResistor(resistance=np.float64(0))
67 conduction_resistor.connect(block_nodes[0], direction=(-1, 0, 0), node_direction_points_to=bc)
68 convective_resistor.double_connect(conduction_resistor, bc)
69 all_resistors.extend([conduction_resistor, convective_resistor])
71 self.rc_objects.set_lists(capacitors=block_nodes, resistors=all_resistors, boundaries=[bc])
74def run_plate_model(plot_data=False):
75 blocks, time_indexes, times, name_add_on = setup()
76 network = PlateNetwork(blocks, 20)
77 network.save_to_pickle = True
78 network.load_from_pickle = True
79 network.num_cores_jacobian = 1
80 # network.settings.save_folder_path = r"C:\Simulations\PyRC\debug"
81 network.create_network()
82 network.solve_network(
83 # t_span=(0, 3600*24*1),
84 t_span=(0, 2000),
85 print_progress=True,
86 check_courant=False,
87 )
88 if plot_data:
89 plot = LinePlot(
90 x=[n.position[0] for n in network.nodes],
91 ys=network.rc_solution.temperature_vectors[time_indexes],
92 labels=[f"{float(t):.1f} s" for t in times],
93 y_title="Temperature / °C (model)",
94 x_title="Length / m",
95 )
96 plot.plot()
97 plot.ax.set_xlim(left=0, right=network.x_major_points[-1])
98 plot.fig.legend(loc="outside upper right", ncols=5)
99 plot.save(
100 r"C:\Simulations\PyRC\debug\plate"
101 f"{name_add_on}.png"
102 )
103 else:
104 return (
105 [n.position[0] for n in network.nodes],
106 network.rc_solution.temperature_vectors[time_indexes],
107 times,
108 name_add_on,
109 )
112if __name__ == "__main__":
113 run_plate_model(True)