-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSmoothHessians.cc
More file actions
208 lines (167 loc) · 6.56 KB
/
SmoothHessians.cc
File metadata and controls
208 lines (167 loc) · 6.56 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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#include "phParAdapt.h"
#include <iostream>
#include <stdlib.h>
using namespace std;
#ifdef __cplusplus
extern "C" {
#endif
extern pMeshDataId nodalHessianID;
extern pMeshDataId numSurroundNodesID;
// simple average over a patch surrounding the vertex
void
SmoothHessians(pMesh mesh) {
pVertex v;
VIter vIter=M_vertexIter(mesh);
int vCount=0;
int* numSurroundingVerts = new int[M_numVertices(mesh)];
// keep the vals in memory before finally setting them
double** averageHessian;
averageHessian = new double*[M_numVertices(mesh)];
#if ( defined DEBUG )
// printf("[%i] in SmoothHessians:\n",PMU_rank());
#endif
while(v = VIter_next(vIter)) {
averageHessian[vCount] = new double[6];
for(int iHess=0;iHess<6;iHess++) {
averageHessian[vCount][iHess]=0.0;
}
// can be different from V_numEdges
// will include the actual vertex, too
numSurroundingVerts[vCount]=0;
// exclude non-interor vertex from contributing to
// its own average
// also make sure this vertex is owned by this proc
if(V_whatInType(v)== 3 && EN_isOwnerProc((pEntity)v) ) {
// first the "central" vertex
double *nodalHessian;
if(!EN_getDataPtr((pEntity)v, nodalHessianID,(void**)&nodalHessian)){
cout<<"\nerror in SmoothHessians: no data attached to vertex\n";
V_info(v);
exit(0);
}
for(int iHess=0; iHess<6; iHess++) {
averageHessian[vCount][iHess]= averageHessian[vCount][iHess] + nodalHessian[iHess];
}
numSurroundingVerts[vCount]++;
#if ( defined DEBUG )
// double c[3];
// V_coord(v,c);
// printf("\n[%i]contributing to vert: coords %f %f %f\n",PMU_rank(),c[0],c[1],c[2]);
#endif
}//if(V_whatInType(v)== 3 && ..
int numEdges = V_numEdges(v);
pEdge edge;
// now for the surrounding vertices
// now this vertex v also can be non-owned
// but EDGES to surrounding verts MUST be owned and verts also be off model-bdry
for(int i=0; i<numEdges ; i++){
edge = V_edge(v,i);
if(EN_isOwnerProc((pEntity)edge)){
pVertex otherVertex;
otherVertex = E_otherVertex(edge,v);
#if ( defined DEBUG )
// double cfq[3], cvq[3];
// V_coord(otherVertex,cfq);
// V_coord(v,cvq);
// printf("\n[%i]considering other vertex (ORIG) (ownflag %i) %f %f %f:\n",PMU_rank(),EN_isOwnerProc((pEntity)v),cvq[0],cvq[1],cvq[2]);
// printf("coords %f %f %f (orig) %f %f %f\n",cfq[0],cfq[1],cfq[2],cvq[0],cvq[1],cvq[2]);
#endif
// if neighbor vert is NOT on bdry NOR is it NOT owned (neighbor HAS to be owned)
if(V_whatInType(otherVertex)== 3){//is in interior
double *nodalHessianOther;
if(!EN_getDataPtr((pEntity)otherVertex, nodalHessianID,(void**)&nodalHessianOther)){
cout<<"\nerror in SmoothHessians: no data attached to OTHER vertex\n";
V_info(otherVertex);
exit(0);
}
// add values up
for(int iHess=0;iHess<6;iHess++) {
averageHessian[vCount][iHess] = averageHessian[vCount][iHess] + nodalHessianOther[iHess];
}
numSurroundingVerts[vCount]++;
#if ( defined DEBUG )
// printf("\n[%i]is also vert (orig):\n",PMU_rank());
// double cf[3], cv[3];
// V_coord(otherVertex,cf);
// V_coord(v,cv);
// printf("coords %f %f %f (orig) %f %f %f\n",cf[0],cf[1],cf[2],cv[0],cv[1],cv[2]);
#endif
}//if(V_whatInType(otherVertex)== 3
}// if(EN_isOwnerProc(edge){
}//for( numEdges
// At this moment we cannnot decide whether a vertex' neighbors are
// exclusively on the bdry --> also look at adjacent partitions
// for now, we rely that the initial mesh hase been prepared and got
// all its bdry-only elements removed
// if no surronding vertex found
// this is not a good point to take care of this for partitioned mesh
if(!numSurroundingVerts[vCount]) {
double *nodalHessian;
if(!EN_getDataPtr((pEntity)v, nodalHessianID,(void**)&nodalHessian)){
cout<<"\nerror in SmoothHessians: no data attached to vertex\n";
V_info(v);
exit(0);
}
// just add its own values up
// mostly the case when a region has no intr. node/vert.
for(int iHess=0;iHess<6;iHess++) {
averageHessian[vCount][iHess] = averageHessian[vCount][iHess] + nodalHessian[iHess];
}
numSurroundingVerts[vCount]++;
}
// if(!numSurroundingVerts[vCount]){
// cout<<"\nerror in SmoothHessians: there is a boundary vertex whose\n"
// <<"neighbors are exclusively classsified on modelfaces/edges/vertices\n"
// <<"and NOT in the interior\n";
// cout<<"For the following vertex : "<<endl;
// V_info(v);
// exit(0);
// }
vCount++;
}// while v = vIter
VIter_reset(vIter);
vCount=0;
while(v = VIter_next(vIter)) {
// delete the old Hessian data
double* oldHessian;
if(!EN_getDataPtr((pEntity)v, nodalHessianID,(void**)&oldHessian)){
cout<<"\nerror in SmoothHessians: no data attached to OTHER vertex\n";
V_info(v);
exit(0);
}
// delete [] oldHessian;
// EN_deleteData((pEntity)v, nodalHessianID);
double* smoothHess = new double[6];
for(int k=0;k<6;k++){
smoothHess[k] = averageHessian[vCount][k];
}
delete [] oldHessian;
EN_deleteData( (pEntity)v, nodalHessianID);
EN_attachDataPtr( (pEntity)v, nodalHessianID, (void *)
smoothHess);
//
double* nSurrNodes = new double[1];
nSurrNodes[0] = 1.0*numSurroundingVerts[vCount] ;
EN_attachDataPtr( (pEntity)v, numSurroundNodesID, (void *)
nSurrNodes);
#if ( defined DEBUG )
// printf("\n[%i]attaching in SmoothHessians:\n %f %f %f\n",PMU_rank(),smoothHess[0],smoothHess[1],smoothHess[2]);
// printf(" %f %f %f\n",smoothHess[3],smoothHess[4],smoothHess[5]);
// printf("\nand local numSurrVertex Num %f\n",nSurrNodes[0]);
// printf("for vertex:");
// double c[3];
// V_coord(v,c);
// printf("coords %f %f %f\n",c[0],c[1],c[2]);
#endif
vCount++;
}
VIter_delete(vIter);
for(int i=0;i<M_numVertices(mesh);i++){
delete [] averageHessian[i];
}
delete [] averageHessian;
delete [] numSurroundingVerts;
}
#ifdef __cplusplus
}
#endif