MFEM  v4.2.0
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
sets.cpp
Go to the documentation of this file.
1 // Copyright (c) 2010-2020, 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 
27 
29 {
30  if (me.Size() != s.me.Size())
31  {
32  return 0;
33  }
34 
35  for (int i = 0; i < me.Size(); i++)
36  if (me[i] != s.me[i])
37  {
38  return 0;
39  }
40 
41  return 1;
42 }
43 
45 {
46  int i, size = me.Size();
47  unsigned int seed = 0;
48 
49  for (i = 0; i < size; i++)
50  {
51  seed += me[i];
52  }
53 
54  srand(seed);
55 
56  return me[rand()/(RAND_MAX/size)];
57 }
58 
59 void IntegerSet::Recreate(const int n, const int *p)
60 {
61  int i, j;
62 
63  me.SetSize(n);
64 
65  for (i = 0; i < n; i++)
66  {
67  me[i] = p[i];
68  }
69 
70  me.Sort();
71 
72  for (j = 0, i = 1; i < n; i++)
73  if (me[i] != me[j])
74  {
75  me[++j] = me[i];
76  }
77 
78  me.SetSize(j+1);
79 }
80 
81 
83 {
84  for (int i = 0; i < TheList.Size(); i++)
85  if (*TheList[i] == s)
86  {
87  return i;
88  }
89 
90  TheList.Append(new IntegerSet(s));
91 
92  return TheList.Size()-1;
93 }
94 
96 {
97  for (int i = 0; i < TheList.Size(); i++)
98  if (*TheList[i] == s)
99  {
100  return i;
101  }
102 
103  mfem_error("ListOfIntegerSets::Lookup (), integer set not found.");
104  return -1;
105 }
106 
108 {
109  int i;
110 
111  t.MakeI(Size());
112 
113  for (i = 0; i < Size(); i++)
114  {
115  t.AddColumnsInRow(i, TheList[i] -> Size());
116  }
117 
118  t.MakeJ();
119 
120  for (i = 0; i < Size(); i++)
121  {
122  Array<int> &row = *TheList[i];
123  t.AddConnections(i, row.GetData(), row.Size());
124  }
125 
126  t.ShiftUpI();
127 }
128 
130 {
131  for (int i = 0; i < TheList.Size(); i++)
132  {
133  delete TheList[i];
134  }
135 }
136 
137 }
int Lookup(IntegerSet &s)
Definition: sets.cpp:95
int Size() const
Return the logical size of the array.
Definition: array.hpp:124
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:59
void AsTable(Table &t)
Write the list of sets into table &#39;t&#39;.
Definition: sets.cpp:107
void AddColumnsInRow(int r, int ncol)
Definition: table.hpp:78
void MakeI(int nrows)
Next 7 methods are used together with the default constructor.
Definition: table.cpp:85
T * GetData()
Returns the data.
Definition: array.hpp:98
int PickRandomElement()
Return the value of a random element of the set.
Definition: sets.cpp:44
void AddConnections(int r, const int *c, int nc)
Definition: table.cpp:108
int operator==(IntegerSet &s)
Return 1 if the sets are equal and 0 otherwise.
Definition: sets.cpp:28
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:153
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:82
void Sort()
Sorts the array in ascending order. This requires operator&lt; to be defined for T.
Definition: array.hpp:234
int Size()
Return the number of integer sets in the list.
Definition: sets.hpp:67
void SetSize(int nsize)
Change the logical size of the array, keep existing entries.
Definition: array.hpp:654
IntegerSet()
Create an empty set.
Definition: sets.hpp:30
void ShiftUpI()
Definition: table.cpp:119
A set of integers.
Definition: sets.hpp:23
void MakeJ()
Definition: table.cpp:95