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

Albany_SolutionCullingStrategy.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_SolutionCullingStrategy.hpp"
00008 
00009 #include "Epetra_BlockMap.h"
00010 
00011 #include "Epetra_GatherAllV.hpp"
00012 
00013 #include "Teuchos_Assert.hpp"
00014 
00015 #include <algorithm>
00016 
00017 namespace Albany {
00018 
00019 class UniformSolutionCullingStrategy : public SolutionCullingStrategyBase {
00020 public:
00021   explicit UniformSolutionCullingStrategy(int numValues);
00022 
00023   virtual Teuchos::Array<int> selectedGIDs(const Epetra_BlockMap &sourceMap) const;
00024 
00025 private:
00026   int numValues_;
00027 };
00028 
00029 } // namespace Albany
00030 
00031 Albany::UniformSolutionCullingStrategy::
00032 UniformSolutionCullingStrategy(int numValues) :
00033   numValues_(numValues)
00034 {
00035   // Nothing to do
00036 }
00037 
00038 Teuchos::Array<int>
00039 Albany::UniformSolutionCullingStrategy::
00040 selectedGIDs(const Epetra_BlockMap &sourceMap) const
00041 {
00042   Teuchos::Array<int> allGIDs(sourceMap.NumGlobalElements());
00043   {
00044     const int ierr = Epetra::GatherAllV(
00045         sourceMap.Comm(),
00046         sourceMap.MyGlobalElements(), sourceMap.NumMyElements(),
00047         allGIDs.getRawPtr(), allGIDs.size());
00048     TEUCHOS_ASSERT(ierr == 0);
00049   }
00050   std::sort(allGIDs.begin(), allGIDs.end());
00051 
00052   Teuchos::Array<int> result(numValues_);
00053   const int stride = 1 + (allGIDs.size() - 1) / numValues_;
00054   for (int i = 0; i < numValues_; ++i) {
00055     result[i] = allGIDs[i * stride];
00056   }
00057   return result;
00058 }
00059 
00060 
00061 #include "Albany_SolutionCullingStrategy.hpp"
00062 
00063 #include "Albany_Application.hpp"
00064 #include "Albany_AbstractDiscretization.hpp"
00065 
00066 #include "Epetra_BlockMap.h"
00067 #include "Epetra_Comm.h"
00068 
00069 #include "Epetra_GatherAllV.hpp"
00070 
00071 #include "Teuchos_Assert.hpp"
00072 
00073 #include <string>
00074 #include <algorithm>
00075 
00076 namespace Albany {
00077 
00078 class NodeSetSolutionCullingStrategy : public SolutionCullingStrategyBase {
00079 public:
00080   NodeSetSolutionCullingStrategy(
00081       const std::string &nodeSetLabel,
00082       const Teuchos::RCP<const Application> &app);
00083 
00084   virtual void setup();
00085 
00086   virtual Teuchos::Array<int> selectedGIDs(const Epetra_BlockMap &sourceMap) const;
00087 
00088 private:
00089   std::string nodeSetLabel_;
00090   Teuchos::RCP<const Application> app_;
00091 
00092   Teuchos::RCP<const AbstractDiscretization> disc_;
00093 };
00094 
00095 } // namespace Albany
00096 
00097 Albany::NodeSetSolutionCullingStrategy::
00098 NodeSetSolutionCullingStrategy(
00099     const std::string &nodeSetLabel,
00100     const Teuchos::RCP<const Application> &app) :
00101   nodeSetLabel_(nodeSetLabel),
00102   app_(app),
00103   disc_(Teuchos::null)
00104 {
00105   // setup() must be called after the discretization has been created to finish initialization
00106 }
00107 
00108 void
00109 Albany::NodeSetSolutionCullingStrategy::
00110 setup()
00111 {
00112   disc_ = app_->getDiscretization();
00113   // Once the discretization has been obtained, a handle to the application is not required
00114   // Release the resource to avoid possible circular references
00115   app_.reset();
00116 }
00117 
00118 Teuchos::Array<int>
00119 Albany::NodeSetSolutionCullingStrategy::
00120 selectedGIDs(const Epetra_BlockMap &sourceMap) const
00121 {
00122   Teuchos::Array<int> result;
00123   {
00124     Teuchos::Array<int> mySelectedGIDs;
00125     {
00126       const NodeSetList &nodeSets = disc_->getNodeSets();
00127 
00128       const NodeSetList::const_iterator it = nodeSets.find(nodeSetLabel_);
00129       if (it != nodeSets.end()) {
00130         typedef NodeSetList::mapped_type NodeSetEntryList;
00131         const NodeSetEntryList &sampleNodeEntries = it->second;
00132 
00133         for (NodeSetEntryList::const_iterator jt = sampleNodeEntries.begin(); jt != sampleNodeEntries.end(); ++jt) {
00134           typedef NodeSetEntryList::value_type NodeEntryList;
00135           const NodeEntryList &sampleEntries = *jt;
00136           for (NodeEntryList::const_iterator kt = sampleEntries.begin(); kt != sampleEntries.end(); ++kt) {
00137             mySelectedGIDs.push_back(sourceMap.GID(*kt));
00138           }
00139         }
00140       }
00141     }
00142 
00143     const Epetra_Comm &comm = sourceMap.Comm();
00144 
00145     {
00146       int selectedGIDCount;
00147       {
00148         int mySelectedGIDCount = mySelectedGIDs.size();
00149         comm.SumAll(&mySelectedGIDCount, &selectedGIDCount, 1);
00150       }
00151       result.resize(selectedGIDCount);
00152     }
00153 
00154     const int ierr = Epetra::GatherAllV(
00155         comm,
00156         mySelectedGIDs.getRawPtr(), mySelectedGIDs.size(),
00157         result.getRawPtr(), result.size());
00158     TEUCHOS_ASSERT(ierr == 0);
00159   }
00160 
00161   std::sort(result.begin(), result.end());
00162 
00163   return result;
00164 }
00165 
00166 
00167 #include "Albany_Application.hpp"
00168 
00169 #include "Teuchos_TestForException.hpp"
00170 
00171 #include <string>
00172 
00173 namespace Albany {
00174 
00175 Teuchos::RCP<SolutionCullingStrategyBase>
00176 createSolutionCullingStrategy(
00177     const Teuchos::RCP<const Application> &app,
00178     Teuchos::ParameterList &params)
00179 {
00180   const std::string cullingStrategyToken = params.get("Culling Strategy", "Uniform");
00181 
00182   if (cullingStrategyToken == "Uniform") {
00183     const int numValues = params.get("Num Values", 10);
00184     return Teuchos::rcp(new UniformSolutionCullingStrategy(numValues));
00185   } else if (cullingStrategyToken == "Node Set") {
00186     const std::string nodeSetLabel = params.get<std::string>("Node Set Label");
00187     return Teuchos::rcp(new NodeSetSolutionCullingStrategy(nodeSetLabel, app));
00188   }
00189 
00190   const bool unsupportedCullingStrategy = true;
00191   TEUCHOS_TEST_FOR_EXCEPT(unsupportedCullingStrategy);
00192 }
00193 
00194 } // namespace Albany

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