Browse Source

Exmple for Andy and Boxin

iss2
Trevor Irons 8 years ago
parent
commit
ac9f4b272e

+ 2724
- 0
examples/borehole/boundarySphere.pvsm
File diff suppressed because it is too large
View File


+ 3
- 3
examples/borehole/sphere.geo View File

25
 lc = radius;   //  0.25;   // Target element size
25
 lc = radius;   //  0.25;   // Target element size
26
 
26
 
27
 // Total Solution Space
27
 // Total Solution Space
28
-Box = 10*radius; // The down side of potential
28
+Box = 30*radius; // The down side of potential
29
 X0 = -Box;
29
 X0 = -Box;
30
 X1 =  Box;
30
 X1 =  Box;
31
 Y0 = -Box;
31
 Y0 = -Box;
131
 ///////////////////////////////////////////////
131
 ///////////////////////////////////////////////
132
 // Attractor Field
132
 // Attractor Field
133
 
133
 
134
-//Field[1] = Attractor;
135
-//Field[1].NodesList = {p}; //0, p0+1, p0+2, p0+3, p0+4, p, p+1, p+2, p+3, p+4};
134
+Field[1] = Attractor;
135
+Field[1].NodesList = {p}; //0, p0+1, p0+2, p0+3, p0+4, p, p+1, p+2, p+3, p+4};
136
 
136
 
137
 //Field[2] = MathEval;
137
 //Field[2] = MathEval;
138
 //Field[2].F = Sprintf("(2.25 - F1)^2 + %g", cellSize*10 );  // WORKS
138
 //Field[2].F = Sprintf("(2.25 - F1)^2 + %g", cellSize*10 );  // WORKS

+ 9
- 6
examples/borehole/sphere.sh View File

1
-
1
+#!/usr/bin/env bash
2
 gmsh  -3 -format vtk -o sphere.vtk  sphere.geo 
2
 gmsh  -3 -format vtk -o sphere.vtk  sphere.geo 
3
 gmsh  -2 -format stl -o sphereBox.stl  sphereBox.geo 
3
 gmsh  -2 -format stl -o sphereBox.stl  sphereBox.geo 
4
+paraview --state=boundarySphere.pvsm 
4
 
5
 
6
+#IMPORTANT! 
7
+#   Select ResampleWithDataset1
8
+#	-->File -> SaveData -> MergedSphere.vtu 
5
 
9
 
10
+# Set up problem 
6
 
11
 
7
-#gmsh -3 -format vtk -o sphere.vtk  sphere.geo
8
-#../utVTKEdgeGsphere sphere.vtk .25 magnet  sphereG.vtu
9
-#../utFEM4EllipticPDE_bhmag  sphereG.vtu  sphereG.vtu   sphereOut.vtu 
10
 
12
 
11
 # Gravity problem
13
 # Gravity problem
12
-../utVTKEdgeGsphere sphere.vtk .25 gravity  sphereGrav.vtu
13
-../utFEM4EllipticPDE_bhmag  sphereGrav.vtu  sphereGrav.vtu   sphereOutGrav.vtu 
14
+#../VTKEdgeGsphere MergedSphere.vtu   2.25  gravity  sphereGrav.vtu
15
+#../FEM4EllipticPDE_bhmag  sphereGrav.vtu  sphereGrav.vtu   sphereOutGrav.vtu 
16
+
14
 #paraview --state=sliceSphere.pvsm
17
 #paraview --state=sliceSphere.pvsm
15
 
18
 
16
 
19
 

+ 32
- 0
examples/borehole/sphere2.sh View File

1
+#!/usr/bin/env bash
2
+#gmsh  -3 -format vtk -o sphere.vtk  sphere.geo 
3
+#gmsh  -2 -format stl -o sphereBox.stl  sphereBox.geo 
4
+#paraview --state=boundarySphere.pvsm 
5
+
6
+#IMPORTANT! 
7
+#   Select ResampleWithDataset1
8
+#	-->File -> SaveData -> MergedSphere.vtu 
9
+
10
+# Set up problem 
11
+# Gravity problem
12
+../VTKEdgeGsphere MergedSphere.vtu   2.25  gravity  sphereGrav.vtu
13
+../FEM4EllipticPDE_bhmag  sphereGrav.vtu  sphereGrav.vtu   sphereOutGrav.vtu 
14
+
15
+#paraview --state=sliceSphere.pvsm
16
+
17
+
18
+# --data=sphereOut.vtu
19
+
20
+# even finer meshing
21
+# radius = 4, u = \pm .9              analytic = \pm 1.33
22
+
23
+# Finer meshing
24
+# radius = 5, u = \pm 1.65            analytic = \pm 1.67
25
+# radius = 4, u = \pm 1.09            analytic = \pm 1.33
26
+
27
+# radius = 5, u = \pm 2.5             analytic = \pm 1.67
28
+# radius = 4, u = \pm 1.66            analytic = \pm 1.33
29
+# radius = 3, u= \pm .926 -.985       analytic = \pm 1
30
+# radius = 2, u = \pm.42              analytic = \pm .667
31
+# for radius=1,  u = \pm .111         analytic = \pm .333 
32
+# for radius=.5, u = \pm .0477 -.0462 analytic = \pm .167

