Пример #1
0
int main(int argc, char *argv[]) {

  int status=0; // 0 = pass, failures are incremented
  bool success = true;
  Teuchos::GlobalMPISession mpiSession(&argc,&argv);
  Teuchos::RCP<Teuchos::FancyOStream> out(Teuchos::VerboseObjectBase::getDefaultOStream());

  // Command-line argument for input file
  char * xmlfilename=0;
  char defaultfile[20]={"inputAnalysis.xml"};
  if(argc>1){
    if(!strcmp(argv[1],"--help")){
      printf("albanyAnalysis [inputfile.xml]\n");
      exit(1);
    }
    else
      xmlfilename=argv[1];
  }
  else
    xmlfilename=defaultfile;


  try {
    Teuchos::RCP<Teuchos::Time> totalTime = 
      Teuchos::TimeMonitor::getNewTimer("AlbanyAnalysis: ***Total Time***");
    Teuchos::TimeMonitor totalTimer(*totalTime); //start timer

    using namespace std;

    *out << "\nStarting Albany Analysis via Piro!" << std::endl;

    // Construct a ModelEvaluator for your application;
  
    Teuchos::RCP<Albany::SolverFactory> slvrfctry =
      Teuchos::rcp(new Albany::SolverFactory(xmlfilename, Albany_MPI_COMM_WORLD));
    Teuchos::RCP<Epetra_Comm> appComm = Albany::createEpetraCommFromMpiComm(Albany_MPI_COMM_WORLD);
    Teuchos::RCP<EpetraExt::ModelEvaluator> App = slvrfctry->create(appComm, appComm);


    Thyra::EpetraModelEvaluator appThyra;
    appThyra.initialize(App, Teuchos::null);

    Teuchos::RCP< Thyra::VectorBase<double> > p;

    status = Piro::PerformAnalysis(appThyra, slvrfctry->getAnalysisParameters(), p); 

//    Dakota::RealVector finalValues = dakota.getFinalSolution().continuous_variables();
//    std::cout << "\nAlbany_Dakota: Final Values from Dakota = " 
//         << setprecision(8) << finalValues << std::endl;

    status =  slvrfctry->checkAnalysisTestResults(0, p);

    // Regression comparisons for Dakota runs only valid on Proc 0.
    if (mpiSession.getRank()>0)  status=0;
    else *out << "\nNumber of Failed Comparisons: " << status << std::endl;
  }
  TEUCHOS_STANDARD_CATCH_STATEMENTS(true, std::cerr, success);
  if (!success) status+=10000;
  
  Teuchos::TimeMonitor::summarize(std::cout, false, true, false);
  return status;
}
Пример #2
0
int main(int argc, char *argv[]) {

  int status=0; // 0 = pass, failures are incremented
  int overall_status=0; // 0 = pass, failures are incremented over multiple tests
  bool success=true;

  // Initialize MPI 
  Teuchos::GlobalMPISession mpiSession(&argc,&argv);
  int Proc=mpiSession.getRank();
#ifdef HAVE_MPI
  MPI_Comm appComm = MPI_COMM_WORLD;
#else
  int appComm=0;
#endif

  using Teuchos::RCP;
  using Teuchos::rcp;

  std::string inputFile;
  bool doAll = (argc==1);
  if (argc>1) doAll = !strcmp(argv[1],"-v");


  for (int iTest=0; iTest<3; iTest++) {

    if (doAll) {
      switch (iTest) {
       case 0: inputFile="input_Analysis_Dakota.xml"; break;
       case 1: inputFile="input_Analysis_OptiPack.xml"; break;
       case 2: inputFile="input_Analysis_MOOCHO.xml"; break;
       default : cout << "iTest logic error " << endl; exit(-1);
      }
    }
    else {
      inputFile=argv[1];
      iTest = 999;
    }

    if (Proc==0) 
     cout << "===================================================\n"
          << "======  Running input file "<< iTest <<": "<< inputFile <<"\n"
          << "===================================================\n"
          << endl;

    try {

      // Create (1) a Model Evaluator and (2) a ParameterList
      RCP<EpetraExt::ModelEvaluator> Model = rcp(new MockModelEval_A(appComm));

      // BEGIN Builder
      Teuchos::ParameterList appParams("Application Parameters");
      Teuchos::updateParametersFromXmlFile(inputFile, Teuchos::ptr(&appParams));

      Teuchos::ParameterList piroParams = appParams.sublist("Piro");
      Teuchos::ParameterList& analysisParams = appParams.sublist("Analysis");

      // Use these two objects to construct a Piro solved application 
      //   EpetraExt::ModelEvaluator is  base class of all Piro::Epetra solvers
      RCP<EpetraExt::ModelEvaluator> piro;

      std::string& solver = piroParams.get("Piro Solver","NOX");
      const RCP<Teuchos::ParameterList> piroParamsRCP = rcp(&piroParams, false);

#ifdef Piro_ENABLE_NOX
      RCP<NOX::Epetra::Observer> observer = rcp(new ObserveSolution_Epetra());

      if (solver=="NOX")
        piro = rcp(new Piro::Epetra::NOXSolver(piroParamsRCP, Model, observer));
      else if (solver=="LOCA")
        piro = rcp(new Piro::Epetra::LOCASolver(piroParamsRCP, Model, observer));
      else
#endif
#ifdef Piro_ENABLE_Rythmos
      if (solver=="Rythmos")
        piro = rcp(new Piro::Epetra::RythmosSolver(piroParamsRCP, Model));
      else 
#endif
        TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
          "Error: Unknown Piro Solver : " << solver);
      // END Builder

      Thyra::EpetraModelEvaluator piroThyra;
      piroThyra.initialize(piro, Teuchos::null);

      RCP< Thyra::VectorBase<double> > p;

      // Now call the analysis routine
      status = Piro::PerformAnalysis(piroThyra, analysisParams, p);

      if (p != Teuchos::null) {
        // Can post-process results here
         if (Proc==0) cout << 
           "\nPiro_AnalysisDrvier:  Optimum printed above has exact soln = {1,3}" << endl;
      }

    }
    TEUCHOS_STANDARD_CATCH_STATEMENTS(true, std::cerr, success);
    if (!success) status+=1000;

    overall_status += status;
  }  // End loop over tests

  if (Proc==0) {
    if (overall_status==0) 
      cout << "\nTEST PASSED\n" << endl;
    else 
      cout << "\nTEST Failed: " << overall_status << "\n" << endl;
  }

  return status;
}