Go to the documentation of this file.00001
00002
00003
00004
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
00014 #include "Teuchos_GlobalMPISession.hpp"
00015 #include "Teuchos_TimeMonitor.hpp"
00016 #include "Teuchos_VerboseObject.hpp"
00017 #include "Teuchos_StandardCatchMacros.hpp"
00018
00019 #include "Epetra_Map.h"
00020 #include "Stokhos.hpp"
00021 #include "Stokhos_Epetra.hpp"
00022 #include "Piro_Epetra_StokhosSolver.hpp"
00023 #include "Piro_Epetra_NECoupledModelEvaluator.hpp"
00024
00025 #include "Albany_Networks.hpp"
00026
00027 int main(int argc, char *argv[]) {
00028
00029 int status=0;
00030 bool success = true;
00031 Teuchos::GlobalMPISession mpiSession(&argc,&argv);
00032
00033 using Teuchos::RCP;
00034 using Teuchos::rcp;
00035
00036 RCP<Teuchos::FancyOStream> out(Teuchos::VerboseObjectBase::getDefaultOStream());
00037
00038
00039
00040
00041
00042 std::string xmlfilename_coupled;
00043 if(argc > 1){
00044 if(!strcmp(argv[1],"--help")){
00045 std::cout << "albany [inputfile.xml]" << std::endl;
00046 std::exit(1);
00047 }
00048 else
00049 xmlfilename_coupled = argv[1];
00050 }
00051 else
00052 xmlfilename_coupled = "input.xml";
00053
00054
00055 try {
00056
00057 RCP<Teuchos::Time> totalTime =
00058 Teuchos::TimeMonitor::getNewTimer("AlbanySG: ***Total Time***");
00059 RCP<Teuchos::Time> setupTime =
00060 Teuchos::TimeMonitor::getNewTimer("AlbanySG: Setup Time");
00061 Teuchos::TimeMonitor totalTimer(*totalTime);
00062
00063
00064
00065
00066 Teuchos::RCP<Epetra_Comm> globalComm =
00067 Albany::createEpetraCommFromMpiComm(Albany_MPI_COMM_WORLD);
00068 Albany::SolverFactory coupled_slvrfctry(xmlfilename_coupled,
00069 Albany_MPI_COMM_WORLD);
00070 Teuchos::ParameterList& coupledParams = coupled_slvrfctry.getParameters();
00071 Teuchos::ParameterList& coupledSystemParams =
00072 coupledParams.sublist("Coupled System");
00073 Teuchos::Array<std::string> model_filenames =
00074 coupledSystemParams.get<Teuchos::Array<std::string> >("Model XML Files");
00075 int num_models = model_filenames.size();
00076 Teuchos::Array< RCP<Albany::Application> > apps(num_models);
00077 Teuchos::Array< RCP<EpetraExt::ModelEvaluator> > models(num_models);
00078 Teuchos::Array< RCP<Teuchos::ParameterList> > piroParams(num_models);
00079 Teuchos::RCP< Teuchos::ParameterList> coupledPiroParams =
00080 Teuchos::rcp(&(coupledParams.sublist("Piro")),false);
00081 Teuchos::RCP<Piro::Epetra::StokhosSolver> coupledSolver =
00082 Teuchos::rcp(new Piro::Epetra::StokhosSolver(coupledPiroParams,
00083 globalComm));
00084 Teuchos::RCP<const Epetra_Comm> app_comm = coupledSolver->getSpatialComm();
00085
00086
00087 Teuchos::Array< Teuchos::RCP<NOX::Epetra::Observer> > observers(num_models);
00088 for (int m=0; m<num_models; m++) {
00089 Albany::SolverFactory slvrfctry(
00090 model_filenames[m],
00091 Albany::getMpiCommFromEpetraComm(*app_comm));
00092 models[m] = slvrfctry.createAlbanyAppAndModel(apps[m], app_comm);
00093 Teuchos::ParameterList& appParams = slvrfctry.getParameters();
00094 piroParams[m] = Teuchos::rcp(&(appParams.sublist("Piro")),false);
00095 observers[m] = Teuchos::rcp(new Albany_NOXObserver(apps[m]));
00096 }
00097
00098
00099 std::string network_name =
00100 coupledSystemParams.get("Network Model", "Param To Response");
00101 RCP<Piro::Epetra::AbstractNetworkModel> network_model;
00102 if (network_name == "Param To Response")
00103 network_model = rcp(new Piro::Epetra::ParamToResponseNetworkModel);
00104 else if (network_name == "Reactor Network")
00105 network_model = rcp(new Albany::ReactorNetworkModel(1));
00106 else
00107 TEUCHOS_TEST_FOR_EXCEPTION(
00108 true, std::logic_error, "Invalid network model name " << network_name);
00109 RCP<EpetraExt::ModelEvaluator> coupledModel =
00110 rcp(new Piro::Epetra::NECoupledModelEvaluator(models, piroParams,
00111 network_model,
00112 coupledPiroParams,
00113 globalComm,
00114 observers));
00115 coupledSolver->setup(coupledModel);
00116
00117
00118 EpetraExt::ModelEvaluator::InArgs inArgs = coupledSolver->createInArgs();
00119 EpetraExt::ModelEvaluator::OutArgs outArgs = coupledSolver->createOutArgs();
00120 for (int i=0; i<inArgs.Np(); i++)
00121 if (inArgs.supports(EpetraExt::ModelEvaluator::IN_ARG_p_sg, i))
00122 inArgs.set_p_sg(i, coupledSolver->get_p_sg_init(i));
00123 for (int i=0; i<outArgs.Ng(); i++)
00124 if (outArgs.supports(EpetraExt::ModelEvaluator::OUT_ARG_g_sg, i)) {
00125 RCP<Stokhos::EpetraVectorOrthogPoly> g_sg =
00126 coupledSolver->create_g_sg(i);
00127 outArgs.set_g_sg(i, g_sg);
00128 }
00129 coupledSolver->evalModel(inArgs, outArgs);
00130
00131
00132 bool printResponse =
00133 coupledSystemParams.get("Print Response Expansion", true);
00134 int idx = outArgs.Ng()-1;
00135 Teuchos::RCP<Stokhos::EpetraVectorOrthogPoly> g_sg =
00136 outArgs.get_g_sg(idx);
00137 Teuchos::RCP<Stokhos::SGModelEvaluator> sg_model =
00138 coupledSolver->get_sg_model();
00139 Teuchos::RCP<Stokhos::EpetraVectorOrthogPoly> g_sg_local =
00140
00141 g_sg;
00142 Epetra_Vector g_mean(*(g_sg->coefficientMap()));
00143 Epetra_Vector g_std_dev(*(g_sg->coefficientMap()));
00144 g_sg->computeMean(g_mean);
00145 g_sg->computeStandardDeviation(g_std_dev);
00146 RCP<Epetra_Vector> g_mean_local = rcp(&g_mean,false);
00147 RCP<Epetra_Vector> g_std_dev_local = rcp(&g_std_dev,false);
00148 if (g_mean.Map().DistributedGlobal()) {
00149 Epetra_LocalMap local_map(g_mean.GlobalLength(), 0,
00150 g_mean.Map().Comm());
00151 g_mean_local = rcp(new Epetra_Vector(local_map));
00152 g_std_dev_local = rcp(new Epetra_Vector(local_map));
00153 Epetra_Import importer(local_map, g_mean.Map());
00154 g_mean_local->Import(g_mean, importer, Insert);
00155 g_std_dev_local->Import(g_std_dev, importer, Insert);
00156 }
00157 out->precision(16);
00158 *out << std::endl
00159 << "Final value of coupling variables:" << std::endl
00160 << "Mean:" << std::endl << *g_mean_local << std::endl
00161 << "Std. Dev.:" << std::endl << *g_std_dev_local << std::endl;
00162 if (printResponse)
00163 *out << "PCE:" << std::endl << *g_sg_local << std::endl;
00164
00165 status += coupled_slvrfctry.checkSGTestResults(
00166 0,
00167 g_sg_local,
00168 g_mean_local.get(),
00169 g_std_dev_local.get());
00170 *out << "\nNumber of Failed Comparisons: " << status << std::endl;
00171 }
00172
00173 TEUCHOS_STANDARD_CATCH_STATEMENTS(true, std::cerr, success);
00174 if (!success) status+=10000;
00175
00176 Teuchos::TimeMonitor::summarize(*out,false,true,false);
00177 return status;
00178 }