damp.c

Go to the documentation of this file.
00001 /*
00002 %M This module contains the funtions to compute the damping value.
00003 %a Joao Luiz Elias Campos.
00004 %d September 16th, 2000.
00005 %r $Id: damp.c,v 1.1 2004/06/22 05:29:58 joaoluiz Exp $
00006 %w (C) COPYRIGHT 2000, Joao Luiz Elias Campos.
00007    All Rights Reserved
00008    Duplication of this program or any part thereof without the express
00009    written consent of the author is prohibited.
00010 
00011    Modificacao: 28/04/2005    Alexandre A. Del Savio
00012      Foram substituídas todas as alocações dinâmicas feitas com malloc 
00013      por calloc.
00014 
00015 */
00016 
00017 /*
00018 ** ------------------------------------------------------------------------
00019 ** Global variables and symbols:
00020 */
00021 #include <stdio.h>
00022 #include <string.h>
00023 #include <stdlib.h>
00024 #include <math.h>
00025 #include <time.h>
00026 
00027 #include "load.h"
00028 #include "elm.h"
00029 #include "node.h"
00030 #include "nfi.h"
00031 #include "rio.h"
00032 #include "damp.h"
00033 
00036 sDampClass DampClass[NumDampTypes];
00037 
00040 sDamp *DampObj = 0L;
00041 
00042 
00043 /*
00044 ** ------------------------------------------------------------------------
00045 ** Local variables and symbols:
00046 */
00047 
00048 #ifndef PI
00049 #define PI 3.141592654
00050 #endif
00051 
00052 
00053 /*
00054 ** ------------------------------------------------------------------------
00055 ** Local functions:
00056 */
00057 
00058 
00059 /*
00060 ** ------------------------------------------------------------------------
00061 ** Auto-Global damping methods:
00062 */
00063 static void AutoGlobalNew ( sDamp ** );
00064 static void AutoGlobalFree( sDamp * );
00065 static void AutoGlobalRead( sDamp * );
00066 static void AutoGlobalCalc( sDamp *, int, double, double *, double *,
00067                                                   double *, double * );
00068 
00071 typedef struct _autoglobal
00072 {
00073  double freq;
00074  double frac;
00075  double adfac;
00076  double admul;
00077 } sAutoGlobal;
00078 
00079 
00082 static void AutoGlobalNew( sDamp **damp )
00083 {
00084  sAutoGlobal *data = 0L;
00085 
00086 /* Get memory for the damping object
00087  */
00088  (*damp) = (sDamp *)calloc(1, sizeof(sDamp));
00089 
00090 /* Get memory for the data object
00091  */
00092  data = (sAutoGlobal *)calloc(1, sizeof(sAutoGlobal));
00093 
00094 /* Initialize data structure
00095  */
00096  data->freq  = 0.0;
00097  data->frac  = 0.0;
00098  data->adfac = 0.0;
00099  data->admul = 0.0;
00100 
00101 /* Fill up damping object descriptor
00102  */
00103  (*damp)->type = AUTO_GLOBAL;
00104  (*damp)->data = (void *)data;
00105 
00106 } /* End of AutoGlobalNew */
00107 
00110 static void AutoGlobalFree( sDamp *damp )
00111 {
00112  sAutoGlobal *data = 0L;
00113 
00114 /* Get damping data
00115  */
00116  data = (sAutoGlobal *)damp->data;
00117 
00118 /* Release data
00119  */
00120  free( data );
00121 
00122 /* Reset data value
00123  */
00124  damp->data = 0L;
00125 
00126 } /* End of AutoGlobalFree */
00127 
00130 static void AutoGlobalRead( sDamp *damp )
00131 {
00132  sAutoGlobal *data = 0L;
00133  double       freq, frac, adfac, admul;
00134 
00135 /* Get the element data
00136  */
00137  data = (sAutoGlobal *)damp->data;
00138 
00139 /* Read the damping incidence
00140  */
00141  fscanf( nf, "%lf %lf %lf %lf", &freq, &frac, &adfac, &admul );
00142 
00143 /* Fill element information
00144  */
00145  data->freq  = freq;
00146  data->frac  = frac;
00147  data->adfac = adfac;
00148  data->admul = admul;
00149 
00150 } /* End of AutoGlobalRead */
00151 
00156 static void AutoGlobalCalc( sDamp *damp, int iteration, double dtime, 
00157                             double *MVector, double *VVector, double *alpha, 
00158                             double *CinEng )
00159 {
00160  sAutoGlobal *data = 0L;
00161  double       damppar, DEnergy, CurrEng;
00162  int          i;
00163 
00164 /* Get the auto-global data
00165  */
00166  data = (sAutoGlobal *)damp->data;
00167 
00168 /* Check for the first iteration
00169  */
00170  if( iteration == 0 )
00171  {
00172  /* Compute the damp value for the first iteration
00173   */
00174   (*alpha) = 2.0 * PI * data->freq * data->frac;
00175  }
00176  else
00177  {
00178  /* Compute for the odd iteration
00179   */
00180   if( (iteration%2) == 0 )
00181   {
00182   /* Initialize the current cinetc energy
00183    */
00184    CurrEng = 0.0;
00185 
00186   /* Loop over the nodes
00187    */
00188    for( i = 0; i < NumNodes; i++ )
00189    {
00190     if( NodeVector[i].rezone == NONE )
00191     {
00192      if( NodeVector[i].dof.x != DISPLACEMENT )
00193       CurrEng += (MVector[NDof*i]*VVector[NDof*i]*VVector[NDof*i])/2.0;
00194      if( NodeVector[i].dof.y != DISPLACEMENT )
00195       CurrEng += (MVector[NDof*i+1]*VVector[NDof*i+1]*VVector[NDof*i+1])/2.0;
00196      if( (NDof == 3) && (NodeVector[i].dof.z != DISPLACEMENT) )
00197       CurrEng += (MVector[NDof*i+2]*VVector[NDof*i+2]*VVector[NDof*i+2])/2.0;
00198     }
00199    }
00200 
00201   /* Compute the cinetic energy variation
00202    */
00203    DEnergy = CurrEng - (*CinEng);
00204 
00205    if( DEnergy != 0.0 )
00206    {
00207    /* Update the damping parameter
00208     */
00209     damppar = (2.0 * (*alpha) * CurrEng * dtime) / fabs(DEnergy);
00210 
00211     if( damppar < data->admul )
00212      (*alpha) *= data->admul;
00213     else
00214      (*alpha) /= data->admul;
00215    }
00216 
00217   /* Update the total cinetic energy
00218    */
00219    (*CinEng) = CurrEng;
00220 
00221   }
00222  }
00223 
00224 } /* End of AutoGlobalCalc */
00225 
00226 
00227 /*
00228 ** ------------------------------------------------------------------------
00229 ** Auto-Local damping methods:
00230 */
00231 static void AutoLocalNew ( sDamp ** );
00232 static void AutoLocalFree( sDamp * );
00233 static void AutoLocalRead( sDamp * );
00234 static void AutoLocalCalc( sDamp *, int, double, double *, double *,
00235                                                  double *, double * );
00236 
00239 typedef struct _autolocal
00240 {
00241  double cadl;
00242 } sAutoLocal;
00243 
00244 
00247 static void AutoLocalNew( sDamp **damp )
00248 {
00249  sAutoLocal *data = 0L;
00250 
00251 /* Get memory for the damping object
00252  */
00253  (*damp) = (sDamp *)calloc(1, sizeof(sDamp));
00254 
00255 /* Get memory for the data object
00256  */
00257  data = (sAutoLocal *)calloc(1, sizeof(sAutoLocal));
00258 
00259 /* Initialize data structure
00260  */
00261  data->cadl = 0.0;
00262 
00263 /* Fill up damping object descriptor
00264  */
00265  (*damp)->type = AUTO_LOCAL;
00266  (*damp)->data = (void *)data;
00267 
00268 } /* End of AutoLocalNew */
00269 
00272 static void AutoLocalFree( sDamp *damp )
00273 {
00274  sAutoLocal *data = 0L;
00275 
00276 /* Get damping data
00277  */
00278  data = (sAutoLocal *)damp->data;
00279 
00280 /* Release data
00281  */
00282  free( data );
00283 
00284 /* Reset data value
00285  */
00286  damp->data = 0L;
00287 
00288 } /* End of AutoLocalFree */
00289 
00292 static void AutoLocalRead( sDamp *damp )
00293 {
00294  sAutoLocal *data = 0L;
00295  double      cadl;
00296 
00297 /* Get the damping data
00298  */
00299  data = (sAutoLocal *)damp->data;
00300 
00301 /* Read the damping parameters
00302  */
00303  fscanf( nf, "%lf", &cadl );
00304 
00305 /* Fill up damping information
00306  */
00307  data->cadl = cadl;
00308 
00309 } /* End of AutoLocalRead */
00310 
00315 static void AutoLocalCalc( sDamp *damp, int iteration, double dtime, 
00316                            double *MVector, double *VVector, double *alpha, 
00317                            double *CinEng )
00318 {
00319  sAutoLocal *data = 0L;
00320  double      CurrEng;
00321  int         i;
00322 
00323 /* Get the auto-local data
00324  */
00325  data = (sAutoLocal *)damp->data;
00326 
00327 /* Check for the first iteration
00328  */
00329  if( iteration == 0 )
00330  {
00331  /* Compute the damp value for the first iteration
00332   */
00333   (*alpha) = data->cadl;
00334  }
00335  else
00336  {
00337  /* Compute for the odd iteration
00338   */
00339   if( (iteration%2) == 0 )
00340   {
00341   /* Initialize the current cinetc energy
00342    */
00343    CurrEng = 0.0;
00344 
00345   /* Loop over the nodes
00346    */
00347    for( i = 0; i < NumNodes; i++ )
00348    {
00349     if( NodeVector[i].rezone == NONE )
00350     {
00351      if( NodeVector[i].dof.x != DISPLACEMENT )
00352       CurrEng += (MVector[NDof*i]*VVector[NDof*i]*VVector[NDof*i])/2.0;
00353      if( NodeVector[i].dof.y != DISPLACEMENT )
00354       CurrEng += (MVector[NDof*i+1]*VVector[NDof*i+1]*VVector[NDof*i+1])/2.0;
00355      if( (NDof == 3) && (NodeVector[i].dof.z != DISPLACEMENT) )
00356       CurrEng += (MVector[NDof*i+2]*VVector[NDof*i+2]*VVector[NDof*i+2])/2.0;
00357     }
00358    }
00359 
00360   /* Update the total cinetic energy
00361    */
00362    (*CinEng) = CurrEng;
00363 
00364   }
00365  }
00366 
00367 } /* End of AutoLocalCalc */
00368 
00369 
00370 /*
00371 ** ------------------------------------------------------------------------
00372 ** Rayleigh damping methods:
00373 */
00374 static void RayleighNew ( sDamp ** );
00375 static void RayleighFree( sDamp * );
00376 static void RayleighRead( sDamp * );
00377 static void RayleighCalc( sDamp *, int, double, double *, double *,
00378                                                 double *, double * );
00379 
00382 typedef struct _rayleigh
00383 {
00384  double freq;
00385  double frac;
00386  double f1;
00387  double f2;
00388 } sRayleigh;
00389 
00390 
00393 static void RayleighNew( sDamp **damp )
00394 {
00395  sRayleigh *data = 0L;
00396 
00397 /* Get memory for the damping object
00398  */
00399  (*damp) = (sDamp *)calloc(1, sizeof(sDamp));
00400 
00401 /* Get memory for the data object
00402  */
00403  data = (sRayleigh *)calloc(1, sizeof(sRayleigh));
00404 
00405 /* Initialize data structure
00406  */
00407  data->freq = 0.0;
00408  data->frac = 0.0;
00409  data->f1   = 0.0;
00410  data->f2   = 0.0;
00411 
00412 /* Fill up damping object descriptor
00413  */
00414  (*damp)->type = RAYLEIGH;
00415  (*damp)->data = (void *)data;
00416 
00417 } /* End of RayleighNew */
00418 
00421 static void RayleighFree( sDamp *damp )
00422 {
00423  sRayleigh *data = 0L;
00424 
00425 /* Get damping data
00426  */
00427  data = (sRayleigh *)damp->data;
00428 
00429 /* Release data
00430  */
00431  free( data );
00432 
00433 /* Reset data value
00434  */
00435  damp->data = 0L;
00436 
00437 } /* End of RayleighFree */
00438 
00441 static void RayleighRead( sDamp *damp )
00442 {
00443  sRayleigh *data = 0L;
00444  double     freq, frac, f1, f2;
00445 
00446 /* Get the damping data
00447  */
00448  data = (sRayleigh *)damp->data;
00449 
00450 /* Read the damping parameters
00451  */
00452  fscanf( nf, "%lf %lf %lf %lf", &freq, &frac, &f1, &f2 );
00453 
00454 /* Fill up damping information
00455  */
00456  data->freq = freq;
00457  data->frac = frac;
00458  data->f1   = f1;
00459  data->f2   = f2;
00460 
00461 } /* End of RayleighRead */
00462 
00467 static void RayleighCalc( sDamp *damp, int iteration, double dtime, 
00468                           double *MVector, double *VVector, double *alpha, 
00469                           double *CinEng )
00470 {
00471  sRayleigh *data = 0L;
00472 
00473 /* Get the rayleigh data
00474  */
00475  data = (sRayleigh *)damp->data;
00476 
00477 } /* End of AutoRayleighCalc */
00478 
00479 
00480 /*
00481 ** ------------------------------------------------------------------------
00482 ** Dampping initialize functions:
00483 */
00484 
00487 void AutoGlobalInit( void );
00488 void AutoGlobalInit( void )
00489 {
00490 /* Initialize Auto-Global damping
00491  */
00492  DampClass[AUTO_GLOBAL].new  = AutoGlobalNew;
00493  DampClass[AUTO_GLOBAL].free = AutoGlobalFree;
00494  DampClass[AUTO_GLOBAL].read = AutoGlobalRead;
00495  DampClass[AUTO_GLOBAL].calc = AutoGlobalCalc;
00496 
00497 } /* End of AutoGlobalInit */
00498 
00499 
00502 void AutoLocalInit( void );
00503 void AutoLocalInit( void )
00504 {
00505 /* Initialize Auto-Local damping
00506  */
00507  DampClass[AUTO_LOCAL].new  = AutoLocalNew;
00508  DampClass[AUTO_LOCAL].free = AutoLocalFree;
00509  DampClass[AUTO_LOCAL].read = AutoLocalRead;
00510  DampClass[AUTO_LOCAL].calc = AutoLocalCalc;
00511 
00512 } /* End of AutoLocalInit */
00513 
00514 
00517 void RayleighInit( void );
00518 void RayleighInit( void )
00519 {
00520 /* Initialize Rayleigh damping
00521  */
00522  DampClass[RAYLEIGH].new  = RayleighNew;
00523  DampClass[RAYLEIGH].free = RayleighFree;
00524  DampClass[RAYLEIGH].read = RayleighRead;
00525  DampClass[RAYLEIGH].calc = RayleighCalc;
00526 
00527 } /* End of RayleighInit */
00528 
00529 
00530 /*
00531 ** ------------------------------------------------------------------------
00532 ** Public functions:
00533 */
00534 
00535 /*
00536 %F
00537 */
00538 void DampingInit( void )
00539 {
00540  int i;
00541 
00542 /* Define the subclasses initialization methods
00543  */
00544  DampClass[AUTO_GLOBAL].init = AutoGlobalInit;
00545  DampClass[AUTO_LOCAL].init  = AutoLocalInit;
00546  DampClass[RAYLEIGH].init    = RayleighInit;
00547 
00548  for( i = 0; i < NumDampTypes; i++ )
00549   DampInit( i );
00550 
00551 } /* End of DampingInit */
00552 
00553 
00554 /* =======================================================  End of File  */
00555 

Generated on Tue Oct 23 11:23:29 2007 for Relax by  doxygen 1.5.3