Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F91951443
test_system_base.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, Nov 16, 01:43
Size
4 KB
Mime Type
text/x-c
Expires
Mon, Nov 18, 01:43 (1 d, 22 h)
Engine
blob
Format
Raw Data
Handle
22352921
Attached To
rMSPPROTO µSpectre prototype implementation
test_system_base.cc
View Options
/**
* file test_system_base.cc
*
* @author Till Junge <till.junge@epfl.ch>
*
* @date 10 May 2017
*
* @brief test SystemBase class
*
* @section LICENCE
*
* Copyright (C) 2017 Till Junge
*
* µSpectre is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3, or (at
* your option) any later version.
*
* µSpectre 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
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Emacs; see the file COPYING. If not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include <boost/test/unit_test.hpp>
#include <boost/mpl/list.hpp>
#include <Eigen/Dense>
#include <iostream>
#include "common/voigt_conversion.hh"
#include "vector"
#include "memory"
#include "system/system_base.hh"
#include "tests.hh"
namespace
muSpectre
{
template
<
Dim_t
DimS
,
Dim_t
DimM
>
struct
sys_fixture:
public
SystemBase
<
DimS
,
DimM
>
{
sys_fixture
()
:
SystemBase
<
DimS
,
DimM
>
(
std_size
,
std_nb_pix
){}
const
static
std
::
array
<
Real
,
DimS
>
std_size
;
const
static
Index_t
<
DimS
>
std_nb_pix
;
const
static
Dim_t
dim_s
=
DimS
,
dim_m
=
DimM
;
};
template
<>
const
std
::
array
<
Real
,
2
>
sys_fixture
<
2
,
2
>::
std_size
{
5
,
3
};
template
<>
const
std
::
array
<
Real
,
2
>
sys_fixture
<
2
,
3
>::
std_size
{
5
,
3
};
template
<>
const
std
::
array
<
Real
,
3
>
sys_fixture
<
3
,
3
>::
std_size
{
7
,
5
,
3
};
template
<>
const
Index_t
<
2
>
sys_fixture
<
2
,
2
>::
std_nb_pix
{
5
,
3
};
template
<>
const
Index_t
<
2
>
sys_fixture
<
2
,
3
>::
std_nb_pix
{
5
,
3
};
template
<>
const
Index_t
<
3
>
sys_fixture
<
3
,
3
>::
std_nb_pix
{
7
,
5
,
3
};
#include "testdata_system_base.hh"
//----------------------------------------------------------------------------//
using
test_systems
=
boost
::
mpl
::
list
<
sys_fixture
<
2
,
2
>
,
sys_fixture
<
2
,
3
>
,
sys_fixture
<
3
,
3
>>
;
//----------------------------------------------------------------------------//
BOOST_AUTO_TEST_CASE
(
fftfreq_test
)
{
auto
length
=
15.2
;
auto
n1
{
8
},
n2
{
9
};
Eigen
::
RowVectorXd
ref1
(
n1
);
ref1
<<
0.0
,
0.06578947368421052
,
0.13157894736842105
,
0.19736842105263158
,
-
0.2631578947368421
,
-
0.19736842105263158
,
-
0.13157894736842105
,
-
0.06578947368421052
;
Eigen
::
RowVectorXd
ref2
(
n2
);
ref2
<<
0.0
,
0.06578947368421052
,
0.13157894736842105
,
0.19736842105263158
,
0.2631578947368421
,
-
0.2631578947368421
,
-
0.19736842105263158
,
-
0.13157894736842105
,
-
0.06578947368421052
;
auto
challenge1
(
Projection
::
fft_freqs
(
n1
,
length
));
auto
challenge2
(
Projection
::
fft_freqs
(
n2
,
length
));
Eigen
::
RowVectorXd
er1
=
ref1
-
challenge1
;
Real
error1
=
(
ref1
-
challenge1
).
norm
();
Real
error2
=
(
ref2
-
challenge2
).
norm
();
BOOST_CHECK_LT
(
error1
,
tol
);
BOOST_CHECK_LT
(
error2
,
tol
);
}
//----------------------------------------------------------------------------//
BOOST_FIXTURE_TEST_CASE_TEMPLATE
(
constructor_test
,
F
,
test_systems
,
F
)
{
}
//----------------------------------------------------------------------------//
BOOST_FIXTURE_TEST_CASE_TEMPLATE
(
Ghat_test
,
F
,
test_systems
,
F
)
{
const
int
dim_s
=
F
::
dim_s
;
const
int
dim_m
=
F
::
dim_m
;
auto
ghat_ref
=
Ghats
<
dim_s
,
dim_m
>
();
//TODO; for unknown reason, the python ref gives different results when material and spatial dimension dffer. not sure who's wrong
if
(
dim_s
==
dim_m
)
{
for
(
size_t
pix_id
=
0
;
pix_id
<
F
::
nb_pixel
;
++
pix_id
)
{
using
Tshape
=
Eigen
::
Sizes
<
F
::
dim_m
,
F
::
dim_m
,
F
::
dim_m
,
F
::
dim_m
>
;
using
Ttype
=
Eigen
::
TensorFixedSize
<
Real
,
Tshape
>
;
Ttype
ghat_i
=
F
::
Ghats
.
template
chip
<
4
>
(
pix_id
);
Real
error
=
(
VoigtConversion
<
F
::
dim_m
>::
fourth_to_2d
(
ghat_i
)
-
(
*
ghat_ref
[
pix_id
])).
norm
();
if
(
error
>=
tol
)
{
std
::
cout
<<
"For dim_m = "
<<
dim_m
<<
", dim_s = "
<<
dim_s
<<
" reference is:
\n
"
<<
VoigtConversion
<
dim_m
>::
fourth_to_2d
(
ghat_i
)
<<
"
\n
but I got:
\n
"
<<
*
ghat_ref
[
pix_id
]
<<
std
::
endl
;
}
BOOST_CHECK_LT
(
error
,
tol
);
}
}
}
}
// muSpectre
Event Timeline
Log In to Comment