File: Cal_IntegralQuantity.cpp

package info (click to toggle)
getdp 2.9.2+dfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 6,384 kB
  • ctags: 8,206
  • sloc: cpp: 55,135; fortran: 13,955; yacc: 8,493; lex: 746; sh: 56; ansic: 34; awk: 33; makefile: 24
file content (360 lines) | stat: -rw-r--r-- 12,175 bytes parent folder | download | duplicates (2)
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
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
// GetDP - Copyright (C) 1997-2016 P. Dular and C. Geuzaine, University of Liege
//
// See the LICENSE.txt file for license information. Please report all
// bugs and problems to the public mailing list <getdp@onelab.info>.

#include <math.h>
#include "ProData.h"
#include "ProDefine.h"
#include "BF.h"
#include "Cal_Quantity.h"
#include "Cal_Value.h"
#include "Get_Geometry.h"
#include "Get_FunctionValue.h"
#include "Message.h"

extern struct Problem Problem_S ;
extern struct CurrentData Current ;

/* ----------------------------------------------------------------------------- */
/*  C a l _ I n i t I n t e g r a l Q u a n t i t y                              */
/* ----------------------------------------------------------------------------- */

void Cal_InitIntegralQuantity(struct Element                *Element,
			      struct IntegralQuantityActive *IQA,
			      struct QuantityStorage        *QuantityStorage_P)
{
  struct Quadrature  *Quadrature_P ;
  int                 ElementSourceType ;
  int                 i,j ;

  ElementSourceType = Element->ElementSource->Type ;

  /* Get integration method */
  IQA->IntegrationCase_P = Get_IntegrationCase(Element,
					       IQA->IntegrationCase_L,
					       IQA->CriterionIndex);

  switch(IQA->IntegrationCase_P->Type) {
    /* Numerical Integration */
  case GAUSS :
  case GAUSSLEGENDRE :
    Quadrature_P = (struct Quadrature*)
      List_PQuery(IQA->IntegrationCase_P->Case, &ElementSourceType, fcmp_int) ;

    if(!Quadrature_P){
      Message::Error("Unknown type of Element (%s) for Integration method (%s)",
		 Get_StringForDefine(Element_Type, ElementSourceType),
		 ((struct IntegrationMethod *)
		  List_Pointer(Problem_S.IntegrationMethod,
			       QuantityStorage_P->DefineQuantity->IntegralQuantity.
			       IntegrationMethodIndex))->Name);
      return;
    }

    IQA->Nbr_IntPoints = Quadrature_P->NumberOfPoints ;
    IQA->Get_IntPoint  = Quadrature_P->Function ;
    IQA->xChangeOfCoordinates =
      (void (*)())Get_ChangeOfCoordinates(1, IQA->Type_FormDof) ;

    i = 0 ;
    while ((i < List_Nbr(IQA->JacobianCase_L)) &&
	   ((j = ((struct JacobianCase *)List_Pointer(IQA->JacobianCase_L, i))
	     ->RegionIndex) >= 0) &&
	   !List_Search
	   (((struct Group *)List_Pointer(Problem_S.Group, j)) ->InitialList,
	    &Element->ElementSource->Region, fcmp_int) )  i++ ;

    if (i == List_Nbr(IQA->JacobianCase_L)){
      Message::Error("Undefined Jacobian in Region %d", Element->ElementSource->Region);
      return;
    }

    Element->ElementSource->JacobianCase =
      (struct JacobianCase*)List_Pointer(IQA->JacobianCase_L, i) ;

    IQA->Get_Jacobian = (double (*)())Get_JacobianFunction
      (Element->ElementSource->JacobianCase->TypeJacobian,
       ElementSourceType, &IQA->Type_Dimension) ;

    if(QuantityStorage_P->DefineQuantity->IntegralQuantity.Symmetry){
      Message::Error("Symmetries of integral kernels not ready with numerical integration");
      return;
    }
    break;

    /* Analytical Integration (the jacobian method is not defined, since we also
       express the basis functions analytically) */

  case ANALYTIC :
    switch(QuantityStorage_P->DefineQuantity->IntegralQuantity.CanonicalWholeQuantity){
    case CWQ_GF :
    case CWQ_GF_PSCA_DOF :
    case CWQ_GF_PSCA_EXP :
    case CWQ_GF_PVEC_EXP :
    case CWQ_EXP_TIME_GF_PSCA_DOF :
      break ;
    case CWQ_GF_PVEC_DOF :
    case CWQ_EXP_TIME_GF_PVEC_DOF :
    default : Message::Error("Unrecognized Integral Quantity to integrate analytically");
      return;
    }
    break ;

  default :
    Message::Error("Unknown type of Integration method (%s) for Integral Quantity",
	       ((struct IntegrationMethod *)
		List_Pointer(Problem_S.IntegrationMethod,
			     QuantityStorage_P->DefineQuantity->IntegralQuantity.
			     IntegrationMethodIndex))->Name);
    return;
  }

