Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Daniel Boeckenhoff
tfields
Commits
400a1023
Commit
400a1023
authored
May 11, 2020
by
dboe
Browse files
merge test works
parent
b3ab07c1
Changes
3
Hide whitespace changes
Inline
Side-by-side
test/test_templating.py
View file @
400a1023
...
...
@@ -12,9 +12,6 @@ class Base_Check(object):
self
.
assertTrue
(
len
(
templates
),
len
(
self
.
_instances
))
for
template
,
inst
in
zip
(
templates
,
self
.
_instances
):
cut
=
merged
.
cut
(
template
)
print
([
inst
,
merged
,
template
,
cut
])
print
()
print
([
inst
.
maps
,
merged
.
maps
,
template
.
maps
,
cut
.
maps
])
self
.
demand_equal_cut
(
inst
,
template
,
cut
)
def
demand_equal_cut
(
self
,
inst
,
template
,
cut
):
...
...
@@ -42,16 +39,13 @@ class TensorMaps_Empty_Test(Base_Check, unittest.TestCase):
for
mp_dim
,
mp
in
inst
.
maps
.
items
():
cut_map
=
cut
.
maps
[
mp_dim
]
template_map
=
template
.
maps
[
mp_dim
]
print
(
mp
,
','
,
cut_map
,
','
,
template_map
)
self
.
assertEqual
(
len
(
mp
),
len
(
cut_map
))
self
.
assertEqual
(
tfields
.
dim
(
mp
),
tfields
.
dim
(
cut_map
))
self
.
assertEqual
(
tfields
.
dim
(
template_map
),
tfields
.
dim
(
cut_map
))
self
.
assertTrue
(
tfields
.
TensorFields
(
inst
).
equal
(
tfields
.
TensorFields
(
cut
)))
self
.
assertTrue
(
inst
.
equal
(
cut
))
self
.
assertTrue
(
inst
.
equal
(
cut
))
# most important
class
TensorFields_Test
(
TensorFields_Empty_Test
):
...
...
tfields/core.py
View file @
400a1023
...
...
@@ -1936,11 +1936,6 @@ class TensorFields(Tensors):
for
i
,
name
in
enumerate
(
names
):
self
.
fields
[
i
].
name
=
name
# def transform(self, coord_sys):
# super(TensorFields, self).transform(coord_sys)
# # for field in self.fields:
# # field.transform(coord_sys)
def
equal
(
self
,
other
,
**
kwargs
):
"""
Test, whether the instance has the same content as other.
...
...
@@ -2118,15 +2113,15 @@ class Maps(sortedcontainers.SortedDict, AbstractObject):
super
().
__init__
(
arg_tuple_list
,
**
kwargs
)
@
staticmethod
def
to_map
(
mp
,
copy
=
False
):
def
to_map
(
mp
,
*
fields
,
copy
=
False
):
if
not
copy
:
if
isinstance
(
mp
,
TensorFields
):
if
isinstance
(
mp
,
TensorFields
)
and
not
fields
:
if
not
np
.
issubdtype
(
np
.
int32
,
np
.
integer
):
mp
=
mp
.
astype
(
int
)
else
:
copy
=
True
if
copy
:
# not else, because in case of wrong mp type we initialize
mp
=
TensorFields
(
mp
,
dtype
=
int
)
mp
=
TensorFields
(
mp
,
*
fields
,
dtype
=
int
)
if
not
mp
.
rank
==
1
:
raise
ValueError
(
"Incorrect map rank {mp.rank}"
.
format
(
**
locals
())
...
...
@@ -2378,6 +2373,35 @@ class TensorMaps(TensorFields):
else
:
return
inst
def
_cut_sympy
(
self
,
expression
):
if
len
(
self
)
==
0
:
return
self
.
copy
()
mask
=
self
.
evalf
(
expression
)
# coord_sys is handled by tmp_transform
mask
.
astype
(
bool
)
inst
=
self
[
mask
].
copy
()
# template
indices
=
np
.
arange
(
len
(
self
))[
mask
]
# TODO: maybe np.empty instead of inst below. Reason why i copy is
# that the template is such marked for where it comes from.
# We have a trade-off with small memory consumpiton here.
template
=
tfields
.
TensorFields
(
inst
,
indices
)
return
inst
,
template
def
_cut_template
(
self
,
template
):
inst
=
super
().
_cut_template
(
template
)
if
template
.
fields
:
# bulk was cut so we need to correct the map references.
index_lut
=
np
.
full
(
len
(
self
),
np
.
nan
)
index_lut
[
template
.
fields
[
0
]]
=
np
.
arange
(
len
(
template
.
fields
[
0
]))
for
mp_dim
,
mp
in
inst
.
maps
.
items
():
mp
=
mp
.
cut
(
template
.
maps
[
mp_dim
])
if
template
.
fields
:
mp
=
Maps
.
to_map
(
index_lut
[
mp
],
*
mp
.
fields
)
inst
.
maps
[
mp_dim
]
=
mp
return
inst
def
equal
(
self
,
other
,
**
kwargs
):
"""
Test, whether the instance has the same content as other.
...
...
@@ -2398,8 +2422,8 @@ class TensorMaps(TensorFields):
# >>> assert tm.equal(cp)
>>> cp.maps[
0
].fields[0] = -42
>>> assert tm.maps[
0
].fields[0] == 42
>>> cp.maps[
1
].fields[0] = -42
>>> assert tm.maps[
1
].fields[0] == 42
>>> assert not tm.equal(cp)
"""
...
...
tfields/mesh3D.py
View file @
400a1023
...
...
@@ -599,7 +599,7 @@ class Mesh3D(tfields.TensorMaps):
key
=
'mesh_tree'
self
.
_cache
[
key
]
=
tree
def
remove
F
aces
(
self
,
face_delete_mask
):
def
remove
_f
aces
(
self
,
face_delete_mask
):
"""
Remove faces where face_delete_mask is True
"""
...
...
@@ -848,13 +848,13 @@ class Mesh3D(tfields.TensorMaps):
still overlaps with the cut.
These are at the intersection line between two cuts.
"""
face
I
nters
M
ask
=
np
.
full
((
inst
.
faces
.
shape
[
0
]),
False
,
dtype
=
bool
)
face
_i
nters
_m
ask
=
np
.
full
((
inst
.
faces
.
shape
[
0
]),
False
,
dtype
=
bool
)
for
i
,
face
in
enumerate
(
inst
.
faces
):
vertices_rejected
=
[
-
mask
[
f
]
for
f
in
face
]
face_on_edge
=
any
(
vertices_rejected
)
and
not
all
(
vertices_rejected
)
if
face_on_edge
:
face
I
nters
M
ask
[
i
]
=
True
new_mesh
.
remove
F
aces
(
-
face
I
nters
M
ask
)
face
_i
nters
_m
ask
[
i
]
=
True
new_mesh
.
remove
_f
aces
(
-
face
_i
nters
_m
ask
)
for
exprPart
in
expression_parts
:
inst
,
_
=
inst
.
_cut_sympy
(
exprPart
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment