44 #include <boost/algorithm/string.hpp>
60 "Reads mesh from Star CCM (.ccm).");
90 cout <<
"InputStarTec: Start reading file..." << endl;
115 std::vector<NodeSharedPtr> Nodes;
119 map<int, vector<int> > FaceNodes;
127 vector< vector<int> > BndElementFaces;
128 vector<string> Facelabels;
130 ElementFaces, Facelabels);
141 int nelements = ElementFaces.num_elements();
142 cout <<
" Generating 3D Zones: " ;
144 for(i = 0; i < nelements; ++i)
147 if(ElementFaces[i].size() > 4)
150 FaceNodes,nComposite,
true);
154 cout << cnt <<
" Prisms,";
160 for(i = 0; i < nelements; ++i)
162 if(ElementFaces[i].size() == 4)
165 FaceNodes,nComposite,
true);
170 cout << cnt <<
" Tets" << endl;
177 for(i = 0; i < BndElementFaces.size(); ++i)
179 cout <<
" Generating 2D Zone (composite = " <<
180 nComposite <<
", label = "<< Facelabels[i] <<
")" << endl;
182 for(
int j = 0; j < BndElementFaces[i].size(); ++j)
185 if(FaceNodes.count(BndElementFaces[i][j]))
192 string msg =
"Failed to find FaceNodes for Face ";
193 msg += boost::lexical_cast<
string>(BndElementFaces[i][j]);
198 m_mesh->m_faceLabels[nComposite] = Facelabels[i];
205 vector<vector<int> > &FacesToPrisms,
206 vector<vector<int> > &PrismsToFaces,
207 vector<bool> &PrismDone);
211 map<
int, vector<int> >&FaceNodes)
215 int face1_map[3] = {0,1,4};
216 int face3_map[3] = {3,2,5};
218 map<int,bool> FacesRenumbered;
221 vector<vector<int> > FaceToPrisms(FaceNodes.size());
222 vector<vector<int> > PrismToFaces(ElementFaces.num_elements());
228 for(i = 0; i < ElementFaces.num_elements(); ++i)
231 if(ElementFaces[i].size() == 5)
233 vector<int> LocTriFaces;
235 for(j = 0; j < ElementFaces[i].size(); ++j)
237 if(FaceNodes[ElementFaces[i][j]].size() == 3)
239 LocTriFaces.push_back(j);
243 if(LocTriFaces.size() == 2)
247 PrismToFaces[i].push_back(ElementFaces[i][LocTriFaces[0]]);
248 PrismToFaces[i].push_back(ElementFaces[i][LocTriFaces[1]]);
250 FaceToPrisms[ElementFaces[i][LocTriFaces[0]]].push_back(i);
251 FaceToPrisms[ElementFaces[i][LocTriFaces[1]]].push_back(i);
257 vector<bool> FacesDone(FaceNodes.size(),
false);
258 vector<bool> PrismDone(ElementFaces.num_elements(),
false);
263 for(PrismIt = Prisms.begin(); PrismIt != Prisms.end(); ++PrismIt)
265 int elmtid = PrismIt->first;
266 map<int,int> facelist;
270 if(PrismDone[elmtid])
278 PrismToFaces, PrismDone);
281 for(faceIt = facelist.begin(); faceIt != facelist.end(); faceIt++)
283 int faceid = faceIt->second;
285 for(i = 0; i < FaceToPrisms[faceid].size(); ++i)
287 int prismid = FaceToPrisms[faceid][i];
289 if((FacesDone[PrismToFaces[prismid][0]] ==
true)&&
290 (FacesDone[PrismToFaces[prismid][1]] ==
true))
296 ElementFaces[prismid],
299 if((FacesDone[PrismToFaces[prismid][0]] ==
false)&&
300 (FacesDone[PrismToFaces[prismid][1]] ==
false))
304 for(i = 0; i < 3; ++i)
306 if(NodeReordering[Nodes[face1_map[i]]] == -1)
308 NodeReordering[Nodes[face1_map[i]]] = nodeid++;
312 for(i = 0; i < 3; ++i)
314 if(NodeReordering[Nodes[face3_map[i]]] == -1)
316 NodeReordering[Nodes[face3_map[i]]] = nodeid++;
320 else if((FacesDone[PrismToFaces[prismid][0]] ==
false)&&
321 (FacesDone[PrismToFaces[prismid][1]] ==
true))
326 max_id1 = (NodeReordering[Nodes[face3_map[0]]] <
327 NodeReordering[Nodes[face3_map[1]]] )? 1:0;
328 max_id2 = (NodeReordering[Nodes[face3_map[max_id1]]] <
329 NodeReordering[Nodes[face3_map[2]]] )? 2:max_id1;
332 int id0 = (max_id1== 1)? 0:1;
334 if(NodeReordering[Nodes[face1_map[id0]]] == -1)
336 NodeReordering[Nodes[face1_map[id0]]] =
340 if(NodeReordering[Nodes[face1_map[max_id1]]] == -1)
342 NodeReordering[Nodes[face1_map[max_id1]]] =
346 if(NodeReordering[Nodes[face1_map[max_id2]]] == -1)
348 NodeReordering[Nodes[face1_map[max_id2]]] =
352 else if((FacesDone[PrismToFaces[prismid][0]] ==
true)&&
353 (FacesDone[PrismToFaces[prismid][1]] ==
false))
359 max_id1 = (NodeReordering[Nodes[face1_map[0]]] <
360 NodeReordering[Nodes[face1_map[1]]] )? 1:0;
361 max_id2 = (NodeReordering[Nodes[face1_map[max_id1]]] <
362 NodeReordering[Nodes[face1_map[2]]] )? 2:max_id1;
365 int id0 = (max_id1== 1)? 0:1;
368 if(NodeReordering[Nodes[face3_map[id0]]] == -1)
370 NodeReordering[Nodes[face3_map[id0]]] =
374 if(NodeReordering[Nodes[face3_map[max_id1]]] == -1)
376 NodeReordering[Nodes[face3_map[max_id1]]] =
380 if(NodeReordering[Nodes[face3_map[max_id2]]] == -1)
382 NodeReordering[Nodes[face3_map[max_id2]]] =
393 for(i = 0; i < NodeReordering.num_elements(); ++i)
395 if(NodeReordering[i] == -1)
397 NodeReordering[i] = nodeid++;
401 ASSERTL1(nodeid == NodeReordering.num_elements(),
"Have not renumbered all nodes");
404 for(i = 0; i < FaceNodes.size(); ++i)
406 for(j = 0; j < FaceNodes[i].size(); ++j)
408 FaceNodes[i][j] = NodeReordering[FaceNodes[i][j]];
412 vector<NodeSharedPtr> save(Vnodes);
413 for(i = 0; i < Vnodes.size(); ++i)
415 Vnodes[NodeReordering[i]] = save[i];
416 Vnodes[NodeReordering[i]]->SetID(NodeReordering[i]);
424 vector<vector<int> > &FaceToPrisms,
425 vector<vector<int> > &PrismToFaces,
426 vector<bool> &PrismDone)
428 if(PrismDone[prismid] ==
false)
430 PrismDone[prismid] =
true;
433 int face = PrismToFaces[prismid][0];
434 facelist[face] = face;
435 for(
int i = 0; i < FaceToPrisms[face].size(); ++i)
438 PrismToFaces, PrismDone);
442 face = PrismToFaces[prismid][1];
443 facelist[face] = face;
444 for(
int i = 0; i < FaceToPrisms[face].size(); ++i)
447 PrismToFaces, PrismDone);
454 vector<int> &FaceNodes,
459 if(FaceNodes.size() == 3)
463 else if(FaceNodes.size() == 4)
469 ASSERTL0(
false,
"Not set up for elements which are not Tets or Prism");
474 tags.push_back(nComposite);
477 vector<NodeSharedPtr> nodeList;
479 for(
int j = 0; j < Nodes.num_elements(); ++j)
481 nodeList.push_back(VertNodes[Nodes[j]]);
488 m_mesh->m_element[E->GetDim()].push_back(E);
492 int i, vector<int> &ElementFaces,
493 map<
int, vector<int> >&FaceNodes,
494 int nComposite,
bool DoOrient)
499 int nnodes = Nodes.num_elements();
500 map<LibUtilities::ShapeType,int> domainComposite;
522 ASSERTL0(
false,
"Not set up for elements which are not Tets or Prism");
527 tags.push_back(nComposite);
530 vector<NodeSharedPtr> nodeList;
531 for(
int j = 0; j < Nodes.num_elements(); ++j)
533 nodeList.push_back(VertNodes[Nodes[j]]);
544 m_mesh->m_element[E->GetDim()].push_back(E);
548 cout <<
"Warning: Pyramid detected " << endl;
553 vector<int> &FaceNodes)
557 if(FaceNodes.size() == 3)
561 returnval[0] = FaceNodes[0];
562 returnval[1] = FaceNodes[1];
563 returnval[2] = FaceNodes[2];
565 else if(FaceNodes.size() == 4)
569 int indx0 = FaceNodes[0];
570 int indx1 = FaceNodes[1];
571 int indx2 = FaceNodes[2];
572 int indx3 = FaceNodes[3];
575 Node a = *(Vnodes[indx1]) - *(Vnodes[indx0]);
577 Node b = *(Vnodes[indx2]) - *(Vnodes[indx0]);
582 Node c = *(Vnodes[indx1]) - *(Vnodes[indx2]);
584 Node d = *(Vnodes[indx3]) - *(Vnodes[indx2]);
588 if(acurlb_dot_acurld > 0.0)
590 returnval[0] = indx0;
591 returnval[1] = indx1;
592 returnval[2] = indx2;
593 returnval[3] = indx3;
597 returnval[0] = indx0;
598 returnval[1] = indx1;
599 returnval[2] = indx3;
600 returnval[3] = indx2;
608 vector<int> &ElementFaces,
609 map<
int, vector<int> >&FaceNodes)
616 if(ElementFaces.size() == 4)
618 ASSERTL1(FaceNodes[ElementFaces[0]].size() == 3,
"Face is not triangular");
622 int indx0 = FaceNodes[ElementFaces[0]][0];
623 int indx1 = FaceNodes[ElementFaces[0]][1];
624 int indx2 = FaceNodes[ElementFaces[0]][2];
629 Node a = *(Vnodes[indx1]) - *(Vnodes[indx0]);
631 Node b = *(Vnodes[indx2]) - *(Vnodes[indx0]);
634 ASSERTL1(FaceNodes[ElementFaces[1]].size() == 3,
"Face is not triangular");
635 for(i = 0; i < 3; ++i)
638 if((FaceNodes[ElementFaces[1]][i] != indx0)&&(FaceNodes[ElementFaces[1]][i] != indx1)&&(FaceNodes[ElementFaces[1]][i] != indx2))
640 indx3 = FaceNodes[ElementFaces[1]][i];
646 Node c = *(Vnodes[indx3]) - *(Vnodes[indx0]);
650 if(acurlb_dotc < 0.0)
652 returnval[0] = indx0;
653 returnval[1] = indx1;
654 returnval[2] = indx2;
655 returnval[3] = indx3;
659 returnval[0] = indx1;
660 returnval[1] = indx0;
661 returnval[2] = indx2;
662 returnval[3] = indx3;
665 else if(ElementFaces.size() == 5)
667 int triface0, triface1;
668 int quadface0, quadface1, quadface2;
673 triface0 = triface1 = -1;
674 quadface0 = quadface1 = quadface2 = -1;
675 for(i = 0; i < 5; ++i)
677 if(FaceNodes[ElementFaces[i]].size() == 3)
683 else if (triface1 == -1)
694 if(FaceNodes[ElementFaces[i]].size() == 4)
700 else if (quadface1 == -1)
704 else if (quadface2 == -1)
714 ASSERTL1(quadface0 != -1,
"Quad face 0 not found");
715 ASSERTL1(quadface1 != -1,
"Quad face 1 not found");
716 ASSERTL1(quadface2 != -1,
"Quad face 2 not found");
717 ASSERTL1(triface0 != -1,
"Tri face 0 not found");
718 ASSERTL1(triface1 != -1,
"Tri face 1 not found");
725 cout <<
"Pyramid found with vertices: " << endl;
726 for(i =0 ; i < 5; ++i)
728 for(j =0; j < FaceNodes[ElementFaces[i]].size(); ++j)
730 vertids.insert(FaceNodes[ElementFaces[i]][j]);
733 for(it = vertids.begin(); it != vertids.end(); ++it)
735 cout << Vnodes[*it] << endl;
738 ASSERTL0(
false,
"Not yet set up for pyramids");
743 int indx0,indx1,indx2,indx3,indx4;
745 indx0 = indx1 = indx2 = indx3 = indx4 = -1;
750 for(i = 0; i < 4; ++i)
752 for(j = 0; j < 3; ++j)
754 if(FaceNodes[ElementFaces[triface0]][j] ==
755 FaceNodes[ElementFaces[quadface0]][i])
765 indx2 = FaceNodes[ElementFaces[quadface0]][i];
770 indx3 = FaceNodes[ElementFaces[quadface0]][i];
774 ASSERTL0(
false,
"More than two vertices do not match triangular face");
781 indx0 = FaceNodes[ElementFaces[quadface0]][i];
785 indx1 = FaceNodes[ElementFaces[quadface0]][i];
791 for(
int i = 0; i < 3; ++i)
793 if((FaceNodes[ElementFaces[triface0]][i] != indx0)&&
794 (FaceNodes[ElementFaces[triface0]][i] != indx1)&&
795 (FaceNodes[ElementFaces[triface0]][i] != indx2))
797 indx4 = FaceNodes[ElementFaces[triface0]][i];
803 Node a = *(Vnodes[indx1]) - *(Vnodes[indx0]);
805 Node b = *(Vnodes[indx4]) - *(Vnodes[indx0]);
807 Node c = *(Vnodes[indx2]) - *(Vnodes[indx0]);
811 if(acurlb_dotc < 0.0)
813 returnval[0] = indx0;
814 returnval[1] = indx1;
815 returnval[4] = indx4;
819 returnval[0] = indx1;
820 returnval[1] = indx0;
821 returnval[4] = indx4;
828 for(
int i = 0; i < 4; ++i)
830 if((FaceNodes[ElementFaces[quadface1]][i] == returnval[1])||
831 (FaceNodes[ElementFaces[quadface1]][i] == indx2))
839 returnval[2] = indx2;
840 returnval[3] = indx3;
845 for(
int i = 0; i < 4; ++i)
847 if((FaceNodes[ElementFaces[quadface2]][i] == returnval[1])||
848 (FaceNodes[ElementFaces[quadface2]][i] == indx2))
856 returnval[2] = indx3;
857 returnval[3] = indx2;
861 returnval[2] = indx2;
862 returnval[3] = indx3;
870 for(
int i = 0; i < 3; ++i)
872 if((FaceNodes[ElementFaces[triface1]][i] != indx2)&&
873 (FaceNodes[ElementFaces[triface1]][i] != indx3)&&
874 (FaceNodes[ElementFaces[triface1]][i] != indx3))
876 returnval[5] = FaceNodes[ElementFaces[triface1]][i];
885 ASSERTL0(
false,
"SortFaceNodes not set up for this number of faces");
900 string fname =
m_config[
"infile"].as<
string>();
901 m_ccmErr = CCMIOOpenFile(NULL, fname.c_str(), kCCMIORead, &root);
903 CCMIOSize_t i = CCMIOSIZEC(0);
904 CCMIOID state, problem;
910 CCMIOGetState(&m_ccmErr, root, kDefaultState, &problem, &state);
911 if (m_ccmErr != kCCMIONoErr)
913 cout <<
"No state named '" << kDefaultState <<
"'" << endl;
920 CCMIONextEntity(&m_ccmErr, state, kCCMIOProcessor, &i, &
m_ccmProcessor);
925 CCMIOID mapID, vertices;
926 CCMIOSize_t nVertices, size, dims = CCMIOSIZEC(1);
930 CCMIOEntitySize(&
m_ccmErr, vertices, &nVertices, NULL);
938 int mapData[nVertices.getValue()];
939 float verts[3*nVertices.getValue()];
940 for(
int k = 0; k < nVertices; ++k)
942 verts[3*k] = verts[3*k+1] = verts[3*k+2] = 0.0;
945 CCMIOReadVerticesf(&
m_ccmErr, vertices, &dims, &scale, &mapID, verts,
947 CCMIOINDEXC(0+nVertices));
948 CCMIOReadMap(&
m_ccmErr, mapID, mapData,
949 CCMIOINDEXC(0), CCMIOINDEXC(0+nVertices));
951 for(
int i = 0; i < nVertices; ++i)
953 Nodes.push_back(boost::shared_ptr<Node>(
new Node(i,verts[3*i],
965 CCMIOSize_t nFaces,size;
966 vector<int> faces, faceCells, mapData;
970 kCCMIOInternalFaces, 0, &
id);
971 CCMIOEntitySize(&
m_ccmErr,
id, &nFaces, NULL);
973 int nf = TOINT64(nFaces);
975 faceCells.resize(2 * nf);
977 CCMIOReadFaces(&
m_ccmErr,
id, kCCMIOInternalFaces, NULL,
978 &size, NULL, CCMIOINDEXC(kCCMIOStart),
979 CCMIOINDEXC(kCCMIOEnd));
980 faces.resize(TOINT64(size));
981 CCMIOReadFaces(&
m_ccmErr,
id, kCCMIOInternalFaces, &mapID,
982 NULL, &faces[0],CCMIOINDEXC(kCCMIOStart),
983 CCMIOINDEXC(kCCMIOEnd));
984 CCMIOReadFaceCells(&
m_ccmErr,
id, kCCMIOInternalFaces,
985 &faceCells[0], CCMIOINDEXC(kCCMIOStart),
986 CCMIOINDEXC(kCCMIOEnd));
987 CCMIOReadMap(&
m_ccmErr, mapID, &mapData[0],
988 CCMIOINDEXC(kCCMIOStart), CCMIOINDEXC(kCCMIOEnd));
992 for(
int i = 0; i < nf; ++i)
996 if(cnt < faces.size())
999 ASSERTL0(nv<= 4,
"Can only handle meshes with "
1000 "up to four nodes per face");
1002 for(j = 0; j < nv; ++j)
1004 if(cnt+1+j < faces.size())
1006 Fnodes.push_back(faces[cnt+1+j]-1);
1011 FacesNodes[mapData[i]-1] = Fnodes;
1017 for(
int i = 0; i < faceCells.size();++i)
1019 nelmt = max(nelmt,faceCells[i]);
1023 for(
int i = 0; i < nf; ++i)
1028 ElementFaces[faceCells[2*i] -1].push_back(mapData[i]-1);
1032 if(faceCells[2*i+1])
1034 ElementFaces[faceCells[2*i+1]-1].push_back(mapData[i]-1);
1041 map<
int, vector<int> >&FacesNodes,
1042 Array<
OneD, vector<int> > &ElementFaces,
1043 vector<string> &Facelabels)
1046 CCMIOSize_t index = CCMIOSIZEC(0);
1048 CCMIOSize_t nFaces,size;
1049 vector<int> faces, faceCells, mapData;
1050 vector<string> facelabel;
1053 kCCMIOBoundaryFaces, &index, &
id)
1058 CCMIOEntitySize(&
m_ccmErr,
id, &nFaces, NULL);
1059 int nf = TOINT64(nFaces);
1061 faceCells.resize(nf);
1062 CCMIOReadFaces(&
m_ccmErr,
id, kCCMIOBoundaryFaces,
1064 CCMIOINDEXC(kCCMIOStart),
1065 CCMIOINDEXC(kCCMIOEnd));
1067 faces.resize(TOINT64(size));
1068 CCMIOReadFaces(&
m_ccmErr,
id, kCCMIOBoundaryFaces,
1069 &mapID, NULL, &faces[0],
1070 CCMIOINDEXC(kCCMIOStart),
1071 CCMIOINDEXC(kCCMIOEnd));
1072 CCMIOReadFaceCells(&
m_ccmErr,
id, kCCMIOBoundaryFaces,
1074 CCMIOINDEXC(kCCMIOStart),
1075 CCMIOINDEXC(kCCMIOEnd));
1076 CCMIOReadMap(&
m_ccmErr, mapID, &mapData[0],
1077 CCMIOINDEXC(kCCMIOStart), CCMIOINDEXC(kCCMIOEnd));
1079 CCMIOGetEntityIndex(&
m_ccmErr,
id, &boundaryVal);
1084 if(CCMIOReadOptstr(NULL,
id,
"Label", &size, NULL) == kCCMIONoErr){
1085 name=
new char[size+1];
1086 CCMIOReadOptstr(NULL,
id,
"Label", NULL, name);
1087 Facelabels.push_back(
string(name));
1091 Facelabels.push_back(
"Not known");
1097 for(
int i = 0; i < nf; ++i)
1101 if(cnt < faces.size())
1103 int nv = faces[cnt];
1104 ASSERTL0(nv<= 4,
"Can only handle meshes with "
1105 "up to four nodes per face");
1107 for(j = 0; j < nv; ++j)
1109 if(cnt+1+j < faces.size())
1111 Fnodes.push_back(faces[cnt+1+j]-1);
1116 FacesNodes[mapData[i]-1] = Fnodes;
1120 vector<int> BndFaces;
1121 for(
int i = 0; i < nf; ++i)
1125 ElementFaces[faceCells[i]-1].push_back(mapData[i]-1);
1127 BndFaces.push_back(mapData[i]-1);
1129 BndElementFaces.push_back(BndFaces);
#define ASSERTL0(condition, msg)
pair< ModuleType, string > ModuleKey
tBaseSharedPtr CreateInstance(tKey idKey BOOST_PP_COMMA_IF(MAX_PARAM) BOOST_PP_ENUM_BINARY_PARAMS(MAX_PARAM, tParam, x))
Create an instance of the class referred to by idKey.
Node curl(const Node &pSrc) const
map< string, ConfigOption > m_config
List of configuration values.
MeshSharedPtr m_mesh
Mesh object.
virtual void ProcessEdges(bool ReprocessEdges=true)
Extract element edges.
boost::shared_ptr< Element > ElementSharedPtr
Shared pointer to an element.
virtual void ProcessVertices()
Extract element vertices.
virtual void ProcessElements()
Generate element IDs.
boost::shared_ptr< Mesh > MeshSharedPtr
Shared pointer to a mesh.
Basic information about an element.
virtual void ProcessComposites()
Generate composites.
Represents a point in the domain.
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs typedef NekMatrix< LhsDataType, StandardMatrixTag >::iterator iterator
static void PrismLineFaces(int prismid, map< int, int > &facelist, vector< vector< int > > &FacesToPrisms, vector< vector< int > > &PrismsToFaces, vector< bool > &PrismDone)
NekDouble dot(const Node &pSrc) const
virtual void ProcessFaces(bool ReprocessFaces=true)
Extract element faces.
static char const kDefaultState[]
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode...
ElementFactory & GetElementFactory()
ModuleFactory & GetModuleFactory()
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, tDescription pDesc="")
Register a class with the factory.