double ov_matrix12x12_rowsumnorm(matrix12x12 A) { double norm, nrm; int i, j; norm = 0.0; for (i=0; i<12; i++) { nrm = 0.0; for (j=0; j<12; j++) nrm += cabs(A[i][j]); if (nrm > norm) norm = nrm; } return norm; }
// log and exponentiate should be equivalent static char *exact_log_test( void ) { GLU_complex A[ NCNC ] , Ua[ NCNC ] , eA[ NCNC ] ; // create a unitary matrix Sunitary_gen( Ua , 0 ) ; exact_log_slow( A , Ua ) ; exponentiate( eA , A ) ; int i ; GLU_bool is_ok = GLU_TRUE ; for( i = 0 ; i < NCNC ; i++ ) { if( cabs( eA[i] - Ua[i] ) > NC*PREC_TOL ) is_ok = GLU_FALSE ; } #if NC < 15 mu_assert( "[GLUnit] error : exact_log_slow is broken", is_ok ) ; #endif return 0 ; }
// Compute Real Cepstrum Of Signal void RealCepstrum(int n, float *signal, float *realCepstrum) { float *realTime, *imagTime, *realFreq, *imagFreq; int i; realTime = new float[n]; imagTime = new float[n]; realFreq = new float[n]; imagFreq = new float[n]; // Compose Complex FFT Input for(i = 0; i < n; i++) { realTime[i] = signal[i]; imagTime[i] = 0.0f; } // Perform DFT DFT(n, realTime, imagTime, realFreq, imagFreq); // Calculate Log Of Absolute Value for(i = 0; i < n; i++) { realFreq[i] = logf(cabs(realFreq[i], imagFreq[i])); imagFreq[i] = 0.0f; } // Perform Inverse FFT InverseDFT(n, realTime, imagTime, realFreq, imagFreq); // Output Real Part Of FFT for(i = 0; i < n; i++) realCepstrum[i] = realTime[i]; delete realTime; delete imagTime; delete realFreq; delete imagFreq; }
PetscErrorCode DiffIE(Vec originalVec, Vec reducedVec, Vec Distance, Vec nParticlePerCube) { // Find the distance between 2 solutions originalVec and reducedVec PetscInt s,t; PetscInt n,xstart,xend; PetscScalar tmp,v,diff; Vec vec; VecScatter scat; IS is; PetscFunctionBegin; VecGetOwnershipRange(originalVec,&xstart,&xend); VecGetSize(reducedVec,&n); VecCreate(PETSC_COMM_SELF,&vec); VecSetSizes(vec,PETSC_DECIDE,n); VecSetFromOptions(vec); ISCreateStride(PETSC_COMM_WORLD,n,0,1,&is); VecScatterCreate(reducedVec,PETSC_NULL,vec,is,&scat); //VecScatterCreateToAll(reducedVec,&scat,&vec); VecScatterBegin(scat,reducedVec,vec,INSERT_VALUES,SCATTER_FORWARD); VecScatterEnd(scat,reducedVec,vec,INSERT_VALUES,SCATTER_FORWARD); for(s=xstart;s<xend;s++) { t = ScatIE.FindCube(s); VecGetValues(vec,1,&t,&tmp); VecGetValues(originalVec,1,&s,&v); diff = cabs(v - tmp); VecSetValues(Distance,1,&t,&diff,ADD_VALUES); tmp = 1; VecSetValues(nParticlePerCube,1,&t,&tmp,ADD_VALUES); } VecDestroy(&vec); VecScatterDestroy(&scat); ISDestroy(&is); PetscFunctionReturn(0); }
/* writes a time-domain waveform to stdout as tab-separated values */ int output_td_waveform(REAL8TimeSeries * h_plus, REAL8TimeSeries * h_cross, struct params p) { double t0; size_t j; t0 = XLALGPSGetREAL8(&h_plus->epoch); if (p.amp_phase) { REAL8Sequence *amp = XLALCreateREAL8Sequence(h_plus->data->length); REAL8Sequence *phi = XLALCreateREAL8Sequence(h_plus->data->length); double phi0; /* compute the amplitude and phase of h+ - i hx */ for (j = 0; j < h_plus->data->length; ++j) { double complex z = h_plus->data->data[j] - I * h_cross->data->data[j]; amp->data[j] = cabs(z); phi->data[j] = carg(z); } /* unwrap the phase */ XLALREAL8VectorUnwrapAngle(phi, phi); /* make phase in range -pi to +pi at end of waveform */ /* extrapolate the end of the waveform using last and second last points */ phi0 = 2 * phi->data[phi->length - 1] - phi->data[phi->length - 2]; // phi0 = phi->data[phi->length - 1]; phi0 -= fmod(phi0 + copysign(LAL_PI, phi0), 2.0 * LAL_PI) - copysign(LAL_PI, phi0); for (j = 0; j < phi->length; ++j) phi->data[j] -= phi0; fprintf(stdout, "# time (s)\th_abs (strain)\t h_arg (rad)\n"); for (j = 0; j < h_plus->data->length; ++j) fprintf(stdout, "%.9f\t%e\t%e\n", t0 + j * h_plus->deltaT, amp->data[j], phi->data[j]); XLALDestroyREAL8Sequence(phi); XLALDestroyREAL8Sequence(amp); } else { fprintf(stdout, "# time (s)\th_+ (strain)\th_x (strain)\n"); for (j = 0; j < h_plus->data->length; ++j) fprintf(stdout, "%.9f\t%e\t%e\n", t0 + j * h_plus->deltaT, h_plus->data->data[j], h_cross->data->data[j]); } return 0; }
// calculates the inverse of the matrix M outputs to M_1 // int inverse( GLU_complex M_1[ NCNC ] , const GLU_complex M[ NCNC ] ) { #if (defined HAVE_LAPACKE_H) const int n = NC , lda = NC ; int ipiv[ NC + 1 ] ; memcpy( M_1 , M , NCNC * sizeof( GLU_complex ) ) ; int info = LAPACKE_zgetrf( LAPACK_ROW_MAJOR , n , n , M_1 , lda , ipiv ) ; info = LAPACKE_zgetri( LAPACK_ROW_MAJOR , n , M_1 , lda, ipiv ) ; return info ; #elif (defined CLASSICAL_ADJOINT_INV) // define the adjunct // GLU_complex adjunct[ NCNC ] GLUalign ; register GLU_complex deter = cofactor_transpose( adjunct , M ) ; // here we worry about numerical stability // if( cabs( deter ) < NC * PREC_TOL ) { fprintf( stderr , "[INVERSE] Matrix is singular !!! " "deter=%1.14e %1.14e \n" , creal( deter ) , cimag( deter ) ) ; write_matrix( M ) ; return GLU_FAILURE ; } // obtain inverse of M from 1/( detM )*adj( M ) // size_t i ; deter = 1.0 / deter ; for( i = 0 ; i < NCNC ; i++ ) { M_1[i] = adjunct[i] * deter ; } return GLU_SUCCESS ; #else #if NC == 2 // use the identity, should warn for singular matrices const double complex INV_detM = 1.0 / ( det( M ) ) ; M_1[ 0 ] = M[ 3 ] * INV_detM ; M_1[ 1 ] = -M[ 1 ] * INV_detM ; M_1[ 2 ] = -M[ 2 ] * INV_detM ; M_1[ 3 ] = M[ 0 ] * INV_detM ; return GLU_SUCCESS ; #else return gauss_jordan( M_1 , M ) ; #endif #endif }
static double_complex v_matrix_element(unsigned *total_num_eval, const struct integrand_params *params, double r_max, double abs_err, double rel_err, unsigned limit) { double est_err; unsigned num_eval; const double_complex integral = gk_cquad(integrand, params, 0, r_max, abs_err, rel_err, limit, &est_err, &num_eval); const double_complex element = 2 / M_PI * integral; if (!(est_err < dmax(abs_err, rel_err * cabs(integral)))) { fprintf(stderr, "WARNING: integral did not converge: " "%i evals; error is %g, required %g\n", num_eval, est_err, abs_err); fflush(stderr); } if (total_num_eval) *total_num_eval += num_eval; return element; }
double compute_mandelbrot(double _Complex c, int maxiter){ double _Complex z = 0; int value = 0; int diverge = 0; int n; for (n=0; n < maxiter; n++){ z = cpow (z, 2) + c; if (cabs(z) > 2){ value = n; diverge = 1; break; } } if (diverge == 1){ return value; } else{ return 2; } }
void CT_Freq_Res_mag(double *num,double *den,int N,int points,double *response,double Wmax) { double complex response_num[points]; double complex response_den[points]; double w; int i,j; double complex S; for(w=0,j=0;w< Wmax; w= w+(Wmax/points)){ S = 1; response_num[j] = 0; response_den[j] = 0; for(i=N-1;i>=0;i--){ response_num[j] += (num[i]*S); response_den[j] += (den[i]*S); S *= I*w; } response[j] = cabs(response_num[j]/response_den[j]); j++; } }
Signal::Signal() { value.resize(N); int n; for (n = 0; n < N; n++) { value[n] = A0 * cos(phase(n)) + A0 * sin(phase(n)) * _Complex_I; } ofstream infile; infile.open("fq.dat"); for (int n = 1; n < N; n++) { infile << (phase(n) - phase(n - 1)) / (Ts * 2 * M_PI) << " " << (n * Ts) << endl; frequency.push_back((phase(n) - phase(n - 1)) / (Ts * 2 * M_PI)); } infile.close(); infile.open("s.dat"); for (int n = 0; n < N; n++) { infile << cabs(value[n]) * cos(carg(value[n])) << " " << (n * Ts) << endl; } infile.close(); }
int main() { FILE *fp_r = fopen("Eth_r.txt", "r"); FILE *fp_i = fopen("Eth_i.txt", "r"); Complex datas[n]; memset(datas, 0, sizeof(Complex)*n); for(int j=0; j<1500; j++) { double rm, im; fscanf(fp_r, "%lf", &rm); fscanf(fp_i, "%lf", &im); datas[j] = rm + I*im; } printf("read file\n"); FILE *outR = fopen("re.txt", "w"); FILE *outI = fopen("im.txt", "w"); for(int i=0; i<1500; i++){ fprintf(outR, "%lf\n", creal(datas[i])); fprintf(outI, "%lf\n", cimag(datas[i])); } fclose(outR); fclose(outI); Complex *res = cdft(datas, n); FILE *fp = fopen("rest2.txt", "w"); for(int i=0; i<1500; i++) { fprintf(fp, "%lf\n", cabs(res[i]) / sqrt(n)); } free(res); fclose(fp); printf("finish\n"); return 0; }
int laguer(double complex a[], const int m, double complex *x, int *its, const int maxit) { int iter, i, j; double abx, abp, abm, err; double complex dx,x1,b,d,f,g,h,sq,gp,gm,g2; static double frac[MR+1] = {0.0,0.5,0.25,0.75,0.13,0.38,0.62,0.88,1.0}; for (iter = 1; iter <= maxit; iter++) { *its = iter; b = a[m]; err = cabs(b); d = 0.; f = 0.; abx = cabs(*x); for (j = m-1; j >= 0; j--) { f = (*x) * f + d; d = (*x) * d + b; b = (*x) * b + a[j]; err = cabs(b) + abx * err; } err *= epss; if (cabs(b) <= err) return(0); g = d / b; g2 = g * g; h = g2 - 2. * f / b; sq = csqrt((double)(m-1) * ((double)(m)*h - g2)); gp = g + sq; gm = g - sq; abp = cabs(gp); abm = cabs(gm); if (abp < abm) gp = gm; dx=((dmax(abp,abm) > 0. ? ((double complex)(m))/gp : (1. + abx)*(cos((double)iter) + _Complex_I*sin((double)iter)))); x1 = (*x) - dx; if (creal(*x) == creal(x1) && cimag(*x) == cimag(x1)) { return(0); } if (iter % MT) { *x=x1; } else { *x = (*x) - frac[iter/MT]*dx; } } fprintf(stderr, "Too many iterations in laguer\n"); return(-1); }
//Calculate noise buffer void noise_estimate(){ int i; float mag,s_factor; for (i=0;i<FFTLEN;i++) { s_factor=1; mag=cabs(buffer[i]); N_i[i] = M1[i]; if(N_i[i]>M2[i]){N_i[i]=M2[i];} if(N_i[i]>M3[i]){N_i[i]=M3[i];} if(N_i[i]>M4[i]){N_i[i]=M4[i];} SNR20=2-mag/N_i[i];//first order maclaurin SNR=SNR20*20; if(SNR>20){SNR=20;} if(SNR<0){SNR=0;} SNR_GAIN=-0.2*SNR+6; if(add1==1){ if(i<=2||(i>=30&&i<=223)||i>=253){s_factor=50;} } N[i]=SNR_GAIN*s_factor*alpha*(1-lpf_weight_noise)*N_i[i]+lpf_weight_noise*N[i]; } }
double complex cpow(double complex a, double complex z) { double complex w; double x, y, r, theta, absa, arga; x = creal(z); y = cimag(z); absa = cabs(a); if (absa == 0.0) { return (0.0 + 0.0 * I); } arga = carg(a); r = pow(absa, x); theta = x * arga; if (y != 0.0) { r = r * exp(-y * arga); theta = theta + y * log(absa); } w = r * cos(theta) + (r * sin(theta)) * I; return w; }
//Calculate noise buffer void noise_estimate(){ int i; float mag,s_factor; for (i=0;i<FFTLEN;i++) { s_factor=1; mag=cabs(buffer[i]); N_i[i] = M1[i]; if(N_i[i]>M2[i]){N_i[i]=M2[i];} if(N_i[i]>M3[i]){N_i[i]=M3[i];} if(N_i[i]>M4[i]){N_i[i]=M4[i];} SNR20=2-mag/N_i[i];//first order maclaurin SNR=SNR20*20; if(SNR>10){SNR=10;} if(SNR<-5){SNR=-5;} alpha=-0.2*SNR+5; if(add1==1){ if(i<=5||i>=80){s_factor=2;} } N[i]=s_factor*alpha*(1-lpf_weight_noise)*N_i[i]+lpf_weight_noise*N[i]; } }
// NOTE: S is both an input AND output. // Combines eigenspectra, fills S, but also computes the normalized absolute difference from what // was previously in S. This difference = || S_new - S_old ||/N is returned in diff. void combine_eig_spec( const fftw_complex *Sk, uint_t K, uint_t N, const double *wk, uint_t nwk, fftw_complex *S, double &diff){ uint_t iwt; //index of weight to use diff=0; double absdiff; fftw_complex Sl; for (uint_t ii=0; ii<N; ii++){ Sl=S[ii]; //stores previous value S[ii]=0; for ( uint_t jj=0; jj< K; jj++){ iwt=jj*nwk+(ii%nwk); S[ii]=S[ii]+wk[iwt]*Sk[jj*N+ii]; //weighted average } absdiff=cabs(S[ii]-Sl); //absolute difference diff=diff+absdiff; } diff=sqrt(diff)/N; }
void deconv(double g[], int lg, double f[], int lf, double out[], int row_len) { int ns = 0; cplx *g2 = pad_two(g, lg, &ns); cplx *f2 = pad_two(f, lf, &ns); fft(g2, ns); fft(f2, ns); cplx h[ns]; for (int i = 0; i < ns; i++) h[i] = g2[i] / f2[i]; fft(h, ns); for (int i = 0; i < ns; i++) { if (cabs(creal(h[i])) < 1e-10) h[i] = 0; } for (int i = 0; i > lf - lg - row_len; i--) out[-i] = h[(i + ns) % ns]/32; free(g2); free(f2); }
static void load_V_from_U(info_t *info, hisq_auxiliary_t *aux, ks_component_paths *ap1){ su3_matrix *U_link = aux->U_link; su3_matrix *V_link = aux->V_link; load_fatlinks(info, V_link, ap1, U_link); #ifdef MILC_GLOBAL_DEBUG #ifdef HISQ_REUNITARIZATION_DEBUG int i, idir; complex cdetV; FORALLSITES_OMP(i,s,private(idir,cdetV)) for(idir=XUP;idir<=TUP;idir++) { if( lattice[i].on_step_V[idir] < global_current_time_step ) { lattice[i].on_step_V[idir] = global_current_time_step; cdetV = det_su3( &(V_link[idir][i]) ); lattice[i].Vdet[idir] = cabs( &cdetV ); } } END_LOOP_OMP; #endif /* HISQ_REUNITARIZATION_DEBUG */ #endif /* MILC_GLOBAL_DEBUG */ }
static void accumulate(int const S1[], int const S2[], double C4[], double cr[], complex double ck[], fftw_plan dft, fftw_plan idct) { int i; /* use convolution theorem to compute correlation function */ /* compute the overlap field */ for (i = 0; i < N; i++) cr[i] = (1./N)*S1[i]*S2[i]; /* FT to k-space and square */ fftw_execute(dft); for (i = 0; i <= N/2; i++) cr[i] = pow(cabs(ck[i]), 2); /* FT back to real space */ fftw_execute(idct); for (i = 0; i < N/2; i++) C4[i] += cr[i]; }
//reduce noise using noise buffer void noise_reduction(){ int k; float a,b,gain; for (k=0;k<FFTLEN;k++) { P[k]=(1-lpf_weight)*cabs(buffer[k])+lpf_weight*P[k]; switch(gain_sel){ case 1://enhancement4 trial 1 a=lambda*N[k]/cabs(buffer[k]); b=1-N[k]/cabs(buffer[k]); break; case 2: a=lambda*P[k]/cabs(buffer[k]); b=1-N[k]/cabs(buffer[k]); break; case 3: a=lambda*N[k]/P[k]; b=1-N[k]/P[k]; break; case 4: a=lambda; b=1-N[k]/P[k]; break; case 5: //enhancement5 a=lambda; b=sqrt(1-N[k]*N[k]/cabs(cmul(buffer[k],buffer[k]))); break; default://no enhancement a=lambda; b=1-N[k]/cabs(buffer[k]); break; } gain=a; if(a<b){ gain=b; } buffer[k] = rmul(gain,buffer[k]); } ifft(FFTLEN,buffer); }
static void BLAS_zge_norm(enum blas_order_type order, enum blas_norm_type norm, int m, int n, const PLASMA_Complex64_t *a, int lda, double *res) { int i, j; float anorm, v; char rname[] = "BLAS_zge_norm"; if (order != blas_colmajor) BLAS_error( rname, -1, order, 0 ); if (norm == blas_frobenius_norm) { anorm = 0.0f; for (j = n; j; --j) { for (i = m; i; --i) { v = a[0]; anorm += v * v; a++; } a += lda - m; } anorm = sqrt( anorm ); } else if (norm == blas_inf_norm) { anorm = 0.0f; for (i = 0; i < m; ++i) { v = 0.0f; for (j = 0; j < n; ++j) { v += cabs( a[i + j * lda] ); } if (v > anorm) anorm = v; } } else { BLAS_error( rname, -2, norm, 0 ); return; } if (res) *res = anorm; }
static char *exponentiate_short_test( void ) { // Hermitian proj has been tested GLU_complex hHa[ HERMSIZE ] , Ha[ NCNC ] GLUalign ; GLU_complex hUa[ NCNC ] GLUalign , Ua[ NCNC ] GLUalign ; // create a unitary matrix Sunitary_gen( Ua , 0 ) ; // hermitian proj it Hermitian_proj( Ha , Ua ) ; Hermitian_proj_short( hHa , Ua ) ; exponentiate( Ua , Ha ) ; exponentiate( hUa , Ha ) ; GLU_bool is_ok = GLU_TRUE ; int i ; for( i = 0 ; i < NCNC ; i++ ) { if( cabs( Ua[i] - hUa[i] ) > PREC_TOL ) is_ok = GLU_FALSE ; } mu_assert( "[GLUnit] error : exponentiate_short is broken", is_ok ); return 0 ; }
PYMIC_KERNEL void pymic_offload_array_abs(const int64_t *dtype, const int64_t *n, const void *x_, void *r_) { /* pymic_offload_array_abs(int dtype, int n, type *x, type *result) */ size_t i; switch(*dtype) { case DTYPE_INT: { const int64_t *x = (const int64_t *)x_; int64_t *r = (int64_t *)r_; for (i = 0; i < *n; i++) { r[i] = labs(x[i]); } } break; case DTYPE_FLOAT: { const double *x = (const double *)x_; double *r = (double *)r_; for (i = 0; i < *n; i++) { r[i] = fabs(x[i]); } } break; case DTYPE_COMPLEX: { const double complex *x = (const double complex *)x_; double *r = (double *)r_; for (i = 0; i < *n; i++) { r[i] = cabs(x[i]); } } break; } }
static int calc_in( int col, int row ) { double x = col_to_x(col); double y = row_to_y(row); complex double z0 = x + y*I; complex double z = z0; char in = TRUE; for (int i=0; i<iter_max; i++) { if (cabs(z) > 16) { in = FALSE; break; } z = z*z + z0; } return in; }
// returns the square root of a complex number complex_double csqrt(complex_double c) { complex_double ret; real mag; if(c.im == 0) { if(c.re >= 0) { c.re = sqrt(c.re); } else { c.im = sqrt(-c.re); c.re = 0; } return c; } else { mag = cabs(c); ret.re = sqrt((c.re+mag)/2); ret.im = sqrt((-c.re+mag)/2); if( c.im < 0 ) { ret.im = -ret.im; } return ret; } }
void init_mandel(void) { mandel_surf = malloc(sizeof(Pixbuf)); mandel_surf->w = mandel_surf->h = 1024; mandel_surf->pitch = mandel_surf->w*sizeof(uint8_t); mandel_surf->bpp = 8; uint8_t *data = mandel_surf->data = malloc(mandel_surf->w * mandel_surf->h * sizeof(*data)); for(int y=0; y < mandel_surf->h; y++) { // TODO: speed this up (marching squares?) for(int x=0; x < mandel_surf->w; x++) { double complex z0 = x*2.0f/mandel_surf->w - 1.5f + (y*2.0f/mandel_surf->h - 1.0f)*I; double complex z = z0; // int i=0; while(cabs(z) < 2 && i < 1024) { int i=0; while(sqrd(cimag(z))+sqrd(creal(z)) < 4 && i < 128) { i++; z = z*z + z0; } //n + log2ln(R) – log2ln|z| float mu = (i + 1 - log2f(logf(cabs(z)))); data[y*mandel_surf->w + x] = 128*log2f(mu*(4.0f/128)+1); //data[y*mandel_surf->w + x] = (256*log2(i*32.0f/1024+1)/5); } } glPushAttrib(GL_TEXTURE_BIT); glGenTextures(1, &mandel_tex); glBindTexture(GL_TEXTURE_2D, mandel_tex); gluBuild2DMipmaps(GL_TEXTURE_2D, GL_LUMINANCE, mandel_surf->w, mandel_surf->h, GL_LUMINANCE, GL_UNSIGNED_BYTE, mandel_surf->data); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glPopAttrib(); }
int main(int argc, char **argv) { printf("starting...\n"); int nx =1001; int nz=1001; int k=5; double xmin=-5.0; double xmax = 5.0; double zmin=-5.0; double zmax = 5.0; double x,z; double dx=(xmax-xmin)/((double)(nx-1)); double dz = (zmax-zmin)/((double)(nz-1)); double m_ord=0; /*for cos(x+theta)^2 */ printf("declaring big vectors ...\n"); complex *U; complex *QUtest; complex *FQ; complex *QU; U = (complex *) malloc(nx*nz*sizeof(complex));printf("1 \n"); FQ = (complex *) malloc(nx*nz*k*sizeof(complex) );printf("2 \n"); QUtest = (complex *) malloc(nx*nz*sizeof(complex) );printf("3 \n"); QU = (complex *) calloc(nx*nz,sizeof(complex) );printf("4 \n");//initialize QU to zero using calloc int m,n,l; printf("variables set...\n"); /* U = (-4+4x^2+4z^2)*exp(-x^2 - z^2) */ for (m=0;m<nx;m++) { for (n=0;n<nz;n++) { x=xmin+m*dx; z=zmin+n*dz; //printf("%d",m*nz+n); U[m*nz+n]= (-4+4*x*x+4*z*z)*exp(-x*x-z*z); //U[m*nz+n]=exp(-pow(x,2)-pow(z,2)); } } /* for( m=0;m<nx;m++) { for(n=0;n<nz;n++) { printf("%3.3f ",creal(U[m*nz+n]));printf("+I %3.3f",cimag(U[m*nz+n]));printf(" "); } printf("\n"); } */ printf("setting U ok...\n"); // exit(0); /* Fourier Expansion of Q(x,z,theta)=cos(x+theta)^2, to construct a symbol */ for (l= -(k-1)/2;l <=(k-1)/2;l++) { printf("l= %d \n",l); for (m=0;m<nx;m++) { for (n=0;n<nz;n++) { x=xmin+m*dx; z=zmin+n*dz; /* if(l==0) FQ[(k-1)/2+l+k*(m*nz+n)]=0; else FQ[(k-1)/2+l+k*(m*nz+n)]=(0+I*1/2);*/ if (l ==-1 || l==1) FQ[(k-1)/2+l+k*(m*nz+n)]=0; if (l ==2 || l==-2) FQ[(k-1)/2+l+k*(m*nz+n)]=cpow(exp(1),I*l*x)/4.0;//cexp causing trouble use cpow instead! if (l==0) FQ[(k-1)/2+l+k*(m*nz+n)]=0.5; // printf("%3.3f ",creal(FQ[(k-1)/2+l+k*(m*nz+n)]));printf("+I %3.3f",cimag(FQ[(k-1)/2+l+k*(m*nz+n)]));printf(" "); }// printf("\n"); } } printf("setting FQ ok ... \n"); /* QUtest=2*(2*cos(x)^2*x^2-4*z*sin(x)*cos(x)*x+2*z^2-2*z%2*cos(x)^2-1)*exp(-x^2 - z^2) the derivative in x */ for (m=0;m<nx;m++) { for (n=0;n<nz;n++) { x=xmin+m*dx; z=zmin+n*dz; // QUtest[m*nz+n]=-2*x*exp(-pow(x,2)-pow(z,2)); QUtest[m*nz+n] = 2*(2*cos(x)*cos(x)*x*x-4*z*sin(x)*cos(x)*x+2*z*z-2*z*z*cos(x)*cos(x)-1)*exp(-x*x-z*z); } } printf("setting QUtest ok ...\n"); clock_t start,end; double elapsed; start = clock(); PsiDO(U,FQ,QU,nx,nz,k,dx,dz,m_ord); end=clock(); elapsed = ((double)(end-start))/CLOCKS_PER_SEC; printf(" time taken: %lf \n",elapsed); printf("PsiDO ok... \n"); double error=0; for (m=0;m<nx;m++) { for (n=0;n<nz;n++) { error = error + pow(cabs(QU[m*nz+n]-QUtest[m*nz+n]),2); } } double n_QUtest=0; for (m=0;m<nx;m++) { for (n=0;n<nz;n++) { n_QUtest = n_QUtest + pow(cabs(QUtest[m*nz+n]),2); } } printf("the relative error is %1.4e \n",pow(error/n_QUtest,0.5)); //cleaning free(U);free(FQ);free(QUtest);free(QU);//free(FQ1);free(FQ2); return; }
void decodeDTMF(char * filename) { const unsigned int n_samples=30000; unsigned int samplesize, i; SNDFILE * f; FILE *plotfile; SF_INFO info; short sample; unsigned int rn_samples; float sec; float complex x[n_samples], r[n_samples]; samplesize=0; samplesize=samplesize; for(i=0;i<n_samples;i++) { x[i] = 0.0 + _Complex_I*0.0; r[i] = 0.0 + _Complex_I*0.0; } f=sf_open(filename,SFM_READ,&info); if(f) { printf("Frames: %u\n",(unsigned int)info.frames); printf("Sample rate: %u\n",info.samplerate); printf("Channels: %u\n",info.channels); printf("Format: 0x%X\n",info.format); if((info.format & SF_FORMAT_WAV)==SF_FORMAT_WAV){ printf("Format: SF_FORMAT_WAV\n"); } if((info.format & SF_FORMAT_PCM_S8)==SF_FORMAT_PCM_S8){ printf("\tSigned 8 bit data\n"); } if((info.format & SF_FORMAT_PCM_U8)==SF_FORMAT_PCM_U8){ printf("\tUnsigned 8 bit data\n"); } if((info.format & SF_FORMAT_PCM_16)==SF_FORMAT_PCM_16){ printf("\tSigned 16 bit data\n"); samplesize=sizeof(int16_t); } if((info.format & SF_FORMAT_PCM_24)==SF_FORMAT_PCM_24){ printf("\tSigned 24 bit data\n"); } if((info.format & SF_FORMAT_PCM_32)==SF_FORMAT_PCM_32){ printf("\tSigned 32 bit data\n"); } if((info.format & SF_FORMAT_FLOAT)==SF_FORMAT_FLOAT){ printf("\t32 bit float data\n"); } if((info.format & SF_FORMAT_DOUBLE)==SF_FORMAT_DOUBLE){ printf("\t64 bit float data\n"); } printf("Sections: %u\n",info.sections); printf("Seekable: %u\n",info.seekable); rn_samples = info.samplerate / 1; sec = ((float)rn_samples)/((float)info.samplerate); printf("Seconds: %f\n",sec); printf("FPS: %f\n",1.0/sec); plotfile = fopen("dtmf_decode/plotfile.txt","w"); if(plotfile){ for(i=0;i<(rn_samples/10);i++) { sf_readf_short(f,&sample, 1); x[rn_samples-i] = (float)sample; /*fprintf(o,"%u\t%i\n",i,sample);*/ } for(i=0;i<(rn_samples/2);i++) { fft(&r[i],x,rn_samples,i); fprintf(plotfile,"%f\t%.10f\n",i/sec,(cabs(r[i])*(2.0/rn_samples))); } } sf_close(f); } }
int main(int argc,char *argv[]) { FILE *parameterfile=NULL,*rlxdfile=NULL, *countfile=NULL; char * filename = NULL; char datafilename[50]; char parameterfilename[50]; char gauge_filename[50]; char * nstore_filename = ".nstore_counter"; char * input_filename = NULL; int rlxd_state[105]; int j,ix,mu; int k; struct timeval t1; int g_nev, max_iter_ev; double stop_prec_ev; /* Energy corresponding to the Gauge part */ double eneg = 0., plaquette_energy = 0., rectangle_energy = 0.; /* Acceptance rate */ int Rate=0; /* Do we want to perform reversibility checks */ /* See also return_check_flag in read_input.h */ int return_check = 0; /* For getopt */ int c; /* For the Polyakov loop: */ int dir = 2; _Complex double pl, pl4; verbose = 0; g_use_clover_flag = 0; g_nr_of_psf = 1; #ifndef XLC signal(SIGUSR1,&catch_del_sig); signal(SIGUSR2,&catch_del_sig); signal(SIGTERM,&catch_del_sig); signal(SIGXCPU,&catch_del_sig); #endif while ((c = getopt(argc, argv, "h?f:o:")) != -1) { switch (c) { case 'f': input_filename = calloc(200, sizeof(char)); strcpy(input_filename,optarg); break; case 'o': filename = calloc(200, sizeof(char)); strcpy(filename,optarg); break; case 'h': case '?': default: usage(); break; } } if(input_filename == NULL){ input_filename = "hmc.input"; } if(filename == NULL){ filename = "output"; } /* Read the input file */ read_input(input_filename); mpi_init(argc, argv); if(Nsave == 0){ Nsave = 1; } if(nstore == -1) { countfile = fopen(nstore_filename, "r"); if(countfile != NULL) { fscanf(countfile, "%d\n", &nstore); fclose(countfile); } else { nstore = 0; } } if(g_rgi_C1 == 0.) { g_dbw2rand = 0; } #ifndef TM_USE_MPI g_dbw2rand = 0; #endif /* Reorder the mu parameter and the number of iterations */ if(g_mu3 > 0.) { g_mu = g_mu1; g_mu1 = g_mu3; g_mu3 = g_mu; j = int_n[1]; int_n[1] = int_n[3]; int_n[3] = j; j = g_csg_N[0]; g_csg_N[0] = g_csg_N[4]; g_csg_N[4] = j; g_csg_N[6] = j; if(fabs(g_mu3) > 0) { g_csg_N[6] = 0; } g_nr_of_psf = 3; } else if(g_mu2 > 0.) { g_mu = g_mu1; g_mu1 = g_mu2; g_mu2 = g_mu; int_n[3] = int_n[1]; int_n[1] = int_n[2]; int_n[2] = int_n[3]; /* For chronological inverter */ g_csg_N[4] = g_csg_N[0]; g_csg_N[0] = g_csg_N[2]; g_csg_N[2] = g_csg_N[4]; if(fabs(g_mu2) > 0) { g_csg_N[4] = 0; } g_csg_N[6] = 0; g_nr_of_psf = 2; } else { g_csg_N[2] = g_csg_N[0]; if(fabs(g_mu2) > 0) { g_csg_N[2] = 0; } g_csg_N[4] = 0; g_csg_N[6] = 0; } for(j = 0; j < g_nr_of_psf+1; j++) { if(int_n[j] == 0) int_n[j] = 1; } if(g_nr_of_psf == 3) { g_eps_sq_force = g_eps_sq_force1; g_eps_sq_force1 = g_eps_sq_force3; g_eps_sq_force3 = g_eps_sq_force; g_eps_sq_acc = g_eps_sq_acc1; g_eps_sq_acc1 = g_eps_sq_acc3; g_eps_sq_acc3 = g_eps_sq_acc; } if(g_nr_of_psf == 2) { g_eps_sq_force = g_eps_sq_force1; g_eps_sq_force1 = g_eps_sq_force2; g_eps_sq_force2 = g_eps_sq_force; g_eps_sq_acc = g_eps_sq_acc1; g_eps_sq_acc1 = g_eps_sq_acc2; g_eps_sq_acc2 = g_eps_sq_acc; } g_mu = g_mu1; g_eps_sq_acc = g_eps_sq_acc1; g_eps_sq_force = g_eps_sq_force1; #ifdef _GAUGE_COPY j = init_gauge_field(VOLUMEPLUSRAND + g_dbw2rand, 1); #else j = init_gauge_field(VOLUMEPLUSRAND + g_dbw2rand, 0); #endif if ( j!= 0) { fprintf(stderr, "Not enough memory for gauge_fields! Aborting...\n"); exit(0); } j = init_geometry_indices(VOLUMEPLUSRAND + g_dbw2rand); if ( j!= 0) { fprintf(stderr, "Not enough memory for geometry_indices! Aborting...\n"); exit(0); } j = init_spinor_field(VOLUMEPLUSRAND/2, NO_OF_SPINORFIELDS); if ( j!= 0) { fprintf(stderr, "Not enough memory for spinor fields! Aborting...\n"); exit(0); } j = init_bispinor_field(VOLUME/2, NO_OF_SPINORFIELDS); j = init_csg_field(VOLUMEPLUSRAND/2, g_csg_N); if ( j!= 0) { fprintf(stderr, "Not enough memory for csg fields! Aborting...\n"); exit(0); } j = init_moment_field(VOLUME, VOLUMEPLUSRAND); if ( j!= 0) { fprintf(stderr, "Not enough memory for moment fields! Aborting...\n"); exit(0); } zero_spinor_field(g_spinor_field[DUM_DERI+4],VOLUME/2); zero_spinor_field(g_spinor_field[DUM_DERI+5],VOLUME/2); zero_spinor_field(g_spinor_field[DUM_DERI+6],VOLUME/2); if(g_proc_id == 0){ /* fscanf(fp6,"%s",filename); */ /*construct the filenames for the observables and the parameters*/ strcpy(datafilename,filename); strcat(datafilename,".data"); strcpy(parameterfilename,filename); strcat(parameterfilename,".para"); parameterfile=fopen(parameterfilename, "w"); printf("# This is the hmc code for twisted Mass Wilson QCD\n\nVersion %s\n", Version); #ifdef SSE printf("# The code was compiled with SSE instructions\n"); #endif #ifdef SSE2 printf("# The code was compiled with SSE2 instructions\n"); #endif #ifdef SSE3 printf("# The code was compiled with SSE3 instructions\n"); #endif #ifdef P4 printf("# The code was compiled for Pentium4\n"); #endif #ifdef OPTERON printf("# The code was compiled for AMD Opteron\n"); #endif #ifdef _NEW_GEOMETRY printf("# The code was compiled with -D_NEW_GEOMETRY\n"); #endif #ifdef _GAUGE_COPY printf("# The code was compiled with -D_GAUGE_COPY\n"); #endif printf("# The lattice size is %d x %d x %d x %d\n", (int)(T*g_nproc_t), (int)(LX*g_nproc_x), (int)(LY), (int)(LZ)); printf("# The local lattice size is %d x %d x %d x %d\n", (int)(T), (int)(LX), (int)(LY),(int) LZ); printf("# beta = %f , kappa= %f\n", g_beta, g_kappa); printf("# mus = %f, %f, %f\n", g_mu1, g_mu2, g_mu3); printf("# int_n_gauge = %d, int_n_ferm1 = %d, int_n_ferm2 = %d, int_n_ferm3 = %d\n", int_n[0], int_n[1], int_n[2], int_n[3]); printf("# g_rgi_C0 = %f, g_rgi_C1 = %f\n", g_rgi_C0, g_rgi_C1); printf("# Number of pseudo-fermion fields: %d\n", g_nr_of_psf); printf("# g_eps_sq_force = %e, g_eps_sq_acc = %e\n", g_eps_sq_force, g_eps_sq_acc); printf("# Integration scheme: "); if(integtyp == 1) printf("leap-frog (single time scale)\n"); if(integtyp == 2) printf("Sexton-Weingarten (single time scale)\n"); if(integtyp == 3) printf("leap-frog (multiple time scales)\n"); if(integtyp == 4) printf("Sexton-Weingarten (multiple time scales)\n"); if(integtyp == 5) printf("higher order and leap-frog (multiple time scales)\n"); printf("# Using %s precision for the inversions!\n", g_relative_precision_flag ? "relative" : "absolute"); printf("# Using in chronological inverter for spinor_field 1,2,3 a history of %d, %d, %d, respectively\n", g_csg_N[0], g_csg_N[2], g_csg_N[4]); fprintf(parameterfile, "The lattice size is %d x %d x %d x %d\n", (int)(g_nproc_t*T), (int)(g_nproc_x*LX), (int)(LY), (int)(LZ)); fprintf(parameterfile, "The local lattice size is %d x %d x %d x %d\n", (int)(T), (int)(LX), (int)(LY), (int)(LZ)); fprintf(parameterfile, "g_beta = %f , g_kappa= %f, c_sw = %f \n",g_beta,g_kappa,g_c_sw); fprintf(parameterfile, "boundary of fermion fields (t,x,y,z): %f %f %f %f \n",X0,X1,X2,X3); fprintf(parameterfile, "EPS_SQ0=%e, EPS_SQ1=%e EPS_SQ2=%e, EPS_SQ3=%e \n" ,EPS_SQ0,EPS_SQ1,EPS_SQ2,EPS_SQ3); fprintf(parameterfile, "g_eps_sq_force = %e, g_eps_sq_acc = %e\n", g_eps_sq_force, g_eps_sq_acc); fprintf(parameterfile, "dtau=%f, Nsteps=%d, Nmeas=%d, Nsave=%d, integtyp=%d, nsmall=%d \n", dtau,Nsteps,Nmeas,Nsave,integtyp,nsmall); fprintf(parameterfile, "mu = %f, mu2=%f, mu3=%f\n ", g_mu, g_mu2, g_mu3); fprintf(parameterfile, "int_n_gauge = %d, int_n_ferm1 = %d, int_n_ferm2 = %d, int_n_ferm3 = %d\n ", int_n[0], int_n[1], int_n[2], int_n[3]); fprintf(parameterfile, "g_rgi_C0 = %f, g_rgi_C1 = %f\n", g_rgi_C0, g_rgi_C1); fprintf(parameterfile, "# Number of pseudo-fermion fields: %d\n", g_nr_of_psf); fprintf(parameterfile, "# Integration scheme: "); if(integtyp == 1) fprintf(parameterfile, "leap-frog (single time scale)\n"); if(integtyp == 2) fprintf(parameterfile, "Sexton-Weingarten (single time scale)\n"); if(integtyp == 3) fprintf(parameterfile, "leap-frog (multiple time scales)\n"); if(integtyp == 4) fprintf(parameterfile, "Sexton-Weingarten (multiple time scales)\n"); if(integtyp == 5) fprintf(parameterfile, "higher order and leap-frog (multiple time scales)\n"); fprintf(parameterfile, "Using %s precision for the inversions!\n", g_relative_precision_flag ? "relative" : "absolute"); fprintf(parameterfile, "Using in chronological inverter for spinor_field 1,2,3 a history of %d, %d, %d, respectively\n", g_csg_N[0], g_csg_N[2], g_csg_N[4]); fflush(stdout); fflush(parameterfile); } /* define the geometry */ geometry(); /* define the boundary conditions for the fermion fields */ boundary(); check_geometry(); if(g_proc_id == 0) { #if defined GEOMETRIC if(g_proc_id==0) fprintf(parameterfile,"The geometric series is used as solver \n\n"); #else if(g_proc_id==0) fprintf(parameterfile,"The BICG_stab is used as solver \n\n"); #endif fflush(parameterfile); } /* Continue */ if(startoption == 3){ rlxdfile = fopen(rlxd_input_filename,"r"); if(rlxdfile != NULL) { if(g_proc_id == 0) { fread(rlxd_state,sizeof(rlxd_state),1,rlxdfile); } } else { if(g_proc_id == 0) { printf("%s does not exist, switching to restart...\n", rlxd_input_filename); } startoption = 2; } fclose(rlxdfile); if(startoption != 2) { if(g_proc_id == 0) { rlxd_reset(rlxd_state); printf("Reading Gauge field from file %s\n", gauge_input_filename); fflush(stdout); } read_gauge_field_time_p(gauge_input_filename,g_gauge_field); } } if(startoption != 3){ /* Initialize random number generator */ if(g_proc_id == 0) { rlxd_init(1, random_seed); /* hot */ if(startoption == 1) { random_gauge_field(); } rlxd_get(rlxd_state); #ifdef TM_USE_MPI MPI_Send(&rlxd_state[0], 105, MPI_INT, 1, 99, MPI_COMM_WORLD); MPI_Recv(&rlxd_state[0], 105, MPI_INT, g_nproc-1, 99, MPI_COMM_WORLD, &status); rlxd_reset(rlxd_state); #endif } #ifdef TM_USE_MPI else { MPI_Recv(&rlxd_state[0], 105, MPI_INT, g_proc_id-1, 99, MPI_COMM_WORLD, &status); rlxd_reset(rlxd_state); /* hot */ if(startoption == 1) { random_gauge_field(); } k=g_proc_id+1; if(k==g_nproc){ k=0; } rlxd_get(rlxd_state); MPI_Send(&rlxd_state[0], 105, MPI_INT, k, 99, MPI_COMM_WORLD); } #endif /* Cold */ if(startoption == 0) { unit_g_gauge_field(); } /* Restart */ else if(startoption == 2) { if (g_proc_id == 0){ printf("Reading Gauge field from file %s\n", gauge_input_filename); fflush(stdout); } read_gauge_field_time_p(gauge_input_filename,g_gauge_field); } } /*For parallelization: exchange the gaugefield */ #ifdef TM_USE_MPI xchange_gauge(g_gauge_field); #endif #ifdef _GAUGE_COPY update_backward_gauge(); #endif /*compute the energy of the gauge field*/ plaquette_energy=measure_gauge_action(); if(g_rgi_C1 > 0. || g_rgi_C1 < 0.) { rectangle_energy = measure_rectangles(); if(g_proc_id==0){ fprintf(parameterfile,"#First rectangle value: %14.12f \n",rectangle_energy/(12.*VOLUME*g_nproc)); } } eneg = g_rgi_C0 * plaquette_energy + g_rgi_C1 * rectangle_energy; /* Measure and print the Polyakov loop: */ polyakov_loop(&pl, dir); if(g_proc_id==0){ fprintf(parameterfile,"#First plaquette value: %14.12f \n", plaquette_energy/(6.*VOLUME*g_nproc)); fprintf(parameterfile,"#First Polyakov loop value in %d-direction |L(%d)|= %14.12f \n", dir, dir, cabs(pl)); } dir=3; polyakov_loop(&pl, dir); if(g_proc_id==0){ fprintf(parameterfile,"#First Polyakov loop value in %d-direction |L(%d)|= %14.12f \n", dir, dir, cabs(pl)); fclose(parameterfile); } /* set ddummy to zero */ for(ix = 0; ix < VOLUME+RAND; ix++){ for(mu=0; mu<4; mu++){ ddummy[ix][mu].d1=0.; ddummy[ix][mu].d2=0.; ddummy[ix][mu].d3=0.; ddummy[ix][mu].d4=0.; ddummy[ix][mu].d5=0.; ddummy[ix][mu].d6=0.; ddummy[ix][mu].d7=0.; ddummy[ix][mu].d8=0.; } } if(g_proc_id == 0) { gettimeofday(&t1,NULL); countfile = fopen("history_hmc_tm", "a"); fprintf(countfile, "!!! Timestamp %ld, Nsave = %d, g_mu = %e, g_mu1 = %e, g_mu_2 = %e, g_mu3 = %e, beta = %f, kappa = %f, C1 = %f, int0 = %d, int1 = %d, int2 = %d, int3 = %d, g_eps_sq_force = %e, g_eps_sq_acc = %e, ", t1.tv_sec, Nsave, g_mu, g_mu1, g_mu2, g_mu3, g_beta, g_kappa, g_rgi_C1, int_n[0], int_n[1], int_n[2], int_n[3], g_eps_sq_force, g_eps_sq_acc); fprintf(countfile, "Nsteps = %d, dtau = %e, tau = %e, integtyp = %d, rel. prec. = %d\n", Nsteps, dtau, tau, integtyp, g_relative_precision_flag); fclose(countfile); } /* HERE THE CALLS FOR SOME EIGENVALUES */ /* for lowest g_nev = 10; */ /* for largest */ g_nev = 10; max_iter_ev = 1000; stop_prec_ev = 1.e-10; if(g_proc_id==0) { printf(" Values of mu = %e mubar = %e eps = %e precision = %e \n \n", g_mu, g_mubar, g_epsbar, stop_prec_ev); } eigenvalues(&g_nev, operator_flag, max_iter_ev, stop_prec_ev); g_nev = 4; max_iter_ev = 200; stop_prec_ev = 1.e-03; max_eigenvalues(&g_nev, operator_flag, max_iter_ev, stop_prec_ev); if(g_proc_id==0) { printf(" Values of mu = %e mubar = %e eps = %e precision = %e \n \n", g_mu, g_mubar, g_epsbar, stop_prec_ev); /* printf(" Values of mu = %e precision = %e \n \n", g_mu, stop_prec_ev); */ } /* END OF EIGENVALUES CALLS */ if(g_proc_id==0) { rlxd_get(rlxd_state); rlxdfile=fopen("last_state","w"); fwrite(rlxd_state,sizeof(rlxd_state),1,rlxdfile); fclose(rlxdfile); printf("Acceptance Rate was: %e Prozent\n", 100.*(double)Rate/(double)Nmeas); fflush(stdout); parameterfile = fopen(parameterfilename, "a"); fprintf(parameterfile, "Acceptance Rate was: %e Prozent\n", 100.*(double)Rate/(double)Nmeas); fclose(parameterfile); } #ifdef TM_USE_MPI MPI_Finalize(); #endif free_gauge_tmp(); free_gauge_field(); free_geometry_indices(); free_spinor_field(); free_bispinor_field(); free_moment_field(); return(0); }
void LUDecompositionComplex(long int run) { int k, i, m, j; unsigned int dimension; #if DEBUG int l; double complex temp_val; #endif dimension = circuit_simulation.number_of_nodes + circuit_simulation.group2_elements; if (circuit_simulation.matrix_sparsity == SPARSE) { if(run == 0) { printf( "\n\nLU Decomposition...\n\n" ); } Scomplex = cs_ci_sqr( 2, G2complex, 0 ); Ncomplex = cs_ci_lu( G2complex, Scomplex, 1 ); cs_ci_spfree( G2complex ); if (Ncomplex == NULL) { printf( "Error, the matrix cannot be inverted.\n\n" ); printf( "Terminating.\n" ); exit( -1 ); } } else { transposition = ( int * ) malloc( dimension * sizeof(int) ); if (transposition == NULL) { printf( "Could not allocate matrices.\n" ); printf( "Terminating.\n" ); exit( -1 ); } for (i = 0; i < dimension; i++) { transposition[i] = i; } if(run == 0) { printf( "\n\nLU Decomposition...\n\n" ); } for (k = 0; k < dimension - 1; k++) { for (m = i = k; i < dimension; i++) { if (cabs( matrix_Gcomplex[i * dimension + k] ) > cabs( matrix_Gcomplex[m * dimension + k] )) { m = i; } } interchangeComplex( m, k ); if (cabs( matrix_Gcomplex[k * dimension + k] ) == 0) { printf( "Error, the matrix cannot be inverted.\n\n" ); printf( "Terminating.\n" ); exit( -1 ); } for (i = k + 1; i < dimension; i++) { matrix_Gcomplex[i * dimension + k] /= matrix_Gcomplex[k * dimension + k]; for (j = k + 1; j < dimension; j++) { matrix_Gcomplex[i * dimension + j] += -matrix_Gcomplex[i * dimension + k] * matrix_Gcomplex[k * dimension + j]; } } } } #if DEBUG printf("\nLU Decomposition\n~~~~~~~~~~~~~~~~~\n\n"); printf("\nDecomposed Matrix:\n\n"); for(k = 0; k < dimension; k++) { for(l = 0; l < dimension; l++) { if(l == k) { printf(" \\\\"); } if (circuit_simulation.matrix_sparsity == SPARSE) { if(l >= k) { temp_val = getElementAtComplex(Ncomplex -> U, k, l); printf("(%7.3lf %7.3lfi) ", creal(temp_val), cimag(temp_val)); } else { temp_val = getElementAtComplex(Ncomplex -> L, k, l); printf("(%7.3lf %7.3lfi) ", creal(temp_val), cimag(temp_val)); } } else { printf("(%7.3lf %7.3lfi) ", creal(matrix_Gcomplex[k * dimension + l]), cimag(matrix_Gcomplex[k * dimension + l])); } } printf("\n\n"); } printf("\n\n"); printf("\nLine Transposition:\n"); for(k = 0; k < dimension; k++) { if (circuit_simulation.matrix_sparsity == SPARSE) { printf("line %d contains line %d\n", Ncomplex -> pinv[k], k); } else { printf("line %d contains line %d\n", k, transposition[k]); } } printf("\n\n"); #endif }