MFEM v4.8.0
Finite element discretization library
Loading...
Searching...
No Matches
sets.hpp
Go to the documentation of this file.
1// Copyright (c) 2010-2025, Lawrence Livermore National Security, LLC. Produced
2// at the Lawrence Livermore National Laboratory. All Rights reserved. See files
3// LICENSE and NOTICE for details. LLNL-CODE-806117.
4//
5// This file is part of the MFEM library. For more information and source code
6// availability visit https://mfem.org.
7//
8// MFEM is free software; you can redistribute it and/or modify it under the
9// terms of the BSD-3 license. We welcome feedback and contributions, see file
10// CONTRIBUTING.md for details.
11
12#ifndef MFEM_SETS
13#define MFEM_SETS
14
15#include "../config/config.hpp"
16#include "array.hpp"
17#include "table.hpp"
18
19namespace mfem
20{
21
22/// A set of integers
23class IntegerSet : public Array<int>
24{
25public:
26 using Array<int>::Array; ///< Inherit all Array constructors.
27 // MSVC fails to recognize that rule of zero applies after using base class
28 // constructors.
29 IntegerSet() = default; ///< Default construct and empty set.
30 IntegerSet(const IntegerSet &) = default; ///< Copy constructor.
31 IntegerSet(IntegerSet &&) = default; ///< Move constructor.
32 IntegerSet& operator=(const IntegerSet &) = default; ///< Copy assignment.
33 IntegerSet& operator=(IntegerSet &&) = default; ///< Move assignment.
34
35 /// Create an integer set from C-array 'p' of 'n' integers.
36 IntegerSet(const int n, const int *p) { Recreate(n, p); }
37
38 /// Return the value of the lowest element of the set.
39 int PickElement() const { return data[0]; }
40
41 /// Return the value of a random element of the set.
42 int PickRandomElement() const;
43
44 /** @brief Create an integer set from C-array 'p' of 'n' integers.
45 Overwrites any existing set data. */
46 void Recreate(const int n, const int *p);
47};
48
49/// List of integer sets
51{
52private:
53 Array<IntegerSet *> TheList;
54
55public:
56
57 /// Return the number of integer sets in the list.
58 int Size() const { return TheList.Size(); }
59
60 /// Return the value of the first element of the ith set.
61 int PickElementInSet(int i) const { return TheList[i]->PickElement(); }
62
63 /// Return a random value from the ith set in the list.
64 int PickRandomElementInSet(int i) const { return TheList[i]->PickRandomElement(); }
65
66 /** @brief Check to see if set 's' is in the list. If not append it to the
67 end of the list. Returns the index of the list where set 's' can be
68 found. */
69 int Insert(const IntegerSet &s);
70
71 /** Return the index of the list where set 's' can be found. Returns -1 if
72 not found. */
73 int Lookup(const IntegerSet &s) const;
74
75 /// Write the list of sets into table 't'.
76 void AsTable(Table &t) const;
77
79};
80
81}
82
83#endif
int Size() const
Return the logical size of the array.
Definition array.hpp:147
Memory< int > data
Definition array.hpp:50
A set of integers.
Definition sets.hpp:24
int PickRandomElement() const
Return the value of a random element of the set.
Definition sets.cpp:18
IntegerSet & operator=(const IntegerSet &)=default
Copy assignment.
void Recreate(const int n, const int *p)
Create an integer set from C-array 'p' of 'n' integers. Overwrites any existing set data.
Definition sets.cpp:33
IntegerSet(const IntegerSet &)=default
Copy constructor.
IntegerSet(const int n, const int *p)
Create an integer set from C-array 'p' of 'n' integers.
Definition sets.hpp:36
IntegerSet()=default
< Inherit all Array constructors.
IntegerSet(IntegerSet &&)=default
Move constructor.
IntegerSet & operator=(IntegerSet &&)=default
Move assignment.
int PickElement() const
Return the value of the lowest element of the set.
Definition sets.hpp:39
List of integer sets.
Definition sets.hpp:51
int Insert(const IntegerSet &s)
Check to see if set 's' is in the list. If not append it to the end of the list. Returns the index of...
Definition sets.cpp:56
int PickRandomElementInSet(int i) const
Return a random value from the ith set in the list.
Definition sets.hpp:64
void AsTable(Table &t) const
Write the list of sets into table 't'.
Definition sets.cpp:81
int PickElementInSet(int i) const
Return the value of the first element of the ith set.
Definition sets.hpp:61
int Lookup(const IntegerSet &s) const
Definition sets.cpp:69
int Size() const
Return the number of integer sets in the list.
Definition sets.hpp:58
real_t p(const Vector &x, real_t t)