1,847
edits
m (Rename "Octave-Forge" to "Octave Forge" (https://lists.gnu.org/archive/html/octave-maintainers/2018-08/msg00138.html).) |
|||
(9 intermediate revisions by 3 users not shown) | |||
Line 2: | Line 2: | ||
__TOC__ | __TOC__ | ||
== History and Motivation == | == History and Motivation == | ||
OCS was developed during the CoMSON (Coupled Multiscale Simulation and Optimization) project which involved several universities but also several industrial partners. | |||
Each of the industrial partners at the time was using its own circuit simulation software and each software had different file formats for circuit netlists. | |||
Given the purposes of the project and the composition of the consortium the main design objectives for OCS where | |||
* provide a format for "element evaluators" independent of time-stepping algorithms | |||
* provide a "hierarchical" data structure where elements could be composed themselves of lumped-element networks | |||
* allow coupling of lumped-element networks (0D) and 1D/2D/3D device models | |||
* use an intermediate/interchange file format so that none of the formats in use by the industrial partners would be favoured over the others | |||
* be written in an interpreted language for quick prototyping and easy maintainance | |||
* be Free Software | |||
== Problem Formulation == | == Problem Formulation == | ||
Line 40: | Line 54: | ||
\qquad | \qquad | ||
\begin{array}{l} | \begin{array}{l} | ||
{n} = 1, \, \ldots \, ,N | {n} = 1, \, \ldots \, ,N | ||
\end{array} | \end{array} | ||
</math> | </math> | ||
<math> | <math> | ||
B_{mi} \dot{{r}}_{m} + | |||
Q_{mi}\ \left( {e}, {r}_{m} \right) = 0 \qquad | |||
\begin{array}{l} | \begin{array}{l} | ||
{i} = 1, \, \ldots \, ,{I}_m \\ | {i} = 1, \, \ldots \, ,{I}_m \\ | ||
Line 59: | Line 73: | ||
A circuit is represented in OCS by a struct variable with the fields listed below | A circuit is represented in OCS by a struct variable with the fields listed below | ||
{{Code| | {{Code|OCS structure format |<syntaxhighlight lang="octave" style="font-size:13px"> | ||
cir_struct = | cir_struct = | ||
{ | { | ||
Line 172: | Line 186: | ||
{{Code|Model evaluator file for simple MOSFET models |<syntaxhighlight lang="octave" style="font-size:13px"> | {{Code|Model evaluator file for simple MOSFET models |<syntaxhighlight lang="octave" style="font-size:13px"> | ||
function [a, b, c] =... | function [a, b, c] =... | ||
func (string , | func (string , pvmatrix(i ,:) , extvar , intvar , t) | ||
</syntaxhighlight>}} | </syntaxhighlight>}} | ||
i.e. it should get as inputs: | i.e. it should get as inputs: | ||
Line 560: | Line 574: | ||
}} | }} | ||
=== A circuit with a linear VCVS === | |||
To parse an IFF format netlist of the VCVS circuit we can use the following command | |||
{{Code|Load the VCVS circuit structure parsing an IFF netlist |<syntaxhighlight lang="octave" style="font-size:13px"> | |||
outstruct = prs_iff ("vcvs"); | |||
</syntaxhighlight> | |||
}} | |||
The IFF netlist consists of the .cir file named "vcvs.cir" shown below | |||
{{Code|IFF netlist for the VCVS circuit (.cir file)|<syntaxhighlight lang="text" style="font-size:13px"> | |||
%0.1b1 | |||
% A Simple linear VCVS example | |||
% Input voltage sources | |||
Mvoltagesources sinwave 2 4 | |||
1 4 | |||
Ampl f delay shift | |||
1 1 0.0 0.0 | |||
1 0 | |||
END | |||
% VCVS | |||
Mvcvs LIN 4 1 | |||
1 1 | |||
Gain | |||
5.0 | |||
2 0 1 0 | |||
% Resistor | |||
Mresistors LIN 2 1 | |||
1 1 | |||
R | |||
1 | |||
1 2 | |||
END | |||
</syntaxhighlight> | |||
}} | |||
and of the .nms file named "and.nms shown below | |||
{{Code|IFF netlist for the VCVS circuit (.nms file)|<syntaxhighlight lang="text" style="font-size:13px"> | |||
% 0.1b1 | |||
1 V_controller | |||
2 V_controlled | |||
</syntaxhighlight> | |||
}} | |||
The implementation for the VCVS with linear gain is shown below | |||
{{Code|Model evaluator file for simple VCVS model |<syntaxhighlight lang="octave" style="font-size:13px"> | |||
function [a,b,c] = Mvcvs (string, parameters, parameternames, extvar, | |||
intvar, t) | |||
if isempty(intvar) | |||
intvar = 0; | |||
endif | |||
switch string | |||
##LCR part | |||
case "LIN" | |||
for ii=1:length(parameternames) | |||
eval([parameternames{ii} "=" num2str(parameters(ii)) ";"]) | |||
endfor | |||
j = intvar (1); | |||
Vin = extvar (3) - extvar (4); | |||
V = Vin * Gain; | |||
a = zeros (5); | |||
b = [0 0 0 0 1; | |||
0 0 0 0 -1; | |||
0 0 0 0 0; | |||
0 0 0 0 0; | |||
1 -1 -Gain Gain 0]; | |||
c = [0 0 0 0 0]; | |||
break | |||
otherwise | |||
error (["unknown section:" string]) | |||
endswitch | |||
endfunction | |||
</syntaxhighlight> | |||
}} | |||
[[File:VCVS_result.png|thumb| Result of the VCVS simulation]] | |||
To run a simulation with this circuit use the following commands: | |||
{{Code|Run a simple transient simulation with the VCVS circuit |<syntaxhighlight lang="octave" style="font-size:13px"> | |||
>> x = [0 0 0 0]'; | |||
>> t = linspace(0,1,50); | |||
>> [out, niter] = tst_backward_euler (outstruct, x, t, 1e-6, 100, pltvars, [0 1]); | |||
</syntaxhighlight> | |||
}} | |||
=== Creating a model for a memristor device === | === Creating a model for a memristor device === | ||
To demonstrate how to write a model evaluator file (SBN file), we | To demonstrate how to write a model evaluator file (SBN file), we | ||
will discuss the simplest memristor model shown in this paper by [[User:KaKiLa| KaKiLa]] et al. ( | will discuss the simplest memristor model shown in this paper by [[User:KaKiLa| KaKiLa]] et al. (Carbajal, J. P. et al.(2015). [http://www.mitpressjournals.org/doi/abs/10.1162/NECO_a_00694?journalCode=neco#.VgFNn9tSukp Memristor models for machine learning]. Neural Computation, 27(3). Learning; Materials Science. doi:10.1162/NECO_a_00694</ref> | ||
The device model is presented in the original paper as | The device model is presented in the original paper as | ||
Line 797: | Line 906: | ||
The results are shown in the figure to the right. | The results are shown in the figure to the right. | ||
[[Category:Octave Forge]] |