File: Operation_PostOperation.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 (287 lines) | stat: -rw-r--r-- 11,568 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
// 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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "GetDPConfig.h"


#include "ProData.h"
#include "DofData.h"
#include "SolvingOperations.h"
#include "SolvingAnalyse.h"
#include "Message.h"
#include "MallocUtils.h"

extern struct CurrentData Current;
extern struct Problem Problem_S;


/* ------------------------------------------------------------------------ */
/*  O p e r a t i o n _ P o s t O p e r a t i o n                           */
/* ------------------------------------------------------------------------ */


void Operation_PostOperation(Resolution  *Resolution_P,
                             DofData     *DofData_P0,
                             GeoData     *GeoData_P0,
                             List_T      *PostOperationNames)
{
  double  Save_Time, Save_TimeImag, Save_TimeStep;
  char    *str;
  int     i, j, k;
  Element *Save_Element;
  PostOperation  *PostOperation_P;
  PostProcessing *PostProcessing_P ;

  Save_Time = Current.Time ;
  Save_TimeImag = Current.TimeImag ;
  Save_TimeStep = Current.TimeStep ;
  Save_Element = Current.Element;

  for(int i=0 ; i<List_Nbr(PostOperationNames); i++){
    str = *(char**)List_Pointer(PostOperationNames, i);
    if((j = List_ISearchSeq(Problem_S.PostOperation, str, fcmp_PostOperation_Name)) < 0){
      Message::Warning("Unknown PostOperation '%s'", str) ;
    }
    else{
      PostOperation_P = (struct PostOperation*)
        List_Pointer(Problem_S.PostOperation, j) ;
      PostProcessing_P = (struct PostProcessing *)
        List_Pointer(Problem_S.PostProcessing, PostOperation_P->PostProcessingIndex) ;
      Current.PostOpDataIndex = i;
      Treatment_PostOperation(Resolution_P, DofData_P0,
         (struct DefineSystem *)List_Pointer(Resolution_P->DefineSystem, 0),
         GeoData_P0, PostProcessing_P, PostOperation_P) ;
    }
  }

  /* the post-processing can (and usually will) change the current
     timestep, current time and current solution pointers: we need
     to reset them */
  Current.Time = Save_Time ;
  Current.TimeImag = Save_TimeImag ;
  Current.TimeStep = Save_TimeStep ;
  for (k = 0 ; k < Current.NbrSystem ; k++){
    i = List_Nbr((Current.DofData_P0+k)->Solutions) - 1;
    if(i >= 0)
      (Current.DofData_P0+k)->CurrentSolution = (struct Solution*)
        List_Pointer((Current.DofData_P0+k)->Solutions, i);
  }
  Current.Element = Save_Element;
  Current.PostOpDataIndex = -1;
}


/* ------------------------------------------------------------------------ */
/*  I n i t L E P o s t O p e r a t i o n                                   */
/* ------------------------------------------------------------------------ */


