35 std::cout <<
"Running HelperFunctionsUnitTest" << std::endl;
37 std::cout <<
" Testing getSaveCountFromNumberOfSavesAndTimeMaxAndTimestep" << std::endl;
41 logger(
ERROR,
"save count is %, but should be %", saveCount, 501);
44 std::cout <<
" Testing getLineFromStringStream" << std::endl;
45 std::stringstream is(
"1.0\n2.000000000000001\n3.0");
46 std::stringstream line(std::stringstream::in | std::stringstream::out);
49 line >> value >> value;
52 logger(
ERROR,
"value is %, but should be %", value, 0.0);
57 if (value != 2.000000000000001)
59 logger(
ERROR,
"value is %, but should be %", value, 2.000000000000001);
62 std::cout <<
" Testing writeToFile, openFile" << std::endl;
65 "0.5 0.5 0 0 0 0.5 0 0 0 0 0 0 0 0\n");
72 logger(
ERROR,
"value is %, but should be %", value, 1.0);
75 std::cout <<
" Testing writeToFile, openFile" << std::endl;
77 if (fileExists !=
true)
79 logger(
ERROR,
"HelperFunctionsUnitTest.ini exists, but is not detected");
82 if (fileExists !=
false)
84 logger(
ERROR,
"HelperFunctionsUnitTest.out does not exist, but is detected");
87 std::cout <<
" Testing getEffectiveMass" << std::endl;
91 logger(
ERROR,
"effective mass is %, but should be %", effectiveMass, 2.0/3.0);
95 std::cout <<
"Running LinearViscoelasticSpecies helper functions unit test" << std::endl;
100 Mdouble realCollisionTime = 0.004971179385062563;
101 Mdouble realRestitution = 0.883132984295725;
102 Mdouble realMaximumVelocity = 316.227766016838;
105 species0.setStiffness(realStiffness);
106 species0.setDissipation(realDissipation);
108 std::cout <<
" Testing getMaximumVelocity" << std::endl;
109 Mdouble maximumVelocity = species0.getMaximumVelocity(radius, mass);
113 logger(
ERROR,
"maximum velocity is %, but should be %", maximumVelocity, realMaximumVelocity);
116 std::cout <<
" Testing getCollisionTime, getRestitutionCoefficient" << std::endl;
117 Mdouble collisionTime = species0.getCollisionTime(mass);
118 Mdouble restitution = species0.getRestitutionCoefficient(mass);
121 logger(
ERROR,
"collision time is %, but should be %", collisionTime, realCollisionTime);
125 logger(
ERROR,
"restitution coefficient is %, but should be %", restitution, realRestitution);
128 std::cout <<
" Testing setStiffnessAndRestitutionCoefficient" << std::endl;
129 species0.setStiffnessAndRestitutionCoefficient(realStiffness, realRestitution, mass);
132 logger(
ERROR,
"stiffness is %, but should be %", species0.getStiffness(), realStiffness);
136 logger(
ERROR,
"dissipation is %, but should be %", species0.getDissipation(), realDissipation);
139 std::cout <<
" Testing setCollisionTimeAndRestitutionCoefficient" << std::endl;
140 species0.setCollisionTimeAndRestitutionCoefficient(realCollisionTime, realRestitution, mass);
143 logger(
ERROR,
"stiffness is %, but should be %", species0.getStiffness(), realStiffness);
147 logger(
ERROR,
"dissipation is %, but should be %", species0.getDissipation(), realDissipation);
150 std::cout <<
" Testing setCollisionTimeAndRestitutionCoefficient for two masses" << std::endl;
151 species0.setCollisionTimeAndRestitutionCoefficient(realCollisionTime, realRestitution, mass, mass);
154 logger(
ERROR,
"stiffness is %, but should be %", species0.getStiffness(), realStiffness);
158 logger(
ERROR,
"dissipation is %, but should be %", species0.getDissipation(), realDissipation);
161 std::cout <<
" Testing copy constructor" << std::endl;
165 logger(
ERROR,
"stiffness is %, but should be %", species1.getStiffness(), realStiffness);
169 logger(
ERROR,
"dissipation is %, but should be %", species1.getDissipation(), realDissipation);
172 std::cout <<
" Testing mix" << std::endl;
174 species2.
mixAll(&species0, &species1);
177 logger(
ERROR,
"stiffness is %, but should be %", species2.getStiffness(), realStiffness);
181 logger(
ERROR,
"dissipation is %, but should be %", species2.getDissipation(), realDissipation);
184 std::cout <<
"Running LinearPlasticViscoelasticSpecies helper functions unit test" << std::endl;
187 std::cout <<
" Testing setPlasticParameters" << std::endl;
188 species3.setPlasticParameters(realStiffness, 2.0 * realStiffness, 0.5 * realStiffness, 0.5);
191 logger(
ERROR,
"stiffness is %, but should be %", species3.getLoadingStiffness(), realStiffness);
193 if (!
mathsFunc::isEqual(species3.getUnloadingStiffnessMax(), 2.0 * realStiffness, 1e-10))
195 logger(
ERROR,
"max. unloading stiffness is %, but should be %", species3.getUnloadingStiffnessMax(), 2.0 * realStiffness);
199 logger(
ERROR,
"max. unloading stiffness is %, but should be %", species3.getCohesionStiffness(), 0.5 * realStiffness);
203 logger(
ERROR,
"dissipation is %, but should be %", species3.getPenetrationDepthMax(), 0.5);
206 std::cout <<
" Testing setCollisionTimeAndRestitutionCoefficient" << std::endl;
207 species3.setCollisionTimeAndRestitutionCoefficient(realCollisionTime, realRestitution, mass);
210 logger(
ERROR,
"stiffness is %, but should be %", species3.getLoadingStiffness(), realStiffness);
214 logger(
ERROR,
"max. unloading stiffness is %, but should be %", species3.getUnloadingStiffnessMax(), realStiffness);
218 logger(
ERROR,
"dissipation is %, but should be %", species3.getDissipation(), realDissipation);
221 std::cout <<
" Testing computeTimeStep" << std::endl;
222 Mdouble timeStep = species3.computeTimeStep(mass);
225 logger(
ERROR,
"time step is %, but should be %", timeStep, 0.02 * realCollisionTime);
bool writeToFile(std::string filename, std::string filecontent)
Writes a string to a file.
Mdouble getEffectiveMass(Mdouble mass0, Mdouble mass1)
Calculates the effective mass of a particle pair, i.e. half the harmonic mean of two particle masses...
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
void mixAll(BaseSpecies *const S, BaseSpecies *const T)
sets the MixedSpecies properties by mixing the properties of two particle species ...
LL< Log::ERROR > ERROR
Error log level.
int main(int argc UNUSED, char *argv[] UNUSED)
void getLineFromStringStream(std::istream &in, std::stringstream &out)
Reads a line from one stringstream into another, and prepares the latter for reading in...
bool isEqual(Mdouble v1, Mdouble v2, double absError)
Compares the difference of two Mdouble with an absolute error, useful in UnitTests.
Contains contact force properties for contacts between particles with two different species...
Contains material and contact force properties.
bool fileExists(std::string strFilename)
Function to check if a file exists, is used to check if a run has already need done.
bool openFile(std::fstream &file, std::string filename, std::fstream::openmode mode)
Provides a simple interface for opening a file.
unsigned int getSaveCountFromNumberOfSavesAndTimeMaxAndTimestep(unsigned int numberOfSaves, Mdouble timeMax, Mdouble timestep)
Returns the correct saveCount if the total number of saves, the final time and the time step is known...