Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F87361910
dumper_text.cc
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Oct 12, 05:31
Size
6 KB
Mime Type
text/x-c++
Expires
Mon, Oct 14, 05:31 (2 d)
Engine
blob
Format
Raw Data
Handle
21580297
Attached To
rLIBMULTISCALE LibMultiScale
dumper_text.cc
View Options
/**
* @file dumper_text.cc
*
* @author Guillaume Anciaux <guillaume.anciaux@epfl.ch>
*
* @date Wed Dec 04 12:14:29 2013
*
* @brief This allows to generate a formated text file
*
* @section LICENSE
*
* Copyright INRIA and CEA
*
* The LibMultiScale is a C++ parallel framework for the multiscale
* coupling methods dedicated to material simulations. This framework
* provides an API which makes it possible to program coupled simulations
* and integration of already existing codes.
*
* This Project was initiated in a collaboration between INRIA Futurs Bordeaux
* within ScAlApplix team and CEA/DPTA Ile de France.
* The project is now continued at the Ecole Polytechnique Fédérale de Lausanne
* within the LSMS/ENAC laboratory.
*
* This software is governed by the CeCILL-C license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL-C
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL-C license and that you accept its terms.
*
*/
#include "lm_common.hh"
#include "dumper_text.hh"
#include "lib_md.hh"
#include "compute.hh"
#include <iomanip>
#include "communicator.hh"
#include <typeinfo>
/* -------------------------------------------------------------------------- */
__BEGIN_LIBMULTISCALE__
template
<
typename
Cont
>
void
DumperText
<
Cont
>::
dump
(
Cont
&
cont
){
const
UInt
Dim
=
cont
.
getDim
();
compute_concat
.
build
(
cont
);
Communicator
&
comm
=
Communicator
::
getCommunicator
();
CommGroup
group
=
cont
.
getCommGroup
();
//only root node will dump the result of this compute
UInt
my_rank
=
comm
.
groupRank
(
lm_my_proc_id
,
group
);
if
(
my_rank
!=
this
->
rank
)
return
;
if
(
!
is_head_printed
){
std
::
string
fname
;
fname
=
this
->
getBaseName
()
+
".txt"
;
my_file
.
open
(
fname
.
c_str
());
if
(
!
my_file
.
is_open
()){
LM_FATAL
(
"could not open output file "
<<
fname
);
}
my_file
<<
comment_tag
<<
"timestep"
<<
separator
;
if
(
!
no_print_entry_flag
)
my_file
<<
"entry"
<<
separator
;
printHead
(
compute_concat
,
my_file
);
is_head_printed
=
true
;
my_file
<<
std
::
endl
;
}
LM_ASSERT
(
cont
.
nbElem
()
%
Dim
==
0
,
"invalid container"
);
UInt
n_entries
=
cont
.
nbElem
()
/
Dim
;
for
(
UInt
entry
=
0
;
entry
<
n_entries
;
++
entry
){
my_file
<<
current_step
<<
separator
;
if
(
!
no_print_entry_flag
)
my_file
<<
entry
<<
separator
;
dumpCompute
(
compute_concat
,
entry
,
my_file
);
my_file
<<
std
::
endl
;
}
if
(
line_break
)
my_file
<<
std
::
endl
;
}
/* -------------------------------------------------------------------------- */
template
<
typename
Cont
>
template
<
typename
Cont2
>
void
DumperText
<
Cont
>::
printHead
(
Cont2
&
cont
,
std
::
ofstream
&
file
){
if
(
cont
.
name_computed
.
size
()
!=
cont
.
getDim
())
LM_FATAL
(
"this compute "
<<
typeid
(
cont
).
name
()
<<
" is not ready for dumper text"
);
// typedef typename Cont::Ref Ref;
typename
Cont
::
iterator
it
=
cont
.
getIterator
();
for
(
UInt
i
=
0
;
i
<
cont
.
name_computed
.
size
();
++
i
){
if
(
cont
.
getID
()
!=
""
)
my_file
<<
cont
.
getID
()
<<
":"
;
my_file
<<
cont
.
name_computed
[
i
]
<<
separator
;
}
}
/* -------------------------------------------------------------------------- */
template
<
typename
Cont
>
template
<
typename
Cont2
>
void
DumperText
<
Cont
>::
dumpCompute
(
Cont2
&
cont
,
UInt
entry
,
std
::
ofstream
&
file
){
UInt
dim
=
cont
.
getDim
();
if
(
dim
*
entry
>=
cont
.
nbElem
())
LM_FATAL
(
"this compute does not have the right number of entries"
);
for
(
UInt
i
=
0
;
i
<
dim
;
++
i
)
{
Real
value
=
cont
[
entry
*
dim
+
i
];
my_file
<<
std
::
setprecision
(
precision
)
<<
std
::
scientific
<<
value
<<
separator
;
}
}
/* -------------------------------------------------------------------------- */
/* LMDESC TEXT
This allows to generate a formated text file taking as an entry the
result of a compute.
*/
/* LMHERITANCE compute_concat dumper */
/* LMEXAMPLE DUMPER txt TEXT INPUT md FREQ 100 PREFIX ./ SEPARATOR , PRECISION 8 */
template
<
typename
_Input
>
void
DumperText
<
_Input
>::
declareParams
(){
Dumper
<
_Input
>::
declareParams
();
this
->
addSubParsableObject
(
compute_concat
);
/* LMKEYWORD SEPARATOR
The generated file will be arranged in columns provided the following separator.
*/
this
->
parseKeyword
(
"SEPARATOR"
,
separator
,
"
\t
"
);
/* LMKEYWORD PRECISION
The generated file will use the provided precision.
*/
this
->
parseKeyword
(
"PRECISION"
,
precision
,
5u
);
/* LMKEYWORD RANK
The rank of processor which should generate the file
*/
this
->
parseKeyword
(
"RANK"
,
rank
,
0u
);
/* LMKEYWORD LINE_BREAK
Dump a line break between timestep series (default is FALSE)
*/
this
->
parseTag
(
"LINE_BREAK"
,
line_break
,
false
);
/* LMKEYWORD COMMENT
Give the tag to be used if comment should be written.
The default is \#.
*/
this
->
parseKeyword
(
"COMMENT"
,
comment_tag
,
"#"
);
/* LMKEYWORD NOPRINT_ENTRY
The entry column will not be included when this option is specified.
*/
this
->
parseTag
(
"NOPRINT_ENTRY"
,
no_print_entry_flag
,
false
);
}
/* -------------------------------------------------------------------------- */
DECLARE_DUMPER_COMPUTE
(
DumperText
);
__END_LIBMULTISCALE__
Event Timeline
Log In to Comment