MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
dirccmh.cc
Go to the documentation of this file.
1 /* $Header: /var/cvs/mbdyn/mbdyn/mbdyn-1.0/libraries/libmbmath/dirccmh.cc,v 1.26 2017/01/12 14:43:53 masarati Exp $ */
2 /*
3  * MBDyn (C) is a multibody analysis code.
4  * http://www.mbdyn.org
5  *
6  * Copyright (C) 2003-2017
7  *
8  * This code is a partial merge of HmFe and MBDyn.
9  *
10  * Pierangelo Masarati <masarati@aero.polimi.it>
11  * Paolo Mantegazza <mantegazza@aero.polimi.it>
12  * Marco Morandini <morandini@aero.polimi.it>
13  *
14  * Dipartimento di Ingegneria Aerospaziale - Politecnico di Milano
15  * via La Masa, 34 - 20156 Milano, Italy
16  * http://www.aero.polimi.it
17  *
18  * Changing this copyright notice is forbidden.
19  *
20  * This program is free software; you can redistribute it and/or modify
21  * it under the terms of the GNU General Public License as published by
22  * the Free Software Foundation (version 2 of the License).
23  *
24  *
25  * This program is distributed in the hope that it will be useful,
26  * but WITHOUT ANY WARRANTY; without even the implied warranty of
27  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28  * GNU General Public License for more details.
29  *
30  * You should have received a copy of the GNU General Public License
31  * along with this program; if not, write to the Free Software
32  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33  */
34 
35 #include "mbconfig.h" /* This goes first in every *.c,*.cc file */
36 
37 #include "spmapmh.h"
38 #include "dirccmh.h"
39 
40 template <int off>
42  const std::vector<integer>& i,
43  const std::vector<integer>& p)
44 : CompactSparseMatrixHandler_tpl<off>(p.size() - 1, p.size() - 1, x, i, p),
45  pindices(SparseMatrixHandler::iGetNumCols() + 1),
46 indices(SparseMatrixHandler::iGetNumRows()*SparseMatrixHandler::iGetNumCols(), -1)
47 {
48  for (integer col = 1; col <= SparseMatrixHandler::iGetNumCols(); col++) {
49  pindices[col] = &indices[(col - 1)*SparseMatrixHandler::iGetNumRows()] - 1;
50 
51  integer row_begin = p[col - 1] - off, row_end = p[col] - off;
52 
53  for (integer r = row_begin; r < row_end; r++) {
54  pindices[col][i[r] - off + 1] = r;
55  }
56  }
57 }
58 
59 template <int off>
61 {
62  NO_OP;
63 }
64 
65 /* used by MultiThreadDataManager to duplicate the storage array
66  * while preserving the CC indices */
67 template <int off>
70 {
71  std::vector<doublereal> *pax =
72  new std::vector<doublereal>(CompactSparseMatrixHandler_tpl<off>::Ax);
76  p->bMatDuplicate = true;
77 
78  return p;
79 }
80 
81 template <int off>
82 void
84 {
85  silent_cerr("DirCColMatrixHandler<off>::Resize called" << std::endl);
87 }
88 
89 /* Estrae una colonna da una matrice */
90 template <int off>
93 {
94  /*
95  * Note: we assume out has been reset
96  */
97 
98  if (icol > SparseMatrixHandler::iGetNumCols()) {
100  }
101 
102  integer idx = CompactSparseMatrixHandler_tpl<off>::Ap[icol - 1] - off;
104 
105  for ( ; idx < idxe; idx++) {
106  out(CompactSparseMatrixHandler_tpl<off>::Ai[idx] - off + 1) =
108  }
109 
110  return out;
111 }
112 
113 /* Moltiplica per uno scalare e somma a una matrice */
114 template <int off>
117  integer drow, integer dcol) const
118 {
119  silent_cerr("DirCColMatrixHandler<off>::MulAndSumWithShift called"
120  << std::endl);
122  if ((out.iGetNumCols() < SparseMatrixHandler::iGetNumCols() + dcol)
123  || (out.iGetNumRows() < SparseMatrixHandler::iGetNumRows() + drow))
124  {
125  silent_cerr("Assertion fault "
126  "in DirCColMatrixHandler<off>::MulAndSumWithShift"
127  << std::endl);
129  }
130  drow = drow + 1;
131  for (integer col = 0; col < SparseMatrixHandler::iGetNumCols(); col++) {
134  integer newcol = col + dcol + 1;
135  for (; idx < idxe; idx++) {
136  out.IncCoef(CompactSparseMatrixHandler_tpl<off>::Ai[idx] - off + drow,
138  }
139  }
140  return out;
141 }
142 
143 template <int off>
146  std::vector<bool> b,
147  doublereal s,
148  integer drow,
149  integer dcol) const
150 {
151  silent_cerr("DirCColMatrixHandler<off>::FakeThirdOrderMulAndSumWithShift "
152  "called" << std::endl);
154  if ((out.iGetNumCols() < SparseMatrixHandler::iGetNumCols() + dcol)
155  || (out.iGetNumRows() < SparseMatrixHandler::iGetNumRows() + drow))
156  {
157  silent_cerr("Assertion fault "
158  "in DirCColMatrixHandler<off>::MulAndSumWithShift"
159  << std::endl);
161  }
162  drow = drow + 1;
163  for (integer col = 0; col < SparseMatrixHandler::iGetNumCols(); col++) {
165  integer idxe = CompactSparseMatrixHandler_tpl<off>::Ap[col + 1] - off;
166  integer newcol = col + dcol + 1;
167  for (; idx < idxe; idx++) {
168  if (b[CompactSparseMatrixHandler_tpl<off>::Ai[idx] - off]) {
169  out.IncCoef(CompactSparseMatrixHandler_tpl<off>::Ai[idx] - off + drow,
171  }
172  }
173  }
174  return out;
175 }
176 
177 template class DirCColMatrixHandler<0>;
178 template class DirCColMatrixHandler<1>;
virtual integer iGetNumCols(void) const =0
virtual void IncCoef(integer iRow, integer iCol, const doublereal &dCoef)
Definition: mh.cc:374
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
integer iGetNumRows(void) const
Definition: spmh.h:113
#define NO_OP
Definition: myassert.h:74
MatrixHandler & FakeThirdOrderMulAndSumWithShift(MatrixHandler &out, std::vector< bool > b, doublereal s=1., integer drow=0, integer dcol=0) const
Definition: dirccmh.cc:145
CompactSparseMatrixHandler * Copy(void) const
Definition: dirccmh.cc:69
integer iGetNumCols(void) const
Definition: spmh.h:117
std::vector< integer * > pindices
Definition: dirccmh.h:53
virtual ~DirCColMatrixHandler()
Definition: dirccmh.cc:60
void Resize(integer n, integer nn)
Definition: dirccmh.cc:83
std::vector< integer > indices
Definition: dirccmh.h:54
double doublereal
Definition: colamd.c:52
MatrixHandler & MulAndSumWithShift(MatrixHandler &out, doublereal s=1., integer drow=0, integer dcol=0) const
Definition: dirccmh.cc:116
long int integer
Definition: colamd.c:51
DirCColMatrixHandler(const DirCColMatrixHandler &)
VectorHandler & GetCol(integer icol, VectorHandler &out) const
Definition: dirccmh.cc:92
virtual integer iGetNumRows(void) const =0