-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmarker.cpp
More file actions
executable file
·177 lines (156 loc) · 3.54 KB
/
Copy pathmarker.cpp
File metadata and controls
executable file
·177 lines (156 loc) · 3.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*
ver.03.03
file marker.cpp
*/
#include "marker.h"
Marker::Marker(void):
weight(1.),
isSurface(false),
parent_elem(0),
material(NULL)
{
F.identity();
F_prev.identity();
F_.zero_out();
F_prev_.zero_out();
}
void Markers_handler::read_gid(ostringstream& filename){
using std::ifstream;
using std::cout;
using std::endl;
static const int MAX_CHAR=0x100;
//surface marker
ifstream fin(filename.str().c_str());
//issue5
try{
if(fin.fail()){
cout << "marker file not found" << endl;
throw;
}
}
catch(int){}
char dump[MAX_CHAR];
char title[MAX_CHAR];
fin.getline(dump,MAX_CHAR);
//title
fin >> dump >> title;
for(int i=0;i<3;i++)
fin.getline(dump,MAX_CHAR);
//coordinates
fin >> dump >> num_markers;
markers=new Marker[num_markers];
for(int i=0;i<2;i++)
fin.getline(dump,MAX_CHAR);
for(int i=0;i<num_markers;i++){
fin >> dump
>> markers[i].x[0]
>> markers[i].x[1]
>> markers[i].x[2];
for(int j=0;j<3;j++)
markers[i].X[j]=markers[i].x[j];
fin.getline(dump,MAX_CHAR);
}
for(int i=0;i<2;i++)
fin.getline(dump,MAX_CHAR);
//border
for(int i=0;i<2;i++)
fin.getline(dump,MAX_CHAR);
while(1){
Connectivity* newCon=new Connectivity;
fin >> newCon->elem_index >>
newCon->node_indices[0] >>
newCon->node_indices[1] >>
newCon->node_indices[2];
fin.getline(dump,MAX_CHAR);
if(fin.fail()){
delete newCon;
fin.clear();
break;
}
for(int i=0;i<NODE_IN_ELEM;i++){
newCon->node_indices[i]--;
newCon->pmarker[i]=&markers[newCon->node_indices[i]];
}
connectivity.push_back(newCon);
}
num_faces=connectivity.size();
try{
if(!num_faces){
cout << "no connectivity found" << endl;
throw;
}
}
catch(int){}
boundary=new Face[num_faces];
for(unsigned int i=0;i<num_faces;i++){
for(int j=0;j<NODE_IN_ELEM;j++){
markers[connectivity[i]->node_indices[j]].weight=.5;
markers[connectivity[i]->node_indices[j]].isSurface=true;
}
}
}
Markers_handler::~Markers_handler(void){
delete[] markers;
delete[] boundary;
for(unsigned int i=0;i<connectivity.size();i++)
delete connectivity[i];
}
void Markers_handler::update_element(void){
for(unsigned int i=0;i<velements.size();i++)
velements[i]->marker_clear();
for(int i=0;i<num_markers;i++){
if(velements[markers[i].parent_elem]->isInside(markers[i].x)){
velements[markers[i].parent_elem]->marker_add(&markers[i]);
}else{
markers[i].parent_elem=-1;
}
}
#ifdef __INTEL_COMPILER
#pragma omp parallel for
#endif
for(unsigned int j=0;j<velements.size();j++){
for(int i=0;i<num_markers;i++){
if(markers[i].parent_elem>=0)
continue;
if(velements[j]->isInside(markers[i].x)){
markers[i].parent_elem=j;
velements[j]->marker_add(&markers[i]);
}
}
}
#ifdef CHECK_MARKER
using std::cout;
using std::endl;
try{
for(int i=0;i<num_markers;i++){
if(markers[i].parent_elem<0){
cout<<"error: marker outside background mesh"<<endl;
cout << "marker" << i << endl;
for(int j=0;j<3;j++)
cout << markers[i].x[j] << "\t";
cout<<endl;
for(int j=0;j<3;j++)
cout << markers[i].X[j] <<"\t";
cout<<endl;
throw;
}
}
}catch(int){return;}
#endif
#ifdef __INTEL_COMPILER
#pragma omp parallel for
#endif
for(unsigned int i=0;i<num_faces;i++)
for(int j=0;j<3;j++)
for(int k=0;k<3;k++)
boundary[i].initialize(
markers[connectivity[i]->node_indices[j]].x[k]
);
#ifdef __INTEL_COMPILER
#pragma omp parallel for
#endif
for(unsigned int j=0;j<velements.size();j++)
for(unsigned int i=0;i<num_faces;i++)
if(velements[j]->isInside(boundary[i]))
velements[j]->face_add(&boundary[i]);
}