MetricLInf.cpp 3.33 KB
Newer Older
Chris Cantwell's avatar
Chris Cantwell committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
///////////////////////////////////////////////////////////////////////////////
//
// File: MetricLInf.cpp
//
// For more information, please see: http://www.nektar.info
//
// The MIT License
//
// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
// Department of Aeronautics, Imperial College London (UK), and Scientific
// Computing and Imaging Institute, University of Utah (USA).
//
// License for the specific language governing rights and limitations under
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// Description: Implementation of the LInf metric.
//
///////////////////////////////////////////////////////////////////////////////

#include <MetricLInf.h>

namespace Nektar
{
    std::string MetricLInf::type = GetMetricFactory().
        RegisterCreatorFunction("LINF", MetricLInf::create);

    MetricLInf::MetricLInf(TiXmlElement *metric) : MetricRegex(metric)
    {
        // Set up the regular expression. This (optionally) matches a variable
        // name if it exists: first field is variable name, second field is L2
        // error.
48 49
        m_regex = "^L inf error\\s*(?:\\(variable "
                  "(\\w+)\\))?\\s*:\\s*([+-]?\\d.+\\d|0).*";
Chris Cantwell's avatar
Chris Cantwell committed
50 51 52 53 54 55 56

        // Find the L2 error to match against.
        TiXmlElement *value = metric->FirstChildElement("value");
        while (value)
        {
            // Set up a match with two fields which correspond with the
            // subexpression above. The first is the variable name, second is
57 58 59 60 61 62 63 64 65 66
            // the L2 error.
            ASSERTL0(value->Attribute("variable"),
                     "Missing variable name in LInf metric.");
            ASSERTL0(value->Attribute("tolerance"),
                     "Missing tolerance in LInf metric");
            ASSERTL0(value->GetText() || value->GetText() == "",
                     "Missing value in LInf metric.");

            MetricRegexFieldValue var;
            var.m_value = value->Attribute("variable");
Chris Cantwell's avatar
Chris Cantwell committed
67

68 69 70 71 72 73 74 75 76
            MetricRegexFieldValue val;
            val.m_value = value->GetText();
            val.m_useTolerance = true;
            val.m_tolerance = atof(value->Attribute("tolerance"));

            std::vector<MetricRegexFieldValue> tmp(2);
            tmp[0] = var;
            tmp[1] = val;
            m_matches.push_back(tmp);
Chris Cantwell's avatar
Chris Cantwell committed
77 78

            value = value->NextSiblingElement("value");
79

Chris Cantwell's avatar
Chris Cantwell committed
80 81 82 83
        }
    }

}