RectangularDomain.cpp 24.4 KB
Newer Older
frey_m's avatar
frey_m committed
1 2 3 4
//
// Class RectangularDomain
//   :FIXME: add brief description
//
5
// Copyright (c) 2008,        Yves Ineichen, ETH Zürich,
frey_m's avatar
frey_m committed
6
//               2013 - 2015, Tülin Kaman, Paul Scherrer Institut, Villigen PSI, Switzerland
7
//               2017 - 2020, Paul Scherrer Institut, Villigen PSI, Switzerland
frey_m's avatar
frey_m committed
8 9
// All rights reserved
//
10 11 12 13 14
// Implemented as part of the master thesis
// "A Parallel Multigrid Solver for Beam Dynamics"
// and the paper
// "A fast parallel Poisson solver on irregular domains applied to beam dynamics simulations"
// (https://doi.org/10.1016/j.jcp.2010.02.022)
frey_m's avatar
frey_m committed
15 16 17 18 19 20 21 22 23 24 25
//
// This file is part of OPAL.
//
// OPAL is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// You should have received a copy of the GNU General Public License
// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
//
26
#ifdef HAVE_SAAMG_SOLVER
gsell's avatar
gsell committed
27

kraus's avatar
kraus committed
28
#include "Solvers/RectangularDomain.h"
Christof Metzger-Kraus's avatar
Christof Metzger-Kraus committed
29
#include "Utilities/OpalException.h"
gsell's avatar
gsell committed
30

frey_m's avatar
frey_m committed
31
RectangularDomain::RectangularDomain(double a, double b, Vector_t nr, Vector_t hr)
32
    : IrregularDomain(nr, hr, "CONSTANT")
frey_m's avatar
frey_m committed
33
{
34
    setRangeMin(Vector_t(-a, -b, getMinZ()));
frey_m's avatar
frey_m committed
35
    setRangeMax(Vector_t( a,  b, getMaxZ()));
gsell's avatar
gsell committed
36 37 38
    nxy_m = nr[0] * nr[1];
}

39
void RectangularDomain::compute(Vector_t hr, NDIndex<3> /*localId*/){
gsell's avatar
gsell committed
40
    setHr(hr);
frey_m's avatar
frey_m committed
41
    nxy_m = nr_m[0] * nr_m[1];
gsell's avatar
gsell committed
42 43
}

44
int RectangularDomain::getNumXY(int /*z*/) {
gsell's avatar
gsell committed
45 46 47
    return nxy_m;
}

