hypre/struct_mv/project.c

120 lines
3.6 KiB
C
Raw Normal View History

1997-11-13 23:59:20 +08:00
/*BHEADER**********************************************************************
2008-07-18 09:34:48 +08:00
* Copyright (c) 2008, Lawrence Livermore National Security, LLC.
* Produced at the Lawrence Livermore National Laboratory.
2008-07-18 09:34:48 +08:00
* This file is part of HYPRE. See file COPYRIGHT for details.
1997-11-13 23:59:20 +08:00
*
2008-07-18 09:34:48 +08:00
* HYPRE 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) version 2.1 dated February 1999.
1997-11-13 23:59:20 +08:00
*
* $Revision$
***********************************************************************EHEADER*/
1997-11-13 23:59:20 +08:00
/******************************************************************************
*
* Projection routines.
*
*****************************************************************************/
2012-03-07 03:15:29 +08:00
#include "_hypre_struct_mv.h"
1997-11-13 23:59:20 +08:00
/*--------------------------------------------------------------------------
1998-02-18 01:56:00 +08:00
* hypre_ProjectBox:
1997-11-13 23:59:20 +08:00
* Projects a box onto a strided index space that contains the
* index `index' and has stride `stride'.
1997-11-26 04:30:53 +08:00
*
* Note: An "empty" projection is represented by a box with volume 0.
1997-11-13 23:59:20 +08:00
*--------------------------------------------------------------------------*/
HYPRE_Int
1998-02-18 01:56:00 +08:00
hypre_ProjectBox( hypre_Box *box,
hypre_Index index,
hypre_Index stride )
1997-11-13 23:59:20 +08:00
{
HYPRE_Int i, s, d, hl, hu, kl, ku, ndim = hypre_BoxNDim(box);
1997-11-13 23:59:20 +08:00
/*------------------------------------------------------
* project in all ndim dimensions
1997-11-13 23:59:20 +08:00
*------------------------------------------------------*/
for (d = 0; d < ndim; d++)
1997-11-13 23:59:20 +08:00
{
1998-02-18 01:56:00 +08:00
i = hypre_IndexD(index, d);
s = hypre_IndexD(stride, d);
1997-11-13 23:59:20 +08:00
hl = hypre_BoxIMinD(box, d) - i;
hu = hypre_BoxIMaxD(box, d) - i;
if ( hl <= 0 )
kl = (HYPRE_Int) (hl / s);
else
kl = (HYPRE_Int) ((hl + (s-1)) / s);
if ( hu >= 0 )
ku = (HYPRE_Int) (hu / s);
else
ku = (HYPRE_Int) ((hu - (s-1)) / s);
1997-11-13 23:59:20 +08:00
hypre_BoxIMinD(box, d) = i + kl * s;
hypre_BoxIMaxD(box, d) = i + ku * s;
1997-11-13 23:59:20 +08:00
}
return hypre_error_flag;
1997-11-13 23:59:20 +08:00
}
/*--------------------------------------------------------------------------
1998-02-18 01:56:00 +08:00
* hypre_ProjectBoxArray:
*
* Note: The dimensions of the modified box array are not changed.
* So, it is possible to have boxes with volume 0.
*--------------------------------------------------------------------------*/
HYPRE_Int
1998-02-18 01:56:00 +08:00
hypre_ProjectBoxArray( hypre_BoxArray *box_array,
hypre_Index index,
hypre_Index stride )
{
hypre_Box *box;
HYPRE_Int i;
1998-02-18 01:56:00 +08:00
hypre_ForBoxI(i, box_array)
{
box = hypre_BoxArrayBox(box_array, i);
hypre_ProjectBox(box, index, stride);
}
return hypre_error_flag;
}
1997-11-13 23:59:20 +08:00
/*--------------------------------------------------------------------------
1998-02-18 01:56:00 +08:00
* hypre_ProjectBoxArrayArray:
1997-11-26 04:30:53 +08:00
*
* Note: The dimensions of the modified box array-array are not changed.
* So, it is possible to have boxes with volume 0.
1997-11-13 23:59:20 +08:00
*--------------------------------------------------------------------------*/
HYPRE_Int
1998-02-18 01:56:00 +08:00
hypre_ProjectBoxArrayArray( hypre_BoxArrayArray *box_array_array,
hypre_Index index,
hypre_Index stride )
1997-11-13 23:59:20 +08:00
{
hypre_BoxArray *box_array;
hypre_Box *box;
HYPRE_Int i, j;
1997-11-13 23:59:20 +08:00
1998-02-18 01:56:00 +08:00
hypre_ForBoxArrayI(i, box_array_array)
{
box_array = hypre_BoxArrayArrayBoxArray(box_array_array, i);
hypre_ForBoxI(j, box_array)
{
box = hypre_BoxArrayBox(box_array, j);
hypre_ProjectBox(box, index, stride);
}
}
1997-11-13 23:59:20 +08:00
return hypre_error_flag;
1997-11-13 23:59:20 +08:00
}