Przeglądaj źródła

Adding Gilbert Strang approach to Dirichlet conditions.

iss2
Trevor Irons 8 lat temu
rodzic
commit
45facaf345

+ 3
- 3
examples/borehole/sphere.geo Wyświetl plik

@@ -8,10 +8,10 @@
8 8
  */
9 9
 
10 10
 radius = 2.25;     // Radius of the damn thing
11
-lc = radius/3;     //  0.25;   // Target element size
11
+lc = radius/4;     //  0.25;   // Target element size
12 12
 
13 13
 // Total Solution Space
14
-Box = 6*radius; // The down side of potential
14
+Box = 3*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/3; ///10;
22
+cellSize=radius/32; ///10;
23 23
 dd = 0 ; //  1e-5; //cellSize; // .01;
24 24
 pio2=Pi/2;
25 25
 

+ 2
- 2
examples/borehole/sphereBox.geo Wyświetl plik

@@ -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 = 2*radius;   //  0.25;   // Target element size
14
+lc = radius;   //  0.25;   // Target element size
15 15
 
16 16
 // Total Solution Space
17
-Box = 6*radius; // The down side of potential
17
+Box = 3*radius; // The down side of potential
18 18
 X0 = -Box;
19 19
 X1 =  Box;
20 20
 Y0 = -Box;

+ 29
- 19
src/FEM4EllipticPDE.cpp Wyświetl plik

