MFEM  v4.5.2
Finite element discretization library
sets.cpp
Go to the documentation of this file.
1 // Copyright (c) 2010-2023, 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 #include "sets.hpp"
13 
14 
15 namespace mfem
16 {
17 
19  : me(s.me.Size())
20 {
21  for (int i = 0; i < me.Size(); i++)
22  {
23  me[i] = s.me[i];
24  }
25 }
26 
28 {
29  me.SetSize(s.me.Size());
30  for (int i = 0; i < me.Size(); i++)
31  {
32  me[i] = s.me[i];
33  }
34  return *this;
35 }
36 
38 {
39  if (me.Size() != s.me.Size())
40  {
41  return 0;
42  }
43 
44  for (int i = 0; i < me.Size(); i++)
45  if (me[i] != s.me[i])
46  {
47  return 0;
48  }
49 
50  return 1;
51 }
52 
54 {
55  int i, size = me.Size();
56  unsigned int seed = 0;
57 
58  for (i = 0; i < size; i++)
59  {
60  seed += me[i];
61  }
62 
63  srand(seed);
64 
65  return me[rand()/(RAND_MAX/size)];
66 }
67 
68 void IntegerSet::Recreate(const int n, const int *p)
69 {
70  int i, j;
71 
72  me.SetSize(n);
73 
74  for (i = 0; i < n; i++)
75  {
76  me[i] = p[i];
77  }
78 
79  me.Sort();
80 
81  for (j = 0, i = 1; i < n; i++)
82  if (me[i] != me[j])
83  {
84  me[++j] = me[i];
85  }
86 
87  me.SetSize(j+1);
88 }
89 
90 
92 {
93  for (int i = 0; i < TheList.Size(); i++)
94  if (*TheList[i] == s)
95  {
96  return i;
97  }
98 
99  TheList.Append(new IntegerSet(s));
100 
101  return TheList.Size()-1;
102 }
103 
105 {
106  for (int i = 0; i < TheList.Size(); i++)
107  if (*TheList[i] == s)
108  {
109  return i;
110  }
111 
112  mfem_error("ListOfIntegerSets::Lookup (), integer set not found.");
113  return -1;
114 }
115 
117 {
118  int i;
119 
120  t.MakeI(Size());
121 
122  for (i = 0; i < Size(); i++)
123  {
124  t.AddColumnsInRow(i, TheList[i] -> Size());
125  }
126 
127  t.MakeJ();
128 
129  for (i = 0; i < Size(); i++)
130  {
131  Array<int> &row = *TheList[i];
132  t.AddConnections(i, row.GetData(), row.Size());
133  }
134 
135  t.ShiftUpI();
136 }
137 
139 {
140  for (int i = 0; i < TheList.Size(); i++)
141  {
142  delete TheList[i];
143  }
144 }
145 
146 }
int Lookup(IntegerSet &s)
Definition: sets.cpp:104
void Recreate(const int n, const int *p)
Create an integer set from C-array &#39;p&#39; of &#39;n&#39; integers. Overwrites any existing set data...
Definition: sets.cpp:68
void AsTable(Table &t)
Write the list of sets into table &#39;t&#39;.
Definition: sets.cpp:116
T * GetData()
Returns the data.
Definition: array.hpp:115
int PickRandomElement()
Return the value of a random element of the set.
Definition: sets.cpp:53
int operator==(IntegerSet &s)
Return 1 if the sets are equal and 0 otherwise.
Definition: sets.cpp:37
void mfem_error(const char *msg)
Function called when an error is encountered. Used by the macros MFEM_ABORT, MFEM_ASSERT, MFEM_VERIFY.
Definition: error.cpp:154
int Insert(IntegerSet &s)
Check to see if set &#39;s&#39; is in the list. If not append it to the end of the list. Returns the index of...
Definition: sets.cpp:91
void Sort()
Sorts the array in ascending order. This requires operator< to be defined for T.
Definition: array.hpp:251
int Size()
Return the number of integer sets in the list.
Definition: sets.hpp:70
void SetSize(int nsize)
Change the logical size of the array, keep existing entries.
Definition: array.hpp:684
IntegerSet()
Create an empty set.
Definition: sets.hpp:30
IntegerSet & operator=(const IntegerSet &s)
Create a copy of set &#39;s&#39;.
Definition: sets.cpp:27
A set of integers.
Definition: sets.hpp:23
int Size() const
Return the logical size of the array.
Definition: array.hpp:141
RefCoord t[3]
RefCoord s[3]