1.3.2
CCC
 
simtub.cpp File Reference
#include "geoslib_f.h"
#include "geoslib_old_f.h"
#include "geoslib_f_private.h"
#include "Enum/EJustify.hpp"
#include "Enum/ECov.hpp"
#include "Enum/EProcessOper.hpp"
#include "Enum/ERule.hpp"
#include "Calculators/CalcMigrate.hpp"
#include "Gibbs/GibbsUMultiMono.hpp"
#include "Gibbs/GibbsUPropMono.hpp"
#include "Gibbs/GibbsMMulti.hpp"
#include "Gibbs/GibbsFactory.hpp"
#include "Morpho/Morpho.hpp"
#include "Covariances/CovAniso.hpp"
#include "Basic/MathFunc.hpp"
#include "Basic/String.hpp"
#include "Basic/NamingConvention.hpp"
#include "Basic/Utilities.hpp"
#include "Basic/Law.hpp"
#include "Basic/File.hpp"
#include "Basic/OptDbg.hpp"
#include "Basic/OptCustom.hpp"
#include "LithoRule/PropDef.hpp"
#include "LithoRule/Rule.hpp"
#include "LithoRule/RuleShift.hpp"
#include "LithoRule/RuleShadow.hpp"
#include "LithoRule/RuleProp.hpp"
#include "Db/Db.hpp"
#include "Model/Model.hpp"
#include "Neigh/NeighUnique.hpp"
#include "Neigh/NeighMoving.hpp"
#include "Simulation/CalcSimuTurningBands.hpp"
#include "Simulation/SimuBoolean.hpp"
#include "Simulation/SimuBooleanParam.hpp"
#include "Simulation/SimuSpherical.hpp"
#include "Simulation/SimuSphericalParam.hpp"
#include "Simulation/SimuFFTParam.hpp"
#include "Simulation/SimuRefineParam.hpp"
#include "Simulation/SimuRefine.hpp"
#include "Simulation/CalcSimuEden.hpp"
#include "Simulation/CalcSimuFFT.hpp"
#include "Space/SpaceRN.hpp"
#include <math.h>
#include <string.h>

Functions

void simu_func_categorical_transf (Db *db, int verbose, int isimu, int nbsimu)
 
void simu_func_continuous_update (Db *db, int verbose, int isimu, int nbsimu)
 
void simu_func_categorical_update (Db *db, int verbose, int isimu, int nbsimu)
 
void simu_func_continuous_scale (Db *db, int verbose, int nbsimu)
 
void simu_func_categorical_scale (Db *db, int verbose, int nbsimu)
 
void check_mandatory_attribute (const char *method, Db *db, const ELoc &locatorType)
 
int get_rank_from_propdef (PropDef *propdef, int ipgs, int igrf)
 
int simpgs (Db *dbin, Db *dbout, RuleProp *ruleprop, Model *model1, Model *model2, ANeigh *neigh, int nbsimu, int seed, int flag_gaus, int flag_prop, int flag_check, int flag_show, int nbtuba, int gibbs_nburn, int gibbs_niter, double percent, const NamingConvention &namconv)
 
int simbipgs (Db *dbin, Db *dbout, RuleProp *ruleprop, Model *model11, Model *model12, Model *model21, Model *model22, ANeigh *neigh, int nbsimu, int seed, int flag_gaus, int flag_prop, int flag_check, int flag_show, int nbtuba, int gibbs_nburn, int gibbs_niter, double percent, const NamingConvention &namconv)
 
int db_simulations_to_ce (Db *db, const ELoc &locatorType, int nbsimu, int nvar, int *iptr_ce_arg, int *iptr_cstd_arg)
 
int gibbs_sampler (Db *dbin, Model *model, int nbsimu, int seed, int gibbs_nburn, int gibbs_niter, bool flag_moving, bool flag_norm, bool flag_multi_mono, bool flag_propagation, bool flag_sym_neigh, int gibbs_optstats, double percent, bool flag_ce, bool flag_cstd, bool verbose, const NamingConvention &namconv)
 
int simtub_constraints (Db *dbin, Db *dbout, Model *model, ANeigh *neigh, int seed, int nbtuba, int nbsimu_min, int nbsimu_quant, int niter_max, VectorInt &cols, int(*func_valid)(int flag_grid, int nDim, int nech, int *nx, double *dx, double *x0, double nonval, double percent, VectorDouble &tab))
 
int simmaxstable (Db *dbout, Model *model, double ratio, int seed, int nbtuba, int flag_simu, int flag_rank, int verbose)
 
