ElecSolver 0.1.3__py3-none-any.whl → 1.0.0__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.
@@ -1,6 +1,7 @@
1
1
  import numpy as np
2
2
  import networkx as nx
3
3
  from scipy.sparse import coo_matrix
4
+ from .utils import SolutionFrequency
4
5
 
5
6
 
6
7
  class FrequencySystemBuilder():
@@ -52,7 +53,7 @@ class FrequencySystemBuilder():
52
53
  self.offset_i = offset_i
53
54
  self.offset_j = offset_j
54
55
 
55
- def set_mass(self,*args):
56
+ def set_ground(self,*args):
56
57
  for index in args:
57
58
  for pivot,subsystem in enumerate(self.list_of_subgraphs):
58
59
  if index in subsystem:
@@ -252,13 +253,13 @@ class FrequencySystemBuilder():
252
253
  def build_intensity_and_voltage_from_vector(self,sol):
253
254
  sign = np.sign(self.impedence_coords[1]-self.impedence_coords[0])
254
255
  if self.source_count!=0:
255
- return (sol[:self.number_intensities]*sign,
256
+ return SolutionFrequency(sol[:self.number_intensities]*sign,
256
257
  sol[self.number_intensities:-self.source_count],
257
258
  sol[...,-self.source_count:]*self.source_signs
258
259
  )
259
260
 
260
261
  else:
261
- return (sol[:self.number_intensities]*sign,
262
+ return SolutionFrequency(sol[:self.number_intensities]*sign,
262
263
  sol[self.number_intensities:],
263
264
  np.array([],dtype=float)
264
265
  )
@@ -1,7 +1,7 @@
1
1
  import numpy as np
2
2
  import networkx as nx
3
3
  from scipy.sparse import coo_matrix, block_diag
4
-
4
+ from .utils import SolutionTemporal
5
5
 
6
6
  class TemporalSystemBuilder():
7
7
  def __init__(self,coil_coords,coil_data,res_coords,res_data,capa_coords,capa_data,inductive_mutuals_coords,inductive_mutuals_data,res_mutual_coords,res_mutual_data):
@@ -88,7 +88,7 @@ class TemporalSystemBuilder():
88
88
  self.offset_i = offset_i
89
89
  self.offset_j = offset_j
90
90
 
91
- def set_mass(self,*args):
91
+ def set_ground(self,*args):
92
92
  """Function to affect a mass to subsystems
93
93
  If the system already has a mass provided then a warning is displayed and mass reaffected
94
94
  """
@@ -446,14 +446,14 @@ class TemporalSystemBuilder():
446
446
  offset_res = self.res_data.shape[0]
447
447
  offset_capa = self.capa_data.shape[0]
448
448
  if self.source_count!=0:
449
- return (sol[...,:offset_coil]*sign[:offset_coil],
449
+ return SolutionTemporal(sol[...,:offset_coil]*sign[:offset_coil],
450
450
  sol[...,offset_coil:offset_coil+offset_res]*sign[offset_coil:offset_coil+offset_res],
451
451
  sol[...,offset_coil+offset_res:offset_coil+offset_res+offset_capa]*sign[offset_coil+offset_res:offset_coil+offset_res+offset_capa],
452
452
  sol[...,self.number_intensities:-self.source_count],
453
453
  sol[...,-self.source_count:]*self.source_signs
454
454
  )
455
455
  else:
456
- return (sol[...,:offset_coil]*sign[:offset_coil],
456
+ return SolutionTemporal(sol[...,:offset_coil]*sign[:offset_coil],
457
457
  sol[...,offset_coil:offset_coil+offset_res]*sign[offset_coil:offset_coil+offset_res],
458
458
  sol[...,offset_coil+offset_res:offset_coil+offset_res+offset_capa]*sign[offset_coil+offset_res:offset_coil+offset_res+offset_capa],
459
459
  sol[...,self.number_intensities:],
ElecSolver/_version.py CHANGED
@@ -17,5 +17,5 @@ __version__: str
17
17
  __version_tuple__: VERSION_TUPLE
18
18
  version_tuple: VERSION_TUPLE
19
19
 
20
- __version__ = version = '0.1.3'
21
- __version_tuple__ = version_tuple = (0, 1, 3)
20
+ __version__ = version = '1.0.0'
21
+ __version_tuple__ = version_tuple = (1, 0, 0)
ElecSolver/utils.py CHANGED
@@ -1,5 +1,9 @@
1
1
  import numpy as np
2
2
  from scipy.sparse import coo_matrix
3
+ from collections import namedtuple
4
+
5
+ SolutionFrequency = namedtuple("ComplexSolution",["intensities","potentials","intensities_sources"])
6
+ SolutionTemporal = namedtuple("RealSolution",["intensities_coil","intensities_res","intensities_capa","potentials","intensities_sources"])
3
7
 
4
8
  def parallel_sum(*impedences):
5
9
  """Function to compute the graph of impedences resulting from // graphs
@@ -77,7 +81,7 @@ def cast_complex_system_in_real_system(sys,b):
77
81
  new_b
78
82
  real second member equivalent to complex system
79
83
  """
80
- coords = np.stack((sys.row,sys.col),axis=1)
84
+ coords = np.stack((sys.row,sys.col),axis=0)
81
85
  data = np.array(sys.data,dtype=complex)
82
86
  b= b.astype(complex)
83
87
  new_coords = np.concatenate((coords,coords+[[0],[sys.shape[0]]],coords+[[sys.shape[0]],[0]],coords+[[sys.shape[0]],[sys.shape[0]]]),axis=1)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ElecSolver
3
- Version: 0.1.3
3
+ Version: 1.0.0
4
4
  Summary: Formalizes electric systems as linear problems for temporal and frequency-domain studies.
5
5
  Author-email: William Piat <william.piat3@gmail.com>
6
6
  License: MIT
@@ -57,6 +57,7 @@ Its main goal is to provide a friendly Python interface for simulating analog el
57
57
  - [Features](#features-1)
58
58
  - [Example](#example-1)
59
59
  - [Solver suggestions](#solver-suggestions)
60
+ - [Extra uses: Hydraulic or Thermal system modeling](#extra-uses-hydraulic-or-thermal-system-modeling)
60
61
 
61
62
  ## How to install
62
63
  For now this package is distributed on pypi and can be installed using pip
@@ -117,9 +118,9 @@ electric_sys = FrequencySystemBuilder(
117
118
  mutuals_data
118
119
  )
119
120
 
120
- # Set node masses
121
- # 2 values because 2 subsystems
122
- electric_sys.set_mass(0, 3)
121
+ # Set ground
122
+ # 2 values because one for each subsystem
123
+ electric_sys.set_ground(0, 3)
123
124
  # Building system
124
125
  electric_sys.build_system()
125
126
  electric_sys.build_second_member_intensity(intensity=10, input_node=2, output_node=0)
@@ -127,10 +128,10 @@ electric_sys.build_second_member_intensity(intensity=10, input_node=2, output_no
127
128
  # Get and solve the system
128
129
  sys, b = electric_sys.get_system()
129
130
  sol = spsolve(sys.tocsr(), b)
130
- intensities, potentials = electric_sys.build_intensity_and_voltage_from_vector(sol)
131
+ frequencial_response = electric_sys.build_intensity_and_voltage_from_vector(sol)
131
132
 
132
133
  ## We see a tension appearing on the lonely coil (between node 3 and 4)
133
- print(potentials[3]-potentials[4])
134
+ print(frequencial_response.potentials[3]-frequencial_response.potentials[4])
134
135
  ```
135
136
  #### Adding a Parallel Resistance
136
137
  We want to add components in parallel with existing components for instance inserting a resistor in parallel with the first inductance (between nodes 0 and 2)
@@ -200,8 +201,8 @@ res_mutuals_data = np.array([],dtype=float)
200
201
 
201
202
  ## initializing system
202
203
  elec_sys = TemporalSystemBuilder(coil_coords,coil_data,res_coords,res_data,capa_coords,capa_data,mutuals_coords,mutuals_data,res_mutuals_coords,res_mutuals_data)
203
- ## Seting mass at point 0
204
- elec_sys.set_mass(0)
204
+ ## Seting ground at point 0
205
+ elec_sys.set_ground(0)
205
206
  ## Build second member
206
207
  elec_sys.build_system()
207
208
  elec_sys.build_second_member_intensity(10,1,0)
@@ -217,9 +218,9 @@ dt=0.08
217
218
  vals_res1 = []
218
219
  vals_res2 = []
219
220
  for i in range(50):
220
- currents_coil,currents_res,currents_capa,voltages,_ = elec_sys.build_intensity_and_voltage_from_vector(sol)
221
- vals_res1.append(currents_res[1])
222
- vals_res2.append(currents_res[0])
221
+ temporal_response = elec_sys.build_intensity_and_voltage_from_vector(sol)
222
+ vals_res1.append(temporal_response.intensities_res[1])
223
+ vals_res2.append(temporal_response.intensities_res[0])
223
224
  ## implicit euler time iterations
224
225
  sol = spsolve(S2+dt*S1,b*dt+S2@sol)
225
226
  import matplotlib.pyplot as plt
@@ -244,3 +245,64 @@ This outputs the following graph that displays the intensity passing through the
244
245
  > [!TIP]
245
246
  > See example `tests.test_temporal_system` in the tests on how to use pyMUMPS for solving the resulting system efficiently.
246
247
 
248
+
249
+ ## Extra uses: Hydraulic or Thermal system modeling
250
+
251
+ This repository can be used as is in order to model the mass flow or thermal flux in respectively Hydraulic networks or Thermal networks where a difference of pressure or a difference of temperature can be assimilated to a tension source. Since electric potentials are always computed relatively to the ground node you might need to rescale the resulting potentials:
252
+
253
+ We are considering the following hydraulic problem:
254
+
255
+ ![Hydraulic system](img/hydraulic.png)
256
+
257
+ Taking R=1 this gives
258
+
259
+ ```python
260
+ import numpy as np
261
+ from scipy.sparse.linalg import spsolve
262
+ from ElecSolver import TemporalSystemBuilder
263
+
264
+ ## Defining resistances
265
+ R = 1
266
+ res_coords = np.array([[0,2,1,0,1,3],[1,3,3,2,2,0]],dtype=int)
267
+ res_data = R*np.array([2,3,1,1,1,1],dtype=float)
268
+
269
+ ## Here we are not using coils, capacities or mutuals we defined them as empty
270
+ ## Defining 0 coil
271
+ coil_coords = np.array([[],[]],dtype=int)
272
+ coil_data = np.array([],dtype=float)
273
+ ## Defining 0 capacity
274
+ capa_coords = np.array([[],[]],dtype=int)
275
+ capa_data = np.array([],dtype=float)
276
+
277
+ ## Defining no mutual
278
+ mutuals_coords=np.array([[],[]],dtype=int)
279
+ mutuals_data = np.array([],dtype=float)
280
+
281
+
282
+ res_mutuals_coords=np.array([[],[]],dtype=int)
283
+ res_mutuals_data = np.array([],dtype=float)
284
+
285
+ ## initializing system
286
+ hydraulic_sys = TemporalSystemBuilder(coil_coords,coil_data,res_coords,res_data,capa_coords,capa_data,mutuals_coords,mutuals_data,res_mutuals_coords,res_mutuals_data)
287
+ ## Seting ground at point 0
288
+ hydraulic_sys.set_ground(0)
289
+ ## Build second member
290
+ hydraulic_sys.build_system()
291
+ ## enforcing a pressure delta of 10 Pa
292
+ hydraulic_sys.build_second_member_tension(10,1,0)
293
+ # get system (S1 is real part, S2 derivative part)
294
+ # the problem is only resitive thus S2 =0
295
+ S1,S2,rhs = hydraulic_sys.get_system()
296
+
297
+ sol = spsolve(S1.tocsr(),rhs)
298
+ solution = hydraulic_sys.build_intensity_and_voltage_from_vector(sol)
299
+ # After you computed the solution of the system
300
+
301
+ pressure_input=10000
302
+ pressure_node=0
303
+ # Rescaling the potential to the new reference
304
+ potentials = solution.potentials - solution.potentials[pressure_node] + pressure_input
305
+ print("Pressures in the system:", potentials)
306
+ ## get the flux passing through the system
307
+ print("Debit through the system",solution.intensities_sources[0])
308
+ ```
@@ -0,0 +1,10 @@
1
+ ElecSolver/FrequencySystemBuilder.py,sha256=1OKNv2NhKvzvCzK8f1XEzmUoP2gbD1tUXNY43cL7j9E,12035
2
+ ElecSolver/TemporalSystemBuilder.py,sha256=AIJSd2qU83XRhiGO7QZFpVMGFz5Ii2f0RZzlBhIe76M,23564
3
+ ElecSolver/__init__.py,sha256=jYln4Hwpz5Y7aXUxCnHU6kPs--2MXc58rbaTTQvcE8I,224
4
+ ElecSolver/_version.py,sha256=fo5PXsZuloQZu3LdpIFTUAXvJmY2L9N5sNGe2tvdU98,511
5
+ ElecSolver/utils.py,sha256=mrGSWW5osBrAKYathyjM9KgZDzVaweqjx2paNvumVQA,5491
6
+ elecsolver-1.0.0.dist-info/licenses/LICENCE.txt,sha256=v-lfIiLUg0gkkSbraLUejUcFsyG7SbKQaK7GqgIEWFQ,1068
7
+ elecsolver-1.0.0.dist-info/METADATA,sha256=LMcmfVzSPRuT5OdoI8dUghL6pjonTjQXYTYkzPJky54,10549
8
+ elecsolver-1.0.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
9
+ elecsolver-1.0.0.dist-info/top_level.txt,sha256=2toqgPNV9y44OzukZZEL4qeFZFkNR1GXZjIlZVmC-Ic,11
10
+ elecsolver-1.0.0.dist-info/RECORD,,
@@ -1,10 +0,0 @@
1
- ElecSolver/FrequencySystemBuilder.py,sha256=8GoF8R1d1Qfs3f2y4tXJfu5Yq7iPrZXM-cwogdzu5v0,11962
2
- ElecSolver/TemporalSystemBuilder.py,sha256=L8VpWzU-7BE4NCHuuvlTdZnjJHdcsuP4HRXpVA0dMAM,23495
3
- ElecSolver/__init__.py,sha256=jYln4Hwpz5Y7aXUxCnHU6kPs--2MXc58rbaTTQvcE8I,224
4
- ElecSolver/_version.py,sha256=NIzzV8ZM0W-CSLuEs1weG4zPrn_-8yr1AwwI1iuS6yo,511
5
- ElecSolver/utils.py,sha256=M-42jBk3BW0jPq1DDAC04VwrDIgTAS0sI9q28l2j5YY,5215
6
- elecsolver-0.1.3.dist-info/licenses/LICENCE.txt,sha256=v-lfIiLUg0gkkSbraLUejUcFsyG7SbKQaK7GqgIEWFQ,1068
7
- elecsolver-0.1.3.dist-info/METADATA,sha256=s9qP3fUrM1yLspQ_jEhOUadzo6K5BAhkCAiHszJokB8,8110
8
- elecsolver-0.1.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
9
- elecsolver-0.1.3.dist-info/top_level.txt,sha256=2toqgPNV9y44OzukZZEL4qeFZFkNR1GXZjIlZVmC-Ic,11
10
- elecsolver-0.1.3.dist-info/RECORD,,