Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
ogs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
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
Dmitri Naumov
ogs
Commits
2ddbf99c
Commit
2ddbf99c
authored
8 years ago
by
Christoph Lehmann
Browse files
Options
Downloads
Patches
Plain Diff
[T] replaced third ODE
parent
e7de2082
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
Tests/NumLib/ODEs.h
+25
-52
25 additions, 52 deletions
Tests/NumLib/ODEs.h
Tests/NumLib/TestODEInt.cpp
+12
-16
12 additions, 16 deletions
Tests/NumLib/TestODEInt.cpp
with
37 additions
and
68 deletions
Tests/NumLib/ODEs.h
+
25
−
52
View file @
2ddbf99c
...
@@ -10,6 +10,7 @@
...
@@ -10,6 +10,7 @@
#ifndef TESTS_NUMLIB_ODES_H
#ifndef TESTS_NUMLIB_ODES_H
#define TESTS_NUMLIB_ODES_H
#define TESTS_NUMLIB_ODES_H
#include
<boost/math/constants/constants.hpp>
#include
"MathLib/LinAlg/LinAlg.h"
#include
"MathLib/LinAlg/LinAlg.h"
#include
"MathLib/LinAlg/UnifiedMatrixSetters.h"
#include
"MathLib/LinAlg/UnifiedMatrixSetters.h"
#include
"NumLib/ODESolver/ODESystem.h"
#include
"NumLib/ODESolver/ODESystem.h"
...
@@ -185,25 +186,16 @@ class ODE3 final : public NumLib::ODESystem<
...
@@ -185,25 +186,16 @@ class ODE3 final : public NumLib::ODESystem<
NumLib
::
NonlinearSolverTag
::
Newton
>
NumLib
::
NonlinearSolverTag
::
Newton
>
{
{
public:
public:
void
assemble
(
const
double
t
,
GlobalVector
const
&
x_curr
,
GlobalMatrix
&
M
,
void
assemble
(
const
double
/*t*/
,
GlobalVector
const
&
x_curr
,
GlobalMatrix
&
M
,
GlobalMatrix
&
K
,
GlobalVector
&
b
)
override
GlobalMatrix
&
K
,
GlobalVector
&
b
)
override
{
{
auto
const
x
=
x_curr
[
0
];
auto
const
u
=
x_curr
[
0
];
auto
const
y
=
x_curr
[
1
];
auto
const
v
=
x_curr
[
1
];
auto
const
z
=
x_curr
[
2
];
MathLib
::
setMatrix
(
M
,
{
u
,
2.0
-
u
,
2.0
-
v
,
v
});
MathLib
::
MathLib
::
setMatrix
(
K
,
{
2.0
-
u
-
v
,
-
u
,
v
,
2.0
*
v
-
5.0
});
setMatrix
(
M
,
{
t
*
y
,
1.0
,
0.0
,
MathLib
::
setVector
(
0.0
,
-
t
,
t
*
y
,
b
,
{
-
2
*
u
+
2.0
*
u
*
v
,
-
2.0
*
v
*
v
+
5.0
*
v
-
4.0
});
omega
*
x
*
t
,
0.0
,
omega
*
x
});
MathLib
::
setMatrix
(
K
,
{
y
,
1.0
/
t
,
-
y
,
omega
*
omega
/
y
,
-
0.5
,
0.0
,
-
0.5
*
omega
*
z
,
y
/
omega
,
-
(
1.0
/
omega
/
t
+
omega
)
*
y
*
z
});
MathLib
::
setVector
(
b
,
{
0.0
,
0.5
/
t
,
0.5
*
omega
*
x
*
z
+
omega
/
t
});
}
}
void
assembleWithJacobian
(
const
double
t
,
GlobalVector
const
&
x_curr
,
void
assembleWithJacobian
(
const
double
t
,
GlobalVector
const
&
x_curr
,
...
@@ -214,12 +206,11 @@ public:
...
@@ -214,12 +206,11 @@ public:
{
{
assemble
(
t
,
x_curr
,
M
,
K
,
b
);
assemble
(
t
,
x_curr
,
M
,
K
,
b
);
auto
const
x
=
x_curr
[
0
];
auto
const
u
=
x_curr
[
0
];
auto
const
y
=
x_curr
[
1
];
auto
const
v
=
x_curr
[
1
];
auto
const
z
=
x_curr
[
2
];
auto
const
d
x
=
xdot
[
0
];
auto
const
d
u
=
xdot
[
0
];
auto
const
d
z
=
xdot
[
2
];
auto
const
d
v
=
xdot
[
1
];
namespace
LinAlg
=
MathLib
::
LinAlg
;
namespace
LinAlg
=
MathLib
::
LinAlg
;
...
@@ -243,26 +234,17 @@ public:
...
@@ -243,26 +234,17 @@ public:
// in this block it is assumed that dx_dx == 1.0
// in this block it is assumed that dx_dx == 1.0
// add dM/dx \cdot \dot x
// add dM/dx \cdot \dot x
MathLib
::
MathLib
::
addToMatrix
(
Jac
,
{
du
-
dv
,
0.0
,
0.0
,
dv
-
du
});
addToMatrix
(
Jac
,
{
0.0
,
t
*
dx
,
0.0
,
0.0
,
t
*
dz
,
0.0
,
omega
*
t
*
dx
+
omega
*
dz
,
0.0
,
0.0
});
LinAlg
::
finalizeAssembly
(
K
);
LinAlg
::
finalizeAssembly
(
K
);
LinAlg
::
axpy
(
Jac
,
dx_dx
,
K
);
// add K \cdot dx_dx
LinAlg
::
axpy
(
Jac
,
dx_dx
,
K
);
// add K \cdot dx_dx
// add dK/dx \cdot \dot x
// add dK/dx \cdot \dot x
MathLib
::
MathLib
::
addToMatrix
(
Jac
,
{
-
du
-
dv
,
-
du
,
0.0
,
du
+
2.0
*
dv
});
addToMatrix
(
Jac
,
{
0.0
,
x
-
z
,
0.0
,
0.0
,
-
omega
*
omega
/
y
/
y
*
x
,
0.0
,
0.0
,
y
/
omega
-
(
1.0
/
omega
/
t
+
omega
)
*
z
*
z
,
// -->
/* --> */
-
0.5
*
omega
*
x
-
(
1.0
/
omega
/
t
+
omega
)
*
y
*
z
});
// add -db/dx
// add -db/dx
MathLib
::
MathLib
::
addToMatrix
(
Jac
,
addToMatrix
(
Jac
,
{
0.0
,
0.0
,
0.0
,
{
2.0
-
2.0
*
v
,
-
2.0
*
u
,
0.0
,
2.0
*
v
-
5.0
});
0.0
,
0.0
,
0.0
,
-
0.5
*
omega
*
z
,
0.0
,
-
0.5
*
omega
*
z
});
}
}
// Eigen::MatrixXd J(Jac.getRawMatrix());
// Eigen::MatrixXd J(Jac.getRawMatrix());
...
@@ -283,23 +265,17 @@ public:
...
@@ -283,23 +265,17 @@ public:
return
false
;
return
false
;
}
}
std
::
size_t
const
N
=
3
;
std
::
size_t
const
N
=
2
;
static
const
double
omega
;
};
};
const
double
ODE3
::
omega
=
15.0
;
template
<
>
template
<
>
class
ODETraits
<
ODE3
>
class
ODETraits
<
ODE3
>
{
{
public:
public:
static
void
setIC
(
GlobalVector
&
x0
)
static
void
setIC
(
GlobalVector
&
x0
)
{
{
auto
const
omega
=
ODE3
::
omega
;
MathLib
::
setVector
(
x0
,
{
std
::
sin
(
2.0
*
t0
),
std
::
cos
(
t0
)
*
std
::
cos
(
t0
)});
MathLib
::
setVector
(
x0
,
{
sin
(
omega
*
t0
)
/
omega
/
t0
,
1.0
/
t0
,
cos
(
omega
*
t0
)
});
MathLib
::
LinAlg
::
finalizeAssembly
(
x0
);
MathLib
::
LinAlg
::
finalizeAssembly
(
x0
);
// std::cout << "IC:\n" << Eigen::VectorXd(x0.getRawVector()) << "\n";
// std::cout << "IC:\n" << Eigen::VectorXd(x0.getRawVector()) << "\n";
...
@@ -307,12 +283,8 @@ public:
...
@@ -307,12 +283,8 @@ public:
static
GlobalVector
solution
(
const
double
t
)
static
GlobalVector
solution
(
const
double
t
)
{
{
auto
const
omega
=
ODE3
::
omega
;
GlobalVector
v
(
2
);
MathLib
::
setVector
(
v
,
{
std
::
sin
(
2.0
*
t
),
std
::
cos
(
t
)
*
std
::
cos
(
t
)});
GlobalVector
v
(
3
);
MathLib
::
setVector
(
v
,
{
sin
(
omega
*
t
)
/
omega
/
t
,
1.0
/
t
,
cos
(
omega
*
t
)
});
MathLib
::
LinAlg
::
finalizeAssembly
(
v
);
MathLib
::
LinAlg
::
finalizeAssembly
(
v
);
return
v
;
return
v
;
}
}
...
@@ -321,9 +293,10 @@ public:
...
@@ -321,9 +293,10 @@ public:
static
const
double
t_end
;
static
const
double
t_end
;
};
};
const
double
ODETraits
<
ODE3
>::
t0
=
1
.0
;
const
double
ODETraits
<
ODE3
>::
t0
=
0
.0
;
const
double
ODETraits
<
ODE3
>::
t_end
=
3.0
;
const
double
ODETraits
<
ODE3
>::
t_end
=
0.5
*
boost
::
math
::
constants
::
pi
<
double
>
();
// ODE 3 end //////////////////////////////////////////////////////
// ODE 3 end //////////////////////////////////////////////////////
#endif // TESTS_NUMLIB_ODES_H
#endif // TESTS_NUMLIB_ODES_H
This diff is collapsed.
Click to expand it.
Tests/NumLib/TestODEInt.cpp
+
12
−
16
View file @
2ddbf99c
...
@@ -215,21 +215,17 @@ struct TestCase;
...
@@ -215,21 +215,17 @@ struct TestCase;
TCLITEM(GMatrix, GVector, ODE2, BackwardEuler, Picard) TCLSEP \
TCLITEM(GMatrix, GVector, ODE2, BackwardEuler, Picard) TCLSEP \
TCLITEM(GMatrix, GVector, ODE2, ForwardEuler, Picard) TCLSEP \
TCLITEM(GMatrix, GVector, ODE2, ForwardEuler, Picard) TCLSEP \
TCLITEM(GMatrix, GVector, ODE2, CrankNicolson, Picard) TCLSEP \
TCLITEM(GMatrix, GVector, ODE2, CrankNicolson, Picard) TCLSEP \
TCLITEM(GMatrix, GVector, ODE2, BackwardDifferentiationFormula, Picard)
TCLITEM(GMatrix, GVector, ODE2, BackwardDifferentiationFormula, Picard) TCLSEP \
\
// ODE3 behaves too badly. Even with very tiny timesteps it cannot be solved.
TCLITEM(GMatrix, GVector, ODE3, BackwardEuler, Newton) TCLSEP \
// Probably because then the singular M matrix has too much weight.
TCLITEM(GMatrix, GVector, ODE3, ForwardEuler, Newton) TCLSEP \
// TCLITEM(EDMatrix, EVector, ODE3, BackwardEuler, Newton) TCLSEP
TCLITEM(GMatrix, GVector, ODE3, CrankNicolson, Newton) TCLSEP \
// /* Not possible because of singular matrix */
TCLITEM(GMatrix, GVector, ODE3, BackwardDifferentiationFormula, Newton) TCLSEP \
// /* TCLITEM(EDMatrix, EVector, ODE3, ForwardEuler, Newton) TCLSEP */
\
// TCLITEM(EDMatrix, EVector, ODE3, CrankNicolson, Newton) TCLSEP
TCLITEM(GMatrix, GVector, ODE3, BackwardEuler, Picard) TCLSEP \
// TCLITEM(EDMatrix, EVector, ODE3, BackwardDifferentiationFormula, Newton) TCLSEP
TCLITEM(GMatrix, GVector, ODE3, ForwardEuler, Picard) TCLSEP \
//
TCLITEM(GMatrix, GVector, ODE3, CrankNicolson, Picard) TCLSEP \
// TCLITEM(EDMatrix, EVector, ODE3, BackwardEuler, Picard) TCLSEP
TCLITEM(GMatrix, GVector, ODE3, BackwardDifferentiationFormula, Picard)
// /* Not possible because of singular matrix */
// /* TCLITEM(EDMatrix, EVector, ODE3, ForwardEuler, Picard) TCLSEP */
// TCLITEM(EDMatrix, EVector, ODE3, CrankNicolson, Picard) TCLSEP
// TCLITEM(EDMatrix, EVector, ODE3, BackwardDifferentiationFormula, Picard)
#define TCLITEM(MAT, VEC, ODE, TIMEDISC, NLTAG) \
#define TCLITEM(MAT, VEC, ODE, TIMEDISC, NLTAG) \
...
@@ -273,7 +269,7 @@ public:
...
@@ -273,7 +269,7 @@ public:
static
void
test
()
static
void
test
()
{
{
for
(
auto
num_timesteps
:
{
10u
,
100u
})
for
(
auto
num_timesteps
:
{
100u
})
{
{
run_test_case
<
Matrix
,
Vector
,
TimeDisc
,
ODE
,
NLTag
>
(
run_test_case
<
Matrix
,
Vector
,
TimeDisc
,
ODE
,
NLTag
>
(
num_timesteps
,
TestParams
::
name
);
num_timesteps
,
TestParams
::
name
);
...
...
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