wolfhece 2.1.98__py3-none-any.whl → 2.1.100__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -40,7 +40,7 @@ from ..PyVertex import getIfromRGB
40
40
  from ..PyTranslate import _
41
41
  from ..CpGrid import CpGrid
42
42
  from ..GraphNotebook import PlotPanel
43
- from ..PyParams import Wolf_Param, new_json
43
+ from ..PyParams import Wolf_Param, new_json, key_Param, Type_Param
44
44
  from .cst_2D_boundary_conditions import BCType_2D, Direction, BCType_2D_To_BCType_2D_GPU
45
45
 
46
46
  PREV_INFILTRATION_NULL = 0 #PAS D'INFILTRATION
@@ -0,0 +1,131 @@
1
+ import numpy as np
2
+
3
+ class PIDController:
4
+ """
5
+ Tuning a PID controller -- https://dewesoft.com/blog/what-is-pid-controller
6
+
7
+ Tuning the PID parameters Kp, Ki and Kd is crucial in PID controller design.
8
+ Tuning must be customized for each of the many PID applications.
9
+ Key tuning parameters include:
10
+
11
+ - Proportional Gain (Kp): This parameter determines the proportion of
12
+ the error signal contributing to the controller output. A higher
13
+ Kp value results in a stronger response to the current error.
14
+ Too high a Kp can lead to oscillations or instability, while too
15
+ low a value can result in a sluggish response.
16
+
17
+ - Integral Gain (Ki): The integral term considers the accumulation
18
+ of past errors and amplifies them over time. It helps eliminate
19
+ steady-state error by continuously adjusting the control signal.
20
+ A higher Ki value helps reduce steady-state error but can lead
21
+ to overshoot or instability if set too high.
22
+
23
+ - Derivative Gain (Kd): The derivative term predicts the future behavior
24
+ of the error based on its current rate of change. It helps dampen
25
+ oscillations by counteracting rapid changes in the error signal.
26
+ Increasing Kd enhances damping and reduces overshoot, but too high
27
+ a value can lead to instability or sensitivity to noise.
28
+
29
+ The tuning process involves adjusting these parameters to achieve
30
+ desired system performance, such as stability, responsiveness,
31
+ and minimal overshoot. Several methods are used for PID tuning,
32
+ including manual tuning, Ziegler-Nichols method, and optimization
33
+ algorithms. Let’s take a closer look at each of these methods:
34
+
35
+ In manual tuning, the engineer adjusts the parameters based on their
36
+ understanding of the system dynamics and the desired performance criteria.
37
+ This method involves iteratively tweaking the parameters while observing
38
+ the system's response until satisfactory performance is achieved.
39
+
40
+ The Ziegler-Nichols Method provides a systematic approach to PID
41
+ tuning based on step response experiments. The integral and derivative
42
+ gains are set to zero and gradually increased until the system oscillates
43
+ at a constant amplitude. The proportional gain and oscillation period
44
+ are determined from the oscillation period and amplitude, which are
45
+ then used to calculate suitable PID parameters. Several other tuning
46
+ methods exist, including Cohen-Coon, Lambda, and Dead Time.
47
+
48
+ Optimization algorithms such as gradient descent, genetic algorithms,
49
+ or particle swarm optimization automatically search for optimal PID
50
+ parameters based on specified performance criteria and system models.
51
+
52
+ PID tuning is a critical step in control system design. It ensures
53
+ that the controller effectively regulates the system while meeting
54
+ performance requirements.
55
+ """
56
+
57
+ def __init__(self, kp, ki, kd):
58
+ """
59
+ Initialize the PID controller with given coefficients.
60
+
61
+ :params kp (float): Proportional gain coefficient.
62
+ :params ki (float): Integral gain coefficient.
63
+ :params kd (float): Derivative gain coefficient.
64
+ """
65
+
66
+ self.kp = kp
67
+ self.ki = ki
68
+ self.kd = kd
69
+ self.error_sum = 0
70
+ self.last_error = 0
71
+
72
+ def calculate(self, setpoint, feedback):
73
+ """ Compute the PID response.
74
+
75
+ :param setpoint: Objective value to achieve.
76
+ :type setpoint: float
77
+ :param feedback: Current measured value.
78
+ :type feedback: float
79
+ :return: PID control output.
80
+ :rtype: float
81
+ """
82
+
83
+ error = setpoint - feedback
84
+ self.error_sum += error
85
+ error_diff = error - self.last_error
86
+ self.last_error = error
87
+
88
+ p = self.kp * error
89
+ i = self.ki * self.error_sum
90
+ d = self.kd * error_diff
91
+
92
+ return p + i + d
93
+
94
+ if __name__ == "__main__":
95
+
96
+ import matplotlib.pyplot as plt
97
+
98
+ # Create a PIDController instance
99
+ pid_controller = PIDController(kp=0.5, ki=0.1, kd=.5)
100
+
101
+ # Define time range and step size
102
+ t_start = 0
103
+ t_end = 10
104
+ dt = 0.1
105
+
106
+ # Initialize lists to store time and output values
107
+ time = []
108
+ output = []
109
+ measures = [1]
110
+
111
+ # Simulate the system over time
112
+ for t in np.arange(t_start, t_end, dt):
113
+ # Calculate the output using the PID controller
114
+ setpoint = 10 # Example setpoint
115
+ control_signal = pid_controller.calculate(setpoint, measures[-1])
116
+
117
+ # Simulate the system dynamics
118
+ # In a real-world application, this would be replaced by actual measurements
119
+ measures.append(measures[-1] + .4 * control_signal)
120
+
121
+ # Store the time and output values
122
+ time.append(t)
123
+ output.append(control_signal)
124
+
125
+ # Plot the output over time
126
+ plt.plot(time, measures[1:], label='System Output')
127
+ plt.xlabel('Time')
128
+ plt.ylabel('Output')
129
+ plt.title('PID Controller Output')
130
+ plt.grid(True)
131
+ plt.show()
wolfhece/pywalous.py CHANGED
@@ -130,13 +130,13 @@ def update_palette_walous(which:Literal['MAJ_NIV1', 'MAJ_NIV2'], pal:wolfpalette
130
130
  return 0
131
131
 
132
132
 
133
- WALOUS2MANNING_MAJ_NIV1 = {1.: 0.04,
134
- 2.: 0.02,
135
- 3.: 0.02,
136
- 4.: 0.03,
137
- 5.: 0.025,
138
- 6.: 0.04,
139
- 7.: 0.05}
133
+ WALOUS2MANNING_MAJ_NIV1 = {1.: 0.04, # Production primaire
134
+ 2.: 0.02, # Production secondaire
135
+ 3.: 0.02, # Production tertiaire
136
+ 4.: 0.03, # Réseaux de transport, Logistique et réseaux d'utilité publique
137
+ 5.: 0.025,# Usage résidentiel
138
+ 6.: 0.04, # Autres usages
139
+ 7.: 0.05} # Zones naturelles
140
140
 
141
141
  WALOUS2MANNING_MAJ_NIV2 = {11.: 0.04, # Agriculture
142
142
  12.: 0.04, # Sylviculture