Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
AlephFactory.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2022 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/* Fabriques pour Aleph. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/aleph/IAlephFactory.h"
15#include "arcane/ServiceBuilder.h"
16
17/*---------------------------------------------------------------------------*/
18/*---------------------------------------------------------------------------*/
19
20namespace Arcane
21{
22
23/*---------------------------------------------------------------------------*/
24/*---------------------------------------------------------------------------*/
25
27{
28 public:
29 FactoryImpl(const String& name)
30 : m_name(name)
31 , m_initialized(false)
32 {}
34 {
35 }
36
37 public:
38 void setFactory(Ref<IAlephFactoryImpl> factory)
39 {
40 m_factory = factory;
41 }
42 IAlephFactoryImpl* factory() { return m_factory.get(); }
43 const String& name() const { return m_name; }
44
45 private:
46 Ref<IAlephFactoryImpl> m_factory;
47 String m_name;
48
49 public:
50 bool m_initialized;
51};
52
53/*---------------------------------------------------------------------------*/
54/*---------------------------------------------------------------------------*/
55
56/******************************************************************************
57 * IAlephFactory::IAlephFactory
58 *****************************************************************************/
59AlephFactory::
60AlephFactory(IApplication* app, ITraceMng* tm)
62{
63 // Liste des implémentations possibles.
64 // 0 est le choix automatique qui doit aller vers une des bibliothèques suivantes:
65 m_impl_map.insert(std::make_pair(1, new FactoryImpl("Sloop")));
66 m_impl_map.insert(std::make_pair(2, new FactoryImpl("Hypre")));
67 m_impl_map.insert(std::make_pair(3, new FactoryImpl("Trilinos")));
68 m_impl_map.insert(std::make_pair(4, new FactoryImpl("Cuda")));
69 m_impl_map.insert(std::make_pair(5, new FactoryImpl("PETSc")));
71 // Pour chaque implémentation possible,
72 // créé la fabrique correspondante si elle est disponible.
73 for (const auto& i : m_impl_map) {
74 FactoryImpl* implementation = i.second;
75 const String& name = implementation->name();
76 debug() << "\33[1;34m\t[AlephFactory] Adding " << name << " library..."
77 << "\33[0m";
78 auto factory = sb.createReference(name + "AlephFactory", SB_AllowNull);
79 implementation->setFactory(factory);
80 }
81 debug() << "\33[1;34m\t[AlephFactory] done"
82 << "\33[0m";
83}
84
85/*---------------------------------------------------------------------------*/
86/*---------------------------------------------------------------------------*/
87
88AlephFactory::
89~AlephFactory()
90{
91 for (const auto& i : m_impl_map)
92 delete i.second;
93}
94
95/*---------------------------------------------------------------------------*/
96/*---------------------------------------------------------------------------*/
97
98IAlephFactoryImpl* AlephFactory::
99_getFactory(Integer solver_index)
100{
101 FactoryImplMap::const_iterator ci = m_impl_map.find(solver_index);
102 if (ci == m_impl_map.end())
103 ARCANE_FATAL("Invalid solver index '{0}' for aleph factory", solver_index);
104 FactoryImpl* implementation = ci->second;
105 IAlephFactoryImpl* factory = implementation->factory();
106 if (!factory)
107 throw NotSupportedException(A_FUNCINFO,
108 String::format("Implementation for '{0}' not available",
109 implementation->name()));
110 // Si la fabrique de l'implémentation considérée n'a pas
111 // été initialisée, on le fait maintenant
112 if (!implementation->m_initialized) {
113 debug() << "\33[1;34m\t\t[_getFactory] initializing solver_index="
114 << solver_index << " ..."
115 << "\33[0m";
116 implementation->m_initialized = true;
117 factory->initialize();
118 }
119 return factory;
120}
121
122/*---------------------------------------------------------------------------*/
123/*---------------------------------------------------------------------------*/
124
125bool AlephFactory::
126hasSolverImplementation(Integer solver_index)
127{
128 FactoryImplMap::const_iterator ci = m_impl_map.find(solver_index);
129 if (ci == m_impl_map.end())
130 return false;
131 FactoryImpl* implementation = ci->second;
132 IAlephFactoryImpl* factory = implementation->factory();
133 if (!factory)
134 return false;
135 return true;
136}
137
138/*---------------------------------------------------------------------------*/
139/*---------------------------------------------------------------------------*/
140
141IAlephTopology* AlephFactory::
142GetTopology(AlephKernel* kernel, Integer index, Integer nb_row_size)
143{
144 debug() << "\33[1;34m\t\t[IAlephFactory::GetTopology] Switch=" << kernel->underlyingSolver() << "\33[0m";
145 auto f = _getFactory(kernel->underlyingSolver());
146 return f->createTopology(traceMng(), kernel, index, nb_row_size);
147}
148
149/*---------------------------------------------------------------------------*/
150/*---------------------------------------------------------------------------*/
151
152IAlephVector* AlephFactory::
153GetVector(AlephKernel* kernel, Integer index)
154{
155 debug() << "\33[1;34m\t\t[AlephFactory::GetVector] Switch=" << kernel->underlyingSolver() << "\33[0m";
156 auto f = _getFactory(kernel->underlyingSolver());
157 return f->createVector(traceMng(), kernel, index);
158}
159
160/*---------------------------------------------------------------------------*/
161/*---------------------------------------------------------------------------*/
162
163IAlephMatrix* AlephFactory::
164GetMatrix(AlephKernel* kernel, Integer index)
165{
166 debug() << "\33[1;34m\t\t[AlephFactory::GetMatrix] Switch=" << kernel->underlyingSolver() << "\33[0m";
167 auto f = _getFactory(kernel->underlyingSolver());
168 return f->createMatrix(traceMng(), kernel, index);
169}
170
171/*---------------------------------------------------------------------------*/
172/*---------------------------------------------------------------------------*/
173
174} // End namespace Arcane
175
176/*---------------------------------------------------------------------------*/
177/*---------------------------------------------------------------------------*/
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
Interface d'une fabrique d'implémentation pour Aleph.
Interface de l'application.
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Definition Lima.cc:120
Interface du gestionnaire de traces.
Chaîne de caractères unicode.
ITraceMng * traceMng() const
Gestionnaire de trace.
TraceMessageDbg debug(Trace::eDebugLevel=Trace::Medium) const
Flot pour un message de debug.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
@ SB_AllowNull
Autorise l'absence du service.