Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
dynamic
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
MostafaMollaali
dynamic
Commits
abeb044e
Commit
abeb044e
authored
9 years ago
by
Dmitri Naumov
Browse files
Options
Downloads
Patches
Plain Diff
[MaL] ODE: Move out Handles implementation.
parent
218331a1
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
MathLib/ODE/Handles.h
+103
-0
103 additions, 0 deletions
MathLib/ODE/Handles.h
MathLib/ODE/OdeSolverFactory.h
+1
-86
1 addition, 86 deletions
MathLib/ODE/OdeSolverFactory.h
with
104 additions
and
86 deletions
MathLib/ODE/Handles.h
0 → 100644
+
103
−
0
View file @
abeb044e
/**
* \copyright
* Copyright (c) 2012-2016, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
*/
#ifndef MATHLIB_ODE_HANDLES_H
#define MATHLIB_ODE_HANDLES_H
namespace
MathLib
{
namespace
detail
{
/// Function handles for N equations and arbitrary arguments.
template
<
unsigned
N
,
typename
...
FunctionArguments
>
struct
Handles
;
/// Function handles for N equations and single argument.
template
<
unsigned
N
,
typename
FunctionArgument
>
struct
Handles
<
N
,
FunctionArgument
>
:
public
MathLib
::
FunctionHandles
{
using
Function
=
MathLib
::
Function
<
N
,
FunctionArgument
>
;
using
JacobianFunction
=
MathLib
::
JacobianFunction
<
N
,
FunctionArgument
>
;
Handles
(
Function
&
f
,
JacobianFunction
&
df
,
FunctionArgument
&
arg
)
:
f
(
f
),
df
(
df
),
_data
(
arg
)
{
}
bool
call
(
const
double
t
,
const
double
*
const
y
,
double
*
const
ydot
)
override
{
// looks like f and df could be any callable object with suitable
// signature
// consider omission of data pointer and switch to std::function or
// alike
if
(
f
)
return
f
(
t
,
MappedConstVector
<
N
>
{
y
},
MappedVector
<
N
>
{
ydot
},
_data
);
return
true
;
}
bool
callJacobian
(
const
double
t
,
const
double
*
const
y
,
double
*
const
ydot
,
double
*
const
jac
)
override
{
if
(
df
)
return
df
(
t
,
MappedConstVector
<
N
>
{
y
},
MappedVector
<
N
>
{
ydot
},
MappedMatrix
<
N
,
N
>
{
jac
},
_data
);
return
true
;
}
bool
hasJacobian
()
const
override
{
return
df
!=
nullptr
;
}
unsigned
getNumEquations
()
const
override
{
return
N
;
}
private
:
Function
f
=
nullptr
;
JacobianFunction
df
=
nullptr
;
FunctionArgument
&
_data
;
};
/// Function handles for N equations and no arguments.
template
<
unsigned
N
>
struct
Handles
<
N
>
:
public
MathLib
::
FunctionHandles
{
using
Function
=
MathLib
::
Function
<
N
>
;
using
JacobianFunction
=
MathLib
::
JacobianFunction
<
N
>
;
Handles
(
Function
&
f
,
JacobianFunction
&
df
)
:
f
(
f
),
df
(
df
)
{}
bool
call
(
const
double
t
,
const
double
*
const
y
,
double
*
const
ydot
)
override
{
if
(
f
)
{
return
f
(
t
,
MappedConstVector
<
N
>
{
y
},
MappedVector
<
N
>
{
ydot
});
}
return
true
;
}
bool
callJacobian
(
const
double
t
,
const
double
*
const
y
,
double
*
const
ydot
,
double
*
const
jac
)
override
{
if
(
df
)
return
df
(
t
,
MappedConstVector
<
N
>
{
y
},
MappedVector
<
N
>
{
ydot
},
MappedMatrix
<
N
,
N
>
{
jac
});
return
true
;
}
bool
hasJacobian
()
const
override
{
return
df
!=
nullptr
;
}
unsigned
getNumEquations
()
const
override
{
return
N
;
}
Function
f
=
nullptr
;
JacobianFunction
df
=
nullptr
;
};
}
// namespace detail
}
// namespace MathLib
#endif // MATHLIB_ODE_HANDLES_H
This diff is collapsed.
Click to expand it.
MathLib/ODE/OdeSolverFactory.h
+
1
−
86
View file @
abeb044e
...
...
@@ -15,97 +15,12 @@
#include
"BaseLib/ConfigTree.h"
#include
"OdeSolver.h"
#include
"Handles.h"
#include
"CVodeSolver.h"
namespace
MathLib
{
namespace
detail
{
template
<
unsigned
N
,
typename
...
FunctionArguments
>
struct
Handles
;
template
<
unsigned
N
,
typename
FunctionArgument
>
struct
Handles
<
N
,
FunctionArgument
>
:
public
MathLib
::
FunctionHandles
{
using
Function
=
MathLib
::
Function
<
N
,
FunctionArgument
>
;
using
JacobianFunction
=
MathLib
::
JacobianFunction
<
N
,
FunctionArgument
>
;
Handles
(
Function
&
f
,
JacobianFunction
&
df
,
FunctionArgument
&
arg
)
:
f
(
f
),
df
(
df
),
_data
(
arg
)
{
}
bool
call
(
const
double
t
,
const
double
*
const
y
,
double
*
const
ydot
)
override
{
// looks like f and df could be any callable object with suitable
// signature
// consider omission of data pointer and switch to std::function or
// alike
if
(
f
)
return
f
(
t
,
MappedConstVector
<
N
>
{
y
},
MappedVector
<
N
>
{
ydot
},
_data
);
return
true
;
}
bool
callJacobian
(
const
double
t
,
const
double
*
const
y
,
double
*
const
ydot
,
double
*
const
jac
)
override
{
if
(
df
)
return
df
(
t
,
MappedConstVector
<
N
>
{
y
},
MappedVector
<
N
>
{
ydot
},
MappedMatrix
<
N
,
N
>
{
jac
/*, order*/
},
_data
);
return
true
;
}
bool
hasJacobian
()
const
override
{
return
df
!=
nullptr
;
}
unsigned
getNumEquations
()
const
override
{
return
N
;
}
private
:
Function
f
=
nullptr
;
JacobianFunction
df
=
nullptr
;
FunctionArgument
&
_data
;
};
template
<
unsigned
N
>
struct
Handles
<
N
>
:
public
MathLib
::
FunctionHandles
{
using
Function
=
MathLib
::
Function
<
N
>
;
using
JacobianFunction
=
MathLib
::
JacobianFunction
<
N
>
;
Handles
(
Function
&
f
,
JacobianFunction
&
df
)
:
f
(
f
),
df
(
df
)
{}
bool
call
(
const
double
t
,
const
double
*
const
y
,
double
*
const
ydot
)
override
{
if
(
f
)
{
// auto ydot_ = Eigen::Map<Eigen::Matrix<double, N, 1>>{y};
// auto ydot_ = Eigen::Map<Eigen::Matrix<double, N, 1>>{ydot};
return
f
(
t
,
MappedConstVector
<
N
>
{
y
},
MappedVector
<
N
>
{
ydot
});
}
return
true
;
}
bool
callJacobian
(
const
double
t
,
const
double
*
const
y
,
double
*
const
ydot
,
double
*
const
jac
)
override
{
if
(
df
)
return
df
(
t
,
MappedConstVector
<
N
>
{
y
},
MappedVector
<
N
>
{
ydot
},
MappedMatrix
<
N
,
N
>
{
jac
/*, order*/
});
return
true
;
}
bool
hasJacobian
()
const
override
{
return
df
!=
nullptr
;
}
unsigned
getNumEquations
()
const
override
{
return
N
;
}
Function
f
=
nullptr
;
JacobianFunction
df
=
nullptr
;
};
}
// namespace detail
template
<
unsigned
NumEquations
,
typename
...
FunctionArguments
>
std
::
unique_ptr
<
OdeSolver
<
NumEquations
,
FunctionArguments
...
>>
createOdeSolver
(
BaseLib
::
ConfigTree
const
&
config
);
...
...
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