void InitLEPostOperation(Resolution  *Resolution_P,
                         DofData     *DofData_P0,
                         GeoData     *GeoData_P0,
                         List_T      *LEPostOp_L,
                         List_T      *LEPostOpNames_L,
                         List_T      *PostOpSolution_L)
{
  int                    NbrPostOps, Index, NbrPostSubOperation, PostOpSolLength;
  int                    *Save_Format_P, *Save_LastTimeStepOnly_P;
  char                   **Save_FileOut_P;
  PostOpSolutions        *PostOpSolutions_P, PostOpSolutions_S;
  LoopErrorPostOperation *LEPostOp_P;
  PostSubOperation       *PostSubOperation_P;
  List_T                 *PostSubOperation_L;
  gVector                PostOpSolution_S;

  Current.PostOpData_L = NULL;
  NbrPostOps = List_Nbr(LEPostOp_L);
  if (NbrPostOps) {
    Current.PostOpData_L = List_Create(NbrPostOps,1,sizeof(PostOpSolutions));

    for (int i=0; i < NbrPostOps; i++) {
      LEPostOp_P = (struct LoopErrorPostOperation*)List_Pointer(LEPostOp_L, i);
      Index = List_ISearchSeq(Problem_S.PostOperation, LEPostOp_P->PostOperationName,
                              fcmp_PostOperation_Name);
      LEPostOp_P->PostOperationIndex = Index;
      if(Index < 0)
        Message::Error("Unknown PostOperation %s in TimeLoopAdaptive",
                       LEPostOp_P->PostOperationName);

      PostOpSolutions_S.PostOperation_P = (struct PostOperation*)
        List_Pointer(Problem_S.PostOperation, Index) ;

      PostSubOperation_L = PostOpSolutions_S.PostOperation_P->PostSubOperation;
      NbrPostSubOperation = List_Nbr(PostSubOperation_L);
      if (NbrPostSubOperation) {
        LEPostOp_P->Save_Format_L = List_Create(NbrPostSubOperation,2,
                                                 sizeof(int));
        LEPostOp_P->Save_LastTimeStepOnly_L = List_Create(NbrPostSubOperation,
                                                           2,sizeof(int));
        LEPostOp_P->Save_FileOut_L = List_Create(NbrPostSubOperation,
                                                  2,sizeof(char *));
      }
      for (int j=0; j<NbrPostSubOperation; j++) {
        PostSubOperation_P = (struct PostSubOperation*)
                              List_Pointer(PostSubOperation_L, j);
        Save_Format_P = &PostSubOperation_P->Format;
        Save_LastTimeStepOnly_P = &PostSubOperation_P->LastTimeStepOnly;
        Save_FileOut_P = &PostSubOperation_P->FileOut;
        List_Add(LEPostOp_P->Save_Format_L, Save_Format_P);
        List_Add(LEPostOp_P->Save_LastTimeStepOnly_L, Save_LastTimeStepOnly_P);
        List_Add(LEPostOp_P->Save_FileOut_L, Save_FileOut_P);
        *Save_Format_P = FORMAT_LOOP_ERROR;
        *Save_LastTimeStepOnly_P = 1;
        *Save_FileOut_P = NULL;
      }

      PostOpSolutions_S.Solutions_L = List_Create(2,2,sizeof(Solution));

      List_Add(Current.PostOpData_L, &PostOpSolutions_S);
      List_Add(LEPostOpNames_L, &LEPostOp_P->PostOperationName);
    }

    // Execute the PostOperations
    Operation_PostOperation(Resolution_P, DofData_P0, GeoData_P0, LEPostOpNames_L);

    // Creating vectors for the PostOperation-solution
    for (int i=0; i < NbrPostOps; i++) {
      PostOpSolutions_P = (struct PostOpSolutions*)
                          List_Pointer(Current.PostOpData_L, i);
      LinAlg_GetVectorSize
        (&((struct Solution*)List_Pointer(PostOpSolutions_P->Solutions_L, 0))->x,
         &PostOpSolLength);
      LinAlg_CreateVector(&PostOpSolution_S, &DofData_P0->Solver, PostOpSolLength);
      List_Add(PostOpSolution_L, &PostOpSolution_S);
    }
  }
}


/* ------------------------------------------------------------------------ */
/*  F r e e _ U n u s e d P o s t O p e r a t i o n R e s u l t s           */
/* ------------------------------------------------------------------------ */

void Free_UnusedPOresults()
{
  struct Solution *Solution_P;
  int             index = -1;
  PostOpSolutions *PostOpSolutions_P;

  for(int i = 0; i < List_Nbr(Current.PostOpData_L); i++) {
    PostOpSolutions_P = (struct PostOpSolutions*)
                                   List_Pointer(Current.PostOpData_L, i);
    // We store 1 solution too much (to allow for an imbricated iterative loop)
    switch (Current.TypeTime) {
    case TIME_THETA :
      index = List_Nbr(PostOpSolutions_P->Solutions_L)-4 ;
      // Fore TimeLoopAdaptive (Trapezoidal) we need 3 past solutions for the predictor
      index = Message::GetOperatingInTimeLoopAdaptive() ? index - 1 : index;
      break;
    case TIME_GEAR :
      // With -9 we store 7 past solutions (for Gear_6)
      index = List_Nbr(PostOpSolutions_P->Solutions_L)-9 ;
      break;
    case TIME_NEWMARK :
      index = List_Nbr(PostOpSolutions_P->Solutions_L)-4 ;
      break;
    }

    if(index >= 0){
      Solution_P = (struct Solution*)
                          List_Pointer(PostOpSolutions_P->Solutions_L, index);
      if(Solution_P->SolutionExist){
        Message::Info("Freeing PostOperationResult %d", index);
        LinAlg_DestroyVector(&Solution_P->x);
        if (Solution_P->TimeFunctionValues)
          Free(Solution_P->TimeFunctionValues);
        Solution_P->SolutionExist = 0 ;
      }
    }
  }
}


