27 assert(
type == HERMES_TYPE_VERTEX);
31 void Node::ref_element(
Element* e)
33 if (
type == HERMES_TYPE_EDGE)
36 if (
elem[0] ==
nullptr)
40 if (
elem[1] ==
nullptr)
43 throw Hermes::Exceptions::Exception(
"No free slot 'elem'");
49 void Node::unref_element(HashTable* ht, Element* e)
51 if (
type == HERMES_TYPE_VERTEX)
53 if (!--
ref) ht->remove_vertex_node(
id);
59 else if (
elem[1] == e)
elem[1] =
nullptr;
61 if (!--
ref) ht->remove_edge_node(
id);
67 for (
unsigned int i = 0; i <
nvert; i++)
70 en[i]->ref_element(
this);
76 bool Element::get_edge_orientation(
int ie)
const
83 for (
unsigned int i = 0; i <
nvert; i++)
85 vn[i]->unref_element(ht);
86 en[i]->unref_element(ht,
this);
92 Element::Element() : visited(false), area(0.0), diameter(0.0), center_set(false)
96 bool Element::hsplit()
const
100 return sons[0] !=
nullptr;
103 bool Element::vsplit()
const
107 return sons[2] !=
nullptr;
110 bool Element::bsplit()
const
114 return sons[0] !=
nullptr &&
sons[2] !=
nullptr;
131 double ax, ay, bx, by;
133 ay =
vn[1]->y -
vn[0]->y;
135 by =
vn[2]->y -
vn[0]->y;
137 this->
area = 0.5*(ax*by - ay*bx);
142 by =
vn[3]->y -
vn[0]->y;
144 this->
area =
area + 0.5*(ax*by - ay*bx);
148 if (!this->is_curved() || !precise_for_curvature)
158 double x_center, y_center;
161 for (
unsigned char isurf = 0; isurf < this->
nvert; isurf++)
164 int eo = g_quad_2d_std.get_edge_points(isurf, this->get_mode() == HERMES_MODE_TRIANGLE ? g_max_tri : g_max_quad, this->get_mode());
165 unsigned char np = g_quad_2d_std.get_num_points(eo, this->get_mode());
166 double* x_curv =
new double[np];
167 double* y_curv =
new double[np];
168 double* x_straight =
new double[np];
169 double* y_straight =
new double[np];
175 memcpy(x_curv, geometry.
x, np*
sizeof(
double));
176 memcpy(y_curv, geometry.
y, np*
sizeof(
double));
183 memcpy(x_straight, geometry.
x, np*
sizeof(
double));
184 memcpy(y_straight, geometry.
y, np*
sizeof(
double));
187 double previous_distance;
188 for (
int i = 0; i < np; i++)
191 double distance_i = std::sqrt(std::pow(x_straight[i] - x_curv[i], 2.0) + std::pow(y_straight[i] - y_curv[i], 2.0));
194 double distance_from_center_curved = std::pow(x_center - x_curv[i], 2.0) + std::pow(y_center - y_curv[i], 2.0);
195 double distance_from_center_straight = std::pow(x_center - x_straight[i], 2.0) + std::pow(y_center - y_straight[i], 2.0);
196 bool add = distance_from_center_curved > distance_from_center_straight;
203 double distance_along_edge = std::sqrt(std::pow(x_straight[i] - this->
vn[isurf]->x, 2.0) + std::pow(y_straight[i] - this->
vn[isurf]->y, 2.0));
204 area_delta = distance_i * distance_along_edge * 0.5;
206 if (i > 0 && i < np - 1)
208 double distance_along_edge = std::sqrt(std::pow(x_straight[i] - x_straight[i - 1], 2.0) + std::pow(y_straight[i] - y_straight[i - 1], 2.0));
209 area_delta = 0.5*(distance_i + previous_distance) * distance_along_edge;
213 double distance_along_edge = std::sqrt(std::pow(x_straight[i] - this->
vn[(isurf + 1) % this->nvert]->x, 2.0) + std::pow(y_straight[i] - this->
vn[(isurf + 1) % this->nvert]->y, 2.0));
214 area_delta = distance_i * distance_along_edge * 0.5;
222 previous_distance = distance_i;
239 if (!this->center_set)
243 if (!this->center_set)
246 this->x_center = this->
vn[0]->
x + this->
vn[1]->
x + this->
vn[2]->
x;
247 this->y_center = this->
vn[0]->y + this->
vn[1]->y + this->
vn[2]->y;
250 this->x_center += this->
vn[3]->
x;
251 this->x_center = this->x_center / 4.0;
252 this->y_center += this->
vn[3]->y;
253 this->y_center = this->y_center / 4.0;
257 this->x_center = this->x_center / 3.0;
258 this->y_center = this->y_center / 3.0;
262 this->center_set =
true;
280 for (
int i = 0; i < 3; i++)
283 l = sqr(
vn[i]->x -
vn[j]->x) + sqr(
vn[i]->y -
vn[j]->y);
290 max = sqr(
vn[0]->x -
vn[2]->x) + sqr(
vn[0]->y -
vn[2]->y);
291 l = sqr(
vn[1]->x -
vn[3]->x) + sqr(
vn[1]->y -
vn[3]->y);
302 newnode->
type = HERMES_TYPE_VERTEX;
307 newnode->
x = (v1->
x + v2->
x) * 0.5;
308 newnode->y = (v1->y + v2->y) * 0.5;
313 Node* get_edge_node()
316 Node* newnode =
new Node();
317 newnode->type = HERMES_TYPE_EDGE;
323 newnode->elem[0] = newnode->elem[1] =
nullptr;
double x
vertex node coordinates
unsigned type
0 = vertex node; 1 = edge node
unsigned char next_vert(unsigned char i) const
Helper functions to obtain the index of the next or previous vertex/edge.
HERMES_API void init_geom_surf_allocated(GeomSurf< double > &geom, RefMap *rm, unsigned char isurf, int marker, const int order, double3 *&tan)
Init element geometry for surface integrals.
Stores one element of a mesh.
T y[H2D_MAX_INTEGRATION_POINTS_COUNT]
y-coordinates[in physical domain].
T x[H2D_MAX_INTEGRATION_POINTS_COUNT]
x-coordinates[in physical domain].
Element * elem[2]
elements sharing the edge node
CurvMap * cm
curved mapping, nullptr if not curvilinear
Common definitions for Hermes2D.
Stores one node of a mesh.
unsigned char nvert
number of vertices (3 or 4)
void ref_all_nodes()
Internal.
void unref_all_nodes(HashTable *ht)
Internal.
double area
Serves for saving the once calculated area of this element.
Node * en[H2D_MAX_NUMBER_EDGES]
edge node pointers
unsigned bnd
1 = boundary node; 0 = inner node
Element * get_neighbor(int ie) const
void get_center(double &x, double &y)
Returns the center of gravity.
bool is_constrained_vertex() const
Returns true if the (vertex) node is constrained.
Represents the reference mapping.
unsigned ref
the number of elements using the node
Element * sons[H2D_MAX_ELEMENT_SONS]
son elements (up to four)
bool active
0 = active, no sons; 1 = inactive (refined), has sons
double diameter
Serves for saving the once calculated diameter of this element.
void calc_diameter()
Calculates the diameter.
Stores and searches node tables.
void calc_area(bool precise_for_curvature=false)
This takes much longer.
virtual void set_active_element(Element *e)
Node * vn[H2D_MAX_NUMBER_VERTICES]
vertex node pointers