Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F90320947
Allocate.cpp
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
Thu, Oct 31, 11:57
Size
3 KB
Mime Type
text/x-c
Expires
Sat, Nov 2, 11:57 (2 d)
Engine
blob
Format
Raw Data
Handle
22051363
Attached To
rGOOSEFEM GooseFEM
Allocate.cpp
View Options
#include <catch2/catch.hpp>
#include <xtensor/xrandom.hpp>
#include <xtensor/xmath.hpp>
#include <GooseFEM/GooseFEM.h>
#define ISCLOSE(a,b) REQUIRE_THAT((a), Catch::WithinAbs((b), 1.e-12));
TEST_CASE
(
"GooseFEM::Allocate"
,
"Allocate.h"
)
{
SECTION
(
"asTensor - 1"
)
{
xt
::
xtensor
<
double
,
2
>
a0
=
{
{
1.0
,
2.0
},
{
3.0
,
4.0
}};
xt
::
xtensor
<
double
,
3
>
a1
=
{
{{
1.0
,
1.0
,
1.0
},
{
2.0
,
2.0
,
2.0
}},
{{
3.0
,
3.0
,
3.0
},
{
4.0
,
4.0
,
4.0
}}};
xt
::
xtensor
<
double
,
4
>
a2
=
{
{{{
1.0
,
1.0
},
{
1.0
,
1.0
},
{
1.0
,
1.0
}},
{{
2.0
,
2.0
},
{
2.0
,
2.0
},
{
2.0
,
2.0
}}},
{{{
3.0
,
3.0
},
{
3.0
,
3.0
},
{
3.0
,
3.0
}},
{{
4.0
,
4.0
},
{
4.0
,
4.0
},
{
4.0
,
4.0
}}}};
xt
::
xtensor
<
double
,
3
>
b1
=
xt
::
empty
<
double
>
({
2
,
2
,
3
});
xt
::
xtensor
<
double
,
4
>
b2
=
xt
::
empty
<
double
>
({
2
,
2
,
3
,
2
});
GooseFEM
::
asTensor
<
2
,
1
>
(
a0
,
b1
);
GooseFEM
::
asTensor
<
2
,
2
>
(
a0
,
b2
);
REQUIRE
(
xt
::
allclose
(
a1
,
b1
));
REQUIRE
(
xt
::
allclose
(
a2
,
b2
));
}
SECTION
(
"asTensor - 2"
)
{
xt
::
xtensor
<
double
,
2
>
a0
=
{
{
1.0
,
2.0
},
{
3.0
,
4.0
}};
xt
::
xtensor
<
double
,
3
>
a1
=
{
{{
1.0
,
1.0
,
1.0
},
{
2.0
,
2.0
,
2.0
}},
{{
3.0
,
3.0
,
3.0
},
{
4.0
,
4.0
,
4.0
}}};
xt
::
xtensor
<
double
,
4
>
a2
=
{
{{{
1.0
,
1.0
},
{
1.0
,
1.0
},
{
1.0
,
1.0
}},
{{
2.0
,
2.0
},
{
2.0
,
2.0
},
{
2.0
,
2.0
}}},
{{{
3.0
,
3.0
},
{
3.0
,
3.0
},
{
3.0
,
3.0
}},
{{
4.0
,
4.0
},
{
4.0
,
4.0
},
{
4.0
,
4.0
}}}};
auto
b1
=
GooseFEM
::
AsTensor
<
2
,
1
>
(
a0
,
3
);
auto
b2
=
GooseFEM
::
AsTensor
<
2
,
2
>
(
a0
,
{
3
,
2
});
REQUIRE
(
xt
::
allclose
(
a1
,
b1
));
REQUIRE
(
xt
::
allclose
(
a2
,
b2
));
}
SECTION
(
"asTensor - 3"
)
{
xt
::
xtensor
<
double
,
2
>
a0
=
{
{
1.0
,
2.0
},
{
3.0
,
4.0
}};
xt
::
xtensor
<
double
,
3
>
a1
=
{
{{
1.0
,
1.0
},
{
2.0
,
2.0
}},
{{
3.0
,
3.0
},
{
4.0
,
4.0
}}};
xt
::
xtensor
<
double
,
4
>
a2
=
{
{{{
1.0
,
1.0
},
{
1.0
,
1.0
}},
{{
2.0
,
2.0
},
{
2.0
,
2.0
}}},
{{{
3.0
,
3.0
},
{
3.0
,
3.0
}},
{{
4.0
,
4.0
},
{
4.0
,
4.0
}}}};
auto
b1
=
GooseFEM
::
AsTensor
<
2
,
1
>
(
a0
,
2
);
auto
b2
=
GooseFEM
::
AsTensor
<
2
,
2
>
(
a0
,
2
);
REQUIRE
(
xt
::
allclose
(
a1
,
b1
));
REQUIRE
(
xt
::
allclose
(
a2
,
b2
));
}
SECTION
(
"asTensor - 4"
)
{
xt
::
xtensor
<
double
,
2
>
a0
=
{
{
1.0
,
2.0
},
{
3.0
,
4.0
}};
xt
::
xtensor
<
double
,
3
>
a1
=
{
{{
1.0
,
1.0
,
1.0
},
{
2.0
,
2.0
,
2.0
}},
{{
3.0
,
3.0
,
3.0
},
{
4.0
,
4.0
,
4.0
}}};
xt
::
xtensor
<
double
,
4
>
a2
=
{
{{{
1.0
,
1.0
},
{
1.0
,
1.0
},
{
1.0
,
1.0
}},
{{
2.0
,
2.0
},
{
2.0
,
2.0
},
{
2.0
,
2.0
}}},
{{{
3.0
,
3.0
},
{
3.0
,
3.0
},
{
3.0
,
3.0
}},
{{
4.0
,
4.0
},
{
4.0
,
4.0
},
{
4.0
,
4.0
}}}};
auto
b1
=
GooseFEM
::
AsTensor
(
1
,
a0
,
3
);
auto
b2
=
GooseFEM
::
AsTensor
(
2
,
a0
,
{
3
,
2
});
REQUIRE
(
xt
::
allclose
(
a1
,
b1
));
REQUIRE
(
xt
::
allclose
(
a2
,
b2
));
}
SECTION
(
"asTensor - 5"
)
{
xt
::
xtensor
<
double
,
2
>
a0
=
{
{
1.0
,
2.0
},
{
3.0
,
4.0
}};
xt
::
xtensor
<
double
,
3
>
a1
=
{
{{
1.0
,
1.0
},
{
2.0
,
2.0
}},
{{
3.0
,
3.0
},
{
4.0
,
4.0
}}};
xt
::
xtensor
<
double
,
4
>
a2
=
{
{{{
1.0
,
1.0
},
{
1.0
,
1.0
}},
{{
2.0
,
2.0
},
{
2.0
,
2.0
}}},
{{{
3.0
,
3.0
},
{
3.0
,
3.0
}},
{{
4.0
,
4.0
},
{
4.0
,
4.0
}}}};
auto
b1
=
GooseFEM
::
AsTensor
(
1
,
a0
,
2
);
auto
b2
=
GooseFEM
::
AsTensor
(
2
,
a0
,
2
);
REQUIRE
(
xt
::
allclose
(
a1
,
b1
));
REQUIRE
(
xt
::
allclose
(
a2
,
b2
));
}
}
Event Timeline
Log In to Comment