int simRI (Db *dbout, Model *model, int ncut, double *zcut, double *wcut, int seed, int nbtuba, int verbose)
 
int simpgs_spde (Db *dbin, Db *dbout, RuleProp *ruleprop, Model *model1, Model *model2, const String &triswitch, const VectorDouble &gext, int flag_gaus, int flag_prop, int flag_check, int flag_show, int nfacies, int seed, int nbsimu, int gibbs_nburn, int gibbs_niter, int ngibbs_int, int verbose, double percent)
 
int simcond (Db *dbin, Db *dbout, Model *model, int seed, int nbsimu, int nbtuba, int gibbs_nburn, int gibbs_niter, int flag_check, int flag_ce, int flag_cstd, int verbose)
 
int simsph (DbGrid *db, Model *model, const SimuSphericalParam &sphepar, int seed, bool verbose, const NamingConvention &namconv)
 
VectorDouble simsph_mesh (MeshSpherical *mesh, Model *model, const SimuSphericalParam &sphepar, int seed, int verbose)
 
DbGridsimfine (DbGrid *dbin, Model *model, const SimuRefineParam &param, int seed)
 
MatrixRectangular fluid_extract (DbGrid *dbgrid, const String &name_facies, const String &name_fluid, const String &name_poro, const String &name_date, int nfacies, int nfluids, int facies0, int fluid0, int ntime, double time0, double dtime, bool verbose)
 

Function Documentation

◆ check_mandatory_attribute()

void check_mandatory_attribute ( const char *  method,
Db db,
const ELoc &  locatorType 
)

Check for the presence of mandatory attributes

Parameters
[in]methodName of the method
[in]dbDb structure
[in]locatorTypeMandatory attribute type

◆ db_simulations_to_ce()

int db_simulations_to_ce ( Db db,
const ELoc &  locatorType,
int  nbsimu,
int  nvar,
int *  iptr_ce_arg,
int *  iptr_cstd_arg 
)

Convert series of simulations to conditional expectation and variance

Returns
Error return code
Parameters
[in]dbDb structure
[in]locatorTypeType of pointer containing the simulations
[in]nbsimuNumber of simulations
[in]nvarNumber of variables
[out]iptr_ce_argPointer to the Conditional Expectation attributes
[out]iptr_cstd_argPointer to the Conditional St. Dev. attributes

◆ fluid_extract()

MatrixRectangular fluid_extract ( DbGrid dbgrid,
const String name_facies,
const String name_fluid,
const String name_poro,
const String name_date,
int  nfacies,
int  nfluids,
int  facies0,
int  fluid0,
int  ntime,
double  time0,
double  dtime,
bool  verbose 
)

Extract time charts from the fluid propagation block

Returns
The returned matrix
Parameters
[in]dbgridDb grid structure
[in]name_faciesName of variable containing Facies
[in]name_fluidName of variable containing Fluid
[in]name_poroName of variable containing Porosity (optional)
[in]name_dateName of variable containing Date
[in]nfaciesnumber of facies (facies 0 excluded)
[in]nfluidsnumber of fluids
[in]facies0Value of the target facies
[in]fluid0Value of the target fluid
[in]ntimeNumber of Time intervals
[in]time0Starting time
[in]dtimeTime interval
[in]verbose1 for a verbose option

◆ get_rank_from_propdef()

int get_rank_from_propdef ( PropDef propdef,
int  ipgs,
int  igrf 
)

Give the rank of a "variable" for a given GRF and PGS

Returns
Returned rank
Parameters
[in]propdefPropDef structure
[in]ipgsRank of the GS
[in]igrfRank of the Gaussian

◆ gibbs_sampler()

int gibbs_sampler ( Db dbin,
Model model,
int  nbsimu,
int  seed,
int  gibbs_nburn,
int  gibbs_niter,
bool  flag_moving,
bool  flag_norm,
bool  flag_multi_mono,
bool  flag_propagation,
bool  flag_sym_neigh,
int  gibbs_optstats,
double  percent,
bool  flag_ce,
bool  flag_cstd,
bool  verbose,
const NamingConvention namconv 
)

Perform the Gibbs sampler

