Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
MeshHandle.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/*---------------------------------------------------------------------------*/
8/* MeshHandle.cc (C) 2000-2023 */
9/* */
10/* Handle on a mesh. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/core/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/core/ISubDomain.h"
22#include "arcane/core/IMesh.h"
23#include "arcane/core/IMeshBase.h"
24
25/*---------------------------------------------------------------------------*/
26/*---------------------------------------------------------------------------*/
27
28namespace Arcane
29{
30
31/*---------------------------------------------------------------------------*/
32/*---------------------------------------------------------------------------*/
33
34// TODO make this constructor private to IMeshMng to avoid
35// possible duplicates for MeshHandles associated with the same mesh name.
36MeshHandle::MeshHandleRef::
37MeshHandleRef(ISubDomain* sd, const String& name)
38: m_mesh_name(name)
39, m_sub_domain(sd)
40, m_is_null(name.null())
41{
42 if (!m_is_null)
43 m_user_data_list = new UserDataList();
45 m_trace_mng = sd->traceMng();
46 m_mesh_mng = sd->meshMng();
47 m_variable_mng = sd->variableMng();
48 m_on_destroy_observable = new Observable();
49 if (auto v = Convert::Type<Int32>::tryParseFromEnvironment("ARCANE_DO_FATAL_IN_MESHHANDLE", true))
50 m_do_fatal_in_mesh_method = v.value() != 0;
51}
52
53/*---------------------------------------------------------------------------*/
54/*---------------------------------------------------------------------------*/
55
56MeshHandle::MeshHandleRef::
57~MeshHandleRef()
58{
59 delete m_user_data_list;
60 delete m_on_destroy_observable;
61}
62
63/*---------------------------------------------------------------------------*/
64/*---------------------------------------------------------------------------*/
65
66void MeshHandle::MeshHandleRef::
67_setMesh(IMesh* mesh)
68{
69 m_mesh_ptr = mesh;
70}
71
72/*---------------------------------------------------------------------------*/
73/*---------------------------------------------------------------------------*/
74
75void MeshHandle::MeshHandleRef::
76_destroyMesh()
77{
78 // TODO: protect against multiple calls
79 IMesh* mesh = m_mesh_ptr;
80 if (!mesh)
81 return;
82 m_on_destroy_observable->notifyAllObservers();
83 m_user_data_list->clear();
84 // Be careful not to set to null until the end of this routine because the
85 // users of \a m_user_data might need this MeshHandle.
86 m_mesh_ptr = nullptr;
87 delete mesh;
88}
89
90/*---------------------------------------------------------------------------*/
91/*---------------------------------------------------------------------------*/
92
93/*---------------------------------------------------------------------------*/
94/*---------------------------------------------------------------------------*/
95
96MeshHandle::
97MeshHandle(ISubDomain* sd, const String& name)
98: m_ref(new MeshHandleRef(sd, name))
99{
100}
101
102/*---------------------------------------------------------------------------*/
103/*---------------------------------------------------------------------------*/
104
105MeshHandle::
106MeshHandle()
107: m_ref(new MeshHandleRef())
108{
109}
110
111/*---------------------------------------------------------------------------*/
112/*---------------------------------------------------------------------------*/
113
114IMeshMng* MeshHandle::
115meshMng() const
116{
117 return m_ref->meshMng();
118}
119
120/*---------------------------------------------------------------------------*/
121/*---------------------------------------------------------------------------*/
122
123bool MeshHandle::
124hasMesh() const
125{
126 IMesh* m = m_ref->mesh();
127 return m;
128}
129
130/*---------------------------------------------------------------------------*/
131/*---------------------------------------------------------------------------*/
132
133IMesh* MeshHandle::
134mesh() const
135{
136 IMesh* m = m_ref->mesh();
137 if (m)
138 return m;
139 // Eventually, make a fatal error if the mesh is null. For reasons of
140 // compatibility with the existing code, we return 'nullptr'.
141 bool do_fatal = m_ref->isDoFatalInMeshMethod();
142 if (do_fatal)
143 ARCANE_FATAL("Invalid call for null mesh. Call MeshHandle::hasMesh() before to make sure mesh is valid");
144 return nullptr;
145}
146
147/*---------------------------------------------------------------------------*/
148/*---------------------------------------------------------------------------*/
149
150IMesh* MeshHandle::
151meshOrNull() const
152{
153 return m_ref->mesh();
154}
155
156/*---------------------------------------------------------------------------*/
157/*---------------------------------------------------------------------------*/
158
159ITraceMng* MeshHandle::
160traceMng() const
161{
162 return m_ref->traceMng();
163}
164
165/*---------------------------------------------------------------------------*/
166/*---------------------------------------------------------------------------*/
167
168IVariableMng* MeshHandle::
169variableMng() const
170{
171 return m_ref->variableMng();
172}
173
174/*---------------------------------------------------------------------------*/
175/*---------------------------------------------------------------------------*/
176
177IApplication* MeshHandle::
178application() const
179{
180 return m_ref->subDomain()->application();
181}
182
183/*---------------------------------------------------------------------------*/
184/*---------------------------------------------------------------------------*/
185
186IObservable* MeshHandle::
187onDestroyObservable() const
188{
189 return m_ref->onDestroyObservable();
190}
191
192/*---------------------------------------------------------------------------*/
193/*---------------------------------------------------------------------------*/
194
195/*---------------------------------------------------------------------------*/
196/*---------------------------------------------------------------------------*/
197
198MeshHandleOrMesh::
199MeshHandleOrMesh(const MeshHandle& handle)
200: m_handle(handle)
201{}
202
203/*---------------------------------------------------------------------------*/
204/*---------------------------------------------------------------------------*/
205
208{
209 if (mesh)
210 m_handle = mesh->handle();
211}
212
213/*---------------------------------------------------------------------------*/
214/*---------------------------------------------------------------------------*/
215
216} // End namespace Arcane
217
218/*---------------------------------------------------------------------------*/
219/*---------------------------------------------------------------------------*/
#define ARCANE_CHECK_POINTER(ptr)
Macro returning the pointer ptr if it is not null or throwing an exception if it is null.
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
Application interface.
Mesh manager interface.
Definition IMeshMng.h:41
Interface of the subdomain manager.
Definition ISubDomain.h:75
Variable manager interface.
IMesh * mesh() const
Associated mesh. Can be null if the mesh has not yet been created.
Definition MeshHandle.h:213
const MeshHandle & handle() const
Associated handle.
Definition MeshHandle.h:219
MeshHandleOrMesh(const MeshHandle &handle)
Constructs an instance from a MeshHandle.
Handle on a mesh.
Definition MeshHandle.h:48
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --