Coverage for pyrc \ tests \ test_main.py: 100%
37 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# ------------------------------------------------------------------------------
8from unittest import TestCase
10import numpy as np
12from pyrc.core.components.resistor import Resistor
13from pyrc.core.inputs import FluidBoundaryConditionGeometric
14from pyrc.core.materials import Concrete
15from pyrc.core.nodes import Node
16from pyrc.model.facade import Facade
17from pyrc.tools.science import celsius_to_kelvin
20class TestNode(TestCase):
21 """
22 Testing basic parts.
24 This test has to be changed in the future, when the solvers are up and running :P
25 """
27 def setUp(self):
28 # setup simple case with two boundary conditions, one node in the middle and two resistors
29 self.bc_outside = FluidBoundaryConditionGeometric(temperature=celsius_to_kelvin(5),
30 position=np.array([1, 0, 0]))
31 self.bc_inside = FluidBoundaryConditionGeometric(temperature=celsius_to_kelvin(5),
32 position=np.array([-1, 0, 0]))
34 self.node = Node(material=Concrete(), # J/K; like 240x100x100 mm of concrete
35 temperature=celsius_to_kelvin(0),
36 position=np.array([0, 0, 0]))
38 self.heat_transfer_outside = Resistor(resistance=0.45333) # 1 W/m/K for 120 mm and alpha=3
39 self.heat_transfer_inside = Resistor(resistance=0.62) # 1 W/m/K for 120 mm and alpha=2
41 # create connections
42 self.bc_outside.connect(self.heat_transfer_outside)
43 self.heat_transfer_outside.connect(self.node, direction=(1, 0, 0), node_direction_points_to=self.bc_outside)
44 self.heat_transfer_inside.connect(self.node, direction=(-1, 0, 0), node_direction_points_to=self.bc_inside)
45 self.heat_transfer_inside.connect(self.bc_inside)
47 def test_connect_to_neighbour(self):
48 self.assertIsInstance(self.node.neighbours[0], Resistor)
49 self.assertAlmostEqual(self.node.neighbours[0].resistance, 0.45333, places=6)
50 self.assertIsInstance(self.node.neighbours[1], Resistor)
51 self.assertAlmostEqual(self.node.neighbours[1].resistance, 0.62, places=6)
54class TestRCNetwork(TestCase):
56 def setUp(self):
57 self.base_case = Facade(num_cores_jacobian=1, load_from_pickle=False)
58 self.base_case.settings.save_all_x_seconds = 0.5
59 self.base_case.create_network()
61 self.base_case_symbolic = Facade(num_cores_jacobian=1, load_from_pickle=False)
62 self.base_case.settings.save_all_x_seconds = 0.5
63 self.base_case.create_network()
65 # def test_make_system_matrix(self):
66 # system_matrix_symbol = self.base_case.system_matrix_symbol
67 # system_matrix = self.base_case.system_matrix
69 def test_solve_network(self):
70 t_span = (0, 1)
71 self.base_case.solve_network(t_span)
72 np.testing.assert_allclose(self.base_case.rc_solution.t, np.array([0, 0.5, 1]))
73 np.testing.assert_allclose(self.base_case.rc_solution.y[-1][-1], 284.15468370747436)