19 product.resize(mat_A.rows() * mat_B.rows(), mat_A.cols() * mat_B.cols());
20 for (
unsigned int i = 0; i < mat_A.rows(); i++)
21 for (
unsigned int j = 0; j < mat_A.cols(); j++)
22 for (
unsigned int k = 0; k < mat_B.rows(); k++)
23 for (
unsigned int l = 0; l < mat_B.cols(); l++)
24 product(((i * mat_B.rows()) + k), ((j * mat_B.cols()) + l)) = mat_A(i, j) * mat_B(k, l);
28 plainLog(Real x,
unsigned int derivative_order)
30 switch (derivative_order)
39 return -1.0 / (x * x);
42 return 2.0 / (x * x * x);
45 mooseError(
"Unsupported derivative order ", derivative_order);
49 poly1Log(Real x, Real tol,
unsigned int derivative_order)
52 return plainLog(x, derivative_order);
54 const auto c1 = [&]() {
return 1.0 / tol; };
55 const auto c2 = [&]() {
return std::log(tol) - 1.0; };
57 switch (derivative_order)
60 return c1() * x + c2();
72 mooseError(
"Unsupported derivative order ", derivative_order);
76 poly2Log(Real x, Real tol,
unsigned int derivative_order)
79 return plainLog(x, derivative_order);
81 const auto c1 = [&]() {
return -0.5 / (tol * tol); };
82 const auto c2 = [&]() {
return 2.0 / tol; };
83 const auto c3 = [&]() {
return std::log(tol) - 3.0 / 2.0; };
85 switch (derivative_order)
88 return c1() * x * x + c2() * x + c3();
91 return 2.0 * c1() * x + c2();
100 mooseError(
"Unsupported derivative order ", derivative_order);
104 poly3Log(Real x, Real tol,
unsigned int derivative_order)
107 return plainLog(x, derivative_order);
109 const auto c1 = [&]() {
return 1.0 / (3.0 * tol * tol * tol); };
110 const auto c2 = [&]() {
return -3.0 / (2.0 * tol * tol); };
111 const auto c3 = [&]() {
return 3.0 / tol; };
112 const auto c4 = [&]() {
return std::log(tol) - 11.0 / 6.0; };
114 switch (derivative_order)
117 return c1() * x * x * x + c2() * x * x + c3() * x + c4();
120 return 3.0 * c1() * x * x + 2.0 * c2() * x + c3();
123 return 6.0 * c1() * x + 2.0 * c2();
129 mooseError(
"Unsupported derivative order ", derivative_order);
133 poly4Log(Real x, Real tol,
unsigned int derivative_order)
136 return plainLog(x, derivative_order);
138 switch (derivative_order)
141 return std::log(tol) + (x - tol) / tol -
143 Utility::pow<3>(x - tol) / (3.0 * Utility::pow<3>(tol)) -
144 Utility::pow<4>(x - tol) / (4.0 * Utility::pow<4>(tol)) +
145 Utility::pow<5>(x - tol) / (5.0 * Utility::pow<5>(tol)) -
146 Utility::pow<6>(x - tol) / (6.0 * Utility::pow<6>(tol));
151 Utility::pow<3>(x - tol) / Utility::pow<4>(tol) +
152 Utility::pow<4>(x - tol) / Utility::pow<5>(tol) -
153 Utility::pow<5>(x - tol) / Utility::pow<6>(tol);
156 return -1.0 /
Utility::pow<2>(tol) + 2.0 * (x - tol) / Utility::pow<3>(tol) -
158 4.0 * Utility::pow<3>(x - tol) / Utility::pow<5>(tol) -
159 5.0 * Utility::pow<4>(x - tol) / Utility::pow<6>(tol);
162 return 2.0 / Utility::pow<3>(tol) - 6.0 * (x - tol) / Utility::pow<4>(tol) +
164 20.0 * Utility::pow<3>(x - tol) / Utility::pow<6>(tol);
167 mooseError(
"Unsupported derivative order ", derivative_order);
174 Real y = (x - 1.0) / (x + 1.0);
176 for (
unsigned int i = 0; i < 5; ++i)
178 Real exponent = i + 2.0;
179 val += 1.0 / (2.0 * (i + 1.0) + 1.0) *
std::pow(y, exponent);
182 return val * 2.0 * y;
185 std::vector<std::vector<unsigned int>>
189 std::vector<std::vector<unsigned int>> multi_index;
190 std::vector<std::vector<unsigned int>> n_choose_k;
191 std::vector<unsigned int> row(
dim, 0);
192 multi_index.push_back(row);
195 for (
unsigned int q = 1; q <= order; q++)
198 multi_index.push_back(row);
201 for (
unsigned int q = 1; q <= order; q++)
204 for (
unsigned int r = 0; r < n_choose_k.size(); r++)
207 for (
unsigned int c = 1; c < n_choose_k[0].size(); c++)
208 row.push_back(n_choose_k[r][c] - n_choose_k[r][c - 1] - 1);
209 multi_index.push_back(row);
224 mooseAssert(!
MooseUtils::isZero(b0 + b1 + b2 - 1.0),
"Barycentric coordinates must sum to one!");
228 for (
unsigned int d = 0; d < 2; ++d)
229 center(d) = p0(d) * b0 + p1(d) * b1 + p2(d) * b2;
247 "Barycentric coordinates must sum to one!");
251 for (
unsigned int d = 0; d < 3; ++d)
252 center(d) = p0(d) * b0 + p1(d) * b1 + p2(d) * b2 + p3(d) * b3;
268 Real weight0 = edge12 * (edge01 + edge02 - edge12);
269 Real weight1 = edge02 * (edge01 + edge12 - edge02);
270 Real weight2 = edge01 * (edge02 + edge12 - edge01);
272 Real sum_weights = weight0 + weight1 + weight2;
276 mooseError(
"Cannot evaluate circumcenter. Points should be non-collinear.");
278 Real inv_sum_weights = 1.0 / sum_weights;
281 Real b0 = weight0 * inv_sum_weights;
282 Real b1 = weight1 * inv_sum_weights;
283 Real b2 = weight2 * inv_sum_weights;
289 circumcenter3D(
const Point & p0,
const Point & p1,
const Point & p2,
const Point & p3)
300 Real weight0 = -2 * edge12 * edge13 * edge23 + edge01 * edge23 * (edge13 + edge12 - edge23) +
301 edge02 * edge13 * (edge12 + edge23 - edge13) +
302 edge03 * edge12 * (edge13 + edge23 - edge12);
303 Real weight1 = -2 * edge02 * edge03 * edge23 + edge01 * edge23 * (edge02 + edge03 - edge23) +
304 edge13 * edge02 * (edge03 + edge23 - edge02) +
305 edge12 * edge03 * (edge02 + edge23 - edge03);
306 Real weight2 = -2 * edge01 * edge03 * edge13 + edge02 * edge13 * (edge01 + edge03 - edge13) +
307 edge23 * edge01 * (edge03 + edge13 - edge01) +
308 edge12 * edge03 * (edge01 + edge13 - edge03);
309 Real weight3 = -2 * edge01 * edge02 * edge12 + edge03 * edge12 * (edge01 + edge02 - edge12) +
310 edge23 * edge01 * (edge02 + edge12 - edge01) +
311 edge13 * edge02 * (edge01 + edge12 - edge02);
313 Real sum_weights = weight0 + weight1 + weight2 + weight3;
317 mooseError(
"Cannot evaluate circumcenter. Points should be non-coplanar.");
319 Real inv_sum_weights = 1.0 / sum_weights;
322 Real b0 = weight0 * inv_sum_weights;
323 Real b1 = weight1 * inv_sum_weights;
324 Real b2 = weight2 * inv_sum_weights;
325 Real b3 = weight3 * inv_sum_weights;
332 std::vector<std::vector<unsigned int>>
335 std::vector<std::vector<unsigned int>> n_choose_k;
336 std::vector<unsigned int> row;
337 std::string bitmask(K, 1);
338 bitmask.resize(
N, 0);
344 for (
unsigned int i = 0; i <
N; ++i)
346 row.push_back(i + 1);
347 row.push_back(
N + 1);
348 n_choose_k.push_back(row);
349 }
while (std::prev_permutation(bitmask.begin(), bitmask.end()));
Point circumcenter2D(const Point &p0, const Point &p1, const Point &p2)
Evaluate circumcenter of a triangle given three arbitrary points.
Point barycentricToCartesian2D(const Point &p0, const Point &p1, const Point &p2, const Real b0, const Real b1, const Real b2)
Evaluate Cartesian coordinates of any center point of a triangle given Barycentric coordinates of cen...
void kron(RealEigenMatrix &product, const RealEigenMatrix &mat_A, const RealEigenMatrix &mat_B)
Computes the Kronecker product of two matrices.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
bool isZero(const T &value, const Real tolerance=TOLERANCE *TOLERANCE *TOLERANCE)
Real poly1Log(Real x, Real tol, unsigned int derivative_order)
Real poly2Log(Real x, Real tol, unsigned int derivative_order)
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.
Point barycentricToCartesian3D(const Point &p0, const Point &p1, const Point &p2, const Point &p3, const Real b0, const Real b1, const Real b2, const Real b3)
Evaluate Cartesian coordinates of any center point of a tetrahedron given Barycentric coordinates of ...
Real plainLog(Real x, unsigned int derivative_order)
Eigen::Matrix< Real, Eigen::Dynamic, Eigen::Dynamic > RealEigenMatrix
Real poly3Log(Real x, Real tol, unsigned int derivative_order)
Point circumcenter3D(const Point &p0, const Point &p1, const Point &p2, const Point &p3)
Evaluate circumcenter of a tetrahedrom given four arbitrary points.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
std::vector< std::vector< unsigned int > > multiIndex(unsigned int dim, unsigned int order)
generate a complete multi index table for given dimension and order i.e.
std::vector< std::vector< unsigned int > > multiIndexHelper(unsigned int N, unsigned int K)
A helper function for MathUtils::multiIndex.
Real poly4Log(Real x, Real tol, unsigned int derivative_order)
MooseUnits pow(const MooseUnits &, int)
CTSub CT_OPERATOR_BINARY CTMul CTCompareLess CTCompareGreater CTCompareEqual _arg template pow< 2 >(tan(_arg))+1.0) *_arg.template D< dtag >()) CT_SIMPLE_UNARY_FUNCTION(sqrt