Nektar++
Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
Nektar::MetricLInf Class Reference

#include <MetricLInf.h>

Inheritance diagram for Nektar::MetricLInf:
[legend]

Static Public Member Functions

static MetricSharedPtr create (TiXmlElement *metric, bool generate)
 
- Static Public Member Functions inherited from Nektar::MetricRegex
static MetricSharedPtr create (TiXmlElement *metric, bool generate)
 

Static Public Attributes

static std::string type
 
static std::string defaultTolerance = "1e-12"
 
- Static Public Attributes inherited from Nektar::MetricRegex
static std::string type
 

Protected Member Functions

 MetricLInf (TiXmlElement *metric, bool generate)
 
void v_Generate (std::istream &pStdout, std::istream &pStderr) override
 Virtual function to generate the metric. Should be redefined in derived classes. More...
 
- Protected Member Functions inherited from Nektar::MetricRegex
 MetricRegex (TiXmlElement *metric, bool generate)
 Constructor. More...
 
bool v_Test (std::istream &pStdout, std::istream &pStderr) override
 Test output against a regex expression and set of matches. More...
 
void v_Generate (std::istream &pStdout, std::istream &pStderr) override
 Test output against a regex expression and set of matches. More...
 
virtual bool v_Test (std::istream &pStdout, std::istream &pStderr)=0
 Virtual function to test the metric. Should be redefined in derived classes. More...
 
virtual void v_Generate (std::istream &pStdout, std::istream &pSrderr)=0
 Virtual function to generate the metric. Should be redefined in derived classes. More...
 

Protected Attributes

std::map< std::string, std::string > m_varTolerance
 
- Protected Attributes inherited from Nektar::MetricRegex
std::regex m_regex
 Storage for the boost regex. More...
 
std::vector< std::vector< MetricRegexFieldValue > > m_matches
 Stores the multiple matches defined in each <MATCH> tag. More...
 
bool m_unordered = false
 If true, regex matches may be in any order in output. More...
 
bool m_useStderr = false
 If true, use stderr for testing/generation instead of stdout. More...
 
- Protected Attributes inherited from Nektar::Metric
int m_id
 Stores the ID of this metric. More...
 
std::string m_type
 Stores the type of this metric (uppercase). More...
 
bool m_generate
 Determines whether to generate this metric or not. More...
 
bool m_average = false
 Indicates whether a metric supports averaging results from multiple runs. More...
 
TiXmlElement * m_metric
 Pointer to XML structure containing metric definition. More...
 

Additional Inherited Members

- Public Member Functions inherited from Nektar::MetricRegex
 ~MetricRegex () override
 
- Public Member Functions inherited from Nektar::Metric
 Metric (TiXmlElement *metric, bool generate)
 Constructor. More...
 
virtual ~Metric ()=default
 
bool Test (std::istream &pStdout, std::istream &pStderr)
 Calls a metric's v_Test function (or v_Generate if m_generate). More...
 
void Generate (std::istream &pStdout, std::istream &pStderr)
 
std::string GetType ()
 Return metric type. More...
 
int GetID ()
 Return metric ID. More...
 
bool SupportsAverage () const
 Return whether this metric supports averaging results from multiple runs. More...
 

Detailed Description

Definition at line 42 of file MetricLInf.h.

Constructor & Destructor Documentation

◆ MetricLInf()

Nektar::MetricLInf::MetricLInf ( TiXmlElement *  metric,
bool  generate 
)
protected

Definition at line 45 of file MetricLInf.cpp.

46 : MetricRegex(metric, generate)
47{
48 // Set up the regular expression. This (optionally) matches a variable
49 // name if it exists: first field is variable name, second field is L2
50 // error.
51 m_regex = "^L inf\\w* error\\s*(?:\\(variable "
52 "(\\w+)\\))?\\s*:\\s*([+-]?\\d.+\\d|-?\\d|[+-]?nan|[+-]?inf).*";
53
54 // Find the L2 error to match against.
55 TiXmlElement *value = metric->FirstChildElement("value");
56 ASSERTL0(value || m_generate, "Missing value tag for LInf metric!");
57
58 while (value)
59 {
60 // Set up a match with two fields which correspond with the
61 // subexpression above. The first is the variable name, second is
62 // the L2 error.
63 ASSERTL0(value->Attribute("tolerance"),
64 "Missing tolerance in L2 metric");
65 ASSERTL0(!EmptyString(value->GetText()), "Missing value in L2 metric.");
66
67 MetricRegexFieldValue var;
68 if (value->Attribute("variable"))
69 {
70 var.m_value = value->Attribute("variable");
71 }
72
73 MetricRegexFieldValue val;
74 val.m_value = value->GetText();
75 val.m_useTolerance = true;
76 val.m_tolerance = atof(value->Attribute("tolerance"));
77
78 if (!m_generate)
79 {
80 std::vector<MetricRegexFieldValue> tmp(2);
81 tmp[0] = var;
82 tmp[1] = val;
83 m_matches.push_back(tmp);
84 }
85 else
86 {
87 m_varTolerance[var.m_value] = value->Attribute("tolerance");
88 }
89
90 value = value->NextSiblingElement("value");
91 }
92}
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:208
bool m_generate
Determines whether to generate this metric or not.
Definition: Metric.h:96
std::map< std::string, std::string > m_varTolerance
Definition: MetricLInf.h:56
MetricRegex(TiXmlElement *metric, bool generate)
Constructor.
Definition: MetricRegex.cpp:51
std::vector< std::vector< MetricRegexFieldValue > > m_matches
Stores the multiple matches defined in each <MATCH> tag.
Definition: MetricRegex.h:84
std::regex m_regex
Storage for the boost regex.
Definition: MetricRegex.h:82
bool EmptyString(const char *s)
Check to see whether the given string s is empty (or null).
Definition: Metric.h:50

