Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
iwr
amdis
Commits
340fd949
Commit
340fd949
authored
Mar 27, 2012
by
Thomas Witkowski
Browse files
Fixed ElementFileWriter to work in parallel.
parent
859d3918
Changes
7
Hide whitespace changes
Inline
Side-by-side
AMDiS/src/Debug.cc
View file @
340fd949
...
...
@@ -106,7 +106,7 @@ namespace AMDiS {
elInfo
=
stack
.
traverseNext
(
elInfo
);
}
ElementFileWriter
::
writeFile
(
vec
,
mesh
,
filename
,
level
);
ElementFileWriter
::
writeFile
(
vec
,
mesh
,
filename
,
""
,
level
);
}
...
...
AMDiS/src/io/ElementFileWriter.cc
View file @
340fd949
...
...
@@ -14,7 +14,9 @@
#include
<boost/iostreams/device/file_descriptor.hpp>
#include
<boost/filesystem/operations.hpp>
#include
<boost/filesystem/convenience.hpp>
#include
<boost/lexical_cast.hpp>
#include
"io/VtkWriter.h"
#include
"ElementFileWriter.h"
#include
"BasisFunction.h"
#include
"Initfile.h"
...
...
@@ -93,7 +95,7 @@ namespace AMDiS {
if
(
writeVtkFormat
)
{
TEST_EXIT
(
mesh
)(
"no mesh
\n
"
);
writeVtkValues
(
const_cast
<
char
*>
((
fn
+
vtkExt
).
c_str
())
);
writeVtkValues
(
fn
,
vtkExt
);
MSG
(
"VTK file written to %s
\n
"
,
(
fn
+
vtkExt
).
c_str
());
}
}
...
...
@@ -102,10 +104,11 @@ namespace AMDiS {
void
ElementFileWriter
::
writeFile
(
map
<
int
,
double
>
&
vec
,
Mesh
*
mesh
,
string
filename
,
string
postfix
,
int
level
)
{
ElementFileWriter
efw
(
""
,
mesh
,
vec
);
efw
.
writeVtkValues
(
filename
,
level
);
efw
.
writeVtkValues
(
filename
,
postfix
,
level
);
}
...
...
@@ -213,10 +216,21 @@ namespace AMDiS {
}
void
ElementFileWriter
::
writeVtkValues
(
string
filename
,
int
level
)
void
ElementFileWriter
::
writeVtkValues
(
string
fname
,
string
postfix
,
int
level
)
{
FUNCNAME
(
"ElementFileWriter::writeVtkValues()"
);
#if HAVE_PARALLEL_DOMAIN_AMDIS
string
filename
=
fname
+
"-p"
+
boost
::
lexical_cast
<
std
::
string
>
(
MPI
::
COMM_WORLD
.
Get_rank
())
+
"-"
+
postfix
;
#else
string
filename
=
fname
+
postfix
;
#endif
boost
::
iostreams
::
filtering_ostream
file
;
{
//boost::iostreams seems not to truncate the file
...
...
@@ -237,7 +251,7 @@ namespace AMDiS {
nElements
=
0
;
TraverseStack
stack
;
ElInfo
*
elInfo
=
stack
.
traverseFirst
(
mesh
,
level
,
Mesh
::
CALL_EL_LEVEL
);
ElInfo
*
elInfo
=
stack
.
traverseFirst
(
mesh
,
level
,
Mesh
::
CALL_EL_LEVEL
);
while
(
elInfo
)
{
nElements
++
;
elInfo
=
stack
.
traverseNext
(
elInfo
);
...
...
@@ -339,5 +353,11 @@ namespace AMDiS {
file
<<
" </Piece>
\n
"
;
file
<<
" </UnstructuredGrid>
\n
"
;
file
<<
"</VTKFile>
\n
"
;
#if HAVE_PARALLEL_DOMAIN_AMDIS
if
(
MPI
::
COMM_WORLD
.
Get_rank
()
==
0
)
VtkWriter
::
writeParallelFile
(
fname
+
".pvtu"
,
MPI
::
COMM_WORLD
.
Get_size
(),
fname
,
".vtu"
,
1
);
#endif
}
}
AMDiS/src/io/ElementFileWriter.h
View file @
340fd949
...
...
@@ -30,6 +30,8 @@
namespace
AMDiS
{
using
namespace
std
;
/** \brief
* Filewriter that make it possible to create mesh files, where the values
* are not defined on DOFs, but instead are defined on the elements.
...
...
@@ -43,9 +45,9 @@ namespace AMDiS {
{
public:
/// Constructor.
ElementFileWriter
(
std
::
string
name
,
ElementFileWriter
(
string
name
,
Mesh
*
mesh
,
std
::
map
<
int
,
double
>
&
vec
);
map
<
int
,
double
>
&
vec
);
/// Implementation of FileWriterInterface::writeFiles().
void
writeFiles
(
AdaptInfo
*
adaptInfo
,
bool
force
,
...
...
@@ -54,30 +56,32 @@ namespace AMDiS {
bool
(
*
writeElem
)(
ElInfo
*
)
=
NULL
);
/// Simple writing procedure for one element map.
static
void
writeFile
(
std
::
map
<
int
,
double
>
&
vec
,
static
void
writeFile
(
map
<
int
,
double
>
&
vec
,
Mesh
*
mesh
,
std
::
string
filename
,
string
filename
,
string
postfix
=
".vtu"
,
int
level
=
-
1
);
protected:
/// Writes element data in AMDiS format (1 file !).
void
writeMeshDatValues
(
std
::
string
filename
,
double
time
);
void
writeMeshDatValues
(
string
filename
,
double
time
);
/// Writes element data in VTK format.
void
writeVtkValues
(
std
::
string
filename
,
int
level
=
-
1
);
void
writeVtkValues
(
string
filename
,
string
postfix
,
int
level
=
-
1
);
protected:
/// Name.
std
::
string
name
;
string
name
;
/// Used filename prefix.
std
::
string
filename
;
string
filename
;
/// AMDiS mesh-data-file extension.
std
::
string
amdisMeshDatExt
;
string
amdisMeshDatExt
;
/// VTK file extension.
std
::
string
vtkExt
;
string
vtkExt
;
/// 0: Don't write AMDiS files.
/// 1: Write AMDiS files.
...
...
@@ -107,7 +111,7 @@ namespace AMDiS {
Mesh
*
mesh
;
/// Vector that stores the solution.
std
::
map
<
int
,
double
>
vec
;
map
<
int
,
double
>
vec
;
};
}
...
...
AMDiS/src/io/FileWriter.cc
View file @
340fd949
...
...
@@ -145,7 +145,8 @@ namespace AMDiS {
if
(
MPI
::
COMM_WORLD
.
Get_rank
()
==
0
)
vtkWriter
.
writeParallelFile
(
paraFilename
+
paraviewParallelFileExt
,
MPI
::
COMM_WORLD
.
Get_size
(),
filename
,
postfix
);
filename
,
postfix
,
dataCollectors
.
size
());
#endif
MSG
(
"ParaView file written to %s
\n
"
,
(
fn
+
paraviewFileExt
).
c_str
());
...
...
@@ -185,11 +186,9 @@ namespace AMDiS {
dofWriter
.
writeFile
(
fn
+
".dof"
,
solutionVecs
);
}
if
(
writeArhFormat
)
ArhWriter
::
write
(
fn
+
".arh"
,
feSpace
->
getMesh
(),
solutionVecs
);
#ifdef HAVE_PNG
if
(
writePngFormat
)
{
PngWriter
pngWriter
(
dataCollectors
[
0
]);
...
...
AMDiS/src/io/VtkWriter.cc
View file @
340fd949
...
...
@@ -32,7 +32,9 @@
namespace
AMDiS
{
int
VtkWriter
::
writeFile
(
std
::
string
name
)
using
namespace
std
;
int
VtkWriter
::
writeFile
(
string
name
)
{
FUNCNAME
(
"VtkWriter::writeFile()"
);
...
...
@@ -51,32 +53,33 @@ namespace AMDiS {
}
{
std
::
ofstream
swapfile
(
name
.
c_str
(),
std
::
ios
::
out
|
std
::
ios
::
trunc
);
ofstream
swapfile
(
name
.
c_str
(),
ios
::
out
|
ios
::
trunc
);
TEST_EXIT
(
swapfile
.
is_open
())
(
"Cannot open file %s for writing!
\n
"
,
name
.
c_str
());
swapfile
.
close
();
}
file
.
push
(
boost
::
iostreams
::
file_descriptor_sink
(
name
,
std
::
ios
::
trunc
));
file
.
push
(
boost
::
iostreams
::
file_descriptor_sink
(
name
,
ios
::
trunc
));
writeFileToStream
(
file
);
return
0
;
}
void
VtkWriter
::
writeParallelFile
(
std
::
string
name
,
int
nRanks
,
std
::
string
fnPrefix
,
std
::
string
fnPostfix
)
void
VtkWriter
::
writeParallelFile
(
string
name
,
int
nRanks
,
string
fnPrefix
,
string
fnPostfix
,
int
nComponents
)
{
FUNCNAME
(
"VtkWriter::writeParallelFile()"
);
boost
::
iostreams
::
filtering_ostream
file
;
{
std
::
ofstream
swapfile
(
name
.
c_str
(),
std
::
ios
::
out
|
std
::
ios
::
trunc
);
ofstream
swapfile
(
name
.
c_str
(),
ios
::
out
|
ios
::
trunc
);
TEST_EXIT
(
swapfile
.
is_open
())
(
"Cannot open file %s for writing!
\n
"
,
name
.
c_str
());
swapfile
.
close
();
}
file
.
push
(
boost
::
iostreams
::
file_descriptor_sink
(
name
,
std
::
ios
::
trunc
));
file
.
push
(
boost
::
iostreams
::
file_descriptor_sink
(
name
,
ios
::
trunc
));
file
<<
"<?xml version=
\"
1.0
\"
?>
\n
"
;
file
<<
"<VTKFile type=
\"
PUnstructuredGrid
\"
>
\n
"
;
...
...
@@ -91,14 +94,14 @@ namespace AMDiS {
<<
" </PCells>
\n
"
;
file
<<
" <PPointData>
\n
"
;
for
(
int
i
=
0
;
i
<
static_cast
<
int
>
(
dataCollector
->
size
())
;
i
++
)
for
(
int
i
=
0
;
i
<
nComponents
;
i
++
)
file
<<
" <PDataArray type=
\"
Float32
\"
Name=
\"
value"
<<
i
<<
"
\"
format=
\"
ascii
\"
/>
\n
"
;
file
<<
" </PPointData>
\n
"
;
for
(
int
i
=
0
;
i
<
nRanks
;
i
++
)
{
std
::
stringstream
oss
;
stringstream
oss
;
oss
<<
fnPrefix
<<
"-p"
<<
i
<<
"-"
<<
fnPostfix
;
boost
::
filesystem
::
path
filepath
(
oss
.
str
());
file
<<
" <Piece Source=
\"
"
...
...
@@ -113,9 +116,9 @@ namespace AMDiS {
int
VtkWriter
::
updateAnimationFile
(
AdaptInfo
*
adaptInfo
,
std
::
string
valueFilename
,
std
::
vector
<
pair
<
double
,
std
::
string
>
>
*
paraViewAnimationFrames
,
std
::
string
animationFilename
)
string
valueFilename
,
vector
<
pair
<
double
,
string
>
>
*
paraViewAnimationFrames
,
string
animationFilename
)
{
FUNCNAME
(
"VtkWriter::updateAnimationFile()"
);
...
...
@@ -125,14 +128,14 @@ namespace AMDiS {
boost
::
iostreams
::
filtering_ostream
file
;
{
std
::
ofstream
swapfile
(
animationFilename
.
c_str
(),
std
::
ios
::
out
|
std
::
ios
::
trunc
);
ofstream
swapfile
(
animationFilename
.
c_str
(),
ios
::
out
|
ios
::
trunc
);
TEST_EXIT
(
swapfile
.
is_open
())
(
"Cannot open file %s for writing!
\n
"
,
animationFilename
.
c_str
());
swapfile
.
close
();
}
file
.
push
(
boost
::
iostreams
::
file_descriptor_sink
(
animationFilename
,
std
::
ios
::
trunc
));
ios
::
trunc
));
file
<<
"<?xml version=
\"
1.0
\"
?>
\n
"
;
file
<<
"<VTKFile type=
\"
Collection
\"
version=
\"
0.1
\"
>"
<<
"
\n
"
;
...
...
@@ -152,23 +155,23 @@ namespace AMDiS {
void
VtkWriter
::
writeFile
(
DOFVector
<
double
>
*
values
,
std
::
string
filename
,
string
filename
,
bool
writeParallel
)
{
FUNCNAME
(
"VtkWriter::writeFile()"
);
DataCollector
<>
dc
(
values
->
getFeSpace
(),
values
);
std
::
vector
<
DataCollector
<>*>
dcList
(
0
);
vector
<
DataCollector
<>*>
dcList
(
0
);
dcList
.
push_back
(
&
dc
);
writeFile
(
dcList
,
filename
,
writeParallel
);
}
void
VtkWriter
::
writeFile
(
std
::
vector
<
DOFVector
<
double
>*
>
&
values
,
std
::
string
filename
,
void
VtkWriter
::
writeFile
(
vector
<
DOFVector
<
double
>*
>
&
values
,
string
filename
,
bool
writeParallel
)
{
std
::
vector
<
DataCollector
<>*>
dcList
(
0
);
vector
<
DataCollector
<>*>
dcList
(
0
);
for
(
unsigned
int
i
=
0
;
i
<
values
.
size
();
i
++
)
dcList
.
push_back
(
new
DataCollector
<>
(
values
[
i
]
->
getFeSpace
(),
values
[
i
]));
writeFile
(
dcList
,
filename
,
writeParallel
);
...
...
@@ -178,10 +181,10 @@ namespace AMDiS {
void
VtkWriter
::
writeFile
(
WorldVector
<
DOFVector
<
double
>*
>
&
values
,
std
::
string
filename
,
string
filename
,
bool
writeParallel
)
{
std
::
vector
<
DataCollector
<>*>
dcList
(
0
);
vector
<
DataCollector
<>*>
dcList
(
0
);
for
(
int
i
=
0
;
i
<
values
.
getSize
();
i
++
)
dcList
.
push_back
(
new
DataCollector
<>
(
values
[
i
]
->
getFeSpace
(),
values
[
i
]));
writeFile
(
dcList
,
filename
,
writeParallel
);
...
...
@@ -191,7 +194,7 @@ namespace AMDiS {
void
VtkWriter
::
writeFile
(
DOFVector
<
WorldVector
<
double
>
>
*
values
,
std
::
string
filename
,
string
filename
,
bool
writeParallel
)
{
WorldVector
<
DOFVector
<
double
>*>
valuesWV
;
...
...
@@ -205,10 +208,10 @@ namespace AMDiS {
void
VtkWriter
::
writeFile
(
SystemVector
*
values
,
std
::
string
filename
,
string
filename
,
bool
writeParallel
)
{
std
::
vector
<
DataCollector
<>*>
dcList
(
0
);
vector
<
DataCollector
<>*>
dcList
(
0
);
for
(
int
i
=
0
;
i
<
values
->
getSize
();
i
++
)
dcList
.
push_back
(
new
DataCollector
<>
(
values
->
getDOFVector
(
i
)
->
getFeSpace
(),
values
->
getDOFVector
(
i
)));
...
...
@@ -218,8 +221,8 @@ namespace AMDiS {
}
void
VtkWriter
::
writeFile
(
std
::
vector
<
DataCollector
<>*>
&
dcList
,
std
::
string
filename
,
void
VtkWriter
::
writeFile
(
vector
<
DataCollector
<>*>
&
dcList
,
string
filename
,
bool
writeParallel
)
{
VtkWriter
writer
(
&
dcList
);
...
...
@@ -230,12 +233,15 @@ namespace AMDiS {
int
sPos
=
filename
.
find
(
".vtu"
);
TEST_EXIT
(
sPos
>=
0
)(
"Failed to find file postfix!
\n
"
);
std
::
string
name
=
filename
.
substr
(
0
,
sPos
);
string
name
=
filename
.
substr
(
0
,
sPos
);
if
(
MPI
::
COMM_WORLD
.
Get_rank
()
==
0
)
writer
.
writeParallelFile
(
name
+
".pvtu"
,
MPI
::
COMM_WORLD
.
Get_size
(),
name
,
".vtu"
);
writer
.
writeParallelFile
(
name
+
".pvtu"
,
MPI
::
COMM_WORLD
.
Get_size
(),
name
,
".vtu"
,
static_cast
<
int
>
(
dcList
.
size
()));
filename
=
name
+
"-p"
+
lexical_cast
<
std
::
string
>
(
MPI
::
COMM_WORLD
.
Get_rank
())
+
"-.vtu"
;
filename
=
name
+
"-p"
+
lexical_cast
<
string
>
(
MPI
::
COMM_WORLD
.
Get_rank
())
+
"-.vtu"
;
}
#endif
writer
.
writeFile
(
filename
);
...
...
AMDiS/src/io/VtkWriter.h
View file @
340fd949
...
...
@@ -36,10 +36,12 @@
namespace
AMDiS
{
using
namespace
std
;
class
VtkWriter
{
public:
VtkWriter
(
std
::
vector
<
DataCollector
<>*>
*
dc
)
VtkWriter
(
vector
<
DataCollector
<>*>
*
dc
)
:
dataCollector
(
dc
),
compress
(
NONE
)
{
...
...
@@ -48,51 +50,52 @@ namespace AMDiS {
}
/// Writes a ParaView-VTK file.
int
writeFile
(
std
::
string
name
);
int
writeFile
(
string
name
);
/// Writes a pvtu file, which contains the links to all the rank files.
void
writeParallelFile
(
std
::
string
name
,
int
nRanks
,
std
::
string
fnPrefix
,
std
::
string
fnPostfix
);
static
void
writeParallelFile
(
string
name
,
int
nRanks
,
string
fnPrefix
,
string
fnPostfix
,
int
nComponents
);
/// May be used to simply write ParaView files.
static
void
writeFile
(
DOFVector
<
double
>
*
values
,
std
::
string
filename
,
string
filename
,
bool
writeParallel
=
true
);
/// May be used to simply write ParaView files.
static
void
writeFile
(
DOFVector
<
double
>
&
values
,
std
::
string
filename
,
string
filename
,
bool
writeParallel
=
true
)
{
writeFile
(
&
values
,
filename
,
writeParallel
);
}
/// May be used to simply write ParaView files with a list of values.
static
void
writeFile
(
std
::
vector
<
DOFVector
<
double
>*>
&
values
,
std
::
string
filename
,
static
void
writeFile
(
vector
<
DOFVector
<
double
>*>
&
values
,
string
filename
,
bool
writeParallel
=
true
);
static
void
writeFile
(
WorldVector
<
DOFVector
<
double
>*>
&
values
,
std
::
string
filename
,
string
filename
,
bool
writeParallel
=
true
);
static
void
writeFile
(
DOFVector
<
WorldVector
<
double
>
>
*
values
,
std
::
string
filename
,
string
filename
,
bool
writeParallel
=
true
);
static
void
writeFile
(
DOFVector
<
WorldVector
<
double
>
>
&
values
,
std
::
string
filename
,
string
filename
,
bool
writeParallel
=
true
)
{
writeFile
(
&
values
,
filename
,
writeParallel
);
}
static
void
writeFile
(
SystemVector
*
values
,
std
::
string
filename
,
string
filename
,
bool
writeParallel
=
true
);
static
void
writeFile
(
std
::
vector
<
DataCollector
<>*>
&
dcList
,
std
::
string
filename
,
static
void
writeFile
(
vector
<
DataCollector
<>*>
&
dcList
,
string
filename
,
bool
writeParallel
=
true
);
/// Set a compressing method for file output.
...
...
@@ -103,15 +106,16 @@ namespace AMDiS {
/// Adds a new entry to a ParaView animation file.
static
int
updateAnimationFile
(
AdaptInfo
*
adaptInfo
,
std
::
string
valueFilename
,
std
::
vector
<
pair
<
double
,
std
::
string
>
>
*
paraViewAnimationFrames
,
std
::
string
animationFilename
);
string
valueFilename
,
vector
<
pair
<
double
,
string
>
>
*
paraViewAnimationFrames
,
string
animationFilename
);
protected:
/// Writes the VTK file to an arbitrary stream.
template
<
typename
T
>
void
writeFileToStream
(
T
&
file
);
/// Writes all coordinates of vertices and interpolation points to an output file.
/// Writes all coordinates of vertices and interpolation points to an
/// output file.
template
<
typename
T
>
void
writeVertexCoords
(
T
&
file
);
...
...
@@ -123,15 +127,18 @@ namespace AMDiS {
template
<
typename
T
>
void
writeConnectivity
(
T
&
file
);
/// Writes the connectivity for the case dim = 2 and degree = 2 to an output file.
/// Writes the connectivity for the case dim = 2 and degree = 2 to an
/// output file.
template
<
typename
T
>
void
writeConnectivity_dim2_degree2
(
T
&
file
);
/// Writes the connectivity for the case dim = 2 and degree = 3 to an output file.
/// Writes the connectivity for the case dim = 2 and degree = 3 to an
/// output file.
template
<
typename
T
>
void
writeConnectivity_dim2_degree3
(
T
&
file
);
/// Writes the connectivity for the case dim = 2 and degree = 4 to an output file.
/// Writes the connectivity for the case dim = 2 and degree = 4 to an
/// output file.
template
<
typename
T
>
void
writeConnectivity_dim2_degree4
(
T
&
file
);
...
...
@@ -140,7 +147,7 @@ namespace AMDiS {
WorldVector
<
double
>
coord
)
{
for
(
int
i
=
0
;
i
<
Global
::
getGeo
(
WORLD
);
i
++
)
file
<<
" "
<<
std
::
scientific
<<
coord
[
i
];
file
<<
" "
<<
scientific
<<
coord
[
i
];
for
(
int
i
=
Global
::
getGeo
(
WORLD
);
i
<
3
;
i
++
)
file
<<
" "
<<
0.0
;
...
...
@@ -148,10 +155,10 @@ namespace AMDiS {
}
/// Writes a world coordinate to a given file.
inline
void
writeCoord
(
std
::
ofstream
&
file
,
WorldVector
<
double
>
coord
)
inline
void
writeCoord
(
ofstream
&
file
,
WorldVector
<
double
>
coord
)
{
for
(
int
i
=
0
;
i
<
Global
::
getGeo
(
WORLD
);
i
++
)
file
<<
" "
<<
std
::
scientific
<<
coord
[
i
];
file
<<
" "
<<
scientific
<<
coord
[
i
];
for
(
int
i
=
Global
::
getGeo
(
WORLD
);
i
<
3
;
i
++
)
file
<<
" "
<<
0.0
;
...
...
@@ -160,12 +167,10 @@ namespace AMDiS {
private:
/// List of DataCollectors, for each component of the problem one.
std
::
vector
<
DataCollector
<>*>
*
dataCollector
;
vector
<
DataCollector
<>*>
*
dataCollector
;
/** \brief
* Defines if the file has to be compressed for ouput, and with which
* kind of compress method.
*/
/// Defines if the file has to be compressed for ouput, and with which
/// kind of compress method.
FileCompression
compress
;
/// Degree of the basis function of the problem.
...
...
AMDiS/src/parallel/MeshDistributor.cc
View file @
340fd949
...
...
@@ -132,8 +132,6 @@ namespace AMDiS {
{
FUNCNAME
(
"MeshDistributor::initParallelization()"
);
MSG
(
"RUN INIT
\n
"
);
if
(
initialized
)
return
;
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment