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

MOR_SingularValuesHelpers.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 "MOR_SingularValuesHelpers.hpp"
00008 
00009 #include <algorithm>
00010 #include <numeric>
00011 #include <iterator>
00012 #include <functional>
00013 #include <cmath>
00014 
00015 namespace MOR {
00016 
00017 namespace Detail {
00018 
00019 struct square : public std::unary_function<double, double> {
00020   double operator()(double x) const { return x * x; }
00021 };
00022 
00023 class relative_magnitude_from_square : public std::unary_function<double, double> {
00024 public:
00025   explicit relative_magnitude_from_square(double x2_ref) :
00026     x2_ref_(x2_ref)
00027   {}
00028 
00029   double operator()(double x2) const { return std::sqrt(x2 / x2_ref_); }
00030 
00031 private:
00032   double x2_ref_;
00033 };
00034 
00035 } // namespace Detail
00036 
00037 Teuchos::Array<double> computeDiscardedEnergyFractions(Teuchos::ArrayView<const double> singularValues)
00038 {
00039   Teuchos::Array<double> result;
00040 
00041   if (singularValues.begin() != singularValues.end()) {
00042     result.reserve(singularValues.size());
00043     std::transform(
00044         singularValues.begin(), singularValues.end(),
00045         std::back_inserter(result),
00046         Detail::square());
00047 
00048     std::partial_sum(result.rbegin(), result.rend(), result.rbegin());
00049 
00050     std::transform(result.begin() + 1, result.end(),
00051         result.begin(),
00052         Detail::relative_magnitude_from_square(result.front()));
00053     result.back() = 0.0;
00054   }
00055 
00056   return result;
00057 }
00058 
00059 } // namespace MOR

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