/* ------------------------------------------------------------------------ */
/*  F r e e _ A l l P o s t O p e r a t i o n R e s u l t s           */
/* ------------------------------------------------------------------------ */

void Free_AllPOresults()
{
  PostOpSolutions        *PostOpSolutions_P;
  Solution               *Solution_P;

  for (int i=0; i < List_Nbr(Current.PostOpData_L); i++) {
    PostOpSolutions_P = (struct PostOpSolutions*)List_Pointer(Current.PostOpData_L, i);
    for (int j=0; j < List_Nbr(PostOpSolutions_P->Solutions_L); j++) {
      Solution_P = (struct Solution*)List_Pointer(PostOpSolutions_P->Solutions_L, j);
      if (Solution_P->SolutionExist)
        LinAlg_DestroyVector(&Solution_P->x);
      if (Solution_P->TimeFunctionValues)
        Free(Solution_P->TimeFunctionValues);
    }
    List_Delete(PostOpSolutions_P->Solutions_L);
  }
  List_Delete(Current.PostOpData_L);
  Current.PostOpData_L = NULL;
  Current.PostOpDataIndex = -1;
}


/* ------------------------------------------------------------------------ */
/*  C l e a r L E P o s t O p e r a t i o n                                   */
/* ------------------------------------------------------------------------ */


void ClearLEPostOperation(Resolution  *Resolution_P,
                          DofData     *DofData_P0,
                          GeoData     *GeoData_P0,
                          List_T      *LEPostOp_L,
                          List_T      *LEPostOpNames_L,
                          List_T      *PostOpSolution_L,
                          bool        Delete_LEPostOp_L)
{
  int                    Index, NbrPostSubOperation;
  int                    *Format_P, *LastTimeStepOnly_P;
  char                   **FileOut_P;
  LoopErrorPostOperation *LEPostOp_P;
  PostSubOperation       *PostSubOperation_P;
  List_T                 *PostSubOperation_L;

  for(int i = 0; i < List_Nbr(LEPostOp_L); i++) {
    LEPostOp_P = (struct LoopErrorPostOperation*)List_Pointer(LEPostOp_L, i);
    NbrPostSubOperation = List_Nbr(LEPostOp_P->Save_Format_L);

    Index = LEPostOp_P->PostOperationIndex;
    PostSubOperation_L = ((struct PostOperation*)
                          List_Pointer(Problem_S.PostOperation, Index))
                            ->PostSubOperation;

    // Restore variables Format, LastTimeStepOnly and FileOut of all used PostOperations
    for (int j=0; j<NbrPostSubOperation; j++) {
      PostSubOperation_P = (struct PostSubOperation*)List_Pointer(PostSubOperation_L, j);
      Format_P = &PostSubOperation_P->Format;
      LastTimeStepOnly_P = &PostSubOperation_P->LastTimeStepOnly;
      FileOut_P = &PostSubOperation_P->FileOut;
      List_Read(LEPostOp_P->Save_Format_L, j, Format_P);
      List_Read(LEPostOp_P->Save_LastTimeStepOnly_L, j, LastTimeStepOnly_P);
      List_Read(LEPostOp_P->Save_FileOut_L, j, FileOut_P);
    }

    if (Delete_LEPostOp_L)
      free(LEPostOp_P->PostOperationName);
    LinAlg_DestroyVector((gVector*)List_Pointer(PostOpSolution_L, i));
  }
  if (Delete_LEPostOp_L)
    List_Delete(LEPostOp_L);
  List_Delete(PostOpSolution_L);

  Free_AllPOresults();

  List_Delete(LEPostOpNames_L);
}