[cig-commits] r4844 - in long/3D/Gale/trunk/src/StGermain: . Discretisation/Mesh/src

walter at geodynamics.org walter at geodynamics.org
Wed Oct 11 13:46:54 PDT 2006


Author: walter
Date: 2006-10-11 13:46:53 -0700 (Wed, 11 Oct 2006)
New Revision: 4844

Added:
   long/3D/Gale/trunk/src/StGermain/Discretisation/Mesh/src/Grid.c
   long/3D/Gale/trunk/src/StGermain/Discretisation/Mesh/src/Grid.h
   long/3D/Gale/trunk/src/StGermain/Discretisation/Mesh/src/Grid.meta
Modified:
   long/3D/Gale/trunk/src/StGermain/
Log:
 r2901 at earth:  boo | 2006-10-11 13:42:36 -0700
  r2817 at earth (orig r3805):  LukeHodkinson | 2006-09-26 20:20:35 -0700
  Adding a utility class to assist in converting
  n-dimensional grid parameterisations to array
  indices and back again.
  
 



Property changes on: long/3D/Gale/trunk/src/StGermain
___________________________________________________________________
Name: svk:merge
   - 1ef209d2-b310-0410-a72d-e20c9eb0015c:/cig:2900
afb6c753-b9d0-0310-b4e7-dbd8d91cdd35:/trunk/StGermain:3804
   + 1ef209d2-b310-0410-a72d-e20c9eb0015c:/cig:2901
afb6c753-b9d0-0310-b4e7-dbd8d91cdd35:/trunk/StGermain:3805

