Coverage for pyrc \ validation \ network.py: 0%
51 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# ------------------------------------------------------------------------------
8import numpy as np
10from pyrc.core.network import RCNetwork
11from pyrc.core.settings import SolveSettings, Settings
12from pyrc.core.components.templates import RCObjects, RCSolution, Solid
15class NetworkTemplate(RCNetwork):
16 def __init__(self, working_dir=r"C:\Simulations\PyRC\debug"):
17 solve_settings = SolveSettings(
18 max_step=1000,
19 save_interval=int(1e5),
20 max_saved_steps=70,
21 # rtol=0.1,
22 atol=1e-8,
23 )
24 settings = Settings(
25 calculate_static=False,
26 use_weather_data=False,
27 weather_data_path=None,
28 save_folder_path=working_dir,
29 save_all_x_seconds=300,
30 solve_settings=solve_settings,
31 )
33 rc_objects = RCObjects()
34 rc_solution = RCSolution(rc_objects=rc_objects)
35 super().__init__(
36 save_to_pickle=True,
37 load_from_pickle=True,
38 load_solution=True,
39 settings=settings,
40 rc_objects=rc_objects,
41 rc_solution=rc_solution,
42 num_cores_jacobian=None,
43 )
45 def _create_network(self, *args, **kwargs):
46 pass
49class Block:
50 counter = 0
52 def __init__(
53 self,
54 width,
55 initial_temperature,
56 increments=10,
57 thermal_conductivity=10,
58 density=10,
59 heat_capacity=10,
60 ):
61 self.width = width
62 self.initial_temperature = initial_temperature
63 self.increments = increments
65 self.material = Solid(
66 f"material_{Block.counter}",
67 thermal_conductivity=thermal_conductivity,
68 density=density,
69 heat_capacity=heat_capacity,
70 )
71 Block.counter += 1
73 self.__increment_positions = None
74 self.__x_values = None
76 @property
77 def x_values(self) -> np.ndarray:
78 if self.__x_values is None:
79 self.__x_values = (np.array(range(self.increments)) + 0.5) * self.width / self.increments
80 return self.__x_values
82 @property
83 def increment_positions(self) -> np.ndarray:
84 if self.__increment_positions is None:
85 self.__increment_positions = np.column_stack(
86 [self.x_values, np.zeros_like(self.x_values), np.zeros_like(self.x_values)]
87 )
88 return self.__increment_positions
91class Model:
92 def __init__(self, blocks: list[Block]):
93 """
94 Initialize heat equation model with blocks.
96 Parameters
97 ----------
98 blocks : list of Block
99 List of Block objects defining initial conditions
100 """
101 self.blocks: list[Block] = blocks
102 self.widths = np.array([block.width for block in blocks])
103 self.length = sum(self.widths)
104 self.x_positions = np.concatenate([[0], np.cumsum(self.widths)])
105 self.alpha = blocks[0].material.thermal_conductivity / (
106 blocks[0].material.density * blocks[0].material.heat_capacity
107 )
108 self._x_values = None
110 @property
111 def x_values(self) -> list:
112 if self._x_values is None:
113 x_values = []
114 for i, block in enumerate(self.blocks):
115 start = sum([b.width for b in self.blocks[:i]])
116 values = block.x_values + start
117 x_values.extend(values.tolist())
118 self._x_values = x_values
119 return self._x_values