Skip to content
Snippets Groups Projects
Commit 09d009e8 authored by Elias Pipping's avatar Elias Pipping Committed by pipping
Browse files

Add a tensor test

[[Imported from SVN: r4671]]
parent af3ae122
No related branches found
No related tags found
No related merge requests found
......@@ -19,7 +19,8 @@ TESTS = basisgridfunctiontest \
ppmtest \
serializationtest \
subgridxyfunctionalassemblertest \
sumfunctiontest
sumfunctiontest \
tensortest
# programs just to build when "make check" is used
check_PROGRAMS = $(TESTS)
......@@ -136,4 +137,6 @@ sumfunctiontest_CPPFLAGS = $(COMMON_CPPFLAGS) $(GRID_CPPFLAGS)
sumfunctiontest_LDADD = $(COMMON_LDADD) $(GRID_LDADD)
sumfunctiontest_LDFLAGS = $(COMMON_LDFLAGS) $(GRID_LDFLAGS)
tensortest_SOURCES = tensortest.cc
include $(top_srcdir)/am/global-rules
// -*- c-basic-offset:2 indent-tabs-mode:nil -*-
#include <dune/fufem/symmetrictensor.hh>
#include <dune/fufem/mechanics/isotropictensor.hh>
#include <dune/fufem/mechanics/cubictensor.hh>
#include <dune/fufem/mechanics/tetratensor.hh>
#include <iostream>
#include <cassert>
int
main()
{
SymmetricTensor<3> e1;
e1(0,0) = 1;
e1(1,1) = 2;
e1(2,2) = 3;
e1(1,0) = 4;
e1(2,0) = 5;
e1(2,1) = 6;
SymmetricTensor<3> e2;
e2(0,0) = 1;
e2(1,1) = 2;
e2(2,2) = 3;
e2(0,1) = 4;
e2(0,2) = 5;
e2(1,2) = 6;
SymmetricTensor<3> const e3(e2);
std::cout << e3 << std::endl;
// There is no `operator() const`
//std::cout << e3(1,1) << std::endl;
assert( e1 == e2);
assert(!(e1 != e2));
e2 *= 2;
assert(abs(e1 * e2 - 2 * (e1 * e1)) < 1e-10);
assert(!(e1 == e2));
assert( e1 != e2);
e2 /= 2;
assert(abs(e1 * e1 - e1 * e2) < 1e-10);
IsotropicTensor<3> const C(.5,.25);
SymmetricTensor<3> h;
C.mv(e1, h);
std::cout << e1 << std::endl;
std::cout << h << std::endl;
std::cout << e1 * h << std::endl;
assert(abs(e1 * h - 74.4) < 1e-10); // e : C : e
TetraTensor<2> const tt2(1,2,3,4);
TetraTensor<3> const tt3(1,2,3,4,5,6);
CubicTensor<2> const ct2(1,2,3);
CubicTensor<3> const ct3(1,2,3);
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment