MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
schurmh.h
Go to the documentation of this file.
1 /* $Header: /var/cvs/mbdyn/mbdyn/mbdyn-1.0/libraries/libmbmath/schurmh.h,v 1.47 2017/01/12 14:43:54 masarati Exp $ */
2 /*
3  * MBDyn (C) is a multibody analysis code.
4  * http://www.mbdyn.org
5  *
6  * Copyright (C) 1996-2017
7  *
8  * Pierangelo Masarati <masarati@aero.polimi.it>
9  * Paolo Mantegazza <mantegazza@aero.polimi.it>
10  *
11  * Dipartimento di Ingegneria Aerospaziale - Politecnico di Milano
12  * via La Masa, 34 - 20156 Milano, Italy
13  * http://www.aero.polimi.it
14  *
15  * Changing this copyright notice is forbidden.
16  *
17  * This program is free software; you can redistribute it and/or modify
18  * it under the terms of the GNU General Public License as published by
19  * the Free Software Foundation (version 2 of the License).
20  *
21  *
22  * This program is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25  * GNU General Public License for more details.
26  *
27  * You should have received a copy of the GNU General Public License
28  * along with this program; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */
31 /*
32  * Copyright (C) 1999-2017
33  * Giuseppe Quaranta <quaranta@aero.polimi.it>
34  *
35  * Dipartimento di Ingegneria Aerospaziale - Politecnico di Milano
36  * via La Masa, 34 - 20156 Milano, Italy
37  * http://www.aero.polimi.it
38  *
39  */
40 /* Schur Matrix Handler */
41 
42 #ifndef SCHURMH_H
43 #define SCHURMH_H
44 
45 #include <myassert.h>
46 #include <mynewmem.h>
47 #include <except.h>
48 #include <spmapmh.h>
49 #include <solman.h>
50 #include <mbcomm.h>
51 
53 public:
54  class ErrGeneric : public MBDynErrBase {
55  public:
57  };
58 
59 protected:
60  integer LSize, ISize; /* dimensioni locali, interfacce */
67 
68  /* Tabella di conversione Global to Local
69  * creata da SchurSolutionManager
70  * i nodi di interfaccia hanno indice negativo
71  * per permetterne la distinzione */
73 
74  bool bExtpdE;
75 
76 public:
77  SchurMatrixHandler(int LocSize, int IntSize,
78  MatrixHandler* pBM,
79  integer* pGlobToLoc, doublereal* pdEv = 0);
80 
81  virtual ~SchurMatrixHandler(void);
82 
83 #ifdef DEBUG
84  /* Usata per il debug */
85  virtual void IsValid(void) const;
86 #endif /* DEBUG */
87 
88  virtual integer iGetNumRows(void) const;
89  virtual integer iGetNumCols(void) const;
90  MatrixHandler* GetBMat(void);
91  void SetBMat(MatrixHandler* pBM);
92  doublereal* GetCMat(void);
93 
94  /* Resetta la matrice */
95  virtual inline void Reset(void);
96 
97  /* Ridimensiona la matrice */
98  virtual void Resize(integer, integer);
99 
100  /* Resetta la matrice */
101  virtual inline void
102  MatEFCReset(void);
103 
104  /* Inserisce un coefficiente */
105  virtual inline void PutCoef(integer iRow, integer iCol,
106  const doublereal& dCoef);
107 
108  /* Incrementa un coefficiente - se non esiste lo crea */
109  virtual inline void IncCoef(integer iRow, integer iCol,
110  const doublereal& dCoef);
111 
112  /* Incrementa un coefficiente - se non esiste lo crea */
113  virtual inline void DecCoef(integer iRow, integer iCol,
114  const doublereal& dCoef);
115 
116  /* Restituisce un coefficiente - zero se non e' definito */
117  virtual inline const doublereal&
118  dGetCoef(integer iRow, integer iCol) const;
119 
120  virtual const doublereal&
121  operator()(integer iRow, integer iCol) const;
122 
123  virtual doublereal&
124  operator()(integer iRow, integer iCol);
125 
126  virtual inline doublereal* GetECol(const integer iCol) const;
127  virtual inline doublereal* GetEColSol(const integer iCol) const;
128 
129  /* calacola g - F*f e lo pone in g */
130  virtual inline VectorHandler&
131  CompNewg(VectorHandler& g, const VectorHandler& f) const;
132 
133  /* Calcola la matrice di schur locale C - F*E' e la memorizza in C */
134  virtual inline void CompLocSchur(void);
135 
136  /* Calcola f - E*g e lo pone in f */
137  virtual inline VectorHandler&
138  CompNewf(VectorHandler& f, const VectorHandler& g) const;
139 
140  virtual inline void PrintMatrix(void);
141 };
142 
143 inline doublereal*
145 {
146  return &pdE[LSize*iCol];
147 }
148 
149 inline doublereal*
151 {
152  return &pdE[LSize*iCol];
153 }
154 
155 inline void
157 {
158 #ifdef DEBUG
159  IsValid();
160 #endif /* DEBUG */
161 
162  pE->Reset();
163  pF->Reset();
164  pC->Reset();
165 }
166 
167 inline void
169 {
170 #ifdef DEBUG
171  IsValid();
172 #endif /* DEBUG */
173 
174  pB->Reset();
175  MatEFCReset();
176 }
177 
178 inline void
180  const doublereal& dCoef)
181 {
182 #ifdef DEBUG
183  IsValid();
184 #endif /* DEBUG */
185 
186  if (pGTL[iRow] > 0) {
187  if (pGTL[iCol] > 0) {
188  pB->PutCoef(pGTL[iRow], pGTL[iCol], dCoef);
189  return;
190 
191  } else if (pGTL[iCol] < 0) {
192  pE->PutCoef(pGTL[iRow] - (pGTL[iCol] + 1)*LSize, dCoef);
193  return;
194  }
195 
196  } else if (pGTL[iRow] < 0) {
197  if (pGTL[iCol] > 0) {
198  pF->PutCoef(-pGTL[iRow], pGTL[iCol], dCoef);
199  return;
200 
201  } else if (pGTL[iCol] < 0) {
202  pC->PutCoef(-pGTL[iRow] - (pGTL[iCol] + 1)*ISize, dCoef);
203  return;
204  }
205  }
206 
207 #ifdef USE_MPI
208  silent_cerr("SchurMatrixHandler::PutCoef() "
209  "Process(" << MBDynComm.Get_rank() << "): "
210  "trying to operate on nonlocal indices "
211  << iRow << "," << iCol << std::endl);
212 #else /* ! USE_MPI */
213  silent_cerr("SchurMatrixHandler::PutCoef() "
214  "trying to operate on nonlocal indices "
215  << iRow << "," << iCol << std::endl);
216 #endif /* ! USE_MPI */
217 
219 }
220 
221 inline void
223  const doublereal& dCoef)
224 {
225 #ifdef DEBUG
226  IsValid();
227 #endif /* DEBUG */
228 
229  if (pGTL[iRow] > 0) {
230  if (pGTL[iCol] > 0) {
231  pB->IncCoef(pGTL[iRow], pGTL[iCol], dCoef);
232  return;
233 
234  } else if (pGTL[iCol] < 0) {
235  pE->IncCoef(pGTL[iRow] - (pGTL[iCol] + 1)*LSize, dCoef);
236  return;
237  }
238 
239  } else if (pGTL[iRow] < 0) {
240  if (pGTL[iCol] > 0) {
241  pF->IncCoef(-pGTL[iRow], pGTL[iCol], dCoef);
242  return;
243 
244  } else if (pGTL[iCol] < 0) {
245  pC->IncCoef(-pGTL[iRow] - (pGTL[iCol] + 1)*ISize, dCoef);
246  return;
247  }
248  }
249 
250 #ifdef USE_MPI
251  silent_cerr("SchurMatrixHandler::IncCoef() "
252  "Process(" << MBDynComm.Get_rank() << "): "
253  "trying to operate on nonlocal indices "
254  << iRow << "," << iCol << std::endl);
255 #else /* ! USE_MPI */
256  silent_cerr("SchurMatrixHandler::IncCoef() "
257  "trying to operate on nonlocal indices "
258  << iRow << "," << iCol << std::endl);
259 #endif /* ! USE_MPI */
260 
262 }
263 
264 inline void
266  const doublereal& dCoef)
267 {
268 #ifdef DEBUG
269  IsValid();
270 #endif /* DEBUG */
271 
272  if (pGTL[iRow] > 0) {
273  if (pGTL[iCol] > 0) {
274  pB->DecCoef(pGTL[iRow], pGTL[iCol], dCoef);
275  return;
276 
277  } else if (pGTL[iCol] < 0) {
278  pE->DecCoef(pGTL[iRow] - (pGTL[iCol] + 1)*LSize, dCoef);
279  return;
280  }
281 
282  } else if (pGTL[iRow] < 0) {
283  if (pGTL[iCol] > 0) {
284  pF->DecCoef(-pGTL[iRow], pGTL[iCol], dCoef);
285  return;
286 
287  } else if (pGTL[iCol] < 0) {
288  pC->DecCoef(-pGTL[iRow] - (pGTL[iCol] + 1)*ISize, dCoef);
289  return;
290  }
291  }
292 
293 #ifdef USE_MPI
294  silent_cerr("SchurMatrixHandler::DecCoef() "
295  "Process(" << MBDynComm.Get_rank() << "): "
296  "trying to operate on nonlocal indices "
297  << iRow << "," << iCol << std::endl);
298 #else /* ! USE_MPI */
299  silent_cerr("SchurMatrixHandler::DecCoef() "
300  "trying to operate on nonlocal indices "
301  << iRow << "," << iCol << std::endl);
302 #endif /* ! USE_MPI */
303 
305 }
306 
307 inline const doublereal&
309 {
310 #ifdef DEBUG
311  IsValid();
312 #endif /* DEBUG */
313 
314  if (pGTL[iRow] > 0) {
315  if (pGTL[iCol] > 0) {
316  return pB->operator()(pGTL[iRow], pGTL[iCol]);
317 
318  } else if(pGTL[iCol] < 0) {
319  return pE->operator()(pGTL[iRow] - (pGTL[iCol] + 1)*LSize);
320  }
321 
322  } else if (pGTL[iRow] < 0) {
323  if (pGTL[iCol] > 0) {
324  return pF->operator()(-pGTL[iRow], pGTL[iCol]);
325 
326  } else if (pGTL[iCol] < 0) {
327  return pC->operator()(-pGTL[iRow] - (pGTL[iCol] + 1)*ISize);
328  }
329  }
330 
331 #ifdef USE_MPI
332  silent_cerr("SchurMatrixHandler::dGetCoef() "
333  "Process(" << MBDynComm.Get_rank() << "): "
334  "trying to operate on nonlocal indices "
335  << iRow << "," << iCol << std::endl);
336 #else /* ! USE_MPI */
337  silent_cerr("SchurMatrixHandler::dGetCoef() "
338  "trying to operate on nonlocal indices "
339  << iRow << "," << iCol << std::endl);
340 #endif /* ! USE_MPI */
341 
343 }
344 
345 inline doublereal&
347 {
348 #ifdef DEBUG
349  IsValid();
350 #endif /* DEBUG */
351 
352  if (pGTL[iRow] > 0) {
353  if (pGTL[iCol] > 0) {
354  return (*pB)(pGTL[iRow], pGTL[iCol]);
355 
356  } else if (pGTL[iCol] < 0) {
357  return (*pE)(pGTL[iRow] - (pGTL[iCol] + 1)*LSize);
358  }
359 
360  } else {
361  if (pGTL[iCol] > 0) {
362  return (*pF)(-pGTL[iRow], pGTL[iCol]);
363 
364  } else if (pGTL[iCol] < 0) {
365  return (*pC)(-pGTL[iRow] - (pGTL[iCol] + 1)*ISize);
366  }
367  }
368 
369 #ifdef USE_MPI
370  silent_cerr("SchurMatrixHandler::operator() "
371  "Process(" << MBDynComm.Get_rank() << "): "
372  "trying to operate on nonlocal indices "
373  << iRow << "," << iCol << std::endl);
374 #else /* ! USE_MPI */
375  silent_cerr("SchurMatrixHandler::operator() "
376  "trying to operate on nonlocal indices "
377  << iRow << "," << iCol << std::endl);
378 #endif /* ! USE_MPI */
379 
381 }
382 
383 inline const doublereal&
385 {
386 #ifdef DEBUG
387  IsValid();
388 #endif /* DEBUG */
389 
390  if (pGTL[iRow] > 0) {
391  if (pGTL[iCol] > 0) {
392  return pB->operator()(pGTL[iRow], pGTL[iCol]);
393 
394  } else if (pGTL[iCol] < 0) {
395  return pE->operator()(pGTL[iRow] - (pGTL[iCol] + 1)*LSize);
396  }
397 
398  } else {
399  if (pGTL[iCol] > 0) {
400  return pF->operator()(-pGTL[iRow], pGTL[iCol]);
401 
402  } else if (pGTL[iCol] < 0) {
403  return pC->operator()(-pGTL[iRow] - (pGTL[iCol] + 1)*ISize);
404  }
405  }
406 
407 #ifdef USE_MPI
408  silent_cerr("SchurMatrixHandler::operator() "
409  "Process(" << MBDynComm.Get_rank() << "): "
410  "trying to operate on nonlocal indices "
411  << iRow << "," << iCol << std::endl);
412 #else /* ! USE_MPI */
413  silent_cerr("SchurMatrixHandler::operator() "
414  "trying to operate on nonlocal indices "
415  << iRow << "," << iCol << std::endl);
416 #endif /* ! USE_MPI */
417 
419 }
420 
421 inline VectorHandler&
423 {
424 #ifdef DEBUG
425  ASSERT(f.iGetSize() == LSize);
426  ASSERT(g.iGetSize() == ISize);
427 #endif /* DEBUG */
428 
429  pF->MatVecDecMul(g, f);
430 
431  return g;
432 }
433 
434 /* Calcola le Schur locali */
435 inline void
437 {
438  for (int j = 0; j < ISize; j++) {
439  int iColc = j * ISize;
440  int iCole = j * LSize;
441 
442  for (int k = 0; k < LSize; k++) {
443  for (int i = 0; i < ISize; i++) {
444  pdC[i + iColc] -=
445  pF->operator()(i + 1, k + 1) * pdE[k + iCole];
446  }
447  }
448  }
449 }
450 
451 inline VectorHandler&
453 {
454 #ifdef DEBUG
455  ASSERT(f.iGetSize() == LSize);
456  ASSERT(g.iGetSize() == ISize);
457 #endif /* DEBUG */
458 
459  for (int j = 0; j < ISize; j++) {
460  int iColx = j * LSize;
461  for (int i = 0; i < LSize; i++) {
462  if (pdE[i + iColx] != 0) {
463  f.DecCoef(i + 1, pdE[i + iColx]*g(j + 1));
464  }
465  }
466  }
467  return f;
468 }
469 
470 inline void
472 {
473  silent_cout("Schur Matrix " << std::endl);
474 
475  for (int i = 0; i < LSize; i++) {
476  for (int j = 0; j < LSize; j++) {
477  silent_cout(pB->operator()(i + 1, j + 1) << " ");
478  }
479 
480  for (int j = 0; j < ISize; j++) {
481  silent_cout(pdE[i + j*LSize] << " ");
482  }
483  silent_cout(std::endl);
484  }
485 
486  for (int i = 0; i < ISize; i++) {
487  for (int j = 0; j < LSize; j++) {
488  silent_cout(pF->operator()(i + 1, j + 1) << " ");
489  }
490 
491  for (int j = 0; j < ISize; j++) {
492  silent_cout(pdC[i + j*ISize] << " ");
493  }
494  silent_cout(std::endl);
495  }
496 }
497 
498 /* SchurMatrixHandler - End */
499 
500 /* SchurVectorHandler - Start */
501 
503 public:
504  class ErrGeneric: public MBDynErrBase {
505  public:
507  };
508 
509 private:
513  bool bExtpIV;
515 
516 public:
517  SchurVectorHandler(int LocSize, int IntSize,
518  VectorHandler* pLocVec,
519  integer* pGlobToLoc);
520  SchurVectorHandler(int LocSize, int IntSize,
521  VectorHandler* pLocV,
522  VectorHandler* pIntV,
523  integer* pGlobToLoc);
524  ~SchurVectorHandler(void);
525 
526 #ifdef DEBUG
527  /* Usata per il debug */
528  void IsValid(void) const;
529 #endif /* DEBUG */
530 
531  /* restituisce il puntatore al vettore */
532  inline doublereal* pdGetVec(void) const;
533 
534  /* restituisce le dimensioni del vettore */
535  inline integer iGetSize(void) const;
536 
537  virtual void Reset(void);
538 
539  inline void Resize(integer iNewSize);
540 
541  inline VectorHandler* GetIVec(void);
542  inline VectorHandler* GetLVec(void);
543 
544  inline void PutCoef(integer iRow, const doublereal& dCoef);
545  inline void IncCoef(integer iRow, const doublereal& dCoef);
546  inline void DecCoef(integer iRow, const doublereal& dCoef);
547  inline const doublereal& dGetCoef(integer iRow) const;
548 
549  inline const doublereal& operator () (integer iRow) const;
550  inline doublereal& operator () (integer iRow);
551 
552  inline void PrintVector(void);
553 };
554 
555 /* restituisce il puntatore al vettore */
556 inline doublereal*
558 {
559  silent_cerr("You shouldn't have asked for "
560  "the internal pointer of a SchurVectorHandler"
561  << std::endl);
562  return pLV->pdGetVec();
563 }
564 
565 /* restituisce le dimensioni del vettore */
566 inline integer
568 {
569  return LSize + ISize;
570 }
571 
572 inline void
574 {
575  silent_cerr("Why are you trying to resize a SchurVector ???? "
576  << "No Operation Performed!!" << std::endl);
577 }
578 
579 /* assegna 0. a tutti gli elementi del vettore */
580 inline void
582 {
583  pLV->Reset();
584  pIV->Reset();
585 }
586 
587 inline VectorHandler*
589 {
590  return pIV;
591 }
592 
593 inline VectorHandler*
595 {
596  return pLV;
597 }
598 
599 inline void
601 {
602 #ifdef DEBUG
603  IsValid();
604 #endif /* DEBUG */
605 
606  if (pGTL[iRow] > 0) {
607  pLV->PutCoef(pGTL[iRow], dCoef);
608 
609  } else if (pGTL[iRow] < 0 ) {
610  pIV->PutCoef(-pGTL[iRow], dCoef);
611 
612  } else {
613 #ifdef USE_MPI
614  silent_cerr("SchurVectorHandler::PutCoef() "
615  "Process(" << MBDynComm.Get_rank() << "): "
616  "trying to operate on nonlocal index "
617  << iRow << std::endl);
618 #else /* ! USE_MPI */
619  silent_cerr("SchurVectorHandler::PutCoef() "
620  "trying to operate on nonlocal index "
621  << iRow << std::endl);
622 #endif /* ! USE_MPI */
624  }
625  return;
626 }
627 
628 inline void
630 {
631 #ifdef DEBUG
632  IsValid();
633 #endif /* DEBUG */
634 
635  if (pGTL[iRow] > 0) {
636  pLV->IncCoef(pGTL[iRow], dCoef);
637 
638  } else if (pGTL[iRow] < 0) {
639  pIV->IncCoef(-pGTL[iRow], dCoef);
640 
641  } else {
642 #ifdef USE_MPI
643  silent_cerr("SchurVectorHandler::IncCoef "
644  "Process(" << MBDynComm.Get_rank() << "): "
645  "trying to operate on nonlocal index "
646  << iRow << std::endl);
647 #else /* ! USE_MPI */
648  silent_cerr("SchurVectorHandler::IncCoef "
649  "trying to operate on nonlocal index "
650  << iRow << std::endl);
651 #endif /* ! USE_MPI */
653  }
654  return;
655 }
656 
657 inline void
659 {
660 #ifdef DEBUG
661  IsValid();
662 #endif /* DEBUG */
663 
664  if (pGTL[iRow] > 0) {
665  pLV->DecCoef(pGTL[iRow], dCoef);
666 
667  } else if (pGTL[iRow] < 0) {
668  pIV->DecCoef(-pGTL[iRow], dCoef);
669 
670  } else {
671 #ifdef USE_MPI
672  silent_cerr("SchurVectorHandler::DecCoef "
673  "Process(" << MBDynComm.Get_rank() << "): "
674  "trying to operate on nonlocal index "
675  << iRow << std::endl);
676 #else /* ! USE_MPI */
677  silent_cerr("SchurVectorHandler::DecCoef "
678  "trying to operate on nonlocal index "
679  << iRow << std::endl);
680 #endif /* ! USE_MPI */
682  }
683  return;
684 }
685 
686 inline const doublereal&
688 {
689 #ifdef DEBUG
690  IsValid();
691 #endif /* DEBUG */
692 
693  if (pGTL[iRow] > 0) {
694  return pLV->operator()(pGTL[iRow]);
695 
696  } else if (pGTL[iRow] < 0) {
697  return pIV->operator()(-pGTL[iRow]);
698 
699  } else {
700 #ifdef USE_MPI
701  silent_cerr("SchurVectorHandler::dGetCoef "
702  "Process(" << MBDynComm.Get_rank() << "): "
703  "trying to operate on nonlocal index "
704  << iRow << std::endl);
705 #else /* ! USE_MPI */
706  silent_cerr("SchurVectorHandler::dGetCoef "
707  "trying to operate on nonlocal index "
708  << iRow << std::endl);
709 #endif /* ! USE_MPI */
710  return Zero1;
711  }
712 }
713 
714 inline const doublereal&
716 {
717 #ifdef DEBUG
718  IsValid();
719 #endif /* DEBUG */
720 
721  if (pGTL[iRow] > 0) {
722  return pLV->operator()(pGTL[iRow]);
723 
724  } else if (pGTL[iRow] < 0) {
725  return pIV->operator()(-pGTL[iRow]);
726 
727  } else {
728 #ifdef USE_MPI
729  silent_cerr("SchurVectorHandler::operator()"
730  "Process(" << MBDynComm.Get_rank() << "): "
731  "trying to operate on nonlocal index "
732  << iRow << std::endl);
733 #else /* ! USE_MPI */
734  silent_cerr("SchurVectorHandler::operator()"
735  "trying to operate on nonlocal index "
736  << iRow << std::endl);
737 #endif /* ! USE_MPI */
738  return Zero1;
739  }
740 }
741 
742 inline doublereal&
744 {
745  silent_cerr("SchurVectorHandler::operator() "
746  "cannot be used on nonlocal index "
747  << iRow << std::endl);
748 
750 }
751 
752 inline void
754 {
755  silent_cout("Schur Vector " << std::endl);
756 
757  for (int j = 0; j < LSize; j++) {
758  silent_cout(pLV->operator()(j + 1) << " " << std::endl);
759  }
760 
761  for (int j = 0; j < ISize; j++) {
762  silent_cout(pIV->operator()(j + 1) << " " << std::endl);
763  }
764 }
765 
766 /* SchurVectorHandler - End */
767 
768 
769 /* SchurMatrixHandlerUm - begin */
770 
772 public:
773  class ErrGeneric : public MBDynErrBase {
774  public:
776  };
777 
778 
779 private:
782  bool Eflag;
783 
784 public:
785  SchurMatrixHandlerUm(int LocSize, int IntSize,
786  MatrixHandler* pBM,
787  integer* pGlobToLoc);
788  ~SchurMatrixHandlerUm(void);
789 
790  /* Resetta le matrici E F e C */
791  inline void MatEFCReset(void);
792 
793  /* Resetta la matrice */
794  inline void Reset(void);
795 
796  /* Inserisce un coefficiente */
797  inline void PutCoef(integer iRow, integer iCol,
798  const doublereal& dCoef);
799 
800  /* Incrementa un coefficiente - se non esiste lo crea */
801  inline void IncCoef(integer iRow, integer iCol,
802  const doublereal& dCoef);
803 
804  /* Incrementa un coefficiente - se non esiste lo crea */
805  inline void DecCoef(integer iRow, integer iCol,
806  const doublereal& dCoef);
807 
808  /* Restituisce un coefficiente - zero se non e' definito */
809  inline const doublereal& dGetCoef(integer iRow, integer iCol) const;
810 
811  inline doublereal* GetECol(const integer iCol) const;
812 
813  inline doublereal* GetEColSol(const integer iCol) const;
814 
815  /* Calcola la matrice di schur locale C-F*E' e la memorizza in C */
816  inline void CompLocSchur(void);
817 
818  /* Calcola f - E*g e lo pone in f */
819  inline VectorHandler&
820  CompNewf(VectorHandler& f, const VectorHandler& g) const;
821 
822  inline void PrintMatrix(void);
823 };
824 
825 inline void
827 {
828 #ifdef DEBUG
829  IsValid();
830 #endif /* DEBUG */
831 
832  Eflag = true;
833  for (int i = 0; i < LSize*(ISize + 1); i++) {
834  pdEs[i] = 0.;
835  }
836  pF->Reset();
837  pC->Reset();
838 }
839 
841 {
842 #ifdef DEBUG
843  IsValid();
844 #endif /* DEBUG */
845 
846  Eflag = true;
847  pB->Reset();
848  MatEFCReset();
849 }
850 
851 inline void
853  const doublereal& dCoef)
854 {
855 #ifdef DEBUG
856  IsValid();
857 #endif /* DEBUG */
858 
859  if (pGTL[iRow] > 0) {
860  if (pGTL[iCol] > 0) {
861  pB->PutCoef(pGTL[iRow], pGTL[iCol], dCoef);
862  return;
863 
864  } else if (pGTL[iCol] < 0 ) {
865  if (Eflag) {
866  pE->PutCoef(pGTL[iRow] - (pGTL[iCol] + 1)*LSize, dCoef);
867 
868  } else {
869  pEs->PutCoef(pGTL[iRow] - (pGTL[iCol] + 1)*LSize, dCoef);
870  }
871  return;
872  }
873 
874  } else if (pGTL[iRow] < 0 ) {
875  if (pGTL[iCol] > 0) {
876  pF->PutCoef(-pGTL[iRow], pGTL[iCol], dCoef);
877  return;
878 
879  } else if (pGTL[iCol] < 0) {
880  pC->PutCoef(-pGTL[iRow] - (pGTL[iCol] + 1)*ISize, dCoef);
881  return;
882  }
883  }
884 
885 #ifdef USE_MPI
886  silent_cerr("SchurMatrixHandlerUm::PutCoef() "
887  "Process(" << MBDynComm.Get_rank() << "): "
888  "trying to operate on nonlocal indices "
889  << iRow << "," << iCol << std::endl);
890 #else /* ! USE_MPI */
891  silent_cerr("SchurMatrixHandlerUm::PutCoef() "
892  "trying to operate on nonlocal indices "
893  << iRow << "," << iCol << std::endl);
894 #endif /* ! USE_MPI */
895 
897 }
898 
899 inline void
901  const doublereal& dCoef)
902 {
903 #ifdef DEBUG
904  IsValid();
905 #endif /* DEBUG */
906 
907  if (pGTL[iRow] > 0) {
908  if (pGTL[iCol] > 0) {
909  pB->IncCoef(pGTL[iRow], pGTL[iCol], dCoef);
910  return;
911 
912  } else if (pGTL[iCol] < 0) {
913  if (Eflag) {
914  pE->IncCoef(pGTL[iRow] - (pGTL[iCol] + 1)*LSize, dCoef);
915 
916  } else {
917  pEs->IncCoef(pGTL[iRow] - (pGTL[iCol] + 1)*LSize, dCoef);
918  }
919  return;
920  }
921 
922  } else if (pGTL[iRow] < 0) {
923  if (pGTL[iCol] > 0) {
924  pF->IncCoef(-pGTL[iRow], pGTL[iCol], dCoef);
925  return;
926 
927  } else if (pGTL[iCol] < 0) {
928  pC->IncCoef(-pGTL[iRow] - (pGTL[iCol] + 1)*ISize, dCoef);
929  return;
930  }
931  }
932 
933 #ifdef USE_MPI
934  silent_cerr("SchurMatrixHandlerUm::IncCoef() "
935  "Process(" << MBDynComm.Get_rank() << "): "
936  "trying to operate on nonlocal indices "
937  << iRow << "," << iCol << std::endl);
938 #else /* ! USE_MPI */
939  silent_cerr("SchurMatrixHandlerUm::IncCoef() "
940  "trying to operate on nonlocal indices "
941  << iRow << "," << iCol << std::endl);
942 #endif /* ! USE_MPI */
943 
945 }
946 
947 inline void
949  const doublereal& dCoef)
950 {
951 #ifdef DEBUG
952  IsValid();
953 #endif /* DEBUG */
954 
955  if (pGTL[iRow] > 0) {
956  if (pGTL[iCol] > 0) {
957  pB->DecCoef(pGTL[iRow], pGTL[iCol], dCoef);
958  return;
959 
960  } else if (pGTL[iCol] < 0) {
961  if (Eflag) {
962  pE->DecCoef(pGTL[iRow] - (pGTL[iCol] + 1)*LSize, dCoef);
963 
964  } else {
965  pEs->DecCoef(pGTL[iRow] - (pGTL[iCol] + 1)*LSize, dCoef);
966  }
967  return;
968  }
969 
970  } else if (pGTL[iRow] < 0) {
971  if (iCol > 0) {
972  pF->DecCoef(-pGTL[iRow], pGTL[iCol], dCoef);
973  return;
974 
975  } else if (iCol < 0) {
976  pC->DecCoef(-pGTL[iRow] - (pGTL[iCol] + 1)*ISize, dCoef);
977  return;
978  }
979  }
980 
981 #ifdef USE_MPI
982  silent_cerr("SchurMatrixHandlerUm::DecCoef() "
983  "Process(" << MBDynComm.Get_rank() << "): "
984  "trying to operate on nonlocal indices "
985  << iRow << "," << iCol << std::endl);
986 #else /* ! USE_MPI */
987  silent_cerr("SchurMatrixHandlerUm::DecCoef() "
988  "trying to operate on nonlocal indices "
989  << iRow << "," << iCol << std::endl);
990 #endif /* ! USE_MPI */
991 
993 }
994 
995 inline const doublereal&
997 {
998 #ifdef DEBUG
999  IsValid();
1000 #endif /* DEBUG */
1001 
1002  if (pGTL[iRow] > 0) {
1003  if (pGTL[iCol] > 0) {
1004  return pB->operator()(pGTL[iRow], pGTL[iCol]);
1005 
1006  } else if (pGTL[iCol] < 0) {
1007  if (Eflag) {
1008  return pE->operator()(pGTL[iRow] - (pGTL[iCol] + 1)*LSize);
1009 
1010  } else {
1011  return pEs->operator()(pGTL[iRow] - (pGTL[iCol] + 1)*LSize);
1012  }
1013  }
1014 
1015  } else if (pGTL[iRow] < 0) {
1016  if (pGTL[iCol] > 0) {
1017  return pF->operator()(-pGTL[iRow], pGTL[iCol]);
1018 
1019  } else if (pGTL[iCol] < 0) {
1020  return pC->operator()(-pGTL[iRow] - (pGTL[iCol] + 1)*ISize);
1021  }
1022  }
1023 
1024 #ifdef USE_MPI
1025  silent_cerr("SchurMatrixHandlerUm::dGetCoef() "
1026  "Process(" << MBDynComm.Get_rank() << "): "
1027  "trying to operate on nonlocal indices "
1028  << iRow << "," << iCol << std::endl);
1029 #else /* ! USE_MPI */
1030  silent_cerr("SchurMatrixHandlerUm::dGetCoef() "
1031  "trying to operate on nonlocal indices "
1032  << iRow << "," << iCol << std::endl);
1033 #endif /* ! USE_MPI */
1034 
1036 }
1037 
1038 inline doublereal*
1040 {
1041  return &pdE[iCol*LSize];
1042 }
1043 
1044 inline doublereal*
1046 {
1047  return &pdEs[iCol*LSize];
1048 }
1049 
1050 /* Calcola le Schur locali */
1051 inline void
1053 {
1054  Eflag = false;
1055  for (int j = 0; j < ISize; j++) {
1056  int iColc = j * ISize;
1057  int iCole = j * LSize;
1058 
1059  for (int k = 0; k < LSize; k++) {
1060  for (int i = 0; i < ISize; i++) {
1061  pdC[i + iColc] -=
1062  pF->operator()(i + 1, k + 1) * pdEs[k + iCole];
1063  }
1064  }
1065  }
1066 }
1067 
1068 inline VectorHandler&
1070 {
1071 #ifdef DEBUG
1072  ASSERT(f.iGetSize() == LSize);
1073  ASSERT(g.iGetSize() == ISize);
1074 #endif /* DEBUG */
1075 
1076  for (int j = 0; j < ISize; j++) {
1077  int iColx = j * LSize;
1078 
1079  for (int i = 0; i < LSize; i++) {
1080  if (pdEs[i + iColx] != 0) {
1081  f.DecCoef(i + 1, pdEs[i + iColx]*g(j + 1));
1082  }
1083  }
1084  }
1085  return f;
1086 }
1087 
1088 inline void
1090 {
1091  silent_cout("Schur Matrix " << std::endl);
1092 
1093  for (int i = 0; i < LSize; i++) {
1094  for (int j = 0; j < LSize; j++) {
1095  silent_cout(pB->operator()(i + 1, j + 1) << " ");
1096  }
1097 
1098  for (int j = 0; j < ISize; j++) {
1099  if (Eflag) {
1100  silent_cout(pdE[i + j*LSize] << " ");
1101  } else {
1102  silent_cout(pdEs[i + j*LSize] << " ");
1103  }
1104  }
1105  silent_cout(std::endl);
1106  }
1107 
1108  for (int i = 0; i < ISize; i++) {
1109  for (int j = 0;j < LSize; j++) {
1110  silent_cout(pF->operator()(i + 1, j + 1) << " ");
1111  }
1112 
1113  for (int j = 0; j < ISize; j++) {
1114  silent_cout(pdC[i + j*ISize] << " ");
1115  }
1116  silent_cout(std::endl);
1117  }
1118 }
1119 
1120 /* SchurMatrixHandlerUm - End */
1121 
1122 #endif /* SCHURMH_H */
1123 
integer ISize
Definition: schurmh.h:60
const doublereal & dGetCoef(integer iRow) const
Definition: schurmh.h:687
virtual void Reset(void)=0
doublereal * GetCMat(void)
Definition: schurmh.cc:77
void DecCoef(integer iRow, const doublereal &dCoef)
Definition: schurmh.h:658
SchurMatrixHandler(int LocSize, int IntSize, MatrixHandler *pBM, integer *pGlobToLoc, doublereal *pdEv=0)
Definition: schurmh.cc:82
virtual doublereal * GetECol(const integer iCol) const
Definition: schurmh.h:144
VectorHandler * pLV
Definition: schurmh.h:511
virtual void MatEFCReset(void)
Definition: schurmh.h:156
SpMapMatrixHandler * pF
Definition: schurmh.h:64
doublereal * GetEColSol(const integer iCol) const
Definition: schurmh.h:1045
void PutCoef(integer iRow, const doublereal &dCoef)
Definition: schurmh.h:600
virtual void IncCoef(integer iRow, integer iCol, const doublereal &dCoef)
Definition: mh.cc:374
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
virtual doublereal * pdGetVec(void) const =0
ErrGeneric(MBDYN_EXCEPT_ARGS_DECL)
Definition: schurmh.h:506
VectorHandler * GetIVec(void)
Definition: schurmh.h:588
#define MBDYN_EXCEPT_ARGS_PASSTHRU
Definition: except.h:55
void DecCoef(integer ix, integer iy, const doublereal &inc)
Definition: spmapmh.h:170
MatrixHandler * GetBMat(void)
Definition: schurmh.cc:62
doublereal * pdE
Definition: schurmh.h:63
virtual void IncCoef(integer iRow, integer iCol, const doublereal &dCoef)
Definition: schurmh.h:222
integer * pGTL
Definition: schurmh.h:72
virtual void IncCoef(integer iRow, const doublereal &dCoef)=0
VectorHandler * GetLVec(void)
Definition: schurmh.h:594
virtual void DecCoef(integer iRow, integer iCol, const doublereal &dCoef)
Definition: mh.cc:379
virtual void Reset(void)
Definition: schurmh.h:168
#define MBDYN_EXCEPT_ARGS_DECL
Definition: except.h:43
virtual VectorHandler & CompNewf(VectorHandler &f, const VectorHandler &g) const
Definition: schurmh.h:452
integer * pGTL
Definition: schurmh.h:514
virtual void CompLocSchur(void)
Definition: schurmh.h:436
virtual VectorHandler & CompNewg(VectorHandler &g, const VectorHandler &f) const
Definition: schurmh.h:422
doublereal * pdEs
Definition: schurmh.h:780
virtual void Resize(integer, integer)
Definition: schurmh.cc:152
void CompLocSchur(void)
Definition: schurmh.h:1052
void Resize(integer iNewSize)
Definition: schurmh.h:573
virtual integer iGetSize(void) const =0
virtual ~SchurMatrixHandler(void)
Definition: schurmh.cc:116
virtual VectorHandler & MatVecDecMul(VectorHandler &out, const VectorHandler &in) const
Definition: mh.cc:362
virtual doublereal * GetEColSol(const integer iCol) const
Definition: schurmh.h:150
virtual void PutCoef(integer iRow, const doublereal &dCoef)
Definition: vh.h:261
integer iGetSize(void) const
Definition: schurmh.h:567
virtual void Reset(void)=0
virtual integer iGetNumRows(void) const
Definition: schurmh.cc:49
~SchurMatrixHandlerUm(void)
Definition: schurmh.cc:227
void IncCoef(integer iRow, const doublereal &dCoef)
Definition: schurmh.h:629
void PrintVector(void)
Definition: schurmh.h:753
virtual void DecCoef(integer iRow, const doublereal &dCoef)=0
const doublereal & dGetCoef(integer iRow, integer iCol) const
Definition: schurmh.h:996
virtual void Reset(void)
Definition: schurmh.h:581
void Reset(void)
Definition: spmapmh.cc:161
ErrGeneric(MBDYN_EXCEPT_ARGS_DECL)
Definition: schurmh.h:56
void Reset(void)
Definition: schurmh.h:840
MyVectorHandler * pC
Definition: schurmh.h:65
SchurMatrixHandlerUm(int LocSize, int IntSize, MatrixHandler *pBM, integer *pGlobToLoc)
Definition: schurmh.cc:211
virtual void DecCoef(integer iRow, const doublereal &dCoef)
Definition: vh.h:291
doublereal * GetECol(const integer iCol) const
Definition: schurmh.h:1039
VectorHandler & CompNewf(VectorHandler &f, const VectorHandler &g) const
Definition: schurmh.h:1069
virtual const doublereal & dGetCoef(integer iRow, integer iCol) const
Definition: schurmh.h:308
virtual integer iGetNumCols(void) const
Definition: schurmh.cc:55
void PutCoef(integer iRow, integer iCol, const doublereal &dCoef)
Definition: schurmh.h:852
virtual void PutCoef(integer iRow, integer iCol, const doublereal &dCoef)
Definition: mh.cc:384
const doublereal Zero1
void MatEFCReset(void)
Definition: schurmh.h:826
MyVectorHandler * pEs
Definition: schurmh.h:781
#define ASSERT(expression)
Definition: colamd.c:977
doublereal * pdGetVec(void) const
Definition: schurmh.h:557
virtual void PutCoef(integer iRow, const doublereal &dCoef)=0
virtual void Reset(void)
Definition: vh.cc:459
void PrintMatrix(void)
Definition: schurmh.h:1089
virtual const doublereal & operator()(integer iRow, integer iCol) const
Definition: schurmh.h:384
MyVectorHandler * pE
Definition: schurmh.h:62
doublereal * pdC
Definition: schurmh.h:66
void PutCoef(integer ix, integer iy, const doublereal &val)
Definition: spmapmh.h:187
void IncCoef(integer iRow, integer iCol, const doublereal &dCoef)
Definition: schurmh.h:900
MatrixHandler * pB
Definition: schurmh.h:61
virtual void PutCoef(integer iRow, integer iCol, const doublereal &dCoef)
Definition: schurmh.h:179
virtual void DecCoef(integer iRow, integer iCol, const doublereal &dCoef)
Definition: schurmh.h:265
void SetBMat(MatrixHandler *pBM)
Definition: schurmh.cc:69
VectorHandler * pIV
Definition: schurmh.h:512
double doublereal
Definition: colamd.c:52
long int integer
Definition: colamd.c:51
const doublereal & operator()(integer iRow) const
Definition: schurmh.h:715
integer LSize
Definition: schurmh.h:60
virtual void PrintMatrix(void)
Definition: schurmh.h:471
SchurVectorHandler(int LocSize, int IntSize, VectorHandler *pLocVec, integer *pGlobToLoc)
Definition: schurmh.cc:162
ErrGeneric(MBDYN_EXCEPT_ARGS_DECL)
Definition: schurmh.h:775
void DecCoef(integer iRow, integer iCol, const doublereal &dCoef)
Definition: schurmh.h:948
void IncCoef(integer ix, integer iy, const doublereal &inc)
Definition: spmapmh.h:153
~SchurVectorHandler(void)
Definition: schurmh.cc:190
virtual void IncCoef(integer iRow, const doublereal &dCoef)
Definition: vh.h:278