Skip to content

Commit

Permalink
MueLu: Cleanup to Avatar interface
Browse files Browse the repository at this point in the history
  • Loading branch information
csiefer2 committed Mar 26, 2019
1 parent db71170 commit 25646e8
Showing 1 changed file with 23 additions and 46 deletions.
69 changes: 23 additions & 46 deletions packages/muelu/src/Utils/MueLu_AvatarInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ RCP<const ParameterList> AvatarInterface::GetValidParameterList() const {
validParamList->set<int>("avatar: good class",int_dummy,"Numeric code for class Avatar considers to be good");

// Which drop tol choice heuristic to use
validParamList->set<int>("avatar: heuristic",int_dummy,"Numeric code for which heurisitc we want to use");
validParamList->set<int>("avatar: heuristic",int_dummy,"Numeric code for which heuristic we want to use");

// Bounds file for extrapolation risk
validParamList->set<Teuchos::Array<std::string> >("avatar: bounds file",ar_dummy,"Bounds file for Avatar extrapolation risk");
Expand Down Expand Up @@ -163,7 +163,9 @@ void AvatarInterface::Setup() {
// Get the avatar strings (NOTE: Only exist on proc 0)
avatarStrings_ = ReadFromFiles("avatar: decision tree files");
namesStrings_ = ReadFromFiles("avatar: names files");
boundsString_ = ReadFromFiles("avatar: bounds file");
if(params_.isParameter("avatar: bounds file"))
boundsString_ = ReadFromFiles("avatar: bounds file");

filestem_ = params_.get<Teuchos::Array<std::string>>("avatar: filestem");


Expand Down Expand Up @@ -322,7 +324,9 @@ void AvatarInterface::SetMueLuParameters(const Teuchos::ParameterList & problemF

std::cout<<"** Avatar TestString ***\n"<<testString<<std::endl;//DEBUG

int bound_check = checkBounds(testString, boundsString_);
int bound_check = true;
if(params_.isParameter("avatar: bounds file"))
bound_check = checkBounds(testString, boundsString_);

// FIXME: Only send in first tree's string
//int* avatar_test(Avatar_handle* a, char* test_data_file, int test_data_is_a_string);
Expand Down Expand Up @@ -395,56 +399,29 @@ void AvatarInterface::SetMueLuParameters(const Teuchos::ParameterList & problemF

int AvatarInterface::checkBounds(std::string trialString, Teuchos::ArrayRCP<std::string> boundsString) const {
std::stringstream ss(trialString);
std::vector<float> vect;

int useNewFeatures = 0;

float i;

while (ss >> i)
{
vect.push_back(i);
std::vector<double> vect;

if (ss.peek() == ',')
ss.ignore();
double b;
while (ss >> b) {
vect.push_back(b);
if (ss.peek() == ',') ss.ignore();
}

std::stringstream ssBounds(boundsString[0]);
std::vector<double> boundsVect;

std::string bounds = const_cast<char*>(boundsString[0].c_str());

std::stringstream ssBounds(bounds);
std::vector<float> boundsVect;

float b;

while (ssBounds >> b)
{
boundsVect.push_back(b);

if (ssBounds.peek() == ',')
ssBounds.ignore();
while (ssBounds >> b) {
boundsVect.push_back(b);
if (ssBounds.peek() == ',') ssBounds.ignore();
}

if (vect.at(3) > boundsVect.at(0) || vect.at(3) < boundsVect.at(1))
return 0;

if (vect.at(4) > boundsVect.at(2) || vect.at(4) < boundsVect.at(3))
return 0;

if (vect.at(5) > boundsVect.at(4) || vect.at(5) < boundsVect.at(5))
return 0;

if (vect.at(6) > boundsVect.at(6) || vect.at(6) < boundsVect.at(7))
return 0;
int min_idx = (int) std::min(vect.size(),boundsVect.size()/2);

if (useNewFeatures == 1){
if (vect.at(8) > boundsVect.at(8) || vect.at(8) < boundsVect.at(9))
return 0;

if (vect.at(9) > boundsVect.at(10) || vect.at(9) < boundsVect.at(11))
return 0;
}
bool inbounds=true;
for(int i=0; inbounds && i<min_idx; i++)
inbounds = boundsVect[2*i] <= vect[i] && vect[i] <= boundsVect[2*i+1];

return 1;
return (int) inbounds;
}

int AvatarInterface::hybrid(float * probabilities, std::vector<int> acceptableCombos) const{
Expand Down

0 comments on commit 25646e8

Please sign in to comment.