https://mooseframework.inl.gov
Loading...
Searching...
No Matches
ClassifyPartialElementTest.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
14namespace
15{
16constexpr SubdomainID INSIDE = 1;
17constexpr SubdomainID OUTSIDE = 2;
18constexpr SubdomainID INTERCEPTED = 3;
19constexpr SBMUtils::InterceptedSubdomainPolicy MARK_INTERCEPTED{true, INTERCEPTED};
20constexpr SBMUtils::InterceptedSubdomainPolicy DO_NOT_MARK_INTERCEPTED{false, INTERCEPTED};
21
23classify(const bool all_nodes_in_domain,
24 const bool all_nodes_outside_domain,
25 const Real fraction_of_element_in_domain,
26 const Real lambda,
27 const bool mark_intercepted)
28{
30 all_nodes_in_domain, all_nodes_outside_domain, fraction_of_element_in_domain};
31 const SBMUtils::ClassificationSubdomains subdomain_id_settings{INSIDE, OUTSIDE, INTERCEPTED};
33 occupancy, subdomain_id_settings, mark_intercepted, lambda);
34}
35}
36
37// A fully active element is inside; a fully inactive element is outside. The downstream
38// inputs do not override these: neither mark_intercepted nor the lambda endpoints (which
39// otherwise force intercepted/outside/inside) change the result.
40TEST(ClassifySubdomainFromOccupancyTest, FullyInsideOrOutside)
41{
42 EXPECT_EQ(classify(true, false, 1.0, 0.5, true), INSIDE);
43 EXPECT_EQ(classify(true, false, 1.0, 0.0, false), INSIDE); // lambda 0 rejects a partial elem
44 EXPECT_EQ(classify(true, false, 1.0, 1.0, false), INSIDE);
45
46 EXPECT_EQ(classify(false, true, 0.0, 0.5, true), OUTSIDE);
47 EXPECT_EQ(classify(false, true, 0.0, 1.0, false), OUTSIDE); // lambda 1 accepts a partial elem
48 EXPECT_EQ(classify(false, true, 0.0, 0.0, false), OUTSIDE);
49}
50
51// A partial element with mark_intercepted gets the intercepted subdomain, ahead of
52// the lambda-threshold decision (checked here at both lambda extremes).
53TEST(ClassifySubdomainFromOccupancyTest, MarkIntercepted)
54{
55 EXPECT_EQ(classify(false, false, 0.5, 0.0, true), INTERCEPTED);
56 EXPECT_EQ(classify(false, false, 0.5, 1.0, true), INTERCEPTED);
57}
58
59// Without mark_intercepted, a partial element is resolved by the lambda threshold:
60// inactive fraction above lambda is outside, below is inside.
61TEST(ClassifySubdomainFromOccupancyTest, LambdaThreshold)
62{
63 EXPECT_EQ(classify(false, false, 0.2, 0.5, false), OUTSIDE); // inactive fraction 0.8 > 0.5
64 EXPECT_EQ(classify(false, false, 0.8, 0.5, false), INSIDE); // inactive fraction 0.2 < 0.5
65}
66
67// All nodes on one side does not force the fully-inside/outside result unless the
68// active fraction is exactly one/zero: an enclosed surface (all nodes active but a
69// partial interior fraction) still routes through the intercepted / lambda logic.
70TEST(ClassifySubdomainFromOccupancyTest, EnclosedSurfaceEndpoints)
71{
72 EXPECT_EQ(classify(true, false, 0.5, 0.5, false), INSIDE); // inactive fraction 0.5 not > 0.5
73 EXPECT_EQ(classify(true, false, 0.5, 0.3, false), OUTSIDE); // inactive fraction 0.5 > 0.3
74 EXPECT_EQ(classify(true, false, 0.5, 0.5, true), INTERCEPTED);
75}
76
77// isInactive endpoints: lambda zero rejects even a fully active element, lambda one
78// accepts even a fully inactive one, and in between it compares the inactive fraction.
79TEST(ClassifySubdomainFromOccupancyTest, IsInactive)
80{
81 EXPECT_TRUE(SBMUtils::isInactive(1.0, 0.0));
82 EXPECT_FALSE(SBMUtils::isInactive(0.0, 1.0));
83 EXPECT_TRUE(SBMUtils::isInactive(0.2, 0.5));
84 EXPECT_FALSE(SBMUtils::isInactive(0.8, 0.5));
85}
86
87TEST(SelectSubdomainFromOccupanciesTest, FullyOccupiedTakesPrecedence)
88{
89 const std::vector<SBMUtils::SubdomainOccupancy> candidates{
90 {4, {false, false, 0.9}}, {7, {true, false, 1.0}}, {3, {true, false, 1.0}}};
91
92 EXPECT_EQ(SBMUtils::selectSubdomainFromOccupancies(candidates, MARK_INTERCEPTED, 0.5), 3);
93}
94
95TEST(SelectSubdomainFromOccupanciesTest, PartialSelection)
96{
97 // This perturbation is small enough for absoluteFuzzyEqual, so the lower ID must win the tie.
98 const std::vector<SBMUtils::SubdomainOccupancy> candidates{
99 {7, {false, false, 0.8 + 1e-14}}, {3, {false, false, 0.8}}, {4, {false, false, 0.6}}};
100
101 EXPECT_EQ(SBMUtils::selectSubdomainFromOccupancies(candidates, DO_NOT_MARK_INTERCEPTED, 0.5), 3);
102 EXPECT_EQ(SBMUtils::selectSubdomainFromOccupancies(candidates, MARK_INTERCEPTED, 0.5),
103 INTERCEPTED);
104 EXPECT_FALSE(SBMUtils::selectSubdomainFromOccupancies(candidates, DO_NOT_MARK_INTERCEPTED, 0.0));
105 EXPECT_EQ(SBMUtils::selectSubdomainFromOccupancies(candidates, DO_NOT_MARK_INTERCEPTED, 1.0), 3);
106}
107
108TEST(SelectSubdomainFromOccupanciesTest, NoOccupiedCandidate)
109{
110 const std::vector<SBMUtils::SubdomainOccupancy> candidates{{3, {false, true, 0.0}},
111 {7, {false, true, 0.0}}};
112
113 EXPECT_FALSE(SBMUtils::selectSubdomainFromOccupancies(candidates, DO_NOT_MARK_INTERCEPTED, 0.5));
114 EXPECT_FALSE(SBMUtils::selectSubdomainFromOccupancies({}, MARK_INTERCEPTED, 0.5));
115}
subdomain_id_type SubdomainID
TEST(ClassifySubdomainFromOccupancyTest, FullyInsideOrOutside)
std::optional< SubdomainID > selectSubdomainFromOccupancies(const std::vector< SubdomainOccupancy > &candidate_occupancies, const InterceptedSubdomainPolicy &intercepted_policy, Real lambda)
Select a subdomain based on how multiple candidate domains occupy an element.
Definition SBMUtils.C:92
SubdomainID classifySubdomainFromOccupancy(const ElementDomainOccupancy &occupancy, const ClassificationSubdomains &subdomain_id_settings, bool mark_intercepted, Real lambda)
Classify an element from its retained-domain occupancy measurements.
Definition SBMUtils.C:138
bool isInactive(Real active_fraction, Real lambda)
Return whether a partial element is inactive, i.e.
Definition SBMUtils.C:81
The subdomain IDs a (possibly partial) element can be labeled with.
Definition SBMUtils.h:102
Results of testing an element against a domain.
Definition SBMUtils.h:45
Policy for assigning partial elements to a dedicated intercepted subdomain.
Definition SBMUtils.h:73