当前位置: 首页>>代码示例>>C++>>正文


C++ ParameterList::getEntry方法代码示例

本文整理汇总了C++中ParameterList::getEntry方法的典型用法代码示例。如果您正苦于以下问题:C++ ParameterList::getEntry方法的具体用法?C++ ParameterList::getEntry怎么用?C++ ParameterList::getEntry使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ParameterList的用法示例。


在下文中一共展示了ParameterList::getEntry方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

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>(&paramList), *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);
//.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:101,代码来源:

示例2: rcp

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()
//.........这里部分代码省略.........
开发者ID:00liujj,项目名称:trilinos,代码行数:101,代码来源:Validator_SerializationTest.cpp

示例3: StringValidatorDependency

/**
 * 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(
//.........这里部分代码省略.........
开发者ID:OpenModelica,项目名称:OMCompiler-3rdParty,代码行数:101,代码来源:Dependencies_UnitTests.cpp


注:本文中的ParameterList::getEntry方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。