MueLu  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MueLu_AvatarInterface.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // MueLu: A package for multigrid based preconditioning
4 //
5 // Copyright 2012 NTESS and the MueLu contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef MUELU_AVATARINTERFACE_HPP
11 #define MUELU_AVATARINTERFACE_HPP
12 
13 #include <string>
14 #include "Teuchos_Comm.hpp"
15 #include "Teuchos_RCP.hpp"
16 #include "Teuchos_ArrayRCP.hpp"
18 #include "MueLu_BaseClass.hpp"
19 
20 #ifdef HAVE_MUELU_AVATAR
21 
22 // Forward declaration
23 struct Avatar_struct;
24 typedef struct Avatar_struct Avatar_handle;
25 
26 namespace MueLu {
27 
34 class AvatarInterface : public BaseClass {
35  public:
36  AvatarInterface(Teuchos::RCP<const Teuchos::Comm<int> >& comm)
37  : comm_(comm) {}
38 
39  AvatarInterface(Teuchos::RCP<const Teuchos::Comm<int> >& comm, Teuchos::ParameterList& inParams)
40  : comm_(comm)
41  , params_(inParams){};
42 
43  ~AvatarInterface() { Cleanup(); }
44 
45  Teuchos::RCP<const Teuchos::ParameterList> GetValidParameterList() const;
46 
47  // Sets the input parameters for the AvatarInterface
48  void SetParameterList(Teuchos::ParameterList& inParams) { params_ = inParams; }
49 
50  // Sets up Avatar
51  void Setup();
52 
53  // Calls Avatar to set MueLu Parameters
54  void SetMueLuParameters(const Teuchos::ParameterList& problemFeatures, Teuchos::ParameterList& mueluParams, bool overwrite = true) const;
55 
56  // Clean up the handle
57  void Cleanup();
58 
59  // Returns 1 if the given parameters are within same
60  // same domain as training data, 0 otherwise
61  int checkBounds(std::string trialString, Teuchos::ArrayRCP<std::string> boundsString) const;
62 
63  int hybrid(float* probabilities, std::vector<int> acceptableCombos) const;
64 
65  int highProb(float* probabilities, std::vector<int> acceptableCombos) const;
66 
67  int lowCrash(float* probabilities, std::vector<int> acceptableCombos) const;
68 
69  int weighted(float* probabilities, std::vector<int> acceptableCombos) const;
70 
71  private:
72  // Utility functions
73  Teuchos::ArrayRCP<std::string> ReadFromFiles(const char* param_name) const;
74  void GenerateFeatureString(const Teuchos::ParameterList& problemFeatures, std::string& featureString) const;
75  std::string ParamsToString(const std::vector<int>& indices) const;
76  void SetIndices(int id, std::vector<int>& indices) const;
77  void GenerateMueLuParametersFromIndex(int id, Teuchos::ParameterList& pl) const;
78  void UnpackMueLuMapping();
79 
80  // Cached data
82  mutable Teuchos::ParameterList params_; // The mutable is a hack to deal with issues in Teuchos
83  Teuchos::ArrayRCP<std::string> avatarStrings_;
84  Teuchos::ArrayRCP<std::string> namesStrings_;
86  Teuchos::ArrayRCP<std::string> boundsString_;
87  int avatarGoodClass_;
88  int heuristicToUse_;
89 
90  // RCP's don't handle opaque pointers well
91  Avatar_handle* avatarHandle_;
92 
93  Teuchos::Array<std::string> mueluParameterName_;
94  Teuchos::Array<std::string> avatarParameterName_;
95 
96  Teuchos::ArrayRCP<Teuchos::Array<double> > mueluParameterValues_;
97  Teuchos::ArrayRCP<Teuchos::Array<double> > avatarParameterValues_;
98 };
99 
100 } // namespace MueLu
101 
102 #endif // HAVE_MUELU_AVATAR
103 
104 #endif // MUELU_AVATARINTERFACE_HPP