hypre/struct_mv/struct_io.c
falgout d9fcb77306 Changed the BoxLoop macro interfaces in preparation for supporting arbitrary
dimension data (see [issue[926]).  Also added initial implementations of the new
loops and named them with the prefix 'zypre_'.  These new loops will be
optimized further before swapping them in permanently.
2012-05-18 23:47:12 +00:00

352 lines
11 KiB
C

/*BHEADER**********************************************************************
* Copyright (c) 2008, Lawrence Livermore National Security, LLC.
* Produced at the Lawrence Livermore National Laboratory.
* This file is part of HYPRE. See file COPYRIGHT for details.
*
* 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.
*
* $Revision$
***********************************************************************EHEADER*/
/******************************************************************************
*
* Functions for scanning and printing "box-dimensioned" data.
*
*****************************************************************************/
#ifdef HYPRE_USE_PTHREADS
#undef HYPRE_USE_PTHREADS
#endif
#include "_hypre_struct_mv.h"
/*--------------------------------------------------------------------------
* hypre_PrintBoxArrayData
*--------------------------------------------------------------------------*/
HYPRE_Int
hypre_PrintBoxArrayData( FILE *file,
hypre_BoxArray *box_array,
hypre_BoxArray *data_space,
HYPRE_Int num_values,
double *data )
{
hypre_Box *box;
hypre_Box *data_box;
HYPRE_Int data_box_volume;
HYPRE_Int datai;
hypre_Index loop_size;
hypre_IndexRef start;
hypre_Index stride;
hypre_Index index;
HYPRE_Int i, j;
/*----------------------------------------
* Print data
*----------------------------------------*/
hypre_SetIndex(stride, 1, 1, 1);
hypre_ForBoxI(i, box_array)
{
box = hypre_BoxArrayBox(box_array, i);
data_box = hypre_BoxArrayBox(data_space, i);
start = hypre_BoxIMin(box);
data_box_volume = hypre_BoxVolume(data_box);
hypre_BoxGetSize(box, loop_size);
hypre_BoxLoop1Begin(3, loop_size,
data_box, start, stride, datai);
hypre_BoxLoop1For(datai)
{
hypre_BoxLoopGetIndex(index);
for (j = 0; j < num_values; j++)
{
hypre_fprintf(file, "%d: (%d, %d, %d; %d) %.14e\n",
i,
hypre_IndexX(start) + hypre_IndexX(index),
hypre_IndexY(start) + hypre_IndexY(index),
hypre_IndexZ(start) + hypre_IndexZ(index),
j,
data[datai + j*data_box_volume]);
}
}
hypre_BoxLoop1End(datai);
data += num_values*data_box_volume;
}
return hypre_error_flag;
}
/*--------------------------------------------------------------------------
* hypre_PrintCCVDBoxArrayData
* Note that the the stencil loop (j) is _outside_ the space index loop (datai),
* unlie hypre_PrintBoxArrayData (there is no j loop in hypre_PrintCCBoxArrayData)
*--------------------------------------------------------------------------*/
HYPRE_Int
hypre_PrintCCVDBoxArrayData( FILE *file,
hypre_BoxArray *box_array,
hypre_BoxArray *data_space,
HYPRE_Int num_values,
HYPRE_Int center_rank,
HYPRE_Int stencil_size,
HYPRE_Int *symm_elements,
double *data )
{
hypre_Box *box;
hypre_Box *data_box;
HYPRE_Int data_box_volume, datai;
hypre_Index loop_size;
hypre_IndexRef start;
hypre_Index stride;
hypre_Index index;
HYPRE_Int i, j;
/*----------------------------------------
* Print data
*----------------------------------------*/
hypre_SetIndex(stride, 1, 1, 1);
/* First is the constant, off-diagonal, part of the matrix: */
for ( j=0; j<stencil_size; ++j )
{
if (symm_elements[j] < 0 && j!=center_rank )
{
hypre_fprintf( file, "*: (*, *, *; %d) %.14e\n",
j, data[0] );
}
++data;
}
/* Then each box has a variable, diagonal, part of the matrix: */
hypre_ForBoxI(i, box_array)
{
box = hypre_BoxArrayBox(box_array, i);
data_box = hypre_BoxArrayBox(data_space, i);
start = hypre_BoxIMin(box);
data_box_volume = hypre_BoxVolume(data_box);
hypre_BoxGetSize(box, loop_size);
hypre_BoxLoop1Begin(3, loop_size,
data_box, start, stride, datai);
hypre_BoxLoop1For(datai)
{
hypre_BoxLoopGetIndex(index);
hypre_fprintf(file, "%d: (%d, %d, %d; %d) %.14e\n",
i,
hypre_IndexX(start) + hypre_IndexX(index),
hypre_IndexY(start) + hypre_IndexY(index),
hypre_IndexZ(start) + hypre_IndexZ(index),
center_rank,
data[datai]);
}
hypre_BoxLoop1End(datai);
data += data_box_volume;
}
return hypre_error_flag;
}
/*--------------------------------------------------------------------------
* hypre_PrintCCBoxArrayData
* same as hypre_PrintBoxArrayData but for constant coefficients
*--------------------------------------------------------------------------*/
HYPRE_Int
hypre_PrintCCBoxArrayData( FILE *file,
hypre_BoxArray *box_array,
hypre_BoxArray *data_space,
HYPRE_Int num_values,
double *data )
{
hypre_Box *box;
HYPRE_Int datai;
hypre_IndexRef start;
HYPRE_Int i, j;
/*----------------------------------------
* Print data
*----------------------------------------*/
hypre_ForBoxI(i, box_array)
{
box = hypre_BoxArrayBox(box_array, i);
start = hypre_BoxIMin(box);
datai = hypre_CCBoxIndexRank_noargs();
for (j = 0; j < num_values; j++)
{
hypre_fprintf( file, "*: (*, *, *; %d) %.14e\n",
j, data[datai + j] );
}
data += num_values;
}
return hypre_error_flag;
}
/*--------------------------------------------------------------------------
* hypre_ReadBoxArrayData (for non-constant coefficients)
*--------------------------------------------------------------------------*/
HYPRE_Int
hypre_ReadBoxArrayData( FILE *file,
hypre_BoxArray *box_array,
hypre_BoxArray *data_space,
HYPRE_Int num_values,
double *data )
{
hypre_Box *box;
hypre_Box *data_box;
HYPRE_Int data_box_volume;
HYPRE_Int datai;
hypre_Index loop_size;
hypre_IndexRef start;
hypre_Index stride;
HYPRE_Int i, j, idummy;
/*----------------------------------------
* Read data
*----------------------------------------*/
hypre_SetIndex(stride, 1, 1, 1);
hypre_ForBoxI(i, box_array)
{
box = hypre_BoxArrayBox(box_array, i);
data_box = hypre_BoxArrayBox(data_space, i);
start = hypre_BoxIMin(box);
data_box_volume = hypre_BoxVolume(data_box);
hypre_BoxGetSize(box, loop_size);
hypre_BoxLoop1Begin(3, loop_size,
data_box, start, stride, datai);
hypre_BoxLoop1For(datai)
{
for (j = 0; j < num_values; j++)
{
hypre_fscanf(file, "%d: (%d, %d, %d; %d) %le\n",
&idummy,
&idummy,
&idummy,
&idummy,
&idummy,
&data[datai + j*data_box_volume]);
}
}
hypre_BoxLoop1End(datai);
data += num_values*data_box_volume;
}
return hypre_error_flag;
}
/*--------------------------------------------------------------------------
* hypre_ReadBoxArrayData_CC (for when there are some constant coefficients)
*--------------------------------------------------------------------------*/
HYPRE_Int
hypre_ReadBoxArrayData_CC( FILE *file,
hypre_BoxArray *box_array,
hypre_BoxArray *data_space,
HYPRE_Int stencil_size,
HYPRE_Int real_stencil_size,
HYPRE_Int constant_coefficient,
double *data )
{
hypre_Box *box;
hypre_Box *data_box;
HYPRE_Int data_box_volume, constant_stencil_size;
HYPRE_Int datai;
hypre_Index loop_size;
hypre_IndexRef start;
hypre_Index stride;
HYPRE_Int i, j, idummy;
/*----------------------------------------
* Read data
*----------------------------------------*/
if ( constant_coefficient==1 ) constant_stencil_size = stencil_size;
if ( constant_coefficient==2 ) constant_stencil_size = stencil_size - 1;
hypre_SetIndex(stride, 1, 1, 1);
hypre_ForBoxI(i, box_array)
{
box = hypre_BoxArrayBox(box_array, i);
data_box = hypre_BoxArrayBox(data_space, i);
start = hypre_BoxIMin(box);
data_box_volume = hypre_BoxVolume(data_box);
hypre_BoxGetSize(box, loop_size);
/* First entries will be the constant part of the matrix.
There is one entry for each constant stencil element,
excluding ones which are redundant due to symmetry.*/
for (j=0; j <constant_stencil_size; j++)
{
hypre_fscanf(file, "*: (*, *, *; %d) %le\n",
&idummy,
&data[j]);
}
/* Next entries, if any, will be for a variable diagonal: */
data += real_stencil_size;
if ( constant_coefficient==2 )
{
hypre_BoxLoop1Begin(3, loop_size,
data_box, start, stride, datai);
hypre_BoxLoop1For(datai)
{
hypre_fscanf(file, "%d: (%d, %d, %d; %d) %le\n",
&idummy,
&idummy,
&idummy,
&idummy,
&idummy,
&data[datai]);
}
hypre_BoxLoop1End(datai);
data += data_box_volume;
}
}
return hypre_error_flag;
}