skill
EDA Skillpack
Public Made by Adomby adom
All skills for all EDA capabilities across the Adom ecosystem.
main
"""Analytical rectangle regression for the same sheet conductance stencil."""
from pathlib import Path
import sys,json
D=Path(__file__).resolve().parent;sys.path.insert(0,str(D/'vendor'))
import numpy as np
from scipy import sparse
from scipy.sparse.linalg import spsolve
rho=1.724e-8;t=35e-6;nx=101;ny=20;h=.1e-3;ids=np.arange(nx*ny).reshape(ny,nx);u=np.r_[ids[:,:-1].ravel(),ids[:-1].ravel()];v=np.r_[ids[:,1:].ravel(),ids[1:].ravel()];c=np.full(len(u),t/rho)
A=sparse.coo_matrix((np.r_[c,c,-c,-c],(np.r_[u,v,u,v],np.r_[u,v,v,u])),shape=(nx*ny,nx*ny)).tocsr();a=ids[:,0];b=ids[:,-1];free=np.setdiff1d(np.arange(nx*ny),np.r_[a,b]);V=np.zeros(nx*ny);V[a]=1;V[free]=spsolve(A[free][:,free],-A[free][:,a].sum(axis=1).A.ravel());I=(A@V)[a].sum();actual=1/I;expected=rho*((nx-1)*h)/(ny*h*t);e=abs(actual/expected-1);assert e<1e-9
out=dict(lengthBetweenTerminalCentersMm=(nx-1)*h*1e3,widthMm=ny*h*1e3,expectedOhm=expected,solvedOhm=actual,relativeError=e);(D/'dc-rectangle-benchmark.json').write_text(json.dumps(out,indent=2));print(out)