Bläddra i källkod

Added preprocessing routine.

iss2
Trevor Irons 8 år sedan
förälder
incheckning
38dbd833c7

+ 4
- 1
examples/CMakeLists.txt Visa fil

@@ -16,9 +16,12 @@ target_link_libraries( VTKEdgeG  "lemmacore" "fem4ellipticpde")
16 16
 add_executable( VTKEdgeGsphere VTKEdgeGsphere.cpp  )
17 17
 target_link_libraries( VTKEdgeGsphere  "lemmacore" "fem4ellipticpde")
18 18
 
19
+add_executable( ResampleWithDataset ResampleWithDataset.cpp  )
20
+target_link_libraries( ResampleWithDataset  "lemmacore" "fem4ellipticpde")
21
+
19 22
 #INSTALL_TARGETS( "${CMAKE_INSTALL_PREFIX}/share/FEM4EllipticPDE/"
20 23
 INSTALL_TARGETS( "/share/FEM4EllipticPDE/"
21
-	FEM4EllipticPDE_bhmag FEM4EllipticPDE merge VTKDC VTKEdgeG VTKEdgeGsphere
24
+	FEM4EllipticPDE_bhmag FEM4EllipticPDE merge VTKDC VTKEdgeG VTKEdgeGsphere ResampleWithDataset
22 25
 )
23 26
 
