Skip to content

Commit

Permalink
Changes for shell stress in gpu_fem (#126)
Browse files Browse the repository at this point in the history
* isotropic shell stress and other fixes for shell element on GPU

* remove shell code from a2d and into shell fem code itself

* remove test ad shell tests

* clang-format

* clang-format v2

* clang format a2dbinary.h
  • Loading branch information
sean-engelstad authored Dec 17, 2024
1 parent 17ba8d1 commit 502cc08
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 1,727 deletions.
7 changes: 0 additions & 7 deletions include/a2dcore.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,4 @@
#include "ad/a2dvecouter.h"
#include "ad/a2dvecsum.h"

// shell routines
#include "ad/shell/a2dshellassembleframe.h"
// #include "ad/shell/a2dmatconcat.h"
#include "ad/shell/a2dmatrotateframe.h"
#include "ad/shell/a2dshellstrain.h"
#include "ad/shell/a2dsymmatrotateframe.h"

#endif // A2D_CORE_H
33 changes: 18 additions & 15 deletions include/ad/a2dveccross.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,22 @@ namespace A2D {

// z = x cross y
template <typename T>
void VecCross(const Vec<T, 3> &x, const Vec<T, 3> &y, Vec<T, 3> &z) {
A2D_FUNCTION void VecCross(const Vec<T, 3> &x, const Vec<T, 3> &y,
Vec<T, 3> &z) {
VecCrossCore<T>(get_data(x), get_data(y), get_data(z));
}

// 2D variants
// Use vec(x) = x * hat(k)
template <typename Tx, typename T>
void VecCross(const Tx x, const Vec<T, 2> &y, Vec<T, 2> &z) {
A2D_FUNCTION void VecCross(const Tx x, const Vec<T, 2> &y, Vec<T, 2> &z) {
z(0) = -x * y(1);
z(1) = x * y(0);
}

// Use vec(y) = y * hat(k)
template <typename T, typename Ty>
void VecCross(const Vec<T, 2> &x, const Ty y, Vec<T, 2> &z) {
A2D_FUNCTION void VecCross(const Vec<T, 2> &x, const Ty y, Vec<T, 2> &z) {
z(0) = y * x(1);
z(1) = -y * x(0);
}
Expand Down Expand Up @@ -115,37 +116,38 @@ class VecCrossExpr {

template <class xtype, class ytype, class ztype,
std::enable_if_t<get_vec_size<ztype>::size == 3, bool> = true>
auto VecCross(ADObj<xtype> &x, ADObj<ytype> &y, ADObj<ztype> &z) {
A2D_FUNCTION auto VecCross(ADObj<xtype> &x, ADObj<ytype> &y, ADObj<ztype> &z) {
return VecCrossExpr<ADObj<xtype>, ADObj<ytype>, ADObj<ztype>>(x, y, z);
}

template <class xtype, class ytype, class ztype,
std::enable_if_t<get_vec_size<ztype>::size == 3, bool> = true>
auto VecCross(const xtype &x, ADObj<ytype> &y, ADObj<ztype> &z) {
A2D_FUNCTION auto VecCross(const xtype &x, ADObj<ytype> &y, ADObj<ztype> &z) {
return VecCrossExpr<const xtype, ADObj<ytype>, ADObj<ztype>>(x, y, z);
}

template <class xtype, class ytype, class ztype,
std::enable_if_t<get_vec_size<ztype>::size == 3, bool> = true>
auto VecCross(ADObj<xtype> &x, const ytype &y, ADObj<ztype> &z) {
A2D_FUNCTION auto VecCross(ADObj<xtype> &x, const ytype &y, ADObj<ztype> &z) {
return VecCrossExpr<ADObj<xtype>, const ytype, ADObj<ztype>>(x, y, z);
}

template <class xtype, class ytype, class ztype,
std::enable_if_t<get_vec_size<ztype>::size == 3, bool> = true>
auto VecCross(A2DObj<xtype> &x, A2DObj<ytype> &y, A2DObj<ztype> &z) {
A2D_FUNCTION auto VecCross(A2DObj<xtype> &x, A2DObj<ytype> &y,
A2DObj<ztype> &z) {
return VecCrossExpr<A2DObj<xtype>, A2DObj<ytype>, A2DObj<ztype>>(x, y, z);
}

template <class xtype, class ytype, class ztype,
std::enable_if_t<get_vec_size<ztype>::size == 3, bool> = true>
auto VecCross(const xtype &x, A2DObj<ytype> &y, A2DObj<ztype> &z) {
A2D_FUNCTION auto VecCross(const xtype &x, A2DObj<ytype> &y, A2DObj<ztype> &z) {
return VecCrossExpr<const xtype, A2DObj<ytype>, A2DObj<ztype>>(x, y, z);
}

template <class xtype, class ytype, class ztype,
std::enable_if_t<get_vec_size<ztype>::size == 3, bool> = true>
auto VecCross(A2DObj<xtype> &x, const ytype &y, A2DObj<ztype> &z) {
A2D_FUNCTION auto VecCross(A2DObj<xtype> &x, const ytype &y, A2DObj<ztype> &z) {
return VecCrossExpr<A2DObj<xtype>, const ytype, A2DObj<ztype>>(x, y, z);
}

Expand Down Expand Up @@ -299,38 +301,39 @@ class VecCross2DExpr {

template <class xtype, class ytype, class ztype,
std::enable_if_t<get_vec_size<ztype>::size == 2, bool> = true>
auto VecCross(ADObj<xtype> &x, ADObj<ytype> &y, ADObj<ztype> &z) {
A2D_FUNCTION auto VecCross(ADObj<xtype> &x, ADObj<ytype> &y, ADObj<ztype> &z) {
return VecCross2DExpr<ADObj<xtype> &, ADObj<ytype> &, ADObj<ztype>>(x, y, z);
}

template <class xtype, class ytype, class ztype,
std::enable_if_t<get_vec_size<ztype>::size == 2, bool> = true>
auto VecCross(const xtype x, ADObj<ytype> &y, ADObj<ztype> &z) {
A2D_FUNCTION auto VecCross(const xtype x, ADObj<ytype> &y, ADObj<ztype> &z) {
return VecCross2DExpr<const xtype, ADObj<ytype> &, ADObj<ztype>>(x, y, z);
}

template <class xtype, class ytype, class ztype,
std::enable_if_t<get_vec_size<ztype>::size == 2, bool> = true>
auto VecCross(ADObj<xtype> &x, const ytype &y, ADObj<ztype> &z) {
A2D_FUNCTION auto VecCross(ADObj<xtype> &x, const ytype &y, ADObj<ztype> &z) {
return VecCross2DExpr<ADObj<xtype> &, const ytype, ADObj<ztype>>(x, y, z);
}

template <class xtype, class ytype, class ztype,
std::enable_if_t<get_vec_size<ztype>::size == 2, bool> = true>
auto VecCross(A2DObj<xtype> &x, A2DObj<ytype> &y, A2DObj<ztype> &z) {
A2D_FUNCTION auto VecCross(A2DObj<xtype> &x, A2DObj<ytype> &y,
A2DObj<ztype> &z) {
return VecCross2DExpr<A2DObj<xtype> &, A2DObj<ytype> &, A2DObj<ztype>>(x, y,
z);
}

template <class xtype, class ytype, class ztype,
std::enable_if_t<get_vec_size<ztype>::size == 2, bool> = true>
auto VecCross(const xtype x, A2DObj<ytype> &y, A2DObj<ztype> &z) {
A2D_FUNCTION auto VecCross(const xtype x, A2DObj<ytype> &y, A2DObj<ztype> &z) {
return VecCross2DExpr<const xtype, A2DObj<ytype> &, A2DObj<ztype>>(x, y, z);
}

template <class xtype, class ytype, class ztype,
std::enable_if_t<get_vec_size<ztype>::size == 2, bool> = true>
auto VecCross(A2DObj<xtype> &x, const ytype y, A2DObj<ztype> &z) {
A2D_FUNCTION auto VecCross(A2DObj<xtype> &x, const ytype y, A2DObj<ztype> &z) {
return VecCross2DExpr<A2DObj<xtype> &, const ytype, A2DObj<ztype>>(x, y, z);
}

Expand Down
4 changes: 4 additions & 0 deletions include/ad/core/a2dmatinvcore.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include "../../a2ddefs.h"

namespace A2D {

template <typename T, int N>
A2D_FUNCTION void MatInvCore(const T A[], T Ainv[]) {
static_assert((N >= 1 && N <= 3), "MatInvCore not implemented for N >= 4");
Expand Down Expand Up @@ -67,4 +69,6 @@ A2D_FUNCTION void SymMatInvCore(const T S[], T Sinv[]) {
}
}

} // namespace A2D

#endif // A2D_MAT_INV_CORE_H
38 changes: 38 additions & 0 deletions include/ad/core/a2dsymmatveccore.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#ifndef A2D_SYMMAT_VEC_CORE_H
#define A2D_SYMMAT_VEC_CORE_H

#include "../../a2ddefs.h"

namespace A2D {

template <typename T, bool additive = false>
A2D_FUNCTION void SymMatVecCore3x3(const T A[], const T x[], T b[]) {
// compute b = A*x
if constexpr (additive) {
b[0] += A[0] * x[0] + A[1] * x[1] + A[2] * x[2];
b[1] += A[1] * x[0] + A[3] * x[1] + A[4] * x[2];
b[2] += A[2] * x[0] + A[4] * x[1] + A[5] * x[2];
} else {
b[0] = A[0] * x[0] + A[1] * x[1] + A[2] * x[2];
b[1] = A[1] * x[0] + A[3] * x[1] + A[4] * x[2];
b[2] = A[2] * x[0] + A[4] * x[1] + A[5] * x[2];
}
}

template <typename T, bool additive = false>
A2D_FUNCTION void SymMatVecCoreScale3x3(const T& scale, const T A[],
const T x[], T b[]) {
// compute b = A * x
if constexpr (additive) {
b[0] += scale * (A[0] * x[0] + A[1] * x[1] + A[2] * x[2]);
b[1] += scale * (A[1] * x[0] + A[3] * x[1] + A[4] * x[2]);
b[2] += scale * (A[2] * x[0] + A[4] * x[1] + A[5] * x[2]);
} else {
b[0] = scale * (A[0] * x[0] + A[1] * x[1] + A[2] * x[2]);
b[1] = scale * (A[1] * x[0] + A[3] * x[1] + A[4] * x[2]);
b[2] = scale * (A[2] * x[0] + A[4] * x[1] + A[5] * x[2]);
}
}
} // namespace A2D

#endif // A2D_SYMMAT_VEC_CORE_H
Loading

0 comments on commit 502cc08

Please sign in to comment.