From 999cf53c079c846be8eba6c4d3cbb160db6f2290 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Thu, 29 Oct 2020 07:42:41 +0100 Subject: [PATCH] tests+fixes --- python/damask/_geom.py | 2 +- python/tests/test_ConfigMaterial.py | 13 +++++++++++++ python/tests/test_Geom.py | 13 +++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/python/damask/_geom.py b/python/damask/_geom.py index 6c5e3907a..48f022805 100644 --- a/python/damask/_geom.py +++ b/python/damask/_geom.py @@ -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) diff --git a/python/tests/test_ConfigMaterial.py b/python/tests/test_ConfigMaterial.py index 4863a8ac4..d0bcd2a56 100644 --- a/python/tests/test_ConfigMaterial.py +++ b/python/tests/test_ConfigMaterial.py @@ -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] + diff --git a/python/tests/test_Geom.py b/python/tests/test_Geom.py index 73d157cfd..dd9c28a3e 100644 --- a/python/tests/test_Geom.py +++ b/python/tests/test_Geom.py @@ -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]