Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
GeometryServiceBase.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2023 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 "GeometryServiceBase.h"
8/* Author : havep at Thu Apr 3 09:09:09 2008
9 * Generated by createNew
10 */
11
12#include <arcane/IMesh.h>
13using namespace Arcane;
14
15#include <arcane/IItemOperationByBasicType.h>
16#include <arcane/IItemFamily.h>
17#include <arcane/ArcaneVersion.h>
18#include <arcane/ItemVectorView.h>
19
20#include <set>
21
22ARCANE_BEGIN_NAMESPACE
23NUMERICS_BEGIN_NAMESPACE
24
25/*---------------------------------------------------------------------------*/
26/*---------------------------------------------------------------------------*/
27
30{
31 m_suffix = String("By") + (unsigned long)(this);
32}
33
39
40/*---------------------------------------------------------------------------*/
41/*---------------------------------------------------------------------------*/
42
44addItemGroupProperty(ItemGroup group, Integer property, Integer storage)
45{
46 ItemGroupGeometryProperty& properties = m_group_property_map[group.internal()];
47 properties.defined |= property;
49 while (property) {
50 if (property & current_property) {
51 properties.storages[static_cast<IGeometryProperty::eProperty>(current_property)].storageType |= storage;
52 traceMng()->debug() << "Add geometric property ["
53 << IGeometryProperty::name(static_cast<IGeometryProperty::eProperty>(current_property))
54 << "] on group " << group.name();
55 }
56 property &= ~current_property;
57 current_property <<= 1;
58 }
59}
60
62addItemGroupProperty(ItemGroup group, IGeometryProperty::eProperty property, RealVariable var)
63{
64 ARCANE_ASSERT((IGeometryProperty::isScalar(property)), ("Scalar property expected"));
65 ItemGroupGeometryProperty& properties = m_group_property_map[group.internal()];
66 ItemGroupGeometryProperty::StorageInfo& storage = properties.storages[property];
67 if (storage.realVar) {
68 if (storage.realVar->name() != var.name())
69 traceMng()->fatal() << "Geometric property [" << IGeometryProperty::name(property)
70 << "] storage already defined on group " << group.name()
71 << " with variable " << storage.realVar->name();
72 ARCANE_ASSERT((properties.defined & property), ("Unconsistent state with undefined property with defined variable"));
73 return;
74 }
75 properties.defined |= property;
76 storage.realVar.reset(new RealVariable(var));
77 storage.storageType |= IGeometryProperty::PVariable;
78 storage.externStorage |= IGeometryProperty::PVariable;
79 // #ifndef NO_USER_WARNING
80 // #warning "Ne plus allouer d'ItemGroupMap implicitement"
81 // #endif /* NO_USER_WARNING */
82 // storage.realMap.reset(new RealGroupMap(group));
83 // storage.storageType |= IGeometryProperty::PItemGroupMap;
84}
85
87addItemGroupProperty(ItemGroup group, IGeometryProperty::eProperty property, Real3Variable var)
88{
89 ARCANE_ASSERT((IGeometryProperty::isVectorial(property)), ("Vectorial property expected"));
90 ItemGroupGeometryProperty& properties = m_group_property_map[group.internal()];
91 ItemGroupGeometryProperty::StorageInfo& storage = properties.storages[property];
92 if (storage.real3Var) {
93 if (storage.real3Var->name() != var.name())
94 traceMng()->fatal() << "Geometric property [" << IGeometryProperty::name(property)
95 << "] storage already defined on group " << group.name()
96 << " with variable " << storage.real3Var->name();
97 ARCANE_ASSERT((properties.defined & property), ("Unconsistent state with undefined property with defined variable"));
98 return;
99 }
100 properties.defined |= property;
101 storage.real3Var.reset(new Real3Variable(var));
102 storage.storageType |= IGeometryProperty::PVariable;
103 storage.externStorage |= IGeometryProperty::PVariable;
104 // #ifndef NO_USER_WARNING
105 // #warning "Ne plus allouer d'ItemGroupMap implicitement"
106 // #endif /* NO_USER_WARNING */
107 // storage.real3Map.reset(new Real3GroupMap(group));
108 // storage.storageType |= IGeometryProperty::PItemGroupMap;
109}
110
111Integer
114{
115 PropertyMap::const_iterator iprop = m_group_property_map.find(group.internal());
116 if (iprop == m_group_property_map.end())
117 return IGeometryProperty::PNone;
118 return iprop->second.defined;
119}
120
123{
124 return (getItemGroupProperty(group) & property) == property;
125}
126
127Integer
129getItemGroupPropertyStorage(ItemGroup group, IGeometryProperty::eProperty property)
130{
131 PropertyMap::const_iterator iprop = m_group_property_map.find(group.internal());
132 if (iprop == m_group_property_map.end())
133 return IGeometryProperty::PNoStorage;
134 return iprop->second.getStorage(property);
135}
136
137/*---------------------------------------------------------------------------*/
138
141getRealVariableProperty(ItemGroup group, IGeometryProperty::eProperty property)
142{
143 if (!IGeometryProperty::isScalar(property))
144 traceMng()->fatal() << "Non scalar property requested by scalar interface";
145 ItemGroupGeometryProperty::StorageInfo& storage = _checkItemGroupProperty(group.internal(), property, IGeometryProperty::PVariable);
146 std::shared_ptr<RealVariable>& pvar = storage.realVar;
147 if (!pvar)
148 throw FatalErrorException(A_FUNCINFO, "Unexpected missing scalar field");
149 storage.usageVarCount++;
150 return *pvar;
151}
152
155getReal3VariableProperty(ItemGroup group, IGeometryProperty::eProperty property)
156{
157 if (!IGeometryProperty::isVectorial(property))
158 traceMng()->fatal() << "Non vectorial property requested by vectorial interface";
159 ItemGroupGeometryProperty::StorageInfo& storage = _checkItemGroupProperty(group.internal(), property, IGeometryProperty::PVariable);
160 std::shared_ptr<Real3Variable>& pvar = storage.real3Var;
161 if (!pvar)
162 throw FatalErrorException(A_FUNCINFO, "Unexpected missing vectorial field");
163 storage.usageVarCount++;
164 return *pvar;
165}
166
167/*---------------------------------------------------------------------------*/
168/*---------------------------------------------------------------------------*/
169
171update(ItemGroup group, [[maybe_unused]] Integer property)
172{
173 update(group);
174}
175
177reset(ItemGroup group, [[maybe_unused]] Integer property)
178{
179 reset(group);
180}
181
182/*---------------------------------------------------------------------------*/
183/*---------------------------------------------------------------------------*/
184
186update()
187{
189
190 _checkItemGroupUsage();
191 _resetComputeFlags();
192
193 IMesh* mesh = this->mesh();
194 //
195 const eItemKind all_kinds[] = { IK_Face, IK_Cell };
196 const Integer all_kind_size = sizeof(all_kinds) / sizeof(eItemKind);
197
198 for (Integer ikind = 0; ikind < all_kind_size; ++ikind) {
200 IItemFamily* family = mesh->itemFamily(current_kind);
201 ItemGroup allItemGroup = family->allItems();
202
203 if (m_group_property_map.find(allItemGroup.internal()) != m_group_property_map.end()) {
204 // Delegate all geometric properties already planned for allItems
205 ItemGroupGeometryProperty& all_group_property = m_group_property_map[allItemGroup.internal()];
207
208 for (PropertyMap::iterator igroup = m_group_property_map.begin(); igroup != m_group_property_map.end(); ++igroup) {
209 ItemGroup group(igroup->first);
210 if (group.itemKind() == current_kind) {
212 for (ItemGroupGeometryProperty::StorageInfos::const_iterator iprop = group_property.storages.begin();
213 iprop != group_property.storages.end(); ++iprop) {
214 const IGeometryProperty::eProperty property = iprop->first;
215 ItemGroupGeometryProperty::StorageInfo& storage = group_property.storages[property];
216
217 if (property & all_group_property.defined) // propriétés communes avec allItemGroup
218 {
219 // Is a scalar property
220 if (IGeometryProperty::isScalar(property)) {
221#ifndef NO_USER_WARNING
222#warning "failed when ItemGroupMap storage only on allItems group"
223#endif
224 RealVariable& var = *all_group_property.storages[property].realVar;
225
226 // Need Variable storage for that property ?
227 if (storage.storageType & IGeometryProperty::PVariable) {
228 if (storage.externStorage & IGeometryProperty::PVariable) {
229 RealVariable& lvar = *storage.realVar;
230 ENUMERATE_ITEM (iitem, group) {
231 lvar[iitem] = var[iitem];
232 }
233 }
234 else {
235 std::shared_ptr<RealVariable>& lvar = storage.realVar;
236 if (lvar) {
237 if (lvar->variable() != var.variable()) {
238 // change reference to allItems container
239 lvar.reset(new RealVariable(var));
240 }
241 // else nothing to copy; already well referenced
242 }
243 else {
244 // new reference on allItems container
245 lvar.reset(new RealVariable(var));
246 }
247 }
248 }
249
250 // Need ItemGroupMap storage for that property ?
251 group_property.computed |= property;
252 group_property.delegated |= property;
253 }
254 else {
255 ARCANE_ASSERT((IGeometryProperty::isVectorial(property)), ("Vectorial property expected"));
256 Real3Variable& var = *all_group_property.storages[property].real3Var;
257
258 // Need Variable storage for that property ?
259 if (storage.storageType & IGeometryProperty::PVariable) {
260 if (storage.externStorage & IGeometryProperty::PVariable) {
261 Real3Variable& lvar = *storage.real3Var;
262 ENUMERATE_ITEM (iitem, group) {
263 lvar[iitem] = var[iitem];
264 }
265 }
266 else {
267 std::shared_ptr<Real3Variable>& lvar = storage.real3Var;
268 if (lvar) {
269 if (lvar->variable() != var.variable()) {
270 // change reference to allItems container
271 lvar.reset(new Real3Variable(var));
272 }
273 // else nothing to copy; already well referenced
274 }
275 else {
276 // new reference on allItems container
277 lvar.reset(new Real3Variable(var));
278 }
279 }
280 }
281
282 // Need ItemGroupMap storage for that property ?
283 group_property.computed |= property;
284 group_property.delegated |= property;
285 }
286 }
287 }
288 }
289 }
290 }
291 }
292
293 // Mise à jour des autres propriétés
294 for (PropertyMap::iterator iprop = m_group_property_map.begin(); iprop != m_group_property_map.end(); ++iprop) {
295 update(iprop->first);
296 }
297}
298
300reset()
301{
302 for (PropertyMap::iterator iprop = m_group_property_map.begin(); iprop != m_group_property_map.end(); ++iprop) {
303 reset(iprop->first);
304 }
305}
306
307/*---------------------------------------------------------------------------*/
308/*---------------------------------------------------------------------------*/
309
312 IGeometryProperty::eProperty property,
313 IGeometryProperty::eStorage storage)
314{
315 PropertyMap::iterator iprop = m_group_property_map.find(group);
316 if (iprop == m_group_property_map.end())
317 ARCANE_FATAL("Non declare group {0}", group->name());
318 ItemGroupGeometryProperty& properties = iprop->second;
319 if ((properties.defined & property) != property)
320 ARCANE_FATAL("Non available property [{0}] requested from group {1}",
321 IGeometryProperty::name(property), group->name());
322 ItemGroupGeometryProperty::StorageInfo& storages = properties.storages[property];
323 if ((storages.storageType & storage) != storage)
324 ARCANE_FATAL("Non available storage [{0}] requested for property {1} on group {2}",
325 IGeometryProperty::name(storage), IGeometryProperty::name(property), group->name());
326 return storages;
327}
328
329/*---------------------------------------------------------------------------*/
330/*---------------------------------------------------------------------------*/
331
332void GeometryServiceBase::_resetComputeFlags()
333{
334 for (PropertyMap::iterator igroup = m_group_property_map.begin(); igroup != m_group_property_map.end(); ++igroup) {
336 group_property.resetFlags();
337 }
338}
339
340/*---------------------------------------------------------------------------*/
341/*---------------------------------------------------------------------------*/
342
343void GeometryServiceBase::_checkItemGroupUsage()
344{
345 // Control that all extern storage are not shared !
346 typedef std::map<const IVariable*, std::pair<ItemGroupImpl*, IGeometryProperty::eProperty>> ExternVariables;
348
349 for (PropertyMap::iterator igroup = m_group_property_map.begin(); igroup != m_group_property_map.end(); ++igroup) {
351 for (ItemGroupGeometryProperty::StorageInfos::const_iterator i = group_property.storages.begin();
352 i != group_property.storages.end(); ++i) {
353 const IGeometryProperty::eProperty property = i->first;
354 const ItemGroupGeometryProperty::StorageInfo& info = i->second;
355 if (info.usageVarCount == 0 && (info.realVar || info.real3Var) && !(info.externStorage & IGeometryProperty::PVariable))
356 traceMng()->warning() << "Geometric property " << IGeometryProperty::name(property)
357 << " on group " << igroup->first->name() << " with Variable storage never used since last update";
358
359 // Check non shared extern Variable storage
360 if (info.realVar || (info.real3Var && (info.externStorage & IGeometryProperty::PVariable))) {
362 if (info.realVar) {
363 check_variable = info.realVar->variable();
364 }
365 if (info.real3Var) {
366 ARCANE_ASSERT((check_variable == NULL), ("Inconsistent real/real3 storage"));
367 check_variable = info.real3Var->variable();
368 }
369 std::map<const IVariable*, std::pair<ItemGroupImpl*, IGeometryProperty::eProperty>>::const_iterator finder = extern_variables.find(check_variable);
370 if (finder != extern_variables.end()) {
371 traceMng()->warning() << "Geometric property " << IGeometryProperty::name(property)
372 << " on group " << igroup->first->name()
373 << " shares extern Variable " << finder->first->name()
374 << " with property " << IGeometryProperty::name(finder->second.second)
375 << " on group " << finder->second.first->name();
376 }
377 else {
378 extern_variables[check_variable] = std::make_pair(igroup->first, property);
379 }
380 }
381 }
382 }
383}
384
385/*---------------------------------------------------------------------------*/
386/*---------------------------------------------------------------------------*/
387
388NUMERICS_END_NAMESPACE
389ARCANE_END_NAMESPACE
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
#define ENUMERATE_ITEM(name, group)
Enumérateur générique d'un groupe de noeuds.
void addItemGroupProperty(ItemGroup group, Integer property, Integer storage=IGeometryProperty::PVariable)
Set geometric properties on a ItemGroup.
void update()
Update property values for all ItemGroups.
Integer getItemGroupPropertyStorage(ItemGroup group, IGeometryProperty::eProperty property)
Check if a storage is available on an ItemGroup.
Integer getItemGroupProperty(ItemGroup group)
Get set of properties of an ItemGroup.
virtual IMesh * mesh()=0
Access to mesh.
ItemGroupGeometryProperty::StorageInfo & _checkItemGroupProperty(ItemGroupImpl *group, IGeometryProperty::eProperty property, IGeometryProperty::eStorage storage)
Return ItemGroupGeometryProperty if requested property and storage are available.
const Real3Variable & getReal3VariableProperty(ItemGroup group, IGeometryProperty::eProperty property)
Get geometric property values for a Real3 field.
const RealVariable & getRealVariableProperty(ItemGroup group, IGeometryProperty::eProperty property)
Get geometric property values for a Real field.
String m_suffix
suffix for internal variable names
void reset()
Reset property for all ItemGroups.
virtual const char * className() const =0
Name of instancied class.
virtual ITraceMng * traceMng()=0
Access to traceMng.
bool hasItemGroupProperty(ItemGroup group, Integer property)
Check is a property is activated on an ItemGroup.
Interface d'une famille d'entités.
virtual ItemGroup allItems() const =0
Groupe de toutes les entités.
Interface d'une variable.
Definition IVariable.h:54
Internal class implementation for TemisGeometryService and Euclidian3GeometryService.
Implémentation d'un groupe d'entités de maillage.
const String & name() const
Nom du groupe.
Groupe d'entités de maillage.
Definition ItemGroup.h:49
ItemGroupImpl * internal() const
Retourne l'implémentation du groupe.
Definition ItemGroup.h:120
const String & name() const
Nom du groupe.
Definition ItemGroup.h:76
eItemKind itemKind() const
Genre du groupe. Il s'agit du genre de ses éléments.
Definition ItemGroup.h:109
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Definition Lima.cc:120
Exception lorsqu'une erreur fatale est survenue.
Chaîne de caractères unicode.
TraceMessageDbg debug(Trace::eDebugLevel=Trace::Medium) const
Flot pour un message de debug.
TraceMessage warning() const
Flot pour un message d'avertissement.
TraceMessage fatal() const
Flot pour un message d'erreur fatale.
Positionne une classe de message.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
eItemKind
Genre d'entité de maillage.
@ IK_Cell
Entité de maillage de genre maille.
@ IK_Face
Entité de maillage de genre face.
Int32 Integer
Type représentant un entier.