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

Albany_ResponseFactory.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 "Albany_ResponseFactory.hpp"
00008 
00009 #include "Albany_SolutionAverageResponseFunction.hpp"
00010 #include "Albany_SolutionTwoNormResponseFunction.hpp"
00011 #include "Albany_SolutionValuesResponseFunction.hpp"
00012 #include "Albany_SolutionMaxValueResponseFunction.hpp"
00013 #include "Albany_SolutionFileResponseFunction.hpp"
00014 #include "Albany_AggregateScalarResponseFunction.hpp"
00015 #include "Albany_FieldManagerScalarResponseFunction.hpp"
00016 #include "Albany_SolutionResponseFunction.hpp"
00017 #include "Albany_KLResponseFunction.hpp"
00018 #ifdef ALBANY_QCAD
00019 #include "QCAD_SaddleValueResponseFunction.hpp"
00020 #endif
00021 
00022 #include "Teuchos_TestForException.hpp"
00023 
00024 void
00025 Albany::ResponseFactory::
00026 createResponseFunction(
00027   const std::string& name,
00028   Teuchos::ParameterList& responseParams,
00029   Teuchos::Array< Teuchos::RCP<AbstractResponseFunction> >& responses) const
00030 {
00031   using std::string;
00032   using Teuchos::RCP;
00033   using Teuchos::rcp;
00034   using Teuchos::ParameterList;
00035   using Teuchos::Array;
00036 
00037   RCP<const Epetra_Comm> comm = app->getComm();
00038 
00039   if (name == "Solution Average") {
00040     responses.push_back(rcp(new Albany::SolutionAverageResponseFunction(comm)));
00041   }
00042 
00043   else if (name == "Solution Two Norm") {
00044     responses.push_back(rcp(new Albany::SolutionTwoNormResponseFunction(comm)));
00045   }
00046 
00047   else if (name == "Solution Values") {
00048     responses.push_back(rcp(new Albany::SolutionValuesResponseFunction(app, responseParams)));
00049   }
00050 
00051   else if (name == "Solution Max Value") {
00052     int eq = responseParams.get("Equation", 0);
00053     int neq = responseParams.get("Num Equations", 1);
00054     bool inor =  responseParams.get("Interleaved Ordering", true);
00055 
00056     responses.push_back(
00057       rcp(new Albany::SolutionMaxValueResponseFunction(comm, neq, eq, inor)));
00058   }
00059 
00060   else if (name == "Solution Two Norm File") {
00061     responses.push_back(
00062       rcp(new Albany::SolutionFileResponseFunction<Albany::NormTwo>(comm)));
00063   }
00064 
00065   else if (name == "Solution Inf Norm File") {
00066     responses.push_back(
00067       rcp(new Albany::SolutionFileResponseFunction<Albany::NormInf>(comm)));
00068   }
00069 
00070   else if (name == "Aggregated") {
00071     int num_aggregate_responses = responseParams.get<int>("Number");
00072     Array< RCP<AbstractResponseFunction> > aggregated_responses;
00073     Array< RCP<ScalarResponseFunction> > scalar_responses;
00074     for (int i=0; i<num_aggregate_responses; i++) {
00075       std::string id = Albany::strint("Response",i);
00076       std::string name = responseParams.get<std::string>(id);
00077       std::string sublist_name = Albany::strint("ResponseParams",i);
00078       createResponseFunction(name, responseParams.sublist(sublist_name),
00079            aggregated_responses);
00080 
00081     }
00082     scalar_responses.resize(aggregated_responses.size());
00083     for (int i=0; i<aggregated_responses.size(); i++) {
00084       TEUCHOS_TEST_FOR_EXCEPTION(
00085   aggregated_responses[i]->isScalarResponse() != true, std::logic_error,
00086   "Response function " << i << " is not a scalar response function." <<
00087   std::endl <<
00088   "The aggregated response can only aggregate scalar response " <<
00089   "functions!");
00090       scalar_responses[i] =
00091   Teuchos::rcp_dynamic_cast<ScalarResponseFunction>(
00092     aggregated_responses[i]);
00093     }
00094     responses.push_back(
00095       rcp(new Albany::AggregateScalarResponseFunction(comm, scalar_responses)));
00096   }
00097 
00098   else if (name == "Field Integral" ||
00099      name == "Field Value" ||
00100      name == "Field Average" ||
00101      name == "Surface Velocity Mismatch" ||
00102      name == "Center Of Mass" ||
00103      name == "Save Field" ||
00104      name == "Region Boundary" ||
00105      name == "Element Size Field" ||
00106      name == "IP to Nodal Field" ||
00107      name == "Save Nodal Fields" ||
00108      name == "PHAL Field Integral") {
00109     responseParams.set("Name", name);
00110     for (int i=0; i<meshSpecs.size(); i++) {
00111       responses.push_back(
00112   rcp(new Albany::FieldManagerScalarResponseFunction(
00113         app, prob, meshSpecs[i], stateMgr, responseParams)));
00114     }
00115   }
00116 
00117   else if (name == "Solution") {
00118     responses.push_back(
00119       rcp(new Albany::SolutionResponseFunction(app, responseParams)));
00120   }
00121 
00122   else if (name == "KL") {
00123     Array< RCP<AbstractResponseFunction> > base_responses;
00124     std::string name = responseParams.get<std::string>("Response");
00125     createResponseFunction(name, responseParams.sublist("ResponseParams"),
00126          base_responses);
00127     for (int i=0; i<base_responses.size(); i++)
00128       responses.push_back(
00129   rcp(new Albany::KLResponseFunction(base_responses[i], responseParams)));
00130   }
00131 
00132 #ifdef ALBANY_QCAD
00133   else if (name == "Saddle Value") {
00134     responseParams.set("Name", name);
00135     for (int i=0; i<meshSpecs.size(); i++) {
00136       responses.push_back(
00137   rcp(new QCAD::SaddleValueResponseFunction(
00138         app, prob, meshSpecs[i], stateMgr, responseParams)));
00139     }
00140   }
00141 #endif
00142 
00143   else {
00144     TEUCHOS_TEST_FOR_EXCEPTION(
00145       true, Teuchos::Exceptions::InvalidParameter,
00146       std::endl << "Error!  Unknown response function " << name <<
00147       "!" << std::endl << "Supplied parameter list is " <<
00148       std::endl << responseParams);
00149   }
00150 }
00151 
00152 Teuchos::Array< Teuchos::RCP<Albany::AbstractResponseFunction> >
00153 Albany::ResponseFactory::
00154 createResponseFunctions(Teuchos::ParameterList& responseList) const
00155 {
00156   using Teuchos::RCP;
00157   using Teuchos::rcp;
00158   using Teuchos::ParameterList;
00159   using Teuchos::Array;
00160 
00161   // First check for the old response specification
00162   if (responseList.isType<int>("Number")) {
00163     int num_aggregate_responses = responseList.get<int>("Number");
00164     if (num_aggregate_responses > 0) {
00165       Array<RCP<AbstractResponseFunction> > responses;
00166       createResponseFunction("Aggregated", responseList, responses);
00167       return responses;
00168     }
00169   }
00170 
00171   int num_response_vecs = responseList.get("Number of Response Vectors", 0);
00172   Array<RCP<AbstractResponseFunction> > responses;
00173 
00174   for (int i=0; i<num_response_vecs; i++) {
00175     std::string sublist_name = Albany::strint("Response Vector",i);
00176     ParameterList& response_params =
00177       responseList.sublist(sublist_name);
00178     std::string response_name = response_params.get<std::string>("Name");
00179     createResponseFunction(response_name, response_params, responses);
00180   }
00181 
00182   return responses;
00183 }

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