16void 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;
45[[deprecated(
"Use CRS_Matrix::AddElem_3(...) instead.")]]
46void 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);
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)
202 double const PENALTY = 1e6;
204 int const nidx =
static_cast<int>(idx.size());
206 for (
int row = 0; row < nidx; ++row)
208 int const k = idx[row];
209 int const id1 =
fetch(k, k);
212 f[k] += PENALTY * u[k];
220 assert( _nrows ==
static_cast<int>(d.size()) );
222 for (
int row = 0; row < _nrows; ++row)
224 const int ia =
fetch(row, row);
233 bool bn = (
nnode == _nrows);
236 cout <<
"######### Error: " <<
"number of rows" << endl;
239 bool bz = (
id[
nnode] == _nnz);
242 cout <<
"######### Error: " <<
"number of non zero elements" << endl;
245 bool bd = equal(
id,
id +
nnode + 1, _id.cbegin());
248 cout <<
"######### Error: " <<
"row starts" << endl;
251 bool bk = equal(ik, ik +
id[
nnode], _ik.cbegin());
254 cout <<
"######### Error: " <<
"column indices" << endl;
257 bool bv = equal(sk, sk +
id[
nnode], _sk.cbegin());
260 cout <<
"######### Error: " <<
"values" << endl;
263 return bn && bz && bd && bk && bv;
269 assert( _nrows ==
static_cast<int>(w.size()) );
270 assert( w.size() == u.size() );
272 for (
int row = 0; row < _nrows; ++row)
275 for (
int ij = _id[row]; ij < _id[row + 1]; ++ij)
277 wi += _sk[ij] * u[ _ik[ij] ];
285 vector<double>
const &f, vector<double>
const &u)
const
287 assert( _nrows ==
static_cast<int>(w.size()) );
288 assert( w.size() == u.size() && u.size() == f.size() );
290 for (
int row = 0; row < _nrows; ++row)
293 for (
int ij = _id[row]; ij < _id[row + 1]; ++ij)
295 wi -= _sk[ij] * u[ _ik[ij] ];
304 int const id2 = _id[row + 1];
307 while (ip < id2 && _ik[ip] != col)
315 cout <<
"No column " << col <<
" in row " << row << endl;
328 for (
int i = 0; i < 3; ++i)
330 const int ii = ial[i];
331 for (
int j = 0; j < 3; ++j)
333 const int jj = ial[j];
334 int ip =
fetch(ii, jj);
338 cout <<
"Error in AddElem: (" << ii <<
"," << jj <<
") ["
339 << ial[0] <<
"," << ial[1] <<
"," << ial[2] <<
"]\n";
343 _sk[ip] += ske[i][j];
function vertex minimal boundary edge info in an ASCII file Matlab indexing is stored(starts with 1). % % The output file format is compatible with Mesh_2d_3_matlab nnode
int fetch(int row, int col) const
void CalculateLaplace(std::vector< double > &f)
void ApplyDirichletBC(std::vector< double > const &u, std::vector< double > &f)
void Defect(std::vector< double > &w, std::vector< double > const &f, std::vector< double > const &u) const
CRS_Matrix(Mesh const &mesh)
void Derive_Matrix_Pattern()
void GetDiag(std::vector< double > &d) const
void Mult(std::vector< double > &w, std::vector< double > const &u) const
void AddElem_3(int const ial[3], double const ske[3][3], double const fe[3], std::vector< double > &f)
bool Compare2Old(int nnode, int const id[], int const ik[], double const sk[]) const
const std::vector< double > & GetCoords() const
virtual std::vector< int > Index_DirichletNodes() const =0
const std::vector< int > & GetConnectivity() const
void AddElem(int const ial[3], double const ske[3][3], double const fe[3], int const id[], int const ik[], double sk[], double f[])
void CalcElem(int const ial[3], double const xc[], double ske[3][3], double fe[3])
void CalcElem(int const ial[3], double const xc[], double ske[3][3], double fe[3])
double fNice(double const x, double const y)