Преглед изворни кода

Fixed positioning bug in octree. Looks good now.

master
Trevor Irons пре 8 година
родитељ
комит
25f37979be
3 измењених фајлова са 64 додато и 16 уклоњено
  1. 1
    1
      examples/KernelV0.cpp
  2. 8
    0
      include/KernelV0.h
  3. 55
    15
      src/KernelV0.cpp

+ 1
- 1
examples/KernelV0.cpp Прегледај датотеку

@@ -30,7 +30,7 @@ int main() {
30 30
 		earth->SetLayerThickness( (VectorXr(1) << 10).finished() );
31 31
 
32 32
     // Transmitter loops
33
-    auto Tx1 = CircularLoop(60, 15, 50, 50);
33
+    auto Tx1 = CircularLoop(60, 15, 100, 100);
34 34
     auto Tx2 = CircularLoop(60, 15, 55, 50);
35 35
     //auto Tx1 = CircularLoop(60, 15, 0, 0); // was 60
36 36
 

+ 8
- 0
include/KernelV0.h Прегледај датотеку

@@ -29,6 +29,7 @@
29 29
 #include "vtkHyperOctree.h"
30 30
 #include "vtkHyperOctreeCursor.h"
31 31
 #include "vtkXMLHyperOctreeWriter.h"
32
+#include "vtkDoubleArray.h"
32 33
 #endif
33 34
 
34 35
 namespace Lemma {
@@ -185,16 +186,23 @@ namespace Lemma {
185 186
          */
186 187
         bool EvaluateKids2(  const Vector3r& size, const int& level, const Vector3r& cpos,
187 188
                             const Complex& parentVal, vtkHyperOctree* octree, vtkHyperOctreeCursor* curse );
189
+
190
+        void GetPosition( vtkHyperOctreeCursor* Cursor, Real* p );
188 191
         #endif
189 192
 
190 193
         // ====================  DATA MEMBERS  =========================
191 194
 
192 195
         Complex                                   SUM;
193 196
 
197
+        Real                                      VOLSUM;
198
+
194 199
         Real                                      tol=1e-3;
195 200
 
196 201
         int                                       nleaves;
197 202
 
203
+        Vector3r   Size;
204
+        Vector3r   Origin;
205
+
198 206
         std::shared_ptr< LayeredEarthEM >         SigmaModel = nullptr;
199 207
 
200 208
         std::map< std::string , std::shared_ptr< PolygonalWireAntenna > >  TxRx;

+ 55
- 15
src/KernelV0.cpp Прегледај датотеку

@@ -118,7 +118,7 @@ namespace Lemma {
118 118
                 // TODO query for method, altough with flat antennae, this is fastest
119 119
                 EMEarths.back()->SetHankelTransformMethod(ANDERSON801);
120 120
         }
121
-        IntegrateOnOctreeGrid( 1e-7, vtkOutput );
121
+        IntegrateOnOctreeGrid( 1e-1, vtkOutput );
122 122
 
123 123
     }
124 124
 
@@ -129,15 +129,17 @@ namespace Lemma {
129 129
     void KernelV0::IntegrateOnOctreeGrid( const Real& tolerance, bool vtkOutput) {
130 130
 
131 131
         this->tol = tolerance;
132
-        Vector3r                Size;
133
-            Size << 100,100,100;
134
-        Vector3r                Origin;
132
+        //Vector3r                Size;
133
+            Size << 200,200,100;
134
+        //Vector3r                Origin;
135 135
             Origin << 0,0,0;
136
-        Vector3r                cpos;
137
-            cpos << 50,50,50;
136
+        Vector3r                cpos;  // centre position
137
+            //cpos << 100,100,50;
138
+            cpos = (Size-Origin).array() / 2.;
138 139
         int                     maxlevel;
139 140
 
140 141
         SUM = 0;
142
+        VOLSUM = 0;
141 143
         nleaves = 0;
142 144
         if (!vtkOutput) {
143 145
             EvaluateKids( Size, 0, cpos, 1e6 );
@@ -150,12 +152,32 @@ namespace Lemma {
150 152
             vtkHyperOctreeCursor* curse = oct->NewCellCursor();
151 153
                 curse->ToRoot();
152 154
             EvaluateKids2( Size, 0, cpos, 1e6, oct, curse );
155
+
156
+            // Fill in leaf data
157
+            vtkDoubleArray* kr = vtkDoubleArray::New();
158
+                kr->SetNumberOfComponents(1);
159
+                kr->SetName("Re($K_0$)");
160
+                kr->SetNumberOfTuples( oct->GetNumberOfLeaves() );
161
+            vtkDoubleArray* ki = vtkDoubleArray::New();
162
+                ki->SetNumberOfComponents(1);
163
+                ki->SetName("Im($K_0$)");
164
+                ki->SetNumberOfTuples( oct->GetNumberOfLeaves() );
165
+            for (auto leaf : LeafDict) {
166
+                kr->InsertTuple1( leaf.first, std::real(leaf.second) );
167
+                ki->InsertTuple1( leaf.first, std::imag(leaf.second) );
168
+            }
169
+            oct->GetLeafData()->AddArray(kr);
170
+            oct->GetLeafData()->AddArray(ki);
171
+
153 172
             auto write = vtkXMLHyperOctreeWriter::New();
154 173
                 //write.SetDataModeToAscii()
155 174
                 write->SetInputData(oct);
156 175
                 write->SetFileName("octree.vto");
157 176
                 write->Write();
158 177
                 write->Delete();
178
+
179
+            kr->Delete();
180
+            ki->Delete();
159 181
             curse->Delete();
160 182
             oct->Delete();
161 183
         #else
@@ -163,8 +185,9 @@ namespace Lemma {
163 185
         #endif
164 186
 
165 187
         }
166
-        std::cout << "SUM\t" << SUM << "\t" << 100*100*100 << "\t" << SUM - Complex(100.*100.*100.) <<  std::endl;
188
+        std::cout << "\nVOLSUM=" << VOLSUM << "\tActual=" <<  Size(0)*Size(1)*Size(2) << "\tDifference=" << VOLSUM - (Size(0)*Size(1)*Size(2)) <<  std::endl;
167 189
         std::cout << "nleaves\t" << nleaves << std::endl;
190
+        std::cout << "KSUM\t" << SUM << std::endl;
168 191
 
169 192
     }
170 193
 
@@ -174,6 +197,7 @@ namespace Lemma {
174 197
     //--------------------------------------------------------------------------------------
175 198
     Complex KernelV0::f( const Vector3r& r, const Real& volume, const Vector3cr& Bt ) {
176 199
         //std::cout << volume*Bt.norm() << std::endl;
200
+        //return Complex(volume*Bt.norm());
177 201
         return Complex(volume*Bt.norm());
178 202
         //return Complex(volume);
179 203
     }
@@ -187,9 +211,10 @@ namespace Lemma {
187 211
 
188 212
         // Next level step, interested in one level below
189 213
         // bitshift requires one extra, faster than, and equivalent to std::pow(2, level+1)
190
-        Vector3r step = size.array() / (Real)(1 << (level+2) );
214
+        Vector3r step  = size.array() / (Real)(1 << (level+1) );
215
+        Vector3r step2 = size.array() / (Real)(1 << (level+2) );
191 216
 
192
-        Real vol = step(0)*step(1)*step(2);     // volume of each child
217
+        Real vol = (step2(0)*step2(1)*step2(2));     // volume of each child
193 218
 
194 219
         Vector3r pos =  cpos - step/2.;
195 220
         Eigen::Matrix<Real, 8, 3> posadd = (Eigen::Matrix<Real, 8, 3>() <<
@@ -227,13 +252,14 @@ namespace Lemma {
227 252
 
228 253
         Complex ksum = kvals.sum();     // Kernel sum
229 254
         // Evaluate whether or not furthur splitting is needed
230
-        if ( std::abs(ksum - parentVal) > tol || level < 5 ) {
255
+        if ( std::abs(ksum - parentVal) > tol || level < 2 ) {
231 256
             for (int ichild=0; ichild<8; ++ichild) {
232 257
                 Vector3r cp = pos; // Eigen complains about combining these
233 258
                 cp += posadd.row(ichild);
234 259
                 bool isleaf = EvaluateKids( size, level+1, cp, kvals(ichild) );
235 260
                 if (isleaf) {      // Include result in final integral
236 261
                     SUM += ksum;
262
+                    VOLSUM += 8.*vol;
237 263
                     nleaves += 1;
238 264
                 }
239 265
             }
@@ -251,14 +277,15 @@ namespace Lemma {
251 277
     bool KernelV0::EvaluateKids2( const Vector3r& size, const int& level, const Vector3r& cpos,
252 278
         const Complex& parentVal, vtkHyperOctree* oct, vtkHyperOctreeCursor* curse) {
253 279
 
254
-        std::cout << "\rlevel " << level << "\t" << nleaves;
255
-        std::cout.flush();
280
+        //std::cout << "\rlevel " << level << "\t" << nleaves;
281
+        //std::cout.flush();
256 282
 
257 283
         // Next level step, interested in one level below
258 284
         // bitshift requires one extra, faster than, and equivalent to std::pow(2, level+1)
259
-        Vector3r step = size.array() / (Real)(1 << (level+2) );
285
+        Vector3r step  = size.array() / (Real)(1 << (level+1) );
286
+        Vector3r step2 = size.array() / (Real)(1 << (level+2) );
260 287
 
261
-        Real vol = step(0)*step(1)*step(2);     // volume of each child
288
+        Real vol = (step2(0)*step2(1)*step2(2));     // volume of each child
262 289
 
263 290
         Vector3r pos =  cpos - step/2.;
264 291
         Eigen::Matrix<Real, 8, 3> posadd = (Eigen::Matrix<Real, 8, 3>() <<
@@ -295,16 +322,20 @@ namespace Lemma {
295 322
 
296 323
         Complex ksum = kvals.sum();     // Kernel sum
297 324
         // Evaluate whether or not furthur splitting is needed
298
-        if ( std::abs(ksum - parentVal) > tol || level < 3 ) {
325
+        if ( std::abs(ksum - parentVal) > tol || level < 2 ) {
299 326
             oct->SubdivideLeaf(curse);
300 327
             for (int ichild=0; ichild<8; ++ichild) {
301 328
                 curse->ToChild(ichild);
302 329
                 Vector3r cp = pos; // Eigen complains about combining these
303 330
                 cp += posadd.row(ichild);
331
+                //Real p[3];
332
+                //GetPosition(curse, p);
333
+                //std::cout << cp[0] << "\t" << p[0] << "\t" << cp[1] << "\t" << p[1] << "\t" << cp[2] << "\t" << p[2] << "\t" <<  vol<< std::endl;
304 334
                 bool isleaf = EvaluateKids2( size, level+1, cp, kvals(ichild), oct, curse );
305 335
                 if (isleaf) {  // Include result in final integral
306 336
                     LeafDict[curse->GetLeafId()] = kvals(ichild);       // VTK
307 337
                     SUM += ksum;
338
+                    VOLSUM += 8*vol;
308 339
                     nleaves += 1;
309 340
                 }
310 341
                 curse->ToParent();
@@ -313,6 +344,15 @@ namespace Lemma {
313 344
         }
314 345
         return true;       // leaf
315 346
     }
347
+
348
+    void KernelV0::GetPosition( vtkHyperOctreeCursor* Cursor, Real* p ) {
349
+        Real ratio=1.0/(1<<(Cursor->GetCurrentLevel()));
350
+        //step  = ((Size).array() / std::pow(2.,Cursor->GetCurrentLevel()));
351
+        p[0]=(Cursor->GetIndex(0)+.5)*ratio*this->Size[0]+this->Origin[0] ;//+ .5*step[0];
352
+        p[1]=(Cursor->GetIndex(1)+.5)*ratio*this->Size[1]+this->Origin[1] ;//+ .5*step[1];
353
+        p[2]=(Cursor->GetIndex(2)+.5)*ratio*this->Size[2]+this->Origin[2] ;//+ .5*step[2];
354
+    }
355
+
316 356
     #endif
317 357
 
318 358
 } // ----  end of namespace Lemma  ----

Loading…
Откажи
Сачувај