File: Cal_SmallFemTermOfFemEquation.cpp

package info (click to toggle)
getdp 3.0.4%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 10,856 kB
  • sloc: cpp: 63,020; fortran: 13,955; yacc: 9,350; f90: 1,640; lex: 799; makefile: 55; ansic: 34; awk: 33; sh: 23
file content (215 lines) | stat: -rw-r--r-- 6,438 bytes parent folder | download
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
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
// GetDP - Copyright (C) 1997-2018 P. Dular and C. Geuzaine, University of Liege
//
// See the LICENSE.txt file for license information. Please report all
// issues on https://gitlab.onelab.info/getdp/getdp/issues
//
// Contributor(s):
//   Nicolas Marsic
//

#include "DofData.h"
#include "Message.h"
#include "Cal_SmallFemTermOfFemEquation.h"

#if defined(HAVE_SMALLFEM)
#include "SmallFem.h"
#include "Mesh.h"
#include "FunctionSpace0Form.h"
#include "System.h"
#include "SystemHelper.h"
#include "FormulationPoisson.h"

extern struct CurrentData Current;

// SmallFEM: helping functions //
double fDirichlet0(fullVector<double>& xyz){
  return -1;
}

double fDirichlet1(fullVector<double>& xyz){
  return +1;
}

double fSource(fullVector<double>& xyz){
  return 0;
}

void fMaterial(fullVector<double>& xyz, fullMatrix<double>& tensor){
  tensor.scale(0);

  if(xyz(0) > 0){
    tensor(0, 0) = 1;
    tensor(1, 1) = 1;
    tensor(2, 2) = 1;
  }
  if(xyz(0) <= 0){
    tensor(0, 0) = 1;
    tensor(1, 1) = 1;
    tensor(2, 2) = 1;
  }
}

int getGoeIdFromGetDPId(GroupOfElement& goe, int getdpId){
  std::vector<const MElement*> element = goe.getAll();

  for(size_t i = 0; i < element.size(); i++)
    if(element[i]->getNum() == getdpId)
      return i;

  throw Exception("Element not found!");
}

struct Dof getGetDPDofFromSmallFEM(const sf::Dof& dofSF,
                                   const     DofManager<double>& dofM){
  size_t     globalId = dofM.getGlobalId(dofSF);
  struct Dof dofDP;
  dofDP.NumType  = 1;
  dofDP.Entity   = dofSF.getEntity() + 1;
  dofDP.Harmonic = 0;

  if(globalId == DofManager<double>::isFixedId()){
    dofDP.Type                                  = 2;
    dofDP.Case.FixedAssociate.TimeFunctionIndex = 0;
    dofDP.Val.s                                 = dofM.getValue(dofSF);
  }
  else{
    dofDP.Type                  = 1;
    dofDP.Case.Unknown.NumDof   = globalId + 1;
    dofDP.Case.Unknown.NonLocal = 0;
  }

  return dofDP;
}

void printDof(struct Dof* dof){
  std::cout << dof->NumType  << ", "
            << dof->Entity   << ", "
            << dof->Harmonic << ", "
            << dof->Type     << "; ";

  switch(dof->Type){
  case 1: std::cout << dof->Case.Unknown.NumDof   << ", "
                    << dof->Case.Unknown.NonLocal; break;

  case 2: std::cout << dof->Case.FixedAssociate.NumDof            << ", "
                    << dof->Case.FixedAssociate.TimeFunctionIndex << ", "
                    << dof->Val.s;                 break;

  default: throw(Exception("Unknown GetDP Dof Type: %d", dof->Type));
  }
}

