int main(int argc, char** argv) { MpiInit(&argc, &argv); const std::string helptxt = "OneDFormat.input: \n" "Input file for Assignment 5, Problem 2. \n" "Format = string; # Which 1-D output format \n" "Basename = string; # Filename (without extension) \n" "Times = double, double, ...; # Which times to output \n"; const std::string options = ReadFileIntoString("OneDFormat.input"); OptionParser parser(options, helptxt); const std::string format = parser.Get<std::string>("Format"); const std::string basename = parser.Get<std::string>("Basename"); MyVector<double> times = parser.Get<MyVector<double> >("Times"); OneDimDataWriter* pWriter = OneDimDataWriter::Create(format, basename); for(int i = 0; i < times.Size(); ++i) { ComputeProfileAndOutput(times[i], pWriter); } delete pWriter; MpiFinalize(); return EXIT_SUCCESS; }
int main(int /*argc*/, char** /*argv*/) { std::cout << "Hello world!" << std::endl; std::string opts = ReadFileIntoString("ImposeCap.input"); OptionParser parser(opts); double x = parser.Get<double>("Value"); double cap = parser.Get<double>("Cap"); double x_capped = ImposeCap(x, cap); std::cout << "x is " << x << ", cap is " << cap << std::endl; std::cout << "The capped value of x is " << x_capped << std::endl; return EXIT_SUCCESS; }
int main(int /*argc*/, char** /*argv*/) { //Create UtilsForTesting object UtilsForTesting u; //Try out the new sumVectorsAndThenDivide function //First, read in some vectors from the file Vectors.input OptionParser p(ReadFileIntoString("Vectors.input")); MyVector<double> A = p.Get<MyVector<double> >("FirstVectorToAdd"); MyVector<double> B = p.Get<MyVector<double> >("SecondVectorToAdd"); double divisor = p.Get<double>("Divisor",1.); //Next, make a vector to store the result MyVector<double> result(MV::Size(A.Size()),0.); //Test that the divisor is nonzero IS_TRUE(divisor != 0, "Divisor is zero"); //REQUIRE the divisor to be nonzero //Commented out to verify that the IS_TRUE line above also causes the test //to fail //REQUIRE(divisor != 0, "Divisor must be nonzero"); //Do the computation result = sumVectorsAndThenDivide(A,B,divisor); //Print out the results std::cout << "Vector A = " << A << std::endl; std::cout << "Vector B = " << B << std::endl; std::cout << "(A+B)/divisor = " << result << std::endl; //Test that the result magnitude is zero double resultMagnitudeSq = 0.0; for(int i=0;i<result.Size();++i) { resultMagnitudeSq += result[i]*result[i]; } IS_ZERO(resultMagnitudeSq,"Sum of vector and its negative nonzero."); //How many tests failed? std::cout << u.NumberOfTestsFailed() << " tests failed." << std::endl; //Return number of failed tests return u.NumberOfTestsFailed(); }
int main(int, char**) { std::string args = ReadFileIntoString("MultiplyAdd.input"); OptionParser parser(args); double a = parser.Get<double>("a"); double b = parser.Get<double>("b"); double c = parser.Get<double>("c"); double d = MultAdd(a,b,c); std::cout << " (" << a << " * " << b << ") + " << c << " = " << d << std::endl; return EXIT_SUCCESS; }
int main(int /*argc*/, char** /*argv*/) { std::string opts = ReadFileIntoString("MultiplyAdd.input"); OptionParser parser(opts); double a = parser.Get<double>("A"); double b = parser.Get<double>("B"); double c = parser.Get<double>("C"); double result = MultiplyAdd(a, b, c); std::cout << "a is " << a << ", b is " << b << ", c is " << c << std::endl; std::cout << "The result of MultiplyAdd on a, b, & c is: " << result << std::endl; return EXIT_SUCCESS; }
//----------------------------------------------------------------------------------- void EngineConfig::LoadConfigFile() { const char* filepath = "config.txt"; const char* jsonText = ReadFileIntoString( filepath ); Json::Value root; Json::Reader reader; if( !reader.parse( jsonText, root ) ) { return; } LoadRenderSettings(root, reader); LoadSceneSettings(root, reader); }
int main(int /*argc*/, char** /*argv*/) { UtilsForTesting u; //Try out the new sumVectors function //First, create a couple of vectors, then add them together /* const MyVector<double> A(MV::fill, 3.,4.,5.); const MyVector<double> B(MV::fill, 6.,7.,8.); */ OptionParser p(ReadFileIntoString("Vectors.input")); MyVector<double> A = p.Get<MyVector<double> >("FirstVectorToAdd"); MyVector<double> B = p.Get<MyVector<double> >("SecondVectorToAdd"); double divisor = p.Get<double>("Divisor",1.0); REQUIRE(divisor!=0.0, "Error: divisor set to zero"); IS_TRUE(divisor!=0.0, "Error: divisor is equal to zero"); //Next, make a vector to store the result MyVector<double> result(MV::Size(A.Size()),0.); //Add the vectors together result = sumVectors(A,B,divisor); //Print out the results std::cout << "Vector A = " << A << std::endl; std::cout << "Vector B = " << B << std::endl; std::cout << "Sum = " << result << std::endl; //Test that the result magnitude is zero double resultMagnitudeSq = 0.0; for(int i=0;i<result.Size();++i) { resultMagnitudeSq += result[i]*result[i]; } IS_ZERO(resultMagnitudeSq,"Sum of vector and its negative nonzero."); //Return success //return EXIT_SUCCESS; return u.NumberOfTestsFailed(); }
int main(int /*argc*/, char** /*argv*/) { //Try out the new sumVectors function //First, create a couple of vectors, then add them together OptionParser p(ReadFileIntoString("Vectors.input")); MyVector<double> A = p.Get<MyVector<double> >("FirstVectorToAdd"); MyVector<double> B = p.Get<MyVector<double> >("SecondVectorToAdd"); const double C = p.Get<double>("DoubleToDivideBy"); // Check that C isn't equal to 0 UtilsForTesting u; IS_TRUE(C != 0.0, "ERROR: DoubleToDivideBy can't be 0.0"); //REQUIRE(divisor != 0.0, "ERROR: DoubleToDivideBY can't be 0.0"); //Next, make a vector to store the result MyVector<double> result(MV::Size(A.Size()),0.); //Add the vectors together result = addDivideVectors(A,B,C); //Print out the results std::cout << "Vector A = " << A << std::endl; std::cout << "Vector B = " << B << std::endl; std::cout << "Result = " << result << std::endl; double resultMagnitudeSq = 0.0; for(int i=0; i<result.Size(); ++i){ resultMagnitudeSq += result[i]*result[i]; } IS_ZERO(resultMagnitudeSq, "Sum of vector and its negative nonzero."); //Return success return u.NumberOfTestsFailed(); }
int main() { const std::string Help = "-------------------------------------------------------------------------\n" "TestComputeAKV: \n" "-------------------------------------------------------------------------\n" "OPTIONS: \n" "Nth=<int> theta resolution [default 3] \n" "Nph=<int> phi resolution [default 4] \n" "Radius=<double> radius of sphere. [default 1.0] \n" "AKVGuess=MyVector<double> a guess for the values of THETA, thetap, phip \n" " [default (0.,0.,0.)] \n" "L_resid_tol=<double> tolerance for L residuals when finding approximate \n" " Killing vectors. [default 1.e-12] \n" "v_resid_tol=<double> tolerance for v residuals when finding approximate \n" " Killing vectors. [default 1.e-12] \n" "min_thetap = for values less than this, thetap is considered close to \n" " zero. [default 1.e-5] \n" "symmetry_tol=<double> abs(THETA) must be less than this value to be \n" " considered an exact symmetry. [default 1.e-11] \n" "ResidualSize=<double> determines the tolerance for residuals from the \n" " multidimensional root finder. [default to 1.e-11] \n" "Solver = <std::string> which gsl multidimensional root finding algorith \n" " should be used. [default Newton] \n" "Verbose=<bool> Print spectral coefficients and warnings if true \n" " [default false] \n" ; std::string Options = ReadFileIntoString("Test.input"); OptionParser op(Options,Help); const int Nth = op.Get<int>("Nth", 3); const int Nph = op.Get<int>("Nph", 4); const double rad = op.Get<double>("Radius",1.0); MyVector<double> AKVGuess = op.Get<MyVector<double> >("AKVGuess",MyVector<double>(MV::Size(3),0.0)); //must be three-dimensional REQUIRE(AKVGuess.Size()==3,"AKVGuess has Size " << AKVGuess.Size() << ", should be 3."); const double L_resid_tol = op.Get<double>("L_resid_tol", 1.e-12); const double v_resid_tol = op.Get<double>("L_resid_tol", 1.e-12); const double residualSize = op.Get<double>("ResidualSize", 1.e-11); const double min_thetap = op.Get<double>("min_theta",1.e-5); const double symmetry_tol = op.Get<double>("symmetry_tol",1.e-11); const std::string solver = op.Get<std::string>("Solver","Newton"); const bool verbose = op.Get<bool>("Verbose", false); const MyVector<bool> printDiagnostic = MyVector<bool>(MV::Size(6), true); //create skm const StrahlkorperMesh skm(Nth, Nph); //create surface basis const SurfaceBasis sb(skm); //get theta, phi const DataMesh theta(skm.SurfaceCoords()(0)); const DataMesh phi(skm.SurfaceCoords()(1)); //set the initial guesses to be along particular axes const int axes = 3; //the number of perpendicular axes //create conformal factors for every rotation const int syms = 5; //the number of axisymmetries we are testing for(int s=4; s<5; s++) { //index over conformal factor symmetries //for(int s=0; s<syms; s++){//index over conformal factor symmetries //create conformal factor const DataMesh Psi = ConstructConformalFactor(theta, phi, s); //set the initial guesses double THETA[3] = {AKVGuess[0],0.,0.}; double thetap[3] = {AKVGuess[1],0.,0.}; double phip[3] = {AKVGuess[2],0.,0.}; //save the v, xi solutions along particular axes MyVector<DataMesh> v(MV::Size(3),DataMesh::Empty); MyVector<DataMesh> rotated_v(MV::Size(3),DataMesh::Empty); MyVector<Tensor<DataMesh> > xi(MV::Size(axes),Tensor<DataMesh>(2,"1",DataMesh::Empty)); //save the <v_i|v_j> inner product solutions double v0v0 = 0.; double v1v1 = 0.; double v2v2 = 0.; double v0v1 = 0.; double v0v2 = 0.; double v1v2 = 0.; //int symmetries[3] = 0; //counts the number of symmetries //compute some useful quantities const DataMesh rp2 = rad * Psi * Psi; const DataMesh r2p4 = rp2*rp2; const DataMesh llncf = sb.ScalarLaplacian(log(Psi)); const DataMesh Ricci = 2.0 * (1.0-2.0*llncf) / r2p4; const Tensor<DataMesh> GradRicci = sb.Gradient(Ricci); for(int a=0; a<axes; a++) { //index over perpendicular axes to find AKV solutions //if the diagnostics below decide that there is a bad solution for v[a] //(usually a repeated solution), this flag will indicate that the //solver should be run again bool badAKVSolution = false; //generate a guess for the next axis of symmetry based on prior solutions. AxisInitialGuess(thetap, phip, a); //create L DataMesh L(DataMesh::Empty); //setup struct with all necessary data rparams p = {theta, phi, rp2, sb, llncf, GradRicci, L, v[a], L_resid_tol, v_resid_tol, verbose, true }; RunAKVsolvers(THETA[a], thetap[a], phip[a], min_thetap, residualSize, verbose, &p, solver); std::cout << "Solution found with : THETA[" << a << "] = " << THETA[a] << "\n" << " thetap[" << a << "] = " << (180.0/M_PI)*thetap[a] << "\n" << " phip[" << a << "] = " << (180.0/M_PI)*phip[a] << std::endl; //check inner products // <v_i|v_j> = Integral 0.5 * Ricci * Grad(v_i) \cdot Grad(v_j) dA switch(a) { case 0: //compute inner product <v_0|v_0> v0v0 = AKVInnerProduct(v[0],v[0],Ricci,sb)*sqrt(2.)*M_PI; //if(v0v0<symmetry_tol) //symmetries++; std::cout << "<v_0|v_0> = " << v0v0 << std::endl; std::cout << "-THETA <v_0|v_0> = " << -THETA[a]*v0v0 << std::endl; break; case 1: //compute inner products <v_1|v_1>, <v_0|v_1> v1v1 = AKVInnerProduct(v[1],v[1],Ricci,sb)*sqrt(2.)*M_PI; v0v1 = AKVInnerProduct(v[0],v[1],Ricci,sb)*sqrt(2.)*M_PI; //if(v1v1<symmetry_tol) //symmetries++; std::cout << "<v_1|v_1> = " << v1v1 << std::endl; std::cout << "<v_0|v_1> = " << v0v1 << std::endl; std::cout << "-THETA <v_1|v_1> = " << -THETA[a]*v1v1 << std::endl; if(fabs(v0v0) == fabs(v1v2)) badAKVSolution = true; break; case 2: //compute inner products <v_2|v_2>, <v_0|v_2>, <v_1|v_2> v2v2 = AKVInnerProduct(v[2],v[2],Ricci,sb)*sqrt(2.)*M_PI; v0v2 = AKVInnerProduct(v[0],v[2],Ricci,sb)*sqrt(2.)*M_PI; v1v2 = AKVInnerProduct(v[1],v[2],Ricci,sb)*sqrt(2.)*M_PI; //if(v2v2<symmetry_tol) //symmetries++; std::cout << "<v_2|v_2> = " << v2v2 << std::endl; std::cout << "<v_0|v_2> = " << v0v2 << std::endl; std::cout << "<v_1|v_2> = " << v1v2 << std::endl; std::cout << "-THETA <v_2|v_2> = " << -THETA[a]*v2v2 << std::endl; if(fabs(v0v0) == fabs(v0v2)) badAKVSolution = true; if(fabs(v1v1) == fabs(v1v2)) badAKVSolution = true; break; } //Gram Schmidt orthogonalization switch(a) { case 1: if(v0v0<symmetry_tol && v1v1<symmetry_tol) { //two symmetries, v2v2 should also be symmetric GramSchmidtOrthogonalization(v[0], v0v0, v[1], v0v1); } break; case 2: if(v0v0<symmetry_tol) { if(v1v1<symmetry_tol) { REQUIRE(v2v2<symmetry_tol, "Three symmetries required, but only two found."); GramSchmidtOrthogonalization(v[0], v0v0, v[2], v0v2); GramSchmidtOrthogonalization(v[1], v1v1, v[2], v1v2); } else if(v2v2<symmetry_tol) { REQUIRE(false, "Three symmetries required, but only two found."); } else { GramSchmidtOrthogonalization(v[1], v1v1, v[2], v1v2); } } else if(v1v1<symmetry_tol) { if(v2v2<symmetry_tol) { REQUIRE(false, "Three symmetries required, but only two found."); } else { GramSchmidtOrthogonalization(v[0], v0v0, v[2], v0v2); } } else if(v2v2<symmetry_tol) { GramSchmidtOrthogonalization(v[0], v0v0, v[1], v0v1); } break; } //create xi (1-form) xi[a] = ComputeXi(v[a], sb); //perform diagnostics //Psi and xi are unscaled and unrotated KillingDiagnostics(sb, L, Psi, xi[a], rad, printDiagnostic); //rotate v, Psi for analysis rotated_v[a] = RotateOnSphere(v[a],theta,phi, sb,thetap[a],phip[a]); DataMesh rotated_Psi = RotateOnSphere(Psi,theta,phi, sb,thetap[a],phip[a]); //compare scale factors const double scaleAtEquator = NormalizeAKVAtOnePoint(sb, rotated_Psi, rotated_v[a], rad, M_PI/2., 0.0); PrintSurfaceNormalization(sb,rotated_Psi,theta,phi,rotated_v[a],scaleAtEquator,rad); MyVector<double> scaleInnerProduct = InnerProductScaleFactors(v[a], v[a], Ricci, r2p4, sb); PrintSurfaceNormalization(sb,rotated_Psi,theta,phi,rotated_v[a],scaleInnerProduct[0],rad); PrintSurfaceNormalization(sb,rotated_Psi,theta,phi,rotated_v[a],scaleInnerProduct[1],rad); PrintSurfaceNormalization(sb,rotated_Psi,theta,phi,rotated_v[a],scaleInnerProduct[2],rad); OptimizeScaleFactor(rotated_v[a], rotated_Psi, rad, sb, theta, phi, scaleAtEquator, scaleInnerProduct[0], scaleInnerProduct[1], scaleInnerProduct[2]); //scale v v[a] *= scaleAtEquator; //recompute scaled xi (1-form) xi[a] = ComputeXi(v[a], sb); if(badAKVSolution) { v[a] = 0.; thetap[a] += M_PI/4.; phip[a] += M_PI/4.; a--; std::cout << "This was a bad / repeated solution, and will be recomputed." << std::endl; } std::cout << std::endl; }//end loop over perpendicular AKV axes std::cout << "\n" << std::endl; } // Return 0 for success return NumberOfTestsFailed; }
return; } for (char c : "0123456789") { if (!AdvanceIndexesByLetter(strings, c, indexes)) { continue; } current_sequence->push_back(c); ShortestCommonSuperstring(strings, indexes, minimum_length_string, current_sequence); current_sequence->pop_back(); RetractIndexesByLetter(strings, c, indexes); } } std::string ShortestCommonSuperstring(const std::vector<std::string>& strings) { std::string sequence; std::vector<int> indexes(strings.size()); std::string minimum_length_string = std::accumulate(strings.begin(), strings.end(), std::string{}); ShortestCommonSuperstring(strings, &indexes, &minimum_length_string, &sequence); return minimum_length_string; } TASK(79) { std::vector<std::string> strings = Split(ReadFileIntoString("data/079_keylog.txt"), '\n', SkipEmpty()); return ShortestCommonSuperstring(strings); }