int main(int argc, char *argv[]) { #include <MueLu_UseShortNames.hpp> using Teuchos::RCP; // reference count pointers using Teuchos::rcp; using Teuchos::TimeMonitor; using Teuchos::ParameterList; // ========================================================================= // MPI initialization using Teuchos // ========================================================================= Teuchos::GlobalMPISession mpiSession(&argc, &argv, NULL); RCP< const Teuchos::Comm<int> > comm = Teuchos::DefaultComm<int>::getComm(); // ========================================================================= // Convenient definitions // ========================================================================= typedef Teuchos::ScalarTraits<SC> STS; SC zero = STS::zero(), one = STS::one(); // ========================================================================= // Parameters initialization // ========================================================================= Teuchos::CommandLineProcessor clp(false); GO nx = 100, ny = 100, nz = 100; Galeri::Xpetra::Parameters<GO> galeriParameters(clp, nx, ny, nz, "Laplace2D"); // manage parameters of the test case Xpetra::Parameters xpetraParameters(clp); // manage parameters of Xpetra std::string xmlFileName = "scalingTest.xml"; clp.setOption("xml", &xmlFileName, "read parameters from a file [default = 'scalingTest.xml']"); bool printTimings = true; clp.setOption("timings", "notimings", &printTimings, "print timings to screen"); int writeMatricesOPT = -2; clp.setOption("write", &writeMatricesOPT, "write matrices to file (-1 means all; i>=0 means level i)"); std::string dsolveType = "cg", solveType; clp.setOption("solver", &dsolveType, "solve type: (none | cg | gmres | standalone)"); double dtol = 1e-12, tol; clp.setOption("tol", &dtol, "solver convergence tolerance"); std::string mapFile; clp.setOption("map", &mapFile, "map data file"); std::string matrixFile; clp.setOption("matrix", &matrixFile, "matrix data file"); std::string coordFile; clp.setOption("coords", &coordFile, "coordinates data file"); int numRebuilds = 0; clp.setOption("rebuild", &numRebuilds, "#times to rebuild hierarchy"); int maxIts = 200; clp.setOption("its", &maxIts, "maximum number of solver iterations"); bool scaleResidualHistory = true; clp.setOption("scale", "noscale", &scaleResidualHistory, "scaled Krylov residual history"); switch (clp.parse(argc, argv)) { case Teuchos::CommandLineProcessor::PARSE_HELP_PRINTED: return EXIT_SUCCESS; case Teuchos::CommandLineProcessor::PARSE_ERROR: case Teuchos::CommandLineProcessor::PARSE_UNRECOGNIZED_OPTION: return EXIT_FAILURE; case Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL: break; } Xpetra::UnderlyingLib lib = xpetraParameters.GetLib(); ParameterList paramList; Teuchos::updateParametersFromXmlFileAndBroadcast(xmlFileName, Teuchos::Ptr<ParameterList>(¶mList), *comm); bool isDriver = paramList.isSublist("Run1"); if (isDriver) { // update galeriParameters with the values from the XML file ParameterList& realParams = galeriParameters.GetParameterList(); for (ParameterList::ConstIterator it = realParams.begin(); it != realParams.end(); it++) { const std::string& name = realParams.name(it); if (paramList.isParameter(name)) realParams.setEntry(name, paramList.getEntry(name)); } } // Retrieve matrix parameters (they may have been changed on the command line) // [for instance, if we changed matrix type from 2D to 3D we need to update nz] ParameterList galeriList = galeriParameters.GetParameterList(); // ========================================================================= // Problem construction // ========================================================================= std::ostringstream galeriStream; comm->barrier(); RCP<TimeMonitor> globalTimeMonitor = rcp(new TimeMonitor(*TimeMonitor::getNewTimer("ScalingTest: S - Global Time"))); RCP<TimeMonitor> tm = rcp(new TimeMonitor(*TimeMonitor::getNewTimer("ScalingTest: 1 - Matrix Build"))); RCP<Matrix> A; RCP<const Map> map; RCP<MultiVector> coordinates; RCP<MultiVector> nullspace; if (matrixFile.empty()) { galeriStream << "========================================================\n" << xpetraParameters << galeriParameters; // Galeri will attempt to create a square-as-possible distribution of subdomains di, e.g., // d1 d2 d3 // d4 d5 d6 // d7 d8 d9 // d10 d11 d12 // A perfect distribution is only possible when the #processors is a perfect square. // This *will* result in "strip" distribution if the #processors is a prime number or if the factors are very different in // size. For example, np=14 will give a 7-by-2 distribution. // If you don't want Galeri to do this, specify mx or my on the galeriList. std::string matrixType = galeriParameters.GetMatrixType(); // Create map and coordinates // In the future, we hope to be able to first create a Galeri problem, and then request map and coordinates from it // At the moment, however, things are fragile as we hope that the Problem uses same map and coordinates inside if (matrixType == "Laplace1D") { map = Galeri::Xpetra::CreateMap<LO, GO, Node>(xpetraParameters.GetLib(), "Cartesian1D", comm, galeriList); coordinates = Galeri::Xpetra::Utils::CreateCartesianCoordinates<SC,LO,GO,Map,MultiVector>("1D", map, galeriList); } else if (matrixType == "Laplace2D" || matrixType == "Star2D" || matrixType == "BigStar2D" || matrixType == "Elasticity2D") { map = Galeri::Xpetra::CreateMap<LO, GO, Node>(xpetraParameters.GetLib(), "Cartesian2D", comm, galeriList); coordinates = Galeri::Xpetra::Utils::CreateCartesianCoordinates<SC,LO,GO,Map,MultiVector>("2D", map, galeriList); } else if (matrixType == "Laplace3D" || matrixType == "Brick3D" || matrixType == "Elasticity3D") { map = Galeri::Xpetra::CreateMap<LO, GO, Node>(xpetraParameters.GetLib(), "Cartesian3D", comm, galeriList); coordinates = Galeri::Xpetra::Utils::CreateCartesianCoordinates<SC,LO,GO,Map,MultiVector>("3D", map, galeriList); } // Expand map to do multiple DOF per node for block problems if (matrixType == "Elasticity2D") map = Xpetra::MapFactory<LO,GO,Node>::Build(map, 2); if (matrixType == "Elasticity3D") map = Xpetra::MapFactory<LO,GO,Node>::Build(map, 3); galeriStream << "Processor subdomains in x direction: " << galeriList.get<int>("mx") << std::endl << "Processor subdomains in y direction: " << galeriList.get<int>("my") << std::endl << "Processor subdomains in z direction: " << galeriList.get<int>("mz") << std::endl << "========================================================" << std::endl; if (matrixType == "Elasticity2D" || matrixType == "Elasticity3D") { // Our default test case for elasticity: all boundaries of a square/cube have Neumann b.c. except left which has Dirichlet galeriList.set("right boundary" , "Neumann"); galeriList.set("bottom boundary", "Neumann"); galeriList.set("top boundary" , "Neumann"); galeriList.set("front boundary" , "Neumann"); galeriList.set("back boundary" , "Neumann"); } RCP<Galeri::Xpetra::Problem<Map,CrsMatrixWrap,MultiVector> > Pr = Galeri::Xpetra::BuildProblem<SC,LO,GO,Map,CrsMatrixWrap,MultiVector>(galeriParameters.GetMatrixType(), map, galeriList); A = Pr->BuildMatrix(); nullspace = MultiVectorFactory::Build(map, 1); if (matrixType == "Elasticity2D" || matrixType == "Elasticity3D") { nullspace = Pr->BuildNullspace(); A->SetFixedBlockSize((galeriParameters.GetMatrixType() == "Elasticity2D") ? 2 : 3); } else { nullspace->putScalar(one); } } else { if (!mapFile.empty()) map = Utils2::ReadMap(mapFile, xpetraParameters.GetLib(), comm); comm->barrier(); if (lib == Xpetra::UseEpetra) { A = Utils::Read(matrixFile, map); } else { // Tpetra matrix reader is still broken, so instead we read in // a matrix in a binary format and then redistribute it const bool binaryFormat = true; A = Utils::Read(matrixFile, lib, comm, binaryFormat); RCP<Matrix> newMatrix = MatrixFactory::Build(map, 1); RCP<Import> importer = ImportFactory::Build(A->getRowMap(), map); newMatrix->doImport(*A, *importer, Xpetra::INSERT); newMatrix->fillComplete(); A.swap(newMatrix); } comm->barrier(); if (!coordFile.empty()) coordinates = Utils2::ReadMultiVector(coordFile, map); nullspace = MultiVectorFactory::Build(map, 1); nullspace->putScalar(one); } comm->barrier(); tm = Teuchos::null; galeriStream << "Galeri complete.\n========================================================" << std::endl; int numReruns = 1; if (paramList.isParameter("number of reruns")) numReruns = paramList.get<int>("number of reruns"); const bool mustAlreadyExist = true; for (int rerunCount = 1; rerunCount <= numReruns; rerunCount++) { ParameterList mueluList, runList; bool stop = false; if (isDriver) { runList = paramList.sublist("Run1", mustAlreadyExist); mueluList = runList .sublist("MueLu", mustAlreadyExist); } else { mueluList = paramList; stop = true; } int runCount = 1; do { A->SetMaxEigenvalueEstimate(-one); solveType = dsolveType; tol = dtol; int savedOut = -1; FILE* openedOut = NULL; if (isDriver) { if (runList.isParameter("filename")) { // Redirect all output into a filename We have to redirect all output, // including printf's, therefore we cannot simply replace C++ cout // buffers, and have to use heavy machinary (dup2) std::string filename = runList.get<std::string>("filename"); if (numReruns > 1) filename += "_run" + MueLu::toString(rerunCount); filename += (lib == Xpetra::UseEpetra ? ".epetra" : ".tpetra"); savedOut = dup(STDOUT_FILENO); openedOut = fopen(filename.c_str(), "w"); dup2(fileno(openedOut), STDOUT_FILENO); } if (runList.isParameter("solver")) solveType = runList.get<std::string>("solver"); if (runList.isParameter("tol")) tol = runList.get<double> ("tol"); } // Instead of checking each time for rank, create a rank 0 stream RCP<Teuchos::FancyOStream> fancy = Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout)); Teuchos::FancyOStream& fancyout = *fancy; fancyout.setOutputToRootOnly(0); fancyout << galeriStream.str(); // ========================================================================= // Preconditioner construction // ========================================================================= comm->barrier(); tm = rcp(new TimeMonitor(*TimeMonitor::getNewTimer("ScalingTest: 1.5 - MueLu read XML"))); RCP<HierarchyManager> mueLuFactory = rcp(new ParameterListInterpreter(mueluList)); comm->barrier(); tm = rcp(new TimeMonitor(*TimeMonitor::getNewTimer("ScalingTest: 2 - MueLu Setup"))); RCP<Hierarchy> H; for (int i = 0; i <= numRebuilds; i++) { A->SetMaxEigenvalueEstimate(-one); H = mueLuFactory->CreateHierarchy(); H->GetLevel(0)->Set("A", A); H->GetLevel(0)->Set("Nullspace", nullspace); if (!coordinates.is_null()) H->GetLevel(0)->Set("Coordinates", coordinates); mueLuFactory->SetupHierarchy(*H); } comm->barrier(); tm = Teuchos::null; // ========================================================================= // System solution (Ax = b) // ========================================================================= comm->barrier(); tm = rcp(new TimeMonitor(*TimeMonitor::getNewTimer("ScalingTest: 3 - LHS and RHS initialization"))); RCP<Vector> X = VectorFactory::Build(map); RCP<Vector> B = VectorFactory::Build(map); { // we set seed for reproducibility Utils::SetRandomSeed(*comm); X->randomize(); A->apply(*X, *B, Teuchos::NO_TRANS, one, zero); Teuchos::Array<STS::magnitudeType> norms(1); B->norm2(norms); B->scale(one/norms[0]); X->putScalar(zero); } tm = Teuchos::null; if (writeMatricesOPT > -2) { tm = rcp(new TimeMonitor(*TimeMonitor::getNewTimer("ScalingTest: 3.5 - Matrix output"))); H->Write(writeMatricesOPT, writeMatricesOPT); tm = Teuchos::null; } comm->barrier(); if (solveType == "none") { // Do not perform a solve } else if (solveType == "standalone") { tm = rcp (new TimeMonitor(*TimeMonitor::getNewTimer("ScalingTest: 4 - Fixed Point Solve"))); H->IsPreconditioner(false); H->Iterate(*B, *X, maxIts); } else if (solveType == "cg" || solveType == "gmres") { #ifdef HAVE_MUELU_BELOS tm = rcp(new TimeMonitor(*TimeMonitor::getNewTimer("ScalingTest: 5 - Belos Solve"))); // Operator and Multivector type that will be used with Belos typedef MultiVector MV; typedef Belos::OperatorT<MV> OP; H->IsPreconditioner(true); // Define Operator and Preconditioner Teuchos::RCP<OP> belosOp = Teuchos::rcp(new Belos::XpetraOp<SC, LO, GO, NO, LMO>(A)); // Turns a Xpetra::Matrix object into a Belos operator Teuchos::RCP<OP> belosPrec = Teuchos::rcp(new Belos::MueLuOp <SC, LO, GO, NO, LMO>(H)); // Turns a MueLu::Hierarchy object into a Belos operator // Construct a Belos LinearProblem object RCP< Belos::LinearProblem<SC, MV, OP> > belosProblem = rcp(new Belos::LinearProblem<SC, MV, OP>(belosOp, X, B)); belosProblem->setRightPrec(belosPrec); bool set = belosProblem->setProblem(); if (set == false) { fancyout << "\nERROR: Belos::LinearProblem failed to set up correctly!" << std::endl; return EXIT_FAILURE; } // Belos parameter list Teuchos::ParameterList belosList; belosList.set("Maximum Iterations", maxIts); // Maximum number of iterations allowed belosList.set("Convergence Tolerance", tol); // Relative convergence tolerance requested belosList.set("Verbosity", Belos::Errors + Belos::Warnings + Belos::StatusTestDetails); belosList.set("Output Frequency", 1); belosList.set("Output Style", Belos::Brief); if (!scaleResidualHistory) belosList.set("Implicit Residual Scaling", "None"); // Create an iterative solver manager RCP< Belos::SolverManager<SC, MV, OP> > solver; if (solveType == "cg") { solver = rcp(new Belos::PseudoBlockCGSolMgr <SC, MV, OP>(belosProblem, rcp(&belosList, false))); } else if (solveType == "gmres") { solver = rcp(new Belos::BlockGmresSolMgr<SC, MV, OP>(belosProblem, rcp(&belosList, false))); } // Perform solve Belos::ReturnType ret = Belos::Unconverged; try { ret = solver->solve(); // Get the number of iterations for this solve. fancyout << "Number of iterations performed for this solve: " << solver->getNumIters() << std::endl; } catch(...) { fancyout << std::endl << "ERROR: Belos threw an error! " << std::endl; } // Check convergence if (ret != Belos::Converged) fancyout << std::endl << "ERROR: Belos did not converge! " << std::endl; else fancyout << std::endl << "SUCCESS: Belos converged!" << std::endl; #endif //ifdef HAVE_MUELU_BELOS } else { throw MueLu::Exceptions::RuntimeError("Unknown solver type: \"" + solveType + "\""); } comm->barrier(); tm = Teuchos::null; globalTimeMonitor = Teuchos::null; if (printTimings) TimeMonitor::summarize(A->getRowMap()->getComm().ptr(), std::cout, false, true, false, Teuchos::Union); TimeMonitor::clearCounters(); if (isDriver) { if (openedOut != NULL) { dup2(savedOut, STDOUT_FILENO); fclose(openedOut); openedOut = NULL; } try { runList = paramList.sublist("Run" + MueLu::toString(++runCount), mustAlreadyExist); mueluList = runList .sublist("MueLu", mustAlreadyExist); } catch (std::exception) { stop = true; } } } while (stop == false); } return 0; } //main
TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL(Teuchos_Validator, EnhancedNumberValidatorConverter, T) { std::string xmlFileName = TypeNameTraits<T>::name() + "EnhancedValidatorList.xml"; std::string defaultParameterName = "default"; std::string minmaxParameterName = "min max"; std::string stepPrecParameterName = "step and prec"; ParameterList myList; RCP<EnhancedNumberValidator< T > > defaultValidator = rcp( new EnhancedNumberValidator< T >()); RCP<EnhancedNumberValidator< T > > minMaxValidator = rcp( new EnhancedNumberValidator< T >(0,10)); RCP<EnhancedNumberValidator< T > > stepAndPrecValidator = rcp( new EnhancedNumberValidator< T >(0,10,4,4)); myList.set(defaultParameterName, ( T )6, "parameter with default validator", defaultValidator); myList.set(minmaxParameterName, ( T )10, "parameter with min and max validator", minMaxValidator); myList.set(stepPrecParameterName, ( T )10, "parameter with min, max, " "step, and prec validator", stepAndPrecValidator); RCP<ParameterList> readInPL = writeThenReadPL(myList); TEST_EQUALITY( rcp_dynamic_cast<const EnhancedNumberValidator< T > >( readInPL->getEntry(defaultParameterName).validator(), true)->getMin(), rcp_dynamic_cast<const EnhancedNumberValidator< T > >( myList.getEntry(defaultParameterName).validator(), true)->getMin() ); TEST_EQUALITY( rcp_dynamic_cast<const EnhancedNumberValidator< T > >( readInPL->getEntry(defaultParameterName).validator(), true)->getMax(), rcp_dynamic_cast<const EnhancedNumberValidator< T > >( myList.getEntry(defaultParameterName).validator(), true)->getMax() ); TEST_EQUALITY( rcp_dynamic_cast<const EnhancedNumberValidator< T > >( readInPL->getEntry(defaultParameterName).validator(), true)->getStep() , rcp_dynamic_cast<const EnhancedNumberValidator< T > >( myList.getEntry(defaultParameterName).validator(), true)->getStep() ); TEST_EQUALITY( rcp_dynamic_cast<const EnhancedNumberValidator< T > >( readInPL->getEntry( defaultParameterName).validator(), true)->getPrecision(), rcp_dynamic_cast<const EnhancedNumberValidator< T > >( myList.getEntry( defaultParameterName).validator(), true)->getPrecision() ); TEST_EQUALITY( rcp_dynamic_cast<const EnhancedNumberValidator< T > >( readInPL->getEntry(defaultParameterName).validator(), true)->hasMin(), rcp_dynamic_cast<const EnhancedNumberValidator< T > >( myList.getEntry(defaultParameterName).validator(), true)->hasMin() ); TEST_EQUALITY( rcp_dynamic_cast<const EnhancedNumberValidator< T > >( readInPL->getEntry(defaultParameterName).validator(), true)->hasMax(), rcp_dynamic_cast<const EnhancedNumberValidator< T > >( myList.getEntry(defaultParameterName).validator(), true)->hasMax() ); TEST_EQUALITY( rcp_dynamic_cast<const EnhancedNumberValidator< T > >( readInPL->getEntry(minmaxParameterName).validator(), true)->getMin(), rcp_dynamic_cast<const EnhancedNumberValidator< T > >( myList.getEntry(minmaxParameterName).validator(), true)->getMin() ); TEST_EQUALITY( rcp_dynamic_cast<const EnhancedNumberValidator< T > >( readInPL->getEntry(minmaxParameterName).validator(), true)->getMax(), rcp_dynamic_cast<const EnhancedNumberValidator< T > >( myList.getEntry(minmaxParameterName).validator(), true)->getMax() ); TEST_EQUALITY( rcp_dynamic_cast<const EnhancedNumberValidator< T > >( readInPL->getEntry(minmaxParameterName).validator(), true)->getStep(), rcp_dynamic_cast<const EnhancedNumberValidator< T > >( myList.getEntry(minmaxParameterName).validator(), true)->getStep() ); TEST_EQUALITY( rcp_dynamic_cast<const EnhancedNumberValidator< T > >( readInPL->getEntry( minmaxParameterName).validator(), true)->getPrecision(), rcp_dynamic_cast<const EnhancedNumberValidator< T > >( myList.getEntry( minmaxParameterName).validator(), true)->getPrecision() ); TEST_EQUALITY( rcp_dynamic_cast<const EnhancedNumberValidator< T > >( readInPL->getEntry(minmaxParameterName).validator(), true)->hasMin(), rcp_dynamic_cast<const EnhancedNumberValidator< T > >( myList.getEntry(minmaxParameterName).validator(), true)->hasMin() ); TEST_EQUALITY( rcp_dynamic_cast<const EnhancedNumberValidator< T > >( readInPL->getEntry(minmaxParameterName).validator(), true)->hasMax(), rcp_dynamic_cast<const EnhancedNumberValidator< T > >( myList.getEntry(minmaxParameterName).validator(), true)->hasMax() ); TEST_EQUALITY( rcp_dynamic_cast<const EnhancedNumberValidator< T > >( readInPL->getEntry(stepPrecParameterName).validator(), true)->getMin(), rcp_dynamic_cast<const EnhancedNumberValidator< T > >( myList.getEntry(stepPrecParameterName).validator(), true)->getMin() ); TEST_EQUALITY( rcp_dynamic_cast<const EnhancedNumberValidator< T > >( readInPL->getEntry(stepPrecParameterName).validator(), true)->getMax(), rcp_dynamic_cast<const EnhancedNumberValidator< T > >( myList.getEntry(stepPrecParameterName).validator(), true)->getMax() ); TEST_EQUALITY( rcp_dynamic_cast<const EnhancedNumberValidator< T > >( readInPL->getEntry(stepPrecParameterName).validator(), true)->getStep() , rcp_dynamic_cast<const EnhancedNumberValidator< T > >( myList.getEntry(stepPrecParameterName).validator(), true)->getStep() ); TEST_EQUALITY( rcp_dynamic_cast<const EnhancedNumberValidator< T > >( readInPL->getEntry( stepPrecParameterName).validator(), true)->getPrecision(), rcp_dynamic_cast<const EnhancedNumberValidator< T > >( myList.getEntry( stepPrecParameterName).validator(), true)->getPrecision()); }
/** * Test all the validator dependencies. */ TEUCHOS_UNIT_TEST(Teuchos_Dependencies, testValiDeps){ RCP<ParameterList> My_deplist = rcp(new ParameterList); RCP<DependencySheet> depSheet1 = rcp(new DependencySheet); /* * Testing StringValidatorDependency */ RCP<StringToIntegralParameterEntryValidator<int> > stringFoodTypeValidator = rcp( new StringToIntegralParameterEntryValidator<int>( tuple<std::string>( "Cheese", "Soda", "Chips" ) ,"Food Type" ) ); RCP<StringToIntegralParameterEntryValidator<int> > cheeseValidator = rcp( new StringToIntegralParameterEntryValidator<int>( tuple<std::string>( "Swiss", "American", "Super Awesome Cheese" ) ,"Food Selector" ) ); RCP<StringToIntegralParameterEntryValidator<int> > sodaValidator = rcp( new StringToIntegralParameterEntryValidator<int>( tuple<std::string>( "Pepsi", "Coke", "Kurtis Cola", "Bad Cola" ) ,"Food Selector" ) ); RCP<StringToIntegralParameterEntryValidator<int> > chipsValidator = rcp( new StringToIntegralParameterEntryValidator<int>( tuple<std::string>( "Lays", "Doritos", "Kurtis Super Awesome Brand" ) ,"Food Selector" ) ); StringValidatorDependency::ValueToValidatorMap testValidatorMap1; testValidatorMap1["Cheese"] = cheeseValidator; testValidatorMap1["Soda"] = sodaValidator; testValidatorMap1["Chips"] = chipsValidator; ParameterList stringValiDepList = My_deplist->sublist( "String Validator Dependency", false, "String Validator Dependency testing list."); stringValiDepList.set( "Food Selector", "Swiss", "select the food you want", cheeseValidator); stringValiDepList.set( "Food Type", "Cheese", "String Validator Dependency Tester", stringFoodTypeValidator); RCP<StringValidatorDependency> stringValiDep = rcp( new StringValidatorDependency( stringValiDepList.getEntryRCP("Food Type"), stringValiDepList.getEntryRCP("Food Selector"), testValidatorMap1, cheeseValidator ) ); depSheet1->addDependency(stringValiDep); TEST_NOTHROW(stringValiDepList.validateParameters(stringValiDepList)); TEST_ASSERT(depSheet1->hasDependents( stringValiDepList.getEntryRCP("Food Type"))); RCP<const DependencySheet::DepSet> stringValiDepSet = depSheet1->getDependenciesForParameter( stringValiDepList.getEntryRCP("Food Type")); TEST_ASSERT(stringValiDepSet->size() == 1); stringValiDepList.set("Food Type","Soda"); stringValiDep->evaluate(); TEST_ASSERT(stringValiDepList.getEntry("Food Selector").validator() == sodaValidator); TEST_THROW(stringValiDepList.validateParameters(stringValiDepList), Exceptions::InvalidParameterValue); stringValiDepList.set("Food Selector", "Pepsi"); TEST_NOTHROW(stringValiDepList.validateParameters(stringValiDepList)); /* * Tesing some different aspects of the StringValidatorDependency */ ParameterList stringValiDepList2 = My_deplist->sublist( "String Validator Dependency (other validators)", false, "String validator testing" ); RCP<StringToIntegralParameterEntryValidator<int> > stringRangeValidator = rcp( new StringToIntegralParameterEntryValidator<int>( tuple<std::string>( "1-10", "10-33", "50-60" ), "Range selector" ) ); RCP<EnhancedNumberValidator<int> > range110Vali = rcp(new EnhancedNumberValidator<int>(1,10)); RCP<EnhancedNumberValidator<int> > range1033Vali = rcp(new EnhancedNumberValidator<int>(10,33)); RCP<EnhancedNumberValidator<int> > range5060Vali = rcp(new EnhancedNumberValidator<int>(50,60)); stringValiDepList2.set("Range selector", "1-10", "selects the range to validate", stringRangeValidator); StringValidatorDependency::ValueToValidatorMap rangeValidatorMap1; rangeValidatorMap1["1-10"] = range110Vali; rangeValidatorMap1["10-33"] = range1033Vali; rangeValidatorMap1["50-60"] = range5060Vali; stringValiDepList2.set( "RangeValue", 3, "the value of the range", range110Vali); RCP<StringValidatorDependency> stringValiDep2 = RCP<StringValidatorDependency>( new StringValidatorDependency( stringValiDepList2.getEntryRCP("Range selector"), stringValiDepList2.getEntryRCP("RangeValue"), rangeValidatorMap1, range110Vali ) ); depSheet1->addDependency(stringValiDep2); TEST_NOTHROW(stringValiDepList2.validateParameters(stringValiDepList2)); TEST_ASSERT(depSheet1->hasDependents( stringValiDepList2.getEntryRCP("Range selector"))); RCP<const DependencySheet::DepSet> stringValiDepSet2 = depSheet1->getDependenciesForParameter( stringValiDepList2.getEntryRCP("Range selector")); TEST_ASSERT(stringValiDepSet2->size() == 1); stringValiDepList2.set("Range selector","50-60"); stringValiDep2->evaluate(); TEST_ASSERT(stringValiDepList2.getEntry("RangeValue").validator() == range5060Vali); TEST_THROW(stringValiDepList2.validateParameters(stringValiDepList2), Exceptions::InvalidParameterValue); stringValiDepList2.set("RangeValue", 55); TEST_NOTHROW(stringValiDepList2.validateParameters(stringValiDepList2)); /* * Testing the BoolValidatorDependency. */ ParameterList boolValidatorDepList = My_deplist->sublist( "Bool Validator Dependency List", false, "Bool Validator Dependency testing list." ); boolValidatorDepList.set("Use Validator?", true, "truns the validator on and off"); RCP<EnhancedNumberValidator<int> > basicVali = rcp(new EnhancedNumberValidator<int>(1,10)); RCP<EnhancedNumberValidator<int> > basicVali2 = rcp(new EnhancedNumberValidator<int>()); boolValidatorDepList.set("do I have a validator?", 4, "does it have a validator?", basicVali); RCP<BoolValidatorDependency> boolValiDep = RCP<BoolValidatorDependency>( new BoolValidatorDependency( boolValidatorDepList.getEntryRCP("Use Validator?"), boolValidatorDepList.getEntryRCP("do I have a validator?"), basicVali, basicVali2 ) ); depSheet1->addDependency(boolValiDep); TEST_ASSERT(depSheet1->hasDependents( boolValidatorDepList.getEntryRCP("Use Validator?"))); TEST_ASSERT( boolValidatorDepList.getEntry("do I have a validator?").validator() == basicVali); TEST_NOTHROW( boolValidatorDepList.validateParameters(boolValidatorDepList)); RCP<const DependencySheet::DepSet> boolValiDepSet = depSheet1->getDependenciesForParameter(boolValidatorDepList.getEntryRCP( "Use Validator?")); TEST_ASSERT(boolValiDepSet->size() == 1); boolValidatorDepList.set("Use Validator?",false); boolValiDep->evaluate(); TEST_ASSERT( boolValidatorDepList.getEntry("do I have a validator?").validator() == basicVali2); /* * Testing the RangeValidatorDependency */ RCP<StringToIntegralParameterEntryValidator<int> > lowTempCheeseValidator = rcp( new StringToIntegralParameterEntryValidator<int>( tuple<std::string>( "PepperJack", "Swiss", "American" ), "Cheese to Fondue" ) ); RCP<StringToIntegralParameterEntryValidator<int> > highTempCheeseValidator = rcp( new StringToIntegralParameterEntryValidator<int>( tuple<std::string>( "Munster", "Provalone", "Kurtis Super Awesome Cheese"), "Cheese to Fondue" ) ); RCP<StringToIntegralParameterEntryValidator<int> > defaultCheeseValidator = rcp( new StringToIntegralParameterEntryValidator<int>( tuple<std::string>( "Other cheese", "other cheese 1", "other cheese 3"), "Cheese to Fondue" ) ); ParameterList& rangeValidatorDepList = My_deplist->sublist( "Range Validator Dependency List", false, "Range Validator Dependency testing list.\nWorking June 27th 2009" ); rangeValidatorDepList.set( "Temperature",101.0, "The temperature of the fondue"); rangeValidatorDepList.set( "Cheese to Fondue", "Swiss", "The cheese we'll be using in our fondue pot.", lowTempCheeseValidator); RangeValidatorDependency<double>::RangeToValidatorMap tempranges; tempranges[std::pair<double,double>(100,200)] = lowTempCheeseValidator; tempranges[std::pair<double,double>(200,300)] = highTempCheeseValidator; RCP<RangeValidatorDependency<double> > cheeseTempDep = RCP<RangeValidatorDependency<double> >( new RangeValidatorDependency<double>( rangeValidatorDepList.getEntryRCP("Temperature"), rangeValidatorDepList.getEntryRCP("Cheese to Fondue"), tempranges, defaultCheeseValidator ) ); depSheet1->addDependency(cheeseTempDep); TEST_ASSERT(depSheet1->hasDependents( rangeValidatorDepList.getEntryRCP("Temperature"))); RCP<const DependencySheet::DepSet> rangeValiDepSet = depSheet1->getDependenciesForParameter( rangeValidatorDepList.getEntryRCP("Temperature")); TEST_ASSERT(rangeValiDepSet->size() == 1); rangeValidatorDepList.set("Temperature",250.0); cheeseTempDep->evaluate(); TEST_ASSERT( rangeValidatorDepList.getEntry("Cheese to Fondue").validator() == highTempCheeseValidator); TEST_THROW( rangeValidatorDepList.validateParameters(rangeValidatorDepList), Exceptions::InvalidParameterValue); rangeValidatorDepList.set("Cheese to Fondue", "Provalone"); TEST_NOTHROW( rangeValidatorDepList.validateParameters(rangeValidatorDepList)); rangeValidatorDepList.set("Temperature", 50.0); cheeseTempDep->evaluate(); TEST_ASSERT( rangeValidatorDepList.getEntry("Cheese to Fondue").validator() == defaultCheeseValidator ); }