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/GMatElastic
import GMatLinearElastic.Cartesian3d as GMat
shape = [...]
K = np.empty(shape)
G = np.empty(shape)
...
GMat.ElasticXd model(K, G);
...
Eps = np.empty(shape + [3, 3])
...
model.Eps = Eps
print(model.Sig)
conda install -c conda-forge python-gmatelastic
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/GMatElastic.git
cd GMatElastic
# Only if you want to use hardware optimisation:
export SKBUILD_CONFIGURE_OPTIONS="-DUSE_SIMD=1"
python -m pip install . -v
#include <GMatLinearElastic/Cartesian3d.h>
namespace GMat = GMatLinearElastic::Cartesian3d;
int main()
{
static const size_t rank = ...;
xt::xtensor<double, rank> K = ...;
xt::xtensor<double, rank> G = ...;
GMat::ElasticXd model(K, G);
...
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 gmatelastic
git checkout https://github.com/tdegeus/GMatElastic.git
cd GMatElastic
cmake -Bbuild
cd build
cmake --install .
Your CMakeLists.txt
can be as follows
cmake_minimum_required(VERSION 3.1)
project(example)
find_package(GMatElastic REQUIRED)
add_executable(example example.cpp)
target_link_libraries(example PRIVATE GMatElastic)
The following targets are available:
-
GMatElastic
Includes the library and its dependencies. -
GMatElastic::assert
Enables IO-assertions by definingGMATELASTIC_ENABLE_ASSERT
. -
GMatElastic::debug
Enables assertions of all dependencies. -
GMatElastic::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(GMatElastic REQUIRED)
find_package(xtensor REQUIRED)
find_package(xsimd REQUIRED)
add_executable(example example.cpp)
target_link_libraries(example PRIVATE
GMatElastic
xtensor::optimize
xtensor::use_xsimd)
See the documentation of xtensor.
Presuming that the compiler is c++
, compile using:
c++ -I/path/to/GMatElastic/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 GMatElastic` ...
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 Elastic
. 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 Elastic
. 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).
- Making functions virtual for override
- Minor code style updates
Complete API overhaul.
Complete API overhaul.
- Using scikit-build, setuptools_scm, xtensor-python (#21)
- CMake clean-up (#21)
- Adding missing overload Python API (#20).
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 usingset_Eps(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