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

Open
wants to merge 107 commits into
base: develop
Choose a base branch
from
Open

Conversation

MelReyCG
Copy link
Contributor

@MelReyCG MelReyCG commented Jan 25, 2024

The goal of this PR is to add a SourceFluxStatistics component which aggregate the producted mass & rate on a SourceFlux set.

  • Log Level 1 outputs the sum of all SourceFluxStatistics produced rate & mass,
  • Log Level 2 details values for each SourceFluxStatistics,
  • Log Level 3 details values for each region.

Here is the typical log output for a multi-phase simulation, with a log level of 2 :

Rank 0: SourceFluxStatistics timeStepFluxStats (of sourceFlux, in all_regions): Producing on 1 elements
Rank 0: SourceFluxStatistics timeStepFluxStats (of sourceFlux, in all_regions): Produced mass = [-280.5, 0] kg
Rank 0: SourceFluxStatistics timeStepFluxStats (of sourceFlux, in all_regions): Production rate = [-0.561, 0] kg/s
Rank 0: SourceFluxStatistics timeStepFluxStats (of sinkFlux, in all_regions): Producing on 1 elements
Rank 0: SourceFluxStatistics timeStepFluxStats (of sinkFlux, in all_regions): Produced mass = [0, 31] kg
Rank 0: SourceFluxStatistics timeStepFluxStats (of sinkFlux, in all_regions): Production rate = [0, 0.062] kg/s
Rank 0: SourceFluxStatistics timeStepFluxStats (of flux_set, in all_regions): Producing on 2 elements
Rank 0: SourceFluxStatistics timeStepFluxStats (of flux_set, in all_regions): Produced mass = [-280.5, 31] kg
Rank 0: SourceFluxStatistics timeStepFluxStats (of flux_set, in all_regions): Production rate = [-0.561, 0.062] kg/s

Note: If the PeriodicEvent that execute the SourceFluxStatistics has a frequency such as multiple time-step are encountered, the statistics are aggregated (masses -> sum, rates -> mean).

I've also added a test which checks if the statistics output of the SourceFluxStatistics and SinglePhaseStatistics::RegionStatistics::totalMass are consistent with the provided production rates table.
The test checks if the statistics are right over the whole simulation, but also for each timesteps. It will crash if a timestep does not run. Thus, it tests if the PeriodicEvent functions as expected (is it the only test to do so ?).

@MelReyCG MelReyCG self-assigned this Jan 25, 2024
@MelReyCG MelReyCG added the type: feature New feature or request label Jan 25, 2024
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks like a task that should belong to physicsSolvers and not quite a fieldSpecification.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So the solvers would expose the producted rates & masses for each SourceFlux, and then the SourceFluxStatistics would access to it?

{
registerWrappedStats( mesh, fluxName, viewKeyStruct::allRegionWrapperString() );

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?

Copy link
Contributor

@TotoGaz TotoGaz left a comment

Choose a reason for hiding this comment

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

That looks like a nice feature.
A question about the display though.

}
}

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>

@MelReyCG MelReyCG requested a review from TotoGaz April 4, 2024 07:28
Comment on lines +141 to +148
case Viscosity: return "Pa*s";
case Enthalpy: return "J/kg";
case Density: return "kg/m3";
case Solubility: return "g/L";
case Mass: return "kg";
case Mole: return "mol";
case MassRate: return "kg/s";
case MoleRate: return "mol/s";
Copy link
Collaborator

Choose a reason for hiding this comment

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

Units are not really strongly enforced in GEOS. One could use any set of units as long as they are consistent. For example a user can decide to specify pressures in MPa an adjust all other properties. I would say that we either properly introduce a unit parser or these units can easily be false.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

About this header, it is in S.I. by default (following the GEOS convention). Some units can be in other systems as you can see for the temperatures (°C rather than °K), and if someone want to add more, I think it should come with conversion functions.
I strongly advise to add comments on all non-S.I. variables / method, it would be less error-prone and would help when implementing a parsing unit system or when adding new outputs.

About adding unit parsing system, it is on my roadmap. Feel free to add suggestions on my EPIC.

@@ -305,7 +304,7 @@ void CompositionalMultiphaseStatistics::computeRegionStatistics( real64 const ti
subRegionImmobilePhaseMass.toView(),
subRegionComponentMass.toView() );

ElementRegionBase & region = elemManager.getRegion( subRegion.getParent().getParent().getName() );
ElementRegionBase & region = elemManager.getRegion( ElementRegionBase::getParentRegion( subRegion ).getName() );
Copy link
Contributor

Choose a reason for hiding this comment

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

That's better!

* As this Group is designed for developpers and not user oriented, it should not appear in the documentation nor in the xsd.
* Question: could this task be used in the integratedTests ?
*/
class TimeStepChecker : public TaskBase
Copy link
Contributor

Choose a reason for hiding this comment

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

@CusiniM What do you think of this. I believe that's interesting.

@@ -734,6 +734,7 @@ class SolverBase : public ExecutableGroup
virtual bool registerCallback( void * func, const std::type_info & funcType ) final override;

SolverStatistics & getSolverStatistics() { return m_solverStatistics; }
SolverStatistics const & getSolverStatistics() const { return m_solverStatistics; }
Copy link
Contributor

Choose a reason for hiding this comment

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

Who's using the non-const version?
If you can, can you remove it or use a setter instead?

Copy link
Contributor Author

@MelReyCG MelReyCG Jun 4, 2024

Choose a reason for hiding this comment

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

It is used at src/coreComponents/physicsSolvers/multiphysics/CoupledSolver.hpp:431, 491, 506, I think the non-const version is useful, should I remove the const one?

regionStats.stats() = StatData();

forAllSubRegionStatsWrappers( region, regionStats.getFluxName(),
[&] ( ElementSubRegionBase &, WrappedStats & subRegionStats )
Copy link
Contributor

Choose a reason for hiding this comment

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

4 nested lambda functions, I think that you tie the record 🤣 😉

}

// 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).

@MelReyCG MelReyCG added the ci: run CUDA builds Allows to triggers (costly) CUDA jobs label Jun 5, 2024
@paveltomin paveltomin added the ci: run integrated tests Allows to run the integrated tests in GEOS CI label Jun 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci: run CUDA builds Allows to triggers (costly) CUDA jobs ci: run integrated tests Allows to run the integrated tests in GEOS CI type: feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Output SourceFlux statistics,
6 participants