14#include "arcane/utils/ApplicationInfo.h"
15#include "arcane/utils/CommandLineArguments.h"
18#include "arcane/core/ServiceBuilder.h"
19#include "arcane/core/ICaseMeshService.h"
20#include "arcane/core/ICaseMeshReader.h"
21#include "arcane/core/IMeshBuilder.h"
22#include "arcane/core/IPrimaryMesh.h"
23#include "arcane/core/IItemFamily.h"
24#include "arcane/core/IMeshPartitionerBase.h"
25#include "arcane/core/IVariableMng.h"
26#include "arcane/core/IMeshModifier.h"
27#include "arcane/core/IMeshUtilities.h"
28#include "arcane/core/IParallelMng.h"
29#include "arcane/core/MeshBuildInfo.h"
30#include "arcane/core/IMeshMng.h"
31#include "arcane/core/IMeshFactoryMng.h"
32#include "arcane/core/IGhostLayerMng.h"
33#include "arcane/core/MeshPartInfo.h"
34#include "arcane/core/IMeshSubdivider.h"
35#include "arcane/core/internal/StringVariableReplace.h"
37#include "arcane/impl/ArcaneCaseMeshService_axl.h"
77 void _initializeVariables();
78 void _doInitialPartition();
79 void _doInitialPartition2(
const String& name);
80 void _setGhostLayerInfos();
87ArcaneCaseMeshService::
90, m_sub_domain(
sbi.subDomain())
103 info() <<
"Creating mesh from 'ArcaneCaseMeshService'";
112 ARCANE_FATAL(
"In '{0}': one and one only of <{1}> or <{2}> has to be specified",
113 options()->configList()->xpathFullName(),
114 options()->generator.rootTagName(),
118 if (m_mesh_file_name.
empty())
120 m_mesh_file_name,
options()->filename.xpathFullName());
126 if (m_mesh_builder_ref.isNull())
127 ARCANE_FATAL(
"No 'IMeshBuilder' created by specific reader");
130 m_mesh_builder_ref = _createBuilderFromFile(
read_info);
132 m_mesh_builder = m_mesh_builder_ref.get();
135 m_mesh_builder =
options()->generator();
144 m_partitioner_name =
options()->partitioner();
148 build_info.addFactoryName(
"ArcaneDynamicMeshFactory");
161 _checkMeshCreationAndAllocation(
false);
165 _setGhostLayerInfos();
177 _checkMeshCreationAndAllocation(
true);
180 if (!m_partitioner_name.
empty())
181 _doInitialPartition();
190 _checkMeshCreationAndAllocation(
true);
196 _initializeVariables();
202void ArcaneCaseMeshService::
206 ARCANE_FATAL(
"Mesh is not created. You should call createMesh() before");
208 ARCANE_FATAL(
"Mesh is not allocated. You should call initializeMesh() before");
214void ArcaneCaseMeshService::
215_fillReadInfo(CaseMeshReaderReadInfo& read_info)
217 read_info.setFileName(m_mesh_file_name);
223 std::size_t extension_pos = fview.find_last_of(
'.');
224 if (extension_pos!=std::string_view::npos){
225 fview.remove_prefix(extension_pos+1);
228 read_info.setFormat(extension);
231 String partitioner_name =
options()->partitioner();
232 bool use_internal_partitioner = partitioner_name !=
"External";
233 if (use_internal_partitioner)
234 m_partitioner_name = partitioner_name;
236 info() <<
"Mesh filename=" << m_mesh_file_name
237 <<
" extension=" << read_info.format() <<
" partitioner=" << partitioner_name;
239 read_info.setParallelRead(use_internal_partitioner);
245Ref<IMeshBuilder> ArcaneCaseMeshService::
246_createBuilderFromFile(
const CaseMeshReaderReadInfo& read_info)
253 ServiceBuilder<ICaseMeshReader> builder(m_sub_domain);
254 UniqueArray<Ref<ICaseMeshReader>> mesh_readers(builder.createAllInstances());
256 for(
auto& mesh_reader_ref : mesh_readers ){
257 ICaseMeshReader* mesh_reader = mesh_reader_ref.get();
258 Ref<IMeshBuilder> builder = mesh_reader->createBuilder(read_info);
259 if (!builder.isNull())
266 builder.getServicesNames(valid_names);
267 String available_readers = String::join(
", ",valid_names);
268 ARCANE_FATAL(
"The mesh reader required for format '{0}' is not available."
269 "The following reader services are available: {1}",
270 read_info.format(),available_readers);
276void ArcaneCaseMeshService::
282 const bool use_partitioner_tester =
false;
283 String test_service =
"MeshPartitionerTester";
284 if (use_partitioner_tester) {
286 Int64 min_nb_cell = m_mesh->
parallelMng()->reduce(Parallel::ReduceMin,nb_cell);
287 info() <<
"Min nb cell=" << min_nb_cell;
289 _doInitialPartition2(test_service);
291 info() <<
"Mesh name=" << m_mesh->
name() <<
" have cells. Do not use " << test_service;
294 info() <<
"No basic partition first needed";
295 _doInitialPartition2(m_partitioner_name);
301void ArcaneCaseMeshService::
302_doInitialPartition2(
const String& partitioner_name)
304 info() <<
"Doing initial partitioning service=" << partitioner_name;
308 ServiceBuilder<IMeshPartitionerBase> sbuilder(m_sub_domain);
309 auto mesh_partitioner = sbuilder.createReference(partitioner_name,m_mesh);
311 IMesh* mesh = m_mesh;
313 mesh->modifier()->setDynamic(
true);
314 mesh->utilities()->partitionAndExchangeMeshWithReplication(mesh_partitioner.get(),
true);
315 mesh->modifier()->setDynamic(is_dynamic);
321void ArcaneCaseMeshService::
322_initializeVariables()
325 const auto& vars_opt =
options()->initialization().variable;
326 UniqueArray<String> errors;
327 for( Integer i=0, n=vars_opt.size(); i<n; ++i ){
328 const auto& o = vars_opt[i];
329 String var_name = o.
name;
330 String group_name = o.group;
331 String value = o.value;
332 info() <<
"Initialize variable=" << var_name <<
" group=" << group_name <<
" value=" << value;
333 IVariable* var = vm->findMeshVariable(m_mesh,var_name);
335 errors.add(String::format(
"No variable named '{0}' exists",var_name));
342 IItemFamily* var_family = var->itemFamily();
344 errors.add(String::format(
"Variable '{0}' has no family",var->fullName()));
348 ItemGroup group = var_family->findGroup(group_name);
350 errors.add(String::format(
"No group named '{0}' exists in family '{1}'",
351 group_name,var_family->name()));
355 bool ret = var->initialize(group,value);
357 errors.add(String::format(
"Bad value '{0}' for initializing variable '{1}'",
358 value,var->fullName()));
362 if (!errors.empty()){
363 for( String s : errors )
364 pinfo() <<
"ERROR: " << s;
365 ARCANE_FATAL(
"Variable initialization failed for option '{0}'",
366 vars_opt.xpathFullName());
373void ArcaneCaseMeshService::
384 if (nb_ghost_layer>=0){
385 info() <<
"Set number of ghost layers to '" << nb_ghost_layer <<
"' from caseoption";
386 gm->setNbGhostLayer(nb_ghost_layer);
390 if (builder_version>=0){
391 info() <<
"Set ghostlayer builder version to '" << builder_version <<
"' from caseoption";
392 gm->setBuilderVersion(builder_version);
399ARCANE_REGISTER_SERVICE_ARCANECASEMESHSERVICE(ArcaneCaseMeshService,
400 ArcaneCaseMeshService);
#define ARCANE_CHECK_POINTER(ptr)
Macro retournant le pointeur ptr s'il est non nul ou lancant une exception s'il est nul.
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
Ce fichier contient les différentes fabriques de services et macro pour enregistrer les services.
Generation de la classe de base du Service.
CaseOptionsArcaneCaseMeshService * options() const
Options du jeu de données du service.
Service Arcane un maillage du jeu de données.
void createMesh(const String &default_name) override
Créé le maillage avec le nom name.
void allocateMeshItems() override
Alloue les éléments du maillage.
void partitionMesh() override
Partitionne le maillage.
void applyAdditionalOperations() override
Applique les opérations après tout le reste.
Informations nécessaires pour la lecture d'un fichier de maillage.
bool isPresent() const
Retourne true si l'option est présente.
virtual String name() const
Retourne le nom de l'élément dans le langage du jeu de données.
virtual String name() const =0
Nom du maillage.
virtual Integer nbCell()=0
Nombre de mailles du maillage.
Interface d'un service de création/lecture du maillage.
virtual void allocateMeshItems(IPrimaryMesh *pm)=0
Alloue les entités du maillage géré par ce service.
virtual void fillMeshBuildInfo(MeshBuildInfo &build_info)=0
Remplit build_info avec les informations nécessaires pour créer le maillage.
virtual void subdivideMesh(IPrimaryMesh *mesh)=0
Subdivise le maillage mesh.
virtual IParallelMng * parallelMng()=0
Gestionnaire de parallèlisme.
virtual bool isAllocated()=0
Vrai si le maillage est allouée.
virtual IGhostLayerMng * ghostLayerMng() const =0
Gestionnare de couche fantômes associé
virtual bool isDynamic() const =0
Indique si le maillage est dynamique (peut évoluer)
virtual const MeshPartInfo & meshPartInfo() const =0
Informations sur les parties du maillage.
Interface du gestionnaire d'un sous-domaine.
virtual const ApplicationInfo & applicationInfo() const =0
Informations sur l'exécutable.
virtual IVariableMng * variableMng()=0
Retourne le gestionnaire de variables.
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Paramètres nécessaires à la construction d'un maillage.
Structure contenant les informations pour créer un service.
static String replaceWithCmdLineArgs(const ParameterList ¶meter_list, const String &string_with_symbols)
Chaîne de caractères unicode.
bool empty() const
Vrai si la chaîne est vide (nulle ou "")
std::string_view toStdStringView() const
Retourne une vue de la STL sur la chaîne actuelle.
TraceMessage pinfo() const
Flot pour un message d'information en parallèle.
TraceMessage info() const
Flot pour un message d'information.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
UniqueArray< String > StringUniqueArray
Tableau dynamique à une dimension de chaînes de caractères.
Int32 Integer
Type représentant un entier.