gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
GModelIO_SAMCEF.cpp
Go to the documentation of this file.
1 // Gmsh - Copyright (C) 1997-2022 C. Geuzaine, J.-F. Remacle
2 //
3 // See the LICENSE.txt file in the Gmsh root directory for license information.
4 // Please report all issues on https://gitlab.onelab.info/gmsh/gmsh/issues.
5 
6 #include <stdlib.h>
7 #include <string.h>
8 #include <sstream>
9 #include "GModel.h"
10 #include "OS.h"
11 #include "MLine.h"
12 #include "MTriangle.h"
13 #include "MQuadrangle.h"
14 #include "MTetrahedron.h"
15 #include "MHexahedron.h"
16 #include "Context.h"
17 
18 static bool getMeshVertices(GModel *m, int num, int *n,
19  std::vector<MVertex *> &vec)
20 {
21  for(int i = 0; i < num; i++) {
22  MVertex *v = m->getMeshVertexByTag(n[i]);
23  if(!v) {
24  Msg::Error("Wrong node number %d", n[i]);
25  return false;
26  }
27  else
28  vec.push_back(v);
29  }
30  return true;
31 }
32 
33 int GModel::readSAMCEF(const std::string &name)
34 {
35  FILE *fp = Fopen(name.c_str(), "r");
36  if(!fp) {
37  Msg::Error("Unable to open file '%s'", name.c_str());
38  return 0;
39  }
40 
41  _vertexMapCache.clear();
42  std::map<int, std::vector<MElement *> > elements[2];
43  char buffer[256], dummy[256];
44 
45  while(!feof(fp)) {
46  if(!fgets(buffer, 256, fp)) break;
47  if(!strncmp(buffer, ".NOE", 4)) {
48  while(!feof(fp)) {
49  if(!fgets(buffer, 256, fp)) break;
50  if(buffer[0] == '!') continue;
51  if(buffer[0] == ';') break;
52  int num;
53  double x, y, z;
54  if(sscanf(buffer, "%s %d %s %lf %s %lf %s %lf", dummy, &num, dummy, &x,
55  dummy, &y, dummy, &z) != 8)
56  return 0;
57  _vertexMapCache[num] = new MVertex(x, y, z, nullptr, num);
58  }
59  Msg::Info("Read %d mesh nodes", (int)_vertexMapCache.size());
60  }
61  else if(!strncmp(buffer, ".MAI", 4)) {
62  while(!feof(fp)) {
63  if(!fgets(buffer, 256, fp)) break;
64  if(buffer[0] == '!') continue;
65  if(buffer[0] == ';') break;
66  std::stringstream s(buffer);
67  std::string word;
68  int nn = 0;
69  while(s >> word) nn++;
70  int num, reg, n[4];
71  std::vector<MVertex *> vertices;
72  if(nn == 8) { // TRIA3
73  if(sscanf(buffer, "%s %d %s %d %s %d %d %d", dummy, &num, dummy, &reg,
74  dummy, &n[0], &n[1], &n[2]) != 8)
75  return 0;
76  if(!getMeshVertices(this, 3, n, vertices)) break;
77  elements[0][reg].push_back(new MTriangle(vertices, num));
78  }
79  else if(nn == 9) { // QUAD4
80  if(sscanf(buffer, "%s %d %s %d %s %d %d %d %d", dummy, &num, dummy,
81  &reg, dummy, &n[0], &n[1], &n[2], &n[3]) != 9)
82  return 0;
83  if(!getMeshVertices(this, 4, n, vertices)) break;
84  elements[1][reg].push_back(new MQuadrangle(vertices, num));
85  }
86  }
87  }
88  }
89 
90  for(int i = 0; i < (int)(sizeof(elements) / sizeof(elements[0])); i++)
91  _storeElementsInEntities(elements[i]);
94 
95  fclose(fp);
96  return 1;
97 }
MTriangle.h
Msg::Info
static void Info(const char *fmt,...)
Definition: GmshMessage.cpp:587
OS.h
MVertex
Definition: MVertex.h:24
Msg::Error
static void Error(const char *fmt,...)
Definition: GmshMessage.cpp:482
GModel::_storeElementsInEntities
void _storeElementsInEntities(std::map< int, std::vector< MElement * > > &map)
Definition: GModel.cpp:2273
GModel::getMeshVertexByTag
MVertex * getMeshVertexByTag(int n)
Definition: GModel.cpp:1953
MLine.h
Fopen
FILE * Fopen(const char *f, const char *mode)
Definition: OS.cpp:273
getMeshVertices
static bool getMeshVertices(GModel *m, int num, int *n, std::vector< MVertex * > &vec)
Definition: GModelIO_SAMCEF.cpp:18
MHexahedron.h
GModel
Definition: GModel.h:44
GModel::vertices
std::set< GVertex *, GEntityPtrLessThan > vertices
Definition: GModel.h:146
GModel::_vertexMapCache
std::map< int, MVertex * > _vertexMapCache
Definition: GModel.h:102
MTriangle
Definition: MTriangle.h:26
GModel::readSAMCEF
int readSAMCEF(const std::string &name)
Definition: GModelIO_SAMCEF.cpp:33
Context.h
MTetrahedron.h
z
const double z
Definition: GaussQuadratureQuad.cpp:56
MQuadrangle.h
GModel.h
GModel::_storeVerticesInEntities
void _storeVerticesInEntities(std::map< int, MVertex * > &vertices)
Definition: GModel.cpp:2496
GModel::_associateEntityWithMeshVertices
void _associateEntityWithMeshVertices()
Definition: GModel.cpp:2470
MQuadrangle
Definition: MQuadrangle.h:26