SPModel: plugins/faultBlocks/FaultBlocks.c Source File
VPAC - Computational Software Development
Main | SPModel | StGermain FrameWork |
Main Page | Alphabetical List | Class List | Directories | File List | Class Members | File Members

FaultBlocks.c

Go to the documentation of this file.
00001 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00002 **
00003 ** Copyright (C), 2004, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
00004 **
00005 ** Authors:
00006 **  Ogar R. Widjaja, Computational Scientist, VPAC.
00007 **  Raquibul Hassan, Software Engineer, VPAC. (raq@vpac.org)
00008 **  Keith Hsuan, Computational Scientist, VPAC (keith@vpac.org)
00009 **  William F. Appelbe, Director, VPAC. (bill@vpac.org)
00010 **  Stevan M. Quenette, Senior Software Engineer, VPAC. (steve@vpac.org)
00011 **  Patrick D. Sunter, Software Engineer, VPAC. (patrick@vpac.org)
00012 **
00013 ** This file may be distributed under the terms of the VPAC Public License
00014 ** as defined by VPAC of Australia and appearing in the file
00015 ** LICENSE.VPL included in the packaging of this file.
00016 **
00017 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00018 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00019 **
00020 ** $Id: FaultBlocks.c 225 2005-12-22 00:01:19Z AlanLo $
00021 **
00022 **~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
00023 
00024 
00025 #include <mpi.h>
00026 #include <StGermain/StGermain.h>
00027 #include "SPModel/SPModel.h"
00028 #include <stdlib.h>
00029 #include <string.h>
00030 #include <assert.h>
00031 
00032 
00033 #include "FaultBlocks.h"
00034 
00035 /* Textual name of this module */
00036 const Type SPModelFaultBlocks_Type = "SPModelFaultBlocks";
00037 ExtensionInfo_Index SPModel_FaultBlocks_ContextExtHandle;
00038 
00039 void* _SPModelFaultBlocks_DefaultNew( Name name ) {
00040     return Codelet_New(
00041             SPModelFaultBlocks_Type,
00042             _SPModelFaultBlocks_DefaultNew,
00043             _SPModelFaultBlocks_Construct,
00044             _Codelet_Build,
00045             _Codelet_Initialise,
00046             _Codelet_Execute,
00047             _Codelet_Destroy,
00048             name );
00049 }
00050 
00051 void _SPModelFaultBlocks_Construct( void* component, Stg_ComponentFactory* data ) { 
00052     SPModel_Context*                context;
00053 
00054     context = (SPModel_Context*)Stg_ComponentFactory_ConstructByName( data, "context", SPModel_Context, True );
00055     
00056     SPModel_FaultBlocks_ContextExtHandle = ExtensionManager_Add( context->extensionMgr, "FaultBlocks",
00057                                             sizeof(SPModelFaultBlocksContextExtension) );
00058     
00059     _SPModelFaultBlocks_Init( context );
00060     
00061     Journal_DPrintf( context->debug, "In %s():\n", __func__ );
00062     ContextEP_Append( context, AbstractContext_EP_Solve, SPModelFaultBlocks_Solve );
00063 }   
00064 
00065 void _SPModelFaultBlocks_Init( void* _context ) {
00066     SPModel_Context *context = NULL;
00067     SPModelFaultBlocksContextExtension *faultBlocks = NULL;
00068     Dictionary *dict = NULL;
00069     FILE *f;
00070     char *fileName = NULL;
00071     int i = 0, j = 0;
00072 
00073     context = (SPModel_Context*)_context;
00074     assert( context );
00075     
00076     faultBlocks = (SPModelFaultBlocksContextExtension*)ExtensionManager_Get
00077                     ( context->extensionMgr, context, SPModel_FaultBlocks_ContextExtHandle );
00078     assert( faultBlocks );
00079     
00080     dict = context->dictionary;
00081 
00082     fileName = Dictionary_GetString_WithDefault( dict, "faultBlockFile", "faultBlocks.dat" );
00083 
00084     if( (f = fopen( fileName, "rt" )) ){
00085         fscanf(f,"%d %d %d\n",&(faultBlocks->numFaultBlocks),
00086                 &(faultBlocks->maxNumFaultBlockNodes),
00087                 &(faultBlocks->maxNat) );
00088         
00089         faultBlocks->numFaultBlockNodes = Memory_Alloc_Array_Unnamed( int, faultBlocks->numFaultBlocks );
00090         faultBlocks->faultBlockNat = Memory_Alloc_Array_Unnamed( int, faultBlocks->numFaultBlocks );
00091         faultBlocks->faultBlockNodes = Memory_Alloc_2DArray_Unnamed( int, faultBlocks->numFaultBlocks,
00092                                                                     faultBlocks->maxNumFaultBlockNodes );
00093         faultBlocks->faultBlockWeights = Memory_Alloc_2DArray_Unnamed( double, faultBlocks->numFaultBlocks,
00094                                                                     faultBlocks->maxNumFaultBlockNodes );
00095 
00096         faultBlocks->faultBlockTimes = Memory_Alloc_3DArray_Unnamed( double, faultBlocks->numFaultBlocks,
00097                                                                     faultBlocks->maxNumFaultBlockNodes, 3 );
00098 
00099         for ( i=0; i<faultBlocks->numFaultBlocks; i++ ){
00100             fscanf( f, "%d %d\n", &(faultBlocks->numFaultBlockNodes[i]), &(faultBlocks->faultBlockNat[i]));
00101             
00102             for ( j=0; j<faultBlocks->numFaultBlockNodes[i]; j++){
00103                 fscanf( f,"%d ",&(faultBlocks->faultBlockNodes[i][j]) );
00104                 fprintf( f,"\n" );
00105             }
00106             
00107             for ( j=0; j<faultBlocks->numFaultBlockNodes[i]; j++){
00108                 fscanf( f,"%lf ", &(faultBlocks->faultBlockWeights[i][j]) );
00109                 fprintf( f,"\n" );
00110             }
00111             
00112             for ( j=0; j<faultBlocks->faultBlockNat[i]; j++){
00113                 fscanf( f,"%lf %lf %lf\n", &(faultBlocks->faultBlockTimes[i][j][0]),
00114                         &(faultBlocks->faultBlockTimes[i][j][1]),
00115                         &(faultBlocks->faultBlockTimes[i][j][2]) );
00116             }   
00117         }
00118         fclose( f );
00119         Journal_Printf( context->info, "Successfully read `%s`\n", fileName );
00120     }
00121     else{
00122         Journal_Printf( context->info, "Error opening file `%s`..!\n", fileName );
00123         abort();
00124     }
00125 }
00126 
00127 void SPModelFaultBlocks_Solve( void *_context ) {
00128     SPModel_Context *context = NULL;
00129     SPModelFaultBlocksContextExtension *faultBlocks = NULL;
00130     SurfaceMesh *mesh = NULL;
00131     int i, j, hit;
00132     double dc = 0;
00133     int interval = 1;
00134     int localIndex = 0;
00135 
00136     context = (SPModel_Context*)_context;
00137     assert( context );
00138     
00139     faultBlocks = (SPModelFaultBlocksContextExtension*)ExtensionManager_Get
00140                     ( context->extensionMgr, context, SPModel_FaultBlocks_ContextExtHandle );
00141     assert( faultBlocks );
00142 
00143     mesh = context->localMesh;
00144     
00145     for( i=0; i<faultBlocks->numFaultBlocks; i++ ){
00146         hit = 0; j = 0; dc = 0.0f;
00147 
00148         while( (hit==0)&&(j<faultBlocks->faultBlockNat[i]) ){
00149             if( (context->currentTime > faultBlocks->faultBlockTimes[i][j][0]) && 
00150                     (context->currentTime > faultBlocks->faultBlockTimes[i][j][0]) ){
00151                 dc = faultBlocks->faultBlockTimes[i][j][2] * context->dt * (double) interval;
00152                 hit = 1;
00153             }
00154             ++j;
00155         }
00156 
00157         for( j=0; j<faultBlocks->numFaultBlockNodes[i]; j++ ){
00158             localIndex = mesh->mapGlobalToLocal[faultBlocks->faultBlockNodes[i][j]-1];
00159             if( localIndex != mesh->myLoad ){
00160                 mesh->h[localIndex] += dc * context->bedRockDensity * context->gravity * 
00161                                             faultBlocks->faultBlockWeights[i][j];
00162                 /*TODO DCMASS*/
00163             }
00164         }
00165     }
00166 }
00167 
00168 Index SPModelFaultBlocks_Register( PluginsManager* pluginsManager ) {
00169     return PluginsManager_Submit( pluginsManager, SPModelFaultBlocks_Type, "0", _SPModelFaultBlocks_DefaultNew );
00170 }
00171