Package solvcon :: Package io :: Package tests :: Module test_block
[hide private]
[frames] | no frames]

Source Code for Module solvcon.io.tests.test_block

  1  # -*- coding: UTF-8 -*- 
  2   
  3  from unittest import TestCase 
  4  from ...testing import get_blk_from_oblique_neu, get_blk_from_sample_neu 
  5   
6 -class CheckBlockIO(TestCase):
7 - def _check_shape(self, newblk, blk):
8 # shape. 9 self.assertEqual(newblk.ndim, blk.ndim) 10 self.assertEqual(newblk.nnode, blk.nnode) 11 self.assertEqual(newblk.nface, blk.nface) 12 self.assertEqual(newblk.ncell, blk.ncell) 13 self.assertEqual(newblk.nbound, blk.nbound) 14 self.assertEqual(newblk.ngstnode, blk.ngstnode) 15 self.assertEqual(newblk.ngstface, blk.ngstface) 16 self.assertEqual(newblk.ngstcell, blk.ngstcell) 17 # serial number. 18 self.assertEqual(newblk.blkn, blk.blkn)
19 - def _check_group(self, newblk, blk):
20 # group names. 21 self.assertEqual(len(newblk.grpnames), len(blk.grpnames)) 22 for igrp in range(len(blk.grpnames)): 23 self.assertEqual(newblk.grpnames[igrp], blk.grpnames[igrp])
24 - def _check_bc(self, newblk, blk):
25 from ...boundcond import interface 26 self.assertTrue((newblk.bndfcs == blk.bndfcs).all()) 27 self.assertEqual(len(newblk.bclist), len(blk.bclist)) 28 for ibc in range(len(newblk.bclist)): 29 newbc = newblk.bclist[ibc] 30 bc = blk.bclist[ibc] 31 self.assertFalse(isinstance(newbc, interface)) 32 self.assertFalse(isinstance(bc, interface)) 33 # meta data. 34 self.assertEqual(newbc.sern, bc.sern) 35 self.assertEqual(newbc.name, bc.name) 36 self.assertNotEqual(newbc.blk, bc.blk) 37 self.assertEqual(newbc.blkn, bc.blkn) 38 self.assertTrue(newbc.svr == None) 39 # faces. 40 self.assertTrue((newbc.facn[:,:2] == bc.facn[:,:2]).all()) 41 # values. 42 self.assertEqual(newbc.value.shape[1], bc.value.shape[1]) 43 if newbc.value.shape[1] > 0: 44 self.assertTrue((newbc.value == bc.value).all())
45 - def _check_array(self, newblk, blk):
46 # metrics. 47 self.assertTrue((newblk.ndcrd == blk.ndcrd).all()) 48 self.assertTrue((newblk.fccnd == blk.fccnd).all()) 49 self.assertTrue((newblk.fcnml == blk.fcnml).all()) 50 self.assertTrue((newblk.fcara == blk.fcara).all()) 51 self.assertTrue((newblk.clcnd == blk.clcnd).all()) 52 self.assertTrue((newblk.clvol == blk.clvol).all()) 53 # type. 54 self.assertTrue((newblk.fctpn == blk.fctpn).all()) 55 self.assertTrue((newblk.cltpn == blk.cltpn).all()) 56 self.assertTrue((newblk.clgrp == blk.clgrp).all()) 57 # connectivity. 58 self.assertTrue((newblk.fcnds == blk.fcnds).all()) 59 self.assertTrue((newblk.fccls == blk.fccls).all()) 60 self.assertTrue((newblk.clnds == blk.clnds).all()) 61 self.assertTrue((newblk.clfcs == blk.clfcs).all()) 62 # ghost metrics. 63 self.assertTrue((newblk.gstndcrd == blk.gstndcrd).all()) 64 self.assertTrue((newblk.gstfccnd == blk.gstfccnd).all()) 65 self.assertTrue((newblk.gstfcnml == blk.gstfcnml).all()) 66 self.assertTrue((newblk.gstfcara == blk.gstfcara).all()) 67 self.assertTrue((newblk.gstclcnd == blk.gstclcnd).all()) 68 self.assertTrue((newblk.gstclvol == blk.gstclvol).all()) 69 # ghost type. 70 self.assertTrue((newblk.gstfctpn == blk.gstfctpn).all()) 71 self.assertTrue((newblk.gstcltpn == blk.gstcltpn).all()) 72 self.assertTrue((newblk.gstclgrp == blk.gstclgrp).all()) 73 # ghost connectivity. 74 self.assertTrue((newblk.gstfcnds == blk.gstfcnds).all()) 75 self.assertTrue((newblk.gstfccls == blk.gstfccls).all()) 76 self.assertTrue((newblk.gstclnds == blk.gstclnds).all()) 77 self.assertTrue((newblk.gstclfcs == blk.gstclfcs).all()) 78 # shared metrics. 79 self.assertTrue((newblk.shndcrd == blk.shndcrd).all()) 80 self.assertTrue((newblk.shfccnd == blk.shfccnd).all()) 81 self.assertTrue((newblk.shfcnml == blk.shfcnml).all()) 82 self.assertTrue((newblk.shfcara == blk.shfcara).all()) 83 self.assertTrue((newblk.shclcnd == blk.shclcnd).all()) 84 self.assertTrue((newblk.shclvol == blk.shclvol).all()) 85 # shared type. 86 self.assertTrue((newblk.shfctpn == blk.shfctpn).all()) 87 self.assertTrue((newblk.shcltpn == blk.shcltpn).all()) 88 self.assertTrue((newblk.shclgrp == blk.shclgrp).all()) 89 # shared connectivity. 90 self.assertTrue((newblk.shfcnds == blk.shfcnds).all()) 91 self.assertTrue((newblk.shfccls == blk.shfccls).all()) 92 self.assertTrue((newblk.shclnds == blk.shclnds).all()) 93 self.assertTrue((newblk.shclfcs == blk.shclfcs).all())
94
95 -class TestReloadOldTrivial(CheckBlockIO):
96 - def _check_reload(self, blk, compressor):
97 from cStringIO import StringIO 98 from ..block import BlockIO 99 # save. 100 bio = BlockIO(compressor=compressor, fmt='OldTrivialBlockFormat') 101 dataio = StringIO() 102 bio.save(blk=blk, stream=dataio) 103 value = dataio.getvalue() 104 # load. 105 bio = BlockIO(fmt='OldTrivialBlockFormat') 106 dataio = StringIO(value) 107 newblk = bio.load(stream=dataio) 108 # check 109 self._check_shape(newblk, blk) 110 self._check_group(newblk, blk) 111 self._check_bc(newblk, blk) 112 self._check_array(newblk, blk)
113 - def test_reload2d_raw(self):
115 - def test_reload2d_gz(self):
117 - def test_reload2d_bz2(self):
119 - def test_reload3d_raw(self):
121 - def test_reload3d_gz(self):
123 - def test_reload3d_bz2(self):
125 -class TestLoadOldTrivial(CheckBlockIO):
126 - def _check_load(self, blk, stream):
127 from ..block import BlockIO 128 bio = BlockIO(fmt='OldTrivialBlockFormat') 129 # check version of stream. 130 meta = bio.read_meta(stream=stream) 131 self.assertEqual(meta.FORMAT_REV, '0.0.0.1') 132 # load from steam. 133 blkl = bio.load(stream=stream) 134 # check. 135 self._check_shape(blk, blkl) 136 self._check_group(blk, blkl) 137 self._check_bc(blk, blkl) 138 self._check_array(blk, blkl)
139 - def test_load2d_raw(self):
140 from ...testing import openfile 141 self._check_load(get_blk_from_oblique_neu(), openfile( 142 'oblique_0.0.0.1.blk', 'rb'))
143 - def test_load2d_gz(self):
144 from ...testing import openfile 145 self._check_load(get_blk_from_oblique_neu(), openfile( 146 'oblique_0.0.0.1_gz.blk', 'rb'))
147 - def test_load2d_bz2(self):
148 from ...testing import openfile 149 self._check_load(get_blk_from_oblique_neu(), openfile( 150 'oblique_0.0.0.1_bz2.blk', 'rb'))
151 - def test_load3d_raw(self):
152 from ...testing import openfile 153 self._check_load(get_blk_from_sample_neu(), openfile( 154 'sample_0.0.0.1.blk', 'rb'))
155 - def test_load3d_gz(self):
156 from ...testing import openfile 157 self._check_load(get_blk_from_sample_neu(), openfile( 158 'sample_0.0.0.1_gz.blk', 'rb'))
159 - def test_load3d_bz2(self):
160 from ...testing import openfile 161 self._check_load(get_blk_from_sample_neu(), openfile( 162 'sample_0.0.0.1_bz2.blk', 'rb'))
163 -class TestDetectLoad(CheckBlockIO):
164 - def test_load_oldtrivial2d(self):
165 import os 166 from ...conf import env 167 from ..block import BlockIO 168 # determine file path. 169 path = [env.datadir] + ['oblique_0.0.0.1.blk'] 170 path = os.path.join(*path) 171 # load block. 172 bio = BlockIO(filename=path) 173 meta = bio.read_meta() 174 self.assertEqual(meta.FORMAT_REV, '0.0.0.1') 175 blkl = bio.load() 176 # check with neu block. 177 blk = get_blk_from_oblique_neu() 178 self._check_shape(blk, blkl) 179 self._check_group(blk, blkl) 180 self._check_bc(blk, blkl) 181 self._check_array(blk, blkl)
182 - def test_load_oldtrivial3d(self):
183 import os 184 from ...conf import env 185 from ..block import BlockIO 186 # determine file path. 187 path = [env.datadir] + ['sample_0.0.0.1.blk'] 188 path = os.path.join(*path) 189 # load block. 190 bio = BlockIO(filename=path) 191 meta = bio.read_meta() 192 self.assertEqual(meta.FORMAT_REV, '0.0.0.1') 193 blkl = bio.load() 194 # check with neu block. 195 blk = get_blk_from_sample_neu() 196 self._check_shape(blk, blkl) 197 self._check_group(blk, blkl) 198 self._check_bc(blk, blkl) 199 self._check_array(blk, blkl)
200
201 -class TestReloadTrivial(CheckBlockIO):
202 - def _check_reload(self, blk, compressor):
203 from cStringIO import StringIO 204 from ..block import BlockIO 205 # save. 206 bio = BlockIO(compressor=compressor, fmt='TrivialBlockFormat') 207 dataio = StringIO() 208 bio.save(blk=blk, stream=dataio) 209 value = dataio.getvalue() 210 # load. 211 bio = BlockIO(fmt='TrivialBlockFormat') 212 dataio = StringIO(value) 213 newblk = bio.load(stream=dataio) 214 # check 215 self._check_shape(newblk, blk) 216 self._check_group(newblk, blk) 217 self._check_bc(newblk, blk) 218 self._check_array(newblk, blk)
219 - def test_reload2d_raw(self):
221 - def test_reload2d_gz(self):
223 - def test_reload2d_bz2(self):
225 - def test_reload3d_raw(self):
227 - def test_reload3d_gz(self):
229 - def test_reload3d_bz2(self):
231