Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F66850045
compute_impulse.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
Tue, Jun 18, 11:26
Size
6 KB
Mime Type
text/x-c++
Expires
Thu, Jun 20, 11:26 (2 d)
Engine
blob
Format
Raw Data
Handle
18304499
Attached To
rLIBMULTISCALE LibMultiScale
compute_impulse.cc
View Options
/**
* @file compute_impulse.cc
*
* @author Guillaume Anciaux <guillaume.anciaux@epfl.ch>
*
* @date Wed Jul 09 21:59:47 2014
*
* @brief This stimulator sets an initial impulse displacement field that will
* generate a wave
*
* @section LICENSE
*
* Copyright (©) 2010-2011 EPFL (Ecole Polytechnique Fédérale de Lausanne)
* Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides)
*
* LibMultiScale is free software: you can redistribute it and/or modify it
* under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* LibMultiScale is distributed in the hope that it will be useful, but
* WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with LibMultiScale. If not, see <http://www.gnu.org/licenses/>.
*
*/
/* -------------------------------------------------------------------------- */
#include "compute_impulse.hh"
#include "filter.hh"
#include "lib_continuum.hh"
#include "lib_dd.hh"
#include "lib_md.hh"
#include "lm_common.hh"
#include "ref_point_data.hh"
/* -------------------------------------------------------------------------- */
__BEGIN_LIBMULTISCALE__
ComputeImpulse
::
ComputeImpulse
(
const
std
::
string
&
name
)
:
ComputeInterface
(
name
)
{
impulseType
=
Impulse
::
PLANAR
;
direction
=
0
;
for
(
UInt
i
=
0
;
i
<
3
;
++
i
)
{
center
[
i
]
=
0.0
;
}
};
/* -------------------------------------------------------------------------- */
ComputeImpulse
::~
ComputeImpulse
()
{}
/* -------------------------------------------------------------------------- */
void
ComputeImpulse
::
init
()
{
wave_number
=
2
*
M_PI
/
wave_length
;
}
/* -------------------------------------------------------------------------- */
inline
Real
ComputeImpulse
::
computeScaleImpulse
(
Real
d
)
{
const
Real
k
=
wave_number
;
const
Real
res
=
intensity
*
sin
(
k
*
d
)
*
exp
(
-
k
*
k
/
9
*
d
*
d
);
DUMP
(
"impulse computed: "
<<
d
<<
" "
<<
k
<<
" "
<<
intensity
<<
" => "
<<
res
,
DBG_INFO
);
return
res
;
}
/* -------------------------------------------------------------------------- */
template
<>
inline
UInt
Parser
::
parse
(
Impulse
::
ImpulseType
&
type
,
std
::
stringstream
&
line
,
UInt
n_entries
)
{
std
::
string
name
;
UInt
nb
=
strNext
(
name
,
line
);
if
(
name
==
"CIRCULAR"
)
type
=
Impulse
::
CIRCULAR
;
else
if
(
name
==
"PLANAR"
)
type
=
Impulse
::
PLANAR
;
else
LM_FATAL
(
"unknown impulse type "
<<
name
);
return
nb
;
}
/* -------------------------------------------------------------------------- */
template
<
typename
Cont
>
void
ComputeImpulse
::
build
(
Cont
&
cont
)
{
constexpr
UInt
Dim
=
Cont
::
Dim
;
this
->
empty
();
this
->
setDim
(
Cont
::
Dim
);
for
(
auto
&&
at
:
cont
)
{
if
(
impulseType
==
Impulse
::
PLANAR
)
{
Real
d
=
at
.
position0
()[
direction
]
-
center
[
direction
];
Real
impulse
=
computeScaleImpulse
(
d
);
for
(
UInt
i
=
0
;
i
<
Dim
;
++
i
)
{
if
(
i
==
direction
)
this
->
add
(
impulse
);
else
this
->
add
(
0.0
);
}
}
else
if
(
impulseType
==
Impulse
::
CIRCULAR
)
{
Real
vec_dir
[
Dim
];
Real
norm_vec_dir
=
0
;
for
(
UInt
i
=
0
;
i
<
Dim
;
++
i
)
{
Real
dist
=
at
.
position0
()[
i
]
-
center
[
i
];
vec_dir
[
i
]
=
dist
;
dist
*=
dist
;
norm_vec_dir
+=
dist
;
}
norm_vec_dir
=
sqrt
(
norm_vec_dir
);
if
(
norm_vec_dir
==
0.
)
LM_FATAL
(
"Cannot compute a displacement at the center of the circle"
);
for
(
UInt
i
=
0
;
i
<
Dim
;
++
i
)
vec_dir
[
i
]
/=
norm_vec_dir
;
Real
d
=
norm_vec_dir
-
radius
;
Real
impulse
=
computeScaleImpulse
(
d
);
for
(
UInt
i
=
0
;
i
<
Dim
;
++
i
)
{
this
->
add
(
impulse
*
vec_dir
[
i
]);
}
}
}
this
->
name_computed
.
clear
();
this
->
name_computed
.
push_back
(
"impulse"
);
}
/* -------------------------------------------------------------------------- */
/* LMDESC IMPULSE
This stimulator sets an initial impulse displacement field that will generate
a wave. It can generate planar or circular waves:\\
\begin{itemize}
\item Planar: $u(\vec{X}) += I \cdot sin\left(k d \right) exp\left(-\frac{(k
d)^2}{9} \right) \vec{e_i}$,
with $I$ the intensity, $i$ the chosen direction and
$k = 2\pi/LWAVE$ and $d = \vec{X}_i-\vec{C}_i$ as defined with the parameters
(see below).
\item Circular:
$u(X) += I \cdot sin\left(k (d - R) \right) exp\left(-\frac{(k (d - R))^2}{9}
\right) \frac{\vec{X} - \vec{C}}{d}$,
with $I$ the intensity,
$k = 2\pi/LWAVE$ and $d = \mid\mid \vec{X} - \vec{C} \mid\mid$ and $R$ a
radius as defined with the parameters (see below).
\end{itemize}
*/
/* LMEXAMPLE COMPUTE impulse IMPULSE INPUT central_md LWAVE WaveLength*r0
* DIRECTION 0 INTENSITY 1.1e-3 ONESHOT 0 */
void
ComputeImpulse
::
declareParams
()
{
/* LMKEYWORD LWAVE
Set the wavelength of the wave to be generated
*/
this
->
parseKeyword
(
"LWAVE"
,
wave_length
);
/* LMKEYWORD DIRECTION
It can be 0,1 or 2 to specify X, Y or Z direction for planar waves
*/
this
->
parseKeyword
(
"DIRECTION"
,
direction
,
0u
);
/* LMKEYWORD RADIUS
Radius to be used to generate the impulse
*/
this
->
parseKeyword
(
"RADIUS"
,
radius
,
0.
);
/* LMKEYWORD INTENSITY
Intensity of the displacement
*/
this
->
parseKeyword
(
"INTENSITY"
,
intensity
);
/* LMKEYWORD CENTER
center of the impulse to be injected
*/
this
->
parseVectorKeyword
(
"CENTER"
,
spatial_dimension
,
center
,
VEC_DEFAULTS
(
0.
,
0.
,
0.
));
/* LMKEYWORD TYPE
Flag to specify the type of impulse.
It can be either CIRCULAR or PLANAR.
Self-explanatory examples are:\\
COMPUTE impulse-planar IMPULSE INPUT md LWAVE L0/10 DIRECTION 0 INTENSITY
1e-3 CENTER 0 0 \\
\includegraphics[scale=.5]{images/planar-impulse} \\
COMPUTE impulse-circular IMPULSE INPUT md LWAVE L0/10 TYPE CIRCULAR RADIUS
L0/4 INTENSITY 1e-3 CENTER 0 0 \\
\includegraphics[scale=.5]{images/radial-impulse}
*/
this
->
parseKeyword
(
"TYPE"
,
impulseType
,
Impulse
::
PLANAR
);
}
/* -------------------------------------------------------------------------- */
DECLARE_COMPUTE_MAKE_CALL
(
ComputeImpulse
);
__END_LIBMULTISCALE__
Event Timeline
Log In to Comment