Files
opm-simulators/test_ad.cpp
Bård Skaflestad b05f65ae70 Add simple library for automatic differentiation
No build system or automatic test cases at this point.
2013-04-29 13:39:57 +02:00

68 lines
2.0 KiB
C++

/*===========================================================================
//
// File: test_ad.cpp
//
// Created: 2013-04-29 11:12:34+0200
//
// Authors: Knut-Andreas Lie <Knut-Andreas.Lie@sintef.no>
// Halvor M. Nilsen <HalvorMoll.Nilsen@sintef.no>
// Atgeirr F. Rasmussen <atgeirr@sintef.no>
// Xavier Raynaud <Xavier.Raynaud@sintef.no>
// Bård Skaflestad <Bard.Skaflestad@sintef.no>
//
//==========================================================================*/
/*
Copyright 2013 SINTEF ICT, Applied Mathematics.
Copyright 2013 Statoil ASA.
This file is part of the Open Porous Media Project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OPM 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#include "AutoDiff.hpp"
#include <iostream>
int
main()
{
AutoDiff::Forward<double> a(0.0);
AutoDiff::Forward<double> b(1.0);
std::cout << "a: " << a << '\n';
std::cout << "b: " << b << '\n';
std::cout << "a + b: " << a + b << '\n';
a = b;
std::cout << "a: " << a << '\n';
std::cout << "b: " << b << '\n';
std::cout << "a + b: " << a + b << '\n';
a = AutoDiff::Forward<double>(0.0);
std::cout << "a: " << a << '\n';
a += 1;
std::cout << "a: " << a << '\n';
std::cout << "a + 1: " << (a + 1) << '\n';
std::cout << "1 + a: " << (1.0f + a) << '\n';
a = AutoDiff::Forward<double>(1);
std::cout << "a: " << a << '\n';
std::cout << "a - 1: " << (a - 1) << '\n';
std::cout << "a - b: " << (a - b) << '\n';
}