24 27
 install( DIRECTORY "borehole"

+ 95
- 0
examples/ResampleWithDataset.cpp Visa fil

@@ -0,0 +1,95 @@
1
+/* This file is part of Lemma, a geophysical modelling and inversion API.
2
+ * More information is available at http://lemmasoftware.org
3
+ */
4
+
5
+/* This Source Code Form is subject to the terms of the Mozilla Public
6
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
7
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
+ */
9
+
10
+/**
11
+ * @file
12
+ * @date      01/27/2016 01:24:24 PM
13
+ * @version   $Id$
14
+ * @author    Trevor Irons (ti)
15
+ * @email     tirons@egi.utah.edu
16
+ * @copyright Copyright (c) 2016, University of Utah
17
+ * @copyright Copyright (c) 2016, Trevor Irons & Lemma Software, LLC
18
+ */
19
+
20
+#include <vtkProbeFilter.h>
21
+#include <vtkSTLReader.h>
22
+#include <vtkUnstructuredGrid.h>
23
+#include <vtkUnstructuredGridReader.h>
24
+#include <vtkUnstructuredGridWriter.h>
25
+#include <vtkGenericDataObjectReader.h>
26
+#include <vtkXMLUnstructuredGridReader.h>
27
+#include <vtkXMLUnstructuredGridWriter.h>
28
+#include <vtkDoubleArray.h>
29
+#include <vtkPointData.h>
30
+#include <cmath>
31
+#include <Eigen/Core>
32
+
33
+
34
+int main(int argc, char**argv) {
35
+
36
+
37
+    std::cout << "Mesh processing routine\n";
38
+    if (argc<4) {
39
+        std::cout << "usage:\n" << "./ResampleWithDataset  inMesh.vtu  boundaries.stl  outG.vtu" << std::endl;
40
+        exit(EXIT_SUCCESS);
41
+    }
42
+
43
+    vtkUnstructuredGrid* uGrid = vtkUnstructuredGrid::New();
44
+
45
+    std::string fn = argv[1];
46
+    if(fn.substr(fn.find_last_of(".") + 1) == "vtk") {
47
+        vtkGenericDataObjectReader* Reader = vtkGenericDataObjectReader::New();
48
+            Reader->SetFileName(argv[1]);
49
+            Reader->Update();
50
+        if(Reader->IsFileUnstructuredGrid()) {
51
+            std::cout << "Found Unstructured grid legacy file" << std::endl;
52
+            uGrid = Reader->GetUnstructuredGridOutput();
53
+        } else {
54
+            std::cerr << "Unknown legacy format";
55
+            exit(EXIT_FAILURE);
56
+        }
57
+
58
+    } else {
59
+
60
+        vtkXMLUnstructuredGridReader* Reader = vtkXMLUnstructuredGridReader::New();
61
+            std::cout << "Reading" << argv[1] << std::endl;
62
+            Reader->SetFileName(argv[1]);
63
+            Reader->Update();
64
+            uGrid = Reader->GetOutput();
65
+    }
66
+        int nc = uGrid->GetNumberOfCells()  ;
67
+        int nn = uGrid->GetNumberOfPoints()  ;
68
+
69
+    std::cout << "Processing grid with nodes=" << nn << "\t cells=" << nc << "\n";
70
+
71
+    vtkSTLReader* Stencil = vtkSTLReader::New();
72
+        Stencil->SetFileName(argv[2]);
73
+        Stencil->Update();
74
+
75
+    vtkUnstructuredGrid* output = vtkUnstructuredGrid::New();
76
+
77
+    vtkProbeFilter* Resample = vtkProbeFilter::New();
78
+        //Resample->SetSourceData( uGrid );
79
+        //Resample->SetInputData( Stencil->GetOutput() );
80
+        Resample->SetInputData( uGrid );
81
+        Resample->SetSourceData( Stencil->GetOutput() );
82
+        Resample->SpatialMatchOn();
83
+        Resample->Update();
84
+
85
+    std::cout << *Resample << std::endl;
86
+
87
+    vtkXMLUnstructuredGridWriter* Writer = vtkXMLUnstructuredGridWriter::New();
88
+        //Resample->Probe(uGrid, Stencil->GetOutput(), output);
89
+        Writer->SetInputData( Resample->GetOutput() );
90
+        Writer->SetFileName( argv[3] );
91
+        Writer->Write();
92
+
93
+    //std::cout << *Stencil << std::endl;
94
+
95
+}

+ 1
- 1
examples/VTKEdgeGsphere.cpp Visa fil

@@ -143,7 +143,7 @@ int main(int argc, char**argv) {
143 143
                 phi->InsertTuple1( in, (1./3.) * (R*R*R) * (costheta / (raddist*raddist))  );
144 144
             }
145 145
         } else if (std::string(argv[3]) == "gravity") {
146
-            double mass = 4./3. * PI * (R*R*R);
146
+            double mass = 4./3. * PI * (R*R*R); // volume * density (1)
147 147
             if (raddist < R) {
148 148
                 phi->InsertTuple1( in, mass * ( 3*(R*R) - raddist*raddist )/(2*(R*R*R)) ); // (1./3.)*point[2] );
149 149
             } else {

+ 25
- 26
examples/borehole/sphere.geo Visa fil

@@ -7,25 +7,11 @@
7 7
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 8
  */
9 9
 
10
-/**
11
- * @file
12
- * @date      08/08/2014 12:19:20 PM
13
- * @version   $Id$
14
- * @author    Trevor Irons (ti)
15
- * @email     Trevor.Irons@xri-geo.com
16
- * @copyright Copyright (c) 2014, XRI Geophysics, LLC
17
- * @copyright Copyright (c) 2014, Trevor Irons
18
- */
19
-
20
-
21
-D0 = 10;          // Top of magnet
22
-D1 = 11;          // Bottom of magnet
23 10
 radius = 2.25;     // Radius of the damn thing
24
-
25
-lc = radius;   //  0.25;   // Target element size
11
+lc = radius;     //  0.25;   // Target element size
26 12
 
27 13
 // Total Solution Space
28
-Box = 30*radius; // The down side of potential
14
+Box = 10*radius; // The down side of potential
29 15
 X0 = -Box;
30 16
 X1 =  Box;
31 17
 Y0 = -Box;
@@ -33,7 +19,7 @@ Y1 =  Box;
33 19
 Z0 = -Box;
34 20
 Z1 =  Box;
35 21
 
36
-cellSize=lc; //300;
22
+cellSize=lc/5; ///10;
37 23
 dd = 0 ; //  1e-5; //cellSize; // .01;
38 24
 pio2=Pi/2;
39 25
 
@@ -60,8 +46,6 @@ Plane Surface(125) = {lv+4};
60 46
 //v = newv;
61 47
 v[] = Extrude {0, 0, Z1-Z0} { Surface{125}; };
62 48
 
63
-
64
-
65 49
 // Calculate offset effect
66 50
 theta = Asin(dd/radius);
67 51
 rr = radius * Cos(theta);
@@ -131,13 +115,28 @@ Surface{t6[0]} In Volume{v[1]};
131 115
 ///////////////////////////////////////////////
132 116
 // Attractor Field
133 117
 
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
-
137
-//Field[2] = MathEval;
138
-//Field[2].F = Sprintf("(2.25 - F1)^2 + %g", cellSize*10 );  // WORKS
139
-//Field[2].F = Sprintf("(%g - F1)^2 + %g", radius, 2*cellSize );
140
-//Background Field = 2;
118
+// Field[1] = Attractor;
119
+// Field[1].NodesList = {p}; //0, p0+1, p0+2, p0+3, p0+4, p, p+1, p+2, p+3, p+4};
120
+//
121
+// Field[2] = MathEval;
122
+// Field[2].F = Sprintf("(2.25 - F1)^1.01 + %g", radius/10 );  // WORKS
123
+//
124
+// Field[3] = MathEval;
125
+// Field[3].F = Sprintf("(12.25 - F1)^1.01 + %g", radius/5 );  // WORKS
126
+//
127
+// Field[4] = MathEval;
128
+// Field[4].F = Sprintf("(22.25 - F1)^1.01 + %g", radius );  // WORKS
129
+//
130
+// Field[5] = MathEval;
131
+// Field[5].F = Sprintf("(42.25 - F1)^1.01 + %g", radius*5 );  // WORKS
132
+//
133
+// //Field[2].F = Sprintf("(%g - F1)^2 + %g", radius, 2*cellSize );
134
+// //Background Field = 2;
135
+//
136
+// // Finally, let's use the minimum of all the fields as the background mesh field
137
+// Field[7] = Min;
138
+// Field[7].FieldsList = {2, 3, 4, 5};
139
+// Background Field = 7;
141 140
 
142 141
 // Don't extend the elements sizes from the boundary inside the domain
143 142
 //Mesh.CharacteristicLengthExtendFromBoundary = 0;

+ 8
- 1
examples/borehole/sphere.sh Visa fil

@@ -1,7 +1,14 @@
1 1
 #!/usr/bin/env bash
2 2
 gmsh  -3 -format vtk -o sphere.vtk  sphere.geo 
3 3
 gmsh  -2 -format stl -o sphereBox.stl  sphereBox.geo 
4
-paraview --state=boundarySphere.pvsm 
4
+//paraview --state=boundarySphere.pvsm 
5
+../ResampleWithDataset  sphere.vtk  sphereBox.stl  MergedSphere.vtu 
6
+
7
+
8
+../VTKEdgeGsphere MergedSphere.vtu   2.25  gravity  sphereGrav.vtu
9
+../FEM4EllipticPDE_bhmag  sphereGrav.vtu  sphereGrav.vtu   sphereOutGrav.vtu 
10
+
11
+paraview --state=sliceGravSphere3.pvsm
5 12
 
6 13
 #IMPORTANT! 
7 14
 #   Select ResampleWithDataset1

+ 2
- 2
examples/borehole/sphereBox.geo Visa fil

@@ -11,10 +11,10 @@ D0 = 10;          // Top of magnet
11 11
 D1 = 11;          // Bottom of magnet
12 12
 radius = 2.25;     // Radius of the damn thing
13 13
 
14
-lc = radius;   //  0.25;   // Target element size
14
+lc = 1*radius;   //  0.25;   // Target element size
15 15
 
16 16
 // Total Solution Space
17
-Box = 30*radius; // The down side of potential
17
+Box = 10*radius; // The down side of potential
18 18
 X0 = -Box;
19 19
 X1 =  Box;
20 20
 Y0 = -Box;

+ 12
- 11
src/FEM4EllipticPDE.cpp Visa fil

@@ -297,7 +297,7 @@ namespace Lemma {
297 297
                 C(ii, 3) =  pts[2] ;
298 298
             }
299 299
 
300
-            Eigen::Matrix<Real, 4, 4> Phi = C.inverse(); // nabla \phi
300
+            Eigen::Matrix<Real, 4, 4> GradPhi = C.inverse(); // nabla \phi
301 301
             Real V = (1./6.) * C.determinant();          // volume of tetrahedra
302 302
 
303 303
             vtkIdList* Ids = vtkGrid->GetCell(ic)->GetPointIds();
@@ -322,17 +322,16 @@ namespace Lemma {
322 322
             for (int ii=0; ii<4; ++ii) {
323 323
                 for (int jj=0; jj<4; ++jj) {
324 324
                     if (jj == ii) {
325
-                        // I apply boundary to Stiffness matrix, it's common to take the other approach and apply to the load vector and then
326
-                        //   solve for the boundaries? Is one better? This seems to work, which is nice.
327
-                        //Real bdry = V*(1./(BndryH*BndryH))*BndrySigma*bndryCnt( ID[ii] ); // + sum;
325
+                        // Apply Homogeneous Dirichlet Boundary conditions
328 326
                         Real bb = vtkGrid->GetPointData()->GetScalars("vtkValidPointMask")->GetTuple(ID[ii])[0];
329
-                        Real bdry = V*(1./(BndryH*BndryH))*BndrySigma*bb; // + sum;
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
+                        Real bdry = (1./(BndryH*BndryH))*BndrySigma*bb; // + sum;
328
+                        //Real bdry = GradPhi.col(ii).tail<3>().dot(GradPhi.col(ii).tail<3>())*BndrySigma*bb; // + sum;
329
+                        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 ) );
331 330
                     } else {
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 ) );
331
+                        coeffs.push_back( Eigen::Triplet<Real> ( ID[ii], ID[jj],        GradPhi.col(ii).tail<3>().dot(GradPhi.col(jj).tail<3>() ) * V * sigma_bar ) );
333 332
                     }
334 333
                     // Stiffness matrix no longer contains boundary conditions...
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 ) );
334
+                    //coeffs.push_back( Eigen::Triplet<Real> ( ID[ii], ID[jj], GradPhi.col(ii).tail<3>().dot(GradPhi.col(jj).tail<3>() ) * V * sigma_bar ) );
336 335
                 }
