Alien  1.3.0
Developer documentation
Loading...
Searching...
No Matches
CompositeSpace.cc
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
19#include "CompositeSpace.h"
20
21#include <map>
22
23#include <arccore/base/FatalErrorException.h>
24#include <arccore/base/String.h>
25#include <arccore/base/TraceInfo.h>
26
27/*---------------------------------------------------------------------------*/
28/*---------------------------------------------------------------------------*/
29
30namespace Alien
31{
32
33using namespace Arccore;
34
35/*---------------------------------------------------------------------------*/
36/*---------------------------------------------------------------------------*/
37
38namespace CompositeKernel
39{
40
41 /*---------------------------------------------------------------------------*/
42 /*---------------------------------------------------------------------------*/
43
44 // Structure interne étant partagée
46 {
47 String m_name;
48
49 // Mapping label -> indices des champs
50 std::map<String, UniqueArray<Integer>> m_fields;
51 // Pour accès direct
52 UniqueArray<String> m_labels;
53
54 UniqueArray<std::shared_ptr<ISpace>> m_sub_spaces;
55 };
56
57 /*---------------------------------------------------------------------------*/
58 /*---------------------------------------------------------------------------*/
59
61 : m_internal(new Space::Internal())
62 {}
63
64 /*---------------------------------------------------------------------------*/
65
66 Space::Space(const Space& space)
67 : ISpace()
68 , m_internal(space.m_internal)
69 {}
70
71 /*---------------------------------------------------------------------------*/
72
73 Space::Space(Space&& space)
74 : m_internal(space.m_internal)
75 {}
76
77 /*---------------------------------------------------------------------------*/
78
79 Space& Space::operator=(const Space& src)
80 {
81 m_internal = src.m_internal;
82 return *this;
83 }
84
85 /*---------------------------------------------------------------------------*/
86
87 Space& Space::operator=(Space&& src)
88 {
89 m_internal = src.m_internal;
90 return *this;
91 }
92
93 /*---------------------------------------------------------------------------*/
94
95 Integer Space::size() const
96 {
97 if (subSpaceSize() == 0)
98 return 0;
99 Integer size = 0;
100 for (auto& s : m_internal->m_sub_spaces)
101 size += s->size();
102 return size;
103 }
104
105 /*---------------------------------------------------------------------------*/
106
107 bool Space::operator==(const ISpace& space) const
108 {
109 return size() == space.size() && space.name().empty();
110 }
111
112 /*---------------------------------------------------------------------------*/
113
114 bool Space::operator!=(const ISpace& space) const { return not operator==(space); }
115
116 /*---------------------------------------------------------------------------*/
117
118 const String& Space::name() const { return m_internal->m_name; }
119
120 /*---------------------------------------------------------------------------*/
121
122 void Space::setField(String label, const UniqueArray<Integer>& indices)
123 {
124 auto& fields = m_internal->m_fields;
125 if (fields.find(label) != fields.end())
126 throw Alien::FatalErrorException(A_FUNCINFO, "Field already defined");
127 fields[label] = indices;
128 m_internal->m_labels.add(label);
129 }
130
131 /*---------------------------------------------------------------------------*/
132
133 Integer Space::nbField() const { return m_internal->m_fields.size(); }
134
135 /*---------------------------------------------------------------------------*/
136
137 const UniqueArray<Integer>& Space::field(String label) const
138 {
139 auto& fields = m_internal->m_fields;
140 auto field = fields.find(label);
141 if (field == fields.end())
142 throw Alien::FatalErrorException(A_FUNCINFO, "Field not defined");
143 return field->second;
144 }
145
146 /*---------------------------------------------------------------------------*/
147
148 const UniqueArray<Integer>& Space::field(Integer i) const
149 {
150 return field(m_internal->m_labels[i]);
151 }
152
153 /*---------------------------------------------------------------------------*/
154
155 String Space::fieldLabel(Integer i) const { return m_internal->m_labels[i]; }
156
157 /*---------------------------------------------------------------------------*/
158
159 std::shared_ptr<ISpace> Space::clone() const { return std::make_shared<Space>(*this); }
160
161 /*---------------------------------------------------------------------------*/
162
163 void Space::resizeSubSpace(Integer size)
164 {
165 m_internal->m_sub_spaces.resize(size);
166 for (auto& s : m_internal->m_sub_spaces)
167 s.reset(new Space());
168 }
169
170 /*---------------------------------------------------------------------------*/
171
172 std::shared_ptr<ISpace>& Space::operator[](Integer i)
173 {
174 ALIEN_ASSERT(i < subSpaceSize(), "Bound error");
175 return m_internal->m_sub_spaces[i];
176 }
177
178 /*---------------------------------------------------------------------------*/
179
180 const std::shared_ptr<ISpace>& Space::operator[](Integer i) const
181 {
182 ALIEN_ASSERT(i < subSpaceSize(), "Bound error");
183 return m_internal->m_sub_spaces[i];
184 }
185
186 /*---------------------------------------------------------------------------*/
187
188 Integer Space::subSpaceSize() const { return m_internal->m_sub_spaces.size(); }
189
190 /*---------------------------------------------------------------------------*/
191 /*---------------------------------------------------------------------------*/
192
193} // namespace CompositeKernel
194
195/*---------------------------------------------------------------------------*/
196/*---------------------------------------------------------------------------*/
197
198} // namespace Alien
199
200/*---------------------------------------------------------------------------*/
201/*---------------------------------------------------------------------------*/
bool operator==(const ISpace &space) const
Comparison operator.
const String & name() const
Get space name.
bool operator!=(const ISpace &space) const
Comparison operator.
Integer size() const
Get space size.
std::shared_ptr< ISpace > clone() const
Clone this object.
Integer nbField() const
Get the number of fields.
Interface for algebraic space objects.
Definition ISpace.h:44
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
Implementation of an algebraic space.
Definition Space.h:47
Space()
Constructor.
Definition Space.cc:149
const Arccore::UniqueArray< Arccore::Integer > & field(Arccore::Integer i) const
Get indices associated to the i-th field \para[in] i The requested field.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Definition BackEnd.h:17