source: trunk/ADOL-C/examples/tapeless_scalar.cpp @ 429

Last change on this file since 429 was 429, checked in by kulshres, 6 years ago

merge branch 'new_traceless' into svn 'trunk'

Also update the tapeless_scalar and tapeless_vector examples updated

The following commits have been merged:

commit b8092a92979317d8c4926a2f01799e3f86493b87
Merge: b883461 d1739a3
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Tue Apr 30 14:31:20 2013 +0200

Merge branch 'master' into new_traceless

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

commit b883461efcdf7ac54268e37884b7d48f94362dad
Author: Benjamin Letschert <letschi@…>
Date: Fri Aug 31 13:35:30 2012 +0200

correct all assignment operators to return this

commit abadb57fb63c5ebe58603313a477d5c62bd75a23
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Fri Jun 8 11:32:52 2012 +0200

use inlining again as much as possible

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

commit 72159664f51564d898a4e8cf24c00169991d43ab
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Mon Jun 4 18:20:33 2012 +0200

bugfixes and efficiency fixes for new traceless mode

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

commit b3139b5123a9e177bb02c93588cd6b48ed365873
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Tue May 29 16:23:38 2012 +0200

get rid of compilation errors

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

commit 9ffa38f804f69f9e2162020aa29adb791fa2966e
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Tue May 29 15:57:48 2012 +0200

add files to build system

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

commit 288b0b568c6b7b10d0eddc649e8c79c65600f62e
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Tue May 29 15:50:31 2012 +0200

reimplement tapeless mode

due to larger functions required with sparsity pattern detection, the
preprocessor based implementation of the tapeless mode was bad. now it
is a runtime based implementation.

the user does
#include <adolc/adtl.h>

using namespace adtl;

there is no more need for ADOLC_TAPELESS_UNIQUE_INTERNALS.

the user needs to call setNumDir(n) for n>1
and setMode(ADTL_INDO) for sparsity detection
then later setMode(ADTL_FOV) for getting derivatives

one could also do setMode(ADTL_FOV_INDO) for both simultaneously.

Signed-off-by: Kshitij Kulshreshtha <kshitij@…>

commit c5bb5abcb3aceeb9ca7e4ac99b3f50e0ae6ac8db
Author: Benjamin Letschert <letschi@…>
Date: Fri Mar 30 13:15:03 2012 +0200

Adding control variable for ADOLC_Init_sparse_pattern

commit b5ae7415cb4bb90d80a1f0cfbcc53197cff7939e
Author: Benjamin Letschert <letschi@…>
Date: Thu Mar 29 18:24:42 2012 +0200

Adding ADOLC_TRACELESS_SPARSE_PATTERN in traceless mode

  • Property svn:keywords set to Author Date Id Revision
File size: 1.9 KB
Line 
1/*----------------------------------------------------------------------------
2 ADOL-C -- Automatic Differentiation by Overloading in C++
3 File:     tapeless_scalar.cpp
4 Revision: $Id: tapeless_scalar.cpp 429 2013-05-27 09:28:48Z kulshres $
5 Contents: computation of coordinate transform,
6           scalar tapeless forward mode
7           described in the manual
8
9 Copyright (c) Andrea Walther, Andreas Kowarz
10 
11 This file is part of ADOL-C. This software is provided as open source.
12 Any use, reproduction, or distribution of the software constitutes
13 recipient's acceptance of the terms of the accompanying license file.
14 
15---------------------------------------------------------------------------*/
16
17
18/****************************************************************************/
19/*                                                                 INCLUDES */
20
21#include <iostream>
22using namespace std;
23
24#include <adolc/adtl.h>
25typedef adtl::adouble adouble;
26
27
28int main(int argc, char *argv[]) {
29    adouble x[3], y[3];
30
31    for (int i=0; i<3;++i)          // Initialize x_i
32        x[i] = i + 1.0;
33
34    cout << endl << "Compute transform from Cartesian to spherical polar coordinates" << endl << endl;
35
36    // derivative of y with respect to x0
37    double one=1.0;
38    x[0].setADValue(&one);
39
40    y[0] = sqrt(x[0]*x[0]+x[1]*x[1]+x[2]*x[2]);
41    y[1] = atan(sqrt(x[0]*x[0]+x[1]*x[1])/x[2]);
42    y[2] = atan(x[1]/x[0]);
43
44    cout << "cartesian coordinates: " << endl;
45    cout << "x[0] = " << x[0].getValue() << "  x[1] = " << x[1].getValue()
46    << "  x[2] = " << x[2].getValue() << endl << endl;
47    cout << "cpherical polar coordinates: " << endl;
48    cout << "y[0] = " << y[0].getValue() << "  y[1] = " << y[1].getValue()
49    << "  y[2] = " << y[2].getValue() << endl <<endl;
50
51    // "use" the derivative
52    cout << "derivative:" << endl;
53    cout << "dy[0]/dx[0] = " << *y[0].getADValue() << "  dy[1]/dx[0] = " << *y[1].getADValue()
54    << "  dy[2]/dx[0] = " << *y[2].getADValue() << endl;
55
56    return 0;
57}
58
Note: See TracBrowser for help on using the repository browser.