337 336
             }
338 337
             std::cout <<  "\r" << (int)(1e2*((float)(ic) / (float)(vtkGrid->GetNumberOfCells()))) << std::flush ;
@@ -354,7 +353,7 @@ namespace Lemma {
354 353
             Eigen::Matrix<Real, 4, 4> C = Eigen::Matrix<Real, 4, 4>::Zero() ;
355 354
             for (int ii=0; ii<4; ++ii) {
356 355
                 double* pts =  vtkGrid->GetCell(ic)->GetPoints()->GetPoint(ii); //[ipc] ;
357
-                C(ii, 0) = 1;
356
+                C(ii, 0) =  1;
358 357
                 C(ii, 1) =  pts[0];
359 358
                 C(ii, 2) =  pts[1];
360 359
                 C(ii, 3) =  pts[2];
@@ -386,9 +385,11 @@ namespace Lemma {
386 385
             //}
387 386
             //TODO this seems wrong!
388 387
             //avg /= 4.;
389
-                //g(ID[ii]) +=  (V/4.) * ( vtkGrid->GetPointData()->GetScalars("G")->GetTuple(ID[ii])[0] )  ;
390
-                g(ID[ii]) +=  (V/4.) * avg;
388
+                //g(ID[ii]) +=  (V) * ( vtkGrid->GetPointData()->GetScalars("G")->GetTuple(ID[ii])[0] )  ;
389
+                g(ID[ii]) += PI* (V) * avg;
390
+                  //g(ID[ii]) +=  6.67 *(V/4.) * avg;
391 391
             }
392
+            //g(ID[0]) +=  (V/4.) * avg;
392 393
         }
393 394
 
394 395
     }

Laddar…
Avbryt
Spara