| 1 |
// Copyright 2002 - 2008, 2010, 2011 National Technology Engineering |
| 2 |
// Solutions of Sandia, LLC (NTESS). Under the terms of Contract |
| 3 |
// DE-NA0003525 with NTESS, the U.S. Government retains certain rights |
| 4 |
// in this software. |
| 5 |
// |
| 6 |
// Redistribution and use in source and binary forms, with or without |
| 7 |
// modification, are permitted provided that the following conditions are |
| 8 |
// met: |
| 9 |
// |
| 10 |
// * Redistributions of source code must retain the above copyright |
| 11 |
// notice, this list of conditions and the following disclaimer. |
| 12 |
// |
| 13 |
// * Redistributions in binary form must reproduce the above |
| 14 |
// copyright notice, this list of conditions and the following |
| 15 |
// disclaimer in the documentation and/or other materials provided |
| 16 |
// with the distribution. |
| 17 |
// |
| 18 |
// * Neither the name of NTESS nor the names of its contributors |
| 19 |
// may be used to endorse or promote products derived from this |
| 20 |
// software without specific prior written permission. |
| 21 |
// |
| 22 |
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 23 |
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 24 |
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 25 |
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 26 |
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 27 |
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 28 |
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 29 |
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 30 |
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 31 |
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 32 |
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 33 |
// |
| 34 |
|
| 35 |
#include <Kokkos_Core.hpp> |
| 36 |
#include <gtest/gtest.h> |
| 37 |
#include <stk_ngp_test/ngp_test.hpp> |
| 38 |
#include <stk_expreval/Evaluator.hpp> |
| 39 |
#include <fstream> |
| 40 |
#include <iostream> |
| 41 |
#include <limits> |
| 42 |
#include <iomanip> |
| 43 |
#include <cmath> |
| 44 |
#include <memory> |
| 45 |
|
| 46 |
namespace { |
| 47 |
|
| 48 |
//-BEGIN |
| 49 |
TEST(HostEvaluation, bindScalar) |
| 50 |
{ |
| 51 |
stk::expreval::Eval expr("x=5; y=y+x; y+z"); |
| 52 |
expr.parse(); |
| 53 |
double y = 3.0; |
| 54 |
double z = 4.0; |
| 55 |
expr.bindVariable("y", y, 1); |
| 56 |
expr.bindVariable("z", z, 1); |
| 57 |
EXPECT_DOUBLE_EQ(expr.evaluate(), 12); |
| 58 |
} |
| 59 |
|
| 60 |
TEST(HostEvaluation, bindVector) |
| 61 |
{ |
| 62 |
stk::expreval::Eval expr("(a[0]*b[0] + a[1]*b[1] + a[2]*b[2])^0.5"); |
| 63 |
expr.parse(); |
| 64 |
double a[3] = {1, 2, 3}; |
| 65 |
double b[3] = {5, 4, 4}; |
| 66 |
expr.bindVariable("a", *a, 3); |
| 67 |
expr.bindVariable("b", *b, 3); |
| 68 |
EXPECT_DOUBLE_EQ(expr.evaluate(), 5); |
| 69 |
} |
| 70 |
|
| 71 |
TEST(HostEvaluation, bindVectorOneBasedIndex) |
| 72 |
{ |
| 73 |
stk::expreval::Eval expr("(a[1]*b[1] + a[2]*b[2] + a[3]*b[3])^0.5", stk::expreval::Variable::ONE_BASED_INDEX); |
| 74 |
expr.parse(); |
| 75 |
double a[3] = {1, 2, 3}; |
| 76 |
double b[3] = {5, 4, 4}; |
| 77 |
expr.bindVariable("a", *a, 3); |
| 78 |
expr.bindVariable("b", *b, 3); |
| 79 |
EXPECT_DOUBLE_EQ(expr.evaluate(), 5); |
| 80 |
} |
| 81 |
//-END |
| 82 |
|
| 83 |
} // namespace <unnamed> |