1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
|
// Copyright (c) 2020 Chris Richardson & Matthew Scroggs
// FEniCS Project
// SPDX-License-Identifier: MIT
#include "lagrange.h"
#include "dof-permutations.h"
#include "lattice.h"
#include "polyset.h"
#include <Eigen/Dense>
#include <iostream>
#include <numeric>
using namespace basix;
//----------------------------------------------------------------------------
FiniteElement basix::create_lagrange(cell::type celltype, int degree,
const std::string& name)
{
if (celltype == cell::type::point)
throw std::runtime_error("Invalid celltype");
const int ndofs = polyset::dim(celltype, degree);
const std::vector<std::vector<std::vector<int>>> topology
= cell::topology(celltype);
std::vector<std::vector<int>> entity_dofs(topology.size());
// Create points at nodes, ordered by topology (vertices first)
Eigen::ArrayXXd pt(ndofs, topology.size() - 1);
if (degree == 0)
{
pt = lattice::create(celltype, 0, lattice::type::equispaced, true);
for (std::size_t i = 0; i < entity_dofs.size(); ++i)
entity_dofs[i].resize(topology[i].size(), 0);
entity_dofs[topology.size() - 1][0] = 1;
}
else
{
int c = 0;
for (std::size_t dim = 0; dim < topology.size(); ++dim)
{
for (std::size_t i = 0; i < topology[dim].size(); ++i)
{
const Eigen::ArrayXXd entity_geom
= cell::sub_entity_geometry(celltype, dim, i);
if (dim == 0)
{
pt.row(c++) = entity_geom.row(0);
entity_dofs[0].push_back(1);
}
else if (dim == topology.size() - 1)
{
const Eigen::ArrayXXd lattice = lattice::create(
celltype, degree, lattice::type::equispaced, false);
for (int j = 0; j < lattice.rows(); ++j)
pt.row(c++) = lattice.row(j);
entity_dofs[dim].push_back(lattice.rows());
}
else
{
cell::type ct = cell::sub_entity_type(celltype, dim, i);
const Eigen::ArrayXXd lattice
= lattice::create(ct, degree, lattice::type::equispaced, false);
entity_dofs[dim].push_back(lattice.rows());
for (int j = 0; j < lattice.rows(); ++j)
{
pt.row(c) = entity_geom.row(0);
for (int k = 0; k < lattice.cols(); ++k)
{
pt.row(c) += (entity_geom.row(k + 1) - entity_geom.row(0))
* lattice(j, k);
}
++c;
}
}
}
}
}
int perm_count = 0;
for (std::size_t i = 1; i < topology.size() - 1; ++i)
perm_count += topology[i].size() * i;
std::vector<Eigen::MatrixXd> base_permutations(
perm_count, Eigen::MatrixXd::Identity(ndofs, ndofs));
if (celltype == cell::type::interval)
{
assert(perm_count == 0);
}
else if (celltype == cell::type::triangle)
{
Eigen::ArrayXi edge_ref = dofperms::interval_reflection(degree - 1);
for (int edge = 0; edge < 3; ++edge)
{
const int start = 3 + edge_ref.size() * edge;
for (int i = 0; i < edge_ref.size(); ++i)
{
base_permutations[edge](start + i, start + i) = 0;
base_permutations[edge](start + i, start + edge_ref[i]) = 1;
}
}
}
else if (celltype == cell::type::quadrilateral)
{
Eigen::ArrayXi edge_ref = dofperms::interval_reflection(degree - 1);
for (int edge = 0; edge < 4; ++edge)
{
const int start = 4 + edge_ref.size() * edge;
for (int i = 0; i < edge_ref.size(); ++i)
{
base_permutations[edge](start + i, start + i) = 0;
base_permutations[edge](start + i, start + edge_ref[i]) = 1;
}
}
}
else if (celltype == cell::type::tetrahedron)
{
Eigen::ArrayXi edge_ref = dofperms::interval_reflection(degree - 1);
for (int edge = 0; edge < 6; ++edge)
{
const int start = 4 + edge_ref.size() * edge;
for (int i = 0; i < edge_ref.size(); ++i)
{
base_permutations[edge](start + i, start + i) = 0;
base_permutations[edge](start + i, start + edge_ref[i]) = 1;
}
}
Eigen::ArrayXi face_ref = dofperms::triangle_reflection(degree - 2);
Eigen::ArrayXi face_rot = dofperms::triangle_rotation(degree - 2);
for (int face = 0; face < 4; ++face)
{
const int start = 4 + edge_ref.size() * 6 + face_ref.size() * face;
for (int i = 0; i < face_rot.size(); ++i)
{
base_permutations[6 + 2 * face](start + i, start + i) = 0;
base_permutations[6 + 2 * face](start + i, start + face_rot[i]) = 1;
base_permutations[6 + 2 * face + 1](start + i, start + i) = 0;
base_permutations[6 + 2 * face + 1](start + i, start + face_ref[i]) = 1;
}
}
}
else if (celltype == cell::type::hexahedron)
{
Eigen::ArrayXi edge_ref = dofperms::interval_reflection(degree - 1);
for (int edge = 0; edge < 12; ++edge)
{
const int start = 8 + edge_ref.size() * edge;
for (int i = 0; i < edge_ref.size(); ++i)
{
base_permutations[edge](start + i, start + i) = 0;
base_permutations[edge](start + i, start + edge_ref[i]) = 1;
}
}
Eigen::ArrayXi face_ref = dofperms::quadrilateral_reflection(degree - 1);
Eigen::ArrayXi face_rot = dofperms::quadrilateral_rotation(degree - 1);
for (int face = 0; face < 6; ++face)
{
const int start = 8 + edge_ref.size() * 12 + face_ref.size() * face;
for (int i = 0; i < face_rot.size(); ++i)
{
base_permutations[12 + 2 * face](start + i, start + i) = 0;
base_permutations[12 + 2 * face](start + i, start + face_rot[i]) = 1;
base_permutations[12 + 2 * face + 1](start + i, start + i) = 0;
base_permutations[12 + 2 * face + 1](start + i, start + face_ref[i])
= 1;
}
}
}
else
{
std::cout << "Base permutations not implemented for this cell type."
<< std::endl;
}
// Point evaluation of basis
Eigen::MatrixXd dualmat = polyset::tabulate(celltype, degree, 0, pt)[0];
Eigen::MatrixXd coeffs = compute_expansion_coefficients(
Eigen::MatrixXd::Identity(ndofs, ndofs), dualmat);
return FiniteElement(name, celltype, degree, {1}, coeffs, entity_dofs,
base_permutations, pt,
Eigen::MatrixXd::Identity(ndofs, ndofs));
}
//-----------------------------------------------------------------------------
FiniteElement basix::create_dlagrange(cell::type celltype, int degree,
const std::string& name)
{
// Only tabulate for scalar. Vector spaces can easily be built from
// the scalar space.
const int ndofs = polyset::dim(celltype, degree);
std::vector<std::vector<std::vector<int>>> topology
= cell::topology(celltype);
std::vector<std::vector<int>> entity_dofs(topology.size());
for (std::size_t i = 0; i < topology.size(); ++i)
entity_dofs[i].resize(topology[i].size(), 0);
entity_dofs[topology.size() - 1][0] = ndofs;
Eigen::ArrayXXd geometry = cell::geometry(celltype);
const Eigen::ArrayXXd pt
= lattice::create(celltype, degree, lattice::type::equispaced, true);
// Point evaluation of basis
Eigen::MatrixXd dualmat = polyset::tabulate(celltype, degree, 0, pt)[0];
Eigen::MatrixXd coeffs = compute_expansion_coefficients(
Eigen::MatrixXd::Identity(ndofs, ndofs), dualmat);
int perm_count = 0;
for (std::size_t i = 1; i < topology.size() - 1; ++i)
perm_count += topology[i].size() * i;
std::vector<Eigen::MatrixXd> base_permutations(
perm_count, Eigen::MatrixXd::Identity(ndofs, ndofs));
return FiniteElement(name, celltype, degree, {1}, coeffs, entity_dofs,
base_permutations, pt,
Eigen::MatrixXd::Identity(ndofs, ndofs));
}
//-----------------------------------------------------------------------------
|