v0.14.0
ftensor_and_adolc_tapeless.cpp
Go to the documentation of this file.
1 
2 #ifndef WITH_ADOL_C
3 #error "MoFEM need to be compiled with ADOL-C"
4 #endif
5 
6 #include <ostream>
7 
8 #define ADOLC_TAPELESS
9 #define NUMBER_DIRECTIONS 6
10 
11 // #include <adolc/adolc.h>
12 #include <adolc/adtl.h>
13 // typedef adtl::adouble adouble;
14 
15 #define FTENSOR_DEBUG
16 #include <FTensor.hpp>
17 
18 int main(int argc, char *argv[])
19 {
20  adtl::setNumDir(6);
23 
24  FTensor::Tensor1<double, 2> t1(1., 1.);
25  FTensor::Tensor2<double, 2, 2> t2(1., 0., 0., 1.);
26 
29 
30  int dd0 = 0;
31  for(int ii = 0; ii != 2; ii++, dd0++)
32  {
33  a_t1(ii).setValue(t1(ii));
34  for(int kk = 0; kk != 6; kk++)
35  {
36  if(dd0 == kk)
37  {
38  a_t1(ii).setADValue(kk, 1);
39  }
40  else
41  {
42  a_t1(ii).setADValue(kk, 0);
43  }
44  }
45  }
46  for(int ii = 0; ii != 2; ii++)
47  {
48  for(int jj = 0; jj != 2; jj++, dd0++)
49  {
50  a_t2(ii, jj).setValue(t2(ii, jj));
51  for(int kk = 0; kk != 6; kk++)
52  {
53  if(kk == dd0)
54  {
55  a_t2(ii, jj).setADValue(kk, 1);
56  }
57  else
58  {
59  a_t2(ii, jj).setADValue(kk, 0);
60  }
61  }
62  }
63  }
64  for(int ii = 0; ii != 2; ii++)
65  {
66  std::cout << "a_t1 ( " << ii << " ) = " << a_t1(ii) << std::endl;
67  }
68  for(int ii = 0; ii != 2; ii++)
69  {
70  for(int jj = 0; jj != 2; jj++)
71  {
72  std::cout << "a_t1 ( " << ii << "," << jj << " ) = " << a_t2(ii, jj)
73  << std::endl;
74  }
75  }
76 
77  adtl::adouble a_t0 = a_t1(I) * a_t2(I, J) * a_t1(J);
78 
79  double t0;
80  t0 = a_t0.getValue();
81  std::cout << "Value: " << t0 << " ( " << a_t0 << " ) " << std::endl;
82 
85 
86  int dd = 0;
87  for(int ii = 0; ii != 2; ii++, dd++)
88  {
89  ad_t0_t1(ii) = a_t0.getADValue(dd);
90  }
91  for(int ii = 0; ii != 2; ii++)
92  {
93  for(int jj = 0; jj != 2; jj++, dd++)
94  {
95  ad_t0_t2(ii, jj) = a_t0.getADValue(dd);
96  }
97  }
98 
99  // 2nd derivative
100  FTensor::Tensor2<double, 2, 2> ad_t0_t1_t1;
101 
102  std::cout << "Derivatives t0_t1" << std::endl;
103  for(int ii = 0; ii != 2; ii++, dd++)
104  {
105  std::cout << ad_t0_t1(ii) << std::endl;
106  if(ad_t0_t1(ii) != 2)
107  {
108  std::cerr << "Wrong result, should be 2" << std::endl;
109  exit(-1);
110  }
111  }
112  std::cout << "Derivatives t0_t2" << std::endl;
113  for(int ii = 0; ii != 2; ii++)
114  {
115  for(int jj = 0; jj != 2; jj++, dd++)
116  {
117  std::cout << ad_t0_t2(ii, jj) << " ";
118  if(ad_t0_t2(ii, ii) != 1)
119  {
120  std::cerr << "Wrong result, should be 1" << std::endl;
121  exit(-1);
122  }
123  }
124  std::cout << "\n";
125  }
126 
127  return 0;
128 }
FTensor::Tensor1
Definition: Tensor1_value.hpp:8
J
FTensor::Index< 'J', DIM1 > J
Definition: level_set.cpp:30
FTensor::Tensor2
Definition: Tensor2_value.hpp:16
I
constexpr IntegrationType I
Definition: operators_tests.cpp:31
main
int main(int argc, char *argv[])
Definition: ftensor_and_adolc_tapeless.cpp:18
FTensor::Index
Definition: Index.hpp:23
FTensor::dd
const Tensor2_symmetric_Expr< const ddTensor0< T, Dim, i, j >, typename promote< T, double >::V, Dim, i, j > dd(const Tensor0< T * > &a, const Index< i, Dim > index1, const Index< j, Dim > index2, const Tensor1< int, Dim > &d_ijk, const Tensor1< double, Dim > &d_xyz)
Definition: ddTensor0.hpp:33
FTensor.hpp
Tensors class implemented by Walter Landry.