Returns
Error return code
Parameters
[in]dbinDb structure
[in]modelModel structure
[in]nbsimuNumber of simulations
[in]seedSeed for random number generator
[in]gibbs_nburnInitial number of iterations for bootstrapping
[in]gibbs_niterMaximum number of iterations
[in]flag_moving1 for Moving
[in]flag_norm1 if the Model must be normalized
[in]flag_multi_mono1 for the Multi_mono algorithm
[in]flag_propagation1 for the propagation algorithm
[in]flag_sym_neighDeprecated argument
[in]gibbs_optstats0: No stats - 1: Print - 2: Save Neutral file
[in]percentAmount of nugget effect added to too continuous model (expressed in percentage of total variance)
[in]flag_ce1 if the conditional expectation should be returned instead of simulations
[in]flag_cstd1 if the conditional standard deviation should be returned instead of simulations
[in]verboseVerbose flag
[in]namconvNaming convention

◆ simbipgs()

int simbipgs ( Db dbin,
Db dbout,
RuleProp ruleprop,
Model model11,
Model model12,
Model model21,
Model model22,
ANeigh neigh,
int  nbsimu,
int  seed,
int  flag_gaus,
int  flag_prop,
int  flag_check,
int  flag_show,
int  nbtuba,
int  gibbs_nburn,
int  gibbs_niter,
double  percent,
const NamingConvention namconv 
)

Perform the conditional or non-conditional Bi Pluri-gaussian simulations

Returns
Error return code
Parameters
[in]dbinInput Db structure (optional)
[in]dboutOutput Db structure
[in]rulepropRuleprop definition
[in]model11First Model structure for First Lithotype Rule
[in]model12Second Model structure for First Lithotype Rule
[in]model21First Model structure for Second Lithotype Rule
[in]model22Second Model structure for Second Lithotype Rule
[in]neighANeigh structure
[in]nbsimuNumber of simulations
[in]seedSeed for random number generator
[in]flag_gaus1 gaussian results; otherwise facies
[in]flag_prop1 for facies proportion
[in]flag_check1 if the facies at data must be checked against the closest simulated grid node
[in]flag_show1 if the grid node which coincides with the data should be represented with the data facies (only if flag_cond && !flag_gaus)
[in]nbtubaNumber of turning bands
[in]gibbs_nburnNumber of bootstrap iterations
[in]gibbs_niterMaximum number of iterations
[in]percentAmount of nugget effect added to too continuous model (expressed in percentage of the total variance)
[in]namconvNaming convention
Remarks
When conditional, the two first variables in the input Db
should correspond to the two facies indices (starting from 1)
The argument 'dbin' is optional: it must be defined only for
conditional simulations
The proportions (nfac1 * nfac2) must be ordered as follows:
f1af2a, f1bf2a, f1cf2a, ..., f1bf2a, f1bf2b, ..., f1nf2m

◆ simcond()

int simcond ( Db dbin,
Db dbout,
Model model,
int  seed,
int  nbsimu,
int  nbtuba,
int  gibbs_nburn,
int  gibbs_niter,
int  flag_check,
int  flag_ce,
int  flag_cstd,
int  verbose 
)

Perform the conditional simulations under inequality constraints

Returns
Error return code
Parameters
[in]dbinInput Db structure (optional)
[in]dboutOutput Db structure
[in]modelModel structure
[in]seedSeed for random number generator
[in]nbsimuNumber of simulations
[in]nbtubaNumber of turning bands
[in]gibbs_nburnInitial number of iterations for bootstrapping
[in]gibbs_niterMaximum number of iterations
[in]flag_check1 to check the proximity in Gaussian scale
[in]flag_ce1 if the conditional expectation should be returned instead of simulations
[in]flag_cstd1 if the conditional standard deviation should be returned instead of simulations
[in]verboseVerbose flag
Remarks
The Neighborhood does not have to be defined as this method
only functions using a Unique Neighborhood. For consistency
it is generated internally.

◆ simfine()

DbGrid* simfine ( DbGrid dbin,
Model model,
const SimuRefineParam param,
int  seed 
)

Refine the simulation

Returns
Newly refined Grid.
Parameters
[in]dbinInput grid Db structure
[in]modelModel structure
[in]paramSimuRefineParam structure
[in]seedSeed for the random number generator
Remarks
For each dimension of the space, if N stands for the number of
nodes in the input grid, the number of nodes of the output grid
will be (N-1) * 2^p + 1 where p is the param.getNmult()

◆ simmaxstable()

int simmaxstable ( Db dbout,
Model model,
double  ratio,
int  seed,
int  nbtuba,
int  flag_simu,
int  flag_rank,
int  verbose 
)

Perform the non-conditional simulation of the Max-Stable Model

Returns
Error return code
Parameters
[in]dboutOutput Db structure
[in]modelModel structure
[in]ratioRatio modifying the range at each iteration
[in]seedSeed for random number generator
[in]nbtubaNumber of turning bands
[in]flag_simu1 if the simulation must be stored
[in]flag_rank1 if the iteration rank must be stored
[in]verboseVerbose flag
Remarks
This function uses a threshold that can be defined using
keypair mechanism with keyword "MaxStableThresh".

◆ simpgs()

int simpgs ( Db dbin,
Db dbout,
RuleProp ruleprop,
Model model1,
Model model2,
ANeigh neigh,
int  nbsimu,
int  seed,
int  flag_gaus,
int  flag_prop,
int  flag_check,
int  flag_show,
int  nbtuba,
int  gibbs_nburn,
int  gibbs_niter,
double  percent,
const NamingConvention namconv 
)

Perform the conditional or non-conditional Pluri-gaussian simulations

Returns
Error return code
Parameters
[in]dbinInput Db structure (optional)
[in]dboutOutput Db structure
[in]rulepropRuleProp structure
[in]model1First Model structure
[in]model2Second Model structure (optional)
[in]neighANeigh structure
[in]nbsimuNumber of simulations
[in]seedSeed for random number generator
[in]flag_gaus1 if results must be gaussian; otherwise facies
[in]flag_prop1 for facies proportion
[in]flag_check1 if the facies at data must be checked against the closest simulated grid node
[in]flag_show1 if the grid node which coincides with the data should be represented with the data facies (only if flag_cond && !flag_gaus)
[in]nbtubaNumber of turning bands
[in]gibbs_nburnNumber of bootstrap iterations
[in]gibbs_niterMaximum number of iterations
[in]percentAmount of nugget effect added to too much continous model (expressed in percentage of the total variance)
[in]namconvNaming convention
Remarks
When conditional, the unique variable in the input Db structure
should correspond to the facies index (starting from 1)
The argument 'dbin' is optional: it must be defined only for
conditional simulations

◆ simpgs_spde()

int simpgs_spde ( Db dbin,
Db dbout,
RuleProp ruleprop,
Model model1,
Model model2,
const String triswitch,
const VectorDouble gext,
int  flag_gaus,
int  flag_prop,
int  flag_check,
int  flag_show,
int  nfacies,
int  seed,
int  nbsimu,
int  gibbs_nburn,
int  gibbs_niter,
int  ngibbs_int,
int  verbose,
double  percent 
)

Perform the conditional Pluri-gaussian simulations using spde

Returns
Error return code
Parameters
[in]dbinInput Db structure (optional)
[in]dboutOutput Db structure
[in]rulepropRuleProp definition
[in]model1First Model structure
[in]model2Second Model structure (optional)
[in]triswitchMeshing option
[in]gextArray of domain dilation
[in]flag_gaus1 if results must be gaussian; otherwise facies
[in]flag_prop1 for facies proportion
[in]flag_check1 if the facies at data must be checked against the closest simulated grid node
[in]flag_show1 if the grid node which coincides with the data should be represented with the data facies
[in]nfaciesNumber of facies
[in]seedSeed for random number generator
[in]nbsimuNumber of simulations
[in]gibbs_nburnNumber of iterations (Burning step)
[in]gibbs_niterMaximum number of iterations
[in]ngibbs_intNumber of iterations internal to Gibbs (SPDE)
[in]verboseVerbose flag
[in]percentAmount of nugget effect added to too continous model (expressed in percentage of the total variance)
Remarks
When conditional, the unique variable in the input Db structure
should correspond to the facies index (starting from 1)

◆ simRI()

int simRI ( Db dbout,
Model model,
int  ncut,
double *  zcut,
double *  wcut,
int  seed,
int  nbtuba,
int  verbose 
)

Perform the non-conditional simulation of the Orthogonal Residual Model

Returns
Error return code
Parameters
[in]dboutOutput Db structure
[in]modelModel structure
[in]ncutNumber of cutoffs
[in]zcutArray of cutoffs
[in]wcutArray of weights
[in]seedSeed for random number generator
[in]nbtubaNumber of turning bands
[in]verboseVerbose flag

◆ simsph()

int simsph ( DbGrid db,
Model model,
const SimuSphericalParam sphepar,
int  seed,
bool  verbose,
const NamingConvention namconv 
)

Simulates the random function on the sphere

