1 /* $Header: /var/cvs/mbdyn/mbdyn/mbdyn-1.0/libraries/libmbmath/schsolman.h,v 1.44 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 /* Solutore Schur */
33 
34 /*
35  * Copyright 1999-2017 Giuseppe Quaranta <quaranta@aero.polimi.it>
36  * Dipartimento di Ingegneria Aerospaziale - Politecnico di Milano
37  */
38 
39 #ifndef SCHSOLMAN_H
40 #define SCHSOLMAN_H
41 
42 #include "myassert.h"
43 #include "mynewmem.h"
44 #include "except.h"
45 #include "solman.h"
46 #ifdef USE_MPI
47 #include "ac/mpi.h"
48 #endif /* USE_MPI */
49 #include "schurmh.h"
50 
51 /* look ahead */
52 class NonlinearSolverTest;
53 
54 template <class T>
55 inline void
InitializeList(T * list,integer dim,T value)56 InitializeList(T* list, integer dim, T value)
57 {
58 	for (int i = 0; i < dim; i++) {
59 		list[i] = value;
60 	}
61 }
62 
63 /* SchurMatrixHandler - Begin */
64 
65 const int G_TAG = 100;
66 const int S_TAG = 200;
67 
68 class SchurSolutionManager : public SolutionManager {
69 public:
70 	class ErrGeneric : public MBDynErrBase {
71 	public:
ErrGeneric(MBDYN_EXCEPT_ARGS_DECL)72 		ErrGeneric(MBDYN_EXCEPT_ARGS_DECL) : MBDynErrBase(MBDYN_EXCEPT_ARGS_PASSTHRU) {};
73 	};
74 
75 
76 private:
77 
78 	/* communicator per lo scambio di messaggi */
79 #ifdef USE_MPI
80 	MPI::Intracomm SolvComm;
81 #endif /* USE_MPI */
82 	int MyRank, SolvCommSize;
83 
84 	integer iPrbmSize;          /* dimensioni totali del problema */
85 	integer iPrbmBlocks;        /* numero di problemi accoppiati, */
86                                     /* ciascuno di dimensione iPrbmSize  */
87 	integer iBlkSize;	    /* size di ciascun blocco */
88 	integer* pLocDofs;          /* lista dei dof locali */
89 	integer* pIntDofs;          /* lista dof interfaccia locale */
90 	int iLocVecDim, iIntVecDim; /* dim. vettori dof locali e interfacce */
91 	int* pRecvDim;              /* vettore dim. interfacce locali; master */
92 	int* pDispl;                /* vettore disp. x comunicazioni; master */
93 	integer* pDofsRecvdList;    /* lista dof da ricevere sul master;
94 				     * i dof del processo i iniziano
95 				     * da pDofsRecvdList[pDispl[i]] */
96 	integer* pSchurDofs;        /* lista totale dof interfaccia; master */
97 	int iSchurIntDim;           /* dimensioni matrice di schur; master */
98 
99 	integer* pGlbToLoc;         /* vett. di trasf. indici Glob->loc */
100 	integer* pSchGlbToLoc;      /* vett. trasf. idx Glob->Schur; master */
101 
102 	int* pBlockLenght;          /* str. di servizio x datatype; master */
103 #ifdef USE_MPI
104 	MPI::Aint* pTypeDsp;        /* str. di servizio x datatype; master */
105 	MPI::Datatype** ppNewTypes; /* datatype per la trasmissione dei vettori
106 				     * soluzione delle interfacce; master */
107 #endif /* USE_MPI */
108 	doublereal* pBuffer;        /* buffer di ricezione */
109 
110 	integer iWorkSpaceSize;
111 
112 
113 	SchurMatrixHandler* pMH;         /* handler della matrice globale */
114 	SchurVectorHandler* pRVH;        /* handler del vettore residuo globale */
115 	/* FIXME: do we need a SchurVectorHandler or is a MyVectorHandler enough? */
116 	VectorHandler* pSolVH;      /* handler del vettore soluzione globale */
117 
118 	MatrixHandler* pSchMH;      /*handler matrice delle interfacce */
119 	VectorHandler* pSchVH;  	   /* vettore delle interfacce  */
120 	VectorHandler* pSolSchVH;     /* soluzione problema delle interfacce */
121 	/* Vettori di lavoro x il Matrix Handler */
122 	MatrixHandler* pBMH;
123 	doublereal* pdCM;                 /* puntatore necessario per lo scambio delle schur locali */
124 	VectorHandler* prVH;
125 	VectorHandler* pgVH;
126 	VectorHandler* pSolrVH;
127 
128 #ifdef USE_MPI
129 	MPI::Request* pGSReq;               /* Array di request Send */
130 	MPI::Request* pGRReq;               /* Array di request Receive */
131 #endif /* USE_MPI */
132 
133 	SolutionManager* pLocalSM;           /* Solutore sparso locale */
134 	SolutionManager* pInterSM;          /* Solutore sparso locale */
135 
136 
137 	bool bNewMatrix;
138 public:
139 
140 	SchurSolutionManager(integer iSize,
141 			integer iBlocks,
142 			integer* pLocalDofs,
143 			int iDim1,
144 			integer* pInterfDofs,
145 			int iDim2,
146 			SolutionManager* pLSM,
147 			LinSol& ls);
148 
149 	virtual ~SchurSolutionManager(void);
150 
151 #ifdef DEBUG
152 	void IsValid(void) const;
153 #endif /* DEBUG */
154 
155 	/* Inizializza il gestore delle  matrici */
156 	void MatrReset(void);
157 
158 	/* Inizializzatore "speciale" */
159 	void MatrInitialize(void);
160 
161 	/* Risolve i blocchi chiamando il solutore */
162 	void Solve(void);
163 
164 	/* sposta il puntatore al vettore del residuo */
165 	doublereal *pdSetResVec(doublereal* pRes);
166 
167 	/* sposta il puntatore al vettore del residuo */
168 	doublereal *pdSetSolVec(doublereal* pSol);
169 
170 	/* Rende disponibile l'handler per la matrice */
171 	MatrixHandler* pMatHdl(void) const;
172 
173 	/* Rende disponibile l'handler per il termine noto */
174 	VectorHandler* pResHdl(void) const;
175 
176 	/* Rende disponibile l'handler per la soluzione */
177 	VectorHandler* pSolHdl(void) const;
178 
179 	void StartExchIntRes(void);
180 	void ComplExchIntRes(doublereal& d, const NonlinearSolverTest* t);
181 	void StartExchIntSol(void);
182 	void ComplExchIntSol(doublereal& d, const NonlinearSolverTest* t);
183 
184 private:
185 	void AssSchur(void);
186 
187 	void InitializeComm(void);
188 };
189 
190 #endif /* SCHSOLMAN_H */
191 
192