145 return this->selected;
150 return this->node[
n];
160 this->node =
new int[
n];
165 delete [] this->node;
185 this->sharp_point = b;
190 return this->sharp_point;
205 return this->edge[
n];
215 this->edge =
new int[
n];
220 delete [] this->edge;
235 this->sharp_edge = b;
240 return this->sharp_edge;
270 delete [] this->
point;
280 return this->surfaces;
330 return this->edge[
n];
335 this->edge =
new int[
n];
340 delete [] this->edge;
350 return this->elements;
355 this->element[
m] =
n;
360 return this->element[
n];
365 this->element =
new int[
n];
370 delete [] this->element;
375 return &this->normal[0];
380 this->normal[0] = d[0];
381 this->normal[1] = d[1];
382 this->normal[2] = d[2];
387 return this->normal[
n];
397 this->vertex_normals[
n][0] = d[0];
398 this->vertex_normals[
n][1] = d[1];
399 this->vertex_normals[
n][2] = d[2];
404 this->vertex_normals[
n][0] += d[0];
405 this->vertex_normals[
n][1] += d[1];
406 this->vertex_normals[
n][2] += d[2];
411 this->vertex_normals[
n][0] -= d[0];
412 this->vertex_normals[
n][1] -= d[1];
413 this->vertex_normals[
n][2] -= d[2];
418 return &this->vertex_normals[
n][0];
434 if((cdim < 0) || (
dim < 0) || (nodes < 1))
472 ifstream mesh_header;
474 ifstream mesh_elements;
475 ifstream mesh_boundary;
479 sprintf(fileName,
"%s/mesh.header", dirName);
480 mesh_header.open(fileName);
482 if(!mesh_header.is_open()) {
483 cout <<
"Mesh: load: unable to open " << fileName << endl;
487 int nodes, elements, boundaryelements,
types, type, ntype;
489 mesh_header >> nodes >> elements >> boundaryelements;
490 mesh_header >>
types;
492 int elements_zero_d = 0;
493 int elements_one_d = 0;
494 int elements_two_d = 0;
495 int elements_three_d = 0;
497 for(
int i = 0; i <
types; i++) {
498 mesh_header >> type >> ntype;
502 elements_zero_d += ntype;
505 elements_one_d += ntype;
509 elements_two_d += ntype;
515 elements_three_d += ntype;
518 cout <<
"Unknown element family (possibly not implamented)" << endl;
525 cout <<
"Summary:" << endl;
526 cout <<
"Nodes: " << nodes << endl;
527 cout <<
"Point elements: " << elements_zero_d << endl;
528 cout <<
"Edge elements: " << elements_one_d << endl;
529 cout <<
"Surface elements: " << elements_two_d << endl;
530 cout <<
"Volume elements: " << elements_three_d << endl;
536 if(elements_one_d > 0)
539 if(elements_two_d > 0)
542 if(elements_three_d > 0)
548 this->points = elements_zero_d;
551 this->edges = elements_one_d;
552 edge =
new edge_t[this->edges];
554 this->surfaces = elements_two_d;
557 this->elements = elements_three_d;
564 sprintf(fileName,
"%s/mesh.nodes", dirName);
565 mesh_nodes.open(fileName);
567 if(!mesh_nodes.is_open()) {
568 cout <<
"Mesh: load: unable to open " << fileName << endl;
575 for(
int i = 0; i < nodes; i++) {
576 node_t *node = &this->node[i];
577 mesh_nodes >> number >> index >> x >> y >>
z;
588 sprintf(fileName,
"%s/mesh.elements", dirName);
589 mesh_elements.open(fileName);
591 if(!mesh_elements.is_open()) {
592 cout <<
"Mesh: load: unable to open " << fileName << endl;
596 int current_point = 0;
597 int current_edge = 0;
598 int current_surface = 0;
599 int current_element = 0;
606 for(
int i = 0; i < elements; i++) {
607 mesh_elements >> number >> index >> type;
611 point = &this->point[current_point++];
617 for(
int j = 0; j < point->
getNodes(); j++) {
629 edge = &this->edge[current_edge++];
635 for(
int j = 0; j < edge->
getNodes(); j++) {
649 surface = &this->surface[current_surface++];
655 for(
int j = 0; j < surface->
getNodes(); j++) {
662 for(
int j = 0; j < surface->
getEdges(); j++)
675 element = &this->element[current_element++];
681 for(
int j = 0; j < element->
getNodes(); j++) {
689 cout <<
"Unknown element type (possibly not implemented" << endl;
696 mesh_elements.close();
700 sprintf(fileName,
"%s/mesh.boundary", dirName);
701 mesh_boundary.open(fileName);
703 if(!mesh_boundary.is_open()) {
704 cout <<
"Mesh: load: unable to open " << fileName << endl;
708 int parent0, parent1;
710 for(
int i = 0; i < boundaryelements; i++) {
711 mesh_boundary >> number >> index >> parent0 >> parent1 >> type;
715 point = &this->point[current_point++];
725 for(
int j = 0; j < point->
getNodes(); j++) {
733 edge = &this->edge[current_edge++];
743 for(
int j = 0; j < edge->
getNodes(); j++) {
753 surface = &this->surface[current_surface++];
763 for(
int j = 0; j < surface->
getNodes(); j++) {
770 for(
int j = 0; j < surface->
getEdges(); j++)
787 mesh_boundary.close();
799 ofstream mesh_header;
801 ofstream mesh_elements;
802 ofstream mesh_boundary;
806 int *bulk_by_type =
new int[maxcode];
807 int *boundary_by_type =
new int[maxcode];
809 for(
int i = 0; i < maxcode; i++) {
811 boundary_by_type[i] = 0;
814 for(
int i = 0; i < elements; i++) {
821 boundary_by_type[e->
getCode()]++;
824 for(
int i = 0; i < surfaces; i++) {
831 boundary_by_type[s->
getCode()]++;
834 for(
int i = 0; i < edges; i++) {
841 boundary_by_type[e->
getCode()]++;
844 for(
int i = 0; i < points; i++) {
851 boundary_by_type[p->
getCode()]++;
854 int bulk_elements = 0;
855 int boundary_elements = 0;
856 int element_types = 0;
858 for(
int i = 0; i < maxcode; i++) {
859 bulk_elements += bulk_by_type[i];
860 boundary_elements += boundary_by_type[i];
862 if((bulk_by_type[i] > 0) || (boundary_by_type[i] > 0))
868 sprintf(fileName,
"%s/mesh.header", dirName);
870 mesh_header.open(fileName);
872 if(!mesh_header.is_open()) {
873 cout <<
"Unable to open " << fileName << endl;
877 cout <<
"Saving " << nodes <<
" nodes" << endl;
878 cout <<
"Saving " << bulk_elements <<
" elements" << endl;
879 cout <<
"Saving " << boundary_elements <<
" boundary elements" << endl;
882 mesh_header << nodes <<
" ";
883 mesh_header << bulk_elements <<
" ";
884 mesh_header << boundary_elements << endl;
885 mesh_header << element_types << endl;
887 for(
int i = 0; i < maxcode; i++) {
888 int j = bulk_by_type[i] + boundary_by_type[i];
890 mesh_header << i <<
" " << j << endl;
897 sprintf(fileName,
"%s/mesh.nodes", dirName);
899 mesh_nodes.open(fileName);
901 if(!mesh_nodes.is_open()) {
902 cout <<
"Unable to open " << fileName << endl;
906 for(
int i = 0; i < this->nodes; i++) {
907 node_t *node = &this->node[i];
911 mesh_nodes << i+1 <<
" " << ind <<
" ";
912 mesh_nodes << node->
getX(0) <<
" ";
913 mesh_nodes << node->
getX(1) <<
" ";
914 mesh_nodes << node->
getX(2) << endl;
922 sprintf(fileName,
"%s/mesh.elements", dirName);
924 mesh_elements.open(fileName);
926 if(!mesh_elements.is_open()) {
927 cout <<
"Unable to open " << fileName << endl;
933 for(
int i = 0; i < this->elements; i++) {
942 mesh_elements << ++current <<
" ";
943 mesh_elements << ind <<
" ";
944 mesh_elements << e->
getCode() <<
" ";
946 for(
int j = 0; j < e->
getNodes(); j++)
949 mesh_elements << endl;
953 for(
int i = 0; i < this->surfaces; i++) {
962 mesh_elements << ++current <<
" ";
963 mesh_elements << ind <<
" ";
964 mesh_elements << s->
getCode() <<
" ";
966 for(
int j = 0; j < s->
getNodes(); j++)
969 mesh_elements << endl;
973 for(
int i = 0; i < this->edges; i++) {
982 mesh_elements << ++current <<
" ";
983 mesh_elements << ind <<
" ";
984 mesh_elements << e->
getCode() <<
" ";
986 for(
int j = 0; j < e->
getNodes(); j++)
989 mesh_elements << endl;
993 for(
int i = 0; i < this->points; i++) {
1002 mesh_elements << ++current <<
" ";
1003 mesh_elements << ind <<
" ";
1004 mesh_elements << p->
getCode() <<
" ";
1006 for(
int j = 0; j < p->
getNodes(); j++)
1009 mesh_elements << endl;
1013 mesh_elements.close();
1017 sprintf(fileName,
"%s/mesh.boundary", dirName);
1019 mesh_boundary.open(fileName);
1021 if(!mesh_boundary.is_open()) {
1022 cout <<
"Unable to open " << fileName << endl;
1028 for(
int i = 0; i < this->surfaces; i++) {
1049 mesh_boundary << ++current <<
" ";
1050 mesh_boundary << ind <<
" ";
1051 mesh_boundary << e0 <<
" " << e1 <<
" ";
1052 mesh_boundary << s->
getCode() <<
" ";
1054 for(
int j = 0; j < s->
getNodes(); j++)
1057 mesh_boundary << endl;
1062 for(
int i = 0; i < this->edges; i++) {
1083 mesh_boundary << ++current <<
" ";
1084 mesh_boundary << ind <<
" ";
1085 mesh_boundary << s0 <<
" " << s1 <<
" ";
1086 mesh_boundary << e->
getCode() <<
" ";
1088 for(
int j = 0; j < e->
getNodes(); j++)
1091 mesh_boundary << endl;
1095 for(
int i = 0; i < this->points; i++) {
1113 mesh_boundary << ++current <<
" ";
1114 mesh_boundary << ind <<
" ";
1115 mesh_boundary << e0 <<
" " << e1 <<
" ";
1116 mesh_boundary << p->
getCode() <<
" ";
1118 for(
int j = 0; j < p->
getNodes(); j++)
1121 mesh_boundary << endl;
1125 mesh_boundary.close();
1127 delete [] bulk_by_type;
1128 delete [] boundary_by_type;
1137 double *result =
new double[10];
1148 for(
int i=0; i < this->nodes; i++) {
1149 node_t *node = &this->node[i];
1152 xmax = node->
getX(0);
1155 xmin = node->
getX(0);
1158 ymax = node->
getX(1);
1161 ymin = node->
getX(1);
1163 if(node->
getX(2) > zmax)
1164 zmax = node->
getX(2);
1166 if(node->
getX(2) < zmin)
1167 zmin = node->
getX(2);
1170 double xmid = (xmin +
xmax)/2.0;
1171 double ymid = (ymin +
ymax)/2.0;
1172 double zmid = (zmin + zmax)/2.0;
1174 double xlen = (xmax -
xmin)/2.0;
1175 double ylen = (ymax -
ymin)/2.0;
1176 double zlen = (zmax - zmin)/2.0;
1188 bool sx = xmin==
xmax;
1189 bool sy = ymin==
ymax;
1190 bool sz = zmin==zmax;
1194 if((sz && sy) || (sz && sx) || (sx && sy))
1197 else if(sz || sy || sx)
1253 return this->points;
1273 return this->surfaces;
1283 return this->elements;
1288 return &this->node[
n];
1303 delete [] this->node;
1323 delete [] this->
point;
1328 return &this->edge[
n];
1343 delete [] this->edge;
1368 return &this->element[
n];
1383 delete [] this->element;