+ 1
- 1
examples/borehole/sphereBox.geo View File

14
 lc = radius;   //  0.25;   // Target element size
14
 lc = radius;   //  0.25;   // Target element size
15
 
15
 
16
 // Total Solution Space
16
 // Total Solution Space
17
-Box = 10*radius; // The down side of potential
17
+Box = 30*radius; // The down side of potential
18
 X0 = -Box;
18
 X0 = -Box;
19
 X1 =  Box;
19
 X1 =  Box;
20
 Y0 = -Box;
20
 Y0 = -Box;

+ 95
- 75
src/FEM4EllipticPDE.cpp View File

156
         for (int ic=0; ic < vtkGrid->GetNumberOfCells(); ++ic) {
156
         for (int ic=0; ic < vtkGrid->GetNumberOfCells(); ++ic) {
157
 
157
 
158
 //             Eigen::Matrix<Real, 4, 4> C = Eigen::Matrix<Real, 4, 4>::Zero() ;
158
 //             Eigen::Matrix<Real, 4, 4> C = Eigen::Matrix<Real, 4, 4>::Zero() ;
159
-//             for (int ip=0; ip<4; ++ip) {
160
-//                 double* pts =  vtkGrid->GetCell(ic)->GetPoints()->GetPoint(ip); //[ipc] ;
161
-//                 C(ip, 0) = 1;
162
-//                 C(ip, 1) =  pts[0];
163
-//                 C(ip, 2) =  pts[1];
164
-//                 C(ip, 3) =  pts[2];
159
+//             for (int ii=0; ii<4; ++ii) {
160
+//                 double* pts =  vtkGrid->GetCell(ic)->GetPoints()->GetPoint(ii); //[ipc] ;
161
+//                 C(ii, 0) = 1;
162
+//                 C(ii, 1) =  pts[0];
163
+//                 C(ii, 2) =  pts[1];
164
+//                 C(ii, 3) =  pts[2];
165
 //             }
165
 //             }
166
 
166
 
167
 //             Real V = (1./6.) * C.determinant();          // volume of tetrahedra
167
 //             Real V = (1./6.) * C.determinant();          // volume of tetrahedra
215
         //Eigen::BiCGSTAB<Eigen::SparseMatrix<Real> > cg(A);
215
         //Eigen::BiCGSTAB<Eigen::SparseMatrix<Real> > cg(A);
216
         cg.setMaxIterations(3000);
216
         cg.setMaxIterations(3000);
217
 
217
 
218
+        std::cout <<"          rows\tcols\n";
218
         std::cout << "A: "  << A.rows() << "\t" << A.cols() << std::endl;
219
         std::cout << "A: "  << A.rows() << "\t" << A.cols() << std::endl;
219
         std::cout << "g: "  << g.rows() << "\t" << g.cols() << std::endl;
220
         std::cout << "g: "  << g.rows() << "\t" << g.cols() << std::endl;
220
 
221
 
257
         // Build stiffness matrix (A)
258
         // Build stiffness matrix (A)
258
         std::cout << "Building Stiffness Matrix (A) " << std::endl;
259
         std::cout << "Building Stiffness Matrix (A) " << std::endl;
259
         std::cout << "\tMesh has " << vtkGrid->GetNumberOfCells()  << " cells "  << std::endl;
260
         std::cout << "\tMesh has " << vtkGrid->GetNumberOfCells()  << " cells "  << std::endl;
261
+        std::cout << "\tMesh has " << vtkGrid->GetNumberOfPoints()  << " points "  << std::endl;
260
 
262
 
261
   	    //Eigen::SparseMatrix<Real>
263
   	    //Eigen::SparseMatrix<Real>
262
         A.resize(vtkGrid->GetNumberOfPoints(), vtkGrid->GetNumberOfPoints());
264
         A.resize(vtkGrid->GetNumberOfPoints(), vtkGrid->GetNumberOfPoints());
287
 
289
 
288
             // construct coordinate matrix C
290
             // construct coordinate matrix C
289
             Eigen::Matrix<Real, 4, 4> C = Eigen::Matrix<Real, 4, 4>::Zero() ;
291
             Eigen::Matrix<Real, 4, 4> C = Eigen::Matrix<Real, 4, 4>::Zero() ;
290
-            for (int ip=0; ip<4; ++ip) {
291
-                double* pts =  vtkGrid->GetCell(ic)->GetPoints()->GetPoint(ip); //[ipc] ;
292
-                C(ip, 0) = 1;
293
-                C(ip, 1) =  pts[0] ;
294
-                C(ip, 2) =  pts[1] ;
295
-                C(ip, 3) =  pts[2] ;
292
+            for (int ii=0; ii<4; ++ii) {
293
+                double* pts =  vtkGrid->GetCell(ic)->GetPoints()->GetPoint(ii); //[ipc] ;
294
+                C(ii, 0) = 1;
295
+                C(ii, 1) =  pts[0] ;
296
+                C(ii, 2) =  pts[1] ;
297
+                C(ii, 3) =  pts[2] ;
296
             }
298
             }
297
 
299
 
298
             Eigen::Matrix<Real, 4, 4> Phi = C.inverse(); // nabla \phi
300
             Eigen::Matrix<Real, 4, 4> Phi = C.inverse(); // nabla \phi
304
                 ID[1] = Ids->GetId(1);
306
                 ID[1] = Ids->GetId(1);
305
                 ID[2] = Ids->GetId(2);
307
                 ID[2] = Ids->GetId(2);
306
                 ID[3] = Ids->GetId(3);
308
                 ID[3] = Ids->GetId(3);
307
-            Real sum(0), sigma_bar(0);
309
+
310
+            Real sigma_bar(0);
308
             if (GCell) {
311
             if (GCell) {
309
                 sigma_bar = vtkGrid->GetCellData()->GetScalars("G")->GetTuple1(ic);
312
                 sigma_bar = vtkGrid->GetCellData()->GetScalars("G")->GetTuple1(ic);
310
             } else {
313
             } else {
314
                 sigma_bar += vtkGrid->GetPointData()->GetScalars("G")->GetTuple1(ID[3]);
317
                 sigma_bar += vtkGrid->GetPointData()->GetScalars("G")->GetTuple1(ID[3]);
315
                 sigma_bar /= 4.;
318
                 sigma_bar /= 4.;
316
             }
319
             }
320
+            sigma_bar = 1.;
317
 
321
 
318
-            for (int ip=0; ip<4; ++ip) {
319
-                for (int ip2=0; ip2<4; ++ip2) {
320
-                    if (ip2 == ip) {
322
+            for (int ii=0; ii<4; ++ii) {
323
+                for (int jj=0; jj<4; ++jj) {
324
+                    if (jj == ii) {
321
                         // I apply boundary to Stiffness matrix, it's common to take the other approach and apply to the load vector and then
325
                         // I apply boundary to Stiffness matrix, it's common to take the other approach and apply to the load vector and then
322
                         //   solve for the boundaries? Is one better? This seems to work, which is nice.
326
                         //   solve for the boundaries? Is one better? This seems to work, which is nice.
323
-                        //Real bdry = V*(1./(BndryH*BndryH))*BndrySigma*bndryCnt( ID[ip] ); // + sum;
324
-                        Real bb = vtkGrid->GetPointData()->GetScalars("vtkValidPointMask")->GetTuple(ID[ip])[0];
327
+                        //Real bdry = V*(1./(BndryH*BndryH))*BndrySigma*bndryCnt( ID[ii] ); // + sum;
328
+                        Real bb = vtkGrid->GetPointData()->GetScalars("vtkValidPointMask")->GetTuple(ID[ii])[0];
325
                         Real bdry = V*(1./(BndryH*BndryH))*BndrySigma*bb; // + sum;
329
                         Real bdry = V*(1./(BndryH*BndryH))*BndrySigma*bb; // + sum;
326
-                        coeffs.push_back( Eigen::Triplet<Real> ( ID[ip], ID[ip2], bdry +  Phi.col(ip).tail<3>().dot(Phi.col(ip2).tail<3>() ) * V * sigma_bar ) );
330
+                        coeffs.push_back( Eigen::Triplet<Real> ( ID[ii], ID[jj], bdry +  Phi.col(ii).tail<3>().dot(Phi.col(jj).tail<3>() ) * V * sigma_bar ) );
327
                     } else {
331
                     } else {
328
-                        coeffs.push_back( Eigen::Triplet<Real> ( ID[ip], ID[ip2],         Phi.col(ip).tail<3>().dot(Phi.col(ip2).tail<3>() ) * V * sigma_bar ) );
332
+                        coeffs.push_back( Eigen::Triplet<Real> ( ID[ii], ID[jj],         Phi.col(ii).tail<3>().dot(Phi.col(jj).tail<3>() ) * V * sigma_bar ) );
329
                     }
333
                     }
330
                     // Stiffness matrix no longer contains boundary conditions...
334
                     // Stiffness matrix no longer contains boundary conditions...
331
-                    //coeffs.push_back( Eigen::Triplet<Real> ( ID[ip], ID[ip2],         Phi.col(ip).tail<3>().dot(Phi.col(ip2).tail<3>() ) * V * sigma_bar ) );
335
+                    //coeffs.push_back( Eigen::Triplet<Real> ( ID[ii], ID[jj], Phi.col(ii).tail<3>().dot(Phi.col(jj).tail<3>() ) * V * sigma_bar ) );
332
                 }
336
                 }
333
             }
337
             }
334
             std::cout <<  "\r" << (int)(1e2*((float)(ic) / (float)(vtkGrid->GetNumberOfCells()))) << std::flush ;
338
             std::cout <<  "\r" << (int)(1e2*((float)(ic) / (float)(vtkGrid->GetNumberOfCells()))) << std::flush ;
335
         }
339
         }
