SPModel: libSPModel/src/SurfaceMeshRectangularCyclicBC.c Source File
VPAC - Computational Software Development
Main | SPModel | StGermain FrameWork |
Main Page | Alphabetical List | Class List | Directories | File List | Class Members | File Members

SurfaceMeshRectangularCyclicBC.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 */
00030 #include <mpi.h>
00031 #include <StGermain/StGermain.h>
00032 #include <Cascade/cascade.h>
00033 
00034 #include <stdio.h>
00035 #include <stdlib.h>
00036 #include <string.h>
00037 #include <assert.h>
00038 #include <math.h>
00039 #include <limits.h>
00040 #include "types.h"
00041 #include "SurfaceMesh.h"
00042 #include "SurfaceMeshCyclicBC.h"
00043 #include "SurfaceMeshRectangularCyclicBC.h"
00044 
00045 /* Textual name of this class */
00046 const Type SurfaceMeshRectangularCyclicBC_Type = "_SurfaceMeshRectangularCyclicBC";
00047     
00048 SurfaceMeshRectangularCyclicBC          *SurfaceMeshRectangularCyclicBC_DefaultNew( Name name ){
00049     return _SurfaceMeshRectangularCyclicBC_New( sizeof( SurfaceMeshRectangularCyclicBC ),
00050                                     SurfaceMeshRectangularCyclicBC_Type,
00051                                     SurfaceMeshRectangularCyclicBC_Delete,
00052                                     SurfaceMeshRectangularCyclicBC_Print,
00053                                     NULL,
00054                                     (void*)SurfaceMeshRectangularCyclicBC_DefaultNew,
00055                                     SurfaceMeshRectangularCyclicBC_Construct,
00056                                     SurfaceMeshRectangularCyclicBC_Build,
00057                                     SurfaceMeshRectangularCyclicBC_Initialise,
00058                                     SurfaceMeshRectangularCyclicBC_Execute,
00059                                     SurfaceMeshRectangularCyclicBC_Destroy,
00060                                     name,
00061                                     False,
00062                                     NULL,
00063                                     NULL,
00064                                     SurfaceMeshRectangularCyclicBC_CreateCyclicBC );
00065 }
00066 
00067 SurfaceMeshRectangularCyclicBC          *SurfaceMeshRectangularCyclicBC_New( Name name,
00068                                                                              SurfaceMesh *mesh,
00069                                                                              Dictionary *dictionary ){
00070     return _SurfaceMeshRectangularCyclicBC_New( sizeof( SurfaceMeshRectangularCyclicBC ),
00071                                     SurfaceMeshRectangularCyclicBC_Type,
00072                                     SurfaceMeshRectangularCyclicBC_Delete,
00073                                     SurfaceMeshRectangularCyclicBC_Print,
00074                                     NULL,
00075                                     (void*)SurfaceMeshRectangularCyclicBC_DefaultNew,
00076                                     SurfaceMeshRectangularCyclicBC_Construct,
00077                                     SurfaceMeshRectangularCyclicBC_Build,
00078                                     SurfaceMeshRectangularCyclicBC_Initialise,
00079                                     SurfaceMeshRectangularCyclicBC_Execute,
00080                                     SurfaceMeshRectangularCyclicBC_Destroy,
00081                                     name,
00082                                     True,
00083                                     dictionary,
00084                                     mesh,
00085                                     SurfaceMeshRectangularCyclicBC_CreateCyclicBC );
00086 }
00087 
00088 SurfaceMeshRectangularCyclicBC                  *_SurfaceMeshRectangularCyclicBC_New( SizeT                         _sizeOfSelf,
00089                                     Type                            type,
00090                                     Stg_Class_DeleteFunction*               _delete,
00091                                     Stg_Class_PrintFunction*                _print,
00092                                     Stg_Class_CopyFunction*             _copy, 
00093                                     Stg_Component_DefaultConstructorFunction*   _defaultConstructor,
00094                                     Stg_Component_ConstructFunction*            _construct,
00095                                     Stg_Component_BuildFunction*        _build,
00096                                     Stg_Component_InitialiseFunction*       _initialise,
00097                                     Stg_Component_ExecuteFunction*      _execute,
00098                                     Stg_Component_DestroyFunction*      _destroy,
00099                                     Name                            name,
00100                                     Bool                            initFlag,
00101                                     Dictionary                      *dictionary,
00102                                     SurfaceMesh                     *_mesh,
00103                                     SurfaceMeshCyclicBC_CreateCyclicBC *_createCyclicBC )
00104 {
00105     SurfaceMeshRectangularCyclicBC* self;
00106     
00107     /* Allocate memory */
00108     assert( _sizeOfSelf >= sizeof(SurfaceMeshRectangularCyclicBC) );
00109     self = (SurfaceMeshRectangularCyclicBC*)_Stg_Component_New( _sizeOfSelf, type, _delete, _print, _copy, _defaultConstructor, _construct, _build, 
00110             _initialise, _execute, _destroy, name, NON_GLOBAL );
00111 
00112     assert( _createCyclicBC );
00113     assert( dictionary );
00114     
00115     self->dictionary = dictionary;
00116     self->mesh = _mesh;
00117     self->createCyclicBC = SurfaceMeshRectangularCyclicBC_CreateCyclicBC;
00118     
00119     if( initFlag ){
00120         SurfaceMeshRectangularCyclicBC_Init( self );
00121     }
00122 
00123     return self;
00124 }
00125 
00126 void SurfaceMeshRectangularCyclicBC_Init( SurfaceMeshRectangularCyclicBC *self )
00127 {
00128     Dictionary *dict = NULL;
00129     int side1 = 0, side2 = 0, i;
00130     
00131     assert( self );
00132     
00133     dict = Dictionary_Entry_Value_AsDictionary( Dictionary_Get( self->dictionary, "CyclicBoundaryConditions" ) );
00134 
00135     assert( dict );
00136     
00137     if( (strcmp( Dictionary_GetString( dict, "BCType" ) , "Rectangular" )) ){
00138         Journal_Printf( Journal_Register( "stream", Info_Type ), 
00139                 "Cyclic Boundary Conditions not yet implemented for %s\n", Dictionary_GetString( dict, "BCType" ) );
00140         abort();
00141     }
00142 
00143     /* The sides are number anticlockwise
00144      *     0
00145      *  -------
00146      *  |     |
00147      * 1|     |3
00148      *  -------
00149      *     2
00150      * */
00151 
00152     for( i=0; i<4; i++ ){
00153         self->sides[i] = -1;
00154     }
00155     
00156     side1 = Dictionary_GetInt_WithDefault( dict, "side1", 0 );
00157     side2 = Dictionary_GetInt_WithDefault( dict, "side2", 3 );
00158 
00159     self->sides[side1] = side1;
00160     self->sides[side2] = side2;
00161 }
00162 
00163 void SurfaceMeshRectangularCyclicBC_Print( void *surfaceMeshRectangularCyclicBC, Stream *stream )
00164 {
00165     SurfaceMeshRectangularCyclicBC *self = (SurfaceMeshRectangularCyclicBC*) surfaceMeshRectangularCyclicBC;
00166 
00167     assert( self );
00168     assert( stream );
00169 
00170     /* print parent */
00171     _Stg_Component_Print( (void*) self, stream );
00172 
00173     /* general info */
00174     Journal_Printf( stream, "SurfaceMeshRectangularCyclicBC (ptr): (%p)\n", self );
00175 
00176     /* Virtual Info */
00177 
00178     /* SurfaceMeshRectangularCyclicBC Info */
00179 }
00180 
00181 void SurfaceMeshRectangularCyclicBC_Delete( void *surfaceMeshRectangularCyclicBC )
00182 {
00183     assert( surfaceMeshRectangularCyclicBC );
00184     
00186     _Stg_Component_Delete( surfaceMeshRectangularCyclicBC );
00187 }
00188 
00189 void SurfaceMeshRectangularCyclicBC_Construct( void *surfaceMeshRectangularCyclicBC, Stg_ComponentFactory *cf )
00190 {
00191     
00192 }
00193 
00194 void SurfaceMeshRectangularCyclicBC_Build( void *surfaceMeshRectangularCyclicBC, void *data )
00195 {
00196     
00197 }
00198 
00199 void SurfaceMeshRectangularCyclicBC_Initialise( void *surfaceMeshRectangularCyclicBC, void *data )
00200 {
00201     
00202 }
00203 
00204 void SurfaceMeshRectangularCyclicBC_Execute( void *surfaceMeshRectangularCyclicBC, void *data )
00205 {
00206     SurfaceMeshRectangularCyclicBC *self = NULL;
00207     
00208     assert( surfaceMeshRectangularCyclicBC );
00209 
00210     self = ( SurfaceMeshRectangularCyclicBC* ) surfaceMeshRectangularCyclicBC;
00211 
00212     if( self->createCyclicBC ){
00213         self->createCyclicBC( (void*)self, NULL );
00214     }
00215 }
00216 
00217 void SurfaceMeshRectangularCyclicBC_Destroy( void *surfaceMeshRectangularCyclicBC, void *data )
00218 {
00219     
00220 }
00221 
00222 void SurfaceMeshRectangularCyclicBC_CreateCyclicBC( _SurfaceMeshCyclicBC *surfaceMeshRectangularCyclicBC, void *data )
00223 {
00224     int i = 0, j = 0;
00225     int adjacent = 0, sum = 0;
00226     SurfaceMesh *mesh = NULL;
00227     SurfaceMeshRectangularCyclicBC *self = NULL;
00228     float tempX, tempY;
00229     float dist;
00230 
00231     assert( surfaceMeshRectangularCyclicBC );
00232     
00233     self = ( SurfaceMeshRectangularCyclicBC* ) surfaceMeshRectangularCyclicBC;
00234     mesh = self->mesh;
00235 
00236     for( i=0; i<4; i++ ){
00237         if( self->sides[i] > -1 ){
00238             sum += self->sides[i];
00239         }
00240     }
00241 
00242     if( (sum % 2) ){
00243         adjacent = 1;
00244     }
00245     else{
00246         adjacent = 0;
00247     }
00248 
00249     if( adjacent ){
00250         for( i=0; i<mesh->numNodes; i++ ){
00251             if( (mesh->boundaryConditions[i]) ){
00252                 tempX = mesh->y[i];
00253                 tempY = mesh->x[i];
00254 
00255                 for( j=0; j<mesh->numNodes; j++ ){
00256                     if( (mesh->boundaryConditions[j]) ){
00257                         dist = sqrt(pow( tempX - mesh->x[j], 2 ) + 
00258                              pow( tempY - mesh->y[j], 2 ));
00259                         
00260                         if( dist <= mesh->delta ){
00261                             mesh->nodeNeighbours[i][mesh->numNeigh[i]] = mesh->id[j];
00262                             mesh->numNeigh[i]++;
00263                         }
00264                     }
00265                 }
00266             }
00267         }
00268     }
00269 }
00270