Back to index

salome-smesh  6.5.0
Functions
StdMeshers_Distribution.cxx File Reference
#include "StdMeshers_Distribution.hxx"
#include <math_GaussSingleIntegration.hxx>
#include <utilities.h>
#include <Standard_Failure.hxx>

Go to the source code of this file.

Functions

double dihotomySolve (Function &f, const double val, const double _start, const double _fin, const double eps, bool &ok)
bool buildDistribution (const TCollection_AsciiString &f, const int conv, const double start, const double end, const int nbSeg, vector< double > &data, const double eps)
bool buildDistribution (const std::vector< double > &f, const int conv, const double start, const double end, const int nbSeg, vector< double > &data, const double eps)
bool buildDistribution (const Function &func, const double start, const double end, const int nbSeg, vector< double > &data, const double eps)

Function Documentation

bool buildDistribution ( const TCollection_AsciiString &  f,
const int  conv,
const double  start,
const double  end,
const int  nbSeg,
vector< double > &  data,
const double  eps 
)

Definition at line 306 of file StdMeshers_Distribution.cxx.

{
  FunctionExpr F( f.ToCString(), conv );
  return buildDistribution( F, start, end, nbSeg, data, eps );
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool buildDistribution ( const std::vector< double > &  f,
const int  conv,
const double  start,
const double  end,
const int  nbSeg,
vector< double > &  data,
const double  eps 
)

Definition at line 313 of file StdMeshers_Distribution.cxx.

{
  FunctionTable F( f, conv );
  return buildDistribution( F, start, end, nbSeg, data, eps );
}

Here is the call graph for this function:

bool buildDistribution ( const Function &  func,
const double  start,
const double  end,
const int  nbSeg,
vector< double > &  data,
const double  eps 
)

Definition at line 320 of file StdMeshers_Distribution.cxx.

{
  if( nbSeg<=0 )
    return false;

  data.resize( nbSeg+1 );
  data[0] = start;
  double J = func.integral( start, end ) / nbSeg;
  if( J<1E-10 )
    return false;

  bool ok;
  //MESSAGE( "distribution:" );
  //char buf[1024];
  for( int i=1; i<nbSeg; i++ )
  {
    FunctionIntegral f_int( &func, data[i-1] );
    data[i] = dihotomySolve( f_int, J, data[i-1], end, eps, ok );
    //sprintf( buf, "%f\n", float( data[i] ) );
    //MESSAGE( buf );
    if( !ok )
      return false;
  }

  data[nbSeg] = end;
  return true;
}

Here is the call graph for this function:

double dihotomySolve ( Function &  f,
const double  val,
const double  _start,
const double  _fin,
const double  eps,
bool &  ok 
)

Definition at line 260 of file StdMeshers_Distribution.cxx.

{
  double start = _start, fin = _fin, start_val, fin_val; bool ok1, ok2;
  ok1 = f.value( start, start_val );
  ok2 = f.value( fin, fin_val );

  if( !ok1 || !ok2 )
  {
    ok = false;
    return 0.0;
  }

  bool start_pos = start_val>=val, fin_pos = fin_val>=val;
  ok = true;
  
  while( fin-start>eps )
  {
    double mid = ( start+fin )/2.0, mid_val;
    ok = f.value( mid, mid_val );
    if( !ok )
      return 0.0;

    //char buf[1024];
    //sprintf( buf, "start=%f\nfin=%f\nmid_val=%f\n", float( start ), float( fin ), float( mid_val ) );
    //MESSAGE( buf );

    bool mid_pos = mid_val>=val;
    if( start_pos!=mid_pos )
    {
      fin_pos = mid_pos;
      fin = mid;
    }
    else if( fin_pos!=mid_pos )
    {
      start_pos = mid_pos;
      start = mid;
    }
    else
    {
      ok = false;
      break;
    }
  }
  return (start+fin)/2.0;
}

Here is the caller graph for this function: