Commit 99361fd6 authored by snuverink_j's avatar snuverink_j

Merge branch '570-segmentation-fault-in-unit-test-field-periodicbc' into 'master'

Resolve "segmentation fault in unit-test  Field.PeriodicBC"

Closes #570

See merge request OPAL/src!402
parents 10354343 a53f404e
// -*- C++ -*-
/***************************************************************************
*
* The IPPL Framework
*
***************************************************************************/
//
// Class LField
// Local Field class
//
// Copyright (c) 2003 - 2020, Paul Scherrer Institut, Villigen PSI, Switzerland
// All rights reserved
//
// This file is part of OPAL.
//
// OPAL is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// You should have received a copy of the GNU General Public License
// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
//
#ifndef LFIELD_H
#define LFIELD_H
......
// -*- C++ -*-
/***************************************************************************
*
* The IPPL Framework
*
* This program was prepared by PSI.
* All rights in the program are reserved by PSI.
* Neither PSI nor the author(s)
* makes any warranty, express or implied, or assumes any liability or
* responsibility for the use of this software
*
* Visit www.amas.web.psi for more details
*
***************************************************************************/
// -*- C++ -*-
/***************************************************************************
*
* The IPPL Framework
*
*
* Visit http://people.web.psi.ch/adelmann/ for more details
*
***************************************************************************/
// include files
//
// Class LField
// Local Field class
//
// Copyright (c) 2003 - 2020, Paul Scherrer Institut, Villigen PSI, Switzerland
// All rights reserved
//
// This file is part of OPAL.
//
// OPAL is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// You should have received a copy of the GNU General Public License
// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
//
#include "Field/LField.h"
#include "Utility/PAssert.h"
......@@ -714,7 +705,7 @@ LField<T,Dim>::allocateStorage(int newsize)
// Allocate the storage, creating some extra to account for offset, and
// then add in the offset.
P = new T[newsize + extra];
P = new T[newsize + extra]();
P += extra;
ADDIPPLSTAT(incLFieldBytes, (newsize+extra)*sizeof(T));
......@@ -759,10 +750,3 @@ void LField<T,Dim>::write(std::ostream& out) const
for (iterator p = begin(); p!=end(); ++p)
out << *p << " ";
}
\ No newline at end of file
/***************************************************************************
* $RCSfile: LField.cpp,v $ $Author: adelmann $
* $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:26 $
* IPPL_VERSION_ID: $Id: LField.cpp,v 1.1.1.1 2003/01/23 07:40:26 adelmann Exp $
***************************************************************************/
// -*- C++ -*-
/***************************************************************************
*
* The IPPL Framework
*
*
* Visit http://people.web.psi.ch/adelmann/ for more details
*
***************************************************************************/
//
// Class SubFieldIter
// Iterator for a subset of a BareField
//
// Copyright (c) 2003 - 2020, Paul Scherrer Institut, Villigen PSI, Switzerland
// All rights reserved
//
// This file is part of OPAL.
//
// OPAL is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// You should have received a copy of the GNU General Public License
// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
//
#ifndef SUB_FIELD_ITER_H
#define SUB_FIELD_ITER_H
......@@ -96,6 +103,7 @@
#include "Index/SIndex.h"
#include "Field/BareField.h"
#include "Field/LField.h"
#include "Utility/IpplException.h"
#include "Utility/PAssert.h"
#include "PETE/IpplExpressions.h"
......@@ -127,7 +135,11 @@ public:
MyDomain(&(const_cast<S&>(s))),
CurrentLField(ldf),
MyBrackets(B) {
if (CurrentLField != getBareField().end_if()) {
LFPtr = (*CurrentLField).second.get();
} else {
LFPtr = nullptr;
}
}
// Default constructor
......@@ -156,8 +168,16 @@ public:
// Go to the next LField.
typename BareField<T,Dim>::iterator_if nextLField() {
if (CurrentLField != getBareField().end_if()) {
++CurrentLField;
} else {
throw IpplException("SubFieldIterBase::nextLField()", "Reached the container end, no next LField!");
}
if (CurrentLField != getBareField().end_if()) {
LFPtr = (*CurrentLField).second.get();
} else {
LFPtr = nullptr;
}
return CurrentLField;
}
......@@ -620,11 +640,4 @@ private:
NDIndex<Dim> Component;
};
#endif // SUB_FIELD_ITER_H
\ No newline at end of file
/***************************************************************************
* $RCSfile: SubFieldIter.h,v $ $Author: adelmann $
* $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:33 $
* IPPL_VERSION_ID: $Id: SubFieldIter.h,v 1.1.1.1 2003/01/23 07:40:33 adelmann Exp $
***************************************************************************/
......@@ -148,7 +148,7 @@ TEST_F(NDGridTest, CoordVectorTest) { // and newCoordArray
EXPECT_NEAR(coords_v[j], gridCoordinates[i][j], 1e-12);
EXPECT_NEAR(coords_a[j], gridCoordinates[i][j], 1e-12);
}
delete coords_a;
delete[] coords_a;
}
}
......
......@@ -62,7 +62,7 @@ TEST(Field, PeriodicBC)
int i,j,k;
for (j=0; j<3; j++) {
for (i=0; i<3; i++) {
for(k=0; k<3; k++) {
for (k=0; k<3; k++) {
if (i==1 && j==1 && k==1)
assign(cA[i][j][k], 1.0);
else
......@@ -71,7 +71,11 @@ TEST(Field, PeriodicBC)
}
}
// Print reference values, then assign values ofsetting across boundaries
// and print results, Cell-centered case:
// and print results.
// For printing we need to reset the output stream (needed when running multiple tests)
setInform(*IpplInfo::Info);
// Cell-centered case:
std::cout << "++++++++++cA+++++++++++" << std::endl ;
fp3(cA);
......
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