cee::ug::CustomResultGenerator Class Reference

A class to generate custom results. More...

Classes

struct  InputDataResults
 Input data results. More...
 
struct  InputValueData
 Input value data. More...
 
struct  OutputDataResult
 Output data result. More...
 
struct  OutputValueData
 Output value data. More...
 

Public Member Functions

 CustomResultGenerator ()
 Creates an empty result generator object. More...
 
 CustomResultGenerator (size_t argumentCount)
 Creates a result generator object. More...
 
bool operator== (const CustomResultGenerator &rhs) const
 Returns true if rhs equals current generator. More...
 
bool operator!= (const CustomResultGenerator &rhs) const
 Returns true if rhs does NOT equals current generator. More...
 
size_t argumentCount () const
 Returns number of arguments. More...
 
ResultType argumentType (size_t index) const
 Returns argument type at index. More...
 
void setArgumentType (size_t index, ResultType resultType)
 Sets argument type at index. More...
 
void setFunction (CustomResultFunction *function)
 Sets custom result function. More...
 
bool hasFunction () const
 Returns true if result generator has function. More...
 
const CustomResultFunctionfunction () const
 Returns custom result function. More...
 
virtual bool generate (const DataSource *dataSource, const ResultInfo &result, const std::vector< CustomResultArgument > &arguments, DataState *state) const
 Generates result. More...
 
- Public Member Functions inherited from cee::RefCountedObject
void addRef () const
 Increments the reference count for this object. More...
 
void release () const
 Decrements the reference count for this object. More...
 
int refCount () const
 Returns the reference count for this object. More...
 
void setRefCountZero () const
 Sets the ref count to zero, but DOES NOT delete the object. More...
 

Protected Member Functions

bool checkArguments (const std::vector< CustomResultArgument > &arguments) const
 Checks arguments and returns false if check failed. More...
 
bool computeCustomArguments (const DataSource *dataSource, const std::vector< CustomResultArgument > &arguments, DataState *state) const
 Computes custom arguments for given dataSource and state. More...
 
bool gatherInputDataResults (const DataResultGroup *resultGroup, const std::vector< CustomResultArgument > &arguments, size_t partCount, InputDataResults *inputDataResults) const
 Gathers input data results for given resultGroup. More...
 
bool gatherInputValuePointers (const std::vector< CustomResultArgument > &arguments, size_t partIndex, const InputDataResults &inputDataResults, InputValueData *inputValueData) const
 Gathers input value pointers. More...
 
bool getOuputDataResult (DataResultGroup *resultGroup, const ResultInfo &result, OutputDataResult *outputDataResult) const
 Gets output data result. More...
 
bool getOutputValuePointer (size_t partIndex, const OutputDataResult &outputDataResult, const InputValueData &inputValueData, size_t outputItemCount, OutputValueData *outputValueData) const
 Gets output value pointer. More...
 
Inheritance diagram for cee::ug::CustomResultGenerator:
cee::RefCountedObject

Detailed Description

A class to generate custom results.

In order to add a custom result, first implement a derived CustomResultFunction that provides the custom result values given a number of inputs.

Example: this custom result function provides the trace of an input tensor. There is one input, a symmetric tensor, for which the 6 values are provided in the corresponding first inputValues raw const double pointer.

The first three values are the diagonal components of the tensor, which are added to provide the output tensor trace.

class TensorTraceFunction : public CustomResultFunction
{
public:
bool computeItem(const std::vector<const double*>& inputValues, double* outputValues)
{
const double* inputTensorValues = inputValues[0];
CVF_ASSERT(inputTensorValues);
*outputValues = inputTensorValues[0] + inputTensorValues[1] + inputTensorValues[2];
return true;
}
};

To generate the custom result with this function, create a CustomResultGenerator providing the number of inputs (one, in the example) and the DataSource that will be used to get the input values, and specify the input argument types. Instantiate the function, and set it on the CustomResultGenerator.

