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

Albany_SolutionValuesResponseFunction.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_SolutionValuesResponseFunction.hpp"
00008 
00009 #include "Albany_SolutionCullingStrategy.hpp"
00010 
00011 #include "Epetra_ImportWithAlternateMap.hpp"
00012 
00013 #include "Epetra_Import.h"
00014 
00015 #include "Teuchos_RCP.hpp"
00016 #include "Teuchos_Array.hpp"
00017 
00018 #include "Teuchos_Assert.hpp"
00019 
00020 
00021 Albany::SolutionValuesResponseFunction::
00022 SolutionValuesResponseFunction(const Teuchos::RCP<const Application>& app,
00023                                Teuchos::ParameterList& responseParams) :
00024   SamplingBasedScalarResponseFunction(app->getComm()),
00025   app_(app),
00026   cullingStrategy_(createSolutionCullingStrategy(app, responseParams)),
00027   solutionImporter_()
00028 {
00029 }
00030 
00031 void
00032 Albany::SolutionValuesResponseFunction::
00033 setup()
00034 {
00035   cullingStrategy_->setup();
00036   this->updateSolutionImporter();
00037 }
00038 
00039 unsigned int
00040 Albany::SolutionValuesResponseFunction::
00041 numResponses() const
00042 {
00043   return Teuchos::nonnull(solutionImporter_) ?
00044     solutionImporter_->TargetMap().NumMyElements() :
00045     0u;
00046 }
00047 
00048 void
00049 Albany::SolutionValuesResponseFunction::
00050 evaluateResponse(const double /*current_time*/,
00051      const Epetra_Vector* /*xdot*/,
00052      const Epetra_Vector* /*xdot*/,
00053      const Epetra_Vector& x,
00054      const Teuchos::Array<ParamVec>& /*p*/,
00055      Epetra_Vector& g)
00056 {
00057   this->updateSolutionImporter();
00058   Epetra::ImportWithAlternateMap(*solutionImporter_, x, g, Insert);
00059 }
00060 
00061 void
00062 Albany::SolutionValuesResponseFunction::
00063 evaluateTangent(const double /*alpha*/,
00064     const double beta,
00065     const double omega,
00066     const double /*current_time*/,
00067     bool /*sum_derivs*/,
00068     const Epetra_Vector* /*xdot*/,
00069     const Epetra_Vector* /*xdot*/,
00070     const Epetra_Vector& x,
00071     const Teuchos::Array<ParamVec>& /*p*/,
00072     ParamVec* /*deriv_p*/,
00073     const Epetra_MultiVector* /*Vxdot*/,
00074     const Epetra_MultiVector* /*Vxdot*/,
00075     const Epetra_MultiVector* Vx,
00076     const Epetra_MultiVector* /*Vp*/,
00077     Epetra_Vector* g,
00078     Epetra_MultiVector* gx,
00079     Epetra_MultiVector* gp)
00080 {
00081   this->updateSolutionImporter();
00082 
00083   if (g) {
00084     Epetra::ImportWithAlternateMap(*solutionImporter_, x, *g, Insert);
00085   }
00086 
00087   if (gx) {
00088     TEUCHOS_ASSERT(Vx);
00089     Epetra::ImportWithAlternateMap(*solutionImporter_, *Vx, *gx, Insert);
00090     if (beta != 1.0) {
00091       gx->Scale(beta);
00092     }
00093   }
00094 
00095   if (gp) {
00096     gp->PutScalar(0.0);
00097   }
00098 }
00099 
00100 void
00101 Albany::SolutionValuesResponseFunction::
00102 evaluateGradient(const double /*current_time*/,
00103      const Epetra_Vector* /*xdot*/,
00104      const Epetra_Vector* /*xdot*/,
00105      const Epetra_Vector& x,
00106      const Teuchos::Array<ParamVec>& /*p*/,
00107      ParamVec* /*deriv_p*/,
00108      Epetra_Vector* g,
00109      Epetra_MultiVector* dg_dx,
00110      Epetra_MultiVector* dg_dxdot,
00111      Epetra_MultiVector* dg_dxdotdot,
00112      Epetra_MultiVector* dg_dp)
00113 {
00114   this->updateSolutionImporter();
00115 
00116   if (g) {
00117     Epetra::ImportWithAlternateMap(*solutionImporter_, x, *g, Insert);
00118   }
00119 
00120   if (dg_dx) {
00121     dg_dx->PutScalar(0.0);
00122 
00123     const Epetra_BlockMap &replicatedMap = solutionImporter_->TargetMap();
00124     const Epetra_BlockMap &derivMap = dg_dx->Map();
00125     const int colCount = dg_dx->NumVectors();
00126     for (int icol = 0; icol < colCount; ++icol) {
00127       const int lid = derivMap.LID(replicatedMap.GID(icol));
00128       if (lid != -1) {
00129         dg_dx->ReplaceMyValue(lid, icol, 1.0);
00130       }
00131     }
00132   }
00133 
00134   if (dg_dxdot) {
00135     dg_dxdot->PutScalar(0.0);
00136   }
00137   if (dg_dxdotdot) {
00138     dg_dxdotdot->PutScalar(0.0);
00139   }
00140 
00141   if (dg_dp) {
00142     dg_dp->PutScalar(0.0);
00143   }
00144 }
00145 
00146 void
00147 Albany::SolutionValuesResponseFunction::
00148 updateSolutionImporter()
00149 {
00150   const Teuchos::RCP<const Epetra_BlockMap> solutionMap = app_->getMap();
00151   if (Teuchos::is_null(solutionImporter_) || !solutionMap->SameAs(solutionImporter_->SourceMap())) {
00152     const Teuchos::Array<int> selectedGIDs = cullingStrategy_->selectedGIDs(*solutionMap);
00153     const Epetra_Map targetMap(-1, selectedGIDs.size(), selectedGIDs.getRawPtr(), 0, solutionMap->Comm());
00154     solutionImporter_ = Teuchos::rcp(new Epetra_Import(targetMap, *solutionMap));
00155   }
00156 }

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