Skip to content

Commit

Permalink
#735 Adding failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
mobernabeu committed Mar 12, 2020
1 parent e7570ae commit 3f7ea8e
Show file tree
Hide file tree
Showing 8 changed files with 3,377 additions and 3 deletions.
8 changes: 6 additions & 2 deletions Code/redblood/Mesh.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ namespace hemelb
return result;
}

std::shared_ptr<MeshData> readMesh(std::istream &stream)
std::shared_ptr<MeshData> readMesh(std::istream &stream, bool fixFacetOrientation)
{
log::Logger::Log<log::Debug, log::Singleton>("Reading red blood cell from stream");

Expand Down Expand Up @@ -132,7 +132,10 @@ namespace hemelb
num_vertices,
num_facets);

orientFacets(*result);
if (fixFacetOrientation)
{
orientFacets(*result);
}
return result;
}

Expand Down Expand Up @@ -704,6 +707,7 @@ namespace hemelb
std::swap(facet[0], facet[2]);
}
}

}
}
} // hemelb::redblood
2 changes: 1 addition & 1 deletion Code/redblood/Mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ namespace hemelb
std::shared_ptr<MeshData> readMesh(std::string const &filename, util::UnitConverter const &);
//! Read mesh from file
//! Format is from T. Krueger's thesis
std::shared_ptr<MeshData> readMesh(std::istream &stream);
std::shared_ptr<MeshData> readMesh(std::istream &stream, bool fixFacetOrientation=true);
std::shared_ptr<MeshData> readMesh(std::istream &stream, util::UnitConverter const &);
//! Write mesh from file
//! Format is from T. Krueger's thesis
Expand Down
3 changes: 3 additions & 0 deletions Code/unittests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,7 @@ add_to_resources(resources/four_cube.gmy resources/four_cube.xml
resources/cyl_l100_r5.xml
resources/cyl_l100_r5.gmy
resources/rbc_ico_2880.msh
resources/rbc_ico_720_correct.msh
resources/rbc_ico_720.msh
resources/992Particles_rank3_26_t992.msh
)
1 change: 1 addition & 0 deletions Code/unittests/redblood.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,6 @@ namespace hemelb
#include "unittests/redblood/WallCellPairIteratorTests.h"
#include "unittests/redblood/NodeIntegrationTests.h"
#include <unittests/redblood/parallel/NodeParallelizationTests.h>
#include "unittests/redblood/LoadingTimmMeshTests.h"
#undef HEMELB_DOING_UNITTESTS
#endif
93 changes: 93 additions & 0 deletions Code/unittests/redblood/LoadingTimmMeshTests.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
//
// Copyright (C) University College London, 2007-2012, all rights reserved.
//
// This file is part of HemeLB and is CONFIDENTIAL. You may not work
// with, install, use, duplicate, modify, redistribute or share this
// file, or any part thereof, other than as allowed by any agreement
// specifically made by you with University College London.
//

#ifndef HEMELB_UNITTESTS_TIMM_MESH_H
#define HEMELB_UNITTESTS_TIMM_MESH_H

#include <sstream>
#include <cppunit/TestFixture.h>
#include "resources/Resource.h"
#include "redblood/Mesh.h"
#include "unittests/redblood/Fixtures.h"

namespace hemelb
{
namespace unittests
{
namespace redblood
{
// Tests we can load .msh files output by Timm's code
class LoadingTimmMeshTests : public BasisFixture
{
CPPUNIT_TEST_SUITE (LoadingTimmMeshTests);
CPPUNIT_TEST (testWrongIcoFile);
CPPUNIT_TEST (testCorrectedIcoFile);
CPPUNIT_TEST (testSimulationOutputFile);
CPPUNIT_TEST_SUITE_END();

public:
void setUp()
{
}

bool checkMeshOrientation(MeshData const &mesh)
{
MeshData copy(mesh);
orientFacets(copy);
for (size_t i(0); i < mesh.facets.size(); ++i)
{
if (mesh.facets[i] != copy.facets[i])
{
return false;
}
}
return true;
}

std::shared_ptr<MeshData> readMeshFromFileNoFix(const std::string filename)
{
auto fullPath = resources::Resource(filename).Path();
CPPUNIT_ASSERT(util::file_exists(fullPath.c_str()));

std::ifstream file;
file.open(fullPath);

return readMesh(file, false);
}

void testWrongIcoFile()
{
// This is one of Timm's original ico files and has a face with the wrong vertex orientation leading to an inward pointing normal
// Loading it without fixing face orientation should lead to inconsistent orientation
auto mesh = readMeshFromFileNoFix("rbc_ico_720.msh");
CPPUNIT_ASSERT(!checkMeshOrientation(*mesh));
}

void testCorrectedIcoFile()
{
// This is the same ico file with the face fixed
// Loading it without fixing face orientation should be fine
auto mesh = readMeshFromFileNoFix("rbc_ico_720_correct.msh");
CPPUNIT_ASSERT(checkMeshOrientation(*mesh));
}

void testSimulationOutputFile()
{
// This is a mesh taken from a simulation in Timm's code, which should have correct face orientation by definition
auto mesh = readMeshFromFileNoFix("992Particles_rank3_26_t992.msh");
CPPUNIT_ASSERT(checkMeshOrientation(*mesh));
}
};

CPPUNIT_TEST_SUITE_REGISTRATION (LoadingTimmMeshTests);
}
}
}

#endif // ONCE
Loading

0 comments on commit 3f7ea8e

Please sign in to comment.