References ASSERTL0, Nektar::EmptyString(), Nektar::Metric::m_generate, Nektar::MetricRegex::m_matches, Nektar::MetricRegex::m_regex, Nektar::MetricRegexFieldValue::m_tolerance, Nektar::MetricRegexFieldValue::m_useTolerance, Nektar::MetricRegexFieldValue::m_value, and m_varTolerance.

Referenced by create().

Member Function Documentation

◆ create()

static MetricSharedPtr Nektar::MetricLInf::create ( TiXmlElement *  metric,
bool  generate 
)
inlinestatic

Definition at line 45 of file MetricLInf.h.

46 {
47 return MetricSharedPtr(new MetricLInf(metric, generate));
48 }
MetricLInf(TiXmlElement *metric, bool generate)
Definition: MetricLInf.cpp:45
std::shared_ptr< Metric > MetricSharedPtr
A shared pointer to an EquationSystem object.
Definition: Metric.h:124

References MetricLInf().

◆ v_Generate()

void Nektar::MetricLInf::v_Generate ( std::istream &  pStdout,
std::istream &  pSrderr 
)
overrideprotectedvirtual

Virtual function to generate the metric. Should be redefined in derived classes.

Parameters
pStdoutReference to test output stream.
pSrderrReference to test error stream.

Implements Nektar::Metric.

Definition at line 94 of file MetricLInf.cpp.

95{
96 // Run MetricRegex to generate matches.
97 MetricRegex::v_Generate(pStdout, pStderr);
98
99 // First remove all existing values.
100 m_metric->Clear();
101
102 ASSERTL0(m_matches.size() > 0, "Unable to find L infinity norm in output!");
103
104 // Now create new values.
105 for (int i = 0; i < m_matches.size(); ++i)
106 {
107 ASSERTL0(m_matches[i].size() == 2,
108 "Wrong number of matches for regular expression.");
109
110 bool tolSet = false;
111 std::string tol = MetricLInf::defaultTolerance;
112 TiXmlElement *value = new TiXmlElement("value");
113
114 // See if there is a tolerance found already for this variable
115 // (including empty variables).
116 std::map<std::string, std::string>::iterator it =
117 m_varTolerance.find(m_matches[i][0].m_value);
118
119 if (it != m_varTolerance.end())
120 {
121 tol = it->second;
122 tolSet = true;
123 }
124
125 if (m_matches[i][0].m_value.size() > 0)
126 {
127 value->SetAttribute("variable", m_matches[i][0].m_value);
128
129 if (m_matches[i][0].m_value == "p" && !tolSet)
130 {
131 // Set lower tolerance for pressure fields automatically if
132 // we haven't already got a tolerance from the existing
133 // file.
134 tol = "1e-8";
135 }
136 }
137
138 value->SetAttribute("tolerance", tol);
139 value->LinkEndChild(new TiXmlText(m_matches[i][1].m_value));
140 m_metric->LinkEndChild(value);
141 }
142}
TiXmlElement * m_metric
Pointer to XML structure containing metric definition.
Definition: Metric.h:101
static std::string defaultTolerance
Definition: MetricLInf.h:51
void v_Generate(std::istream &pStdout, std::istream &pStderr) override
Test output against a regex expression and set of matches.

References ASSERTL0, defaultTolerance, Nektar::MetricRegex::m_matches, Nektar::Metric::m_metric, m_varTolerance, and Nektar::MetricRegex::v_Generate().

Member Data Documentation

◆ defaultTolerance

std::string Nektar::MetricLInf::defaultTolerance = "1e-12"
static

Definition at line 51 of file MetricLInf.h.

Referenced by v_Generate().

◆ m_varTolerance

std::map<std::string, std::string> Nektar::MetricLInf::m_varTolerance
protected

Definition at line 56 of file MetricLInf.h.

Referenced by MetricLInf(), and v_Generate().

◆ type

std::string Nektar::MetricLInf::type
static
Initial value:
=
std::string RegisterCreatorFunction(std::string key, CreatorFunction func)
Definition: Metric.h:133
static MetricSharedPtr create(TiXmlElement *metric, bool generate)
Definition: MetricLInf.h:45
MetricFactory & GetMetricFactory()
Definition: Metric.cpp:42

Definition at line 50 of file MetricLInf.h.