  IQA->Type_ValueDof = Get_ValueFromForm(IQA->Type_FormDof);
}

/* ----------------------------------------------------------------------------- */
/*  A p p l y _ C o n s t a n t F a c t o r                                      */
/* ----------------------------------------------------------------------------- */

void Apply_ConstantFactor(struct QuantityStorage * QuantityStorage_P,
			  struct Value           * vBFxDof,
			  struct Value           * Val)
{
  switch(QuantityStorage_P->DefineQuantity->IntegralQuantity.CanonicalWholeQuantity){
  case CWQ_GF :
  case CWQ_GF_PSCA_DOF :
  case CWQ_GF_PVEC_DOF :
  case CWQ_DOF_PVEC_GF :
    break ;
  case CWQ_GF_PSCA_EXP :
  case CWQ_EXP_TIME_GF_PSCA_DOF :
  case CWQ_EXP_TIME_GF_PVEC_DOF :
  case CWQ_FCT_TIME_GF_PSCA_DOF :
  case CWQ_FCT_TIME_GF_PVEC_DOF :
    Cal_ProductValue(Val, vBFxDof, vBFxDof);
    break;
  case CWQ_GF_PVEC_EXP :
    Cal_CrossProductValue(vBFxDof, Val, vBFxDof);
    break;
  case CWQ_EXP_PVEC_GF :
  case CWQ_EXP_PVEC_GF_PSCA_DOF :
  case CWQ_EXP_PVEC_GF_PVEC_DOF :
  case CWQ_FCT_PVEC_GF_PSCA_DOF :
  case CWQ_FCT_PVEC_GF_PVEC_DOF :
    Cal_CrossProductValue(Val, vBFxDof, vBFxDof);
    break;
  default :
    Message::Error("Unknown type of canonical Integral Quantity");
    return;
  }
}

/* ------------------------------------------------------------------------------- */
/*  C a l _ N u m e r i c a l I n t e g r a l Q u a n t i t y                      */
/* ------------------------------------------------------------------------------- */

void Cal_NumericalIntegralQuantity(struct Element                 *Element,
				   struct IntegralQuantityActive  *IQA,
				   struct QuantityStorage         *QuantityStorage_P0,
				   struct QuantityStorage         *QuantityStorage_P,
				   int                             Type_DefineQuantity,
				   int                             Nbr_Dof,
				   void                          (*xFunctionBF[])(),
				   struct Value                    vBFxDof[])
{
  struct Value   vBFx[NBR_MAX_BASISFUNCTIONS] ;
  int            i, j, i_IntPoint ;
  double         Factor, weight ;
  double         vBFu[NBR_MAX_BASISFUNCTIONS] [MAX_DIM] ;
  struct Element *ES  ;

  /* This routine is valid for all QUADRATURE cases: GAUSS,
     GAUSSLEGENDRE */