Added: long/3D/Gale/trunk/src/StGermain/Discretisation/Mesh/src/Grid.c
===================================================================
--- long/3D/Gale/trunk/src/StGermain/Discretisation/Mesh/src/Grid.c	2006-10-11 20:46:51 UTC (rev 4843)
+++ long/3D/Gale/trunk/src/StGermain/Discretisation/Mesh/src/Grid.c	2006-10-11 20:46:53 UTC (rev 4844)
@@ -0,0 +1,248 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+** $Id: Grid.c 3584 2006-05-16 11:11:07Z PatrickSunter $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+
+#include <mpi.h>
+#include "Base/Base.h"
+
+#include "Discretisation/Geometry/Geometry.h"
+#include "Discretisation/Shape/Shape.h"
+
+#include "types.h"
+#include "shortcuts.h"
+#include "Grid.h"
+
+
+/* Textual name of this class */
+const Type Grid_Type = "Grid";
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Constructors
+*/
+
+Grid* Grid_New() {
+	return _Grid_New( sizeof(Grid), 
+			  Grid_Type, 
+			  _Grid_Delete, 
+			  _Grid_Print, 
+			  _Grid_Copy );
+}
+
+Grid* _Grid_New( GRID_DEFARGS ) {
+	Grid* self;
+	
+	/* Allocate memory */
+	assert( sizeOfSelf >= sizeof(Grid) );
+	self = (Grid*)_Stg_Class_New( STG_CLASS_PASSARGS );
+
+	/* Virtual info */
+
+	/* Grid info */
+	_Grid_Init( self );
+
+	return self;
+}
+
+void _Grid_Init( Grid* self ) {
+	self->nDims = 0;
+	self->sizes = NULL;
+	self->basis = NULL;
+	self->nPoints = 0;
+}
+
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Virtual functions
+*/
+
+void _Grid_Delete( void* grid ) {
+	Grid*	self = (Grid*)grid;
+
+	/* Delete the parent. */
+	_Stg_Class_Delete( self );
+}
+
+void _Grid_Print( void* grid, Stream* stream ) {
+	Grid*	self = (Grid*)grid;
+	
+	/* Set the Journal for printing informations */
+	Stream* gridStream;
+	gridStream = Journal_Register( InfoStream_Type, "GridStream" );
+
+	/* Print parent */
+	Journal_Printf( stream, "Grid (ptr): (%p)\n", self );
+	_Stg_Class_Print( self, stream );
+}
+
+void* _Grid_Copy( void* grid, void* destProc_I, Bool deep, Name nameExt, PtrMap* ptrMap ) {
+#if 0
+	Grid*	self = (Grid*)grid;
+	Grid*	newGrid;
+	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;
+	}
+	
+	newGrid = (Grid*)_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*)newGrid;
+#endif
+
+	return NULL;
+}
+
+/*--------------------------------------------------------------------------------------------------------------------------
+** Public Functions
+*/
+
+void Grid_SetNDims( void* grid, unsigned nDims ) {
+	Grid*	self = (Grid*)grid;
+
+	/* Sanity check. */
+	assert( self );
+
+	/* If we're changing dimensions, kill everything and begin again. */
+	KillArray( self->sizes );
+	KillArray( self->basis );
+
+	/* Set dimensions. */
+	self->nDims = nDims;
+}
+
+void Grid_SetSizes( void* grid, unsigned* sizes ) {
+	Grid*	self = (Grid*)grid;
+
+	/* Sanity check. */
+	assert( self );
+	assert( !self->nDims || sizes );
+#ifndef NDEBUG
+	{
+		unsigned	d_i;
+
+		for( d_i = 0; d_i < self->nDims; d_i++ )
+			assert( sizes[d_i] );
+	}
+#endif
+
+	/* Copy the sizes, allocate arrays and build basis. */
+	if( self->nDims ) {
+		unsigned	d_i;
+
+		self->sizes = Memory_Alloc_Array( unsigned, self->nDims, "Grid::sizes" );
+		self->basis = Memory_Alloc_Array( unsigned, self->nDims, "Grid::basis" );
+		memcpy( self->sizes, sizes, self->nDims * sizeof(unsigned) );
+
+		/* Build basis. */
+		self->basis[0] = 1;
+		self->nPoints = sizes[0];
+		for( d_i = 1; d_i < self->nDims; d_i++ ) {
+			self->basis[d_i] = self->basis[d_i - 1] * self->sizes[d_i - 1];
+			self->nPoints *= sizes[d_i];
+		}
+	}
+}
+
+void Grid_Lift( void* grid, unsigned ind, unsigned* params ) {
+	Grid*		self = (Grid*)grid;
+	unsigned	rem;
+	unsigned	d_i;
+
+	/* Sanity check. */
+	assert( self );
+	assert( self->nDims );
+	assert( self->sizes && self->basis );
+	assert( params );
+
+	/*
+	** Take a one dimensional array index and lift it into a regular mesh topological
+	** space.
+	*/
+
+	rem = ind;
+	for( d_i = self->nDims; d_i > 0; d_i-- ) {
+		unsigned	dimInd = d_i - 1;
+		div_t		divRes;
+
+		divRes = div( rem, self->basis[dimInd] );
+		params[dimInd] = divRes.quot;
+		rem = divRes.rem;
+
+		/* Ensure this is a valid lifting. */
+		assert( params[dimInd] < self->sizes[dimInd] );
+	}
+}
+
+unsigned Grid_Project( void* grid, unsigned* params ) {
+	Grid*		self = (Grid*)grid;
+	unsigned	ind = 0;
+	unsigned	d_i;
+
+	/* Sanity check. */
+	assert( self );
+	assert( self->nDims );
+	assert( self->sizes && self->basis );
+	assert( params );
+
+	/*
+	** Project an n-dimensional set of topological indices into a one-dimensional, unique space.
+	*/
+
+	for( d_i = 0; d_i < self->nDims; d_i++ ) {
+		assert( params[d_i] < self->sizes[d_i] );
+		ind += params[d_i] * self->basis[d_i];
+	}
+
+	return ind;
+}
+
+/*----------------------------------------------------------------------------------------------------------------------------------
+** Private Functions
+*/

