int params(int nfe1, int nfe2) { starttime = time(NULL); /* I know, I know, I have way to many freaking variables. * I am sure there is a better way to do this, but I just don't * feel like trying to figure it out right now. As a result, this * method is a PRIME candidate for third party patches. */ float temp, mtvel, logg, m; float otemp,omtvel,ologg; float inep, inrw, fe1, fe2; float abinep, abinrw, stdfe1, stdfe2; int auto1 = 0; int auto2 = 0; int n = 2; int done1 = 0; int done2 = 0; int plt, itts, last; char inpt[100], yn[1]; FILE *stats; FILE *plts = popen("sm","w"); abinep = 1; abinrw = 1; m = 0.0; itts = 0; fprintf(stderr, "MOOGIN' the Sun. . . "); runmoog("./sun.par"); fprintf(stderr, "COMPLETE!\n"); char mgbnds[64]; char pltcmd[100]; char sttscmd[100]; sprintf(mgbnds, "define start1 %i define end1 %i define start2 %i define end2 %i", 7, (6+nfe1), (14+nfe1), (13+nfe1+nfe2)); // find out if the user wants to do this automagically fprintf(stderr, "Do you want to automate this process? [Y/N] "); fscanf(stdin, " %c", &yn[0]); if ('Y' == *yn || 'y' == *yn) { auto1 = 1; auto2 = 0; plt = -2; } else { auto1 = 0; plt = 1; } do { done2 = 0; while (done2 == 0) { /* The following bit of code is for my use only. I am trying to understand how changes are made by the user to the various values * during the parameter search */ /* otemp = temp;*/ /* omtvel = mtvel;*/ /* ologg = logg;*/ /* END OF PARAMETER COLLECTING CODE BLOCK. WE NOW RETURN YOU TO YOUR REGULARLY SCHEDULED CODE. */ itts++; if (auto2 == 0) { fprintf(stderr,"Type in an Effective Temperature:\n"); scanf("%f", &temp); fprintf(stderr,"Type in a Surface Gravity:\n"); scanf("%f", &logg); //fprintf(stderr,"Type in a Metallicity:\n"); //scanf("%f", &m); fprintf(stderr,"Type in a Microturbulence:\n"); scanf("%f", &mtvel); if (auto1 == 1) auto2 = 1; } /* fprintf(chngs, "%f\t%f\t%f\t%f\t%f\t%f\n",(otemp-temp),(omtvel-mtvel),(ologg-logg),inep,inrw,(fe1-fe2));*/ /* make the model based on the input values */ partest(&temp, &logg, &m, &mtvel); makemodel(temp, logg, m, mtvel); fprintf(stderr, "Running Moog. . . "); runmoog("./star.par"); fprintf(stderr, "COMPLETE!\n"); n = 0; /* Let's set the statistical values to zero */ inep = 0; inrw = 0; fe1 = 0; fe2 = 0; if(plt == 1) { fprintf(stderr, "opening ploting window\n"); sprintf(pltcmd, "sm >sm.out"); fflush(plts); plts = popen(pltcmd, "w"); fflush(plts); plt = 0; } else if(plt == -1) { fprintf(plts, "QUIT\n"); pclose(plts); } /* Okay, I want to display a plot of the data, so I will use this */ if (plt == 0) { fprintf(plts, "macro read \"/usr/bin/moogplots.sm\"\n"); fprintf(plts, "%s", mgbnds); fprintf(plts, "\nmoogplots"); fprintf(plts, "\necho Hi, at least this worked!\n"); fflush(plts); } /* fprintf(stderr, pltcmd);*/ /* Since I have now learned how to open a process with a pipe * between two programs, we open a pipe to sm below. */ sprintf(sttscmd, "sm %s macro read stelstats.sm stelstats quit", mgbnds); stats = popen(sttscmd, "r"); while (n != 6) { /* Here we read the pipe, and find our statistics */ fgets(inpt, 100, stats); n = sscanf(inpt, "%f %f %f %f %f %f", &inep, &inrw, &fe1, &fe2, &stdfe1, &stdfe2); } pclose(stats); abinep = abv(inep); system("clear"); fprintf(stderr,"temp\tlogg\t m\tmtvel\t EPcorr\tRWCorr\tFeI - FeII\tFeI stddev\tFeII stddev\n"); fprintf(stderr, "%.0f\t%.2f\t%.2f\t%.2f", temp, logg, m, mtvel); fprintf(stderr, "\t%.3f\t%.3f\t %.3f\t%.3f (%i)\t%.3f (%i)\n", inep, inrw, (fe1 - fe2), stdfe1, nfe1, stdfe2, nfe2); m = fe1; abinep = abv(inep); abinrw = abv(inrw); /* * Begin the block of code that will automate the process of finding the parameters */ if (auto1 == 1) { if(0.005 > abinep && 0.005 > abinrw && 0.005 > (abv(fe1 - fe2))) done2 = 1; else { if(abinep > (fe1 - fe2) && last == 2) { last = 1; if (inep > 0) temp = temp + 1; else if (inep < 0) temp = temp - 1; } else if(abinep > abinrw && last == 3) { last = 1; if (inep > 0) temp = temp + 1; else if (inep < 0) temp = temp - 1; } else if (abinrw > (fe1 - fe2) && last == 1) { last = 2; if (inrw > 0) logg = logg + 0.01; else if (inrw < 0) logg = logg - 0.01; } else if (abinrw > abinep && last == 3) { last = 2; if (inrw > 0) logg = logg + 0.01; else if (inrw < 0) logg = logg - 0.01; } else { last = 3; if ((fe1 - fe2) > 0) mtvel = mtvel + 0.01; else if ((fe1 - fe2) > 0) mtvel = mtvel - 0.01; } } fprintf(stderr, "%f seconds elapsed\n%i itterations\n", difftime(time(NULL), starttime), itts); } /* End the block of code that determines the parameters automatically */ if(0.005 > abinep && 0.005 > abinrw && 0.005 > (abv(fe1 - fe2))) done2 = 1; } fprintf(stdout, "Have you finished testing parameters? [y/n] "); fscanf(stdin, " %c", yn); if('y' == yn[0]) { plt = -1; done1 = 1; } }while (done1 == 0); /* fclose(chngs);*/ fprintf(stderr, "Final Parameters Listing\n"); fprintf(stderr, "Temperature = %f\n", temp); fprintf(stderr, "Surface Gravity = %f\n", logg); fprintf(stderr, "Metalicity = %f\n", m); fprintf(stderr, "Micro-Turbulence = %f\n", mtvel); return 1; }
/// split the fractures void TPZFracSet::SplitFractures(int64_t ifrac, double xy, int64_t jfrac, double ab) { TPZManVector<REAL,3> x(3),y(3),xyv(3); int64_t inode0 = fFractureVec[ifrac].fNodes[0]; int64_t inode1 = fFractureVec[ifrac].fNodes[1]; fNodeVec[inode0].GetCoordinates(x); fNodeVec[inode1].GetCoordinates(y); if (jfrac>=0) { TPZManVector<REAL,3> a(3),b(3),abv(3); int64_t jnode0 = fFractureVec[jfrac].fNodes[0]; int64_t jnode1 = fFractureVec[jfrac].fNodes[1]; fNodeVec[jnode0].GetCoordinates(a); fNodeVec[jnode1].GetCoordinates(b); REAL diff = 0; for (int i=0; i<3; i++) { xyv[i] = x[i]+xy*(y[i]-x[i]); abv[i] = a[i]+ab*(b[i]-a[i]); diff += (xyv[i]-abv[i])*(xyv[i]-abv[i]); } if(xy < 0.) xy = 0.; if(xy > 1.) xy = 1.; if(ab < 0.) ab = 0.; if(ab > 1.) ab = 1.; for (int i=0; i<3; i++) { xyv[i] = x[i]+xy*(y[i]-x[i]); abv[i] = a[i]+ab*(b[i]-a[i]); } if (jfrac != -1 && diff > 1.e-10) { DebugStop(); } } else { for (int i=0; i<3; i++) { xyv[i] = x[i]+xy*(y[i]-x[i]); } } TPZGeoNode node; node.SetCoord(xyv); int64_t nodeindex = InsertNode(node); if(nodeindex != inode0 && nodeindex != inode1) { TPZFracture frac1(fFractureVec[ifrac].fOrigId, fFractureVec[ifrac].fMatId, fFractureVec[ifrac].fNodes[0], nodeindex); frac1.fPhysicalName = fFractureVec[ifrac].fPhysicalName; frac1.fFracPerm = fFractureVec[ifrac].fFracPerm; TPZFracture frac2(fFractureVec[ifrac].fOrigId, fFractureVec[ifrac].fMatId, nodeindex, fFractureVec[ifrac].fNodes[1]); frac2.fPhysicalName = fFractureVec[ifrac].fPhysicalName; frac2.fFracPerm = fFractureVec[ifrac].fFracPerm; fFractureVec[ifrac] = frac1; int64_t nfrac2 = fFractureVec.AllocateNewElement(); fFractureVec[nfrac2] = frac2; } if (jfrac != -1 && nodeindex != fFractureVec[jfrac].fNodes[0] && nodeindex != fFractureVec[jfrac].fNodes[1]) { TPZFracture frac1(fFractureVec[jfrac].fOrigId, fFractureVec[jfrac].fMatId, fFractureVec[jfrac].fNodes[0], nodeindex); TPZFracture frac2(fFractureVec[jfrac].fOrigId, fFractureVec[jfrac].fMatId, nodeindex, fFractureVec[jfrac].fNodes[1]); frac1.fPhysicalName = fFractureVec[jfrac].fPhysicalName; frac1.fFracPerm = fFractureVec[jfrac].fFracPerm; frac2.fPhysicalName = fFractureVec[jfrac].fPhysicalName; frac2.fFracPerm = fFractureVec[jfrac].fFracPerm; fFractureVec[jfrac] = frac1; int64_t nfrac2 = fFractureVec.AllocateNewElement(); fFractureVec[nfrac2] = frac2; } }
void Arnoldi<SCAL>::Calc (int numval, Array<Complex> & lam, int numev, Array<shared_ptr<BaseVector>> & hevecs, const BaseMatrix * pre) const { static Timer t("arnoldi"); static Timer t2("arnoldi - orthogonalize"); static Timer t3("arnoldi - compute large vectors"); RegionTimer reg(t); auto hv = a.CreateVector(); auto hv2 = a.CreateVector(); auto hva = a.CreateVector(); auto hvm = a.CreateVector(); int n = hv.FV<SCAL>().Size(); int m = min2 (numval, n); Matrix<SCAL> matH(m); Array<shared_ptr<BaseVector>> abv(m); for (int i = 0; i < m; i++) abv[i] = a.CreateVector(); auto mat_shift = a.CreateMatrix(); mat_shift->AsVector() = a.AsVector() - shift*b.AsVector(); shared_ptr<BaseMatrix> inv; if (!pre) inv = mat_shift->InverseMatrix (freedofs); else { auto itso = make_shared<GMRESSolver<double>> (*mat_shift, *pre); itso->SetPrintRates(1); itso->SetMaxSteps(2000); inv = itso; } hv.SetRandom(); hv.SetParallelStatus (CUMULATED); FlatVector<SCAL> fv = hv.FV<SCAL>(); if (freedofs) for (int i = 0; i < hv.Size(); i++) if (! (*freedofs)[i] ) fv(i) = 0; t2.Start(); // matV = SCAL(0.0); why ? matH = SCAL(0.0); *hv2 = *hv; SCAL len = sqrt (S_InnerProduct<SCAL> (*hv, *hv2)); // parallel *hv /= len; for (int i = 0; i < m; i++) { cout << IM(1) << "\ri = " << i << "/" << m << flush; /* for (int j = 0; j < n; j++) matV(i,j) = hv.FV<SCAL>()(j); */ *abv[i] = *hv; *hva = b * *hv; *hvm = *inv * *hva; for (int j = 0; j <= i; j++) { /* SCAL sum = 0.0; for (int k = 0; k < n; k++) sum += hvm.FV<SCAL>()(k) * matV(j,k); matH(j,i) = sum; for (int k = 0; k < n; k++) hvm.FV<SCAL>()(k) -= sum * matV(j,k); */ /* SCAL sum = 0.0; FlatVector<SCAL> abvj = abv[j] -> FV<SCAL>(); FlatVector<SCAL> fv_hvm = hvm.FV<SCAL>(); for (int k = 0; k < n; k++) sum += fv_hvm(k) * abvj(k); matH(j,i) = sum; for (int k = 0; k < n; k++) fv_hvm(k) -= sum * abvj(k); */ matH(j,i) = S_InnerProduct<SCAL> (*hvm, *abv[j]); *hvm -= matH(j,i) * *abv[j]; } *hv = *hvm; *hv2 = *hv; SCAL len = sqrt (S_InnerProduct<SCAL> (*hv, *hv2)); if (i<m-1) matH(i+1,i) = len; *hv /= len; } t2.Stop(); t2.AddFlops (double(n)*m*m); cout << "n = " << n << ", m = " << m << " n*m*m = " << n*m*m << endl; cout << IM(1) << "\ri = " << m << "/" << m << endl; Vector<Complex> lami(m); Matrix<Complex> evecs(m); Matrix<Complex> matHt(m); matHt = Trans (matH); evecs = Complex (0.0); lami = Complex (0.0); cout << "Solve Hessenberg evp with Lapack ... " << flush; LapackHessenbergEP (matH.Height(), &matHt(0,0), &lami(0), &evecs(0,0)); cout << "done" << endl; for (int i = 0; i < m; i++) lami(i) = 1.0 / lami(i) + shift; lam.SetSize (m); for (int i = 0; i < m; i++) lam[i] = lami(i); t3.Start(); if (numev>0) { int nout = min2 (numev, m); hevecs.SetSize(nout); for (int i = 0; i< nout; i++) { hevecs[i] = a.CreateVector(); *hevecs[i] = 0; for (int j = 0; j < m; j++) *hevecs[i] += evecs(i,j) * *abv[j]; // hevecs[i]->FVComplex() = Trans(matV)*evecs.Row(i); } } t3.Stop(); }