Skip to content

Commit

Permalink
Improved UniformOverMesh
Browse files Browse the repository at this point in the history
Now, computeCDF() uses the new Mesh intersection capabilities to improve both the speed and the precision of the computation in 2D.
  • Loading branch information
regislebrun committed Jul 29, 2024
1 parent 3eeec24 commit b1953e9
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions lib/src/Uncertainty/Distribution/UniformOverMesh.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "openturns/RegularGrid.hxx"
#include "openturns/DistFunc.hxx"
#include "openturns/GaussLegendre.hxx"
#include "openturns/IntervalMesher.hxx"
#include "openturns/PersistentObjectFactory.hxx"


Expand Down Expand Up @@ -202,8 +203,24 @@ Scalar UniformOverMesh::computeCDF(const Point & point) const
// Waiting for a better implementation
const Interval quadrant(Point(getDimension(), -SpecFunc::MaxScalar), point);
const Interval intersection(quadrant.intersect(getRange()));
if (intersection == getRange()) cdf = 1.0;
else if (!intersection.isEmpty())
Bool useIntegration = false;
if (intersection.isEmpty())
cdf = 0.0;
else if (intersection == getRange()) cdf = 1.0;
else if (getDimension() == 2)
{
#ifdef OPENTURNS_HAVE_BOOST
const Mesh intersectionMesh(mesh_.intersect(IntervalMesher(Indices(2, 1)).build(intersection)));
const Point intersectionVolumes_(intersectionMesh.computeSimplicesVolume());
const Scalar intersectionVolume = std::accumulate(intersectionVolumes_.begin(), intersectionVolumes_.end(), 0.0);
cdf = intersectionVolume / meshVolume_;
#else
useIntegration = true;
#endif
}
else
useIntegration = true; // getDimension() != 2
if (useIntegration)
cdf = integrationAlgorithm_.integrate(PDFWrapper(this), intersection)[0];
return cdf;
}
Expand Down

0 comments on commit b1953e9

Please sign in to comment.