Kaynağa Gözat

Appears to be working with Dirichlet (non-homogeneous) conditions

iss2
Trevor Irons 8 yıl önce
ebeveyn
işleme
d0984ebe8d

+ 4
- 1
examples/CMakeLists.txt Dosyayı Görüntüle

@@ -16,12 +16,15 @@ 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( VTKGsphere VTKGsphere.cpp  )
20
+target_link_libraries( VTKGsphere  "lemmacore" "fem4ellipticpde")
21
+
19 22
 add_executable( ResampleWithDataset ResampleWithDataset.cpp  )
20 23
 target_link_libraries( ResampleWithDataset  "lemmacore" "fem4ellipticpde")
21 24
 
22 25
 #INSTALL_TARGETS( "${CMAKE_INSTALL_PREFIX}/share/FEM4EllipticPDE/"
23 26
 INSTALL_TARGETS( "/share/FEM4EllipticPDE/"
24
-	FEM4EllipticPDE_bhmag FEM4EllipticPDE merge VTKDC VTKEdgeG VTKEdgeGsphere ResampleWithDataset
27
+	FEM4EllipticPDE_bhmag FEM4EllipticPDE merge VTKDC VTKEdgeG VTKGsphere VTKEdgeGsphere ResampleWithDataset
25 28
 )
26 29
 
