Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F79158207
compute_energydensity.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
Sun, Aug 25, 01:26
Size
3 KB
Mime Type
text/x-c++
Expires
Tue, Aug 27, 01:26 (2 d)
Engine
blob
Format
Raw Data
Handle
20156050
Attached To
rLIBMULTISCALE LibMultiScale
compute_energydensity.cc
View Options
/**
* @file compute_energydensity.cc
*
* @author Guillaume Anciaux <guillaume.anciaux@epfl.ch>
*
* @date Wed Jul 09 21:59:47 2014
*
* @brief This computes the spectral energy density for 1D models
*
* @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 <complex>
#include <fftw3.h>
/* -------------------------------------------------------------------------- */
#include "compute_energydensity.hh"
#include "lib_continuum.hh"
#include "lib_dd.hh"
#include "lib_md.hh"
#include "lm_common.hh"
#include "ref_point_data.hh"
/* -------------------------------------------------------------------------- */
__BEGIN_LIBMULTISCALE__
template
<
typename
Cont
>
void
ComputeEnergyDensity
<
Cont
>::
build
(
Cont
&
cont
)
{
if
(
cont
.
size
()
==
0
)
LM_FATAL
(
"there is nothing to compute"
);
if
(
Cont
::
Dim
!=
1
)
LM_FATAL
(
"this compute operates only on 1D models"
);
UInt
nbDof
=
cont
.
size
();
std
::
vector
<
std
::
complex
<
Real
>>
dos
;
dos
.
resize
(
nbDof
*
2
);
std
::
complex
<
Real
>
zero
=
0.
;
dos
.
assign
(
nbDof
*
2
,
zero
);
UInt
cpt
=
0
;
for
(
auto
&&
at
:
cont
)
{
dos
[
cpt
]
=
at
.
velocity
()[
0
];
++
cpt
;
}
std
::
vector
<
Real
>
power
;
fftw_complex
*
in
=
(
fftw_complex
*
)
&
dos
[
0
];
fftw_plan
p
=
fftw_plan_dft_1d
(
nbDof
*
2
,
in
,
in
,
FFTW_FORWARD
,
FFTW_ESTIMATE
);
fftw_execute
(
p
);
power
.
resize
(
nbDof
);
for
(
UInt
j
=
0
;
j
<
nbDof
;
++
j
)
{
Real
dw
=
norm
(
dos
[
j
]);
power
[
j
]
=
sqrt
(
dw
)
/
nbDof
;
}
fftw_destroy_plan
(
p
);
this
->
empty
();
this
->
setDim
(
2
);
this
->
add
(
power
[
0
]);
this
->
add
(
0.0
);
for
(
UInt
i
=
1
;
i
<
nbDof
;
++
i
)
{
Real
pw
=
2.0
*
power
[
i
];
Real
k
=
i
*
0.5
/
nbDof
/
shift_fft
;
this
->
add
(
pw
);
this
->
add
(
k
);
}
}
/* -------------------------------------------------------------------------- */
/* LMDESC ENERGY_DENSITY
This computes the energy per mode in the wavevector space
Warning: Currently, this works only in 1D.
*/
/* LMEXAMPLE */
template
<
typename
Cont
>
void
ComputeEnergyDensity
<
Cont
>::
declareParams
()
{
/* LMKEYWORD SHIFT_FFT
This keyword is used to shift the wavenumber axis
by given value provided by the user.
*/
this
->
parseKeyword
(
"SHIFT_FFT"
,
shift_fft
);
};
/* -------------------------------------------------------------------------- */
DECLARE_COMPUTE_REF
(
ComputeEnergyDensity
,
LIST_ATOM_MODEL
)
DECLARE_COMPUTE_REF
(
ComputeEnergyDensity
,
LIST_CONTINUUM_MODEL
)
DECLARE_COMPUTE_REF
(
ComputeEnergyDensity
,
LIST_DD_MODEL
)
DECLARE_COMPUTE_REFPOINT
(
ComputeEnergyDensity
)
DECLARE_COMPUTE_GENERIC_MESH
(
ComputeEnergyDensity
)
__END_LIBMULTISCALE__
Event Timeline
Log In to Comment