Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
GeometryServiceBase.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7#include "arcane/geometry/impl/GeometryServiceBase.h"
8/* Author : havep at Thu Apr 3 09:09:09 2008
9 * Generated by createNew
10 */
11
12#include "arcane/core/IMesh.h"
13using namespace Arcane;
14
15#include "arcane/core/IItemOperationByBasicType.h"
16#include "arcane/core/IItemFamily.h"
17#include "arcane/core/ArcaneVersion.h"
18#include "arcane/core/ItemVectorView.h"
19
20#include <set>
21
22/*---------------------------------------------------------------------------*/
23/*---------------------------------------------------------------------------*/
24
25namespace Arcane::Numerics
26{
27
28/*---------------------------------------------------------------------------*/
29/*---------------------------------------------------------------------------*/
30
33{
34 m_suffix = String("By") + (unsigned long)(this);
35}
36
42
43/*---------------------------------------------------------------------------*/
44/*---------------------------------------------------------------------------*/
45
47addItemGroupProperty(ItemGroup group, Integer property, Integer storage)
48{
49 ItemGroupGeometryProperty& properties = m_group_property_map[group.internal()];
50 properties.defined |= property;
51 Integer current_property = 1;
52 while (property) {
53 if (property & current_property) {
54 properties.storages[static_cast<IGeometryProperty::eProperty>(current_property)].storageType |= storage;
55 traceMng()->debug() << "Add geometric property ["
56 << IGeometryProperty::name(static_cast<IGeometryProperty::eProperty>(current_property))
57 << "] on group " << group.name();
58 }
59 property &= ~current_property;
60 current_property <<= 1;
61 }
62}
63
65addItemGroupProperty(ItemGroup group, IGeometryProperty::eProperty property, RealVariable var)
66{
67 ARCANE_ASSERT((IGeometryProperty::isScalar(property)), ("Scalar property expected"));
68 ItemGroupGeometryProperty& properties = m_group_property_map[group.internal()];
69 ItemGroupGeometryProperty::StorageInfo& storage = properties.storages[property];
70 if (storage.realVar) {
71 if (storage.realVar->name() != var.name())
72 traceMng()->fatal() << "Geometric property [" << IGeometryProperty::name(property)
73 << "] storage already defined on group " << group.name()
74 << " with variable " << storage.realVar->name();
75 ARCANE_ASSERT((properties.defined & property), ("Unconsistent state with undefined property with defined variable"));
76 return;
77 }
78 properties.defined |= property;
79 storage.realVar.reset(new RealVariable(var));
80 storage.storageType |= IGeometryProperty::PVariable;
81 storage.externStorage |= IGeometryProperty::PVariable;
82 // #ifndef NO_USER_WARNING
83 // #warning "No longer allocate ItemGroupMap implicitly"
84 // #endif /* NO_USER_WARNING */
85 // storage.realMap.reset(new RealGroupMap(group));
86 // storage.storageType |= IGeometryProperty::PItemGroupMap;
87}
88
90addItemGroupProperty(ItemGroup group, IGeometryProperty::eProperty property, Real3Variable var)
91{
92 ARCANE_ASSERT((IGeometryProperty::isVectorial(property)), ("Vectorial property expected"));
93 ItemGroupGeometryProperty& properties = m_group_property_map[group.internal()];
94 ItemGroupGeometryProperty::StorageInfo& storage = properties.storages[property];
95 if (storage.real3Var) {
96 if (storage.real3Var->name() != var.name())
97 traceMng()->fatal() << "Geometric property [" << IGeometryProperty::name(property)
98 << "] storage already defined on group " << group.name()
99 << " with variable " << storage.real3Var->name();
100 ARCANE_ASSERT((properties.defined & property), ("Unconsistent state with undefined property with defined variable"));
101 return;
102 }
103 properties.defined |= property;
104 storage.real3Var.reset(new Real3Variable(var));
105 storage.storageType |= IGeometryProperty::PVariable;
106 storage.externStorage |= IGeometryProperty::PVariable;
107 // #ifndef NO_USER_WARNING
108 // #warning "No longer allocate ItemGroupMap implicitly"
109 // #endif /* NO_USER_WARNING */
110 // storage.real3Map.reset(new Real3GroupMap(group));
111 // storage.storageType |= IGeometryProperty::PItemGroupMap;
112}
113
117{
118 PropertyMap::const_iterator iprop = m_group_property_map.find(group.internal());
119 if (iprop == m_group_property_map.end())
120 return IGeometryProperty::PNone;
121 return iprop->second.defined;
122}
123
126{
127 return (getItemGroupProperty(group) & property) == property;
128}
129
132getItemGroupPropertyStorage(ItemGroup group, IGeometryProperty::eProperty property)
133{
134 PropertyMap::const_iterator iprop = m_group_property_map.find(group.internal());
135 if (iprop == m_group_property_map.end())
136 return IGeometryProperty::PNoStorage;
137 return iprop->second.getStorage(property);
138}
139
140/*---------------------------------------------------------------------------*/
141
142const IGeometryMng::RealVariable&
144getRealVariableProperty(ItemGroup group, IGeometryProperty::eProperty property)
145{
146 if (!IGeometryProperty::isScalar(property))
147 traceMng()->fatal() << "Non scalar property requested by scalar interface";
148 ItemGroupGeometryProperty::StorageInfo& storage = _checkItemGroupProperty(group.internal(), property, IGeometryProperty::PVariable);
149 std::shared_ptr<RealVariable>& pvar = storage.realVar;
150 if (!pvar)
151 throw FatalErrorException(A_FUNCINFO, "Unexpected missing scalar field");
152 storage.usageVarCount++;
153 return *pvar;
154}
155
156const IGeometryMng::Real3Variable&
158getReal3VariableProperty(ItemGroup group, IGeometryProperty::eProperty property)
159{
160 if (!IGeometryProperty::isVectorial(property))
161 traceMng()->fatal() << "Non vectorial property requested by vectorial interface";
162 ItemGroupGeometryProperty::StorageInfo& storage = _checkItemGroupProperty(group.internal(), property, IGeometryProperty::PVariable);
163 std::shared_ptr<Real3Variable>& pvar = storage.real3Var;
164 if (!pvar)
165 throw FatalErrorException(A_FUNCINFO, "Unexpected missing vectorial field");
166 storage.usageVarCount++;
167 return *pvar;
168}
169
170/*---------------------------------------------------------------------------*/
171/*---------------------------------------------------------------------------*/
172
174update(ItemGroup group, [[maybe_unused]] Integer property)
175{
176 update(group);
177}
178
180reset(ItemGroup group, [[maybe_unused]] Integer property)
181{
182 reset(group);
183}
184
185/*---------------------------------------------------------------------------*/
186/*---------------------------------------------------------------------------*/
187
189update()
190{
191 Trace::Setter setter(traceMng(), className());
192
193 _checkItemGroupUsage();
194 _resetComputeFlags();
195
196 IMesh* mesh = this->mesh();
197 //
198 const eItemKind all_kinds[] = { IK_Face, IK_Cell };
199 const Integer all_kind_size = sizeof(all_kinds) / sizeof(eItemKind);
200
201 for (Integer ikind = 0; ikind < all_kind_size; ++ikind) {
202 const eItemKind current_kind = all_kinds[ikind];
203 IItemFamily* family = mesh->itemFamily(current_kind);
204 ItemGroup allItemGroup = family->allItems();
205
206 if (m_group_property_map.find(allItemGroup.internal()) != m_group_property_map.end()) {
207 // Delegate all geometric properties already planned for allItems
208 ItemGroupGeometryProperty& all_group_property = m_group_property_map[allItemGroup.internal()];
209 update(allItemGroup);
210
211 for (PropertyMap::iterator igroup = m_group_property_map.begin(); igroup != m_group_property_map.end(); ++igroup) {
212 ItemGroup group(igroup->first);
213 if (group.itemKind() == current_kind) {
214 ItemGroupGeometryProperty& group_property = igroup->second;
215 for (ItemGroupGeometryProperty::StorageInfos::const_iterator iprop = group_property.storages.begin();
216 iprop != group_property.storages.end(); ++iprop) {
217 const IGeometryProperty::eProperty property = iprop->first;
218 ItemGroupGeometryProperty::StorageInfo& storage = group_property.storages[property];
219
220 if (property & all_group_property.defined) // properties common with allItemGroup
221 {
222 // Is a scalar property
223 if (IGeometryProperty::isScalar(property)) {
224#ifndef NO_USER_WARNING
225#warning "failed when ItemGroupMap storage only on allItems group"
226#endif
227 RealVariable& var = *all_group_property.storages[property].realVar;
228
229 // Need Variable storage for that property ?
230 if (storage.storageType & IGeometryProperty::PVariable) {
231 if (storage.externStorage & IGeometryProperty::PVariable) {
232 RealVariable& lvar = *storage.realVar;
233 ENUMERATE_ITEM (iitem, group) {
234 lvar[iitem] = var[iitem];
235 }
236 }
237 else {
238 std::shared_ptr<RealVariable>& lvar = storage.realVar;
239 if (lvar) {
240 if (lvar->variable() != var.variable()) {
241 // change reference to allItems container
242 lvar.reset(new RealVariable(var));
243 }
244 // else nothing to copy; already well referenced
245 }
246 else {
247 // new reference on allItems container
248 lvar.reset(new RealVariable(var));
249 }
250 }
251 }
252
253 // Need ItemGroupMap storage for that property ?
254 group_property.computed |= property;
255 group_property.delegated |= property;
256 }
257 else {
258 ARCANE_ASSERT((IGeometryProperty::isVectorial(property)), ("Vectorial property expected"));
259 Real3Variable& var = *all_group_property.storages[property].real3Var;
260
261 // Need Variable storage for that property ?
262 if (storage.storageType & IGeometryProperty::PVariable) {
263 if (storage.externStorage & IGeometryProperty::PVariable) {
264 Real3Variable& lvar = *storage.real3Var;
265 ENUMERATE_ITEM (iitem, group) {
266 lvar[iitem] = var[iitem];
267 }
268 }
269 else {
270 std::shared_ptr<Real3Variable>& lvar = storage.real3Var;
271 if (lvar) {
272 if (lvar->variable() != var.variable()) {
273 // change reference to allItems container
274 lvar.reset(new Real3Variable(var));
275 }
276 // else nothing to copy; already well referenced
277 }
278 else {
279 // new reference on allItems container
280 lvar.reset(new Real3Variable(var));
281 }
282 }
283 }
284
285 // Need ItemGroupMap storage for that property ?
286 group_property.computed |= property;
287 group_property.delegated |= property;
288 }
289 }
290 }
291 }
292 }
293 }
294 }
295
296 // Update other properties
297 for (PropertyMap::iterator iprop = m_group_property_map.begin(); iprop != m_group_property_map.end(); ++iprop) {
298 update(iprop->first);
299 }
300}
301
303reset()
304{
305 for (PropertyMap::iterator iprop = m_group_property_map.begin(); iprop != m_group_property_map.end(); ++iprop) {
306 reset(iprop->first);
307 }
308}
309
310/*---------------------------------------------------------------------------*/
311/*---------------------------------------------------------------------------*/
312
315 IGeometryProperty::eProperty property,
316 IGeometryProperty::eStorage storage)
317{
318 PropertyMap::iterator iprop = m_group_property_map.find(group);
319 if (iprop == m_group_property_map.end())
320 ARCANE_FATAL("Non declare group {0}", group->name());
321 ItemGroupGeometryProperty& properties = iprop->second;
322 if ((properties.defined & property) != property)
323 ARCANE_FATAL("Non available property [{0}] requested from group {1}",
324 IGeometryProperty::name(property), group->name());
325 ItemGroupGeometryProperty::StorageInfo& storages = properties.storages[property];
326 if ((storages.storageType & storage) != storage)
327 ARCANE_FATAL("Non available storage [{0}] requested for property {1} on group {2}",
328 IGeometryProperty::name(storage), IGeometryProperty::name(property), group->name());
329 return storages;
330}
331
332/*---------------------------------------------------------------------------*/
333/*---------------------------------------------------------------------------*/
334
335void GeometryServiceBase::_resetComputeFlags()
336{
337 for (PropertyMap::iterator igroup = m_group_property_map.begin(); igroup != m_group_property_map.end(); ++igroup) {
338 ItemGroupGeometryProperty& group_property = igroup->second;
339 group_property.resetFlags();
340 }
341}
342
343/*---------------------------------------------------------------------------*/
344/*---------------------------------------------------------------------------*/
345
346void GeometryServiceBase::_checkItemGroupUsage()
347{
348 // Control that all extern storage are not shared !
349 typedef std::map<const IVariable*, std::pair<ItemGroupImpl*, IGeometryProperty::eProperty>> ExternVariables;
350 ExternVariables extern_variables;
351
352 for (PropertyMap::iterator igroup = m_group_property_map.begin(); igroup != m_group_property_map.end(); ++igroup) {
353 ItemGroupGeometryProperty& group_property = igroup->second;
354 for (ItemGroupGeometryProperty::StorageInfos::const_iterator i = group_property.storages.begin();
355 i != group_property.storages.end(); ++i) {
356 const IGeometryProperty::eProperty property = i->first;
357 const ItemGroupGeometryProperty::StorageInfo& info = i->second;
358 if (info.usageVarCount == 0 && (info.realVar || info.real3Var) && !(info.externStorage & IGeometryProperty::PVariable))
359 traceMng()->warning() << "Geometric property " << IGeometryProperty::name(property)
360 << " on group " << igroup->first->name() << " with Variable storage never used since last update";
361
362 // Check non shared extern Variable storage
363 if (info.realVar || (info.real3Var && (info.externStorage & IGeometryProperty::PVariable))) {
364 IVariable* check_variable = NULL;
365 if (info.realVar) {
366 check_variable = info.realVar->variable();
367 }
368 if (info.real3Var) {
369 ARCANE_ASSERT((check_variable == NULL), ("Inconsistent real/real3 storage"));
370 check_variable = info.real3Var->variable();
371 }
372 std::map<const IVariable*, std::pair<ItemGroupImpl*, IGeometryProperty::eProperty>>::const_iterator finder = extern_variables.find(check_variable);
373 if (finder != extern_variables.end()) {
374 traceMng()->warning() << "Geometric property " << IGeometryProperty::name(property)
375 << " on group " << igroup->first->name()
376 << " shares extern Variable " << finder->first->name()
377 << " with property " << IGeometryProperty::name(finder->second.second)
378 << " on group " << finder->second.first->name();
379 }
380 else {
381 extern_variables[check_variable] = std::make_pair(igroup->first, property);
382 }
383 }
384 }
385 }
386}
387
388/*---------------------------------------------------------------------------*/
389/*---------------------------------------------------------------------------*/
390
391} // namespace Arcane::Numerics
392
393/*---------------------------------------------------------------------------*/
394/*---------------------------------------------------------------------------*/
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
#define ENUMERATE_ITEM(name, group)
Generic enumerator for a node group.
Interface of an entity family.
Definition IItemFamily.h:83
virtual ItemGroup allItems() const =0
Group of all entities.
virtual TraceMessage warning()=0
Stream for a warning message.
virtual TraceMessage fatal()=0
Stream for a fatal error message.
virtual TraceMessageDbg debug(Trace::eDebugLevel=Trace::Medium)=0
Stream for a debug message.
Interface of a variable.
Definition IVariable.h:40
Brief: Implementation of a mesh entity group.
const String & name() const
Group name.
Mesh entity group.
Definition ItemGroup.h:51
ItemGroupImpl * internal() const
Returns the group implementation.
Definition ItemGroup.h:125
const String & name() const
Group name.
Definition ItemGroup.h:81
eItemKind itemKind() const
Group kind. This is the kind of its elements.
Definition ItemGroup.h:114
String m_suffix
suffix for internal variable names
Integer getItemGroupProperty(ItemGroup group)
Get set of properties of an ItemGroup.
void addItemGroupProperty(ItemGroup group, Integer property, Integer storage=IGeometryProperty::PVariable)
Set geometric properties on an ItemGroup.
virtual IMesh * mesh()=0
Access to mesh.
void reset()
Reset property for all ItemGroups.
virtual const char * className() const =0
Name of instantiated class.
virtual ITraceMng * traceMng()=0
Access to traceMng.
const Real3Variable & getReal3VariableProperty(ItemGroup group, IGeometryProperty::eProperty property)
Get geometric property values for a Real3 field.
bool hasItemGroupProperty(ItemGroup group, Integer property)
Check if a property is activated on an ItemGroup.
Integer getItemGroupPropertyStorage(ItemGroup group, IGeometryProperty::eProperty property)
Check if storage is available on an ItemGroup.
const RealVariable & getRealVariableProperty(ItemGroup group, IGeometryProperty::eProperty property)
Get geometric property values for a Real field.
void update()
Update property values for all ItemGroups.
ItemGroupGeometryProperty::StorageInfo & _checkItemGroupProperty(ItemGroupImpl *group, IGeometryProperty::eProperty property, IGeometryProperty::eStorage storage)
Return ItemGroupGeometryProperty if requested property and storage are available.
Internal class implementation for TemisGeometryService and Euclidian3GeometryService.
IVariable * variable() const
Associated variable.
String name() const
Variable name.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Int32 Integer
Type representing an integer.
eItemKind
Mesh entity type.
@ IK_Cell
Cell mesh entity.
@ IK_Face
Face mesh entity.