/Users/huttone/Devel/sedflux-new/sedflux/trunk/ew/subside/subside.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 #include <stdio.h>
00022 #include <stdlib.h>
00023 #include <utils/utils.h>
00024 #include <sed/sed_sedflux.h>
00025 #include "subside.h"
00026 
00027 #include <math.h>
00028 
00029 #define N_THREADS 5
00030 
00031 typedef struct
00032 {
00033    Eh_dbl_grid w;
00034    double      v_0;
00035    double      eet;
00036    double      y;
00037    gint        id;
00038 }
00039 Subside_data;
00040 
00041 void subside_helper( gpointer data , gpointer v_0 );
00042 
00043 /* Calculate a deflection grid
00044 
00045 \param w   Grid of deflections.
00046 \param v_0 Grid of loads.
00047 \param eet Effective elastic thickness.
00048 \parma y   Young's modulus
00049 
00050 */
00051 void
00052 subside_grid_load( Eh_dbl_grid w , Eh_dbl_grid v_0 , double eet , double y )
00053 {
00054    eh_require( w   );
00055    eh_require( v_0 );
00056 
00057    if ( !g_thread_supported() ) g_thread_init(NULL);
00058 #undef WITH_THREADS
00059 #ifndef WITH_THREADS
00060    if ( w && v_0 )
00061    {
00062       gssize i, j;
00063       double load;
00064       gssize n_x = eh_grid_n_x( v_0 );
00065       gssize n_y = eh_grid_n_y( v_0 );
00066    
00067       for ( i=0 ; i<n_x ; i++ )
00068          for ( j=0 ; j<n_y ; j++ )
00069          {
00070             load = eh_dbl_grid_val( v_0 , i , j );
00071             if ( fabs(load) > 1e-3 )
00072                subside_point_load( w , load , eet , y , i , j );
00073          }
00074    }
00075 #else
00076    if ( w && v_0 )
00077    {
00078       GThreadPool* pool;
00079 
00080       pool = g_thread_pool_new( subside_helper , NULL , N_THREADS , TRUE , NULL );
00081 
00082       eh_require( pool );
00083       {
00084          Subside_data* queue = NULL;
00085          gssize len = eh_grid_n_el( v_0 );
00086          gssize id, n, n_jobs;
00087          double load;
00088 
00089          queue = eh_new( Subside_data , len );
00090          for ( id=0,n=0 ; id<len ; id++ )
00091          {
00092             load = eh_dbl_grid_data( v_0 )[0][id];
00093             if ( fabs(load) > 1e-3 )
00094             {
00095                queue[n].w   = eh_grid_dup( w );
00096                eh_dbl_grid_set( queue[n].w , 0. );
00097 
00098                queue[n].v_0 = load;
00099                queue[n].id  = id;
00100                queue[n].eet = eet;
00101                queue[n].y   = y;
00102 
00103                g_thread_pool_push( pool , &(queue[n]) , NULL );
00104 
00105                n++;
00106             }
00107          }
00108          g_thread_pool_free( pool , FALSE , TRUE );
00109          n_jobs = n;
00110 
00111          for ( n=0 ; n<n_jobs ; n++ )
00112          {
00113             eh_dbl_grid_add( w , queue[n].w );
00114             eh_grid_destroy( queue[n].w , TRUE );
00115          }
00116          eh_free( queue );
00117       }
00118    }
00119 #endif
00120 
00121    return;
00122 }
00123 
00124 void subside_helper( gpointer d , gpointer g )
00125 {
00126    Subside_data* data = (Subside_data*)d;
00127    Eh_ind_2      sub  = eh_grid_id_to_sub( eh_grid_n_y(data->w) , data->id );
00128    double        load = data->v_0;
00129 
00130    subside_point_load( data->w , load , data->eet , data->y , sub.i , sub.j );
00131 
00132    return;
00133 }
00134 
00135 void
00136 subside_point_load( Eh_dbl_grid g , double load , double h , double E , int i_load , int j_load )
00137 {
00138    double alpha;
00139    double x_0, y_0;
00140    double **z = eh_dbl_grid_data(g);
00141 
00142    alpha = get_flexure_parameter( h , E , (eh_grid_n_x(g)==1)?1:2 );
00143 
00144    x_0 = eh_grid_x(g)[i_load];
00145    y_0 = eh_grid_y(g)[j_load];
00146 
00147    if ( eh_grid_n_x(g) > 1 )
00148    {
00149       gssize i, j;
00150       double r;
00151       double c = load/(2.*M_PI*sed_rho_mantle()*sed_gravity()*pow(alpha,2.));
00152 
00153       for ( i=0 ; i<eh_grid_n_x(g) ; i++ )
00154          for ( j=0 ; j<eh_grid_n_y(g) ; j++ )
00155          {
00156             r              = sqrt( pow(eh_grid_x(g)[i]-x_0,2) + pow(eh_grid_y(g)[j]-y_0,2) )
00157                            / alpha;
00158             z[i][j] += - c * eh_kei_0( r );
00159          }
00160    }
00161    else
00162    {
00163       if ( fabs( load )>1e-5 )
00164       {
00165          gssize j;
00166          double r;
00167          double c = load/( 2.*alpha*sed_rho_mantle()*sed_gravity() );
00168 
00169          for ( j=0 ; j<eh_grid_n_y(g) ; j++ )
00170          {
00171             r = fabs(eh_grid_y(g)[j]-y_0)/alpha;
00172             z[0][j] += c * exp( -r ) * ( cos(r) + sin(r) );
00173          }
00174       }
00175 
00176    }
00177 
00178 }
00179 
00180 void subside_half_plane_load( Eh_dbl_grid g ,
00181                               double load    ,
00182                               double h       ,
00183                               double E )
00184 {
00185    double alpha = get_flexure_parameter( h , E , (eh_grid_n_x(g)==1)?1:2 );
00186 
00187    //---
00188    // This half-plane solution is only valid for the 1D case.
00189    //---
00190    eh_require( eh_grid_n_x(g)==1 )
00191    {
00192       //---
00193       // Add half-plane load.
00194       //---
00195       if ( fabs(load)>1e-5 )
00196       {
00197          gssize i;
00198          double r;
00199          double y_l = 1.5*eh_grid_y(g)[eh_grid_n_y(g)-1]
00200                     -  .5*eh_grid_y(g)[eh_grid_n_y(g)-2];
00201          double c   = load/(2*sed_rho_mantle()*sed_gravity());
00202          double** z = eh_dbl_grid_data(g);
00203 
00204          for ( i=0 ; i<eh_grid_n_y(g) ; i++ )
00205          {
00206             r        = (y_l - eh_grid_y(g)[i])/alpha;
00207             z[0][i] += c * exp(-r)*cos(r);
00208          }
00209       }
00210    }
00211 }
00212 
00213 double get_flexure_parameter( double h , double E , gssize n_dim )
00214 {
00215    double poisson = .25;
00216    double D       = E*pow(h,3)/12./(1-pow(poisson,2));
00217    double rho_m   = sed_rho_mantle();
00218    double alpha;
00219 
00220    eh_require( n_dim==1 || n_dim==2 );
00221 
00222    if ( n_dim > 1 )
00223       alpha = pow( D / (rho_m * sed_gravity()) , .25 );
00224    else
00225       alpha = pow( 4.*D/(rho_m * sed_gravity()) , .25 );
00226 
00227    return alpha;
00228 }
00229 

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