Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
MeshGeneratorService.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/* MeshGeneratorService.cc (C) 2000-2020 */
9/* */
10/* Mesh generation service. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/utils/PlatformUtils.h"
15#include "arcane/utils/ScopedPtr.h"
16
17#include "arcane/core/IMeshReader.h"
18#include "arcane/core/ISubDomain.h"
19#include "arcane/core/XmlNode.h"
20#include "arcane/core/Service.h"
21#include "arcane/core/IParallelMng.h"
22#include "arcane/core/IPrimaryMesh.h"
23#include "arcane/core/MeshVariable.h"
24#include "arcane/core/ItemPrinter.h"
25#include "arcane/core/FactoryService.h"
26#include "arcane/core/AbstractService.h"
27
28#include "arcane/std/SodMeshGenerator.h"
29#include "arcane/std/SimpleMeshGenerator.h"
30#include "arcane/std/CartesianMeshGenerator.h"
31
32/*---------------------------------------------------------------------------*/
33/*---------------------------------------------------------------------------*/
34
35namespace Arcane
36{
37
38/*---------------------------------------------------------------------------*/
39/*---------------------------------------------------------------------------*/
40
44class MeshGeneratorService
45: public AbstractService
46, public IMeshReader
47{
48 public:
49
50 MeshGeneratorService(const ServiceBuildInfo& sbi);
51
52 public:
53
54 virtual void build() {}
55
56 public:
57
58 virtual bool allowExtension(const String& str)
59 {
60 return str.null();
61 }
63 const XmlNode& mesh_node,
64 const String& file_name,
65 const String& dirname,
66 bool use_internal_partition);
67};
68
69/*---------------------------------------------------------------------------*/
70/*---------------------------------------------------------------------------*/
71
72MeshGeneratorService::
73MeshGeneratorService(const ServiceBuildInfo& sbi)
74: AbstractService(sbi)
75{
76}
77
78/*---------------------------------------------------------------------------*/
79/*---------------------------------------------------------------------------*/
80
83 const XmlNode& mesh_node,
84 const String& filename,
85 const String& dirname,
86 bool use_internal_partition)
87{
88 ARCANE_UNUSED(filename);
89 ARCANE_UNUSED(dirname);
90 ARCANE_UNUSED(use_internal_partition);
91
92 String meshclass = platform::getEnvironmentVariable("ARCANE_MESHGENERATOR");
93 String meshgen_ustr("meshgenerator");
94 XmlNode gen_node;
96
97 //msg->warning() << "USING MESHGENERATOR !!\n";
98 if (!meshclass.null()) {
99 gen_node = mesh_node.childWithNameAttr(meshgen_ustr, meshclass);
100 info() << "Using ARCANE_MESHGENERATOR";
101 }
102 else {
103 gen_node = mesh_node.child(meshgen_ustr);
104 }
105 if (gen_node.null())
106 return RTIrrelevant;
107 XmlNode node;
108 // Searching for the 'cartesian' mesh generator
109 if (node.null()) {
110 node = gen_node.child("cartesian");
111 if (!node.null())
112 generator = new CartesianMeshGenerator(mesh);
113 }
114 // Searching for the 'sod' mesh generator
115 if (node.null()) {
116 node = gen_node.child("sod");
117 if (!node.null())
118 generator = new SodMeshGenerator(mesh, node.attr("zyx").valueAsBoolean());
119 }
120 // Searching for the 'simple' mesh generator
121 if (node.null()) {
122 node = gen_node.child("simple");
123 if (!node.null())
124 generator = new SimpleMeshGenerator(mesh);
125 }
126 if (!generator.get()) {
127 warning() << "Unknown mesh generator type.";
128 return RTIrrelevant;
129 }
130 if (generator->readOptions(node))
131 return RTError;
132 if (generator->generateMesh())
133 return RTError;
134 return RTOk;
135}
136
137/*---------------------------------------------------------------------------*/
138/*---------------------------------------------------------------------------*/
139
141
142/*---------------------------------------------------------------------------*/
143/*---------------------------------------------------------------------------*/
144
145} // namespace Arcane
146
147/*---------------------------------------------------------------------------*/
148/*---------------------------------------------------------------------------*/
#define ARCANE_REGISTER_SUB_DOMAIN_FACTORY(aclass, ainterface, aname)
Registers a factory service for the class aclass.
AbstractService(const ServiceBuildInfo &)
Constructor from a ServiceBuildInfo.
Interface of the service managing the reading of a mesh.
Definition IMeshReader.h:33
eReturnType
Types of return codes for a read or write operation.
Definition IMeshReader.h:38
@ RTIrrelevant
Not relevant to the operation. This means that the file format does not match this reader or that the...
Definition IMeshReader.h:46
@ RTError
Error during the operation.
Definition IMeshReader.h:40
@ RTOk
Operation successfully performed.
Definition IMeshReader.h:39
virtual eReturnType readMeshFromFile(IPrimaryMesh *mesh, const XmlNode &mesh_node, const String &file_name, const String &dirname, bool use_internal_partition)
Reads a mesh from a file.
virtual void build()
Build-level construction of the service.
virtual bool allowExtension(const String &str)
Checks if the service supports files with the extension str.
T * get() const
Returns the object referenced by the instance.
Definition Ptr.h:122
Encapsulation of an automatically destructing pointer.
Definition ScopedPtr.h:44
Structure containing the information to create a service.
Simple generator for each type of mesh entity.
Mesh generator for a shock tube.
bool null() const
Returns true if the string is null.
Definition String.cc:306
TraceMessage info() const
Flow for an information message.
TraceMessage warning() const
Flow for a warning message.
Node of a DOM tree.
Definition XmlNode.h:51
XmlNode attr(const String &name, bool throw_exception=false) const
Returns the attribute of name name.
Definition XmlNode.cc:257
XmlNode childWithNameAttr(const String &elem_name, const String &attr_value) const
Returns the child of this node having the name elem_name and an attribute of name "name" with value a...
Definition XmlNode.cc:509
XmlNode child(const String &name) const
Child node of this node with name name.
Definition XmlNode.cc:73
bool null() const
True if the node is null.
Definition XmlNode.h:303
bool valueAsBoolean(bool throw_exception=false) const
Node value converted to boolean.
Definition XmlNode.cc:421
String getEnvironmentVariable(const String &name)
Environment variable named name.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --