MUQ  0.4.3
IndexedScalarBasis.cpp
Go to the documentation of this file.
2 
4 
5 #include <cstdlib>
6 #include <typeinfo>
7 #include <memory>
8 #include <cxxabi.h>
9 
10 using namespace muq::Modeling;
11 using namespace muq::Approximation;
12 
13 IndexedScalarBasis::IndexedScalarBasis() :
14  WorkPiece(std::vector<std::string>({typeid(unsigned int).name(), typeid(double).name()}), // input types (order, point)
15  std::vector<std::string>({typeid(double).name()})) // output times (polynomial evaluation)
16 {}
17 
19  // extract the inputs
20  const unsigned int order = boost::any_cast<unsigned int>(inputs[0]);
21  const double x = boost::any_cast<double>(inputs[1]);
22 
23  // evaluate the polynomial
24  outputs.resize(1);
25  outputs[0] = BasisEvaluate(order, x);
26 }
27 
28 
29 
30 std::shared_ptr<IndexedScalarBasis> IndexedScalarBasis::Construct(std::string const& polyName){
31 
32  auto map = GetScalarBasisMap();
33  auto it = map->find(polyName);
34  if(it == map->end()){
35  std::string message = "The basis family, \"" + polyName + "\" has not been registered with the scalar basis factory. Does the class exist?\n Registered families include:\n";
36  for(auto iter = map->begin(); iter!=map->end(); ++iter)
37  message += " " + iter->first + "\n";
38  message += "\n";
39 
40  throw muq::NotRegisteredError(message);
41  return nullptr;
42  }else{
43  return it->second();
44  }
45 }
46 
47 std::shared_ptr<IndexedScalarBasis::ScalarBasisMapType> IndexedScalarBasis::GetScalarBasisMap() {
48  // define a static map from type to constructor
49  static std::shared_ptr<ScalarBasisMapType> map;
50 
51  if( !map ) { // if the map has not yet been created ...
52  // ... create the map
53  map = std::make_shared<ScalarBasisMapType>();
54  }
55 
56  return map;
57 }
virtual void EvaluateImpl(muq::Modeling::ref_vector< boost::any > const &inputs)
Evaluate the polynomial at a given point and order.
static std::shared_ptr< IndexedScalarBasis > Construct(std::string const &polyName)
virtual double BasisEvaluate(int const order, double const x) const =0
Evaluate the specific basis type (must be implemented by the child)
static std::shared_ptr< ScalarBasisMapType > GetScalarBasisMap()
Base class for MUQ's modelling envronment.
Definition: WorkPiece.h:40
std::vector< boost::any > outputs
The outputs.
Definition: WorkPiece.h:546
std::string name
A unique name for this WorkPiece. Defaults to <ClassName>_<id>
Definition: WorkPiece.h:583
Used when a child class has not been registered with the factory method.
Definition: Exceptions.h:37
std::vector< std::reference_wrapper< const T > > ref_vector
A vector of references to something ...
Definition: WorkPiece.h:37