Skip to content

Commit

Permalink
Refs #11551. Added LatticeDomain
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Wedel committed Apr 15, 2015
1 parent 29f209d commit f22490c
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Code/Mantid/Framework/API/CMakeLists.txt
Expand Up @@ -76,6 +76,7 @@ set ( SRC_FILES
src/ImplicitFunctionParserFactory.cpp
src/InstrumentDataService.cpp
src/JointDomain.cpp
src/LatticeDomain.cpp
src/LinearScale.cpp
src/LiveListenerFactory.cpp
src/LogManager.cpp
Expand Down Expand Up @@ -242,6 +243,7 @@ set ( INC_FILES
inc/MantidAPI/InstrumentDataService.h
inc/MantidAPI/Jacobian.h
inc/MantidAPI/JointDomain.h
inc/MantidAPI/LatticeDomain.h
inc/MantidAPI/LinearScale.h
inc/MantidAPI/LiveListenerFactory.h
inc/MantidAPI/LogManager.h
Expand Down Expand Up @@ -348,6 +350,7 @@ set ( TEST_FILES
ImplicitFunctionParserFactoryTest.h
IncreasingAxisValidatorTest.h
InstrumentDataServiceTest.h
LatticeDomainTest.h
LiveListenerFactoryTest.h
LogManagerTest.h
MDGeometryTest.h
Expand Down
55 changes: 55 additions & 0 deletions Code/Mantid/Framework/API/inc/MantidAPI/LatticeDomain.h
@@ -0,0 +1,55 @@
#ifndef MANTID_API_LATTICEDOMAIN_H_
#define MANTID_API_LATTICEDOMAIN_H_

#include "MantidAPI/DllConfig.h"
#include "MantidAPI/FunctionDomain.h"
#include "MantidKernel/V3D.h"

namespace Mantid {
namespace API {

/** LatticeDomain
This domain stores V3D-objects as HKLs instead of double-values. It can be
used to refine lattice parameters from HKL/d-pairs.
@author Michael Wedel, Paul Scherrer Institut - SINQ
@date 15/04/2015
Copyright © 2015 PSI-NXMM
This file is part of Mantid.
Mantid 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.
Mantid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://github.com/mantidproject/mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class MANTID_API_DLL LatticeDomain : public FunctionDomain {
public:
LatticeDomain(const std::vector<Kernel::V3D> &hkls);
virtual ~LatticeDomain() {}

size_t size() const;

const Kernel::V3D &operator[](size_t i) const;

protected:
std::vector<Kernel::V3D> m_hkls;
};

} // namespace API
} // namespace Mantid

#endif /* MANTID_API_LATTICEDOMAIN_H_ */
20 changes: 20 additions & 0 deletions Code/Mantid/Framework/API/src/LatticeDomain.cpp
@@ -0,0 +1,20 @@
#include "MantidAPI/LatticeDomain.h"
#include "MantidKernel/Exception.h"
namespace Mantid {
namespace API {

LatticeDomain::LatticeDomain(const std::vector<Kernel::V3D> &hkls)
: m_hkls(hkls) {}

size_t LatticeDomain::size() const { return m_hkls.size(); }

const Kernel::V3D &LatticeDomain::operator[](size_t i) const {
if (i >= m_hkls.size()) {
throw Kernel::Exception::IndexError(i, m_hkls.size() - 1,
"Index exceeds size of LatticeDomain.");
}
return m_hkls[i];
}

} // namespace API
} // namespace Mantid
61 changes: 61 additions & 0 deletions Code/Mantid/Framework/API/test/LatticeDomainTest.h
@@ -0,0 +1,61 @@
#ifndef MANTID_API_LATTICEDOMAINTEST_H_
#define MANTID_API_LATTICEDOMAINTEST_H_

#include <cxxtest/TestSuite.h>

#include "MantidAPI/LatticeDomain.h"
#include "MantidKernel/Exception.h"

using Mantid::API::LatticeDomain;
using Mantid::Kernel::V3D;
using Mantid::Kernel::Exception::IndexError;

using namespace Mantid::API;

class LatticeDomainTest : public CxxTest::TestSuite {
public:
// This pair of boilerplate methods prevent the suite being created statically
// This means the constructor isn't called when running other tests
static LatticeDomainTest *createSuite() { return new LatticeDomainTest(); }
static void destroySuite(LatticeDomainTest *suite) { delete suite; }

void testConstruction() {
std::vector<V3D> hkls;
hkls.push_back(V3D(1, 1, 1));
hkls.push_back(V3D(2, 1, 0));
hkls.push_back(V3D(0, 0, 1));

TS_ASSERT_THROWS_NOTHING(LatticeDomain domain(hkls));

std::vector<V3D> empty;
TS_ASSERT_THROWS_NOTHING(LatticeDomain domain(empty));
}

void testSize() {
std::vector<V3D> hkls;
hkls.push_back(V3D(1, 1, 1));
hkls.push_back(V3D(2, 1, 0));
hkls.push_back(V3D(0, 0, 1));

LatticeDomain domain(hkls);

TS_ASSERT_EQUALS(domain.size(), hkls.size());
}

void testAccess() {
std::vector<V3D> hkls;
hkls.push_back(V3D(1, 1, 1));
hkls.push_back(V3D(2, 1, 0));
hkls.push_back(V3D(0, 0, 1));

LatticeDomain domain(hkls);

TS_ASSERT_THROWS_NOTHING(domain[0]);
TS_ASSERT_THROWS_NOTHING(domain[1]);
TS_ASSERT_THROWS_NOTHING(domain[2]);

TS_ASSERT_THROWS(domain[3], IndexError)
}
};

#endif /* MANTID_API_LATTICEDOMAINTEST_H_ */

0 comments on commit f22490c

Please sign in to comment.