Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007 #ifdef ALBANY_DAKOTA
00008 #include <iostream>
00009 #include "Albany_Dakota.hpp"
00010 #include "Albany_Utils.hpp"
00011
00012 #include "Teuchos_XMLParameterListHelpers.hpp"
00013 #include "TriKota_MPDirectApplicInterface.hpp"
00014 #include "Piro_Epetra_StokhosMPSolver.hpp"
00015
00016 #include "TriKota_Driver.hpp"
00017 #include "TriKota_DirectApplicInterface.hpp"
00018 #include "Albany_SolverFactory.hpp"
00019
00020
00021
00022
00023 int Albany_Dakota(int argc, char *argv[])
00024 {
00025 using std::cout;
00026 using std::endl;
00027 using Teuchos::RCP;
00028 using Teuchos::rcp;
00029 using Teuchos::FancyOStream;
00030 using Teuchos::VerboseObjectBase;
00031 using Teuchos::OSTab;
00032 using Teuchos::ParameterList;
00033
00034 const RCP<FancyOStream> out = VerboseObjectBase::getDefaultOStream();
00035
00036 *out << "\nStarting Albany_Dakota!" << endl;
00037
00038
00039 std::string xml_filename = "input.xml";
00040 if(argc>1){
00041 if(!std::strcmp(argv[1],"--help")){
00042 *out << "albany [inputfile.xml]\n";
00043 std::exit(1);
00044 }
00045 else
00046 xml_filename=argv[1];
00047 }
00048 RCP<ParameterList> appParams =
00049 Teuchos::getParametersFromXmlFile(xml_filename);
00050 ParameterList& dakotaParams = appParams->sublist("Piro").sublist("Dakota");
00051 std::string dakota_input_file =
00052 dakotaParams.get("Input File", "dakota.in");
00053 std::string dakota_output_file =
00054 dakotaParams.get("Output File", "dakota.out");
00055 std::string dakota_restart_file =
00056 dakotaParams.get("Restart File", "dakota.res");
00057 std::string dakota_error_file =
00058 dakotaParams.get("Error File", "dakota.err");
00059
00060 std::string dakotaRestartIn;
00061 const char * dakRestartIn = NULL;
00062 if (dakotaParams.isParameter("Restart File To Read")) {
00063 dakotaRestartIn = dakotaParams.get<std::string>("Restart File To Read");
00064 dakRestartIn = dakotaRestartIn.c_str();
00065 }
00066 int dakotaRestartEvals= dakotaParams.get("Restart Evals To Read", 0);
00067
00068 int p_index = dakotaParams.get("Parameter Vector Index", 0);
00069 int g_index = dakotaParams.get("Response Vector Index", 0);
00070
00071
00072 TriKota::Driver dakota(dakota_input_file.c_str(),
00073 dakota_output_file.c_str(),
00074 dakota_restart_file.c_str(),
00075 dakota_error_file.c_str(),
00076 dakRestartIn, dakotaRestartEvals );
00077
00078
00079
00080
00081
00082
00083
00084 Albany_MPI_Comm analysis_comm = dakota.getAnalysisComm();
00085 if (analysis_comm == Albany_MPI_COMM_NULL)
00086 return 0;
00087 RCP<Epetra_Comm> appComm =
00088 Albany::createEpetraCommFromMpiComm(analysis_comm);
00089 RCP<Albany::SolverFactory> slvrfctry =
00090 rcp(new Albany::SolverFactory(xml_filename, analysis_comm));
00091
00092
00093
00094 RCP<Dakota::DirectApplicInterface> trikota_interface;
00095 bool use_multi_point = dakotaParams.get("Use Multi-Point", false);
00096 if (use_multi_point) {
00097
00098 RCP<ParameterList> mpParams =
00099 rcp(&(dakotaParams.sublist("Multi-Point")),false);
00100 ParameterList& appParams2 = slvrfctry->getParameters();
00101 RCP<ParameterList> piroParams =
00102 rcp(&(appParams2.sublist("Piro")),false);
00103 RCP<Piro::Epetra::StokhosMPSolver> mp_solver =
00104 rcp(new Piro::Epetra::StokhosMPSolver(
00105 piroParams, mpParams, appComm,
00106 mpParams->get("Block Size", 10),
00107 mpParams->get("Number of Spatial Processors", -1)));
00108
00109
00110 Teuchos::RCP<Albany::Application> app;
00111 Teuchos::RCP<EpetraExt::ModelEvaluator> model =
00112 slvrfctry->createAlbanyAppAndModel(app, appComm);
00113
00114
00115 mp_solver->setup(model);
00116
00117 trikota_interface =
00118 rcp(new TriKota::MPDirectApplicInterface(dakota.getProblemDescDB(),
00119 mp_solver, p_index, g_index),
00120 false);
00121 }
00122 else {
00123 RCP<EpetraExt::ModelEvaluator> App = slvrfctry->create(appComm, appComm);
00124 trikota_interface =
00125 rcp(new TriKota::DirectApplicInterface(dakota.getProblemDescDB(), App,
00126 p_index, g_index),
00127 false);
00128 }
00129
00130
00131 dakota.run(trikota_interface.get());
00132
00133 if (dakota.rankZero()) {
00134 Dakota::RealVector finalValues =
00135 dakota.getFinalSolution().continuous_variables();
00136 *out << "\nAlbany_Dakota: Final Values from Dakota = "
00137 << std::setprecision(8) << finalValues << endl;
00138
00139 return slvrfctry->checkDakotaTestResults(0, &finalValues);
00140 }
00141 else return 0;
00142 }
00143 #endif