stdve.c

Go to the documentation of this file.
00001 /*
00002 %M This modules contains the driver methods to solve a problem using the 
00003    dynamic relax algorithm with visco elastic materials.
00004 %a Joao Luiz Elias Campos.
00005 %d June 20th, 2000.
00006 %r $Id: stdve.c,v 1.1 2004/06/22 05:29:59 joaoluiz Exp $
00007 %w (C) COPYRIGHT 1995-1996, Eduardo Nobre Lages.
00008    (C) COPYRIGHT 1997-2000, Joao Luiz Elias Campos.
00009    All Rights Reserved
00010    Duplication of this program or any part thereof without the express
00011    written consent of the author is prohibited.
00012 *
00013 *  Modified: 28-Apr-2005    Alexandre A. Del Savio
00014 *    Foram substituídas todas as alocações dinâmicas feitas com malloc 
00015 *    por calloc.
00016 *
00017 *  Modified: 23-Fev-2006    Juan Pablo Ibañez
00018 *    Modificada a funcão StandardVEAnalysis que passa a retornar un valor int.       
00019 */
00020 
00021 /*
00022 ** ------------------------------------------------------------------------
00023 ** Global variables and symbols:
00024 */
00025 #include <stdio.h>
00026 #include <stdlib.h>
00027 #include <string.h>
00028 #include <math.h>
00029 
00030 #include "drv.h"
00031 #include "fem.h"
00032 #include "load.h"
00033 #include "elm.h"
00034 #include "node.h"
00035 #include "alg.h"
00036 #include "rio.h"
00037 #include "nfi.h"
00038 #include "load.h"
00039 #include "xgplib.h"
00040 
00041 
00042 /*
00043 ** ------------------------------------------------------------------------
00044 ** Local variables and symbols:
00045 */
00046 
00047 /*
00048 ** ------------------------------------------------------------------------
00049 ** Local functions:
00050 */
00051 static void StandardVEViscoForces( double * );
00052 static void StandardVENew        ( sDriver ** );
00053 static void StandardVEFree       ( sDriver * );
00054 static int  StandardVEAnalysis   (UI_State *);
00055 static int  StandardVEPrintResult( int, double *, double * );
00056 
00057 
00058 /*
00059 %F
00060 */
00061 static void StandardVEViscoForces( double *U )
00062 {
00063  int     i, j, num, id;
00064  int     inc[8];
00065  sTensor stress[8], strain[8];
00066  double  vforce[24];
00067 
00068 /* Loop over the elements
00069  */
00070  for( i = 0; i < NumElements; i++ )
00071  {
00072  /* Check to see if the element was not rezoned
00073   */
00074   if( ElmList[i]->rezone != NONE )
00075    continue;
00076 
00077  /* Compute element stress strain
00078   */
00079   ElmStressStrain( ElmList[i], 0.0, U, 0L, stress, strain );
00080 
00081  /* Compute element visco forces
00082   */
00083   ElmViscoForce( ElmList[i], Config.timeStep, stress, vforce );
00084 
00085  /* Add to the node information
00086   */
00087   ElmConnect( ElmList[i], inc );
00088   ElmNumNodes( ElmList[i], &num );
00089   for( j = 0; j < num; j++ )
00090   {
00091    id = inc[j] - 1;
00092    if( NodeVector[id].rezone == NONE )
00093    {
00094     if( NodeVector[id].dof.x == FORCE )
00095      NodeVector[id].dof.vpx += vforce[NDof*j];
00096 
00097     if( NodeVector[id].dof.y == FORCE ) 
00098      NodeVector[id].dof.vpy += vforce[NDof*j+1];
00099 
00100     if( NDof == 3 )
00101      if( NodeVector[id].dof.z == FORCE )
00102       NodeVector[id].dof.vpz += vforce[NDof*j+2];
00103    }
00104   }
00105  }
00106  
00107 } /* End of StandardVEViscoForces */
00108 
00109 
00110 /*
00111 %F
00112 */
00113 static void StandardVENew( sDriver **drv )
00114 {
00115 /* Get memory for the driver descriptor
00116  */
00117  (*drv) = (sDriver *)calloc(1, sizeof(sDriver));
00118 
00119 /* Fill up driver descriptor
00120  */
00121  (*drv)->type = STANDARD_VE;
00122 
00123 } /* End of StandardVENew */
00124 
00125 
00126 /*
00127 %F
00128 */
00129 static void StandardVEFree( sDriver *drv )
00130 {
00131 /* Reset driver data
00132  */
00133  drv->data = 0L;
00134 
00135 } /* End of StandardVEFree */
00136 
00137 
00138 /*
00139 %F This function process the probleam analysis using a dynamic relax 
00140    algorithm.
00141 */
00142 static int StandardVEAnalysis(UI_State *R)
00143 {
00144  int     i, n;
00145  double  time, disp;
00146  double *F  = 0L;
00147  double *U  = 0L;
00148  double *V  = 0L;
00149  double *M  = 0L;
00150  double *dU = 0L;
00151  
00152 /* Get memory for the vectors used during the analysis
00153  */
00154  F  = (double *)calloc( NDof*NumNodes, sizeof(double) );
00155  U  = (double *)calloc( NDof*NumNodes, sizeof(double) );
00156  V  = (double *)calloc( NDof*NumNodes, sizeof(double) );
00157  M  = (double *)calloc( NDof*NumNodes, sizeof(double) );
00158  dU = (double *)calloc( NDof*NumNodes, sizeof(double) );
00159 
00160 /* Start graphic module
00161  */
00162  XGPBegin( );
00163 
00164 /* Print feedback message
00165  */
00166  printf( "\tSolve problem........................:\n" );
00167  fflush( stdout );
00168 
00169 /* For each time step
00170  */
00171  for( time = 0.0; time <= Config.totalTime; time += Config.timeStep )
00172  {
00173  /* Apply prescribed values
00174   */
00175   PrescribedValues( );
00176 
00177  /* Add visco forces
00178   */
00179   StandardVEViscoForces( U );
00180 
00181  /* Print feedback message
00182   */
00183   printf( "\tTotal time...........................: %f\n", time );
00184   fflush( stdout );
00185 
00186  /* Reset all vectors 
00187   */
00188   F  = (double *)memset( (void *)F, 0, NDof*NumNodes*sizeof(double) );
00189   V  = (double *)memset( (void *)V, 0, NDof*NumNodes*sizeof(double) );
00190   M  = (double *)memset( (void *)M, 0, NDof*NumNodes*sizeof(double) );
00191   dU = (double *)memset( (void *)dU, 0, NDof*NumNodes*sizeof(double) );
00192 
00193  /* Call the dynamic relaxation algorithm
00194   */
00195   if( !DRSolver(R, F, dU, V, M, 0) )
00196   {
00197    IoCloseFiles( );
00198    IoCloseTempFile( );
00199    return 0;
00200   }
00201 
00202  /* Update displacement vector
00203   */
00204   for( i = 0; i < NDof*NumNodes; i++ )
00205    U[i] += dU[i];
00206 
00207  /* Plot displacement x time
00208   */
00209   if( (NumCurves != 0) && (GpType == 4) )
00210   {
00211    for( n = 0; n < NumNodes; n++ )
00212    {
00213     disp  = U[NDof*n] * U[NDof*n];
00214     disp += U[NDof*n+1] * U[NDof*n+1];
00215     if( NDof == 3 )
00216      disp += U[NDof*n+2] * U[NDof*n+2];
00217     if( NodeVector[n].dspTime == DSP_YES )
00218      XGPSendPoint( NodeVector[n].curve, time, sqrt(disp) );
00219    }
00220   }
00221 
00222  /* Update number of time steps
00223   */
00224   Config.num_time_step++;
00225 
00226  /* Write results on a temporary file
00227   */
00228   if( !IoStartSave( ) ) return 0;
00229 
00230   fwrite( U, sizeof(double), NDof*NumNodes, ndlr );
00231   fflush( ndlr );
00232 
00233   for( i = 0; i < NumElements; i++ )
00234    ElmWriteStress( ElmList[i], elmr, U, V );
00235   fflush( elmr );
00236  }
00237 
00238 /* Finish graphic module
00239  */
00240  XGPEnd( );
00241 
00242 /* Release memory
00243  */
00244  free( F );
00245  free( U );
00246  free( V );
00247  free( M );
00248  free( dU );
00249 
00250  return 1;
00251 
00252 } /* End of StandardVEAnalysis */
00253 
00254 
00255 /*
00256 %F
00257 */
00258 static int  StandardVEPrintResult( int iteration, double *U, double *V )
00259 {
00260  return 1;
00261 } /* End of StandardVEPrintResult */
00262 
00263 
00264 /*
00265 ** ------------------------------------------------------------------------
00266 ** Public functions:
00267 */
00268 
00269 /*
00270 %F This function initializes the sub-class STANDARD_VE.
00271 */
00272 void StandardVEInit( void );
00273 void StandardVEInit( void )
00274 {
00275 /* Initialize STANDARD_VE driver sub-class
00276  */
00277  DrvClass[STANDARD_VE].new      = StandardVENew;
00278  DrvClass[STANDARD_VE].free     = StandardVEFree;
00279  DrvClass[STANDARD_VE].analysis = StandardVEAnalysis;
00280  DrvClass[STANDARD_VE].printres = StandardVEPrintResult;
00281 
00282 } /* End of StandardVEInit */
00283 
00284 
00285 /* =======================================================  End of File  */
00286 

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