Hermes2D  2.0
mesh_function.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 "mesh_function.h"
17 
18 namespace Hermes
19 {
20  namespace Hermes2D
21  {
22  template<typename Scalar>
23  MeshFunction<Scalar>::MeshFunction()
24  : Function<Scalar>()
25  {
26  refmap = new RefMap;
27  mesh = NULL;
28  this->element = NULL;
29  }
30 
31  template<typename Scalar>
32  MeshFunction<Scalar>::MeshFunction(const Mesh *mesh) :
33  Function<Scalar>()
34  {
35  this->mesh = mesh;
36  this->refmap = new RefMap;
37  }
38 
39  template<typename Scalar>
40  MeshFunction<Scalar>::~MeshFunction()
41  {
42  delete refmap;
43  if(this->overflow_nodes != NULL)
44  {
45  for(unsigned int i = 0; i < this->overflow_nodes->get_size(); i++)
46  if(this->overflow_nodes->present(i))
47  ::free(this->overflow_nodes->get(i));
48  delete this->overflow_nodes;
49  }
50  }
51 
52  template<typename Scalar>
54  {
55  bool okay = true;
56  if(this->mesh == NULL)
57  okay = false;
58  try
59  {
60  if(this->mesh->get_max_element_id() < 0)
61  throw Hermes::Exceptions::Exception("Internal exception.");
62  this->mesh->get_element(this->mesh->get_max_element_id() - 1);
63  }
64  catch(std::exception& e)
65  {
66  okay = false;
67  }
68  return okay;
69  }
70 
71  template<typename Scalar>
73  {
74  }
75 
76  template<typename Scalar>
77  void MeshFunction<Scalar>::reinit()
78  {
79  this->free();
80  init();
81  }
82 
83  template<typename Scalar>
84  int MeshFunction<Scalar>::get_edge_fn_order(int edge)
85  {
87  }
88 
89  template<typename Scalar>
90  const Mesh* MeshFunction<Scalar>::get_mesh() const
91  {
92  return mesh;
93  }
94 
95  template<typename Scalar>
96  RefMap* MeshFunction<Scalar>::get_refmap(bool update)
97  {
98  if(update)
99  this->update_refmap();
100  return refmap;
101  }
102 
103  template<typename Scalar>
104  void MeshFunction<Scalar>::set_refmap(RefMap* refmap_to_set)
105  {
106  delete refmap;
107  this->refmap = refmap_to_set;
108  }
109 
110  template<typename Scalar>
112  {
113  if(quad_2d == NULL)
114  throw Exceptions::NullException(1);
116  refmap->set_quad_2d(quad_2d);
117  }
118 
119  template<typename Scalar>
121  {
123  mode = e->get_mode();
124  refmap->set_active_element(e);
126  }
127 
128  template<typename Scalar>
130  {
131  if(this->overflow_nodes != NULL) {
132  for(unsigned int i = 0; i < this->overflow_nodes->get_size(); i++)
133  if(this->overflow_nodes->present(i))
134  ::free(this->overflow_nodes->get(i));
135  delete this->overflow_nodes;
136  }
137  this->nodes = new LightArray<typename Function<Scalar>::Node *>;
138  this->overflow_nodes = this->nodes;
139  }
140 
141  template<typename Scalar>
143  {
146  }
147 
148  template<typename Scalar>
150  {
153  }
154 
155  template<typename Scalar>
157  {
159  }
160 
161  template<typename Scalar>
162  void MeshFunction<Scalar>::update_refmap()
163  {
164  refmap->force_transform(this->sub_idx, this->ctm);
165  }
166 
167  template<typename Scalar>
168  void MeshFunction<Scalar>::force_transform(uint64_t sub_idx, Trf* ctm)
169  {
170  this->sub_idx = sub_idx;
171  this->ctm = ctm;
172  }
173 
174  template class HERMES_API MeshFunction<double>;
175  template class HERMES_API MeshFunction<std::complex<double> >;
176  }
177 }