Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
mantid
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mantidproject
mantid
Commits
2ea79abe
Commit
2ea79abe
authored
10 years ago
by
Owen Arnold
Browse files
Options
Downloads
Patches
Plain Diff
refs #11393. Use OMP macros.
parent
1b51c6b6
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Code/Mantid/Framework/MDAlgorithms/inc/MantidMDAlgorithms/SmoothMD.h
+9
-0
9 additions, 0 deletions
.../Framework/MDAlgorithms/inc/MantidMDAlgorithms/SmoothMD.h
Code/Mantid/Framework/MDAlgorithms/src/SmoothMD.cpp
+59
-53
59 additions, 53 deletions
Code/Mantid/Framework/MDAlgorithms/src/SmoothMD.cpp
with
68 additions
and
53 deletions
Code/Mantid/Framework/MDAlgorithms/inc/MantidMDAlgorithms/SmoothMD.h
+
9
−
0
View file @
2ea79abe
...
...
@@ -3,9 +3,14 @@
#include
"MantidKernel/System.h"
#include
"MantidAPI/Algorithm.h"
#include
<boost/shared_ptr.hpp>
namespace
Mantid
{
namespace
API
{
class
IMDHistoWorkspace
;
}
namespace
MDAlgorithms
{
...
...
@@ -43,7 +48,11 @@ namespace MDAlgorithms
virtual
const
std
::
string
summary
()
const
;
std
::
map
<
std
::
string
,
std
::
string
>
validateInputs
();
boost
::
shared_ptr
<
Mantid
::
API
::
IMDHistoWorkspace
>
hatSmooth
(
boost
::
shared_ptr
<
const
Mantid
::
API
::
IMDHistoWorkspace
>
toSmooth
,
const
std
::
vector
<
int
>
&
widthVector
);
private:
void
init
();
void
exec
();
...
...
This diff is collapsed.
Click to expand it.
Code/Mantid/Framework/MDAlgorithms/src/SmoothMD.cpp
+
59
−
53
View file @
2ea79abe
...
...
@@ -18,6 +18,7 @@
#include
<sstream>
#include
<utility>
#include
<boost/function.hpp>
#include
<boost/bind.hpp>
#include
<boost/scoped_ptr.hpp>
#include
<boost/tuple/tuple.hpp>
...
...
@@ -27,7 +28,7 @@ using namespace Mantid::MDEvents;
typedef
std
::
vector
<
int
>
WidthVector
;
typedef
boost
::
function
<
IMDHistoWorkspace_sptr
(
IMDHistoWorkspace_const_sptr
,
const
WidthVector
&
,
Progress
&
)
>
SmoothFunction
;
IMDHistoWorkspace_const_sptr
,
const
WidthVector
&
)
>
SmoothFunction
;
typedef
std
::
map
<
std
::
string
,
SmoothFunction
>
SmoothFunctionMap
;
namespace
{
...
...
@@ -43,17 +44,61 @@ std::vector<std::string> functions() {
return
propOptions
;
}
/**
* Maps a function name to a smoothing function
* @return function map
*/
SmoothFunctionMap
makeFunctionMap
(
Mantid
::
MDAlgorithms
::
SmoothMD
*
instance
)
{
SmoothFunctionMap
map
;
map
.
insert
(
std
::
make_pair
(
"Hat"
,
boost
::
bind
(
&
Mantid
::
MDAlgorithms
::
SmoothMD
::
hatSmooth
,
instance
,
_1
,
_2
)));
return
map
;
}
}
namespace
Mantid
{
namespace
MDAlgorithms
{
// Register the algorithm into the AlgorithmFactory
DECLARE_ALGORITHM
(
SmoothMD
)
//----------------------------------------------------------------------------------------------
/** Constructor
*/
SmoothMD
::
SmoothMD
()
{}
//----------------------------------------------------------------------------------------------
/** Destructor
*/
SmoothMD
::~
SmoothMD
()
{}
//----------------------------------------------------------------------------------------------
/// Algorithms name for identification. @see Algorithm::name
const
std
::
string
SmoothMD
::
name
()
const
{
return
"SmoothMD"
;
}
/// Algorithm's version for identification. @see Algorithm::version
int
SmoothMD
::
version
()
const
{
return
1
;
};
/// Algorithm's category for identification. @see Algorithm::category
const
std
::
string
SmoothMD
::
category
()
const
{
return
"MDAlgorithms"
;
}
/// Algorithm's summary for use in the GUI and help. @see Algorithm::summary
const
std
::
string
SmoothMD
::
summary
()
const
{
return
"Smooth an MDHistoWorkspace according to a weight function"
;
};
/**
* Hat function smoothing. All weights even. Hat function boundaries beyond
* width.
* @param toSmooth : Workspace to smooth
* @param widthVector : Width vector
* @param progress : progress object
* @return Smoothed MDHistoWorkspace
*/
IMDHistoWorkspace_sptr
hatSmooth
(
IMDHistoWorkspace_const_sptr
toSmooth
,
const
WidthVector
&
widthVector
,
Progress
&
progress
)
{
IMDHistoWorkspace_sptr
SmoothMD
::
hatSmooth
(
IMDHistoWorkspace_const_sptr
toSmooth
,
const
WidthVector
&
widthVector
)
{
Progress
progress
(
this
,
0
,
1
,
size_t
(
toSmooth
->
getNPoints
()
)
);
// Create the output workspace.
IMDHistoWorkspace_sptr
outWS
=
toSmooth
->
clone
();
...
...
@@ -62,11 +107,13 @@ IMDHistoWorkspace_sptr hatSmooth(IMDHistoWorkspace_const_sptr toSmooth,
auto
iterators
=
toSmooth
->
createIterators
(
nThreads
,
NULL
);
PRA
GMA_OMP
(
parallel
for
schedule
(
dynamic
,
1
)
)
for
(
int
it
=
0
;
it
<
iterators
.
size
();
++
it
)
{
P
A
RA
LLEL_FOR_NO_WSP_CHECK
(
)
for
(
int
it
=
0
;
it
<
int
(
iterators
.
size
()
)
;
++
it
)
{
boost
::
scoped_ptr
<
MDHistoWorkspaceIterator
>
iterator
(
dynamic_cast
<
MDHistoWorkspaceIterator
*>
(
iterators
[
it
]));
size_t
counter
=
0
;
do
{
// Gets all vertex-touching neighbours
...
...
@@ -90,7 +137,10 @@ IMDHistoWorkspace_sptr hatSmooth(IMDHistoWorkspace_const_sptr toSmooth,
outWS
->
setErrorSquaredAt
(
iterator
->
getLinearIndex
(),
sumSqError
/
(
nNeighbours
+
1
));
progress
.
report
();
if
(
counter
%
1000
==
0
)
{
progress
.
report
();
}
++
counter
;
}
while
(
iterator
->
next
());
}
...
...
@@ -98,48 +148,6 @@ IMDHistoWorkspace_sptr hatSmooth(IMDHistoWorkspace_const_sptr toSmooth,
return
outWS
;
}
/**
* Maps a function name to a smoothing function
* @return function map
*/
SmoothFunctionMap
makeFunctionMap
()
{
SmoothFunctionMap
map
;
map
.
insert
(
std
::
make_pair
(
"Hat"
,
hatSmooth
));
return
map
;
}
}
namespace
Mantid
{
namespace
MDAlgorithms
{
// Register the algorithm into the AlgorithmFactory
DECLARE_ALGORITHM
(
SmoothMD
)
//----------------------------------------------------------------------------------------------
/** Constructor
*/
SmoothMD
::
SmoothMD
()
{}
//----------------------------------------------------------------------------------------------
/** Destructor
*/
SmoothMD
::~
SmoothMD
()
{}
//----------------------------------------------------------------------------------------------
/// Algorithms name for identification. @see Algorithm::name
const
std
::
string
SmoothMD
::
name
()
const
{
return
"SmoothMD"
;
}
/// Algorithm's version for identification. @see Algorithm::version
int
SmoothMD
::
version
()
const
{
return
1
;
};
/// Algorithm's category for identification. @see Algorithm::category
const
std
::
string
SmoothMD
::
category
()
const
{
return
"MDAlgorithms"
;
}
/// Algorithm's summary for use in the GUI and help. @see Algorithm::summary
const
std
::
string
SmoothMD
::
summary
()
const
{
return
"Smooth an MDHistoWorkspace according to a weight function"
;
};
//----------------------------------------------------------------------------------------------
/** Initialize the algorithm's properties.
...
...
@@ -191,12 +199,10 @@ void SmoothMD::exec() {
// Find the choosen smooth operation
const
std
::
string
smoothFunctionName
=
this
->
getProperty
(
"Function"
);
SmoothFunctionMap
functionMap
=
makeFunctionMap
();
SmoothFunctionMap
functionMap
=
makeFunctionMap
(
this
);
SmoothFunction
smoothFunction
=
functionMap
[
smoothFunctionName
];
Progress
progress
(
this
,
0
,
1
,
size_t
(
toSmooth
->
getNPoints
()
)
);
// invoke the smoothing operation
auto
smoothed
=
smoothFunction
(
toSmooth
,
widthVector
,
progress
);
auto
smoothed
=
smoothFunction
(
toSmooth
,
widthVector
);
setProperty
(
"OutputWorkspace"
,
smoothed
);
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment