14#include "arcane/utils/Ptr.h"
15#include "arcane/utils/List.h"
17#include "arcane/core/EntryPoint.h"
18#include "arcane/core/ISubDomain.h"
19#include "arcane/core/IVariableMng.h"
20#include "arcane/core/IParallelMng.h"
21#include "arcane/core/ItemGroup.h"
22#include "arcane/core/Directory.h"
23#include "arcane/core/ITimeHistoryMng.h"
24#include "arcane/core/ServiceUtils.h"
25#include "arcane/core/IPostProcessorWriter.h"
26#include "arcane/core/MeshAccessor.h"
27#include "arcane/core/IMesh.h"
28#include "arcane/core/VariableTypes.h"
29#include "arcane/core/CommonVariables.h"
31#include "arcane/core/ITimeLoopMng.h"
33#include "arcane/core/ModuleFactory.h"
34#include "arcane/core/Timer.h"
35#include "arcane/core/VariableCollection.h"
36#include "arcane/core/OutputChecker.h"
37#include "arcane/core/IExternalPlugin.h"
39#include "arcane/std/ArcanePostProcessing_axl.h"
61class ArcanePostProcessingModule
62:
public ArcaneArcanePostProcessingObject
67 ~ArcanePostProcessingModule()
override;
78 void postProcessingStartInit()
override;
79 void postProcessingInit()
override;
95 bool m_is_plugin_initialized =
false;
100 void _saveAtTime(
Real);
102 void _checkCreateOutputDir();
105 void _checkExternalPlugin();
116ArcanePostProcessingModule::
119, m_output_checker(mbi.subDomain(),
"PostProcessing")
120, m_history_output_checker(mbi.subDomain(),
"PostProcessingHistory")
121, m_times(VariableBuilder(this,
"ExportTimes"))
124 m_output_checker.assignGlobalTime(&m_next_global_time, &
options()->outputFrequency);
126 m_history_output_checker.assignIteration(&m_history_next_iteration, &
options()->outputHistoryPeriod);
133ArcanePostProcessingModule::
134~ArcanePostProcessingModule()
152 std::set<String> used_variables;
155 info() <<
"-- List of output variables (" << nb_var <<
" variables):";
156 for (
Integer i = 0; i < nb_var; ++i) {
160 ARCANE_FATAL(
"PostTreatment: no variable with name '{0}' exists", varname);
164 " be a mesh variable (node, edge, face or cell)",
167 if (used_variables.find(varname) == used_variables.end()) {
168 info() <<
"Variable <" << varname <<
">";
170 used_variables.insert(varname);
174 warning() <<
"Variable <" << varname <<
"> required twice during post-processing analysis";
182 std::set<String> used_groups;
185 info() <<
"-- List of output groups (" << nb_group <<
" groups):";
186 for (
Integer i = 0; i < nb_group; ++i) {
191 if (used_groups.find(groupname) == used_groups.end()) {
192 info() <<
"Group <" << groupname <<
">";
193 used_groups.insert(groupname);
197 warning() <<
"Group <" << groupname <<
"> required twice during post-processing analysis";
206 if (
mesh->isAmrActivated())
216void ArcanePostProcessingModule::
217_checkCreateOutputDir()
229void ArcanePostProcessingModule::
232 info() <<
" -------------------------------------------";
233 info() <<
"| POST PROCESSING |";
234 info() <<
" -------------------------------------------";
239 info() <<
"Variables output:";
240 m_output_checker.initialize(is_continue);
242 info() <<
"History output:";
243 m_history_output_checker.initialize(is_continue);
248 if (
options()->outputHistoryShrink)
254 const Real current_time = vc.globalTime();
255 m_output_checker.
check(old_time, current_time, vc.globalIteration(), 0);
256 m_history_output_checker.
check(old_time, current_time, vc.globalIteration(), 0);
259 _saveAtTime(current_time);
265void ArcanePostProcessingModule::
266postProcessingStartInit()
268 m_next_global_time = 0.0;
270 m_curves_next_global_time = 0.0;
271 m_curves_next_iteration = 0;
272 m_history_next_iteration = 0;
290 bool save_at_exit =
false;
291 if (
subDomain()->timeLoopMng()->finalTimeReached())
292 save_at_exit =
options()->saveFinalTime();
294 save_at_exit =
options()->endExecutionOutput();
296 _saveAtTime(current_time);
301 info() <<
"Total time for post-processing analysis output (second): " << total_time;
304 info() <<
"Average time per output (second): " << total_time / nb_time
305 <<
" (for " << nb_time <<
" outputs";
308 post_processor->
close();
322 _saveAtTime(current_time);
340 if (global_iteration == 0)
348 bool do_history_output = m_history_output_checker.check(old_time, current_time, global_iteration, 0);
353 bool do_at_current_iteration = m_output_checker.check(old_time, current_time, global_iteration, 0);
354 if (do_at_current_iteration)
362void ArcanePostProcessingModule::
363_saveAtTime(
Real saved_time)
379 _checkCreateOutputDir();
388 info() <<
"**** Output in progress at time " << saved_time <<
" ******";
392 _checkExternalPlugin();
408 for (VariableList::Enumerator v_iter(
m_variables); ++v_iter;) {
424 for (VariableList::Enumerator v_iter(
m_variables); ++v_iter;) {
433void ArcanePostProcessingModule::
434_checkExternalPlugin()
438 auto& plugin_option =
options()->experimentalPythonPlugin;
439 if (!plugin_option.isPresent())
442 String function = plugin_option.functionName();
443 info() <<
"Executing Python function '" << function <<
"'";
444 if (!m_is_plugin_initialized) {
445 info() <<
"Initializing Python environment";
447 m_is_plugin_initialized =
true;
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
Various mathematical functions.
Generation de la classe de base du Module.
CaseOptionsArcanePostProcessing * options() const
Options du jeu de données du module.
Arcane::VariableScalarInteger m_next_iteration
Variables du module.
ISubDomain * subDomain() const override
Sub-domain associated with the module.
IMesh * defaultMesh() const override
Default mesh for this module.
Output module for post-processing.
Timer * m_post_processor_timer
Timer for time spent writing.
bool m_output_dir_created
true if directory created.
VariableArrayReal m_times
Time points of saves.
void _markCurrentIterationPostProcessing()
Marks variables as post-processed during this iteration.
VariableList m_variables
List of variables to export.
bool m_is_output_at_current_iteration
Indicates if outputs are performed during this iteration.
void _resetCurrentIterationPostProcessing()
Removes tags from variables post-processed during this iteration.
void exportData() override
Checks and writes the values for post-processing.
void postProcessingExit() override
Post-processing information at the end of the calculation loop.
ItemGroupList m_groups
List of groups to export.
void exportDataStart() override
Entry point at the beginning of an iteration.
VersionInfo versionInfo() const override
Module version.
Directory m_output_directory
Output directory.
constexpr Integer size() const noexcept
Returns the size of the array.
Common variables of a case.
Real globalTime() const
Current time.
Int32 globalIteration() const
Current iteration number.
CommonVariables(IModule *c)
Constructs the references of the common variables for the module c.
Real globalOldTime() const
Previous current time.
Class managing a directory.
bool createDirectory() const override
Creates the directory.
String path() const override
Returns the path of the directory.
Interface for external service loading.
virtual void executeContextFunction(const String &function_name)=0
Executes the function function_name with a context.
virtual void loadFile(const String &filename)=0
Loads and executes a file containing an external script.
Interface for a writer for post-processing information.
virtual void setVariables(VariableCollection variables)=0
Positions the list of variables to output.
virtual void close()=0
Closes the writer. After closing, it can no longer be used.
virtual void setGroups(ItemGroupCollection groups)=0
Positions the list of groups to output.
virtual void setBaseDirectoryName(const String &dirname)=0
Positions the output directory name for files.
virtual void setTimes(ConstArrayView< Real > times)=0
Positions the list of times.
Interface of the subdomain manager.
virtual const CommonVariables & commonVariables() const =0
Information on standard variables.
virtual IMesh * defaultMesh()=0
Default mesh.
virtual bool isContinue() const =0
True if a restart is being performed, false otherwise.
virtual ITimeHistoryMng * timeHistoryMng()=0
Returns the history manager.
virtual IVariableMng * variableMng()=0
Returns the variable manager.
virtual void setShrinkActive(bool is_active)=0
Sets the boolean indicating if the history is compressed.
virtual void setActive(bool is_active)=0
Sets the activation status.
Variable manager interface.
virtual IVariable * findMeshVariable(IMesh *mesh, const String &name)=0
Returns the mesh variable named name or 0 if no such name exists.
virtual void writePostProcessing(IPostProcessorWriter *writer)=0
Writes variables for post-processing.
virtual void addTag(const String &tagname, const String &tagvalue)=0
Adds the tag tagname with the value tagvalue.
virtual eItemKind itemKind() const =0
Kind of mesh entities on which the variable is based.
static const char * TAG_POST_PROCESSING
Tag used to indicate if a variable will be post-processed.
virtual void removeTag(const String &tagname)=0
Removes the tag tagname.
static const char * TAG_POST_PROCESSING_AT_THIS_ITERATION
Tag used to indicate if a variable will be post-processed at this iteration.
const String & name() const
Group name.
bool null() const
true means the group is the null group
Information for building a module.
ISubDomain * subDomain() const
Access to the associated subdomain.
Manages outputs based on physical time, CPU time, or a number of iterations.
bool check(Real old_time, Real current_time, Integer current_iteration, Integer current_cpu_time, const String &from_function=String())
Checks whether an output should be performed.
Unicode character string.
Sentinel for the timer. The sentinel associated with a timer allows it to be triggered upon its const...
@ TimerReal
Timer using real time.
TraceMessage info() const
Flow for an information message.
TraceMessage warning() const
Flow for a warning message.
virtual void resize(Integer new_size)
Resizes the array to contain new_size elements.
Information about a version.
constexpr Integer size() const noexcept
Returns the size of the array.
VariableRefArrayT< Real > VariableArrayReal
Array variable of real type.
constexpr __host__ __device__ bool isEqual(const _Type &a, const _Type &b)
Tests the bit-by-bit equality between two values.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Int32 Integer
Type representing an integer.
List< ItemGroup > ItemGroupList
Array of mesh item groups.
eItemKind
Mesh entity type.
@ IK_Node
Node mesh entity.
@ IK_Cell
Cell mesh entity.
@ IK_Face
Face mesh entity.
@ IK_Edge
Edge mesh entity.
double Real
Type representing a real number.
std::int32_t Int32
Signed integer type of 32 bits.