Newlines in UNV output section 2477
The UNV output is usually consumed by legacy readers/converters. I think there might a minor issue with endlines when writing group data when both nodes and elements are written. I say I am not sure because I do not know if there is a standard and if it addresses this issue or not. All I could found was https://docs.plm.automation.siemens.com/tdoc/nx/12/nx_help#uid:xid1128419:index_advanced:xid602249:xid1390189:xid1390190:xid1390195:id973882
For example, this is the current output:
7 71 0 0 7 72 0 0
7 73 0 0
8 1 0 0 8 2 0 0
8 3 0 0 8 4 0 0
When switching from an odd number of nodes (7) to elements (8) there is one line with data for one node only. I found that some legacy readers struggle because they read the UNV line-by-line and they allocate the number of lines to be read from the number of entities in the section.
I modified GModelIO_UNV.cpp
like this
--- GModelIO_UNV.cpp 2021-09-20 09:33:07.245391781 -0300
+++ GModelIO_UNV.cpp 2021-10-27 06:37:47.617668100 -0300
@@ -466,8 +466,8 @@
0, 0, (int)nodes.size() + nele);
fprintf(fp, "%s\n", physicalName(this, dim, it->first).c_str());
+ int row = 0;
if(saveGroupsOfNodes) {
- int row = 0;
for(auto it2 = nodes.begin(); it2 != nodes.end(); it2++) {
if(row == 2) {
fprintf(fp, "\n");
@@ -476,10 +476,17 @@
fprintf(fp, "%10d%10ld%10d%10d", 7, (*it2)->getIndex(), 0, 0);
row++;
}
+ }
+
+ // this output will be consumed by legacy codes that rely on
+ // full lines, each having two entities even if the first is
+ // a node and the second is an element
+ if(row == 2) {
fprintf(fp, "\n");
+ row = 0;
}
+
if(saveGroupsOfElements) {
- int row = 0;
for(std::size_t i = 0; i < entities.size(); i++) {
for(std::size_t j = 0; j < entities[i]->getNumMeshElements(); j++) {
MElement *e = entities[i]->getMeshElement(j);
So now the output is
7 71 0 0 7 72 0 0
7 73 0 0 8 1 0 0
8 2 0 0 8 3 0 0
8 4 0 0 8 5 0 0
and the legacy reader works. Let me know @geuzaine if this change is worth introducing into Gmsh or I am getting it wrong. If it is, let me also know if the patch above is enough or you want me to create a pull request.