MFEM v4.7.0 Finite element discretization library
Searching...
No Matches
sets.hpp
Go to the documentation of this file.
1// Copyright (c) 2010-2024, Lawrence Livermore National Security, LLC. Produced
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
24{
25private:
26 Array<int> me;
27
28public:
29 /// Create an empty set.
31
32 /// Create a copy of set 's'.
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 size of the set.
39 int Size() { return me.Size(); }
40
41 /// Return a reference to the sorted array of all the set entries.
42 operator Array<int>& () { return me; }
43
44 /// Return the value of the lowest element of the set.
45 int PickElement() { return me[0]; }
46
47 /// Return the value of a random element of the set.
49
50 /// Create a copy of set 's'.
52
53 /// Return 1 if the sets are equal and 0 otherwise.
55
56 /** @brief Create an integer set from C-array 'p' of 'n' integers.
57 Overwrites any existing set data. */
58 void Recreate(const int n, const int *p);
59};
60
61/// List of integer sets
63{
64private:
65 Array<IntegerSet *> TheList;
66
67public:
68
69 /// Return the number of integer sets in the list.
70 int Size() { return TheList.Size(); }
71
72 /// Return the value of the first element of the ith set.
73 int PickElementInSet(int i) { return TheList[i]->PickElement(); }
74
75 /// Return a random value from the ith set in the list.
76 int PickRandomElementInSet(int i) { return TheList[i]->PickRandomElement(); }
77
78 /** @brief Check to see if set 's' is in the list. If not append it to the
79 end of the list. Returns the index of the list where set 's' can be
80 found. */
81 int Insert(IntegerSet &s);
82
83 /** Return the index of the list where set 's' can be found. Returns -1 if
85 int Lookup(IntegerSet &s);
86
87 /// Write the list of sets into table 't'.
88 void AsTable(Table &t);
89
91};
92
93}
94
95#endif
int Size() const
Return the logical size of the array.
Definition array.hpp:144
A set of integers.
Definition sets.hpp:24
int operator==(IntegerSet &s)
Return 1 if the sets are equal and 0 otherwise.
Definition sets.cpp:37
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:68
int PickRandomElement()
Return the value of a random element of the set.
Definition sets.cpp:53
IntegerSet(const int n, const int *p)
Create an integer set from C-array 'p' of 'n' integers.
Definition sets.hpp:36
int Size()
Return the size of the set.
Definition sets.hpp:39
IntegerSet & operator=(const IntegerSet &s)
Create a copy of set 's'.
Definition sets.cpp:27
IntegerSet()
Create an empty set.
Definition sets.hpp:30
int PickElement()
Return the value of the lowest element of the set.
Definition sets.hpp:45
List of integer sets.
Definition sets.hpp:63
int Size()
Return the number of integer sets in the list.
Definition sets.hpp:70
int Insert(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:91
void AsTable(Table &t)
Write the list of sets into table 't'.
Definition sets.cpp:116
int Lookup(IntegerSet &s)
Definition sets.cpp:104
int PickElementInSet(int i)
Return the value of the first element of the ith set.
Definition sets.hpp:73
int PickRandomElementInSet(int i)
Return a random value from the ith set in the list.
Definition sets.hpp:76
real_t p(const Vector &x, real_t t)
RefCoord t[3]
RefCoord s[3]