model::model(double in_t0, double in_t1, double in_mmin, double in_mmax, double in_cmfslope, double in_gamma_min, double in_gamma_max, double in_eta, double in_ageslope, double in_start, double in_stop, double in_step, double in_length, double in_fc){ f_c = in_fc; length = in_length; t0 = in_t0; t1 = in_t1; mmin = in_mmin; mmax = in_mmax; cmf_slope = in_cmfslope; cmf_slope1 = cmf_slope + 1.; eta = in_eta; gamma_min = in_gamma_min; gamma_max = in_gamma_max; age_slope = in_ageslope; start = in_start; stop = in_stop; step = in_step; //make array of luminosity convertying to ln L for(double v =log(pow(10,start)); v<log(pow(10,stop));v+=log(pow(10,step))){ x.push_back(v); } //cout<<x.size()<<endl; //exit(1); omega = (age_slope + 1.)/eta - cmf_slope1; if (cmf_slope == -1){ mean_m=(pow(mmax,cmf_slope+2)-pow(mmin,cmf_slope+2))/(cmf_slope+2); mean_m/=log(mmax/mmin); } else if( cmf_slope == -2){ mean_m=log(mmax/mmin); mean_m/=(pow(mmax,cmf_slope+1)-pow(mmin,cmf_slope+1))/(cmf_slope+1); }else{ mean_m=(pow(mmax,cmf_slope+2)-pow(mmin,cmf_slope+2))/(cmf_slope+2); mean_m/=(pow(mmax,cmf_slope+1)-pow(mmin,cmf_slope+1))/(cmf_slope+1); } //for(int i=0;i<(long)x.size();i++)cout<<x[i]<<endl; get_cdf(); //CDF needs to be first to get normalization right get_pdf(); /* sfr_grid.push_back(x); sfr_grid.push_back(x); sfr_grid.push_back(x); sfr_grid.push_back(x); cout<<x[0]<<"\t"<<x[1]<<endl; cout<<sfr_grid[0][0]<<"\t"<<sfr_grid[0][1]<<endl; cout<<sfr_grid[1][0]<<"\t"<<sfr_grid[1][1]<<endl; cout<<sfr_grid[2][0]<<"\t"<<sfr_grid[2][1]<<endl; cout<<sfr_grid[3][0]<<"\t"<<sfr_grid[3][1]<<endl; exit(1);*/ }
bool dssim::initialize( const Parameters_handler* parameters, Error_messages_handler* errors ) { OPEN_DEBUG_STREAM( "dssim.dbg" ); // Extract the parameters input by the user from the parameter handler //------------- // The "simulation" grid parameters std::string simul_grid_name = parameters->value( "Grid_Name.value" ); errors->report( simul_grid_name.empty(), "Grid_Name", "No grid selected" ); std::string property_name = parameters->value( "Property_Name.value" ); errors->report( property_name.empty(), "Property_Name", "No property name specified" ); // Get the simulation grid from the grid manager if( simul_grid_name.empty() ) return false; bool ok = geostat_utils::create( simul_grid_, simul_grid_name, "Grid_Name", errors ); if( !ok ) return false; // create a multi-realization property multireal_property_ = simul_grid_->add_multi_realization_property( property_name ); //------------- // The hard data parameters std::string harddata_grid_name = parameters->value( "Hard_Data.grid" ); if( !harddata_grid_name.empty() ) { std::string hdata_prop_name = parameters->value( "Hard_Data.property" ); errors->report( hdata_prop_name.empty(), "Hard_Data", "No property name specified" ); // Get the harddata grid from the grid manager bool ok = geostat_utils::create( harddata_grid_, harddata_grid_name, "Hard_Data", errors ); if( !ok ) return false; harddata_property_ = harddata_grid_->property( hdata_prop_name ); if( !harddata_property_ ) { std::ostringstream error_stream; error_stream << harddata_grid_name << " does not have a property called " << hdata_prop_name; errors->report( "Hard_Data", error_stream.str() ); return false; } } // hard data assignement and transform is only needed if we have a valid // hard data grid and property bool assign_harddata = String_Op::to_number<bool>( parameters->value( "Assign_Hard_Data.value" ) ); if( harddata_grid_ == NULL ) assign_harddata=false; else if( harddata_grid_ == simul_grid_ ) assign_harddata=true; if( harddata_grid_ ) { property_copier_ = Property_copier_factory::get_copier( harddata_grid_, simul_grid_ ); if( !property_copier_ ) { std::ostringstream message; message << "It is currently not possible to copy a property from a " << harddata_grid_->classname() << " to a " << simul_grid_->classname() ; errors->report( !property_copier_, "Assign_Hard_Data", message.str() ); return false; } } //------------- // Number of realizations and random number seed nb_of_realizations_ = String_Op::to_number<int>( parameters->value( "Nb_Realizations.value" ) ); seed_ = String_Op::to_number<int>( parameters->value( "Seed.value" ) ); //------------- // Variogram (covariance) initialization bool init_cov_ok = geostat_utils::initialize_covariance( &covar_, "Variogram", parameters, errors ); if( !init_cov_ok ) return false; //------------- // Set up the search neighborhood int max_neigh = String_Op::to_number<int>( parameters->value( "Max_Conditioning_Data.value" ) ); GsTLTriplet ranges; GsTLTriplet angles; bool extract_ok = geostat_utils::extract_ellipsoid_definition( ranges, angles, "Search_Ellipsoid.value", parameters, errors ); if( !extract_ok ) return false; extract_ok = geostat_utils::is_valid_range_triplet( ranges ); errors->report( !extract_ok, "Search_Ellipsoid", "Ranges must verify: major range >= " "medium range >= minor range >= 0" ); if( !extract_ok ) return false; // If the hard data are not "relocated" on the simulation grid, // use a "combined neighborhood", otherwise use a single // neighborhood if( !harddata_grid_ || assign_harddata ) { neighborhood_ = SmartPtr<Neighborhood>( simul_grid_->neighborhood( ranges, angles, &covar_ ) ); } else { Neighborhood* simul_neigh = simul_grid_->neighborhood( ranges, angles, &covar_ ); Neighborhood* harddata_neigh = harddata_grid_->neighborhood( ranges, angles, &covar_ ); harddata_neigh->max_size( max_neigh ); harddata_neigh->select_property( harddata_property_->name() ); neighborhood_ = SmartPtr<Neighborhood>( new Combined_neighborhood_dedup( harddata_neigh, simul_neigh, &covar_, false ) ); } neighborhood_->max_size( max_neigh ); //----------------- // The kriging constraints and combiner geostat_utils::KrigTagMap tags_map; tags_map[ geostat_utils::KT ] = "Trend.value"; tags_map[ geostat_utils::LVM ] = "Local_Mean_Property.value"; geostat_utils::KrigDefaultsMap defaults; defaults[ geostat_utils::SK ] = "0.0"; geostat_utils::Kriging_type ktype = geostat_utils::kriging_type( "Kriging_Type.value", parameters, errors ); if(ktype == geostat_utils::SK ) defaults[ geostat_utils::SK ] = parameters->value("SK_mean.value"); geostat_utils::initialize( ktype, combiner_, Kconstraints_, tags_map, parameters, errors, simul_grid_, defaults ); // Type and parametrization of the cdf get_cdf( parameters, errors ); //ccdf_ = get_cdf( parameters, errors ); //---------------- // Report errors if any if( !errors->empty() ) return false; return true; }