📄 firelib.c
字号:
if ( FuelCat_FlameArray(catalog)[mid] > byrams )
hi = mid;
else
lo = mid + 1;
} while (lo != hi);
Fuel_FlameLength(catalog,model) =
FuelCat_FlameStep(catalog) * (lo+1);
}
/* otherwise compute flame length from scratch. */
else
{
Fuel_FlameLength(catalog,model) = 0.45 * pow(byrams, 0.46);
}
}
}
/* Scorch height is requested. */
if ( (which & FIRE_SCORCH) )
{
if ( byrams < Smidgen )
{
Fuel_ScorchHeight(catalog,model) = 0.;
}
else
{
mph = Fuel_WindSpeed(catalog,model) / 88.;
Fuel_ScorchHeight(catalog,model) =
pow(byrams, 1.166667) / sqrt(byrams + (mph * mph * mph));
/* Fuel_ScorchHeight(catalog,model) *= (63. / (140. - temp_f) ); */
}
}
return (FuelCat_Status(catalog) = FIRE_STATUS_OK);
}
/*
*******************************************************************************
*
* Fire_FlameLengthTable()
*
* Description
* Creates a flame length lookup table containing "flameClasses" classes
* with each class spanning "flameStep" feet.
*
* Discussion
* Since flame length is strictly an output variable (e.g., it is never
* used as the basis for subsequent computations), we can usually afford
* to round it to some precision that makes sense to fire managers.
* Usually this will be in 1 foot or perhaps 6 inch increments. The call
*
*
* creates a flame length table for flame lengths of 1 through 500 feet.
*
* Fire_SpreadAtAzimuth() uses the flame table (if one is defined for the
* catalog) to avoid using the costly pow() function for highly iterative
* flame length calculations, saving a considerable amount of processing
* time. Fire_SpreadAtAzimuth() will still use the pow() function to
* compute flame length if (1) a flame length table is not defined,
* (2) the fireline intensity exceeds the upper limit of the currently
* defined flame length table, or (3) the flame length table becomes
* undefined by a Fire_FlameLengthTable(catalog, 0, 0.) call.
*
*
* Examples
* Fire_FlameLengthTable(catalog, 200, 1.0);
* Creates a table for flame lengths of 1 through 200 feet in 1-foot
* intervals. Any previously defined flame length table for this
* fuel catalog is destroyed.
*
* Fire_FlameLengthTable(catalog, 500, 0.5);
* Creates a table for flame lengths of 0.5 through 250 feet in 6-inch
* intervals. ANy previously defined flame length table for this
* fuel catalog is destroyed.
*
* Fire_FlameLengthTable(catalog, 0, 0.);
* Destroys any existing flame length table for this catalog, and
* forces actual flame length computation using pow() function.
*
* Side Effects
* If a flame length table currently exists, it is destroyed, and the
* FuelCat_FlameArray(), FuelCat_FlameClasses(), and
* FuelCat_FlameStep() are set to NULL, 0, and 0.0, respectively.
*
* If fireClasses > 0, allocates a flame length table and fills it with
* the fireline intensity associated with the upper limit of each flame
* length class. The FuelCat_FlameArray(), FuelCat_FlameClasses(), and
* FuelCat_FlameStep() are then updated.
*
* Function Returns
* FIRE_STATUS_OK or FIRE_STATUS_ERROR.
* Return status and error text are stored in the Fire Catalog's buffers.
*
*******************************************************************************
*/
int
Fire_FlameLengthTable ( FuelCatalogPtr catalog, size_t flameClasses, double flameStep )
// FuelCatalogPtr catalog; /* FuelCatalogData instance pointer */
// size_t flameClasses; /* number of flame length classes */
// double flameStep; /* flame length step value per class */
{
double power, flame;
size_t i;
/* Validate the catalog. */
assert(catalog!= NULL && FuelCat_MagicCookie(catalog)==FIRE_CATALOG_MAGIC);
/* If a flame table already exists, destroy it. */
if ( FuelCat_FlameArray(catalog) )
{
free(FuelCat_FlameArray(catalog));
FuelCat_FlameArray(catalog) = NULL;
FuelCat_FlameClasses(catalog) = 0;
FuelCat_FlameStep(catalog) = 0.0;
}
/* If flameClasses is zero, simply return. */
if ( flameClasses == 0 )
return (FuelCat_Status(catalog) = FIRE_STATUS_OK);
/* Otherwise create a new flame table. */
if ( (FuelCat_FlameArray(catalog) = (double *)
calloc(flameClasses, sizeof(double))) == NULL )
{
sprintf(FuelCat_Error(catalog),
"Fire_FlameLengthTable(): imposible asignar tabla de longitud de llama con %d clases de %f pies.",
flameClasses, flameStep);
return (FuelCat_Status(catalog) = FIRE_STATUS_ERROR);
}
/* Fill the array. */
power = 1. / .46;
for ( i=0; i<flameClasses; i++ )
{
flame = flameStep * (i+1);
FuelCat_FlameArray(catalog)[i] = pow((flame / .45), power);
}
FuelCat_FlameClasses(catalog) = flameClasses;
FuelCat_FlameStep(catalog) = flameStep;
return (FuelCat_Status(catalog) = FIRE_STATUS_OK);
}
/*
*******************************************************************************
*
* Fire_FuelCatalogCreate()
*
* Description
* Creates a new fuel model catalog capable of holding fuel models with
* id's in the range [0..maxModel].
* The catalog is filled by subsequent calls to Fire_FuelModelCreate().
*
* Side Effects
* Allocates a new FuelCatalogData structure.
* Allocates an error text buffer for the catalog.
* Allocates a name for the catalog.
* Allocates an array of pointers to FuelData structures (the FuelData
* structures themselves are allocated by Fire_FuelModelCreate() and
* their pointers are stored here).
*
* Notes
* The FuelCatalog contains a dynamically-allocated array of pointers
* to FuelData blocks. These pointers are initially NULL and are
* subsequently assigned by Fire_FuelModelCreate(). The array provides
* the programmer with a means of directly accessing fuel models via
* their model number, which is handy when simulating fire growth.
*
* Function Returns
* While most FireLib functions return a status code, this one returns
* a pointer to the new FuelCatalogData on success or NULL if unable
* to allocate any of the dynamic structures.
*
*******************************************************************************
*/
FuelCatalogPtr
Fire_FuelCatalogCreate ( char *name, size_t maxModels )
// char *name; /* FuelCatalogData instance name */
// size_t maxModels; /* maximum modelId allowed in this catalog */
{
FuelCatalogPtr catalog;
static char *blank = {""};
/* Catch a NULL name. */
if ( name == NULL )
name = blank;
/* Allocate the FireCatalogData structure. */
if ( (catalog = (FuelCatalogPtr) malloc(sizeof(FuelCatalogData))) == NULL )
{
fprintf(stderr,
"Fire_FuelCatalogCreate(): imposible asignar el objeto \"%s\" del cat醠ogo de combustibles.\n",
name);
return (NULL);
}
/* Assign the magic cookie right away. */
FuelCat_MagicCookie(catalog) = FIRE_CATALOG_MAGIC;
/* Allocate and store the catalog instance name. */
if ( (FuelCat_Name(catalog) = strdup(name)) == NULL )
{
fprintf(stderr,
"Fire_FuelCatalogCreate(): imposible duplicar el nombre \"%s\" del cat醠ogo de combustibles.\n",
name);
free(catalog);
return (NULL);
}
/* Allocate the FireCatalogData error message buffer. */
if ( (FuelCat_Error(catalog) =
(char *) calloc(FIRE_ERROR_BUFFER_SIZE, sizeof(char))) == NULL )
{
fprintf(stderr,
"Fire_FuelCatalogCreate(): imposible asignar el bufer de error \"%s\" del cat醠ogo de combustibles.\n",
name);
free(FuelCat_Name(catalog));
free(catalog);
return (NULL);
}
FuelCat_Status(catalog) = FIRE_STATUS_ERROR;
/* Allocate a FuelModelPtr array to handle models [0..maxModels]. */
maxModels++;
FuelCat_MaxModels(catalog) = maxModels;
if ( (FuelCat_ModelArray(catalog) = (FuelModelPtr *)
calloc(FuelCat_MaxModels(catalog), sizeof(FuelModelPtr))) == NULL )
{
fprintf(stderr,
"Fire_FuelCatalogCreate(): imposible asignar \"%s\" con %d modelos de combustible del cat醠ogo de combustibles.\n",
name, maxModels);
free(FuelCat_Error(catalog));
free(FuelCat_Name(catalog));
free(catalog);
return (NULL);
}
/* Initialize variables and return ptr to this instance. */
FuelCat_FlameArray(catalog) = NULL;
FuelCat_FlameClasses(catalog) = 0;
FuelCat_FlameStep(catalog) = 0.0;
FuelCat_Status(catalog) = FIRE_STATUS_OK;
return (catalog);
}
/*
*******************************************************************************
*
* Fire_FuelCatalogCreateStandard()
*
* Description
* Creates a new fuel model catalog capable of holding fuel models with
* id's in the range [0..maxModel].
* The catalog is then filled with the 13 standard fire behavior fuel
* models. Other models may be added by subsequent calls to
* Fire_FuelModelCreate().
*
* Side Effects
* Allocates a new FuelCatalogData structure.
* Fills the catalog with standard fuels models 0-13.
*
* Function Returns
* While most FireLib functions return a status code, this one returns
* a pointer to the new FuelCatalogData on success, or NULL if unable
* to allocate any of the dynamic structures.
*
*******************************************************************************
*/
FuelCatalogPtr
Fire_FuelCatalogCreateStandard (char *name, size_t maxModels )
// char *name; /* FuelCatalogData instance name */
// size_t maxModels; /* maximum modelId allowed in this catalog */
{
FuelCatalogPtr catalog;
double stot, seff, heat, dens, adjust;
size_t m, p;
/* Fuel model definitions. */
typedef struct {
char *name; double depth; double mext; size_t maxParticles; char *desc;
} StandardModels;
StandardModels M[14] = {
{"NoFuel", 0.1, 0.01, 0, "No Combustible Fuel" },
{"NFFL01", 1.0, 0.12, 1, "Short Grass (1 ft)" },
{"NFFL02", 1.0, 0.15, 4, "Timber (grass & understory)" },
{"NFFL03", 2.5, 0.25, 1, "Tall Grass (2.5 ft)" },
{"NFFL04", 6.0, 0.20, 4, "Chaparral (6 ft)" },
{"NFFL05", 2.0, 0.20, 3, "Brush (2 ft)" },
{"NFFL06", 2.5, 0.25, 3, "Dormant Brush & Hardwood Slash" },
{"NFFL07", 2.5, 0.40, 4, "Southern Rough" },
{"NFFL08", 0.2, 0.30, 3, "Closed Timber Litter" },
{"NFFL09", 0.2, 0.25, 3, "Hardwood Litter" },
{"NFFL10", 1.0, 0.25, 4, "Timber (litter & understory)" },
{"NFFL11", 1.0, 0.15, 3, "Light Logging Slash" },
{"NFFL12", 2.3, 0.20, 3, "Medium Logging Slash" },
{"NFFL13", 3.0, 0.25, 3, "Heavy Logging Slash" }
};
/* Fuel particle definitions. */
typedef struct {
size_t model; size_t type; double load; double savr;
} StandardParticle;
static StandardParticle P[39] = {
{ 1, FIRE_TYPE_DEAD, 0.0340, 3500.},
{ 2, FIRE_TYPE_DEAD, 0.0920, 3000.},
{ 2, FIRE_TYPE_DEAD, 0.0460, 109.},
{ 2, FIRE_TYPE_DEAD, 0.0230, 30.},
{ 2, FIRE_TYPE_HERB, 0.0230, 1500.},
{ 3, FIRE_TYPE_DEAD, 0.1380, 1500.},
{ 4, FIRE_TYPE_DEAD, 0.2300, 2000.},
{ 4, FIRE_TYPE_DEAD, 0.1840, 109.},
{ 4, FIRE_TYPE_DEAD, 0.0920, 30.},
{ 4, FIRE_TYPE_WOOD, 0.2300, 1500.},
{ 5, FIRE_TYPE_DEAD, 0.0460, 2000.},
{ 5, FIRE_TYPE_DEAD, 0.0230, 109.},
{ 5, FIRE_TYPE_WOOD, 0.0920, 1500.},
{ 6, FIRE_TYPE_DEAD, 0.0690, 1750.},
{ 6, FIRE_TYPE_DEAD, 0.1150, 109.},
{ 6, FIRE_TYPE_DEAD, 0.0920, 30.},
{ 7, FIRE_TYPE_DEAD, 0.0520, 1750.},
{ 7, FIRE_TYPE_DEAD, 0.0860, 109.},
{ 7, FIRE_TYPE_DEAD, 0.0690, 30.},
{ 7, FIRE_TYPE_WOOD, 0.0170, 1550.},
{ 8, FIRE_TYPE_DEAD, 0.0690, 2000.},
{ 8, FIRE_TYPE_DEAD, 0.0460, 109.},
{ 8, FIRE_TYPE_DEAD, 0.1150, 30.},
{ 9, FIRE_TYPE_DEAD, 0.1340, 2500.},
{ 9, FIRE_TYPE_DEAD, 0.0190, 109.},
{ 9, FIRE_TYPE_DEAD, 0.0070, 30.},
{10, FIRE_TYPE_DEAD, 0.1380, 2000.},
{10, FIRE_TYPE_DEAD, 0.0920, 109.},
{10, FIRE_TYPE_DEAD, 0.2300, 30.},
{10, FIRE_TYPE_WOOD, 0.0920, 1500.},
{11, FIRE_TYPE_DEAD, 0.0690, 1500.},
{11, FIRE_TYPE_DEAD, 0.2070, 109.},
{11, FIRE_TYPE_DEAD, 0.2530, 30.},
{12, FIRE_TYPE_DEAD, 0.1840, 1500.},
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -