Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F88822817
xml_parser_restart.hh
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
Sun, Oct 20, 20:51
Size
8 KB
Mime Type
text/x-c++
Expires
Tue, Oct 22, 20:51 (2 d)
Engine
blob
Format
Raw Data
Handle
21825377
Attached To
rLIBMULTISCALE LibMultiScale
xml_parser_restart.hh
View Options
/**
* @file xml_parser_restart.hh
*
* @author Guillaume Anciaux <guillaume.anciaux@epfl.ch>
*
* @date Wed Sep 03 14:49:43 2014
*
* @brief XML parser for restart files
*
* @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.
*
*/
#ifndef XML_PARSER_RESTART_H
#define XML_PARSER_RESTART_H
/* -------------------------------------------------------------------------- */
#include "base64_reader.hh"
#include "lm_common.hh"
#include "xml_parser.hh"
#include <map>
#include <valarray>
#include <vector>
/* -------------------------------------------------------------------------- */
__BEGIN_LIBMULTISCALE__
/* -------------------------------------------------------------------------- */
static
const
Real
epsilon
=
.000001
;
static
const
Real
epsilon2
=
epsilon
*
epsilon
;
/* -------------------------------------------------------------------------- */
template
<
UInt
Dim
>
class
Triplet
{
public
:
Triplet
(
Real
*
X
)
:
X
(
X
)
{
read
=
0
;
};
template
<
typename
T
>
Triplet
(
const
T
&
X
)
:
X
(
X
)
{
read
=
0
;
};
Triplet
()
{
read
=
0
;
};
Real
&
operator
()(
UInt
i
)
{
LM_ASSERT
(
i
>=
0
&&
i
<
Dim
,
"out of range access "
<<
i
);
return
this
->
X
[
i
];
}
Real
&
operator
[](
UInt
i
)
{
return
(
*
this
)(
i
);
}
UInt
&
getRead
()
{
return
read
;
};
private
:
Vector
<
Dim
>
X
;
UInt
read
;
};
/* -------------------------------------------------------------------------- */
class
CompareTriplet
{
public
:
template
<
UInt
Dim
>
bool
operator
()(
Triplet
<
Dim
>
t1
,
Triplet
<
Dim
>
t2
)
const
{
Real
d
=
0.
;
for
(
UInt
i
=
0
;
i
<
Dim
;
++
i
)
{
Real
dist
=
t1
(
i
)
-
t2
(
i
);
d
+=
dist
*
dist
;
}
if
(
d
<
epsilon2
)
return
false
;
for
(
UInt
i
=
0
;
i
<
Dim
;
++
i
)
{
if
(
fabs
(
t1
(
i
)
-
t2
(
i
))
>
epsilon
)
{
if
(
t1
(
i
)
<
t2
(
i
))
return
true
;
else
return
false
;
}
}
return
false
;
}
};
/* -------------------------------------------------------------------------- */
template
<
UInt
Dim
>
class
XMLRestartParser
:
public
XMLParser
{
/* ------------------------------------------------------------------------ */
/* Typedefs */
/* ------------------------------------------------------------------------ */
public
:
enum
RestartField
{
NONE
,
P0S
,
DEP
,
VEL
,
ACC
};
enum
RestartType
{
TEXT
,
BINARY
};
/* ------------------------------------------------------------------------ */
/* Constructors/Destructors */
/* ------------------------------------------------------------------------ */
public
:
XMLRestartParser
()
{
nbDofs
=
0
;
cpt
=
0
;
};
~
XMLRestartParser
()
{
cleanMemory
();
};
/* ------------------------------------------------------------------------ */
/* Methods */
/* ------------------------------------------------------------------------ */
void
cleanMemory
()
{
mapU
.
clear
();
mapV
.
clear
();
mapA
.
clear
();
mapP0
.
clear
();
}
virtual
UInt
parseFile
(
const
std
::
string
&
name
,
bool
restart_continue_if_notfound
)
{
if
(
UInt
ret
=
XMLParser
::
parseFile
(
name
,
restart_continue_if_notfound
))
{
return
ret
;
}
return
0
;
}
bool
isDofRegistered
(
VectorView
<
Dim
>
&
X
);
template
<
typename
V1
,
typename
V2
>
void
assignDispField
(
V1
&
X
,
V2
&
U
);
template
<
typename
V1
,
typename
V2
>
void
assignVelField
(
V1
&
X
,
V2
&
V
);
template
<
typename
V1
,
typename
V2
>
void
assignForceField
(
V1
&
X
,
V2
&
F
);
template
<
typename
V
>
void
assignInitialPosition
(
UInt
index
,
V
&
X
);
UInt
getReadDofsNumber
()
{
return
nbDofs
;
};
protected
:
void
charHandler
(
const
XML_Char
*
str
,
int
len
);
void
startElement
(
const
char
*
name
,
const
char
**
atts
);
void
endElement
(
const
char
*
name
);
private
:
void
manageP0
(
char
*
s
);
void
manageU
(
char
*
s
);
void
manageV
(
char
*
s
);
void
manageA
(
char
*
s
);
UInt
readTriplet
(
Triplet
<
Dim
>
&
C
,
std
::
stringstream
&
s
);
/* ------------------------------------------------------------------------ */
/* Class Members */
/* ------------------------------------------------------------------------ */
//! temporary triplet (for incomlete lines)
Triplet
<
Dim
>
triplet
;
UInt
nbDofs
;
RestartField
current_field
;
UInt
cpt
;
RestartType
type
;
//! helper for base64
Base64Reader
b64
;
std
::
map
<
Triplet
<
Dim
>
,
Triplet
<
Dim
>
,
CompareTriplet
>
mapU
;
std
::
map
<
Triplet
<
Dim
>
,
Triplet
<
Dim
>
,
CompareTriplet
>
mapV
;
std
::
map
<
Triplet
<
Dim
>
,
Triplet
<
Dim
>
,
CompareTriplet
>
mapA
;
// MyVector<Triplet<Dim> > mapP0;
std
::
vector
<
Triplet
<
Dim
>>
mapP0
;
};
/* -------------------------------------------------------------------------- */
template
<
UInt
Dim
>
inline
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
Triplet
<
Dim
>
&
t
)
{
os
<<
"Triplet :"
;
for
(
UInt
i
=
0
;
i
<
Dim
;
++
i
)
os
<<
" "
<<
t
(
i
);
os
<<
std
::
endl
;
return
os
;
}
/* -------------------------------------------------------------------------- */
template
<
UInt
Dim
>
inline
bool
XMLRestartParser
<
Dim
>::
isDofRegistered
(
VectorView
<
Dim
>
&
X
)
{
Triplet
<
Dim
>
a
(
X
);
bool
test
=
(
mapU
.
count
(
a
)
!=
0
);
return
test
;
}
/* -------------------------------------------------------------------------- */
template
<
UInt
Dim
>
template
<
typename
V
>
inline
void
XMLRestartParser
<
Dim
>::
assignInitialPosition
(
UInt
index
,
V
&
X
)
{
Triplet
<
Dim
>
&
b
=
mapP0
[
index
];
for
(
UInt
i
=
0
;
i
<
Dim
;
++
i
)
X
[
i
]
=
b
(
i
);
}
/* -------------------------------------------------------------------------- */
template
<
UInt
Dim
>
template
<
typename
V1
,
typename
V2
>
inline
void
XMLRestartParser
<
Dim
>::
assignDispField
(
V1
&
X
,
V2
&
U
)
{
Triplet
<
Dim
>
a
(
X
);
Triplet
<
Dim
>
&
b
=
mapU
[
a
];
for
(
UInt
i
=
0
;
i
<
Dim
;
++
i
)
U
[
i
]
=
b
(
i
);
}
/* -------------------------------------------------------------------------- */
template
<
UInt
Dim
>
template
<
typename
V1
,
typename
V2
>
inline
void
XMLRestartParser
<
Dim
>::
assignVelField
(
V1
&
X
,
V2
&
V
)
{
Triplet
<
Dim
>
a
(
X
);
Triplet
<
Dim
>
&
b
=
mapV
[
a
];
for
(
UInt
i
=
0
;
i
<
Dim
;
++
i
)
V
[
i
]
=
b
(
i
);
}
/* -------------------------------------------------------------------------- */
template
<
UInt
Dim
>
template
<
typename
V1
,
typename
V2
>
inline
void
XMLRestartParser
<
Dim
>::
assignForceField
(
V1
&
X
,
V2
&
F
)
{
Triplet
<
Dim
>
a
(
X
);
Triplet
<
Dim
>
&
b
=
mapA
[
a
];
for
(
UInt
i
=
0
;
i
<
Dim
;
++
i
)
F
[
i
]
=
b
(
i
);
}
/* -------------------------------------------------------------------------- */
__END_LIBMULTISCALE__
#endif
Event Timeline
Log In to Comment