27 30
 install( DIRECTORY "borehole"

+ 164
- 0
examples/VTKGsphere.cpp Dosyayı Görüntüle

@@ -0,0 +1,164 @@
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      08/07/2014 04:16:25 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
+#include <vtkUnstructuredGrid.h>
21
+
22
+#include <vtkUnstructuredGridReader.h>
23
+#include <vtkUnstructuredGridWriter.h>
24
+
25
+#include <vtkGenericDataObjectReader.h>
26
+
27
+#include <vtkXMLUnstructuredGridReader.h>
28
+#include <vtkXMLUnstructuredGridWriter.h>
29
+#include <vtkDoubleArray.h>
30
+#include <vtkPointData.h>
31
+#include <vtkCellData.h>
32
+#include <vtkCell.h>
33
+#include <vtkCellCenters.h>
34
+#include <cmath>
35
+#include <Eigen/Core>
36
+
37
+const double PI = 4.0*atan(1.0);
38
+
39
+int main(int argc, char**argv) {
40
+
41
+    std::cout << "Mesh processing routine\n";
42
+    if (argc<4) {
43
+        std::cout << "usage:\n" << "./utVTKEdge  inMesh.vtu  <radius> <problemType>  outG.vtu" << std::endl;
44
+        exit(EXIT_SUCCESS);
45
+    }
46
+
47
+    vtkUnstructuredGrid* uGrid = vtkUnstructuredGrid::New();
48
+
49
+    std::string fn = argv[1];
50
+    if(fn.substr(fn.find_last_of(".") + 1) == "vtk") {
51
+        vtkGenericDataObjectReader* Reader = vtkGenericDataObjectReader::New();
52
+            Reader->SetFileName(argv[1]);
53
+            Reader->Update();
54
+        if(Reader->IsFileUnstructuredGrid()) {
55
+            std::cout << "Found Unstructured grid legacy file" << std::endl;
56
+            uGrid = Reader->GetUnstructuredGridOutput();
57
+        } else {
58
+            std::cerr << "Unknown legacy format";
59
+            exit(EXIT_FAILURE);
60
+        }
61
+
62
+    } else {
63
+
64
+        vtkXMLUnstructuredGridReader* Reader = vtkXMLUnstructuredGridReader::New();
65
+            std::cout << "Reading" << argv[1] << std::endl;
66
+            Reader->SetFileName(argv[1]);
67
+            Reader->Update();
68
+            uGrid = Reader->GetOutput();
69
+    }
70
+
71
+
72
+        int nc = uGrid->GetNumberOfCells()  ;
73
+        int nn = uGrid->GetNumberOfPoints()  ;
74
+
75
+    std::cout << "Processing grid with nodes=" << nn << "\t cells=" << nc << "\n";
76
+
77
+    // Input magnet size TODO get from file or .geo file even?
78
+    double R =  atof(argv[2]); //.25;          // radius of magnet
79
+    double eps = 1e-4;       // epsilon for on the point
80
+    // Pol = double[3];
81
+
82
+    // Declare new array for the data
83
+    vtkDoubleArray* G = vtkDoubleArray::New();
84
+        G->SetNumberOfComponents(1);
85
+        G->SetNumberOfTuples(nc);
86
+        G->SetName("G");
87
+
88
+    vtkDoubleArray* phi = vtkDoubleArray::New();
89
+        phi->SetNumberOfComponents(1);
90
+        phi->SetNumberOfTuples(nn);
91
+        phi->SetName("analytic_phi");
92
+
93
+    // Set point data
94
+    double point[3];
95
+    Eigen::Vector3d M; M << 0,0,1;
96
+    for (int in=0; in<nn; ++in) {
97
+        uGrid->GetPoint(in, &point[0]);
98
+        //std::cout << point[0] << "\t" <<point[1] << "\t" << point[2] << std::endl;
99
+        double raddist = sqrt( point[0]*point[0] + point[1]*point[1] + point[2]*point[2] );
100
+
101
+        //double rho = sqrt( point[1]*point[1] + point[2]*point[2] );
102
+        // Calculate RHS
103
+
104
+        // Insert analytic phi part
105
+        /* magnetics problem p. 198 Jackson */
106
+        if (std::string(argv[3]) == "magnet") {
107
+            if (raddist < R) {
108
+                phi->InsertTuple1( in, (1./3.)*point[2] );
109
+            } else {
110
+                phi->InsertTuple1( in, 0);
111
+                double costheta = point[2]/raddist ;
112
+                //phi->InsertTuple1( in, -(1./3.)*(R*R*R) * ( costheta / (rho*rho) )  );
113
+                phi->InsertTuple1( in, (1./3.) * (R*R*R) * (costheta / (raddist*raddist))  );
114
+            }
115
+        } else if (std::string(argv[3]) == "gravity") {
116
+            double mass = 4./3. * PI * (R*R*R); // volume * density (1)
117
+            if (raddist < R) {
118
+                phi->InsertTuple1( in, mass * (( 3*(R*R) - raddist*raddist )/(2*(R*R*R))) ); // (1./3.)*point[2] );
119
+                //phi->InsertTuple1( in,  (2*PI/3)*(3*R*R-raddist*raddist)  ); // (1./3.)*point[2] );
120
+            } else {
121
+                //phi->InsertTuple1( in, 0);
122
+                //double costheta = point[2]/raddist ;
123
+                //phi->InsertTuple1( in, -(1./3.)*(R*R*R) * ( costheta / (rho*rho) )  );
124
+                phi->InsertTuple1( in, mass/raddist );
125
+            }
126
+        }
127
+    }
128
+
129
+    vtkCellCenters* cellCentersFilter = vtkCellCenters::New();
130
+    cellCentersFilter->SetInputData( uGrid );
131
+    cellCentersFilter->VertexCellsOn();
132
+    cellCentersFilter->Update();
133
+
134
+    // Set Cell Data
135
+    for (int ic=0; ic<nc; ++ic) {
136
+        //uGrid->GetCell(ic)->GetParametricCenter( &point[0] );
137
+        cellCentersFilter->GetOutput()->GetPoint(ic, &point[0]);
138
+        double raddist = sqrt( point[0]*point[0] + point[1]*point[1] + point[2]*point[2] );
139
+        //std::cout << "point " << point[0] << "\t" << point[1] << "\t" << point[2] << std::endl;
140
+        if ( std::string(argv[3]) == "gravity") {
141
+            if ( raddist < R + eps) {
142
+                G->InsertTuple1( ic, 1 );
143
+            } else {
144
+                G->InsertTuple1( ic, 0 );
145
+            }
146
+        }
147
+
148
+    }
149
+
150
+    // Add new data
151
+    uGrid->GetPointData()->AddArray( phi );
152
+    uGrid->GetCellData()->AddArray( G );
153
+
154
+    // Write out new file
155
+    vtkXMLUnstructuredGridWriter* Writer = vtkXMLUnstructuredGridWriter::New();
156
+        //Writer->SetInputConnection(Reader->GetOutputPort());
157
+        Writer->SetInputData( uGrid );
158
+        Writer->SetFileName( argv[4] );
159
+        Writer->Write();
160
+
161
+    //Reader->Delete();
162
+
163
+
164
+}

+ 4
- 4
examples/borehole/sphere.geo Dosyayı Görüntüle

@@ -7,11 +7,11 @@
7 7
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 8
  */
9 9
 
10
-radius = 2.25;     // Radius of the damn thing
11
-lc = radius/4;     //  0.25;   // Target element size
10
+radius = 4.25;     // Radius of the damn thing
11
+lc = radius/5;     //  0.25;   // Target element size
12 12
 
13 13
 // Total Solution Space
14
-Box = 3*radius; // The down side of potential
14
+Box = 5*radius; // The down side of potential
15 15
 X0 = -Box;
16 16
 X1 =  Box;
17 17
 Y0 = -Box;
@@ -19,7 +19,7 @@ Y1 =  Box;
19 19
 Z0 = -Box;
20 20
 Z1 =  Box;
21 21
 
22
-cellSize=radius/32; ///10;
22
+cellSize=radius/10; ///10;
23 23
 dd = 0 ; //  1e-5; //cellSize; // .01;
24 24
 pio2=Pi/2;
25 25
 

+ 1
- 1
examples/borehole/sphere.sh Dosyayı Görüntüle

@@ -2,7 +2,7 @@
2 2
 gmsh  -3 -format vtk -o sphere.vtk  sphere.geo 
3 3
 gmsh  -2 -format stl -o sphereBox.stl  sphereBox.geo 
4 4
 ../ResampleWithDataset  sphere.vtk  sphereBox.stl  MergedSphere.vtu 
5
-../VTKEdgeGsphere MergedSphere.vtu   2.25  gravity  sphereGrav.vtu
5
+../VTKGsphere MergedSphere.vtu   4.25  gravity  sphereGrav.vtu
6 6
 ../FEM4EllipticPDE_bhmag  sphereGrav.vtu  sphereGrav.vtu   sphereOutGrav.vtu 
7 7
 
8 8
 #paraview --data=sphereOutGrav.vtu 

+ 2
- 2
examples/borehole/sphereBox.geo Dosyayı Görüntüle

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

+ 1
- 1
src/FEM4EllipticPDE.cpp Dosyayı Görüntüle

@@ -436,7 +436,7 @@ namespace Lemma {
436 436
                 if (vtkGrid->GetPointData()->GetScalars("HomogeneousDirichlet")->GetTuple(ID[ii])[0]) {
437 437
                     g(ID[ii]) += vtkGrid->GetPointData()->GetScalars("analytic_phi")->GetTuple(ID[ii])[0];
438 438
                 } else {
439
-                    g(ID[ii]) += (3.0*V)*(vtkGrid->GetPointData()->GetScalars("G")->GetTuple(ID[ii])[0]); // Why 3.0??
439
+                    g(ID[ii]) += (PI*V)*(vtkGrid->GetCellData()->GetScalars("G")->GetTuple(ic)[0]); // Why 3.0??
440 440
                 }
441 441
                 //if (std::abs(C(ii,3)-13.5) > 1e-5) {
442 442
                 //    g(ID[ii]) -= G[ii]*(V)*sigma_bar;

Loading…
İptal
Kaydet