https://mooseframework.inl.gov
Loading...
Searching...
No Matches
ActiveElementFractionTest.C
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
3//*
4//* All rights reserved, see COPYRIGHT for full restrictions
5//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6//*
7//* Licensed under LGPL 2.1, please see LICENSE for details
8//* https://www.gnu.org/licenses/lgpl-2.1.html
9
10#include "gtest/gtest.h"
11
12#include "SBMUtils.h"
13
14#include "libmesh/serial_mesh.h"
15#include "libmesh/face_quad4.h"
16#include "libmesh/enum_order.h"
17
18// activeElementFraction integrates a predicate over the element with quadrature and returns the
19// active fraction of the total measure. On the unit square, a symmetric Gauss rule splits an
20// x < 0.5 half-space predicate exactly in two, and the all/none predicates give the exact
21// endpoints one/zero.
22TEST(ActiveElementFractionTest, UnitSquare)
23{
24 Parallel::Communicator comm(MPI_COMM_SELF);
25 auto mesh = std::make_unique<libMesh::SerialMesh>(comm);
26
27 Node * n0 = mesh->add_point(Point(0.0, 0.0, 0.0), 0);
28 Node * n1 = mesh->add_point(Point(1.0, 0.0, 0.0), 1);
29 Node * n2 = mesh->add_point(Point(1.0, 1.0, 0.0), 2);
30 Node * n3 = mesh->add_point(Point(0.0, 1.0, 0.0), 3);
31
32 auto quad = new Quad4();
33 quad->set_node(0, n0);
34 quad->set_node(1, n1);
35 quad->set_node(2, n2);
36 quad->set_node(3, n3);
37 const Elem * elem = mesh->add_elem(quad);
38
39 mesh->prepare_for_use();
40
41 const auto all_active = [](const Point &) { return true; };
42 const auto none_active = [](const Point &) { return false; };
43 const auto left_half = [](const Point & p) { return p(0) < 0.5; };
44
45 // SECOND-order Gauss has 2 points per dimension, symmetric about the centre with none on it.
46 EXPECT_NEAR(SBMUtils::activeElementFraction(*elem, SECOND, all_active), 1.0, 1e-12);
47 EXPECT_NEAR(SBMUtils::activeElementFraction(*elem, SECOND, none_active), 0.0, 1e-12);
48 EXPECT_NEAR(SBMUtils::activeElementFraction(*elem, SECOND, left_half), 0.5, 1e-12);
49}
TEST(ActiveElementFractionTest, UnitSquare)
const Real p
MeshBase & mesh
Real activeElementFraction(const Elem &elem, Order qrule_order, const std::function< bool(const libMesh::Point &)> &is_active)
Compute the fraction of an element's quadrature-weighted measure satisfying a predicate.
Definition SBMUtils.C:26