Skip to content

Commit

Permalink
added tests for COMaligner
Browse files Browse the repository at this point in the history
git-svn-id: https://scm.projects.hlrs.de/svn/ls1/MarDyn/trunk@6285 a63bd714-7e14-4b5e-94e7-302c8c8ff188
  • Loading branch information
kruegener committed May 31, 2018
1 parent 90db3d2 commit 93f6466
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 17 deletions.
9 changes: 1 addition & 8 deletions src/plugins/COMaligner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void COMaligner::readXML(XMLfileUnits& xmlconfig){
global_log -> error() << "[COMaligner] HALTING SIMULATION" << std::endl;
_enabled = false;
// HALT SIM
global_simulation -> exit(-1);
global_simulation -> exit(1);
return;
}

Expand Down Expand Up @@ -88,13 +88,6 @@ void COMaligner::readXML(XMLfileUnits& xmlconfig){

global_log -> debug() << "[COMaligner] dim settings are: " << _dim_start << " " << _dim_end << " " << _dim_step << std::endl;

// SETUP
for (unsigned d = 0; d < 3; d++) {
_balance[d] = 0.0;
_motion[d] = 0.0;
}
_mass = 0;

}

//! @brief called before Forces are applied
Expand Down
24 changes: 15 additions & 9 deletions src/plugins/COMaligner.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
#ifndef MARDYN_TRUNK_COMALIGNER_H
#define MARDYN_TRUNK_COMALIGNER_H

class COMalignerTest;
#include "PluginBase.h"
#include "particleContainer/ParticleContainer.h"
#include "Domain.h"
#include "parallel/DomainDecompBase.h"


//! @brief
//! Plugin: can be enabled via config.xml <br>
//!
Expand All @@ -33,30 +33,36 @@
class COMaligner : public PluginBase{

private:

friend COMalignerTest;
// DEFAULT: ALIGN IN ALL DIMENSIONS
bool _alignX = true;
bool _alignY = true;
bool _alignZ = true;

bool _enabled = true;

int _dim_start;
int _dim_end;
int _dim_step;
int _dim_start = 0;
int _dim_end = 3;
int _dim_step = 1;

// DEFAULT: EVERY 25th FRAME FULL ALIGNMENT
int _interval = 25;
// DEFAULT: EVERY FRAME FULL ALIGNMENT
int _interval = 1;
float _alignmentCorrection = 1.0f;

double _motion[3];
double _balance[3];
double _mass;
double _mass = 0.0;
double _boxLength[3];
double _cutoff;

public:
COMaligner(){};
COMaligner(){
// SETUP
for (unsigned d = 0; d < 3; d++) {
_balance[d] = 0.0;
_motion[d] = 0.0;
}
};
~COMaligner(){};

void init(ParticleContainer* particleContainer, DomainDecompBase* domainDecomp, Domain* domain) override {
Expand Down
52 changes: 52 additions & 0 deletions src/plugins/tests/COMalignerTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//
// Created by kruegener on 5/31/2018.
//

#include "COMalignerTest.h"
#include "plugins/COMaligner.h"
#include "parallel/DomainDecomposition.h"
#include "particleContainer/ParticleContainer.h"
#include "particleContainer/LinkedCells.h"

TEST_SUITE_REGISTRATION(COMalignerTest);

COMalignerTest::COMalignerTest() {}

COMalignerTest::~COMalignerTest() {}

void COMalignerTest::testCOMalign() {

_domainDecomposition = new DomainDecomposition();

const char* filename = "1clj-regular-2x2x2-offset.inp";
double cutoff = 1.5;
ParticleContainer* container = initializeFromFile(ParticleContainerFactory::LinkedCell, filename, cutoff);
ParticleContainer* oldContainer = initializeFromFile(ParticleContainerFactory::LinkedCell, filename, cutoff);

COMaligner* plugin = new COMaligner();

plugin->init(container, _domainDecomposition, _domain);
plugin->beforeForces(container, _domainDecomposition, 1);

// TEST MASS
double m = plugin->_mass;
ASSERT_EQUAL_MSG("Mass does not match number of particles", double(container->getNumberOfParticles()), m);

// TEST MOTION
ASSERT_EQUAL_MSG("x motion is wrong", -.5, plugin->_motion[0]);
ASSERT_EQUAL_MSG("y motion is wrong", -.5, plugin->_motion[1]);
ASSERT_EQUAL_MSG("z motion is wrong", -.5, plugin->_motion[2]);

// TEST IF MOTION WAS APPLIED
ParticleIterator newPos = container->iterator();
ParticleIterator oldPos = oldContainer->iterator();
while(newPos.hasNext()){
for(int d = 0; d < 3; d++){
ASSERT_EQUAL_MSG("Motion has not been properly applied" ,oldPos->r(d) - .5, newPos->r(d));
}
newPos.next();
oldPos.next();
}

delete _domainDecomposition;
}
28 changes: 28 additions & 0 deletions src/plugins/tests/COMalignerTest.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// Created by kruegener on 5/31/2018.
//


#ifndef DCOMALIGNERTEST_H
#define DCOMALIGNERTEST_H

//#include "utils/Testing.h"
#include "utils/TestWithSimulationSetup.h"

class COMalignerTest : public utils::TestWithSimulationSetup {

TEST_SUITE(COMalignerTest);
TEST_METHOD(testCOMalign);
TEST_SUITE_END;

public:

COMalignerTest();

virtual ~COMalignerTest();

void testCOMalign();

};

#endif //DCOMALIGNERTEST_H
21 changes: 21 additions & 0 deletions test_input/1clj-regular-2x2x2-offset.inp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
mardyn trunk 20090721
currentTime 0.00
#rho 0.001893
# Vmax 0.006831
Temperature 0.700000
Length 3.0000 3.0000 3.0000
NumberOfComponents 1
1 0 0 0 0
0 0 0 1 1 1 1 0
0 0 0
1e+10
NumberOfMolecules 8
MoleculeFormat ICRV
1 1 1.500000 1.500000 1.500000 0.0 0.0 0.0
2 1 2.500000 1.500000 1.500000 0.0 0.0 0.0
3 1 1.500000 2.500000 1.500000 0.0 0.0 0.0
4 1 2.500000 2.500000 1.500000 0.0 0.0 0.0
5 1 1.500000 1.500000 2.500000 0.0 0.0 0.0
6 1 2.500000 1.500000 2.500000 0.0 0.0 0.0
7 1 1.500000 2.500000 2.500000 0.0 0.0 0.0
8 1 2.500000 2.500000 2.500000 0.0 0.0 0.0

0 comments on commit 93f6466

Please sign in to comment.