Commit d5bfe7c2 authored by hrchilds's avatar hrchilds
Browse files

Update from January 20, 2005

git-svn-id: http://visit.ilight.com/svn/visit/trunk/src@400 18c085ea-50e0-402c-830e-de6fd14e8384
parent 1dd9f53d
......@@ -702,6 +702,9 @@ avtDatabase::GetNewMetaData(int timeState)
// Hank Childs, Thu Jul 29 09:30:43 PDT 2004
// Do not add MQE for nodes or edges.
//
// Hank Childs, Thu Jan 20 15:47:25 PST 2005
// Added side volume.
//
// ****************************************************************************
void
......@@ -730,7 +733,7 @@ avtDatabase::AddMeshQualityExpressions(avtDatabaseMetaData *md)
if (topoDim == 0 || topoDim == 1)
continue;
const int nPairs = 20;
const int nPairs = 21;
MQExprTopoPair exprs[nPairs];
exprs[0] = MQExprTopoPair("area", 2);
exprs[1] = MQExprTopoPair("aspect_gamma", 3);
......@@ -751,7 +754,8 @@ avtDatabase::AddMeshQualityExpressions(avtDatabaseMetaData *md)
exprs[16] = MQExprTopoPair("stretch", -1);
exprs[17] = MQExprTopoPair("taper", -1);
exprs[18] = MQExprTopoPair("volume", 3);
exprs[19] = MQExprTopoPair("warpage", 2);
exprs[19] = MQExprTopoPair("side_volume", 3);
exprs[20] = MQExprTopoPair("warpage", 2);
string name = mmd->name;
for (int i = 0 ; i < nPairs ; i++)
......
......@@ -88,6 +88,9 @@ avtBinaryMathFilter::~avtBinaryMathFilter()
// Hank Childs, Thu Apr 22 11:11:33 PDT 2004
// When the centerings are different, always use zonal.
//
// Hank Childs, Thu Jan 20 17:32:13 PST 2005
// Make cur_mesh accessible to derived types.
//
// ****************************************************************************
vtkDataArray *
......@@ -162,7 +165,9 @@ avtBinaryMathFilter::DeriveVariable(vtkDataSet *in_ds)
dv->SetNumberOfComponents(ncomps);
dv->SetNumberOfTuples(nvals);
cur_mesh = in_ds;
DoOperation(data1, data2, dv, ncomps, nvals);
cur_mesh = NULL;
if (GetOutput()->GetInfo().GetAttributes().GetVariableDimension()
!= ncomps)
......
......@@ -29,6 +29,10 @@ class vtkDataArray;
// Moved inlined constructor and destructor definitions to .C files
// because certain compilers have problems with them.
//
// Hank Childs, Thu Jan 20 17:30:09 PST 2005
// Add data member cur_mesh so derived types can access mesh when
// deriving variables.
//
// ****************************************************************************
class EXPRESSION_API avtBinaryMathFilter
......@@ -55,6 +59,7 @@ class EXPRESSION_API avtBinaryMathFilter
};
avtCentering centering;
vtkDataSet *cur_mesh;
};
......
......@@ -15,6 +15,7 @@
#include <vtkRectilinearGrid.h>
#include <vtkStructuredGrid.h>
#include <avtCallback.h>
using std::vector;
......@@ -48,6 +49,24 @@ avtNeighborEvaluatorFilter::~avtNeighborEvaluatorFilter()
}
// ****************************************************************************
// Method: avtNeighborEvaluatorFilter::PreExecute
//
// Purpose:
// Called before Execute, this will initialize haveIssuedWarning.
//
// Programmer: Hank Childs
// Creation: January 20, 2005
//
// ****************************************************************************
void
avtNeighborEvaluatorFilter::PreExecute(void)
{
haveIssuedWarning = false;
}
// ****************************************************************************
// Method: avtNeighborEvaluatorFilter::DeriveVariable
//
......@@ -86,11 +105,20 @@ avtNeighborEvaluatorFilter::DeriveVariable(vtkDataSet *in_ds)
results->SetNumberOfTuples(nvals);
float *r_ptr = (float *) results->GetVoidPointer(0);
if (input == NULL)
return results;
if (input->GetNumberOfComponents() != 1)
if (input == NULL || input->GetNumberOfComponents() != 1)
{
// only deal with scalars, should issue warning.
// Don't return uninitialized memory.
for (i = 0 ; i < nvals ; i++)
r_ptr[i] = 0.;
if (!haveIssuedWarning)
{
avtCallback::IssueWarning("The biggest neighbor/smallest neighbor/"
"average neighbor expression only "
"operates on scalar quantities.");
haveIssuedWarning = true;
}
return results;
}
......
......@@ -19,6 +19,11 @@
// Programmer: Hank Childs
// Creation: September 17, 2004
//
// Modifications:
//
// Hank Childs, Thu Jan 20 11:10:08 PST 2005
// Add better warnings when error conditions are encountered.
//
// ****************************************************************************
class EXPRESSION_API avtNeighborEvaluatorFilter
......@@ -42,11 +47,13 @@ class EXPRESSION_API avtNeighborEvaluatorFilter
{ return "avtNeighborEvaluatorFilter"; };
virtual const char *GetDescription(void)
{ return "Calculating neighbors values"; };
virtual void PreExecute(void);
protected:
EvaluationType evaluationType;
float *buff;
int *nEntries;
bool haveIssuedWarning;
virtual vtkDataArray *DeriveVariable(vtkDataSet *);
virtual avtPipelineSpecification_p
......
// ************************************************************************* //
// avtResradFilter.C //
// ************************************************************************* //
#include <avtResradFilter.h>
#include <vtkDataArray.h>
#include <vtkRectilinearGrid.h>
#include <avtCallback.h>
#include <ExpressionException.h>
static bool varres(float *var, float *newvar, int nxvar, int nyvar,
int reflflag, float dx, float dy, float resrad);
// ****************************************************************************
// Method: avtResradFilter constructor
//
// Purpose:
// Defines the constructor. Note: this should not be inlined in the
// header because it causes problems for certain compilers.
//
// Programmer: Hank Childs
// Creation: January 20, 2005
//
// ****************************************************************************
avtResradFilter::avtResradFilter()
{
haveIssuedWarning = false;
}
// ****************************************************************************
// Method: avtResradFilter destructor
//
// Purpose:
// Defines the destructor. Note: this should not be inlined in the header
// because it causes problems for certain compilers.
//
// Programmer: Hank Childs
// Creation: January 20, 2005
//
// ****************************************************************************
avtResradFilter::~avtResradFilter()
{
;
}
// ****************************************************************************
// Method: avtResradFilter::PreExecute
//
// Purpose:
// Initialize the haveIssuedWarning flag.
//
// Programmer: Hank Childs
// Creation: January 20, 2005
//
// ****************************************************************************
void
avtResradFilter::PreExecute(void)
{
avtBinaryMathFilter::PreExecute();
haveIssuedWarning = false;
}
// ****************************************************************************
// Method: avtResradFilter::DoOperation
//
// Purpose:
// Calculates the resrad. This adjusts the resolution using a monte
// carlo resampling.
//
// Arguments:
// in1 The first input data array.
// in2 The second input data array.
// out The output data array.
// ncomponents The number of components ('1' for scalar, '2' or '3' for
// vectors, etc.)
// ntuples The number of tuples (ie 'npoints' or 'ncells')
//
// Programmer: Hank Childs
// Creation: January 20, 2005
//
// ****************************************************************************
void
avtResradFilter::DoOperation(vtkDataArray *in1, vtkDataArray *in2,
vtkDataArray *out, int ncomponents,int ntuples)
{
int i;
float *var = (float *) in1->GetVoidPointer(0);
float radius = in2->GetTuple1(0); // Assuming constant.
float *newvar = (float *) out->GetVoidPointer(0);
//
// There are so many ways to go wrong, initialize the array assuming we
// will return with an error condition.
//
int nvals = out->GetNumberOfTuples();
for (int i = 0 ; i < nvals ; i++)
newvar[i] = var[i];
if (cur_mesh->GetDataObjectType() != VTK_RECTILINEAR_GRID)
{
if (!haveIssuedWarning)
{
avtCallback::IssueWarning("The resrad expression only operates on"
" 2D rectilinear meshes.");
haveIssuedWarning = true;
}
return;
}
int dims[3];
vtkRectilinearGrid *rgrid = (vtkRectilinearGrid *) cur_mesh;
rgrid->GetDimensions(dims);
if (dims[2] != 1)
{
if (!haveIssuedWarning)
{
avtCallback::IssueWarning("The resrad expression only operates on"
" 2D rectilinear meshes.");
haveIssuedWarning = true;
}
return;
}
float *X = (float *) rgrid->GetXCoordinates()->GetVoidPointer(0);
float *Y = (float *) rgrid->GetYCoordinates()->GetVoidPointer(0);
bool hasEqualSpacing = true;
float dx = X[1] - X[0];
float fudge = dx/1000.;
for (i = 1 ; i < dims[0]-1 ; i++)
if (fabs((X[i+1] - X[i]) - dx) > fudge)
hasEqualSpacing = false;
float dy = Y[1] - Y[0];
fudge = dy/1000.;
for (i = 1 ; i < dims[1]-1 ; i++)
if (fabs((Y[i+1] - Y[i]) - dy) > fudge)
hasEqualSpacing = false;
if (!hasEqualSpacing)
{
if (!haveIssuedWarning)
{
avtCallback::IssueWarning("The spacing of the rectilinear grid "
"must be regular (equidistant).");
haveIssuedWarning = true;
}
return;
}
int nX = dims[0];
int nY = dims[1];
if (centering != AVT_NODECENT)
{
nX--;
nY--;
}
if (!varres(var, newvar, nX, nY, 1, dx, dy, radius))
{
if (!haveIssuedWarning)
{
avtCallback::IssueWarning("The resrad expression failed. This is"
"probably because the radius you specified is too large.");
haveIssuedWarning = true;
}
return;
}
}
// The below all comes from the MeshTV file qrvarres where resrad was
// originally implemented.
#include <stdlib.h>
#include <math.h>
#define NPG 200
#define NGPS 2000
#define TPI 6.283185308
#define NRES 8
#define RES(k,j) res[((j)+8)*(NRES+NRES+1)+((k)+8)]
#define VAR(i,j) var[((j)-1)*nxvar+((i)-1)]
#define NEWVAR(i,j) newvar[((j)-1)*nxvar+((i)-1)]
#ifndef MIN
#define MIN(a,b) ((a < b) ? a : b)
#endif
#ifndef MAX
#define MAX(a,b) ((a > b) ? a : b)
#endif
static float res[(NRES+NRES+1)*(NRES+NRES+1)];
static int kx [NPG], jy [NPG];
/*-------------------------------------------------------------------------
* Function: randf
*
* Purpose: Generates random numbers between RMIN (inclusive) and
* RMAX (exclusive). RMIN should be smaller than RMAX.
*
* Return: A pseudo-random number
*
* Programmer: Robb Matzke
* robb@callisto.nuance.mdn.com
* Jul 9, 1996
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
static double
randf(double rmin, double rmax)
{
unsigned long acc;
static double divisor = 0;
if (divisor < 1)
divisor = pow(2.0, 30);
rmax -= rmin;
acc = ((rand() & 0x7fff) << 15) | (rand() & 0x7fff);
return (rmax * (acc / divisor) + rmin);
}
/***********************************************************************
* PURPOSE -- Adjust resolution of regular grid data using
* Monte Carlo algo.
*
* PROGRAMMER -- Algorithm: Gary Carlson
* Minor coding/comment changes: Jeffery W. Long, NSSD-B
*
* PARAMETERS
*
* var =| original (raw) var data
* newvar |= array to hold new (revised) var data
* nxvar =| number of var bins in the z-direction
* nyvar =| number of var bins in the r-direction
* reflflag =| special reflection flag (1=on)
* dx =| delta (width) for z bins
* dy =| delta (width) for r bins
* resrad =| resolution of new varhole (in cm.)
* ret value |= error indicator
*
* MODIFICATIONS
* Al Leibee, Mon Aug 2 10:32:58 PDT 1993
* Fixed 'randfact'.
*
* Al Leibee, Thu Jun 23 13:20:43 PDT 1994
* Fixed 'randfact'.
*
* Eric Brugger, Wed Mar 1 10:44:17 PST 1995
* I further fixed 'randfact' for the sun.
*
* Sean Ahern, Wed Apr 24 14:17:46 PDT 1996
* Added more return values for better error reporting.
*
* Sean Ahern, Wed Jul 10 15:51:15 PDT 1996
* To finalize things... :-) I removed randfact altogether. It's not
* needed since we aren't using rand any more.
*
**********************************************************************/
bool
varres (float *var, float *newvar, int nxvar, int nyvar, int reflflag,
float dx, float dy, float resrad)
{
int i, j, jj, jm, j2, k, kk, k1, k2;
int jext, kext;
int nresp1;
float fnresp1;
float rr, phi, x, y, avg;
int ngroup;
float randnum;
float pnormi;
float rr2;
pnormi = 1. / (float) (NGPS * NPG);
rr2 = resrad * resrad;
for (i = 0; i < nxvar * nyvar; i++)
newvar [i] = 0.0;
for (i = 0; i < (2 * NRES + 1) * (2 * NRES + 1); i++)
res [i] = 0.0;
/*
* Check for legal resolution ratio
*/
jext = (int) (resrad / dy + 1.);
kext = (int) (resrad / dx + 1.);
if (jext<1)
return false;
if (kext<1)
return false;
if (jext>NRES)
return false;
if (kext>NRES)
return false;
/*
* use monte carlo method to find resolution function
*/
nresp1 = NRES + 1;
fnresp1 = nresp1;
for (ngroup = 1; ngroup < NGPS; ngroup++)
{
for (i = 0; i < NPG; i++)
{
randnum = randf(0.0,1.0);
rr = sqrt (rr2 * randnum);
randnum = randf(0.0,1.0);
phi = randnum * TPI;
randnum = randf(0.0,1.0);
x = fnresp1 + randnum + rr * cos (phi) / dx;
randnum = randf(0.0,1.0);
y = fnresp1 + randnum + rr * sin (phi) / dy;
kx [i] = ((int) x) - nresp1;
jy [i] = ((int) y) - nresp1;
}
for (i = 0; i < NPG; i++)
RES (kx[i],jy[i]) = RES (kx[i],jy[i]) + pnormi;
}
for (j = 1; j <= NRES; j++) {
for (k = -NRES; k <= NRES; k++) {
avg = .5 * (RES (j,k) + RES (-j,k));
RES (j,k) = avg;
RES (-j,k) = avg;
}
}
for (k = 1; k <= NRES; k++) {
for (j = -NRES; j <= NRES; j++) {
avg = .5 * (RES (j,k) + RES (j,-k));
RES (j,k) = avg;
RES (j,-k) = avg;
}
}
/*
* Calculate resolution effect on var
*/
for (jj = -jext; jj <= jext; jj++) {
j2 = MIN (nyvar, nyvar - jj);
for (kk = -kext; kk <= kext; kk++) {
k1 = MAX (1, 1 - kk);
k2 = MIN (nxvar, nxvar - kk);
for (j = 1; j <= j2; j++) {
jm = j + jj;
if (jm < 1)
jm = 1 - jm;
for (k = k1; k <= k2; k++)
NEWVAR (k,j) += VAR (k+kk, jm) * RES (kk,jj);
if (reflflag == 1. && kk < 0) {
for (k = 1; k <= -kk; k++)
NEWVAR (k,j) += VAR (-kk + 1 - k, jm) *
RES (kk, jj);
}
}
}
}
return true;
}
// ************************************************************************* //
// avtResradFilter.h //
// ************************************************************************* //
#ifndef AVT_RESRAD_FILTER_H
#define AVT_RESRAD_FILTER_H
#include <avtBinaryMathFilter.h>
class vtkDataArray;
// ****************************************************************************
// Class: avtResradFilter
//
// Purpose:
// A filter that calculates resrad -- which adjusts the resolution
// using a monte carlo resampling with a given radius.
//
// Programmer: Hank Childs
// Creation: January 20, 2005
//
// ****************************************************************************
class EXPRESSION_API avtResradFilter : public avtBinaryMathFilter
{
public:
avtResradFilter();
virtual ~avtResradFilter();
virtual const char *GetType(void)
{ return "avtResradFilter"; };
virtual const char *GetDescription(void)
{ return "Calculating resrad"; };
protected:
bool haveIssuedWarning;
virtual void PreExecute(void);
virtual void DoOperation(vtkDataArray *in1, vtkDataArray *in2,
vtkDataArray *out, int ncomps, int ntuples);
};
#endif
......@@ -92,6 +92,9 @@
# Brad Whitlock, Tue Jan 4 18:14:57 PST 2005
# Added -lexpr so we can link on MacOS X.
#
# Hank Childs, Thu Jan 20 15:47:25 PST 2005
# Added avtSideVolume, avtResradFilter.
#
##############################################################################