MFEM  v3.0
 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.googlecode.com.
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  me[i] = s.me[i];
23 }
24 
25 
27 {
28  if (me.Size() != s.me.Size())
29  return 0;
30 
31  for (int i = 0; i < me.Size(); i++)
32  if (me[i] != s.me[i])
33  return 0;
34 
35  return 1;
36 }
37 
39 {
40  int i, size = me.Size();
41  unsigned int seed = 0;
42 
43  for (i = 0; i < size; i++)
44  seed += me[i];
45 
46  srand(seed);
47 
48  return me[rand()/(RAND_MAX/size)];
49 }
50 
51 void IntegerSet::Recreate(const int n, const int *p)
52 {
53  int i, j;
54 
55  me.SetSize(n);
56 
57  for (i = 0; i < n; i++)
58  me[i] = p[i];
59 
60  me.Sort();
61 
62  for (j = 0, i = 1; i < n; i++)
63  if (me[i] != me[j])
64  me[++j] = me[i];
65 
66  me.SetSize(j+1);
67 }
68 
69 
71 {
72  for (int i = 0; i < TheList.Size(); i++)
73  if (*TheList[i] == s)
74  return i;
75 
76  TheList.Append(new IntegerSet(s));
77 
78  return TheList.Size()-1;
79 }
80 
82 {
83  for (int i = 0; i < TheList.Size(); i++)
84  if (*TheList[i] == s)
85  return i;
86 
87  mfem_error("ListOfIntegerSets::Lookup ()");
88  return -1;
89 }
90 
92 {
93  int i;
94 
95  t.MakeI(Size());
96 
97  for (i = 0; i < Size(); i++)
98  t.AddColumnsInRow(i, TheList[i] -> Size());
99 
100  t.MakeJ();
101 
102  for (i = 0; i < Size(); i++)
103  {
104  Array<int> &row = *TheList[i];
105  t.AddConnections(i, row.GetData(), row.Size());
106  }
107 
108  t.ShiftUpI();
109 }
110 
112 {
113  for (int i = 0; i < TheList.Size(); i++)
114  delete TheList[i];
115 }
116 
117 }
int Lookup(IntegerSet &s)
Definition: sets.cpp:81
int Size() const
Logical size of the array.
Definition: array.hpp:108
void Recreate(const int n, const int *p)
Definition: sets.cpp:51
void AsTable(Table &t)
Definition: sets.cpp:91
void AddColumnsInRow(int r, int ncol)
Definition: table.hpp:52
void MakeI(int nrows)
Next 7 methods are used together with the default constructor.
Definition: table.cpp:57
T * GetData()
Returns the data.
Definition: array.hpp:90
int PickRandomElement()
Definition: sets.cpp:38
void AddConnections(int r, const int *c, int nc)
Definition: table.cpp:75
int operator==(IntegerSet &s)
Definition: sets.cpp:26
int Insert(IntegerSet &s)
Definition: sets.cpp:70
void Sort()
Sorts the array.
Definition: array.cpp:112
void mfem_error(const char *msg)
Definition: error.cpp:23
void SetSize(int nsize)
Change logical size of the array, keep existing entries.
Definition: array.hpp:293
void ShiftUpI()
Definition: table.cpp:84
A set of integers.
Definition: sets.hpp:23
void MakeJ()
Definition: table.cpp:65