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 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
|
// Copyright (c) 2020 Chris Richardson
// FEniCS Project
// SPDX-License-Identifier: MIT
#include "cell.h"
#include "lagrange.h"
#include "quadrature.h"
#include <iostream>
#include <map>
using namespace basix;
//-----------------------------------------------------------------------------
Eigen::ArrayXXd cell::geometry(cell::type celltype)
{
Eigen::ArrayXXd geom;
switch (celltype)
{
case cell::type::interval:
geom.resize(2, 1);
geom << 0.0, 1.0;
break;
case cell::type::triangle:
geom.resize(3, 2);
geom << 0.0, 0.0, 1.0, 0.0, 0.0, 1.0;
break;
case cell::type::quadrilateral:
geom.resize(4, 2);
geom << 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0;
break;
case cell::type::tetrahedron:
geom.resize(4, 3);
geom << 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0;
break;
case cell::type::prism:
geom.resize(6, 3);
geom << 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 1.0,
0.0, 1.0, 0.0, 1.0, 1.0;
break;
case cell::type::pyramid:
geom.resize(5, 3);
geom << 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 0.0,
0.0, 1.0;
break;
case cell::type::hexahedron:
geom.resize(8, 3);
geom << 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 0.0,
0.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0;
break;
default:
throw std::runtime_error("Unsupported cell type");
}
return geom;
}
//-----------------------------------------------------------------------------
std::vector<std::vector<std::vector<int>>> cell::topology(cell::type celltype)
{
std::vector<std::vector<std::vector<int>>> topo;
switch (celltype)
{
case cell::type::interval:
topo.resize(2);
// Vertices
topo[0] = {{0}, {1}};
// Cell
topo[1] = {{0, 1}};
break;
case cell::type::triangle:
topo.resize(3);
// Vertices
topo[0] = {{0}, {1}, {2}};
// Edges
topo[1] = {{1, 2}, {0, 2}, {0, 1}};
// Cell
topo[2] = {{0, 1, 2}};
break;
case cell::type::quadrilateral:
topo.resize(3);
// FIXME - check all these
// Vertices
topo[0] = {{0}, {1}, {2}, {3}};
// Edges
topo[1] = {{0, 1}, {0, 2}, {1, 3}, {2, 3}};
// Cell
topo[2] = {{0, 1, 2, 3}};
break;
case cell::type::tetrahedron:
topo.resize(4);
// Vertices
topo[0] = {{0}, {1}, {2}, {3}};
// Edges
topo[1] = {{2, 3}, {1, 3}, {1, 2}, {0, 3}, {0, 2}, {0, 1}};
// Faces
topo[2] = {{1, 2, 3}, {0, 2, 3}, {0, 1, 3}, {0, 1, 2}};
// Cell
topo[3] = {{0, 1, 2, 3}};
break;
case cell::type::prism:
// FIXME: check
topo.resize(4);
// Vertices
topo[0] = {{0}, {1}, {2}, {3}, {4}, {5}};
// Edges
topo[1] = {{0, 1}, {1, 2}, {2, 0}, {0, 3}, {1, 4},
{2, 5}, {3, 4}, {4, 5}, {5, 3}};
// Faces
topo[2] = {{0, 1, 2}, {0, 1, 3, 4}, {1, 2, 4, 5}, {2, 0, 5, 3}, {3, 4, 5}};
// Cell
topo[3] = {{0, 1, 2, 3, 4, 5}};
break;
case cell::type::pyramid:
// FIXME: check all these
topo.resize(4);
// Vertices
topo[0] = {{0}, {1}, {2}, {3}, {4}};
// Edges
topo[1] = {{0, 1}, {0, 2}, {2, 3}, {3, 1}, {0, 4}, {1, 4}, {2, 4}, {3, 4}};
// Faces
topo[2] = {{0, 1, 2, 3}, {0, 1, 4}, {0, 2, 4}, {2, 3, 4}, {3, 1, 4}};
// Cell
topo[3] = {{0, 1, 2, 3, 4}};
break;
case cell::type::hexahedron:
topo.resize(4);
// FIXME: check over
// Vertices
topo[0] = {{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}};
// Edges
topo[1] = {{0, 1}, {0, 2}, {0, 4}, {1, 3}, {1, 5}, {2, 3},
{2, 6}, {3, 7}, {4, 5}, {4, 6}, {5, 7}, {6, 7}};
// Faces
topo[2] = {{0, 1, 2, 3}, {0, 1, 4, 5}, {0, 2, 4, 6},
{1, 3, 5, 7}, {2, 3, 6, 7}, {4, 5, 6, 7}};
// Cell
topo[3] = {{0, 1, 2, 3, 4, 5, 6, 7}};
break;
default:
throw std::runtime_error("Unsupported cell type");
}
return topo;
}
//-----------------------------------------------------------------------------
int cell::topological_dimension(cell::type cell_type)
{
switch (cell_type)
{
case cell::type::interval:
return 1;
case cell::type::triangle:
return 2;
case cell::type::quadrilateral:
return 2;
case cell::type::tetrahedron:
return 3;
case cell::type::hexahedron:
return 3;
case cell::type::prism:
return 3;
case cell::type::pyramid:
return 3;
default:
throw std::runtime_error("Unsupported cell type");
}
return 0;
}
//-----------------------------------------------------------------------------
Eigen::ArrayXXd cell::sub_entity_geometry(cell::type celltype, int dim,
int index)
{
std::vector<std::vector<std::vector<int>>> cell_topology
= cell::topology(celltype);
Eigen::ArrayXXd cell_geometry = cell::geometry(celltype);
if (dim < 0 or dim >= (int)cell_topology.size())
throw std::runtime_error("Invalid dimension for sub-entity");
const std::vector<std::vector<int>>& t = cell_topology[dim];
if (index < 0 or index >= (int)t.size())
throw std::runtime_error("Invalid entity index");
Eigen::ArrayXXd sub_entity(t[index].size(), cell_geometry.cols());
for (int i = 0; i < sub_entity.rows(); ++i)
sub_entity.row(i) = cell_geometry.row(t[index][i]);
return sub_entity;
}
//----------------------------------------------------------------------------
int cell::sub_entity_count(cell::type celltype, int dim)
{
const std::vector<std::vector<std::vector<int>>> cell_topology
= cell::topology(celltype);
return cell_topology.at(dim).size();
}
//----------------------------------------------------------------------------
cell::type cell::sub_entity_type(cell::type celltype, int dim, int index)
{
const int tdim = cell::topological_dimension(celltype);
assert(dim >= 0 and dim <= tdim);
if (dim == 0)
return cell::type::point;
else if (dim == 1)
return cell::type::interval;
else if (dim == tdim)
return celltype;
const std::vector<std::vector<std::vector<int>>> t = cell::topology(celltype);
const std::vector<int>& entity = t[dim][index];
switch (entity.size())
{
case 3:
return cell::type::triangle;
case 4:
return cell::type::quadrilateral;
default:
throw std::runtime_error("Error in sub_entity_type");
}
}
//-----------------------------------------------------------------------------
cell::type cell::str_to_type(std::string name)
{
static const std::map<std::string, cell::type> name_to_type
= {{"point", cell::type::point},
{"interval", cell::type::interval},
{"triangle", cell::type::triangle},
{"tetrahedron", cell::type::tetrahedron},
{"quadrilateral", cell::type::quadrilateral},
{"pyramid", cell::type::pyramid},
{"prism", cell::type::prism},
{"hexahedron", cell::type::hexahedron}};
auto it = name_to_type.find(name);
if (it == name_to_type.end())
throw std::runtime_error("Can't find name " + name);
return it->second;
}
//-----------------------------------------------------------------------------
const std::string& cell::type_to_str(cell::type type)
{
static const std::map<cell::type, std::string> type_to_name
= {{cell::type::point, "point"},
{cell::type::interval, "interval"},
{cell::type::triangle, "triangle"},
{cell::type::tetrahedron, "tetrahedron"},
{cell::type::quadrilateral, "quadrilateral"},
{cell::type::pyramid, "pyramid"},
{cell::type::prism, "prism"},
{cell::type::hexahedron, "hexahedron"}};
auto it = type_to_name.find(type);
if (it == type_to_name.end())
throw std::runtime_error("Can't find type");
return it->second;
}
|