InSpice 1.5__tar.gz
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.
- inspice-1.5/InSpice/Config/ConfigInstall.py +65 -0
- inspice-1.5/InSpice/Config/__init__.py +0 -0
- inspice-1.5/InSpice/Config/logging.yml +44 -0
- inspice-1.5/InSpice/DeviceLibrary/__init__.py +106 -0
- inspice-1.5/InSpice/Doc/ExampleTools.py +48 -0
- inspice-1.5/InSpice/Doc/__init__.py +0 -0
- inspice-1.5/InSpice/Logging/Logging.py +69 -0
- inspice-1.5/InSpice/Logging/__init__.py +0 -0
- inspice-1.5/InSpice/Math/Calculus.py +164 -0
- inspice-1.5/InSpice/Math/__init__.py +46 -0
- inspice-1.5/InSpice/Physics/MaterialProperties.py +40 -0
- inspice-1.5/InSpice/Physics/PhysicalConstants.py +64 -0
- inspice-1.5/InSpice/Physics/Resistor.py +30 -0
- inspice-1.5/InSpice/Physics/SemiConductor.py +66 -0
- inspice-1.5/InSpice/Physics/__init__.py +0 -0
- inspice-1.5/InSpice/Plot/BodeDiagram.py +60 -0
- inspice-1.5/InSpice/Plot/__init__.py +0 -0
- inspice-1.5/InSpice/Probe/Plot.py +43 -0
- inspice-1.5/InSpice/Probe/WaveForm.py +477 -0
- inspice-1.5/InSpice/Probe/__init__.py +0 -0
- inspice-1.5/InSpice/Scripts/__init__.py +0 -0
- inspice-1.5/InSpice/Scripts/cir2py.py +70 -0
- inspice-1.5/InSpice/Scripts/pyspice_post_installation.py +470 -0
- inspice-1.5/InSpice/Spice/BasicElement.py +1715 -0
- inspice-1.5/InSpice/Spice/ElementParameter.py +395 -0
- inspice-1.5/InSpice/Spice/Expression/Ast.py +407 -0
- inspice-1.5/InSpice/Spice/Expression/Parser.py +346 -0
- inspice-1.5/InSpice/Spice/Expression/__init__.py +19 -0
- inspice-1.5/InSpice/Spice/HighLevelElement.py +865 -0
- inspice-1.5/InSpice/Spice/Library.py +150 -0
- inspice-1.5/InSpice/Spice/Netlist.py +1307 -0
- inspice-1.5/InSpice/Spice/NgSpice/RawFile.py +234 -0
- inspice-1.5/InSpice/Spice/NgSpice/Server.py +162 -0
- inspice-1.5/InSpice/Spice/NgSpice/Shared.py +1347 -0
- inspice-1.5/InSpice/Spice/NgSpice/Simulation.py +131 -0
- inspice-1.5/InSpice/Spice/NgSpice/SimulationType.py +90 -0
- inspice-1.5/InSpice/Spice/NgSpice/__init__.py +23 -0
- inspice-1.5/InSpice/Spice/NgSpice/api.h +76 -0
- inspice-1.5/InSpice/Spice/Parser/parsetab.py +82 -0
- inspice-1.5/InSpice/Spice/Parser.py +1057 -0
- inspice-1.5/InSpice/Spice/Parser_jmgc.py +1486 -0
- inspice-1.5/InSpice/Spice/RawFile.py +417 -0
- inspice-1.5/InSpice/Spice/Simulation.py +1236 -0
- inspice-1.5/InSpice/Spice/Xyce/RawFile.py +175 -0
- inspice-1.5/InSpice/Spice/Xyce/Server.py +140 -0
- inspice-1.5/InSpice/Spice/Xyce/Simulation.py +73 -0
- inspice-1.5/InSpice/Spice/Xyce/__init__.py +0 -0
- inspice-1.5/InSpice/Spice/__init__.py +75 -0
- inspice-1.5/InSpice/Tools/EnumFactory.py +176 -0
- inspice-1.5/InSpice/Tools/File.py +292 -0
- inspice-1.5/InSpice/Tools/Path.py +53 -0
- inspice-1.5/InSpice/Tools/StringTools.py +84 -0
- inspice-1.5/InSpice/Tools/__init__.py +0 -0
- inspice-1.5/InSpice/Unit/SiUnits.py +330 -0
- inspice-1.5/InSpice/Unit/Unit.py +1944 -0
- inspice-1.5/InSpice/Unit/__init__.py +244 -0
- inspice-1.5/InSpice/__init__.py +27 -0
- inspice-1.5/InSpice.egg-info/PKG-INFO +119 -0
- inspice-1.5/InSpice.egg-info/SOURCES.txt +148 -0
- inspice-1.5/InSpice.egg-info/dependency_links.txt +1 -0
- inspice-1.5/InSpice.egg-info/entry_points.txt +2 -0
- inspice-1.5/InSpice.egg-info/requires.txt +11 -0
- inspice-1.5/InSpice.egg-info/top_level.txt +1 -0
- inspice-1.5/LICENSE.txt +661 -0
- inspice-1.5/MANIFEST.in +14 -0
- inspice-1.5/PKG-INFO +119 -0
- inspice-1.5/README.md +81 -0
- inspice-1.5/examples/.travis/travis.py +3 -0
- inspice-1.5/examples/Settings.py +12 -0
- inspice-1.5/examples/advanced-usages/index.rst +5 -0
- inspice-1.5/examples/advanced-usages/internal-device-parameters.py +89 -0
- inspice-1.5/examples/analyses/analyses.py +196 -0
- inspice-1.5/examples/analyses/pole_zero_analysis.py +59 -0
- inspice-1.5/examples/analyses/test_pole_zero.cir +11 -0
- inspice-1.5/examples/basic-usages/index.rst +7 -0
- inspice-1.5/examples/basic-usages/netlist-manipulations.py +70 -0
- inspice-1.5/examples/basic-usages/raw-spice.py +36 -0
- inspice-1.5/examples/basic-usages/subcircuit.py +62 -0
- inspice-1.5/examples/basic-usages/unit.py +86 -0
- inspice-1.5/examples/c-examples/ngspice-shared/test-module.py +68 -0
- inspice-1.5/examples/c-examples/ngspice-shared/test.py +225 -0
- inspice-1.5/examples/c-examples/ngspice_cb/examples/adder_mos.cir +66 -0
- inspice-1.5/examples/data-analysis/fft.py +103 -0
- inspice-1.5/examples/diode/RingModulator.py +41 -0
- inspice-1.5/examples/diode/diode-characteristic-curve.py +203 -0
- inspice-1.5/examples/diode/diode-recovery-time.py +158 -0
- inspice-1.5/examples/diode/index.rst +7 -0
- inspice-1.5/examples/diode/rectification.py +153 -0
- inspice-1.5/examples/diode/ring-modulator.py +93 -0
- inspice-1.5/examples/diode/voltage-multiplier.py +71 -0
- inspice-1.5/examples/diode/zener-characteristic-curve.py +79 -0
- inspice-1.5/examples/electricity/three-phase.py +99 -0
- inspice-1.5/examples/filter/low-pass-rc-filter.py +58 -0
- inspice-1.5/examples/filter/rlc-filter.py +123 -0
- inspice-1.5/examples/fundamental-laws/index.rst +61 -0
- inspice-1.5/examples/fundamental-laws/millman-theorem.py +80 -0
- inspice-1.5/examples/fundamental-laws/thevenin-norton-theorem.py +90 -0
- inspice-1.5/examples/fundamental-laws/voltage-current-divider.py +78 -0
- inspice-1.5/examples/index.rst +11 -0
- inspice-1.5/examples/ngspice-shared/external-source.py +100 -0
- inspice-1.5/examples/ngspice-shared/index.rst +12 -0
- inspice-1.5/examples/ngspice-shared/ngspice-interpreter.py +87 -0
- inspice-1.5/examples/operational-amplifier/OperationalAmplifier-api-brainstorming.py +57 -0
- inspice-1.5/examples/operational-amplifier/OperationalAmplifier.py +59 -0
- inspice-1.5/examples/operational-amplifier/astable.py +56 -0
- inspice-1.5/examples/operational-amplifier/operational-amplifier.py +50 -0
- inspice-1.5/examples/passive/capacitor-inductor.py +115 -0
- inspice-1.5/examples/power-supplies/HP54501A.py +28 -0
- inspice-1.5/examples/power-supplies/capacitive-half-wave-rectification-post-zener.py +75 -0
- inspice-1.5/examples/power-supplies/capacitive-half-wave-rectification-pre-zener.py +81 -0
- inspice-1.5/examples/power-supplies/hp54501a-cem.py +69 -0
- inspice-1.5/examples/power-supplies/rectification.py +153 -0
- inspice-1.5/examples/relay/relay.py +72 -0
- inspice-1.5/examples/resistor/resistor-bridge.py +31 -0
- inspice-1.5/examples/resistor/voltage-divider.py +36 -0
- inspice-1.5/examples/skywater/simple_nand.py +25 -0
- inspice-1.5/examples/spice-examples/ac-coupled-amplifier.cir +18 -0
- inspice-1.5/examples/spice-examples/ac-coupled-transistor-amplifier.cir +25 -0
- inspice-1.5/examples/spice-examples/astable.cir +33 -0
- inspice-1.5/examples/spice-examples/diode-ac.cir +11 -0
- inspice-1.5/examples/spice-examples/diode.cir +18 -0
- inspice-1.5/examples/spice-examples/low-pass-rc-filter.cir +12 -0
- inspice-1.5/examples/spice-examples/operational-amplifier-model-1.cir +31 -0
- inspice-1.5/examples/spice-examples/operational-amplifier-model-2.cir +56 -0
- inspice-1.5/examples/spice-examples/resistor-bridge.cir +15 -0
- inspice-1.5/examples/spice-examples/small-signal-amplifier-with-diodes.cir +26 -0
- inspice-1.5/examples/spice-examples/small-signal-amplifier.cir +16 -0
- inspice-1.5/examples/spice-examples/transform-less-power-supply.cir +48 -0
- inspice-1.5/examples/spice-examples/transistor.cir +14 -0
- inspice-1.5/examples/spice-examples/transistor2.cir +9 -0
- inspice-1.5/examples/spice-examples/voltage-divider.cir +7 -0
- inspice-1.5/examples/spice-parser/bootstrap-example.py +58 -0
- inspice-1.5/examples/spice-parser/index.rst +3 -0
- inspice-1.5/examples/spice-parser/kicad-example.py +151 -0
- inspice-1.5/examples/spice-parser/kicad-pyspice-example/kicad-pyspice-example.cir +17 -0
- inspice-1.5/examples/spice-parser/kicad-spice-example/netlist/kicad-spice-example.default.cir +28 -0
- inspice-1.5/examples/spice-parser/kicad-spice-example/netlist/kicad-spice-example.number-node.cir +28 -0
- inspice-1.5/examples/spice-parser/kicad-spice-example/netlist/kicad-spice-example.using-X.cir +28 -0
- inspice-1.5/examples/spice-parser/kicad-spice-example/spice/components.cir +31 -0
- inspice-1.5/examples/spice-parser/kicad-spice-example/spice/example.cir +25 -0
- inspice-1.5/examples/switched-power-supplies/buck-converter.py +118 -0
- inspice-1.5/examples/transformer/Transformer.py +54 -0
- inspice-1.5/examples/transformer/transformer-example.py +55 -0
- inspice-1.5/examples/transistor/ac-coupled-amplifier.py +67 -0
- inspice-1.5/examples/transistor/nmos-transistor.py +64 -0
- inspice-1.5/examples/transistor/transistor.py +146 -0
- inspice-1.5/examples/transmission-lines/time-delay.py +43 -0
- inspice-1.5/pyproject.toml +54 -0
- inspice-1.5/setup.cfg +4 -0
- inspice-1.5/setup.py +53 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
####################################################################################################
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
import sys
|
|
5
|
+
|
|
6
|
+
####################################################################################################
|
|
7
|
+
|
|
8
|
+
import InSpice.Tools.Path as PathTools # Fixme: why ?
|
|
9
|
+
|
|
10
|
+
####################################################################################################
|
|
11
|
+
|
|
12
|
+
class OsFactory:
|
|
13
|
+
|
|
14
|
+
##############################################
|
|
15
|
+
|
|
16
|
+
def __init__(self):
|
|
17
|
+
|
|
18
|
+
if sys.platform.startswith('linux'):
|
|
19
|
+
self._name = 'linux'
|
|
20
|
+
elif sys.platform.startswith('win'):
|
|
21
|
+
self._name = 'windows'
|
|
22
|
+
elif sys.platform.startswith('darwin'):
|
|
23
|
+
self._name = 'osx'
|
|
24
|
+
|
|
25
|
+
##############################################
|
|
26
|
+
|
|
27
|
+
@property
|
|
28
|
+
def name(self):
|
|
29
|
+
return self._name
|
|
30
|
+
|
|
31
|
+
@property
|
|
32
|
+
def on_linux(self):
|
|
33
|
+
return self._name == 'linux'
|
|
34
|
+
|
|
35
|
+
@property
|
|
36
|
+
def on_windows(self):
|
|
37
|
+
return self._name == 'windows'
|
|
38
|
+
|
|
39
|
+
@property
|
|
40
|
+
def on_osx(self):
|
|
41
|
+
return self._name == 'osx'
|
|
42
|
+
|
|
43
|
+
OS = OsFactory()
|
|
44
|
+
|
|
45
|
+
####################################################################################################
|
|
46
|
+
|
|
47
|
+
_this_file = PathTools.to_absolute_path(__file__)
|
|
48
|
+
|
|
49
|
+
class Path:
|
|
50
|
+
|
|
51
|
+
InSpice_module_directory = PathTools.parent_directory_of(_this_file, step=2)
|
|
52
|
+
config_directory = os.path.dirname(_this_file)
|
|
53
|
+
|
|
54
|
+
####################################################################################################
|
|
55
|
+
|
|
56
|
+
class Logging:
|
|
57
|
+
|
|
58
|
+
default_config_file = 'logging.yml'
|
|
59
|
+
directories = (Path.config_directory,)
|
|
60
|
+
|
|
61
|
+
##############################################
|
|
62
|
+
|
|
63
|
+
@staticmethod
|
|
64
|
+
def find(config_file):
|
|
65
|
+
return PathTools.find(config_file, Logging.directories)
|
|
File without changes
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
####################################################################################################
|
|
2
|
+
|
|
3
|
+
version: 1
|
|
4
|
+
|
|
5
|
+
####################################################################################################
|
|
6
|
+
|
|
7
|
+
formatters:
|
|
8
|
+
|
|
9
|
+
simple:
|
|
10
|
+
format: '%(asctime)s - %(name)s - %(module)s.%(levelname)s - %(message)s'
|
|
11
|
+
|
|
12
|
+
ansi:
|
|
13
|
+
# RESET_SEQ = "\033[0m"
|
|
14
|
+
# COLOR_SEQ = "\033[1;%dm"
|
|
15
|
+
# BOLD_SEQ = "\033[1m"
|
|
16
|
+
format: '<ESC>[1;32m%(asctime)s<ESC>[0m - <ESC>[1;34m%(name)s.%(funcName)s<ESC>[0m - <ESC>[1;31m%(levelname)s<ESC>[0m - %(message)s'
|
|
17
|
+
|
|
18
|
+
####################################################################################################
|
|
19
|
+
|
|
20
|
+
handlers:
|
|
21
|
+
|
|
22
|
+
console:
|
|
23
|
+
class: logging.StreamHandler
|
|
24
|
+
# level: INFO
|
|
25
|
+
# formatter: ansi
|
|
26
|
+
stream: ext://sys.stdout
|
|
27
|
+
|
|
28
|
+
####################################################################################################
|
|
29
|
+
|
|
30
|
+
root:
|
|
31
|
+
level: INFO
|
|
32
|
+
# level: WARNING
|
|
33
|
+
# level: DEBUG
|
|
34
|
+
handlers: [console]
|
|
35
|
+
|
|
36
|
+
####################################################################################################
|
|
37
|
+
|
|
38
|
+
# loggers:
|
|
39
|
+
|
|
40
|
+
# InSpice:
|
|
41
|
+
# level: DEBUG
|
|
42
|
+
# #level: INFO
|
|
43
|
+
# #level: WARNING
|
|
44
|
+
# handlers: [console]
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
####################################################################################################
|
|
2
|
+
#
|
|
3
|
+
# InSpice - A Spice Package for Python
|
|
4
|
+
# Copyright (C) 2017 Fabrice Salvaire
|
|
5
|
+
#
|
|
6
|
+
# This program is free software: you can redistribute it and/or modify
|
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
|
8
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
9
|
+
# (at your option) any later version.
|
|
10
|
+
#
|
|
11
|
+
# This program is distributed in the hope that it will be useful,
|
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
+
# GNU General Public License for more details.
|
|
15
|
+
#
|
|
16
|
+
# You should have received a copy of the GNU General Public License
|
|
17
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
18
|
+
#
|
|
19
|
+
####################################################################################################
|
|
20
|
+
|
|
21
|
+
####################################################################################################
|
|
22
|
+
|
|
23
|
+
class Manufacturer:
|
|
24
|
+
|
|
25
|
+
##############################################
|
|
26
|
+
|
|
27
|
+
def __init__(self,
|
|
28
|
+
name,
|
|
29
|
+
url=None,
|
|
30
|
+
):
|
|
31
|
+
|
|
32
|
+
self._name = name
|
|
33
|
+
self._url = url
|
|
34
|
+
|
|
35
|
+
##############################################
|
|
36
|
+
|
|
37
|
+
@property
|
|
38
|
+
def name(self):
|
|
39
|
+
return self._name
|
|
40
|
+
|
|
41
|
+
@name.setter
|
|
42
|
+
def name(self, value):
|
|
43
|
+
self._name = value
|
|
44
|
+
|
|
45
|
+
@property
|
|
46
|
+
def url(self):
|
|
47
|
+
return self._url
|
|
48
|
+
|
|
49
|
+
@url.setter
|
|
50
|
+
def url(self, value):
|
|
51
|
+
self._url = value
|
|
52
|
+
|
|
53
|
+
####################################################################################################
|
|
54
|
+
|
|
55
|
+
class Footprint:
|
|
56
|
+
|
|
57
|
+
##############################################
|
|
58
|
+
|
|
59
|
+
def __init__(self,
|
|
60
|
+
name,
|
|
61
|
+
):
|
|
62
|
+
|
|
63
|
+
self._name = name
|
|
64
|
+
|
|
65
|
+
##############################################
|
|
66
|
+
|
|
67
|
+
@property
|
|
68
|
+
def name(self):
|
|
69
|
+
return self._name
|
|
70
|
+
|
|
71
|
+
@name.setter
|
|
72
|
+
def name(self, value):
|
|
73
|
+
self._name = value
|
|
74
|
+
|
|
75
|
+
####################################################################################################
|
|
76
|
+
|
|
77
|
+
class Device:
|
|
78
|
+
|
|
79
|
+
##############################################
|
|
80
|
+
|
|
81
|
+
def __init__(self,
|
|
82
|
+
name,
|
|
83
|
+
manufacturer,
|
|
84
|
+
datasheet_url=None,
|
|
85
|
+
model_url=None
|
|
86
|
+
):
|
|
87
|
+
|
|
88
|
+
# part
|
|
89
|
+
# part_number
|
|
90
|
+
# footprint
|
|
91
|
+
# description
|
|
92
|
+
# device_category x/y
|
|
93
|
+
# pins
|
|
94
|
+
# features / parameters
|
|
95
|
+
|
|
96
|
+
self._name = name
|
|
97
|
+
|
|
98
|
+
##############################################
|
|
99
|
+
|
|
100
|
+
@property
|
|
101
|
+
def name(self):
|
|
102
|
+
return self._name
|
|
103
|
+
|
|
104
|
+
@name.setter
|
|
105
|
+
def name(self, value):
|
|
106
|
+
self._name = value
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
####################################################################################################
|
|
2
|
+
#
|
|
3
|
+
# InSpice - A Spice Package for Python
|
|
4
|
+
# Copyright (C) 2017 Fabrice Salvaire
|
|
5
|
+
#
|
|
6
|
+
# This program is free software: you can redistribute it and/or modify
|
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
|
8
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
9
|
+
# (at your option) any later version.
|
|
10
|
+
#
|
|
11
|
+
# This program is distributed in the hope that it will be useful,
|
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
+
# GNU General Public License for more details.
|
|
15
|
+
#
|
|
16
|
+
# You should have received a copy of the GNU General Public License
|
|
17
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
18
|
+
#
|
|
19
|
+
####################################################################################################
|
|
20
|
+
|
|
21
|
+
####################################################################################################
|
|
22
|
+
|
|
23
|
+
import logging
|
|
24
|
+
import os
|
|
25
|
+
import sys
|
|
26
|
+
|
|
27
|
+
from InSpice.Tools.Path import parent_directory_of
|
|
28
|
+
|
|
29
|
+
####################################################################################################
|
|
30
|
+
|
|
31
|
+
_module_logger = logging.getLogger(__name__)
|
|
32
|
+
|
|
33
|
+
####################################################################################################
|
|
34
|
+
|
|
35
|
+
def find_libraries():
|
|
36
|
+
|
|
37
|
+
try:
|
|
38
|
+
library_path = os.environ['InSpiceLibraryPath']
|
|
39
|
+
except KeyError:
|
|
40
|
+
# Fixme: only works for one level
|
|
41
|
+
python_file = os.path.abspath(sys.argv[0])
|
|
42
|
+
examples_root = parent_directory_of(python_file, step=2)
|
|
43
|
+
# .../InSpice/examples/diode/__example_rst_factory__nlrrr2fh.py .../InSpice/examples
|
|
44
|
+
library_path = os.path.join(examples_root, 'libraries')
|
|
45
|
+
|
|
46
|
+
_module_logger.info('SPICE library path is {}'.format(library_path))
|
|
47
|
+
|
|
48
|
+
return library_path
|
|
File without changes
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
####################################################################################################
|
|
2
|
+
#
|
|
3
|
+
# InSpice - A Spice Package for Python
|
|
4
|
+
# Copyright (C) 2014 Fabrice Salvaire
|
|
5
|
+
#
|
|
6
|
+
# This program is free software: you can redistribute it and/or modify
|
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
|
8
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
9
|
+
# (at your option) any later version.
|
|
10
|
+
#
|
|
11
|
+
# This program is distributed in the hope that it will be useful,
|
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
+
# GNU General Public License for more details.
|
|
15
|
+
#
|
|
16
|
+
# You should have received a copy of the GNU General Public License
|
|
17
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
18
|
+
#
|
|
19
|
+
####################################################################################################
|
|
20
|
+
|
|
21
|
+
####################################################################################################
|
|
22
|
+
|
|
23
|
+
import yaml
|
|
24
|
+
import logging
|
|
25
|
+
import logging.config
|
|
26
|
+
import os
|
|
27
|
+
|
|
28
|
+
####################################################################################################
|
|
29
|
+
|
|
30
|
+
import InSpice.Config.ConfigInstall as ConfigInstall
|
|
31
|
+
|
|
32
|
+
####################################################################################################
|
|
33
|
+
|
|
34
|
+
def setup_logging(application_name='InSpice',
|
|
35
|
+
config_file=ConfigInstall.Logging.default_config_file,
|
|
36
|
+
logging_level=None):
|
|
37
|
+
|
|
38
|
+
"""Setup the logging.
|
|
39
|
+
|
|
40
|
+
Logging configuration is set by a YAML file given by *config_file*. Alternatively we can set
|
|
41
|
+
the logging level using the environment variable 'InSpiceLogLevel' or using *logging_level*,
|
|
42
|
+
level can be a integer or a string
|
|
43
|
+
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
logging_config_file_name = ConfigInstall.Logging.find(config_file)
|
|
47
|
+
logging_config = yaml.load(open(logging_config_file_name, 'r'), Loader=yaml.SafeLoader)
|
|
48
|
+
|
|
49
|
+
if ConfigInstall.OS.on_linux:
|
|
50
|
+
# Fixme: \033 is not interpreted in YAML
|
|
51
|
+
formatter_config = logging_config['formatters']['ansi']['format']
|
|
52
|
+
logging_config['formatters']['ansi']['format'] = formatter_config.replace('<ESC>', '\033')
|
|
53
|
+
|
|
54
|
+
if ConfigInstall.OS.on_windows or ConfigInstall.OS.on_osx:
|
|
55
|
+
formatter = 'simple'
|
|
56
|
+
else:
|
|
57
|
+
formatter = 'ansi'
|
|
58
|
+
logging_config['handlers']['console']['formatter'] = formatter
|
|
59
|
+
|
|
60
|
+
logging.config.dictConfig(logging_config)
|
|
61
|
+
|
|
62
|
+
logger = logging.getLogger(application_name)
|
|
63
|
+
if logging_level:
|
|
64
|
+
logger.setLevel(logging_level)
|
|
65
|
+
if 'InSpiceLogLevel' in os.environ: # used by tools/make-examples
|
|
66
|
+
level = getattr(logging, os.environ['InSpiceLogLevel'].upper(), None)
|
|
67
|
+
logger.setLevel(level) # level can be int or string
|
|
68
|
+
|
|
69
|
+
return logger
|
|
File without changes
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
####################################################################################################
|
|
2
|
+
#
|
|
3
|
+
# InSpice - A Spice Package for Python
|
|
4
|
+
# Copyright (C) 2014 Fabrice Salvaire
|
|
5
|
+
#
|
|
6
|
+
# This program is free software: you can redistribute it and/or modify
|
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
|
8
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
9
|
+
# (at your option) any later version.
|
|
10
|
+
#
|
|
11
|
+
# This program is distributed in the hope that it will be useful,
|
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
+
# GNU General Public License for more details.
|
|
15
|
+
#
|
|
16
|
+
# You should have received a copy of the GNU General Public License
|
|
17
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
18
|
+
#
|
|
19
|
+
####################################################################################################
|
|
20
|
+
|
|
21
|
+
"""This module provides algorithms to compute the derivative of a function sampled on an uniform
|
|
22
|
+
grid.
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
####################################################################################################
|
|
26
|
+
|
|
27
|
+
import fractions
|
|
28
|
+
|
|
29
|
+
import numpy as np
|
|
30
|
+
|
|
31
|
+
####################################################################################################
|
|
32
|
+
|
|
33
|
+
from InSpice.Math import odd
|
|
34
|
+
|
|
35
|
+
####################################################################################################
|
|
36
|
+
|
|
37
|
+
def compute_exact_finite_difference_coefficients(derivative_order, grid, x0=0):
|
|
38
|
+
|
|
39
|
+
"""This function compute the finite difference coefficients for the given derivative order and
|
|
40
|
+
grid. The parameter *x* specifies where is computed the derivative on the grid. The grid is
|
|
41
|
+
given as a list of integer offsets.
|
|
42
|
+
|
|
43
|
+
The algorithm is derived from the article: Generation of Finite Difference Formulas on Arbitrary Space
|
|
44
|
+
Grids, Bengt Fornberg, Mathematics of computation, volume 51, number 184, october 1988
|
|
45
|
+
"""
|
|
46
|
+
|
|
47
|
+
N = len(grid)
|
|
48
|
+
|
|
49
|
+
# d[m,n,v]
|
|
50
|
+
d = [[[0
|
|
51
|
+
for v in range(N)]
|
|
52
|
+
for n in range(N)]
|
|
53
|
+
for m in range(derivative_order +1)]
|
|
54
|
+
|
|
55
|
+
d[0][0][0] = fractions.Fraction(1,1)
|
|
56
|
+
c1 = 1
|
|
57
|
+
for n in range(1, N):
|
|
58
|
+
c2 = 1
|
|
59
|
+
for v in range(n):
|
|
60
|
+
c3 = grid[n] - grid[v]
|
|
61
|
+
c2 *= c3
|
|
62
|
+
if n <= derivative_order:
|
|
63
|
+
d[n][n-1][v] = 0
|
|
64
|
+
for m in range(min(n, derivative_order) +1):
|
|
65
|
+
d[m][n][v] = ( (grid[n] - x0)*d[m][n-1][v] - m*d[m-1][n-1][v] ) / c3
|
|
66
|
+
for m in range(min(n, derivative_order) +1):
|
|
67
|
+
d[m][n][n] = fractions.Fraction(c1,c2)*( m*d[m-1][n-1][n-1] - (grid[n-1] - x0)*d[m][n-1][n-1] )
|
|
68
|
+
c1 = c2
|
|
69
|
+
|
|
70
|
+
return d[-1][-1]
|
|
71
|
+
|
|
72
|
+
####################################################################################################
|
|
73
|
+
|
|
74
|
+
def compute_finite_difference_coefficients(derivative_order, grid):
|
|
75
|
+
return [float(x) for x in compute_exact_finite_difference_coefficients(derivative_order, grid)]
|
|
76
|
+
|
|
77
|
+
####################################################################################################
|
|
78
|
+
|
|
79
|
+
_coefficient_cache = dict(centred={}, forward={}, backward={})
|
|
80
|
+
|
|
81
|
+
def get_finite_difference_coefficients(derivative_order, accuracy_order, grid_type):
|
|
82
|
+
|
|
83
|
+
if derivative_order < 1:
|
|
84
|
+
raise ValueError("Wrong derivative order")
|
|
85
|
+
|
|
86
|
+
if odd(accuracy_order) or accuracy_order < 2:
|
|
87
|
+
raise ValueError("Wrong accuracy order")
|
|
88
|
+
|
|
89
|
+
if grid_type == 'centred':
|
|
90
|
+
window_size = accuracy_order // 2
|
|
91
|
+
grid = list(range(-window_size, window_size +1))
|
|
92
|
+
elif grid_type == 'forward':
|
|
93
|
+
grid = list(range(derivative_order + accuracy_order))
|
|
94
|
+
elif grid_type == 'backward':
|
|
95
|
+
grid = list(range(-(derivative_order + accuracy_order) +1, 1))
|
|
96
|
+
grid = list(reversed(grid)) # Fixme: why ?
|
|
97
|
+
else:
|
|
98
|
+
raise ValueError("Wrong grid type")
|
|
99
|
+
|
|
100
|
+
key = '{}-{}'.format(derivative_order, accuracy_order)
|
|
101
|
+
coefficients = _coefficient_cache[grid_type].get(key, None)
|
|
102
|
+
if coefficients is None:
|
|
103
|
+
coefficients = compute_finite_difference_coefficients(derivative_order, grid)
|
|
104
|
+
_coefficient_cache[grid_type][key] = coefficients
|
|
105
|
+
|
|
106
|
+
return grid, coefficients
|
|
107
|
+
|
|
108
|
+
####################################################################################################
|
|
109
|
+
|
|
110
|
+
def simple_derivative(x, values):
|
|
111
|
+
""" Compute the derivative as a simple slope. """
|
|
112
|
+
return x[:-1], np.diff(values)/np.diff(x)
|
|
113
|
+
|
|
114
|
+
####################################################################################################
|
|
115
|
+
|
|
116
|
+
def derivative(x, values, derivative_order=1, accuracy_order=4):
|
|
117
|
+
|
|
118
|
+
"""Compute the derivative at the given derivative order and accuracy order. The precision of the
|
|
119
|
+
Taylor expansion is :math:`\mathcal{O}(dx^{accuracy})`.
|
|
120
|
+
"""
|
|
121
|
+
|
|
122
|
+
dx = np.diff(x)
|
|
123
|
+
# if not np.all(dx == dx[0]):
|
|
124
|
+
# raise ValueError("Sampling is not uniform")
|
|
125
|
+
dx = dx[0]
|
|
126
|
+
|
|
127
|
+
values_size, = values.shape
|
|
128
|
+
|
|
129
|
+
derivative = np.zeros(values_size, dtype=values.dtype)
|
|
130
|
+
|
|
131
|
+
grid, coefficients = get_finite_difference_coefficients(derivative_order, accuracy_order, 'centred')
|
|
132
|
+
window_size = grid[-1]
|
|
133
|
+
# print grid, coefficients
|
|
134
|
+
vector_size = values_size - 2*window_size
|
|
135
|
+
if not vector_size:
|
|
136
|
+
raise ValueError("The size of the value's array is not sufficient for the given accuracy order")
|
|
137
|
+
lower_index = window_size
|
|
138
|
+
upper_index = values_size - window_size
|
|
139
|
+
derivative_view = derivative[window_size:-window_size]
|
|
140
|
+
for offset, coefficient in zip(grid, coefficients):
|
|
141
|
+
if coefficient:
|
|
142
|
+
# print offset, lower_index + offset, upper_index + offset
|
|
143
|
+
derivative_view += values[lower_index + offset:upper_index + offset] * coefficient
|
|
144
|
+
|
|
145
|
+
grid, coefficients = get_finite_difference_coefficients(derivative_order, accuracy_order, 'forward')
|
|
146
|
+
# print grid, coefficients
|
|
147
|
+
grid_size = len(grid)
|
|
148
|
+
upper_index = window_size
|
|
149
|
+
derivative_view = derivative[:window_size]
|
|
150
|
+
for offset, coefficient in zip(grid, coefficients):
|
|
151
|
+
# print offset, offset, window_size+offset
|
|
152
|
+
derivative_view += values[offset:upper_index + offset] * coefficient
|
|
153
|
+
|
|
154
|
+
grid, coefficients = get_finite_difference_coefficients(derivative_order, accuracy_order, 'backward')
|
|
155
|
+
# print grid, coefficients
|
|
156
|
+
grid_size = len(grid)
|
|
157
|
+
lower_index = values_size - window_size
|
|
158
|
+
upper_index = values_size
|
|
159
|
+
derivative_view = derivative[-window_size:]
|
|
160
|
+
for offset, coefficient in zip(grid, coefficients):
|
|
161
|
+
# print offset, lower_index + offset, upper_index + offset
|
|
162
|
+
derivative_view += values[lower_index + offset:upper_index + offset] * coefficient
|
|
163
|
+
|
|
164
|
+
return derivative / dx**derivative_order
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
####################################################################################################
|
|
2
|
+
#
|
|
3
|
+
# InSpice - A Spice Package for Python
|
|
4
|
+
# Copyright (C) 2014 Fabrice Salvaire
|
|
5
|
+
#
|
|
6
|
+
# This program is free software: you can redistribute it and/or modify
|
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
|
8
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
9
|
+
# (at your option) any later version.
|
|
10
|
+
#
|
|
11
|
+
# This program is distributed in the hope that it will be useful,
|
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
+
# GNU General Public License for more details.
|
|
15
|
+
#
|
|
16
|
+
# You should have received a copy of the GNU General Public License
|
|
17
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
18
|
+
#
|
|
19
|
+
####################################################################################################
|
|
20
|
+
|
|
21
|
+
"""This module implements mathematical functions.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
####################################################################################################
|
|
25
|
+
|
|
26
|
+
import math
|
|
27
|
+
|
|
28
|
+
####################################################################################################
|
|
29
|
+
|
|
30
|
+
def odd(x):
|
|
31
|
+
"""Return True is *x* is odd"""
|
|
32
|
+
return x & 1
|
|
33
|
+
|
|
34
|
+
def even(x):
|
|
35
|
+
"""Return True is *x* is even"""
|
|
36
|
+
return not(odd(x))
|
|
37
|
+
|
|
38
|
+
####################################################################################################
|
|
39
|
+
|
|
40
|
+
def rms_to_amplitude(x):
|
|
41
|
+
"""Return :math:`x \sqrt{2}`"""
|
|
42
|
+
return x * math.sqrt(2)
|
|
43
|
+
|
|
44
|
+
def amplitude_to_rms(x):
|
|
45
|
+
"""Return :math:`x / \sqrt{2}`"""
|
|
46
|
+
return x / math.sqrt(2)
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
####################################################################################################
|
|
4
|
+
#
|
|
5
|
+
# InSpice - A Spice Package for Python
|
|
6
|
+
# Copyright (C) 2014 Fabrice Salvaire
|
|
7
|
+
#
|
|
8
|
+
# This program is free software: you can redistribute it and/or modify
|
|
9
|
+
# it under the terms of the GNU General Public License as published by
|
|
10
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
11
|
+
# (at your option) any later version.
|
|
12
|
+
#
|
|
13
|
+
# This program is distributed in the hope that it will be useful,
|
|
14
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16
|
+
# GNU General Public License for more details.
|
|
17
|
+
#
|
|
18
|
+
# You should have received a copy of the GNU General Public License
|
|
19
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
20
|
+
#
|
|
21
|
+
####################################################################################################
|
|
22
|
+
|
|
23
|
+
####################################################################################################
|
|
24
|
+
|
|
25
|
+
class Copper:
|
|
26
|
+
|
|
27
|
+
atomic_number = 29
|
|
28
|
+
|
|
29
|
+
atomic_mass = 63.546 * 1e-3 # kg
|
|
30
|
+
density = 8.96 * 1e3 # kg·m−3
|
|
31
|
+
thermal_conductivity = 401 # W·m−1·K−1
|
|
32
|
+
electrical_resistivity = 16.78 * 1e-9 # Ω·m @20 °C
|
|
33
|
+
electron_mobility = - 4.6 * 1e3 # m2·V−1·s−1
|
|
34
|
+
|
|
35
|
+
##############################################
|
|
36
|
+
|
|
37
|
+
def electrical_resistance_for_conductor(self, degree):
|
|
38
|
+
""" Used to compute conductor resistance. """
|
|
39
|
+
rho0 = 16e-3 # Ω·m·mm−2
|
|
40
|
+
return rho0 * (1 + .00393 * degree)
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
####################################################################################################
|
|
4
|
+
#
|
|
5
|
+
# InSpice - A Spice Package for Python
|
|
6
|
+
# Copyright (C) 2014 Fabrice Salvaire
|
|
7
|
+
#
|
|
8
|
+
# This program is free software: you can redistribute it and/or modify
|
|
9
|
+
# it under the terms of the GNU General Public License as published by
|
|
10
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
11
|
+
# (at your option) any later version.
|
|
12
|
+
#
|
|
13
|
+
# This program is distributed in the hope that it will be useful,
|
|
14
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16
|
+
# GNU General Public License for more details.
|
|
17
|
+
#
|
|
18
|
+
# You should have received a copy of the GNU General Public License
|
|
19
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
20
|
+
#
|
|
21
|
+
####################################################################################################
|
|
22
|
+
|
|
23
|
+
####################################################################################################
|
|
24
|
+
#
|
|
25
|
+
# Physical Constants from Particle Data Group 2013
|
|
26
|
+
# http://pdg.lbl.gov/2013/reviews/rpp2013-rev-phys-constants.pdf
|
|
27
|
+
#
|
|
28
|
+
####################################################################################################
|
|
29
|
+
|
|
30
|
+
####################################################################################################
|
|
31
|
+
|
|
32
|
+
pi = 3.141592653589793238 # π = 3.141 592 653 589 793 238
|
|
33
|
+
|
|
34
|
+
####################################################################################################
|
|
35
|
+
|
|
36
|
+
speed_of_light_in_vacuum = c = 299792458 # 299 792 458 m s−1
|
|
37
|
+
electron_charge_magnitude = e = q = 1.602176565e-19 # 1.602 176 565(35)×10−19 C = 4.803 204 50(11)×10−10 esu
|
|
38
|
+
|
|
39
|
+
permeability_of_free_space = mu0 = 4*pi*1e-7 # 4π × 10−7 N A−2 = 12.566 370 614 ... ×10−7 N A−2
|
|
40
|
+
permittivity_of_free_space = epsilon0 = 1./(mu0*c**2) # 8.854 187 817 ... ×10−12 F m −1
|
|
41
|
+
|
|
42
|
+
avogadro_constant = Na = 6.02214129e23 # 6.022 141 29(27)×1023 mol−1
|
|
43
|
+
boltzmann_constant = k = 1.3806488e-23 # 1.380 6488(13)×10−23 J K−1 = 8.617 3324(78)×10−5 eV K−1
|
|
44
|
+
|
|
45
|
+
# 1 eV = 1.602 176 565(35) × 10−19 J
|
|
46
|
+
# 1 eV/c2 = 1.782 661 845(39) × 10−36 kg
|
|
47
|
+
|
|
48
|
+
####################################################################################################
|
|
49
|
+
|
|
50
|
+
# 0 ◦C ≡ 273.15 K
|
|
51
|
+
def degree_to_kelvin(x):
|
|
52
|
+
return x + 273.15
|
|
53
|
+
def kelvin_to_degree(x):
|
|
54
|
+
return x - 273.15
|
|
55
|
+
|
|
56
|
+
def temperature(degree=None, kelvin=None):
|
|
57
|
+
if degree is not None:
|
|
58
|
+
return degree_to_kelvin(degree)
|
|
59
|
+
else:
|
|
60
|
+
return kelvin
|
|
61
|
+
|
|
62
|
+
# kT at 300 K = [38.681 731(35)]−1 eV
|
|
63
|
+
def kT(degree=None, kelvin=None):
|
|
64
|
+
return k*temperature(degree=degree, kelvin=kelvin)
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
####################################################################################################
|
|
2
|
+
#
|
|
3
|
+
# InSpice - A Spice Package for Python
|
|
4
|
+
# Copyright (C) 2014 Fabrice Salvaire
|
|
5
|
+
#
|
|
6
|
+
# This program is free software: you can redistribute it and/or modify
|
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
|
8
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
9
|
+
# (at your option) any later version.
|
|
10
|
+
#
|
|
11
|
+
# This program is distributed in the hope that it will be useful,
|
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
+
# GNU General Public License for more details.
|
|
15
|
+
#
|
|
16
|
+
# You should have received a copy of the GNU General Public License
|
|
17
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
18
|
+
#
|
|
19
|
+
####################################################################################################
|
|
20
|
+
|
|
21
|
+
####################################################################################################
|
|
22
|
+
#
|
|
23
|
+
# Notes: Drude model, Nernst-Einstein law
|
|
24
|
+
#
|
|
25
|
+
####################################################################################################
|
|
26
|
+
|
|
27
|
+
####################################################################################################
|
|
28
|
+
|
|
29
|
+
def conductor_resistance(resistivity, length, section):
|
|
30
|
+
return resistivity * length / section
|