MFEM v4.8.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-2025, 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
15namespace mfem
16{
17
19{
20 int i, size = Size();
21 unsigned int seed = 0;
22
23 for (i = 0; i < size; i++)
24 {
25 seed += data[i];
26 }
27
28 srand(seed);
29
30 return data[rand()/(RAND_MAX/size)];
31}
32
33void IntegerSet::Recreate(const int n, const int *p)
34{
35 int i, j;
36
37 SetSize(n);
38
39 for (i = 0; i < n; i++)
40 {
41 data[i] = p[i];
42 }
43
44 Sort();
45
46 for (j = 0, i = 1; i < n; i++)
47 if (data[i] != data[j])
48 {
49 data[++j] = data[i];
50 }
51
52 SetSize(j+1);
53}
54
55
57{
58 for (int i = 0; i < TheList.Size(); i++)
59 if (*TheList[i] == s)
60 {
61 return i;
62 }
63
64 TheList.Append(new IntegerSet(s));
65
66 return TheList.Size()-1;
67}
68
70{
71 for (int i = 0; i < TheList.Size(); i++)
72 if (*TheList[i] == s)
73 {
74 return i;
75 }
76
77 mfem_error("ListOfIntegerSets::Lookup (), integer set not found.");
78 return -1;
79}
80
82{
83 int i;
84
85 t.MakeI(Size());
86
87 for (i = 0; i < Size(); i++)
88 {
89 t.AddColumnsInRow(i, TheList[i] -> Size());
90 }
91
92 t.MakeJ();
93
94 for (i = 0; i < Size(); i++)
95 {
96 Array<int> &row = *TheList[i];
97 t.AddConnections(i, row.GetData(), row.Size());
98 }
99
100 t.ShiftUpI();
101}
102
104{
105 for (int i = 0; i < TheList.Size(); i++)
106 {
107 delete TheList[i];
108 }
109}
110
111}
void SetSize(int nsize)
Definition array.hpp:758
int Size() const
Definition array.hpp:147
Memory< int > data
Definition array.hpp:50
T * GetData()
Returns the data.
Definition array.hpp:121
A set of integers.
Definition sets.hpp:24
int PickRandomElement() const
Return the value of a random element of the set.
Definition sets.cpp:18
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:33
int Insert(const 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:56
void AsTable(Table &t) const
Write the list of sets into table 't'.
Definition sets.cpp:81
int Lookup(const IntegerSet &s) const
Definition sets.cpp:69
int Size() const
Return the number of integer sets in the list.
Definition sets.hpp:58
void AddConnections(int r, const int *c, int nc)
Definition table.cpp:176
void ShiftUpI()
Definition table.cpp:187
void MakeI(int nrows)
Next 7 methods are used together with the default constructor.
Definition table.cpp:153
void AddColumnsInRow(int r, int ncol)
Definition table.hpp:86
void MakeJ()
Definition table.cpp:163
void mfem_error(const char *msg)
Definition error.cpp:154
real_t p(const Vector &x, real_t t)