void check_copiar_y_comparar() { Arturo<int> mesa; int arturo = 10, cab1 = 1, cab2 = 2; mesa.sentarArturo(arturo); mesa.incorporarCaballero(cab1); mesa.incorporarCaballero(cab2); Arturo<int> mesa2(mesa); ASSERT_EQ(mesa.tamanio(), mesa2.tamanio()); ASSERT_EQ(to_s(mesa), "[ARTURO(10), 2, 1]"); ASSERT_EQ(to_s(mesa2), "[ARTURO(10), 2, 1]"); ASSERT(mesa==mesa2); mesa.expulsarCaballero(2); ASSERT(!(mesa==mesa2)); ASSERT_EQ(to_s(mesa), "[ARTURO(10), 1]"); ASSERT_EQ(to_s(mesa2), "[ARTURO(10), 2, 1]"); mesa.expulsarCaballero(1); mesa.expulsarCaballero(10); ASSERT(!(mesa==mesa2)); ASSERT_EQ(to_s(mesa), "[]"); ASSERT_EQ(to_s(mesa2), "[ARTURO(10), 2, 1]"); }
int MESAload(GENmodel *inModel, CKTcircuit *ckt) { MESAmodel *model = (MESAmodel*)inModel; MESAinstance *here; double capgd; double capgs; double cd; double cdhat = 0.0; double cdrain; double cdreq; double ceq; double ceqgd; double ceqgs; double cg; double cgd; double cgs; double cghat = 0.0; double arg; double earg; double delvds; double delvgd; double delvgs; double delvgspp=0; double delvgdpp=0; double evgd; double evgs; double gds; double geq; double ggd; double ggs; double gm; double ggspp=0; double cgspp=0; double ggdpp=0; double cgdpp=0; double vcrits; double vcritd; double vds=0; double vgd=0; double vgs=0; double vgspp=0; double vgdpp=0; double vgs1=0; double vgd1=0; double xfact; double temp; double vted; double vtes; double vtd; double vts; double von; double ccorr; int inverse=FALSE; int icheck; int ichk1; int error; double m; /* loop through all the models */ for( ; model != NULL; model = model->MESAnextModel ) { /* loop through all the instances of the model */ for (here = model->MESAinstances; here != NULL ; here=here->MESAnextInstance) { if (here->MESAowner != ARCHme) continue; /* * dc model parameters */ vcrits = here->MESAvcrits; vcritd = here->MESAvcritd; vtd = CONSTKoverQ * here->MESAtd; vts = CONSTKoverQ * here->MESAts; vted = model->MESAn*vtd; vtes = model->MESAn*vts; /* * initialization */ icheck = 1; if( ckt->CKTmode & MODEINITSMSIG) { vgs = *(ckt->CKTstate0 + here->MESAvgs); vgd = *(ckt->CKTstate0 + here->MESAvgd); vgspp = *(ckt->CKTstate0 + here->MESAvgspp); vgdpp = *(ckt->CKTstate0 + here->MESAvgdpp); } else if (ckt->CKTmode & MODEINITTRAN) { vgs = *(ckt->CKTstate1 + here->MESAvgs); vgd = *(ckt->CKTstate1 + here->MESAvgd); vgspp = *(ckt->CKTstate1 + here->MESAvgspp); vgdpp = *(ckt->CKTstate1 + here->MESAvgdpp); } else if ( (ckt->CKTmode & MODEINITJCT) && (ckt->CKTmode & MODETRANOP) && (ckt->CKTmode & MODEUIC) ) { vds = here->MESAicVDS; vgs = here->MESAicVGS; vgd = vgs-vds; vgspp = vgs; vgdpp = vgd; } else if ( (ckt->CKTmode & MODEINITJCT) && (here->MESAoff == 0) ) { vgs = -1; vgd = -1; vgspp = 0; vgdpp = 0; } else if( (ckt->CKTmode & MODEINITJCT) || ((ckt->CKTmode & MODEINITFIX) && (here->MESAoff))) { vgs = 0; vgd = 0; vgspp = 0; vgdpp = 0; } else { #ifndef PREDICTOR if(ckt->CKTmode & MODEINITPRED) { xfact = ckt->CKTdelta/ckt->CKTdeltaOld[2]; *(ckt->CKTstate0 + here->MESAvgs) = *(ckt->CKTstate1 + here->MESAvgs); vgs = (1+xfact) * *(ckt->CKTstate1 + here->MESAvgs) - xfact * *(ckt->CKTstate2 + here->MESAvgs); *(ckt->CKTstate0 + here->MESAvgspp) = *(ckt->CKTstate1 + here->MESAvgspp); vgspp = (1+xfact) * *(ckt->CKTstate1 + here->MESAvgspp) - xfact * *(ckt->CKTstate2 + here->MESAvgspp); *(ckt->CKTstate0 + here->MESAvgd) = *(ckt->CKTstate1 + here->MESAvgd); vgd = (1+xfact)* *(ckt->CKTstate1 + here->MESAvgd) - xfact * *(ckt->CKTstate2 + here->MESAvgd); *(ckt->CKTstate0 + here->MESAvgdpp) = *(ckt->CKTstate1 + here->MESAvgdpp); vgdpp = (1+xfact) * *(ckt->CKTstate1 + here->MESAvgdpp) - xfact * *(ckt->CKTstate2 + here->MESAvgdpp); *(ckt->CKTstate0 + here->MESAcg) = *(ckt->CKTstate1 + here->MESAcg); *(ckt->CKTstate0 + here->MESAcd) = *(ckt->CKTstate1 + here->MESAcd); *(ckt->CKTstate0 + here->MESAcgd) = *(ckt->CKTstate1 + here->MESAcgd); *(ckt->CKTstate0 + here->MESAcgs) = *(ckt->CKTstate1 + here->MESAcgs); *(ckt->CKTstate0 + here->MESAgm) = *(ckt->CKTstate1 + here->MESAgm); *(ckt->CKTstate0 + here->MESAgds) = *(ckt->CKTstate1 + here->MESAgds); *(ckt->CKTstate0 + here->MESAggs) = *(ckt->CKTstate1 + here->MESAggs); *(ckt->CKTstate0 + here->MESAggd) = *(ckt->CKTstate1 + here->MESAggd); *(ckt->CKTstate0 + here->MESAggspp) = *(ckt->CKTstate1 + here->MESAggspp); *(ckt->CKTstate0 + here->MESAcgspp) = *(ckt->CKTstate1 + here->MESAcgspp); *(ckt->CKTstate0 + here->MESAggdpp) = *(ckt->CKTstate1 + here->MESAggdpp); *(ckt->CKTstate0 + here->MESAcgdpp) = *(ckt->CKTstate1 + here->MESAcgdpp); } else { #endif /* PREDICTOR */ /* * compute new nonlinear branch voltages */ vgs = (*(ckt->CKTrhsOld+ here->MESAgatePrimeNode)- *(ckt->CKTrhsOld+here->MESAsourcePrimeNode)); vgd = (*(ckt->CKTrhsOld+here->MESAgatePrimeNode)- *(ckt->CKTrhsOld+here->MESAdrainPrimeNode)); vgspp = (*(ckt->CKTrhsOld+here->MESAgatePrimeNode)- *(ckt->CKTrhsOld+here->MESAsourcePrmPrmNode)); vgdpp = (*(ckt->CKTrhsOld+here->MESAgatePrimeNode)- *(ckt->CKTrhsOld+here->MESAdrainPrmPrmNode)); #ifndef PREDICTOR } #endif /* PREDICTOR */ delvgs=vgs - *(ckt->CKTstate0 + here->MESAvgs); delvgd=vgd - *(ckt->CKTstate0 + here->MESAvgd); delvds=delvgs - delvgd; delvgspp = vgspp - *(ckt->CKTstate0 + here->MESAvgspp); delvgdpp = vgdpp - *(ckt->CKTstate0 + here->MESAvgdpp); cghat= *(ckt->CKTstate0 + here->MESAcg) + *(ckt->CKTstate0 + here->MESAggd)*delvgd + *(ckt->CKTstate0 + here->MESAggs)*delvgs + *(ckt->CKTstate0 + here->MESAggspp)*delvgspp+ *(ckt->CKTstate0 + here->MESAggdpp)*delvgdpp; cdhat= *(ckt->CKTstate0 + here->MESAcd) + *(ckt->CKTstate0 + here->MESAgm)*delvgs + *(ckt->CKTstate0 + here->MESAgds)*delvds - *(ckt->CKTstate0 + here->MESAggd)*delvgd; /* * bypass if solution has not changed */ if((ckt->CKTbypass) && (!(ckt->CKTmode & MODEINITPRED)) && (fabs(delvgs) < ckt->CKTreltol*MAX(fabs(vgs), fabs(*(ckt->CKTstate0 + here->MESAvgs)))+ ckt->CKTvoltTol) ) if((fabs(delvgd) < ckt->CKTreltol*MAX(fabs(vgd), fabs(*(ckt->CKTstate0 + here->MESAvgd)))+ ckt->CKTvoltTol)) if((fabs(delvgspp) < ckt->CKTreltol*MAX(fabs(vgspp), fabs(*(ckt->CKTstate0 + here->MESAvgspp)))+ ckt->CKTvoltTol)) if((fabs(delvgdpp) < ckt->CKTreltol*MAX(fabs(vgdpp), fabs(*(ckt->CKTstate0 + here->MESAvgdpp)))+ ckt->CKTvoltTol)) if((fabs(cghat-*(ckt->CKTstate0 + here->MESAcg)) < ckt->CKTreltol*MAX(fabs(cghat), fabs(*(ckt->CKTstate0 + here->MESAcg)))+ ckt->CKTabstol)) if((fabs(cdhat-*(ckt->CKTstate0 + here->MESAcd)) < ckt->CKTreltol*MAX(fabs(cdhat), fabs(*(ckt->CKTstate0 + here->MESAcd)))+ ckt->CKTabstol)) { /* we can do a bypass */ vgs= *(ckt->CKTstate0 + here->MESAvgs); vgd= *(ckt->CKTstate0 + here->MESAvgd); vds= vgs-vgd; vgspp = *(ckt->CKTstate0 + here->MESAvgspp); vgdpp = *(ckt->CKTstate0 + here->MESAvgdpp); cg= *(ckt->CKTstate0 + here->MESAcg); cd= *(ckt->CKTstate0 + here->MESAcd); cgs= *(ckt->CKTstate0 + here->MESAcgs); cgd= *(ckt->CKTstate0 + here->MESAcgd); gm= *(ckt->CKTstate0 + here->MESAgm); gds= *(ckt->CKTstate0 + here->MESAgds); ggs= *(ckt->CKTstate0 + here->MESAggs); ggd= *(ckt->CKTstate0 + here->MESAggd); ggspp = *(ckt->CKTstate0 + here->MESAggspp); cgspp = *(ckt->CKTstate0 + here->MESAcgspp); ggdpp = *(ckt->CKTstate0 + here->MESAggdpp); cgdpp = *(ckt->CKTstate0 + here->MESAcgdpp); goto load; } /* * limit nonlinear branch voltages */ ichk1=1; vgs = DEVpnjlim(vgs,*(ckt->CKTstate0 + here->MESAvgs),vtes, vcrits, &icheck); vgd = DEVpnjlim(vgd,*(ckt->CKTstate0 + here->MESAvgd),vted, vcritd,&ichk1); if (ichk1 == 1) { icheck=1; } vgs = DEVfetlim(vgs,*(ckt->CKTstate0 + here->MESAvgs), here->MESAtVto); vgd = DEVfetlim(vgd,*(ckt->CKTstate0 + here->MESAvgd), here->MESAtVto); if(here->MESAsourcePrmPrmNode == here->MESAsourcePrimeNode) vgspp = vgs; if(here->MESAdrainPrmPrmNode == here->MESAdrainPrimeNode) vgdpp = vgd; } /* * determine dc current and derivatives */ vds = vgs-vgd; arg = -vgs*model->MESAdel/vts; earg = exp(arg); evgs = exp(vgs/vtes); ggs = here->MESAcsatfs*evgs/vtes+here->MESAggrwl*earg*(1-arg)+ckt->CKTgmin; cgs = here->MESAcsatfs*(evgs-1)+here->MESAggrwl*vgs*earg+ ckt->CKTgmin*vgs; cg = cgs; arg = -vgd*model->MESAdel/vtd; earg = exp(arg); evgd = exp(vgd/vted); ggd = here->MESAcsatfd*evgd/vted+here->MESAggrwl*earg*(1-arg)+ckt->CKTgmin; cgd = here->MESAcsatfd*(evgd-1)+here->MESAggrwl*vgd*earg+ ckt->CKTgmin*vgd; cg = cg+cgd; if(vds < 0) { vds = -vds; inverse = TRUE; } von = here->MESAtVto+model->MESAks*(*(ckt->CKTrhsOld+here->MESAsourcePrimeNode)-model->MESAvsg); if(model->MESAlevel == 2) mesa1(model,here,inverse?vgd:vgs,vds,von,&cdrain,&gm,&gds,&capgs,&capgd); else if(model->MESAlevel == 3) mesa2(model,here,inverse?vgd:vgs,vds,von,&cdrain,&gm,&gds,&capgs,&capgd); else if(model->MESAlevel == 4) mesa3(model,here,inverse?vgd:vgs,vds,von,&cdrain,&gm,&gds,&capgs,&capgd); if(inverse) { cdrain = -cdrain; vds = -vds; temp = capgs; capgs = capgd; capgd = temp; } /* * compute equivalent drain current source */ cd = cdrain - cgd; if ( (ckt->CKTmode & (MODETRAN|MODEINITSMSIG)) || ((ckt->CKTmode & MODETRANOP) && (ckt->CKTmode & MODEUIC)) ){ /* * charge storage elements */ vgs1 = *(ckt->CKTstate1 + here->MESAvgspp); vgd1 = *(ckt->CKTstate1 + here->MESAvgdpp); if(ckt->CKTmode & MODEINITTRAN) { *(ckt->CKTstate1 + here->MESAqgs) = capgs*vgspp; *(ckt->CKTstate1 + here->MESAqgd) = capgd*vgdpp; } *(ckt->CKTstate0+here->MESAqgs) = *(ckt->CKTstate1 + here->MESAqgs) + capgs*(vgspp-vgs1); *(ckt->CKTstate0+here->MESAqgd) = *(ckt->CKTstate1 + here->MESAqgd) + capgd*(vgdpp-vgd1); /* * store small-signal parameters */ if( (!(ckt->CKTmode & MODETRANOP)) || (!(ckt->CKTmode & MODEUIC)) ) { if(ckt->CKTmode & MODEINITSMSIG) { *(ckt->CKTstate0 + here->MESAqgs) = capgs; *(ckt->CKTstate0 + here->MESAqgd) = capgd; continue; /*go to 1000*/ } /* * transient analysis */ if(ckt->CKTmode & MODEINITTRAN) { *(ckt->CKTstate1 + here->MESAqgs) = *(ckt->CKTstate0 + here->MESAqgs); *(ckt->CKTstate1 + here->MESAqgd) = *(ckt->CKTstate0 + here->MESAqgd); } error = NIintegrate(ckt,&geq,&ceq,capgs,here->MESAqgs); if(error) return(error); ggspp = geq; cgspp = *(ckt->CKTstate0 + here->MESAcqgs); cg = cg + cgspp; error = NIintegrate(ckt,&geq,&ceq,capgd,here->MESAqgd); if(error) return(error); ggdpp = geq; cgdpp = *(ckt->CKTstate0 + here->MESAcqgd); cg = cg + cgdpp; cd = cd - cgdpp; if (ckt->CKTmode & MODEINITTRAN) { *(ckt->CKTstate1 + here->MESAcqgs) = *(ckt->CKTstate0 + here->MESAcqgs); *(ckt->CKTstate1 + here->MESAcqgd) = *(ckt->CKTstate0 + here->MESAcqgd); } } } /* * check convergence */ if( (!(ckt->CKTmode & MODEINITFIX)) | (!(ckt->CKTmode & MODEUIC))) { if( (icheck == 1) || (fabs(cghat-cg) >= ckt->CKTreltol* MAX(fabs(cghat),fabs(cg))+ckt->CKTabstol) || (fabs(cdhat-cd) > ckt->CKTreltol* MAX(fabs(cdhat),fabs(cd))+ckt->CKTabstol) ) { ckt->CKTnoncon++; } } *(ckt->CKTstate0 + here->MESAvgs) = vgs; *(ckt->CKTstate0 + here->MESAvgspp) = vgspp; *(ckt->CKTstate0 + here->MESAvgd) = vgd; *(ckt->CKTstate0 + here->MESAvgdpp) = vgdpp; *(ckt->CKTstate0 + here->MESAcg) = cg; *(ckt->CKTstate0 + here->MESAcd) = cd; *(ckt->CKTstate0 + here->MESAcgd) = cgd; *(ckt->CKTstate0 + here->MESAcgs) = cgs; *(ckt->CKTstate0 + here->MESAgm) = gm; *(ckt->CKTstate0 + here->MESAgds) = gds; *(ckt->CKTstate0 + here->MESAggs) = ggs; *(ckt->CKTstate0 + here->MESAggd) = ggd; *(ckt->CKTstate0 + here->MESAggspp) = ggspp; *(ckt->CKTstate0 + here->MESAcgspp) = cgspp; *(ckt->CKTstate0 + here->MESAggdpp) = ggdpp; *(ckt->CKTstate0 + here->MESAcgdpp) = cgdpp; /* * load current vector */ load: m = here->MESAm; ccorr = model->MESAag*(cgs-cgd); ceqgd = cgd + cgdpp - ggd*vgd - ggdpp*vgdpp; ceqgs = cgs + cgspp - ggs*vgs - ggspp*vgspp; cdreq=((cd+cgd+cgdpp)-gds*vds-gm*vgs); *(ckt->CKTrhs + here->MESAgatePrimeNode) += m * (-ceqgs-ceqgd); ceqgd = (cgd-ggd*vgd); *(ckt->CKTrhs + here->MESAdrainPrimeNode) += m * (-cdreq+ceqgd+ccorr); ceqgd = (cgdpp-ggdpp*vgdpp); *(ckt->CKTrhs + here->MESAdrainPrmPrmNode) += ceqgd; ceqgs = (cgs-ggs*vgs); *(ckt->CKTrhs + here->MESAsourcePrimeNode) += m * (cdreq+ceqgs-ccorr); ceqgs = (cgspp-ggspp*vgspp); *(ckt->CKTrhs + here->MESAsourcePrmPrmNode) += ceqgs; /* * load y matrix */ *(here->MESAdrainDrainPtr) += m * (here->MESAdrainConduct); *(here->MESAsourceSourcePtr) += m * (here->MESAsourceConduct); *(here->MESAgateGatePtr) += m * (here->MESAgateConduct); *(here->MESAsourcePrmPrmSourcePrmPrmPtr) += m * (here->MESAtGi+ggspp); *(here->MESAdrainPrmPrmDrainPrmPrmPtr) += m * (here->MESAtGf+ggdpp); *(here->MESAgatePrimeGatePrimePtr) += m * (ggd+ggs+here->MESAgateConduct+ggspp+ggdpp); *(here->MESAdrainPrimeDrainPrimePtr) += m * (gds+ggd+here->MESAdrainConduct+here->MESAtGf); *(here->MESAsourcePrimeSourcePrimePtr) += m * (gds+gm+ggs+here->MESAsourceConduct+here->MESAtGi); *(here->MESAdrainDrainPrimePtr) -= m * (here->MESAdrainConduct); *(here->MESAdrainPrimeDrainPtr) -= m * (here->MESAdrainConduct); *(here->MESAsourceSourcePrimePtr) -= m * (here->MESAsourceConduct); *(here->MESAsourcePrimeSourcePtr) -= m * (here->MESAsourceConduct); *(here->MESAgateGatePrimePtr) -= m * (here->MESAgateConduct); *(here->MESAgatePrimeGatePtr) -= m * (here->MESAgateConduct); *(here->MESAgatePrimeDrainPrimePtr) -= m * (ggd); *(here->MESAgatePrimeSourcePrimePtr) -= m * (ggs); *(here->MESAdrainPrimeGatePrimePtr) += m * (gm-ggd); *(here->MESAdrainPrimeSourcePrimePtr) += m * (-gds-gm); *(here->MESAsourcePrimeGatePrimePtr) += m * (-ggs-gm); *(here->MESAsourcePrimeDrainPrimePtr) -= m * (gds); *(here->MESAsourcePrimeSourcePrmPrmPtr) -= m * (here->MESAtGi); *(here->MESAsourcePrmPrmSourcePrimePtr) -= m * (here->MESAtGi); *(here->MESAgatePrimeSourcePrmPrmPtr) -= m * (ggspp); *(here->MESAsourcePrmPrmGatePrimePtr) -= m * (ggspp); *(here->MESAdrainPrimeDrainPrmPrmPtr) -= m * (here->MESAtGf); *(here->MESAdrainPrmPrmDrainPrimePtr) -= m * (here->MESAtGf); *(here->MESAgatePrimeDrainPrmPrmPtr) -= m * (ggdpp); *(here->MESAdrainPrmPrmGatePrimePtr) -= m * (ggdpp); } } return(OK); }