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/IMeshUniqueIdMng.h"
36#include "arcane/core/internal/StringVariableReplace.h"
38#include "arcane/impl/ArcaneCaseMeshService_axl.h"
78 void _initializeVariables();
79 void _doInitialPartition();
80 void _doInitialPartition2(
const String& name);
81 void _setGhostLayerInfos();
83 void _setUniqueIdNumberingVersion();
89ArcaneCaseMeshService::
92, m_sub_domain(
sbi.subDomain())
105 info() <<
"Creating mesh from 'ArcaneCaseMeshService'";
114 ARCANE_FATAL(
"In '{0}': one and one only of <{1}> or <{2}> has to be specified",
115 options()->configList()->xpathFullName(),
116 options()->generator.rootTagName(),
120 if (m_mesh_file_name.
empty())
122 m_mesh_file_name,
options()->filename.xpathFullName());
128 if (m_mesh_builder_ref.isNull())
129 ARCANE_FATAL(
"No 'IMeshBuilder' created by specific reader");
132 m_mesh_builder_ref = _createBuilderFromFile(
read_info);
134 m_mesh_builder = m_mesh_builder_ref.get();
137 m_mesh_builder =
options()->generator();
146 m_partitioner_name =
options()->partitioner();
150 build_info.addFactoryName(
"ArcaneDynamicMeshFactory");
163 _checkMeshCreationAndAllocation(
false);
167 _setGhostLayerInfos();
168 _setUniqueIdNumberingVersion();
179 _checkMeshCreationAndAllocation(
true);
182 if (!m_partitioner_name.
empty())
183 _doInitialPartition();
192 _checkMeshCreationAndAllocation(
true);
198 _initializeVariables();
204void ArcaneCaseMeshService::
208 ARCANE_FATAL(
"Mesh is not created. You should call createMesh() before");
210 ARCANE_FATAL(
"Mesh is not allocated. You should call initializeMesh() before");
216void ArcaneCaseMeshService::
217_fillReadInfo(CaseMeshReaderReadInfo& read_info)
219 read_info.setFileName(m_mesh_file_name);
225 std::size_t extension_pos = fview.find_last_of(
'.');
226 if (extension_pos!=std::string_view::npos){
227 fview.remove_prefix(extension_pos+1);
230 read_info.setFormat(extension);
233 String partitioner_name =
options()->partitioner();
234 bool use_internal_partitioner = partitioner_name !=
"External";
235 if (use_internal_partitioner)
236 m_partitioner_name = partitioner_name;
238 info() <<
"Mesh filename=" << m_mesh_file_name
239 <<
" extension=" << read_info.format() <<
" partitioner=" << partitioner_name;
241 read_info.setParallelRead(use_internal_partitioner);
247Ref<IMeshBuilder> ArcaneCaseMeshService::
248_createBuilderFromFile(
const CaseMeshReaderReadInfo& read_info)
255 ServiceBuilder<ICaseMeshReader> builder(m_sub_domain);
256 UniqueArray<Ref<ICaseMeshReader>> mesh_readers(builder.createAllInstances());
258 for(
auto& mesh_reader_ref : mesh_readers ){
259 ICaseMeshReader* mesh_reader = mesh_reader_ref.get();
260 Ref<IMeshBuilder> builder = mesh_reader->createBuilder(read_info);
261 if (!builder.isNull())
268 builder.getServicesNames(valid_names);
269 String available_readers = String::join(
", ",valid_names);
270 ARCANE_FATAL(
"The mesh reader required for format '{0}' is not available."
271 "The following reader services are available: {1}",
272 read_info.format(),available_readers);
278void ArcaneCaseMeshService::
284 const bool use_partitioner_tester =
false;
285 String test_service =
"MeshPartitionerTester";
286 if (use_partitioner_tester) {
288 Int64 min_nb_cell = m_mesh->
parallelMng()->reduce(Parallel::ReduceMin,nb_cell);
289 info() <<
"Min nb cell=" << min_nb_cell;
291 _doInitialPartition2(test_service);
293 info() <<
"Mesh name=" << m_mesh->
name() <<
" have cells. Do not use " << test_service;
296 info() <<
"No basic partition first needed";
297 _doInitialPartition2(m_partitioner_name);
303void ArcaneCaseMeshService::
304_doInitialPartition2(
const String& partitioner_name)
306 info() <<
"Doing initial partitioning service=" << partitioner_name;
310 ServiceBuilder<IMeshPartitionerBase> sbuilder(m_sub_domain);
311 auto mesh_partitioner = sbuilder.createReference(partitioner_name,m_mesh);
313 IMesh* mesh = m_mesh;
315 mesh->modifier()->setDynamic(
true);
316 mesh->utilities()->partitionAndExchangeMeshWithReplication(mesh_partitioner.get(),
true);
317 mesh->modifier()->setDynamic(is_dynamic);
323void ArcaneCaseMeshService::
324_initializeVariables()
327 const auto& vars_opt =
options()->initialization().variable;
328 UniqueArray<String> errors;
329 for( Integer i=0, n=vars_opt.size(); i<n; ++i ){
330 const auto& o = vars_opt[i];
331 String var_name = o.
name;
332 String group_name = o.group;
333 String value = o.value;
334 info() <<
"Initialize variable=" << var_name <<
" group=" << group_name <<
" value=" << value;
335 IVariable* var = vm->findMeshVariable(m_mesh,var_name);
337 errors.add(String::format(
"No variable named '{0}' exists",var_name));
344 IItemFamily* var_family = var->itemFamily();
346 errors.add(String::format(
"Variable '{0}' has no family",var->fullName()));
350 ItemGroup group = var_family->findGroup(group_name);
352 errors.add(String::format(
"No group named '{0}' exists in family '{1}'",
353 group_name,var_family->name()));
357 bool ret = var->initialize(group,value);
359 errors.add(String::format(
"Bad value '{0}' for initializing variable '{1}'",
360 value,var->fullName()));
364 if (!errors.empty()){
365 for( String s : errors )
366 pinfo() <<
"ERROR: " << s;
367 ARCANE_FATAL(
"Variable initialization failed for option '{0}'",
368 vars_opt.xpathFullName());
375void ArcaneCaseMeshService::
386 if (nb_ghost_layer >= 0) {
387 info() <<
"Set number of ghost layers to '" << nb_ghost_layer <<
"' from caseoption";
388 gm->setNbGhostLayer(nb_ghost_layer);
392 if (builder_version >= 0) {
393 info() <<
"Set ghostlayer builder version to '" << builder_version <<
"' from caseoption";
394 gm->setBuilderVersion(builder_version);
401void ArcaneCaseMeshService::
402_setUniqueIdNumberingVersion()
407 if (
options()->faceNumberingVersion.isPresent()) {
409 info() <<
"Set face uniqueId numbering version to '" << v <<
"' from caseoption";
411 mum->setFaceBuilderVersion(v);
418ARCANE_REGISTER_SERVICE_ARCANECASEMESHSERVICE(ArcaneCaseMeshService,
419 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.
const Type & value() const
Retourne la valeur de l'option.
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 IMeshUniqueIdMng * meshUniqueIdMng() const =0
Gestionnare de la numérotation des identifiants uniques.
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.