/Users/huttone/Devel/sedflux-new/sedflux/trunk/ew/plume/plumecheck.c

Go to the documentation of this file.
00001 //---
00002 //
00003 // This file is part of sedflux.
00004 //
00005 // sedflux is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation; either version 2 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // sedflux is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with sedflux; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 //
00019 //---
00020 
00021 /*
00022  * PlumeCheck   Checks the ranges of the input values of PLUME
00023  *
00024  *      Author:         M.D. Morehead
00025  *      Original:       April 1998
00026  *      Modified:       Sep 1998, MDM, Conversion for SEDFLUX3D
00027  *
00028  */
00029 #include "plumeinput.h"
00030 #include "plumevars.h"
00031 
00032 //---
00033 // outputs:
00034 //    O1, O2, O3
00035 // inputs:
00036 //    river.Q
00037 //    river.u0
00038 //    river.b0
00039 //    river.rma
00040 //    river.Cs
00041 //    n_grains
00042 //    sedload.lambda
00043 //    sedload.rho
00044 //    ocean.Cw
00045 //    ocean.v0
00046 //    ocean.cc
00047 //    kwf
00048 //    lat
00049 //    dy
00050 //    dx
00051 //    fjrd
00052 //    strt
00053 //    ymin
00054 //    ymax
00055 //    ndy
00056 //    ndx
00057 //    O1, O2, O3
00058 //---
00059 /*
00060 static gchar* err_msg[] = {
00061    [PLUME_ERROR_LOW_Q]    = "River discharge is too low" ,
00062    [PLUME_ERROR_HIGH_Q]   = "River discharge is too high" ,
00063    [PLUME_ERROR_LOW_VEL]  = "River velocity is too low" ,
00064    [PLUME_ERROR_HIGH_VEL] = "River velocity is too high" ,
00065 };
00066 */
00067 
00068 int plumecheck( Plume_enviro *env , Plume_grid *grid , Plume_options *opt )
00069 {
00070    int err, ii;
00071    double mncs, mxcs, mnlm, mxlm, mnrs, mxrs;
00072    Plume_river *river = env->river;
00073    Plume_ocean *ocean = env->ocean;
00074    Plume_sediment *sedload = env->sed;
00075 
00076    err = 0;
00077 /*
00078    if ( river->Q<1.    ) error = PLUME_ERROR_LOW_Q;
00079    if ( river->Q>1e6   ) error = PLUME_ERROR_HIGH_Q;
00080    if ( river->u0<.01  ) error = PLUME_ERROR_LOW_VEL;
00081    if ( river->u0>10   ) error = PLUME_ERROR_HIGH_VEL;
00082    if ( river->b0<1    ) error = PLUME_ERROR_LOW_WIDTH;
00083    if ( river->b0>1e5  ) error = PLUME_ERROR_HIGH_WIDTH;
00084    if ( river->rma>80  ) error = PLUME_ERROR_LOW_ANGLE;
00085    if ( river->rma<-80 ) error = PLUME_ERROR_HIGH_ANGLE;
00086 */
00087    // Check river parameters
00088    if( river->Q < 1.0 || river->Q > 1e6 )
00089    {
00090       fprintf( stderr," \n ERROR in PLUME input parameters (plumecheck.c) \n");
00091       fprintf( stderr,"   The river discharge is out of range \n");
00092       fprintf( stderr,"   river.Q = %g, qmin = 1.0, qmax = 1e6 (m^3/s) \n" ,
00093                river->Q );
00094 /*
00095       eh_strv_append( &err_s , g_strdup_printf( "Plume input parameter error: River discharge out of range." ) );
00096       eh_strv_append( &err_s , g_strdup_printf( "River discharge = %g ()." , river->Q ) );
00097 */
00098       err = 1;
00099    }
00100    
00101    if( river->u0 < 0.01 || river->u0 > 10 )
00102    {
00103       fprintf( stderr," \n ERROR in PLUME input parameters (plumecheck.c) \n");
00104       fprintf( stderr,"   The river velocity is out of range \n");
00105       fprintf( stderr,"   river.u0 = %g, umin = 0.01, umax = 10 (m/s) \n" ,
00106                river->u0 );
00107       err = 1;
00108    }
00109    
00110    if( river->b0 < 1.0 || river->b0 > 1e5 )
00111    {
00112       fprintf( stderr," \n ERROR in PLUME input parameters (plumecheck.c) \n");
00113       fprintf( stderr,"   The river width is out of range \n");
00114       fprintf( stderr,"   river.b0 = %g, bmin = 1.0, bmax = 1e5 (m) \n" ,
00115                river->b0);
00116       err = 1;
00117    }
00118    
00119    if( fabs(river->rma) > 80 )
00120    {
00121       fprintf( stderr," \n ERROR in PLUME input parameters (PlumeCheck.c) \n");
00122       fprintf( stderr,"   The river mouth angle is out of range \n");
00123       fprintf( stderr,"   rma = %g \n", river->rma);
00124       fprintf( stderr,"   Allowed range: -80 < rma < 80 (degrees) \n");
00125       err = 1;
00126    }
00127 
00128    // Sediment Load
00129 
00130    // find min's and max's
00131    mxcs = mncs = river->Cs[0];
00132    mxlm = mnlm = sedload[0].lambda*dTOs;
00133    mxrs = mnrs = sedload[0].rho;
00134    for( ii=0 ; ii<env->n_grains ; ii++ ) 
00135    {
00136       mncs = mn( mncs, river->Cs[ii]);
00137       mxcs = mx( mxcs, river->Cs[ii]);
00138       mnlm = mn( mnlm, sedload[ii].lambda*dTOs);
00139       mxlm = mx( mxlm, sedload[ii].lambda*dTOs);
00140       mnrs = mn( mnrs, sedload[ii].rho);
00141       mxrs = mx( mxrs, sedload[ii].rho);
00142    }   
00143 
00144 /*
00145    if( (int)ngrains != ngrains )
00146    {
00147       fprintf(stderr," \n ERROR in PLUME input parameters (PlumeCheck.c) \n");
00148       fprintf(stderr,"   The Number of Grain Sizes simulated must be an integer \n");
00149       fprintf(stderr,"   ngrains = %d \n", ngrains);
00150       err = 1;
00151    }
00152 */
00153    
00154    if( mncs < 0.001 || mxcs > 500. )
00155    {
00156    /*
00157       fprintf(stderr," \n ERROR in PLUME input parameters (PlumeCheck.c) \n");
00158       fprintf(stderr,"   The river concentration is out of range \n");
00159       fprintf(stderr,"   min(Cs) = %g, max(Cs) = %g \n", mncs, mxcs);
00160       fprintf(stderr,"   Allowed Range: min(Cs) = 0.001, max(Cs) = 100 (kg/m^3) \n");
00161    */
00162       err = 1;
00163    }
00164    
00165    if( mnlm < 0.1 || mxlm > 40 ) 
00166    {
00167       fprintf(stderr," \n ERROR in PLUME input parameters (PlumeCheck.c) \n");
00168       fprintf(stderr,"   The removal rate coefficients are out of range \n");
00169       fprintf(stderr,"   min(lambda) = %g, max(lambda) = %g \n", mnlm, mxlm);
00170       fprintf(stderr,"   Allowed Range = 0.1 to 40 (1/day) \n");
00171       err = 1;
00172    }
00173    
00174    if( mnrs < 1100 || mxrs > 2600 ) 
00175    {
00176       fprintf(stderr," \n ERROR in PLUME input parameters (PlumeCheck.c) \n");
00177       fprintf(stderr,"   The sediment densities are out of range \n");
00178       fprintf(stderr,"   min(rho) = %g, max(rho) = %g \n", mnrs, mxrs);
00179       fprintf(stderr,"   Allowed Range = 1100 to 2600 (kg/m^3) \n");
00180       err = 1;
00181    }
00182 
00183    // Check Ocean parameters
00184 
00185    if( ocean->Cw != 0 )
00186    {
00187       fprintf(stderr," \n WARNING in PLUME input parameters (PlumeCheck.c) \n");
00188       fprintf(stderr,"   Plume edge effects may occur if ocean.Cw != 0, \n");
00189       fprintf(stderr,"   especially for low Cs, high lambda grain sizes. \n");
00190       fprintf(stderr,"   Cw = %g \n ", ocean->Cw);
00191       fprintf(stderr,"   Allowed Range: min(Cw) = 0, max(Cw) = min(Cs) = %g (kg/m^3) \n", mncs);
00192    }
00193    
00194    if( ocean->Cw < 0 || ocean->Cw > mncs )
00195    {
00196       fprintf(stderr," \n ERROR in PLUME input parameters (PlumeCheck.c) \n");
00197       fprintf(stderr,"   The ocean concentration is out of range \n");
00198       fprintf(stderr,"   Cw = %g \n ", ocean->Cw);
00199       fprintf(stderr,"   Allowed Range: min(Cw) = 0, max(Cw) = min(Cs) = %g (kg/m^3) \n", mncs);
00200       err = 1;
00201    }
00202    
00203    if( fabs(ocean->vo) > 3.0 )
00204    {
00205       fprintf(stderr," \n ERROR in PLUME input parameters (PlumeCheck.c) \n");
00206       fprintf(stderr,"   The alongshore current is out of range \n");
00207       fprintf(stderr,"   vo = %g \n", ocean->vo);
00208       fprintf(stderr,"   Allowed range: -3.0 < vo < 3.0 (m/s) \n");
00209       err = 1;
00210    }
00211    
00212    if( 0.1 > ocean->cc || ocean->cc > 1 )
00213    {
00214       fprintf(stderr," \n ERROR in PLUME input parameters (PlumeCheck.c) \n");
00215       fprintf(stderr,"   The coastal current width multiplier is out of range \n");
00216       fprintf(stderr,"   ocean.cc = %g \n", ocean->cc);
00217       fprintf(stderr,"   Allowed range: 0.1 < cc < 1 (percent of Inertial Length Scale) \n");
00218       err = 1;
00219    }
00220    
00221    if( opt->kwf != 1 && opt->kwf != 0 )
00222    {
00223       fprintf(stderr," \n ERROR in PLUME input parameters (PlumeCheck.c) \n");
00224       fprintf(stderr,"   The Kelvin Wave Flag is out of range \n");
00225       fprintf(stderr,"   kwf = %d \n", opt->kwf);
00226       fprintf(stderr,"   kwf must equal 0 or 1");
00227       err = 1;
00228    }
00229    
00230    if( 0 > env->lat || env->lat > 90 )
00231    {
00232       fprintf(stderr," \n ERROR in PLUME input parameters (PlumeCheck.c) \n");
00233       fprintf(stderr,"   The latitude is out of range \n");
00234       fprintf(stderr,"   lat = %d \n", env->lat );
00235       fprintf(stderr,"   Allowed range: 0 < lat < 90 (degrees) \n");
00236       fprintf(stderr,"   Not tested for Southern Hemisphere yet \n");
00237       err = 1;
00238    }
00239 
00240    /* 
00241     *   Check Conservative Concentration Parameters
00242     *           no clear checks to be made
00243     *           we want this to be general
00244     *           ie.     Salinity (ppt): So = 0, Sw = 32
00245     *                   deltaO18:       ???
00246     */
00247 
00248    #if !defined(SEDFLUX3D) && !defined(SEDFLUX2D)
00249    // fprintf(stderr," PlumeCheck Warning: No checks made on So or Sw at present time \n");
00250    #endif
00251 
00252 //   if ( finite(So) == 0 || finite(Sw) == 0 )
00253 //   {
00254 //      fprintf(stderr," \n ERROR in PLUME input parameters (PlumeCheck.c) \n");
00255 //      fprintf(stderr,"   The conservative concentration values are not finite \n");
00256 //      fprintf(stderr,"   So and Sw must be present in the input file. \n");
00257 //      err = 1;
00258 //   }
00259 
00260    // Check grid parameters
00261    if( fmod(river->b0,grid->dy) || fmod(river->b0/grid->dy,2) == 0. )
00262    {
00263       fprintf( stderr," \n ERROR in PLUME input parameters (PlumeCheck.c) \n");
00264       fprintf( stderr,"The river width (bo) should be an odd integer multiple of the grid size (dy) \n");
00265       fprintf( stderr ,
00266                "bo = %g, dy = %f, ndy = %d \n" ,
00267                river->b0 ,
00268                grid->dy ,
00269                grid->ndy );
00270       err = 1;
00271    }
00272    
00273    if( (opt->fjrd || opt->strt) && grid->ymin > -2*river->b0 )
00274    {
00275       fprintf(stderr," \n ERROR in PLUME input parameters (PlumeCheck.c) \n");
00276       fprintf(stderr,"   The ymin grid point is too close to the river mouth \n");
00277       fprintf(stderr,"   ymin = %f, bo = %g \n", grid->ymin, river->b0);
00278       fprintf(stderr,"   Allowed range: ymin < -2*bo (m) \n");
00279       err = 1;
00280    }
00281    
00282    if( (opt->fjrd || opt->strt) && grid->ymax < 2*river->b0 )
00283    {
00284       fprintf(stderr," \n ERROR in PLUME input parameters (PlumeCheck.c) \n");
00285       fprintf(stderr,"   The ymax grid point is too close to the river mouth \n");
00286       fprintf(stderr,"   ymax = %f, bo = %g \n", grid->ymax, river->b0);
00287       fprintf(stderr,"   Allowed range: ymax > 2*bo (m) \n");
00288       err = 1;
00289    }
00290    
00291    if(    grid->ndy < 3    || grid->ndy > 21
00292        || grid->ndy%2 == 0 || grid->ndy%1 != 0 )
00293    {
00294       fprintf(stderr," \n ERROR in PLUME input parameters (PlumeCheck.c) \n");
00295       fprintf(stderr,"   The number of y grid points is incorrect \n");
00296       fprintf(stderr,"   ndy = %d \n", grid->ndy);
00297       fprintf(stderr,"   Allowed range: ndy must be an odd integer and 0 < ndy < 22 \n");
00298       err = 1;
00299    }
00300    
00301    if( !(opt->fjrd || opt->strt) && grid->ndx != 1)
00302    {
00303 /*
00304       fprintf(stderr," \n PlumeCheck: Warning \n");
00305       fprintf(stderr,"  Curved centerlines must have ndx == 1 \n");
00306       fprintf(stderr,"  ndx reset to 1 \n");
00307 */
00308       grid->ndx = 1;
00309       grid->dx = grid->dy;
00310    }
00311    
00312    if( grid->dx <= 0 || grid->ndx%1 != 0 )
00313    {
00314       fprintf(stderr," \n ERROR in PLUME input parameters (PlumeCheck.c) \n");
00315       fprintf(stderr,"   The x grid spacing (dx) is out of range \n");
00316       fprintf(stderr,"   dx = %f, ndx = %d \n", grid->dx, grid->ndx);
00317       fprintf(stderr,"   Allowed Range: ndx must be an integer and dx > 0 \n");
00318       err = 1;
00319    }
00320    
00321    if( opt->o1 != 1 && opt->o1 != 0 )
00322    {
00323       fprintf(stderr," \n PlumeCheck.c: Warning  \n");
00324       fprintf(stderr,"   The standalone output Flag is out of range \n");
00325       fprintf(stderr,"   o1 = %d \n", opt->o1);
00326       fprintf(stderr,"   o1 must equal 0 or 1 \n");
00327       fprintf(stderr,"   defaulting to 1 \n");
00328       opt->o1 = 1;
00329    }
00330    
00331    if( opt->o2 != 1 && opt->o2 != 0 )
00332    {
00333       fprintf(stderr," \n PlumeCheck.c: Warning  \n");
00334       fprintf(stderr,"   The SEDFLUX-2D output Flag is out of range \n");
00335       fprintf(stderr,"   o2 = %d \n", opt->o2);
00336       fprintf(stderr,"   o2 must equal 0 or 1 \n");
00337       fprintf(stderr,"   defaulting to 0 \n");
00338       opt->o2 = 0;
00339    }
00340    
00341    if( opt->o3 != 1 && opt->o3 != 0 )
00342    {
00343       fprintf(stderr," \n PlumeCheck.c: Warning  \n");
00344       fprintf(stderr,"   The SEDFLUX-3D output Flag is out of range \n");
00345       fprintf(stderr,"   o3 = %d \n", opt->o3);
00346       fprintf(stderr,"   o3 must equal 0 or 1 \n");
00347       fprintf(stderr,"   defaulting to 0 \n");
00348       opt->o3 = 0;
00349    }
00350    
00351    if( opt->o1 == 0 && opt->o2 == 0 && opt->o3 == 0)
00352    {
00353       fprintf(stderr," \n PlumeCheck.c: Warning  \n");
00354       fprintf(stderr,"   All of the output flags are set to 0 (ie no output) \n");
00355       fprintf(stderr,"   defaulting standalone output (o1) to 1 \n");
00356       opt->o1 = 1;
00357    }
00358 
00359    return(err);
00360    
00361 } // end of PlumeCheck.c
00362 

Generated on Fri Jan 4 18:04:15 2008 for sedflux by  doxygen 1.5.2