NeoPZ
TPZFront.cpp
Go to the documentation of this file.
1 
6 #include "pzsfulmat.h"
7 #include "TPZFront.h"
8 #include "pzstack.h"
9 #include "pzreal.h"
10 #include <math.h>
11 
12 #include "tpzeqnarray.h"
13 #include <iostream>
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <fstream>
17 
18 using namespace std;
19 
20 template<class TVar>
22  fExpandRatio = 200;
23  fFront = 0;
24  fMaxFront=0;
25  fWork = 0;
26  fNextRigidBodyMode = 0;
27  fProductMTData = NULL;
28  fDecomposeType = ELU;
29 }
30 
31 template<class TVar>
32 TPZFront<TVar>::TPZFront(int64_t GlobalSize)
33 {
34  fExpandRatio = 200;
35  fFront = 0;
36  fMaxFront=0;
37  fLocal.Resize(GlobalSize);
38  int64_t i;
39  for(i=0;i<GlobalSize;i++) fLocal[i]=-1;
40  fWork = 0;
41  fNextRigidBodyMode = GlobalSize;
42  fProductMTData = NULL;
43  fDecomposeType = ELU;
44 }
45 
46 template<class TVar>
47 TPZFront<TVar>::TPZFront(const TPZFront<TVar> &cp) : fMaxFront(cp.fMaxFront),
48 fGlobal(cp.fGlobal), fLocal(cp.fLocal),fFront(cp.fFront),fFree(cp.fFree),
49 fData(cp.fData),
50 fDecomposeType(cp.fDecomposeType)
51 {
54  if (cp.fProductMTData) {
55  const int nthreads = cp.fProductMTData->NThreads();
56  this->fProductMTData = new STensorProductMTData(nthreads,this);
57  }
58  else {
59  this->fProductMTData = NULL;
60  }
61 }
62 
63 
64 template<class TVar>
66 }
67 
68 template<class TVar>
69 void TPZFront<TVar>::PrintGlobal(const char *name, std::ostream& out){
70  out << name << endl;
71  /*
72  int i, j;
73  for(i=0;i<fLocal.NElements();i++){
74  if(fLocal[i]!=-1) out << i << " ";
75  }
76  out << endl;
77  for(i=0;i<fLocal.NElements();i++){
78  if(fLocal[i]==-1) continue;
79  for(j=0;j<fLocal.NElements();j++){
80  if(fLocal[j]==-1) continue;
81  out << Element(fLocal[i],fLocal[j]) << " ";
82  }
83  out << endl;
84  }
85  out << endl;
86  */
87  out << "Not implemented in the abstract Class !" << endl;
88  out << "Try one of the subclasses" << endl;
89 }
90 
91 
92 template<class TVar>
93 void TPZFront<TVar>::Print(const char *name, std::ostream& out) const
94 {
95  if(name) out << name << endl;
96  /*int i,j,loop_limit;
97 
98 
99  out << "Frontal Matrix Size "<< fFront << endl;
100  out << "Maximum Frontal Matrix Size "<< fMaxFront << endl;
101 
102  out << endl;
103  out << "Local Indexation "<< endl;
104  out << "Position "<<" Local index"<< endl;
105  for(i=0;i<fLocal.NElements();i++){
106  out << i << " " << fLocal[i] << endl;
107  }
108 
109  out << endl;
110  out << "Global Indexation "<< endl;
111  out << "Position "<<" Global index"<< endl;
112 
113  for(i=0;i<fGlobal.NElements();i++){
114  out << i << " "<< fGlobal[i] << endl;
115  }
116 
117  out << endl;
118  out << "Local Freed Equatoins "<< fFree.NElements() << endl;
119  out << "position "<< "Local Equation "<<endl;
120  loop_limit=fFree.NElements();
121  for(i=0;i<loop_limit;i++){
122  out << i << " " << fFree[i] << endl;
123  }
124  out << "Frontal Matrix "<< endl;
125  if(fData.NElements() > 0) {
126  for(i=0;i<fFront;i++){
127  for(j=0;j<fFront;j++) out << ((i<j) ? Element(i,j) : Element(j,i)) << " ";
128  out << endl;
129  }
130  }*/
131 
132  out << "Not implemented in the abstract Class !" << endl;
133  out << "Try one of the subclasses" << endl;
134 }
135 
136 template<class TVar>
137 void TPZFront<TVar>::FreeGlobal(int64_t global)
138 {
139  if(fLocal[global]==-1){
140  cout << "TPZFront FreeGlobal was called with wrong parameters !" << endl;
141  return;
142  }
143  int64_t index;
144  index=fLocal[global];
145  fGlobal[index]=-1;
146  fLocal[global]=-1;
147  fFree.Push(index);
148 }
149 
150 template<class TVar>
151 int TPZFront<TVar>::Local(int64_t global){
152  /* int index;
153  if(fLocal[global]!=-1) return fLocal[global];
154  if(fFree.NElements()){
155  index=fFree.Pop();
156  }else{
157  index=fFront++;
158  }
159  fLocal[global]=index;
160  // At this point we extend the frontmatrix
161  if(index >= fMaxFront) {
162  cout << "Dynamically expanding the front size to " << index+10 << endl;
163  Expand(index+10);
164  }
165  if(fGlobal.NElements()<=index) fGlobal.Resize(index+1);
166  fGlobal[index]=global;
167  return index;
168  */
169  cout << "Not implemented in the abstract Class !" << endl;
170  cout << "Try one of the subclasses" << endl;
171  return -1;
172 }
173 
175 template<class TVar>
177 {
178  int64_t i, loop_limit, aux;
179  loop_limit=destinationindex.NElements();
180  for(i=0;i<loop_limit;i++){
181  aux=destinationindex[i];
182  Local(aux);
184  }
186 
187 }
188 
189 template<class TVar>
190 void TPZFront<TVar>::SymbolicDecomposeEquations(int64_t mineq, int64_t maxeq)
191 {
192  int64_t i;
193  for(i=mineq;i<=maxeq;i++) FreeGlobal(i);
194 }
195 
196 
197 
199 /*
200 template<class TVar>
201 void TPZFront<TVar>::main()
202 {
203  int i, j;
204 
205  //Populates data structure
206  int matsize=6;
207  TPZFMatrix<TVar> TestMatrix(matsize,matsize);
208  for(i=0;i<matsize;i++) {
209  for(j=i;j<matsize;j++) {
210  int random = rand();
211  float rnd = (float)(random*matsize)/RAND_MAX;
212  TestMatrix(i,j)= (TVar)rnd;
213  TestMatrix(j,i)=TestMatrix(i,j);
214  if(i==j) TestMatrix(i,j)=6000.;
215  }
216  }
217 
218  TPZFMatrix<TVar> Prova;
219  Prova=TestMatrix;
220 
221  // Prova.Decompose_Cholesky();
222  Prova.Print("TPZFMatrix<REAL> Cholesky");
223 
224  TPZFront TestFront(matsize);
225 
226 
227  TPZVec<int64_t> DestIndex(matsize);
228  for(i=0;i<matsize;i++) DestIndex[i]=i;
229 
230  TestFront.SymbolicAddKel(DestIndex);
231  TestFront.SymbolicDecomposeEquations(0,matsize-1);
232 
233  std::string OutFile;
234  OutFile = "TPZFrontTest.txt";
235 
236  ofstream output(OutFile.c_str(),ios::app);
237 
238  // TestFront.Compress();
239 
240  // TestFront.AllocData();
241 
242  // TestFront.AddKel(TestMatrix, DestIndex);
243  TPZEqnArray<TVar> Result;
244 
245 // TestFront.DecomposeEquations(0,0,Result);
246 //
247 // TestFront.Print(OutFile, output);
248 //
249 // ofstream outeqn("TestEQNArray.txt",ios::app);
250 // Result.Print("TestEQNArray.txt",outeqn);
251 //
252 // TestFront.Compress();
253 //
254 // TestFront.Print(OutFile, output);
255 //
256  // TestFront.DecomposeEquations(0,matsize-1,Result);
257  ofstream outeqn("TestEQNArray.txt",ios::app);
258 
259  Result.Print("TestEQNArray.txt",outeqn);
260 
261 
262  TPZFMatrix<TVar> Load(matsize);
263 
264  for(i=0;i<matsize;i++) {
265  int random = rand();
266  float rnd = (float)(random*matsize)/RAND_MAX;
267  Load(i,0)= (TVar)rnd;
268  }
269 
270  TPZFMatrix<TVar> Load_2(matsize);
271  Load_2=Load;
272 
273  // Prova.Subst_Forward(&Load);
274  // Prova.Subst_Backward(&Load);
275 
276 
277  DecomposeType decType = ECholesky;
278  Prova.SolveDirect(Load, decType);
279 
280  Load.Print("Load");
281  //TestFront.Print(OutFile, output);
282 
283  Result.EqnForward(Load_2, decType);
284  Result.EqnBackward(Load_2, decType);
285 
286  Load_2.Print("Eqn");
287 
288 }
289 */
290 
291 template<class TVar>
292 void TPZFront<TVar>::Reset(int64_t GlobalSize)
293 {
294  fData.Resize(0);
295  fFree.Resize(0);
296  fFront=0;
297  fGlobal.Resize(0);
298  fLocal.Resize(GlobalSize);
299  fLocal.Fill(-1);
300  fMaxFront=0;
301  fExpandRatio = 200;
302  fWork = 0;
303  fNextRigidBodyMode = GlobalSize;
304 }
305 
306 template<class TVar>
308  return fLocal.NElements();
309 }
310 
311 
312 template<class TVar>
314 {
315  int64_t i;
316  int64_t free_eq=0;
317  for(i=0;i<fGlobal.NElements();i++)
318  {
319  if(fGlobal[i]==-1){
320  free_eq=free_eq+1;
321  }
322  }
323  return free_eq;
324 }
325 
326 template<class TVar>
328 {
329  PZError << "This Method Should only be called in the lower classes" << std::endl;
330  DebugStop();
331 }
332 
333 template class TPZFront<float>;
334 template class TPZFront<std::complex<float> >;
335 
336 template class TPZFront<double>;
337 template class TPZFront<std::complex<double> >;
338 
339 template class TPZFront<long double>;
340 template class TPZFront<std::complex<long double> >;
virtual ~TPZFront()
Simple destructor.
Definition: TPZFront.cpp:65
TPZFront()
Simple constructor.
Definition: TPZFront.cpp:21
TPZVec< TVar > fData
Frontal matrix data.
Definition: TPZFront.h:164
Contains the TPZFront class which implements decomposition process of the frontal matrix...
TPZVec< int64_t > fLocal
Front equation to each global equation.
Definition: TPZFront.h:152
struct para paralelizar a decomposicao da matriz
Definition: TPZFront.h:178
int NThreads()
num threads
Definition: TPZFront.h:202
STensorProductMTData * fProductMTData
Definition: TPZFront.h:294
int fWork
Definition: TPZFront.h:74
virtual void Resize(const int64_t newsize, const T &object)
Resizes the vector object.
Definition: pzmanvector.h:426
Contains the TPZEqnArray class which implements an equation array.
Abstract class implements storage and decomposition process of the frontal matrix. Frontal.
void FreeGlobal(int64_t global)
Sets the global equation as freed, allowing the space used by this equation to be used...
Definition: TPZFront.cpp:137
virtual void Resize(const int64_t newsize, const T &object)
Resizes the vector object reallocating the necessary storage, copying the existing objects to the new...
Definition: pzvec.h:373
void SymbolicAddKel(TPZVec< int64_t > &destinationindex)
Add a contribution of a stiffness matrix using the indexes to compute the frontwidth.
Definition: TPZFront.cpp:176
void Push(const T object)
Pushes a copy of the object on the stack.
Definition: pzstack.h:80
int nthreads
Definition: numatst.cpp:315
#define DebugStop()
Returns a message to user put a breakpoint in.
Definition: pzerror.h:20
Definition: pzmatrix.h:52
virtual int64_t NFree()
Returns the number of free equations.
Definition: TPZFront.cpp:313
int fExpandRatio
Expansion Ratio of frontal matrix.
Definition: TPZFront.h:167
int Local(int64_t global)
return a local index corresponding to a global equation number
Definition: TPZFront.cpp:151
int64_t fNextRigidBodyMode
Equation where rigid body modes can be stored.
Definition: TPZFront.h:158
void PrintGlobal(const char *name, std::ostream &out=std::cout)
Definition: TPZFront.cpp:69
A simple stack.
int64_t fFront
Actual front size.
Definition: TPZFront.h:155
void Print(const char *name, std::ostream &out) const
It prints TPZFront data.
Definition: TPZFront.cpp:93
int fMaxFront
Maximum size of the front.
Definition: TPZFront.h:136
void Fill(const T &copy, const int64_t from=0, const int64_t numelem=-1)
Will fill the elements of the vector with a copy object.
Definition: pzvec.h:460
void Reset(int64_t GlobalSize=0)
Definition: TPZFront.cpp:292
virtual void TensorProductIJ(int ithread, typename TPZFront< TVar >::STensorProductMTData *data)
void
Definition: TPZFront.cpp:327
int64_t NElements() const
Returns the number of elements of the vector.
Definition: pzvec.h:190
Contains the declaration of TPZFlopCounter class and TPZCounter struct.
void SymbolicDecomposeEquations(int64_t mineq, int64_t maxeq)
Decompose these equations in a symbolic way and store freed indexes in fFree.
Definition: TPZFront.cpp:190
int64_t NElements()
Static main used for testing.
Definition: TPZFront.cpp:307
TPZStack< int > fFree
Colection of already decomposed equations still on the front.
Definition: TPZFront.h:161
TPZManVector< int64_t > fGlobal
Global equation associated to each front equation.
Definition: TPZFront.h:145
#define PZError
Defines the output device to error messages and the DebugStop() function.
Definition: pzerror.h:15
Contains TPZSFMatrix class which implements a symmetric full matrix.