Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
MeshMaterialVariableFactoryMng.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/* MeshMaterialVariableFactoryMng.cc (C) 2000-2022 */
9/* */
10/* Material variable factory manager. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/utils/TraceAccessor.h"
15#include "arcane/utils/FatalErrorException.h"
16
17#include "arcane/core/materials/MaterialVariableTypeInfo.h"
18#include "arcane/core/materials/IMeshMaterialVariableFactory.h"
19#include "arcane/core/materials/IMeshMaterialVariableFactoryMng.h"
20#include "arcane/core/materials/IMeshMaterialMng.h"
21
22#include <map>
23
24/*---------------------------------------------------------------------------*/
25/*---------------------------------------------------------------------------*/
26
27namespace Arcane::Materials
28{
29
30/*---------------------------------------------------------------------------*/
31/*---------------------------------------------------------------------------*/
32
33// TODO: Use Ref<>
34class MeshMaterialVariableFactoryMng
35: public TraceAccessor
37{
38 public:
39
40 MeshMaterialVariableFactoryMng(IMeshMaterialMng* mm);
41 ~MeshMaterialVariableFactoryMng() override;
42
43 public:
44
45 void build() override;
46 ITraceMng* traceMng() const override;
48 IMeshMaterialVariable* createVariable(const String& storage_type,
49 const MaterialVariableBuildInfo& build_info) override;
50
51 private:
52
53 std::map<String, Ref<IMeshMaterialVariableFactory>> m_factories;
54};
55
56/*---------------------------------------------------------------------------*/
57/*---------------------------------------------------------------------------*/
58
59MeshMaterialVariableFactoryMng::
60MeshMaterialVariableFactoryMng(IMeshMaterialMng* mm)
61: TraceAccessor(mm->traceMng())
62{
63}
64
65/*---------------------------------------------------------------------------*/
66/*---------------------------------------------------------------------------*/
67
68MeshMaterialVariableFactoryMng::
69~MeshMaterialVariableFactoryMng()
70{
71}
72
73/*---------------------------------------------------------------------------*/
74/*---------------------------------------------------------------------------*/
75
77createVariable(const String& storage_type, const MaterialVariableBuildInfo& build_info)
78{
79 auto x = m_factories.find(storage_type);
80 if (x == m_factories.end())
81 ARCANE_FATAL("Can not find mesh IMeshMaterialVariableFactory named={0}", storage_type);
82
83 return x->second->createVariable(build_info);
84}
85
86/*---------------------------------------------------------------------------*/
87/*---------------------------------------------------------------------------*/
88
93
94/*---------------------------------------------------------------------------*/
95/*---------------------------------------------------------------------------*/
96
102
103/*---------------------------------------------------------------------------*/
104/*---------------------------------------------------------------------------*/
105
108{
109 MaterialVariableTypeInfo t = factory->materialVariableTypeInfo();
110 m_factories.insert(std::make_pair(t.fullName(), factory));
111}
112
113/*---------------------------------------------------------------------------*/
114/*---------------------------------------------------------------------------*/
115
117arcaneCreateMeshMaterialVariableFactoryMng(IMeshMaterialMng* mm)
118{
119 auto* x = new MeshMaterialVariableFactoryMng(mm);
120 x->build();
121 return x;
122}
123
124/*---------------------------------------------------------------------------*/
125/*---------------------------------------------------------------------------*/
126
127} // End namespace Arcane::Materials
128
129/*---------------------------------------------------------------------------*/
130/*---------------------------------------------------------------------------*/
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
Interface for the material and environment manager of a mesh.
Interface of the material variable factory manager.
Interface of a material variable on a mesh.
Information characterizing the type of a material variable.
String fullName() const
Full name of the variable type.
IMeshMaterialVariable * createVariable(const String &storage_type, const MaterialVariableBuildInfo &build_info) override
Creates a material variable.
ITraceMng * traceMng() const override
Associated trace manager.
void registerFactory(Ref< IMeshMaterialVariableFactory > factory) override
Registers the factory factory.
Reference to an instance.
TraceAccessor(ITraceMng *m)
Constructs an accessor via the trace manager m.
ITraceMng * traceMng() const
Trace manager.
Always enables tracing in Arcane parts concerning materials.