diff --git a/XdmfFunction.cpp b/XdmfFunction.cpp deleted file mode 100644 index 186d1c3d5d7ba46b2320fc37be3ded2784f4027d..0000000000000000000000000000000000000000 --- a/XdmfFunction.cpp +++ /dev/null @@ -1,710 +0,0 @@ -/*****************************************************************************/ -/* XDMF */ -/* eXtensible Data Model and Format */ -/* */ -/* Id : XdmfFunction.cpp */ -/* */ -/* Author: */ -/* Kenneth Leiter */ -/* kenneth.leiter@arl.army.mil */ -/* US Army Research Laboratory */ -/* Aberdeen Proving Ground, MD */ -/* */ -/* Copyright @ 2011 US Army Research Laboratory */ -/* All Rights Reserved */ -/* See Copyright.txt for details */ -/* */ -/* This software is distributed WITHOUT ANY WARRANTY; without */ -/* even the implied warranty of MERCHANTABILITY or FITNESS */ -/* FOR A PARTICULAR PURPOSE. See the above copyright notice */ -/* for more information. */ -/* */ -/*****************************************************************************/ - - -#include "XdmfArray.hpp" -#include "XdmfArrayType.hpp" -#include "XdmfFunction.hpp" -#include -#include -#include -#include "XdmfError.hpp" - -std::string XdmfFunction::mSupportedOperations = "|#()"; -const std::string XdmfFunction::mValidVariableChars = - "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_:."; -const std::string XdmfFunction::mValidDigitChars = "-1234567890."; -// List the priorities for the operations, based on the order of operations -// The index of the corresponding operation in validOperationChars -// is the same as the index of its priority in this array -std::map XdmfFunction::mOperationPriority = - boost::assign::map_list_of ('|', 2) - ('#', 1) - ('(', 0) - (')', 0); -// The higher the value, the earlier the operation is -// evaluated in the order of operations -// With the exception of parenthesis which are evaluated -// as soon as the closing parenthesis is found - -// Note, it doesn't handle overloaded functions well. -// Will generate errors unless overload methods are typecast. -std::map (*)(std::vector >)> - XdmfFunction::arrayFunctions = - boost::assign::map_list_of ("SUM", (shared_ptr (*)(std::vector >))XdmfFunction::sum) - ("AVE", (shared_ptr (*)(std::vector >))XdmfFunction::average); -std::map (*)(shared_ptr, shared_ptr)> - XdmfFunction::operations = boost::assign::map_list_of ('|', XdmfFunction::chunk) ('#', XdmfFunction::interlace); - - - - - -shared_ptr -XdmfFunction::New() -{ - shared_ptr p(new XdmfFunction()); - return p; -} - -XdmfFunction::XdmfFunction() -{ -} - -XdmfFunction::~XdmfFunction() -{ -} - -const std::string XdmfFunction::ItemTag = "Function"; - -int -XdmfFunction::addFunction(std::string name, - shared_ptr(*functionref)(std::vector >)) -{ - // Check to ensure that the name has valid characters - for (unsigned int i = 0; i < name.size(); ++i) { - // If the character is not found in the list of valid characters - if (mValidVariableChars.find(name[i]) == std::string::npos) { - // Then throw an error - try { - XdmfError::message(XdmfError::FATAL, - "Error: Function Name Contains Invalid Character(s)"); - } - catch (XdmfError e) { - throw e; - } - } - } - size_t origsize = arrayFunctions.size(); - arrayFunctions[name] = functionref; - // If no new functions were added - if (origsize == arrayFunctions.size()) { - // Toss a warning, it's nice to let people know that they're doing this - try { - XdmfError::message(XdmfError::WARNING, - "Warning: Function Overwritten"); - } - catch (XdmfError e) { - throw e; - } - } - return arrayFunctions.size(); -} - -shared_ptr -XdmfFunction::average(std::vector > values) -{ - double total = sum(values)->getValue(0);; - int totalSize = 0; - for (unsigned int i = 0; i < values.size(); ++i) - { - totalSize += values[i]->getSize(); - } - shared_ptr returnArray = XdmfArray::New(); - returnArray->insert(0, total/totalSize); - return returnArray; -} - -shared_ptr -XdmfFunction::chunk(shared_ptr val1, shared_ptr val2) -{ - // Join chunk (add the new array to the end of the first one) - // Joins into new array and returns it - shared_ptr returnArray = XdmfArray::New(); - // Determining what type to class it as in order to not lose data - // and to still have the smallest data type of the two - shared_ptr resultType = - XdmfArrayType::comparePrecision(val1->getArrayType(), - val2->getArrayType()); - - if (resultType == XdmfArrayType::Int8()) { - char sampleValue = 0; - returnArray->resize(val1->getSize()+val2->getSize(), sampleValue); - } - else if (resultType == XdmfArrayType::Int16()) { - short sampleValue = 0; - returnArray->resize(val1->getSize()+val2->getSize(), sampleValue); - } - else if (resultType == XdmfArrayType::Int32()) { - int sampleValue = 0; - returnArray->resize(val1->getSize()+val2->getSize(), sampleValue); - } - else if (resultType == XdmfArrayType::Int64()) { - long sampleValue = 0; - returnArray->resize(val1->getSize()+val2->getSize(), sampleValue); - } - else if (resultType == XdmfArrayType::UInt8()) { - unsigned char sampleValue = 0; - returnArray->resize(val1->getSize()+val2->getSize(), sampleValue); - } - else if (resultType == XdmfArrayType::UInt16()) { - unsigned short sampleValue = 0; - returnArray->resize(val1->getSize()+val2->getSize(), sampleValue); - } - else if (resultType == XdmfArrayType::UInt32()) { - unsigned int sampleValue = 0; - returnArray->resize(val1->getSize()+val2->getSize(), sampleValue); - } - else if (resultType == XdmfArrayType::Float32()) { - float sampleValue = 0.0; - returnArray->resize(val1->getSize()+val2->getSize(), sampleValue); - } - else if (resultType == XdmfArrayType::Float64()) { - double sampleValue = 0.0; - returnArray->resize(val1->getSize()+val2->getSize(), sampleValue); - } - else if (resultType == XdmfArrayType::String()) { - std::string sampleValue = ""; - returnArray->resize(val1->getSize()+val2->getSize(), sampleValue); - } - else { - // error type not supported - XdmfError::message(XdmfError::FATAL, "Invalid type during Interlace"); - } - returnArray->insert(0, val1, 0, val1->getSize(), 1, 1); - returnArray->insert(val1->getSize(), val2, 0, val2->getSize(), 1, 1); - return returnArray; -} - -// This function and the functions it depends on are reimplemented -// in XdmfCore.i in order to properly interface with python. -// There are differences between the versions, -// but the overall algorithm remains mostly the same. -shared_ptr -XdmfFunction::evaluateExpression(std::string expression, - std::map > variables) -{ - std::stack > valueStack; - std::stack operationStack; - - // String is parsed left to right - // Elements of the same priority are evaluated right to left - for (unsigned int i = 0; i < expression.size(); ++i) { - // Found to be a digit - if (mValidDigitChars.find(expression[i]) != std::string::npos) { - // Progress until a non-digit is found - int valueStart = i; - if (i + 1 < expression.size()) { - while (mValidDigitChars.find(expression[i+1]) != std::string::npos) { - i++; - } - } - // Push back to the value stack - shared_ptr valueArray = XdmfArray::New(); - // Use this to convert to double - valueArray->insert(0, atof(expression.substr(valueStart, i + 1 - valueStart).c_str())); - valueStack.push(valueArray); - } - else if (mValidVariableChars.find(expression[i]) != std::string::npos) { - // Found to be a variable - int valueStart = i; - // Progress until a nonvariable value is found - if (i+1 < expression.size()){ - while (mValidVariableChars.find(expression[i+1]) != std::string::npos) { - i++; - } - } - // Convert to equivalent - if (variables.find(expression.substr(valueStart, i + 1 - valueStart)) - == variables.end()) { - if (arrayFunctions.find(expression.substr(valueStart, i + 1 - valueStart)) - == arrayFunctions.end()) { - try { - XdmfError::message(XdmfError::FATAL, - "Error: Invalid Variable in evaluateExpression " - + expression.substr(valueStart, i + 1 - valueStart)); - } - catch (XdmfError e) { - throw e; - } - } - else { - std::string currentFunction = - expression.substr(valueStart, i + 1 - valueStart); - // Check if next character is an open parenthesis - if (i+1 >= expression.size()) { - if (expression[i+1] != '(') { - try { - XdmfError::message(XdmfError::FATAL, - "Error: No values supplied to function " - + expression.substr(valueStart, i + 1 - valueStart)); - } - catch (XdmfError e) { - throw e; - } - } - } - // If it is grab the string between paranthesis - - if (i + 2 >= expression.size()) { - XdmfError::message(XdmfError::FATAL, - "Error: Missing closing parethesis to function " - + expression.substr(valueStart, i + 1 - valueStart)); - } - i = i + 2; - valueStart = i; - int numOpenParenthesis = 0; - while ((expression[i] != ')' || numOpenParenthesis) && i < expression.size()) { - if (expression[i] == '(') { - numOpenParenthesis++; - } - else if (expression[i] == ')') { - numOpenParenthesis--; - } - i++; - } - std::string functionParameters = expression.substr(valueStart, i - valueStart); - std::vector > parameterVector; - // Split that string at commas - size_t parameterSplit = 0; - while (parameterSplit != std::string::npos) { - parameterSplit = 0; - parameterSplit = functionParameters.find_first_of(",", parameterSplit); - // Feed the substrings to the parse function - if (parameterSplit == std::string::npos) { - parameterVector.push_back(evaluateExpression(functionParameters, variables)); - } - else { - parameterVector.push_back( - evaluateExpression(functionParameters.substr(0, parameterSplit), - variables)); - functionParameters = functionParameters.substr(parameterSplit+1); - } - } - valueStack.push(evaluateFunction(parameterVector, currentFunction)); - } - } - else { - // Push equivalent to value stack - valueStack.push(variables.find(expression.substr(valueStart, i + 1 - valueStart))->second); - } - } - else if (mSupportedOperations.find(expression[i]) != std::string::npos) { - // Found to be an operation - // Ppop operations off the stack until one of a lower or equal importance is found - if (operationStack.size() > 0) { - if (expression[i] == ')') { - // To close a parenthesis pop off all operations until another parentheis is found - while (operationStack.size() > 0 && operationStack.top() != '(') { - // Must be at least two values for this loop to work properly - if (valueStack.size() < 2) { - try { - XdmfError::message(XdmfError::FATAL, - "Error: Not Enough Values in evaluateExpression"); - } - catch (XdmfError e) { - throw e; - } - } - else { - shared_ptr val2 = valueStack.top(); - valueStack.pop(); - shared_ptr val1 = valueStack.top(); - valueStack.pop(); - valueStack.push(evaluateOperation(val1, val2, operationStack.top())); - operationStack.pop(); - } - } - operationStack.pop(); - } - else if (expression[i] == '(') { - // Just add it if it's a start parenthesis - // Nothing happens here in that case - // Addition happens after the if statement - } - else { - int operationLocation = getOperationPriority(expression[i]); - int topOperationLocation = getOperationPriority(operationStack.top()); - // See order of operations to determine importance - while (operationStack.size() > 0 && operationLocation < topOperationLocation) { - // Must be at least two values for this loop to work properly - if (valueStack.size() < 2) { - try { - XdmfError::message(XdmfError::FATAL, - "Error: Not Enough Values in evaluateExpression"); - } - catch (XdmfError e) { - throw e; - } - } - else { - shared_ptr val2 = valueStack.top(); - valueStack.pop(); - shared_ptr val1 = valueStack.top(); - valueStack.pop(); - valueStack.push(evaluateOperation(val1, val2, operationStack.top())); - operationStack.pop(); - if (operationStack.size() == 0) { - break; - } - topOperationLocation = getOperationPriority(operationStack.top()); - } - } - } - } - if (expression[i] != ')') { - // Add the operation to the operation stack - operationStack.push(expression[i]); - } - } - // If not a value or operation the character is ignored - } - - // Empty what's left in the stacks before finishing - while (valueStack.size() > 1 && operationStack.size() > 0) { - if (valueStack.size() < 2) { - // Must be at least two values for this loop to work properly - try { - XdmfError::message(XdmfError::FATAL, - "Error: Not Enough Values in evaluateExpression"); - } - catch (XdmfError e) { - throw e; - } - } - else { - if(operationStack.top() == '(') { - try { - XdmfError::message(XdmfError::WARNING, - "Warning: Unpaired Parenthesis"); - } - catch (XdmfError e) { - throw e; - } - } - else { - shared_ptr val2 = valueStack.top(); - valueStack.pop(); - shared_ptr val1 = valueStack.top(); - valueStack.pop(); - if (operationStack.size() == 0) { - try { - XdmfError::message(XdmfError::FATAL, - "Error: Not Enough Operators in evaluateExpression"); - } - catch (XdmfError e) { - throw e; - } - } - else { - valueStack.push(evaluateOperation(val1, val2, operationStack.top())); - operationStack.pop(); - } - } - } - } - - // Throw error if there's extra operations - if (operationStack.size() > 0) { - try { - XdmfError::message(XdmfError::WARNING, - "Warning: Left Over Operators in evaluateExpression"); - } - catch (XdmfError e) { - throw e; - } - } - - if (valueStack.size() > 1) { - try { - XdmfError::message(XdmfError::WARNING, - "Warning: Left Over Values in evaluateExpression"); - } - catch (XdmfError e) { - throw e; - } - } - - return valueStack.top(); -} - -shared_ptr -XdmfFunction::evaluateOperation(shared_ptr val1, - shared_ptr val2, - char operation) -{ - if (operations.find(operation) != operations.end()) { - return (*(shared_ptr(*)(shared_ptr, - shared_ptr))operations[operation])(val1, - val2); - } - else { - return shared_ptr(); - } -} - -int -XdmfFunction::addOperation(char newoperator, - shared_ptr(*operationref)(shared_ptr, - shared_ptr), - int priority) -{ - if (newoperator == '(' || newoperator == ')') { - try { - XdmfError::message(XdmfError::FATAL, - "Error: Parenthesis can not be redefined"); - } - catch (XdmfError e) { - throw e; - } - } - if (mValidVariableChars.find(newoperator) != std::string::npos - || mValidDigitChars.find(newoperator) != std::string::npos) { - try { - XdmfError::message(XdmfError::FATAL, - "Error: Operation Overlaps with Variables"); - } - catch (XdmfError e) { - throw e; - } - } - // Give warning if the operation already exists - size_t origsize = operations.size(); - // Place reference in the associated location - operations[newoperator] = operationref; - // It's nice to let people know they're doing this - // So they don't get surprised about changes in behavior - if (origsize == operations.size()) { - try { - XdmfError::message(XdmfError::WARNING, - "Warning: Operation Overwritten"); - } - catch (XdmfError e) { - throw e; - } - // Overwrite the existing info for that operation - // Add the priority to the specified location in the priority array - mOperationPriority[newoperator] = priority; - } - else { - // Create new operation - // Add operation to the supported character string - mSupportedOperations.push_back(newoperator); - mOperationPriority[newoperator] = priority; - } - return operations.size(); -} - -// This is how you use references to functions -shared_ptr -XdmfFunction::evaluateFunction(std::vector > valueVector, - std::string functionName) -{ - if (arrayFunctions.find(functionName) != arrayFunctions.end()) { - return (*(shared_ptr(*)(std::vector >))arrayFunctions[functionName])(valueVector); - } - else { - return shared_ptr(); - } -} - -std::string -XdmfFunction::getItemTag() const -{ - return ItemTag; -} - -std::map -XdmfFunction::getItemProperties() const -{ - std::map functionProperties; - return functionProperties; -} - -int -XdmfFunction::getOperationPriority(char operation) -{ - size_t operationLocation = mSupportedOperations.find(operation); - if (operationLocation != std::string::npos) { - return mOperationPriority[operation]; - } - else { - return -1; - } -} - - -const std::string -XdmfFunction::getSupportedOperations() -{ - return mSupportedOperations; -} - -const std::vector -XdmfFunction::getSupportedFunctions() -{ - std::vector returnVector; - for (std::map(*)(std::vector >)>::iterator functionWalker - = arrayFunctions.begin(); - functionWalker != arrayFunctions.end(); - ++functionWalker) { - returnVector.push_back(functionWalker->first); - } - return returnVector; -} - -const std::string -XdmfFunction::getValidDigitChars() -{ - return mValidDigitChars; -} - -const std::string -XdmfFunction::getValidVariableChars() -{ - return mValidVariableChars; -} - -shared_ptr -XdmfFunction::interlace(shared_ptr val1, shared_ptr val2) -{ - // Join interlace (evenly space the second array within the first one) - // Builds a new array - shared_ptr returnArray = XdmfArray::New(); - // Resize to the combined size of both arrays - // Determining what type to class it as in order to not lose data - // and to still have the smallest data type of the two - shared_ptr resultType = - XdmfArrayType::comparePrecision(val1->getArrayType(), val2->getArrayType()); - - if (resultType == XdmfArrayType::Int8()) { - char sampleValue = 0; - returnArray->resize(val1->getSize()+val2->getSize(), sampleValue); - } - else if (resultType == XdmfArrayType::Int16()) { - short sampleValue = 0; - returnArray->resize(val1->getSize()+val2->getSize(), sampleValue); - } - else if (resultType == XdmfArrayType::Int32()) { - int sampleValue = 0; - returnArray->resize(val1->getSize()+val2->getSize(), sampleValue); - } - else if (resultType == XdmfArrayType::Int64()) { - long sampleValue = 0; - returnArray->resize(val1->getSize()+val2->getSize(), sampleValue); - } - else if (resultType == XdmfArrayType::UInt8()) { - unsigned char sampleValue = 0; - returnArray->resize(val1->getSize()+val2->getSize(), sampleValue); - } - else if (resultType == XdmfArrayType::UInt16()) { - unsigned short sampleValue = 0; - returnArray->resize(val1->getSize()+val2->getSize(), sampleValue); - } - else if (resultType == XdmfArrayType::UInt32()) { - unsigned int sampleValue = 0; - returnArray->resize(val1->getSize()+val2->getSize(), sampleValue); - } - else if (resultType == XdmfArrayType::Float32()) { - float sampleValue = 0.0; - returnArray->resize(val1->getSize()+val2->getSize(), sampleValue); - } - else if (resultType == XdmfArrayType::Float64()) { - double sampleValue = 0.0; - returnArray->resize(val1->getSize()+val2->getSize(), sampleValue); - } - else if (resultType == XdmfArrayType::String()) { - std::string sampleValue = ""; - returnArray->resize(val1->getSize()+val2->getSize(), sampleValue); - } - else { - // error type not supported - XdmfError::message(XdmfError::FATAL, "Invalid type during Interlace"); - } - - // Determine ratio of array sizes - int arrayRatio1 = (int)floor(static_cast(val1->getSize())/val2->getSize()); - int arrayRatio2 = (int)floor(static_cast(val2->getSize())/val1->getSize()); - if (arrayRatio1 < 1) { - arrayRatio1 = 1; - } - if (arrayRatio2 < 1) { - arrayRatio2 = 1; - } - // Stride is equal to the ratios rounded up and added together - int stride = arrayRatio1+arrayRatio2; - int arrayExcess1 = 0; - int arrayExcess2 = 0; - for (int i = 0; i < stride; ++i) { - // Add the values of each array - // using strides to interlace and starting index to offset - // first array gets the first value of the new array - if (igetSize()/arrayRatio1; - if (((amountWritten * arrayRatio1) + i) < (int)val1->getSize()) { - amountWritten++; - } - if (amountWritten > floor(val2->getSize()/arrayRatio2)) { - arrayExcess1 += amountWritten - (int)floor(val2->getSize()/arrayRatio2); - amountWritten = (int)floor(val2->getSize()/arrayRatio2); - } - returnArray->insert(i, val1, i, amountWritten, stride, arrayRatio1); - } - else { - // Second array takes the rest - int amountWritten = val2->getSize()/arrayRatio2; - if (((amountWritten * arrayRatio2) + i) < (int)val2->getSize()) { - amountWritten++; - } - if (amountWritten > floor(val1->getSize()/arrayRatio1)) { - arrayExcess2 += amountWritten - (int)floor(val1->getSize()/arrayRatio1); - amountWritten = (int)floor(val1->getSize()/arrayRatio1); - } - returnArray->insert(i, val2, i-arrayRatio1, amountWritten, stride, arrayRatio2); - } - } - if (arrayExcess1 > 0) { - returnArray->insert(val1->getSize()+val2->getSize()-arrayExcess1, - val1, - 0, - arrayExcess1, - 1, - 1); - } - else if (arrayExcess2 > 0) { - returnArray->insert(val1->getSize()+val2->getSize()-arrayExcess2, - val2, - 0, - arrayExcess2, - 1, - 1); - } - // After all inserts are done, add the excess values to the end of the array - return returnArray; -} - -shared_ptr -XdmfFunction::sum(std::vector > values) -{ - double total = 0.0; - for (unsigned int i = 0; i < values.size(); ++i) { - for (unsigned int j = 0; j < values[i]->getSize(); ++j) { - total += values[i]->getValue(j); - } - } - shared_ptr returnArray = XdmfArray::New(); - returnArray->insert(0, total); - return returnArray; -} - diff --git a/XdmfFunction.hpp b/XdmfFunction.hpp deleted file mode 100644 index 9674bae6b70bd4246aad6a7a7468942b65a9c892..0000000000000000000000000000000000000000 --- a/XdmfFunction.hpp +++ /dev/null @@ -1,510 +0,0 @@ -/*****************************************************************************/ -/* XDMF */ -/* eXtensible Data Model and Format */ -/* */ -/* Id : XdmfFunction.hpp */ -/* */ -/* Author: */ -/* Kenneth Leiter */ -/* kenneth.leiter@arl.army.mil */ -/* US Army Research Laboratory */ -/* Aberdeen Proving Ground, MD */ -/* */ -/* Copyright @ 2011 US Army Research Laboratory */ -/* All Rights Reserved */ -/* See Copyright.txt for details */ -/* */ -/* This software is distributed WITHOUT ANY WARRANTY; without */ -/* even the implied warranty of MERCHANTABILITY or FITNESS */ -/* FOR A PARTICULAR PURPOSE. See the above copyright notice */ -/* for more information. */ -/* */ -/*****************************************************************************/ - -#ifndef XDMFFUNCTION_HPP_ -#define XDMFFUNCTION_HPP_ - -// Includes -#include "Xdmf.hpp" -#include "XdmfArray.hpp" - -/** - * @brief Manipulates arrays based on expressions. - * - * The function class provides a way to manipulate XdmfArrays via predefined functions. - */ -class XDMF_EXPORT XdmfFunction : public XdmfItem { - -public: - - /** - * Create a new XdmfFunction - * - * @return constructed XdmfFunction. - */ - static shared_ptr New(); - - virtual ~XdmfFunction(); - - LOKI_DEFINE_VISITABLE(XdmfFunction, XdmfItem); - - static const std::string ItemTag; - - /** - * Adds an operation to the list of viable operators. - * - * Example of Use: - * - * C++ - * - * @dontinclude ExampleXdmfArray.cpp - * @dontinclude ExampleXdmfArray.cpp - * @skipline //#declareoperation - * @until //#declareoperation - * @skipline //#programstart - * @until //#programstart - * @skipline //#addOperation - * @until //#addOperation - * @skipline //#programend - * @until //#programend - * @skipline //#defineoperation - * @until //#defineoperation - * - * Python - * - * @dontinclude XdmfExampleArray.py - * @skipline #//defineoperation - * @until #//defineoperation - * @skipline #//programstart - * @until #//programstart - * @skipline #//addOperation - * @until #//addOperation - * - * @param newoperator the character to be associated with the provided binary operation - * @param functionref a pointer to the function to be associated with the provided operator - * @param priority used to determine order of operations the higher the value the earlier it is evaluated - */ - static int addOperation(char newoperator, - shared_ptr(*functionref)(shared_ptr, shared_ptr), - int priority); - - /* - * adds a specified function to the list of functions used while evaluating strings - * - * C++ - * - * @dontinclude ExampleXdmfArray.cpp - * @skipline //#declarefunction - * @until //#declarefunction - * @skipline //#programstart - * @until //#programstart - * @skipline //#addFunction - * @until //#addFunction - * @skipline //#programend - * @until //#programend - * @skipline //#definefunction - * @until //#definefunction - * - * Python - * - * @dontinclude XdmfExampleArray.py - * @skipline #//definefunction - * @until #//definefunction - * @skipline #//programstart - * @until #//programstart - * @skipline #//addFunction - * @until #//addFunction - * - * @param name A string to be associated with the provided function during string evaluation - * @param functionref A pointer to the function to be associated with the given string - * @return The total number of functions currently associated - */ - static int addFunction(std::string name, - shared_ptr(*functionref)(std::vector >)); - - /** - * Averages the values contained in all the provided arrays. - * - * C++ - * - * @dontinclude ExampleXdmfArray.cpp - * @skipline //#valueinit - * @until //#valueinit - * @skipline //#average - * @until //#average - * - * Python - * - * @dontinclude XdmfExampleArray.py - * @skipline #//valueinit - * @until #//valueinit - * @skipline #//average - * @until #//average - * - * @param values a vector containing the arrays to be used - * @return an XdmfArray containing one value which is the average of all values contained within the provided arrays - */ - static shared_ptr average(std::vector > values); - - /** - * Joins the two provided arrays together end to end. - * - * Example of Use: - * - * C++ - * - * @dontinclude ExampleXdmfArray.cpp - * @skipline //#valueinit - * @until //#valueinit - * @skipline //#chunk - * @until //#chunk - * - * Python - * - * @dontinclude XdmfExampleArray.py - * @skipline #//valueinit - * @until #//valueinit - * @skipline #//chunk - * @until #//chunk - * - * @param val1 the first array being evaluated - * @param val2 the second array being evaluated - * @return the arrays joined end to end - */ - static shared_ptr chunk(shared_ptr val1, - shared_ptr val2); - - /** - * Evaluates an expression based on the list of variables provided. - * A list of valid operations is retrievable from the getSupportedOperations static method. - * None of the XdmfArrays provided are modified during the evaluation process. - * - * Example of Use: - * - * C++ - * - * @dontinclude ExampleXdmfArray.cpp - * @skipline //#declarefunction - * @until //#declarefunction - * @skipline //#declareoperation - * @until //#declareoperation - * @skipline //#programstart - * @until //#programstart - * @skipline //#valueinit - * @until //#valueinit - * @skipline //#addOperation - * @until //#addOperation - * @skipline //#addFunction - * @until //#addFunction - * @skipline //#evaluateExpression - * @until //#evaluateExpression - * @skipline //#programend - * @until //#programend - * @skipline //#definefunction - * @until //#definefunction - * @skipline //#defineoperation - * @until //#defineoperation - * - * Python - * - * @dontinclude XdmfExampleArray.py - * @skipline #//definefunction - * @until #//definefunction - * @skipline #//defineoperation - * @until #//defineoperation - * @skipline #//programstart - * @until #//programstart - * @skipline #//valueinit - * @until #//valueinit - * @skipline #//addOperation - * @until #//addOperation - * @skipline #//addFunction - * @until #//addFunction - * @skipline #//evaluateExpression - * @until #//evaluateExpression - * - * @param expression a string containing the expresion to be evaluated - * @param variables a map of strings to their XdmfArray equivalent - * @return a shared pointer to the XdmfArray resulting from the expression - */ - static shared_ptr evaluateExpression(std::string expression, - std::map > variables); - - /** - * Evaluates the operation specified using the two shared pointers to XdmfArrays provided. - * A list of valid operations is retrievable from the getSupportedOperations static method. - * None of the XdmfArrays provided are modified during the evaluation process. - * - * Example of Use: - * - * C++ - * - * @dontinclude ExampleXdmfArray.cpp - * @skipline //#declareoperation - * @until //#declareoperation - * @skipline //#programstart - * @until //#programstart - * @skipline //#valueinit - * @until //#valueinit - * @skipline //#addOperation - * @until //#addOperation - * @skipline //#evaluateOperation - * @until //#evaluateOperation - * @skipline //#programend - * @until //#programend - * @skipline //#defineoperation - * @until //#defineoperation - * - * Python - * - * @dontinclude XdmfExampleArray.py - * @skipline #//defineoperation - * @until #//defineoperation - * @skipline #//programstart - * @until #//programstart - * @skipline #//valueinit - * @until #//valueinit - * @skipline #//addOperation - * @until #//addOperation - * @skipline #//evaluateOperation - * @until #//evaluateOperation - * - * @param val1 the first array being evaluated - * @param val2 the second array being evaluated - * @param operation a character specifying the operation performed - * @return a shared pointer to the Xdmf Array that results from the calculation - */ - static shared_ptr evaluateOperation(shared_ptr val1, - shared_ptr val2, - char operation); - - /** - * Evaluates the function specified using the vector of XdmfArrays provided. - * None of the XdmfArrays provided are modified during the evaluation process. - * - * C++ - * - * @dontinclude ExampleXdmfArray.cpp - * @skipline //#declarefunction - * @until //#declarefunction - * @skipline //#programstart - * @until //#programstart - * @skipline //#valueinit - * @until //#valueinit - * @skipline //#addFunction - * @until //#addFunction - * @skipline //#evaluateFunction - * @until //#evaluateFunction - * @skipline //#programend - * @until //#programend - * @skipline //#definefunction - * @until //#definefunction - * - * Python - * - * @dontinclude XdmfExampleArray.py - * @skipline #//definefunction - * @until #//definefunction - * @skipline #//programstart - * @until #//programstart - * @skipline #//valueinit - * @until #//valueinit - * @skipline #//addFunction - * @until #//addFunction - * @skipline #//evaluateFunction - * @until #//evaluateFunction - * - * @param valueVector a vector containing the arrays to be used - * @param functionName the string associated with the function being called - * @return the result of the function being called, a scalar will be returned as an XdmfArray with one value - */ - static shared_ptr evaluateFunction(std::vector > valueVector, - std::string functionName); - - std::map getItemProperties() const; - - virtual std::string getItemTag() const; - - /** - * Gets the priority of operation whose associated character is provided. Returns -1 if the operation is not supported. - * The higher the value the earlier that operation is evaluated during evaluateExpression. - * - * Example of Use: - * - * C++ - * - * @dontinclude ExampleXdmfArray.cpp - * @skipline //#getOperationPriority - * @until //#getOperationPriority - * - * Python - * - * @dontinclude XdmfExampleArray.py - * @skipline #//getOperationPriority - * @until #//getOperationPriority - * - * @param operation the character associated with the operation to be checked - * @return the priority of the operation - */ - static int getOperationPriority(char operation); - - /** - * Gets a string that contains all the characters of the supported operations. - * Parenthesis are included for grouping purposes in expressions. - * - * Example of Use: - * - * C++ - * - * @dontinclude ExampleXdmfArray.cpp - * @skipline //#getSupportedOperations - * @until //#getSupportedOperations - * - * Python - * - * @dontinclude XdmfExampleArray.py - * @skipline #//getSupportedOperations - * @until #//getSupportedOperations - * - * @return a string containing the characters for all supported operations - */ - static const std::string getSupportedOperations(); - - /** - * Gets a string that contains all the characters of the supported operations. - * Parenthesis are included for grouping purposes in expressions. - * - * Example of Use: - * - * C++ - * - * @dontinclude ExampleXdmfArray.cpp - * @skipline //#getSupportedFunctions - * @until //#getSupportedFunctions - * - * Python - * - * @dontinclude XdmfExampleArray.py - * @skipline #//getSupportedFunctions - * @until #//getSupportedFunctions - * - * @return a vector containing the strings associated with all valid functions - */ - static const std::vector getSupportedFunctions(); - - /** - * Gets a string that contains all strings that are viable for use when mapping - * to scalars (which are stored in XdmfArrays of size 1) for the evaluateExpression function. - * - * Example of Use: - * - * C++ - * - * @dontinclude ExampleXdmfArray.cpp - * @skipline //#getValidDigitChars - * @until //#getValidDigitChars - * - * Python - * - * @dontinclude XdmfExampleArray.py - * @skipline #//getValidDigitChars - * @until #//getValidDigitChars - * - * @return a string containing all valid variable characters - */ - static const std::string getValidDigitChars(); - - /** - * Gets a string that contains all strings that are viable for use when mapping - * to shared pointers of XdmfArrays for the evaluateExpression function. - * - * Example of Use: - * - * C++ - * - * @dontinclude ExampleXdmfArray.cpp - * @skipline //#getValidVariableChars - * @until //#getValidVariableChars - * - * Python - * - * @dontinclude XdmfExampleArray.py - * @skipline #//getValidVariableChars - * @until #//getValidVariableChars - * - * @return a string containing all valid variable characters - */ - static const std::string getValidVariableChars(); - - /** - * Joins the two provided arrays while interspercing their values evenly. - * Example of Use: - * - * C++ - * - * @dontinclude ExampleXdmfArray.cpp - * @skipline //#valueinit - * @until //#valueinit - * @skipline //#interlace - * @until //#interlace - * - * Python - * - * @dontinclude XdmfExampleArray.py - * @skipline #//valueinit - * @until #//valueinit - * @skipline #//interlace - * @until #//interlace - * - * @param val1 the first array being evaluated - * @param val2 the second array being evaluated - * @return the interlaced arrays - */ - static shared_ptr interlace(shared_ptr val1, - shared_ptr val2); - - /** - * Adds together all the values contained in the provided arrays. - * - * C++ - * - * @dontinclude ExampleXdmfArray.cpp - * @skipline //#valueinit - * @until //#valueinit - * @skipline //#sum - * @until //#sum - * - * Python - * - * @dontinclude XdmfExampleArray.py - * @skipline #//valueinit - * @until #//valueinit - * @skipline #//sum - * @until #//sum - * - * @param values a vector containing the arrays to be used - * @return an XdmfArray containing one value which is the total of all the values contained within the provided arrays - */ - static shared_ptr sum(std::vector > values); - -protected: - - XdmfFunction(); - -private: - - XdmfFunction(const XdmfFunction &); // Not implemented. - void operator=(const XdmfFunction &); // Not implemented. - - - static std::string mSupportedOperations; - static const std::string mValidVariableChars; - static const std::string mValidDigitChars; - - static std::map mOperationPriority; - static std::map(*)(std::vector >)> arrayFunctions; - static std::map(*)(shared_ptr, shared_ptr)> operations; - -}; - -#endif /* XDMFFUNCTION_HPP_ */