@@ -221,8 +221,8 @@ namespace Lemma {
221 221
 
222 222
         //#ifdef CGSOLVE
223 223
         //Eigen::ConjugateGradient<Eigen::SparseMatrix<Real, Eigen::Lower >  Eigen::DiagonalPreconditioner > cg;
224
-        Eigen::ConjugateGradient< Eigen::SparseMatrix<Real>  > cg(A);
225
-        //Eigen::BiCGSTAB<Eigen::SparseMatrix<Real> > cg(A);
224
+        //Eigen::ConjugateGradient< Eigen::SparseMatrix<Real>  > cg(A);
225
+        Eigen::BiCGSTAB<Eigen::SparseMatrix<Real> > cg(A);
226 226
         //cg.setMaxIterations(3000);
227 227
         //cg.setTolerance(1e-28);
228 228
         VectorXr u = cg.solve(g);
@@ -340,21 +340,24 @@ namespace Lemma {
340 340
 
341 341
 
342 342
             for (int ii=0; ii<4; ++ii) {
343
-                for (int jj=0; jj<4; ++jj) {
344
-                    /* homogeneous Dirichlet boundary */
345
-                    if (jj==ii && C(ii,3)==13.5) {
346
-                    //Real bb = vtkGrid->GetPointData()->GetScalars("HomogeneousDirichlet")->GetTuple(ID[ii])[0];
347
-                    //if (jj==ii && ((bb-1.)<1e-8) ) {
348
-                        // Apply Homogeneous Dirichlet Boundary conditions
349
-                        Real bb = vtkGrid->GetPointData()->GetScalars("HomogeneousDirichlet")->GetTuple(ID[ii])[0];
350
-                        Real bdry = (1./(BndryH*BndryH))*BndrySigma*bb; // + sum;
351
-                        //Real bdry = GradPhi.col(ii).tail<3>().dot(GradPhi.col(ii).tail<3>())*BndrySigma*bb; // + sum;
352
-                        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 ) );
353
-                        //coeffs.push_back( Eigen::Triplet<Real> ( ID[ii], ID[jj], 1));
354
-                        //break;
355
-                    } else {
343
+                int bbi = vtkGrid->GetPointData()->GetScalars("HomogeneousDirichlet")->GetTuple(ID[ii])[0];
344
+                if (bbi) {
345
+                    coeffs.push_back( Eigen::Triplet<Real> ( ID[ii], ID[ii], 1));
346
+                } else {
347
+                    for (int jj=0; jj<4; ++jj) {
348
+                        /* homogeneous Dirichlet boundary */
349
+                        //if (jj==ii && C(ii,3)==13.5) {
350
+                        //if (jj==ii && ((bb-1.)<1e-8) ) {
351
+                            // Apply Homogeneous Dirichlet Boundary conditions
352
+                        //    Real bb = vtkGrid->GetPointData()->GetScalars("HomogeneousDirichlet")->GetTuple(ID[ii])[0];
353
+                        //    Real bdry = (1./(BndryH*BndryH))*BndrySigma*bb; // + sum;
354
+                            //Real bdry = GradPhi.col(ii).tail<3>().dot(GradPhi.col(ii).tail<3>())*BndrySigma*bb; // + sum;
355
+                        //    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 ) );
356
+                            //coeffs.push_back( Eigen::Triplet<Real> ( ID[ii], ID[jj], 1));
357
+                            //break;
358
+                        //} else {
356 359
                         coeffs.push_back( Eigen::Triplet<Real> ( ID[ii], ID[jj],        GradPhi.col(ii).tail<3>().dot(GradPhi.col(jj).tail<3>() ) * V * sigma_bar ) );
357
-                    }
360
+                        //}
358 361
                     /* */
359 362
                     /* Inhomogeneous Dirichlet */
360 363
                     //coeffs.push_back( Eigen::Triplet<Real> ( ID[ii], ID[jj], GradPhi.col(ii).tail<3>().dot(GradPhi.col(jj).tail<3>())*V*sigma_bar ));
@@ -362,6 +365,7 @@ namespace Lemma {
362 365
                     //coeffs.push_back( Eigen::Triplet<Real> ( ID[ii], ID[jj], GradPhi.col(ii).tail<3>().dot(GradPhi.col(jj).tail<3>() ) * V * sigma_bar ) );
363 366
                 }
364 367
             }
368
+            }
365 369
             //std::cout <<  "\r" << (int)(1e2*((float)(ic) / (float)(vtkGrid->GetNumberOfCells()))) << std::flush ;
366 370
         }
367 371
         A.setFromTriplets(coeffs.begin(), coeffs.end());
@@ -409,6 +413,7 @@ namespace Lemma {
409 413
             }
410 414
             */
411 415
 
416
+            /*
412 417
             VectorXr W = VectorXr::Zero(4);
413 418
             for (int ii=0; ii<4; ++ii) {
414 419
                 W[ii] = vtkGrid->GetPointData()->GetScalars("HomogeneousDirichlet")->GetTuple(ID[ii])[0] *
@@ -419,6 +424,7 @@ namespace Lemma {
419 424
             //auto G = GradPhi.block<3,4>(1,0).transpose()*GradPhi.block<3,4>(1,0)*W;
420 425
             VectorXr G = GradPhi.block<3,4>(1,0).transpose()*GradPhi.block<3,4>(1,0)*W;
421 426
             Real  sigma_bar(1.);
427
+            */
422 428
 
423 429
             for (int ii=0; ii<4; ++ii) {
424 430
             //     avg += vtkGrid->GetPointData()->GetScalars()->GetTuple(ID[ii])[0];
@@ -427,10 +433,14 @@ namespace Lemma {
427 433
             //TODO this seems wrong!
428 434
             //avg /= 4.;
429 435
                 // TODO test code remove
430
-                g(ID[ii]) += V/4*(vtkGrid->GetPointData()->GetScalars("G")->GetTuple(ID[ii])[0])  ;
431
-                if (std::abs(C(ii,3)-13.5) > 1e-5) {
432
-                    g(ID[ii]) -= G[ii]*(V/3.)*sigma_bar;
436
+                if (vtkGrid->GetPointData()->GetScalars("HomogeneousDirichlet")->GetTuple(ID[ii])[0]) {
437
+                    g(ID[ii]) += vtkGrid->GetPointData()->GetScalars("analytic_phi")->GetTuple(ID[ii])[0];
438
+                } else {
439
+                    g(ID[ii]) += (3.0*V)*(vtkGrid->GetPointData()->GetScalars("G")->GetTuple(ID[ii])[0]); // Why 3.0??
433 440
                 }
441
+                //if (std::abs(C(ii,3)-13.5) > 1e-5) {
442
+                //    g(ID[ii]) -= G[ii]*(V)*sigma_bar;
443
+                //}
434 444
                 //g(ID[ii]) +=  V/4*avg;
435 445
                   //g(ID[ii]) +=  6.67 *(V/4.) * avg;
436 446
             }

Ładowanie…
Anuluj
Zapisz