MFEM v4.7.0
Finite element discretization library
Loading...
Searching...
No Matches
attribute_sets.cpp
Go to the documentation of this file.
1// Copyright (c) 2010-2024, 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 "attribute_sets.hpp"
13
14namespace mfem
15{
16
18 : attributes(attr)
19{}
20
22{
23 copy.attr_sets = attr_sets;
24}
25
27{
28 return attr_sets.Size() > 0;
29}
30
31std::set<std::string> AttributeSets::GetAttributeSetNames() const
32{
33 return attr_sets.GetNames();
34}
35
36bool AttributeSets::AttributeSetExists(const std::string &name) const
37{
38 return attr_sets.EntryExists(name);
39}
40
41Array<int> & AttributeSets::CreateAttributeSet(const std::string &set_name)
42{
43 return attr_sets.CreateArray(set_name);
44}
45
46void AttributeSets::DeleteAttributeSet(const std::string &set_name)
47{
48 attr_sets.DeleteArray(set_name);
49}
50
51void AttributeSets::SetAttributeSet(const std::string &set_name,
52 const Array<int> &attr)
53{
54 if (!attr_sets.EntryExists(set_name))
55 {
56 attr_sets.CreateArray(set_name);
57 }
58 attr_sets[set_name] = attr;
59 attr_sets[set_name].Sort();
60 attr_sets[set_name].Unique();
61}
62
63void AttributeSets::AddToAttributeSet(const std::string &set_name, int attr)
64{
65 attr_sets[set_name].Append(attr);
66 attr_sets[set_name].Sort();
67 attr_sets[set_name].Unique();
68}
69
70void AttributeSets::AddToAttributeSet(const std::string &set_name,
71 const Array<int> &attr)
72{
73 attr_sets[set_name].Append(attr);
74 attr_sets[set_name].Sort();
75 attr_sets[set_name].Unique();
76}
77
78void AttributeSets::RemoveFromAttributeSet(const std::string &set_name,
79 int attr)
80{
81 if (!attr_sets.EntryExists(set_name))
82 {
83 mfem::err << "Unrecognized attribute set name \"" << set_name
84 << "\" in AttributeSets::RemoveFromAttributeSet" << std::endl;
85 }
86
87 Array<int> &attr_set = attr_sets[set_name];
88
89 attr_set.DeleteFirst(attr);
90}
91
92void AttributeSets::Print(std::ostream &os, int width) const
93{
94 attr_sets.Print(os, width > 0 ? width : def_width);
95}
96
97Array<int> & AttributeSets::GetAttributeSet(const std::string & set_name)
98{
99 return attr_sets[set_name];
100}
101
103{
104 return AttrToMarker(attributes.Max(), GetAttributeSet(set_name));
105}
106
108{
109 MFEM_ASSERT(attrs.Max() <= max_attr, "Invalid attribute number present.");
110
111 Array<int> marker(max_attr);
112 marker = 0;
113 for (auto const &attr : attrs)
114 {
115 MFEM_VERIFY(attr > 0, "Attribute number less than one!");
116 marker[attr-1] = 1;
117 }
118 return marker;
119}
120
121} // namespace mfem
void DeleteFirst(const T &el)
Delete the first entry with value == 'el'.
Definition array.hpp:847
T Max() const
Find the maximal element in the array, using the comparison operator < for class T.
Definition array.cpp:68
void Print(std::ostream &out=mfem::out, int width=-1) const
Print the contents of the container to an output stream.
std::set< std::string > GetNames() const
Return an STL set of strings giving the names of the arrays.
void DeleteArray(const std::string &name)
Delete the named array from the container.
int Size() const
Return the number of named arrays in the container.
bool EntryExists(const std::string &name) const
Return true if an array with the given name is present in the container.
Array< T > & CreateArray(const std::string &name)
Create a new empty array with the given name.
void SetAttributeSet(const std::string &set_name, const Array< int > &attr)
Create a new attribute set.
Array< int > GetAttributeSetMarker(const std::string &set_name)
Return a marker array corresponding to a named attribute set.
bool SetsExist() const
Return true if any named sets are currently defined.
bool AttributeSetExists(const std::string &name) const
Return true is the named attribute set is present.
void RemoveFromAttributeSet(const std::string &set_name, int attr)
Remove a single entry from an existing attribute set.
Array< int > & GetAttributeSet(const std::string &set_name)
Access a named attribute set.
static Array< int > AttrToMarker(int max_attr, const Array< int > &attrs)
Prepares a marker array corresponding to an array of element attributes.
void AddToAttributeSet(const std::string &set_name, int attr)
Add a single entry to an existing attribute set.
ArraysByName< int > attr_sets
Named sets of attributes.
Array< int > & CreateAttributeSet(const std::string &set_name)
Create an empty named attribute set.
std::set< std::string > GetAttributeSetNames() const
Return all attribute set names as an STL set.
AttributeSets(const Array< int > &attr)
void Print(std::ostream &out=mfem::out, int width=-1) const
Print the contents of the container to an output stream.
void DeleteAttributeSet(const std::string &set_name)
Delete a named attribute set.
void Copy(AttributeSets &copy) const
Create a copy of the internal data to the provided copy.
OutStream err(std::cerr)
Global stream used by the library for standard error output. Initially it uses the same std::streambu...
Definition globals.hpp:71