Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dune-fufem
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
Container registry
Model registry
Operate
Environments
Monitor
Incidents
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
Ansgar Burchardt
dune-fufem
Commits
976a63e1
Commit
976a63e1
authored
8 years ago
by
Carsten Gräser
Browse files
Options
Downloads
Patches
Plain Diff
[test][python] Test convertion python->gridfactory
parent
8006be79
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
dune/fufem/test/dunepythontest.cc
+36
-0
36 additions, 0 deletions
dune/fufem/test/dunepythontest.cc
dune/fufem/test/dunepythontest.py
+78
-0
78 additions, 0 deletions
dune/fufem/test/dunepythontest.py
with
114 additions
and
0 deletions
dune/fufem/test/dunepythontest.cc
+
36
−
0
View file @
976a63e1
...
...
@@ -13,6 +13,13 @@
#include
<dune/common/function.hh>
#include
<dune/common/parametertree.hh>
#if HAVE_UG
#include
<dune/grid/uggrid.hh>
#include
<dune/grid/uggrid/uggridfactory.hh>
#include
<dune/grid/common/gridfactory.hh>
#include
<dune/grid/io/file/vtk/vtkwriter.hh>
#endif
#include
<dune/functions/common/differentiablefunctionfromcallables.hh>
#include
<dune/fufem/dunepython.hh>
...
...
@@ -759,6 +766,35 @@ int main(int argc, char** argv)
std
::
cout
<<
"Result of calling a function double(double) : "
<<
h
(
0.5
)
<<
std
::
endl
;
}
#if HAVE_UG
std
::
cout
<<
std
::
endl
;
std
::
cout
<<
"Example 17: Filling a GridFactory form python **********************************"
<<
std
::
endl
;
{
// prepare types and grid factory
using
Grid
=
Dune
::
UGGrid
<
2
>
;
using
GridFactory
=
Dune
::
GridFactory
<
Grid
>
;
GridFactory
gridFactory
;
// Get grid describtion from python and convert it to GridFactory
auto
pyGrid
=
pyMain
.
get
(
"grid"
);
pyGrid
.
toC
(
gridFactory
);
// Let GridFactory create grid
std
::
unique_ptr
<
Grid
>
gridPtr
(
gridFactory
.
createGrid
());
auto
&
grid
=
*
gridPtr
;
// Refine and write grid to visualize parametrized boundary
grid
.
globalRefine
(
1
);
grid
.
globalRefine
(
1
);
Dune
::
VTKWriter
<
Grid
::
LeafGridView
>
vtkWriter
(
grid
.
leafGridView
());
vtkWriter
.
write
(
"python-generated-grid"
);
std
::
cout
<<
"number of elements in created grid : "
<<
grid
.
leafGridView
().
indexSet
().
size
(
0
)
<<
std
::
endl
;
}
#endif
// Before exiting you should stop the python interpreter.
Python
::
stop
();
...
...
This diff is collapsed.
Click to expand it.
dune/fufem/test/dunepythontest.py
+
78
−
0
View file @
976a63e1
from
numpy
import
*
from
numpy.linalg
import
norm
foo
=
'
foo
'
bar
=
'
bar
'
...
...
@@ -9,3 +12,78 @@ str_list=["string1","string2","string3"]
int_tuple
=
(
1
,
2
,
3
)
# some utilities for creating parametrized boundaries
class
BoundarySegment
(
list
):
"""
A python BoundarySegment representation
It behaves like a list and function at the same time.
You can access the passed vertices using [] and
call the passed parametrization usin ().
"""
def
__init__
(
self
,
vertices
,
parametrization
):
super
(
BoundarySegment
,
self
).
__init__
(
vertices
)
self
.
parametrization
=
parametrization
def
__call__
(
self
,
x
):
return
self
.
parametrization
(
x
)
class
TransformedBoundarySegment
(
BoundarySegment
):
"""
This transforms a local parametrization into global one
The local parametrization is assumed to be a curve f
on [0,1] with f(0)=(0,0) and f(1)=(1,0).
This class rotatetes, scales, and translates the graph
of the curve such that the transformed curve Tf satisfies
Tf(0) = coordinates(vertices[0]) and
Tf(1) = coordinates(vertices[1]).
The scaling in normal direction is done with the
same factor such that T is angle and curvature preserving.
"""
def
__init__
(
self
,
vertices
,
localParametrization
,
allCoordinates
):
coordinates
=
array
([
allCoordinates
[
i
]
for
i
in
vertices
])
edge
=
coordinates
[
1
]
-
coordinates
[
0
]
normal
=
(
-
edge
[
1
],
edge
[
0
])
parametrization
=
lambda
x
:
dot
(
transpose
(
array
((
edge
,
normal
))),
localParametrization
(
x
))
+
coordinates
[
0
]
super
(
TransformedBoundarySegment
,
self
).
__init__
(
vertices
,
parametrization
)
class
ArcOverSecant
:
"""
Parametrization of a circle arc over a secant
The circle arc is parametrized over [0,1] and
placed such that its secant line goes from
(0,0) to (1,0). The radius of the arc is
selected automatically such that the
arc has the given angle.
"""
def
__init__
(
self
,
angle
):
self
.
alphaHalf
=
float
(
angle
)
/
2.0
self
.
invSinAlphaHalf
=
1.0
/
sin
(
self
.
alphaHalf
)
def
__call__
(
self
,
x
):
betaHalf
=
self
.
alphaHalf
*
x
[
0
]
secantlength
=
sin
(
betaHalf
)
*
self
.
invSinAlphaHalf
secantangle
=
self
.
alphaHalf
-
betaHalf
return
(
cos
(
secantangle
)
*
secantlength
,
sin
(
secantangle
)
*
secantlength
)
# reentrent corner circle grid
class
Grid
:
def
__init__
(
self
):
self
.
vertices
=
[(
0
,
0
),
(
1
,
0
),
(
0
,
1
),
(
-
1
,
0
),
(
0
,
-
1
)]
self
.
elements
=
[(
0
,
1
,
2
),
(
0
,
2
,
3
),
(
0
,
3
,
4
)]
# We use some utility classes here, but each segment essentially needs to be iterable,
# e.g, a list. If it is additionally callable, it is used as parametrization.
self
.
segments
=
[]
self
.
segments
.
append
(
TransformedBoundarySegment
((
2
,
1
),
ArcOverSecant
(
2.0
*
pi
/
4
),
self
.
vertices
))
self
.
segments
.
append
(
TransformedBoundarySegment
((
3
,
2
),
ArcOverSecant
(
2.0
*
pi
/
4
),
self
.
vertices
))
self
.
segments
.
append
(
TransformedBoundarySegment
((
4
,
3
),
ArcOverSecant
(
2.0
*
pi
/
4
),
self
.
vertices
))
grid
=
Grid
()
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