hypre/struct_mv/box.c

398 lines
10 KiB
C
Raw Normal View History

1997-11-13 23:59:20 +08:00
/*BHEADER**********************************************************************
* (c) 1997 The Regents of the University of California
*
* See the file COPYRIGHT_and_DISCLAIMER for a complete copyright
* notice, contact person, and disclaimer.
*
* $Revision$
*********************************************************************EHEADER*/
/******************************************************************************
*
1998-02-18 01:56:00 +08:00
* Member functions for hypre_Box class:
1997-11-13 23:59:20 +08:00
* Basic class functions.
*
*****************************************************************************/
#include "headers.h"
/*--------------------------------------------------------------------------
* hypre_BoxCreate
1997-11-13 23:59:20 +08:00
*--------------------------------------------------------------------------*/
1998-02-18 01:56:00 +08:00
hypre_Box *
hypre_BoxCreate( )
1997-11-13 23:59:20 +08:00
{
1998-02-18 01:56:00 +08:00
hypre_Box *box;
1997-11-13 23:59:20 +08:00
1999-01-05 05:06:34 +08:00
#if 1
box = hypre_TAlloc(hypre_Box, 1);
#else
1998-06-30 07:09:37 +08:00
box = hypre_BoxAlloc();
#endif
1997-11-13 23:59:20 +08:00
return box;
}
/*--------------------------------------------------------------------------
* hypre_BoxSetExtents
*--------------------------------------------------------------------------*/
int
hypre_BoxSetExtents( hypre_Box *box,
hypre_Index imin,
hypre_Index imax )
{
int ierr = 0;
hypre_CopyIndex(imin, hypre_BoxIMin(box));
hypre_CopyIndex(imax, hypre_BoxIMax(box));
return ierr;
}
1997-11-13 23:59:20 +08:00
/*--------------------------------------------------------------------------
* hypre_BoxArrayCreate
1997-11-13 23:59:20 +08:00
*--------------------------------------------------------------------------*/
1998-02-18 01:56:00 +08:00
hypre_BoxArray *
hypre_BoxArrayCreate( int size )
1997-11-13 23:59:20 +08:00
{
1998-02-18 01:56:00 +08:00
hypre_BoxArray *box_array;
1997-11-13 23:59:20 +08:00
1998-02-18 01:56:00 +08:00
box_array = hypre_TAlloc(hypre_BoxArray, 1);
1997-11-13 23:59:20 +08:00
hypre_BoxArrayBoxes(box_array) = hypre_CTAlloc(hypre_Box, size);
hypre_BoxArraySize(box_array) = size;
hypre_BoxArrayAllocSize(box_array) = size;
1997-11-13 23:59:20 +08:00
return box_array;
}
/*--------------------------------------------------------------------------
* hypre_BoxArraySetSize
*--------------------------------------------------------------------------*/
int
hypre_BoxArraySetSize( hypre_BoxArray *box_array,
int size )
{
int ierr = 0;
int alloc_size;
alloc_size = hypre_BoxArrayAllocSize(box_array);
if (size > alloc_size)
{
alloc_size = size + hypre_BoxArrayExcess;
hypre_BoxArrayBoxes(box_array) =
hypre_TReAlloc(hypre_BoxArrayBoxes(box_array),
hypre_Box, alloc_size);
hypre_BoxArrayAllocSize(box_array) = alloc_size;
}
hypre_BoxArraySize(box_array) = size;
return ierr;
}
1997-11-13 23:59:20 +08:00
/*--------------------------------------------------------------------------
* hypre_BoxArrayArrayCreate
1997-11-13 23:59:20 +08:00
*--------------------------------------------------------------------------*/
1998-02-18 01:56:00 +08:00
hypre_BoxArrayArray *
hypre_BoxArrayArrayCreate( int size )
1997-11-13 23:59:20 +08:00
{
1998-02-18 01:56:00 +08:00
hypre_BoxArrayArray *box_array_array;
int i;
1997-11-13 23:59:20 +08:00
1998-02-18 01:56:00 +08:00
box_array_array = hypre_CTAlloc(hypre_BoxArrayArray, 1);
1997-11-13 23:59:20 +08:00
1998-02-18 01:56:00 +08:00
hypre_BoxArrayArrayBoxArrays(box_array_array) =
hypre_CTAlloc(hypre_BoxArray *, size);
1997-11-13 23:59:20 +08:00
for (i = 0; i < size; i++)
{
hypre_BoxArrayArrayBoxArray(box_array_array, i) = hypre_BoxArrayCreate(0);
}
1998-02-18 01:56:00 +08:00
hypre_BoxArrayArraySize(box_array_array) = size;
1997-11-13 23:59:20 +08:00
return box_array_array;
}
/*--------------------------------------------------------------------------
* hypre_BoxDestroy
1997-11-13 23:59:20 +08:00
*--------------------------------------------------------------------------*/
int
hypre_BoxDestroy( hypre_Box *box )
1997-11-13 23:59:20 +08:00
{
int ierr = 0;
1997-11-26 04:30:53 +08:00
if (box)
{
1999-01-05 05:06:34 +08:00
#if 1
hypre_TFree(box);
#else
1998-06-30 07:09:37 +08:00
hypre_BoxFree(box);
#endif
1997-11-26 04:30:53 +08:00
}
return ierr;
1997-11-26 04:30:53 +08:00
}
1997-11-13 23:59:20 +08:00
/*--------------------------------------------------------------------------
* hypre_BoxArrayDestroy
1997-11-13 23:59:20 +08:00
*--------------------------------------------------------------------------*/
int
hypre_BoxArrayDestroy( hypre_BoxArray *box_array )
1997-11-13 23:59:20 +08:00
{
int ierr = 0;
1997-11-13 23:59:20 +08:00
1997-11-26 04:30:53 +08:00
if (box_array)
1997-11-13 23:59:20 +08:00
{
hypre_TFree(hypre_BoxArrayBoxes(box_array));
hypre_TFree(box_array);
1997-11-26 04:30:53 +08:00
}
return ierr;
1997-11-13 23:59:20 +08:00
}
/*--------------------------------------------------------------------------
* hypre_BoxArrayArrayDestroy
1997-11-13 23:59:20 +08:00
*--------------------------------------------------------------------------*/
int
hypre_BoxArrayArrayDestroy( hypre_BoxArrayArray *box_array_array )
1997-11-13 23:59:20 +08:00
{
int ierr = 0;
1997-11-13 23:59:20 +08:00
int i;
1997-11-26 04:30:53 +08:00
if (box_array_array)
{
1998-02-18 01:56:00 +08:00
hypre_ForBoxArrayI(i, box_array_array)
hypre_BoxArrayDestroy(
hypre_BoxArrayArrayBoxArray(box_array_array, i));
1997-11-13 23:59:20 +08:00
hypre_TFree(hypre_BoxArrayArrayBoxArrays(box_array_array));
hypre_TFree(box_array_array);
1997-11-26 04:30:53 +08:00
}
return ierr;
1997-11-13 23:59:20 +08:00
}
/*--------------------------------------------------------------------------
* hypre_BoxDuplicate:
1997-11-13 23:59:20 +08:00
* Return a duplicate box.
*--------------------------------------------------------------------------*/
1998-02-18 01:56:00 +08:00
hypre_Box *
hypre_BoxDuplicate( hypre_Box *box )
1997-11-13 23:59:20 +08:00
{
hypre_Box *new_box;
1997-11-13 23:59:20 +08:00
new_box = hypre_BoxCreate();
hypre_CopyBox(box, new_box);
1997-11-13 23:59:20 +08:00
return new_box;
}
/*--------------------------------------------------------------------------
* hypre_BoxArrayDuplicate:
1997-11-13 23:59:20 +08:00
* Return a duplicate box_array.
*--------------------------------------------------------------------------*/
1998-02-18 01:56:00 +08:00
hypre_BoxArray *
hypre_BoxArrayDuplicate( hypre_BoxArray *box_array )
1997-11-13 23:59:20 +08:00
{
1998-02-18 01:56:00 +08:00
hypre_BoxArray *new_box_array;
1997-11-13 23:59:20 +08:00
int i;
1997-11-13 23:59:20 +08:00
new_box_array = hypre_BoxArrayCreate(hypre_BoxArraySize(box_array));
hypre_ForBoxI(i, box_array)
{
hypre_CopyBox(hypre_BoxArrayBox(box_array, i),
hypre_BoxArrayBox(new_box_array, i));
}
1997-11-13 23:59:20 +08:00
return new_box_array;
}
/*--------------------------------------------------------------------------
* hypre_BoxArrayArrayDuplicate:
1997-11-13 23:59:20 +08:00
* Return a duplicate box_array_array.
*--------------------------------------------------------------------------*/
1998-02-18 01:56:00 +08:00
hypre_BoxArrayArray *
hypre_BoxArrayArrayDuplicate( hypre_BoxArrayArray *box_array_array )
1997-11-13 23:59:20 +08:00
{
1998-02-18 01:56:00 +08:00
hypre_BoxArrayArray *new_box_array_array;
hypre_BoxArray **new_box_arrays;
int new_size;
1997-11-13 23:59:20 +08:00
1998-02-18 01:56:00 +08:00
hypre_BoxArray **box_arrays;
int i;
1997-11-13 23:59:20 +08:00
1998-02-18 01:56:00 +08:00
new_size = hypre_BoxArrayArraySize(box_array_array);
new_box_array_array = hypre_BoxArrayArrayCreate(new_size);
1997-11-13 23:59:20 +08:00
if (new_size)
{
1998-02-18 01:56:00 +08:00
new_box_arrays = hypre_BoxArrayArrayBoxArrays(new_box_array_array);
box_arrays = hypre_BoxArrayArrayBoxArrays(box_array_array);
1997-11-13 23:59:20 +08:00
for (i = 0; i < new_size; i++)
{
hypre_AppendBoxArray(box_arrays[i], new_box_arrays[i]);
1997-11-13 23:59:20 +08:00
}
}
return new_box_array_array;
}
/*--------------------------------------------------------------------------
1998-02-18 01:56:00 +08:00
* hypre_AppendBox:
1997-11-13 23:59:20 +08:00
* Append box to the end of box_array.
* The box_array may be empty.
*--------------------------------------------------------------------------*/
int
1998-02-18 01:56:00 +08:00
hypre_AppendBox( hypre_Box *box,
hypre_BoxArray *box_array )
1997-11-13 23:59:20 +08:00
{
int ierr = 0;
int size;
size = hypre_BoxArraySize(box_array);
hypre_BoxArraySetSize(box_array, (size + 1));
hypre_CopyBox(box, hypre_BoxArrayBox(box_array, size));
return ierr;
1997-11-13 23:59:20 +08:00
}
/*--------------------------------------------------------------------------
1998-02-18 01:56:00 +08:00
* hypre_DeleteBox:
1997-11-13 23:59:20 +08:00
* Delete box from box_array.
*--------------------------------------------------------------------------*/
int
1998-02-18 01:56:00 +08:00
hypre_DeleteBox( hypre_BoxArray *box_array,
int index )
1997-11-13 23:59:20 +08:00
{
int ierr = 0;
int i;
1997-11-13 23:59:20 +08:00
1998-02-18 01:56:00 +08:00
for (i = index; i < hypre_BoxArraySize(box_array) - 1; i++)
{
hypre_CopyBox(hypre_BoxArrayBox(box_array, i+1),
hypre_BoxArrayBox(box_array, i));
}
1997-11-13 23:59:20 +08:00
1998-02-18 01:56:00 +08:00
hypre_BoxArraySize(box_array) --;
return ierr;
1997-11-13 23:59:20 +08:00
}
/*--------------------------------------------------------------------------
1998-02-18 01:56:00 +08:00
* hypre_AppendBoxArray:
1997-11-13 23:59:20 +08:00
* Append box_array_0 to the end of box_array_1.
* The box_array_1 may be empty.
*--------------------------------------------------------------------------*/
int
1998-02-18 01:56:00 +08:00
hypre_AppendBoxArray( hypre_BoxArray *box_array_0,
hypre_BoxArray *box_array_1 )
1997-11-13 23:59:20 +08:00
{
int ierr = 0;
int size, size_0;
1997-11-13 23:59:20 +08:00
int i;
size = hypre_BoxArraySize(box_array_1);
size_0 = hypre_BoxArraySize(box_array_0);
hypre_BoxArraySetSize(box_array_1, (size + size_0));
1997-11-13 23:59:20 +08:00
/* copy box_array_0 boxes into box_array_1 */
for (i = 0; i < size_0; i++)
{
hypre_CopyBox(hypre_BoxArrayBox(box_array_0, i),
hypre_BoxArrayBox(box_array_1, size + i));
}
return ierr;
1997-11-13 23:59:20 +08:00
}
1997-12-20 00:59:03 +08:00
/*--------------------------------------------------------------------------
* hypre_BoxGetSize:
1997-12-20 00:59:03 +08:00
*--------------------------------------------------------------------------*/
int
hypre_BoxGetSize( hypre_Box *box,
hypre_Index size )
1997-12-20 00:59:03 +08:00
{
hypre_IndexD(size, 0) = hypre_BoxSizeD(box, 0);
hypre_IndexD(size, 1) = hypre_BoxSizeD(box, 1);
hypre_IndexD(size, 2) = hypre_BoxSizeD(box, 2);
return 0;
}
/*--------------------------------------------------------------------------
* hypre_BoxGetStrideSize:
*--------------------------------------------------------------------------*/
int
hypre_BoxGetStrideSize( hypre_Box *box,
hypre_Index stride,
hypre_Index size )
{
int d, s;
for (d = 0; d < 3; d++)
{
s = hypre_BoxSizeD(box, d);
if (s > 0)
{
s = (s - 1) / hypre_IndexD(stride, d) + 1;
}
hypre_IndexD(size, d) = s;
}
1997-12-20 00:59:03 +08:00
return 0;
}
/*--------------------------------------------------------------------------
* GEC0209 function to expand a box given a ghostvector numexp
* the idea is to dilatate the box using two vectors.
*
* even components of numexp shift negatively the imin of the box
* odd components of numexp shift positively the imax of the box
*
*
*--------------------------------------------------------------------------*/
int
hypre_BoxExpand( hypre_Box *box,
int *numexp)
{
int ierr = 0;
int *imin = hypre_BoxIMin(box);
int *imax = hypre_BoxIMax(box);
int d;
for (d = 0; d < 3; d++)
{
imin[d] -= numexp[2*d];
imax[d] += numexp[2*d+1];
}
return ierr;
}
1999-06-05 05:55:21 +08:00