Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F90444648
Element.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
Fri, Nov 1, 17:47
Size
2 KB
Mime Type
text/x-c
Expires
Sun, Nov 3, 17:47 (1 d, 22 h)
Engine
blob
Format
Raw Data
Handle
22076273
Attached To
rGOOSEFEM GooseFEM
Element.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::Element", "Element.h")
{
SECTION("QuadratureBase - AsTensor - e.g. Quad4")
{
size_t nelem = 3;
size_t nip = 4;
GooseFEM::Element::QuadratureBase<4, 2, 2> quad(nelem, nip);
xt::xtensor<double, 2> qscalar = xt::random::rand<double>({nelem, nip});
auto qtensor = quad.AsTensor<2>(qscalar);
REQUIRE(xt::has_shape(quad.AllocateQscalar<double>(), qscalar.shape()));
REQUIRE(xt::has_shape(quad.AllocateQscalar<double>(0.0), qscalar.shape()));
REQUIRE(xt::has_shape(quad.AllocateQtensor<2, double>(), qtensor.shape()));
REQUIRE(xt::has_shape(quad.AllocateQtensor<2, double>(0.0), qtensor.shape()));
REQUIRE(xt::has_shape(quad.AllocateQtensor<double>(2), qtensor.shape()));
REQUIRE(xt::has_shape(quad.AllocateQtensor<double>(2, 0.0), qtensor.shape()));
for (size_t e = 0; e < nelem; ++e) {
for (size_t q = 0; q < nip; ++q) {
REQUIRE(xt::allclose(xt::view(qtensor, xt::keep(e), xt::keep(q)), qscalar(e, q)));
}
}
}
SECTION("QuadratureBase - AsTensor - e.g. Hex8")
{
size_t nelem = 6;
size_t nip = 8;
GooseFEM::Element::QuadratureBase<8, 3, 3> quad(nelem, nip);
xt::xtensor<double, 2> qscalar = xt::random::rand<double>({nelem, nip});
auto qtensor = quad.AsTensor<2>(qscalar);
REQUIRE(xt::has_shape(quad.AllocateQscalar<double>(), qscalar.shape()));
REQUIRE(xt::has_shape(quad.AllocateQscalar<double>(0.0), qscalar.shape()));
REQUIRE(xt::has_shape(quad.AllocateQtensor<2, double>(), qtensor.shape()));
REQUIRE(xt::has_shape(quad.AllocateQtensor<2, double>(0.0), qtensor.shape()));
REQUIRE(xt::has_shape(quad.AllocateQtensor<double>(2), qtensor.shape()));
REQUIRE(xt::has_shape(quad.AllocateQtensor<double>(2, 0.0), qtensor.shape()));
for (size_t e = 0; e < nelem; ++e) {
for (size_t q = 0; q < nip; ++q) {
REQUIRE(xt::allclose(xt::view(qtensor, xt::keep(e), xt::keep(q)), qscalar(e, q)));
}
}
}
}
Event Timeline
Log In to Comment