void Cal_SmallFemTermOfFemEquation(struct Element*         Element,
                                   struct EquationTerm*    EquationTerm_P,
                                   struct QuantityStorage* QuantityStorage_P0){
  extern                int  Flag_RHS;
  struct FemLocalTermActive* FI = EquationTerm_P->Case.LocalTerm.Active;
  Current.flagAssDiag = 0; /*+++prov*/

  /* treatment of MHBilinear-term in separate routine */
  if(FI->MHBilinear){
    /* if only the RHS of the system is to be calculated
       (in case of adaptive relaxation of the Newton-Raphson scheme)
       the (expensive and redundant) calculation of this term can be skipped */
    if(!Flag_RHS)
      Message::Error("MHBilinear not in SmallFEM");
    return;
  }

  // Init SmallFEM (only once) //
  static int once = 0;
  static Mesh* msh;
  static GroupOfElement*    volume;
  static GroupOfElement* boundary0;
  static GroupOfElement* boundary1;

  static sf::FunctionSpace0Form*      fs;
  static FormulationPoisson*     poisson;
  static System<double>*      sysPoisson;
  static const DofManager<double>*  dofM;

  static const std::vector<std::vector<sf::Dof> >* allDofField;
  static const std::vector<std::vector<sf::Dof> >* allDofTest;

  if(!once){
    // Say it loudly and proudly! //
    Message::Direct("U s i n g  S m a l l F E M . . .");

    // Create a SmallFEM Formulation for Poisson //
    // Get Domains //
    msh       = new Mesh("mesh.msh");
    volume    = new GroupOfElement(msh->getFromPhysical(7));
    boundary0 = new GroupOfElement(msh->getFromPhysical(6));
    boundary1 = new GroupOfElement(msh->getFromPhysical(5));

    // Full Domain //
    std::vector<const GroupOfElement*> domain(3);
    domain[0] = volume;
    domain[1] = boundary0;
    domain[2] = boundary1;

    // Get Order //
    int order = 1;

    // Function Space //
    fs = new sf::FunctionSpace0Form(domain, order);

    // Compute //
    poisson = new FormulationPoisson(*volume, *fs, fSource, fMaterial);

    sysPoisson = new System<double>;
    sysPoisson->addFormulation(*poisson);

    SystemHelper<double>::dirichlet(*sysPoisson, *fs, *boundary0, fDirichlet0);
    SystemHelper<double>::dirichlet(*sysPoisson, *fs, *boundary1, fDirichlet1);

    sysPoisson->assemble();
    dofM = &sysPoisson->getDofManager();

    allDofField = &(poisson->field().getKeys(poisson->domain()));
    allDofTest  = &( poisson->test().getKeys(poisson->domain()));

    once = 1;
  }

  // Get GetDP Number of Dofs
  //struct QuantityStorage* QuantityStorageEqu_P = FI->QuantityStorageEqu_P;
  //struct QuantityStorage* QuantityStorageDof_P = FI->QuantityStorageDof_P;
  //int Nbr_Dof =
  //  FI->SymmetricalMatrix ? QuantityStorageEqu_P->NbrElementaryBasisFunction :
  //  QuantityStorageDof_P->NbrElementaryBasisFunction;
  //int Nbr_Equ =
  //  QuantityStorageEqu_P->NbrElementaryBasisFunction;

  // SF Dofs
  int elementIdSF = getGoeIdFromGetDPId(*volume, Element->Num);
  std::vector<sf::Dof> dofField = (*allDofField)[elementIdSF];
  std::vector<sf::Dof> dofTest  =  (*allDofTest)[elementIdSF];

  // Assemble
  int nDofField = dofField.size();
  int nDofTest  = dofTest.size();

  for (int i = 0; i < nDofField; i++){
    struct Dof dofI = getGetDPDofFromSmallFEM(dofField[i], *dofM);

    for (int j = 0; j < nDofTest; j++){
      struct Dof dofJ = getGetDPDofFromSmallFEM(dofTest[j], *dofM);
      double   termIJ = poisson->weak(i, j, elementIdSF);

      ((void (*)(struct Dof*, struct Dof*, double*))
       FI->Function_AssembleTerm)(&dofI, &dofJ, &termIJ);
    }
  }

  // Done
  return;
}

#else
void Cal_SmallFemTermOfFemEquation(struct Element*         Element,
                                   struct EquationTerm*    EquationTerm_P,
                                   struct QuantityStorage* QuantityStorage_P0){
  Message::Error("SmallFEM not activated");
}
#endif