  if (Element->Num != NO_ELEMENT) {
    Current.x = Current.y = Current.z = 0. ;
    for (i = 0 ; i < Element->GeoElement->NbrNodes ; i++) {
      Current.x += Element->x[i] * Element->n[i] ;
      Current.y += Element->y[i] * Element->n[i] ;
      Current.z += Element->z[i] * Element->n[i] ;
    }
  }

  Current.Element = Element ;
  Current.ElementSource = Element->ElementSource ;

  for (j = 0 ; j < Nbr_Dof ; j++) Cal_ZeroValue(&vBFxDof[j]);

  ES = Element->ElementSource ;

  for (i_IntPoint = 0 ; i_IntPoint < IQA->Nbr_IntPoints ; i_IntPoint++) {

    ((void (*)(int,int,double*,double*,double*,double*))
     IQA->Get_IntPoint) (IQA->Nbr_IntPoints, i_IntPoint,
			 &Current.us, &Current.vs, &Current.ws, &weight) ;

    Get_BFGeoElement (ES, Current.us, Current.vs, Current.ws) ;

    ES->DetJac =
      ((double (*)(struct Element*, MATRIX3x3*))
       IQA->Get_Jacobian) (ES, &ES->Jac) ;

    if(IQA->Type_FormDof == FORM1)
      Get_InverseMatrix(IQA->Type_Dimension, ES->Type,
			ES->DetJac, &ES->Jac, &ES->InvJac) ;

    Current.xs = Current.ys = Current.zs = 0. ;
    for (i = 0 ; i < ES->GeoElement->NbrNodes ; i++) {
      Current.xs += ES->x[i] * ES->n[i] ;
      Current.ys += ES->y[i] * ES->n[i] ;
      Current.zs += ES->z[i] * ES->n[i] ;
    }

    if(Type_DefineQuantity != NODOF){
      for (j = 0 ; j < Nbr_Dof ; j++) {
	((void (*)(struct Element*, int, double, double, double, double*))
	 xFunctionBF[j]) (Element->ElementSource,
			  QuantityStorage_P->BasisFunction[j].NumEntityInElement+1,
			  Current.us, Current.vs, Current.ws, vBFu[j]) ;

	((void (*)(struct Element*, double*, double*))
	 IQA->xChangeOfCoordinates) (Element->ElementSource, vBFu[j], vBFx[j].Val) ;

	vBFx[j].Type = IQA->Type_ValueDof ;
	Cal_SetHarmonicValue(&vBFx[j]);
      }
    }

    Factor = weight * fabs(ES->DetJac) ;

    Current.Region = Element->ElementSource->Region ;

    /* Il faudrait definir le cas canonique Function[] * Dof  */

    Cal_WholeQuantity
      (Element->ElementSource, QuantityStorage_P0,
       QuantityStorage_P->DefineQuantity->IntegralQuantity.WholeQuantity,
       Current.us, Current.vs, Current.ws,
       QuantityStorage_P->DefineQuantity->IntegralQuantity.DofIndexInWholeQuantity,
       Nbr_Dof, vBFx) ;

    Current.Region = Element->Region ;

    for (j = 0 ; j < Nbr_Dof ; j++) {
      vBFxDof[j].Type = vBFx[j].Type ;
      Cal_AddMultValue(&vBFxDof[j],&vBFx[j],Factor,&vBFxDof[j]);
    }

  }
}

/* ------------------------------------------------------------------------------- */
/*  C a l _ A n a l y t i c I n t e g r a l Q u a n t i t y                        */
/* ------------------------------------------------------------------------------- */

void Cal_AnalyticIntegralQuantity(struct Element         *Element,
				  struct QuantityStorage *QuantityStorage_P,
				  int                     Nbr_Dof,
				  void                  (*xFunctionBF[])(),
				  struct Value            vBFxDof[])
{
  struct Value   Val0 ;
  int            i, j ;

