Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
MainFactory.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/* MainFactory.cc (C) 2000-2025 */
9/* */
10/* AbstractFactory for Arcane managers. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/impl/MainFactory.h"
15
16#include "arcane/utils/Iostream.h"
17#include "arcane/utils/PlatformUtils.h"
18#include "arcane/utils/ITraceMng.h"
19#include "arcane/utils/ScopedPtr.h"
20
21#include "arcane/core/IArcaneMain.h"
22#include "arcane/core/ISubDomain.h"
23#include "arcane/core/IModuleMng.h"
24#include "arcane/core/IModule.h"
25#include "arcane/core/IModuleMaster.h"
26#include "arcane/core/ServiceUtils.h"
27#include "arcane/core/IFactoryService.h"
28#include "arcane/core/IMeshFactory.h"
29#include "arcane/core/IPrimaryMesh.h"
30#include "arcane/core/IApplication.h"
31#include "arcane/core/ItemGroup.h"
32#include "arcane/core/ServiceBuilder.h"
33#include "arcane/core/IMeshMng.h"
34#include "arcane/core/MeshHandle.h"
35#include "arcane/core/MeshBuildInfo.h"
36
37#include "arcane/impl/internal/MeshFactoryMng.h"
38
39/*---------------------------------------------------------------------------*/
40/*---------------------------------------------------------------------------*/
41
42namespace Arcane
43{
44
45/*---------------------------------------------------------------------------*/
46/*---------------------------------------------------------------------------*/
47
48extern "C++" ARCANE_IMPL_EXPORT IArcaneMain*
49createArcaneMainBatch(const ApplicationInfo& app_info, IMainFactory* main_factory);
50extern "C++" IApplication* arcaneCreateApplication(IArcaneMain*);
51extern "C++" IVariableMng* arcaneCreateVariableMng(ISubDomain*);
52extern "C++" IModuleMng* arcaneCreateModuleMng(ISubDomain*);
53extern "C++" IEntryPointMng* arcaneCreateEntryPointMng(ISubDomain*);
54extern "C++" ARCANE_IMPL_EXPORT ITimeHistoryMng* arcaneCreateTimeHistoryMng2(ISubDomain*);
55extern "C++" ICaseMng* arcaneCreateCaseMng(ISubDomain*);
56extern "C++" ICaseDocument* arcaneCreateCaseDocument(ITraceMng*, const String& lang);
57extern "C++" ICaseDocument* arcaneCreateCaseDocument(ITraceMng*, IXmlDocumentHolder* doc);
58extern "C++" ITimeStats* arcaneCreateTimeStats(ITimerMng* timer_mng, ITraceMng* trm, const String& name);
59extern "C++" ITimeLoopMng* arcaneCreateTimeLoopMng(ISubDomain*);
60extern "C++" IServiceLoader* arcaneCreateServiceLoader();
61extern "C++" IServiceMng* arcaneCreateServiceMng(IBase*);
62extern "C++" ICheckpointMng* arcaneCreateCheckpointMng(ISubDomain*);
63extern "C++" IPropertyMng* arcaneCreatePropertyMng(ITraceMng*);
64extern "C++" Ref<IPropertyMng> arcaneCreatePropertyMngReference(ITraceMng*);
65extern "C++" IDataFactory* arcaneCreateDataFactory(IApplication*);
66extern "C++" Ref<IDataFactoryMng> arcaneCreateDataFactoryMngRef(IApplication*);
67extern "C++" ITraceMng* arcaneCreateTraceMng();
68extern "C++" ITraceMngPolicy* arcaneCreateTraceMngPolicy(IApplication*);
69extern "C++" ILoadBalanceMng* arcaneCreateLoadBalanceMng(ISubDomain*);
70
71extern "C++" ARCANE_CORE_EXPORT IModuleMaster*
72arcaneCreateModuleMaster(ISubDomain*);
73
74extern "C++" ARCANE_CORE_EXPORT ITimeLoop*
75arcaneCreateTimeLoop(IApplication* sm, const String& name);
76
77extern "C++" ARCANE_IMPL_EXPORT IIOMng*
78arcaneCreateIOMng(IParallelSuperMng*);
79
80extern "C++" ARCANE_IMPL_EXPORT IIOMng*
81arcaneCreateIOMng(IParallelMng*);
82
83namespace Accelerator
84{
85 extern "C++" ARCANE_IMPORT Ref<IAcceleratorMng>
86 arccoreCreateAcceleratorMngRef(ITraceMng* tm);
87}
88
89/*---------------------------------------------------------------------------*/
90/*---------------------------------------------------------------------------*/
91
92namespace
93{
95 String _getMeshFactoryName(bool is_amr)
96 {
97 if (is_amr)
98 return String("ArcaneDynamicAMRMeshFactory");
99 return String("ArcaneDynamicMeshFactory");
100 }
101} // namespace
102
103/*---------------------------------------------------------------------------*/
104/*---------------------------------------------------------------------------*/
105
106MainFactory::
107MainFactory()
108{
109}
110
111/*---------------------------------------------------------------------------*/
112/*---------------------------------------------------------------------------*/
113
114MainFactory::
115~MainFactory()
116{
117}
118
119/*---------------------------------------------------------------------------*/
120/*---------------------------------------------------------------------------*/
121
123createArcaneMain(const ApplicationInfo& app_info)
124{
125 return createArcaneMainBatch(app_info, this);
126}
127
128/*---------------------------------------------------------------------------*/
129/*---------------------------------------------------------------------------*/
130
133{
134 return arcaneCreateApplication(am);
135}
136
137/*---------------------------------------------------------------------------*/
138/*---------------------------------------------------------------------------*/
139
142{
143 return arcaneCreateVariableMng(sd);
144}
145
146/*---------------------------------------------------------------------------*/
147/*---------------------------------------------------------------------------*/
148
151{
152 return arcaneCreateModuleMng(sd);
153}
154
155/*---------------------------------------------------------------------------*/
156/*---------------------------------------------------------------------------*/
157
160{
161 return arcaneCreateEntryPointMng(sd);
162}
163
164/*---------------------------------------------------------------------------*/
165/*---------------------------------------------------------------------------*/
166
169{
170 ITimeHistoryMng* thm = 0;
171 thm = arcaneCreateTimeHistoryMng2(sd);
172 return thm;
173}
174
175/*---------------------------------------------------------------------------*/
176/*---------------------------------------------------------------------------*/
177
180{
181 return arcaneCreateCaseMng(sd);
182}
183
184/*---------------------------------------------------------------------------*/
185/*---------------------------------------------------------------------------*/
186
189{
190 ITimerMng* tm = sd->timerMng();
191 String name = String::format("Rank{0}", sd->subDomainId());
192 return arcaneCreateTimeStats(tm, sd->traceMng(), name);
193}
194
195/*---------------------------------------------------------------------------*/
196/*---------------------------------------------------------------------------*/
197
199createTimeStats(ITimerMng* tim, ITraceMng* trm, const String& name)
200{
201 return arcaneCreateTimeStats(tim, trm, name);
202}
203
204/*---------------------------------------------------------------------------*/
205/*---------------------------------------------------------------------------*/
206
209{
210 return arcaneCreateTimeLoopMng(sd);
211}
212
213/*---------------------------------------------------------------------------*/
214/*---------------------------------------------------------------------------*/
215
217createTimeLoop(IApplication* sm, const String& name)
218{
219 return arcaneCreateTimeLoop(sm, name);
220}
221
222/*---------------------------------------------------------------------------*/
223/*---------------------------------------------------------------------------*/
224
227{
228 return arcaneCreateIOMng(app->parallelSuperMng());
229}
230
231/*---------------------------------------------------------------------------*/
232/*---------------------------------------------------------------------------*/
233
236{
237 return arcaneCreateIOMng(pm);
238}
239
240/*---------------------------------------------------------------------------*/
241/*---------------------------------------------------------------------------*/
242
245{
246 return arcaneCreateServiceLoader();
247}
248
249/*---------------------------------------------------------------------------*/
250/*---------------------------------------------------------------------------*/
251
254{
255 return arcaneCreateServiceMng(base);
256}
257
258/*---------------------------------------------------------------------------*/
259/*---------------------------------------------------------------------------*/
260
263{
264 return arcaneCreateCheckpointMng(sd);
265}
266
267/*---------------------------------------------------------------------------*/
268/*---------------------------------------------------------------------------*/
269
272{
273 return arcaneCreatePropertyMng(sd->traceMng());
274}
275
276/*---------------------------------------------------------------------------*/
277/*---------------------------------------------------------------------------*/
278
281{
282 return arcaneCreatePropertyMngReference(sd->traceMng());
283}
284
285/*---------------------------------------------------------------------------*/
286/*---------------------------------------------------------------------------*/
287
290{
291 return arcaneCreateCaseDocument(sm->traceMng(), String());
292}
293
294/*---------------------------------------------------------------------------*/
295/*---------------------------------------------------------------------------*/
296
298createCaseDocument(IApplication* sm, const String& lang)
299{
300 return arcaneCreateCaseDocument(sm->traceMng(), lang);
301}
302
303/*---------------------------------------------------------------------------*/
304/*---------------------------------------------------------------------------*/
305
308{
309 return arcaneCreateCaseDocument(sm->traceMng(), doc);
310}
311
312/*---------------------------------------------------------------------------*/
313/*---------------------------------------------------------------------------*/
314
316createMesh(ISubDomain* sd, const String& name, eMeshAMRKind amr_type)
317{
318 return createMesh(sd, sd->parallelMng(), name, amr_type);
319}
320
321/*---------------------------------------------------------------------------*/
322/*---------------------------------------------------------------------------*/
323
325createMesh(ISubDomain* sd, const String& name, bool is_amr)
326{
327 return createMesh(sd, sd->parallelMng(), name, (is_amr ? eMeshAMRKind::Cell : eMeshAMRKind::None));
328}
329
330/*---------------------------------------------------------------------------*/
331/*---------------------------------------------------------------------------*/
332
334createMesh(ISubDomain* sd, IParallelMng* pm, const String& name, bool is_amr)
335{
336 return createMesh(sd, pm, name, (is_amr ? eMeshAMRKind::Cell : eMeshAMRKind::None));
337}
338
339/*---------------------------------------------------------------------------*/
340/*---------------------------------------------------------------------------*/
341
343createMesh(ISubDomain* sd, IParallelMng* pm, const String& name, eMeshAMRKind amr_type)
344{
345 String factory_name = _getMeshFactoryName(amr_type != eMeshAMRKind::None);
346 IMeshFactoryMng* mfm = sd->meshMng()->meshFactoryMng();
347 MeshBuildInfo build_info(name);
348 MeshKind mk(build_info.meshKind());
349 mk.setMeshAMRKind(amr_type);
350 build_info.addMeshKind(mk);
351 build_info.addFactoryName(factory_name);
352 build_info.addParallelMng(makeRef(pm));
353 return mfm->createMesh(build_info);
354}
355
356/*---------------------------------------------------------------------------*/
357/*---------------------------------------------------------------------------*/
358
360createMesh(ISubDomain* sd, const String& name)
361{
362 return createMesh(sd, sd->parallelMng(), name, eMeshAMRKind::None);
363}
364
365/*---------------------------------------------------------------------------*/
366/*---------------------------------------------------------------------------*/
367
369createMesh(ISubDomain* sd, IParallelMng* pm, const String& name)
370{
371 return createMesh(sd, pm, name, eMeshAMRKind::None);
372}
373
374/*---------------------------------------------------------------------------*/
375/*---------------------------------------------------------------------------*/
376
378createSubMesh(IMesh* mesh, const ItemGroup& group, const String& name)
379{
380 // Currently, sub-meshes of AMR meshes are not supported
381 bool is_amr = false;
382 String factory_name = _getMeshFactoryName(is_amr);
383 IMeshFactoryMng* mfm = mesh->meshMng()->meshFactoryMng();
384 MeshBuildInfo build_info(name);
385 build_info.addFactoryName(factory_name);
386 build_info.addParentGroup(group);
387 return mfm->createMesh(build_info);
388}
389
390/*---------------------------------------------------------------------------*/
391/*---------------------------------------------------------------------------*/
392
395{
396 return arcaneCreateDataFactory(sm);
397}
398
399/*---------------------------------------------------------------------------*/
400/*---------------------------------------------------------------------------*/
401
404{
405 return arcaneCreateDataFactoryMngRef(app);
406}
407
408/*---------------------------------------------------------------------------*/
409/*---------------------------------------------------------------------------*/
410
413{
414 return Accelerator::arccoreCreateAcceleratorMngRef(tm);
415}
416
417/*---------------------------------------------------------------------------*/
418/*---------------------------------------------------------------------------*/
419
422{
423 return arcaneCreateTraceMng();
424}
425
426/*---------------------------------------------------------------------------*/
427/*---------------------------------------------------------------------------*/
428
431{
432 return arcaneCreateTraceMngPolicy(app);
433}
434
435/*---------------------------------------------------------------------------*/
436/*---------------------------------------------------------------------------*/
437
440{
441 IModuleMaster* mm = arcaneCreateModuleMaster(sd);
442 IModule* m = dynamic_cast<IModule*>(mm);
443 if (!m)
444 ARCANE_FATAL("module is not a derived class of 'IModule'");
445 sd->moduleMng()->addModule(makeRef(m));
446 return mm;
447}
448
449/*---------------------------------------------------------------------------*/
450/*---------------------------------------------------------------------------*/
451
454{
455 return arcaneCreateLoadBalanceMng(sd);
456}
457
458/*---------------------------------------------------------------------------*/
459/*---------------------------------------------------------------------------*/
460
461} // End namespace Arcane
462
463/*---------------------------------------------------------------------------*/
464/*---------------------------------------------------------------------------*/
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
Application information.
Application interface.
virtual IParallelSuperMng * parallelSuperMng()=0
Supervisory parallelism manager.
Interface of the code management class.
Definition IArcaneMain.h:55
Interface of the base class for main arcane objects.
Definition IBase.h:32
virtual ITraceMng * traceMng() const =0
Trace manager.
Interface of a class managing an XML document of the dataset.
Case manager interface.
Definition ICaseMng.h:57
Interface of the checkpoint information manager.
Interface of a data factory.
Interface for the entry point manager.
Interface of the input/output manager.
Definition IIOMng.h:37
Interface for registering variables for load balancing.
Factory for Arcane classes.
Interface of the mesh factory manager.
virtual IPrimaryMesh * createMesh(const MeshBuildInfo &build_info)=0
Creates a mesh or a sub-mesh.
virtual IMeshFactoryMng * meshFactoryMng() const =0
Mesh factory associated with this manager.
Interface of the main module.
Module manager interface.
Definition IModuleMng.h:39
virtual void addModule(Ref< IModule > m)=0
Adds module m to the manager.
Interface of a module.
Definition IModule.h:40
Interface of the parallelism manager for a subdomain.
Abstract class of the parallelism supervisor.
Interface of the property manager.
Service loading interface.
Service manager interface.
Definition IServiceMng.h:32
Interface of the subdomain manager.
Definition ISubDomain.h:75
virtual IModuleMng * moduleMng()=0
Returns the module manager.
virtual Int32 subDomainId() const =0
Subdomain ID associated with this manager.
virtual IParallelMng * parallelMng()=0
Returns the parallelism manager.
virtual IMeshMng * meshMng() const =0
Returns the mesh manager.
virtual ITimerMng * timerMng() const =0
Returns the timer manager.
Class managing a history of values.
Interface for the time loop manager.
Interface of a time loop.
Definition ITimeLoop.h:33
Interface managing execution time statistics.
Definition ITimeStats.h:44
Interface of a timer manager.
Definition ITimerMng.h:50
Interface for the configuration manager of a trace manager.
Variable manager interface.
Manager of a DOM document.
Mesh entity group.
Definition ItemGroup.h:51
IMesh * createSubMesh(IMesh *mesh, const ItemGroup &group, const String &name) override
Creates a sub-mesh for the mesh mesh, named name.
IVariableMng * createVariableMng(ISubDomain *) override
Creates an instance of the variable manager.
ITraceMng * createTraceMng() override
Creates a trace manager.
Ref< IPropertyMng > createPropertyMngReference(ISubDomain *) override
Creates an instance of the property manager.
ITraceMngPolicy * createTraceMngPolicy(IApplication *app) override
Creates a configuration manager for a trace manager.
IIOMng * createIOMng(IApplication *) override
Creates an instance of the I/O manager.
ICaseMng * createCaseMng(ISubDomain *) override
Creates an instance of the case manager.
ITimeHistoryMng * createTimeHistoryMng(ISubDomain *) override
Creates an instance of the time history manager.
ICheckpointMng * createCheckpointMng(ISubDomain *) override
Creates an instance of the checkpoint manager.
IEntryPointMng * createEntryPointMng(ISubDomain *) override
Creates an instance of the entry point manager.
ILoadBalanceMng * createLoadBalanceMng(ISubDomain *sd) override
Creates a description manager for load balancing.
IPropertyMng * createPropertyMng(ISubDomain *) override
Creates an instance of the property manager.
IServiceMng * createServiceMng(IBase *) override
Creates an instance of the service manager.
IApplication * createApplication(IArcaneMain *) override
Creates an instance of a supervisor.
IArcaneMain * createArcaneMain(const ApplicationInfo &app_info) override
Creates an instance of IArcaneMain.
ICaseDocument * createCaseDocument(IApplication *) override
Creates an instance of a case document.
IPrimaryMesh * createMesh(ISubDomain *sub_domain, const String &name) override
Creates or retrieves a mesh.
Ref< IAcceleratorMng > createAcceleratorMngRef(ITraceMng *tm) override
Creates a manager for accelerators.
IDataFactory * createDataFactory(IApplication *) override
Creates a factory for data.
Ref< IDataFactoryMng > createDataFactoryMngRef(IApplication *) override
Creates a factory manager for data.
IServiceLoader * createServiceLoader() override
Creates an instance of the service loader.
ITimeStats * createTimeStats(ISubDomain *) override
Creates an instance of execution time statistics.
IModuleMng * createModuleMng(ISubDomain *) override
Creates an instance of the module manager.
ITimeLoop * createTimeLoop(IApplication *sm, const String &name) override
Creates a time loop named name.
IModuleMaster * createModuleMaster(ISubDomain *sd) override
Creates the master module for the sub-domain sd.
ITimeLoopMng * createTimeLoopMng(ISubDomain *) override
Creates an instance of the time loop manager.
Parameters necessary for building a mesh.
const MeshKind meshKind() const
Mesh characteristics.
MeshBuildInfo & addParallelMng(Ref< IParallelMng > pm)
Sets the parallelism manager to create the mesh.
MeshBuildInfo & addParentGroup(const ItemGroup &parent_group)
Sets the cell group for a sub-mesh.
MeshBuildInfo & addMeshKind(const MeshKind &v)
Sets the mesh characteristics.
MeshBuildInfo & addFactoryName(const String &factory_name)
Sets the factory name to create this mesh.
Characteristics of a mesh.
Definition MeshKind.h:113
Reference to an instance.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
auto makeRef(InstanceType *t) -> Ref< InstanceType >
Creates a reference on a pointer.
eMeshAMRKind
AMR mesh type.
Definition MeshKind.h:49
@ Cell
The mesh is AMR by cell.
Definition MeshKind.h:53
@ None
The mesh is not AMR.
Definition MeshKind.h:51