Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
exercise_4
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cp1_ws19
exercise_4
Commits
f238962c
Commit
f238962c
authored
Nov 23, 2019
by
Kevin Höllring
Browse files
Options
Downloads
Patches
Plain Diff
Make Polynomials Coordinate compliant
parent
2758e34d
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/sample_functions.h
+68
-9
68 additions, 9 deletions
include/sample_functions.h
src/function.cpp
+6
-7
6 additions, 7 deletions
src/function.cpp
with
74 additions
and
16 deletions
include/sample_functions.h
+
68
−
9
View file @
f238962c
...
@@ -3,12 +3,13 @@
...
@@ -3,12 +3,13 @@
#include
"function.h"
#include
"function.h"
#include
"matrix.h"
#include
"matrix.h"
#include
<cmath>
namespace
numerics
{
namespace
numerics
{
class
Parabola_2D
class
Parabola_2D
:
public
numerics
::
Function
<
numerics
::
Coordinate
<
double
>
,
double
>
{
:
public
numerics
::
Function
<
numerics
::
Coordinate
<
double
>
,
double
>
{
virtual
double
operator
()(
numerics
::
Coordinate
<
double
>
x
)
const
override
{
double
operator
()(
numerics
::
Coordinate
<
double
>
x
)
const
override
{
assert
(
x
.
dimension
()
==
input_dimension
());
assert
(
x
.
dimension
()
==
input_dimension
());
double
a
=
x
[
0
];
double
a
=
x
[
0
];
double
b
=
x
[
1
];
double
b
=
x
[
1
];
...
@@ -16,30 +17,88 @@ class Parabola_2D
...
@@ -16,30 +17,88 @@ class Parabola_2D
return
a
*
a
+
b
*
b
;
return
a
*
a
+
b
*
b
;
}
}
virtual
size_t
input_dimension
()
const
override
{
return
2
;
}
size_t
input_dimension
()
const
override
{
return
2
;
}
virtual
size_t
output_dimension
()
const
override
{
return
1
;
}
size_t
output_dimension
()
const
override
{
return
1
;
}
};
};
class
Periodic_Wave_2D
class
Periodic_Wave_2D
:
public
numerics
::
Function
<
numerics
::
Coordinate
<
double
>
,
double
>
{
:
public
numerics
::
Function
<
numerics
::
Coordinate
<
double
>
,
double
>
{
virtual
double
operator
()(
numerics
::
Coordinate
<
double
>
x
)
const
override
{
double
operator
()(
numerics
::
Coordinate
<
double
>
x
)
const
override
{
assert
(
x
.
dimension
()
==
input_dimension
());
assert
(
x
.
dimension
()
==
input_dimension
());
return
sin
(
x
[
0
])
+
cos
(
x
[
1
]);
return
sin
(
x
[
0
])
+
cos
(
x
[
1
]);
}
}
virtual
size_t
input_dimension
()
const
override
{
return
2
;
}
size_t
input_dimension
()
const
override
{
return
2
;
}
virtual
size_t
output_dimension
()
const
override
{
return
1
;
}
size_t
output_dimension
()
const
override
{
return
1
;
}
};
class
LennardJones
:
public
numerics
::
Function
<
numerics
::
Coordinate
<
double
>
,
double
>
{
public:
LennardJones
(
double
_epsilon
,
double
_sigma
)
:
epsilon
(
_epsilon
),
sigma
(
_sigma
)
{}
double
operator
()(
numerics
::
Coordinate
<
double
>
x
)
const
override
{
assert
(
x
.
dimension
()
==
input_dimension
());
double
r
=
x
[
0
];
double
rel
=
sigma
/
r
;
double
rel2
=
rel
*
rel
;
double
rel4
=
rel2
*
rel2
;
double
rel8
=
rel4
*
rel4
;
return
4
*
epsilon
*
(
rel8
*
rel4
-
rel4
*
rel2
);
}
size_t
input_dimension
()
const
override
{
return
1
;
}
size_t
output_dimension
()
const
override
{
return
1
;
}
double
get_rm
()
{
return
pow
(
2
,
1.0
/
6.0
)
*
sigma
;
}
protected
:
double
epsilon
,
sigma
;
};
class
PolyWrapper
:
public
numerics
::
Function
<
numerics
::
Coordinate
<
double
>
,
double
>
,
public
Polynomial
{
public:
PolyWrapper
(
std
::
vector
<
double
>
_coeff
)
:
Polynomial
(
_coeff
)
{}
double
operator
()(
numerics
::
Coordinate
<
double
>
x
)
const
override
{
assert
(
x
.
dimension
()
==
Polynomial
::
input_dimension
());
return
Polynomial
::
operator
()(
x
[
0
]);
}
size_t
input_dimension
()
const
override
{
return
Polynomial
::
input_dimension
();
}
size_t
output_dimension
()
const
override
{
return
Polynomial
::
output_dimension
();
}
};
};
struct
functions
{
struct
functions
{
public:
public:
// 2D test functions
static
Parabola_2D
parabola_2d
;
static
Parabola_2D
parabola_2d
;
static
Periodic_Wave_2D
periodic_wave_2d
;
static
Periodic_Wave_2D
periodic_wave_2d
;
static
Polynomial
ref_polynomial_1d
;
static
Polynomial
parabola_1d
;
// 1D test functions
static
Polynomial
higher_parabola_1d
;
// 1D Lennard Jones potentials
static
LennardJones
wide_LJ
;
static
LennardJones
narrow_LJ
;
// 1D polynomials
static
PolyWrapper
parabola_1d
;
static
PolyWrapper
higher_parabola_1d
;
static
PolyWrapper
ref_polynomial_1d
;
};
};
};
// namespace numerics
};
// namespace numerics
...
...
This diff is collapsed.
Click to expand it.
src/function.cpp
+
6
−
7
View file @
f238962c
...
@@ -19,10 +19,9 @@ numerics::Parabola_2D numerics::functions::parabola_2d =
...
@@ -19,10 +19,9 @@ numerics::Parabola_2D numerics::functions::parabola_2d =
numerics
::
Periodic_Wave_2D
numerics
::
functions
::
periodic_wave_2d
=
numerics
::
Periodic_Wave_2D
numerics
::
functions
::
periodic_wave_2d
=
numerics
::
Periodic_Wave_2D
();
numerics
::
Periodic_Wave_2D
();
numerics
::
Polynomial
numerics
::
functions
::
ref_polynomial_1d
=
numerics
::
PolyWrapper
numerics
::
functions
::
parabola_1d
=
numerics
::
Polynomial
({
1.
,
-
3.
,
-
1.
,
11.
,
-
17.
,
16.
,
-
4.
});
numerics
::
PolyWrapper
({
1.
,
0.
,
-
1.4
});
numerics
::
PolyWrapper
numerics
::
functions
::
higher_parabola_1d
=
numerics
::
Polynomial
numerics
::
functions
::
parabola_1d
=
numerics
::
PolyWrapper
({
1.
,
0.0
,
-
2.3
,
0.
,
-
1.4
});
numerics
::
Polynomial
({
1.
,
0.
,
-
1.4
});
numerics
::
PolyWrapper
numerics
::
functions
::
ref_polynomial_1d
=
numerics
::
Polynomial
numerics
::
functions
::
higher_parabola_1d
=
numerics
::
PolyWrapper
({
1.
,
-
3.
,
-
1.
,
11.
,
-
17.
,
16.
,
-
4.
});
numerics
::
Polynomial
({
1.
,
0.0
,
-
2.3
,
0.
,
-
1.4
});
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