Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
gmsh
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
gmsh
gmsh
Commits
23b9d246
Commit
23b9d246
authored
11 years ago
by
Christophe Geuzaine
Browse files
Options
Downloads
Patches
Plain Diff
SU2 mesh output
parent
392a55ba
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Geo/GModelIO_SU2.cpp
+109
-0
109 additions, 0 deletions
Geo/GModelIO_SU2.cpp
with
109 additions
and
0 deletions
Geo/GModelIO_SU2.cpp
0 → 100644
+
109
−
0
View file @
23b9d246
// Gmsh - Copyright (C) 1997-2013 C. Geuzaine, J.-F. Remacle
//
// See the LICENSE.txt file for license information. Please report all
// bugs and problems to the public mailing list <gmsh@geuz.org>.
#include
<stdlib.h>
#include
<string.h>
#include
"GModel.h"
#include
"OS.h"
#include
"MElement.h"
static
std
::
string
physicalName
(
GModel
*
m
,
int
dim
,
int
num
)
{
std
::
string
name
=
m
->
getPhysicalName
(
dim
,
num
);
if
(
name
.
empty
()){
char
tmp
[
256
];
sprintf
(
tmp
,
"%s%d"
,
(
dim
==
3
)
?
"PhysicalVolume"
:
(
dim
==
2
)
?
"PhysicalSurface"
:
"PhysicalLine"
,
num
);
name
=
tmp
;
}
for
(
unsigned
int
i
=
0
;
i
<
name
.
size
();
i
++
)
if
(
name
[
i
]
==
' '
)
name
[
i
]
=
'_'
;
return
name
;
}
int
GModel
::
writeSU2
(
const
std
::
string
&
name
,
bool
saveAll
,
double
scalingFactor
)
{
FILE
*
fp
=
Fopen
(
name
.
c_str
(),
"w"
);
if
(
!
fp
){
Msg
::
Error
(
"Unable to open file '%s'"
,
name
.
c_str
());
return
0
;
}
int
ndime
=
getDim
();
if
(
ndime
!=
2
&&
ndime
!=
3
){
Msg
::
Error
(
"SU2 mesh output valid only for 2D or 3D models (not %dD)"
,
ndime
);
return
0
;
}
if
(
noPhysicalGroups
())
saveAll
=
true
;
fprintf
(
fp
,
"NDIME= %d
\n
"
,
ndime
);
// all interior elements are printed in a single section; indices start at 0;
// node ordering is the same as VTK
int
nelem
=
0
;
if
(
ndime
==
2
){
for
(
fiter
it
=
firstFace
();
it
!=
lastFace
();
it
++
)
if
(
saveAll
||
(
*
it
)
->
physicals
.
size
())
nelem
+=
(
*
it
)
->
getNumMeshElements
();
}
else
{
for
(
riter
it
=
firstRegion
();
it
!=
lastRegion
();
it
++
)
if
(
saveAll
||
(
*
it
)
->
physicals
.
size
())
nelem
+=
(
*
it
)
->
getNumMeshElements
();
}
int
npoin
=
indexMeshVertices
(
saveAll
);
Msg
::
Info
(
"Writing %d elements and %d vertices"
,
nelem
,
npoin
);
// elements
fprintf
(
fp
,
"NELEM= %d
\n
"
,
nelem
);
int
num
=
0
;
if
(
ndime
==
2
){
for
(
fiter
it
=
firstFace
();
it
!=
lastFace
();
it
++
)
if
(
saveAll
||
(
*
it
)
->
physicals
.
size
())
for
(
int
i
=
0
;
i
<
(
*
it
)
->
getNumMeshElements
();
i
++
)
(
*
it
)
->
getMeshElement
(
i
)
->
writeSU2
(
fp
,
num
++
);
}
else
{
for
(
riter
it
=
firstRegion
();
it
!=
lastRegion
();
it
++
)
if
(
saveAll
||
(
*
it
)
->
physicals
.
size
())
for
(
int
i
=
0
;
i
<
(
*
it
)
->
getNumMeshElements
();
i
++
)
(
*
it
)
->
getMeshElement
(
i
)
->
writeSU2
(
fp
,
num
++
);
}
// vertices
fprintf
(
fp
,
"NPOIN= %d
\n
"
,
npoin
);
std
::
vector
<
GEntity
*>
entities
;
getEntities
(
entities
);
for
(
unsigned
int
i
=
0
;
i
<
entities
.
size
();
i
++
)
for
(
unsigned
int
j
=
0
;
j
<
entities
[
i
]
->
mesh_vertices
.
size
();
j
++
)
entities
[
i
]
->
mesh_vertices
[
j
]
->
writeSU2
(
fp
,
ndime
,
scalingFactor
);
// markers for physical groups of dimension (ndime - 1)
std
::
map
<
int
,
std
::
vector
<
GEntity
*>
>
groups
[
4
];
getPhysicalGroups
(
groups
);
int
nmark
=
groups
[
ndime
-
1
].
size
();
if
(
nmark
){
fprintf
(
fp
,
"NMARK= %d
\n
"
,
nmark
);
for
(
std
::
map
<
int
,
std
::
vector
<
GEntity
*>
>::
iterator
it
=
groups
[
ndime
-
1
].
begin
();
it
!=
groups
[
ndime
-
1
].
end
();
it
++
){
std
::
vector
<
GEntity
*>
&
entities
=
it
->
second
;
int
n
=
0
;
for
(
unsigned
int
i
=
0
;
i
<
entities
.
size
();
i
++
){
for
(
unsigned
int
j
=
0
;
j
<
entities
[
i
]
->
getNumMeshElements
();
j
++
)
n
++
;
}
if
(
n
){
fprintf
(
fp
,
"MARKER_TAG= %s
\n
"
,
physicalName
(
this
,
ndime
-
1
,
it
->
first
).
c_str
());
fprintf
(
fp
,
"MARKER_ELEMS= %d
\n
"
,
n
);
for
(
unsigned
int
i
=
0
;
i
<
entities
.
size
();
i
++
)
for
(
unsigned
int
j
=
0
;
j
<
entities
[
i
]
->
getNumMeshElements
();
j
++
)
entities
[
i
]
->
getMeshElement
(
j
)
->
writeSU2
(
fp
,
-
1
);
}
}
}
fclose
(
fp
);
return
1
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment