Arcane  v3.14.10.0
Documentation utilisateur
Chargement...
Recherche...
Aucune correspondance
MeshHandle.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/*---------------------------------------------------------------------------*/
8/* MeshHandle.cc (C) 2000-2023 */
9/* */
10/* Handle sur un maillage. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/MeshHandle.h"
15
16#include "arcane/utils/UserDataList.h"
17#include "arcane/utils/FatalErrorException.h"
18#include "arcane/utils/Observable.h"
19#include "arcane/utils/ValueConvert.h"
20
21#include "arcane/ISubDomain.h"
22#include "arcane/IMesh.h"
23#include "arcane/IMeshBase.h"
24
25/*---------------------------------------------------------------------------*/
26/*---------------------------------------------------------------------------*/
27
28namespace Arcane
29{
30
31/*---------------------------------------------------------------------------*/
32/*---------------------------------------------------------------------------*/
33// TODO rendre ce constructeur privé à IMeshMng pour éviter d'avoir des
34// doublons possibles pour les MeshHandle associés au même nom de maillage.
35MeshHandle::MeshHandleRef::
36MeshHandleRef(ISubDomain* sd,const String& name)
37: m_mesh_name(name)
38, m_sub_domain(sd)
39, m_is_null(name.null())
40{
41 if (!m_is_null)
42 m_user_data_list = new UserDataList();
44 m_trace_mng = sd->traceMng();
45 m_mesh_mng = sd->meshMng();
46 m_variable_mng = sd->variableMng();
47 m_on_destroy_observable = new Observable();
48 if (auto v = Convert::Type<Int32>::tryParseFromEnvironment("ARCANE_DO_FATAL_IN_MESHHANDLE",true))
49 m_do_fatal_in_mesh_method = v.value()!=0;
50}
51
52/*---------------------------------------------------------------------------*/
53/*---------------------------------------------------------------------------*/
54
55MeshHandle::MeshHandleRef::
56~MeshHandleRef()
57{
58 delete m_user_data_list;
59 delete m_on_destroy_observable;
60}
61
62/*---------------------------------------------------------------------------*/
63/*---------------------------------------------------------------------------*/
64
65void MeshHandle::MeshHandleRef::
66_setMesh(IMesh* mesh)
67{
68 m_mesh_ptr = mesh;
69}
70
71/*---------------------------------------------------------------------------*/
72/*---------------------------------------------------------------------------*/
73
74void MeshHandle::MeshHandleRef::
75_destroyMesh()
76{
77 // TODO: protéger les appels multiples
78 IMesh* mesh = m_mesh_ptr;
79 if (!mesh)
80 return;
81 m_on_destroy_observable->notifyAllObservers();
82 m_user_data_list->clear();
83 // Attention à ne mettre à nul que à la fin de cette routine car les
84 // utilisateurs de \a m_user_data peuvent avoir besoin de ce MeshHandle.
85 m_mesh_ptr = nullptr;
86 delete mesh;
87}
88
89/*---------------------------------------------------------------------------*/
90/*---------------------------------------------------------------------------*/
91
92/*---------------------------------------------------------------------------*/
93/*---------------------------------------------------------------------------*/
94
95MeshHandle::
96MeshHandle(ISubDomain* sd,const String& name)
97: m_ref(new MeshHandleRef(sd,name))
98{
99}
100
101/*---------------------------------------------------------------------------*/
102/*---------------------------------------------------------------------------*/
103
104MeshHandle::
105MeshHandle()
106: m_ref(new MeshHandleRef())
107{
108}
109
110/*---------------------------------------------------------------------------*/
111/*---------------------------------------------------------------------------*/
112
113IMeshMng* MeshHandle::
114meshMng() const
115{
116 return m_ref->meshMng();
117}
118
119/*---------------------------------------------------------------------------*/
120/*---------------------------------------------------------------------------*/
121
122bool MeshHandle::
123hasMesh() const
124{
125 IMesh* m = m_ref->mesh();
126 return m;
127}
128
129/*---------------------------------------------------------------------------*/
130/*---------------------------------------------------------------------------*/
131
132IMesh* MeshHandle::
133mesh() const
134{
135 IMesh* m = m_ref->mesh();
136 if (m)
137 return m;
138 // A terme, faire un fatal si le maillage est nul. Pour des raisons de
139 // compatibilité avec l'existant, on retourne 'nullptr'.
140 bool do_fatal = m_ref->isDoFatalInMeshMethod();
141 if (do_fatal)
142 ARCANE_FATAL("Invalid call for null mesh. Call MeshHandle::hasMesh() before to make sure mesh is valid");
143 return nullptr;
144}
145
146/*---------------------------------------------------------------------------*/
147/*---------------------------------------------------------------------------*/
148
149IMesh* MeshHandle::
150meshOrNull() const
151{
152 return m_ref->mesh();
153}
154
155/*---------------------------------------------------------------------------*/
156/*---------------------------------------------------------------------------*/
157
158ITraceMng* MeshHandle::
159traceMng() const
160{
161 return m_ref->traceMng();
162}
163
164/*---------------------------------------------------------------------------*/
165/*---------------------------------------------------------------------------*/
166
167IVariableMng* MeshHandle::
168variableMng() const
169{
170 return m_ref->variableMng();
171}
172
173/*---------------------------------------------------------------------------*/
174/*---------------------------------------------------------------------------*/
175
176IApplication* MeshHandle::
177application() const
178{
179 return m_ref->subDomain()->application();
180}
181
182/*---------------------------------------------------------------------------*/
183/*---------------------------------------------------------------------------*/
184
185IObservable* MeshHandle::
186onDestroyObservable() const
187{
188 return m_ref->onDestroyObservable();
189}
190
191/*---------------------------------------------------------------------------*/
192/*---------------------------------------------------------------------------*/
193
194/*---------------------------------------------------------------------------*/
195/*---------------------------------------------------------------------------*/
196
197MeshHandleOrMesh::
198MeshHandleOrMesh(const MeshHandle& handle)
199: m_handle(handle){}
200
201/*---------------------------------------------------------------------------*/
202/*---------------------------------------------------------------------------*/
203
206{
207 if (mesh)
208 m_handle = mesh->handle();
209}
210
211/*---------------------------------------------------------------------------*/
212/*---------------------------------------------------------------------------*/
213
214} // End namespace Arcane
215
216/*---------------------------------------------------------------------------*/
217/*---------------------------------------------------------------------------*/
#define ARCANE_CHECK_POINTER(ptr)
Macro retournant le pointeur ptr s'il est non nul ou lancant une exception s'il est nul.
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
Interface de l'application.
virtual MeshHandle handle() const =0
Handle sur ce maillage.
Interface du gestionnaire des maillages.
Definition IMeshMng.h:40
Interface d'un observable.
Interface du gestionnaire de variables.
IMesh * mesh() const
Maillage associé. Peut être nul si le maillage n'a pas encore été créé
Definition MeshHandle.h:211
MeshHandleOrMesh(const MeshHandle &handle)
Construit une instance à partir d'un MeshHandle.
Handle sur un maillage.
Definition MeshHandle.h:47
Interface du gestionnaire de traces.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-