• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

Main_Coupled.cpp

Go to the documentation of this file.
00001 //*****************************************************************//
00002 //    Albany 2.0:  Copyright 2012 Sandia Corporation               //
00003 //    This Software is released under the BSD license detailed     //
00004 //    in the file "license.txt" in the top-level Albany directory  //
00005 //*****************************************************************//
00006 
00007 #include <iostream>
00008 #include <string>
00009 
00010 #include "Albany_Utils.hpp"
00011 #include "Albany_SolverFactory.hpp"
00012 #include "Albany_NOXObserver.hpp"
00013 #include "Teuchos_GlobalMPISession.hpp"
00014 #include "Teuchos_TimeMonitor.hpp"
00015 #include "Teuchos_VerboseObject.hpp"
00016 #include "Teuchos_StandardCatchMacros.hpp"
00017 #include "Epetra_Map.h"  //Needed for serial, somehow
00018 #include "Piro_Epetra_NECoupledModelEvaluator.hpp"
00019 #include "Piro_Epetra_Factory.hpp"
00020 #include "Epetra_LocalMap.h"
00021 #include "Epetra_Import.h"
00022 
00023 #include "Albany_Networks.hpp"
00024 
00025 int main(int argc, char *argv[]) {
00026 
00027   int status=0; // 0 = pass, failures are incremented
00028   bool success = true;
00029   Teuchos::GlobalMPISession mpiSession(&argc,&argv);
00030 
00031   using Teuchos::RCP;
00032   using Teuchos::rcp;
00033 
00034   RCP<Teuchos::FancyOStream> out(Teuchos::VerboseObjectBase::getDefaultOStream());
00035   
00036   //***********************************************************
00037   // Command-line argument for input file
00038   //***********************************************************
00039 
00040   std::string xmlfilename_coupled;
00041   if(argc > 1){
00042     if(!strcmp(argv[1],"--help")){
00043       std::cout << "albany [inputfile.xml]" << std::endl;
00044       std::exit(1);
00045     }
00046     else
00047       xmlfilename_coupled = argv[1];
00048   }
00049   else
00050     xmlfilename_coupled = "input.xml";
00051 
00052   try {
00053 
00054     RCP<Teuchos::Time> totalTime = 
00055       Teuchos::TimeMonitor::getNewTimer("Albany: ***Total Time***");
00056     RCP<Teuchos::Time> setupTime = 
00057       Teuchos::TimeMonitor::getNewTimer("Albany: Setup Time");
00058     Teuchos::TimeMonitor totalTimer(*totalTime); //start timer
00059     Teuchos::TimeMonitor setupTimer(*setupTime); //start timer
00060 
00061     //***********************************************************
00062     // Set up coupled model
00063     //***********************************************************
00064 
00065     Albany::SolverFactory coupled_slvrfctry(xmlfilename_coupled, 
00066               Albany_MPI_COMM_WORLD);
00067     RCP<Epetra_Comm> coupledComm = 
00068       Albany::createEpetraCommFromMpiComm(Albany_MPI_COMM_WORLD);
00069     Teuchos::ParameterList& coupledParams = coupled_slvrfctry.getParameters();
00070     Teuchos::ParameterList& coupledSystemParams = 
00071       coupledParams.sublist("Coupled System");
00072     Teuchos::RCP< Teuchos::ParameterList> coupledPiroParams = 
00073       Teuchos::rcp(&(coupledParams.sublist("Piro")),false);
00074     Teuchos::Array<std::string> model_filenames =
00075       coupledSystemParams.get<Teuchos::Array<std::string> >("Model XML Files");
00076     int num_models = model_filenames.size();
00077     Teuchos::Array< RCP<Albany::Application> > apps(num_models);
00078     Teuchos::Array< RCP<EpetraExt::ModelEvaluator> > models(num_models);
00079     Teuchos::Array< RCP<Teuchos::ParameterList> > piroParams(num_models);
00080 
00081     // Set up each model
00082     for (int m=0; m<num_models; m++) {
00083       Albany::SolverFactory slvrfctry(model_filenames[m], 
00084               Albany_MPI_COMM_WORLD);
00085       RCP<Epetra_Comm> appComm = 
00086   Albany::createEpetraCommFromMpiComm(Albany_MPI_COMM_WORLD);
00087       models[m] = slvrfctry.createAlbanyAppAndModel(apps[m], appComm);
00088       Teuchos::ParameterList& appParams = slvrfctry.getParameters();
00089       piroParams[m] = Teuchos::rcp(&(appParams.sublist("Piro")),false);
00090     }
00091     
00092     // Setup network model
00093     std::string network_name = 
00094       coupledSystemParams.get("Network Model", "Param To Response");
00095     RCP<Piro::Epetra::AbstractNetworkModel> network_model;
00096     if (network_name == "Param To Response")
00097       network_model = rcp(new Piro::Epetra::ParamToResponseNetworkModel);
00098     else if (network_name == "Reactor Network")
00099       network_model = rcp(new Albany::ReactorNetworkModel(1));
00100     else
00101       TEUCHOS_TEST_FOR_EXCEPTION(
00102   true, std::logic_error, "Invalid network model name " << network_name);
00103     RCP<EpetraExt::ModelEvaluator> coupledModel =
00104       rcp(new Piro::Epetra::NECoupledModelEvaluator(models, piroParams,
00105                 network_model,
00106                 coupledPiroParams, 
00107                 coupledComm));
00108     RCP<EpetraExt::ModelEvaluator> coupledSolver =
00109       Piro::Epetra::Factory::createSolver(coupledPiroParams, coupledModel);
00110     
00111     // Solve coupled system
00112     EpetraExt::ModelEvaluator::InArgs inArgs = coupledSolver->createInArgs();
00113     EpetraExt::ModelEvaluator::OutArgs outArgs = coupledSolver->createOutArgs();
00114     for (int i=0; i<inArgs.Np(); i++)
00115       inArgs.set_p(i, coupledSolver->get_p_init(i));
00116     for (int i=0; i<outArgs.Ng(); i++) {
00117       RCP<Epetra_Vector> g = 
00118   rcp(new Epetra_Vector(*(coupledSolver->get_g_map(i))));
00119       outArgs.set_g(i, g);
00120     }
00121     coupledSolver->evalModel(inArgs, outArgs);
00122 
00123     // "observe solution" -- need to integrate this with the solvers
00124     for (int m=0; m<num_models; m++) {
00125       Albany_NOXObserver observer(apps[m]);
00126       observer.observeSolution(*(outArgs.get_g(m)));
00127     }
00128     
00129     // Print results
00130     RCP<Epetra_Vector> x_final = outArgs.get_g(outArgs.Ng()-1);
00131     RCP<Epetra_Vector> x_final_local = x_final;
00132     if (x_final->Map().DistributedGlobal()) {
00133       Epetra_LocalMap local_map(x_final->GlobalLength(), 0, 
00134         x_final->Map().Comm());
00135       x_final_local = rcp(new Epetra_Vector(local_map));
00136       Epetra_Import importer(local_map, x_final->Map());
00137       x_final_local->Import(*x_final, importer, Insert);
00138     }
00139     *out << std::endl
00140    << "Final value of coupling variables:" << std::endl
00141    << *x_final_local << std::endl;
00142 
00143     status += coupled_slvrfctry.checkSolveTestResults(0, 0, x_final_local.get(), NULL);
00144     *out << "\nNumber of Failed Comparisons: " << status << std::endl;
00145   }
00146 
00147   TEUCHOS_STANDARD_CATCH_STATEMENTS(true, std::cerr, success);
00148   if (!success) status+=10000;
00149 
00150   Teuchos::TimeMonitor::summarize(*out,false,true,false/*zero timers*/);
00151   return status;
00152 }

Generated on Wed Mar 26 2014 18:36:39 for Albany: a Trilinos-based PDE code by  doxygen 1.7.1