public EruptionValues(Eruption erupt, Wind[] wind, Config config) { Guard.NotNull(erupt, "erupt"); Guard.NotNull(wind, "wind"); Guard.NotNull(config, "config"); _config = config; SetEruptionValues(erupt, wind, config); }
public Config Read() { Logger.Info("Reading Configuration"); var result = new Config(); foreach (var tokens in _configFileContent .Where(configLine => !string.IsNullOrWhiteSpace(configLine)) .Select(configLine => configLine.Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries))) { ReadTokensIntoConfig(tokens, result); } return result; }
public static Wind[][] GetWind(string[] configFileContent, Config config) { var wind = new WindFactory(); try { return wind.get_wind(config, GetWindData(configFileContent)); } catch (IOException e) { // TODO Auto-generated catch block //e.printStackTrace(); } return null; }
//private FileInfo configFileInfo = getResourceFile("CerroNegro.conf"); //@Option(name= "-p", usage= "Point File", required= false) //private File pointFile = getResourceFile("CerroNegro.pos"); //@Option(name= "-w", usage= "Wind File", required= false) //private File windFile = getResourceFile("CerroNegro.wind"); // receives other command line parameters than options //@Argument //private List<String> arguments = new ArrayList<String>(); private static Config GetDefaultConfig() { var defaultConfig = new Config(); return defaultConfig; }
private static void PrintConfig(Config config) { Console.WriteLine("Config:"); Console.WriteLine("\tAirDensity:" + config.AirDensity); Console.WriteLine("\tAirViscosity:" + config.AirViscosity); Console.WriteLine("\tColumnIntegrationSteps:" + config.ColumnIntegrationSteps); Console.WriteLine("\tDiffusionCoefficient:" + config.DiffusionCoefficient); Console.WriteLine("\tEddyDiff:" + config.EddyDiff); Console.WriteLine("\tFallTimeThreshold:" + config.FallTimeThreshold); Console.WriteLine("\tGravity:" + config.Gravity); Console.WriteLine("\tPlume:"); Console.WriteLine("\t\tPlumeModel :" + config.Plume.PlumeModel); Console.WriteLine("\t\tRatio :" + config.Plume.Ratio); Console.WriteLine("\tEruption:"); Console.WriteLine("\t\tPlumeHeight : " + config.Eruption.PlumeHeight); Console.WriteLine("\t\tEruptionMass : " + config.Eruption.EruptionMass); Console.WriteLine("\t\tGrainSize:"); Console.WriteLine("\t\t\tMax : " + config.Eruption.GrainSize.Max); Console.WriteLine("\t\t\tMin : " + config.Eruption.GrainSize.Min); Console.WriteLine("\t\t\tMedian : " + config.Eruption.GrainSize.Median); Console.WriteLine("\t\t\tStandard : " + config.Eruption.GrainSize.Standard); Console.WriteLine("\tVent:"); Console.WriteLine("\t\tEasting : " + config.Vent.Easting); Console.WriteLine("\t\tNorthing : " + config.Vent.Northing); Console.WriteLine("\t\tElevation : " + config.Vent.Elevation); Console.WriteLine("\tDensity:"); Console.WriteLine("\t\tLithicDensity : " + config.Density.LithicDensity); Console.WriteLine("\t\tPumiceDensity : " + config.Density.PumiceDensity); }
private static Wind[][] GetWind(Config config, FileSystemInfo windFile) { var configReader = new WindDataReader(windFile); var wind = new WindFactory(); try { return wind.get_wind(config, configReader.Read()); } catch (IOException e) { // TODO Auto-generated catch block //e.printStackTrace(); Logger.Error("Error Processing Wind File", e); } return null; }
private Wind[][] GetWindArray(Config config) { var winds = new Wind[config.WindDays][]; for (var i = 0; i < config.WindDays; i++) { winds[i] = new Wind[config.ColumnIntegrationSteps + 1]; for (var j = 0; j <= config.ColumnIntegrationSteps; j++) { winds[i][j] = new Wind(); } } return winds; }
public static double GetWindInterval(Config config) { return (config.Eruption.PlumeHeight - config.Vent.Elevation) / config.ColumnIntegrationSteps; }
/************************************************************** FUNCTION: get_wind DESCRIPTION: This function reads wind data into the WIND array. Each node stores all of the wind data. * @throws IOException ***************************************************************/ // int get_wind(FILE *in) { public Wind[][] get_wind(Config config, WindData[] windData) { // int i=0, j=0, ret; // char line[MAX_LINE]; // double wind_height, wind_dir, windspeed, dir0, ht0, sp0; // double level; // // #ifdef _PRINT // fprintf(log_file,"ENTER[get_wind].\n"); // #endif // // WIND_INTERVAL = (PLUME_HEIGHT - VENT_ELEVATION)/COL_STEPS; var windInterval = GetWindInterval(config); // // W = (WIND**)GC_MALLOC(WIND_DAYS * sizeof(WIND *)); var w = GetWindArray(config); // if (W == NULL) { // fprintf(stderr, "Cannot malloc memory for wind columns:[%s]\n", strerror(errno)); // return -1; // } else { // for (i=0; i < WIND_DAYS; i++) { // W[i] = (WIND *)GC_MALLOC((COL_STEPS+1) * sizeof(WIND)); // if (W[i] == NULL) { // fprintf(stderr, "Cannot malloc memory for wind rows %d:[%s]\n", i, strerror(errno)); // return -1; // } // } for (var i = 0; i < config.WindDays; i++) { /* start at the vent */ // level = VENT_ELEVATION; var level = config.Vent.Elevation; // /* Do for each column step */ /* j = 0 is for the interval between the vent and the ground. * Here we set the wind speed and direction to be at the level of the vent; * The values used in the calculations change for each location and are * set in the tephra_calc routine when the point elevation is known. * The last interval ends at the top of the column. */ // for (j=0; j <= COL_STEPS; j++) { for (var j = 0; j <= config.ColumnIntegrationSteps; j++) { //W[i][j] = new Wind(); /* my own */ var windInstance = w[i][j]; windInstance.SetDay(i + 1); // W[i][j].wind_height = 0.0; // ht0 = 0.0; var ht0 = 0.0; // dir0 = 0.0; var dir0 = 0.0; // sp0 = 0.0; var sp0 = 0.0; /* Find wind elevation just greater than current level */ /* Start scanning the wind file for the best match. * Each new level starts scanning the file from the beginning. */ // while (NULL != fgets(line, MAX_LINE, in)) { foreach (var data in windData) { // if (line[0] == '#' || strlen(line) < WIND_COLUMNS) continue; // else { // while (ret = sscanf(line, // "%lf %lf %lf", // &wind_height, // &windspeed, // &wind_dir), ret != 3) { // // if (ret == EOF && errno == EINTR) continue; // // fprintf(stderr, // "[line=%d,ret=%d] Did not read in 3 parameters:[%s]\n", // i+1,ret, strerror(errno)); // // return -1; // } // } // /* This is the case where we find the first height that is equal to * or greater that the level that we are assigning. */ // if (wind_height >= level) { if (data.GetWindHeight() >= level) { // if(wind_height == level) { if (data.GetWindHeight() == level) { // W[i][j].wind_dir = wind_dir; windInstance.SetWindDir(data.GetWindDir()); // W[i][j].windspeed = windspeed; windInstance.SetWindSpeed(data.GetWindSpeed()); // // } else { /* interpolate */ } else { /* interpolate */ // W[i][j].wind_dir = // ((wind_dir - dir0) * (level - ht0) / (wind_height - ht0)) + dir0; windInstance.SetWindDir(((data.GetWindDir() - dir0) * (level - ht0) / (data.GetWindHeight() - ht0)) + dir0); // // W[i][j].windspeed = // ((windspeed - sp0) * (level - ht0) / (wind_height - ht0)) + sp0; windInstance.SetWindSpeed(((data.GetWindSpeed() - sp0) * (level - ht0) / (data.GetWindHeight() - ht0)) + sp0); // } } // W[i][j].wind_height = level; windInstance.SetWindHeight(level); // fprintf(log_file, // "%f %f %f\n", // W[i][j].wind_height, W[i][j].windspeed, W[i][j].wind_dir); // W[i][j].wind_dir *= DEG2RAD; /* change to radians */ windInstance.SetWindDir(windInstance.GetWindDir() * Config.Deg2Rad); // break; /* ready to rescan the file for a match for the next level */ break; // } } /* This is the case where the scanned height is less than the level * we are assigning. */ // else { else { // /* Maintain the scanned values for possible interpolation // * at the next level. // */ // ht0 = wind_height; ht0 = data.GetWindHeight(); // dir0 = wind_dir; dir0 = data.GetWindDir(); // sp0 = windspeed; sp0 = data.GetWindSpeed(); // } } // } } /* If we finish scanning the file and all heights are below the level we are * currently assigning, then just use the direction and speed * at the upper-most height. */ // if (!W[i][j].wind_height) { if (windInstance.GetWindHeight() == 0.0) { // W[i][j].wind_height = level; windInstance.SetWindHeight(level); // W[i][j].windspeed = sp0; windInstance.SetWindSpeed(sp0); // W[i][j].wind_dir = dir0; windInstance.SetWindDir(dir0); // } } // /* Go to the next column height */ // rewind(in); // level += WIND_INTERVAL; level += windInterval; //logger.info("Wind Instance: Day: {}\t Height: {}\tSpeed: {}\tDir: {}", new Object[] { windInstance.getDay(), windInstance.getWindHeight(), windInstance.getWindSpeed(), windInstance.getWindDir() }); } } // // // #ifdef _PRINT // fprintf(log_file, "\tRead %d wind days with %d wind levels per day.\n", i, j); Logger.InfoFormat("Read {0} wind days with {1} wind levels per day.", config.WindDays, config.ColumnIntegrationSteps); // fprintf(log_file, "EXIT[get_wind].\n"); // #endif // return 0; return w; }
// void set_eruption_values(ERUPTION *erupt, WIND *wind) { /* set_eruption_values */ private void SetEruptionValues(Eruption erupt, Wind[] wind, Config config) { //PART_STEPS = (erupt->max_phi - erupt->min_phi) * 10; PartSteps = (int)Math.Abs((erupt.MaxPhi - erupt.MinPhi) * 10); //threshold = erupt->vent_height + (PLUME_RATIO * (erupt->max_plume_height - erupt->vent_height)); Threshold = erupt.VentHeight + (config.Plume.Ratio * (erupt.MaxPlumeHeight - erupt.VentHeight)); //SQRT_TWO_PI = sqrt(2.0 * pi); /* new line, 12-2-2010 */ SqrtTwoPi = Math.Sqrt(2.0 * Config.Pi); //BETA_x_SQRT_TWO_PI = erupt->column_beta * SQRT_TWO_PI; BetaSqrtTwoPi = erupt.ColumnBeta * SqrtTwoPi; //TWO_BETA_SQRD = 2.0 * erupt->column_beta * erupt->column_beta; TwoBetaSqrd = 2.0 * erupt.ColumnBeta * erupt.ColumnBeta; //PDF_GRAINSIZE_DEMON1 = 1.0 / (2.506628 * erupt->sigma_phi); /* changed 12-02-2010 */ PdfGrainSizeDemon1 = 1.0 / (2.506628 * erupt.SigmaPhi); //TWO_x_PART_SIGMA_SIZE = 2.0 * erupt->sigma_phi * erupt->sigma_phi; TwoPartSigmaSize = 2.0 * erupt.SigmaPhi * erupt.SigmaPhi; /*define the limits of integration */ //ht_section_width = erupt->max_plume_height - erupt->vent_height; var htSectionWidth = erupt.MaxPlumeHeight - erupt.VentHeight; //part_section_width = erupt->max_phi - erupt->min_phi; var partSectionWidth = erupt.MaxPhi - erupt.MinPhi; //ht_step_width = ht_section_width / (double)COL_STEPS; var htStepWidth = htSectionWidth / config.ColumnIntegrationSteps; //part_step_width = part_section_width / (double)PART_STEPS; var partStepWidth = partSectionWidth / PartSteps; /* steps for nomalization of probabilities */ var totalPCol = GetTotalPCol(erupt, config, htSectionWidth, htStepWidth); var totalPPart = GetTotalPPart(erupt, partStepWidth); /* Normalization constant */ var totalP = GetTotalP(totalPCol, totalPPart); /* End of normalization steps */ /* Dynamically allocated table for storing integration data. * Used in the double integration steps below for each point considered. * */ _table = CreateTableArray(); double pmin = 10e6, pmax = 0.0; Logger.InfoFormat("\tpmax={0}", pmax); Logger.InfoFormat("\tpmin={0}", pmin); /* Start with the maximum particle size */ //y = (erupt)->min_phi var y = erupt.MinPhi; for (var i = 0; i < PartSteps; i++) { /* PART_STEPS_LOOP */ var partStepTable = _table[i, 0]; //T[i][0].part_density = ParticleDensity(y); partStepTable.SetPartDensity(ParticleDensity(y)); //T[i][0].ashdiam = phi2m(y); partStepTable.SetAshDiam(Phi2M(y)); /* the expected fraction of particles of this size based on given mean and std deviation */ var partProb = pdf_grainsize(erupt.MeanPhi, y, partStepWidth); var cumFallTime = 0.0; var windX = 0.0; var windY = 0.0; /* Start at the height of the vent */ var particleHt = erupt.VentHeight; for (var j = 0; j < config.ColumnIntegrationSteps; j++) { /* COL_STEPS_LOOP */ var table = _table[i, j]; /* define the small slice dz */ particleHt += htStepWidth; /* * Calculate the time it takes a particle to fall from its release point * in the column to the next column release point. * */ //T[i][j].fall_time = PartFallTime(particle_ht, ht_step_width, T[i][0].ashdiam, T[i][0].part_density); table.SetFallTime(PartFallTime(particleHt, htStepWidth, partStepTable.GetAshDiam(), partStepTable.GetPartDensity())); /* Particle diffusion time (seconds) */ //ht_above_vent = particle_ht - erupt->vent_height; var htAboveVent = particleHt - erupt.VentHeight; var temp = 0.2 * htAboveVent * htAboveVent; //T[i][j].plume_diffusion_fine_particle = pow(temp, 0.4); /* 0.4 = 2.0/5.0 */ table.SetPlumeDiffusionFineParticle(Math.Pow(temp, 0.4)); //T[i][j].plume_diffusion_coarse_particle = 0.0032 * (ht_above_vent * ht_above_vent) / DIFFUSION_COEFFICIENT; table.SetPlumeDiffusionCoarseParticle(0.0032 * (htAboveVent * htAboveVent) / config.DiffusionCoefficient); /* * Sum the windspeed and wind_direction for each particle size * falling from each level. In the wind array, the first wind level * gives wind speed and direction at the vent height. * Start with the next wind level, * so that we are using the wind speed and direction * starting from one step above the vent. * */ var windNextLevel = wind[j + 1]; //wind_x += T[i][j].fall_time * wind[j+1].windspeed * cos(wind[j+1].wind_dir); windX += table.GetFallTime() * windNextLevel.GetWindSpeed() * Math.Cos(windNextLevel.GetWindDir()); //wind_y += T[i][j].fall_time * wind[j+1].windspeed * sin(wind[j+1].wind_dir); windY += table.GetFallTime() * windNextLevel.GetWindSpeed() * Math.Sin(windNextLevel.GetWindDir()); //T[i][j].wind_sum_x = wind_x; table.SetWindSumX(windX); //T[i][j].wind_sum_y = wind_y; table.SetWindSumY(windY); /* * Accumulate the time it takes each particle size to descend * from its release point down * to its final resting place.This part of the code just * calculates the fall_time from the release point to the * height of the vent. * The time it takes a particle to fall from the vent height * to a grid cell will be calculated later. * */ //cum_fall_time += T[i][j].fall_time; cumFallTime += table.GetFallTime(); //T[i][j].total_fall_time = cum_fall_time; table.SetTotalFallTime(cumFallTime); //if (T[i][j].total_fall_time > pmax) pmax = T[i][j].total_fall_time; if (cumFallTime > pmax) { pmax = table.GetTotalFallTime(); } else //if (T[i][j].total_fall_time < pmin) pmin = T[i][j].total_fall_time; if (cumFallTime < pmin) { pmin = table.GetTotalFallTime(); } /* the probability that a given grainsize will be released from a given height */ //col_prob = (*pdf)(particle_ht, j, erupt->column_beta, erupt->max_plume_height); var colProb = config.Plume.PlumeModel == PlumeModel.UniformDistribution ? plume_pdf0(particleHt, j) : PlumePdf1(particleHt, j, erupt.ColumnBeta, erupt.MaxPlumeHeight); /* Normalization is now done here */ //T[i][j].demon1 = (erupt->total_ash_mass * col_prob * part_prob)/total_P; table.SetDemon1((erupt.TotalAshMass * colProb * partProb) / totalP); //T[i][j].particle_ht = particle_ht; table.SetParticleHt(particleHt); Logger.InfoFormat("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}\t{9}\t{10}\t{11}", new[] { i, j, table.GetParticleHt(), table.GetAshDiam(), table.GetPartDensity(), table.GetFallTime(), table.GetPlumeDiffusionFineParticle(), table.GetPlumeDiffusionCoarseParticle(), table.GetTotalFallTime(), table.GetWindSumX(), table.GetWindSumY(), table.GetDemon1() }); /* fprintf(log_file, "%g\t%g\t%g\t%g\t%g\t%g\t%g\t%g\t%g\t%g\n", T[i][j].particle_ht, T[i][j].ashdiam, T[i][j].part_density, T[i][j].fall_time, T[i][j].plume_diffusion_fine_particle, T[i][j].plume_diffusion_coarse_particle, T[i][j].total_fall_time, T[i][j].wind_sum_x, T[i][j].wind_sum_y, T[i][j].demon1); */ } /* END COL_STEPS_LOOP */ Logger.Info(" "); /* fprintf(log_file, "\n"); */ y += partStepWidth; /* moved from beg of loop 12-02-2010 */ } /* END PART_STEPS_LOOP */ /* fprintf(log_file, "OUT\n"); */ // fprintf(stderr, "MIN particle fall time = %.1f\n", pmin); Logger.Info("MIN particle fall time = " + pmin); // fprintf(stderr, "MAX particle fall time = %.1f\n", pmax); Logger.Info("MAX particle fall time = " + pmax); }
public double GetTotalPCol(Eruption erupt, Config config, double htSectionWidth, double htStepWidth) { var cumProbCol = 0.0; //x = erupt->vent_height; var x = erupt.VentHeight; //for (i=0; i < COL_STEPS; i++) { for (var i = 0; i < config.ColumnIntegrationSteps; i++) { x += htStepWidth; double prob; //prob = (*pdf)(x, (double)i, ht_section_width, erupt->max_plume_height); if (config.Plume.PlumeModel == PlumeModel.UniformDistribution) { prob = plume_pdf0(x, i); } else { // TODO : I can't see how this can be used anywhere as beta is never set! // TwoBetaSqrd & BetaSqrtTwoPi is not valid as beta is always 0. Debug.Assert(Math.Abs(TwoBetaSqrd) > 0.0000001 || Math.Abs(BetaSqrtTwoPi) > 0.0000001); prob = PlumePdf1(x, i, htSectionWidth, erupt.MaxPlumeHeight); } cumProbCol += prob; } return cumProbCol; }
private static void ReadTokensIntoConfig(IReadOnlyList<string> tokens, Config config) { if (tokens.Count != 2) { return; } var configName = tokens[0]; //logger.info("Config: {}: {}", configName, tokens[1]); switch (configName) { case "PLUME_HEIGHT": config.Eruption.PlumeHeight = double.Parse(tokens[1]); break; case "ERUPTION_MASS": config.Eruption.EruptionMass = double.Parse(tokens[1]); break; case "MAX_GRAINSIZE": config.Eruption.GrainSize.Max = double.Parse(tokens[1]); break; case "MIN_GRAINSIZE": config.Eruption.GrainSize.Min = double.Parse(tokens[1]); break; case "MEDIAN_GRAINSIZE": config.Eruption.GrainSize.Median = double.Parse(tokens[1]); break; case "STD_GRAINSIZE": config.Eruption.GrainSize.Standard = double.Parse(tokens[1]); break; case "VENT_EASTING": config.Vent.Easting = double.Parse(tokens[1]); break; case "VENT_NORTHING": config.Vent.Northing = double.Parse(tokens[1]); break; case "VENT_ELEVATION": config.Vent.Elevation = double.Parse(tokens[1]); break; case "EDDY_CONST": config.EddyDiff = double.Parse(tokens[1]); break; case "DIFFUSION_COEFFICIENT": config.DiffusionCoefficient = double.Parse(tokens[1]); break; case "FALL_TIME_THRESHOLD": config.FallTimeThreshold = double.Parse(tokens[1]); break; case "LITHIC_DENSITY": config.Density.LithicDensity = double.Parse(tokens[1]); break; case "PUMICE_DENSITY": config.Density.PumiceDensity = double.Parse(tokens[1]); break; case "COL_STEPS": config.ColumnIntegrationSteps = int.Parse(tokens[1]); break; case "PLUME_MODEL": config.Plume.PlumeModel = (PlumeModel)Enum.Parse(typeof(PlumeModel), tokens[1]); break; case "PLUME_RATIO": config.Plume.Ratio = double.Parse(tokens[1]); break; case "WIND_DAYS": config.WindDays = int.Parse(tokens[1]); break; case "WIND_COLUMNS": config.WindColumns = int.Parse(tokens[1]); break; default: Logger.InfoFormat("Unknown Configuration Settings: {0}", configName); break; } }
public TephraCalc(Config config) { _config = config; }