/usr/share/openturns/examples/t_MergeRandomAndConstantInput.cxx is in openturns-examples 1.3-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
| 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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | //                                               -*- C++ -*-
/**
 *  @file  t_MergeRandomAndConstantInput.cxx
 *  @brief The test file of class NumericalMathFunction for standard methods
 *
 *  Copyright (C) 2005-2014 Airbus-EDF-Phimeca
 *
 *  This library is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  along with this library.  If not, see <http://www.gnu.org/licenses/>.
 *
 *  @author schueller
 *  @date   2012-02-17 19:35:43 +0100 (Fri, 17 Feb 2012)
 */
#include "OT.hxx"
#include "OTtestcode.hxx"
using namespace OT;
using namespace OT::Test;
int main(int argc, char *argv[])
{
  TESTPREAMBLE;
  OStream fullprint(std::cout);
  try
  {
    /** External code. This code has an input vector of dimension 4, namely (p0, p1, p2, p3)'. */
    Description input(4);
    input[0] = "E";
    input[1] = "F";
    input[2] = "L";
    input[3] = "I";
    NumericalMathFunction externalCode(input, Description(1, "d"), Description(1, "F*L^3/(3*E*I)"));
    UnsignedLong dim(externalCode.getInputDimension());
    /** The external code will be connected to 2 independent random variables X0 and X1 and one deterministic variable X2 with the following scheme:
        X2->p0
        X0->p1
        X1->p2
        X0->p3
        It means that (p0, p1, p2, p3)' = A.(X0, X1)' + b with:
        A = [0 0] b = [X2]
        [1 0]     [ 0]
        [0 1]     [ 0]
        [1 0]     [ 0]
        Here we build the linear function x -> A.x + b
    */
    UnsignedLong stochasticDimension(2);
    // UnsignedLong deterministicDimension(1);
    Matrix A(dim, stochasticDimension);
    A(1, 0) = 1;
    A(2, 1) = 1;
    A(3, 0) = 1;
    NumericalPoint b(dim, 0);
    NumericalScalar X2(50.0);
    b[0] = X2;
    NumericalMathFunction connect;
    NumericalPoint zero(stochasticDimension, 0);
    /** A LinearNumericalMathFunction will arrive soon... */
    connect.setEvaluationImplementation(new LinearNumericalMathEvaluationImplementation(zero, b, A.transpose()));
    connect.setGradientImplementation(new ConstantNumericalMathGradientImplementation(A.transpose()));
    connect.setHessianImplementation(new ConstantNumericalMathHessianImplementation(SymmetricTensor(stochasticDimension, dim)));
    /** We are now ready to build the resulting code externalCode(connect()) */
    NumericalMathFunction finalCode(externalCode, connect);
    /** Check if it worked */
    NumericalPoint x(connect.getInputDimension());
    x[0] = 5;
    x[1] = 10;
    fullprint << "finalCode(x)=" << finalCode(x) << std::endl;
    NumericalPoint xRef(dim);
    xRef[0] = X2;
    xRef[1] = x[0];
    xRef[2] = x[1];
    xRef[3] = x[0];
    fullprint << "ref=" << externalCode(xRef) << std::endl;
  }
  catch (TestFailed & ex)
  {
    std::cerr << ex << std::endl;
    return ExitCode::Error;
  }
  return ExitCode::Success;
}
 |