Added: long/3D/Gale/trunk/src/StGermain/Discretisation/Mesh/src/Grid.h
===================================================================
--- long/3D/Gale/trunk/src/StGermain/Discretisation/Mesh/src/Grid.h	2006-10-11 20:46:51 UTC (rev 4843)
+++ long/3D/Gale/trunk/src/StGermain/Discretisation/Mesh/src/Grid.h	2006-10-11 20:46:53 UTC (rev 4844)
@@ -0,0 +1,105 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+**
+** Copyright (C), 2003, Victorian Partnership for Advanced Computing (VPAC) Ltd, 110 Victoria Street, Melbourne, 3053, Australia.
+**
+** Authors:
+**	Stevan M. Quenette, Senior Software Engineer, VPAC. (steve at vpac.org)
+**	Patrick D. Sunter, Software Engineer, VPAC. (pds at vpac.org)
+**	Luke J. Hodkinson, Computational Engineer, VPAC. (lhodkins at vpac.org)
+**	Siew-Ching Tan, Software Engineer, VPAC. (siew at vpac.org)
+**	Alan H. Lo, Computational Engineer, VPAC. (alan at vpac.org)
+**	Raquibul Hassan, Computational Engineer, VPAC. (raq at vpac.org)
+**
+**  This library is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU Lesser General Public
+**  License as published by the Free Software Foundation; either
+**  version 2.1 of the License, or (at your option) any later version.
+**
+**  This library is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+**  Lesser General Public License for more details.
+**
+**  You should have received a copy of the GNU Lesser General Public
+**  License along with this library; if not, write to the Free Software
+**  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+**
+*/
+/** \file
+**  Role:
+**
+** Assumptions:
+**
+** Invariants:
+**
+** Comments:
+**
+** $Id: Grid.h 3584 2006-05-16 11:11:07Z PatrickSunter $
+**
+**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+#ifndef __Discretisaton_Mesh_Grid_h__
+#define __Discretisaton_Mesh_Grid_h__
+
+	/** Textual name of this class */
+	extern const Type Grid_Type;
+
+	/** Virtual function types */
+
+	/** Grid class contents */
+	#define __Grid			\
+		/* General info */	\
+		__Stg_Class		\
+					\
+		/* Virtual info */	\
+					\
+		/* Grid info */		\
+		unsigned	nDims;	\
+		unsigned*	sizes;	\
+		unsigned*	basis;	\
+		unsigned	nPoints;
+
+	struct Grid { __Grid };
+
+	/*--------------------------------------------------------------------------------------------------------------------------
+	** Constructors
+	*/
+
+	#define GRID_DEFARGS		\
+		STG_CLASS_DEFARGS
+
+	#define GRID_PASSARGS		\
+		STG_CLASS_PASSARGS
+
+	Grid* Grid_New();
+	Grid* _Grid_New( GRID_DEFARGS );
+	void _Grid_Init( Grid* self );
+
+	/*--------------------------------------------------------------------------------------------------------------------------
+	** Virtual functions
+	*/
+
+	void _Grid_Delete( void* grid );
+	void _Grid_Print( void* grid, Stream* stream );
+
+	#define Grid_Copy( self ) \
+		(Mesh*)Stg_Class_Copy( self, NULL, False, NULL, NULL )
+	#define Grid_DeepCopy( self ) \
+		(Mesh*)Stg_Class_Copy( self, NULL, True, NULL, NULL )
+	void* _Grid_Copy( void* grid, void* dest, Bool deep, Name nameExt, PtrMap* ptrMap );
+
+	/*--------------------------------------------------------------------------------------------------------------------------
+	** Public functions
+	*/
+
+	void Grid_SetNDims( void* grid, unsigned nDims );
+	void Grid_SetSizes( void* grid, unsigned* sizes );
+
+	void Grid_Lift( void* grid, unsigned ind, unsigned* params );
+	unsigned Grid_Project( void* grid, unsigned* params );
+
+	/*--------------------------------------------------------------------------------------------------------------------------
+	** Private Member functions
+	*/
+
+#endif /* __Discretisaton_Mesh_Grid_h__ */

Added: long/3D/Gale/trunk/src/StGermain/Discretisation/Mesh/src/Grid.meta
===================================================================
--- long/3D/Gale/trunk/src/StGermain/Discretisation/Mesh/src/Grid.meta	2006-10-11 20:46:51 UTC (rev 4843)
+++ long/3D/Gale/trunk/src/StGermain/Discretisation/Mesh/src/Grid.meta	2006-10-11 20:46:53 UTC (rev 4844)
@@ -0,0 +1,15 @@
+<?xml version="1.0"?>
+<!DOCTYPE StGermainData SYSTEM "stgermain.dtd">
+<StGermainData xmlns="http://www.vpac.org/StGermain/XML_IO_Handler/Jun2003">
+
+<param name="Name">Grid</param>
+<param name="Organisation">VPAC</param>
+<param name="Project">StGermain</param>
+<param name="Location">./StGermain/Discretisation/Mesh/src/</param>
+<param name="Project Web">https://csd.vpac.org/twiki/bin/view/Stgermain/WebHome</param>
+<param name="Copyright">StGermain Framework. Copyright (C) 2003-2005 VPAC.</param>
+<param name="License">The Gnu Lesser General Public License http://www.gnu.org/licenses/lgpl.html</param>
+<param name="Parent"></param>
+<param name="Description">...</param>
+
+</StGermainData>



More information about the cig-commits mailing list