Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dune-alugrid
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ag-ohlberger
dune-community
dune-alugrid
Commits
22390cd9
Commit
22390cd9
authored
5 years ago
by
Robert K
Browse files
Options
Downloads
Patches
Plain Diff
[feature][gmsh2dgf] Added conversion tool.
parent
00edc2f2
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/quality/gmsh2dgf.cc
+62
-37
62 additions, 37 deletions
examples/quality/gmsh2dgf.cc
with
62 additions
and
37 deletions
examples/quality/gmsh2dgf.cc
+
62
−
37
View file @
22390cd9
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
/** \file
* \author Matrin Nolte
* \brief a small program converting a gmsh file into a DGF file
*
* gmsh2dgf is a small example program for the DGFWriter. It reads a gmsh file
* into any grid (selected by gridtype.hh) and writes it back as a DGF file.
*
* The program's usage is as follows:
\code
./gmsh2dgf <gmshfile>
\endcode
*/
#include
<config.h>
#include
"config.h"
#include
<iostream>
#include
<memory>
#include
<sstream>
#include
<string>
#include
<vector>
#include
<dune/common/parallel/mpihelper.hh>
#include
<dune/grid/io/file/gmshreader.hh>
#include
<dune/alugrid/grid.hh>
#include
<dune/alugrid/dgf.hh>
#include
<dune/grid/io/file/vtk/vtkwriter.hh>
#include
<dune/grid/io/file/gmshwriter.hh>
#include
<dune/grid/io/file/dgfparser/dgfwriter.hh>
using
namespace
Dune
;
int
main
(
int
argc
,
char
*
argv
[]
)
int
main
(
int
argc
,
char
*
*
argv
)
try
{
Dune
::
MPIHelper
::
instance
(
argc
,
argv
);
typedef
Dune
::
GridSelector
::
GridType
Grid
;
auto
&
mpiHelper
=
MPIHelper
::
instance
(
argc
,
argv
);
const
int
rank
=
mpiHelper
.
rank
()
;
if
(
argc
<
2
)
std
::
string
filename
;
if
(
argc
>
1
)
{
filename
=
std
::
string
(
argv
[
1
]);
}
else
{
std
::
cerr
<<
"
U
sage: "
<<
argv
[
0
]
<<
" <
gmshfil
e>"
<<
std
::
endl
;
return
1
;
std
::
cerr
<<
"
u
sage: "
<<
argv
[
0
]
<<
" <
filenam
e>"
<<
std
::
endl
;
return
0
;
}
const
std
::
string
gmshFileName
(
argv
[
1
]
)
;
std
::
string
dgfFileName
(
gmshFileName
)
;
dgfFileName
.
resize
(
dgfFileName
.
find_last_of
(
"."
)
)
;
dgfF
ile
N
ame
+=
".dgf"
;
typedef
typename
GridSelector
::
GridType
GridType
;
std
::
unique_ptr
<
GridType
>
gridPtr
;
typedef
typename
GridSelector
::
GridType
GridType
;
gridPtr
.
reset
(
Dune
::
GridPtr
<
GridType
>
(
f
ile
n
ame
).
release
()
)
;
Grid
*
grid
=
GmshReader
<
Grid
>::
read
(
gmshFileName
);
GridType
&
grid
=
*
gridPtr
;
typedef
typename
GridType
::
LeafGridView
LeafGridView
;
const
LeafGridView
&
gridView
=
grid
.
leafGridView
();
// Write MSH
{
Dune
::
GmshWriter
<
LeafGridView
>
writer
(
leafGridView
);
writer
.
setPrecision
(
10
);
const
std
::
string
outputName
(
filename
+
".msh"
);
writer
.
write
(
outputName
);
}
typedef
Grid
::
LeafGridView
GridView
;
GridView
gridView
=
grid
->
leafGridView
();
// Write DGF
{
Dune
::
DGFWriter
<
LeafGridView
>
writer
(
leafGridView
);
DGFWriter
<
GridView
>
dgfWriter
(
gridView
);
dgfWriter
.
write
(
dgfFileName
);
const
std
::
string
outputName
(
filename
+
".msh"
);
writer
.
write
(
outputName
);
}
const
GridView
::
IndexSet
&
indexSet
=
gridView
.
indexSet
();
std
::
cerr
<<
"Grid successfully written: "
<<
indexSet
.
size
(
Grid
::
dimension
)
<<
" vertices, "
<<
indexSet
.
size
(
0
)
<<
" elements."
<<
std
::
endl
;
// Write VTK
{
std
::
ostringstream
vtkName
;
vtkName
<<
gridName
<<
".vtk"
;
VTKWriter
<
LeafGridView
>
vtkWriter
(
leafGridView
);
vtkWriter
.
write
(
vtkName
.
str
()
);
}
return
0
;
}
catch
(
const
Exception
&
e
xception
)
catch
(
const
Dune
::
Exception
&
e
)
{
std
::
cerr
<<
e
xception
<<
std
::
endl
;
std
::
cerr
<<
e
<<
std
::
endl
;
return
1
;
}
catch
(
const
std
::
exception
&
e
)
{
std
::
cerr
<<
e
.
what
()
<<
std
::
endl
;
return
1
;
}
catch
(
...
)
{
std
::
cerr
<<
"Generic exception!"
<<
std
::
endl
;
return
2
;
}
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