Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tnl-dev
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
TNL
tnl-dev
Commits
4934ddb6
There was an error fetching the commit references. Please try again later.
Commit
4934ddb6
authored
3 years ago
by
Jakub Klinkovský
Browse files
Options
Downloads
Patches
Plain Diff
Refactored tnl-mesh-converter to support all file formats and mesh topologies, including polyhedron
parent
b4cb0152
No related branches found
No related tags found
1 merge request
!117
Mesh followup
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Tools/tnl-mesh-converter.cpp
+96
-33
96 additions, 33 deletions
src/Tools/tnl-mesh-converter.cpp
with
96 additions
and
33 deletions
src/Tools/tnl-mesh-converter.cpp
+
96
−
33
View file @
4934ddb6
...
...
@@ -10,10 +10,11 @@
#include
<TNL/Config/parseCommandLine.h>
#include
<TNL/Meshes/TypeResolver/resolveMeshType.h>
#include
<TNL/Meshes/Writers/FPMAWriter.h>
#include
<TNL/Meshes/Writers/VTKWriter.h>
#include
<TNL/Meshes/Writers/VTUWriter.h>
//
#include <TNL/Meshes/Writers/VTIWriter.h>
//
#include <TNL/Meshes/Writers/NetgenWriter.h>
#include
<TNL/Meshes/Writers/VTIWriter.h>
#include
<TNL/Meshes/Writers/NetgenWriter.h>
using
namespace
TNL
;
...
...
@@ -46,6 +47,7 @@ template<> struct MeshCellTopologyTag< MeshConverterConfigTag, Topologies::Tetra
template
<
>
struct
MeshCellTopologyTag
<
MeshConverterConfigTag
,
Topologies
::
Hexahedron
>
{
static
constexpr
bool
enabled
=
true
;
};
template
<
>
struct
MeshCellTopologyTag
<
MeshConverterConfigTag
,
Topologies
::
Wedge
>
{
static
constexpr
bool
enabled
=
true
;
};
template
<
>
struct
MeshCellTopologyTag
<
MeshConverterConfigTag
,
Topologies
::
Pyramid
>
{
static
constexpr
bool
enabled
=
true
;
};
template
<
>
struct
MeshCellTopologyTag
<
MeshConverterConfigTag
,
Topologies
::
Polyhedron
>
{
static
constexpr
bool
enabled
=
true
;
};
// Meshes are enabled only for the space dimension equal to the cell dimension.
template
<
typename
CellTopology
,
int
SpaceDimension
>
...
...
@@ -72,6 +74,13 @@ struct MeshConfigTemplateTag< MeshConverterConfigTag >
{
static
constexpr
bool
subentityStorage
(
int
entityDimension
,
int
subentityDimension
)
{
// faces must be stored for polyhedral meshes
if
(
std
::
is_same
<
Cell
,
TNL
::
Meshes
::
Topologies
::
Polyhedron
>::
value
)
{
if
(
subentityDimension
==
0
&&
entityDimension
==
Cell
::
dimension
-
1
)
return
true
;
if
(
subentityDimension
==
Cell
::
dimension
-
1
&&
entityDimension
==
Cell
::
dimension
)
return
true
;
}
return
subentityDimension
==
0
&&
entityDimension
==
Cell
::
dimension
;
}
...
...
@@ -96,54 +105,107 @@ struct MeshConfigTemplateTag< MeshConverterConfigTag >
}
// namespace Meshes
}
// namespace TNL
// specialization for polyhedral meshes
template
<
typename
Mesh
,
std
::
enable_if_t
<
std
::
is_same
<
typename
Mesh
::
Cell
::
EntityTopology
,
TNL
::
Meshes
::
Topologies
::
Polyhedron
>
::
value
,
bool
>
=
true
>
bool
writeMesh
(
const
Mesh
&
mesh
,
std
::
ostream
&
out
,
const
std
::
string
&
format
)
{
if
(
format
==
"fpma"
)
{
using
Writer
=
Meshes
::
Writers
::
FPMAWriter
<
Mesh
>
;
Writer
writer
(
out
);
writer
.
writeEntities
(
mesh
);
return
true
;
}
// TODO: implement VTKWriter for polyhedral meshes
// if( format == "vtk" ) {
// using Writer = Meshes::Writers::VTKWriter< Mesh >;
// Writer writer( out );
// writer.template writeEntities< Mesh::getMeshDimension() >( mesh );
// return true;
// }
if
(
format
==
"vtu"
)
{
using
Writer
=
Meshes
::
Writers
::
VTUWriter
<
Mesh
>
;
Writer
writer
(
out
);
writer
.
template
writeEntities
<
Mesh
::
getMeshDimension
()
>(
mesh
);
return
true
;
}
return
false
;
}
template
<
typename
Mesh
>
bool
convertMesh
(
const
Mesh
&
mesh
,
const
std
::
string
&
inputFileName
,
const
std
::
string
&
outputFileName
,
const
std
::
string
&
outputFormat
)
// specialization for unstructured meshes except polyhedral
template
<
typename
Mesh
,
std
::
enable_if_t
<
!
std
::
is_same
<
typename
Mesh
::
Cell
::
EntityTopology
,
TNL
::
Meshes
::
Topologies
::
Polyhedron
>
::
value
,
bool
>
=
true
>
bool
writeMesh
(
const
Mesh
&
mesh
,
std
::
ostream
&
out
,
const
std
::
string
&
format
)
{
std
::
string
format
=
outputFormat
;
if
(
outputFormat
==
"auto"
)
{
namespace
fs
=
std
::
experimental
::
filesystem
;
format
=
fs
::
path
(
outputFileName
).
extension
();
if
(
format
.
length
()
>
0
)
// remove dot from the extension
format
=
format
.
substr
(
1
);
if
(
format
==
"vtk"
)
{
using
Writer
=
Meshes
::
Writers
::
VTKWriter
<
Mesh
>
;
Writer
writer
(
out
);
writer
.
template
writeEntities
<
Mesh
::
getMeshDimension
()
>(
mesh
);
return
true
;
}
if
(
format
==
"vtu"
)
{
using
Writer
=
Meshes
::
Writers
::
VTUWriter
<
Mesh
>
;
Writer
writer
(
out
);
writer
.
template
writeEntities
<
Mesh
::
getMeshDimension
()
>(
mesh
);
return
true
;
}
if
(
format
==
"ng"
)
{
using
NetgenWriter
=
Meshes
::
Writers
::
NetgenWriter
<
Mesh
>
;
NetgenWriter
::
writeMesh
(
mesh
,
out
);
return
true
;
}
return
false
;
}
// specialization for grids
template
<
int
Dimension
,
typename
Real
,
typename
Device
,
typename
Index
>
bool
writeMesh
(
const
TNL
::
Meshes
::
Grid
<
Dimension
,
Real
,
Device
,
Index
>&
mesh
,
std
::
ostream
&
out
,
const
std
::
string
&
format
)
{
using
Mesh
=
TNL
::
Meshes
::
Grid
<
Dimension
,
Real
,
Device
,
Index
>
;
if
(
format
==
"vtk"
)
{
using
Writer
=
Meshes
::
Writers
::
VTKWriter
<
Mesh
>
;
std
::
ofstream
file
(
outputFileName
);
Writer
writer
(
file
);
Writer
writer
(
out
);
writer
.
template
writeEntities
<
Mesh
::
getMeshDimension
()
>(
mesh
);
return
true
;
}
if
(
format
==
"vtu"
)
{
using
Writer
=
Meshes
::
Writers
::
VTUWriter
<
Mesh
>
;
std
::
ofstream
file
(
outputFileName
);
Writer
writer
(
file
);
Writer
writer
(
out
);
writer
.
template
writeEntities
<
Mesh
::
getMeshDimension
()
>(
mesh
);
return
true
;
}
// FIXME: VTIWriter is not specialized for meshes
// if( outputFormat == "vti" ) {
// using Writer = Meshes::Writers::VTIWriter< Mesh >;
// std::ofstream file( outputFileName );
// Writer writer( file );
// writer.writeImageData( mesh );
// return true;
// }
// FIXME: NetgenWriter is not specialized for grids
// if( outputFormat == "ng" ) {
// using NetgenWriter = Meshes::Writers::NetgenWriter< Mesh >;
// std::fstream file( outputFileName );
// NetgenWriter::writeMesh( mesh, file );
// return true;
// }
if
(
format
==
"vti"
)
{
using
Writer
=
Meshes
::
Writers
::
VTIWriter
<
Mesh
>
;
Writer
writer
(
out
);
writer
.
writeImageData
(
mesh
);
return
true
;
}
return
false
;
}
template
<
typename
Mesh
>
bool
convertMesh
(
const
Mesh
&
mesh
,
const
std
::
string
&
inputFileName
,
const
std
::
string
&
outputFileName
,
const
std
::
string
&
outputFormat
)
{
std
::
string
format
=
outputFormat
;
if
(
outputFormat
==
"auto"
)
{
namespace
fs
=
std
::
experimental
::
filesystem
;
format
=
fs
::
path
(
outputFileName
).
extension
();
if
(
format
.
length
()
>
0
)
// remove dot from the extension
format
=
format
.
substr
(
1
);
}
std
::
ofstream
file
(
outputFileName
);
if
(
writeMesh
(
mesh
,
file
,
format
)
)
return
true
;
if
(
outputFormat
==
"auto"
)
std
::
cerr
<<
"File '"
<<
outputFileName
<<
"' has unsupported format (based on the file extension): "
<<
format
<<
"."
;
else
std
::
cerr
<<
"Unsupported output file format: "
<<
outputFormat
<<
"."
;
std
::
cerr
<<
" Supported formats are 'vtk'
and 'vtu'
."
<<
std
::
endl
;
std
::
cerr
<<
" Supported formats are 'vtk'
, 'vtu', 'vti' (only grids), 'ng' (only static unstructured meshes) and 'fpma' (only polyhedral meshes)
."
<<
std
::
endl
;
return
false
;
}
...
...
@@ -165,8 +227,9 @@ void configSetup( Config::ConfigDescription& config )
config
.
addEntryEnum
(
"auto"
);
config
.
addEntryEnum
(
"vtk"
);
config
.
addEntryEnum
(
"vtu"
);
// config.addEntryEnum( "vti" );
// config.addEntryEnum( "ng" );
config
.
addEntryEnum
(
"vti"
);
config
.
addEntryEnum
(
"ng"
);
config
.
addEntryEnum
(
"fpma"
);
}
int
main
(
int
argc
,
char
*
argv
[]
)
...
...
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