Coverage for pyrc \ validation \ plate \ analytic.py: 0%

43 statements  

« 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# ------------------------------------------------------------------------------ 

7 

8# Script for validation 

9# 

10# Calculation of the dynamic solution of a semi-infinite plate 

11# 

12# Analytic solution 

13# 

14import numpy as np 

15from scipy.special import erf 

16 

17from pyrc.visualization.plot import LinePlot 

18from pyrc.validation.network import Model 

19from pyrc.validation.plate import setup 

20 

21thermal_conductivity = 10 

22density = 10 

23heat_capacity = 10 

24a = thermal_conductivity / (density * heat_capacity) 

25 

26 

27def u(x, time, alpha, initial_temperature, new_temperature): 

28 x = np.atleast_1d(x) 

29 time = np.atleast_1d(time) 

30 X, T = np.meshgrid(x, time, indexing="ij") 

31 

32 result = (1 - erf(X / (2 * (alpha * T) ** 0.5))) * (new_temperature - initial_temperature) + initial_temperature 

33 

34 # Handle x=0 and time=0 case 

35 mask = (X == 0) & (T == 0) 

36 result[mask] = initial_temperature 

37 

38 return result.squeeze() 

39 

40 

41class ModelPlate(Model): 

42 def __init__(self, blocks, new_temperature): 

43 super().__init__(blocks) 

44 self.initial_temperature = blocks[0].initial_temperature 

45 self.new_temperature = new_temperature 

46 

47 def u(self, time): 

48 x = np.atleast_1d(self.x_values) 

49 time = np.atleast_1d(time) 

50 X, T = np.meshgrid(x, time, indexing="ij") 

51 

52 result = (1 - erf(X / (2 * (self.alpha * T) ** 0.5))) * ( 

53 self.new_temperature - self.initial_temperature 

54 ) + self.initial_temperature 

55 

56 # Handle x=0 and time=0 case 

57 mask = (X == 0) & (T == 0) 

58 result[mask] = self.initial_temperature 

59 

60 return result.squeeze() 

61 

62 

63def run_plate_analytic(plot_data=False): 

64 blocks, _, times, name_add_on = setup() 

65 

66 model = ModelPlate(blocks, 20) 

67 

68 result = model.u(times) # x from top to bottom (axis=0) and time from left to right (axis=1) 

69 

70 if plot_data: 

71 plot = LinePlot( 

72 x=model.x_values, 

73 ys=result.T, 

74 labels=[f"{float(t):.1f} s" for t in times], 

75 y_title="Temperature / °C (analytic)", 

76 x_title="Length / m", 

77 ) 

78 plot.plot() 

79 plot.ax.set_xlim(left=0, right=model.x_positions[-1]) 

80 plot.fig.legend(loc="outside upper right", ncols=5) 

81 plot.save( 

82 r"C:\Simulations\PyRC\debug\plate_analytic" 

83 f"{name_add_on}.png" 

84 ) 

85 else: 

86 return model.x_values, result.T, times, name_add_on 

87 

88 

89if __name__ == '__main__': 

90 run_plate_analytic(True)