Parameters
[in]dbData base containing the coordinates of target points These coordinates must be expressed in long/lat
[in]modelModel (defined in Euclidean space) to be used
[in]spheparSimuSphericalParam structure
[in]seedSeed for random number generation
[in]verboseVerbose flag
[in]namconvNaming convention

◆ simsph_mesh()

VectorDouble simsph_mesh ( MeshSpherical mesh,
Model model,
const SimuSphericalParam sphepar,
int  seed,
int  verbose 
)

Simulates the random function on the sphere

Returns
The Vector simulated values
Parameters
[in]meshMeshSpherical object
[in]modelModel (defined in Euclidean space) to be used
[in]spheparSimuSphericalParam structure
[in]seedSeed for random number generation
[in]verboseVerbose flag

◆ simtub_constraints()

int simtub_constraints ( Db dbin,
Db dbout,
Model model,
ANeigh neigh,
int  seed,
int  nbtuba,
int  nbsimu_min,
int  nbsimu_quant,
int  niter_max,
VectorInt cols,
int(*)(int flag_grid, int nDim, int nech, int *nx, double *dx, double *x0, double nonval, double percent, VectorDouble &tab)  func_valid 
)

Perform a set of valid conditional or non-conditional simulations

Returns
Error return code
Parameters
[in]dbinInput Db structure (optional)
[in]dboutOutput Db structure
[in]modelModel structure
[in]neighANeigh structure (optional)
[in]seedSeed for random number generator
[in]nbtubaNumber of turning bands
[in]nbsimu_minMinimum number of simulations
[in]nbsimu_quantAdditional quantum of simulations
[in]niter_maxMaximum number of iterations
[in]colsVector of column indices
[in]func_validTesting function
Remarks
This function calls a simulation outcome.
It provides a return code:
-1: the simulation outcome is not valid and the process must be
interrupted gently with no error (case of non-convergence)
0: the simulation outcome is not valid
1: the simulation outcome is valid and must be kept
2: the simulation outcome is valid and its returned version
must be kept (this is usefull if func_valid() has modified it).
The func_valid prototype has the following arguments:
  • ndim Space dimension
  • nx Array of number of grid meshes along all space direction
  • dx Array of grid mesh along all space direction
  • x0 Array of grid origin along all space direction
  • nonval Value corresponding to a missing grid value
  • percent Percentage of the simulations already validated
  • tab Array containing the simulated outcome
The following lines give an example of func_valid() which considers
a simulation outcome as valid if more than 50% of the valid samples
have a positive value.
int func_valid(int flag_grid,int ndim,int nech,
int *nx,double *dx,double *x0,
double nonval, double percent, double *tab)
{
double ratio;
int i,npositive,nvalid;
for (i=0; i<nech; i++)
{
if (tab[i] == nonval) continue;
nvalid++;
if (tab[i] > 10.) npositive++;
}
ratio = (nvalid > 0) ? npositive / nvalid : 0.;
return(ratio > 0.5);
}

◆ simu_func_categorical_scale()

void simu_func_categorical_scale ( Db db,
int  verbose,
int  nbsimu 
)

Scaling function for the Modification categorical case

Parameters
[in]dbDb structure
[in]verbose1 for the verbose flag
[in]nbsimuNumber of simulations

◆ simu_func_categorical_transf()

void simu_func_categorical_transf ( Db db,
int  verbose,
int  isimu,
int  nbsimu 
)

Transformation function for the Modification categorical case

Parameters
[in]dbDb structure
[in]verbose1 for the verbose flag
[in]isimuRank of the current simulation
[in]nbsimuNumber of simulations

◆ simu_func_categorical_update()

void simu_func_categorical_update ( Db db,
int  verbose,
int  isimu,
int  nbsimu 
)

Updating function for the Modification categorical case

Parameters
[in]dbDb structure
[in]verbose1 for the verbose flag
[in]isimuRank of the current simulation
[in]nbsimuNumber of simulations (stored)

◆ simu_func_continuous_scale()

void simu_func_continuous_scale ( Db db,
int  verbose,
int  nbsimu 
)

Scaling function for the Modification continuous case

Parameters
[in]dbDb structure
[in]verbose1 for the verbose flag
[in]nbsimuNumber of simulations

◆ simu_func_continuous_update()

void simu_func_continuous_update ( Db db,
int  verbose,
int  isimu,
int  nbsimu 
)

Updating function for the Modification continuous case

Parameters
[in]dbDb structure
[in]verbose1 for the verbose flag
[in]isimuRank of the current simulation
[in]nbsimuNumber of simulations (stored)