Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
AlephFactory.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/* AlephFactory.cc (C) 2010-2022 */
9/* */
10/* Factories for Aleph. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/aleph/IAlephFactory.h"
15#include "arcane/core/ServiceBuilder.h"
16
17/*---------------------------------------------------------------------------*/
18/*---------------------------------------------------------------------------*/
19
20namespace Arcane
21{
22
23/*---------------------------------------------------------------------------*/
24/*---------------------------------------------------------------------------*/
25
27{
28 public:
29
30 FactoryImpl(const String& name)
31 : m_name(name)
32 , m_initialized(false)
33 {}
34 ~FactoryImpl()
35 {
36 }
37
38 public:
39
40 void setFactory(Ref<IAlephFactoryImpl> factory)
41 {
42 m_factory = factory;
43 }
44 IAlephFactoryImpl* factory() { return m_factory.get(); }
45 const String& name() const { return m_name; }
46
47 private:
48
49 Ref<IAlephFactoryImpl> m_factory;
50 String m_name;
51
52 public:
53
54 bool m_initialized;
55};
56
57/*---------------------------------------------------------------------------*/
58/*---------------------------------------------------------------------------*/
59
60/******************************************************************************
61 * IAlephFactory::IAlephFactory
62 *****************************************************************************/
63AlephFactory::
64AlephFactory(IApplication* app, ITraceMng* tm)
65: IAlephFactory(tm)
66{
67 // List of possible implementations.
68 // 0 is the automatic choice which must go to one of the following libraries:
69 m_impl_map.insert(std::make_pair(1, new FactoryImpl("Sloop")));
70 m_impl_map.insert(std::make_pair(2, new FactoryImpl("Hypre")));
71 m_impl_map.insert(std::make_pair(3, new FactoryImpl("Trilinos")));
72 m_impl_map.insert(std::make_pair(4, new FactoryImpl("Cuda")));
73 m_impl_map.insert(std::make_pair(5, new FactoryImpl("PETSc")));
75 // For each possible implementation,
76 // create the corresponding factory if it is available.
77 for (const auto& i : m_impl_map) {
78 FactoryImpl* implementation = i.second;
79 const String& name = implementation->name();
80 debug() << "\33[1;34m\t[AlephFactory] Adding " << name << " library..."
81 << "\33[0m";
82 auto factory = sb.createReference(name + "AlephFactory", SB_AllowNull);
83 implementation->setFactory(factory);
84 }
85 debug() << "\33[1;34m\t[AlephFactory] done"
86 << "\33[0m";
87}
88
89/*---------------------------------------------------------------------------*/
90/*---------------------------------------------------------------------------*/
91
92AlephFactory::
93~AlephFactory()
94{
95 for (const auto& i : m_impl_map)
96 delete i.second;
97}
98
99/*---------------------------------------------------------------------------*/
100/*---------------------------------------------------------------------------*/
101
102IAlephFactoryImpl* AlephFactory::
103_getFactory(Integer solver_index)
104{
105 FactoryImplMap::const_iterator ci = m_impl_map.find(solver_index);
106 if (ci == m_impl_map.end())
107 ARCANE_FATAL("Invalid solver index '{0}' for aleph factory", solver_index);
108 FactoryImpl* implementation = ci->second;
109 IAlephFactoryImpl* factory = implementation->factory();
110 if (!factory)
111 throw NotSupportedException(A_FUNCINFO,
112 String::format("Implementation for '{0}' not available",
113 implementation->name()));
114 // If the factory of the considered implementation has not been initialized, we do it now
115 if (!implementation->m_initialized) {
116 debug() << "\33[1;34m\t\t[_getFactory] initializing solver_index="
117 << solver_index << " ..."
118 << "\33[0m";
119 implementation->m_initialized = true;
120 factory->initialize();
121 }
122 return factory;
123}
124
125/*---------------------------------------------------------------------------*/
126/*---------------------------------------------------------------------------*/
127
128bool AlephFactory::
129hasSolverImplementation(Integer solver_index)
130{
131 FactoryImplMap::const_iterator ci = m_impl_map.find(solver_index);
132 if (ci == m_impl_map.end())
133 return false;
134 FactoryImpl* implementation = ci->second;
135 IAlephFactoryImpl* factory = implementation->factory();
136 if (!factory)
137 return false;
138 return true;
139}
140
141/*---------------------------------------------------------------------------*/
142/*---------------------------------------------------------------------------*/
143
144IAlephTopology* AlephFactory::
145GetTopology(AlephKernel* kernel, Integer index, Integer nb_row_size)
146{
147 debug() << "\33[1;34m\t\t[IAlephFactory::GetTopology] Switch=" << kernel->underlyingSolver() << "\33[0m";
148 auto f = _getFactory(kernel->underlyingSolver());
149 return f->createTopology(traceMng(), kernel, index, nb_row_size);
150}
151
152/*---------------------------------------------------------------------------*/
153/*---------------------------------------------------------------------------*/
154
155IAlephVector* AlephFactory::
156GetVector(AlephKernel* kernel, Integer index)
157{
158 debug() << "\33[1;34m\t\t[AlephFactory::GetVector] Switch=" << kernel->underlyingSolver() << "\33[0m";
159 auto f = _getFactory(kernel->underlyingSolver());
160 return f->createVector(traceMng(), kernel, index);
161}
162
163/*---------------------------------------------------------------------------*/
164/*---------------------------------------------------------------------------*/
165
166IAlephMatrix* AlephFactory::
167GetMatrix(AlephKernel* kernel, Integer index)
168{
169 debug() << "\33[1;34m\t\t[AlephFactory::GetMatrix] Switch=" << kernel->underlyingSolver() << "\33[0m";
170 auto f = _getFactory(kernel->underlyingSolver());
171 return f->createMatrix(traceMng(), kernel, index);
172}
173
174/*---------------------------------------------------------------------------*/
175/*---------------------------------------------------------------------------*/
176
177} // End namespace Arcane
178
179/*---------------------------------------------------------------------------*/
180/*---------------------------------------------------------------------------*/
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
Interface of an implementation factory for Aleph.
Application interface.
Reference to an instance.
Utility class for instantiating a service of a given interface.
TraceMessageDbg debug(Trace::eDebugLevel=Trace::Medium) const
Flow for a debug message.
ITraceMng * traceMng() const
Trace manager.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
@ SB_AllowNull
Allows the service to be absent.
Int32 Integer
Type representing an integer.