Hermes2D  2.0
asmlist.cpp
1 // This file is part of Hermes2D.
2 //
3 // Hermes2D is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 2 of the License, or
6 // (at your option) any later version.
7 //
8 // Hermes2D is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with Hermes2D. If not, see <http://www.gnu.org/licenses/>.
15 
16 #include "asmlist.h"
17 
18 namespace Hermes
19 {
20  namespace Hermes2D
21  {
22  template<typename Scalar>
23  AsmList<Scalar>::AsmList(const AsmList<Scalar> & other)
24  {
25  this->cnt = other.cnt;
26  this->cap = other.cap;
27  this->idx = (int*) malloc(sizeof(int) * cap);
28  this->dof = (int*) malloc(sizeof(int) * cap);
29  this->coef = (Scalar*) malloc(sizeof(Scalar) * cap);
30  for(unsigned int i = 0; i < cnt; i++) {
31  coef[i] = other.coef[i];
32  dof[i] = other.dof[i];
33  idx[i] = other.idx[i];
34  }
35  }
36 
37  template<typename Scalar>
39  {
40  cnt = 0;
41  cap = 128;
42  idx = (int*) malloc(sizeof(int) * cap);
43  dof = (int*) malloc(sizeof(int) * cap);
44  coef = (Scalar*) malloc(sizeof(Scalar) * cap);
45  }
46 
47  template<typename Scalar>
49  {
50  free(idx);
51  free(dof);
52  free(coef);
53  }
54 
55  template<typename Scalar>
57  {
58  return this->idx;
59  }
60 
61  template<typename Scalar>
62  int* AsmList<Scalar>::get_dof()
63  {
64  return this->dof;
65  }
66 
67  template<typename Scalar>
68  unsigned int AsmList<Scalar>::get_cnt()
69  {
70  return this->cnt;
71  }
72 
73  template<typename Scalar>
74  Scalar* AsmList<Scalar>::get_coef()
75  {
76  return this->coef;
77  }
78 
79  template<typename Scalar>
80  void AsmList<Scalar>::add_triplet(int i, int d, Scalar c)
81  {
82  if(cnt >= cap)
83  enlarge();
84  idx[cnt] = i;
85  dof[cnt] = d;
86  coef[cnt++] = c;
87  }
88 
89  template<typename Scalar>
90  void AsmList<Scalar>::enlarge()
91  {
92  cap = !cap ? 128 : cap * 2;
93  idx = (int*) realloc(idx, sizeof(int) * cap);
94  dof = (int*) realloc(dof, sizeof(int) * cap);
95  coef = (Scalar*) realloc(coef, sizeof(Scalar) * cap);
96  }
97 
98  template HERMES_API class AsmList<double>;
99  template HERMES_API class AsmList<std::complex<double> >;
100  }
101 }