16 void CalcElem(
int const ial[3],
double const xc[],
double ske[3][3],
double fe[3])
19 const int i1 = 2 * ial[0], i2 = 2 * ial[1], i3 = 2 * ial[2];
20 const double x13 =
xc[i3 + 0] -
xc[i1 + 0], y13 =
xc[i3 + 1] -
xc[i1 + 1],
21 x21 =
xc[i1 + 0] -
xc[i2 + 0], y21 =
xc[i1 + 1] -
xc[i2 + 1],
22 x32 =
xc[i2 + 0] -
xc[i3 + 0], y32 =
xc[i2 + 1] -
xc[i3 + 1];
23 const double jac = fabs(x21 * y13 - x13 * y21);
25 ske[0][0] = 0.5 / jac * (y32 * y32 + x32 * x32);
26 ske[0][1] = 0.5 / jac * (y13 * y32 + x13 * x32);
27 ske[0][2] = 0.5 / jac * (y21 * y32 + x21 * x32);
28 ske[1][0] = ske[0][1];
29 ske[1][1] = 0.5 / jac * (y13 * y13 + x13 * x13);
30 ske[1][2] = 0.5 / jac * (y21 * y13 + x21 * x13);
31 ske[2][0] = ske[0][2];
32 ske[2][1] = ske[1][2];
33 ske[2][2] = 0.5 / jac * (y21 * y21 + x21 * x21);
35 const double xm = (
xc[i1 + 0] +
xc[i2 + 0] +
xc[i3 + 0]) / 3.0,
36 ym = (
xc[i1 + 1] +
xc[i2 + 1] +
xc[i3 + 1]) / 3.0;
38 fe[0] = fe[1] = fe[2] = 0.5 * jac *
fNice(xm, ym) / 3.0;
46 void AddElem(
int const ial[3],
double const ske[3][3],
double const fe[3],
47 int const id[],
int const ik[],
double sk[],
double f[])
49 for (
int i = 0; i < 3; ++i)
51 const int ii = ial[i],
55 for (
int j = 0; j < 3; ++j)
57 const int jj = ial[j];
58 bool not_found =
true;
61 not_found = (ik[ip] != jj);
64 while (not_found && ip < id2);
66 #ifndef NDEBUG // compiler option -DNDEBUG switches off the check
69 cout <<
"Error in AddElem: (" << ii <<
"," << jj <<
") ["
70 << ial[0] <<
"," << ial[1] <<
"," << ial[2] <<
"]\n";
74 sk[ip - 1] += ske[i][j];
89 : _mesh(mesh), _nrows(0), _nnz(0), _id(0), _ik(0), _sk(0)
101 _nrows = *max_element(
ia.cbegin(),
ia.cbegin() + ndof_e *
nelem);
103 assert(*min_element(
ia.cbegin(),
ia.cbegin() + ndof_e *
nelem) == 0);
107 vector< list<int> > cc(_nrows);
108 for (
int i = 0; i <
nelem; ++i)
110 int const idx = ndof_e * i;
111 for (
int k = 0; k < ndof_e; ++k)
113 list<int> &cck = cc.at(
ia[idx + k]);
114 cck.insert( cck.end(),
ia.cbegin() + idx,
ia.cbegin() + idx + ndof_e );
123 _nnz +=
static_cast<int>(it.size());
128 _id.resize(_nrows + 1);
133 for (
size_t i = 0; i < cc.size(); ++i)
136 const list<int> &ci = cc.at(i);
137 const auto nci =
static_cast<int>(ci.size());
138 _id[i + 1] = _id[i] + nci;
139 copy(ci.begin(), ci.end(), _ik.begin() + _id[i] );
142 assert(_nnz == _id[_nrows]);
152 cout <<
"\nMatrix (nnz = " << _id[_nrows] <<
")\n";
154 for (
int row = 0; row < _nrows; ++row)
156 cout <<
"Row " << row <<
" : ";
157 int const id1 = _id[row];
158 int const id2 = _id[row + 1];
159 for (
int j = id1; j < id2; ++j)
161 cout.setf(ios::right, ios::adjustfield);
162 cout <<
"[" << setw(2) << _ik[j] <<
"] " << setw(4) << _sk[j] <<
" ";
173 assert(_nnz == _id[_nrows]);
175 for (
int k = 0; k < _nrows; ++k)
179 for (
int k = 0; k < _nrows; ++k)
184 double ske[3][3], fe[3];
190 for (
int i = 0; i <
nelem; ++i)
204 double const PENALTY = 1e6;
206 int const nidx =
static_cast<int>(idx.size());
208 for (
int row = 0; row < nidx; ++row)
210 int const k = idx[row];
211 int const id1 =
fetch(k, k);
214 f[k] += PENALTY * u[k];
222 assert( _nrows ==
static_cast<int>(d.size()) );
224 for (
int row = 0; row < _nrows; ++row)
226 const int ia =
fetch(row, row);
235 bool bn = (
nnode == _nrows);
238 cout <<
"######### Error: " <<
"number of rows" << endl;
241 bool bz = (
id[
nnode] == _nnz);
244 cout <<
"######### Error: " <<
"number of non zero elements" << endl;
247 bool bd = equal(
id,
id +
nnode + 1, _id.cbegin());
250 cout <<
"######### Error: " <<
"row starts" << endl;
253 bool bk = equal(ik, ik +
id[
nnode], _ik.cbegin());
256 cout <<
"######### Error: " <<
"column indices" << endl;
259 bool bv = equal(sk, sk +
id[
nnode], _sk.cbegin());
262 cout <<
"######### Error: " <<
"values" << endl;
265 return bn && bz && bd && bk && bv;
271 assert( _nrows ==
static_cast<int>(w.size()) );
272 assert( w.size() == u.size() );
274 for (
int row = 0; row < _nrows; ++row)
277 for (
int ij = _id[row]; ij < _id[row + 1]; ++ij)
279 wi += _sk[ij] * u[ _ik[ij] ];
287 vector<double>
const &f, vector<double>
const &u)
const
289 assert( _nrows ==
static_cast<int>(w.size()) );
290 assert( w.size() == u.size() && u.size() == f.size() );
292 for (
int row = 0; row < _nrows; ++row)
295 for (
int ij = _id[row]; ij < _id[row + 1]; ++ij)
297 wi -= _sk[ij] * u[ _ik[ij] ];
306 int const id2 = _id[row + 1];
309 while (ip < id2 && _ik[ip] != col)
316 #ifndef NDEBUG // compiler option -DNDEBUG switches off the check
317 cout <<
"No column " << col <<
" in row " << row << endl;
327 for (
int i = 0; i < 3; ++i)
329 const int ii = ial[i];
330 for (
int j = 0; j < 3; ++j)
332 const int jj = ial[j];
333 int ip =
fetch(ii, jj);
334 #ifndef NDEBUG // compiler option -DNDEBUG switches off the check
337 cout <<
"Error in AddElem: (" << ii <<
"," << jj <<
") ["
338 << ial[0] <<
"," << ial[1] <<
"," << ial[2] <<
"]\n";
342 _sk[ip] += ske[i][j];