Commit 12cdf566 authored by Andrew J. Burns (Cont's avatar Andrew J. Burns (Cont
Browse files

Fixing issues with arrays not currently read to disk when dealing with functions

parent 7cd77983
......@@ -191,9 +191,17 @@ XdmfFunction::abs(std::vector<shared_ptr<XdmfArray> > values)
XdmfError::message(XdmfError::FATAL,
"Error: No Array Passed to Function abs");
}
bool release = false;
if (!values[0]->getIsInitialized()) {
values[0]->read();
release = true;
}
for (unsigned int i = 0; i < values[0]->getSize(); ++i) {
returnArray->pushBack(std::abs(values[0]->getValue<double>(i)));
}
if (release) {
values[0]->release();
}
return returnArray;
}
......@@ -283,6 +291,16 @@ shared_ptr<XdmfArray>
XdmfFunction::addition(shared_ptr<XdmfArray> val1, shared_ptr<XdmfArray> val2)
{
shared_ptr<XdmfArray> returnArray = XdmfArray::New();
bool release1 = false;
bool release2 = false;
if (!val1->isInitialized()) {
val1->read();
release1 = true;
}
if (!val2->isInitialized()) {
val2->read();
release2 = true;
}
for (unsigned int i = 0; i < val1->getSize() || i < val2->getSize(); ++i) {
if (val1->getSize() == val2->getSize()) {
returnArray->pushBack(val1->getValue<double>(i) + val2->getValue<double>(i));
......@@ -298,6 +316,12 @@ XdmfFunction::addition(shared_ptr<XdmfArray> val1, shared_ptr<XdmfArray> val2)
"Error: Array Size Mismatch in Function addition");
}
}
if (release1) {
val1->release()
}
if (release2) {
val2->release()
}
return returnArray;
}
......@@ -310,9 +334,17 @@ XdmfFunction::arcsin(std::vector<shared_ptr<XdmfArray> > values)
XdmfError::message(XdmfError::FATAL,
"Error: No Array Passed to Function arcsin");
}
bool release = false;
if (!values[0]->getIsInitialized()) {
values[0]->read();
release = true;
}
for (unsigned int i = 0; i < values[0]->getSize(); ++i) {
returnArray->pushBack(asin(values[0]->getValue<double>(i)));
}
if (release) {
values[0]->release();
}
return returnArray;
}
......@@ -325,9 +357,17 @@ XdmfFunction::arccos(std::vector<shared_ptr<XdmfArray> > values)
XdmfError::message(XdmfError::FATAL,
"Error: No Array Passed to Function arccos");
}
bool release = false;
if (!values[0]->getIsInitialized()) {
values[0]->read();
release = true;
}
for (unsigned int i = 0; i < values[0]->getSize(); ++i) {
returnArray->pushBack(acos(values[0]->getValue<double>(i)));
}
if (release) {
values[0]->release();
}
return returnArray;
}
......@@ -340,9 +380,17 @@ XdmfFunction::arctan(std::vector<shared_ptr<XdmfArray> > values)
XdmfError::message(XdmfError::FATAL,
"Error: No Array Passed to Function arctan");
}
bool release = false;
if (!values[0]->getIsInitialized()) {
values[0]->read();
release = true;
}
for (unsigned int i = 0; i < values[0]->getSize(); ++i) {
returnArray->pushBack(atan(values[0]->getValue<double>(i)));
}
if (release) {
values[0]->release();
}
return returnArray;
}
......@@ -369,9 +417,17 @@ XdmfFunction::cos(std::vector<shared_ptr<XdmfArray> > values)
XdmfError::message(XdmfError::FATAL,
"Error: No Array Passed to Function cos");
}
bool release = false;
if (!values[0]->getIsInitialized()) {
values[0]->read();
release = true;
}
for (unsigned int i = 0; i < values[0]->getSize(); ++i) {
returnArray->pushBack(std::cos(values[0]->getValue<double>(i)));
}
if (release) {
values[0]->release();
}
return returnArray;
}
......@@ -386,7 +442,16 @@ XdmfFunction::chunk(shared_ptr<XdmfArray> val1, shared_ptr<XdmfArray> val2)
shared_ptr<const XdmfArrayType> resultType =
XdmfArrayType::comparePrecision(val1->getArrayType(),
val2->getArrayType());
bool release1 = false;
bool release2 = false;
if (!val1->isInitialized()) {
val1->read();
release1 = true;
}
if (!val2->isInitialized()) {
val2->read();
release2 = true;
}
if (resultType == XdmfArrayType::Int8()) {
char sampleValue = 0;
returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
......@@ -433,6 +498,12 @@ XdmfFunction::chunk(shared_ptr<XdmfArray> val1, shared_ptr<XdmfArray> val2)
}
returnArray->insert(0, val1, 0, val1->getSize(), 1, 1);
returnArray->insert(val1->getSize(), val2, 0, val2->getSize(), 1, 1);
if (release1) {
val1->release()
}
if (release2) {
val2->release()
}
return returnArray;
}
......@@ -445,6 +516,16 @@ XdmfFunction::exponent(std::vector<shared_ptr<XdmfArray> > values)
XdmfError::message(XdmfError::FATAL,
"Error: Two Arrays Needed for Function exponent");
}
bool release1 = false;
bool release2 = false;
if (!values[0]->isInitialized()) {
values[0]->read();
release1 = true;
}
if (!values[1]->isInitialized()) {
values[1]->read();
release2 = true;
}
for (unsigned int i = 0; i < values[0]->getSize() || i < values[1]->getSize(); ++i) {
if (values[0]->getSize() == values[1]->getSize()) {
returnArray->pushBack(std::pow(values[0]->getValue<double>(i), values[1]->getValue<double>(i)));
......@@ -460,12 +541,28 @@ XdmfFunction::exponent(std::vector<shared_ptr<XdmfArray> > values)
"Error: Array Size Mismatch in Function exponent");
}
}
if (release1) {
values[0]->release()
}
if (release2) {
values[1]->release()
}
return returnArray;
}
shared_ptr<XdmfArray>
XdmfFunction::division(shared_ptr<XdmfArray> val1, shared_ptr<XdmfArray> val2)
{
bool release1 = false;
bool release2 = false;
if (!val1->isInitialized()) {
val1->read();
release1 = true;
}
if (!val2->isInitialized()) {
val2->read();
release2 = true;
}
shared_ptr<XdmfArray> returnArray = XdmfArray::New();
for (unsigned int i = 0; i < val1->getSize() || i < val2->getSize(); ++i) {
if (val1->getSize() == val2->getSize()) {
......@@ -482,6 +579,12 @@ XdmfFunction::division(shared_ptr<XdmfArray> val1, shared_ptr<XdmfArray> val2)
"Error: Array Size Mismatch in Function division");
}
}
if (release1) {
val1->release()
}
if (release2) {
val2->release()
}
return returnArray;
}
......@@ -862,7 +965,16 @@ XdmfFunction::interlace(shared_ptr<XdmfArray> val1, shared_ptr<XdmfArray> val2)
// and to still have the smallest data type of the two
shared_ptr<const XdmfArrayType> resultType =
XdmfArrayType::comparePrecision(val1->getArrayType(), val2->getArrayType());
bool release1 = false;
bool release2 = false;
if (!val1->isInitialized()) {
val1->read();
release1 = true;
}
if (!val2->isInitialized()) {
val2->read();
release2 = true;
}
if (resultType == XdmfArrayType::Int8()) {
char sampleValue = 0;
returnArray->resize(val1->getSize()+val2->getSize(), sampleValue);
......@@ -966,6 +1078,12 @@ XdmfFunction::interlace(shared_ptr<XdmfArray> val1, shared_ptr<XdmfArray> val2)
1);
}
// After all inserts are done, add the excess values to the end of the array
if (release1) {
val1->release()
}
if (release2) {
val2->release()
}
return returnArray;
}
......@@ -999,6 +1117,18 @@ XdmfFunction::log(std::vector<shared_ptr<XdmfArray> > values)
XdmfError::message(XdmfError::FATAL,
"Error: No Array Passed to Function log");
}
bool release1 = false;
bool release2 = false;
if (!values[0]->isInitialized()) {
values[0]->read();
release1 = true;
}
if (values.size() > 1) {
if (!values[1]->isInitialized()) {
values[1]->read();
release2 = true;
}
}
for (unsigned int i = 0; i < values[0]->getSize(); ++i) {
if (values.size() > 1) {
if (values[0]->getSize() == values[1]->getSize()) {
......@@ -1016,6 +1146,12 @@ XdmfFunction::log(std::vector<shared_ptr<XdmfArray> > values)
returnArray->pushBack(std::log(values[0]->getValue<double>(i)));
}
}
if (release1) {
values[0]->release()
}
if (release2) {
values[1]->release()
}
return returnArray;
}
......@@ -1023,6 +1159,16 @@ shared_ptr<XdmfArray>
XdmfFunction::multiplication(shared_ptr<XdmfArray> val1, shared_ptr<XdmfArray> val2)
{
shared_ptr<XdmfArray> returnArray = XdmfArray::New();
bool release1 = false;
bool release2 = false;
if (!val1->isInitialized()) {
val1->read();
release1 = true;
}
if (!val2->isInitialized()) {
val2->read();
release2 = true;
}
for (unsigned int i = 0; i < val1->getSize() || i < val2->getSize(); ++i) {
if (val1->getSize() == val2->getSize()) {
returnArray->pushBack(val1->getValue<double>(i) * val2->getValue<double>(i));
......@@ -1038,6 +1184,12 @@ XdmfFunction::multiplication(shared_ptr<XdmfArray> val1, shared_ptr<XdmfArray> v
"Error: Array Size Mismatch in Function multiplication");
}
}
if (release1) {
val1->release()
}
if (release2) {
val2->release()
}
return returnArray;
}
......@@ -1073,9 +1225,17 @@ XdmfFunction::sin(std::vector<shared_ptr<XdmfArray> > values)
XdmfError::message(XdmfError::FATAL,
"Error: No Array Passed to Function sin");
}
bool release = false;
if (!values[0]->getIsInitialized()) {
values[0]->read();
release = true;
}
for (unsigned int i = 0; i < values[0]->getSize(); ++i) {
returnArray->pushBack(std::sin(values[0]->getValue<double>(i)));
}
if (release) {
values[0]->release();
}
return returnArray;
}
......@@ -1088,9 +1248,17 @@ XdmfFunction::sqrt(std::vector<shared_ptr<XdmfArray> > values)
XdmfError::message(XdmfError::FATAL,
"Error: No Array Passed to Function sqrt");
}
bool release = false;
if (!values[0]->getIsInitialized()) {
values[0]->read();
release = true;
}
for (unsigned int i = 0; i < values[0]->getSize(); ++i) {
returnArray->pushBack(std::sqrt(values[0]->getValue<double>(i)));
}
if (release) {
values[0]->release();
}
return returnArray;
}
......@@ -1098,6 +1266,16 @@ shared_ptr<XdmfArray>
XdmfFunction::subtraction(shared_ptr<XdmfArray> val1, shared_ptr<XdmfArray> val2)
{
shared_ptr<XdmfArray> returnArray = XdmfArray::New();
bool release1 = false;
bool release2 = false;
if (!val1->isInitialized()) {
val1->read();
release1 = true;
}
if (!val2->isInitialized()) {
val2->read();
release2 = true;
}
for (unsigned int i = 0; i < val1->getSize() || i < val2->getSize(); ++i) {
if (val1->getSize() == val2->getSize()) {
returnArray->pushBack(val1->getValue<double>(i) - val2->getValue<double>(i));
......@@ -1113,6 +1291,12 @@ XdmfFunction::subtraction(shared_ptr<XdmfArray> val1, shared_ptr<XdmfArray> val2
"Error: Array Size Mismatch in Function subtraction");
}
}
if (release1) {
val1->release()
}
if (release2) {
val2->release()
}
return returnArray;
}
......@@ -1120,10 +1304,19 @@ shared_ptr<XdmfArray>
XdmfFunction::sum(std::vector<shared_ptr<XdmfArray> > values)
{
double total = 0.0;
bool release = false;
for (unsigned int i = 0; i < values.size(); ++i) {
release = false;
if (!values[i]->getIsInitialized()) {
values[i]->read();
release = true;
}
for (unsigned int j = 0; j < values[i]->getSize(); ++j) {
total += values[i]->getValue<double>(j);
}
if (release) {
values[i]->release();
}
}
shared_ptr<XdmfArray> returnArray = XdmfArray::New();
returnArray->insert(0, total);
......@@ -1139,9 +1332,17 @@ XdmfFunction::tan(std::vector<shared_ptr<XdmfArray> > values)
XdmfError::message(XdmfError::FATAL,
"Error: No Array Passed to Function tan");
}
bool release = false;
if (!values[0]->getIsInitialized()) {
values[0]->read();
release = true;
}
for (unsigned int i = 0; i < values[0]->getSize(); ++i) {
returnArray->pushBack(std::tan(values[0]->getValue<double>(i)));
}
if (release) {
values[0]->release();
}
return returnArray;
}
......
......@@ -331,7 +331,8 @@ public:
* @skipline #//addition
* @until #//addition
*
* @param values A vector containing the array to be used
* @param val1 The first Array to be used
* @param val2 The second Array to be used
* @return An XdmfArray containing the sums
* of the values of the arrays
*/
......@@ -521,7 +522,8 @@ public:
* @skipline #//division
* @until #//division
*
* @param values A vector containing the array to be used
* @param val1 The array to be divided
* @param val2 The array to be divided by
* @return An XdmfArray containing the results
* of the division of the arrays
*/
......@@ -1072,7 +1074,8 @@ public:
* @skipline #//multiplication
* @until #//multiplication
*
* @param values A vector containing the array to be used
* @param val1 The first array to be used
* @param val2 The second array to be used
* @return An XdmfArray containing the products
* of the multiplication of the arrays
*/
......@@ -1235,7 +1238,8 @@ public:
* @skipline #//subtraction
* @until #//subtraction
*
* @param values A vector containing the array to be used
* @param val1 The array to be subtracted from
* @param val2 The array to be subtracted
* @return An XdmfArray containing the difference
* of the arrays
*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment