1 /*----------------------------------------------------------------------------
2  ADOL-C -- Automatic Differentiation by Overloading in C++
3  File:     adouble.cpp
4  Revision: $Id$
5  Contents: adouble_tl.cpp contains that definitions of procedures used to
6            define various tapeless adouble operations.
7            These operations actually have two purposes.
8            The first purpose is to actual compute the function, just as
9            the same code written for double precision (single precision -
10            complex - interval) arithmetic would.  The second purpose is
11            to compute directional derivatives in forward mode of
12 	   automatic differentiation.
13 
14  Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz,
15                Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel,
16                Benjamin Letschert
17 
18  This file is part of ADOL-C. This software is provided as open source.
19  Any use, reproduction, or distribution of the software constitutes
20  recipient's acceptance of the terms of the accompanying license file.
21 
22 ----------------------------------------------------------------------------*/
23 
24 #include <adolc/adtl.h>
25 #include <cmath>
26 #include <iostream>
27 #include <limits>
28 #include "dvlparms.h"
29 
30 using std::cout;
31 
32 extern "C" void adolc_exit(int errorcode, const char *what, const char* function, const char *file, int line);
33 
34 namespace adtl {
35 
36 
37 size_t adouble::numDir = 1;
38 
39 #ifdef USE_ADTL_REFCOUNTING
40 size_t refcounter::refcnt = 0;
41 #endif
42 
43 
44 #if USE_BOOST_POOL
45 boost::pool<boost::default_user_allocator_new_delete>* adouble::advalpool = new
46 boost::pool<boost::default_user_allocator_new_delete>((adouble::numDir+1) * sizeof(double), 32, 10000);
47 #endif
48 
49 /*******************  i/o operations  ***************************************/
operator <<(ostream & out,const adouble & a)50 ostream& operator << ( ostream& out, const adouble& a) {
51 	out << "Value: " << a.PRIMAL_VALUE;
52 	out << " ADValues (" << adouble::numDir << "): ";
53 	FOR_I_EQ_1_LTEQ_NUMDIR
54 	    out << a.ADVAL_I << " ";
55 	out << "(a)";
56     return out;
57 }
58 
operator >>(istream & in,adouble & a)59 istream& operator >> ( istream& in, adouble& a) {
60 	char c;
61 	do in >> c;
62 	while (c!=':' && !in.eof());
63 	in >> a.PRIMAL_VALUE;
64 	unsigned int num;
65 	do in >> c;
66 	while (c!='(' && !in.eof());
67 	in >> num;
68 	if (num>adouble::numDir)
69 	{
70 	    cout << "ADOL-C error: to many directions in input\n";
71 	    adolc_exit(-1,"",__func__,__FILE__,__LINE__);
72 	}
73 	do in >> c;
74 	while (c!=':' && !in.eof());
75 	FOR_I_EQ_1_LTEQ_NUMDIR
76 	    in >> a.ADVAL_I;
77 	do in >> c;
78 	while (c!=')' && !in.eof());
79 	return in;
80 }
81 
82 }
83