Commit 3f90c999 authored by cyrush's avatar cyrush
Browse files

added value_for_material expression

git-svn-id: http://visit.ilight.com/svn/visit/trunk/src@3076 18c085ea-50e0-402c-830e-de6fd14e8384
parent 646719ea
......@@ -2897,6 +2897,9 @@ avtGenericDatabase::GetMesh(const char *meshname, int ts, int domain,
// Hank Childs, Tue Feb 15 07:21:10 PST 2005
// Make translations when we have hidden characters.
//
// Cyrus Harrison, Wed Jan 30 13:26:28 PST 2008
// Added support for passing variable name from a mixed variable request.
//
// ****************************************************************************
void
......@@ -2914,7 +2917,8 @@ avtGenericDatabase::GetAuxiliaryData(avtDataSpecification_p spec,
avtSILSpecification sil = spec->GetSIL();
const char *var = spec->GetVariable();
if ((strcmp(type, AUXILIARY_DATA_SPATIAL_EXTENTS) == 0) ||
(strcmp(type, AUXILIARY_DATA_DATA_EXTENTS) == 0))
(strcmp(type, AUXILIARY_DATA_DATA_EXTENTS) == 0) ||
(strcmp(type, AUXILIARY_DATA_MIXED_VARIABLE) == 0))
{
if (args != NULL)
var = (char *) args;
......
/*****************************************************************************
*
* Copyright (c) 2000 - 2008, Lawrence Livermore National Security, LLC
* Produced at the Lawrence Livermore National Laboratory
* LLNL-CODE-400142
* All rights reserved.
*
* This file is part of VisIt. For details, see https://visit.llnl.gov/. The
* full copyright notice is contained in the file COPYRIGHT located at the root
* of the VisIt distribution or at http://www.llnl.gov/visit/copyright.html.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the disclaimer below.
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the disclaimer (as noted below) in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of the LLNS/LLNL nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL SECURITY,
* LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
*****************************************************************************/
// ************************************************************************* //
// avtPerMaterialValueFilter.C //
// ************************************************************************* //
#include <avtPerMaterialValueFilter.h>
#include <math.h>
#include <vtkCellData.h>
#include <vtkDataSet.h>
#include <vtkFloatArray.h>
#include <vtkUnsignedIntArray.h>
#include <avtExprNode.h>
#include <ExprToken.h>
#include <avtCallback.h>
#include <avtMaterial.h>
#include <avtMetaData.h>
#include <avtMixedVariable.h>
#include <DebugStream.h>
#include <ExpressionException.h>
#include <ImproperUseException.h>
#include <visitstream.h>
using std::ostringstream;
// ****************************************************************************
// Method: avtPerMaterialValueFilter constructor
//
// Purpose:
// Defines the constructor. Note: this should not be inlined in the
// header because it causes problems for certain compilers.
//
// Programmer: Cyrus Harrison
// Creation: January 29, 2008
//
// ****************************************************************************
avtPerMaterialValueFilter::avtPerMaterialValueFilter()
{
;
}
// ****************************************************************************
// Method: avtPerMaterialValueFilter destructor
//
// Purpose:
// Defines the destructor. Note: this should not be inlined in the header
// because it causes problems for certain compilers.
//
// Programmer: Cyrus Harrison
// Creation: January 29, 2008
//
// ****************************************************************************
avtPerMaterialValueFilter::~avtPerMaterialValueFilter()
{
;
}
// ****************************************************************************
// Method: avtPerMaterialValueFilter::DeriveVariable
//
// Purpose:
// Extracts the proper zonal value for the given material.
//
// Arguments:
// inDS The input dataset.
//
// Returns: The derived variable. The calling class must free this
// memory.
//
// Programmer: Cyrus Harrison
// Creation: January 29, 2008
//
// Modifications:
//
// ****************************************************************************
vtkDataArray *
avtPerMaterialValueFilter::DeriveVariable(vtkDataSet *in_ds)
{
int i, j;
int ncells = in_ds->GetNumberOfCells();
// if the cell is clean, we simply need the orig value
// if the cell is mixed, we need the correct value from the
// avtMixedVariable entry.
// get input array
vtkFloatArray *val_array = NULL;
val_array = (vtkFloatArray *)in_ds->GetCellData()->GetArray(activeVariable);
if(val_array == NULL) // check for error on input
{
ostringstream oss;
oss << "could not find zonal variable named: " << activeVariable
<< "." << endl
<< "The value_for_material expression requires a varaible with"
<< " zonal centering." <<endl;
EXCEPTION2(ExpressionException, outputVariableName,oss.str().c_str());
}
// prepare result array
vtkFloatArray *res = vtkFloatArray::New();
res->SetNumberOfTuples(ncells);
avtMaterial *mat = GetMetaData()->GetMaterial(currentDomainsIndex,
currentTimeState);
if(mat == NULL ) // error
{
EXCEPTION2(ExpressionException, outputVariableName,
"could not obtaing valid material object.");
}
// get the mixed var
// note: this will only exists in domains that have mixed vars,
// so it can be null
avtMixedVariable *mvar = GetMetaData()->GetMixedVar(activeVariable,
currentDomainsIndex,
currentTimeState);
// get the material index from give material number or name
int n_mats = mat->GetNMaterials();
int mat_idx = -1;
if(matNumber == -1 && matName != "")
{
// find material index from name
for (i = 0 ; i < n_mats && mat_idx == -1; i++)
{
std::string curr_mat = mat->GetMaterials()[i];
if(curr_mat == matName)
mat_idx = i;
}
}
else
{
// match mat # to proper index
for (i = 0 ; i < n_mats && mat_idx == -1; i++)
{
std::string curr_mat = mat->GetMaterials()[i];
char tmp[256];
sprintf(tmp, "%d", matNumber);
std::string matname(tmp);
if (curr_mat == matname ||
(curr_mat.length() > matname.length() &&
curr_mat.substr(0,matname.length() + 1) == (matname + " ")))
{
mat_idx = i;
}
}
}
// make sure we actually found a valid material index
if(mat_idx < 0 || mat_idx > n_mats)
{
EXCEPTION2(ExpressionException, outputVariableName,
"an invalid material number or name was passed.");
}
std::vector<float> mv_vals;
const int *mat_list = mat->GetMatlist();
// get the proper value
for(i=0;i<ncells;i++)
{
float val = 0.0;
// check for clean case
if( mat_list[i] == mat_idx)
{
// if clean use original value
val = val_array->GetTuple1(i);
}
else if(mvar != NULL)
{
// mixed case, use mix var to get the proper value
mvar->GetValuesForZone(i,mat,mv_vals);
val = mv_vals[mat_idx];
}
// set val
// (will be zero if desired material does not exist in this zone)
res->SetTuple1(i,val);
}
return res;
}
// ****************************************************************************
// Method: avtPerMaterialValueFilter::ProcessArguments
//
// Purpose:
// Parses arguments for the avtPerMaterialValueFilter.
// Expected arguments are:
// variable name and material number or name.
//
// Programmer: Cyrus Harrison
// Creation: January 29, 2008
//
// Modifications:
//
// ****************************************************************************
void
avtPerMaterialValueFilter::ProcessArguments(ArgsExpr *args,
ExprPipelineState *state)
{
// clear mat info
matNumber = -1;
matName = "";
// Check the number of arguments
std::vector<ArgExpr*> *arguments = args->GetArgs();
int nargs = arguments->size();
// get var name
if (nargs == 0)
{
EXCEPTION2(ExpressionException, outputVariableName,
"avtPerMaterialValueFilter: No arguments given.");
}
// Tell the first argument to create its filters.
ArgExpr *first_arg= (*arguments)[0];
avtExprNode *first_tree = dynamic_cast<avtExprNode*>(first_arg->GetExpr());
first_tree->CreateFilters(state);
// Check if there's a second argument.
if (nargs == 1)
{
debug5 << "avtPerMaterialValueFilter: Missing second argument." << endl;
EXCEPTION2(ExpressionException, outputVariableName,
"avtPerMaterialValueFilter: Missing second argument.");
}
// Check for too many arguments.
if (nargs > 2)
{
EXCEPTION2(ExpressionException, outputVariableName,
"avtPerMaterialValueFilter expects only two arguments.");
}
// get material id or name
ArgExpr *sec_arg= (*arguments)[1];
avtExprNode *sec_tree= dynamic_cast<avtExprNode*>(sec_arg->GetExpr());
string type = sec_tree->GetTypeName();
if (type == "IntegerConst")
{
matNumber = dynamic_cast<IntegerConstExpr*>(sec_tree)->GetValue();
}
else if (type == "StringConst")
{
matName = dynamic_cast<StringConstExpr*>(sec_tree)->GetValue();
}
else
{
debug5 << "avtPerMaterialValueFilter: Second argument is not a valid "
"material id (integer) or name (string): "
<< type.c_str() << endl;
EXCEPTION2(ExpressionException, outputVariableName,
"avtPerMaterialValueFilter: Second argument is not a material "
"number (integer) or name (string).");
}
}
// ****************************************************************************
// Method: avtPerMaterialValueFilter::PerformRestriction
//
// Purpose:
// This routine allows the filter to change the data specification.
// It is only re-defined for matvf to get around a shortcoming in the
// generic database. The problem is that if ghost zones are communicated,
// the new avtMaterial object (if it exists at all), is not stored
// anywhere for this filter to get. Instead, this filter will get the
// original avtMaterial object and quickly have an internal error.
//
// This could be solved in the generic database, but require a fairly
// large re-organization. For more information, look at '3939.
//
// Programmer: Cyrus Harrison (copied from Hank Childs' matvf implementation)
// Creation: January 29, 2008
//
// Modifications:
//
// ****************************************************************************
avtPipelineSpecification_p
avtPerMaterialValueFilter::PerformRestriction(avtPipelineSpecification_p spec)
{
spec->GetDataSpecification()->SetMaintainOriginalConnectivity(true);
return spec;
}
/*****************************************************************************
*
* Copyright (c) 2000 - 2008, Lawrence Livermore National Security, LLC
* Produced at the Lawrence Livermore National Laboratory
* LLNL-CODE-400142
* All rights reserved.
*
* This file is part of VisIt. For details, see https://visit.llnl.gov/. The
* full copyright notice is contained in the file COPYRIGHT located at the root
* of the VisIt distribution or at http://www.llnl.gov/visit/copyright.html.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the disclaimer below.
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the disclaimer (as noted below) in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of the LLNS/LLNL nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL SECURITY,
* LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
*****************************************************************************/
// ************************************************************************* //
// avtPerMaterialValueFilter.h //
// ************************************************************************* //
#ifndef AVT_PER_MATERIAL_VALUE_FILTER_H
#define AVT_PER_MATERIAL_VALUE_FILTER_H
#include <avtSingleInputExpressionFilter.h>
class vtkDataArray;
class ArgsExpr;
class ExprPipelineState;
// ****************************************************************************
// Class: avtPerMaterialValueFilter
//
// Purpose:
// Extracts the correct per material zonal value for a mixed variable.
//
// Programmer: Cyrus Harrison
// Creation: January 29, 2008
//
// Modifications:
//
// ****************************************************************************
class EXPRESSION_API avtPerMaterialValueFilter
: public avtSingleInputExpressionFilter
{
public:
avtPerMaterialValueFilter();
virtual ~avtPerMaterialValueFilter();
virtual const char *GetType(void)
{ return "avtPerMaterialValueFilter"; };
virtual const char *GetDescription(void)
{return "Extracting mixed material value.";};
virtual void ProcessArguments(ArgsExpr*, ExprPipelineState *);
protected:
virtual int GetVariableDimension(void) { return 1; };
virtual avtPipelineSpecification_p
PerformRestriction(avtPipelineSpecification_p);
virtual vtkDataArray *DeriveVariable(vtkDataSet *);
virtual bool IsPointVariable(void) { return false; };
int matNumber;
std::string matName;
};
#endif
......@@ -190,6 +190,9 @@
# Hank Childs, Thu Jan 24 15:48:41 PST 2008
# Added avtExecuteThenTimeLoopFilter.
#
# Cyrus Harrison, Tue Jan 29 08:35:15 PST 2008
# Added avtPerMaterialValueFilter.C
#
##############################################################################
@SET_MAKE@
......@@ -278,6 +281,7 @@ General_src= \
General/avtNeighborEvaluatorFilter.C \
General/avtNormalizeFilter.C \
General/avtPerformColorTableLookupFilter.C \
General/avtPerMaterialValueFilter.C \
General/avtProcessorIdFilter.C \
General/avtRelativeDifferenceFilter.C \
General/avtResradFilter.C \
......
......@@ -154,6 +154,7 @@
#include <avtTensorContractionFilter.h>
#include <avtViscousStressFilter.h>
#include <avtPerformColorTableLookupFilter.h>
#include <avtPerMaterialValueFilter.h>
#include <stdio.h>
#include <ExpressionException.h>
......@@ -466,6 +467,9 @@ avtVectorExpr::CreateFilters(ExprPipelineState *state)
// Gunther H. Weber, Wed Jan 9 10:22:55 PST 2008
// Added colorlookup.
//
// Cyrus Harrison, Tue Jan 29 08:51:41 PST 2008
// Added value_for_material (& val4mat alias)
//
// ****************************************************************************
avtExpressionFilter *
......@@ -525,6 +529,10 @@ avtFunctionExpr::CreateFilters(string functionName)
return new avtMIRvfFilter();
if (functionName == "materror")
return new avtMatErrorFilter();
if (functionName == "value_for_material")
return new avtPerMaterialValueFilter();
if (functionName == "val4mat")
return new avtPerMaterialValueFilter();
if (functionName == "specmf")
return new avtSpecMFFilter();
if (functionName == "nmats")
......
......@@ -1563,6 +1563,40 @@ avtMaterial::Initialize(int nMats, const vector<string> &matnames,
}
}
// ****************************************************************************
// Method: GetVolFracsForZone
//
// Purpose:
// Constructs the per material volume fraction list for the given zone.
//
// Programmer: Cyrus Harrison
// Creation: January 30, 2008
//
// ****************************************************************************
void
avtMaterial::GetVolFracsForZone(int zone_id, std::vector<float> &vfs)
{
// init with zeros
vfs.clear();
for (int m=0; m<nMaterials; m++)
vfs.push_back(0.0);
// mixed case
if(matlist[zone_id] < 0)
{
int mix_idx = -matlist[zone_id] - 1;
while(mix_idx >=0)
{
vfs[mix_mat[mix_idx]] = mix_vf[mix_idx];
mix_idx = mix_next[mix_idx] -1;
}
}
else // clean case the vf = 1.0 for the only material in the zone
{
vfs[matlist[zone_id]] = 1.0;
}
}
// ****************************************************************************
// Method: ExtractCellMatInfo
......
This diff is collapsed.
......@@ -374,11 +374,15 @@ avtMetaData::GetPipelineSpecification(int domain)
// Creation: July 1, 2004
//
// Modifications:
// Cyrus Harrison, Wed Jan 30 13:23:30 PST 2008
// Added variable name argument to GetMixedVar, allowing this method
// to be used when the desired mixed var differs from the active
// variable in the contract.
//
// ****************************************************************************
avtMixedVariable *
avtMetaData::GetMixedVar(int domain, int timestep)
avtMetaData::GetMixedVar(const char *varname, int domain, int timestep)
{
VoidRefList list;
avtPipelineSpecification_p spec = GetPipelineSpecification(domain);
......@@ -388,7 +392,11 @@ avtMetaData::GetMixedVar(int domain, int timestep)
if (timestep != -1)
spec->GetDataSpecification()->SetTimestep(timestep);
source->GetVariableAuxiliaryData(AUXILIARY_DATA_MIXED_VARIABLE, NULL, spec,list);
// pass the varname, so the source can obtain the proper mixed var.
source->GetVariableAuxiliaryData(AUXILIARY_DATA_MIXED_VARIABLE,
(void*)varname,
spec,
list);
if (list.nList == 0)
{
return NULL;
......
......@@ -101,6 +101,11 @@ class avtTerminatingSource;
// Define private copy constructor and assignment operator to prevent
// accidental use of default, bitwise copy implementations.
//
// Cyrus Harrison, Wed Jan 30 13:23:30 PST 2008
// Added variable name argument to GetMixedVar, allowing this method
// to be used when the desired mixed var differs from the active
// variable in the contract.
//
// ****************************************************************************
class PIPELINE_API avtMetaData
......@@ -115,7 +120,7 @@ class PIPELINE_API avtMetaData
avtFacelist *GetExternalFacelist(int);
avtMaterial *GetMaterial(int, int = -1);
avtSpecies *GetSpecies(int, int = -1);
avtMixedVariable *GetMixedVar(int, int = -1);
avtMixedVariable *GetMixedVar(const char *,int, int = -1);
protected:
avtTerminatingSource *source;
......
......@@ -45,6 +45,7 @@
// For NULL
#include <stdio.h>