MFEM  v3.3
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, Lawrence Livermore National Security, LLC. Produced at
2 // the Lawrence Livermore National Laboratory. LLNL-CODE-443211. All Rights
3 // reserved. See file COPYRIGHT for details.
4 //
5 // This file is part of the MFEM library. For more information and source code
6 // availability see http://mfem.org.
7 //
8 // MFEM is free software; you can redistribute it and/or modify it under the
9 // terms of the GNU Lesser General Public License (as published by the Free
10 // Software Foundation) version 2.1 dated February 1999.
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
Logical size of the array.
Definition: array.hpp:109
void Recreate(const int n, const int *p)
Definition: sets.cpp:59
void AsTable(Table &t)
Definition: sets.cpp:107
void AddColumnsInRow(int r, int ncol)
Definition: table.hpp:72
void MakeI(int nrows)
Next 7 methods are used together with the default constructor.
Definition: table.cpp:74
T * GetData()
Returns the data.
Definition: array.hpp:91
int PickRandomElement()
Definition: sets.cpp:44
void AddConnections(int r, const int *c, int nc)
Definition: table.cpp:96
int operator==(IntegerSet &s)
Definition: sets.cpp:28
int Insert(IntegerSet &s)
Definition: sets.cpp:82
void Sort()
Sorts the array. This requires operator&lt; to be defined for T.
Definition: array.hpp:207
void mfem_error(const char *msg)
Definition: error.cpp:106
void SetSize(int nsize)
Change logical size of the array, keep existing entries.
Definition: array.hpp:349
void ShiftUpI()
Definition: table.cpp:107
A set of integers.
Definition: sets.hpp:23
void MakeJ()
Definition: table.cpp:84