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
18b61283
Commit
18b61283
authored
11 years ago
by
Zhou, Wenduo
Browse files
Options
Downloads
Plain Diff
Merge remote-tracking branch 'origin/bugfix/8157_multidomain_fitting_properties'
parents
7eb36f0c
c9d761c1
Loading
Loading
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Code/Mantid/Framework/CurveFitting/src/Fit.cpp
+3
-2
3 additions, 2 deletions
Code/Mantid/Framework/CurveFitting/src/Fit.cpp
Code/Mantid/Framework/CurveFitting/test/MultiDomainFunctionTest.h
+77
-0
77 additions, 0 deletions
...tid/Framework/CurveFitting/test/MultiDomainFunctionTest.h
with
80 additions
and
2 deletions
Code/Mantid/Framework/CurveFitting/src/Fit.cpp
+
3
−
2
View file @
18b61283
...
...
@@ -342,9 +342,10 @@ namespace CurveFitting
auto
mdf
=
boost
::
dynamic_pointer_cast
<
API
::
MultiDomainFunction
>
(
m_function
);
if
(
mdf
)
{
m_workspacePropertyNames
.
resize
(
mdf
->
nFunctions
());
size_t
ndom
=
mdf
->
getMaxIndex
()
+
1
;
m_workspacePropertyNames
.
resize
(
ndom
);
m_workspacePropertyNames
[
0
]
=
"InputWorkspace"
;
for
(
size_t
i
=
1
;
i
<
mdf
->
nFunctions
()
;
++
i
)
for
(
size_t
i
=
1
;
i
<
ndom
;
++
i
)
{
std
::
string
workspacePropertyName
=
"InputWorkspace_"
+
boost
::
lexical_cast
<
std
::
string
>
(
i
);
m_workspacePropertyNames
[
i
]
=
workspacePropertyName
;
...
...
This diff is collapsed.
Click to expand it.
Code/Mantid/Framework/CurveFitting/test/MultiDomainFunctionTest.h
+
77
−
0
View file @
18b61283
...
...
@@ -229,6 +229,83 @@ public:
fit
.
setProperty
(
"InputWorkspace_1"
,
ws1
);
}
void
test_fit_one_function_to_two_parts_of_workspace
()
{
const
double
A0
=
1
,
A1
=
100
;
const
double
B0
=
2
;
// Set up a workspace which is divided into 3 parts: 0 <= x < 10, 10 <= x < 20, 20 <= x < 30
// The first and last parts have their data on line A0 + B0 * x, and the middle part has
// constant value A1
MatrixWorkspace_sptr
ws
=
boost
::
shared_ptr
<
MatrixWorkspace
>
(
new
WorkspaceTester
);
ws
->
initialize
(
1
,
30
,
30
);
{
const
double
dx
=
1.0
;
Mantid
::
MantidVec
&
x
=
ws
->
dataX
(
0
);
Mantid
::
MantidVec
&
y
=
ws
->
dataY
(
0
);
for
(
size_t
i
=
0
;
i
<
10
;
++
i
)
{
x
[
i
]
=
dx
*
double
(
i
);
y
[
i
]
=
A0
+
B0
*
x
[
i
];
}
for
(
size_t
i
=
10
;
i
<
20
;
++
i
)
{
x
[
i
]
=
dx
*
double
(
i
);
y
[
i
]
=
A1
;
}
for
(
size_t
i
=
20
;
i
<
30
;
++
i
)
{
x
[
i
]
=
dx
*
double
(
i
);
y
[
i
]
=
A0
+
B0
*
x
[
i
];
}
}
// Set up a multi-domain function and Fit algorithm to fit a single function to two
// parts of the workspace
boost
::
shared_ptr
<
MultiDomainFunction
>
mf
=
boost
::
make_shared
<
MultiDomainFunction
>
();
mf
->
addFunction
(
boost
::
make_shared
<
MultiDomainFunctionTest_Function
>
());
mf
->
setParameter
(
0
,
0.0
);
mf
->
setParameter
(
1
,
0.0
);
std
::
vector
<
size_t
>
ind
(
2
);
ind
[
0
]
=
0
;
ind
[
1
]
=
1
;
mf
->
setDomainIndices
(
0
,
ind
);
TS_ASSERT_EQUALS
(
mf
->
getMaxIndex
(),
1
);
Mantid
::
API
::
IAlgorithm_sptr
alg
=
Mantid
::
API
::
AlgorithmManager
::
Instance
().
create
(
"Fit"
);
Mantid
::
API
::
IAlgorithm
&
fit
=
*
alg
;
fit
.
initialize
();
fit
.
setProperty
(
"Function"
,
boost
::
dynamic_pointer_cast
<
IFunction
>
(
mf
));
// at this point Fit knows the number of domains and creates additional properties InputWorkspace_#
TS_ASSERT
(
fit
.
existsProperty
(
"InputWorkspace_1"
)
);
fit
.
setProperty
(
"InputWorkspace"
,
ws
);
fit
.
setProperty
(
"WorkspaceIndex"
,
0
);
fit
.
setProperty
(
"StartX"
,
0.0
);
fit
.
setProperty
(
"EndX"
,
9.9999
);
fit
.
setProperty
(
"InputWorkspace_1"
,
ws
);
// at this point Fit knows the type of InputWorkspace_1 (MatrixWorkspace) and creates additional
// properties for it
TS_ASSERT
(
fit
.
existsProperty
(
"WorkspaceIndex_1"
)
);
TS_ASSERT
(
fit
.
existsProperty
(
"StartX_1"
)
);
TS_ASSERT
(
fit
.
existsProperty
(
"EndX_1"
)
);
fit
.
setProperty
(
"WorkspaceIndex_1"
,
0
);
fit
.
setProperty
(
"StartX_1"
,
20.0
);
fit
.
setProperty
(
"EndX_1"
,
30.0
);
fit
.
execute
();
TS_ASSERT
(
fit
.
isExecuted
()
);
IFunction_sptr
fun
=
fit
.
getProperty
(
"Function"
);
TS_ASSERT_DELTA
(
fun
->
getParameter
(
0
),
1.0
,
1e-15
);
// == A0
TS_ASSERT_DELTA
(
fun
->
getParameter
(
1
),
2.0
,
1e-15
);
// == B0
}
private
:
boost
::
shared_ptr
<
MultiDomainFunction
>
multi
;
boost
::
shared_ptr
<
JointDomain
>
domain
;
...
...
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