Panzer Version of the Day
Loading...
Searching...
No Matches
Panzer_ModelEvaluator_Utilities.cpp
Go to the documentation of this file.
2#include <Thyra_ModelEvaluator.hpp>
3#include <Teuchos_Assert.hpp>
4
5std::tuple<int,int> panzer::findParameterIndex(const std::string& p_name,const Thyra::ModelEvaluator<double>& me, const bool& throw_if_not_found)
6{
7 bool found = false;
8 int index = -1;
9 int sub_index = -1;
10 for (int p = 0; p < me.Np(); ++p) {
11 auto p_names = me.get_p_names(p);
12 for (Teuchos::Ordinal p_sub=0; p_sub < p_names->size(); ++p_sub) {
13 if ((*p_names)[p_sub] == p_name) {
14 found = true;
15 index = p;
16 sub_index = p_sub;
17 break;
18 }
19 }
20 if (found) break;
21 }
22
23 TEUCHOS_TEST_FOR_EXCEPTION( (!found and throw_if_not_found), std::runtime_error,
24 "ERROR: the parameter \"" << p_name << "\" is not a valid parameter name in the model evaluator!");
25
26 return {index,sub_index};
27}
28
29std::tuple<int,int> panzer::findResponseIndex(const std::string& g_name,const Thyra::ModelEvaluator<double>& me, const bool& throw_if_not_found)
30{
31 bool found = false;
32 int index = -1;
33 int sub_index = -1;
34 for (int g = 0; g < me.Ng(); ++g) {
35 auto g_names = me.get_g_names(g);
36 for (Teuchos::Ordinal g_sub=0; g_sub < g_names.size(); ++g_sub) {
37 std::cout << "g(" << g << "," << g_sub << ")=" << g_names[g_sub] << std::endl;
38 if (g_names[g_sub] == g_name) {
39 found = true;
40 index = g;
41 sub_index = g_sub;
42 break;
43 }
44 }
45 if (found) break;
46 }
47
48 TEUCHOS_TEST_FOR_EXCEPTION( (!found and throw_if_not_found), std::runtime_error,
49 "ERROR: the response \"" << g_name << "\" is not a valid response name in the model evaluator!");
50
51 return {index,sub_index};
52}
std::tuple< int, int > findParameterIndex(const std::string &p_name, const Thyra::ModelEvaluator< double > &me, const bool &throw_if_not_found=true)
Given a parameter name and a ModelEvaluator, returns the index and subindex of the parameter in the M...
std::tuple< int, int > findResponseIndex(const std::string &g_name, const Thyra::ModelEvaluator< double > &me, const bool &throw_if_not_found=true)
Given a response name and a ModelEvaluator, returns the index and subindex of the response in the Mod...