~chaffra/+junk/trilinos

« back to all changes in this revision

Viewing changes to packages/sacado/test/TestSuite/ELRDFadUnitTests.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Christophe Prud'homme, Christophe Prud'homme, Johannes Ring
  • Date: 2009-12-13 12:53:22 UTC
  • mfrom: (5.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20091213125322-in0nrdjc55deqsw9
Tags: 10.0.3.dfsg-1
[Christophe Prud'homme]
* New upstream release

[Johannes Ring]
* debian/patches/libname.patch: Add prefix 'libtrilinos_' to all
  libraries. 
* debian/patches/soname.patch: Add soversion to libraries.
* debian/watch: Update download URL.
* debian/control:
  - Remove python-numeric from Build-Depends (virtual package).
  - Remove automake and autotools from Build-Depends and add cmake to
    reflect switch to CMake.
  - Add python-support to Build-Depends.
* debian/rules: 
  - Cleanup and updates for switch to CMake.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// $Id: ELRDFadUnitTests.cpp,v 1.1.4.1 2009/03/05 20:35:26 etphipp Exp $ 
2
 
// $Source: /space/CVS/Trilinos/packages/sacado/test/TestSuite/Attic/ELRDFadUnitTests.cpp,v $ 
3
 
// @HEADER
4
 
// ***********************************************************************
5
 
// 
6
 
//                           Sacado Package
7
 
//                 Copyright (2006) Sandia Corporation
8
 
// 
9
 
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
10
 
// the U.S. Government retains certain rights in this software.
11
 
// 
12
 
// This library is free software; you can redistribute it and/or modify
13
 
// it under the terms of the GNU Lesser General Public License as
14
 
// published by the Free Software Foundation; either version 2.1 of the
15
 
// License, or (at your option) any later version.
16
 
//  
17
 
// This library is distributed in the hope that it will be useful, but
18
 
// WITHOUT ANY WARRANTY; without even the implied warranty of
19
 
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20
 
// Lesser General Public License for more details.
21
 
//  
22
 
// You should have received a copy of the GNU Lesser General Public
23
 
// License along with this library; if not, write to the Free Software
24
 
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
25
 
// USA
26
 
// Questions? Contact David M. Gay (dmgay@sandia.gov) or Eric T. Phipps
27
 
// (etphipp@sandia.gov).
28
 
// 
29
 
// ***********************************************************************
30
 
// @HEADER
31
 
 
32
 
#include "ELRDFadUnitTests.hpp"
33
 
 
34
 
CPPUNIT_TEST_SUITE_REGISTRATION( ELRDFadOpsUnitTest );
35
 
 
36
 
ELRDFadOpsUnitTest::ELRDFadOpsUnitTest() :
37
 
  urand(0.0, 1.0), n(5), tol_a(1.0e-15), tol_r(1.0e-14) {}
38
 
 
39
 
ELRDFadOpsUnitTest::ELRDFadOpsUnitTest(int numComponents, 
40
 
                                           double absolute_tolerance, 
41
 
                                           double relative_tolerance) :
42
 
  urand(0.0, 1.0), 
43
 
  n(numComponents), 
44
 
  tol_a(absolute_tolerance), 
45
 
  tol_r(relative_tolerance) {}
46
 
 
47
 
void ELRDFadOpsUnitTest::setUp() {
48
 
  double val;
49
 
 
50
 
  val = urand.number();
51
 
  a_dfad = DFadType(n,val);
52
 
  a_fad = FAD::Fad<double>(n,val);
53
 
  
54
 
  val = urand.number();
55
 
  b_dfad = DFadType(n,val);
56
 
  b_fad = FAD::Fad<double>(n,val);
57
 
 
58
 
  for (int i=0; i<n; i++) {
59
 
    val = urand.number();
60
 
    a_dfad.fastAccessDx(i) = val;
61
 
    a_fad.fastAccessDx(i) = val;
62
 
 
63
 
    val = urand.number();
64
 
    b_dfad.fastAccessDx(i) = val;
65
 
    b_fad.fastAccessDx(i) = val;
66
 
  }
67
 
}
68
 
 
69
 
void ELRDFadOpsUnitTest::tearDown() {}
70
 
 
71
 
void ELRDFadOpsUnitTest::compareFads(const DFadType& x_dfad,
72
 
                                       const FAD::Fad<double>& x_fad) {
73
 
 
74
 
  if (x_dfad.size() != x_fad.size()) {
75
 
    std::cout << "x_dfad.size() = " << x_dfad.size() << std::endl
76
 
              << "x_fad.size() = " << x_fad.size() << std::endl
77
 
              << "x_dfad = " << x_dfad << std::endl
78
 
              << "x_fad = " << x_fad << std::endl;
79
 
  }
80
 
 
81
 
  // Compare sizes
82
 
  CPPUNIT_ASSERT(x_dfad.size() == x_fad.size());
83
 
  
84
 
  // Compare hasFastAccess
85
 
  CPPUNIT_ASSERT(x_dfad.hasFastAccess() == x_fad.hasFastAccess());
86
 
  
87
 
  // Compare values
88
 
  compareDoubles(x_dfad.val(), x_fad.val());
89
 
  
90
 
  for (int i=0; i<x_fad.size(); i++) {
91
 
    
92
 
    // Compare dx
93
 
    compareDoubles(x_dfad.dx(i), x_fad.dx(i));
94
 
    
95
 
    // Compare fastAccessDx
96
 
    compareDoubles(x_dfad.fastAccessDx(i), x_fad.fastAccessDx(i));
97
 
  }
98
 
}
99
 
 
100
 
void ELRDFadOpsUnitTest::compareDoubles(double a, double b) {
101
 
  if ( fabs(a-b) >= tol_a + tol_r*fabs(a) )
102
 
    std::cout << "a = " << a << std::endl
103
 
              << "b = " << b << std::endl;
104
 
  CPPUNIT_ASSERT( fabs(a-b) < tol_a + tol_r*fabs(a) );
105
 
}
106
 
 
107
 
void ELRDFadOpsUnitTest::testMax() {
108
 
  double val;
109
 
 
110
 
  DFadType aa_dfad = a_dfad + 1.0;
111
 
  c_dfad = max(aa_dfad, a_dfad);
112
 
  compareDoubles(c_dfad.val(), aa_dfad.val());
113
 
  for (int i=0; i<n; i++) {
114
 
    compareDoubles(c_dfad.dx(i), aa_dfad.dx(i));
115
 
    compareDoubles(c_dfad.fastAccessDx(i), aa_dfad.fastAccessDx(i));
116
 
  }
117
 
  
118
 
  c_dfad = max(a_dfad, aa_dfad);
119
 
  compareDoubles(c_dfad.val(), aa_dfad.val());
120
 
  for (int i=0; i<n; i++) {
121
 
    compareDoubles(c_dfad.dx(i), aa_dfad.dx(i));
122
 
    compareDoubles(c_dfad.fastAccessDx(i), aa_dfad.fastAccessDx(i));
123
 
  }
124
 
 
125
 
  c_dfad = max(a_dfad+1.0, a_dfad);
126
 
  compareDoubles(c_dfad.val(), aa_dfad.val());
127
 
  for (int i=0; i<n; i++) {
128
 
    compareDoubles(c_dfad.dx(i), aa_dfad.dx(i));
129
 
    compareDoubles(c_dfad.fastAccessDx(i), aa_dfad.fastAccessDx(i));
130
 
  }
131
 
  
132
 
  c_dfad = max(a_dfad, a_dfad+1.0);
133
 
  compareDoubles(c_dfad.val(), aa_dfad.val());
134
 
  for (int i=0; i<n; i++) {
135
 
    compareDoubles(c_dfad.dx(i), aa_dfad.dx(i));
136
 
    compareDoubles(c_dfad.fastAccessDx(i), aa_dfad.fastAccessDx(i));
137
 
  }
138
 
 
139
 
  // Expr, Expr (same)
140
 
  this->c_dfad = max(this->a_dfad+1.0, this->a_dfad+1.0);
141
 
  compareDoubles(c_dfad.val(), aa_dfad.val());
142
 
  for (int i=0; i<n; i++) {
143
 
    compareDoubles(c_dfad.dx(i), aa_dfad.dx(i));
144
 
    compareDoubles(c_dfad.fastAccessDx(i), aa_dfad.fastAccessDx(i));
145
 
  }
146
 
 
147
 
  // Expr, Expr (different)
148
 
  this->c_dfad = max(this->a_dfad+1.0, this->a_dfad-1.0);
149
 
  compareDoubles(c_dfad.val(), aa_dfad.val());
150
 
  for (int i=0; i<n; i++) {
151
 
    compareDoubles(c_dfad.dx(i), aa_dfad.dx(i));
152
 
    compareDoubles(c_dfad.fastAccessDx(i), aa_dfad.fastAccessDx(i));
153
 
  }
154
 
  this->c_dfad = max(this->a_dfad-1.0, this->a_dfad+1.0);
155
 
  compareDoubles(c_dfad.val(), aa_dfad.val());
156
 
  for (int i=0; i<n; i++) {
157
 
    compareDoubles(c_dfad.dx(i), aa_dfad.dx(i));
158
 
    compareDoubles(c_dfad.fastAccessDx(i), aa_dfad.fastAccessDx(i));
159
 
  }
160
 
  
161
 
  val = a_dfad.val() + 1;
162
 
  c_dfad = max(a_dfad, val);
163
 
  compareDoubles(c_dfad.val(), val);
164
 
  for (int i=0; i<n; i++)
165
 
    compareDoubles(c_dfad.dx(i), 0.0);
166
 
  
167
 
  val = a_dfad.val() - 1;
168
 
  c_dfad = max(a_dfad, val);
169
 
  compareDoubles(c_dfad.val(), a_dfad.val());
170
 
  for (int i=0; i<n; i++) {
171
 
    compareDoubles(c_dfad.dx(i), a_dfad.dx(i));
172
 
    compareDoubles(c_dfad.fastAccessDx(i), a_dfad.fastAccessDx(i));
173
 
  }
174
 
 
175
 
  val = b_dfad.val() + 1;
176
 
  c_dfad = max(val, b_dfad);
177
 
  compareDoubles(c_dfad.val(), val);
178
 
  for (int i=0; i<n; i++)
179
 
    compareDoubles(c_dfad.dx(i), 0.0);
180
 
  
181
 
  val = b_dfad.val() - 1;
182
 
  c_dfad = max(val, b_dfad);
183
 
  compareDoubles(c_dfad.val(), b_dfad.val());
184
 
  for (int i=0; i<n; i++) {
185
 
    compareDoubles(c_dfad.dx(i), b_dfad.dx(i));
186
 
    compareDoubles(c_dfad.fastAccessDx(i), b_dfad.fastAccessDx(i));
187
 
  }
188
 
}
189
 
 
190
 
void ELRDFadOpsUnitTest::testMin() {
191
 
  double val;
192
 
 
193
 
  DFadType aa_dfad = a_dfad - 1.0;
194
 
  c_dfad = min(aa_dfad, a_dfad);
195
 
  compareDoubles(c_dfad.val(), aa_dfad.val());
196
 
  for (int i=0; i<n; i++) {
197
 
    compareDoubles(c_dfad.dx(i), aa_dfad.dx(i));
198
 
    compareDoubles(c_dfad.fastAccessDx(i), aa_dfad.fastAccessDx(i));
199
 
  }
200
 
 
201
 
  c_dfad = min(a_dfad, aa_dfad);
202
 
  compareDoubles(c_dfad.val(), aa_dfad.val());
203
 
  for (int i=0; i<n; i++) {
204
 
    compareDoubles(c_dfad.dx(i), aa_dfad.dx(i));
205
 
    compareDoubles(c_dfad.fastAccessDx(i), aa_dfad.fastAccessDx(i));
206
 
  }
207
 
 
208
 
  // Expr, Expr (same)
209
 
  this->c_dfad = min(this->a_dfad-1.0, this->a_dfad-1.0);
210
 
  compareDoubles(c_dfad.val(), aa_dfad.val());
211
 
  for (int i=0; i<n; i++) {
212
 
    compareDoubles(c_dfad.dx(i), aa_dfad.dx(i));
213
 
    compareDoubles(c_dfad.fastAccessDx(i), aa_dfad.fastAccessDx(i));
214
 
  }
215
 
 
216
 
  // Expr, Expr (different)
217
 
  this->c_dfad = min(this->a_dfad+1.0, this->a_dfad-1.0);
218
 
  compareDoubles(c_dfad.val(), aa_dfad.val());
219
 
  for (int i=0; i<n; i++) {
220
 
    compareDoubles(c_dfad.dx(i), aa_dfad.dx(i));
221
 
    compareDoubles(c_dfad.fastAccessDx(i), aa_dfad.fastAccessDx(i));
222
 
  }
223
 
  this->c_dfad = min(this->a_dfad-1.0, this->a_dfad+1.0);
224
 
  compareDoubles(c_dfad.val(), aa_dfad.val());
225
 
  for (int i=0; i<n; i++) {
226
 
    compareDoubles(c_dfad.dx(i), aa_dfad.dx(i));
227
 
    compareDoubles(c_dfad.fastAccessDx(i), aa_dfad.fastAccessDx(i));
228
 
  }
229
 
 
230
 
  val = a_dfad.val() - 1;
231
 
  c_dfad = min(a_dfad, val);
232
 
  compareDoubles(c_dfad.val(), val);
233
 
  for (int i=0; i<n; i++)
234
 
    compareDoubles(c_dfad.dx(i), 0.0);
235
 
  
236
 
  val = a_dfad.val() + 1;
237
 
  c_dfad = min(a_dfad, val);
238
 
  compareDoubles(c_dfad.val(), a_dfad.val());
239
 
  for (int i=0; i<n; i++) {
240
 
    compareDoubles(c_dfad.dx(i), a_dfad.dx(i));
241
 
    compareDoubles(c_dfad.fastAccessDx(i), a_dfad.fastAccessDx(i));
242
 
  }
243
 
 
244
 
  val = b_dfad.val() - 1;
245
 
  c_dfad = min(val, b_dfad);
246
 
  compareDoubles(c_dfad.val(), val);
247
 
  for (int i=0; i<n; i++)
248
 
    compareDoubles(c_dfad.dx(i), 0.0);
249
 
  
250
 
  val = b_dfad.val() + 1;
251
 
  c_dfad = min(val, b_dfad);
252
 
  compareDoubles(c_dfad.val(), b_dfad.val());
253
 
  for (int i=0; i<n; i++) {
254
 
    compareDoubles(c_dfad.dx(i), b_dfad.dx(i));
255
 
    compareDoubles(c_dfad.fastAccessDx(i), b_dfad.fastAccessDx(i));
256
 
  }
257
 
}