336
         A.setFromTriplets(coeffs.begin(), coeffs.end());
340
         A.setFromTriplets(coeffs.begin(), coeffs.end());
341
+        //std::cout << "A\n" << A << std::endl;
337
     }
342
     }
338
 
343
 
339
     void FEM4EllipticPDE::SetupPotential() {
344
     void FEM4EllipticPDE::SetupPotential() {
342
 	    // Load vector g
347
 	    // Load vector g
343
         std::cout << "\nBuilding load vector (g)" << std::endl;
348
         std::cout << "\nBuilding load vector (g)" << std::endl;
344
         g = VectorXr::Zero(vtkGrid->GetNumberOfPoints());
349
         g = VectorXr::Zero(vtkGrid->GetNumberOfPoints());
345
-        std::cout << "made g with "  << vtkGrid->GetNumberOfPoints() << " cells" << std::endl;
350
+        std::cout << "made g with "  << vtkGrid->GetNumberOfPoints() << " points" << std::endl;
346
 
351
 
347
         for (int ic=0; ic < vtkGrid->GetNumberOfCells(); ++ic) {
352
         for (int ic=0; ic < vtkGrid->GetNumberOfCells(); ++ic) {
348
 
353
 
349
-                Eigen::Matrix<Real, 4, 4> C = Eigen::Matrix<Real, 4, 4>::Zero() ;
350
-                for (int ip=0; ip<4; ++ip) {
351
-                    double* pts =  vtkGrid->GetCell(ic)->GetPoints()->GetPoint(ip); //[ipc] ;
352
-                    C(ip, 0) = 1;
353
-                    C(ip, 1) =  pts[0];
354
-                    C(ip, 2) =  pts[1];
355
-                    C(ip, 3) =  pts[2];
356
-                }
354
+            Eigen::Matrix<Real, 4, 4> C = Eigen::Matrix<Real, 4, 4>::Zero() ;
355
+            for (int ii=0; ii<4; ++ii) {
356
+                double* pts =  vtkGrid->GetCell(ic)->GetPoints()->GetPoint(ii); //[ipc] ;
357
+                C(ii, 0) = 1;
358
+                C(ii, 1) =  pts[0];
359
+                C(ii, 2) =  pts[1];
360
+                C(ii, 3) =  pts[2];
361
+            }
357
 
362
 
358
-                Real V = (1./6.) * C.determinant();          // volume of tetrahedra
359
-                //Real V = C.determinant();          // volume of tetrahedra
363
+            Real V = (1./6.) * C.determinant();          // volume of tetrahedra
364
+
365
+            vtkIdList* Ids = vtkGrid->GetCell(ic)->GetPointIds();
366
+            int ID[4];
367
+                ID[0] = Ids->GetId(0);
368
+                ID[1] = Ids->GetId(1);
369
+                ID[2] = Ids->GetId(2);
370
+                ID[3] = Ids->GetId(3);
360
 
371
 
361
-                vtkIdList* Ids = vtkGrid->GetCell(ic)->GetPointIds();
362
-                int ID[4];
363
-                    ID[0] = Ids->GetId(0);
364
-                    ID[1] = Ids->GetId(1);
365
-                    ID[2] = Ids->GetId(2);
366
-                    ID[3] = Ids->GetId(3);
367
 
372
 
368
-            for (int ip=0; ip<4; ++ip) {
369
-                 g(ID[ip]) +=  (V/4.) *  ( vtkGrid->GetPointData()->GetScalars()->GetTuple(ID[ip])[0] )  ;
370
-                 //if ( std::abs(vtkGrid->GetPointData()->GetScalars()->GetTuple(ID[ip])[0]) > 1e-3 )
373
+            Real avg(0);
374
+            Real GG[4];
375
+            for (int ii=0; ii<4; ++ii) {
376
+                GG[ii] = vtkGrid->GetPointData()->GetScalars("G")->GetTuple(ID[ii])[0];
377
+                //avg /= 4.;
378
+            }
379
+            if ( std::abs( (GG[0]+GG[1]+GG[2]+GG[3])/4. - GG[0])  < 1e-5) {
380
+                avg = GG[0];
371
             }
381
             }
372
 
382
 
383
+            for (int ii=0; ii<4; ++ii) {
384
+            //     avg += vtkGrid->GetPointData()->GetScalars()->GetTuple(ID[ii])[0];
385
+            //     //if ( std::abs(vtkGrid->GetPointData()->GetScalars()->GetTuple(ID[ii])[0]) > 1e-3 )
386
+            //}
387
+            //TODO this seems wrong!
388
+            //avg /= 4.;
389
+                //g(ID[ii]) +=  (V/4.) * ( vtkGrid->GetPointData()->GetScalars("G")->GetTuple(ID[ii])[0] )  ;
390
+                g(ID[ii]) +=  (V/4.) * avg;
391
+            }
373
         }
392
         }
374
 
393
 
375
     }
394
     }
