Commit c3588bdf authored by snuverink_j's avatar snuverink_j
Browse files

Port IPPL simple unit tests to OPAL unit tests and cleanup

parent 12d309ea
......@@ -78,8 +78,10 @@ public:
// copy constructor
SubParticleAttribIter(const SubParticleAttribIter<PA,T,Dim> &i)
: attrib(const_cast<PA *>(i.attrib)),
dom(i.dom), lfield(i.lfield), attribOffset(i.attribOffset) { }
: dom(i.dom),
attrib(const_cast<PA *>(i.attrib)),
lfield(i.lfield),
attribOffset(i.attribOffset) { }
// default constructor
SubParticleAttribIter() : dom(0), attrib(0), attribOffset(0) { }
......
......@@ -502,7 +502,7 @@ inline void FieldDebugWriteb(BareField<T,Dim>& F)
<< endl;
(*FldDbgInform) << "****************************************"
<< "***************************************" << endl;
std::cout << "Owned = " << endl << Owned << endl;
(*FldDbgInform) << "Owned = " << endl << Owned << endl;
typename LField<T,Dim>::iterator lf_bi = ldf->begin();
if ( Dim==1 ) {
int n0 = ldf->size(0);
......
......@@ -85,9 +85,6 @@ target_link_libraries (
add_executable (chsr-1 chsr-1.cpp)
target_link_libraries (chsr-1 ${IPPL_LIBS} ${MPI_CXX_LIBRARIES} boost_timer)
add_executable (chsr-2 chsr-2.cpp)
target_link_libraries (chsr-2 ${IPPL_LIBS} ${MPI_CXX_LIBRARIES} boost_timer)
add_executable (pbconds3D pbconds3D.cpp)
target_link_libraries (pbconds3D ${IPPL_LIBS} ${MPI_CXX_LIBRARIES} boost_timer)
......
// -*- 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 http://www.acl.lanl.gov/POOMS for more details
*
***************************************************************************/
/***************************************************************************
TEST 1: testing accumulation: Field += Field
TEST 2: testing substraction: Field -= Field
TEST 3: testing multipplication: Field *= Field
TEST 4: testing division: Field *= Field
TEST 5: testing scalar addition: Field += T
TEST 6: testing scalar substraction: Field -= T
TEST 7: testing scalar multipplication: Field *= T
TEST 8: testing scalar division: Field /= T
TEST 9: testing field expression and accumulation: Field += ExprElem
TEST 10: testing field expression and substraction: Field -= ExprElem
TEST 11: testing field expression and multipplication: Field *= ExprElem
TEST 12: testing field expression and division: Field /= ExprElem
TEST 13: testing accumulation with indexed field: IndexingField += IndexingField
TEST 14: testing substraction with indexed field: IndexingField -= IndexingField
TEST 15: testing multipplication with indexed field: IndexingField *= IndexingField
TEST 16: testing division with indexed field: IndexingField /= IndexingField
TEST 17: testing accumulation with indexed field: IndexingField += T
TEST 18: testing substraction with indexed field: IndexingField -= T
TEST 19: testing multipplication with indexed field: IndexingField *= T
TEST 20: testing division with indexed field: IndexingField /= T
TEST 21: testing accumulation index: IndexingField += Index
TEST 22: testing substraction index: IndexingField -= Index
TEST 23: testing multipplication index: IndexingField *= Index
TEST 24: testing division index: IndexingField /= Index
TEST 25: testing accumulation with IndexingFields on rhs: IndexingField += ExprElem
TEST 26: testing substraction with IndexingFields on rhs: IndexingField -= ExprElem
TEST 27: testing multipplication with IndexingFields on rhs: IndexingField *= ExprElem
TEST 28: testing divisiond with IndexingFields on rhs: IndexingField /= ExprElem
// testing accumulation: IndexingField += ExprElem
// (with Fields on rhs
// // test 29
// A = 0.0;
// B = 1.0;
// C = 2.0;
// A[I][J] += B + C;
// testmsg << A << endl;
usage: chsr-2 <gridSize>
note: gridSize is used for all 6 dimensions in this testprogram
***************************************************************************/
#include "Ippl.h"
// dimension of f
const unsigned Dim = 6;
// presision
typedef double T;
// typedef our particle layout type
typedef ParticleSpatialLayout<T,Dim> playout_t;
int n;
const T pi = acos(-1.0);
const T fMax = 1.0; // maximum value for f
void notify( bool passedSingleTest, int *testNum);
void notify( bool passedSingleTest, int *testNum, Timer *t) {
Inform msg;
if (!passedSingleTest)
msg << "test "<< *testNum << " failed" << endl;
else {
msg << "test "<< *testNum << " passed";
msg << " CpuTime= " << t->clock_time() << endl;
}
(*testNum)++;
}
int main(int argc, char *argv[]){
Ippl ippl(argc, argv);
Inform msg(argv[0]);
n = atoi(argv[1]);
msg << "Dim=" << Dim << " n= "<< n << " M= " << pow(Dim,n) << endl;
// create layout objects for max DIM==6
const Index I(n), J(n), K(n); // spacial
const Index L(n), N(n), M(n); // momenta
// Initialize domain objects
NDIndex<Dim> domain, domain1;
domain[0] = n;
domain[1] = n;
domain[2] = n;
domain[3] = n;
domain1[0] = n+1;
domain1[1] = n+1;
domain1[2] = n+1;
domain1[3] = n+1;
if (Dim==6) {
domain[4] = n;
domain[5] = n;
domain1[4] = n+1;
domain1[5] = n+1;
}
UniformCartesian<Dim> mymesh(domain1);
FieldLayout<Dim> FL(domain);
int testNum = 1;
double eps = 1.0e-07;
// Flags to keep track of pass/fail results:
bool passed = true; // True at end means passed all tests
bool passedSingleTest = true; // For individual tests
Timer timer1;
timer1.clear();
timer1.start();
Field<T,Dim> A(mymesh,FL);
Field<T,Dim> B(mymesh,FL);
Field<T,Dim> C(mymesh,FL);
timer1.stop();
msg << "Static field objects created t= " << timer1.clock_time() << endl;
Field<double,Dim>::iterator fIt;
T a,b,c;
// TEST 1: testing accumulation: Field += Field
a = 0.0; b = 1.0;
timer1.clear();
timer1.start();
A = 0.0; B = 1.0;
A += B;
timer1.stop();
a += b;
passedSingleTest = true;
for (fIt=A.begin() ; fIt!=A.end(); ++fIt){
if (fabs(*fIt - a) > eps) {
passedSingleTest = false; passed = false;
fIt = A.end();
}
}
notify(passedSingleTest,&testNum,&timer1);
// --------------------------------------------
// TEST 2: testing substraction: Field -= Field
a = 0.0; b = 1.0;
timer1.clear();
timer1.start();
A = 0.0; B = 1.0;
A -= B;
timer1.stop();
a -= b;
passedSingleTest = true;
for (fIt=A.begin() ; fIt!=A.end(); ++fIt){
if (fabs(*fIt - a) > eps) {
passedSingleTest = false; passed = false;
fIt = A.end();
}
}
notify(passedSingleTest,&testNum,&timer1);
// --------------------------------------------
// TEST 3: testing multipplication: Field *= Field
a = 1.0; b = 2.0;
timer1.clear();
timer1.start();
A = 1.0; B = 2.0;
A *= B;
timer1.stop();
a *= b;
passedSingleTest = true;
for (fIt=A.begin() ; fIt!=A.end(); ++fIt){
if (fabs(*fIt - a) > eps) {
passedSingleTest = false; passed = false;
fIt = A.end();
}
}
notify(passedSingleTest,&testNum,&timer1);
// --------------------------------------------
// TEST 4: testing multipplication: Field /= Field
a = 1.0; b = 5.0;
timer1.clear();
timer1.start();
A = 1.0; B = 5.0;
A /= B;
timer1.stop();
a /= b;
passedSingleTest = true;
for (fIt=A.begin() ; fIt!=A.end(); ++fIt){
if (fabs(*fIt - a) > eps) {
passedSingleTest = false; passed = false;
fIt = A.end();
}
}
notify(passedSingleTest,&testNum,&timer1);
// --------------------------------------------
// TEST 5: testing scalar addition: Field += T
a = 1.0;
timer1.clear();
timer1.start();
A = 0.0;
A += a;
timer1.stop();
passedSingleTest = true;
for (fIt=A.begin() ; fIt!=A.end(); ++fIt){
if (fabs(*fIt - a) > eps) {
passedSingleTest = false; passed = false;
fIt = A.end();
}
}
notify(passedSingleTest,&testNum,&timer1);
// --------------------------------------------
// TEST 6: testing scalar substraction: Field -= T
a = 1.0;
timer1.clear();
timer1.start();
A = 2.0;
A -= a;
timer1.stop();
passedSingleTest = true;
for (fIt=A.begin() ; fIt!=A.end(); ++fIt){
if (fabs(*fIt - a) > eps) {
passedSingleTest = false; passed = false;
fIt = A.end();
}
}
notify(passedSingleTest,&testNum,&timer1);
// --------------------------------------------
// TEST 7: testing scalar multipplication: Field *= T
a = 2.0;
timer1.clear();
timer1.start();
A = 1.0;
A *= a;
timer1.stop();
passedSingleTest = true;
for (fIt=A.begin() ; fIt!=A.end(); ++fIt){
if (fabs(*fIt - a) > eps) {
passedSingleTest = false; passed = false;
fIt = A.end();
}
}
notify(passedSingleTest,&testNum,&timer1);
// --------------------------------------------
// TEST 8: testing scalar division: Field /= T
a = 2.0;
timer1.clear();
timer1.start();
A = 4.0;
A /= a;
timer1.stop();
passedSingleTest = true;
for (fIt=A.begin() ; fIt!=A.end(); ++fIt){
if (fabs(*fIt - a) > eps) {
passedSingleTest = false; passed = false;
fIt = A.end();
}
}
notify(passedSingleTest,&testNum,&timer1);
// --------------------------------------------
// TEST 9: testing field expression and accumulation: Field += ExprElem
a = 0.0;
b = 1.0;
c = 2.0;
timer1.clear();
timer1.start();
A = 0.0;
B = 1.0;
C = 2.0;
A += B + C;
timer1.stop();
a += b + c;
passedSingleTest = true;
for (fIt=A.begin() ; fIt!=A.end(); ++fIt){
if (fabs(*fIt - a) > eps) {
passedSingleTest = false; passed = false;
fIt = A.end();
}
}
notify(passedSingleTest,&testNum,&timer1);
// --------------------------------------------
// TEST 10: testing field expression and substraction: Field -= ExprElem
a = 0.0;
b = 1.0;
c = 2.0;
timer1.clear();
timer1.start();
A = 0.0;
B = 1.0;
C = 2.0;
A -= B + C;
timer1.stop();
a -= b + c;
passedSingleTest = true;
for (fIt=A.begin() ; fIt!=A.end(); ++fIt){
if (fabs(*fIt - a) > eps) {
passedSingleTest = false; passed = false;
fIt = A.end();
}
}
notify(passedSingleTest,&testNum,&timer1);
// --------------------------------------------
// TEST 11: testing field expression and multipplication: Field *= ExprElem
a = 1.0;
b = 2.0;
c = 3.0;
timer1.clear();
timer1.start();
A = 1.0;
B = 2.0;
C = 3.0;
A *= B + C;
timer1.stop();
a *= b + c;
passedSingleTest = true;
for (fIt=A.begin() ; fIt!=A.end(); ++fIt){
if (fabs(*fIt - a) > eps) {
passedSingleTest = false; passed = false;
fIt = A.end();
}
}
notify(passedSingleTest,&testNum,&timer1);
// --------------------------------------------
// TEST 12: testing field expression and division: Field /= ExprElem
a = 1.0;
b = 2.0;
c = 3.0;
timer1.clear();
timer1.start();
A = 1.0;
B = 2.0;
C = 3.0;
A /= B + C;
timer1.stop();
a /= b + c;
passedSingleTest = true;
for (fIt=A.begin() ; fIt!=A.end(); ++fIt){
if (fabs(*fIt - a) > eps) {
passedSingleTest = false; passed = false;
fIt = A.end();
}
}
notify(passedSingleTest,&testNum,&timer1);
// --------------------------------------------
// TEST 13: testing accumulation with indexed field: IndexingField += IndexingField
a = 0.0;
b = 1.0;
timer1.clear();
timer1.start();
A = 0.0;
B = 1.0;
A[I][J][K][L][M][N] += B[I][J][K][L][M][N];
timer1.stop();
a += b;
passedSingleTest = true;
for (fIt=A.begin() ; fIt!=A.end(); ++fIt){
if (fabs(*fIt - a) > eps) {
passedSingleTest = false; passed = false;
fIt = A.end();
}
}
notify(passedSingleTest,&testNum,&timer1);
// --------------------------------------------
// TEST 14: testing substraction with indexed field: IndexingField -= IndexingField
a = 0.0;
b = 1.0;
timer1.clear();
timer1.start();
A = 0.0;
B = 1.0;
A[I][J][K][L][M][N] -= B[I][J][K][L][M][N];
timer1.stop();
a -= b;
passedSingleTest = true;
for (fIt=A.begin() ; fIt!=A.end(); ++fIt){
if (fabs(*fIt - a) > eps) {
passedSingleTest = false; passed = false;
fIt = A.end();
}
}
notify(passedSingleTest,&testNum,&timer1);
// --------------------------------------------
// TEST 15: testing multipplication with indexed field: IndexingField *= IndexingField
a = 1.0;
b = 2.0;
timer1.clear();
timer1.start();
A = 1.0;
B = 2.0;
A[I][J][K][L][M][N] *= B[I][J][K][L][M][N];
timer1.stop();
a *= b;
passedSingleTest = true;
for (fIt=A.begin() ; fIt!=A.end(); ++fIt){
if (fabs(*fIt - a) > eps) {
passedSingleTest = false; passed = false;
fIt = A.end();
}
}
notify(passedSingleTest,&testNum,&timer1);
// --------------------------------------------
// TEST 16: testing division with indexed field: IndexingField /= IndexingField
a = 1.0;
b = 2.0;
timer1.clear();
timer1.start();
A = 1.0;
B = 2.0;
A[I][J][K][L][M][N] /= B[I][J][K][L][M][N];
timer1.stop();
a /= b;
passedSingleTest = true;
for (fIt=A.begin() ; fIt!=A.end(); ++fIt){
if (fabs(*fIt - a) > eps) {
passedSingleTest = false; passed = false;
fIt = A.end();
}
}
notify(passedSingleTest,&testNum,&timer1);
// --------------------------------------------
// TEST 17: testing accumulation with indexed field: IndexingField += T
a = 1.0;
timer1.clear();
timer1.start();
A = 0.0;
A[I][J][K][L][M][N] += a;
timer1.stop();
passedSingleTest = true;
for (fIt=A.begin() ; fIt!=A.end(); ++fIt){
if (fabs(*fIt - a) > eps) {
passedSingleTest = false; passed = false;
fIt = A.end();
}
}
notify(passedSingleTest,&testNum,&timer1);
// --------------------------------------------
// TEST 18: testing substraction with indexed field: IndexingField -= T
a = 1.0;
timer1.clear();
timer1.start();
A = 2.0;
A[I][J][K][L][M][N] -= a;
timer1.stop();
passedSingleTest = true;
for (fIt=A.begin() ; fIt!=A.end(); ++fIt){
if (fabs(*fIt - a) > eps) {
passedSingleTest = false; passed = false;
fIt = A.end();
}
}
notify(passedSingleTest,&testNum,&timer1);
// --------------------------------------------
// TEST 19: testing multipplication with indexed field: IndexingField *= T
a = 2.0;
timer1.clear();
timer1.start();
A = 1.0;
A[I][J][K][L][M][N] *= a;
timer1.stop();
passedSingleTest = true;
for (fIt=A.begin() ; fIt!=A.end(); ++fIt){
if (fabs(*fIt - a) > eps) {
passedSingleTest = false; passed = false;
fIt = A.end();
}
}
notify(passedSingleTest,&testNum,&timer1);
// --------------------------------------------
// TEST 20: testing division with indexed field: IndexingField /= T
a = 2.0;
timer1.clear();
timer1.start();
A = 4.0;
A[I][J][K][L][M][N] /= a;
timer1.stop();