source: trunk/ADOL-C/examples/additional_examples/ode/vfunc_robertson.cpp @ 171

Last change on this file since 171 was 171, checked in by kulshres, 9 years ago

Squashed merge branch 'master' of 'gitclone' into svn

  • 'master' of 'gitclone': (84 commits) adjust example makefiles and include paths get rid of the symlink in the src subdirectory

details of the commits:
commit c9e4bc332d2363f737fc2e8a8fcfc2e43ddb9d15
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Mon Oct 4 15:43:47 2010 +0200

adjust example makefiles and include paths

include paths in example sources were wrong for some time now
simplify makefile rules too, there is really no need for checking SPARSE
adjust include paths in makefiles.

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

commit e6e1963e41e097fd5b4a79cd1611c12f6868dc94
Author: Kshitij Kulshreshtha <kshitij@…>
Date: Mon Oct 4 15:41:25 2010 +0200

get rid of the symlink in the src subdirectory

windows doesn't like symlinks and make infinite depth directories
we now create a symlink for build in the directory parallel to src
adjust all makefiles.am accordingly for build

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

  • Property svn:keywords set to Author Date Id Revision
File size: 4.6 KB
Line 
1/*----------------------------------------------------------------------------
2 ADOL-C -- Automatic Differentiation by Overloading in C++
3 File:     vfunc_robertson.cpp
4 Revision: $Id: vfunc_robertson.cpp 171 2010-10-04 13:57:19Z kulshres $
5 Contents: example for function module containing the Robertson test problem
6            (based on odexam.C of version 1.7)
7 
8   Each << function module >> contains:
9         
10     (1) const char* const controlFileName
11     (2) int indepDim;
12     (3) int depDim;
13     (4) void initProblemParameters( void )
14     (5) void initIndependents( double* indEPS_ )
15     (6) void originalVectorFunction( double* indEPS_, double* dEPS_ )
16     (7) void tapingVectorFunction( int tag, double* indEPS_, double* dEPS_ )   
17
18 Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz,
19               Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel
20 
21 This file is part of ADOL-C. This software is provided as open source.
22 Any use, reproduction, or distribution of the software constitutes
23 recipient's acceptance of the terms of the accompanying license file.
24 
25---------------------------------------------------------------------------*/
26#define _VFUNC_ROBERTSON_C_
27
28/****************************************************************************/
29/*                                                                 INCLUDES */
30#include <adolc/adolc.h>
31
32#include <math.h>
33
34
35/****************************************************************************/
36/*                                                         GLOBAL VARIABLES */
37
38/*--------------------------------------------------------------------------*/
39/*                                                        Control file name */
40const char* controlFileName = "robertsonexam.ctrl";
41
42/*--------------------------------------------------------------------------*/
43/*                                                               Dimensions */
44int indepDim;
45int depDim;
46
47/*--------------------------------------------------------------------------*/
48/*                                       Other problem dependent parameters */
49
50
51/****************************************************************************/
52/*                                                  INIT PROBLEM PARAMETERS */
53void initProblemParameters( void ) {
54    fprintf(stdout,"ROBERTSONEXAM (ADOL-C Example)\n\n");
55
56    /* number of indeps & deps */
57    indepDim = 3;
58    depDim   = 3;
59}
60
61
62/****************************************************************************/
63/*                                                        INITIALIZE INDEPs */
64void initIndependents( double* indeps ) {
65    indeps[0]  = 1.0;
66    indeps[1]  = 0.01; /* originally 0.0 */
67    indeps[2]  = 0.02; /* originally 0.0 */
68}
69
70
71/****************************************************************************/
72/*                                                 ORIGINAL SCALAR FUNCTION */
73
74/*--------------------------------------------------------------------------*/
75/*                                               The Robertson test problem */
76void robertson( double* indeps, double* deps ) {
77    deps[0] = -sin(indeps[2]) + 1.0e8*indeps[2]*(1.0-1.0/indeps[0]);
78    deps[1] = -10.0*indeps[0]
79              + 3.0e7*indeps[2]*(1.0-indeps[1]);
80    deps[2] = -deps[0] - deps[1];
81}
82
83/*--------------------------------------------------------------------------*/
84/*                                                   The interface function */
85void originalVectorFunction( double* indeps, double* deps ) {
86    robertson(indeps,deps);
87}
88
89
90/****************************************************************************/
91/*                                                   TAPING SCALAR FUNCTION */
92
93/*--------------------------------------------------------------------------*/
94/*                                        The active Robertson test problem */
95void activeRobertson( adouble* indeps, adouble* deps ) {
96    deps[0] = -sin(indeps[2]) + 1.0e8*indeps[2]*(1.0-1.0/indeps[0]);
97    deps[1] = -10.0*indeps[0]
98              + 3.0e7*indeps[2]*(1.0-indeps[1]);
99    deps[2] = -deps[0] - deps[1];
100}
101
102
103/*--------------------------------------------------------------------------*/
104/*                                                   The interface function */
105void tapingVectorFunction( int tag, double* indeps, double* deps ) {
106    int i;
107    trace_on(tag);
108    adouble* activeIndeps = new adouble[indepDim];
109    adouble* activeDeps   = new adouble[depDim];
110    adouble* aIP = activeIndeps;
111    double*  iP  = indeps;
112    for (i=0; i<indepDim; i++)
113        *aIP++ <<= *iP++;
114    activeRobertson(activeIndeps,activeDeps);
115    aIP = activeDeps;
116    iP  = deps;
117    for (i=0; i<depDim; i++)
118        *aIP++ >>= *iP++;
119    trace_off();
120}
121
122#undef _VFUNC_ROBERTSON_C_
123
124
125
126
127
Note: See TracBrowser for help on using the repository browser.