  if (Element->Num != NO_ELEMENT) {
    Current.x = Current.y = Current.z = 0. ;
    for (i = 0 ; i < Element->GeoElement->NbrNodes ; i++) {
      Current.x += Element->x[i] * Element->n[i] ;
      Current.y += Element->y[i] * Element->n[i] ;
      Current.z += Element->z[i] * Element->n[i] ;
    }
  }

  Current.Element = Element ;
  Current.ElementSource = Element->ElementSource ;

  switch(QuantityStorage_P->DefineQuantity->IntegralQuantity.CanonicalWholeQuantity){
  case CWQ_GF :
  case CWQ_GF_PSCA_DOF :
    break ;
  case CWQ_GF_PVEC_DOF :
  case CWQ_EXP_TIME_GF_PVEC_DOF :
    Message::Error("Vector product of GF_Function and Dof{} not done for analytic integration");
    return ;
  case CWQ_GF_PSCA_EXP :
  case CWQ_GF_PVEC_EXP :
  case CWQ_EXP_TIME_GF_PSCA_DOF :
    Current.ElementSource = Element->ElementSource ;
    Current.Region = Element->ElementSource->Region ;
    Get_ValueOfExpression((struct Expression *)
			  List_Pointer(Problem_S.Expression,
				       QuantityStorage_P->DefineQuantity->IntegralQuantity.
				       ExpressionIndexForCanonical),
			  NULL, 0., 0., 0., &Val0) ;
    Current.Region = Element->Region ;
    break ;
  default :
    Message::Error("Unknown type of canonical Integral Quantity");
    return;
  }


  for (j = 0 ; j < Nbr_Dof ; j++) {

    ((void (*)(struct Element*, struct Function *, void(*)(), int,
	       double, double, double, struct Value *))
     QuantityStorage_P->DefineQuantity->IntegralQuantity.FunctionForCanonical.Fct)
      (Element,
       &QuantityStorage_P->DefineQuantity->IntegralQuantity.FunctionForCanonical,
       xFunctionBF[j],
       QuantityStorage_P->BasisFunction[j].NumEntityInElement+1,
       Current.x, Current.y, Current.z,
       &vBFxDof[j]) ;

    Apply_ConstantFactor(QuantityStorage_P, &vBFxDof[j], &Val0) ;
  }

  switch(QuantityStorage_P->DefineQuantity->IntegralQuantity.Symmetry) {
  case 0 : /* No Symmetry */
    break;

  case 1 : /* y -> -y */
    for (i = 0 ; i < Element->ElementSource->GeoElement->NbrNodes ; i++)
      Element->ElementSource->y[i] *= -1. ;

    for (j = 0 ; j < Nbr_Dof ; j++) {

      ((void (*)(struct Element*, struct Function *, void(*)(), int,
		 double, double, double, struct Value *))
       QuantityStorage_P->DefineQuantity->IntegralQuantity.FunctionForCanonical.Fct)
	(Element,
	 &QuantityStorage_P->DefineQuantity->IntegralQuantity.FunctionForCanonical,
	 xFunctionBF[j],
	 QuantityStorage_P->BasisFunction[j].NumEntityInElement+1,
	 Current.x, Current.y, Current.z,
	 &Val0) ;

      Apply_ConstantFactor(QuantityStorage_P, &vBFxDof[j], &Val0) ;

      if (vBFxDof[j].Type == SCALAR) {
	vBFxDof[j].Val[0] -= Val0.Val[0] ;
      }
      else {
	vBFxDof[j].Val[0] -= Val0.Val[0] ;
	vBFxDof[j].Val[1] -= Val0.Val[1] ;
	vBFxDof[j].Val[2] -= Val0.Val[2] ;
      }

    }

    for (i = 0 ; i < Element->ElementSource->GeoElement->NbrNodes ; i++)
      Element->ElementSource->y[i] *= -1. ;

    break;

  default:
    Message::Error("Unknown type of symmetry in Integral Quantity");
    break;
  }
}