Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
ArcaneCeaVerifierModule.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/* ArcaneVerifierModule.cc (C) 2000-2026 */
9/* */
10/* Verification module. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/utils/PlatformUtils.h"
15#include "arcane/utils/ScopedPtr.h"
16
17#include "arcane/core/EntryPoint.h"
18#include "arcane/core/ISubDomain.h"
19#include "arcane/core/ModuleFactory.h"
20#include "arcane/core/IVerifierService.h"
21#include "arcane/core/ServiceUtils.h"
22#include "arcane/core/IVariableMng.h"
23#include "arcane/core/IParallelMng.h"
24#include "arcane/core/IMesh.h"
25#include "arcane/core/IItemFamily.h"
26#include "arcane/core/ITimeLoopMng.h"
27#include "arcane/core/ServiceBuilder.h"
28#include "arcane/core/ObserverPool.h"
29#include "arcane/core/ICheckpointMng.h"
30#include "arcane/core/MeshVisitor.h"
31#include "arcane/core/IDirectory.h"
32
33#include "arcane/std/ArcaneCeaVerifier_axl.h"
34
35/*---------------------------------------------------------------------------*/
36/*---------------------------------------------------------------------------*/
37
38namespace Arcane
39{
40
41/*---------------------------------------------------------------------------*/
42/*---------------------------------------------------------------------------*/
46class ArcaneVerifierModule
47: public ArcaneArcaneCeaVerifierObject
48{
49 public:
50
51 explicit ArcaneVerifierModule(const ModuleBuildInfo& mb);
52
53 public:
54
55 VersionInfo versionInfo() const override { return VersionInfo(0, 0, 1); }
56
57 public:
58
59 void onExit() override;
60 void onInit() override;
61
62 private:
63
64 ObserverPool m_observers;
65
66 private:
67
68 void _checkSortedGroups();
69};
70
71/*---------------------------------------------------------------------------*/
72/*---------------------------------------------------------------------------*/
73
74ArcaneVerifierModule::
75ArcaneVerifierModule(const ModuleBuildInfo& mb)
76: ArcaneArcaneCeaVerifierObject(mb)
77{
78}
79
80/*---------------------------------------------------------------------------*/
81/*---------------------------------------------------------------------------*/
82
83void ArcaneVerifierModule::
84onInit()
85{
86 if (options()->trace.size() != 0)
87 this->pwarning() << "The option 'trace' is no longer used and should be removed";
88
89 if (!platform::getEnvironmentVariable("ARCANE_VERIFY_SORTEDGROUP").null()) {
90 info() << "Add observer to check sorted groups before checkpoint";
91 // Adds an observer signaling unsorted groups.
92 m_observers.addObserver(this,
93 &ArcaneVerifierModule::_checkSortedGroups,
94 subDomain()->checkpointMng()->writeObservable());
95 }
96}
97
98/*---------------------------------------------------------------------------*/
99/*---------------------------------------------------------------------------*/
100
101void ArcaneVerifierModule::
102_checkSortedGroups()
103{
104 // Displays the list of unsorted groups.
105 Integer nb_sorted_group = 0;
106 Integer nb_group = 0;
107 auto check_sorted_func = [&](ItemGroup& g) {
108 ++nb_group;
109 if (g.checkIsSorted())
110 ++nb_sorted_group;
111 else
112 info() << "VerifierModule: group not sorted name=" << g.name();
113 };
114 meshvisitor::visitGroups(this->mesh(), check_sorted_func);
115 info() << "VerifierModule: nb_unsorted_group=" << (nb_group - nb_sorted_group)
116 << "/" << nb_group;
117}
118
119/*---------------------------------------------------------------------------*/
120/*---------------------------------------------------------------------------*/
121
123onExit()
124{
125 if (!options()->verify())
126 return;
127 if (!platform::getEnvironmentVariable("ARCANE_NO_VERIFY").null())
128 return;
129
131 bool is_parallel = pm->isParallel();
132
133 Ref<IVerifierService> verifier_service;
134
135 {
137
138 String verifier_service_name = options()->verifierServiceName();
139 // Allows an environment variable for overriding the service for testing
140 String env_service_name = platform::getEnvironmentVariable("ARCANE_VERIFIER_SERVICE");
141 if (!env_service_name.null())
142 verifier_service_name = env_service_name;
143 info() << "Verification Module using service=" << verifier_service_name;
144 verifier_service = sf.createReference(verifier_service_name);
145 }
146
147 bool compare_from_sequential = options()->compareParallelSequential();
148 if (!is_parallel)
149 compare_from_sequential = false;
150
151 String result_file_name = options()->resultFile();
152 String reference_file_name = options()->referenceFile();
153
154 if (options()->filesInOutputDir()) {
155 if (result_file_name.empty()) {
156 result_file_name = subDomain()->exportDirectory().file("compare.xml");
157 }
158 else {
159 result_file_name = subDomain()->exportDirectory().file(result_file_name);
160 }
161
162 if (reference_file_name.empty()) {
163 reference_file_name = subDomain()->exportDirectory().file("check");
164 }
165 else {
166 reference_file_name = subDomain()->exportDirectory().file(reference_file_name);
167 }
168 }
169 else {
170 if (result_file_name.empty()) {
171 result_file_name = "compare.xml";
172 }
173
174 if (reference_file_name.empty()) {
175 reference_file_name = "check";
176 }
177 }
178
179 verifier_service->setResultFileName(result_file_name);
180
181 info() << "Verification check is_parallel?=" << is_parallel << " compare_from_sequential?=" << compare_from_sequential;
182 verifier_service->setFileName(reference_file_name);
183
184 if (options()->generate()) {
185 info() << "Writing check file '" << reference_file_name << "'";
186 verifier_service->writeReferenceFile();
187 }
188 else {
189 info() << "Comparing reference file '" << reference_file_name << "'";
190 verifier_service->doVerifFromReferenceFile(compare_from_sequential, false);
191 }
192}
193
194/*---------------------------------------------------------------------------*/
195/*---------------------------------------------------------------------------*/
196
197ARCANE_REGISTER_MODULE_ARCANECEAVERIFIER(ArcaneVerifierModule);
198
199/*---------------------------------------------------------------------------*/
200/*---------------------------------------------------------------------------*/
201
202} // End namespace Arcane
203
204/*---------------------------------------------------------------------------*/
205/*---------------------------------------------------------------------------*/
ISubDomain * subDomain() const override
Sub-domain associated with the module.
CaseOptionsArcaneCeaVerifier * options() const
Options du jeu de données du module.
void onExit() override
points d'entrée
VersionInfo versionInfo() const override
Module version.
virtual String file(const String &file_name) const =0
Returns the full path of the file file_name in the directory.
Interface of the parallelism manager for a subdomain.
virtual bool isParallel() const =0
Returns true if the execution is parallel.
virtual IParallelMng * parallelMng()=0
Returns the parallelism manager.
virtual const IDirectory & exportDirectory() const =0
Base directory for exports.
Information for building a module.
List of observers.
Reference to an instance.
Utility class for instantiating a service of a given interface.
Ref< InterfaceType > createReference(const String &name, eServiceBuilderProperties properties=SB_None)
Creates an instance implementing the InterfaceType interface.
bool null() const
Returns true if the string is null.
Definition String.cc:306
bool empty() const
True if the string is empty (null or "").
Definition String.cc:317
TraceMessage info() const
Flow for an information message.
TraceMessage pwarning() const
Information about a version.
Definition VersionInfo.h:47
String getEnvironmentVariable(const String &name)
Environment variable named name.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Int32 Integer
Type representing an integer.