Non-linear elastic material model.
An overview of the theory can be found in docs/theory/readme.tex
conveniently compiled to this PDF.
This library is free to use under the MIT license. Any additions are very much appreciated, in terms of suggested functionality, code, documentation, testimonials, word-of-mouth advertisement, etc. Bug reports or feature requests can be filed on GitHub. As always, the code comes with no guarantee. None of the developers can be held responsible for possible mistakes.
Download: .zip file | .tar.gz file.
(c - MIT) T.W.J. de Geus (Tom) | tom@geus.me | www.geus.me | github.com/tdegeus/GMatNonLinearElastic
import GMatNonLinearElastic.Cartesian3d as GMat
shape = [...]
kappa = np.empty(shape)
sig0 = np.empty(shape)
eps0 = np.empty(shape)
m = np.empty(shape)
...
GMat.NonLinearElasticXd model(kappa, sig0, eps0, m);
...
Eps = np.empty(shape + [3, 3])
...
model.Eps = Eps
print(model.Sig)
conda install -c conda-forge python-gmatnonlinearelastic
Note that xsimd and hardware optimisations are not enabled. To enable them you have to compile on your system, as is discussed next.
You need xtensor, xtensor-python and optionally xsimd as prerequisites. The easiest is to use conda to get the prerequisites:
conda install -c conda-forge xtensor xsimd xtensor-pythonIf you then compile and install with the same environment you should be good to go. Otherwise, a bit of manual labour might be needed to treat the dependencies.
git checkout https://github.com/tdegeus/GMatNonLinearElastic.git
cd GMatNonLinearElastic
# Only if you want to use hardware optimisation:
export SKBUILD_CONFIGURE_OPTIONS="-DUSE_SIMD=1"
python -m pip install . -v
#include <GMatNonLinearElastic/Cartesian3d.h>
namespace GMat = GMatNonLinearElastic::Cartesian3d;
int main()
{
static const size_t rank = ...;
xt::xtensor<double, rank> kappa = ...;
xt::xtensor<double, rank> sig0 = ...;
xt::xtensor<double, rank> eps0 = ...;
xt::xtensor<double, rank> m = ...;
GMat::NonLinearElasticXd model(kappa, sig0, eps0, m);
...
xt::xtensor<double, rank + 2> Eps;
...
// all necessary computation are done at this point
model.set_Eps(Eps);
...
// get reference to stress
auto Sig = model.Sig();
return 0;
}
conda install -c conda-forge gmatnonlinearelastic
git checkout https://github.com/tdegeus/GMatNonLinearElastic.git
cd GMatNonLinearElastic
cmake -Bbuild
cd build
cmake --install .
Your CMakeLists.txt
can be as follows
cmake_minimum_required(VERSION 3.1)
project(example)
find_package(GMatNonLinearElastic REQUIRED)
add_executable(example example.cpp)
target_link_libraries(example PRIVATE GMatNonLinearElastic)
The following targets are available:
-
GMatNonLinearElastic
Includes the library and its dependencies. -
GMatNonLinearElastic::assert
Enables IO-assertions by definingGMATNONLINEARELASTIC_ENABLE_ASSERT
. -
GMatNonLinearElastic::debug
Enables assertions of all dependencies. -
GMatNonLinearElastic::compiler_warings
Enables compiler warnings (generic).
It is advised to think about compiler optimisation and enabling xsimd.
Using CMake this can be done using the xtensor::optimize
and xtensor::use_xsimd
targets.
The above example then becomes:
cmake_minimum_required(VERSION 3.1)
project(example)
find_package(GMatNonLinearElastic REQUIRED)
find_package(xtensor REQUIRED)
find_package(xsimd REQUIRED)
add_executable(example example.cpp)
target_link_libraries(example PRIVATE
GMatNonLinearElastic
xtensor::optimize
xtensor::use_xsimd)
See the documentation of xtensor.
Presuming that the compiler is c++
, compile using:
c++ -I/path/to/GMatNonLinearElastic/include ...
Note that you have to take care of the xtensor dependency, the C++ version, optimisation, enabling xsimd, ...
Presuming that the compiler is c++
, compile using:
c++ `pkg-config --cflags GMatNonLinearElastic` ...
Note that you have to take care of the xtensor dependency, the C++ version, optimization, enabling xsimd, ...
The individual material point and the array of material points was fully integrated. In addition, the number of copies was reduced.
There is only a single class NonLinearElastic
. It's functions where renamed:
.setStrain(...)
->.set_Eps(...)
.Stress()
->.Sig()
(now returns a reference)..stress(...)
: deprecated..Tangent()
->.C()
(now returns a reference)..tangent(...)
: deprecated.
There is only a single class NonLinearElastic
. It's functions are converted to properties:
.setStrain(...)
->.Eps = ...
.Stress()
->.Sig
(now returns a reference)..stress(...)
: deprecated..Tangent()
->.C
(now returns a reference)..tangent(...)
: deprecated.
xtensor_fixed
was completely deprecated in v0.2.0, as were the type aliases
Tensor2
and Tensor4
.
Please update your code as follows:
Tensor2
->xt::xtensor<double, 2>
.Tensor4
->xt::xtensor<double, 4>
.
Tip: Used auto
as return type as much as possible.
This simplifies implementation, and renders is less subjective to library
return type changes.
Compared to v0.1.0, v0.2.0 has some generalisations and efficiency updates. This requires the following changes:
-
Matrix
has been generalised toArray<rank>
. Practically this requires changing:Matrix
toArray<2>
in C++.Matrix
toArray2d
in Python. Note thatArray1d
,Array3d
, are also available.
-
Array<rank>.check
->if (xt::any(xt::equal(array.type(), Type::Unset))) { throw std::runtime_error("Please set all points"); }
Note however that it is no longer required to set all points, unset points are filled-up with zeros.
-
Strain is now stored as a member. Functions like
stress
now return the state based on the last specified strain, specified usingsetStrain(Esp)
. This leads to the following changes:stress
: no argument.tangent
: no argument, single return value (no longer returns stress).
Complete API overhaul.
- Using scikit-build, setuptools_scm, xtensor-python (#21)
- CMake clean-up (#21)
Compared to v0.1.0, v0.2.0 has some generalisations and efficiency updates. This requires the following changes:
-
Matrix
has been generalised toArray<rank>
. Practically this requires changing:Matrix
toArray<2>
in C++.Matrix
toArray2d
in Python. Note thatArray1d
,Array3d
, are also available.
-
Array
now sets zeros for allType::Unset
points. The functioncheck
is deprecated accordingly. -
Strain is now stored as a member. Functions like
stress
now return the state based on the last specified strain, specified usingsetStrain(Esp)
. This leads to the following changes:stress
: no argument.tangent
: no argument, single return value (no longer returns stress).
-
Tensor operations are now provided centrally in the GMat eco-system, by GMatTensor