Alien  1.3.0
Developer documentation
Loading...
Searching...
No Matches
Space.cc
Go to the documentation of this file.
1/*
2 * Copyright 2020 IFPEN-CEA
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * SPDX-License-Identifier: Apache-2.0
17 */
18
23
24#include "Space.h"
25
26#include <map>
27
28#include <arccore/base/BaseTypes.h>
29#include <arccore/base/FatalErrorException.h>
30#include <arccore/base/String.h>
31
32#include <arccore/collections/Array.h>
33
34/*---------------------------------------------------------------------------*/
35/*---------------------------------------------------------------------------*/
36
37namespace Alien
38{
39
40using namespace Arccore;
41
42/*---------------------------------------------------------------------------*/
43/*---------------------------------------------------------------------------*/
44
48class Space::Internal final
49{
50 public:
56 Internal(Integer size, String name)
57 : m_size(size)
58 , m_name(name)
59 , m_fields()
60 , m_labels()
61 {}
62
67 Internal(Integer size)
68 : m_size(size)
69 , m_name()
70 , m_fields()
71 , m_labels()
72 {}
73
78 Integer size() const { return m_size; }
79
84 const String& name() const { return m_name; }
85
91 void setField(String label, const UniqueArray<Arccore::Integer>& indices)
92 {
93 if (m_fields.find(label) != m_fields.end())
94 throw Alien::FatalErrorException("Field already defined");
95 m_fields[label] = indices;
96 m_labels.add(label);
97 }
98
103 Integer nbField() const { return static_cast<Integer>(m_fields.size()); }
104
110 const UniqueArray<Arccore::Integer>& field(String label) const
111 {
112 auto field = m_fields.find(label);
113 if (field == m_fields.end())
114 throw Alien::FatalErrorException("Field not defined");
115 return field->second;
116 }
117
123 const UniqueArray<Arccore::Integer>& field(Integer i) const
124 {
125 return field(m_labels[i]);
126 }
127
133 String fieldLabel(Integer i) const { return m_labels[i]; }
134
135 private:
137 Integer m_size;
139 String m_name;
141 std::map<String, UniqueArray<Arccore::Integer>> m_fields;
143 UniqueArray<String> m_labels;
144};
145
146/*---------------------------------------------------------------------------*/
147/*---------------------------------------------------------------------------*/
148
150: Space(0)
151{}
152
153/*---------------------------------------------------------------------------*/
154/*---------------------------------------------------------------------------*/
155
156Space::Space(Integer size)
157: m_internal(new Internal(size))
158{}
159
160/*---------------------------------------------------------------------------*/
161/*---------------------------------------------------------------------------*/
162
163Space::Space(Integer size, String name)
164: m_internal(new Internal(size, name))
165{}
166
167/*---------------------------------------------------------------------------*/
168/*---------------------------------------------------------------------------*/
169
170Space::Space(const Space& space)
171: ISpace()
172, m_internal(space.m_internal)
173{}
174
175/*---------------------------------------------------------------------------*/
176/*---------------------------------------------------------------------------*/
177
179: m_internal(space.m_internal)
180{}
181
182/*---------------------------------------------------------------------------*/
183/*---------------------------------------------------------------------------*/
184
186
187/*---------------------------------------------------------------------------*/
188/*---------------------------------------------------------------------------*/
189
190Space&
192{
194 return *this;
195}
196
197/*---------------------------------------------------------------------------*/
198/*---------------------------------------------------------------------------*/
199
200Space&
202{
203 m_internal = src.m_internal;
204 return *this;
205}
206
207/*---------------------------------------------------------------------------*/
208/*---------------------------------------------------------------------------*/
209
210Integer
212{
213 return m_internal->size();
214}
215
216/*---------------------------------------------------------------------------*/
217/*---------------------------------------------------------------------------*/
218
219bool Space::operator==(const ISpace& space) const
220{
221 return (size() == space.size()) && ((name() == space.name()) || (name().empty() || space.name().empty()));
222}
223
224/*---------------------------------------------------------------------------*/
225/*---------------------------------------------------------------------------*/
226
227bool Space::operator!=(const ISpace& space) const
228{
229 return not operator==(space);
230}
231
232/*---------------------------------------------------------------------------*/
233/*---------------------------------------------------------------------------*/
234
235const String&
237{
238 return m_internal->name();
239}
240
241/*---------------------------------------------------------------------------*/
242/*---------------------------------------------------------------------------*/
243
244void Space::setField(String label, const UniqueArray<Arccore::Integer>& indices)
245{
246 m_internal->setField(label, indices);
247}
248
249/*---------------------------------------------------------------------------*/
250/*---------------------------------------------------------------------------*/
251
252Integer
254{
255 return m_internal->nbField();
256}
257
258/*---------------------------------------------------------------------------*/
259/*---------------------------------------------------------------------------*/
260
261const UniqueArray<Arccore::Integer>&
262Space::field(String label) const
263{
264 return m_internal->field(label);
265}
266
267/*---------------------------------------------------------------------------*/
268/*---------------------------------------------------------------------------*/
269
270const UniqueArray<Arccore::Integer>&
271Space::field(Integer i) const
272{
273 return m_internal->field(i);
274}
275
276/*---------------------------------------------------------------------------*/
277/*---------------------------------------------------------------------------*/
278
279String
280Space::fieldLabel(Integer i) const
281{
282 return m_internal->fieldLabel(i);
283}
284
285/*---------------------------------------------------------------------------*/
286/*---------------------------------------------------------------------------*/
287
288std::shared_ptr<ISpace>
290{
291 return std::make_shared<Space>(*this);
292}
293
294/*---------------------------------------------------------------------------*/
295/*---------------------------------------------------------------------------*/
296
297} // namespace Alien
298
299/*---------------------------------------------------------------------------*/
300/*---------------------------------------------------------------------------*/
Space.h.
virtual const Arccore::String & name() const =0
Get space name.
virtual Arccore::Integer size() const =0
Get space size.
ISpace()
Constructor.
Definition ISpace.h:47
Internal structure of Space object.
Definition Space.cc:49
String fieldLabel(Integer i) const
Get the label of the i-th field.
Definition Space.cc:133
std::map< String, UniqueArray< Arccore::Integer > > m_fields
Mapping label to indices.
Definition Space.cc:141
Integer nbField() const
Get the number of fields.
Definition Space.cc:103
const UniqueArray< Arccore::Integer > & field(String label) const
Get the indices associated to a label.
Definition Space.cc:110
Internal(Integer size)
Size constructor.
Definition Space.cc:67
const UniqueArray< Arccore::Integer > & field(Integer i) const
Get indices associated to the i-th field \para[in] i The requested field.
Definition Space.cc:123
const String & name() const
Get space name.
Definition Space.cc:84
Integer m_size
The size of the space.
Definition Space.cc:137
UniqueArray< String > m_labels
Direct acces for labels.
Definition Space.cc:143
Integer size() const
Get space size.
Definition Space.cc:78
void setField(String label, const UniqueArray< Arccore::Integer > &indices)
Set label on matrix entries.
Definition Space.cc:91
String m_name
The name of the space.
Definition Space.cc:139
Internal(Integer size, String name)
Full constructor.
Definition Space.cc:56
Implementation of an algebraic space.
Definition Space.h:47
Space & operator=(const Space &src)
Equal operator.
Definition Space.cc:191
Arccore::Integer nbField() const
Get the number of fields.
Definition Space.cc:253
Arccore::String fieldLabel(Arccore::Integer i) const
Get the label of the i-th field.
const Arccore::String & name() const
Get space name.
Definition Space.cc:236
Arccore::Integer size() const
Get space size.
Definition Space.cc:211
void setField(Arccore::String label, const Arccore::UniqueArray< Arccore::Integer > &indices)
Set label on matrix entries.
Space()
Constructor.
Definition Space.cc:149
std::shared_ptr< Internal > m_internal
Internal implementation of a space.
Definition Space.h:164
const Arccore::UniqueArray< Arccore::Integer > & field(Arccore::Integer i) const
Get indices associated to the i-th field \para[in] i The requested field.
std::shared_ptr< ISpace > clone() const
Clone this object.
Definition Space.cc:289
bool operator!=(const ISpace &space) const
Comparison operator.
Definition Space.cc:227
~Space()
Free resources.
Definition Space.cc:185
bool operator==(const ISpace &space) const
Comparison operator.
Definition Space.cc:219
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Definition BackEnd.h:17