MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
JacSubMatrix.h
Go to the documentation of this file.
1 /* $Header: /var/cvs/mbdyn/mbdyn/mbdyn-1.0/libraries/libmbmath/JacSubMatrix.h,v 1.12 2011/05/22 20:41:59 masarati Exp $ */
2 /*
3  * MBDyn (C) is a multibody analysis code.
4  * http://www.mbdyn.org
5  *
6  * Copyright (C) 2003
7  *
8  * Marco Morandini <morandini@aero.polimi.it>
9  *
10  * Dipartimento di Ingegneria Aerospaziale - Politecnico di Milano
11  * via La Masa, 34 - 20156 Milano, Italy
12  * http://www.aero.polimi.it
13  *
14  * Changing this copyright notice is forbidden.
15  *
16  * This program is free software; you can redistribute it and/or modify
17  * it under the terms of the GNU General Public License as published by
18  * the Free Software Foundation (version 2 of the License).
19  *
20  *
21  * This program is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24  * GNU General Public License for more details.
25  *
26  * You should have received a copy of the GNU General Public License
27  * along with this program; if not, write to the Free Software
28  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29  */
30 
31 /* Portions Copyright (C) 2009 Pierangelo Masarati <masarati@aero.polimi.it> */
32 
33 
34 #ifndef JacSubMatrix_hh
35 #define JacSubMatrix_hh
36 
37 #include <vector>
38 
39 #include "ac/f2c.h"
40 #include "submat.h"
41 
43 public:
46  std::vector<const ExpandableRowVector *> xm;
48  ExpandableRowElement(void) : x(0.), idx(0) {xm.resize(1); x = 0;};
49  };
50 private:
51  std::vector<ExpandableRowElement> v;
52 
53 // ExpandableRowVector & operator = (const ExpandableRowVector &); // not to be implemented
54 // ExpandableRowVector (const ExpandableRowVector &); // not to be implemented
55 
56 public:
57  ExpandableRowVector(void);
59  virtual ~ExpandableRowVector(void);
60  void ReDim(const integer n);
61  integer GetDim(void) const;
62  void Zero(void);
63  void Reset(void);
64  void Link(const integer i, const ExpandableRowVector* const xp, const integer rhs_block = 1);
65  void SetIdx(integer i, integer iidx);
66  void Set(doublereal xx, integer i, integer iidx);
67  void Set(Vec3 xx, integer i, integer iidx);
69  const doublereal& operator ()(integer i) const;
70  void Set(doublereal xx, integer i);
71  void Set(Vec3 xx, integer i);
72  void Add(doublereal xx, integer i);
73  void Sub(doublereal xx, integer i);
74  void Add(SubVectorHandler& WorkVec, const doublereal c = 1.) const;
75  void Sub(SubVectorHandler& WorkVec, const doublereal c = 1.) const;
76  void Add(FullSubMatrixHandler& WM, const integer eq, const doublereal c = 1.) const;
77  void Add(FullSubMatrixHandler& WM, const std::vector<integer>& eq,
78  const std::vector<doublereal>& cc, const doublereal c = 1.) const;
79  void Sub(FullSubMatrixHandler& WM, const integer eq, const doublereal c = 1.) const;
80  void Sub(FullSubMatrixHandler& WM, const std::vector<integer>& eq,
81  const std::vector<doublereal>& cc, const doublereal c = 1.) const;
82  std::ostream & Write(std::ostream &out, const char *sFill = "") const;
83 };
84 
85 std::ostream & operator << (std::ostream & s, const ExpandableRowVector & z);
86 
88 public:
90 private:
91  std::vector<ExpandableColBlock> v;
92 
93  ExpandableMatrix & operator = (const ExpandableMatrix &); // not to be implemented
94  ExpandableMatrix (const ExpandableMatrix &); // not to be implemented
95 
96 public:
98  std::vector<ExpandableRowVector> rows;
99 // const ExpandableMatrix *xm;
100 // integer ncols;
101 // integer idx;
102  ExpandableColBlock(void) : rows(0) {}; //, idx(0) {};
103  void Zero(void) {
104  for (std::vector<ExpandableRowVector>::iterator i = rows.begin();
105  i != rows.end(); ++i)
106  {
107  i->Zero();
108  }
109  };
110  void ReDim(const integer nrows) {
111  rows.resize(nrows);
112  };
113  void SetBlockDim(const integer nrows, const integer ncols) {
114  for (std::vector<ExpandableRowVector>::iterator i = rows.begin();
115  i != rows.end(); ++i)
116  {
117  i->ReDim(ncols);
118  }
119  };
121  return rows.size();
122  };
124  if (rows.begin() != rows.end()) {
125  return rows[0].GetDim();
126  } else {
127  return 0;
128  }
129  };
130  void Reset() {
131  for (std::vector<ExpandableRowVector>::iterator i = rows.begin();
132  i != rows.end(); ++i)
133  {
134  i->Reset();
135  }
136  };
137 // void Link(ExpandableRowVector & row, std::vector<ExpandableRowVector>& m1) {
138 // ASSERTMSGBREAK(row.GetDim() == m1.size(),
139 // "ExpandableMatrix::ExpandableColBlock::Link() dimension mismatch");
140 // for (integer i = 0; i < m1.size(); i++) {
141 // v1.Link(i, m1[i]);
142 // }
143 // }
144  void Link(const ExpandableMatrix *const xp) {
145 // xm = xp;
146 // integer rhs_block = 0;
147 // integer rhs_block_nrows = xp->GetNRows();
148 // std::cerr << "ExpandableColBlock::Link" << std::endl;
149  for (integer col = 1; col <= GetBlockNCols(); col++) {
150 // std::cerr << "\t col " << col << std::endl;
151 // if (col >= rhs_block_ncols) {
152 // rhs_block++;
153 // rhs_block_ncols += xp->v[rhs_block].GetBlockNCols();
154 // }
155  for (std::vector<ExpandableRowVector>::size_type eq = 0; eq < rows.size(); eq++) {
156 // std::cerr << "\t\t eq " << eq << std::endl;
157  for (integer rhs_block = 1; rhs_block <=
158  xp->GetNBlocks(); rhs_block++) {
159 // std::cerr << "\t\t\t rhs_block " << rhs_block << std::endl;
160  rows[eq].Link(col, &(xp->v[rhs_block - 1].rows[col - 1]), rhs_block);
161  }
162  }
163  }
164 // std::cerr << "-------------------" << std::endl;
165  };
166  void Link(const ExpandableRowVector *const xp) {
167 // xm = xp;
168  for (std::vector<ExpandableRowVector>::size_type eq = 0; eq < rows.size(); eq++) {
169  rows[eq].Link(1, xp);
170  }
171  };
172  void SetColIdx(integer iidx) {
173 // std::cerr << "\tBloc::SetColIdx" << std::endl;
174  for (integer col = 1; col <= GetBlockNCols(); col++, iidx++) {
175 // std::cerr << "\t\tcol " << col << " iidx " << iidx << std::endl;
176  for (std::vector<ExpandableRowVector>::size_type eq = 0; eq < rows.size(); eq++) {
177 // std::cerr << "\t\t\teq " << eq <<std::endl;
178  rows[eq].SetIdx(col, iidx);
179  }
180  }
181  };
182  void Add(FullSubMatrixHandler& WM, const integer eq, const doublereal c = 1.) const {
183 // std::cerr << "\t\tBlock::Add " << std::endl;
184  for (integer e = 0; e < GetBlockNRows(); e++) {
185 // std::cerr << "\t\t\te " << e << " eq+e " << eq+e << std::endl;
186  rows[e].Add(WM, eq + e, c);
187  }
188  };
189  void Sub(FullSubMatrixHandler& WM, const integer eq, const doublereal c = 1.) const {
190  for (integer e = 0; e < GetBlockNRows(); e++) {
191  rows[e].Sub(WM, eq + e, c);
192  }
193  };
194  std::ostream & Write(std::ostream &out, const char *sFill) const {
195  for (integer eq = 0; eq < GetBlockNRows(); eq++) {
196  out << sFill << "Row: " << eq << std::endl;
197  rows[eq].Write(out, "\t\t");
198  }
199  return out;
200  }
201  };
202 public:
203  ExpandableMatrix(void);
204  ExpandableMatrix(const integer n, const integer m);
205  virtual ~ExpandableMatrix(void);
206  void ReDim(const integer n, const integer m);
207  void SetBlockDim(const integer block, const integer ncols);
208  void Zero(void);
209  integer GetNRows() const;
210  integer GetNBlocks() const;
211  integer GetBlockNCols(const integer block) const;
212 
213  void Reset(void);
214  void Link(const integer block, const ExpandableMatrix* const xp);
215  void Link(const integer block, const ExpandableRowVector* const xp);
216  void SetBlockIdx(integer block, integer iidx);
217 
218 // void Set(doublereal xx, integer block, integer eq, integer iidx);
219 // doublereal& operator ()(integer i);
220 // const doublereal& operator ()(integer i) const;
221  void Set(doublereal xx, integer eq, integer block, integer block_col = 1);
222  void Set(Vec3 xx, integer eq, integer block, integer block_col = 1);
223  void Set(Mat3x3 xx, integer eq, integer block, integer block_col = 1);
224  void Add(doublereal xx, integer eq, integer block, integer block_col = 1);
225  void Sub(doublereal xx, integer eq, integer block, integer block_col = 1);
226  void Add(Vec3 xx, integer eq, integer block, integer block_col = 1);
227  void Sub(Vec3 xx, integer eq, integer block, integer block_col = 1);
228  void Add(Mat3x3 xx, integer eq, integer block, integer block_col = 1);
229  void Sub(Mat3x3 xx, integer eq, integer block, integer block_col = 1);
230 // void Add(SubVectorHandler& WorkVec, const doublereal c = 1.) const;
231 // void Sub(SubVectorHandler& WorkVec, const doublereal c = 1.) const;
232  void Add(FullSubMatrixHandler& WM, const integer eq, const doublereal c = 1.) const;
233 // void Add(FullSubMatrixHandler& WM, const std::vector<integer>& eq,
234 // const std::vector<doublereal>& cc, const doublereal c = 1.) const;
235  void Sub(FullSubMatrixHandler& WM, const integer eq, const doublereal c = 1.) const;
236 // void Sub(FullSubMatrixHandler& WM, const std::vector<integer>& eq,
237 // const std::vector<doublereal>& cc, const doublereal c = 1.) const;
238  std::ostream & Write(std::ostream &out, const char *sFill = "") const;
239 };
240 
241 
242 #endif /* JacSubMatrix_hh */
243 
integer GetBlockNCols(const integer block) const
integer GetNRows() const
integer GetDim(void) const
Definition: JacSubMatrix.cc:57
void Set(doublereal xx, integer i, integer iidx)
Definition: JacSubMatrix.cc:95
std::vector< ExpandableColBlock > v
Definition: JacSubMatrix.h:89
Definition: matvec3.h:98
std::vector< ExpandableRowElement > v
Definition: JacSubMatrix.h:51
void Add(doublereal xx, integer i)
void Set(doublereal xx, integer eq, integer block, integer block_col=1)
void Sub(doublereal xx, integer eq, integer block, integer block_col=1)
void SetBlockDim(const integer nrows, const integer ncols)
Definition: JacSubMatrix.h:113
std::ostream & Write(std::ostream &out, const char *sFill) const
Definition: JacSubMatrix.h:194
ExpandableMatrix & operator=(const ExpandableMatrix &)
std::vector< const ExpandableRowVector * > xm
Definition: JacSubMatrix.h:46
void Link(const ExpandableRowVector *const xp)
Definition: JacSubMatrix.h:166
void ReDim(const integer n)
Definition: JacSubMatrix.cc:50
void Sub(FullSubMatrixHandler &WM, const integer eq, const doublereal c=1.) const
Definition: JacSubMatrix.h:189
void Link(const ExpandableMatrix *const xp)
Definition: JacSubMatrix.h:144
void ReDim(const integer nrows)
Definition: JacSubMatrix.h:110
static const char * eq[]
Definition: drvdisp.cc:196
void Add(doublereal xx, integer eq, integer block, integer block_col=1)
virtual ~ExpandableRowVector(void)
Definition: JacSubMatrix.cc:49
std::ostream & Write(std::ostream &out, const char *sFill="") const
void Link(const integer i, const ExpandableRowVector *const xp, const integer rhs_block=1)
Definition: JacSubMatrix.cc:68
void ReDim(const integer n, const integer m)
std::vector< ExpandableRowVector > rows
Definition: JacSubMatrix.h:98
static std::stack< cleanup * > c
Definition: cleanup.cc:59
virtual ~ExpandableMatrix(void)
void Add(FullSubMatrixHandler &WM, const integer eq, const doublereal c=1.) const
Definition: JacSubMatrix.h:182
void SetIdx(integer i, integer iidx)
Definition: JacSubMatrix.cc:89
std::ostream & Write(std::ostream &out, const char *sFill="") const
void Sub(doublereal xx, integer i)
doublereal & operator()(integer i)
void Reset(void)
std::ostream & operator<<(std::ostream &s, const ExpandableRowVector &z)
double doublereal
Definition: colamd.c:52
void SetBlockDim(const integer block, const integer ncols)
long int integer
Definition: colamd.c:51
void Link(const integer block, const ExpandableMatrix *const xp)
integer GetNBlocks() const
void SetBlockIdx(integer block, integer iidx)