MFEM v4.7.0
Finite element discretization library
Loading...
Searching...
No Matches
attribute_sets.hpp
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#ifndef MFEM_ATTRIBUTE_SETS
13#define MFEM_ATTRIBUTE_SETS
14
15#include "../config/config.hpp"
17
18#include <iostream>
19#include <map>
20#include <set>
21#include <string>
22
23namespace mfem
24{
25
27{
28private:
29 const Array<int> & attributes;
30
31 const int def_width = 10;
32
33public:
34 /// Named sets of attributes
36
37 AttributeSets(const Array<int> &attr);
38
39 /// @brief Create a copy of the internal data to the provided @a copy.
40 void Copy(AttributeSets &copy) const;
41
42 /// @brief Return true if any named sets are currently defined
43 bool SetsExist() const;
44
45 /// @brief Return all attribute set names as an STL set
46 std::set<std::string> GetAttributeSetNames() const;
47
48 /// @brief Return true is the named attribute set is present
49 bool AttributeSetExists(const std::string &name) const;
50
51 /// @brief Create an empty named attribute set
52 Array<int> & CreateAttributeSet(const std::string &set_name);
53
54 /// @brief Delete a named attribute set
55 void DeleteAttributeSet(const std::string &set_name);
56
57 /// @brief Create a new attribute set
58 /**
59 @param[in] set_name The name of the new set
60 @param[in] attr An array of attribute numbers making up the new set
61
62 @note If an attribute set matching this name already exists, that set
63 will be replaced with this new attribute set.
64
65 @note The attribute numbers are not checked for validity or
66 existence within the mesh.
67 */
68 void SetAttributeSet(const std::string &set_name, const Array<int> &attr);
69
70 /// @brief Add a single entry to an existing attribute set
71 /**
72 @param[in] set_name The name of the set being augmented
73 @param[in] attr A single attribute number to be inserted in the set
74
75 @note If the named set does not exist an error message will be printed
76 and execution will halt. `AttributeSetExists()` may be used to verify
77 existence of a named set.
78 @note Duplicate entries will be ignored and the resulting sets will be
79 sorted.
80 */
81 void AddToAttributeSet(const std::string &set_name, int attr);
82
83 /// @brief Add an array of entries to an existing attribute set
84 /**
85 @param[in] set_name The name of the set being augmented
86 @param[in] attr Array of attribute numbers to be inserted in the set
87
88 @note If the named set does not exist an error message will be printed
89 and execution will halt. `AttributeSetExists()` may be used to verify
90 existence of a named set.
91 @note Duplicate entries will be ignored and the resulting sets will be
92 sorted.
93 */
94 void AddToAttributeSet(const std::string &set_name, const Array<int> &attr);
95
96 /// @brief Remove a single entry from an existing attribute set
97 /**
98 @param[in] set_name The name of the set being modified
99 @param[in] attr A single attribute number to be removed from the set
100
101 @note If the named set does not exist an error message will be printed
102 and execution will halt. `AttributeSetExists()` may be used to verify
103 existence of a named set.
104 @note If @a attr is not a member of the named set the set will not
105 be modified and no error will occur.
106 */
107 void RemoveFromAttributeSet(const std::string &set_name, int attr);
108
109 /// @brief Print the contents of the container to an output stream
110 ///
111 /// @note The array entries will contain 10 entries per line. A specific
112 /// number of entries per line can be used by changing the @a width argument.
113 void Print(std::ostream &out = mfem::out, int width = -1) const;
114
115 /// @brief Access a named attribute set
116 /**
117 @param[in] set_name The name of the set being accessed
118
119 @note If the named set does not exist an error message will be printed
120 and execution will halt. `AttributeSetExists()` may be used to verify
121 existence of a named set.
122
123 @note The reference returned by this method can be invalidated by
124 subsequent calls to SetAttributeSet, ClearAttributeSet, or
125 RemoveFromAttributeSet. AddToAttributeSet should not invalidate this
126 reference.
127 */
128 Array<int> & GetAttributeSet(const std::string & set_name);
129
130 /// @brief Return a marker array corresponding to a named attribute set
131 /**
132 @param[in] set_name The name of the set being accessed
133
134 @note If the named set does not exist an error message will be printed
135 and execution will halt. `AttributeSetExists()` may be used to verify
136 existence of a named set.
137 */
138 Array<int> GetAttributeSetMarker(const std::string & set_name);
139
140 /// @brief Prepares a marker array corresponding to an array of element
141 /// attributes
142 /**
143 @param[in] max_attr Number of entries to create in the @a marker array
144 @param[in] attrs An array of attribute numbers which should be
145 activated
146
147 The returned marker array will be of size @a max_attr and it will contain
148 only zeroes and ones. Ones indicate which attribute numbers are present
149 in the @a attrs array.
150 */
151 static Array<int> AttrToMarker(int max_attr, const Array<int> &attrs);
152};
153
154} // namespace mfem
155
156#endif
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 out(std::cout)
Global stream used by the library for standard output. Initially it uses the same std::streambuf as s...
Definition globals.hpp:66