Test_BackgroundMesh.h 7.97 KB
Newer Older
1
2
3
4
5
6
7
/******************************************************************************
 *
 * AMDiS - Adaptive multidimensional simulations
 *
 * Copyright (C) 2013 Dresden University of Technology. All Rights Reserved.
 * Web: https://fusionforge.zih.tu-dresden.de/projects/amdis
 *
8
 * Authors:
9
10
11
12
13
14
15
16
17
 * Simon Vey, Thomas Witkowski, Andreas Naumann, Simon Praetorius, et al.
 *
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 *
 * This file is part of AMDiS
 *
 * See also license.opensource.txt in the distribution.
18
 *
19
20
21
22
23
24
25
26
27
28
 ******************************************************************************/



/** \file Test_BackgroundMesh.h */

#ifndef AMDIS_TEST_BACKGROUND_MESH_H
#define AMDIS_TEST_BACKGROUND_MESH_H

#include "AMDiS.h"
29
30
#include "extensions/Views.h"
#include "extensions/search/BackgroundMesh.h"
31
32
33
34
35
36
37
38
39
#include "boost/date_time/posix_time/posix_time.hpp"

namespace amdis_tests
{
  using namespace boost::posix_time;
  using namespace AMDiS;
  using namespace AMDiS::extensions;

  class Test_BackgroundMesh {
40
  public:
41
42
43
44
45
46
47
    void init(const FiniteElemSpace *feSpace_,const FiniteElemSpace *feSpace2_) {
      feSpace = feSpace_;
      feSpace2 = feSpace2_;
      dim = feSpace->getMesh()->getDim();
      boxCreated = false;
      boxFilled = false;
    }
48

49
50
51
52
    void test1()
    {
      ptime start_time;
      time_duration td;
53

54
55
56
      WorldVector<double> center; center.set(0.0);
      WorldVector<double> dimension; dimension.set(1.0);
      DOFVector<double> vec(feSpace, "vec");
57

58
59
      std::vector<int> N(Global::getGeo(WORLD), 4);
      Parameters::get("box->dimension", N);
60

61
      // test 1: create and fill Box
62

63
64
65
66
      start_time= microsec_clock::local_time();
      box = Box::provideBackgroundMesh(feSpace);
      td = microsec_clock::local_time()-start_time;
      std::cout<<"create box ... "<<(td.total_milliseconds()/1000.0)<<" sec\n";
67

68
69
70
71
72
  //     start_time= microsec_clock::local_time();
  //     box->fillBox(feSpace);
  //     td = microsec_clock::local_time()-start_time;
  //     std::cout<<"fillBox ... "<<(td.total_milliseconds()/1000.0)<<" sec\n";
      std::cout<<"nr of dofs = "<<vec.getUsedSize()<<"\n";
73

74
75
      // test 2: test whether a point is recognised as inside
      BOOST_CHECK( box->inBox(center) );
76

77
78
79
      // test 3: test whether a point outside of the box is recognised as ouside
      WorldVector<double> outside = 2.0*dimension;
      BOOST_CHECK( !box->inBox(outside) );
80

81
82
      WorldVector<double> first; first.set(-1.0);
      BOOST_CHECK( box->inBox(first) );
83

84
85
86
87
88
      WorldVector<double> last; last.set(1.0);
      start_time= microsec_clock::local_time();
      BOOST_CHECK( box->inBox(last) );
      td = microsec_clock::local_time()-start_time;
      std::cout<<"inBox + getBox ... "<<(td.total_milliseconds()/1000.0)<<" sec\n";
89
90


91
      std::vector<DataType> nearestData;
92

93
94
95
96
97
98
99
      int nData = 3;
      Parameters::get("box->nr of neares data", nData);
      start_time= microsec_clock::local_time();
      box->getNearestData(center, nearestData, nData);
      td = microsec_clock::local_time()-start_time;
      std::cout<<"getNearestData ... "<<(td.total_milliseconds()/1000.0)<<" sec\n";
      BOOST_CHECK( nearestData.size() == nData );
100

101
102
103
104
      std::cout<<"nearestData = {\n";
      for (int i = 0; i < nData; i++)
	std::cout<<" ["<<nearestData[i].first<<"; "<<nearestData[i].second<<"], \n";
      std::cout<<"\n}\n";
105

106
      vec.interpol(new AMDiS::Norm2Sqr<WorldVector<double> >);
107

108
109
110
111
112
113
114
115
116
      double exact1 = AMDiS::Norm2Sqr<WorldVector<double> >()(center);
      double value0 = box->evalAtPoint(vec, center, 0);
      double value1 = box->evalAtPoint(vec, center, 1);
      double value2 = box->evalAtPoint(vec, center, 2);
      double value3 = box->evalAtPoint(vec, center, 3);
      std::cout<< "|evalAtPoint(center,0) - "<<exact1<<"| = "<<abs(value0-exact1)<<"\n";
      std::cout<< "|evalAtPoint(center,1) - "<<exact1<<"| = "<<abs(value1-exact1)<<"\n";
      std::cout<< "|evalAtPoint(center,2) - "<<exact1<<"| = "<<abs(value2-exact1)<<"\n";
      std::cout<< "|evalAtPoint(center,3) - "<<exact1<<"| = "<<abs(value3-exact1)<<"\n";
117

118
119
120
121
122
123
124
125
126
      double exact2 = AMDiS::Norm2Sqr<WorldVector<double> >()(last);
      value0 = box->evalAtPoint(vec, last, 0);
      value1 = box->evalAtPoint(vec, last, 1);
      value2 = box->evalAtPoint(vec, last, 2);
      value3 = box->evalAtPoint(vec, last, 3);
      std::cout<< "|evalAtPoint(last,0) - "<<exact2<<"| = "<<abs(value0-exact2)<<"\n";
      std::cout<< "|evalAtPoint(last,1) - "<<exact2<<"| = "<<abs(value1-exact2)<<"\n";
      std::cout<< "|evalAtPoint(last,2) - "<<exact2<<"| = "<<abs(value2-exact2)<<"\n";
      std::cout<< "|evalAtPoint(last,3) - "<<exact2<<"| = "<<abs(value3-exact2)<<"\n";
127

128
129
130
131
132
133
134
135
136
137
      last.set(std::sqrt(2.0)/3.0);
      double exact3 = AMDiS::Norm2Sqr<WorldVector<double> >()(last);
      value0 = box->evalAtPoint(vec, last, 0);
      value1 = box->evalAtPoint(vec, last, 1);
      value2 = box->evalAtPoint(vec, last, 2);
      value3 = box->evalAtPoint(vec, last, 3);
      std::cout<< "|evalAtPoint(last,0) - "<<exact3<<"| = "<<abs(value0-exact3)<<"\n";
      std::cout<< "|evalAtPoint(last,1) - "<<exact3<<"| = "<<abs(value1-exact3)<<"\n";
      std::cout<< "|evalAtPoint(last,2) - "<<exact3<<"| = "<<abs(value2-exact3)<<"\n";
      std::cout<< "|evalAtPoint(last,3) - "<<exact3<<"| = "<<abs(value3-exact3)<<"\n";
138

139
140
      boxCreated = true;
    }
141

142
143
144
145
146
  //____________________________________________________________________________//

