Mercurial > forge
changeset 6666:475a0870b649 octave-forge
Updated ocs to version 0.1.0
author | culpo |
---|---|
date | Tue, 09 Feb 2010 07:43:42 +0000 |
parents | 296c2bd7d204 |
children | 94452cb02314 |
files | extra/ocs/DESCRIPTION extra/ocs/INDEX extra/ocs/PKG_ADD extra/ocs/PKG_DEL extra/ocs/doc/Minductors.m extra/ocs/inst/ASM/ASMbuildsystem.m extra/ocs/inst/ASM/ASMinitsystem.m extra/ocs/inst/NLS/NLSnewtonraphson.m extra/ocs/inst/NLS/NLSstationary.m extra/ocs/inst/PRS/PRSIFFparse.m extra/ocs/inst/SBN/Mcapacitors.m extra/ocs/inst/SBN/Mcurrentsources.m extra/ocs/inst/SBN/Mdiode.m extra/ocs/inst/SBN/Minductors.m extra/ocs/inst/SBN/Mnmoscap.m extra/ocs/inst/SBN/Mnmosfet.m extra/ocs/inst/SBN/Mpdesympnjunct.m extra/ocs/inst/SBN/Mpmosfet.m extra/ocs/inst/SBN/Mresistors.m extra/ocs/inst/SBN/Mschichmanhodgesmosfet.m extra/ocs/inst/SBN/Mtdnmos.cir extra/ocs/inst/SBN/Mtdnmos.nms extra/ocs/inst/SBN/Mtdpmos.cir extra/ocs/inst/SBN/Mtdpmos.nms extra/ocs/inst/SBN/Mvoltagesources.m extra/ocs/inst/TST/TSTBWEFUNJAC0.m extra/ocs/inst/TST/TSTBWEFUNJAC1.m extra/ocs/inst/TST/TSTBWEFUNRES0.m extra/ocs/inst/TST/TSTBWEFUNRES1.m extra/ocs/inst/TST/TSTBWEFUNUP1.m extra/ocs/inst/TST/TSTDASPKFUNJAC.m extra/ocs/inst/TST/TSTDASPKFUNRES.m extra/ocs/inst/TST/TSTODEPKGFUNJAC.m extra/ocs/inst/TST/TSTODEPKGFUNMASS.m extra/ocs/inst/TST/TSTODEPKGFUNRES.m extra/ocs/inst/TST/TSTTHETAFUNJAC1.m extra/ocs/inst/TST/TSTTHETAFUNRES1.m extra/ocs/inst/TST/TSTbweuler.m extra/ocs/inst/TST/TSTbweulernr.m extra/ocs/inst/TST/TSTdaspk.m extra/ocs/inst/TST/TSTodepkg.m extra/ocs/inst/TST/TSTthetamethod.m extra/ocs/inst/UTL/UTLplotbyname.m extra/ocs/inst/UTL/UTLsbnserver.m extra/ocs/inst/asm/asm_build_system.m extra/ocs/inst/asm/asm_initialize_system.m extra/ocs/inst/nls/nls_newton_raphson.m extra/ocs/inst/nls/nls_stationary.m extra/ocs/inst/prs/prs_iff.m extra/ocs/inst/sbn/Mcapacitors.m extra/ocs/inst/sbn/Mcurrentsources.m extra/ocs/inst/sbn/Mdiode.m extra/ocs/inst/sbn/Minductors.m extra/ocs/inst/sbn/Mnmosfet.m extra/ocs/inst/sbn/Mpdesympnjunct.m extra/ocs/inst/sbn/Mpmosfet.m extra/ocs/inst/sbn/Mresistors.m extra/ocs/inst/sbn/Mshichmanhodgesmosfet.m extra/ocs/inst/sbn/Mtdnmos.cir extra/ocs/inst/sbn/Mtdnmos.nms extra/ocs/inst/sbn/Mtdpmos.cir extra/ocs/inst/sbn/Mtdpmos.nms extra/ocs/inst/sbn/Mvoltagesources.m extra/ocs/inst/tst/tst_backward_euler.m extra/ocs/inst/tst/tst_daspk.m extra/ocs/inst/tst/tst_odepkg.m extra/ocs/inst/tst/tst_theta_method.m extra/ocs/inst/utl/utl_plot_by_name.m extra/ocs/inst/utl/utl_sbn_server.m |
diffstat | 69 files changed, 3205 insertions(+), 3875 deletions(-) [+] |
line wrap: on
line diff
--- a/extra/ocs/DESCRIPTION Tue Feb 09 05:24:36 2010 +0000 +++ b/extra/ocs/DESCRIPTION Tue Feb 09 07:43:42 2010 +0000 @@ -1,5 +1,5 @@ Name: OCS -Version: 0.0.4 +Version: 0.1.0 Date: 2009-02-25 Author: Carlo de Falco, Culpo Massimiliano Maintainer: Culpo Massimiliano
--- a/extra/ocs/INDEX Tue Feb 09 05:24:36 2010 +0000 +++ b/extra/ocs/INDEX Tue Feb 09 07:43:42 2010 +0000 @@ -1,20 +1,20 @@ OCS >> Octave Circuit Simulator Matrix Assembly Functions - ASMinitsystem - ASMbuildsystem + asm_initialize_system + asm_build_system Netlist Parsing Functions - PRSIFFparse + prs_iff Time Stepping Functions - TSTbweuler - TSTdaspk - TSTthetamethod - TSTodepkg + tst_backward_euler + tst_daspk + tst_theta_method + tst_odepkg Non Linear Solvers - NLSstationary - NLSnewtonraphson -Miscellaneous Utility Functions - UTLplotbyname - UTLsbnserver + nls_stationary + nls_newton_raphson +UTiLity Functions + utl_plot_by_name + utl_sbn_server SuBNet Function Library Mcapacitors Mcurrentsources @@ -23,6 +23,6 @@ Mnmosfet Mpmosfet Mresistors - Mschichmanhodgesmosfet + Mshichmanhodgesmosfet Mvoltagesources
--- a/extra/ocs/PKG_ADD Tue Feb 09 05:24:36 2010 +0000 +++ b/extra/ocs/PKG_ADD Tue Feb 09 07:43:42 2010 +0000 @@ -1,8 +1,10 @@ -dirlist= {"UTL","ASM","TST","NLS","PRS","SBN"}; +dirlist = {"utl","asm","tst","nls","prs","sbn"}; +[basename,dir] = fileparts(fileparts (mfilename ("fullpath"))); + for ii=1:length(dirlist) - if (! exist (fullfile (fileparts (mfilename ("fullpath")), "inst"), "dir")) + if (! exist (fullfile (basename, "inst"), "dir")) ## Run this if the package is installed - addpath ( [ fileparts( mfilename("fullpath")) "/" dirlist{ii}]) + addpath ( [ basename "/" dirlist{ii}],"-end") else ## Run this if we are testing the package is installed without installation addpath ( [ fileparts( mfilename("fullpath")) "/inst/" dirlist{ii}])
--- a/extra/ocs/PKG_DEL Tue Feb 09 05:24:36 2010 +0000 +++ b/extra/ocs/PKG_DEL Tue Feb 09 07:43:42 2010 +0000 @@ -1,10 +1,12 @@ -dirlist= {"UTL","ASM","TST","NLS","PRS","SBN"}; +dirlist = {"utl","asm","tst","nls","prs","sbn"}; +[basename,dir] = fileparts(fileparts (mfilename ("fullpath"))); + for ii=1:length(dirlist) - if (! exist (fullfile (fileparts (mfilename ("fullpath")), "inst"), "dir")) + if (! exist (fullfile (basename, "inst"), "dir")) ## Run this if the package is installed - rmpath ( [ fileparts( mfilename("fullpath")) "/" dirlist{ii}]) + rmpath ( [ basename "/" dirlist{ii}]) else ## Run this if we are testing the package is installed without installation rmpath ( [ fileparts( mfilename("fullpath")) "/inst/" dirlist{ii}]) end -end +end \ No newline at end of file
--- a/extra/ocs/doc/Minductors.m Tue Feb 09 05:24:36 2010 +0000 +++ b/extra/ocs/doc/Minductors.m Tue Feb 09 07:43:42 2010 +0000 @@ -1,5 +1,5 @@ function [a,b,c] =... - Minductorstors(string,parameters,parameternames,extvar,intvar,t) + Minductors(string,parameters,parameternames,extvar,intvar,t) ## Minductors(string,parameters,parameternames,extvar,intvar,t)
--- a/extra/ocs/inst/ASM/ASMbuildsystem.m Tue Feb 09 05:24:36 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,102 +0,0 @@ -## Copyright (C) 2006,2007,2008 Carlo de Falco, Culpo Massimiliano -## -## This file is part of: -## OCS - A Circuit Simulator for Octave -## -## OCS is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation. -## -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program (see the file LICENSE); if not, -## see <http://www.gnu.org/licenses/>. -## -## author: Carlo de Falco <cdf _AT_ users.sourceforge.net> -## author: culpo@math.uni-wuppertal.de - -## -*- texinfo -*- -## @deftypefn{Function File} [@var{A}, @var{Jac}, @var{res} ] = @ -## ASMbuildsystem (@var{instruct}, @var{x}, @var{t}) -## -## Cycles through the circuit description structure @var{instruct} -## to build the system matrices @var{A}, @var{Jac}, @var{res} for -## the current step of the Newton method. -## -## @itemize @minus -## @item @var{x} is the current value of the state variables -## @item @var{t} is the current time point -## @end itemize -## -## see the @cite{IFF file format specifications} for details about -## the output matrices. -## -## @seealso{ASMinitsystem} -## -## @end deftypefn - -function [A,Jac,res] = ASMbuildsystem(instruct,x,t); - - n = instruct.totextvar+instruct.totintvar; - A = sparse(n,n); - Jac = sparse(n,n); - res = sparse(n,1); - - - ## NLC section - nblocks = length(instruct.NLC); - - for ibl = 1:nblocks - for iel = 1:instruct.NLC(ibl).nrows - - ## evaluate element - if instruct.NLC(ibl).nintvar(iel) - intvars = instruct.totextvar+instruct.NLC(ibl).osintvar(iel)+... - [1:instruct.NLC(ibl).nintvar(iel)]'; - else - intvars=[]; - endif - - il = instruct.NLC(ibl).vnmatrix(iel,:)'; - nzil = find(il!=0); - - y = zeros(size(il)); - y(nzil)=x(il(nzil)); - - z = x(intvars); - - [a,b,c] = feval(instruct.NLC(ibl).func,... - instruct.NLC(ibl).section,... - instruct.NLC(ibl).pvmatrix(iel,:),... - instruct.NLC(ibl).parnames,... - y,z,t); - - ## ASSEMBLE MATRICES - - ## global indexing - vars = [il(nzil);intvars]; - ## local indexing - lclvars = [nzil; instruct.NLC(ibl).nextvar + (1:length(intvars))' ]; - ## reshaping sparse stamps - a = a(lclvars,lclvars); - b = b(lclvars,lclvars); - c = reshape(c(lclvars),[],1); - - [na,ma,va] = find(a); - [nb,mb,vb] = find(b); - [nc,mc,vc] = find(c); - - ## stamping - A += sparse(vars(na),vars(ma),va,n,n); - Jac += sparse(vars(nb),vars(mb),vb,n,n); - res += sparse(vars(nc),1,vc,n,1); - - endfor - endfor - - -endfunction \ No newline at end of file
--- a/extra/ocs/inst/ASM/ASMinitsystem.m Tue Feb 09 05:24:36 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,169 +0,0 @@ -## Copyright (C) 2006,2007,2008 Carlo de Falco, Culpo Massimiliano -## -## This file is part of: -## OCS - A Circuit Simulator for Octave -## -## OCS is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation. -## -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program (see the file LICENSE); if not, -## see <http://www.gnu.org/licenses/>. -## -## author: Carlo de Falco <cdf _AT_ users.sourceforge.net> -## author: culpo@math.uni-wuppertal.de - -## -*- texinfo -*- -## -## @deftypefn{Function File} {[@var{A}, @var{B}, @var{C},@ -## @var{struct}] =} ASMinitsystem (@var{instruct}, @var{x}) -## -## Cycles through the circuit description structure @var{instruct} -## to build the system matrices @var{A}, @var{B}, @var{C} for -## the linear and time-invariant part of the system -## -## @itemize @minus -## @item @var{x} is the current value of the state variables -## @end itemize -## -## see the @cite{IFF file format specifications} for details about -## the output matrices. -## -## @seealso{ASMbuildsystem} -## -## @end deftypefn - -function [varargout] = ASMinitsystem(instruct,x); - - if (~isfield(instruct,"totintvar")) - ## Check number of internal variables - intvar = 0; - - ## NLC section - nblocks = length(instruct.NLC); - - for ibl = 1:nblocks - for iel = 1:instruct.NLC(ibl).nrows - - ## evaluate element - il = instruct.NLC(ibl).vnmatrix(iel,:)'; - nzil = find(il!=0); - - y = zeros(size(il)); - y(nzil)=x(il(nzil)); - - [a,b,c] = feval(instruct.NLC(ibl).func,... - instruct.NLC(ibl).section,... - instruct.NLC(ibl).pvmatrix(iel,:),... - instruct.NLC(ibl).parnames,... - y,[],0); - - instruct.NLC(ibl).nintvar(iel) = columns(a)-instruct.NLC(ibl).nextvar; - instruct.NLC(ibl).osintvar(iel) = intvar; - intvar += instruct.NLC(ibl).nintvar(iel); - - endfor - endfor - - - ## LCR section - nblocks = length(instruct.LCR); - - for ibl = 1:nblocks - for iel = 1:instruct.LCR(ibl).nrows - - ## evaluate element - il = instruct.LCR(ibl).vnmatrix(iel,:)'; - nzil = find(il!=0); - - y = zeros(size(il)); - y(nzil)=x(il(nzil)); - - - [a,b,c] = feval(instruct.LCR(ibl).func,... - instruct.LCR(ibl).section,... - instruct.LCR(ibl).pvmatrix(iel,:),... - instruct.LCR(ibl).parnames,... - y,[],0); - - instruct.LCR(ibl).nintvar(iel) = columns(a)-instruct.LCR(ibl).nextvar; - instruct.LCR(ibl).osintvar(iel) = intvar; - intvar += instruct.LCR(ibl).nintvar(iel); - - endfor - endfor - instruct.totintvar = intvar; - endif - - ## Build linear part of the system - n = instruct.totextvar+instruct.totintvar; - lx = length(x); - if lx < n - x(lx+1:n) = 0; - endif - A = spalloc(n,n,0); - - ## LCR section - B = spalloc(n,n,0); - C = spalloc(n,1,0); - - nblocks = length(instruct.LCR); - - for ibl = 1:nblocks - for iel = 1:instruct.LCR(ibl).nrows - - ## evaluate element - if instruct.LCR(ibl).nintvar(iel) - intvars = instruct.totextvar+instruct.LCR(ibl).osintvar(iel)+... - [1:instruct.LCR(ibl).nintvar(iel)]'; - else - intvars=[]; - endif - - il = instruct.LCR(ibl).vnmatrix(iel,:)'; - nzil = find(il!=0); - - y = zeros(size(il)); - y(nzil)=x(il(nzil)); - z = x(intvars); - - [a,b,c] = feval(instruct.LCR(ibl).func,... - instruct.LCR(ibl).section,... - instruct.LCR(ibl).pvmatrix(iel,:),... - instruct.LCR(ibl).parnames,... - y,z,0); - - ## ASSEMBLE MATRICES - - ## global indexing - vars = [il(nzil);intvars]; - ## local indexing - lclvars = [nzil; instruct.LCR(ibl).nextvar + (1:length(intvars))' ]; - ## reshaping sparse stamps - a = a(lclvars,lclvars); - b = b(lclvars,lclvars); - c = reshape(c(lclvars),[],1); - - [na,ma,va] = find(a); - [nb,mb,vb] = find(b); - [nc,mc,vc] = find(c); - - ## stamping - A += sparse(vars(na),vars(ma),va,n,n); - B += sparse(vars(nb),vars(mb),vb,n,n); - C += sparse(vars(nc),1,vc,n,1); - - endfor - endfor - - varargout{1}=A; - varargout{2}=B; - varargout{3}=C; - varargout{4}=instruct; -endfunction \ No newline at end of file
--- a/extra/ocs/inst/NLS/NLSnewtonraphson.m Tue Feb 09 05:24:36 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,102 +0,0 @@ -## Copyright (C) 2006,2007,2008 Carlo de Falco -## -## This file is part of: -## OCS - A Circuit Simulator for Octave -## -## OCS is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation. -## -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program (see the file LICENSE); if not, -## see <http://www.gnu.org/licenses/>. -## -## author: Carlo de Falco <cdf _AT_ users.sourceforge.net> - -## -*- texinfo -*- -## @deftypefn{Function File}{[@var{y},@var{numit},@var{resnrm}] =} @ -## NLSnewtonraphson @ -## (@var{y0}, @var{RES}, @var{JAC}, @var{tol}, @ -## @var{maxit},@var{verbosity}, @var{update}); -## -## Solves a non-linear system of equations using the Newton-Raphson -## method with damping. -## -## Input: -## @itemize @minus -## @item @var{y0}: initial guess -## @item @var{RES}: function handle to compute the residual -## @item @var{JAC} function handle to compute the jacobian -## @item @var{tol}: tolerance for convergence check -## @item @var{maxit}: maximum number of iterations -## @item @var{verbosity}: verbosity level -## @item @var{update}: update function to run at each timestep -## @end itemize -## -## Output: -## @itemize @minus -## @item @var{y}: initial guess -## @item @var{numit}: number of iterations performed -## @item @var{resnrm}: residual norm at each step -## @end itemize -## @seealso{NLSstationary, TSTbweuler, TSTdaspk} -## @end deftypefn - -function [y,ii,resnrm] = NLSnewtonraphson (y0,RES,JAC,tol,maxit,verbosity,update); - - if ~exist("verbosity") - verbosity = 0; - endif - - if ~exist("update") - update = @(x) ({}); - endif - - jjtot = 0; - y = y0; - - uptodate = update(y); - res_y = RES(y,uptodate{:}); - resnrm(1) = norm(res_y,inf); - - for ii=1:maxit - - jac_y = JAC(y,uptodate{:}); - ynew = jac_y\(-res_y+jac_y*y); - uptodate = update(ynew); - res_y = RES(ynew,uptodate{:}); - resnrm(ii+1) = norm(res_y,inf); - - jj=0; - while (resnrm(ii+1)>resnrm(ii))&(jj<10) - jj++; - damp=2^(-jj); - ynew = y*(1-damp)+ynew*damp; - uptodate = update(ynew); - res_y = RES(ynew,uptodate{:}); - resnrm(ii+1) = norm(res_y,inf); - endwhile - - jjtot+=jj; - y = ynew; - - if resnrm(ii+1)<tol - if (verbosity) - fprintf(1,"converged in %d newton iterations and ",ii); - fprintf(1,"%d damping iterations\n",jjtot); - endif - break - elseif ii==maxit - if(verbosity) - fprintf(1,"not converged, nrm=%g\n",resnrm(maxit)) - endif - break - endif - endfor - -endfunction \ No newline at end of file
--- a/extra/ocs/inst/NLS/NLSstationary.m Tue Feb 09 05:24:36 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,42 +0,0 @@ -## Copyright (C) 2006,2007,2008 Carlo de Falco -## -## This file is part of: -## OCS - A Circuit Simulator for Octave -## -## OCS is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation. -## -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program (see the file LICENSE); if not, -## see <http://www.gnu.org/licenses/>. -## -## author: Carlo de Falco <cdf _AT_ users.sourceforge.net> - -## -*- texinfo -*- -## @deftypefn{Function File} @var{out} = NLSstationary @ -## (@var{instruct},@var{x},@var{tol},@var{maxit},@var{dmp}) -## Computes a stationary state for the system described by -## @var{sysstruct}. -## -## Input: -## @itemize @minus -## @item @var{instruct}: system description structure -## @item @var{x}: initial guess -## @item @var{tol, maxit, dmp}: parameters to be passed to NLSnewtonraphson -## @end itemize -## @end deftypefn - -function out = NLSstationary(outstruct,x,tol,maxit,dmp) - - [A0,B,C,outstruct] = ASMinitsystem(outstruct,x,0); - JAC = @(x) TSTBWEFUNJAC0(outstruct,x,0,B); - RES = @(x) TSTBWEFUNRES0(outstruct,x,0,B,C); - [out,ii,resnrm] = NLSnewtonraphson(x, RES, JAC, tol, maxit); - -endfunction \ No newline at end of file
--- a/extra/ocs/inst/PRS/PRSIFFparse.m Tue Feb 09 05:24:36 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,247 +0,0 @@ -## Copyright (C) 2006,2007,2008 Carlo de Falco -## -## This file is part of: -## OCS - A Circuit Simulator for Octave -## -## OCS is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation. -## -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program (see the file LICENSE); if not, -## see <http://www.gnu.org/licenses/>. -## -## author: Carlo de Falco <cdf _AT_ users.sourceforge.net> - -## -*- texinfo -*- -## @deftypefn{Function File} @var{outstruct} = PRSIFFparse(@var{name}) -## Parses a netlist in IFF format and produces the system description -## structure @var{outstruct}. -## @var{name} is the basename of the CIR and NMS files to -## be parsed. -## -## See the @cite{IFF file format specifications} (distributed together -## with the OCS package) for more details on the file format -## -## The returned structure @var{outstruct} has the following fields: -## -## @example -## outstruct = -## @{ -## LCR: struct % the fields of LCR are shown below -## NLC: struct % NLC has the same fields as LCR -## namesn: matrix % numbers of vars named in .nms file -## namess: cell % the names corresponding to the vars above -## totextvar: scalar % the total number of external variables -## totintvar: scalar % the total number of internal variables -## @} -## -## outstruct.LCR = -## @{ -## struct array containing the fields: % array has one element per block -## -## func % name of the sbn file corresponding to each block -## section % string parameter to be passed to the sbn files -## nextvar % number of external variables for each element of the block -## vnmatrix % numbers of the external variables of each element -## nintvar % number of internal variables for each element of the block -## osintvar % number of the first internal variable -## npar % number of parameters -## nparnames% number of parameter names -## nrows % number of rows in the block -## parnames % list of parameter names -## pvmatrix % list of parameter values for each element -## -## @} -## @end example -## -## @end deftypefn - -function outstruct = PRSIFFparse(name) - - ## init - version ="0.1b1"; - outstruct = struct("NLC",[],... - "LCR",[],... - "totextvar",0); - - ## open cir file - filename = [name ".cir"]; - if isempty(file_in_path(".",filename)) - error([".cir file not found:" filename]); - endif - fid = fopen(filename,"r"); - - ## Check version - line = fgetl(fid); - - if line(1)~="%" - error(["missing version number in file " filename]); - endif - - if ~strcmp(version,sscanf(line(2:end),"%s")); - error(["conflicting version number in file " filename]); - endif - - ## NLC section - NLCcount = 0; - while ~strcmp(line,"END") - - ## skip comments - while line(1)=="%" - line = fgetl(fid); - endwhile - - if strcmp(line,"END") - break - else - NLCcount++; - endif - - ## parse block header - [outstruct]=parseNLCblockheader(fid,line,outstruct,NLCcount); - - ## parse block par-value matrix - [outstruct.NLC(NLCcount).pvmatrix]=... - fscanf(fid,"%g",[outstruct.NLC(NLCcount).npar,... - outstruct.NLC(NLCcount).nrows])'; - - ## parse block var-number matrix - [outstruct.NLC(NLCcount).vnmatrix]=... - fscanf(fid,"%g",[outstruct.NLC(NLCcount).nextvar,... - outstruct.NLC(NLCcount).nrows])'; - - outstruct.totextvar = max([max(outstruct.NLC(NLCcount).vnmatrix(:)) - outstruct.totextvar]); - - ## skip the newline char after the matrix - line = fgetl(fid); - - ## proceed to next line - line = fgetl(fid); - - endwhile - - ## LCR section - LCRcount = 0; - line = fgetl(fid); - - while (~strcmp(line,"END")) - - ## skip comments - while line(1)=="%" - line = fgetl(fid); - endwhile - - if strcmp(line,"END") - break - else - LCRcount++; - endif - - ## parse block header - [outstruct]=parseLCRblockheader(fid,line,outstruct,LCRcount); - - ## parse block par-value matrix - [outstruct.LCR(LCRcount).pvmatrix]=... - fscanf(fid,"%g",[outstruct.LCR(LCRcount).npar,... - outstruct.LCR(LCRcount).nrows])'; - - ## parse block var-number matrix - [outstruct.LCR(LCRcount).vnmatrix]=... - fscanf(fid,"%g",[outstruct.LCR(LCRcount).nextvar,... - outstruct.LCR(LCRcount).nrows])'; - - outstruct.totextvar = max([max(outstruct.LCR(LCRcount).vnmatrix(:)) - outstruct.totextvar]); - - ## skip the newline char after the matrix - line = fgetl(fid); - - ## proceed to next line - line = fgetl(fid); - - endwhile - - ## fclose cir file - fclose(fid); - - ## open nms file - filename = [name ".nms"]; - if isempty(file_in_path(".",filename)) - error([".nms file not found:" filename]); - endif - fid = fopen(filename,"r"); - - ## Check version - line = fgetl(fid); - - if line(1)~="%" - error(["missing version number in file " filename]); - endif - - if ~strcmp(version,sscanf(line(2:end),"%s")); - error(["conflicting version number in file " filename]); - endif - - ## Init - cnt = 1; - outstruct.namesn = []; - outstruct.namess = {}; - nnames = 0; - - while cnt - [nn,cnt] = fscanf(fid,"%d","C"); - [ns,cnt] = fscanf(fid,"%s","C"); - if cnt - outstruct.namesn(++nnames)=nn; - outstruct.namess{nnames}=ns; - endif - endwhile - - ## fclose nms file - fclose(fid); - -endfunction - - -############################################## -function [outstruct]=parseNLCblockheader(fid,line,outstruct,NLCcount); - - [func,section,nextvar,npar]=sscanf(line,"%s %s %g %g","C"); - outstruct.NLC(NLCcount).func = func; - outstruct.NLC(NLCcount).section = section; - outstruct.NLC(NLCcount).nextvar = nextvar; - outstruct.NLC(NLCcount).npar = npar; - [nrows,nparnames]=fscanf(fid,"%g %g","C"); - outstruct.NLC(NLCcount).nrows = nrows; - outstruct.NLC(NLCcount).nparnames = nparnames; - outstruct.NLC(NLCcount).parnames = {}; - for ii=1:nparnames - outstruct.NLC(NLCcount).parnames{ii}=fscanf(fid,"%s","C"); - endfor - -endfunction - -############################################## -function [outstruct]=parseLCRblockheader(fid,line,outstruct,LCRcount); - - [func,section,nextvar,npar]=sscanf(line,"%s %s %g %g","C"); - outstruct.LCR(LCRcount).func = func; - outstruct.LCR(LCRcount).section = section; - outstruct.LCR(LCRcount).nextvar = nextvar; - outstruct.LCR(LCRcount).npar = npar; - [nrows,nparnames]=fscanf(fid,"%g %g","C"); - outstruct.LCR(LCRcount).nrows = nrows; - outstruct.LCR(LCRcount).nparnames = nparnames; - outstruct.LCR(LCRcount).parnames = {}; - for ii=1:nparnames - outstruct.LCR(LCRcount).parnames{ii}=fscanf(fid,"%s","C"); - endfor - -endfunction
--- a/extra/ocs/inst/SBN/Mcapacitors.m Tue Feb 09 05:24:36 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,119 +0,0 @@ -## Copyright (C) 2006,2007,2008 Carlo de Falco -## -## This file is part of: -## OCS - A Circuit Simulator for Octave -## -## OCS is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation. -## -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program (see the file LICENSE); if not, -## see <http://www.gnu.org/licenses/>. -## -## author: Carlo de Falco <cdf _AT_ users.sourceforge.net> - -## -*- texinfo -*- -## -## @deftypefn{Function File} @ -## {[@var{a},@var{b},@var{c}]=}Mcapacitors@ -## (@var{string}, @var{parameters}, @var{parameternames}, @ -## @var{extvar},@var{intvar},@var{t}) -## -## SBN file implementing models for capacitors. -## -## @var{string} is used to select among models. Parameters are listed -## as inner items. Possible models are: -## -## @enumerate -## @item @var{string} = "LIN" (Linear Capacitor) -## @itemize @minus -## @item C -> capacitance value -## @end itemize -## @item @var{string} = "MULTICAP" (Multipole Capacitor) -## @itemize @minus -## @item C -> capacitance values -## @end itemize -## @item @var{string} = "PDE_NMOS" (Drift-Diffusion PDE NMOS capacitor) -## @itemize @minus -## @item tbulk -> bulk thickness -## @item tox -> oxide thickness -## @item Nnodes -> number of nodes of 1D grid -## @item Na -> bulk doping -## @item toll -> absolute tolerance -## @item maxit -> max iterations number -## @item Area -> device area -## @end itemize -## @end enumerate -## -## @seealso{ PRSiffparse, ASMinitsystem, ASMbuildsystem, the IFF file -## format specifications } -## @end deftypefn - -function [a,b,c] = Mcapacitors(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 - - a = [0 0 1; 0 0 -1; 0 0 0]; - b = [0 0 0;0 0 0;-C C 1]; - c = [0 0 0]'; - break - - case "MULTICAP" - - n = length(extvar); - C = reshape(parameters,n,n); - - a = [zeros(n) eye(n); zeros(n) zeros(n)]; - b = [zeros(n) zeros(n); -C eye(n)]; - c = [zeros(2*n,1)]'; - - break - - ##NLC part - case "PDE_NMOS" - - constants - - tbulk = 1.5e-6; - tox = 90e-9; - len = tbulk + tox; - Nnodes = 300; - Na=1e21; - toll = 1e-10; - maxit = 1000; - Area = 1e-12; - - for ii=1:length(parameternames) - eval([parameternames{ii} "=" num2str(parameters(ii)) ";"]) - endfor - - Vg = extvar(1) - extvar(2); - q = intvar(1); - - [Q,C]=Mnmoscap(tbulk,tox,Area,Vg,Na,Nnodes,toll,maxit); - - a = [0 0 1; 0 0 -1; 0 0 0]; - b = [0 0 0;0 0 0;C -C -1]; - c = [0 0 Q-q]'; - break - - otherwise - error (["unknown section:" string]) - endswitch - -endfunction \ No newline at end of file
--- a/extra/ocs/inst/SBN/Mcurrentsources.m Tue Feb 09 05:24:36 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,122 +0,0 @@ -## Copyright (C) 2006,2007,2008 Carlo de Falco, Culpo Massimiliano -## -## This file is part of: -## OCS - A Circuit Simulator for Octave -## -## OCS is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation. -## -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program (see the file LICENSE); if not, -## see <http://www.gnu.org/licenses/>. -## -## author: Carlo de Falco <cdf _AT_ users.sourceforge.net> -## author culpo@math.uni-wuppertal.de - -## -*- texinfo -*- -## -## @deftypefn{Function File} @ -## {[@var{a},@var{b},@var{c}]=}Mcurrentsources @ -## (@var{string}, @var{parameters}, @var{parameternames}, @ -## @var{extvar},@var{intvar},@var{t}) -## -## SBN file implementing models for current sources. -## -## @var{string} is used to select among models. Parameters are listed -## as inner items. Possible models are: -## -## @enumerate -## @item @var{string} = "DC" (Static indipendent current source) -## @itemize @minus -## @item I -> Current source value -## @end itemize -## @item @var{string} = "VCCS" (Voltage controlled current source) -## @itemize @minus -## @item K -> Control parameter -## @end itemize -## @item @var{string} = "sinwave" (Sinusoidal indipendent current -## source) -## @itemize @minus -## @item shift -> mean value of sinusoidal input -## @item Ampl -> amplitude of sinusoidal wave -## @item f -> frequency of sinusoidal wave -## @item delay -> delay of sinusoidal wave -## @end itemize -## @item @var{string} = "VCPS" (Voltage controlled power source) -## @itemize @minus -## @item K -> Control parameter -## @end itemize -## @end enumerate -## -## @seealso{ PRSiffparse, ASMinitsystem, ASMbuildsystem, the IFF file -## format specifications } -## @end deftypefn - -function [a,b,c] = Mcurrentsources (string,parameters,parameternames,extvar,intvar,t) - - switch string - ## LCR part - case "DC" - for ii=1:length(parameternames) - eval([parameternames{ii} "=" num2str(parameters(ii)) ";"]) - endfor - - a = zeros(2); - b = a; - c = [I -I]'; - break - - case "VCCS" - ## Voltage controlled current source - K = 1; - for ii=1:length(parameternames) - eval([parameternames{ii} "=" num2str(parameters(ii)) ";"]) - endfor - - a = zeros(4); - b = [0 0 K -K;\ - 0 0 -K K;\ - 0 0 0 0;\ - 0 0 0 0]; - c = zeros(4,1); - ## NLC part - case "sinwave" - for ii=1:length(parameternames) - eval([parameternames{ii} "=" num2str(parameters(ii)) ";"]) - endfor - - I = shift+Ampl * sin(2*pi*(t+delay)*f ); - a = zeros(2); - b = a; - c = [I -I]'; - break - - case "VCPS" - ## Voltage controlled power source - K = 1; - for ii=1:length(parameternames) - eval([parameternames{ii} "=" num2str(parameters(ii)) ";"]) - endfor - - dv = extvar(3) - extvar(4); - I = K*(dv^2); - dIdv = 2*K*dv; - - a = zeros(4); - b = [0 0 dIdv -dIdv;\ - 0 0 -dIdv dIdv;\ - 0 0 0 0;\ - 0 0 0 0]; - c = [I -I 0 0]; - - otherwise - error (["unknown section:" string]) - endswitch - -endfunction
--- a/extra/ocs/inst/SBN/Mdiode.m Tue Feb 09 05:24:36 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,110 +0,0 @@ -## Copyright (C) 2006,2007,2008 Massimiliano Culpo, Carlo de Falco -## -## This file is part of: -## OCS - A Circuit Simulator for Octave -## -## OCS is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation. -## -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program (see the file LICENSE); if not, -## see <http://www.gnu.org/licenses/>. -## -## author: culpo@math.uni-wuppertal.de, Carlo de Falco <cdf _AT_ users.sourceforge.net> - -## -*- texinfo -*- -## -## @deftypefn{Function File} @ -## {[@var{a},@var{b},@var{c}]=}Mdiode@ -## (@var{string}, @var{parameters}, @var{parameternames}, @ -## @var{extvar},@var{intvar},@var{t}) -## -## SBN file implementing models for diodes. -## -## @var{string} is used to select among models. Parameters are listed -## as inner items. Possible models are: -## -## @itemize @minus -## @item @var{string} = "simple" (Usual exponential diode model) -## @itemize @minus -## @item Is -> reverse current -## @item Vth -> thermal voltage -## @item Rpar -> parasitic resistance -## @end itemize -## @item @var{string} = "PDEsymmetric" (Drift-Diffusion PDE model) -## @itemize @minus -## @item len -> diode length -## @item Nnodes -> number of nodes of 1D grid -## @item Dope -> doping (abrupt and symmetric) -## @item toll -> absolute tolerance -## @item maxit -> max iterations number -## @item Area -> device area -## @end itemize -## @end itemize -## -## @seealso{ PRSiffparse, ASMinitsystem, ASMbuildsystem, the IFF file -## format specifications } -## @end deftypefn - -function [a,b,c] = Mdiode (string,parameters,parameternames,extvar,intvar,t) - - switch string - - case "simple" - Is = 1e-14; - Vth = 2.5e-2; - Rpar = 1e12; - for ii=1:length(parameternames) - eval([parameternames{ii} "=" num2str(parameters(ii)) ";"]) - endfor - - vp = extvar(1); - vm = extvar(2); - - I = Is*(exp((vp - vm)/Vth) -1 ) + (vp - vm)/Rpar; - geq = Is*exp((vp - vm)/Vth)/Vth + 1/Rpar; - - a = zeros(2); - b = [geq -geq; -geq geq]; - c = [I ; -I] ; - break - - case "PDEsymmetric" - - len = 1e-6; - Nnodes = 100; - Dope=1e23; - - toll = 1e-5; - maxit = 100; - ptoll = 1e-10; - pmaxit = 100; - - Area = 1e-10; - - for ii=1:length(parameternames) - eval([parameternames{ii} "=" num2str(parameters(ii)) ";"]) - endfor - - vp = extvar(1); - vm = extvar(2); - - [I,g] = Mpdesympnjunct (len,Dope,vp-vm,Area,Nnodes,toll,maxit,ptoll,pmaxit); - - a = zeros(2); - b = [g -g; -g g]; - c = [I ; -I] ; - - break - - otherwise - error(["unknown section:" string]) - endswitch - -endfunction
--- a/extra/ocs/inst/SBN/Minductors.m Tue Feb 09 05:24:36 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,76 +0,0 @@ -## Copyright (C) 2006,2007,2008 Carlo de Falco -## -## This file is part of: -## OCS - A Circuit Simulator for Octave -## -## OCS is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation. -## -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program (see the file LICENSE); if not, -## see <http://www.gnu.org/licenses/>. -## -## author: Carlo de Falco <cdf _AT_ users.sourceforge.net> - -## -*- texinfo -*- -## -## @deftypefn{Function File} @ -## {[@var{a},@var{b},@var{c}]=}Minductors @ -## (@var{string}, @var{parameters}, @var{parameternames}, @ -## @var{extvar},@var{intvar},@var{t}) -## -## SBN file implementing models for inductors. -## -## @var{string} is used to select among models. Parameters are listed -## as inner items. Possible models are: -## -## @enumerate -## @item @var{string} = "LIN" (Linear inductor model) -## @itemize @minus -## @item L -> inductance value -## @end itemize -## @end enumerate -## -## @seealso{ PRSiffparse, ASMinitsystem, ASMbuildsystem, the IFF file -## format specifications } -## @end deftypefn - -function [a,b,c] = Minductors (string,parameters,parameternames,extvar,intvar,t) - - if isempty(intvar) - intvar = [0 0]; - endif - - switch string - - case "LIN" - for ii=1:length(parameternames) - eval([parameternames{ii} "=" num2str(parameters(ii)) ";"]) - endfor - - phi = intvar(1); - jl = intvar(2); - - a = [0 0 0 0; - 0 0 0 0; - 0 0 1 0; - 0 0 0 0]; - - b = [0 0 0 1; - 0 0 0 -1; - -1 1 0 0; - 0 0 1 -L]; - - c = [0 0 0 0]'; - otherwise - error (["unknown section:" string]) - endswitch - -endfunction - \ No newline at end of file
--- a/extra/ocs/inst/SBN/Mnmoscap.m Tue Feb 09 05:24:36 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,89 +0,0 @@ -## Copyright (C) 2006,2007,2008 Carlo de Falco -## -## This file is part of: -## OCS - A Circuit Simulator for Octave -## -## OCS is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation. -## -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program (see the file LICENSE); if not, -## see <http://www.gnu.org/licenses/>. -## -## author: Carlo de Falco <cdf _AT_ users.sourceforge.net> - -## -*- texinfo -*- -## -## @deftypefn{Function File} @ -## {[@var{Q},@var{C}]=}Mnmoscap@ -## (@var{tbulk}, @var{tox}, @var{Area}, @ -## @var{Vg},@var{Na},@var{Nnodes},@var{toll},@var{maxit}) -## -## INTERNAL FUNCTION: -## -## NOT SUPPOSED TO BE CALLED DIRECTLY BY USERS -## @end deftypefn - -function [Q,C]=Mnmoscap(tbulk,tox,Area,Vg,Na,Nnodes,toll,maxit); - - constants - - Nelements = Nnodes - 1; - len = tox+tbulk; - x = linspace(0,len,Nnodes)'; - sinodes = find(x<=tbulk); - Nsinodes = length(sinodes); - NelementsSi = Nsinodes-1; - D = - Na* ones(Nsinodes,1); - pp = Na ; - p = pp* ones(Nsinodes,1); - n = (ni^2)./p; - Fn = 0*n; - Fp = 0*n; - - - V = -Phims + Vg * ones(Nnodes,1); - V(sinodes) = Fn + Vth*log(n/ni); - - ## Scaling - xs = len; - ns = norm(D,inf); - Din = D/ns; - Vs = Vth; - xin = x/xs; - nin = n/ns; - pin = p/ns; - Vin = V/Vs; - Fnin = (Fn - Vs * log(ni/ns))/Vs; - Fpin = (Fp + Vs * log(ni/ns))/Vs; - - l2 = (Vs*esio2)/(q*ns*xs^2)* ones(Nelements,1); - l2(1:NelementsSi) = (Vs*esi)/(q*ns*xs^2); - - ## Solution of Nonlinear Poisson equation - [V,nout,pout,res,niter] = DDGnlpoisson (xin,sinodes,Vin,nin,... - pin,Fnin,Fpin,Din,l2,... - toll,maxit,0); - - L = Ucomplap(xin,Nnodes,[],Nelements,l2); - C22 = L(end,end); - C12 = L(2:end-1,end); - C11 = L(2:end-1,2:end-1); - - drdv = zeros(Nnodes,1); drdv(sinodes) = nout + pout; - coeff = zeros(Nelements,1); coeff(1:NelementsSi) = 1; - M = Ucompmass(xin,Nnodes,[],[],drdv,coeff); - C = C22 - C12'*((C11+M(2:end-1,2:end-1))\C12); - Q =(C12'*V(2:end-1)+C22*V(end)); - - ## Descaling - C = Area*C*(q*ns*xs/Vs); - Q = Area*Q*(q*ns*xs); - -endfunction \ No newline at end of file
--- a/extra/ocs/inst/SBN/Mnmosfet.m Tue Feb 09 05:24:36 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,160 +0,0 @@ -## Copyright (C) 2006,2007,2008 Carlo de Falco -## -## This file is part of: -## OCS - A Circuit Simulator for Octave -## -## OCS is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation. -## -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program (see the file LICENSE); if not, -## see <http://www.gnu.org/licenses/>. -## -## author: Carlo de Falco <cdf _AT_ users.sourceforge.net> - -## -*- texinfo -*- -## -## @deftypefn{Function File} @ -## {[@var{a},@var{b},@var{c}]=}Mnmosfet@ -## (@var{string}, @var{parameters}, @var{parameternames}, @ -## @var{extvar},@var{intvar},@var{t}) -## -## SBN file implementing standard models for n-mosfets. -## -## @var{string} is used to select among models. Parameters are listed -## as inner items. Possible models are: -## -## @enumerate -## @item @var{string} = "simple" (Standard model for MOSFET) -## @itemize @minus -## @item rd -> parasitic resistance between drain and source -## @item k -> k parameter for usual mosfet model -## @item Vth -> threshold voltage -## @end itemize -## @item @var{string} = "lincap" (Adds RC parasitics) -## @itemize @minus -## @item rd -> parasitic resistance between drain and source -## @item k -> k parameter for usual mosfet model -## @item Vth -> threshold voltage -## @item Rs -> parasitic source resistance -## @item Rd -> parasitic drain resistance -## @item Cs -> gate-source capacitance -## @item Cd -> gate-drain capacitance -## @item Cb -> gate-bulk capacitance -## @end itemize -## @end enumerate -## -## @seealso{ PRSiffparse, ASMinitsystem, ASMbuildsystem, the IFF file -## format specifications } -## @end deftypefn - -function [a,b,c]=Mnmosfet(string,parameters,parameternames,extvar,intvar,t) - - switch string - case "simple" - - rd = 1e6; - k = 1e-5; - Vth = .5; - - for ii=1:length(parameternames) - eval([parameternames{ii} "=",... - num2str(parameters(ii)) " ;"]) - endfor - - vg = extvar(1); - vs = extvar(2); - vd = extvar(3); - vb = extvar(4); - - vgs = vg-vs; - vds = vd-vs; - - if (vgs < Vth) - - - gm = 0; - gd = 1/rd; - id = vds*gd; - - elseif ((vgs-Vth)>=(vds))&(vds>=0) - - id = k*((vgs-Vth)*vds-(vds^2)/2)+vds/rd; - gm = k*vds; - gd = k*(vgs-Vth-vds)+1/rd; - - elseif ((vgs-Vth)>=(vds))&(vds<0) - - gm = 0; - gd = 1/rd; - id = vds*gd; - - else # (i.e. if 0 <= vgs-vth <= vds) - - id = (k/(2))*(vgs-Vth)^2+vds/rd; - gm = (2*k/(2))*(vgs-Vth); - gd = 1/rd; - - endif - - a = zeros(4); - - b = [0 0 0 0; - -gm (gm+gd) -gd 0; - gm -(gm+gd) gd 0; - 0 0 0 0]; - - c = [0 -id id 0]'; - break; - - case "lincap" - - ## Default parameter values - if isempty(intvar) - intvar = zeros(5,1); - endif - Rs = 1e2; Rd = 1e2; Cs = 1e-15; - Cd = 1e-15; Cb = 1e-14; - rd = inf; k = 1e-3; Vth = .1; - - ## parameters given in input - for ii=1:length(parameternames) - eval([parameternames{ii} "=",... - num2str(parameters(ii)) " ;"]) - endfor - - - persistent tmpstruct - - if isempty(tmpstruct) - - mtdnmos = file_in_path(path,"Mtdnmos.cir"); - mtdnmos(end-3:end)=[]; - tmpstruct = PRSIFFparse(mtdnmos); - - endif - - - tmpstruct.NLC.pvmatrix = [k Vth rd]; - tmpstruct.LCR(1).pvmatrix = [Rs; Rd]; - tmpstruct.LCR(2).pvmatrix = [Cs; Cd; Cb]; - - [A0,B,C,tmpstruct] = ASMinitsystem(tmpstruct,[extvar;intvar]); - [A1,Jac,res] = ASMbuildsystem(tmpstruct,[extvar;intvar],t); - - a = A0+A1; - b = B+Jac; - c = res + B*[extvar;intvar] + C; - - break; - otherwise - error(["unknown option:" string]); - endswitch - -endfunction
--- a/extra/ocs/inst/SBN/Mpdesympnjunct.m Tue Feb 09 05:24:36 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,125 +0,0 @@ -## Copyright (C) 2006,2007,2008 Carlo de Falco -## -## This file is part of: -## OCS - A Circuit Simulator for Octave -## -## OCS is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation. -## -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program (see the file LICENSE); if not, -## see <http://www.gnu.org/licenses/>. -## -## author: Carlo de Falco <cdf _AT_ users.sourceforge.net> - -## -*- texinfo -*- -## -## @deftypefn{Function File} @ -## {[@var{j},@var{g}]=}Mpdesympnjunct@ -## (@var{len}, @var{Dope}, @var{va}, @ -## @var{Area}, @var{Nnodes}, @var{toll}, @var{maxit}, @var{ptoll}, @var{pmaxit}) -## -## INTERNAL FUNCTION: -## -## NOT SUPPOSED TO BE CALLED DIRECTLY BY USERS -## @end deftypefn - -function [j,g] = Mpdesympnjunct (len,Dope,va,Area,Nnodes,toll,maxit,ptoll,pmaxit) - - constants - - x = linspace(0,len,Nnodes)'; - xm = mean(x); - Nd=Dope; - Na=Dope; - nn = (Nd + sqrt(Nd^2+4*ni^2))/2; - pp = (Na + sqrt(Na^2+4*ni^2))/2; - xn = xm+len/10; - xp = xm-len/10; - D = Nd * (x>xm) - Na * (x<=xm); - - ## Scaling coefficients - xs = len; - ns = norm(D,inf); - Vs = Vth; - us = un; - Js = (Area*us*Vs*q*ns/xs); - xin = x/xs; - gs = Js/Vs; - - n = nn * (x>=xn) + (ni^2)/pp * (x<xn); - p = (ni^2)/nn * (x>xp) + pp * (x<=xp); - - Fn = va*(x<=xm); - Fp = Fn; - - V = (Fn - Vth * log(p/ni)); - - ## Scaling - idata.D = D/ns; - idata.un = un/us; - idata.up = up/us; - idata.tn = inf; - idata.tp = inf; - idata.l2 = (Vs*esi)/(q*ns*xs^2); - idata.nis = ni/ns; - idata.n = n/ns; - idata.p = p/ns; - idata.V = V/Vs; - idata.Fn = (Fn - Vs * log(ni/ns))/Vs; - idata.Fp = (Fp + Vs * log(ni/ns))/Vs; - - - ## Solution of DD system - ## Algorithm parameters - - sinodes = [1:length(x)]; - - [idata,it,res] = DDGgummelmap (xin,idata,toll,maxit/2,ptoll,pmaxit,0); - [odata,it,res] = DDNnewtonmap (xin,idata,toll,maxit/2,0); - - DV = diff(odata.V); - h = xin(2)-xin(1); - - Bp = Ubernoulli(DV,1); - Bm = Ubernoulli(DV,0); - - Jn = -odata.un * (odata.n(2:end).*Bp-odata.n(1:end-1).*Bm)/h; - Jp = odata.up * (odata.p(2:end).*Bm-odata.p(1:end-1).*Bp)/h; - - coeff = idata.un.*Umediaarmonica(odata.n); - L =- Ucomplap (xin,Nnodes,[],[],coeff); - Jn1 = L*odata.Fn; - fprintf(1,"jn1=%g\n",Jn1(1)) - fprintf(1,"jn=%g\n",Jn(1)) - - C11 = L(1,1); - C1I = L(1,2:end-1); - CII = L(2:end-1,2:end-1); - Gn = C11 - C1I*(CII\C1I'); - Gn = Gn - coeff(1)*(odata.Fn(2)-odata.Fn(1))/h - - coeff = idata.up.*Umediaarmonica(odata.p); - L =- Ucomplap (xin,Nnodes,[],[],coeff); - Jp1 = L*odata.Fp; - fprintf(1,"jp1=%g\n",Jp1(1)) - fprintf(1,"jp=%g\n",Jp(1)) - - C11 = L(1,1); - C1I = L(1,2:end-1); - CII = L(2:end-1,2:end-1); - Gp = C11 - C1I*(CII\C1I'); - Gp = Gp - coeff(1)*(odata.Fp(2)-odata.Fp(1))/h - - - ## Descaling - j= -(Jp(1)+Jn(1))*Js - g= gs*(Gn+Gp) - -endfunction \ No newline at end of file
--- a/extra/ocs/inst/SBN/Mpmosfet.m Tue Feb 09 05:24:36 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,152 +0,0 @@ -## Copyright (C) 2006,2007,2008 Carlo de Falco -## -## This file is part of: -## OCS - A Circuit Simulator for Octave -## -## OCS is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation. -## -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program (see the file LICENSE); if not, -## see <http://www.gnu.org/licenses/>. -## -## author: Carlo de Falco <cdf _AT_ users.sourceforge.net> - -## -*- texinfo -*- -## -## @deftypefn{Function File} @ -## {[@var{a},@var{b},@var{c}]=}Mpmosfet@ -## (@var{string}, @var{parameters}, @var{parameternames}, @ -## @var{extvar},@var{intvar},@var{t}) -## -## SBN file implementing standard models for p-mosfets. -## -## @var{string} is used to select among models. Parameters are listed -## as inner items. Possible models are: -## -## @enumerate -## @item @var{string} = "simple" (Standard model for MOSFET) -## @itemize @minus -## @item rd -> parasitic resistance between drain and source -## @item k -> k parameter for usual mosfet model -## @item Vth -> threshold voltage -## @end itemize -## @item @var{string} = "lincap" (Adds RC parasitics) -## @itemize @minus -## @item rd -> parasitic resistance between drain and source -## @item k -> k parameter for usual mosfet model -## @item Vth -> threshold voltage -## @item Rs -> parasitic source resistance -## @item Rd -> parasitic drain resistance -## @item Cs -> gate-source capacitance -## @item Cd -> gate-drain capacitance -## @item Cb -> gate-bulk capacitance -## @end itemize -## @end enumerate -## -## @seealso{ PRSiffparse, ASMinitsystem, ASMbuildsystem, the IFF file -## format specifications } -## @end deftypefn - -function [a,b,c]= Mpmosfet (string,parameters,parameternames,extvar,intvar,t) - - switch string - case "simple" - - rd = 1e6; - - for ii=1:length(parameternames) - eval([parameternames{ii} "=",... - num2str(parameters(ii)) " ;"]); - endfor - - vg = extvar(1); - vs = extvar(2); - vd = extvar(3); - vb = extvar(4); - - vgs = vg-vs; - vds = vd-vs; - - if (vgs > Vth) - - gm = 0; - gd = 1/rd; - id = vds*gd; - - elseif ((vgs-Vth)<=(vds))&(vds<=0) - - id = k*((vgs-Vth)*vds-(vds^2)/2)+vds/rd; - gm = k*vds; - gd = k*(vgs-Vth-vds)+1/rd; - - elseif ((vgs-Vth)<=(vds))&(vds>0) - - gm = 0; - gd = 1/rd; - id = vds*gd; - - else - - id = k*(vgs-Vth)^2/2+vds/rd; - gm = k*(vgs-Vth); - gd = 1/rd; - - endif - a = zeros(4); - - b = [0 0 0 0; - -gm (gm+gd) -gd 0; - gm -(gm+gd) gd 0; - 0 0 0 0 ]; - - c =[0 -id id 0]'; - break; - - case "lincap" - - ## Default parameter values - if isempty(intvar) - intvar = zeros(5,1); - endif - Rs = 1e2; Rd = 1e2; Cs = 1e-15; - Cd = 1e-15; Cb = 1e-12; - rd = inf; k = -1e-3; Vth = -.1; - - ## parameters given in input - - for ii=1:length(parameternames) - eval([parameternames{ii} "=",... - num2str(parameters(ii)) " ;"]) - endfor - - - mtdpmos = file_in_path(path,"Mtdpmos.cir"); - mtdpmos(end-3:end)=[]; - tmpstruct = PRSIFFparse(mtdpmos); - - - tmpstruct.NLC.pvmatrix = [k Vth rd]; - tmpstruct.LCR(1).pvmatrix = [Rs; Rd]; - tmpstruct.LCR(2).pvmatrix = [Cs; Cd; Cb]; - - [A0,B,C,tmpstruct] = ASMinitsystem(tmpstruct,[extvar;intvar]); - [A1,Jac,res] = ASMbuildsystem(tmpstruct,[extvar;intvar],t); - - a = A0+A1; - b = B+Jac; - c = res + B*[extvar;intvar] + C; - - break; - - otherwise - error(["unknown option:" string]); - endswitch - -endfunction
--- a/extra/ocs/inst/SBN/Mresistors.m Tue Feb 09 05:24:36 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,130 +0,0 @@ -## Copyright (C) 2006,2007,2008 Carlo de Falco, Culpo Massimiliano -## -## This file is part of: -## OCS - A Circuit Simulator for Octave -## -## OCS is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation. -## -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program (see the file LICENSE); if not, -## see <http://www.gnu.org/licenses/>. -## -## author: Carlo de Falco <cdf _AT_ users.sourceforge.net> -## author: culpo@math.uni-wuppertal.de - -## -*- texinfo -*- -## -## @deftypefn{Function File} @ -## {[@var{a},@var{b},@var{c}]=}Mresistors@ -## (@var{string}, @var{parameters}, @var{parameternames}, @ -## @var{extvar},@var{intvar},@var{t}) -## -## SBN file implementing models for resistors. -## -## @var{string} is used to select among models. Parameters are listed -## as inner items. Possible models are: -## -## @enumerate -## @item @var{string} = "LIN" (Linear resistor) -## @itemize @minus -## @item R -> resistance value -## @end itemize -## @item @var{string} = "THERMAL" (Linear resistor with termal pin) -## @itemize @minus -## @item R0 -> reference resistance value at temperature @code{TNOM} -## @item TC1 -> coefficient for first order Taylor expansion -## @item TC2 -> coefficient for second order Taylor expansion -## @item TNOM -> reference temperature -## @end itemize -## @item @var{string} = "THERMAL1D" (1D Thermal resistor) -## @itemize @minus -## @item L -> length of 1D domain -## @item N -> number of discretized elements -## @item cv -> PDE coefficient for dynamic part -## @item k -> PDE coefficient for diffusion part -## @end itemize -## @end enumerate -## -## @seealso{ PRSiffparse, ASMinitsystem, ASMbuildsystem, the IFF file -## format specifications } -## @end deftypefn - - -function [a,b,c] =Mresistors(string,parameters,parameternames,extvar,intvar,t) - - switch string - ## LCR part - case "LIN" - for ii=1:length(parameternames) - eval([parameternames{ii} "=" num2str(parameters(ii)) ";"]) - endfor - - vp = extvar(1); - vm = extvar(2); - - a = zeros(2); - b = [1 -1 ;-1 1]/R; - c = -[0; 0]; - - break - ##NLCpart - case "THERMAL" - - for ii=1:length(parameternames) - eval([parameternames{ii} "=" num2str(parameters(ii)) ";"]) - endfor - - v1 = extvar(1); - v2 = extvar(2); - T = extvar(3); - - RT = R0*(1 + TC1*(T-TNOM) + TC2*(T - TNOM)^2); - dRdT = R0*(TC1 + 2*TC2*(T-TNOM)); - - i1 = (v1-v2)/RT; - i2 = (v2-v1)/RT; - P = -(v1-v2)^2/RT; - - a = zeros(3); - b = [ 1/RT -1/RT (v2-v1)*dRdT/RT^2;... - -1/RT 1/RT (v1-v2)*dRdT/RT^2;... - -2*(v1-v2)/RT -2*(v2-v1)/RT (v1-v2)^2*dRdT/RT^2]; - c = [i1 i2 P]'; - - break; - - case "THERMAL1D" - - for ii=1:length(parameternames) - eval([parameternames{ii} "=" num2str(parameters(ii)) ";"]) - endfor - - h = L/N; - - A = (cv*S*h)*speye(N+1); - - B = spdiags([ -ones(N+1,1) 2*ones(N+1,1) -ones(N+1,1)],-1:1,N+1,N+1); - B(1 ,1) = 1; - B(N+1 ,N+1) = 1; - - ext=[1 N+1]; - int=[2:N]; - - a = [A(ext,ext), A(ext,int); A(int,ext), A(int,int)]; - b = k*(S/h)*[B(ext,ext), B(ext,int); B(int,ext), B(int,int)]; - c = zeros(N+1,1); - - break; - - otherwise - error (["unknown section:" string]) - endswitch - -endfunction
--- a/extra/ocs/inst/SBN/Mschichmanhodgesmosfet.m Tue Feb 09 05:24:36 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,623 +0,0 @@ -## Copyright (C) 2006,2007,2008 Carlo de Falco, Massimiliano Culpo -## -## This file is part of: -## OCS - A Circuit Simulator for Octave -## -## OCS is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation. -## -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program (see the file LICENSE); if not, -## see <http://www.gnu.org/licenses/>. -## -## author: Carlo de Falco <cdf _AT_ users.sourceforge.net>, culpo@math.uni-wuppertal.de - -## -*- texinfo -*- -## -## @deftypefn{Function File} @ -## {[@var{a},@var{b},@var{c}]=} Mschichmanhodgesmosfet@ -## (@var{string}, @var{parameters}, @var{parameternames}, @ -## @var{extvar},@var{intvar},@var{t}) -## -## SBN file implementing Schichman-Hodges MOSFETs model. -## -## @var{string} is used to select among models. Possible models are: -## -## @enumerate -## @item @var{string} = "NMOS" (Schichman-Hodges n-MOSFET) -## @item @var{string} = "PMOS" (Schichman-Hodges p-MOSFET) -## @item @var{string} = "NMOStpar" (n-MOSFET with temperature treated as a parameter) -## @item @var{string} = "PMOStpar" (p-MOSFET with temperature treated as a parameter) -## @item @var{string} = "NMOSnoP" (n-MOSFET without heat-flux) -## @item @var{string} = "PMOSnoP" (p-MOSFET without heat-flux) -## @end enumerate -## -## Parameters for all the above models are: -## @itemize -## @item rd -> parasitic resistance between drain and source -## @item W -> MOSFET width -## @item L -> channel length -## @item mu0 -> reference value for mobility -## @item Vth -> threshold voltage -## @item Cox -> oxide capacitance -## @item Cgs -> gate-source capacitance -## @item Cgd -> gate-drain capacitance -## @item Cgb -> gate-bulk capacitance -## @item Csb -> source-bulk capacitance -## @item Cdb -> drain-bulk capacitance -## @item Tshift -> shift for reference temperature on MOSFETs (default 0) -## @end itemize -## -## @seealso{ PRSiffparse, ASMinitsystem, ASMbuildsystem, the IFF file -## format specifications } -## @end deftypefn - -function [a,b,c]= Mschichmanhodgesmosfet (string,parameters,parameternames,extvar,intvar,t) - switch string - case "NMOS" - - rd = 1e6; - W = 1; - L = 1; - mu0 = 1e-5; - Vth = .5; - Cox = 1e-9; - Cgb = Cox; - Cgs=Cgd=Csb=Cdb=.1*Cox; - Tshift = 0; - - for ii=1:length(parameternames) - eval([parameternames{ii} "=",... - num2str(parameters(ii)) " ;"]) - endfor - - [gm,gd,ids,didT,P,dPdT,dPdvgs,dPdvds] = \ - nmos(extvar,mu0,Cox,W,L,Vth,rd,Tshift); - - vg = extvar(1); - vs = extvar(2); - vd = extvar(3); - vb = extvar(4); - T = max(extvar(5),0); - - if isempty(intvar) - intvar = zeros(5,1); - endif - - Qgb = intvar(1); - Qgs = intvar(2); - Qgd = intvar(3); - Qsb = intvar(4); - Qdb = intvar(5); - - a11 = a21 = a22 = zeros(5,5); - a12 = [ 1 1 1 0 0; \ - 0 -1 0 1 0; \ - 0 0 -1 0 1; \ - -1 0 0 -1 -1; \ - 0 0 0 0 0]; - - a = [a11 a12; a21 a22]; - - b11 = [0 0 0 0 0; \ - -gm (gm+gd) -gd 0 -didT; \ - gm -(gm+gd) gd 0 didT; \ - 0 0 0 0 0; \ - dPdvgs -(dPdvgs+dPdvds) dPdvds 0 dPdT]; - - b12 = zeros(5,5); - - b21 = [Cgb 0 0 -Cgb 0; \ - Cgs -Cgs 0 0 0; \ - Cgd 0 -Cgd 0 0; \ - 0 Csb 0 -Csb 0; \ - 0 0 Cdb -Cdb 0]; - b22 = -eye(5); - - b = [b11 b12; b21 b22]; - - - c1 = [0; -ids; ids; 0; P]; - - c2 = [Cgb*(vg - vb) - Qgb;\ - Cgs*(vg - vs) - Qgs;\ - Cgd*(vg - vd) - Qgd;\ - Csb*(vs - vb) - Qsb;\ - Cdb*(vd - vb) - Qdb]; - - c = [c1;c2]; - - - break; - - case "PMOS" - - rd = 1e6; - W = 1; - L = 1; - mu0 = 1e-5; - Vth = -.5; - Cox = 1e-9; - Cgb=Cox; - Cgs=Cgd=Csb=Cdb=.1*Cox; - Tshift = 0; - - for ii=1:length(parameternames) - eval([parameternames{ii} "=",... - num2str(parameters(ii)) " ;"]) - endfor - - [gm,gd,ids,didT,P,dPdT,dPdvgs,dPdvds] = \ - pmos(extvar,mu0,Cox,W,L,Vth,rd,Tshift); - - - vg = extvar(1); - vs = extvar(2); - vd = extvar(3); - vb = extvar(4); - T = extvar(5); - - if isempty(intvar) - intvar = zeros(5,1); - endif - - Qgb = intvar(1); - Qgs = intvar(2); - Qgd = intvar(3); - Qsb = intvar(4); - Qdb = intvar(5); - - a11 = a21 = a22 = zeros(5,5); - a12 = [ 1 1 1 0 0; \ - 0 -1 0 1 0; \ - 0 0 -1 0 1; \ - -1 0 0 -1 -1; \ - 0 0 0 0 0]; - - a = [a11 a12; a21 a22]; - - b11 = [0 0 0 0 0; \ - -gm (gm+gd) -gd 0 -didT; \ - gm -(gm+gd) gd 0 didT; \ - 0 0 0 0 0; \ - dPdvgs -(dPdvgs+dPdvds) dPdvds 0 dPdT]; - - b12 = zeros(5,5); - - b21 = [Cgb 0 0 -Cgb 0; \ - Cgs -Cgs 0 0 0; \ - Cgd 0 -Cgd 0 0; \ - 0 Csb 0 -Csb 0; \ - 0 0 Cdb -Cdb 0]; - - b22 = -eye(5); - - b = [b11 b12; b21 b22]; - - - c1 = [0; -ids; ids; 0; P]; - - c2 = [Cgb*(vg - vb) - Qgb;\ - Cgs*(vg - vs) - Qgs;\ - Cgd*(vg - vd) - Qgd;\ - Csb*(vs - vb) - Qsb;\ - Cdb*(vd - vb) - Qdb]; - - c = [c1;c2]; - - break; - - case "NMOStpar" - ## Nmos model with temperature treated as a parameter - rd = 1e6; - W = 1; - L = 1; - mu0 = 1e-5; - Vth = .5; - Cox = 1e-9; - Cgb = Cox; - Cgs=Cgd=Csb=Cdb=.1*Cox; - - for ii=1:length(parameternames) - eval([parameternames{ii} "=",... - num2str(parameters(ii)) " ;"]) - endfor - - [gm,gd,ids,didT,P,dPdT,dPdvgs,dPdvds] = \ - nmos(extvar,mu0,Cox,W,L,Vth,rd,Tshift); - - vg = extvar(1); - vs = extvar(2); - vd = extvar(3); - vb = extvar(4); - T = extvar(5); - - if isempty(intvar) - intvar = zeros(5,1); - endif - - Qgb = intvar(1); - Qgs = intvar(2); - Qgd = intvar(3); - Qsb = intvar(4); - Qdb = intvar(5); - - a11 = a21 = a22 = zeros(5,5); - a12 = [ 1 1 1 0 0; \ - 0 -1 0 1 0; \ - 0 0 -1 0 1; \ - -1 0 0 -1 -1; \ - 0 0 0 0 0]; - - a = [a11 a12; a21 a22]; - - b11 = [0 0 0 0 0; \ - -gm (gm+gd) -gd 0 0; \ - gm -(gm+gd) gd 0 0; \ - 0 0 0 0 0; \ - 0 0 0 0 0]; - - b12 = zeros(5,5); - - b21 = [Cgb 0 0 -Cgb 0; \ - Cgs -Cgs 0 0 0; \ - Cgd 0 -Cgd 0 0; \ - 0 Csb 0 -Csb 0; \ - 0 0 Cdb -Cdb 0]; - b22 = -eye(5); - - b = [b11 b12; b21 b22]; - - - c1 = [0; -ids; ids; 0; 0]; - - c2 = [Cgb*(vg - vb) - Qgb;\ - Cgs*(vg - vs) - Qgs;\ - Cgd*(vg - vd) - Qgd;\ - Csb*(vs - vb) - Qsb;\ - Cdb*(vd - vb) - Qdb]; - - c = [c1;c2]; - - break; - - case "PMOStpar" - ## Pmos model with temperature treated as a parameter - rd = 1e6; - W = 1; - L = 1; - mu0 = 1e-5; - Vth = -.5; - Cox = 1e-9; - Cgb = Cox; - Cgs=Cgd=Csb=Cdb=.1*Cox; - - for ii=1:length(parameternames) - eval([parameternames{ii} "=",... - num2str(parameters(ii)) " ;"]) - endfor - - [gm,gd,ids,didT,P,dPdT,dPdvgs,dPdvds] = \ - pmos(extvar,mu0,Cox,W,L,Vth,rd,Tshift); - - vg = extvar(1); - vs = extvar(2); - vd = extvar(3); - vb = extvar(4); - T = extvar(5); - - if isempty(intvar) - intvar = zeros(5,1); - endif - - Qgb = intvar(1); - Qgs = intvar(2); - Qgd = intvar(3); - Qsb = intvar(4); - Qdb = intvar(5); - - a11 = a21 = a22 = zeros(5,5); - a12 = [ 1 1 1 0 0; \ - 0 -1 0 1 0; \ - 0 0 -1 0 1; \ - -1 0 0 -1 -1; \ - 0 0 0 0 0]; - - a = [a11 a12; a21 a22]; - - b11 = [0 0 0 0 0; \ - -gm (gm+gd) -gd 0 -didT; \ - gm -(gm+gd) gd 0 didT; \ - 0 0 0 0 0; \ - 0 0 0 0 0]; - - b12 = zeros(5,5); - - b21 = [Cgb 0 0 -Cgb 0; \ - Cgs -Cgs 0 0 0; \ - Cgd 0 -Cgd 0 0; \ - 0 Csb 0 -Csb 0; \ - 0 0 Cdb -Cdb 0]; - - b22 = -eye(5); - - b = [b11 b12; b21 b22]; - - - c1 = [0; -ids; ids; 0; 0]; - - c2 = [Cgb*(vg - vb) - Qgb;\ - Cgs*(vg - vs) - Qgs;\ - Cgd*(vg - vd) - Qgd;\ - Csb*(vs - vb) - Qsb;\ - Cdb*(vd - vb) - Qdb]; - - c = [c1;c2]; - - break; - - case "NMOSnoP" - - rd = 1e6; - W = 1; - L = 1; - mu0 = 1e-5; - Vth = .5; - Cox = 1e-9; - Cgb=Cox; - Cgs=Cgd=Csb=Cdb=.1*Cox; - - for ii=1:length(parameternames) - eval([parameternames{ii} "=",... - num2str(parameters(ii)) " ;"]) - endfor - - [gm,gd,ids,didT,P,dPdT,dPdvgs,dPdvds] = \ - nmos(extvar,mu0,Cox,W,L,Vth,rd,Tshift); - - vg = extvar(1); - vs = extvar(2); - vd = extvar(3); - vb = extvar(4); - T = extvar(5); - - if isempty(intvar) - intvar = zeros(5,1); - endif - - Qgb = intvar(1); - Qgs = intvar(2); - Qgd = intvar(3); - Qsb = intvar(4); - Qdb = intvar(5); - - a11 = a21 = a22 = zeros(5,5); - a12 = [ 1 1 1 0 0; \ - 0 -1 0 1 0; \ - 0 0 -1 0 1; \ - -1 0 0 -1 -1; \ - 0 0 0 0 0]; - - a = [a11 a12; a21 a22]; - - b11 = [0 0 0 0 0; \ - -gm (gm+gd) -gd 0 -didT; \ - gm -(gm+gd) gd 0 didT; \ - 0 0 0 0 0; \ - 0 0 0 0 0]; - - b12 = zeros(5,5); - - b21 = [Cgb 0 0 -Cgb 0; \ - Cgs -Cgs 0 0 0; \ - Cgd 0 -Cgd 0 0; \ - 0 Csb 0 -Csb 0; \ - 0 0 Cdb -Cdb 0]; - b22 = -eye(5); - - b = [b11 b12; b21 b22]; - - - c1 = [0; -ids; ids; 0; 0]; - - c2 = [Cgb*(vg - vb) - Qgb;\ - Cgs*(vg - vs) - Qgs;\ - Cgd*(vg - vd) - Qgd;\ - Csb*(vs - vb) - Qsb;\ - Cdb*(vd - vb) - Qdb]; - - c = [c1;c2]; - - - break; - - case "PMOSnoP" - - rd = 1e6; - W = 1; - L = 1; - mu0 = 1e-5; - Vth = -.5; - Cox = 1e-9; - Cgb=Cox; - Cgs=Cgd=Csb=Cdb=.1*Cox; - - for ii=1:length(parameternames) - eval([parameternames{ii} "=",... - num2str(parameters(ii)) " ;"]) - endfor - - [gm,gd,ids,didT,P,dPdT,dPdvgs,dPdvds] = \ - pmos(extvar,mu0,Cox,W,L,Vth,rd,Tshift); - - vg = extvar(1); - vs = extvar(2); - vd = extvar(3); - vb = extvar(4); - T = extvar(5); - - if isempty(intvar) - intvar = zeros(5,1); - endif - - Qgb = intvar(1); - Qgs = intvar(2); - Qgd = intvar(3); - Qsb = intvar(4); - Qdb = intvar(5); - - a11 = a21 = a22 = zeros(5,5); - a12 = [ 1 1 1 0 0; \ - 0 -1 0 1 0; \ - 0 0 -1 0 1; \ - -1 0 0 -1 -1; \ - 0 0 0 0 0]; - - a = [a11 a12; a21 a22]; - - b11 = [0 0 0 0 0; \ - -gm (gm+gd) -gd 0 -didT; \ - gm -(gm+gd) gd 0 didT; \ - 0 0 0 0 0; \ - 0 0 0 0 0]; - - b12 = zeros(5,5); - - b21 = [Cgb 0 0 -Cgb 0; \ - Cgs -Cgs 0 0 0; \ - Cgd 0 -Cgd 0 0; \ - 0 Csb 0 -Csb 0; \ - 0 0 Cdb -Cdb 0]; - - b22 = -eye(5); - - b = [b11 b12; b21 b22]; - - - c1 = [0; -ids; ids; 0; 0]; - - c2 = [Cgb*(vg - vb) - Qgb;\ - Cgs*(vg - vs) - Qgs;\ - Cgd*(vg - vd) - Qgd;\ - Csb*(vs - vb) - Qsb;\ - Cdb*(vd - vb) - Qdb]; - - c = [c1;c2]; - - break; - - otherwise - error(["unknown option:" string]); - endswitch - -endfunction - -function [gm,gd,ids,didT,P,dPdT,dPdvgs,dPdvds] = nmos(extvar,mu0,Cox,W,L,Vth,rd,Tshift) - ##Computes values for nmos case - - vg = extvar(1); - vs = extvar(2); - vd = extvar(3); - vb = extvar(4); - T = max(extvar(5),0); - - k = mu0*Cox*((T + Tshift)/300)^(-3/2)*W/L; - dkdT = mu0*Cox*W*(-3/2)*((T + Tshift)/300)^(-5/2)*(1/300)/L; - - vgs = vg-vs; - vds = vd-vs; - - if (vgs < Vth) - - gm = 0; - gd = 1/rd; - ids = vds*gd; - didT= 0; - - elseif ((vgs-Vth)>=(vds))&(vds>=0) - - ids = k*((vgs-Vth)*vds-(vds^2)/2)+vds/rd; - gm = k*vds; - gd = k*(vgs-Vth-vds) + 1/rd; - didT= dkdT*((vgs-Vth)*vds-(vds^2)/2); - - elseif ((vgs-Vth)>=(vds))&(vds<0) - - gm = 0; - gd = 1/rd; - ids = vds*gd; - didT= 0; - - else # (i.e. if 0 <= vgs-vth <= vds) - - ids = (k/2)*(vgs-Vth)^2+vds/rd; - gm = k*(vgs-Vth); - gd = 1/rd; - didT= (dkdT/(2))*(vgs-Vth)^2; - - endif - - P = -ids * vds; - dPdT = -didT* vds; - dPdvgs = -(gm*vds); - dPdvds = -(gd*vds + ids); - -endfunction - -function [gm,gd,ids,didT,P,dPdT,dPdvgs,dPdvds] = pmos(extvar,mu0,Cox,W,L,Vth,rd,Tshift) - ##Computes values for pmos case - - vg = extvar(1); - vs = extvar(2); - vd = extvar(3); - vb = extvar(4); - T = extvar(5); - - k = - mu0 * Cox * ((T + Tshift)/300)^(-3/2) *W/L; - dkdT = - mu0 * Cox * W *(-3/2)*((T + Tshift)/300)^(-5/2)*(1/300)/L; - - vgs = vg-vs; - vds = vd-vs; - - if (vgs > Vth) - - gm = 0; - gd = 1/rd; - ids = vds*gd; - didT= 0; - - elseif ((vgs-Vth)<=(vds))&(vds<=0) - - ids = k*((vgs-Vth)*vds-(vds^2)/2)+vds/rd; - gm = k*vds; - gd = k*(vgs-Vth-vds)+1/rd; - didT= dkdT*((vgs-Vth)*vds-(vds^2)/2); - - elseif ((vgs-Vth)<=(vds))&(vds>0) - - gm = 0; - gd = 1/rd; - ids = vds*gd; - didT= 0; - - else - - ids = (k/2)*(vgs-Vth)^2+vds/rd; - gm = k*(vgs-Vth); - gd = 1/rd; - didT= (dkdT/(2))*(vgs-Vth)^2; - - endif - - P = -ids * vds; - dPdT = -didT* vds; - dPdvgs = -(gm*vds); - dPdvds = -(gd*vds + ids); - -endfunction \ No newline at end of file
--- a/extra/ocs/inst/SBN/Mtdnmos.cir Tue Feb 09 05:24:36 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,29 +0,0 @@ -% 0.1b1 -% A Simple MOSFET model -% including charge stores -% N-Mosfet -Mnmosfet simple 4 3 -1 3 -k Vth rd -1 1 1e30 -1 5 6 4 -END -% Resistors -Mresistors LIN 2 1 -2 1 -R -1 -1 -2 5 -3 6 -% Capacitors -Mcapacitors LIN 2 1 -3 1 -C -1 -1 -1 -1 5 -1 6 -1 4 -END
--- a/extra/ocs/inst/SBN/Mtdnmos.nms Tue Feb 09 05:24:36 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,10 +0,0 @@ -% 0.1b1 -1 Vg -2 Vs -3 Vd -4 Vb -5 Vsi -6 Vdi -7 Qs -8 Qd -9 Qb \ No newline at end of file
--- a/extra/ocs/inst/SBN/Mtdpmos.cir Tue Feb 09 05:24:36 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,29 +0,0 @@ -% 0.1b1 -% A Simple MOSFET model -% including charge stores -% N-Mosfet -Mpmosfet simple 4 3 -1 3 -k Vth rd -1 1 1e30 -1 5 6 4 -END -% Resistors -Mresistors LIN 2 1 -2 1 -R -1 -1 -2 5 -3 6 -% Capacitors -Mcapacitors LIN 2 1 -3 1 -C -1 -1 -1 -1 5 -1 6 -1 4 -END
--- a/extra/ocs/inst/SBN/Mtdpmos.nms Tue Feb 09 05:24:36 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,10 +0,0 @@ -% 0.1b1 -1 Vg -2 Vs -3 Vd -4 Vb -5 Vsi -6 Vdi -7 Qs -8 Qd -9 Qb \ No newline at end of file
--- a/extra/ocs/inst/SBN/Mvoltagesources.m Tue Feb 09 05:24:36 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,182 +0,0 @@ -## Copyright (C) 2006,2007,2008 Carlo de Falco -## -## This file is part of: -## OCS - A Circuit Simulator for Octave -## -## OCS is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation. -## -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program (see the file LICENSE); if not, -## see <http://www.gnu.org/licenses/>. -## -## author: Carlo de Falco <cdf _AT_ users.sourceforge.net> - -## -*- texinfo -*- -## -## @deftypefn{Function File} @ -## {[@var{a},@var{b},@var{c}]=}Mvoltagesources @ -## (@var{string}, @var{parameters}, @var{parameternames}, @ -## @var{extvar},@var{intvar},@var{t}) -## -## SBN file implementing models for voltage sources. -## -## @var{string} is used to select among models. Parameters are listed -## as inner items. Possible models are: -## -## @enumerate -## @item @var{string} = "DC" (Static indipendent voltage source) -## @itemize @minus -## @item V -> Current source value -## @end itemize -## @item @var{string} = "sinwave" (Sinusoidal indipendent voltage -## source) -## @itemize @minus -## @item shift -> mean value of sinusoidal input -## @item Ampl -> amplitude of sinusoidal wave -## @item f -> frequency of sinusoidal wave -## @item delay -> delay of sinusoidal wave -## @end itemize -## @item @var{string} = "pwl" (Piecewise linear voltage source) -## @itemize @minus -## @item takes as parameter times and values. For example @code{0 1 4 6} -## means at time instant 0 value 1, at time instant 4 value 6, etc. -## @end itemize -## @item @var{string} = "squarewave" (Square wave) -## @itemize @minus -## @item low -> low-state value -## @item high -> high-state value -## @item tlow -> duration of low-state -## @item thigh -> duration of high-state -## @item delay -> delay of square wave -## @item start -> starting voltage value -## @end itemize -## @item @var{string} = "step" (Voltage step) -## @itemize @minus -## @item low -> low-state value -## @item high -> high-state value -## @item tstep -> time instant of step transition -## @end itemize -## @item @var{string} = "VCVS" (Voltage controlled voltage source) -## @itemize @minus -## @item K -> Control parameter -## @end itemize -## @end enumerate -## -## @seealso{ PRSiffparse, ASMinitsystem, ASMbuildsystem, the IFF file -## format specifications } -## @end deftypefn - -function [a,b,c] = Mvoltagesources (string,parameters,parameternames,extvar,intvar,t) - - if isempty(intvar) - intvar = 0; - endif - - switch string - ##LCR part - case "DC" - for ii=1:length(parameternames) - eval([parameternames{ii} "=" num2str(parameters(ii)) ";"]) - endfor - - j = intvar(1); - - a = zeros(3); - b = [0 0 1;0 0 -1;1 -1 0]; - c = [0 0 -V]; - break - ## NLC part - case "sinwave" - for ii=1:length(parameternames) - eval([parameternames{ii} "=" num2str(parameters(ii)) ";"]) - endfor - - DV = shift+Ampl * sin(2*pi*(t+delay)*f ); - j = intvar(1); - - a = zeros(3); - b = [0 0 1;0 0 -1;1 -1 0]; - c = [0 0 -DV]' + b * [extvar;intvar]; - break - - case "pwl" - - times = parameters(1:2:end-1); - values= parameters(2:2:end); - - DV = interp1(times,values,t,"linear","extrap"); - j = intvar(1); - - a = zeros(3); - b = [0 0 1;0 0 -1;1 -1 0]; - c = [0 0 -DV]' + b * [extvar;intvar]; - break - - case "squarewave" - for ii=1:length(parameternames) - eval([parameternames{ii} "=" num2str(parameters(ii)) ";"]) - endfor - if t<delay - if exist("start") - DV=start; - else - DV=low; - endif - else - T = tlow+thigh; - t = mod(t-delay,T); - if t<tlow - DV = low; - else - DV = high; - endif - endif - j = intvar(1); - - a = zeros(3); - b = [0 0 1;0 0 -1;1 -1 0]; - c = [0 0 -DV]' + b * [extvar;intvar]; - break - - case "step" - for ii=1:length(parameternames) - eval([parameternames{ii} "=" num2str(parameters(ii)) ";"]) - endfor - - if t<tstep - DV=low; - else - DV = high; - endif - - j = intvar(1); - - a = zeros(3); - b = [0 0 1;0 0 -1;1 -1 0]; - c = [0 0 -DV]' + b * [extvar;intvar]; - break - - case "VCVS" - K = 1; - for ii=1:length(parameternames) - eval([parameternames{ii} "=" num2str(parameters(ii)) ";"]) - endfor - - j = intvar(1); - - 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 -K K 0]; - c = zeros(5,1); - break - otherwise - error (["unknown section:" string]) - endswitch - -endfunction
--- a/extra/ocs/inst/TST/TSTBWEFUNJAC0.m Tue Feb 09 05:24:36 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,37 +0,0 @@ -## Copyright (C) 2006,2007,2008 Carlo de Falco -## -## This file is part of: -## OCS - A Circuit Simulator for Octave -## -## OCS is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation. -## -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program (see the file LICENSE); if not, -## see <http://www.gnu.org/licenses/>. -## -## author: Carlo de Falco <cdf _AT_ users.sourceforge.net> - -## -*- texinfo -*- -## -## @deftypefn{Function File} @ -## {[@var{lhs}]=} TSTBWEFUNJAC0@ -## (@var{outstruct}, @var{x}, @var{t}, @var{B}) -## -## INTERNAL FUNCTION: -## -## NOT SUPPOSED TO BE CALLED DIRECTLY BY USERS -## @end deftypefn - -function lhs = TSTBWEFUNJAC0(outstruct,x,t,B) - - [A1,Jac,res] = ASMbuildsystem(outstruct,x,t); - lhs = ( B + Jac); - -endfunction \ No newline at end of file
--- a/extra/ocs/inst/TST/TSTBWEFUNJAC1.m Tue Feb 09 05:24:36 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,41 +0,0 @@ -## Copyright (C) 2006,2007,2008 Carlo de Falco -## -## This file is part of: -## OCS - A Circuit Simulator for Octave -## -## OCS is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation. -## -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program (see the file LICENSE); if not, -## see <http://www.gnu.org/licenses/>. -## -## author: Carlo de Falco <cdf _AT_ users.sourceforge.net> - -## -*- texinfo -*- -## -## @deftypefn{Function File} @ -## {[@var{lhs}]=} TSTBWEFUNJAC1@ -## (@var{outstruct}, @var{x}, @var{t0}, @var{t1}, @var{A0}, @var{B}, -## @var{A1}, @var{Jac}, @var{res}) -## -## INTERNAL FUNCTION: -## -## NOT SUPPOSED TO BE CALLED DIRECTLY BY USERS -## @end deftypefn - -function lhs = TSTBWEFUNJAC1(outstruct,x,t0,t1,A0,B,A1,Jac,res) - - DT = t1-t0; - if ( nargin < 9 ) - [A1,Jac,res] = ASMbuildsystem(outstruct,x,t1); - endif - lhs = ( (A0+A1)/DT + B + Jac); - -endfunction \ No newline at end of file
--- a/extra/ocs/inst/TST/TSTBWEFUNRES0.m Tue Feb 09 05:24:36 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,37 +0,0 @@ -## Copyright (C) 2006,2007,2008 Carlo de Falco -## -## This file is part of: -## OCS - A Circuit Simulator for Octave -## -## OCS is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation. -## -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program (see the file LICENSE); if not, -## see <http://www.gnu.org/licenses/>. -## -## author: Carlo de Falco <cdf _AT_ users.sourceforge.net> - -## -*- texinfo -*- -## -## @deftypefn{Function File} @ -## {[@var{rhs}]=} TSTBWEFUNRES0@ -## (@var{outstruct}, @var{x}, @var{t}, @var{B}, @var{C}) -## -## INTERNAL FUNCTION: -## -## NOT SUPPOSED TO BE CALLED DIRECTLY BY USERS -## @end deftypefn - -function rhs = TSTBWEFUNRES0(outstruct,x,t,B,C) - - [A1,Jac,res] = ASMbuildsystem(outstruct,x,t); - rhs = (res + C + B*x); - -endfunction
--- a/extra/ocs/inst/TST/TSTBWEFUNRES1.m Tue Feb 09 05:24:36 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,41 +0,0 @@ -## Copyright (C) 2006,2007,2008 Carlo de Falco -## -## This file is part of: -## OCS - A Circuit Simulator for Octave -## -## OCS is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation. -## -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program (see the file LICENSE); if not, -## see <http://www.gnu.org/licenses/>. -## -## author: Carlo de Falco <cdf _AT_ users.sourceforge.net> - -## -*- texinfo -*- -## -## @deftypefn{Function File} @ -## {[@var{rhs}]=} TSTBWEFUNRES1@ -## (@var{outstruct}, @var{x}, @var{xold}, @var{t0}, @var{t1}, @var{A0}, -## @var{B}, @var{C}, @var{A1}, @var{Jac}, @var{res}) -## -## INTERNAL FUNCTION: -## -## NOT SUPPOSED TO BE CALLED DIRECTLY BY USERS -## @end deftypefn - -function rhs = TSTBWEFUNRES1(outstruct,x,xold,t0,t1,A0,B,C,A1,Jac,res) - - DT = t1-t0; - if ( nargin < 11 ) - [A1,Jac,res] = ASMbuildsystem(outstruct,x,t1); - endif - rhs = (res + C + B*x + (A0+A1)*(x-xold)/DT ); - -endfunction
--- a/extra/ocs/inst/TST/TSTBWEFUNUP1.m Tue Feb 09 05:24:36 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,37 +0,0 @@ -## Copyright (C) 2006,2007,2008 Carlo de Falco -## -## This file is part of: -## OCS - A Circuit Simulator for Octave -## -## OCS is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation. -## -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program (see the file LICENSE); if not, -## see <http://www.gnu.org/licenses/>. -## -## author: Carlo de Falco <cdf _AT_ users.sourceforge.net> - -## -*- texinfo -*- -## -## @deftypefn{Function File} @ -## {[@var{update}]=} TSTBWEFUNUP1@ -## (@var{outstruct}, @var{x}, @var{t1}) -## -## INTERNAL FUNCTION: -## -## NOT SUPPOSED TO BE CALLED DIRECTLY BY USERS -## @end deftypefn - -function update = TSTBWEFUNUP1(outstruct,x,t1) - - [A1,Jac,res] = ASMbuildsystem(outstruct,x,t1); - update = {A1,Jac,res}; - -endfunction \ No newline at end of file
--- a/extra/ocs/inst/TST/TSTDASPKFUNJAC.m Tue Feb 09 05:24:36 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,38 +0,0 @@ -## Copyright (C) 2006,2007,2008 Carlo de Falco -## -## This file is part of: -## OCS - A Circuit Simulator for Octave -## -## OCS is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation. -## -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program (see the file LICENSE); if not, -## see <http://www.gnu.org/licenses/>. -## -## author: Carlo de Falco <cdf _AT_ users.sourceforge.net> - -## -*- texinfo -*- -## -## @deftypefn{Function File} @ -## {[@var{lhs}]=} TSTDASPKFUNJAC@ -## (@var{outstruct}, @var{x}, @var{xdot}, @var{A0}, @var{B}, @var{t}, -## @var{c}) -## -## INTERNAL FUNCTION: -## -## NOT SUPPOSED TO BE CALLED DIRECTLY BY USERS -## @end deftypefn - -function lhs = TSTDASPKFUNJAC(outstruct,x,xdot,A0,B,t,c) - - [A1,Jac,res] = ASMbuildsystem(outstruct,x,t); - lhs = ( c*(A0+A1) + B + Jac); - -endfunction \ No newline at end of file
--- a/extra/ocs/inst/TST/TSTDASPKFUNRES.m Tue Feb 09 05:24:36 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,38 +0,0 @@ -## Copyright (C) 2006,2007,2008 Carlo de Falco -## -## This file is part of: -## OCS - A Circuit Simulator for Octave -## -## OCS is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation. -## -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program (see the file LICENSE); if not, -## see <http://www.gnu.org/licenses/>. -## -## author: Carlo de Falco <cdf _AT_ users.sourceforge.net> - -## -*- texinfo -*- -## -## @deftypefn{Function File} @ -## {[@var{rhs}]=} TSTDASPKFUNJAC@ -## (@var{outstruct}, @var{x}, @var{xdot}, @var{A0}, @var{B}, @var{C}, @var{t}) -## -## INTERNAL FUNCTION: -## -## NOT SUPPOSED TO BE CALLED DIRECTLY BY USERS -## @end deftypefn - -function rhs = TSTDASPKFUNRES(outstruct,x,xdot,A0,B,C,t) - - [A1,Jac,res] = ASMbuildsystem(outstruct,x,t); - rhs = (A0+A1)*xdot + B*x + C + res; - -endfunction -
--- a/extra/ocs/inst/TST/TSTODEPKGFUNJAC.m Tue Feb 09 05:24:36 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,37 +0,0 @@ -## Copyright (C) 2006,2007,2008 Carlo de Falco -## -## This file is part of: -## OCS - A Circuit Simulator for Octave -## -## OCS is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation. -## -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program (see the file LICENSE); if not, -## see <http://www.gnu.org/licenses/>. -## -## author: Carlo de Falco <cdf _AT_ users.sourceforge.net> - -## -*- texinfo -*- -## -## @deftypefn{Function File} @ -## {[@var{lhs}]=} TSTODEPKGFUNJAC@ -## (@var{outstruct}, @var{x}, @var{A0}, @var{B}, @var{t}) -## -## INTERNAL FUNCTION: -## -## NOT SUPPOSED TO BE CALLED DIRECTLY BY USERS -## @end deftypefn - -function lhs = TSTODEPKGFUNJAC(outstruct,x,A0,B,t) - - [A1,Jac,res] = ASMbuildsystem(outstruct,x,t); - lhs = ( B + Jac); - -endfunction \ No newline at end of file
--- a/extra/ocs/inst/TST/TSTODEPKGFUNMASS.m Tue Feb 09 05:24:36 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,37 +0,0 @@ -## Copyright (C) 2006,2007,2008 Carlo de Falco -## -## This file is part of: -## OCS - A Circuit Simulator for Octave -## -## OCS is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation. -## -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program (see the file LICENSE); if not, -## see <http://www.gnu.org/licenses/>. -## -## author: Carlo de Falco <cdf _AT_ users.sourceforge.net> - -## -*- texinfo -*- -## -## @deftypefn{Function File} @ -## {[@var{lhs}]=} TSTODEPKGFUNMASS@ -## (@var{outstruct}, @var{x}, @var{A0}, @var{t}) -## -## INTERNAL FUNCTION: -## -## NOT SUPPOSED TO BE CALLED DIRECTLY BY USERS -## @end deftypefn - -function lhs = TSTODEPKGFUNMASS(outstruct,x,A0,t) - - [A1,Jac,res] = ASMbuildsystem(outstruct,x,t); - lhs = -(A0+A1); - -endfunction \ No newline at end of file
--- a/extra/ocs/inst/TST/TSTODEPKGFUNRES.m Tue Feb 09 05:24:36 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,38 +0,0 @@ -## Copyright (C) 2006,2007,2008 Carlo de Falco -## -## This file is part of: -## OCS - A Circuit Simulator for Octave -## -## OCS is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation. -## -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program (see the file LICENSE); if not, -## see <http://www.gnu.org/licenses/>. -## -## author: Carlo de Falco <cdf _AT_ users.sourceforge.net> - -## -*- texinfo -*- -## -## @deftypefn{Function File} @ -## {[@var{rhs}]=} TSTODEPKGFUNRES@ -## (@var{outstruct}, @var{x}, @var{A0}, @var{B}, @var{C}, @var{t}) -## -## INTERNAL FUNCTION: -## -## NOT SUPPOSED TO BE CALLED DIRECTLY BY USERS -## @end deftypefn - -function rhs = TSTODEPKGFUNRES(outstruct,x,A0,B,C,t) - - [A1,Jac,res] = ASMbuildsystem(outstruct,x,t); - rhs = B*x + C + res; - -endfunction -
--- a/extra/ocs/inst/TST/TSTTHETAFUNJAC1.m Tue Feb 09 05:24:36 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,39 +0,0 @@ -## Copyright (C) 2008 Carlo de Falco -## -## This file is part of: -## OCS - A Circuit Simulator for Octave -## -## OCS is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation. -## -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program (see the file LICENSE); if not, -## see <http://www.gnu.org/licenses/>. -## -## author: Carlo de Falco <cdf _AT_ users.sourceforge.net> - -## -*- texinfo -*- -## -## @deftypefn{Function File} @ -## {[@var{lhs}]=} TSTTHETAFUNJAC1@ -## (@var{outstruct}, @var{x}, @var{t0}, @var{t1}, @var{A0}, @var{B}, @ -## @var{theta}, @var{A1}, @var{Jac}, @var{res}) -## -## INTERNAL FUNCTION: NOT SUPPOSED TO BE CALLED DIRECTLY BY USERS -## @end deftypefn - -function lhs = TSTTHETAFUNJAC1(outstruct, x, t0, t1, A0, B, theta, A1, Jac, res) - - DT = t1-t0; - if ( nargin < 10 ) - [A1,Jac,res] = ASMbuildsystem(outstruct,x,t1); - endif - lhs = ( (A0+A1)/DT + theta*(B + Jac) ); - -endfunction \ No newline at end of file
--- a/extra/ocs/inst/TST/TSTTHETAFUNRES1.m Tue Feb 09 05:24:36 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,43 +0,0 @@ -## Copyright (C) 2008 Carlo de Falco -## -## This file is part of: -## OCS - A Circuit Simulator for Octave -## -## OCS is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation. -## -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program (see the file LICENSE); if not, -## see <http://www.gnu.org/licenses/>. -## -## author: Carlo de Falco <cdf _AT_ users.sourceforge.net> - -## -*- texinfo -*- -## -## @deftypefn{Function File} {@var{rhs} = } TSTTHETAFUNRES1 @ -## (@var{outstruct}, @var{x}, @var{xold}, @ -## @var{t0}, @var{t1}, @var{A0}, @var{B}, @var{C},@ -## @var{resold}, @var{theta}, [@var{A1}, @var{Jac}, @var{res}]) -## -## INTERNAL FUNCTION: -## -## NOT SUPPOSED TO BE CALLED DIRECTLY BY USERS -## -## @end deftypefn - -function rhs = TSTTHETAFUNRES1(outstruct, x, xold, t0, t1, A0, B, C, - resold, theta, A1, Jac, res) - DT = t1-t0; - if ( nargin < 13 ) - [A1,Jac,res] = ASMbuildsystem(outstruct,x,t1); - endif - rhs = ( (A1+A0)*(x-xold)/DT + theta * (res + C + B*x) + - (1-theta) * (resold + C + B*xold) ); - -endfunction
--- a/extra/ocs/inst/TST/TSTbweuler.m Tue Feb 09 05:24:36 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,144 +0,0 @@ -## Copyright (C) 2006,2007,2008 Carlo de Falco -## -## This file is part of: -## OCS - A Circuit Simulator for Octave -## -## OCS is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation. -## -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program (see the file LICENSE); if not, -## see <http://www.gnu.org/licenses/>. -## -## author: Carlo de Falco <cdf _AT_ users.sourceforge.net> - -## -*- texinfo -*- -## -## @deftypefn{Function File} {[@var{out}, @var{niter}] =} @ -## TSTbweuler(@var{cirstruct}, @var{x},@var{t}, @var{tol},@ -## @var{maxit},@var{dmp}, @var{pltvars},@ -## @var{verbosity} ,@var{dae_fun}); -## -## Performs a transient simulation of the system described by -## @var{cirstruct} over the time interval @var{t} using the backward -## Euler algorithm -## -## An initial value for the state vector is computed by solving a -## steady state problem at @var{t}(1) -## the initial guess for the state vector is set to @var{x} -## @var{tol} @var{maxit} and @var{dmp} are parameters passed to -## NLSnewtonraphson. -## -## The output @var{out} will contain the value of the state vector at -## each point of @var{t}. -## -## The optional parameter @var{verbosity} controls the amount of -## output produced: -## -## @itemize @minus -## @item if verbosity(1) != 0, information on the progress -## of the algorithm are output at runtime -## @item if verbosity(2) != 0, the plot of the variables whose names -## are listed in @var{pltvars} is -## produced after the computation -## @end itemize -## -## For special purposes one may need to pass modified jacobian and -## residual functions, this can be done -## via the cell array of function handles @var{dae_fun}, such -## functions should have the same input and output -## parameter list as the default functions -## TSTBWEFUNJAC0,TSTBWEFUNRES0, TSTBWEFUNJAC,TSTBWEFUNRES -## -## The optional output @var{niter} returns the number of Newton iterations -## needed to reach convergence. -## -## -## @seealso{TSTdaspk, NLSnewtonraphson, TSTthetamethod} -## -## @end deftypefn - -function [out, varargout] = TSTbweuler(outstruct,x,t,tol,maxit,dmp,pltvars,verbosity,dae_fun) - - if ~exist("verbosity") - verbosity = [0,0]; - elseif length(verbosity)<2 - verbosity(2) =0; - endif - - out = zeros(rows(x),columns(t)); - out(:,1) = x; - - if nargout > 1 - niter = zeros(length(t),1); - endif - - if (verbosity(1)) - fprintf(1,"initial value:\n"); - endif - - - [A0,B,C,outstruct] = ASMinitsystem(outstruct,x); - - if (nargin > 8) - JAC = @(x) dae_fun{1}(outstruct,x,t(1),B); - RES = @(x) dae_fun{2}(outstruct,x,t(1),B,C); - else - JAC = @(x) TSTBWEFUNJAC0(outstruct,x,t(1),B); - RES = @(x) TSTBWEFUNRES0(outstruct,x,t(1),B,C); - endif - - %%out = repmat (x, 1, length(t)); - [out(:,1),ii,resnrm] = NLSnewtonraphson(x, RES, JAC, tol, maxit,verbosity(1)); - %%nrm(1) = resnrm(ii); - - for it=2:length(t) - - if (verbosity) - fprintf(1,"timestep #%d:\n",it); - endif - - if nargin > 8 - JAC = @(x) dae_fun{3}(outstruct,x,t(it-1),t(it),A0,B); - RES = @(x) dae_fun{4}(outstruct,x,out(:,it-1),t(it-1),t(it),A0,B,C); - else - JAC = @(x,A1,Jac,res) TSTBWEFUNJAC1(outstruct, x, t(it-1), - t(it), A0, B, A1, Jac, res); - RES = @(x,A1,Jac,res) TSTBWEFUNRES1(outstruct, x, out(:,it-1), - t(it-1), t(it), A0, B, C, - A1, Jac, res); - UPDT = @(x) TSTBWEFUNUP1 (outstruct, x, t(it)); - endif - - [out(:,it),ii,resnrm] = NLSnewtonraphson(out(:,it-1), RES, JAC, ... - tol, maxit, verbosity(1), - UPDT); - %%nrm(it) = resnrm(ii); - - if nargout > 1 - niter(it) = ii; - endif - - if (verbosity(2)) - UTLplotbyname(t(1:it),out(:,1:it),outstruct,pltvars), pause(.01) - endif - - if exist("~/.stop_ocs","file") - printf("stopping at timestep %d\n",it); - unix("rm ~/.stop_ocs"); - break - end - - endfor - - if nargout > 1 - varargout{1} = niter; - endif - -endfunction \ No newline at end of file
--- a/extra/ocs/inst/TST/TSTbweulernr.m Tue Feb 09 05:24:36 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,99 +0,0 @@ -## Copyright (C) 2006,2007,2008 Carlo de Falco -## -## This file is part of: -## OCS - A Circuit Simulator for Octave -## -## OCS is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation. -## -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program (see the file LICENSE); if not, -## see <http://www.gnu.org/licenses/>. -## -## author: Carlo de Falco <cdf _AT_ users.sourceforge.net> - -## -*- texinfo -*- -## -## @deftypefn{Function File} {[@var{out}, @var{niter}] =} @ -## TSTbweulernr(@var{cirstruct}, @var{x},@var{t}, @var{tol},@ -## @var{maxit},@var{dmp}, @var{pltvars},@ -## @var{verbosity} ,@var{dae_fun}); -## -## TSTbweulernr is the same as TSTbweuler except that no steady state -## simulation is computed to initialize the first timestep. -## -## @seealso{TSTbweulernr, TSTdaspk, NLSnewtonraphson, TSTthetamethod} -## -## @end deftypefn - -function [out, varargout] = TSTbweulernr(outstruct, out, t, tol, maxit, dmp, pltvars, verbosity, istart, dae_fun) - - if ~exist("verbosity") - verbosity = [0,0]; - elseif length(verbosity)<2 - verbosity(2) =0; - endif - - if nargout > 1 - niter = zeros(length(t),1); - endif - - x = out(:,istart); - [A0,B,C,outstruct] = ASMinitsystem(outstruct,x,t(1)); - - if (nargin > 9) - JAC = @(x) dae_fun{1}(outstruct,x,t(1),B); - RES = @(x) dae_fun{2}(outstruct,x,t(1),B,C); - else - JAC = @(x) TSTBWEFUNJAC0(outstruct,x,t(1),B); - RES = @(x) TSTBWEFUNRES0(outstruct,x,t(1),B,C); - endif - - for it=istart+1:length(t) - - if (verbosity) - fprintf(1,"timestep #%d:\n",it); - endif - - if nargin > 9 - JAC = @(x) dae_fun{3}(outstruct,x,t(it-1),t(it),A0,B); - RES = @(x) dae_fun{4}(outstruct,x,out(:,it-1),t(it-1),t(it),A0,B,C); - else - JAC = @(x,A1,Jac,res) TSTBWEFUNJAC1(outstruct, x, t(it-1), - t(it), A0, B, A1, Jac, res); - RES = @(x,A1,Jac,res) TSTBWEFUNRES1(outstruct, x, out(:,it-1), - t(it-1), t(it), A0, B, C, - A1, Jac, res); - UPDT = @(x) TSTBWEFUNUP1 (outstruct, x, t(it)); - endif - - [out(:,it),ii,resnrm] = NLSnewtonraphson(out(:,it-1), RES, JAC, ... - tol, maxit, verbosity(1), UPDT); - - if nargout > 1 - niter(it) = ii; - endif - - if (verbosity(2)) - UTLplotbyname(t(1:it),out(:,1:it),outstruct,pltvars), pause(.01) - endif - - if exist("~/.stop_ocs","file") - printf("stopping at timestep %d\n",it); - unix("rm ~/.stop_ocs"); - break - end - - endfor - - if nargout > 1 - varargout{1} = niter; - endif - -endfunction \ No newline at end of file
--- a/extra/ocs/inst/TST/TSTdaspk.m Tue Feb 09 05:24:36 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,115 +0,0 @@ -## Copyright (C) 2006,2007,2008 Carlo de Falco -## -## This file is part of: -## OCS - A Circuit Simulator for Octave -## -## OCS is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation. -## -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program (see the file LICENSE); if not, -## see <http://www.gnu.org/licenses/>. -## -## author: Carlo de Falco <cdf _AT_ users.sourceforge.net> - -## -*- texinfo -*- -## -## @deftypefn{Function File} {[@var{out}] =} TSTdaspk @ -## (@var{cirstruct}, @var{x},@var{t}, @var{tol}, @var{maxit},@ -## @var{dmp}, @var{pltvars},@var{verbosity}, @var{daskopts},@var{dae_fun}); -## -## Performs a transient simulation of the system described by -## @var{cirstruct} over the time interval @var{t} using daspk. -## -## An initial value for the state vector is computed by solving -## a steady state problem at @var{t}(1). -## The initial guess for the state vector is set to @var{x}. -## @var{tol} @var{maxit} and @var{dmp} are parameters passed -## to NLSnewtonraphson. -## -## The output @var{out} will contain the value of the state vector -## at each point of @var{t} -## -## Extra options for daspkcan be passed as name/value pairs in -## the cellarray @var{daskopts}. -## -## The optional parameter @var{verbosity} controls the amount of -## output produced: -## -## @itemize @minus -## @item if verbosity(1) != 0, information on the progress -## of the algorithm are output at runtime -## @item if verbosity(2) != 0, the plot of the variables whose names -## are listed in @var{pltvars} is -## produced after the computation -## @end itemize -## -## For special purposes one may need to pass modified jacobian -## and residual functions, this can be done -## via the cell array of function handles @var{dae_fun}, such -## functions should have the same input and output -## parameter list as the default functions -## TSTBWEFUNJAC0,TSTBWEFUNRES0, TSTDASPKFUNJAC,TSTDASPKFUNRES -## @seealso{TSTbweuler, NLSnewtonraphson, daspk} -## -## @end deftypefn - -function out = TSTdaspk (outstruct, x, t, tol, maxit, - dmp, pltvars, verbosity, daspkopts, dae_fun) - if ~exist("verbosity") - verbosity = [0,0]; - elseif length(verbosity)<2 - verbosity(2) =0; - endif - - if(verbosity(1)) - fprintf(1,"initial value:\n"); - endif - - daspk_options ("print initial condition info",1); - daspk_options("maximum order",2); - daspk_options("initial step size",t(2)-t(1)); - daspk_options("relative tolerance",1e-3); - - if ( nargin > 8 ) - for ii = 1:2:length(daspkopts) - daspk_options (daspkopts{ii},daspkopts{ii+1}); - endfor - endif - - - [A0,B,C,outstruct] = ASMinitsystem(outstruct,x,t(1)); - - if nargin > 9 - JAC = @(x) dae_fun{1}(outstruct,x,t(1),B); - RES = @(x) dae_fun{2}(outstruct,x,t(1),B,C); - else - JAC = @(x) TSTBWEFUNJAC0(outstruct,x,t(1),B); - RES = @(x) TSTBWEFUNRES0(outstruct,x,t(1),B,C); - endif - - [x,ii,resnrm] = NLSnewtonraphson(x, RES, JAC, tol, maxit,verbosity); - nrm(1) = resnrm(ii); - - if nargin > 9 - JAC = @(x) dae_fun{3}(outstruct,x,t(1),B); - RES = @(x) dae_fun{4}(outstruct,x,t(1),B,C); - else - JAC = @(x,xdot,t,c) TSTDASPKFUNJAC(outstruct,x,xdot,A0,B,t,c); - RES = @(x,xdot,t) TSTDASPKFUNRES(outstruct,x,xdot,A0,B,C,t); - endif - - [out, xdot, istate, msg] = daspk ({RES,JAC}, x, zeros(size(x)), t); - - out = out'; - if verbosity(2) - UTLplotbyname(t,out,outstruct,pltvars) - endif - -endfunction \ No newline at end of file
--- a/extra/ocs/inst/TST/TSTodepkg.m Tue Feb 09 05:24:36 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,141 +0,0 @@ -## Copyright (C) 2006,2007,2008 Carlo de Falco -## -## This file is part of: -## OCS - A Circuit Simulator for Octave -## -## OCS is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation. -## -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program (see the file LICENSE); if not, -## see <http://www.gnu.org/licenses/>. -## -## author: Carlo de Falco <cdf _AT_ users.sourceforge.net> - -## -*- texinfo -*- -## -## @deftypefn{Function File} {[@var{out}, [@var{tout}]] =} TSTodepkg @ -## (@var{cirstruct}, @var{x},@var{t}, @var{tol}, @var{maxit},@ -## @var{dmp}, @var{pltvars},@var{solver}, @var{odestruct}, @var{verbosity}); -## -## Performs a transient simulation of the system described by -## @var{cirstruct} over the time interval @var{t} using the odepkg DAE -## solver specified in @var{solver}. -## -## Pssible values for @var{solver} are @code{'ode2r'}, @code{'ode5r'}, -## @code{'oders'} or @code{'odesx'}. -## -## An initial value for the state vector is computed by solving -## a steady state problem at @var{t}(1). -## The initial guess for the state vector is set to @var{x}. -## @var{tol} @var{maxit} and @var{dmp} are parameters passed -## to NLSnewtonraphson. -## -## If one output is requested @var{out} will contain the value of the state vector -## at each point of @var{t}. -## If two outputs are requested @var{out} will contain the value of the state vector -## at each point of @var{tout}. -## -## Extra options for options for the solver can be passed to the solver -## via @var{odestruct}. -## -## The optional parameter @var{verbosity} controls the amount of -## output produced: -## -## @itemize @minus -## @item if verbosity(1) != 0, information on the progress -## of the algorithm are output at runtime -## @item if verbosity(2) != 0, the plot of the variables whose names -## are listed in @var{pltvars} is -## produced after the computation -## @end itemize -## -## @seealso{TSTbweuler, TSTdaspk, NLSnewtonraphson, odepkg, odeset, @ -## ode2r, ode5r, oders, odesx} -## -## @end deftypefn - -function [out, tout] = TSTodepkg (outstruct, x, t, tol, maxit, - dmp, pltvars, solver, - verbosity, odestruct) - - if ~exist("verbosity") - verbosity = [0,0]; - elseif length(verbosity)<2 - verbosity(2) =0; - endif - - if(verbosity(1)) - fprintf(1,"initial value:\n"); - endif - - if ~exist("odestruct") - odestruct = odeset(); - endif - - [A0,B,C,outstruct] = ASMinitsystem(outstruct,x,t(1)); - - JAC = @(x) TSTBWEFUNJAC0(outstruct,x,t(1),B); - RES = @(x) TSTBWEFUNRES0(outstruct,x,t(1),B,C); - - [x,ii,resnrm] = NLSnewtonraphson(x, RES, JAC, tol, maxit,verbosity); - nrm(1) = resnrm(ii); - - JAC = @(t, x) TSTODEPKGFUNJAC(outstruct, x, A0, B, t); - RES = @(t, x) TSTODEPKGFUNRES(outstruct, x, A0, B, C, t); - MASS= @(t, x) TSTODEPKGFUNMASS(outstruct, x, A0, t); - - odestruct = odeset(odestruct, 'Jacobian', JAC); - odestruct = odeset(odestruct, 'Mass', - A0); - odestruct = odeset(odestruct, 'RelTol', 1e-9, 'AbsTol', 100*eps, - 'MaxStep', max(diff(t)), 'InitialStep', - (diff(t))(1)); - - if verbosity(2) - odestruct = odeset(odestruct, 'OutputFcn', - @(t, y, deci) plotfun(t, y, flag, outstruct, pltvars) ); - endif - - [tout, out] = feval( solver, RES, t([1 end]), x, odestruct); - if (nargout < 2) - out = interp1(tout, out, t).'; - endif - - -endfunction - -function [varargout] = plotfun (vt, vy, vflag, outstruct, pltvars) - ## this function is a modified version of odeplot distributed - ## with odepkg (c) Thomas Treichl - - %# No input argument check is done for a higher processing speed - persistent vfigure; persistent vtold; - persistent vyold; persistent vcounter; - - if (strcmp (vflag, 'init')) - %# Nothing to return, vt is either the time slot [tstart tstop] - %# or [t0, t1, ..., tn], vy is the inital value vector 'vinit' - vfigure = figure; vtold = vt(1,1); vyold = vy(:,1); - vcounter = 1; - - elseif (isempty (vflag)) - %# Return something in varargout{1}, either false for 'not stopping - %# the integration' or true for 'stopping the integration' - vcounter = vcounter + 1; figure (vfigure); - vtold(vcounter,1) = vt(1,1); - vyold(:,vcounter) = vy(:,1); - UTLplotbyname(vtold, vyold, outstruct, pltvars); drawnow; - varargout{1} = false; - - elseif (strcmp (vflag, 'done')) - %# Cleanup has to be done, clear the persistent variables because - %# we don't need them anymore - clear ('vfigure', 'vtold', 'vyold', 'vcounter'); - - end
--- a/extra/ocs/inst/TST/TSTthetamethod.m Tue Feb 09 05:24:36 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,113 +0,0 @@ -## Copyright (C) 2006,2007,2008 Carlo de Falco -## -## This file is part of: -## OCS - A Circuit Simulator for Octave -## -## OCS is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation. -## -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program (see the file LICENSE); if not, -## see <http://www.gnu.org/licenses/>. -## -## author: Carlo de Falco <cdf _AT_ users.sourceforge.net> - -## -*- texinfo -*- -## -## @deftypefn{Function File} {[@var{out}] =} TSTthetamethod @ -## (@var{cirstruct}, @var{x},@var{t}, @var{tol},@ -## @var{maxit},@var{dmp}, @var{theta}, @var{pltvars},@ -## @var{verbosity}); -## -## Performs a transient simulation of the system described by -## @var{cirstruct} over the time interval @var{t} using the -## theta-method with parameter @var{theta} -## -## An initial value for the state vector is computed by solving a -## steady state problem at @var{t}(1) -## the initial guess for the state vector is set to @var{x} -## @var{tol} @var{maxit} and @var{dmp} are parameters passed to -## NLSnewtonraphson. -## -## The output @var{out} will contain the value of the state vector at -## each point of @var{t} -## -## The optional parameter @var{verbosity} controls the amount of -## output produced: -## -## @itemize @minus -## @item if verbosity(1) != 0, information on the progress -## of the algorithm are output at runtime -## @item if verbosity(2) != 0, the plot of the variables whose names -## are listed in @var{pltvars} is -## produced after the computation -## @end itemize -## -## -## @seealso{TSTbweuler, NLSnewtonraphson, daspk} -## -## @end deftypefn - -function out = TSTthetamethod(outstruct, x, t, tol, maxit, dmp, theta, - pltvars, verbosity) - - if ~exist("verbosity") - verbosity = [0,0]; - elseif length(verbosity)<2 - verbosity(2) = 0; - endif - - out=zeros(rows(x),columns(t)); - out(:,1) = x; - - if (verbosity(1)) - fprintf(1,"initial value:\n"); - endif - - - [A0,B,C,outstruct] = ASMinitsystem(outstruct,x,t(1)); - - JAC = @(x) TSTBWEFUNJAC0(outstruct,x,t(1),B); - RES = @(x) TSTBWEFUNRES0(outstruct,x,t(1),B,C); - - [out(:,1),ii,resnrm] = NLSnewtonraphson(x, RES, JAC, tol, maxit,verbosity(1)); - nrm(1) = resnrm(ii); - - for it=2:length(t) - - if(verbosity) - fprintf(1,"timestep #%d:\n",it); - endif - - - [A1old,Jacold,resold] = ASMbuildsystem(outstruct, out(:,it-1), t(it-1)); - - JAC = @(x,A1,Jac,res) TSTTHETAFUNJAC1(outstruct, x, t(it-1), - t(it), A0, B, theta, - A1, Jac, res); - RES = @(x,A1,Jac,res) TSTTHETAFUNRES1(outstruct, x, out(:,it-1), - t(it-1), t(it), A0, B, C, - resold, theta, A1, Jac, res); - UPDT = @(x) TSTBWEFUNUP1 (outstruct, x, t(it)); - - [out(:,it),ii,resnrm] = NLSnewtonraphson(out(:,it-1), RES, JAC, - tol, maxit, verbosity(1), - UPDT); - nrm(it) = resnrm(ii); - - if (verbosity(2)) - UTLplotbyname(t(1:it),out(:,1:it),outstruct,pltvars), pause(.1) - endif - - if exist("~/.stop_ocs","file") - break - end - endfor - -endfunction \ No newline at end of file
--- a/extra/ocs/inst/UTL/UTLplotbyname.m Tue Feb 09 05:24:36 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,54 +0,0 @@ -## Copyright (C) 2006,2007,2008 Carlo de Falco -## -## This file is part of: -## OCS - A Circuit Simulator for Octave -## -## OCS is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation. -## -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program (see the file LICENSE); if not, -## see <http://www.gnu.org/licenses/>. -## -## author: Carlo de Falco <cdf _AT_ users.sourceforge.net> - -## -*- texinfo -*- -## @deftypefn{Function File} {} UTLplotbyname(@var{t},@var{out}, @ -## @var{outstruct},@var{namelist}) -## -## Selects by name some elements of the state vector of the system described -## by @var{outstruct} and plots their dynamics over the time interval -## @var{t}. -## -## @var{namelist} should contain the list of names of the variables -## to plot -## @var{out} should be the output of a trnsient simulation over the -## time interval @var{t} -## -## @seealso{TSTdaspk, TSTbweuler, PRSiffparse} -## -## @end deftypefn - -function UTLplotbyname(t,out,outstruct,namelist) - - nn = length(outstruct.namesn); - - for ip = 1:nn - for in = 1:length(namelist) - if strcmp(namelist{in},outstruct.namess{ip}) - plot(t,out(outstruct.namesn(ip),:),... - [sprintf('%d',mod(in+1,6)+1) ";" outstruct.namess{ip} ";"]); - hold on - endif - endfor - endfor - - hold off - -endfunction \ No newline at end of file
--- a/extra/ocs/inst/UTL/UTLsbnserver.m Tue Feb 09 05:24:36 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,96 +0,0 @@ -## Copyright (C) 2006,2007,2008 Carlo de Falco -## -## This file is part of: -## OCS - A Circuit Simulator for Octave -## -## OCS is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation. -## -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program (see the file LICENSE); if not, -## see <http://www.gnu.org/licenses/>. -## -## author: Carlo de Falco <cdf _AT_ users.sourceforge.net> - -## -*- texinfo -*- -## @deftypefn{Function File} {} UTLsbnserver(@var{port}) -## Listen for socket connections on port @var{port}, read a command @ -## and return the corresponding output to the socket. -## @end deftypefn - -function UTLsbnserver (portnum) - - QUITMESSAGE = "quit UTLsbnserver"; - CONFIRMMESSAGE = "confirmed"; - - ## CREATE THE SOCKET AND WAIT FOR CONNECTIONS - s = socket(AF_INET, SOCK_STREAM, 0); - if s < 0 - error("cannot create socket\n"); - end - - if bind(s, portnum) < 0 - error("bind failed\n"); - end - - if listen(s, 1) < 0 - error("listen failed\n"); - end - - ##MAIN LOOP - while 1 - - ##ACCEPT CONNETCIONS - c = accept(s); - if c < 0 - error("connection error") - end - - ## READ COMMANDS FROM THE SOCKET - msg = readstring (c) - - ##IF CLIENT SENT SHUTDOWN MESSAGE EXIT - if strcmp (msg,QUITMESSAGE) - printf("client requested server shutdown, goodbye!\n"); - disconnect(c); disconnect(s); - break - end - - ##EXECUTE COMMANDS FROM THE CLIENT - [A,B,C] = eval(msg); - - ##SEND OUTPUT TO THE CLIENT - str = [ sprintf("%17g ",A) "\n" sprintf("%17g ",B)... - "\n" sprintf("%17g ",C) "\n"] - - send(c,str); - - ##END CONNECTION - disconnect(c); - - end - - disconnect(s); -endfunction - - -function msg = readstring (c) - - BUFFER_SIZE = 255; - - msg = ''; - read = BUFFER_SIZE; - - while read >= BUFFER_SIZE - newmsg = char(recv(c, BUFFER_SIZE)); - read = length(newmsg) - msg = [ msg newmsg]; - end - -endfunction
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/extra/ocs/inst/asm/asm_build_system.m Tue Feb 09 07:43:42 2010 +0000 @@ -0,0 +1,112 @@ +## Copyright (C) 2006,2007,2008 Carlo de Falco, Culpo Massimiliano +## +## This file is part of: +## OCS - A Circuit Simulator for Octave +## +## OCS is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program (see the file LICENSE); if not, +## see <http://www.gnu.org/licenses/>. +## +## author: Carlo de Falco <cdf _AT_ users.sourceforge.net> +## author: culpo@math.uni-wuppertal.de + +## -*- texinfo -*- +## @deftypefn{Function File} {[@var{A},@var{Jac},@var{res}] =}@ +## asm_build_system(@var{instruct},@var{x},@var{t}) +## +## Cycle through the circuit description structure @var{instruct} +## to build the system matrices @var{A}, @var{Jac}, @var{res} for +## the current step of the Newton method. +## +## @var{x} is the current value of the state variables, while @var{t} is the current time point. +## +## See the @cite{IFF file format specifications} for details about +## the output matrices. +## +## @seealso{asm_initialize_system,prs_iff} +## +## @end deftypefn + +function [A,Jac,res] = asm_build_system(instruct,x,t); + + ## Check input + if nargin != 3 + error("asm_build_system: wrong number of input parameters."); + elseif !(isstruct(instruct) && isfield(instruct,"LCR") && + isfield(instruct,"NLC")) + error("asm_build_system: first input is not a valid structure."); + elseif !isvector(x) + error("asm_build_system: second input is not a valid vector."); + elseif !isscalar(t) + error("asm_build_system: third input is not a valid scalar."); + endif + + n = instruct.totextvar + instruct.totintvar; + A = sparse(n,n); + Jac = sparse(n,n); + res = sparse(n,1); + + + ## NLC section + nblocks = length(instruct.NLC); + + for ibl = 1:nblocks + for iel = 1:instruct.NLC(ibl).nrows + + ## Evaluate element + if instruct.NLC(ibl).nintvar(iel) + intvars = instruct.totextvar+instruct.NLC(ibl).osintvar(iel) + \ + [1:instruct.NLC(ibl).nintvar(iel)]'; + else + intvars=[]; + endif + + il = instruct.NLC(ibl).vnmatrix(iel,:)'; + nzil = find(il!=0); + + y = zeros(size(il)); + y(nzil) = x(il(nzil)); + + z = x(intvars); + + [a,b,c] = feval(instruct.NLC(ibl).func,\ + instruct.NLC(ibl).section,\ + instruct.NLC(ibl).pvmatrix(iel,:),\ + instruct.NLC(ibl).parnames,\ + y,z,t); + + ## Assemble matrices + + ## Global indexing + vars = [il(nzil);intvars]; + + ## Local indexing + lclvars = [nzil; instruct.NLC(ibl).nextvar + (1:length(intvars))' ]; + + ## Reshaping sparse stamps + a = a(lclvars,lclvars); + b = b(lclvars,lclvars); + c = reshape(c(lclvars),[],1); + + [na,ma,va] = find(a); + [nb,mb,vb] = find(b); + [nc,mc,vc] = find(c); + + ## Stamping + A += sparse(vars(na),vars(ma),va,n,n); + Jac += sparse(vars(nb),vars(mb),vb,n,n); + res += sparse(vars(nc),1,vc,n,1); + + endfor + endfor + +endfunction \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/extra/ocs/inst/asm/asm_initialize_system.m Tue Feb 09 07:43:42 2010 +0000 @@ -0,0 +1,118 @@ +## Copyright (C) 2006,2007,2008 Carlo de Falco, Culpo Massimiliano +## +## This file is part of: +## OCS - A Circuit Simulator for Octave +## +## OCS is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program (see the file LICENSE); if not, +## see <http://www.gnu.org/licenses/>. +## +## author: Carlo de Falco <cdf _AT_ users.sourceforge.net> +## author: culpo@math.uni-wuppertal.de + +## -*- texinfo -*- +## +## @deftypefn{Function File} {[@var{A},@var{B},@var{C}] =}@ +## asm_initialize_system(@var{instruct},@var{x}) +## +## Cycle through the circuit description structure @var{instruct} +## to build the system matrices @var{A}, @var{B}, @var{C} for +## the linear and time-invariant part of the system. +## +## @var{x} is the current value of the state variables. +## +## See the @cite{IFF file format specifications} for details about +## the output matrices. +## +## @seealso{asm_build_system,prs_iff} +## +## @end deftypefn + +function [A,B,C] = asm_initialize_system(instruct,x); + + ## Check input + if nargin != 2 + error("asm_initialize_system: wrong number of input parameters."); + elseif !(isstruct(instruct) && isfield(instruct,"LCR") && + isfield(instruct,"NLC")) + error("asm_initialize_system: first input is not a valid structure."); + elseif !isvector(x) + error("asm_initialize_system: second input is not a valid vector."); + endif + + ## Build linear part of the system + n = instruct.totextvar + instruct.totintvar; # Number of variables + + ## Initialize to zero any state variable that is not in the input argument + lx = length(x); + if lx < n + x(lx+1:n) = 0; + endif + ## FIXME: should a warning be passed if lx != n ? + + A = sparse(n,n); + + ## LCR section + B = sparse(n,n); + C = sparse(n,1); + + nblocks = length(instruct.LCR); + + for ibl = 1:nblocks + for iel = 1:instruct.LCR(ibl).nrows + + ## Evaluate element + if instruct.LCR(ibl).nintvar(iel) + intvars = instruct.totextvar + instruct.LCR(ibl).osintvar(iel) + [1:instruct.LCR(ibl).nintvar(iel)]'; + else + intvars=[]; + endif + + il = instruct.LCR(ibl).vnmatrix(iel,:)'; + nzil = find(il!=0); + + y = zeros(size(il)); + y(nzil) = x(il(nzil)); + z = x(intvars); + + [a,b,c] = feval(instruct.LCR(ibl).func,\ + instruct.LCR(ibl).section,\ + instruct.LCR(ibl).pvmatrix(iel,:),\ + instruct.LCR(ibl).parnames,\ + y,z,0); + + ## Assemble matrices + + ## Global indexing + vars = [il(nzil);intvars]; + + ## Local indexing + lclvars = [nzil; instruct.LCR(ibl).nextvar + (1:length(intvars))' ]; + + ## Reshaping sparse stamps + a = a(lclvars,lclvars); + b = b(lclvars,lclvars); + c = reshape(c(lclvars),[],1); + + [na,ma,va] = find(a); + [nb,mb,vb] = find(b); + [nc,mc,vc] = find(c); + + ## Stamping + A += sparse(vars(na),vars(ma),va,n,n); + B += sparse(vars(nb),vars(mb),vb,n,n); + C += sparse(vars(nc),1,vc,n,1); + + endfor + endfor + +endfunction \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/extra/ocs/inst/nls/nls_newton_raphson.m Tue Feb 09 07:43:42 2010 +0000 @@ -0,0 +1,110 @@ +## Copyright (C) 2006-2009 Carlo de Falco +## +## This file is part of: +## OCS - A Circuit Simulator for Octave +## +## OCS is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program (see the file LICENSE); if not, +## see <http://www.gnu.org/licenses/>. +## +## author: Carlo de Falco <cdf _AT_ users.sourceforge.net> +## author: Massimiliano Culpo <culpo@math.uni-wuppertal.de> + +## -*- texinfo -*- +## @deftypefn{Function File}{[@var{y},@var{numit},@var{resnrm}] =} @ +## nls_newton_raphson (@var{y0},@var{RES},@var{JAC},@var{tol},@ +## @var{maxit},@var{verbosity},@var{update}); +## +## Solve a non-linear system of equations using the Newton-Raphson +## method with damping and return the computed solution vector @var{y}. +## +## The initial guess for the algorithm is set to @var{y0}. +## +## The Jacobian and residual at each step are computed via the function +## handles @var{RES} and @var{JAC}. +## +## The variables @var{tol} and @var{maxit} are the relative tolerance on the +## error of the computed solution and the maximum number of iterations to be +## performed by the algorithm. +## +## The optional parameter @var{verbosity} produce verbose output if non-zero. +## +## The optional function handle @var{update} may be used to provide +## a faster mean to update Jacobian and residual at runtime. +## +## @var{numit} is the number of performed iterations while @var{resnrm} +## is a vector containing the residual norm at each step. +## +## @seealso{nls_stationary,tst_backward_euler,tst_theta_method,tst_daspk,tst_odepkg} +## @end deftypefn + +function [y,ii,resnrm] = nls_newton_raphson(y0,RES,JAC,tol,maxit,\ + verbosity,update); + + ## Check input + ## FIXME: add input check! + if ((nargin < 5) || (nargin > 7)) + error("nls_newton_raphson: wrong number of input parameters."); + endif + + if ~exist("verbosity") + verbosity = 0; + endif + + if ~exist("update") + update = @(x) ({}); + endif + + jjtot = 0; + y = y0; + + uptodate = update(y); + res_y = RES(y,uptodate{:}); + resnrm(1) = norm(res_y,inf); + + for ii = 1:maxit + + jac_y = JAC(y,uptodate{:}); + ynew = jac_y\(-res_y+jac_y*y); + uptodate = update(ynew); + res_y = RES(ynew,uptodate{:}); + + resnrm(ii+1) = norm(res_y,inf); + + jj = 0; + while ((resnrm(ii+1)>resnrm(ii))&&(jj<10)) + jj++; + damp = 2^(-jj); + ynew = y*(1-damp) + ynew*damp; + uptodate = update(ynew); + res_y = RES(ynew,uptodate{:}); + resnrm(ii+1) = norm(res_y,inf); + endwhile + + jjtot += jj; + y = ynew; + + if resnrm(ii+1)<tol + if (verbosity) + fprintf(1,"Converged in %d newton iterations and ",ii); + fprintf(1,"%d damping iterations.\n",jjtot); + endif + break + elseif ii==maxit + if(verbosity) + fprintf(1,"Not converged, nrm=%g.\n",resnrm(maxit)) + endif + break + endif + endfor + +endfunction \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/extra/ocs/inst/nls/nls_stationary.m Tue Feb 09 07:43:42 2010 +0000 @@ -0,0 +1,81 @@ +## Copyright (C) 2006,2007,2008 Carlo de Falco +## +## This file is part of: +## OCS - A Circuit Simulator for Octave +## +## OCS is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program (see the file LICENSE); if not, +## see <http://www.gnu.org/licenses/>. +## +## author: Carlo de Falco <cdf _AT_ users.sourceforge.net> + +## -*- texinfo -*- +## @deftypefn{Function File} {[@var{out}, @var{niter}]} = nls_stationary @ +## (@var{instruct},@var{x},@var{tol},@var{maxit}) +## Compute the stationary state solution @var{out} of the system described +## by @var{instruct}. +## +## @var{x} is the initial guess used by the Newton-Raphson algorithm implemented in +## @code{nls_newton_raphson}, while @var{tol} and @var{maxit} are the corresponding +## parameters. +## +## The optional output @var{niter} returns the number of Newton iterations +## needed to reach convergence. +## +## @seealso{nls_newton_raphson} +## @end deftypefn + +function [out, varargout] = nls_stationary(outstruct,x,tol,maxit) + + ## Check input + ## FIXME: add input check! + if nargin != 4 + error("nls_stationary: wrong number of input parameters."); + endif + + [A0,B,C] = asm_initialize_system(outstruct,x); + JAC = @(x) TSTSTATFUNJAC(outstruct,x,B); + RES = @(x) TSTSTATFUNRES(outstruct,x,B,C); + UPD = @(x) TSTSTATUP(outstruct,x); + [out,ii,resnrm] = nls_newton_raphson(x,RES,JAC,tol,maxit,0,UPD); + + if nargin > 1 + varargout{1} = ii; + endif + +endfunction + +## Jacobian for steady state problems +function lhs = TSTSTATFUNJAC(outstruct,x,B,Jac,res) + + if nargin < 5 + [A1,Jac,res] = asm_build_system(outstruct,x,0); + endif + lhs = (B + Jac); + +endfunction +## Residual for steady state problem +function rhs = TSTSTATFUNRES(outstruct,x,B,C,Jac,res) + + if nargin < 6 + [A1,Jac,res] = asm_build_system(outstruct,x,0); + endif + rhs = (res + C + B*x); + +endfunction +## Update for transient problem +function update = TSTSTATUP(outstruct,x) + + [A1,Jac,res] = asm_build_system(outstruct,x,0); + update = {Jac,res}; + +endfunction \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/extra/ocs/inst/prs/prs_iff.m Tue Feb 09 07:43:42 2010 +0000 @@ -0,0 +1,313 @@ +## Copyright (C) 2006,2007,2008 Carlo de Falco +## +## This file is part of: +## OCS - A Circuit Simulator for Octave +## +## OCS is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program (see the file LICENSE); if not, +## see <http://www.gnu.org/licenses/>. +## +## author: Carlo de Falco <cdf _AT_ users.sourceforge.net> +## author: Massimiliano Culpo <culpo _AT_ users.sourceforge.net> + +## -*- texinfo -*- +## @deftypefn{Function File} @var{outstruct} = prs_iff(@var{name}) +## Parse a netlist in IFF format and produce the system description +## structure @var{outstruct}. +## +## @var{name} is the basename of the CIR and NMS files to +## be parsed. +## +## See the @cite{IFF file format specifications} (distributed together +## with the OCS package) for more details on the file format. +## +## @var{outstruct} has the following fields: +## +## @example +## outstruct = +## @{ +## LCR: struct % the fields of LCR are shown below +## NLC: struct % NLC has the same fields as LCR +## namesn: matrix % numbers of vars named in .nms file +## namess: cell % the names corresponding to the vars above +## totextvar: scalar % the total number of external variables +## totintvar: scalar % the total number of internal variables +## @} +## +## outstruct.LCR = +## outstruct.NLC = +## @{ +## struct array containing the fields: % array has one element per block +## +## func % name of the sbn file corresponding to each block +## section % string parameter to be passed to the sbn files +## nextvar % number of external variables for each element of the block +## vnmatrix % numbers of the external variables of each element +## nintvar % number of internal variables for each element of the block +## osintvar % number of the first internal variable +## npar % number of parameters +## nparnames% number of parameter names +## nrows % number of rows in the block +## parnames % list of parameter names +## pvmatrix % list of parameter values for each element +## +## @} +## @end example +## +## See the @cite{IFF file format specifications} for details about +## the output structures. +## +## @end deftypefn + +function outstruct = prs_iff(name) + + ## Check input + if (nargin != 1 || !ischar(name)) + error("prs_iff: wrong input.") + endif + + ## Initialization + version ="0.1b1"; + outstruct = struct("NLC",[],\ + "LCR",[],\ + "totextvar",0); + + ## Open cir file + filename = [name ".cir"]; + if isempty(file_in_path(".",filename)) + error(["prs_iff: .cir file not found:" filename]); + endif + fid = fopen(filename,"r"); + + ## Check version + ## FIXME: this part can be improved a lot!! + line = fgetl(fid); + + if line(1)!="%" + error(["prs_iff: missing version number in file " filename]); + endif + + if ~strcmp(version,sscanf(line(2:end),"%s")); + error(["prs_iff: conflicting version number in file " filename]); + endif + + ndsvec = []; # Vector of circuit nodes + intvar = 0; # Number of internal variables + + ## NLC section + NLCcount = 0; + while !strcmp(line,"END") + + ## Skip comments + while line(1)=="%" + line = fgetl(fid); + endwhile + + if strcmp(line,"END") + break + else + NLCcount++; + endif + + ## parse NLC block + [outstruct,intvar] = parseNLCblock(fid,line,outstruct,NLCcount,intvar); + + ndsvec = [ndsvec ; \ + outstruct.NLC(NLCcount).vnmatrix(:)]; + + ## skip the newline char after the matrix + line = fgetl(fid); + + ## proceed to next line + line = fgetl(fid); + + endwhile + + ## LCR section + LCRcount = 0; + line = fgetl(fid); + + while (!strcmp(line,"END")) + + ## Skip comments + while line(1)=="%" + line = fgetl(fid); + endwhile + + if strcmp(line,"END") + break + else + LCRcount++; + endif + + ## parse block header + [outstruct,intvar] = parseLCRblock(fid,line,outstruct,LCRcount,intvar); + + ndsvec = [ndsvec ; \ + outstruct.LCR(LCRcount).vnmatrix(:)]; + + ## skip the newline char after the matrix + line = fgetl(fid); + + ## proceed to next line + line = fgetl(fid); + + endwhile + + ## Set the number of internal and external variables + outstruct.totintvar = intvar; + nnodes = length(unique(ndsvec)); + maxidx = max(ndsvec); + + if nnodes <= (maxidx+1) + ## If the valid file is a subcircuit it may happen + ## that nnodes == maxidx, otherwise nnodes == (maxidx+1) + outstruct.totextvar = max(ndsvec); + else + error("prs_iff: hanging nodes in circuit %s",name); + endif + ## fclose cir file + fclose(fid); + + ## Open nms file + filename = [name ".nms"]; + if isempty(file_in_path(".",filename)) + error(["prs_iff: .nms file not found:" filename]); + endif + fid = fopen(filename,"r"); + + ## Check version + line = fgetl(fid); + + if line(1)~="%" + error(["prs_iff: missing version number in file " filename]); + endif + + if ~strcmp(version,sscanf(line(2:end),"%s")); + error(["prs_iff: conflicting version number in file " filename]); + endif + + ## Initialization + cnt = 1; + outstruct.namesn = []; + outstruct.namess = {}; + nnames = 0; + + while cnt + [nn,cnt] = fscanf(fid,"%d","C"); + [ns,cnt] = fscanf(fid,"%s","C"); + + if cnt + outstruct.namesn(++nnames)=nn; + outstruct.namess{nnames}=ns; + endif + endwhile + + ## fclose nms file + fclose(fid); + +endfunction + + +############################################## +function [outstruct,intvar] = parseNLCblock(fid,line,outstruct,NLCcount,intvar); + + ## Parse first line of the header and retrieve: + ## 1 - SBN function name + ## 2 - Section + ## 3 - Number of external variables + ## 4 - Number of parameters + [func,section,nextvar,npar] = sscanf(line,"%s %s %g %g","C"); + outstruct.NLC(NLCcount).func = func; + outstruct.NLC(NLCcount).section = section; + outstruct.NLC(NLCcount).nextvar = nextvar; + outstruct.NLC(NLCcount).npar = npar; + ## Parse second line of the header and retrieve: + ## 1 - Number of elements of this type + ## 2 - Number of parameter names to be parsed + [nrows,nparnames] = fscanf(fid,"%g %g","C"); + outstruct.NLC(NLCcount).nrows = nrows; + outstruct.NLC(NLCcount).nparnames = nparnames; + outstruct.NLC(NLCcount).parnames = {}; + for ii=1:nparnames + outstruct.NLC(NLCcount).parnames{ii} = fscanf(fid,"%s","C"); + endfor + + ## Parse the matrix containing the values of parameters + [outstruct.NLC(NLCcount).pvmatrix] = fscanf(fid,"%g",[npar,nrows])'; + + ## Parse the connectivity matrix + [outstruct.NLC(NLCcount).vnmatrix] = fscanf(fid,"%g",[nextvar,nrows])'; + + ## Compute internal variables cycling over each + ## element in the section + for iel = 1:nrows + [a,b,c] = feval(func,section,outstruct.NLC(NLCcount).pvmatrix(iel,:),\ + outstruct.NLC(NLCcount).parnames,zeros(nextvar,1),[],0); + + ## FIXME: if all the element in the same section share the + ## same number of internal variables, the for cycle can be + ## substituted by only one call + outstruct.NLC(NLCcount).nintvar(iel) = columns(a) - outstruct.NLC(NLCcount).nextvar; + outstruct.NLC(NLCcount).osintvar(iel) = intvar; + + intvar += outstruct.NLC(NLCcount).nintvar(iel); + endfor + +endfunction + +############################################## +function [outstruct,intvar] = parseLCRblock(fid,line,outstruct,LCRcount,intvar); + + ## Parse first line of the header and retrieve: + ## 1 - SBN function name + ## 2 - Section + ## 3 - Number of external variables + ## 4 - Number of parameters + [func,section,nextvar,npar] = sscanf(line,"%s %s %g %g","C"); + outstruct.LCR(LCRcount).func = func; + outstruct.LCR(LCRcount).section = section; + outstruct.LCR(LCRcount).nextvar = nextvar; + outstruct.LCR(LCRcount).npar = npar; + ## Parse second line of the header and retrieve: + ## 1 - Number of elements of this type + ## 2 - Number of parameter names to be parsed + [nrows,nparnames] = fscanf(fid,"%g %g","C"); + outstruct.LCR(LCRcount).nrows = nrows; + outstruct.LCR(LCRcount).nparnames = nparnames; + outstruct.LCR(LCRcount).parnames = {}; + for ii=1:nparnames + outstruct.LCR(LCRcount).parnames{ii} = fscanf(fid,"%s","C"); + endfor + + ## Parse the matrix containing the values of parameters + [outstruct.LCR(LCRcount).pvmatrix] = fscanf(fid,"%g",[npar,nrows])'; + + ## Parse the connectivity matrix + [outstruct.LCR(LCRcount).vnmatrix] = fscanf(fid,"%g",[nextvar,nrows])'; + + ## Compute internal variables cycling over each + ## element in the section + for iel = 1:nrows + [a,b,c] = feval(func,section,outstruct.LCR(LCRcount).pvmatrix(iel,:),\ + outstruct.LCR(LCRcount).parnames,zeros(nextvar,1),[],0); + + ## FIXME: if all the element in the same section share the + ## same number of internal variables, the for cycle can be + ## substituted by only one call + outstruct.LCR(LCRcount).nintvar(iel) = columns(a) - outstruct.LCR(LCRcount).nextvar; + outstruct.LCR(LCRcount).osintvar(iel) = intvar; + + intvar += outstruct.LCR(LCRcount).nintvar(iel); + endfor + +endfunction \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/extra/ocs/inst/sbn/Mcapacitors.m Tue Feb 09 07:43:42 2010 +0000 @@ -0,0 +1,178 @@ +## Copyright (C) 2006,2007,2008 Carlo de Falco +## +## This file is part of: +## OCS - A Circuit Simulator for Octave +## +## OCS is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program (see the file LICENSE); if not, +## see <http://www.gnu.org/licenses/>. +## +## author: Carlo de Falco <cdf _AT_ users.sourceforge.net> + +## -*- texinfo -*- +## +## @deftypefn{Function File} @ +## {[@var{a},@var{b},@var{c}]=} Mcapacitors(@var{string},@var{parameters},@ +## @var{parameternames},@var{extvar},@var{intvar},@var{t}) +## +## SBN file implementing models for capacitors. +## +## @var{string} is used to select among models. Parameters are listed +## as inner items. Possible models are: +## +## @enumerate +## @item @var{string} = "LIN" (Linear Capacitor) +## @itemize @minus +## @item C -> capacitance value +## @end itemize +## @item @var{string} = "MULTICAP" (Multipole Capacitor) +## @itemize @minus +## @item C -> capacitance values +## @end itemize +## @item @var{string} = "PDE_NMOS" (Drift-Diffusion PDE NMOS capacitor) +## @itemize @minus +## @item tbulk -> bulk thickness +## @item tox -> oxide thickness +## @item Nnodes -> number of nodes of 1D grid +## @item Na -> bulk doping +## @item toll -> absolute tolerance +## @item maxit -> max iterations number +## @item Area -> device area +## @end itemize +## @end enumerate +## +## See the @cite{IFF file format specifications} for details about +## the output structures. +## +## @seealso{prs_iff,asm_initialize_system,asm_build_system} +## @end deftypefn + +function [a,b,c] = Mcapacitors(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 + + a = [0 0 1; 0 0 -1; 0 0 0]; + b = [0 0 0;0 0 0;-C C 1]; + c = [0 0 0]'; + break + + case "MULTICAP" + + n = length(extvar); + C = reshape(parameters,n,n); + + a = [zeros(n) eye(n); zeros(n) zeros(n)]; + b = [zeros(n) zeros(n); -C eye(n)]; + c = [zeros(2*n,1)]'; + + break + + ##NLC part + case "PDE_NMOS" + + constants + + tbulk = 1.5e-6; + tox = 90e-9; + len = tbulk + tox; + Nnodes = 300; + Na=1e21; + toll = 1e-10; + maxit = 1000; + Area = 1e-12; + + for ii=1:length(parameternames) + eval([parameternames{ii} "=" num2str(parameters(ii)) ";"]) + endfor + + Vg = extvar(1) - extvar(2); + q = intvar(1); + + [Q,C]=Mnmoscap(tbulk,tox,Area,Vg,Na,Nnodes,toll,maxit); + + a = [0 0 1; 0 0 -1; 0 0 0]; + b = [0 0 0;0 0 0;C -C -1]; + c = [0 0 Q-q]'; + break + + otherwise + error (["unknown section:" string]) + endswitch + +endfunction +## Non-linear 1D MOS structure. +## FIXME: requires SECS1D!!! +function [Q,C]=Mnmoscap(tbulk,tox,Area,Vg,Na,Nnodes,toll,maxit); + + constants + + Nelements = Nnodes - 1; + len = tox+tbulk; + x = linspace(0,len,Nnodes)'; + sinodes = find(x<=tbulk); + Nsinodes = length(sinodes); + NelementsSi = Nsinodes-1; + D = - Na* ones(Nsinodes,1); + pp = Na ; + p = pp* ones(Nsinodes,1); + n = (ni^2)./p; + Fn = 0*n; + Fp = 0*n; + + V = -Phims + Vg * ones(Nnodes,1); + V(sinodes) = Fn + Vth*log(n/ni); + + ## Scaling + xs = len; + ns = norm(D,inf); + Din = D/ns; + Vs = Vth; + xin = x/xs; + nin = n/ns; + pin = p/ns; + Vin = V/Vs; + Fnin = (Fn - Vs * log(ni/ns))/Vs; + Fpin = (Fp + Vs * log(ni/ns))/Vs; + + l2 = (Vs*esio2)/(q*ns*xs^2)* ones(Nelements,1); + l2(1:NelementsSi) = (Vs*esi)/(q*ns*xs^2); + + ## Solution of Nonlinear Poisson equation + [V,nout,pout,res,niter] = DDGnlpoisson (xin,sinodes,Vin,nin,... + pin,Fnin,Fpin,Din,l2,... + toll,maxit,0); + + L = Ucomplap(xin,Nnodes,[],Nelements,l2); + C22 = L(end,end); + C12 = L(2:end-1,end); + C11 = L(2:end-1,2:end-1); + + drdv = zeros(Nnodes,1); drdv(sinodes) = nout + pout; + coeff = zeros(Nelements,1); coeff(1:NelementsSi) = 1; + M = Ucompmass(xin,Nnodes,[],[],drdv,coeff); + C = C22 - C12'*((C11+M(2:end-1,2:end-1))\C12); + Q =(C12'*V(2:end-1)+C22*V(end)); + + ## Descaling + C = Area*C*(q*ns*xs/Vs); + Q = Area*Q*(q*ns*xs); + +endfunction \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/extra/ocs/inst/sbn/Mcurrentsources.m Tue Feb 09 07:43:42 2010 +0000 @@ -0,0 +1,123 @@ +## Copyright (C) 2006,2007,2008 Carlo de Falco, Culpo Massimiliano +## +## This file is part of: +## OCS - A Circuit Simulator for Octave +## +## OCS is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program (see the file LICENSE); if not, +## see <http://www.gnu.org/licenses/>. +## +## author: Carlo de Falco <cdf _AT_ users.sourceforge.net> +## author culpo@math.uni-wuppertal.de + +## -*- texinfo -*- +## +## @deftypefn{Function File} @ +## {[@var{a},@var{b},@var{c}]=}Mcurrentsources(@var{string},@var{parameters},@ +## @var{parameternames},@var{extvar},@var{intvar},@var{t}) +## +## SBN file implementing models for current sources. +## +## @var{string} is used to select among models. Parameters are listed +## as inner items. Possible models are: +## +## @enumerate +## @item @var{string} = "DC" (Static indipendent current source) +## @itemize @minus +## @item I -> Current source value +## @end itemize +## @item @var{string} = "VCCS" (Voltage controlled current source) +## @itemize @minus +## @item K -> Control parameter +## @end itemize +## @item @var{string} = "sinwave" (Sinusoidal indipendent current +## source) +## @itemize @minus +## @item shift -> mean value of sinusoidal input +## @item Ampl -> amplitude of sinusoidal wave +## @item f -> frequency of sinusoidal wave +## @item delay -> delay of sinusoidal wave +## @end itemize +## @item @var{string} = "VCPS" (Voltage controlled power source) +## @itemize @minus +## @item K -> Control parameter +## @end itemize +## @end enumerate +## +## See the @cite{IFF file format specifications} for details about +## the output structures. +## +## @seealso{prs_iff,asm_initialize_system,asm_build_system} +## @end deftypefn + +function [a,b,c] = Mcurrentsources (string,parameters,parameternames,extvar,intvar,t) + + switch string + ## LCR part + case "DC" + for ii=1:length(parameternames) + eval([parameternames{ii} "=" num2str(parameters(ii)) ";"]) + endfor + + a = zeros(2); + b = a; + c = [I -I]'; + break + + case "VCCS" + ## Voltage controlled current source + K = 1; + for ii=1:length(parameternames) + eval([parameternames{ii} "=" num2str(parameters(ii)) ";"]) + endfor + + a = zeros(4); + b = [0 0 K -K;\ + 0 0 -K K;\ + 0 0 0 0;\ + 0 0 0 0]; + c = zeros(4,1); + ## NLC part + case "sinwave" + for ii=1:length(parameternames) + eval([parameternames{ii} "=" num2str(parameters(ii)) ";"]) + endfor + + I = shift+Ampl * sin(2*pi*(t+delay)*f ); + a = zeros(2); + b = a; + c = [I -I]'; + break + + case "VCPS" + ## Voltage controlled power source + K = 1; + for ii=1:length(parameternames) + eval([parameternames{ii} "=" num2str(parameters(ii)) ";"]) + endfor + + dv = extvar(3) - extvar(4); + I = K*(dv^2); + dIdv = 2*K*dv; + + a = zeros(4); + b = [0 0 dIdv -dIdv;\ + 0 0 -dIdv dIdv;\ + 0 0 0 0;\ + 0 0 0 0]; + c = [I -I 0 0]; + + otherwise + error (["unknown section:" string]) + endswitch + +endfunction
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/extra/ocs/inst/sbn/Mdiode.m Tue Feb 09 07:43:42 2010 +0000 @@ -0,0 +1,111 @@ +## Copyright (C) 2006,2007,2008 Massimiliano Culpo, Carlo de Falco +## +## This file is part of: +## OCS - A Circuit Simulator for Octave +## +## OCS is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program (see the file LICENSE); if not, +## see <http://www.gnu.org/licenses/>. +## +## author: culpo@math.uni-wuppertal.de, Carlo de Falco <cdf _AT_ users.sourceforge.net> + +## -*- texinfo -*- +## +## @deftypefn{Function File} @ +## {[@var{a},@var{b},@var{c}]=}Mdiode(@var{string},@var{parameters},@ +## @var{parameternames},@var{extvar},@var{intvar},@var{t}) +## +## SBN file implementing models for diodes. +## +## @var{string} is used to select among models. Parameters are listed +## as inner items. Possible models are: +## +## @itemize @minus +## @item @var{string} = "simple" (Usual exponential diode model) +## @itemize @minus +## @item Is -> reverse current +## @item Vth -> thermal voltage +## @item Rpar -> parasitic resistance +## @end itemize +## @item @var{string} = "PDEsymmetric" (Drift-Diffusion PDE model) +## @itemize @minus +## @item len -> diode length +## @item Nnodes -> number of nodes of 1D grid +## @item Dope -> doping (abrupt and symmetric) +## @item toll -> absolute tolerance +## @item maxit -> max iterations number +## @item Area -> device area +## @end itemize +## @end itemize +## +## See the @cite{IFF file format specifications} for details about +## the output structures. +## +## @seealso{prs_iff,asm_initialize_system,asm_build_system} +## @end deftypefn + +function [a,b,c] = Mdiode (string,parameters,parameternames,extvar,intvar,t) + + switch string + + case "simple" + Is = 1e-14; + Vth = 2.5e-2; + Rpar = 1e12; + for ii=1:length(parameternames) + eval([parameternames{ii} "=" num2str(parameters(ii)) ";"]) + endfor + + vp = extvar(1); + vm = extvar(2); + + I = Is*(exp((vp - vm)/Vth) -1 ) + (vp - vm)/Rpar; + geq = Is*exp((vp - vm)/Vth)/Vth + 1/Rpar; + + a = zeros(2); + b = [geq -geq; -geq geq]; + c = [I ; -I] ; + break + + case "PDEsymmetric" + + len = 1e-6; + Nnodes = 100; + Dope=1e23; + + toll = 1e-5; + maxit = 100; + ptoll = 1e-10; + pmaxit = 100; + + Area = 1e-10; + + for ii=1:length(parameternames) + eval([parameternames{ii} "=" num2str(parameters(ii)) ";"]) + endfor + + vp = extvar(1); + vm = extvar(2); + + [I,g] = Mpdesympnjunct (len,Dope,vp-vm,Area,Nnodes,toll,maxit,ptoll,pmaxit); + + a = zeros(2); + b = [g -g; -g g]; + c = [I ; -I] ; + + break + + otherwise + error(["unknown section:" string]) + endswitch + +endfunction
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/extra/ocs/inst/sbn/Minductors.m Tue Feb 09 07:43:42 2010 +0000 @@ -0,0 +1,77 @@ +## Copyright (C) 2006,2007,2008 Carlo de Falco +## +## This file is part of: +## OCS - A Circuit Simulator for Octave +## +## OCS is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program (see the file LICENSE); if not, +## see <http://www.gnu.org/licenses/>. +## +## author: Carlo de Falco <cdf _AT_ users.sourceforge.net> + +## -*- texinfo -*- +## +## @deftypefn{Function File} @ +## {[@var{a},@var{b},@var{c}]=}Minductors(@var{string},@var{parameters},@ +## @var{parameternames},@var{extvar},@var{intvar},@var{t}) +## +## SBN file implementing models for inductors. +## +## @var{string} is used to select among models. Parameters are listed +## as inner items. Possible models are: +## +## @enumerate +## @item @var{string} = "LIN" (Linear inductor model) +## @itemize @minus +## @item L -> inductance value +## @end itemize +## @end enumerate +## +## See the @cite{IFF file format specifications} for details about +## the output structures. +## +## @seealso{prs_iff,asm_initialize_system,asm_build_system} +## @end deftypefn + +function [a,b,c] = Minductors (string,parameters,parameternames,extvar,intvar,t) + + if isempty(intvar) + intvar = [0 0]; + endif + + switch string + + case "LIN" + for ii=1:length(parameternames) + eval([parameternames{ii} "=" num2str(parameters(ii)) ";"]) + endfor + + phi = intvar(1); + jl = intvar(2); + + a = [0 0 0 0; + 0 0 0 0; + 0 0 1 0; + 0 0 0 0]; + + b = [0 0 0 1; + 0 0 0 -1; + -1 1 0 0; + 0 0 1 -L]; + + c = [0 0 0 0]'; + otherwise + error (["unknown section:" string]) + endswitch + +endfunction + \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/extra/ocs/inst/sbn/Mnmosfet.m Tue Feb 09 07:43:42 2010 +0000 @@ -0,0 +1,161 @@ +## Copyright (C) 2006,2007,2008 Carlo de Falco +## +## This file is part of: +## OCS - A Circuit Simulator for Octave +## +## OCS is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program (see the file LICENSE); if not, +## see <http://www.gnu.org/licenses/>. +## +## author: Carlo de Falco <cdf _AT_ users.sourceforge.net> + +## -*- texinfo -*- +## +## @deftypefn{Function File} @ +## {[@var{a},@var{b},@var{c}]=}Mnmosfet(@var{string},@var{parameters},@ +## @var{parameternames},@var{extvar},@var{intvar},@var{t}) +## +## SBN file implementing standard models for n-mosfets. +## +## @var{string} is used to select among models. Parameters are listed +## as inner items. Possible models are: +## +## @enumerate +## @item @var{string} = "simple" (Standard model for MOSFET) +## @itemize @minus +## @item rd -> parasitic resistance between drain and source +## @item k -> k parameter for usual mosfet model +## @item Vth -> threshold voltage +## @end itemize +## @item @var{string} = "lincap" (Adds RC parasitics) +## @itemize @minus +## @item rd -> parasitic resistance between drain and source +## @item k -> k parameter for usual mosfet model +## @item Vth -> threshold voltage +## @item Rs -> parasitic source resistance +## @item Rd -> parasitic drain resistance +## @item Cs -> gate-source capacitance +## @item Cd -> gate-drain capacitance +## @item Cb -> gate-bulk capacitance +## @end itemize +## @end enumerate +## +## See the @cite{IFF file format specifications} for details about +## the output structures. +## +## @seealso{prs_iff,asm_initialize_system,asm_build_system} +## @end deftypefn + +function [a,b,c]=Mnmosfet(string,parameters,parameternames,extvar,intvar,t) + + switch string + case "simple" + + rd = 1e6; + k = 1e-5; + Vth = .5; + + for ii=1:length(parameternames) + eval([parameternames{ii} "=",... + num2str(parameters(ii)) " ;"]) + endfor + + vg = extvar(1); + vs = extvar(2); + vd = extvar(3); + vb = extvar(4); + + vgs = vg-vs; + vds = vd-vs; + + if (vgs < Vth) + + + gm = 0; + gd = 1/rd; + id = vds*gd; + + elseif ((vgs-Vth)>=(vds))&(vds>=0) + + id = k*((vgs-Vth)*vds-(vds^2)/2)+vds/rd; + gm = k*vds; + gd = k*(vgs-Vth-vds)+1/rd; + + elseif ((vgs-Vth)>=(vds))&(vds<0) + + gm = 0; + gd = 1/rd; + id = vds*gd; + + else # (i.e. if 0 <= vgs-vth <= vds) + + id = (k/(2))*(vgs-Vth)^2+vds/rd; + gm = (2*k/(2))*(vgs-Vth); + gd = 1/rd; + + endif + + a = zeros(4); + + b = [0 0 0 0; + -gm (gm+gd) -gd 0; + gm -(gm+gd) gd 0; + 0 0 0 0]; + + c = [0 -id id 0]'; + break; + + case "lincap" + + ## Default parameter values + if isempty(intvar) + intvar = zeros(5,1); + endif + Rs = 1e2; Rd = 1e2; Cs = 1e-15; + Cd = 1e-15; Cb = 1e-14; + rd = inf; k = 1e-3; Vth = .1; + + ## parameters given in input + for ii=1:length(parameternames) + eval([parameternames{ii} "=",... + num2str(parameters(ii)) " ;"]) + endfor + + + persistent tmpstruct + + if isempty(tmpstruct) + + mtdnmos = file_in_path(path,"Mtdnmos.cir"); + mtdnmos(end-3:end)=[]; + tmpstruct = prs_iff(mtdnmos); + + endif + + + tmpstruct.NLC.pvmatrix = [k Vth rd]; + tmpstruct.LCR(1).pvmatrix = [Rs; Rd]; + tmpstruct.LCR(2).pvmatrix = [Cs; Cd; Cb]; + + [A0,B,C] = asm_initialize_system(tmpstruct,[extvar;intvar]); + [A1,Jac,res] = asm_build_system(tmpstruct,[extvar;intvar],t); + + a = A0+A1; + b = B+Jac; + c = res + B*[extvar;intvar] + C; + + break; + otherwise + error(["unknown option:" string]); + endswitch + +endfunction
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/extra/ocs/inst/sbn/Mpdesympnjunct.m Tue Feb 09 07:43:42 2010 +0000 @@ -0,0 +1,125 @@ +## Copyright (C) 2006,2007,2008 Carlo de Falco +## +## This file is part of: +## OCS - A Circuit Simulator for Octave +## +## OCS is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program (see the file LICENSE); if not, +## see <http://www.gnu.org/licenses/>. +## +## author: Carlo de Falco <cdf _AT_ users.sourceforge.net> + +## -*- texinfo -*- +## +## @deftypefn{Function File} @ +## {[@var{j},@var{g}]=}Mpdesympnjunct@ +## (@var{len}, @var{Dope}, @var{va}, @ +## @var{Area}, @var{Nnodes}, @var{toll}, @var{maxit}, @var{ptoll}, @var{pmaxit}) +## +## INTERNAL FUNCTION: +## +## NOT SUPPOSED TO BE CALLED DIRECTLY BY USERS +## @end deftypefn + +function [j,g] = Mpdesympnjunct (len,Dope,va,Area,Nnodes,toll,maxit,ptoll,pmaxit) + + constants + + x = linspace(0,len,Nnodes)'; + xm = mean(x); + Nd=Dope; + Na=Dope; + nn = (Nd + sqrt(Nd^2+4*ni^2))/2; + pp = (Na + sqrt(Na^2+4*ni^2))/2; + xn = xm+len/10; + xp = xm-len/10; + D = Nd * (x>xm) - Na * (x<=xm); + + ## Scaling coefficients + xs = len; + ns = norm(D,inf); + Vs = Vth; + us = un; + Js = (Area*us*Vs*q*ns/xs); + xin = x/xs; + gs = Js/Vs; + + n = nn * (x>=xn) + (ni^2)/pp * (x<xn); + p = (ni^2)/nn * (x>xp) + pp * (x<=xp); + + Fn = va*(x<=xm); + Fp = Fn; + + V = (Fn - Vth * log(p/ni)); + + ## Scaling + idata.D = D/ns; + idata.un = un/us; + idata.up = up/us; + idata.tn = inf; + idata.tp = inf; + idata.l2 = (Vs*esi)/(q*ns*xs^2); + idata.nis = ni/ns; + idata.n = n/ns; + idata.p = p/ns; + idata.V = V/Vs; + idata.Fn = (Fn - Vs * log(ni/ns))/Vs; + idata.Fp = (Fp + Vs * log(ni/ns))/Vs; + + + ## Solution of DD system + ## Algorithm parameters + + sinodes = [1:length(x)]; + + [idata,it,res] = DDGgummelmap (xin,idata,toll,maxit/2,ptoll,pmaxit,0); + [odata,it,res] = DDNnewtonmap (xin,idata,toll,maxit/2,0); + + DV = diff(odata.V); + h = xin(2)-xin(1); + + Bp = Ubernoulli(DV,1); + Bm = Ubernoulli(DV,0); + + Jn = -odata.un * (odata.n(2:end).*Bp-odata.n(1:end-1).*Bm)/h; + Jp = odata.up * (odata.p(2:end).*Bm-odata.p(1:end-1).*Bp)/h; + + coeff = idata.un.*Umediaarmonica(odata.n); + L =- Ucomplap (xin,Nnodes,[],[],coeff); + Jn1 = L*odata.Fn; + fprintf(1,"jn1=%g\n",Jn1(1)) + fprintf(1,"jn=%g\n",Jn(1)) + + C11 = L(1,1); + C1I = L(1,2:end-1); + CII = L(2:end-1,2:end-1); + Gn = C11 - C1I*(CII\C1I'); + Gn = Gn - coeff(1)*(odata.Fn(2)-odata.Fn(1))/h + + coeff = idata.up.*Umediaarmonica(odata.p); + L =- Ucomplap (xin,Nnodes,[],[],coeff); + Jp1 = L*odata.Fp; + fprintf(1,"jp1=%g\n",Jp1(1)) + fprintf(1,"jp=%g\n",Jp(1)) + + C11 = L(1,1); + C1I = L(1,2:end-1); + CII = L(2:end-1,2:end-1); + Gp = C11 - C1I*(CII\C1I'); + Gp = Gp - coeff(1)*(odata.Fp(2)-odata.Fp(1))/h + + + ## Descaling + j= -(Jp(1)+Jn(1))*Js + g= gs*(Gn+Gp) + +endfunction \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/extra/ocs/inst/sbn/Mpmosfet.m Tue Feb 09 07:43:42 2010 +0000 @@ -0,0 +1,153 @@ +## Copyright (C) 2006,2007,2008 Carlo de Falco +## +## This file is part of: +## OCS - A Circuit Simulator for Octave +## +## OCS is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program (see the file LICENSE); if not, +## see <http://www.gnu.org/licenses/>. +## +## author: Carlo de Falco <cdf _AT_ users.sourceforge.net> + +## -*- texinfo -*- +## +## @deftypefn{Function File} @ +## {[@var{a},@var{b},@var{c}]=} Mpmosfet(@var{string},@var{parameters},@ +## @var{parameternames},@var{extvar},@var{intvar},@var{t}) +## +## SBN file implementing standard models for p-mosfets. +## +## @var{string} is used to select among models. Parameters are listed +## as inner items. Possible models are: +## +## @enumerate +## @item @var{string} = "simple" (Standard model for MOSFET) +## @itemize @minus +## @item rd -> parasitic resistance between drain and source +## @item k -> k parameter for usual mosfet model +## @item Vth -> threshold voltage +## @end itemize +## @item @var{string} = "lincap" (Adds RC parasitics) +## @itemize @minus +## @item rd -> parasitic resistance between drain and source +## @item k -> k parameter for usual mosfet model +## @item Vth -> threshold voltage +## @item Rs -> parasitic source resistance +## @item Rd -> parasitic drain resistance +## @item Cs -> gate-source capacitance +## @item Cd -> gate-drain capacitance +## @item Cb -> gate-bulk capacitance +## @end itemize +## @end enumerate +## +## See the @cite{IFF file format specifications} for details about +## the output structures. +## +## @seealso{prs_iff,asm_initialize_system,asm_build_system} +## @end deftypefn + +function [a,b,c]= Mpmosfet (string,parameters,parameternames,extvar,intvar,t) + + switch string + case "simple" + + rd = 1e6; + + for ii=1:length(parameternames) + eval([parameternames{ii} "=",... + num2str(parameters(ii)) " ;"]); + endfor + + vg = extvar(1); + vs = extvar(2); + vd = extvar(3); + vb = extvar(4); + + vgs = vg-vs; + vds = vd-vs; + + if (vgs > Vth) + + gm = 0; + gd = 1/rd; + id = vds*gd; + + elseif ((vgs-Vth)<=(vds))&(vds<=0) + + id = k*((vgs-Vth)*vds-(vds^2)/2)+vds/rd; + gm = k*vds; + gd = k*(vgs-Vth-vds)+1/rd; + + elseif ((vgs-Vth)<=(vds))&(vds>0) + + gm = 0; + gd = 1/rd; + id = vds*gd; + + else + + id = k*(vgs-Vth)^2/2+vds/rd; + gm = k*(vgs-Vth); + gd = 1/rd; + + endif + a = zeros(4); + + b = [0 0 0 0; + -gm (gm+gd) -gd 0; + gm -(gm+gd) gd 0; + 0 0 0 0 ]; + + c =[0 -id id 0]'; + break; + + case "lincap" + + ## Default parameter values + if isempty(intvar) + intvar = zeros(5,1); + endif + Rs = 1e2; Rd = 1e2; Cs = 1e-15; + Cd = 1e-15; Cb = 1e-12; + rd = inf; k = -1e-3; Vth = -.1; + + ## parameters given in input + + for ii=1:length(parameternames) + eval([parameternames{ii} "=",... + num2str(parameters(ii)) " ;"]) + endfor + + + mtdpmos = file_in_path(path,"Mtdpmos.cir"); + mtdpmos(end-3:end)=[]; + tmpstruct = prs_iff(mtdpmos); + + + tmpstruct.NLC.pvmatrix = [k Vth rd]; + tmpstruct.LCR(1).pvmatrix = [Rs; Rd]; + tmpstruct.LCR(2).pvmatrix = [Cs; Cd; Cb]; + + [A0,B,C] = asm_initialize_system(tmpstruct,[extvar;intvar]); + [A1,Jac,res] = asm_build_system(tmpstruct,[extvar;intvar],t); + + a = A0+A1; + b = B+Jac; + c = res + B*[extvar;intvar] + C; + + break; + + otherwise + error(["unknown option:" string]); + endswitch + +endfunction
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/extra/ocs/inst/sbn/Mresistors.m Tue Feb 09 07:43:42 2010 +0000 @@ -0,0 +1,131 @@ +## Copyright (C) 2006,2007,2008 Carlo de Falco, Culpo Massimiliano +## +## This file is part of: +## OCS - A Circuit Simulator for Octave +## +## OCS is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program (see the file LICENSE); if not, +## see <http://www.gnu.org/licenses/>. +## +## author: Carlo de Falco <cdf _AT_ users.sourceforge.net> +## author: culpo@math.uni-wuppertal.de + +## -*- texinfo -*- +## +## @deftypefn{Function File} @ +## {[@var{a},@var{b},@var{c}]=}Mresistors(@var{string},@var{parameters},@ +## @var{parameternames},@var{extvar},@var{intvar},@var{t}) +## +## SBN file implementing models for resistors. +## +## @var{string} is used to select among models. Parameters are listed +## as inner items. Possible models are: +## +## @enumerate +## @item @var{string} = "LIN" (Linear resistor) +## @itemize @minus +## @item R -> resistance value +## @end itemize +## @item @var{string} = "THERMAL" (Linear resistor with termal pin) +## @itemize @minus +## @item R0 -> reference resistance value at temperature @code{TNOM} +## @item TC1 -> coefficient for first order Taylor expansion +## @item TC2 -> coefficient for second order Taylor expansion +## @item TNOM -> reference temperature +## @end itemize +## @item @var{string} = "THERMAL1D" (1D Thermal resistor) +## @itemize @minus +## @item L -> length of 1D domain +## @item N -> number of discretized elements +## @item cv -> PDE coefficient for dynamic part +## @item k -> PDE coefficient for diffusion part +## @end itemize +## @end enumerate +## +## See the @cite{IFF file format specifications} for details about +## the output structures. +## +## @seealso{prs_iff,asm_initialize_system,asm_build_system} +## @end deftypefn + + +function [a,b,c] =Mresistors(string,parameters,parameternames,extvar,intvar,t) + + switch string + ## LCR part + case "LIN" + for ii=1:length(parameternames) + eval([parameternames{ii} "=" num2str(parameters(ii)) ";"]) + endfor + + vp = extvar(1); + vm = extvar(2); + + a = zeros(2); + b = [1 -1 ;-1 1]/R; + c = -[0; 0]; + + break + ##NLCpart + case "THERMAL" + + for ii=1:length(parameternames) + eval([parameternames{ii} "=" num2str(parameters(ii)) ";"]) + endfor + + v1 = extvar(1); + v2 = extvar(2); + T = extvar(3); + + RT = R0*(1 + TC1*(T-TNOM) + TC2*(T - TNOM)^2); + dRdT = R0*(TC1 + 2*TC2*(T-TNOM)); + + i1 = (v1-v2)/RT; + i2 = (v2-v1)/RT; + P = -(v1-v2)^2/RT; + + a = zeros(3); + b = [ 1/RT -1/RT (v2-v1)*dRdT/RT^2;... + -1/RT 1/RT (v1-v2)*dRdT/RT^2;... + -2*(v1-v2)/RT -2*(v2-v1)/RT (v1-v2)^2*dRdT/RT^2]; + c = [i1 i2 P]'; + + break; + + case "THERMAL1D" + + for ii=1:length(parameternames) + eval([parameternames{ii} "=" num2str(parameters(ii)) ";"]) + endfor + + h = L/N; + + A = (cv*S*h)*speye(N+1); + + B = spdiags([ -ones(N+1,1) 2*ones(N+1,1) -ones(N+1,1)],-1:1,N+1,N+1); + B(1 ,1) = 1; + B(N+1 ,N+1) = 1; + + ext=[1 N+1]; + int=[2:N]; + + a = [A(ext,ext), A(ext,int); A(int,ext), A(int,int)]; + b = k*(S/h)*[B(ext,ext), B(ext,int); B(int,ext), B(int,int)]; + c = zeros(N+1,1); + + break; + + otherwise + error (["unknown section:" string]) + endswitch + +endfunction
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/extra/ocs/inst/sbn/Mshichmanhodgesmosfet.m Tue Feb 09 07:43:42 2010 +0000 @@ -0,0 +1,332 @@ +## Copyright (C) 2006-2009 Carlo de Falco, Massimiliano Culpo +## +## This file is part of: +## OCS - A Circuit Simulator for Octave +## +## OCS is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program (see the file LICENSE); if not, +## see <http://www.gnu.org/licenses/>. +## +## author: Carlo de Falco <cdf _AT_ users.sourceforge.net>, culpo@math.uni-wuppertal.de + +## -*- texinfo -*- +## +## @deftypefn{Function File} @ +## {[@var{a},@var{b},@var{c}]=} Mshichmanhodgesmosfet(@var{string},@var{parameters},@ +## @var{parameternames},@var{extvar},@var{intvar},@var{t}) +## +## SBN file implementing Schichman-Hodges MOSFETs model. +## +## @var{string} is used to select among models. Possible models are: +## +## @enumerate +## @item @var{string} = "NMOS" (Schichman-Hodges n-MOSFET) +## @item @var{string} = "PMOS" (Schichman-Hodges p-MOSFET) +## @end enumerate +## +## Parameters for all the above models are: +## @itemize +## @item rd -> parasitic resistance between drain and source +## @item W -> MOSFET width +## @item L -> channel length +## @item mu0 -> reference value for mobility +## @item Vth -> threshold voltage +## @item Cox -> oxide capacitance +## @item Cgs -> gate-source capacitance +## @item Cgd -> gate-drain capacitance +## @item Cgb -> gate-bulk capacitance +## @item Csb -> source-bulk capacitance +## @item Cdb -> drain-bulk capacitance +## @item Tshift -> shift for reference temperature on MOSFETs (default 0) +## @end itemize +## +## See the @cite{IFF file format specifications} for details about +## the output structures. +## +## @seealso{prs_iff,asm_initialize_system,asm_build_system} +## @end deftypefn + +function [a,b,c]= Mshichmanhodgesmosfet (string,parameters,parameternames,extvar,intvar,t) + + if isempty(intvar) + ## If intvar is empty, then we are initializing the system + ## and there is no need of a matrix evaluation + a = sparse(10,10); + b = []; + c = []; + else + ## If intvar is NOT empty, then we are evaluating the + ## element stamp + switch string + case "NMOS" + + rd = 1e6; + W = 1; + L = 1; + mu0 = 1e-5; + Vth = .5; + Cox = 1e-9; + Cgb = Cox; + Cgs=Cgd=Csb=Cdb=.1*Cox; + Tshift = 0; + + for ii=1:length(parameternames) + eval([parameternames{ii} "=",... + num2str(parameters(ii)) " ;"]) + endfor + + [gm,gd,ids,didT,P,dPdT,dPdvgs,dPdvds] = \ + nmos(extvar,mu0,Cox,W,L,Vth,rd,Tshift); + + vg = extvar(1); + vs = extvar(2); + vd = extvar(3); + vb = extvar(4); + T = max(extvar(5),0); + + if isempty(intvar) + intvar = zeros(5,1); + endif + + Qgb = intvar(1); + Qgs = intvar(2); + Qgd = intvar(3); + Qsb = intvar(4); + Qdb = intvar(5); + + a11 = a21 = a22 = zeros(5,5); + a12 = [ 1 1 1 0 0; \ + 0 -1 0 1 0; \ + 0 0 -1 0 1; \ + -1 0 0 -1 -1; \ + 0 0 0 0 0]; + + a = [a11 a12; a21 a22]; + + b11 = [0 0 0 0 0; \ + -gm (gm+gd) -gd 0 -didT; \ + gm -(gm+gd) gd 0 didT; \ + 0 0 0 0 0; \ + dPdvgs -(dPdvgs+dPdvds) dPdvds 0 dPdT]; + + b12 = zeros(5,5); + + b21 = [Cgb 0 0 -Cgb 0; \ + Cgs -Cgs 0 0 0; \ + Cgd 0 -Cgd 0 0; \ + 0 Csb 0 -Csb 0; \ + 0 0 Cdb -Cdb 0]; + b22 = -eye(5); + + b = [b11 b12; b21 b22]; + + + c1 = [0; -ids; ids; 0; P]; + + c2 = [Cgb*(vg - vb) - Qgb;\ + Cgs*(vg - vs) - Qgs;\ + Cgd*(vg - vd) - Qgd;\ + Csb*(vs - vb) - Qsb;\ + Cdb*(vd - vb) - Qdb]; + + c = [c1;c2]; + + + break; + + case "PMOS" + + rd = 1e6; + W = 1; + L = 1; + mu0 = 1e-5; + Vth = -.5; + Cox = 1e-9; + Cgb=Cox; + Cgs=Cgd=Csb=Cdb=.1*Cox; + Tshift = 0; + + for ii=1:length(parameternames) + eval([parameternames{ii} "=",... + num2str(parameters(ii)) " ;"]) + endfor + + [gm,gd,ids,didT,P,dPdT,dPdvgs,dPdvds] = \ + pmos(extvar,mu0,Cox,W,L,Vth,rd,Tshift); + + + vg = extvar(1); + vs = extvar(2); + vd = extvar(3); + vb = extvar(4); + T = extvar(5); + + if isempty(intvar) + intvar = zeros(5,1); + endif + + Qgb = intvar(1); + Qgs = intvar(2); + Qgd = intvar(3); + Qsb = intvar(4); + Qdb = intvar(5); + + a11 = a21 = a22 = zeros(5,5); + a12 = [ 1 1 1 0 0; \ + 0 -1 0 1 0; \ + 0 0 -1 0 1; \ + -1 0 0 -1 -1; \ + 0 0 0 0 0]; + + a = [a11 a12; a21 a22]; + + b11 = [0 0 0 0 0; \ + -gm (gm+gd) -gd 0 -didT; \ + gm -(gm+gd) gd 0 didT; \ + 0 0 0 0 0; \ + dPdvgs -(dPdvgs+dPdvds) dPdvds 0 dPdT]; + + b12 = zeros(5,5); + + b21 = [Cgb 0 0 -Cgb 0; \ + Cgs -Cgs 0 0 0; \ + Cgd 0 -Cgd 0 0; \ + 0 Csb 0 -Csb 0; \ + 0 0 Cdb -Cdb 0]; + + b22 = -eye(5); + + b = [b11 b12; b21 b22]; + + + c1 = [0; -ids; ids; 0; P]; + + c2 = [Cgb*(vg - vb) - Qgb;\ + Cgs*(vg - vs) - Qgs;\ + Cgd*(vg - vd) - Qgd;\ + Csb*(vs - vb) - Qsb;\ + Cdb*(vd - vb) - Qdb]; + + c = [c1;c2]; + + break; + + otherwise + error(["unknown option:" string]); + endswitch + endif + +endfunction + +function [gm,gd,ids,didT,P,dPdT,dPdvgs,dPdvds] = nmos(extvar,mu0,Cox,W,L,Vth,rd,Tshift) + ##Computes values for nmos case + + vg = extvar(1); + vs = extvar(2); + vd = extvar(3); + vb = extvar(4); + T = max(extvar(5),0); + + k = mu0*Cox*((T + Tshift)/300)^(-3/2)*W/L; + dkdT = mu0*Cox*W*(-3/2)*((T + Tshift)/300)^(-5/2)*(1/300)/L; + + vgs = vg-vs; + vds = vd-vs; + + if (vgs < Vth) + + gm = 0; + gd = 1/rd; + ids = vds*gd; + didT= 0; + + elseif ((vgs-Vth)>=(vds))&(vds>=0) + + ids = k*((vgs-Vth)*vds-(vds^2)/2)+vds/rd; + gm = k*vds; + gd = k*(vgs-Vth-vds) + 1/rd; + didT= dkdT*((vgs-Vth)*vds-(vds^2)/2); + + elseif ((vgs-Vth)>=(vds))&(vds<0) + + gm = 0; + gd = 1/rd; + ids = vds*gd; + didT= 0; + + else # (i.e. if 0 <= vgs-vth <= vds) + + ids = (k/2)*(vgs-Vth)^2+vds/rd; + gm = k*(vgs-Vth); + gd = 1/rd; + didT= (dkdT/(2))*(vgs-Vth)^2; + + endif + + P = -ids * vds; + dPdT = -didT* vds; + dPdvgs = -(gm*vds); + dPdvds = -(gd*vds + ids); + +endfunction + +function [gm,gd,ids,didT,P,dPdT,dPdvgs,dPdvds] = pmos(extvar,mu0,Cox,W,L,Vth,rd,Tshift) + ##Computes values for pmos case + + vg = extvar(1); + vs = extvar(2); + vd = extvar(3); + vb = extvar(4); + T = extvar(5); + + k = - mu0 * Cox * ((T + Tshift)/300)^(-3/2) *W/L; + dkdT = - mu0 * Cox * W *(-3/2)*((T + Tshift)/300)^(-5/2)*(1/300)/L; + + vgs = vg-vs; + vds = vd-vs; + + if (vgs > Vth) + + gm = 0; + gd = 1/rd; + ids = vds*gd; + didT= 0; + + elseif ((vgs-Vth)<=(vds))&(vds<=0) + + ids = k*((vgs-Vth)*vds-(vds^2)/2)+vds/rd; + gm = k*vds; + gd = k*(vgs-Vth-vds)+1/rd; + didT= dkdT*((vgs-Vth)*vds-(vds^2)/2); + + elseif ((vgs-Vth)<=(vds))&(vds>0) + + gm = 0; + gd = 1/rd; + ids = vds*gd; + didT= 0; + + else + + ids = (k/2)*(vgs-Vth)^2+vds/rd; + gm = k*(vgs-Vth); + gd = 1/rd; + didT= (dkdT/(2))*(vgs-Vth)^2; + + endif + + P = -ids * vds; + dPdT = -didT* vds; + dPdvgs = -(gm*vds); + dPdvds = -(gd*vds + ids); + +endfunction \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/extra/ocs/inst/sbn/Mtdnmos.cir Tue Feb 09 07:43:42 2010 +0000 @@ -0,0 +1,29 @@ +% 0.1b1 +% A Simple MOSFET model +% including charge stores +% N-Mosfet +Mnmosfet simple 4 3 +1 3 +k Vth rd +1 1 1e30 +1 5 6 4 +END +% Resistors +Mresistors LIN 2 1 +2 1 +R +1 +1 +2 5 +3 6 +% Capacitors +Mcapacitors LIN 2 1 +3 1 +C +1 +1 +1 +1 5 +1 6 +1 4 +END
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/extra/ocs/inst/sbn/Mtdnmos.nms Tue Feb 09 07:43:42 2010 +0000 @@ -0,0 +1,10 @@ +% 0.1b1 +1 Vg +2 Vs +3 Vd +4 Vb +5 Vsi +6 Vdi +7 Qs +8 Qd +9 Qb \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/extra/ocs/inst/sbn/Mtdpmos.cir Tue Feb 09 07:43:42 2010 +0000 @@ -0,0 +1,29 @@ +% 0.1b1 +% A Simple MOSFET model +% including charge stores +% N-Mosfet +Mpmosfet simple 4 3 +1 3 +k Vth rd +1 1 1e30 +1 5 6 4 +END +% Resistors +Mresistors LIN 2 1 +2 1 +R +1 +1 +2 5 +3 6 +% Capacitors +Mcapacitors LIN 2 1 +3 1 +C +1 +1 +1 +1 5 +1 6 +1 4 +END
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/extra/ocs/inst/sbn/Mtdpmos.nms Tue Feb 09 07:43:42 2010 +0000 @@ -0,0 +1,10 @@ +% 0.1b1 +1 Vg +2 Vs +3 Vd +4 Vb +5 Vsi +6 Vdi +7 Qs +8 Qd +9 Qb \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/extra/ocs/inst/sbn/Mvoltagesources.m Tue Feb 09 07:43:42 2010 +0000 @@ -0,0 +1,183 @@ +## Copyright (C) 2006,2007,2008 Carlo de Falco +## +## This file is part of: +## OCS - A Circuit Simulator for Octave +## +## OCS is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program (see the file LICENSE); if not, +## see <http://www.gnu.org/licenses/>. +## +## author: Carlo de Falco <cdf _AT_ users.sourceforge.net> + +## -*- texinfo -*- +## +## @deftypefn{Function File} @ +## {[@var{a},@var{b},@var{c}]=} Mvoltagesources(@var{string},@var{parameters},@ +## @var{parameternames},@var{extvar},@var{intvar},@var{t}) +## +## SBN file implementing models for voltage sources. +## +## @var{string} is used to select among models. Parameters are listed +## as inner items. Possible models are: +## +## @enumerate +## @item @var{string} = "DC" (Static indipendent voltage source) +## @itemize @minus +## @item V -> Current source value +## @end itemize +## @item @var{string} = "sinwave" (Sinusoidal indipendent voltage +## source) +## @itemize @minus +## @item shift -> mean value of sinusoidal input +## @item Ampl -> amplitude of sinusoidal wave +## @item f -> frequency of sinusoidal wave +## @item delay -> delay of sinusoidal wave +## @end itemize +## @item @var{string} = "pwl" (Piecewise linear voltage source) +## @itemize @minus +## @item takes as parameter times and values. For example @code{0 1 4 6} +## means at time instant 0 value 1, at time instant 4 value 6, etc. +## @end itemize +## @item @var{string} = "squarewave" (Square wave) +## @itemize @minus +## @item low -> low-state value +## @item high -> high-state value +## @item tlow -> duration of low-state +## @item thigh -> duration of high-state +## @item delay -> delay of square wave +## @item start -> starting voltage value +## @end itemize +## @item @var{string} = "step" (Voltage step) +## @itemize @minus +## @item low -> low-state value +## @item high -> high-state value +## @item tstep -> time instant of step transition +## @end itemize +## @item @var{string} = "VCVS" (Voltage controlled voltage source) +## @itemize @minus +## @item K -> Control parameter +## @end itemize +## @end enumerate +## +## See the @cite{IFF file format specifications} for details about +## the output structures. +## +## @seealso{prs_iff,asm_initialize_system,asm_build_system} +## @end deftypefn + +function [a,b,c] = Mvoltagesources (string,parameters,parameternames,extvar,intvar,t) + + if isempty(intvar) + intvar = 0; + endif + + switch string + ##LCR part + case "DC" + for ii=1:length(parameternames) + eval([parameternames{ii} "=" num2str(parameters(ii)) ";"]) + endfor + + j = intvar(1); + + a = zeros(3); + b = [0 0 1;0 0 -1;1 -1 0]; + c = [0 0 -V]; + break + ## NLC part + case "sinwave" + for ii=1:length(parameternames) + eval([parameternames{ii} "=" num2str(parameters(ii)) ";"]) + endfor + + DV = shift+Ampl * sin(2*pi*(t+delay)*f ); + j = intvar(1); + + a = zeros(3); + b = [0 0 1;0 0 -1;1 -1 0]; + c = [0 0 -DV]' + b * [extvar;intvar]; + break + + case "pwl" + + times = parameters(1:2:end-1); + values= parameters(2:2:end); + + DV = interp1(times,values,t,"linear","extrap"); + j = intvar(1); + + a = zeros(3); + b = [0 0 1;0 0 -1;1 -1 0]; + c = [0 0 -DV]' + b * [extvar;intvar]; + break + + case "squarewave" + for ii=1:length(parameternames) + eval([parameternames{ii} "=" num2str(parameters(ii)) ";"]) + endfor + if t<delay + if exist("start") + DV=start; + else + DV=low; + endif + else + T = tlow+thigh; + t = mod(t-delay,T); + if t<tlow + DV = low; + else + DV = high; + endif + endif + j = intvar(1); + + a = zeros(3); + b = [0 0 1;0 0 -1;1 -1 0]; + c = [0 0 -DV]' + b * [extvar;intvar]; + break + + case "step" + for ii=1:length(parameternames) + eval([parameternames{ii} "=" num2str(parameters(ii)) ";"]) + endfor + + if t<tstep + DV=low; + else + DV = high; + endif + + j = intvar(1); + + a = zeros(3); + b = [0 0 1;0 0 -1;1 -1 0]; + c = [0 0 -DV]' + b * [extvar;intvar]; + break + + case "VCVS" + K = 1; + for ii=1:length(parameternames) + eval([parameternames{ii} "=" num2str(parameters(ii)) ";"]) + endfor + + j = intvar(1); + + 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 -K K 0]; + c = zeros(5,1); + break + otherwise + error (["unknown section:" string]) + endswitch + +endfunction
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/extra/ocs/inst/tst/tst_backward_euler.m Tue Feb 09 07:43:42 2010 +0000 @@ -0,0 +1,178 @@ +## Copyright (C) 2006,2007,2008 Carlo de Falco +## +## This file is part of: +## OCS - A Circuit Simulator for Octave +## +## OCS is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program (see the file LICENSE); if not, +## see <http://www.gnu.org/licenses/>. +## +## author: Carlo de Falco <cdf _AT_ users.sourceforge.net> + +## -*- texinfo -*- +## +## @deftypefn{Function File} {[@var{out},@var{niter}] =} @ +## tst_backward_euler(@var{cirstruct},@var{x},@var{t},@var{tol},@ +## @var{maxit},@var{pltvars},@var{verbosity},@var{dae_fun}) +## +## Perform a transient simulation of the system described by +## @var{cirstruct} over the time interval @var{t} using the backward +## Euler algorithm. +## +## The initial value for the state vector is computed by solving a +## steady state problem at @var{t}(1), with starting guess @var{x}. +## +## @var{tol} and @var{maxit} are parameters passed to +## @code{nls_newton_raphson}. +## +## The output @var{out} will contain the value of the state vector at +## each point of @var{t}. +## +## The optional parameter @var{verbosity} controls the amount of +## output produced: +## +## @itemize @minus +## @item if verbosity(1) != 0, information on the progress +## of the algorithm are output at runtime +## @item if verbosity(2) != 0, the plot of the variables whose names +## are listed in @var{pltvars} is +## produced after the computation +## @end itemize +## +## For special purposes one may need to pass modified jacobian and +## residual functions. This can be done via the cell array of function +## handles @var{dae_fun}. +## +## Such functions should have the same input and output +## parameter list as the default sub-functions +## TSTBWEFUNJAC0,TSTBWEFUNRES0, TSTBWEFUNJAC,TSTBWEFUNRES. +## +## The optional output @var{niter} returns the number of Newton iterations +## needed to reach convergence. +## +## @seealso{tst_daspk,tst_theta_method,tst_odepkg,nls_newton_raphson} +## +## @end deftypefn + +function [out, varargout] = tst_backward_euler(outstruct,x,t,\ + tol,maxit,pltvars,verbosity,dae_fun) + + ## Check input + ## FIXME: add input check! + if ((nargin < 6) || (nargin > 8)) + error("tst_backward_euler: wrong number of input parameters."); + endif + + if ~exist("verbosity") + verbosity = [0,0]; + elseif length(verbosity)<2 + verbosity(2) =0; + endif + + out = zeros(rows(x),columns(t)); + out(:,1) = x; + + if nargout > 1 + niter = zeros(length(t),1); + endif + + if (verbosity(1)) + fprintf(1,"Initial value.\n"); + endif + + + [A0,B,C] = asm_initialize_system(outstruct,x); + + if (nargin > 8) + JAC = @(x) dae_fun{1}(outstruct,x,t(1),B); + RES = @(x) dae_fun{2}(outstruct,x,t(1),B,C); + [out(:,1),ii,resnrm] = nls_newton_raphson(x,RES,JAC,tol,maxit,verbosity(1)); + else + [out(:,1),ii] = nls_stationary(outstruct,x,tol,maxit); + endif + + if nargout > 1 + niter(1) = ii; + endif + + for it=2:length(t) + + if (verbosity(1)) + fprintf(1,"Timestep #%d.\n",it); + endif + + if nargin > 8 + JAC = @(x) dae_fun{3}(outstruct,x,t(it-1),t(it),A0,B); + RES = @(x) dae_fun{4}(outstruct,x,out(:,it-1),t(it-1),t(it),A0,B,C); + else + JAC = @(x,A1,Jac,res) TSTBWEFUNJAC1(outstruct, x, t(it-1), + t(it), A0, B, A1, Jac, res); + RES = @(x,A1,Jac,res) TSTBWEFUNRES1(outstruct, x, out(:,it-1), + t(it-1), t(it), A0, B, C, + A1, Jac, res); + UPDT = @(x) TSTBWEFUNUP1 (outstruct, x, t(it)); + endif + + [out(:,it),ii,resnrm] = \ + nls_newton_raphson(out(:,it-1),RES,JAC,tol,maxit,verbosity(1),UPDT); + + if nargout > 1 + niter(it) = ii; + endif + + if (verbosity(2)) + utl_plot_by_name(t(1:it),out(:,1:it),outstruct,pltvars), pause(.01) + endif + + ## Stop at runtime + ## FIXME: maintain this part? + if exist("~/.stop_ocs","file") + printf("stopping at timestep %d\n",it); + unix("rm ~/.stop_ocs"); + break + end + + endfor + + if nargout > 1 + varargout{1} = niter; + endif + +endfunction + +## Jacobian for transient problem +function lhs = TSTBWEFUNJAC1(outstruct,x,t0,t1,A0,B,A1,Jac,res) + + DT = t1-t0; + if ( nargin < 9 ) + [A1,Jac,res] = asm_build_system(outstruct,x,t1); + endif + lhs = ( (A0+A1)/DT + B + Jac); + +endfunction +## Residual for transient problem +function rhs = TSTBWEFUNRES1(outstruct,x,xold,t0,t1,A0,B,C,A1,Jac,res) + + DT = t1-t0; + if ( nargin < 11 ) + [A1,Jac,res] = asm_build_system(outstruct,x,t1); + endif + rhs = (res + C + B*x + (A0+A1)*(x-xold)/DT ); + +endfunction +## Update for transient problem +function update = TSTBWEFUNUP1(outstruct,x,t1) + + [A1,Jac,res] = asm_build_system(outstruct,x,t1); + update = {A1,Jac,res}; + +endfunction \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/extra/ocs/inst/tst/tst_daspk.m Tue Feb 09 07:43:42 2010 +0000 @@ -0,0 +1,135 @@ +## Copyright (C) 2006,2007,2008 Carlo de Falco +## +## This file is part of: +## OCS - A Circuit Simulator for Octave +## +## OCS is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program (see the file LICENSE); if not, +## see <http://www.gnu.org/licenses/>. +## +## author: Carlo de Falco <cdf _AT_ users.sourceforge.net> + +## -*- texinfo -*- +## +## @deftypefn{Function File} {[@var{out}] =} tst_daspk @ +## (@var{cirstruct},@var{x},@var{t},@var{tol},@var{maxit},@ +## @var{pltvars},@var{verbosity},@var{daskopts},@var{dae_fun}); +## +## Perform a transient simulation of the system described by +## @var{cirstruct} over the time interval @var{t} using @code{daspk}. +## +## The initial value for the state vector is computed by solving a +## steady state problem at @var{t}(1), with starting guess @var{x}. +## +## @var{tol} and @var{maxit} are parameters passed to +## @code{nls_newton_raphson}. +## +## The output @var{out} will contain the value of the state vector +## at each point of @var{t}. +## +## Extra options for @code{daspk} can be passed as name/value pairs in +## the cellarray @var{daskopts}. +## +## The optional parameter @var{verbosity} controls the amount of +## output produced: +## +## @itemize @minus +## @item if verbosity(1) != 0, information on the progress +## of the algorithm are output at runtime +## @item if verbosity(2) != 0, the plot of the variables whose names +## are listed in @var{pltvars} is +## produced after the computation +## @end itemize +## +## For special purposes one may need to pass modified jacobian and +## residual functions. This can be done via the cell array of function +## handles @var{dae_fun}. +## +## Such functions should have the same input and output +## parameter list as the default sub-functions +## TSTBWEFUNJAC0,TSTBWEFUNRES0, TSTBWEFUNJAC,TSTBWEFUNRES. +## +## @seealso{tst_backward_euler,tst_odepkg,tst_theta_method,nls_newton_raphson,daspk} +## +## @end deftypefn + +function [out] = tst_daspk (outstruct,x,t,tol,maxit,\ + pltvars,verbosity,daspkopts,dae_fun) + + ## FIXME: add input check! + if ((nargin < 6) || (nargin > 9)) + error("tst_daspk: wrong number of input parameters."); + endif + + if ~exist("verbosity") + verbosity = [0,0]; + elseif length(verbosity)<2 + verbosity(2) =0; + endif + + if(verbosity(1)) + fprintf(1,"initial value:\n"); + endif + + daspk_options("print initial condition info",1); + daspk_options("maximum order",2); + daspk_options("initial step size",t(2)-t(1)); + daspk_options("relative tolerance",1e-3); + + if ( nargin > 8 ) + for ii = 1:2:length(daspkopts) + daspk_options (daspkopts{ii},daspkopts{ii+1}); + endfor + endif + + + [A0,B,C] = asm_initialize_system(outstruct,x); + + if nargin > 9 + JAC = @(x) dae_fun{1}(outstruct,x,t(1),B); + RES = @(x) dae_fun{2}(outstruct,x,t(1),B,C); + [x,ii,resnrm] = nls_newton_raphson(x,RES,JAC,tol,maxit,verbosity); + else + [out(:,1),ii] = nls_stationary(outstruct,x,tol,maxit); + endif + + if nargin > 9 + JAC = @(x) dae_fun{3}(outstruct,x,t(1),B); + RES = @(x) dae_fun{4}(outstruct,x,t(1),B,C); + else + JAC = @(x,xdot,t,c) TSTDASPKFUNJAC(outstruct,x,xdot,A0,B,t,c); + RES = @(x,xdot,t) TSTDASPKFUNRES(outstruct,x,xdot,A0,B,C,t); + endif + + [out, xdot, istate, msg] = daspk ({RES,JAC}, x, zeros(size(x)), t); + + out = out'; + if verbosity(2) + utl_plot_by_name(t,out,outstruct,pltvars) + endif + +endfunction + +## Jacobian for transient problem +function lhs = TSTDASPKFUNJAC(outstruct,x,xdot,A0,B,t,c) + + [A1,Jac,res] = asm_build_system(outstruct,x,t); + lhs = ( c*(A0+A1) + B + Jac); + +endfunction +## Residual for transient problem +function rhs = TSTDASPKFUNRES(outstruct,x,xdot,A0,B,C,t) + + [A1,Jac,res] = asm_build_system(outstruct,x,t); + rhs = (A0+A1)*xdot + B*x + C + res; + +endfunction \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/extra/ocs/inst/tst/tst_odepkg.m Tue Feb 09 07:43:42 2010 +0000 @@ -0,0 +1,164 @@ +## Copyright (C) 2006,2007,2008 Carlo de Falco +## +## This file is part of: +## OCS - A Circuit Simulator for Octave +## +## OCS is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program (see the file LICENSE); if not, +## see <http://www.gnu.org/licenses/>. +## +## author: Carlo de Falco <cdf _AT_ users.sourceforge.net> + +## -*- texinfo -*- +## +## @deftypefn{Function File} {[@var{out}, [@var{tout}]] =} tst_odepkg @ +## (@var{cirstruct},@var{x},@var{t},@var{tol},@var{maxit},@ +## @var{pltvars},@var{solver},@var{odestruct},@var{verbosity}); +## +## Perform a transient simulation of the system described by +## @var{cirstruct} over the time interval @var{t} using the @code{odepkg} DAE +## solver specified in @var{solver}. +## +## Pssible values for @var{solver} are @code{ode2r}, @code{ode5r}, +## @code{oders} or @code{odesx}. +## +## The initial value for the state vector is computed by solving a +## steady state problem at @var{t}(1), with starting guess @var{x}. +## +## @var{tol} and @var{maxit} are parameters passed to @code{nls_newton_raphson}. +## +## If one output is requested @var{out} will contain the value of the state vector +## at each point of @var{t}. +## +## If two outputs are requested @var{out} will contain the value of the state vector +## at each point of @var{tout}. +## +## Extra options for options for the solver can be passed to the solver +## via @var{odestruct}. +## +## The optional parameter @var{verbosity} controls the amount of +## output produced: +## +## @itemize @minus +## @item if verbosity(1) != 0, information on the progress +## of the algorithm are output at runtime +## @item if verbosity(2) != 0, the plot of the variables whose names +## are listed in @var{pltvars} is +## produced after the computation +## @end itemize +## +## @seealso{tst_backward_euler,tst_theta_method,tst_daspk,nls_newton_raphson,odepkg,odeset,@ +## ode2r,ode5r,oders,odesx} +## +## @end deftypefn + +function [out, tout] = tst_odepkg (outstruct,x,t,tol,maxit,\ + pltvars,solver,verbosity,odestruct) + + ## Check input + ## FIXME: add input check! + if ((nargin < 7) || (nargin > 9)) + error("tst_odepkg:wrong number of input parameters"); + endif + + if ~exist("verbosity") + verbosity = [0,0]; + elseif length(verbosity)<2 + verbosity(2) =0; + endif + + if(verbosity(1)) + fprintf(1,"initial value:\n"); + endif + + if ~exist("odestruct") + odestruct = odeset(); + endif + + [A0,B,C] = asm_initialize_system(outstruct,x); + + [out(:,1),ii] = nls_stationary(outstruct,x,tol,maxit); + + JAC = @(t, x) TSTODEPKGFUNJAC(outstruct, x, A0, B, t); + RES = @(t, x) TSTODEPKGFUNRES(outstruct, x, A0, B, C, t); + MASS= @(t, x) TSTODEPKGFUNMASS(outstruct, x, A0, t); + + odestruct = odeset(odestruct,"Jacobian", JAC); + odestruct = odeset(odestruct,"Mass",MASS(0,x)); + odestruct = odeset(odestruct,"RelTol", 1e-6,"AbsTol",1e6*eps, + "MaxStep", max(diff(t)),"InitialStep",(diff(t))(1)); + + if verbosity(2) + odestruct = odeset(odestruct, "OutputFcn", + @(t, y, flag) plotfun(t, y, flag, outstruct, pltvars) ); + endif + + [tout, out] = feval( solver, RES, t([1 end]), x, odestruct); + if (nargout < 2) + out = interp1(tout, out, t).'; + endif + +endfunction + +function [varargout] = plotfun (vt, vy, vflag, outstruct, pltvars) + ## this function is a modified version of odeplot distributed + ## with odepkg (c) Thomas Treichl + + %# No input argument check is done for a higher processing speed + persistent vfigure; persistent vtold; + persistent vyold; persistent vcounter; + + if (strcmp (vflag, "init")) + %# Nothing to return, vt is either the time slot [tstart tstop] + %# or [t0, t1, ..., tn], vy is the inital value vector 'vinit' + vfigure = figure; vtold = vt(1,1); vyold = vy(:,1); + vcounter = 1; + + elseif (isempty (vflag)) + %# Return something in varargout{1}, either false for 'not stopping + %# the integration' or true for 'stopping the integration' + vcounter = vcounter + 1; figure (vfigure); + vtold(vcounter,1) = vt(1,1); + vyold(:,vcounter) = vy(:,1); + utl_plot_by_name(vtold, vyold, outstruct, pltvars); drawnow; + varargout{1} = false; + + elseif (strcmp (vflag, "done")) + %# Cleanup has to be done, clear the persistent variables because + %# we don't need them anymore + clear ("vfigure","vtold","vyold","vcounter"); + + endif + +endfunction +## Jacobian for transient problems +function lhs = TSTODEPKGFUNJAC(outstruct,x,A0,B,t) + + [A1,Jac,res] = asm_build_system(outstruct,x,t); + lhs = ( B + Jac); + +endfunction + +function lhs = TSTODEPKGFUNMASS(outstruct,x,A0,t) + + [A1,Jac,res] = asm_build_system(outstruct,x,t); + lhs = -(A0+A1); + +endfunction + +## Residual for transient problems +function rhs = TSTODEPKGFUNRES(outstruct,x,A0,B,C,t) + + [A1,Jac,res] = asm_build_system(outstruct,x,t); + rhs = B*x + C + res; + +endfunction \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/extra/ocs/inst/tst/tst_theta_method.m Tue Feb 09 07:43:42 2010 +0000 @@ -0,0 +1,162 @@ +## Copyright (C) 2006,2007,2008 Carlo de Falco +## +## This file is part of: +## OCS - A Circuit Simulator for Octave +## +## OCS is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program (see the file LICENSE); if not, +## see <http://www.gnu.org/licenses/>. +## +## author: Carlo de Falco <cdf _AT_ users.sourceforge.net> + +## -*- texinfo -*- +## +## @deftypefn{Function File} {[@var{out},@var{niter}] =} tst_theta_method @ +## (@var{cirstruct},@var{x},@var{t},@var{tol},@ +## @var{maxit},@var{theta},@var{pltvars},@ +## @var{verbosity}); +## +## Perform a transient simulation of the system described by +## @var{cirstruct} over the time interval @var{t} using the +## theta-method with parameter @var{theta}. +## +## The initial value for the state vector is computed by solving a +## steady state problem at @var{t}(1), with starting guess @var{x}. +## +## @var{tol} and @var{maxit} are parameters passed to +## @code{nls_newton_raphson}. +## +## The output @var{out} will contain the value of the state vector at +## each point of @var{t}. +## +## The optional parameter @var{verbosity} controls the amount of +## output produced: +## +## @itemize @minus +## @item if verbosity(1) != 0, information on the progress +## of the algorithm are output at runtime +## @item if verbosity(2) != 0, the plot of the variables whose names +## are listed in @var{pltvars} is +## produced after the computation +## @end itemize +## +## The optional output @var{niter} returns the number of Newton iterations +## needed to reach convergence. +## +## @seealso{tst_backward_euler,tst_daspk,tst_odepkg,nls_newton_raphson} +## +## @end deftypefn + +function [out, varargout] = tst_theta_method(outstruct,x,t,tol,maxit,\ + theta,pltvars,verbosity) + + ## Check input + ## FIXME: add input check! + if ((nargin < 7) || (nargin > 8)) + error("tst_theta_method: wrong number of input parameters."); + endif + + if ~exist("verbosity") + verbosity = [0,0]; + elseif length(verbosity)<2 + verbosity(2) = 0; + endif + + out = zeros(rows(x),columns(t)); + out(:,1) = x; + + if nargout > 1 + niter = zeros(length(t),1); + endif + + if (verbosity(1)) + fprintf(1,"Initial value.\n"); + endif + + + [A0,B,C] = asm_initialize_system(outstruct,x); + + [out(:,1),ii] = nls_stationary(outstruct,x,tol,maxit); + + if nargout > 1 + niter(1) = ii; + endif + + for it=2:length(t) + + if(verbosity) + fprintf(1,"Timestep #%d.\n",it); + endif + + + [A1old,Jacold,resold] = asm_build_system(outstruct, out(:,it-1), t(it-1)); + + JAC = @(x,A1,Jac,res) TSTTHETAFUNJAC1(outstruct, x, t(it-1), + t(it), A0, B, theta, + A1, Jac, res); + RES = @(x,A1,Jac,res) TSTTHETAFUNRES1(outstruct, x, out(:,it-1), + t(it-1), t(it), A0, B, C, + resold, theta, A1, Jac, res); + UPDT = @(x) TSTTHETAFUNUP1 (outstruct, x, t(it)); + + [out(:,it),ii,resnrm] = nls_newton_raphson(out(:,it-1),RES,JAC,\ + tol, maxit,verbosity(1),\ + UPDT); + + if nargout > 1 + niter(it) = ii; + endif + + if (verbosity(2)) + utl_plot_by_name(t(1:it),out(:,1:it),outstruct,pltvars); + pause(.1); + endif + + if exist("~/.stop_ocs","file") + break + end + endfor + + if nargout > 1 + varargout{1} = niter; + endif + +endfunction + +## Jacobian for transient problem +function lhs = TSTTHETAFUNJAC1(outstruct, x, t0, t1, A0, B, theta, A1, Jac, res) + + DT = t1-t0; + if ( nargin < 10 ) + [A1,Jac,res] = asm_build_system(outstruct,x,t1); + endif + lhs = ( (A0+A1)/DT + theta*(B + Jac) ); + +endfunction +## Residual for transient problem +function rhs = TSTTHETAFUNRES1(outstruct, x, xold, t0, t1, A0, B, C, + resold, theta, A1, Jac, res) + DT = t1-t0; + if ( nargin < 13 ) + [A1,Jac,res] = asm_build_system(outstruct,x,t1); + endif + rhs = ( (A1+A0)*(x-xold)/DT + theta * (res + C + B*x) + + (1-theta) * (resold + C + B*xold) ); + +endfunction +## Update for transient problem +function update = TSTTHETAFUNUP1(outstruct,x,t1) + + [A1,Jac,res] = asm_build_system(outstruct,x,t1); + update = {A1,Jac,res}; + +endfunction \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/extra/ocs/inst/utl/utl_plot_by_name.m Tue Feb 09 07:43:42 2010 +0000 @@ -0,0 +1,58 @@ +## Copyright (C) 2006,2007,2008 Carlo de Falco +## +## This file is part of: +## OCS - A Circuit Simulator for Octave +## +## OCS is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program (see the file LICENSE); if not, +## see <http://www.gnu.org/licenses/>. +## +## author: Carlo de Falco <cdf _AT_ users.sourceforge.net> + +## -*- texinfo -*- +## @deftypefn{Function File} {} utl_plot_by_name(@var{t},@var{out}, @ +## @var{outstruct},@var{namelist}) +## +## Select by name some elements of the state vector of the system described +## by @var{outstruct} and plot their dynamics over the time interval +## @var{t}. +## +## @var{namelist} should contain the list of names of the variables +## to plot. +## @var{out} should be the output of a transient simulation over the +## time interval @var{t} +## +## @seealso{tst_backward_euler,tst_daspk,tst_theta_method,tst_odepkg,prs_iff} +## +## @end deftypefn + +function utl_plot_by_name(t,out,outstruct,namelist) + + if nargin != 4 + error("utl_plot_by_name: wrong number of input parameters.") + endif + + nn = length(outstruct.namesn); + + for ip = 1:nn + for in = 1:length(namelist) + if strcmp(namelist{in},outstruct.namess{ip}) + plot(t,out(outstruct.namesn(ip),:),\ + [sprintf('%d',mod(in+1,6)+1) ";" outstruct.namess{ip} ";"]); + hold on + endif + endfor + endfor + + hold off + +endfunction \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/extra/ocs/inst/utl/utl_sbn_server.m Tue Feb 09 07:43:42 2010 +0000 @@ -0,0 +1,96 @@ +## Copyright (C) 2006,2007,2008 Carlo de Falco +## +## This file is part of: +## OCS - A Circuit Simulator for Octave +## +## OCS is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program (see the file LICENSE); if not, +## see <http://www.gnu.org/licenses/>. +## +## author: Carlo de Falco <cdf _AT_ users.sourceforge.net> + +## -*- texinfo -*- +## @deftypefn{Function File} {} utl_sbn_server(@var{port}) +## Listen for socket connections on port @var{port}, read a command @ +## and return the corresponding output to the socket. +## @end deftypefn + +function utl_sbn_server (portnum) + + QUITMESSAGE = "quit UTLsbnserver"; + CONFIRMMESSAGE = "confirmed"; + + ## CREATE THE SOCKET AND WAIT FOR CONNECTIONS + s = socket(AF_INET, SOCK_STREAM, 0); + if s < 0 + error("cannot create socket\n"); + end + + if bind(s, portnum) < 0 + error("bind failed\n"); + end + + if listen(s, 1) < 0 + error("listen failed\n"); + end + + ##MAIN LOOP + while 1 + + ##ACCEPT CONNECTIONS + c = accept(s); + if c < 0 + error("connection error") + end + + ## READ COMMANDS FROM THE SOCKET + msg = readstring (c) + + ##IF CLIENT SENT SHUTDOWN MESSAGE EXIT + if strcmp (msg,QUITMESSAGE) + printf("client requested server shutdown, goodbye!\n"); + disconnect(c); disconnect(s); + break + end + + ##EXECUTE COMMANDS FROM THE CLIENT + [A,B,C] = eval(msg); + + ##SEND OUTPUT TO THE CLIENT + str = [ sprintf("%17g ",A) "\n" sprintf("%17g ",B)... + "\n" sprintf("%17g ",C) "\n"] + + send(c,str); + + ##END CONNECTION + disconnect(c); + + end + + disconnect(s); +endfunction + + +function msg = readstring (c) + + BUFFER_SIZE = 255; + + msg = ''; + read = BUFFER_SIZE; + + while read >= BUFFER_SIZE + newmsg = char(recv(c, BUFFER_SIZE)); + read = length(newmsg) + msg = [ msg newmsg]; + end + +endfunction