23 (dim == 3) ?
"PhysicalVolume" :
24 (dim == 2) ?
"PhysicalSurface" :
29 for(std::size_t i = 0; i < name.size(); i++)
30 if(name[i] ==
' ') name[i] =
'_';
34 static int partID(
int dim,
int num) {
return dim * 1000000 + num; }
40 if(elements.size() && (saveAll || ge->
physicals.size())) {
41 const char *typ = elements[0]->getStringForKEY();
44 fprintf(fp,
"*ELEMENT%s\n$#SET_ELEMENT=%s%d\n", typ,
47 for(std::size_t i = 0; i < elements.size(); i++)
48 elements[i]->writeKEY(fp, pid, elements[i]->getNum());
54 int saveGroupsOfNodes,
double scalingFactor)
56 FILE *fp =
Fopen(name.c_str(),
"w");
58 Msg::Error(
"Unable to open file '%s'", name.c_str());
69 std::vector<GEntity *> entities;
72 fprintf(fp,
"$# LS-DYNA Keyword file created by Gmsh\n*KEYWORD\n*TITLE\n");
73 fprintf(fp,
" %s\n", name.c_str());
75 fprintf(fp,
"*NODE\n");
76 for(std::size_t i = 0; i < entities.size(); i++)
77 for(std::size_t j = 0; j < entities[i]->mesh_vertices.size(); j++)
78 entities[i]->mesh_vertices[j]->
writeKEY(fp, scalingFactor);
101 std::map<int, std::vector<GEntity *> > groups[4];
106 if(saveGroupsOfNodes & 0x2) {
107 for(
int dim = 0; dim <= 3; dim++) {
108 if(saveAll & (0x2 << (2 * dim)))
continue;
109 for(
auto it = groups[dim].begin(); it != groups[dim].end(); it++) {
110 std::vector<GEntity *> &entities = it->second;
112 for(std::size_t i = 0; i < entities.size(); i++) {
113 for(std::size_t j = 0; j < entities[i]->getNumMeshElements(); j++) {
114 MElement *e = entities[i]->getMeshElement(j);
116 const char *str = (e->
getDim() == 3) ?
"SOLID" :
117 (e->
getDim() == 2) ?
"SHELL" :
118 (e->
getDim() == 1) ?
"BEAM" :
120 fprintf(fp,
"*SET_%s_LIST\n$# %s\n%d", str,
124 fprintf(fp,
"\n%lu", e->
getNum());
126 fprintf(fp,
", %lu", e->
getNum());
130 if(n) fprintf(fp,
"\n");
136 if(saveGroupsOfNodes & 0x1) {
137 for(
int dim = 1; dim <= 3; dim++) {
138 for(
auto it = groups[dim].begin(); it != groups[dim].end(); it++) {
139 std::set<MVertex *> nodes;
140 std::vector<GEntity *> &entities = it->second;
141 for(std::size_t i = 0; i < entities.size(); i++) {
142 for(std::size_t j = 0; j < entities[i]->getNumMeshElements(); j++) {
143 MElement *e = entities[i]->getMeshElement(j);
148 fprintf(fp,
"*SET_NODE_LIST\n$# %s\n%d",
151 for(
auto it2 = nodes.begin(); it2 != nodes.end(); it2++) {
153 fprintf(fp,
"\n%ld", (*it2)->getIndex());
155 fprintf(fp,
", %ld", (*it2)->getIndex());
158 if(n) fprintf(fp,
"\n");
163 fprintf(fp,
"*END\n");