BddcMlSolver.cc 3.67 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
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
//
// Software License for AMDiS
//
// Copyright (c) 2010 Dresden University of Technology 
// All rights reserved.
// Authors: Simon Vey, Thomas Witkowski et al.
//
// This file is part of AMDiS
//
// See also license.opensource.txt in the distribution.

extern "C" {
#include <bddcml_interface_c.h>
}

#include "parallel/BddcMlSolver.h"

namespace AMDiS {

#ifdef HAVE_BDDC_ML

  void BddcMlSolver::fillPetscMatrix(Matrix<DOFMatrix*> *mat)
  {
    FUNCNAME("BddcMlSolver::fillPetscMatrix()");
  }


  void BddcMlSolver::fillPetscRhs(SystemVector *vec)
  {
    FUNCNAME("BddcMlSolver::fillPetscRhs()");
  }


  void BddcMlSolver::solvePetscMatrix(SystemVector &vec, AdaptInfo *adaptInfo)
  {
    FUNCNAME("BddcMlSolver::solvePetscMatrix()");
    
    int nComponents = vec.getSize();
    const FiniteElemSüace *feSpace = vec.getFeSpace(0);
    Mesh *mesh = feSpace->getMesh();
    

    // === First, create a continous leaf element index on each subdomain ===

    std::set<int> leafElIndex;
    TraverseStack stack;
    ElInfo *elInfo = stack.traverseFirst(mesh, -1, Mesh::CALL_LEAF_EL);
    while (elInfo) {
      leafElIndex.insert(elInfo->getElement()->getIndex());
      elInfo = stack.traverseNext(elInfo);
    }

    map<int, int> mapElIndex;
    int c = nLeafEls;
    for (std::set<int>::iterator it = leafElIndex.begin();
	 it != leafElIndex.end(); ++it)
      mapElIndex[*it] = nLeafEls++;



    int nLevel = 1;
    int nSubdomains = meshDistributor->getMpiSize();
    int length = 1;
    int nSubPerProc = 1;
    MPI_Fint c2f = MPI_Comm_c2f(MPI::COMM_WORLD);
    int verboseLevel = 2;
    int numbase = 0;

    bddcml_init(&nLevel, &nSubdomains, &length, &nSubPerProc, 
		&c2f, &verboseLevel, &numbase);

    // global number of elements
    int nelem = mesh->getNumberOfLeaves();
    mpi::globalAdd(nelem);

    // global number of nodes
    int nnod = meshDistributor->getNumberOverallDofs(feSpace);

    // global number of dofs
    int ndof = nnod * nComponents;

    // space dimenstion
    int ndim = 2;

    // mesh dimension
    int meshdim = 2;

    // global indes of subdomain
    int isub = meshDistributor->getMpiRank();

    // local number of elements
    int nelems = nLeafEls;

    // local number of nodes
    int nnods = feSpace->getUsedSize();

    // local number of dofs
    int ndofs = nnods * nComponents;

    // Length of array inet
    int linet = nelems * 3;
    
    // Local array with indices of nodes on each element
    int inet[linet];
    elInfo = stack.traverseFirst(mesh, -1, Mesh::CALL_LEAF_EL);
    while (elInfo) {
      int localElIndex = mapElIndex[elInfo->getElement()->getIndex()];
      for (int i = 0; i < 3; i++)
	inet[localElIndex * 3 + i] = elInfo->getElement()->getDof(i, 0);
      elInfo = stack.traverseNext(elInfo);
    }


    // local array of number of nodes per element
    int nnet[nelems];
    for (int i = 0; i < nelems; i++)
      nnet[i] = 3;

    // local array with number of DOFs per node.
    int nndf[nnod];
    for (int i = 0; i < nnod; i++)
      nndf[i] = nComponents;

    // array of indices of subdomain nodes in global numbering
    int isngn[nnod];
    for (int i = 0; i < nnod; i++)
      nnod[i] = meshDistributor->mapLocalToGlobal(feSpace, i);

    // array of indices of subdomain variables in global numbering
    int isvgvn[ndof];

    /*
      bddcml_upload_subdomain_data(
      &nelem,
      &nnod,
      &ndof,
      &ndim,
      &meshdim,
      &isub,
      &nelems,
      &nnods,
      &ndofs,
      inet,
      &linet,
      nnet,
      &nelems,
      nndf,
      &nnods,
      isngn,
      &nnods,

      );
    */

    bddcml_finalize();
  }


  void BddcMlSolver::destroyMatrixData()
  {
    FUNCNAME("BddcMlSolver::destroyMatrixData()");
  }

#endif

}