48 49 50
void RectangularDomain::getBoundaryStencil(int x, int y, int z, StencilValue_t& value,
                                           double &scaleFactor)
{
gsell's avatar
gsell committed
51 52
    //scaleFactor = 1.0;

frey_m's avatar
frey_m committed
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
    //W = -1/hr_m_m[0]*1/hr_m[0];
    //E = -1/hr_m[0]*1/hr_m[0];
    //N = -1/hr_m[1]*1/hr_m[1];
    //S = -1/hr_m[1]*1/hr_m[1];
    //F = -1/hr_m[2]*1/hr_m[2];
    //B = -1/hr_m[2]*1/hr_m[2];
    //C = 2/hr_m[0]*1/hr_m[0] + 2/hr_m[1]*1/hr_m[1] + 2/hr_m[2]*1/hr_m[2];

    scaleFactor  = hr_m[0] * hr_m[1] * hr_m[2];
    value.west   = -hr_m[1] * hr_m[2] / hr_m[0];
    value.east   = -hr_m[1] * hr_m[2] / hr_m[0];
    value.north  = -hr_m[0] * hr_m[2] / hr_m[1];
    value.south  = -hr_m[0] * hr_m[2] / hr_m[1];
    value.front  = -hr_m[0] * hr_m[1] / hr_m[2];
    value.back   = -hr_m[0] * hr_m[1] / hr_m[2];
    value.center = 2 * hr_m[1] * hr_m[2] / hr_m[0] + 2 * hr_m[0] * hr_m[2] / hr_m[1] + 2 * hr_m[0] * hr_m[1] / hr_m[2];
gsell's avatar
gsell committed
69 70

    if(!isInside(x + 1, y, z))
71
        value.east = 0.0; //we are a right boundary point
gsell's avatar
gsell committed
72 73

    if(!isInside(x - 1, y, z))
74
        value.west = 0.0; //we are a left boundary point
gsell's avatar
gsell committed
75 76

    if(!isInside(x, y + 1, z))
77
        value.north = 0.0; //we are a upper boundary point
gsell's avatar
gsell committed
78 79

    if(!isInside(x, y - 1, z))
80
        value.south = 0.0; //we are a lower boundary point
gsell's avatar
gsell committed
81 82 83

    //dirichlet
    if(z == 0)
84
        value.front = 0.0;
frey_m's avatar
frey_m committed
85
    if(z == nr_m[2] - 1)
86
        value.back = 0.0;
gsell's avatar
gsell committed
87

frey_m's avatar
frey_m committed
88
    if(false /*z == 0 || z == nr_m[2]-1*/) {
gsell's avatar
gsell committed
89 90 91 92 93 94

        //case where we are on the Robin BC in Z-direction
        //where we distinguish two cases
        //IFF: this values should not matter because they
        //never make it into the discretization matrix
        if(z == 0)
95
            value.front = 0.0;
gsell's avatar
gsell committed
96
        else
97
            value.back = 0.0;
gsell's avatar
gsell committed
98 99 100

        //add contribution of Robin discretization to center point
        //d the distance between the center of the bunch and the boundary
frey_m's avatar
frey_m committed
101 102 103
        //double cx = (x-(nr_m[0]-1)/2)*hr_m[0];
        //double cy = (y-(nr_m[1]-1)/2)*hr_m[1];
        //double cz = hr_m[2]*(nr_m[2]-1);
gsell's avatar
gsell committed
104
        //double d = sqrt(cx*cx+cy*cy+cz*cz);
frey_m's avatar
frey_m committed
105 106 107 108
        double d = hr_m[2] * (nr_m[2] - 1) / 2;
        //cout << cx << " " << cy << " " << cz << " " << 2/(d*hr_m[2]) << endl;
        value.center += 2 / (d * hr_m[2]);
        //C += 2/((hr_m[2]*(nr_m[2]-1)/2.0) * hr_m[2]);
gsell's avatar
gsell committed
109 110

        //scale all stencil-points in z-plane with 0.5 (Neumann discretization)
111 112 113 114 115 116
        value.west   /= 2.0;
        value.east   /= 2.0;
        value.north  /= 2.0;
        value.south  /= 2.0;
        value.center /= 2.0;
        scaleFactor  *= 0.5;
gsell's avatar
gsell committed
117 118 119 120 121
    }


    //simple check if center value of stencil is positive
#ifdef DEBUG
122
    if(value.center <= 0)
Christof Metzger-Kraus's avatar
Christof Metzger-Kraus committed
123 124
        throw OpalException("RectangularDomain::getBoundaryStencil",
                            "Stencil C is <= 0! This case should never occure!");
gsell's avatar
gsell committed
125 126 127 128
#endif
}

