Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding SourceFluxStatistics #2954

Merged
merged 110 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from 54 commits
Commits
Show all changes
110 commits
Select commit Hold shift + click to select a range
d73ac6d
added region mass stats
MelReyCG Dec 21, 2023
909a1c5
added region temperature stats
MelReyCG Dec 21, 2023
8bee3cf
Logging debug info - to be removed laster
MelReyCG Jan 12, 2024
256caeb
better debug output
MelReyCG Jan 12, 2024
0ec69b5
annotations
MelReyCG Jan 15, 2024
67d8a7e
cleaning
MelReyCG Jan 16, 2024
27bec78
Output flux stats in log
MelReyCG Jan 16, 2024
f89e2d8
completed previous commit
MelReyCG Jan 19, 2024
e0592ed
Add the logLevel viewkey & description
MelReyCG Jan 19, 2024
078e6ed
Add a way to expend the description of a wrapper
MelReyCG Jan 19, 2024
5b8f213
Intermediate progress to properly store the SourceFlux stats
MelReyCG Jan 19, 2024
953ec3a
adding the SourceFluxStatistics Task which will allow to aggregate st…
MelReyCG Jan 19, 2024
1a9fe0c
simplify description to avoid regenerating a lot of .rst (to be added…
MelReyCG Jan 19, 2024
867a20c
Merge remote-tracking branch 'origin/develop' into feature/rey/source…
MelReyCG Jan 19, 2024
814fd34
missed a few details
MelReyCG Jan 19, 2024
818fcc2
forgotten generated files...
MelReyCG Jan 19, 2024
a5d762b
SourceFlluxStatistics now compiles
MelReyCG Jan 19, 2024
28a7730
generated docs
MelReyCG Jan 19, 2024
4e71130
SourceFluxStatistics now runs:
MelReyCG Jan 25, 2024
cc55358
few edits
MelReyCG Jan 25, 2024
69c6918
uncrustify
MelReyCG Jan 26, 2024
a164ece
architecture adaptations to expose values to unit tests
MelReyCG Feb 1, 2024
badfc4e
added singlephase test
MelReyCG Feb 1, 2024
23e41fc
removed debug infos
MelReyCG Feb 1, 2024
d59318a
unit test: code layout, removed debug info
MelReyCG Feb 1, 2024
db72798
unit test: code layout, removed debug info, xmlInput improvements
MelReyCG Feb 2, 2024
232106b
Merge branch 'feature/rey/sourceflux-stats' of https://github.com/GEO…
MelReyCG Feb 2, 2024
8477262
Added multiphase xml input
MelReyCG Feb 2, 2024
317560a
few comments
MelReyCG Feb 2, 2024
af7be1e
code style
MelReyCG Feb 6, 2024
796f020
unit test: Added checks on every timesteps stats
MelReyCG Feb 6, 2024
c6ccc63
unit test: separated the input parameters and expected value set
MelReyCG Feb 6, 2024
b806da7
unit test: cleaning comments
MelReyCG Feb 6, 2024
aa4b250
unit test: compositional multiphase sim now runs
MelReyCG Feb 7, 2024
c2fa0f8
allowed multiple component stats for SourceFluxStatistics
MelReyCG Feb 7, 2024
dc3398c
changed singlephase parameters so that they are not multiple among th…
MelReyCG Feb 8, 2024
c2c74f0
forgot to replace some hard coded values
MelReyCG Feb 8, 2024
0a0fb7b
Whole multiphase sim stat check
MelReyCG Feb 8, 2024
e2ac446
crash investigating...
MelReyCG Feb 8, 2024
4c3fa0b
fixed crashed :)
MelReyCG Feb 8, 2024
41b0fc8
Revert unwanted pushed files
MelReyCG Feb 8, 2024
f163aed
Finished the multiphase test
MelReyCG Feb 9, 2024
1781ac9
Unexpected result debugging
MelReyCG Feb 9, 2024
620a53b
forgotten decls
MelReyCG Feb 9, 2024
45f7452
code cleaning
MelReyCG Feb 9, 2024
703b73a
fixing gpu captures + adding support for ReactiveCompositionalMultiph…
MelReyCG Feb 9, 2024
cdebcff
fixed sum operations (=> reduceSum)
MelReyCG Feb 12, 2024
ffcf39b
uncrustify
MelReyCG Feb 12, 2024
7a96ee2
test pvt tables optimisation (13.4s -> 3.0s)
MelReyCG Feb 12, 2024
2446436
exposed SinglePhaseStatistics::RegionStatistics
MelReyCG Feb 13, 2024
a0d085a
compared mass difference from SinglePhaseStatistics and SourceFluxSta…
MelReyCG Feb 13, 2024
e427189
Merge branch 'develop' into feature/rey/sourceflux-stats
MelReyCG Feb 14, 2024
e1e79cf
fixed typo
MelReyCG Feb 14, 2024
3da5569
Merge branch 'feature/rey/sourceflux-stats' of https://github.com/GEO…
MelReyCG Feb 14, 2024
e9f7f4a
Added guard to test sub-timesteps
MelReyCG Feb 15, 2024
6af8726
Added CSV export & more docs
MelReyCG Feb 16, 2024
3d19803
Removing the MultifluidBase::useMass wrapper as it is set by the solv…
MelReyCG Feb 21, 2024
a2d618a
fixed catalog name of TimeStepChecker
MelReyCG Feb 21, 2024
7ee9b4d
Fixed solver "amount of fluid" units (kg or mol), and added documenta…
MelReyCG Feb 22, 2024
7378ec2
better timestep cut checking + refactored a bit
MelReyCG Feb 22, 2024
322a3f8
Merge remote-tracking branch 'origin/develop' into feature/rey/source…
MelReyCG Feb 22, 2024
0161b19
generated docs
MelReyCG Feb 22, 2024
d6a47d8
uncrustify
MelReyCG Feb 22, 2024
c528da8
typo
MelReyCG Feb 22, 2024
5907f9c
reverting undesired paste
MelReyCG Feb 22, 2024
720c493
wrappers like this one is required to be able to "deliverClone()"
MelReyCG Feb 22, 2024
afab7c7
generated documentations
MelReyCG Feb 22, 2024
1e33b3d
docs
MelReyCG Feb 22, 2024
f911df3
wrong doxygen keyword
MelReyCG Feb 22, 2024
8dfe5db
doxygen test
MelReyCG Feb 22, 2024
2662637
test2
MelReyCG Feb 22, 2024
7fcf887
fixed doxygen
MelReyCG Feb 22, 2024
ffaf9d4
ajusting test value to facilitate convergence
MelReyCG Feb 23, 2024
e9ee4ea
code reordering + docs
MelReyCG Feb 23, 2024
a9d17d4
debugging sub-sub-timestep behaviour
MelReyCG Feb 23, 2024
2003fd2
finally fixed numerical precision issue
MelReyCG Feb 23, 2024
45084b5
removing double decl
MelReyCG Feb 23, 2024
000978a
removing unrelated code change
MelReyCG Feb 23, 2024
923b0d8
ajusting test value to facilitate convergence
MelReyCG Feb 23, 2024
02d35fc
test
MelReyCG Feb 23, 2024
f53a8f5
allow non converged solution is tests as trilinos struggles with the …
MelReyCG Feb 27, 2024
d5b4a14
Solver setting test
MelReyCG Feb 28, 2024
fad3edf
Solver setting test 2 (Mass test is passed with trilinos)
MelReyCG Feb 28, 2024
68eb991
Solver setting test
MelReyCG Feb 28, 2024
9b0628f
reverted to previous settings
MelReyCG Feb 29, 2024
adab7a0
forgotten ILUK attribute
MelReyCG Feb 29, 2024
32cdd5e
trying to test sub-timesteps only with hypre
MelReyCG Mar 5, 2024
42a57d8
trilinos & hyper work in stastifying time
MelReyCG Mar 5, 2024
7f2a913
removed unused headers
MelReyCG Mar 5, 2024
7f51542
Merge remote-tracking branch 'origin/develop' into feature/rey/source…
MelReyCG Mar 5, 2024
dc5b827
solver precision
MelReyCG Mar 5, 2024
7f9097c
avoiding exact 0 / 1 values in test
MelReyCG Mar 8, 2024
de20aba
removed parameter as they are to defualt values
MelReyCG Mar 8, 2024
9f78b8d
renaming testFluidStatistics to testFlowStatistics
MelReyCG Mar 8, 2024
25bc30f
removing the 4th log level
MelReyCG Apr 3, 2024
f56b2f6
missing inlines
MelReyCG Apr 3, 2024
37b3c97
xsd / rst changes
MelReyCG Apr 3, 2024
3165aef
moving the TimeStepChecker in its own file (& created a testingUtilit…
MelReyCG Apr 3, 2024
9905ae1
Merge remote-tracking branch 'origin/develop' into feature/rey/source…
MelReyCG Apr 3, 2024
3883d39
moving some definition to cpp
MelReyCG Apr 3, 2024
8f72e9f
uncrustify :s
MelReyCG Apr 3, 2024
43fe9f4
few adjustments
MelReyCG Jun 4, 2024
34fc78d
Merge commit '79856a0e653a508b4fe4dcd8c582fcdc2838b756' into feature/…
MelReyCG Jun 4, 2024
cf15bb3
added an header due to incomplete DomainPartition type
MelReyCG Jun 4, 2024
b051ed1
by default, SourceFluxStat targets al SourceFlux + adapted test
MelReyCG Jun 4, 2024
cf0271a
generated files
MelReyCG Jun 4, 2024
b0c7fe6
Added star character * in group name reference regex.
MelReyCG Jun 5, 2024
db2efea
Merge branch 'develop' into feature/rey/sourceflux-stats
paveltomin Jun 7, 2024
ce24a37
Merge branch 'develop' into feature/rey/sourceflux-stats
paveltomin Jun 13, 2024
fc11f5b
Merge branch 'develop' into feature/rey/sourceflux-stats
paveltomin Jun 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/coreComponents/dataRepository/Group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -644,9 +644,8 @@ void Group::postRestartInitializationRecursive()

void Group::enableLogLevelInput()
{
string const logLevelString = "logLevel";

registerWrapper( logLevelString, &m_logLevel ).
// TODO : Improve the Log Level description to clearly assign a usecase per log level (incoming PR).
registerWrapper( viewKeyStruct::logLevelString(), &m_logLevel ).
setApplyDefaultValue( 0 ).
setInputFlag( InputFlags::OPTIONAL ).
setDescription( "Log level" );
Expand Down
9 changes: 9 additions & 0 deletions src/coreComponents/dataRepository/Group.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1414,6 +1414,15 @@ class Group
*/
void setInputFlags( InputFlags flags ) { m_input_flags = flags; }

/**
* @struct viewKeyStruct holds char strings and viewKeys for fast lookup
*/
struct viewKeyStruct
{
/// String for the logLevel wrapper
constexpr static char const * logLevelString() { return "logLevel"; }
};

///@}

/**
Expand Down
9 changes: 9 additions & 0 deletions src/coreComponents/dataRepository/Wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,15 @@ class Wrapper final : public WrapperBase
return *this;
}

/**
* @copydoc WrapperBase::appendDescription(string const &)
*/
Wrapper< T > & appendDescription( string const & description )
{
WrapperBase::appendDescription( description );
return *this;
}

/**
* @copydoc WrapperBase::setRegisteringObjects(string const &)
*/
Expand Down
11 changes: 11 additions & 0 deletions src/coreComponents/dataRepository/WrapperBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,17 @@ class WrapperBase
return *this;
}

/**
* @brief Add up more text to the existing description string of the wrapper.
* @param description the description to add to the end of the previous one.
* @return a pointer to this wrapper
*/
WrapperBase & appendDescription( string const & description )
{
m_description += description;
return *this;
}

/**
* @brief Get the description string of the wrapper.
* @return this wrapper's description string
Expand Down
2 changes: 2 additions & 0 deletions src/coreComponents/fieldSpecification/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ set( fieldSpecification_headers
TractionBoundaryCondition.hpp
AquiferBoundaryCondition.hpp
PerfectlyMatchedLayer.hpp
SourceFluxStatistics.hpp
)

#
Expand All @@ -24,6 +25,7 @@ set( fieldSpecification_sources
TractionBoundaryCondition.cpp
AquiferBoundaryCondition.cpp
PerfectlyMatchedLayer.cpp
SourceFluxStatistics.cpp
)

set( dependencyList ${parallelDeps} functions linearAlgebra )
Expand Down
317 changes: 317 additions & 0 deletions src/coreComponents/fieldSpecification/SourceFluxStatistics.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,317 @@
/*
* ------------------------------------------------------------------------------------------------------------
* SPDX-License-Identifier: LGPL-2.1-only
*
* Copyright (c) 2018-2020 Lawrence Livermore National Security LLC
* Copyright (c) 2018-2020 The Board of Trustees of the Leland Stanford Junior University
* Copyright (c) 2018-2020 TotalEnergies
* Copyright (c) 2019- GEOSX Contributors
* All rights reserved
*
* See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details.
* ------------------------------------------------------------------------------------------------------------
*/

/**
* @file SourceFluxStatistics.cpp
*/

#include "SourceFluxStatistics.hpp"

#include "SourceFluxBoundaryCondition.hpp"
#include "FieldSpecificationManager.hpp"
#include "LvArray/src/tensorOps.hpp"

namespace geos
{
using namespace dataRepository;

SourceFluxStatsAggregator::SourceFluxStatsAggregator( const string & name,
Group * const parent ):
Base( name, parent )
{
getWrapper< integer >( Group::viewKeyStruct::logLevelString() ).
appendDescription( GEOS_FMT( "\n- Log Level 1 outputs the sum of all {0}(s) produced rate & mass,\n"
"- Log Level 2 details values for each {0},\n"
"- Log Level 3 details values for each region,\n"
"- Log Level 4 details values for each sub-region.",
MelReyCG marked this conversation as resolved.
Show resolved Hide resolved
SourceFluxBoundaryCondition::catalogName() ) );

registerWrapper( viewKeyStruct::fluxNamesString().data(), &m_fluxNames ).
setRTTypeName( rtTypes::CustomTypes::groupNameRefArray ).
setInputFlag( InputFlags::REQUIRED ).
setSizedFromParent( 0 ).
setDescription( GEOS_FMT( "Name(s) array of the {0}(s) for which we want the statistics. "
"Use \"all\" to target all {0}.",
SourceFluxBoundaryCondition::catalogName() ) );
}

void SourceFluxStatsAggregator::postProcessInput()
{
Base::postProcessInput();

FieldSpecificationManager & fsManager = FieldSpecificationManager::getInstance();
if( m_fluxNames.size() == 1 && m_fluxNames[0] == "all" )
MelReyCG marked this conversation as resolved.
Show resolved Hide resolved
{
m_fluxNames.clear();
fsManager.forSubGroups< SourceFluxBoundaryCondition >( [&]( SourceFluxBoundaryCondition & sourceFlux )
{
m_fluxNames.emplace_back( string( sourceFlux.getName() ) );
} );
GEOS_WARNING_IF( m_fluxNames.empty(),
GEOS_FMT( "{}: No {} was found in {}.",
getDataContext(), SourceFluxBoundaryCondition::catalogName(),
fsManager.getDataContext() ) );
}
else
{
for( string const & fluxName : m_fluxNames )
{
GEOS_ERROR_IF( !fsManager.hasGroup< SourceFluxBoundaryCondition >( fluxName ),
GEOS_FMT( "{}: No {} named {} was found in {}.",
getDataContext(), SourceFluxBoundaryCondition::catalogName(),
fluxName, fsManager.getDataContext() ) );
}
}
}

Wrapper< SourceFluxStatsAggregator::WrappedStats > &
SourceFluxStatsAggregator::registerWrappedStats( Group & group, string_view fluxName )
{
string const wrapperName = getStatWrapperName( fluxName );
Wrapper< WrappedStats > & statsWrapper = group.registerWrapper< WrappedStats >( wrapperName );
statsWrapper.setRestartFlags( RestartFlags::NO_WRITE );
statsWrapper.reference().setTarget( getName(), fluxName );
return statsWrapper;
}
void SourceFluxStatsAggregator::registerDataOnMesh( Group & meshBodies )
{
if( m_solver == nullptr )
{
return;
}

m_solver->forDiscretizationOnMeshTargets( meshBodies, [&] ( string const &,
MeshLevel & mesh,
arrayView1d< string const > const & )
{
registerWrappedStats( mesh, viewKeyStruct::fluxSetWrapperString() );
for( string const & fluxName : m_fluxNames )
{
registerWrappedStats( mesh, fluxName );

mesh.getElemManager().forElementRegions( [&]( ElementRegionBase & region )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the logLevel is low enough, then we don't need to create these wrappers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I use them to collect stats from the SinglePhaseBase::applySourceFluxBC() methods that have no knowledge of the regions. Can I keep them to collect the data or should I proceed differently?

{
Wrapper< WrappedStats > & regionStatsWrapper = registerWrappedStats( region, fluxName );
region.excludeWrappersFromPacking( { regionStatsWrapper.getName() } );

region.forElementSubRegions( [&]( ElementSubRegionBase & subRegion )
{
Wrapper< WrappedStats > & subRegionStatsWrapper = registerWrappedStats( subRegion, fluxName );
subRegion.excludeWrappersFromPacking( { subRegionStatsWrapper.getName() } );
} );
} );
}
} );
}

void SourceFluxStatsAggregator::writeStatData( integer minLogLevel,
string_view elementSetName,
WrappedStats const & wrappedStats )
{
if( getLogLevel() >= minLogLevel && logger::internal::rank == 0 )
{
GEOS_LOG_RANK( GEOS_FMT( "{} {} (of {}, in {}): Producing on {} elements",
catalogName(), getName(), wrappedStats.getFluxName(), elementSetName,
wrappedStats.stats().m_elementCount ) );

// we want to format differently if we have got multiple phases or not
if( wrappedStats.stats().m_producedMass.size() == 1 )
{
GEOS_LOG_RANK( GEOS_FMT( "{} {} (of {}, in {}): Produced mass = {} kg",
catalogName(), getName(), wrappedStats.getFluxName(), elementSetName,
wrappedStats.stats().m_producedMass[0] ) );
GEOS_LOG_RANK( GEOS_FMT( "{} {} (of {}, in {}): Production rate = {} kg/s",
catalogName(), getName(), wrappedStats.getFluxName(), elementSetName,
wrappedStats.stats().m_productionRate[0] ) );
}
else
{
GEOS_LOG_RANK( GEOS_FMT( "{} {} (of {}, in {}): Produced mass = {} kg",
catalogName(), getName(), wrappedStats.getFluxName(), elementSetName,
wrappedStats.stats().m_producedMass ) );
GEOS_LOG_RANK( GEOS_FMT( "{} {} (of {}, in {}): Production rate = {} kg/s",
catalogName(), getName(), wrappedStats.getFluxName(), elementSetName,
wrappedStats.stats().m_productionRate ) );
}
}
}

bool SourceFluxStatsAggregator::execute( real64 const GEOS_UNUSED_PARAM( time_n ),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, I'd be interested in decoupling the gathering/aggregation of the data from its output.
Here we impose log and csv, for example. There's no reason not to use the CSV for other types of data, and to impose CSV for the source flux data.

@MelReyCG , I had a quick chat with @arng40 about that.

Copy link
Contributor Author

@MelReyCG MelReyCG Mar 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to notify everyone about the conclusion of our chat on this subject:

  • There are currently a lot of these log / CSV output in the statistics classes,
  • Statistics output must be unified, and not strictly bound to CSV,
  • This output refactoring is not the subject of this PR, but is a task that I have got in my roadmap.
  • An Outputs new node could be created to output those stats, maybe something like:
<Outputs>
  <StatsOutput
    name="mySourceFluxesOutput"
    source="mySourceFluxesStats"
    outputFile="sourceFluxStats.csv" /> <!-- could be json or so -->
</Outputs>

real64 const GEOS_UNUSED_PARAM( dt ),
integer const GEOS_UNUSED_PARAM( cycleNumber ),
integer const GEOS_UNUSED_PARAM( eventCounter ),
real64 const GEOS_UNUSED_PARAM( eventProgress ),
DomainPartition & domain )
{
forMeshLevelStatsWrapper( domain,
[&] ( MeshLevel & meshLevel, WrappedStats & meshLevelStats )
{
meshLevelStats.stats() = StatData();

forAllFluxStatsWrappers( meshLevel,
[&] ( MeshLevel &, WrappedStats & fluxStats )
{
fluxStats.stats() = StatData();

forAllRegionStatsWrappers( meshLevel, fluxStats.getFluxName(),
[&] ( ElementRegionBase & region, WrappedStats & regionStats )
{
regionStats.stats() = StatData();

forAllSubRegionStatsWrappers( region, regionStats.getFluxName(),
[&] ( ElementSubRegionBase & subRegion, WrappedStats & subRegionStats )
{
subRegionStats.finalizePeriod();

regionStats.stats().combine( subRegionStats.stats() );
writeStatData( 4, subRegion.getName(), subRegionStats );
} );

fluxStats.stats().combine( regionStats.stats() );
writeStatData( 3, region.getName(), regionStats );
} );

meshLevelStats.stats().combine( fluxStats.stats() );
writeStatData( 2, viewKeyStruct::allRegionWrapperString(), fluxStats );
} );

writeStatData( 1, viewKeyStruct::allRegionWrapperString(), meshLevelStats );
} );

return false;
}



void SourceFluxStatsAggregator::StatData::allocate( integer phaseCount )
{
if( m_producedMass.size() != phaseCount )
{
m_producedMass.resize( phaseCount );
m_productionRate.resize( phaseCount );
}
}
void SourceFluxStatsAggregator::StatData::reset()
{
for( int ip = 0; ip < getPhaseCount(); ++ip )
{
m_producedMass[ip] = 0.0;
m_productionRate[ip] = 0.0;
}
m_elementCount = 0;
}
void SourceFluxStatsAggregator::StatData::combine( StatData const & other )
{
allocate( other.getPhaseCount() );

for( int ip = 0; ip < other.getPhaseCount(); ++ip )
{
m_producedMass[ip] += other.m_producedMass[ip];
m_productionRate[ip] += other.m_productionRate[ip];
}
m_elementCount += other.m_elementCount;
}
void SourceFluxStatsAggregator::StatData::mpiReduce()
{
for( int ip = 0; ip < getPhaseCount(); ++ip )
{
m_producedMass[ip] = MpiWrapper::sum( m_producedMass[ip] );
m_productionRate[ip] = MpiWrapper::sum( m_productionRate[ip] );
}
m_elementCount = MpiWrapper::sum( m_elementCount );
}

void SourceFluxStatsAggregator::WrappedStats::setTarget( string_view aggregatorName,
string_view fluxName )
{
m_aggregatorName = aggregatorName;
m_fluxName = fluxName;
}
void SourceFluxStatsAggregator::WrappedStats::gatherTimeStepStats( real64 const currentTime, real64 const dt,
arrayView1d< real64 const > const & producedMass,
integer const elementCount )
{
m_periodStats.allocate( producedMass.size() );

// if beginning a new timestep, we must aggregate the stats from previous timesteps (mass & dt) before collecting the new ones
bool isBeginingNewTS = currentTime >= ( m_periodStats.m_timeStepStart + m_periodStats.m_timeStepDeltaTime );
if( isBeginingNewTS )
{
for( int ip = 0; ip < m_periodStats.getPhaseCount(); ++ip )
{
m_periodStats.m_periodPendingMass[ip] += m_periodStats.m_timeStepMass[ip];
}
m_periodStats.m_elementCount = elementCount;
m_periodStats.m_periodPendingDeltaTime += m_periodStats.m_timeStepDeltaTime;
}

// new timestep stats to take into account
m_periodStats.m_timeStepStart = currentTime;
m_periodStats.m_timeStepDeltaTime = dt;
for( int ip = 0; ip < m_periodStats.getPhaseCount(); ++ip )
{
m_periodStats.m_timeStepMass = producedMass;
}
}
void SourceFluxStatsAggregator::WrappedStats::finalizePeriod()
{
// init phase data memory allocation if needed
m_stats.allocate( m_periodStats.getPhaseCount() );

// produce timestep stats of this ranks
m_stats.m_elementCount = m_periodStats.m_elementCount;

real64 const dt = m_periodStats.m_timeStepDeltaTime + m_periodStats.m_periodPendingDeltaTime;
real64 const timeDivisor = dt > 0.0 ? 1.0 / dt : 0.0;
for( int ip = 0; ip < m_periodStats.getPhaseCount(); ++ip )
{
real64 periodMass = m_periodStats.m_timeStepMass[ip] + m_periodStats.m_periodPendingMass[ip];
m_stats.m_producedMass[ip] = periodMass;
m_stats.m_productionRate[ip] = periodMass * timeDivisor;
}

// combine period results from all MPI ranks
m_stats.mpiReduce();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to be sure that this is called by all the ranks. Is it the case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, I tested that all ranks send & combine how much the SourceFlux produced / injected (possibly 0).


// start a new timestep
m_periodStats.reset();
}
void SourceFluxStatsAggregator::WrappedStats::PeriodStats::allocate( integer phaseCount )
{
if( m_timeStepMass.size() != phaseCount )
{
m_timeStepMass.resize( phaseCount );
m_periodPendingMass.resize( phaseCount );
}
}
void SourceFluxStatsAggregator::WrappedStats::PeriodStats::reset()
{
for( int ip = 0; ip < getPhaseCount(); ++ip )
{
m_timeStepMass[ip] = 0.0;
m_periodPendingMass[ip] = 0.0;
}
m_periodPendingDeltaTime = 0.0;
m_elementCount = 0;
m_timeStepStart = 0.0;
m_timeStepDeltaTime = 0.0;
}


REGISTER_CATALOG_ENTRY( TaskBase,
SourceFluxStatsAggregator,
string const &,
dataRepository::Group * const )

} /* namespace geos */
Loading
Loading