CustomResultGenerator generator(dataSource, 1);
generator.setArgumentType(0, SYMMETRIC_TENSOR);
PtrRef<TensorTraceFunction> function = new TensorTraceFunction;
generator.setFunction(function.get());

A custom result can now be added as a ResultInfo to the directory of the DataSource that contains the input argument results. If "tensorResultInfo" is the ResultInfo associated to the input tensor result, the custom result is registered like this:

std::vector<CustomResultArgument> arguments;
arguments.push_back(CustomResultArgument(tensorResultInfo));
ResultInfo customInfo(SCALAR, dataSource->directory()->nextUnusedId(SCALAR), "Tensor trace", PER_NODE, arguments, generator);
ds->directory()->setCustomResultInfo(customInfo);

The generation of the custom result for a given DataState is performed in CustomResultGenerator::generate(). The default implementation assumes that the custom result and the arguments have the same mapping. A loop runs through all the items of this mapping and calls the CustomResultFunction on each of them. For more complex custom results, for example node-averaging of element-mapped results, CustomResultGenerator::generate() can be specialized in a derived CustomResultGenerator.

Constructor & Destructor Documentation

cee::ug::CustomResultGenerator::CustomResultGenerator ( )

Creates an empty result generator object.

cee::ug::CustomResultGenerator::CustomResultGenerator ( size_t  argumentCount)

Creates a result generator object.

Member Function Documentation

size_t cee::ug::CustomResultGenerator::argumentCount ( ) const

Returns number of arguments.

ResultType cee::ug::CustomResultGenerator::argumentType ( size_t  index) const

Returns argument type at index.

bool cee::ug::CustomResultGenerator::checkArguments ( const std::vector< CustomResultArgument > &  arguments) const
protected

Checks arguments and returns false if check failed.

bool cee::ug::CustomResultGenerator::computeCustomArguments ( const DataSource dataSource,
const std::vector< CustomResultArgument > &  arguments,
DataState state 
) const
protected

Computes custom arguments for given dataSource and state.

const CustomResultFunction * cee::ug::CustomResultGenerator::function ( ) const

Returns custom result function.

bool cee::ug::CustomResultGenerator::gatherInputDataResults ( const DataResultGroup resultGroup,
const std::vector< CustomResultArgument > &  arguments,
size_t  partCount,
InputDataResults inputDataResults 
) const
protected

Gathers input data results for given resultGroup.

bool cee::ug::CustomResultGenerator::gatherInputValuePointers ( const std::vector< CustomResultArgument > &  arguments,
size_t  partIndex,
const InputDataResults inputDataResults,
InputValueData inputValueData 
) const
protected

Gathers input value pointers.

bool cee::ug::CustomResultGenerator::generate ( const DataSource dataSource,
const ResultInfo result,
const std::vector< CustomResultArgument > &  arguments,
DataState state 
) const
virtual

Generates result.

bool cee::ug::CustomResultGenerator::getOuputDataResult ( DataResultGroup resultGroup,
const ResultInfo result,
OutputDataResult outputDataResult 
) const
protected

Gets output data result.

bool cee::ug::CustomResultGenerator::getOutputValuePointer ( size_t  partIndex,
const OutputDataResult outputDataResult,
const InputValueData inputValueData,
size_t  outputItemCount,
OutputValueData outputValueData 
) const
protected

Gets output value pointer.

bool cee::ug::CustomResultGenerator::hasFunction ( ) const

Returns true if result generator has function.

bool cee::ug::CustomResultGenerator::operator!= ( const CustomResultGenerator rhs) const

Returns true if rhs does NOT equals current generator.

bool cee::ug::CustomResultGenerator::operator== ( const CustomResultGenerator rhs) const

Returns true if rhs equals current generator.

void cee::ug::CustomResultGenerator::setArgumentType ( size_t  index,
ResultType  resultType 
)

Sets argument type at index.

void cee::ug::CustomResultGenerator::setFunction ( CustomResultFunction function)

Sets custom result function.