    void test2()
    {
      BOOST_REQUIRE( boxCreated );
147

148
149
150
151
152
153
154
155
156
157
158
      ptime start_time;
      time_duration td;

      DOFVector<double> vec(feSpace, "vec");
      DOFVector<double> vec2(feSpace2, "vec2");
      DOFVector<double> vec2test(feSpace2, "vec2test");
      vec.interpol(new AMDiS::Norm2Sqr<WorldVector<double> >);
      vec2test.interpol(new AMDiS::Norm2Sqr<WorldVector<double> >);

      WorldVector<double> point;
      point.set(std::sqrt(2.0)/3.0);
159
160


161
162
163
164
165
166
167
168
169
170
171
172
      bool notEnabled = false;
      bool enabled = true;
      bool used = false;
      double diff = 1.e15;
  #ifdef USE_BACKGROUNDMESH
      Parameters::set("backgroundMesh->enabled",enabled);
      Parameters::set("KD-Tree->enabled",notEnabled);

      start_time= microsec_clock::local_time();
      interpol_coords(vec,vec2);
      td = microsec_clock::local_time()-start_time;
      std::cout<<"interpol_coords (backgroundMesh) ... "<<(td.total_milliseconds()/1000.0)<<" sec\n";
173

174
175
176
177
178
179
180
181
182
      diff = integrate_Vec2(vec2,vec2test,new AMDiS::L2Diff<double>);
      BOOST_CHECK_MESSAGE( diff < 1.e-8 , "backgroundMesh: L2-diff = "<<diff );
//       used = false;
//       Parameters::get("USE_BACKGROUNDMESH",used);
//       BOOST_CHECK( used );
  #endif
  #ifdef USE_KD_TREE
      Parameters::set("backgroundMesh->enabled",notEnabled);
      Parameters::set("KD-Tree->enabled",enabled);
183

184
185
186
187
      start_time= microsec_clock::local_time();
      interpol_coords(vec,vec2);
      td = microsec_clock::local_time()-start_time;
      std::cout<<"interpol_coords (KD-Tree) ... "<<(td.total_milliseconds()/1000.0)<<" sec\n";
188

189
190
191
192
193
194
195
196
      diff = integrate_Vec2(vec2,vec2test,new AMDiS::L2Diff<double>);
      BOOST_CHECK_MESSAGE( diff < 1.e-8 , "KD-Tree: L2-diff = "<<diff );
//       used = false;
//       Parameters::get("USE_KD_TREE",used);
//       BOOST_CHECK( used );
  #endif
      Parameters::set("backgroundMesh->enabled",notEnabled);
      Parameters::set("KD-Tree->enabled",notEnabled);
197

198
199
200
201
      start_time= microsec_clock::local_time();
      interpol_coords(vec,vec2);
      td = microsec_clock::local_time()-start_time;
      std::cout<<"interpol_coords (AMDiS) ... "<<(td.total_milliseconds()/1000.0)<<" sec\n";
202

203
204
205
206
207
208
      diff = integrate_Vec2(vec2,vec2test,new AMDiS::L2Diff<double>);
      BOOST_CHECK_MESSAGE( diff < 1.e-8 , "AMDiS: L2-diff = "<<diff );
//       used = false;
//       Parameters::get("USE_STANDARD",used);
//       BOOST_CHECK( used );
    }
209

210
211
212
213
  protected:
    const FiniteElemSpace *feSpace;
    const FiniteElemSpace *feSpace2;
    Box* box;
214

215
216
217
218
219
220
221
222
    int dim;
    bool boxCreated;
    bool boxFilled;
  };

} // end namespace amdis_tests

#endif