Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add iso element on a tetrahedron #688

Merged
merged 9 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ The following elements are supported on a triangle:
- [Crouzeix-Raviart](https://defelement.com/elements/crouzeix-raviart.html)
- [Bubble](https://defelement.com/elements/bubble.html)
- [Hermite](https://defelement.com/elements/hermite.html)
- [iso](https://defelement.com/elements/p1-iso-p2.html)


### Quadrilateral
Expand Down Expand Up @@ -132,6 +133,7 @@ The following elements are supported on a tetrahedron:
- [Crouzeix-Raviart](https://defelement.com/elements/crouzeix-raviart.html)
- [Bubble](https://defelement.com/elements/bubble.html)
- [Hermite](https://defelement.com/elements/hermite.html)
- [iso](https://defelement.com/elements/p1-iso-p2.html)


### Hexahedron
Expand Down
339 changes: 339 additions & 0 deletions cpp/basix/polyset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,340 @@ void tabulate_polyset_triangle_macroedge_derivs(
}
//-----------------------------------------------------------------------------
/// Compute the complete set of derivatives from 0 to nderiv, for all
/// the piecewise polynomials up to order n on a tetrahedron split into 8 by
/// splitting each edge into two parts
template <typename T>
void tabulate_polyset_tetrahedron_macroedge_derivs(
stdex::mdspan<T, stdex::dextents<std::size_t, 3>> P, std::size_t n,
std::size_t nderiv,
stdex::mdspan<const T, stdex::dextents<std::size_t, 2>> x)
{
assert(x.extent(0) > 0);
assert(P.extent(0) == nderiv + 1);
assert(P.extent(1) == (n + 1) * (2 * n + 1) * (2 * n + 3) / 3);
assert(P.extent(2) == x.extent(0));

auto x0 = stdex::submdspan(x, stdex::full_extent, 0);
auto x1 = stdex::submdspan(x, stdex::full_extent, 1);
auto x2 = stdex::submdspan(x, stdex::full_extent, 2);

std::fill(P.data_handle(), P.data_handle() + P.size(), 0.0);

if (n == 0)
{
for (std::size_t p = 0; p < P.extent(2); ++p)
P(idx(0, 0), 0, p) = std::sqrt(6);
}
else if (n == 1)
{
for (std::size_t p = 0; p < P.extent(2); ++p)
{
if (x0[p] + x1[p] + x2[p] < 0.5)
{
P(idx(0, 0), 0, p) = 21.908902300206645 - 43.81780460041329 * x2[p]
- 43.81780460041329 * x1[p]
- 43.81780460041329 * x0[p];
P(idx(0, 0), 4, p) = -5.855400437691199 + 11.710800875382398 * x2[p]
+ 11.710800875382398 * x1[p]
+ 35.1324026261472 * x0[p];
P(idx(0, 0), 5, p) = -3.1326068447244277 + 6.2652136894488555 * x2[p]
+ 25.75698961217863 * x1[p]
- 0.6961348543832062 * x0[p];
P(idx(0, 0), 6, p) = -4.079436335011508 + 32.853642355761124 * x2[p]
+ 3.359535805303594 * x1[p]
+ 4.581185189050355 * x0[p];
P(idx(0, 0), 7, p) = 1.6490105505038288 - 7.300270809207225 * x2[p]
- 8.666892660787566 * x1[p]
- 0.5229420350434975 * x0[p];
P(idx(0, 0), 8, p) = 3.365373344712382 - 10.492441445989503 * x2[p]
- 11.258215021433038 * x1[p]
- 11.903076979701279 * x0[p];
P(idx(0, 0), 9, p) = 0.8017837257372732 + 2.6726124191242437 * x2[p]
- 5.3452248382484875 * x1[p]
- 5.3452248382484875 * x0[p];
if (nderiv >= 1)
{
P(idx(0, 0, 1), 0, p) = -43.81780460041329;
P(idx(0, 0, 1), 4, p) = 11.710800875382398;
P(idx(0, 0, 1), 5, p) = 6.2652136894488555;
P(idx(0, 0, 1), 6, p) = 32.853642355761124;
P(idx(0, 0, 1), 7, p) = -7.300270809207225;
P(idx(0, 0, 1), 8, p) = -10.492441445989503;
P(idx(0, 0, 1), 9, p) = 2.6726124191242437;
P(idx(0, 1, 0), 0, p) = -43.81780460041329;
P(idx(0, 1, 0), 4, p) = 11.710800875382398;
P(idx(0, 1, 0), 5, p) = 25.75698961217863;
P(idx(0, 1, 0), 6, p) = 3.359535805303594;
P(idx(0, 1, 0), 7, p) = -8.666892660787566;
P(idx(0, 1, 0), 8, p) = -11.258215021433038;
P(idx(0, 1, 0), 9, p) = -5.3452248382484875;
P(idx(1, 0, 0), 0, p) = -43.81780460041329;
P(idx(1, 0, 0), 4, p) = 35.1324026261472;
P(idx(1, 0, 0), 5, p) = -0.6961348543832062;
P(idx(1, 0, 0), 6, p) = 4.581185189050355;
P(idx(1, 0, 0), 7, p) = -0.5229420350434975;
P(idx(1, 0, 0), 8, p) = -11.903076979701279;
P(idx(1, 0, 0), 9, p) = -5.3452248382484875;
}
}
else if (x0[p] > 0.5)
{
P(idx(0, 0), 1, p) = -21.908902300206645 + 43.81780460041329 * x0[p];
P(idx(0, 0), 4, p) = 29.277002188455995 - 23.421601750764797 * x2[p]
- 23.421601750764797 * x1[p]
- 35.1324026261472 * x0[p];
P(idx(0, 0), 5, p) = -8.701685679790078 + 6.961348543832062 * x2[p]
+ 6.961348543832062 * x1[p]
+ 10.442022815748093 * x0[p];
P(idx(0, 0), 6, p) = -4.472109351215823 + 3.5776874809726587 * x2[p]
+ 3.5776874809726587 * x1[p]
+ 5.366531221458988 * x0[p];
P(idx(0, 0), 7, p) = 3.4688488324552 - 2.77507906596416 * x2[p]
- 2.77507906596416 * x1[p]
- 4.16261859894624 * x0[p];
P(idx(0, 0), 8, p) = -1.148660363165304 + 26.439340288997876 * x2[p]
+ 5.172330290276515 * x1[p]
- 2.8750095639459072 * x0[p];
P(idx(0, 0), 9, p) = 0.8017837257372732 + 29.398736610366683 * x1[p]
- 5.3452248382484875 * x0[p];
if (nderiv >= 1)
{
P(idx(0, 0, 1), 4, p) = -23.421601750764797;
P(idx(0, 0, 1), 5, p) = 6.961348543832062;
P(idx(0, 0, 1), 6, p) = 3.5776874809726587;
P(idx(0, 0, 1), 7, p) = -2.77507906596416;
P(idx(0, 0, 1), 8, p) = 26.439340288997876;
P(idx(0, 1, 0), 4, p) = -23.421601750764797;
P(idx(0, 1, 0), 5, p) = 6.961348543832062;
P(idx(0, 1, 0), 6, p) = 3.5776874809726587;
P(idx(0, 1, 0), 7, p) = -2.77507906596416;
P(idx(0, 1, 0), 8, p) = 5.172330290276515;
P(idx(0, 1, 0), 9, p) = 29.398736610366683;
P(idx(1, 0, 0), 1, p) = 43.81780460041329;
P(idx(1, 0, 0), 4, p) = -35.1324026261472;
P(idx(1, 0, 0), 5, p) = 10.442022815748093;
P(idx(1, 0, 0), 6, p) = 5.366531221458988;
P(idx(1, 0, 0), 7, p) = -4.16261859894624;
P(idx(1, 0, 0), 8, p) = -2.8750095639459072;
P(idx(1, 0, 0), 9, p) = -5.3452248382484875;
}
}
else if (x1[p] > 0.5)
{
P(idx(0, 0), 2, p) = -21.908902300206645 + 43.81780460041329 * x1[p];
P(idx(0, 0), 5, p) = 24.36471990341222 - 19.491775922729772 * x2[p]
- 29.237663884094662 * x1[p]
- 19.491775922729772 * x0[p];
P(idx(0, 0), 6, p) = -5.999171080899275 + 4.79933686471942 * x2[p]
+ 7.199005297079131 * x1[p]
+ 4.79933686471942 * x0[p];
P(idx(0, 0), 7, p) = -0.4985380734081343 + 30.219077065046907 * x2[p]
- 4.371795412963639 * x1[p]
+ 5.368871559779907 * x0[p];
P(idx(0, 0), 8, p) = -6.952417987579472 - 0.6448619582682409 * x2[p]
+ 9.377367643150668 * x1[p]
+ 4.527468332008274 * x0[p];
P(idx(0, 0), 9, p) = 0.8017837257372732 - 5.3452248382484875 * x1[p]
+ 29.398736610366683 * x0[p];
if (nderiv >= 1)
{
P(idx(0, 0, 1), 5, p) = -19.491775922729772;
P(idx(0, 0, 1), 6, p) = 4.79933686471942;
P(idx(0, 0, 1), 7, p) = 30.219077065046907;
P(idx(0, 0, 1), 8, p) = -0.6448619582682409;
P(idx(0, 1, 0), 2, p) = 43.81780460041329;
P(idx(0, 1, 0), 5, p) = -29.237663884094662;
P(idx(0, 1, 0), 6, p) = 7.199005297079131;
P(idx(0, 1, 0), 7, p) = -4.371795412963639;
P(idx(0, 1, 0), 8, p) = 9.377367643150668;
P(idx(0, 1, 0), 9, p) = -5.3452248382484875;
P(idx(1, 0, 0), 5, p) = -19.491775922729772;
P(idx(1, 0, 0), 6, p) = 4.79933686471942;
P(idx(1, 0, 0), 7, p) = 5.368871559779907;
P(idx(1, 0, 0), 8, p) = 4.527468332008274;
P(idx(1, 0, 0), 9, p) = 29.398736610366683;
}
}
else if (x2[p] > 0.5)
{
P(idx(0, 0), 3, p) = -21.908902300206645 + 43.81780460041329 * x2[p];
P(idx(0, 0), 6, p) = 30.868462107172636 - 37.04215452860716 * x2[p]
- 24.69476968573811 * x1[p]
- 24.69476968573811 * x0[p];
P(idx(0, 0), 7, p) = 1.209739241067291 - 6.421728190334149 * x2[p]
+ 28.85245521346657 * x1[p]
+ 4.002249708199567 * x0[p];
P(idx(0, 0), 8, p) = -0.6784485185947118 - 2.4047977193753147 * x2[p]
- 1.4106355337117769 * x1[p]
+ 25.0287047552861 * x0[p];
P(idx(0, 0), 9, p) = 3.474396144861517 - 2.6726124191242437 * x2[p]
- 8.017837257372731 * x1[p]
- 8.017837257372731 * x0[p];
if (nderiv >= 1)
{
P(idx(0, 0, 1), 3, p) = 43.81780460041329;
P(idx(0, 0, 1), 6, p) = -37.04215452860716;
P(idx(0, 0, 1), 7, p) = -6.421728190334149;
P(idx(0, 0, 1), 8, p) = -2.4047977193753147;
P(idx(0, 0, 1), 9, p) = -2.6726124191242437;
P(idx(0, 1, 0), 6, p) = -24.69476968573811;
P(idx(0, 1, 0), 7, p) = 28.85245521346657;
P(idx(0, 1, 0), 8, p) = -1.4106355337117769;
P(idx(0, 1, 0), 9, p) = -8.017837257372731;
P(idx(1, 0, 0), 6, p) = -24.69476968573811;
P(idx(1, 0, 0), 7, p) = 4.002249708199567;
P(idx(1, 0, 0), 8, p) = 25.0287047552861;
P(idx(1, 0, 0), 9, p) = -8.017837257372731;
}
}
else if (x1[p] + x2[p] < 0.5 && x0[p] + x1[p] < 0.5)
{
P(idx(0, 0), 4, p) = 11.710800875382398 - 23.421601750764797 * x2[p]
- 23.421601750764797 * x1[p];
P(idx(0, 0), 5, p) = -3.480674271916031 + 6.961348543832062 * x2[p]
+ 26.453124466561835 * x1[p];
P(idx(0, 0), 6, p) = 10.558541102382724 + 3.5776874809726587 * x2[p]
- 25.91641906948487 * x1[p]
- 24.69476968573811 * x0[p];
P(idx(0, 0), 7, p) = -0.6135853211177037 - 2.77507906596416 * x2[p]
- 4.1417009175445 * x1[p]
+ 4.002249708199567 * x0[p];
P(idx(0, 0), 8, p) = -15.100517522781306 + 26.439340288997876 * x2[p]
+ 25.67356671355434 * x1[p]
+ 25.0287047552861 * x0[p];
P(idx(0, 0), 9, p) = 2.138089935299395 - 8.017837257372731 * x1[p]
- 8.017837257372731 * x0[p];
if (nderiv >= 1)
{
P(idx(0, 0, 1), 4, p) = -23.421601750764797;
P(idx(0, 0, 1), 5, p) = 6.961348543832062;
P(idx(0, 0, 1), 6, p) = 3.5776874809726587;
P(idx(0, 0, 1), 7, p) = -2.77507906596416;
P(idx(0, 0, 1), 8, p) = 26.439340288997876;
P(idx(0, 1, 0), 4, p) = -23.421601750764797;
P(idx(0, 1, 0), 5, p) = 26.453124466561835;
P(idx(0, 1, 0), 6, p) = -25.91641906948487;
P(idx(0, 1, 0), 7, p) = -4.1417009175445;
P(idx(0, 1, 0), 8, p) = 25.67356671355434;
P(idx(0, 1, 0), 9, p) = -8.017837257372731;
P(idx(1, 0, 0), 6, p) = -24.69476968573811;
P(idx(1, 0, 0), 7, p) = 4.002249708199567;
P(idx(1, 0, 0), 8, p) = 25.0287047552861;
P(idx(1, 0, 0), 9, p) = -8.017837257372731;
}
}
else if (x1[p] + x2[p] < 0.5)
{
P(idx(0, 0), 4, p) = 11.710800875382398 - 23.421601750764797 * x2[p]
- 23.421601750764797 * x1[p];
P(idx(0, 0), 5, p) = 6.2652136894488555 + 6.961348543832062 * x2[p]
+ 6.961348543832062 * x1[p]
- 19.491775922729772 * x0[p];
P(idx(0, 0), 6, p) = -4.18851217284604 + 3.5776874809726587 * x2[p]
+ 3.5776874809726587 * x1[p]
+ 4.79933686471942 * x0[p];
P(idx(0, 0), 7, p) = -1.2968962469078738 - 2.77507906596416 * x2[p]
- 2.77507906596416 * x1[p]
+ 5.368871559779907 * x0[p];
P(idx(0, 0), 8, p) = -4.849899311142394 + 26.439340288997876 * x2[p]
+ 5.172330290276515 * x1[p]
+ 4.527468332008274 * x0[p];
P(idx(0, 0), 9, p) = -16.57019699857031 + 29.398736610366683 * x1[p]
+ 29.398736610366683 * x0[p];
if (nderiv >= 1)
{
P(idx(0, 0, 1), 4, p) = -23.421601750764797;
P(idx(0, 0, 1), 5, p) = 6.961348543832062;
P(idx(0, 0, 1), 6, p) = 3.5776874809726587;
P(idx(0, 0, 1), 7, p) = -2.77507906596416;
P(idx(0, 0, 1), 8, p) = 26.439340288997876;
P(idx(0, 1, 0), 4, p) = -23.421601750764797;
P(idx(0, 1, 0), 5, p) = 6.961348543832062;
P(idx(0, 1, 0), 6, p) = 3.5776874809726587;
P(idx(0, 1, 0), 7, p) = -2.77507906596416;
P(idx(0, 1, 0), 8, p) = 5.172330290276515;
P(idx(0, 1, 0), 9, p) = 29.398736610366683;
P(idx(1, 0, 0), 5, p) = -19.491775922729772;
P(idx(1, 0, 0), 6, p) = 4.79933686471942;
P(idx(1, 0, 0), 7, p) = 5.368871559779907;
P(idx(1, 0, 0), 8, p) = 4.527468332008274;
P(idx(1, 0, 0), 9, p) = 29.398736610366683;
}
}
else if (x0[p] + x1[p] > 0.5)
{
P(idx(0, 0), 5, p) = 19.491775922729772 - 19.491775922729772 * x2[p]
- 19.491775922729772 * x1[p]
- 19.491775922729772 * x0[p];
P(idx(0, 0), 6, p) = -4.79933686471942 + 4.79933686471942 * x2[p]
+ 4.79933686471942 * x1[p]
+ 4.79933686471942 * x0[p];
P(idx(0, 0), 7, p) = -17.793974312413408 + 30.219077065046907 * x2[p]
+ 30.219077065046907 * x1[p]
+ 5.368871559779907 * x0[p];
P(idx(0, 0), 8, p) = 8.692201812490664 - 0.6448619582682409 * x2[p]
- 21.9118719569896 * x1[p]
+ 4.527468332008274 * x0[p];
P(idx(0, 0), 9, p) = -16.57019699857031 + 29.398736610366683 * x1[p]
+ 29.398736610366683 * x0[p];
if (nderiv >= 1)
{
P(idx(0, 0, 1), 5, p) = -19.491775922729772;
P(idx(0, 0, 1), 6, p) = 4.79933686471942;
P(idx(0, 0, 1), 7, p) = 30.219077065046907;
P(idx(0, 0, 1), 8, p) = -0.6448619582682409;
P(idx(0, 1, 0), 5, p) = -19.491775922729772;
P(idx(0, 1, 0), 6, p) = 4.79933686471942;
P(idx(0, 1, 0), 7, p) = 30.219077065046907;
P(idx(0, 1, 0), 8, p) = -21.9118719569896;
P(idx(0, 1, 0), 9, p) = 29.398736610366683;
P(idx(1, 0, 0), 5, p) = -19.491775922729772;
P(idx(1, 0, 0), 6, p) = 4.79933686471942;
P(idx(1, 0, 0), 7, p) = 5.368871559779907;
P(idx(1, 0, 0), 8, p) = 4.527468332008274;
P(idx(1, 0, 0), 9, p) = 29.398736610366683;
}
}
else
{
P(idx(0, 0), 5, p) = 9.745887961364886 - 19.491775922729772 * x2[p];
P(idx(0, 0), 6, p) = 9.947716410509344 + 4.79933686471942 * x2[p]
- 24.69476968573811 * x1[p]
- 24.69476968573811 * x0[p];
P(idx(0, 0), 7, p) = -17.110663386623237 + 30.219077065046907 * x2[p]
+ 28.85245521346657 * x1[p]
+ 4.002249708199567 * x0[p];
P(idx(0, 0), 8, p) = -1.5584163991482487 - 0.6448619582682409 * x2[p]
- 1.4106355337117769 * x1[p]
+ 25.0287047552861 * x0[p];
P(idx(0, 0), 9, p) = 2.138089935299395 - 8.017837257372731 * x1[p]
- 8.017837257372731 * x0[p];
if (nderiv >= 1)
{
P(idx(0, 0, 1), 5, p) = -19.491775922729772;
P(idx(0, 0, 1), 6, p) = 4.79933686471942;
P(idx(0, 0, 1), 7, p) = 30.219077065046907;
P(idx(0, 0, 1), 8, p) = -0.6448619582682409;
P(idx(0, 1, 0), 6, p) = -24.69476968573811;
P(idx(0, 1, 0), 7, p) = 28.85245521346657;
P(idx(0, 1, 0), 8, p) = -1.4106355337117769;
P(idx(0, 1, 0), 9, p) = -8.017837257372731;
P(idx(1, 0, 0), 6, p) = -24.69476968573811;
P(idx(1, 0, 0), 7, p) = 4.002249708199567;
P(idx(1, 0, 0), 8, p) = 25.0287047552861;
P(idx(1, 0, 0), 9, p) = -8.017837257372731;
}
}
}
}
else
{
throw std::runtime_error("Only degree 0 and 1 macro polysets are currently "
"implemented on a tetrahedron.");
}
}
//-----------------------------------------------------------------------------
/// Compute the complete set of derivatives from 0 to nderiv, for all
/// the piecewise polynomials up to order n on a hexahedron split into 4 by
/// splitting each edge into two parts
template <typename T>
Expand Down Expand Up @@ -2682,6 +3016,9 @@ void polyset::tabulate(
case cell::type::triangle:
tabulate_polyset_triangle_macroedge_derivs(P, d, n, x);
return;
case cell::type::tetrahedron:
tabulate_polyset_tetrahedron_macroedge_derivs(P, d, n, x);
return;
case cell::type::quadrilateral:
tabulate_polyset_quadrilateral_macroedge_derivs(P, d, n, x);
return;
Expand Down Expand Up @@ -2760,6 +3097,8 @@ int polyset::dim(cell::type celltype, polyset::type ptype, int d)
return 2 * d + 1;
case cell::type::triangle:
return (d + 1) * (2 * d + 1);
case cell::type::tetrahedron:
return (d + 1) * (2 * d + 1) * (2 * d + 3) / 3;
case cell::type::quadrilateral:
return (2 * d + 1) * (2 * d + 1);
case cell::type::hexahedron:
Expand Down
Loading