void retris(complex *data,complex *a,complex *c, complex *b, complex endl,complex endr, int nx, complex *d) { int ix; complex *e,den; complex *f; e=alloc1complex(nx); f=alloc1complex(nx); e[0]=cdiv(cneg(a[0]),endl); f[0]=cdiv(d[0],endl); for(ix=1;ix<nx-1;++ix){ den=cadd(b[ix],cmul(c[ix],e[ix-1])); e[ix]=cdiv(cneg(a[ix]),den); f[ix]=cdiv(csub(d[ix],cmul(f[ix-1],c[ix])),den); } data[nx-1]=cdiv(csub(d[nx-1],cmul(f[nx-2],c[nx-2])),cadd(endr,cmul(c[nx-2],e[nx-2]))); for(ix=nx-2;ix>-1;--ix) data[ix]=cadd(cmul(data[ix+1],e[ix]),f[ix]); free1complex(e); free1complex(f); return; }
/* c <- a - s*b, matrices */ void c_scalar_mult_sub_su3mat( su3_matrix *a, su3_matrix *b, complex *s, su3_matrix *c){ #ifndef NATIVEDOUBLE register int i,j; complex t; for(i=0;i<3;i++)for(j=0;j<3;j++){ t = cmul(&b->e[i][j], s); c->e[i][j] = csub(&a->e[i][j], &t); } #else register int i,j; register double sr,si,br,bi,cr,ci; sr = (*s).real; si = (*s).imag; for(i=0;i<3;i++)for(j=0;j<3;j++){ br=b->e[i][j].real; bi=b->e[i][j].imag; cr = sr*br - si*bi; ci = sr*bi + si*br; c->e[i][j].real = a->e[i][j].real - cr; c->e[i][j].imag = a->e[i][j].imag - ci; } #endif }
int fft_exec (int N, complex * in) { int flops; unsigned int n = N; unsigned int a, b, i, j, k, r, s; complex w, p; flops = 0; for (i = 1; i < N; i = i * 2) { n = n >> 1; for (k = 0; k < i; k++) { w = tableW[k]; r = 2 * n * k; s = n * (1 + 2 * k); for (j = 0; j < n; j++) { flops += 10; a = j + r; b = j + s; cmult (p, w, in[b]); //6 flop csub (in[b], in[a], p); //2 flop cadd (in[a], in[a], p); //2 flop } } } return flops; }
void fft_exec (int N, complex * in) { unsigned int n = N; unsigned int a, b, i, j, k, r, s; complex w, p; for (i = 1; i < N; i = i * 2) { n = n >> 1; for (k = 0; k < i; k++) { w = tableW[k]; r = 2 * n * k; s = n * (1 + 2 * k); for (j = 0; j < n; j++) { a = j + r/0; // An error b = j + s; cmult (p, w, in[b]); //6 flop csub (in[b], in[a], p); //2 flop cadd (in[a], in[a], p); //2 flop } } } }
void fft(Complex f[], int len, int t) { int i, j, k; Complex e, u, v; reverse(f, len); for (i = 2; i <= len; i <<= 1) { Complex wn; wn.real = cos(-t * 2 * pi / i); wn.image = sin(-t * 2 * pi / i); for (j = 0; j < len; j += i) { e.real = 1, e.image = 0; for (k = j; k < j + i / 2; k++) { u = f[k]; v = cmul(e, f[k+i/2]); f[k] = cadd(u, v); f[k+i/2] = csub(u, v); e = cmul(e, wn); } } } if (-1 == t) { for (i = 0; i < len; i++) f[i].real /= len; } }
void c_scalar_mult_sub_su3vec( su3_vector *v1, complex *phase, su3_vector *v2 ){ #ifndef NATIVEDOUBLE register int i; complex t; for(i=0;i<3;i++){ t = cmul(&v2->c[i],phase); v1->c[i] = csub(&v1->c[i],&t); } #else register int i; register double sr,si,br,bi,cr,ci; sr = (*phase).real; si = (*phase).imag; for(i=0;i<3;i++){ br=v2->c[i].real; bi=v2->c[i].imag; cr = sr*br - si*bi; ci = sr*bi + si*br; v1->c[i].real -= cr; v1->c[i].imag -= ci; } #endif }
int main () { int arg,cres,fres; printf ("Welcome to GNU libtool mixed C/Fortran demo!\n"); arg = 2; cres = csub (arg); printf ("The C subroutine returned, claiming that 2*%d = %d\n",arg,cres); if (cres == 2*arg) printf ("The C subroutine is ok!\n"); printf ("\nCalling the C wrapper routine...\n"); fres = fwrapper (arg); printf ("The C wrapper to the fortran subroutine returned,\n" "claiming that 2*%d = %d\n",arg,fres); if (fres == 2*arg) printf ("The Fortran subroutine is ok!\n"); return 0; }
main() { int n1,n2,j; float scale,sumz,sume; for (n1=1,n2=npfa(n1+1); n2<NMAX; n1=n2,n2=npfa(n1+1)) { for (j=0; j<n1*n2; j++) c[j] = z[j] = cmplx(franuni(),franuni()); pfamcc(1,n1,n2,1,n1,z); pfamcc(1,n2,n1,n1,1,z); pfamcc(-1,n1,n2,1,n1,z); pfamcc(-1,n2,n1,n1,1,z); scale = 1.0/(float)(n1*n2); for (j=0; j<n1*n2; j++) z[j] = crmul(z[j],scale); for (j=0,sumz=sume=0.0; j<n1*n2; j++) { sumz += fcabs(z[j]); sume += fcabs(csub(z[j],c[j])); } printf("n1 = %d n2 = %d sume/sumz = %0.10f\n", n1,n2,sume/sumz); if (sume/sumz>1.0e-6) printf("!!! warning !!!\n"); } }
UnArray * mxstr_toArray(const char *s){ if (s == NULL ) { THROW_D("NullPointerException"); } { int i,length = strlen(s); UnArray* arr = arr_create(1,0,0,&length,ARR_CHAR_TYPE); for (i=0;i<length;i++){ *csub(arr,i) = s[i]; } return arr; } }
double PPCA::err(){ // ||(I-QQ*)A|| alglib::complex_2d_array tmp; alglib::complex_2d_array tmp2; alglib::complex_2d_array Q_t; Q_t.setlength(Q.cols(), Q.rows()); alglib::cmatrixtranspose(Q.rows(), Q.cols(), Q, 0, 0, Q_t, 0, 0); tmp.setlength(Q_t.rows(), data.cols()); tmp2.setlength(Q.rows(), tmp.cols()); alglib::cmatrixgemm(Q_t.rows(), data.cols(), Q_t.cols(), 1.0, Q_t, 0, 0, 0, data, 0, 0, 0, 0, tmp, 0, 0); alglib::cmatrixgemm(Q.rows(), tmp.cols(), Q.cols(), 1.0, Q, 0, 0, 0, tmp, 0, 0, 0, 0, tmp2, 0, 0); return norm_L2(csub(data,tmp2)); }
void cgauj(Complex a[], int l, int m, int n, double eps) { int c, i, iw, j, k, mm1, *p, r, *work; double api, w, wmax; Complex pivot, *q, *q1, wk, wk1; if(l < n || m < 2 || m >= n || eps <= 0.) { fprintf(stderr, "Error : Illegal parameter in cgauj()\n"); return; } work = (int *)malloc(m * sizeof(int)); if(work == NULL) { fprintf(stderr, "Error : Out of memory in cgauj()\n"); return; } for(i = 0, p = work; i < m; i++) *p++ = i; for(k = 0; k < m; k++) { wmax = 0.; for(i = k; i < m; i++) { for(j = k, q = a + i * l + k; j < m; j++) { w = cabslt(*q++); if(w > wmax) { wmax = w; r = i; c = j; } } } pivot = *(a + r * l + c); api = cabslt(pivot); if(api < eps) { fprintf(stderr, "Error : api < eps in cgauj()\n"); free((char *)work); return; } if(c != k) { iw = *(work + k); *(work + k) = *(work + c); *(work + c) = iw; for(i = 0, q = a + i * l; i < m; i++, q += l) { wk = *(q + k); *(q + k) = *(q + c); *(q + c) = wk; } } if(r != k) { for(j = k; j < n; j++) { wk = *(a + r * l + j); *(a + r * l + j) = *(a + k * l + j); *(a + k * l + j) = wk; } } *(a + k * l + k) = tocomplex(1., 0.); for(i = k + 1, q = a + k * l + k + 1; i < n; i++, q++) *q = cdiv(*q, pivot); for(i = 0; i < m; i++) { if(i != k) { wk = *(a + i * l + k); for(j = k; j < n; j++) { wk1 = cmul(wk, *(a + k * l + j)); *(a + i * l + j) = csub(*(a + i * l + j), wk1); } } } } mm1 = m - 1; for(i = 0; i < mm1; i++) { for(;;) { k = *(work + i); if(k == i) break; iw = *(work + k); *(work + k) = *(work + i); *(work + i) = iw; for(j = m, q = a + k * l + m, q1 = a + i * l + m; j < n; j++) { wk = *q; *q++ = *q1; *q1++ = wk; } } } free((char *)work); return; }
static long convert(struct cvtRecord *pcvt) { double value; if (pcvt->iaom) { value = pcvt->iaov; } else { switch (pcvt->meth) { case menuCvtMethodLinear: { value = pcvt->x * pcvt->xslo + pcvt->y * pcvt->yslo + pcvt->voff; break; } case menuCvtMethodSubroutine: { cvt_subroutine *csub = (cvt_subroutine *)pcvt->csub; if (!csub) { goto error; } value = csub(pcvt->x, pcvt->y, &pcvt->dpvt); break; } case menuCvtMethod1DTable: { csm_function *csub = (csm_function *)pcvt->csub; if (!csub) { goto error; } value = csm_y(csub, pcvt->x); break; } case menuCvtMethod1DTableInverted: { csm_function *csub = (csm_function *)pcvt->csub; if (!csub) { goto error; } value = csm_x(csub, pcvt->y); break; } case menuCvtMethod2DTable: { csm_function *csub = (csm_function *)pcvt->csub; if (!csub) { goto error; } value = csm_z(csub, pcvt->x, pcvt->y); break; } default: { errmsg("internal error: METH is not a member of menuCvtMethod"); goto error; } } } /* check drive limits */ if (pcvt->drvh > pcvt->drvl) { if (value > pcvt->drvh) value = pcvt->drvh; else if (value < pcvt->drvl) value = pcvt->drvl; } pcvt->val = value; pcvt->udf = FALSE; return 0; error: recGblSetSevr(pcvt, SOFT_ALARM, INVALID_ALARM); return -1; }
int foo__Fi (int x) { return csub (x / 2); }
int main() { //malha geometrica TPZGeoMesh *firstmesh = new TPZGeoMesh; firstmesh->SetName("Malha Geometrica : Nós e Elementos"); firstmesh->NodeVec().Resize(4); TPZVec<REAL> coord(2),coordtrans(2); REAL ct,st,PI=3.141592654; cout << "\nEntre rotacao do eixo n1 (graus) -> "; REAL g; cin >> g; g = g*PI/180.; ct = cos(g); st = sin(g); //ct = 1.; //st = 0.; coord[0] = 0; coord[1] = 0; coordtrans[0] = ct*coord[0]-st*coord[1]; coordtrans[1] = st*coord[0]+ct*coord[1]; //nos geometricos firstmesh->NodeVec()[0].Initialize(coordtrans,*firstmesh); coord[0] = 5; coordtrans[0] = ct*coord[0]-st*coord[1]; coordtrans[1] = st*coord[0]+ct*coord[1]; firstmesh->NodeVec()[1].Initialize(coordtrans,*firstmesh); coord[0] = 5; coord[1] = 5; coordtrans[0] = ct*coord[0]-st*coord[1]; coordtrans[1] = st*coord[0]+ct*coord[1]; firstmesh->NodeVec()[2].Initialize(coordtrans,*firstmesh); coord[0] = 0; coordtrans[0] = ct*coord[0]-st*coord[1]; coordtrans[1] = st*coord[0]+ct*coord[1]; firstmesh->NodeVec()[3].Initialize(coordtrans,*firstmesh); /* TPZVec<int> nodeindexes(3); nodeindexes[0] = 0; nodeindexes[1] = 1; nodeindexes[2] = 2; //elementos geometricos TPZGeoElT2d *elg0 = new TPZGeoElT2d(nodeindexes,1,*firstmesh); nodeindexes[0] = 0; nodeindexes[1] = 2; nodeindexes[2] = 3; TPZGeoElT2d *elg1 = new TPZGeoElT2d(nodeindexes,1,*firstmesh); nodeindexes[0] = 0; nodeindexes[1] = 1; nodeindexes[2] = 2; TPZGeoElT2d *elg2 = new TPZGeoElT2d(nodeindexes,2,*firstmesh); nodeindexes[0] = 0; nodeindexes[1] = 2; nodeindexes[2] = 3; TPZGeoElT2d *elg3 = new TPZGeoElT2d(nodeindexes,2,*firstmesh); */ TPZVec<int> nodeindexes(4); nodeindexes[0] = 0; nodeindexes[1] = 1; nodeindexes[2] = 2; nodeindexes[3] = 3; //elementos geometricos TPZGeoEl *elg0 = new TPZGeoElQ2d(nodeindexes,1,*firstmesh); TPZGeoEl *elg1 = new TPZGeoElQ2d(nodeindexes,2,*firstmesh); TPZGeoEl *elg2 = new TPZGeoElQ2d(nodeindexes,3,*firstmesh); //Arquivos de saida ofstream outgm1("outgm1.dat"); ofstream outcm1("outcm1.dat"); ofstream outcm2("outcm2.dat"); //montagem de conectividades entre elementos firstmesh->BuildConnectivity(); //malha computacional TPZCompMesh *secondmesh = new TPZCompMesh(firstmesh); secondmesh->SetName("Malha Computacional : Conectividades e Elementos"); //material TPZMaterial *pl = LerMaterial("placa1.dat"); secondmesh->InsertMaterialObject(pl); pl = LerMaterial("placa2.dat"); secondmesh->InsertMaterialObject(pl); pl = LerMaterial("placa3.dat"); secondmesh->InsertMaterialObject(pl); //CC : condicões de contorno TPZBndCond *bc; REAL big = 1.e12; TPZFMatrix val1(6,6,0.),val2(6,1,0.); val1(0,0)=big; val1(1,1)=big; val1(2,2)=big; val1(3,3)=0.; val1(4,4)=0.; val1(5,5)=0.; TPZGeoElBC(elg0,5,-2,*firstmesh); bc = pl->CreateBC(-2,2,val1,val2); secondmesh->InsertMaterialObject(bc); TPZGeoElBC(elg0,6,-3,*firstmesh); bc = pl->CreateBC(-3,2,val1,val2); secondmesh->InsertMaterialObject(bc); val1(0,0)=0.; val1(1,1)=big; val1(2,2)=0.; val1(3,3)=big; val1(4,4)=0.; val1(5,5)=0.; TPZGeoElBC(elg0,4,-1,*firstmesh); bc = pl->CreateBC(-1,2,val1,val2); secondmesh->InsertMaterialObject(bc); val1(0,0)=big; val1(1,1)=0.; val1(2,2)=0.; val1(3,3)=0.; val1(4,4)=big; val1(5,5)=0.; TPZGeoElBC(elg0,7,-4,*firstmesh); bc = pl->CreateBC(-4,2,val1,val2); secondmesh->InsertMaterialObject(bc); //ordem de interpolacao int ord; cout << "Entre ordem 1,2,3,4,5 : "; cin >> ord; // TPZCompEl::gOrder = ord; cmesh.SetDefaultOrder(ord); //construção malha computacional TPZVec<int> csub(0); TPZManVector<TPZGeoEl *> pv(4); int n1=1,level=0; cout << "\nDividir ate nivel ? "; int resp; cin >> resp; int nelc = firstmesh->ElementVec().NElements(); int el; TPZGeoEl *cpel; for(el=0;el<firstmesh->ElementVec().NElements();el++) { cpel = firstmesh->ElementVec()[el]; if(cpel && cpel->Level() < resp) cpel->Divide(pv); } //analysis secondmesh->AutoBuild(); secondmesh->AdjustBoundaryElements(); secondmesh->InitializeBlock(); secondmesh->Print(outcm1); TPZAnalysis an(secondmesh,outcm1); int numeq = secondmesh->NEquations(); secondmesh->Print(outcm1); outcm1.flush(); TPZVec<int> skyline; secondmesh->Skyline(skyline); TPZSkylMatrix *stiff = new TPZSkylMatrix(numeq,skyline); an.SetMatrix(stiff); an.Solver().SetDirect(ECholesky); secondmesh->SetName("Malha Computacional : Connects e Elementos"); // Posprocessamento an.Run(outcm2); TPZVec<char *> scalnames(5); scalnames[0] = "Mn1"; scalnames[1] = "Mn2"; scalnames[2] = "Sign1"; scalnames[3] = "Sign2"; scalnames[4] = "Deslocz"; TPZVec<char *> vecnames(0); char plotfile[] = "placaPos.pos"; char pltfile[] = "placaView.plt"; an.DefineGraphMesh(2, scalnames, vecnames, plotfile); an.Print("FEM SOLUTION ",outcm1); an.PostProcess(2); an.DefineGraphMesh(2, scalnames, vecnames, pltfile); an.PostProcess(2); firstmesh->Print(outgm1); outgm1.flush(); delete secondmesh; delete firstmesh; return 0; }
/* ==================================================================== */ int sci_csub(char *fname) { SciErr sciErr; int m1 = 0, n1 = 0; int *piAddressVarOne = NULL; double *pdVarOne = NULL; int iType1 = 0; int m2 = 0, n2 = 0; int *piAddressVarTwo = NULL; double *pdVarTwo = NULL; int iType2 = 0; int m_out = 0, n_out = 0; double dOut = 0.0; /* --> result = csub(3,8) /* check that we have only 2 input arguments */ /* check that we have only 1 output argument */ CheckInputArgument(pvApiCtx, 2, 2); CheckOutputArgument(pvApiCtx, 1, 1); /* get Address of inputs */ sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddressVarOne); if (sciErr.iErr) { printError(&sciErr, 0); return 0; } sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddressVarTwo); if (sciErr.iErr) { printError(&sciErr, 0); return 0; } /* check input type */ sciErr = getVarType(pvApiCtx, piAddressVarOne, &iType1); if (sciErr.iErr) { printError(&sciErr, 0); return 0; } if ( iType1 != sci_matrix ) { Scierror(999, _("%s: Wrong type for input argument #%d: A scalar expected.\n"), fname, 1); return 0; } sciErr = getVarType(pvApiCtx, piAddressVarTwo, &iType2); if (sciErr.iErr) { printError(&sciErr, 0); return 0; } if ( iType2 != sci_matrix ) { Scierror(999, _("%s: Wrong type for input argument #%d: A scalar expected.\n"), fname, 2); return 0; } /* get matrix */ sciErr = getMatrixOfDouble(pvApiCtx, piAddressVarOne, &m1, &n1, &pdVarOne); if (sciErr.iErr) { printError(&sciErr, 0); return 0; } sciErr = getMatrixOfDouble(pvApiCtx, piAddressVarTwo, &m2, &n2, &pdVarTwo); if (sciErr.iErr) { printError(&sciErr, 0); return 0; } /* check size */ if ( (m1 != n1) && (n1 != 1) ) { Scierror(999, _("%s: Wrong size for input argument #%d: A scalar expected.\n"), fname, 1); return 0; } if ( (m2 != n2) && (n2 != 1) ) { Scierror(999, _("%s: Wrong size for input argument #%d: A scalar expected.\n"), fname, 2); return 0; } /* call c function csub */ csub(&pdVarOne[0], &pdVarTwo[0], &dOut); /* create result on stack */ m_out = 1; n_out = 1; createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, m_out, n_out, &dOut); AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; ReturnArguments(pvApiCtx); return 0; }
int ChebyshevFilter::zplna() { cmplx r, cnum, cden, cwc, ca, cb, b4ac; double C; if( kind == 3 ) C = c; else C = wc; for( i=0; i<ARRSIZ; i++ ) { z[i].r = 0.0; z[i].i = 0.0; } nc = np; jt = -1; ii = -1; for( icnt=0; icnt<2; icnt++ ) { /* The maps from s plane to z plane */ do { ir = ii + 1; ii = ir + 1; r.r = zs[ir]; r.i = zs[ii]; switch( type ) { case 1: case 3: /* Substitute s - r = s/wc - r = (1/wc)(z-1)/(z+1) - r * * 1 1 - r wc ( 1 + r wc ) * = --- -------- ( z - -------- ) * z+1 wc ( 1 - r wc ) * * giving the root in the z plane. */ cnum.r = 1 + C * r.r; cnum.i = C * r.i; cden.r = 1 - C * r.r; cden.i = -C * r.i; jt += 1; cdiv( &cden, &cnum, &z[jt] ); if( r.i != 0.0 ) { /* fill in complex conjugate root */ jt += 1; z[jt].r = z[jt-1 ].r; z[jt].i = -z[jt-1 ].i; } break; case 2: case 4: /* Substitute s - r => s/wc - r * * z^2 - 2 z cgam + 1 * => ------------------ - r * (z^2 + 1) wc * * 1 * = ------------ [ (1 - r wc) z^2 - 2 cgam z + 1 + r wc ] * (z^2 + 1) wc * * and solve for the roots in the z plane. */ if( kind == 2 ) cwc.r = cbp; else cwc.r = c; cwc.i = 0.0; cmul( &r, &cwc, &cnum ); /* r wc */ csub( &cnum, &cone, &ca ); /* a = 1 - r wc */ cmul( &cnum, &cnum, &b4ac ); /* 1 - (r wc)^2 */ csub( &b4ac, &cone, &b4ac ); b4ac.r *= 4.0; /* 4ac */ b4ac.i *= 4.0; cb.r = -2.0 * cgam; /* b */ cb.i = 0.0; cmul( &cb, &cb, &cnum ); /* b^2 */ csub( &b4ac, &cnum, &b4ac ); /* b^2 - 4 ac */ csqrt( &b4ac, &b4ac ); cb.r = -cb.r; /* -b */ cb.i = -cb.i; ca.r *= 2.0; /* 2a */ ca.i *= 2.0; cadd( &b4ac, &cb, &cnum ); /* -b + sqrt( b^2 - 4ac) */ cdiv( &ca, &cnum, &cnum ); /* ... /2a */ jt += 1; cmov( &cnum, &z[jt] ); if( cnum.i != 0.0 ) { jt += 1; z[jt].r = cnum.r; z[jt].i = -cnum.i; } if( (r.i != 0.0) || (cnum.i == 0) ) { csub( &b4ac, &cb, &cnum ); /* -b - sqrt( b^2 - 4ac) */ cdiv( &ca, &cnum, &cnum ); /* ... /2a */ jt += 1; cmov( &cnum, &z[jt] ); if( cnum.i != 0.0 ) { jt += 1; z[jt].r = cnum.r; z[jt].i = -cnum.i; } } } /* end switch */ } while( --nc > 0 ); if( icnt == 0 ) { zord = jt+1; if( nz <= 0 ) { if( kind != 3 ) return(0); else break; } } nc = nz; } /* end for() loop */ return 0; }
int main() { //malha geometrica TPZGeoMesh *firstmesh = new TPZGeoMesh; firstmesh->SetName("Malha Geometrica : Nós e Elementos"); firstmesh->NodeVec().Resize(10); TPZVec<REAL> coord(2); //,coordtrans(2); // REAL ct,st,PI=3.141592654; // cout << "\nEntre rotacao do eixo n1 (graus) -> "; // REAL g; // cin >> g; // g = g*PI/180.; // ct = cos(g); // st = sin(g); //ct = 1.; //st = 0.; //nos geometricos //no 0 coord[0] = 0; coord[1] = 0; // coordtrans[0] = ct*coord[0]-st*coord[1]; // coordtrans[1] = st*coord[0]+ct*coord[1]; firstmesh->NodeVec()[0].Initialize(coord,*firstmesh); //no 1 coord[0] = 1.; coord[1] = 0; // coordtrans[0] = ct*coord[0]-st*coord[1]; // coordtrans[1] = st*coord[0]+ct*coord[1]; firstmesh->NodeVec()[1].Initialize(coord,*firstmesh); //no 2 coord[0] = 2.; coord[1] = 0.; // coordtrans[0] = ct*coord[0]-st*coord[1]; // coordtrans[1] = st*coord[0]+ct*coord[1]; firstmesh->NodeVec()[2].Initialize(coord,*firstmesh); //no 3 coord[0] = 3.; coord[1] = 0.; // coordtrans[0] = ct*coord[0]-st*coord[1]; // coordtrans[1] = st*coord[0]+ct*coord[1]; firstmesh->NodeVec()[3].Initialize(coord,*firstmesh); //no 4 coord[0] = 4; coord[1] = 0.; // coordtrans[0] = ct*coord[0]-st*coord[1]; // coordtrans[1] = st*coord[0]+ct*coord[1]; firstmesh->NodeVec()[4].Initialize(coord,*firstmesh); //no 5 coord[0] = 0; coord[1] = 1; // coordtrans[0] = ct*coord[0]-st*coord[1]; // coordtrans[1] = st*coord[0]+ct*coord[1]; firstmesh->NodeVec()[5].Initialize(coord,*firstmesh); //no 6 coord[0] = 1.; coord[1] = 1.; // coordtrans[0] = ct*coord[0]-st*coord[1]; // coordtrans[1] = st*coord[0]+ct*coord[1]; firstmesh->NodeVec()[6].Initialize(coord,*firstmesh); //no 7 coord[0] = 2.; coord[1] = 1.; // coordtrans[0] = ct*coord[0]-st*coord[1]; // coordtrans[1] = st*coord[0]+ct*coord[1]; firstmesh->NodeVec()[7].Initialize(coord,*firstmesh); //no 8 coord[0] = 3.; coord[1] = 1; // coordtrans[0] = ct*coord[0]-st*coord[1]; // coordtrans[1] = st*coord[0]+ct*coord[1]; firstmesh->NodeVec()[8].Initialize(coord,*firstmesh); //no 9 coord[0] = 4; coord[1] = 1; // coordtrans[0] = ct*coord[0]-st*coord[1]; // coordtrans[1] = st*coord[0]+ct*coord[1]; firstmesh->NodeVec()[9].Initialize(coord,*firstmesh); /* TPZVec<int> nodeindexes(3); nodeindexes[0] = 0; nodeindexes[1] = 1; nodeindexes[2] = 2; //elementos geometricos TPZGeoElT2d *elg0 = new TPZGeoElT2d(nodeindexes,1,*firstmesh); nodeindexes[0] = 0; nodeindexes[1] = 2; nodeindexes[2] = 3; TPZGeoElT2d *elg1 = new TPZGeoElT2d(nodeindexes,1,*firstmesh); nodeindexes[0] = 0; nodeindexes[1] = 1; nodeindexes[2] = 2; TPZGeoElT2d *elg2 = new TPZGeoElT2d(nodeindexes,2,*firstmesh); nodeindexes[0] = 0; nodeindexes[1] = 2; nodeindexes[2] = 3; TPZGeoElT2d *elg3 = new TPZGeoElT2d(nodeindexes,2,*firstmesh); */ TPZVec<int> nodeindexes(4); //elementos geometricos TPZGeoEl *elg[4]; nodeindexes[0] = 0; nodeindexes[1] = 1; nodeindexes[2] = 6; nodeindexes[3] = 5; elg[0] = new TPZGeoElQ2d(nodeindexes,1,*firstmesh); nodeindexes[0] = 1; nodeindexes[1] = 2; nodeindexes[2] = 7; nodeindexes[3] = 6; elg[1] = new TPZGeoElQ2d(nodeindexes,1,*firstmesh); nodeindexes[0] = 2; nodeindexes[1] = 3; nodeindexes[2] = 8; nodeindexes[3] = 7; elg[2] = new TPZGeoElQ2d(nodeindexes,1,*firstmesh); nodeindexes[0] = 3; nodeindexes[1] = 4; nodeindexes[2] = 9; nodeindexes[3] = 8; elg[3] = new TPZGeoElQ2d(nodeindexes,1,*firstmesh); //Arquivos de saida ofstream outgm1("outgm1.dat"); ofstream outcm1("outcm1.dat"); ofstream outcm2("outcm2.dat"); //montagem de conectividades entre elementos firstmesh->BuildConnectivity(); //malha computacional TPZCompMesh *secondmesh = new TPZCompMesh(firstmesh); secondmesh->SetName("Malha Computacional : Conectividades e Elementos"); //material TPZMaterial *pl = LerMaterial("flavio.dat"); secondmesh->InsertMaterialObject(pl); // pl = LerMaterial("placa2.dat"); // secondmesh->InsertMaterialObject(pl); // pl = LerMaterial("placa3.dat"); // secondmesh->InsertMaterialObject(pl); // carregamento hidrostatico no plano vertica xz pl->SetForcingFunction(PressaoHid); //CC : condicões de contorno TPZBndCond *bc; REAL big = 1.e12; TPZFMatrix val1(6,6,0.),val2(6,1,0.); // engastes nos lados 4 e 7 do elemento 0 TPZGeoElBC(elg[0],4,-2,*firstmesh); TPZGeoElBC(elg[0],7,-2,*firstmesh); // engaste no lado 4 do elemento 1 TPZGeoElBC(elg[1],4,-2,*firstmesh); // engaste no lado 4 do elemento 2 TPZGeoElBC(elg[2],4,-2,*firstmesh); // engaste no lado 4 do elemento 3 TPZGeoElBC(elg[3],4,-2,*firstmesh); // imposicao do valor zero associado a condicao -2 (engaste) bc = pl->CreateBC(-2,0,val1,val2); secondmesh->InsertMaterialObject(bc); // imposicao da condicao de simetria no lado 5 do elemento 4 val1(0,0)=big; val1(1,1)=0.; val1(2,2)=0.; val1(3,3)=0.; val1(4,4)=big; val1(5,5)=big; TPZGeoElBC(elg[3],5,-3,*firstmesh); bc = pl->CreateBC(-3,2,val1,val2); secondmesh->InsertMaterialObject(bc); //ordem de interpolacao int ord; cout << "Entre ordem 1,2,3,4,5 : "; cin >> ord; // TPZCompEl::gOrder = ord; firstmesh.SetDefaultOrder(order); //construção malha computacional TPZVec<int> csub(0); TPZManVector<TPZGeoEl *> pv(4); int n1=1,level=0; cout << "\nDividir ate nivel ? "; int resp; cin >> resp; int nelc = firstmesh->ElementVec().NElements(); int el; TPZGeoEl *cpel; for(el=0;el<firstmesh->ElementVec().NElements();el++) { cpel = firstmesh->ElementVec()[el]; if(cpel && cpel->Level() < resp) cpel->Divide(pv); } cout << "\nDividir o elemento esquerdo superior quantas vezes? "; cin >> resp; cpel = firstmesh->ElementVec()[0]; for(el=0; el<resp; el++) { cpel->Divide(pv); cpel = pv[3]; } //analysis secondmesh->AutoBuild(); firstmesh->Print(outgm1); outgm1.flush(); secondmesh->AdjustBoundaryElements(); secondmesh->InitializeBlock(); secondmesh->Print(outcm1); TPZAnalysis an(secondmesh,outcm1); int numeq = secondmesh->NEquations(); secondmesh->Print(outcm1); outcm1.flush(); TPZVec<int> skyline; secondmesh->Skyline(skyline); TPZSkylMatrix *stiff = new TPZSkylMatrix(numeq,skyline); an.SetMatrix(stiff); an.Solver().SetDirect(ECholesky); secondmesh->SetName("Malha Computacional : Connects e Elementos"); // Posprocessamento an.Run(outcm2); TPZVec<char *> scalnames(5); scalnames[0] = "Mn1"; scalnames[1] = "Mn2"; scalnames[2] = "Vn1"; scalnames[3] = "Vn2"; scalnames[4] = "Deslocz"; TPZVec<char *> vecnames(0); char plotfile[] = "placaPos.pos"; char pltfile[] = "placaView.plt"; an.DefineGraphMesh(2, scalnames, vecnames, plotfile); an.Print("FEM SOLUTION ",outcm1); an.PostProcess(3); an.DefineGraphMesh(2, scalnames, vecnames, pltfile); an.PostProcess(2); firstmesh->Print(outgm1); outgm1.flush(); delete secondmesh; delete firstmesh; return 0; }
void fft1x(Complex a[], int n, int iter, int flag) { int i, it, j, j1, j2, k, xp, xp2; double arg, sign, w; Complex d1, d2, *p, *q, t, ww; if(n < 2) { fprintf(stderr, "Error : n < 2 in fft1()\n"); return; } if(iter <= 0) { iter = 0; i = n; while((i /= 2) != 0) iter++; } j = 1; for(i = 0; i < iter; i++) j *= 2; if(n != j) { fprintf(stderr, "Error : n != 2 ^ k in fft1()\n"); return; } sign = (flag == 1)? 1.: -1.; xp2 = n; for(it = 0; it < iter; it++) { xp = xp2; xp2 = xp / 2; w = M_PI / xp2; for(k = 0; k < xp2; k++) { arg = k * w; ww = tocomplex(cos(arg), sign * sin(arg)); i = k - xp; for(j = xp, p = a + i + xp, q = a + i + xp + xp2; j <= n; j += xp, p += xp, q += xp) { t = csub(*p, *q); *p = cadd(*p, *q); *q = cmul(t, ww); } } } j1 = n / 2; j2 = n - 1; j = 1; for(i = 1, p = a; i <= j2; i++, p++) { if(i < j) swapx(p, a + j - 1); k = j1; while(k < j) { j -= k; k /= 2; } j += k; } if(flag == 0) return; w = n; for(i = 0, p = a; i < n; i++, p++) *p = cdiv1(*p, w); return; }