Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
IMeshMaterialMng.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/* IMeshMaterialMng.cc (C) 2000-2023 */
9/* */
10/* Interface for the mesh material and domain manager. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/core/materials/IMeshMaterialMng.h"
15
16#include "arcane/utils/Ref.h"
17#include "arcane/utils/FatalErrorException.h"
18
19#include "arcane/core/IMesh.h"
20#include "arcane/core/MeshHandle.h"
21
22/*---------------------------------------------------------------------------*/
23/*---------------------------------------------------------------------------*/
24
25namespace Arcane::Materials
26{
27
28/*---------------------------------------------------------------------------*/
29/*---------------------------------------------------------------------------*/
30
31namespace
32{
33 IMeshMaterialMng::IFactory* global_mesh_material_mng_factory = nullptr;
34}
35
36/*---------------------------------------------------------------------------*/
37/*---------------------------------------------------------------------------*/
38
39void IMeshMaterialMng::
40_internalSetFactory(IFactory* f)
41{
42 global_mesh_material_mng_factory = f;
43}
44
45/*---------------------------------------------------------------------------*/
46/*---------------------------------------------------------------------------*/
47
49getTrueReference(const MeshHandle& mesh_handle, bool is_create)
50{
51 if (mesh_handle.isNull())
52 ARCANE_FATAL("Null MeshHandle is not allowed");
53 auto* f = global_mesh_material_mng_factory;
54 if (!f) {
55 if (is_create)
56 ARCANE_FATAL("No factory for 'IMeshMaterialMng': You need to link with 'arcane_materials' library");
57 return {};
58 }
59 return f->getTrueReference(mesh_handle, is_create);
60}
61
62/*---------------------------------------------------------------------------*/
63/*---------------------------------------------------------------------------*/
64
66getReference(const MeshHandleOrMesh& mesh_handle, bool create)
67{
68 return getTrueReference(mesh_handle.handle(), create).get();
69}
70
71/*---------------------------------------------------------------------------*/
72/*---------------------------------------------------------------------------*/
73
74} // End namespace Arcane::Materials
75
76/*---------------------------------------------------------------------------*/
77/*---------------------------------------------------------------------------*/
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
Interface for the material and environment manager of a mesh.
static Ref< IMeshMaterialMng > getTrueReference(const MeshHandle &mesh_handle, bool create=true)
Retrieves or creates the reference associated with mesh.
static IMeshMaterialMng * getReference(const MeshHandleOrMesh &mesh_handle, bool create=true)
Retrieves or creates the reference associated with mesh.
Compatibility class to hold a MeshHandle or an IMesh*.
Definition MeshHandle.h:196
const MeshHandle & handle() const
Associated handle.
Definition MeshHandle.h:219
Handle on a mesh.
Definition MeshHandle.h:48
bool isNull() const
Indicates if the handle is null (it does not reference any existing mesh or not).
Definition MeshHandle.h:163
Reference to an instance.
Always enables tracing in Arcane parts concerning materials.