/*
129
void MGPoissonSolver::getNeighbours(const int idx, int& W, int& E, int& S, int& N, int& F, int& B, int& numOutOfDomain)
gsell's avatar
gsell committed
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
{

    int ixy, iz, iy, ix;
    int nx = nr_m[0];
    int ny = nr_m[1];
    int nz = nr_m[2];
    int nxy = nx*ny;
    ixy = idx % nxy;

    ix = ixy % nx;
    iy = (ixy - ix) / nx;
    iz = (idx - ixy) / nxy;
    numOutOfDomain = 0;

    if (iz == 0)
    {F = -1; numOutOfDomain++;}
    else
        F = idx - nxy;
    if (iz == nz - 1)
    {B = -1; numOutOfDomain++;}
    else
        B = idx + nxy;

    if (ix == 0)
    {W = -1; numOutOfDomain++;}
    else
        W = ixy - 1;
    if (ix == nx - 1)
    {E = -1; numOutOfDomain++;}
    else
        E = ixy + 1;

    if (iy == 0)
    {S = -1; numOutOfDomain++;}
    else
        S = ixy - nx;
    if (iy == ny - 1)
    {N = -1; numOutOfDomain++;}
    else
        N = ixy + nx;

    int cor = iz * nxy;
    switch(W) {
        case -1: break;
        default: W += cor;
    }
    switch(E) {
        case -1: break;
        default: E += cor;
    }
    switch(S) {
        case -1: break;
        default: S += cor;
    }
    switch(N) {
        case -1: break;
        default: N += cor;
    }

}

//at the moment this stencil has neumann everywhere except on the z=0 plane (Dirichlet)
//this code is experimental/not-optimized/not-final at the moment
193
inline Epetra_CrsMatrix* MGPoissonSolver::stencil3DOneSidedDirichlet(Vector_t hr)
gsell's avatar
gsell committed
194 195 196 197 198 199 200 201 202 203 204 205 206
{
    Epetra_CrsMatrix* Matrix = new Epetra_CrsMatrix(Copy, *Map,  7);

    Vector_t hr2 = hr*hr;
    double a = 2*(1/hr2[0]+1/hr2[1]+1/hr2[2]);
    double b = -1/hr2[0];
    double d = -1/hr2[1];
    double f = -1/hr2[2];

    int NumMyElements = Map->NumMyElements();
    int* MyGlobalElements = Map->MyGlobalElements();

    int W, E, S, N, F, B, numout;
207 208
    std::vector<double> Values(6);
    std::vector<int> Indices(6);
gsell's avatar
gsell committed
209 210 211

    for (int i = 0 ; i < NumMyElements ; ++i)
    {
212
        getNeighbours(MyGlobalElements[i], W, E, S, N, F, B, numout);
gsell's avatar
gsell committed
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524

        int NumEntries = 0;
        double diag = a;

        if(F != -1) {

            switch(numout) {

                case 3: {
                            if(W == -1) {
                                Indices[NumEntries] = E;
                                Values[NumEntries++] = 0.25*b;
                            }

                            if(E == -1) {
                                Indices[NumEntries] = W;
                                Values[NumEntries++] = 0.25*b;
                            }

                            if(N == -1) {
                                Indices[NumEntries] = S;
                                Values[NumEntries++] = 0.25*d;
                            }

                            if(S == -1) {
                                Indices[NumEntries] = N;
                                Values[NumEntries++] = 0.25*d;
                            }

                            if(B == -1) {
                                Indices[NumEntries] = F;
                                Values[NumEntries++] = 0.25*f;
                            }

                            if(F == -1) {
                                Indices[NumEntries] = B;
                                Values[NumEntries++] = 0.25*f;
                            }

                            diag *= 0.125;

                            if(NumEntries != 3)
                                cout << "ERROR: while calc corners in stencil" << endl;

                            break;

                        }
                case 2: {

                            if(W != -1 && E != -1) {
                                Indices[NumEntries] = W;
                                Values[NumEntries++] = 0.25*b;
                                Indices[NumEntries] = E;
                                Values[NumEntries++] = 0.25*b;
                            }
                            if(E == -1 && W != -1) {
                                Indices[NumEntries] = W;
                                Values[NumEntries++] = 0.5*b;
                            }
                            if(W == -1 && E != -1) {
                                Indices[NumEntries] = E;
                                Values[NumEntries++] = 0.5*b;
                            }


                            if(N != -1 && S != -1) {
                                Indices[NumEntries] = N;
                                Values[NumEntries++] = 0.25*d;
                                Indices[NumEntries] = S;
                                Values[NumEntries++] = 0.25*d;
                            }
                            if(S == -1 && N != -1) {
                                Indices[NumEntries] = N;
                                Values[NumEntries++] = 0.5*d;
                            }
                            if(N == -1 && S != -1) {
                                Indices[NumEntries] = S;
                                Values[NumEntries++] = 0.5*d;
                            }


                            if(B != -1 && F != -1) {
                                Indices[NumEntries] = B;
                                Values[NumEntries++] = 0.25*f;
                                Indices[NumEntries] = F;
                                Values[NumEntries++] = 0.25*f;
                            }
                            if(B == -1 && F != -1) {
                                Indices[NumEntries] = F;
                                Values[NumEntries++] = 0.5*f;
                            }
                            if(F == -1 && B != -1) {
                                Indices[NumEntries] = B;
                                Values[NumEntries++] = 0.5*f;
                            }

                            diag *= 0.25;

                            if(NumEntries != 4)
                                cout << "ERROR: while calc edge stencil elements" << endl;

                            break;
                        }
                case 1: {


                            if(W != -1 && E != -1) {
                                Indices[NumEntries] = W;
                                Values[NumEntries++] = 0.5*b;
                                Indices[NumEntries] = E;
                                Values[NumEntries++] = 0.5*b;
                            }
                            if(E == -1 && W != -1) {
                                Indices[NumEntries] = W;
                                Values[NumEntries++] = b;
                            }
                            if(W == -1 && E != -1) {
                                Indices[NumEntries] = E;
                                Values[NumEntries++] = b;
                            }


                            if(N != -1 && S != -1) {
                                Indices[NumEntries] = S;
                                Values[NumEntries++] = 0.5*d;
                                Indices[NumEntries] = N;
                                Values[NumEntries++] = 0.5*d;
                            }
                            if(S == -1 && N != -1) {
                                Indices[NumEntries] = N;
                                Values[NumEntries++] = d;
                            }
                            if(N == -1 && S != -1) {
                                Indices[NumEntries] = S;
                                Values[NumEntries++] = d;
                            }


                            if(B != -1 && F != -1) {
                                Indices[NumEntries] = F;
                                Values[NumEntries++] = 0.5*f;
                                Indices[NumEntries] = B;
                                Values[NumEntries++] = 0.5*f;
                            }
                            if(B == -1 && F != -1) {
                                Indices[NumEntries] = F;
                                Values[NumEntries++] = f;
                            }
                            if(F == -1 && B != -1) {
                                Indices[NumEntries] = B;
                                Values[NumEntries++] = f;
                            }

                            diag *= 0.5;

                            if(NumEntries != 5)
                                cout << "ERROR: calc surface elements of stencil" << endl;

                            break;
                        }

                case 0: {
                            if(W != -1) {
                                Indices[NumEntries] = W;
                                Values[NumEntries++] = b;
                            } if(E != -1) {
                                Indices[NumEntries] = E;
                                Values[NumEntries++] = b;
                            } if(S != -1) {
                                Indices[NumEntries] = S;
                                Values[NumEntries++] = d;
                            } if(N != -1) {
                                Indices[NumEntries] = N;
                                Values[NumEntries++] = d;
                            } if(F != -1) {
                                Indices[NumEntries] = F;
                                Values[NumEntries++] = f;
                            } if(B != -1) {
                                Indices[NumEntries] = B;
                                Values[NumEntries++] = f;
                            }

                            break;
                        }
                default: {
                             cout << "ERROR CREATING THE STENCIL: points out of domain (" << numout << ") is >3 OR <0" << endl;
                         }
            }
        } else {
            //F == -1 --> this is our dirichlet boundary surface
            switch(numout) {
                case 3: {

                            if(W == -1) {
                                Indices[NumEntries] = E;
                                Values[NumEntries++] = 0.5*b;
                            }

                            if(E == -1) {
                                Indices[NumEntries] = W;
                                Values[NumEntries++] = 0.5*b;
                            }

                            if(N == -1) {
                                Indices[NumEntries] = S;
                                Values[NumEntries++] = 0.5*d;
                            }

                            if(S == -1) {
                                Indices[NumEntries] = N;
                                Values[NumEntries++] = 0.5*d;
                            }

                            Indices[NumEntries] = B;
                            Values[NumEntries++] = 0.25*f;

                            if(NumEntries != 3)
                                cout << "ERROR: calc corner (below) elements of stencil" << endl;

                            diag *= 0.25;
                            break;

                        }
                case 2:{

                           if(W != -1 && E != -1) {
                               Indices[NumEntries] = W;
                               Values[NumEntries++] = 0.5*b;
                               Indices[NumEntries] = E;
                               Values[NumEntries++] = 0.5*b;
                           }
                           if(W == -1 && E != -1) {
                               Indices[NumEntries] = E;
                               Values[NumEntries++] = b;
                           }

                           if(E == -1 && W != -1) {
                               Indices[NumEntries] = W;
                               Values[NumEntries++] = b;
                           }

                           if(N != -1 && S != -1) {
                               Indices[NumEntries] = N;
                               Values[NumEntries++] = 0.5*d;
                               Indices[NumEntries] = S;
                               Values[NumEntries++] = 0.5*d;
                           }
                           if(N == -1 && S != -1) {
                               Indices[NumEntries] = S;
                               Values[NumEntries++] = d;
                           }

                           if(S == -1 && N != -1) {
                               Indices[NumEntries] = N;
                               Values[NumEntries++] = d;
                           }

                           Indices[NumEntries] = B;
                           Values[NumEntries++] = 0.25*f;

                           if(NumEntries != 4)
                               cout << "ERROR: calc edge (below) elements of stencil" << endl;

                           diag *= 0.25;
                           break;

                       }
                case 1:{

                           Indices[NumEntries] = E;
                           Values[NumEntries++] = b;

                           Indices[NumEntries] = W;
                           Values[NumEntries++] = b;

                           Indices[NumEntries] = S;
                           Values[NumEntries++] = d;

                           Indices[NumEntries] = N;
                           Values[NumEntries++] = d;

                           Indices[NumEntries] = B;
                           Values[NumEntries++] = f;

                           if(NumEntries != 5)
                               cout << "ERROR: calc surface (below) elements of stencil: " << NumEntries << endl;

                           break;

                       }
                default: {
                             cout << "error in dirichlet surface!" << endl;
                         }
            }
        }
        // put the off-diagonal entries
        Matrix->InsertGlobalValues(MyGlobalElements[i], NumEntries,
                &Values[0], &Indices[0]);

        // Put in the diagonal entry
        Matrix->InsertGlobalValues(MyGlobalElements[i], 1,
                &diag, MyGlobalElements + i);

    }
    Matrix->FillComplete();
    Matrix->OptimizeStorage();

    return(Matrix);
}

//stencil for longitudinal neumann and transversal dirichlet BC
//this code is experimental/not-optimized/not-final at the moment
525
inline Epetra_CrsMatrix* MGPoissonSolver::stencil3DLongitudinalNeumann(Vector_t hr)
gsell's avatar
gsell committed
526 527 528 529 530 531 532 533 534 535 536 537 538
{
    Epetra_CrsMatrix* Matrix = new Epetra_CrsMatrix(Copy, *Map,  7);

    Vector_t hr2 = hr*hr;
    double a = 2*(1/hr2[0]+1/hr2[1]+1/hr2[2]);
    double b = -1/hr2[0];
    double d = -1/hr2[1];
    double f = -1/hr2[2];

    int NumMyElements = Map->NumMyElements();
    int* MyGlobalElements = Map->MyGlobalElements();

    int W, E, S, N, F, B, numout;
539 540
    std::vector<double> Values(6);
    std::vector<int> Indices(6);
gsell's avatar
gsell committed
541 542 543

    for (int i = 0 ; i < NumMyElements ; ++i)
    {
544
        getNeighbours(MyGlobalElements[i], W, E, S, N, F, B, numout);
gsell's avatar
gsell committed
545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715

        int NumEntries = 0;
        double diag = a;
        //numout = 0;

        //transversal direction: if below == -1 || above == -1 ===> NEUMANN
        //else dirichlet:
        if(F != -1 && B != -1)
            numout = 0;

        //only on left longitudinal end open bc -- else dirichlet
        //if(F != -1)
        //  numout = 0;

        switch(numout) {

            case 3: {
                        if(W == -1) {
                            Indices[NumEntries] = E;
                            Values[NumEntries++] = 0.5*b;
                        }

                        if(E == -1) {
                            Indices[NumEntries] = W;
                            Values[NumEntries++] = 0.5*b;
                        }

                        if(N == -1) {
                            Indices[NumEntries] = S;
                            Values[NumEntries++] = 0.5*d;
                        }

                        if(S == -1) {
                            Indices[NumEntries] = N;
                            Values[NumEntries++] = 0.5*d;
                        }

                        if(B == -1) {
                            Indices[NumEntries] = F;
                            Values[NumEntries++] = f;
                        }

                        if(F == -1) {
                            Indices[NumEntries] = B;
                            Values[NumEntries++] = f;
                        }

                        diag *= 0.5;

                        if(NumEntries != 3)
                            cout << "ERROR: while calc corners in stencil" << endl;

                        break;

                    }
            case 2: { //edges

                        if(E != -1) {
                            Indices[NumEntries] = E;
                            Values[NumEntries++] = 0.5*b;
                        }
                        if(W != -1) {
                            Indices[NumEntries] = W;
                            Values[NumEntries++] = 0.5*b;
                        }

                        if(S != -1) {
                            Indices[NumEntries] = S;
                            Values[NumEntries++] = 0.5*d;
                        }
                        if(N != -1) {
                            Indices[NumEntries] = N;
                            Values[NumEntries++] = 0.5*d;
                        }

                        if(B == -1) {
                            Indices[NumEntries] = F;
                            Values[NumEntries++] = f;
                        }
                        if(F == -1) {
                            Indices[NumEntries] = B;
                            Values[NumEntries++] = f;
                        }

                        diag *= 0.5;

                        if(NumEntries != 4)
                            cout << "ERROR: while calc edge stencil elements" << endl;

                        break;
                    }
            case 1: {

                        if(E != -1) {
                            Indices[NumEntries] = E;
                            Values[NumEntries++] = 0.5*b;
                        }
                        if(W != -1) {
                            Indices[NumEntries] = W;
                            Values[NumEntries++] = 0.5*b;
                        }

                        if(S != -1) {
                            Indices[NumEntries] = S;
                            Values[NumEntries++] = 0.5*d;
                        }
                        if(N != -1) {
                            Indices[NumEntries] = N;
                            Values[NumEntries++] = 0.5*d;
                        }

                        if(B == -1) {
                            Indices[NumEntries] = F;
                            Values[NumEntries++] = f;
                        }
                        if(F == -1) {
                            Indices[NumEntries] = B;
                            Values[NumEntries++] = f;
                        }

                        diag *= 0.5;

                        if(NumEntries != 5)
                            cout << "ERROR: calc surface elements of stencil" << endl;

                        break;
                    }

            case 0: {  //interior points (& dirichlet)
                        if(W != -1) {
                            Indices[NumEntries] = W;
                            Values[NumEntries++] = b;
                        } if(E != -1) {
                            Indices[NumEntries] = E;
                            Values[NumEntries++] = b;
                        } if(S != -1) {
                            Indices[NumEntries] = S;
                            Values[NumEntries++] = d;
                        } if(N != -1) {
                            Indices[NumEntries] = N;
                            Values[NumEntries++] = d;
                        } if(F != -1) {
                            Indices[NumEntries] = F;
                            Values[NumEntries++] = f;
                        } if(B != -1) {
                            Indices[NumEntries] = B;
                            Values[NumEntries++] = f;
                        }

                        break;
                    }
            default: {
                         cout << "ERROR CREATING THE STENCIL: points out of domain (" << numout << ") is >3 OR <0" << endl;
                     }
        }
        // put the off-diagonal entries
        Matrix->InsertGlobalValues(MyGlobalElements[i], NumEntries,
                &Values[0], &Indices[0]);

        // Put in the diagonal entry
        Matrix->InsertGlobalValues(MyGlobalElements[i], 1,
                &diag, MyGlobalElements + i);

    }
    Matrix->FillComplete();
    Matrix->OptimizeStorage();

    return(Matrix);
}
*/

Christof Metzger-Kraus's avatar
Christof Metzger-Kraus committed
716
#endif //#ifdef HAVE_SAAMG_SOLVER