[cig-commits] r5283 - in long/3D/Gale/trunk/src/StGermain: .
Discretisation/Mesh/src
walter at geodynamics.org
walter at geodynamics.org
Wed Nov 15 13:06:19 PST 2006
Author: walter
Date: 2006-11-15 13:06:18 -0800 (Wed, 15 Nov 2006)
New Revision: 5283
Modified:
long/3D/Gale/trunk/src/StGermain/
long/3D/Gale/trunk/src/StGermain/Discretisation/Mesh/src/CartesianGenerator.c
long/3D/Gale/trunk/src/StGermain/Discretisation/Mesh/src/SurfaceAdaptor.c
long/3D/Gale/trunk/src/StGermain/Discretisation/Mesh/src/SurfaceAdaptor.h
Log:
r3180 at earth: boo | 2006-11-15 13:05:10 -0800
r3155 at earth (orig r3889): LukeHodkinson | 2006-11-07 17:47:11 -0800
Added support for sine and cosine top surface
generation.
Property changes on: long/3D/Gale/trunk/src/StGermain
___________________________________________________________________
Name: svk:merge
- 1ef209d2-b310-0410-a72d-e20c9eb0015c:/cig:3179
afb6c753-b9d0-0310-b4e7-dbd8d91cdd35:/trunk/StGermain:3888
+ 1ef209d2-b310-0410-a72d-e20c9eb0015c:/cig:3180
afb6c753-b9d0-0310-b4e7-dbd8d91cdd35:/trunk/StGermain:3889
Modified: long/3D/Gale/trunk/src/StGermain/Discretisation/Mesh/src/CartesianGenerator.c
===================================================================
--- long/3D/Gale/trunk/src/StGermain/Discretisation/Mesh/src/CartesianGenerator.c 2006-11-15 21:06:15 UTC (rev 5282)
+++ long/3D/Gale/trunk/src/StGermain/Discretisation/Mesh/src/CartesianGenerator.c 2006-11-15 21:06:18 UTC (rev 5283)
@@ -256,8 +256,6 @@
minList = Dictionary_Get( dict, "coordMin" );
maxList = Dictionary_Get( dict, "coordMax" );
if( minList && maxList ) {
-
-
assert( Dictionary_Entry_Value_GetCount( sizeList ) == nDims );
assert( Dictionary_Entry_Value_GetCount( sizeList ) == nDims );
crdMin = Memory_Alloc_Array_Unnamed( double, nDims );
Modified: long/3D/Gale/trunk/src/StGermain/Discretisation/Mesh/src/SurfaceAdaptor.c
===================================================================
--- long/3D/Gale/trunk/src/StGermain/Discretisation/Mesh/src/SurfaceAdaptor.c 2006-11-15 21:06:15 UTC (rev 5282)
+++ long/3D/Gale/trunk/src/StGermain/Discretisation/Mesh/src/SurfaceAdaptor.c 2006-11-15 21:06:18 UTC (rev 5283)
@@ -30,6 +30,7 @@
#include <stdio.h>
#include <stdlib.h>
+#include <math.h>
#include <string.h>
#include <assert.h>
@@ -51,28 +52,33 @@
#include "SurfaceAdaptor.h"
+typedef double (SurfaceAdaptor_DeformFunc)( SurfaceAdaptor* self, Mesh* mesh,
+ unsigned* globalSize, unsigned vertex, unsigned* vertexInds );
+
+
/* Textual name of this class */
const Type SurfaceAdaptor_Type = "SurfaceAdaptor";
+
/*----------------------------------------------------------------------------------------------------------------------------------
** Constructors
*/
SurfaceAdaptor* SurfaceAdaptor_New( Name name ) {
return _SurfaceAdaptor_New( sizeof(SurfaceAdaptor),
- SurfaceAdaptor_Type,
- _SurfaceAdaptor_Delete,
- _SurfaceAdaptor_Print,
- _SurfaceAdaptor_Copy,
- (void* (*)(Name))_SurfaceAdaptor_New,
- _SurfaceAdaptor_Construct,
- _SurfaceAdaptor_Build,
- _SurfaceAdaptor_Initialise,
- _SurfaceAdaptor_Execute,
- _SurfaceAdaptor_Destroy,
- name,
- NON_GLOBAL,
- SurfaceAdaptor_Generate );
+ SurfaceAdaptor_Type,
+ _SurfaceAdaptor_Delete,
+ _SurfaceAdaptor_Print,
+ NULL,
+ (void* (*)(Name))_SurfaceAdaptor_New,
+ _SurfaceAdaptor_Construct,
+ _SurfaceAdaptor_Build,
+ _SurfaceAdaptor_Initialise,
+ _SurfaceAdaptor_Execute,
+ _SurfaceAdaptor_Destroy,
+ name,
+ NON_GLOBAL,
+ SurfaceAdaptor_Generate );
}
SurfaceAdaptor* _SurfaceAdaptor_New( SURFACEADAPTOR_DEFARGS ) {
@@ -91,6 +97,8 @@
}
void _SurfaceAdaptor_Init( SurfaceAdaptor* self ) {
+ self->surfaceType = SurfaceAdaptor_SurfaceType_Invalid;
+ memset( &self->info, 0, sizeof(SurfaceAdaptor_SurfaceInfo) );
}
@@ -117,43 +125,10 @@
_MeshGenerator_Print( self, stream );
}
-void* _SurfaceAdaptor_Copy( void* adaptor, void* destProc_I, Bool deep, Name nameExt, PtrMap* ptrMap ) {
-#if 0
- SurfaceAdaptor* self = (SurfaceAdaptor*)adaptor;
- SurfaceAdaptor* newSurfaceAdaptor;
- PtrMap* map = ptrMap;
- Bool ownMap = False;
-
- /* Damn me for making copying so difficult... what was I thinking? */
-
- /* We need to create a map if it doesn't already exist. */
- if( !map ) {
- map = PtrMap_New( 10 );
- ownMap = True;
- }
-
- newSurfaceAdaptor = (SurfaceAdaptor*)_Mesh_Copy( self, destProc_I, deep, nameExt, map );
-
- /* Copy the virtual methods here. */
-
- /* Deep or shallow? */
- if( deep ) {
- }
- else {
- }
-
- /* If we own the map, get rid of it here. */
- if( ownMap ) Stg_Class_Delete( map );
-
- return (void*)newSurfaceAdaptor;
-#endif
-
- return NULL;
-}
-
void _SurfaceAdaptor_Construct( void* adaptor, Stg_ComponentFactory* cf, void* data ) {
SurfaceAdaptor* self = (SurfaceAdaptor*)adaptor;
-
+ Dictionary* dict;
+ char* surfaceType;
assert( self );
assert( cf );
@@ -161,9 +136,45 @@
/* Call parent construct. */
_MeshAdaptor_Construct( self, cf, data );
- /* Read the parameters. */
- self->offs = Stg_ComponentFactory_GetDouble( cf, self->name, "offset", 0.0 );
- self->grad = Stg_ComponentFactory_GetDouble( cf, self->name, "gradient", 0.5 );
+ /* Rip out the components structure as a dictionary. */
+ dict = Dictionary_Entry_Value_AsDictionary( Dictionary_Get( cf->componentDict, self->name ) );
+
+ /* What kind of surface do we want? */
+ surfaceType = Stg_ComponentFactory_GetString( cf, self->name, "surfaceType", "" );
+ if( !strcmp( surfaceType, "wedge" ) ) {
+ self->surfaceType = SurfaceAdaptor_SurfaceType_Wedge;
+ self->info.wedge.offs = Stg_ComponentFactory_GetDouble( cf, self->name, "offset", 0.0 );
+ self->info.wedge.grad = Stg_ComponentFactory_GetDouble( cf, self->name, "gradient", 0.5 );
+ }
+ else if( !strcmp( surfaceType, "sine" ) || !strcmp( surfaceType, "cosine" ) ) {
+ Dictionary_Entry_Value* originList;
+
+ if( !strcmp( surfaceType, "sine" ) )
+ self->surfaceType = SurfaceAdaptor_SurfaceType_Sine;
+ else
+ self->surfaceType = SurfaceAdaptor_SurfaceType_Cosine;
+
+ originList = Dictionary_Get( dict, "origin" );
+ if( originList ) {
+ unsigned nDims;
+ unsigned d_i;
+
+ nDims = Dictionary_Entry_Value_GetCount( originList );
+ for( d_i = 0; d_i < nDims; d_i++ ) {
+ Dictionary_Entry_Value* val;
+
+ val = Dictionary_Entry_Value_GetElement( originList, d_i );
+ self->info.trig.origin[d_i] = Dictionary_Entry_Value_AsDouble( val );
+ }
+ }
+ else
+ memset( self->info.trig.origin, 0, sizeof(double) * 2 );
+
+ self->info.trig.amp = Stg_ComponentFactory_GetDouble( cf, self->name, "amplitude", 1.0 );
+ self->info.trig.freq = Stg_ComponentFactory_GetDouble( cf, self->name, "frequency", 1.0 );
+ }
+ else
+ _SurfaceAdaptor_Init( self );
}
void _SurfaceAdaptor_Build( void* adaptor, void* data ) {
@@ -171,6 +182,7 @@
}
void _SurfaceAdaptor_Initialise( void* adaptor, void* data ) {
+ _MeshAdaptor_Initialise( adaptor, data );
}
void _SurfaceAdaptor_Execute( void* adaptor, void* data ) {
@@ -184,12 +196,13 @@
*/
void SurfaceAdaptor_Generate( void* adaptor, void* _mesh ) {
- SurfaceAdaptor* self = (SurfaceAdaptor*)adaptor;
- Mesh* mesh = (Mesh*)_mesh;
- unsigned* gSize;
- Grid* grid;
- unsigned* inds;
- unsigned d_i, n_i;
+ SurfaceAdaptor* self = (SurfaceAdaptor*)adaptor;
+ Mesh* mesh = (Mesh*)_mesh;
+ SurfaceAdaptor_DeformFunc* deformFunc;
+ unsigned* gSize;
+ Grid* grid;
+ unsigned* inds;
+ unsigned d_i, n_i;
/* Build base mesh, which is assumed to be cartesian. */
MeshGenerator_Generate( self->generator, mesh );
@@ -198,6 +211,21 @@
if( mesh->topo->nDims != 2 && mesh->topo->nDims != 3 )
return;
+ /* What kind of surface do we want? */
+ switch( self->surfaceType ) {
+ case SurfaceAdaptor_SurfaceType_Wedge:
+ deformFunc = SurfaceAdaptor_Wedge;
+ break;
+ case SurfaceAdaptor_SurfaceType_Sine:
+ deformFunc = SurfaceAdaptor_Sine;
+ break;
+ case SurfaceAdaptor_SurfaceType_Cosine:
+ deformFunc = SurfaceAdaptor_Cosine;
+ break;
+ default:
+ break;
+ };
+
/* Extract the cartesian information. */
gSize = (unsigned*)ExtensionManager_Get( mesh->info, mesh,
ExtensionManager_GetHandle( mesh->info, "cartesianGlobalSize" ) );
@@ -224,8 +252,7 @@
height = (double)inds[1] / (double)(gSize[1] - 1);
/* Deform this node. */
- if( mesh->nodeCoord[n_i][0] >= self->offs )
- mesh->nodeCoord[n_i][1] += height * (mesh->nodeCoord[n_i][0] - self->offs) * self->grad;
+ mesh->nodeCoord[n_i][1] += height * deformFunc( self, mesh, gSize, n_i, inds );
}
/* Free resources. */
@@ -233,6 +260,50 @@
FreeObject( grid );
}
+
/*----------------------------------------------------------------------------------------------------------------------------------
** Private Functions
*/
+
+double SurfaceAdaptor_Wedge( SurfaceAdaptor* self, Mesh* mesh,
+ unsigned* globalSize, unsigned vertex, unsigned* vertexInds )
+{
+ if( mesh->nodeCoord[vertex][0] >= self->info.wedge.offs )
+ return (mesh->nodeCoord[vertex][0] - self->info.wedge.offs) * self->info.wedge.grad;
+ else
+ return 0.0;
+}
+
+double SurfaceAdaptor_Sine( SurfaceAdaptor* self, Mesh* mesh,
+ unsigned* globalSize, unsigned vertex, unsigned* vertexInds )
+{
+ double dx, dy;
+ double rad;
+
+ dx = mesh->nodeCoord[vertex][0] - self->info.trig.origin[0];
+ rad = dx * dx;
+ if( mesh->topo->nDims == 3 ) {
+ dy = mesh->nodeCoord[vertex][1] - self->info.trig.origin[1];
+ rad += dy * dy;
+ }
+ rad = sqrt( rad );
+
+ return self->info.trig.amp * sin( self->info.trig.freq * rad );
+}
+
+double SurfaceAdaptor_Cosine( SurfaceAdaptor* self, Mesh* mesh,
+ unsigned* globalSize, unsigned vertex, unsigned* vertexInds )
+{
+ double dx, dy;
+ double rad;
+
+ dx = mesh->nodeCoord[vertex][0] - self->info.trig.origin[0];
+ rad = dx * dx;
+ if( mesh->topo->nDims == 3 ) {
+ dy = mesh->nodeCoord[vertex][1] - self->info.trig.origin[1];
+ rad += dy * dy;
+ }
+ rad = sqrt( rad );
+
+ return self->info.trig.amp * cos( self->info.trig.freq * rad );
+}
Modified: long/3D/Gale/trunk/src/StGermain/Discretisation/Mesh/src/SurfaceAdaptor.h
===================================================================
--- long/3D/Gale/trunk/src/StGermain/Discretisation/Mesh/src/SurfaceAdaptor.h 2006-11-15 21:06:15 UTC (rev 5282)
+++ long/3D/Gale/trunk/src/StGermain/Discretisation/Mesh/src/SurfaceAdaptor.h 2006-11-15 21:06:18 UTC (rev 5283)
@@ -47,16 +47,39 @@
/** Virtual function types */
/** SurfaceAdaptor class contents */
- #define __SurfaceAdaptor \
- /* General info */ \
- __MeshAdaptor \
- \
- /* Virtual info */ \
- \
- /* SurfaceAdaptor info */ \
- double offs; \
- double grad;
+ typedef enum {
+ SurfaceAdaptor_SurfaceType_Wedge,
+ SurfaceAdaptor_SurfaceType_Sine,
+ SurfaceAdaptor_SurfaceType_Cosine,
+ SurfaceAdaptor_SurfaceType_Invalid
+ } SurfaceAdaptor_SurfaceType;
+ typedef struct {
+ double offs;
+ double grad;
+ } SurfaceAdaptor_WedgeInfo;
+
+ typedef struct {
+ double origin[2];
+ double amp;
+ double freq;
+ } SurfaceAdaptor_TrigInfo;
+
+ typedef union {
+ SurfaceAdaptor_WedgeInfo wedge;
+ SurfaceAdaptor_TrigInfo trig;
+ } SurfaceAdaptor_SurfaceInfo;
+
+ #define __SurfaceAdaptor \
+ /* General info */ \
+ __MeshAdaptor \
+ \
+ /* Virtual info */ \
+ \
+ /* SurfaceAdaptor info */ \
+ SurfaceAdaptor_SurfaceType surfaceType; \
+ SurfaceAdaptor_SurfaceInfo info;
+
struct SurfaceAdaptor { __SurfaceAdaptor };
/*--------------------------------------------------------------------------------------------------------------------------
@@ -79,13 +102,6 @@
void _SurfaceAdaptor_Delete( void* adaptor );
void _SurfaceAdaptor_Print( void* adaptor, Stream* stream );
-
- #define SurfaceAdaptor_Copy( self ) \
- (Mesh*)Stg_Class_Copy( self, NULL, False, NULL, NULL )
- #define SurfaceAdaptor_DeepCopy( self ) \
- (Mesh*)Stg_Class_Copy( self, NULL, True, NULL, NULL )
- void* _SurfaceAdaptor_Copy( void* adaptor, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap );
-
void _SurfaceAdaptor_Construct( void* adaptor, Stg_ComponentFactory* cf, void* data );
void _SurfaceAdaptor_Build( void* adaptor, void* data );
void _SurfaceAdaptor_Initialise( void* adaptor, void* data );
@@ -102,4 +118,11 @@
** Private Member functions
*/
+ double SurfaceAdaptor_Wedge( SurfaceAdaptor* self, Mesh* mesh,
+ unsigned* globalSize, unsigned vertex, unsigned* vertexInds );
+ double SurfaceAdaptor_Sine( SurfaceAdaptor* self, Mesh* mesh,
+ unsigned* globalSize, unsigned vertex, unsigned* vertexInds );
+ double SurfaceAdaptor_Cosine( SurfaceAdaptor* self, Mesh* mesh,
+ unsigned* globalSize, unsigned vertex, unsigned* vertexInds );
+
#endif /* __Discretisaton_Mesh_SurfaceAdaptor_h__ */
More information about the cig-commits
mailing list