Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
dumux
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
Show more breadcrumbs
dumux-repositories
dumux
Commits
05a2c982
Commit
05a2c982
authored
6 years ago
by
Timo Koch
Browse files
Options
Downloads
Patches
Plain Diff
[io][vtkreader] Reduce code duplication and computational effort for reading parallel file names
parent
b7a5f1d8
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!1039
Feature/restart from vtk
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
dumux/io/vtk/vtkreader.hh
+38
-40
38 additions, 40 deletions
dumux/io/vtk/vtkreader.hh
with
38 additions
and
40 deletions
dumux/io/vtk/vtkreader.hh
+
38
−
40
View file @
05a2c982
...
...
@@ -59,14 +59,12 @@ public:
* \brief The contructor creates a tinyxml2::XMLDocument from file
*/
explicit
VTKReader
(
const
std
::
string
&
fileName
)
:
fileName_
(
fileName
)
{
if
(
Dune
::
MPIHelper
::
getCollectiveCommunication
().
size
()
>
1
)
get
SequentialNameFromParal
le
l
Name
_
()
;
fileName_
=
Dune
::
MPIHelper
::
getCollectiveCommunication
().
size
()
>
1
?
get
ProcessFileName_
(
fileName
)
:
fi
leName
;
using
namespace
tinyxml2
;
const
auto
eResult
=
doc_
.
LoadFile
(
fileName_
.
c_str
());
if
(
eResult
!=
XML_SUCCESS
)
if
(
eResult
!=
tinyxml2
::
XML_SUCCESS
)
DUNE_THROW
(
Dune
::
IOError
,
"Couldn't open XML file "
<<
fileName_
<<
"."
);
}
...
...
@@ -138,49 +136,36 @@ public:
private
:
/*!
* \brief get
sequential V
tk filename f
rom a parallel one
* \brief get
the v
tk filename f
or the current processor
*/
void
getSequentialNameFromParal
le
l
Name
_
(
)
std
::
string
getProcessFileName_
(
const
std
::
string
&
pvtkFi
leName
)
{
using
namespace
tinyxml2
;
const
auto
eResult
=
doc_
.
LoadFile
(
fileName_
.
c_str
());
XMLDocument
pDoc
;
const
auto
eResult
=
pDoc
.
LoadFile
(
pvtkFileName
.
c_str
());
if
(
eResult
!=
XML_SUCCESS
)
DUNE_THROW
(
Dune
::
IOError
,
"Couldn't open XML file "
<<
fileName_
<<
"."
);
const
XMLElement
*
pieceNode
=
doc_
.
FirstChildElement
(
"VTKFile"
);
if
(
pieceNode
==
nullptr
)
DUNE_THROW
(
Dune
::
IOError
,
"Couldn't get 'VTKFile' node in "
<<
fileName_
<<
"."
);
DUNE_THROW
(
Dune
::
IOError
,
"Couldn't open XML file "
<<
pvtkFileName
<<
"."
);
pieceNode
=
pieceNode
->
FirstChildElement
(
"PUnstructuredGrid"
);
// get the first piece node
const
XMLElement
*
pieceNode
=
getPieceNode_
(
pDoc
,
pvtkFileName
);
if
(
pieceNode
==
nullptr
)
pieceNode
=
doc_
.
FirstChildElement
(
"VTKFile"
)
->
FirstChildElement
(
"PPolyData"
);
if
(
pieceNode
==
nullptr
)
DUNE_THROW
(
Dune
::
IOError
,
"Couldn't get 'PUnstructuredGrid' or 'PPolyData' node in "
<<
fileName_
<<
"."
);
DUNE_THROW
(
Dune
::
IOError
,
"Couldn't get 'Piece' node in "
<<
pvtkFileName
<<
"."
);
pieceNode
=
pieceNode
->
FirstChildElement
(
"Piece"
);
const
auto
&
comm
=
Dune
::
MPIHelper
::
getCollectiveCommunication
();
for
(
int
rank
=
0
;
rank
<
comm
.
size
();
++
rank
)
const
auto
myrank
=
Dune
::
MPIHelper
::
getCollectiveCommunication
().
rank
();
for
(
int
rank
=
0
;
rank
<
myrank
;
++
rank
)
{
if
(
pieceNode
==
nullptr
)
DUNE_THROW
(
Dune
::
IOError
,
"Couldn't get 'Piece' node for rank "
<<
rank
<<
" in "
<<
fileName_
<<
"."
);
const
char
*
seqName
=
pieceNode
->
Attribute
(
"Source"
);
if
(
seqName
==
nullptr
)
DUNE_THROW
(
Dune
::
IOError
,
"Couldn't get 'Source' attribute of a 'Piece' node in "
<<
fileName_
);
if
(
comm
.
rank
()
==
rank
)
{
fileName_
=
seqName
;
break
;
}
pieceNode
=
pieceNode
->
NextSiblingElement
(
"Piece"
);
if
(
pieceNode
==
nullptr
)
DUNE_THROW
(
Dune
::
IOError
,
"Couldn't find 'Piece' node for rank "
<<
rank
<<
" in "
<<
pvtkFileName
<<
"."
);
}
doc_
.
Clear
();
const
char
*
vtkFileName
=
pieceNode
->
Attribute
(
"Source"
);
if
(
vtkFileName
==
nullptr
)
DUNE_THROW
(
Dune
::
IOError
,
"Couldn't get 'Source' attribute of 'Piece' node no. "
<<
myrank
<<
" in "
<<
pvtkFileName
);
return
vtkFileName
;
}
/*!
...
...
@@ -324,18 +309,31 @@ private:
* \note Returns nullptr if the piece node wasn't found
*/
const
tinyxml2
::
XMLElement
*
getPieceNode_
()
const
{
return
getPieceNode_
(
doc_
,
fileName_
);
}
/*!
* \brief Get the piece node an xml document
* \note Returns nullptr if the piece node wasn't found
* \param doc an xml document
* \param fileName a file name the doc was created from
*/
const
tinyxml2
::
XMLElement
*
getPieceNode_
(
const
tinyxml2
::
XMLDocument
&
doc
,
const
std
::
string
&
fileName
)
const
{
using
namespace
tinyxml2
;
const
XMLElement
*
pieceNode
=
doc
_
.
FirstChildElement
(
"VTKFile"
);
const
XMLElement
*
pieceNode
=
doc
.
FirstChildElement
(
"VTKFile"
);
if
(
pieceNode
==
nullptr
)
DUNE_THROW
(
Dune
::
IOError
,
"Couldn't get 'VTKFile' node in "
<<
fileName
_
<<
"."
);
DUNE_THROW
(
Dune
::
IOError
,
"Couldn't get 'VTKFile' node in "
<<
fileName
<<
"."
);
pieceNode
=
pieceNode
->
FirstChildElement
(
"UnstructuredGrid"
);
if
(
pieceNode
==
nullptr
)
pieceNode
=
doc_
.
FirstChildElement
(
"VTKFile"
)
->
FirstChildElement
(
"PolyData"
);
pieceNode
=
doc
.
FirstChildElement
(
"VTKFile"
)
->
FirstChildElement
(
"PolyData"
);
if
(
pieceNode
==
nullptr
)
pieceNode
=
doc
.
FirstChildElement
(
"VTKFile"
)
->
FirstChildElement
(
"PUnstructuredGrid"
);
if
(
pieceNode
==
nullptr
)
pieceNode
=
doc
.
FirstChildElement
(
"VTKFile"
)
->
FirstChildElement
(
"PPolyData"
);
if
(
pieceNode
==
nullptr
)
DUNE_THROW
(
Dune
::
IOError
,
"Couldn't get 'UnstructuredGrid' or 'PolyData' node in "
<<
fileName
_
<<
"."
);
DUNE_THROW
(
Dune
::
IOError
,
"Couldn't get 'UnstructuredGrid'
, 'PUnstructuredGrid', 'PolyData',
or '
P
PolyData' node in "
<<
fileName
<<
"."
);
return
pieceNode
->
FirstChildElement
(
"Piece"
);
}
...
...
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