MueLu Version of the Day
Loading...
Searching...
No Matches
MueLu_AvatarInterface.hpp
Go to the documentation of this file.
1// @HEADER
2//
3// ***********************************************************************
4//
5// MueLu: A package for multigrid based preconditioning
6// Copyright 2012 Sandia Corporation
7//
8// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9// the U.S. Government retains certain rights in this software.
10//
11// Redistribution and use in source and binary forms, with or without
12// modification, are permitted provided that the following conditions are
13// met:
14//
15// 1. Redistributions of source code must retain the above copyright
16// notice, this list of conditions and the following disclaimer.
17//
18// 2. Redistributions in binary form must reproduce the above copyright
19// notice, this list of conditions and the following disclaimer in the
20// documentation and/or other materials provided with the distribution.
21//
22// 3. Neither the name of the Corporation nor the names of the
23// contributors may be used to endorse or promote products derived from
24// this software without specific prior written permission.
25//
26// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37//
38// Questions? Contact
39// Jonathan Hu (jhu@sandia.gov)
40// Andrey Prokopenko (aprokop@sandia.gov)
41// Ray Tuminaro (rstumin@sandia.gov)
42//
43// ***********************************************************************
44//
45// @HEADER
46#ifndef MUELU_AVATARINTERFACE_HPP
47#define MUELU_AVATARINTERFACE_HPP
48
49#include <string>
50#include "Teuchos_Comm.hpp"
51#include "Teuchos_RCP.hpp"
52#include "Teuchos_ArrayRCP.hpp"
53#include "Teuchos_ParameterList.hpp"
54#include "MueLu_BaseClass.hpp"
55
56
57#ifdef HAVE_MUELU_AVATAR
58
59
60// Forward declaration
61struct Avatar_struct;
62typedef struct Avatar_struct Avatar_handle;
63
64namespace MueLu {
65
72 class AvatarInterface : public BaseClass {
73
74 public:
75
76 AvatarInterface(Teuchos::RCP<const Teuchos::Comm<int> >& comm ):comm_(comm) {}
77
78 AvatarInterface(Teuchos::RCP<const Teuchos::Comm<int> >& comm, Teuchos::ParameterList& inParams):comm_(comm),params_(inParams){};
79
80 ~AvatarInterface(){Cleanup();}
81
82 Teuchos::RCP<const Teuchos::ParameterList> GetValidParameterList() const;
83
84 // Sets the input parameters for the AvatarInterface
85 void SetParameterList(Teuchos::ParameterList& inParams) {params_ = inParams;}
86
87 // Sets up Avatar
88 void Setup();
89
90 // Calls Avatar to set MueLu Parameters
91 void SetMueLuParameters(const Teuchos::ParameterList & problemFeatures, Teuchos::ParameterList & mueluParams, bool overwrite=true) const;
92
93 // Clean up the handle
94 void Cleanup();
95
96 // Returns 1 if the given parameters are within same
97 // same domain as training data, 0 otherwise
98 int checkBounds(std::string trialString, Teuchos::ArrayRCP<std::string> boundsString) const;
99
100 int hybrid(float * probabilities, std::vector<int> acceptableCombos) const;
101
102 int highProb(float * probabilities, std::vector<int> acceptableCombos) const;
103
104 int lowCrash(float * probabilities, std::vector<int> acceptableCombos) const;
105
106 int weighted(float * probabilities, std::vector<int> acceptableCombos) const;
107
108 private:
109 // Utility functions
110 Teuchos::ArrayRCP<std::string> ReadFromFiles(const char * param_name) const;
111 void GenerateFeatureString(const Teuchos::ParameterList & problemFeatures, std::string & featureString) const;
112 std::string ParamsToString(const std::vector<int> & indices) const;
113 void SetIndices(int id,std::vector<int> & indices) const;
114 void GenerateMueLuParametersFromIndex(int id,Teuchos::ParameterList & pl) const;
115 void UnpackMueLuMapping();
116
117 // Cached data
118 Teuchos::RCP<const Teuchos::Comm<int> > comm_;
119 mutable Teuchos::ParameterList params_; // The mutable is a hack to deal with issues in Teuchos
120 Teuchos::ArrayRCP<std::string> avatarStrings_;
121 Teuchos::ArrayRCP<std::string> namesStrings_;
122 Teuchos::Array<std::string> filestem_;
123 Teuchos::ArrayRCP<std::string> boundsString_;
124 int avatarGoodClass_;
125 int heuristicToUse_;
126
127 // RCP's don't handle opaque pointers well
128 Avatar_handle * avatarHandle_;
129
130 Teuchos::Array<std::string> mueluParameterName_;
131 Teuchos::Array<std::string> avatarParameterName_;
132
133 Teuchos::ArrayRCP<Teuchos::Array<double> > mueluParameterValues_;
134 Teuchos::ArrayRCP<Teuchos::Array<double> > avatarParameterValues_;
135
136 };
137
138
139} // namespace MueLu
140
141#endif// HAVE_MUELU_AVATAR
142
143#endif // MUELU_AVATARINTERFACE_HPP
Namespace for MueLu classes and methods.