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

#include <MetricEigenvalue.h>

Inheritance diagram for Nektar::MetricEigenvalue:
[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-03"
 
- Static Public Attributes inherited from Nektar::MetricRegex
static std::string type
 

Protected Member Functions

 MetricEigenvalue (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::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 43 of file MetricEigenvalue.h.

Constructor & Destructor Documentation

◆ MetricEigenvalue()

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

Definition at line 47 of file MetricEigenvalue.cpp.

48 : MetricRegex(metric, generate)
49{
50 // We do not mind which order the converged eigenvalues are listed.
51 m_unordered = true;
52
53 // Regex for FP numbers of forms: 120, -23, 4.345, 2.4563e-01, -nan
54 std::string fp = R"(-?\d+\.?\d*(?:e[+-]\d+)?|-?nan)";
55
56 // Set up the regular expression. This matches lines beginning with EV:
57 // followed by an eigenvalue index and then at least 2 floating-point
58 // values comprising real and imaginary components of complex evals.
59 // Comparison is made only on the captured eigenvalue components.
60 m_regex = R"(^EV:\s+\d+\s+()" + fp + ")\\s+(" + fp + ").*";
61
62 // Find the number of iterations to match against.
63 TiXmlElement *value = metric->FirstChildElement("value");
64 ASSERTL0(value || m_generate, "Missing value tag for eigenvalue metric!");
65
66 while (value)
67 {
68 ASSERTL0(value->Attribute("tolerance"),
69 "Missing tolerance in eigenvalue metric");
70 ASSERTL0(!EmptyString(value->GetText()),
71 "Missing value in preconditioner metric.");
72
73 MetricRegexFieldValue mag, angle;
74
75 // Read valute as comma-separate mag,angle parts
76 std::string cmplx = value->GetText();
77 std::vector<std::string> cmpts;
78 boost::split(cmpts, cmplx, boost::is_any_of(","));
79 ASSERTL0(cmpts.size() == 2,
80 "Value should be magnitude and angle, separated by comma");
81
82 mag.m_value = cmpts[0];
83 mag.m_useTolerance = true;
84 mag.m_tolerance = atof(value->Attribute("tolerance"));
85
86 angle.m_value = cmpts[1];
87 angle.m_useTolerance = true;
88 angle.m_tolerance = atof(value->Attribute("tolerance"));
89
90 if (!m_generate)
91 {
92 std::vector<MetricRegexFieldValue> tmp(2);
93 tmp[0] = mag;
94 tmp[1] = angle;
95 m_matches.push_back(tmp);
96 }
97 else
98 {
99 m_varTolerance = value->Attribute("tolerance");
100 }
101
102 value = value->NextSiblingElement("value");
103 }
104}
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:208
bool m_generate
Determines whether to generate this metric or not.
Definition: Metric.h:96
bool m_unordered
If true, regex matches may be in any order in output.
Definition: MetricRegex.h:86
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::MetricRegex::m_unordered, Nektar::MetricRegexFieldValue::m_useTolerance, Nektar::MetricRegexFieldValue::m_value, and m_varTolerance.

Referenced by create().

Member Function Documentation

◆ create()

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

Definition at line 46 of file MetricEigenvalue.h.

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

References MetricEigenvalue().

◆ v_Generate()

void Nektar::MetricEigenvalue::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 106 of file MetricEigenvalue.cpp.

107{
108 // Run MetricRegex to generate matches.
109 MetricRegex::v_Generate(pStdout, pStderr);
110
111 // First remove all existing values.
112 m_metric->Clear();
113
114 // Now create new values.
115 for (int i = 0; i < m_matches.size(); ++i)
116 {
117 ASSERTL0(m_matches[i].size() == 3,
118 "Wrong number of matches for regular expression.");
119
120 std::string tol = MetricEigenvalue::defaultTolerance;
121 TiXmlElement *value = new TiXmlElement("value");
122
123 if (m_varTolerance != "")
124 {
125 tol = m_varTolerance;
126 }
127
128 value->SetAttribute("index", m_matches[i][0].m_value);
129 value->SetAttribute("tolerance", tol);
130 value->LinkEndChild(new TiXmlText(m_matches[i][1].m_value + "," +
131 m_matches[i][2].m_value));
132 m_metric->LinkEndChild(value);
133 }
134}
static std::string defaultTolerance
TiXmlElement * m_metric
Pointer to XML structure containing metric definition.
Definition: Metric.h:101
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::MetricEigenvalue::defaultTolerance = "1e-03"
static

Definition at line 52 of file MetricEigenvalue.h.

Referenced by v_Generate().

◆ m_varTolerance

std::string Nektar::MetricEigenvalue::m_varTolerance
protected

Definition at line 57 of file MetricEigenvalue.h.

Referenced by MetricEigenvalue(), and v_Generate().

◆ type

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

Definition at line 51 of file MetricEigenvalue.h.