Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Michael Wedel
committed
Apr 15, 2015
1 parent
29f209d
commit f22490c
Showing
4 changed files
with
139 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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_ */ |