392
         // Expensive search for whether or not point is on boundary. O(n) cost.
411
         // Expensive search for whether or not point is on boundary. O(n) cost.
393
         VectorXi bndryCnt = VectorXi::Zero(vtkGrid->GetNumberOfPoints());
412
         VectorXi bndryCnt = VectorXi::Zero(vtkGrid->GetNumberOfPoints());
394
         for (int isp=0; isp < Surface->GetOutput()->GetNumberOfPoints(); ++isp) {
413
         for (int isp=0; isp < Surface->GetOutput()->GetNumberOfPoints(); ++isp) {
395
-            //double* pts =  vtkGrid->GetCell(ic)->GetPoints()->GetPoint(ip); //[ipc] ;
414
+            //double* pts =  vtkGrid->GetCell(ic)->GetPoints()->GetPoint(ii); //[ipc] ;
396
             // x \in -14.5 to 14.5
415
             // x \in -14.5 to 14.5
397
             // y \in 0 to 30
416
             // y \in 0 to 30
398
             bndryCnt(BdryIds->GetTuple1(isp)) += 1;
417
             bndryCnt(BdryIds->GetTuple1(isp)) += 1;
402
         // Build stiffness matrix (A)
421
         // Build stiffness matrix (A)
403
         std::cout << "Building Stiffness Matrix (A) " << std::endl;
422
         std::cout << "Building Stiffness Matrix (A) " << std::endl;
404
         std::cout << "\tMesh has " << vtkGrid->GetNumberOfCells()  << " cells "  << std::endl;
423
         std::cout << "\tMesh has " << vtkGrid->GetNumberOfCells()  << " cells "  << std::endl;
424
+        std::cout << "\tMesh has " << vtkGrid->GetNumberOfPoints()  << " points "  << std::endl;
405
 
425
 
406
 
426
 
407
   	    Eigen::SparseMatrix<Real> A(vtkGrid->GetNumberOfPoints(), vtkGrid->GetNumberOfPoints());
427
   	    Eigen::SparseMatrix<Real> A(vtkGrid->GetNumberOfPoints(), vtkGrid->GetNumberOfPoints());
420
 
440
 
421
             // construct coordinate matrix C
441
             // construct coordinate matrix C
422
             Eigen::Matrix<Real, 4, 4> C = Eigen::Matrix<Real, 4, 4>::Zero() ;
442
             Eigen::Matrix<Real, 4, 4> C = Eigen::Matrix<Real, 4, 4>::Zero() ;
423
-            for (int ip=0; ip<4; ++ip) {
424
-                double* pts =  vtkGrid->GetCell(ic)->GetPoints()->GetPoint(ip); //[ipc] ;
425
-                C(ip, 0) = 1;
426
-                C(ip, 1) =  pts[0] ;
427
-                C(ip, 2) =  pts[1] ;
428
-                C(ip, 3) =  pts[2] ;
443
+            for (int ii=0; ii<4; ++ii) {
444
+                double* pts =  vtkGrid->GetCell(ic)->GetPoints()->GetPoint(ii); //[ipc] ;
445
+                C(ii, 0) = 1;
446
+                C(ii, 1) =  pts[0] ;
447
+                C(ii, 2) =  pts[1] ;
448
+                C(ii, 3) =  pts[2] ;
429
             }
449
             }
430
 
450
 
431
-            Eigen::Matrix<Real, 4, 4> Phi = C.inverse(); // nabla \phi
451
+            Eigen::Matrix<Real, 4, 4> GradPhi = C.inverse(); // nabla \phi
432
             Real V = (1./6.) * C.determinant();          // volume of tetrahedra
452
             Real V = (1./6.) * C.determinant();          // volume of tetrahedra
433
 
453
 
434
             vtkIdList* Ids = vtkGrid->GetCell(ic)->GetPointIds();
454
             vtkIdList* Ids = vtkGrid->GetCell(ic)->GetPointIds();
440
             Real sum(0);
460
             Real sum(0);
441
             Real sigma_bar = vtkGrid->GetCellData()->GetScalars()->GetTuple1(ic);
461
             Real sigma_bar = vtkGrid->GetCellData()->GetScalars()->GetTuple1(ic);
442
 
462
 
443
-            for (int ip=0; ip<4; ++ip) {
444
-                for (int ip2=0; ip2<4; ++ip2) {
445
-                    if (ip2 == ip) {
463
+            for (int ii=0; ii<4; ++ii) {
464
+                for (int jj=0; jj<4; ++jj) {
465
+                    if (jj == ii) {
446
                         // I apply boundary to Stiffness matrix, it's common to take the other approach and apply to the load vector and then
466
                         // I apply boundary to Stiffness matrix, it's common to take the other approach and apply to the load vector and then
447
                         //   solve for the boundaries? Is one better? This seems to work, which is nice.
467
                         //   solve for the boundaries? Is one better? This seems to work, which is nice.
448
-                        //Real bdry = V*(1./(BndryH*BndryH))*BndrySigma*bndryCnt( ID[ip] ); // + sum;
449
-                        Real bb = vtkGrid->GetPointData()->GetScalars("vtkValidPointMask")->GetTuple(ID[ip])[0];
468
+                        //Real bdry = V*(1./(BndryH*BndryH))*BndrySigma*bndryCnt( ID[ii] ); // + sum;
469
+                        Real bb = vtkGrid->GetPointData()->GetScalars("vtkValidPointMask")->GetTuple(ID[ii])[0];
450
                         //std::cout << "bb " << bb  << std::endl;
470
                         //std::cout << "bb " << bb  << std::endl;
451
                         Real bdry = V*(1./(BndryH*BndryH))*BndrySigma*bb; // + sum;
471
                         Real bdry = V*(1./(BndryH*BndryH))*BndrySigma*bb; // + sum;
452
-                        coeffs.push_back( Eigen::Triplet<Real> ( ID[ip], ID[ip2], bdry +  Phi.col(ip).tail<3>().dot(Phi.col(ip2).tail<3>() ) * V * sigma_bar ) );
472
+                        coeffs.push_back( Eigen::Triplet<Real> ( ID[ii], ID[jj], bdry +  GradPhi.col(ii).tail<3>().dot(GradPhi.col(jj).tail<3>() ) * V * sigma_bar ) );
453
                     } else {
473
                     } else {
454
-                        coeffs.push_back( Eigen::Triplet<Real> ( ID[ip], ID[ip2],         Phi.col(ip).tail<3>().dot(Phi.col(ip2).tail<3>() ) * V * sigma_bar ) );
474
+                        coeffs.push_back( Eigen::Triplet<Real> ( ID[ii], ID[jj],         GradPhi.col(ii).tail<3>().dot(GradPhi.col(jj).tail<3>() ) * V * sigma_bar ) );
455
                     }
475
                     }
456
                     // Stiffness matrix no longer contains boundary conditions...
476
                     // Stiffness matrix no longer contains boundary conditions...
457
-                    //coeffs.push_back( Eigen::Triplet<Real> ( ID[ip], ID[ip2],         Phi.col(ip).tail<3>().dot(Phi.col(ip2).tail<3>() ) * V * sigma_bar ) );
477
+                    //coeffs.push_back( Eigen::Triplet<Real> ( ID[ii], ID[jj],         GradPhi.col(ii).tail<3>().dot(GradPhi.col(jj).tail<3>() ) * V * sigma_bar ) );
458
                 }
478
                 }
459
             }
479
             }
460
             std::cout <<  "\r" << (int)(1e2*((float)(ic) / (float)(vtkGrid->GetNumberOfCells()))) << std::flush ;
480
             std::cout <<  "\r" << (int)(1e2*((float)(ic) / (float)(vtkGrid->GetNumberOfCells()))) << std::flush ;
482
             for (int ic=0; ic < vtkGrid->GetNumberOfCells(); ++ic) {
502
             for (int ic=0; ic < vtkGrid->GetNumberOfCells(); ++ic) {
483
 
503
 
484
                 Eigen::Matrix<Real, 4, 4> C = Eigen::Matrix<Real, 4, 4>::Zero() ;
504
                 Eigen::Matrix<Real, 4, 4> C = Eigen::Matrix<Real, 4, 4>::Zero() ;
485
-                for (int ip=0; ip<4; ++ip) {
486
-                    double* pts =  vtkGrid->GetCell(ic)->GetPoints()->GetPoint(ip); //[ipc] ;
487
-                    C(ip, 0) = 1;
488
-                    C(ip, 1) =  pts[0];
489
-                    C(ip, 2) =  pts[1];
490
-                    C(ip, 3) =  pts[2];
505
+                for (int ii=0; ii<4; ++ii) {
506
+                    double* pts =  vtkGrid->GetCell(ic)->GetPoints()->GetPoint(ii); //[ipc] ;
507
+                    C(ii, 0) = 1;
508
+                    C(ii, 1) =  pts[0];
509
+                    C(ii, 2) =  pts[1];
510
+                    C(ii, 3) =  pts[2];
491
                 }
511
                 }
492
 
512
 
493
                 Real V = (1./6.) * C.determinant();          // volume of tetrahedra
513
                 Real V = (1./6.) * C.determinant();          // volume of tetrahedra
506
                 /*
526
                 /*
507
                 if (!pe) {
527
                 if (!pe) {
508
                     if (std::abs(pt[0]) < .2 && std::abs(pt[1]-15) < .2 && pt[2] < 3.25 ) {
528
                     if (std::abs(pt[0]) < .2 && std::abs(pt[1]-15) < .2 && pt[2] < 3.25 ) {
509
-                        sum = 1; //vtkGrid->GetPointData()->GetScalars()->GetTuple(ID[ip])[0];
529
+                        sum = 1; //vtkGrid->GetPointData()->GetScalars()->GetTuple(ID[ii])[0];
510
                         pe = true;
530
                         pe = true;
511
                     }
531
                     }
512
                 }*/
532
                 }*/
520
 /*
540
 /*
521
                 if (!ne) {
541
                 if (!ne) {
522
                     if (std::abs(pt[0]+1.) < .2 && std::abs(pt[1]-15) < .2 && pt[2] < 3.25 ) {
542
                     if (std::abs(pt[0]+1.) < .2 && std::abs(pt[1]-15) < .2 && pt[2] < 3.25 ) {
523
-                        sum = -1; //vtkGrid->GetPointData()->GetScalars()->GetTuple(ID[ip])[0];
543
+                        sum = -1; //vtkGrid->GetPointData()->GetScalars()->GetTuple(ID[ii])[0];
524
                         std::cout << "Negative Electroce\n";
544
                         std::cout << "Negative Electroce\n";
525
                         ne = true;
545
                         ne = true;
526
                     }
546
                     }
527
                 }
547
                 }
528
 */
548
 */
529
-                //for (int ip=0; ip<4; ++ip) {
530
-                    //g(ID[ip]) +=  (V/4.) *  ( vtkGrid->GetPointData()->GetScalars()->GetTuple(ID[ip])[0] )  ;
531
-                    //if ( std::abs(vtkGrid->GetPointData()->GetScalars()->GetTuple(ID[ip])[0]) > 1e-3 )
549
+                //for (int ii=0; ii<4; ++ii) {
550
+                    //g(ID[ii]) +=  (V/4.) *  ( vtkGrid->GetPointData()->GetScalars()->GetTuple(ID[ii])[0] )  ;
551
+                    //if ( std::abs(vtkGrid->GetPointData()->GetScalars()->GetTuple(ID[ii])[0]) > 1e-3 )
532
                 //}
552
                 //}
533
                 // TODO check Load Vector...
553
                 // TODO check Load Vector...
534
                 g(ID[0]) = sum; //(V/4.) * sum; // Why 3, Why!!!?
554
                 g(ID[0]) = sum; //(V/4.) * sum; // Why 3, Why!!!?
545
 
565
 
546
                     for(vtkIdType i = 0; i < connectedVertices->GetNumberOfIds(); ++i) {
566
                     for(vtkIdType i = 0; i < connectedVertices->GetNumberOfIds(); ++i) {
547
 
567
 
548
-                        int ip = connectedVertices->GetId(i);
549
-                        vtkGrid->GetPoint(ip, r1);
550
-                        double g1 = vtkGrid->GetPointData()->GetScalars()->GetTuple(ip)[0] ;
568
+                        int ii = connectedVertices->GetId(i);
569
+                        vtkGrid->GetPoint(ii, r1);
570
+                        double g1 = vtkGrid->GetPointData()->GetScalars()->GetTuple(ii)[0] ;
551
                         //g(ic) += g0*dist(r0,r1); //CompositeSimpsons2(g0, r0, r1, 8);
571
                         //g(ic) += g0*dist(r0,r1); //CompositeSimpsons2(g0, r0, r1, 8);
552
                         if ( std::abs(g1) > 1e-3 ) {
572
                         if ( std::abs(g1) > 1e-3 ) {
553
                             g(ic) += CompositeSimpsons2(g1, g0, r1, r0, 1000);
573
                             g(ic) += CompositeSimpsons2(g1, g0, r1, r0, 1000);
580
                 //g(ic) += vtkGrid->GetPointData()->GetScalars()->GetTuple1(ic);// FunctionValue(r0[0], r0[1], r0[2]) ;
600
                 //g(ic) += vtkGrid->GetPointData()->GetScalars()->GetTuple1(ic);// FunctionValue(r0[0], r0[1], r0[2]) ;
581
                 /*
601
                 /*
582
                 for(vtkIdType i = 0; i < connectedVertices->GetNumberOfIds(); ++i) {
602
                 for(vtkIdType i = 0; i < connectedVertices->GetNumberOfIds(); ++i) {
583
-                    int ip = connectedVertices->GetId(i);
584
-                    vtkGrid->GetPoint(ip, r1);
603
+                    int ii = connectedVertices->GetId(i);
604
+                    vtkGrid->GetPoint(ii, r1);
585
                     g(ic) += CompositeSimpsons2(vtkG, r0, r1, 8); // vtkG->FunctionValue(r0[0], r0[1], r0[2]) ;
605
                     g(ic) += CompositeSimpsons2(vtkG, r0, r1, 8); // vtkG->FunctionValue(r0[0], r0[1], r0[2]) ;
586
                 }
606
                 }
587
                 */
607
                 */
598
                 //#pragma omp parallel for reduction(+:sum)
618
                 //#pragma omp parallel for reduction(+:sum)
599
                 //#endif
619
                 //#endif
600
                 for(vtkIdType i = 0; i < connectedVertices->GetNumberOfIds(); ++i) {
620
                 for(vtkIdType i = 0; i < connectedVertices->GetNumberOfIds(); ++i) {
601
-                    int ip = connectedVertices->GetId(i);
602
-                    vtkGrid->GetPoint(ip, r1);
621
+                    int ii = connectedVertices->GetId(i);
622
+                    vtkGrid->GetPoint(ii, r1);
603
                     g(ic) += CompositeSimpsons2(gFcn3, r0, r1, 8); // vtkG->FunctionValue(r0[0], r0[1], r0[2]) ;
623
                     g(ic) += CompositeSimpsons2(gFcn3, r0, r1, 8); // vtkG->FunctionValue(r0[0], r0[1], r0[2]) ;
604
                     //sum += CompositeSimpsons2(gFcn3, r0, r1, 8); // vtkG->FunctionValue(r0[0], r0[1], r0[2]) ;
624
                     //sum += CompositeSimpsons2(gFcn3, r0, r1, 8); // vtkG->FunctionValue(r0[0], r0[1], r0[2]) ;
605
                 }
625
                 }

Loading…
Cancel
Save