00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00030 #include <mpi.h>
00031 #include <StGermain/StGermain.h>
00032 #include <Cascade/cascade.h>
00033
00034
00035 #include "types.h"
00036 #include "SurfaceMesh.h"
00037
00038 #include <stdio.h>
00039 #include <stdlib.h>
00040 #include <string.h>
00041 #include <assert.h>
00042 #include <math.h>
00043 #include "Catchment.h"
00044 #include "SurfaceMesh.h"
00045 #include "Context.h"
00046 #include "SurfaceMeshSmoother.h"
00047
00048
00049
00050 const Type SurfaceMeshSmoother_Type = "SurfaceMeshSmoother";
00051
00052 SurfaceMeshSmoother *SurfaceMeshSmoother_DefaultNew( Name name )
00053 {
00054 return _SurfaceMeshSmoother_New( sizeof( SurfaceMeshSmoother ),
00055 SurfaceMeshSmoother_Type,
00056 _SurfaceMeshSmoother_Delete,
00057 _SurfaceMeshSmoother_Print,
00058 NULL,
00059 (void*)SurfaceMeshSmoother_DefaultNew,
00060 _SurfaceMeshSmoother_Construct,
00061 _SurfaceMeshSmoother_Build,
00062 _SurfaceMeshSmoother_Initialise,
00063 _SurfaceMeshSmoother_Execute,
00064 _SurfaceMeshSmoother_Destroy,
00065 name,
00066 False,
00067 NULL );
00068
00069 }
00070
00071 SurfaceMeshSmoother *SurfaceMeshSmoother_New( Name name, Dictionary *dictionary )
00072 {
00073 return _SurfaceMeshSmoother_New( sizeof( SurfaceMeshSmoother ),
00074 SurfaceMeshSmoother_Type,
00075 _SurfaceMeshSmoother_Delete,
00076 _SurfaceMeshSmoother_Print,
00077 NULL,
00078 (void*)SurfaceMeshSmoother_DefaultNew,
00079 _SurfaceMeshSmoother_Construct,
00080 _SurfaceMeshSmoother_Build,
00081 _SurfaceMeshSmoother_Initialise,
00082 _SurfaceMeshSmoother_Execute,
00083 _SurfaceMeshSmoother_Destroy,
00084 name,
00085 True,
00086 dictionary );
00087
00088 }
00089
00090 SurfaceMeshSmoother *_SurfaceMeshSmoother_New( SizeT _sizeOfSelf,
00091 Type type,
00092 Stg_Class_DeleteFunction* _delete,
00093 Stg_Class_PrintFunction* _print,
00094 Stg_Class_CopyFunction* _copy,
00095 Stg_Component_DefaultConstructorFunction* _defaultConstructor,
00096 Stg_Component_ConstructFunction* _construct,
00097 Stg_Component_BuildFunction* _build,
00098 Stg_Component_InitialiseFunction* _initialise,
00099 Stg_Component_ExecuteFunction* _execute,
00100 Stg_Component_DestroyFunction* _destroy,
00101 Name name,
00102 Bool initFlag,
00103 Dictionary *dictionary )
00104 {
00105 SurfaceMeshSmoother* self;
00106
00107
00108 assert( _sizeOfSelf >= sizeof(SurfaceMeshSmoother) );
00109 self = (SurfaceMeshSmoother*)_Stg_Component_New( _sizeOfSelf, type, _delete, _print, _copy, _defaultConstructor, _construct, _build,
00110 _initialise, _execute, _destroy, name, NON_GLOBAL );
00111
00112 self->dictionary = dictionary;
00113
00114 if( initFlag ){
00115 _SurfaceMeshSmoother_Init( self );
00116 }
00117
00118 return self;
00119
00120 }
00121
00122 void _SurfaceMeshSmoother_Init( SurfaceMeshSmoother *self )
00123 {
00124
00125 }
00126
00127 void _SurfaceMeshSmoother_Print( void *surfaceMeshSmoother, Stream *stream )
00128 {
00129
00130 SurfaceMeshSmoother *self = (SurfaceMeshSmoother*) surfaceMeshSmoother;
00131
00132 assert( self );
00133 assert( stream );
00134
00135
00136 _Stg_Component_Print( (void*) self, stream );
00137
00138
00139 Journal_Printf( stream, "SurfaceMeshSmoother (ptr): (%p)\n", self );
00140
00141
00142
00143
00144 }
00145
00146 void _SurfaceMeshSmoother_Delete( void *surfaceMeshSmoother )
00147 {
00148 SurfaceMeshSmoother *self = (SurfaceMeshSmoother*) surfaceMeshSmoother;
00149
00150 assert( self );
00151
00152 _Stg_Component_Delete( self );
00153
00154 }
00155
00156 void _SurfaceMeshSmoother_Construct( void *surfaceMeshSmoother, Stg_ComponentFactory *cf )
00157 {
00158
00159 }
00160
00161 void _SurfaceMeshSmoother_Build( void *surfaceMeshSmoother, void *data )
00162 {
00163
00164 }
00165
00166 void _SurfaceMeshSmoother_Initialise( void *surfaceMeshSmoother, void *data )
00167 {
00168
00169 }
00170
00171 void _SurfaceMeshSmoother_Destroy( void *surfaceMeshSmoother, void *data )
00172 {
00173
00174 }
00175
00176
00177 void _SurfaceMeshSmoother_Execute( void *meshSmoother, void *surfaceMesh )
00178 {
00179 typedef struct vector_t{
00180 float x;
00181 float y;
00182 }
00183 vector;
00184
00185 int i, j, iter;
00186 vector ab;
00187 int neighNode;
00188 SurfaceMeshSmoother *surfaceMeshSmoother = NULL;
00189 SurfaceMesh *mesh = NULL;
00190
00191 surfaceMeshSmoother = (SurfaceMeshSmoother*)meshSmoother;
00192 mesh = (SurfaceMesh*)surfaceMesh;
00193
00194 assert( surfaceMeshSmoother );
00195 assert( mesh );
00196
00197
00198 if( mesh->rank != 0 ){
00199 return;
00200 }
00201
00202 for( iter=0; iter<50; iter++ ){
00203 for( i=0; i<mesh->numNodes; i++ ){
00204 memset( &ab, 0, sizeof(vector) );
00205 if( mesh->boundaryConditions[i] ){
00206 for( j=0; j<mesh->numNeigh[i]; j++ ){
00207 neighNode = mesh->id[mesh->nodeNeighbours[i][j]-1];
00208 ab.x += mesh->x[neighNode-1] - mesh->x[i];
00209 ab.y += mesh->y[neighNode-1] - mesh->y[i];
00210 }
00211
00212 ab.x = ab.x * 0.05 / (j-1);
00213 ab.y = ab.y * 0.05 / (j-1);
00214
00215 mesh->x[i] += ab.x;
00216 mesh->y[i] += ab.y;
00217 }
00218 else{
00219
00220 }
00221 }
00222 }
00223 }
00224