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;
19
21classify(const bool all_nodes_active,
22 const bool all_nodes_inactive,
23 const Real active_fraction,
24 const Real lambda,
25 const bool mark_intercepted)
26{
27 const SBMUtils::ElementActivity activity{all_nodes_active, all_nodes_inactive, active_fraction};
28 const SBMUtils::ClassificationSubdomains subdomains{INSIDE, OUTSIDE, INTERCEPTED};
29 return SBMUtils::classifyPartialElement(activity, subdomains, mark_intercepted, lambda);
30}
31}
32
33// A fully active element is inside; a fully inactive element is outside. The downstream
34// inputs do not override these: neither mark_intercepted nor the lambda endpoints (which
35// otherwise force intercepted/outside/inside) change the result.
36TEST(ClassifyPartialElementTest, FullyInsideOrOutside)
37{
38 EXPECT_EQ(classify(true, false, 1.0, 0.5, true), INSIDE);
39 EXPECT_EQ(classify(true, false, 1.0, 0.0, false), INSIDE); // lambda 0 rejects a partial elem
40 EXPECT_EQ(classify(true, false, 1.0, 1.0, false), INSIDE);
41
42 EXPECT_EQ(classify(false, true, 0.0, 0.5, true), OUTSIDE);
43 EXPECT_EQ(classify(false, true, 0.0, 1.0, false), OUTSIDE); // lambda 1 accepts a partial elem
44 EXPECT_EQ(classify(false, true, 0.0, 0.0, false), OUTSIDE);
45}
46
47// A partial element with mark_intercepted gets the intercepted subdomain, ahead of
48// the lambda-threshold decision (checked here at both lambda extremes).
49TEST(ClassifyPartialElementTest, MarkIntercepted)
50{
51 EXPECT_EQ(classify(false, false, 0.5, 0.0, true), INTERCEPTED);
52 EXPECT_EQ(classify(false, false, 0.5, 1.0, true), INTERCEPTED);
53}
54
55// Without mark_intercepted, a partial element is resolved by the lambda threshold:
56// inactive fraction above lambda is outside, below is inside.
57TEST(ClassifyPartialElementTest, LambdaThreshold)
58{
59 EXPECT_EQ(classify(false, false, 0.2, 0.5, false), OUTSIDE); // inactive fraction 0.8 > 0.5
60 EXPECT_EQ(classify(false, false, 0.8, 0.5, false), INSIDE); // inactive fraction 0.2 < 0.5
61}
62
63// All nodes on one side does not force the fully-inside/outside result unless the
64// active fraction is exactly one/zero: an enclosed surface (all nodes active but a
65// partial interior fraction) still routes through the intercepted / lambda logic.
66TEST(ClassifyPartialElementTest, EnclosedSurfaceEndpoints)
67{
68 EXPECT_EQ(classify(true, false, 0.5, 0.5, false), INSIDE); // inactive fraction 0.5 not > 0.5
69 EXPECT_EQ(classify(true, false, 0.5, 0.3, false), OUTSIDE); // inactive fraction 0.5 > 0.3
70 EXPECT_EQ(classify(true, false, 0.5, 0.5, true), INTERCEPTED);
71}
72
73// isInactive endpoints: lambda zero rejects even a fully active element, lambda one
74// accepts even a fully inactive one, and in between it compares the inactive fraction.
75TEST(ClassifyPartialElementTest, IsInactive)
76{
77 EXPECT_TRUE(SBMUtils::isInactive(1.0, 0.0));
78 EXPECT_FALSE(SBMUtils::isInactive(0.0, 1.0));
79 EXPECT_TRUE(SBMUtils::isInactive(0.2, 0.5));
80 EXPECT_FALSE(SBMUtils::isInactive(0.8, 0.5));
81}
subdomain_id_type SubdomainID
TEST(ClassifyPartialElementTest, FullyInsideOrOutside)
bool isInactive(Real active_fraction, Real lambda)
Return whether a partial element is inactive, i.e.
Definition SBMUtils.C:51
SubdomainID classifyPartialElement(const ElementActivity &activity, const ClassificationSubdomains &subdomains, bool mark_intercepted, Real lambda)
Classify a (possibly partial) element into an inside/outside/intercepted subdomain.
Definition SBMUtils.C:62
The subdomain IDs a (possibly partial) element can be labeled with.
Definition SBMUtils.h:58
Measured activity state of a (possibly partial) element, used to classify it.
Definition SBMUtils.h:47