tests+fixes

This commit is contained in:
Martin Diehl 2020-10-29 07:42:41 +01:00
parent 3be0c462a8
commit 999cf53c07
3 changed files with 27 additions and 1 deletions

View File

@ -262,7 +262,7 @@ class Geom:
Each unique combintation of values results in a material.
"""
grid,size,origin = grid_filters.cell_coord0_gridSizeOrigin(coords)
grid,size,origin = grid_filters.cell_coord0_gridSizeOrigin(table.get(coordinates))
labels_ = [labels] if isinstance(labels,str) else labels
unique,unique_inverse = np.unique(np.hstack([table.get(l) for l in labels_]),return_inverse=True,axis=0)

View File

@ -1,8 +1,10 @@
import os
import pytest
import numpy as np
from damask import ConfigMaterial
from damask import Table
@pytest.fixture
def reference_dir(reference_dir_base):
@ -74,3 +76,14 @@ class TestConfigMaterial:
material_config = ConfigMaterial.load(reference_dir/'material.yaml')
new = material_config.material_rename_homogenization({'Taylor':'isostrain'})
assert not new.is_complete
def test_from_table(self):
N = np.random.randint(3,10)
a = np.vstack((np.hstack((np.arange(N),np.arange(N)[::-1])),np.ones(N*2),np.zeros(N*2),np.ones(N*2))).T
t = Table(a,{'varying':2,'constant':2})
c = ConfigMaterial.from_table(t,constituents={'a':'varying','b':'1_constant'},c='2_constant')
assert len(c['material']) == N
for i,m in enumerate(c['material']):
c = m['constituents'][0]
assert m['c'] == 1 and c['b'] == 0 and c['a'] == [i,1]

View File

@ -3,8 +3,10 @@ import numpy as np
from damask import VTK
from damask import Geom
from damask import Table
from damask import Rotation
from damask import util
from damask import grid_filters
def geom_equal(a,b):
@ -371,3 +373,14 @@ class TestGeom:
grid = np.ones(3,dtype=int)*64
geom = Geom.from_minimal_surface(grid,np.ones(3),surface,threshold)
assert np.isclose(np.count_nonzero(geom.material==1)/np.prod(geom.grid),.5,rtol=1e-3)
def test_from_table(self):
grid = np.random.randint(60,100,3)
size = np.ones(3)+np.random.rand(3)
coords = grid_filters.cell_coord0(grid,size).reshape(-1,3,order='F')
x = np.ones(grid.prod()).reshape(-1,1)
y = np.hstack([np.arange(grid[1])]*grid[0]*grid[2]).reshape(-1,1)
t = Table(np.hstack((coords,x,y)),{'coords':3,'x':1,'y':1})
g = Geom.from_table(t,'coords',['x','y'])
assert g.N_materials == g.grid[2]