55 ProcessPerAlign::create);
67 "Tag identifying first surface.");
69 "Tag identifying first surface.");
71 "Direction in which to align (either x, y, or z)");
73 "Attempt to reorient tets and prisms");
86 int surf1 =
m_config[
"surf1"]. as<int> ();
87 int surf2 =
m_config[
"surf2"]. as<int> ();
88 string dir =
m_config[
"dir"]. as<string>();
89 bool orient =
m_config[
"orient"].as<
bool> ();
93 cerr <<
"WARNING: surf1 must be set to a positive integer. "
94 <<
"Skipping periodic alignment." << endl;
100 cerr <<
"WARNING: surf2 must be set to a positive integer. "
101 <<
"Skipping periodic alignment." << endl;
105 if (dir !=
"x" && dir !=
"y" && dir !=
"z")
107 cerr <<
"WARNING: dir must be set to either x, y or z. "
108 <<
"Skipping periodic alignment." << endl;
113 vec[0] = dir ==
"x" ? 1.0 : 0.0;
114 vec[1] = dir ==
"y" ? 1.0 : 0.0;
115 vec[2] = dir ==
"z" ? 1.0 : 0.0;
120 if (it1 ==
m_mesh->m_composite.end())
122 cerr <<
"WARNING: Couldn't find surface " << surf1
123 <<
". Skipping periodic alignment." << endl;
127 if (it2 ==
m_mesh->m_composite.end())
129 cerr <<
"WARNING: Couldn't find surface " << surf2 <<
", "
130 <<
"skipping periodic alignment." << endl;
137 if (c1->m_items.size() != c2->m_items.size())
139 cerr <<
"WARNING: Surfaces " << surf1 <<
" and " << surf2
140 <<
" have different numbers of elements. Skipping periodic"
141 <<
" alignment." << endl;
145 c1->m_reorder =
false;
146 c2->m_reorder =
false;
148 map<int, pair<FaceSharedPtr, vector<int> > > perFaces;
151 map<int, Node> centroidMap;
153 for (
int i = 0; i < c2->m_items.size(); ++i)
156 for (
int j = 0; j < c2->m_items[i]->GetVertexCount(); ++j)
158 centroid += *(c2->m_items[i]->GetVertex(j));
160 centroid /= (
NekDouble)c2->m_items[i]->GetVertexCount();
161 centroidMap[i] = centroid;
164 boost::unordered_set<int> elmtDone;
165 map<int, int> elmtPairs;
166 map<int, int> vertCheck;
168 for (
int i = 0; i < c1->m_items.size(); ++i)
171 for (
int j = 0; j < c1->m_items[i]->GetVertexCount(); ++j)
173 centroid += *(c1->m_items[i]->GetVertex(j));
175 centroid /= (
NekDouble)c1->m_items[i]->GetVertexCount();
177 for (it = centroidMap.begin(); it != centroidMap.end(); ++it)
179 if (elmtDone.count(it->first) > 0)
184 Node dx = it->second - centroid;
185 if (fabs(fabs(dx.
m_x*vec[0] + dx.
m_y*vec[1] + dx.
m_z*vec[2])/
186 sqrt(dx.
abs2()) - 1.0) < 1e-8)
189 int id1 = c1->m_items[i] ->GetFaceLink()->
m_id;
190 int id2 = c2->m_items[it->first]->GetFaceLink()->m_id;
192 elmtDone.insert(it->first);
193 elmtPairs[i] = it->first;
196 int nVerts = c1->m_items[i]->GetVertexCount();
197 vector<int> perVerts(nVerts, 0), perVertsInv(nVerts, 0);
201 for (
int k = 0; k < nVerts; ++k)
203 NodeSharedPtr n1 = c1->m_items[i]->GetFaceLink()->m_vertexList[k];
206 for (l = 0; l < nVerts; ++l)
209 c2->m_items[it->first]->GetFaceLink()->m_vertexList[l];
212 if (fabs(fabs(dn.
m_x*vec[0] + dn.
m_y*vec[1] +
214 sqrt(dn.
abs2()) - 1.0) < 1e-8)
221 if (vertCheck.count(id1) == 0)
223 vertCheck[id1] = id2;
228 "Periodic vertex already "
235 "Could not identify periodic vertices.");
238 int tot1 = 0, tot2 = 0;
239 for (
int k = 0; k < nVerts; ++k)
241 tot1 += perVerts [k];
242 tot2 += perVertsInv[k];
244 ASSERTL0(tot1 == nVerts*(nVerts-1)/2 &&
245 tot2 == nVerts*(nVerts-1)/2,
246 "Error identifying periodic vertices");
249 perFaces[id1] = make_pair(
250 c2->m_items[it->first]->GetFaceLink(), perVerts);
251 perFaces[id2] = make_pair(
252 c1->m_items[i] ->GetFaceLink(), perVertsInv);
257 if (it == centroidMap.end())
259 cerr <<
"WARNING: Could not find matching edge for surface "
260 <<
"element " << c1->m_items[i]->GetId() <<
". "
261 <<
"Skipping periodic alignment." << endl;
267 vector<ElementSharedPtr> tmp = c2->m_items;
271 for (
int i = 0; i < tmp.size(); ++i)
273 c2->m_items[i] = tmp[elmtPairs[i]];