Exemple #1
0
    def test_blake_dflt_regress(self):
        r"""Regression test of default solver instance.

        Compares current output on :attr:`TestBlakeSolution.intl_test_grid`
        (three points) using the default solver instance against regression
        standard output, :attr:`TestBlakeSolution.blk_dflt_std`.
        """

        print ' '
        tsnap = Blake.tsnap_default
        grid = TestBlakeSolution.intl_test_grid
        blk_dflt_std = self.blk_dflt_std
        blk_dflt_std_shp = self.blk_dflt_std_shp
        curr_slvr = Blake()
        curr_soln = curr_slvr(grid, tsnap)

        # ###NOTE### rec_array.view() requires that both both dtype and type
        # be specified to get correct conversion, even if dtype is not changed.
        # recarray.view(..., type=np.ndarray) is a 1D array.
        curr_soln_2d = np.reshape(
            curr_soln.view(dtype=np.float64, type=np.ndarray),
            blk_dflt_std_shp)

        abstol = 0.0
        reltol = 1.0e-15
        errmsg = TestBlakeSolution.errmsg_pre + str(reltol)

        np.testing.assert_allclose(curr_soln_2d,
                                   blk_dflt_std,
                                   atol=abstol,
                                   rtol=reltol,
                                   verbose=True,
                                   err_msg=errmsg)
Exemple #2
0
    def test_defaults(self):
        """Test default param values are present in the default solver."""

        lame_mod = 25.0e9
        shear_mod = 25.0e9
        youngs_mod = 62.5e9
        poisson_ratio = 0.25
        bulk_mod = 41.66666666666667e9
        long_mod = 75.0e9
        # other dflts
        geometry = 3
        ref_density = 3000.0
        cavity_radius = 0.1
        pressure_scale = 1.0e6
        blake_debug = False

        slvr = Blake()
        self.assertEqual(slvr.lame_mod, lame_mod)
        self.assertEqual(slvr.shear_mod, shear_mod)
        self.assertEqual(slvr.youngs_mod, youngs_mod)
        self.assertEqual(slvr.poisson_ratio, poisson_ratio)
        self.assertEqual(slvr.bulk_mod, bulk_mod)
        self.assertEqual(slvr.long_mod, long_mod)
        self.assertEqual(slvr.geometry, geometry)
        self.assertEqual(slvr.ref_density, ref_density)
        self.assertEqual(slvr.cavity_radius, cavity_radius)
        self.assertEqual(slvr.pressure_scale, pressure_scale)
        self.assertEqual(slvr.blake_debug, blake_debug)
Exemple #3
0
 def test_pscale_warn_check(self):
     """Test the pressure_scale parameter range warning."""
     with warnings.catch_warnings(record=True) as wcm:
         # Default bulk_mod big enough to trigger this warning.
         big_pscale = self.elas_dflt_prms['bulk_mod']
         blk_slvr = Blake(pressure_scale=big_pscale)  # trigger
         # test
         assert len(wcm) > 0
         assert issubclass(wcm[-1].category, UserWarning)
         assert 'pressure_scale parameter' in str(wcm[-1].message)
Exemple #4
0
    def test_radii_positive_check(self):
        """Test execution radial coordinates positive check."""

        blk_slvr = Blake()
        radii = np.array([-1., 1.])
        tsnap = Blake.tsnap_default
        args = [radii, tsnap]
        kwargs = {}
        self.assertRaisesRegexp(ValueError, "Minimum coordinate.*is negative",
                                blk_slvr, *args, **kwargs)
Exemple #5
0
    def test_assign_non_elastic_params(self):
        """Test that the non-elastic parameters are passed to the instance."""

        geom = 3
        refd = 6000.0
        crad = 0.25
        pscl = 1.0e8
        dbgflag = False

        slvr = Blake(geometry=geom, ref_density=refd, cavity_radius=crad,
                     pressure_scale=pscl, blake_debug=dbgflag)
        self.assertEqual(slvr.geometry, geom)
        self.assertEqual(slvr.ref_density, refd)
        self.assertEqual(slvr.cavity_radius, crad)
        self.assertEqual(slvr.pressure_scale, pscl)
        self.assertEqual(slvr.blake_debug, dbgflag)
Exemple #6
0
    def test_blake_non_dflt_regress(self):
        r"""Regression test of solver instance with param values given.

        Same as test_blake_dflt_regress() but a full set of default parameter
        values are supplied.
        """

        elas_dflt_keys = self.elas_dflt_keys
        elas_dflt_prms = self.elas_dflt_prms

        # Use dflt values of bulk_mod, long_mod as elas param values.
        kwargs = {k: elas_dflt_prms[k] for k in elas_dflt_keys[4:6]}
        # Specify all the non-elastic params (dflt values).
        kwargs.update({
            'geometry': 3,
            'ref_density': 3000.0,
            'cavity_radius': 0.1,
            'pressure_scale': 1.0e6
        })

        tsnap = Blake.tsnap_default
        grid = TestBlakeSolution.intl_test_grid
        blk_dflt_std = self.blk_dflt_std
        blk_dflt_std_shp = self.blk_dflt_std_shp
        curr_slvr = Blake(**kwargs)
        curr_soln = curr_slvr(grid, tsnap)
        curr_soln_2d = np.reshape(
            curr_soln.view(dtype=np.float64, type=np.ndarray),
            blk_dflt_std_shp)

        abstol = 0.
        reltol = 1.0e-12  # NOT 1.0e-15 as in full-default case.
        errmsg = TestBlakeSolution.errmsg_pre + str(reltol)

        # There is some loss of accuracy in computing the solution
        # in this case.  Non-elastic params are specified exactly here,
        # so they aren't the cause.
        # However, the given elastic params here are NOT those used internally
        # for default soln calculation.  Calculation of the internal
        # elastic params causes this loss of accuracy.
        # This is dependent on which params are given here.
        np.testing.assert_allclose(curr_soln_2d,
                                   blk_dflt_std,
                                   atol=abstol,
                                   rtol=reltol,
                                   verbose=True,
                                   err_msg=errmsg)
Exemple #7
0
    def test_blake_vs_kamm(self):
        r"""Test spherical Blake fields and compare against Kamm output."""

        # kamm_sph_dat: Kamm F90 solver output data.
        kamm_sph_dat1 = np.array([
            #    0                      1                       2
            #    position               displacement            stress_rad
            3.75000000000000E-02,
            0.00000000000000E+00,
            0.00000000000000E+00,
            1.12500000000000E-01,
            7.91729548518875E-07,
            -7.02702469218342E+05,
            1.87500000000000E-01,
            2.84225705240826E-07,
            -1.54399885073962E+05,
            2.62500000000000E-01,
            1.41455165224225E-07,
            -6.01559358293565E+04,
            3.37500000000000E-01,
            7.96700674058918E-08,
            -3.15798436396484E+04,
            4.12500000000000E-01,
            4.74304458774152E-08,
            -1.70103854094798E+04,
            4.87500000000000E-01,
            3.27363284735378E-08,
            -3.40137748463715E+03,
            5.62500000000000E-01,
            3.39585162727519E-08,
            1.21503162121726E+04,
            6.37500000000000E-01,
            4.99358394789389E-08,
            2.55080127582440E+04,
            7.12500000000000E-01,
            7.26569497152086E-08,
            2.55556598291575E+04,
            7.87500000000000E-01,
            8.17337333358558E-08,
            -2.65424005640929E+03,
            8.62500000000000E-01,
            4.52710826644583E-08,
            -6.78530461070724E+04,
            9.37500000000000E-01,
            0.00000000000000E+00,
            0.00000000000000E+00,
            1.01250000000000E+00,
            0.00000000000000E+00,
            0.00000000000000E+00,
            1.08750000000000E+00,
            0.00000000000000E+00,
            0.00000000000000E+00,
            1.16250000000000E+00,
            0.00000000000000E+00,
            0.00000000000000E+00,
        ]).reshape(16, 3)

        kamm_sph_dat2 = np.array([
            #    3                      4                       5
            #    stress_hoop            pressure                stress_diff
            0.00000000000000E+00,
            0.00000000000000E+00,
            0.00000000000000E+00,
            3.52232175830090E+05,
            -5.87294147279051E+02,
            1.05493464504843E+06,
            7.48559073046019E+04,
            1.56269015491954E+03,
            2.29255792378564E+05,
            2.48544230486987E+04,
            3.48236324398638E+03,
            8.50103588780552E+04,
            9.14500703515220E+03,
            4.42994318978133E+03,
            4.07248506748006E+04,
            3.91177978823708E+03,
            3.06227527766854E+03,
            2.09221651977169E+04,
            4.46216109034108E+03,
            -1.84098156534834E+03,
            7.86353857497823E+03,
            9.08099670372448E+03,
            -1.01041032065405E+04,
            3.06931950844813E+03,
            1.50302316356158E+04,
            -1.85228253431586E+04,
            1.04777811226282E+04,
            1.70164421319658E+04,
            -1.98628480310297E+04,
            8.53921769719173E+03,
            7.76432562520280E+03,
            -4.29147039799877E+03,
            1.04185656816121E+04,
            -1.82436643869509E+04,
            3.47801249603247E+04,
            4.96093817201215E+04,
            0.00000000000000E+00,
            0.00000000000000E+00,
            0.00000000000000E+00,
            0.00000000000000E+00,
            0.00000000000000E+00,
            0.00000000000000E+00,
            0.00000000000000E+00,
            0.00000000000000E+00,
            0.00000000000000E+00,
            0.00000000000000E+00,
            0.00000000000000E+00,
            0.00000000000000E+00,
        ]).reshape(16, 3)

        # finalize kamm data: column index is leftmost
        kamm_sph_dat = np.hstack((kamm_sph_dat1, kamm_sph_dat2))
        del kamm_sph_dat1
        del kamm_sph_dat2

        # set the grid
        grid_dr = 0.075
        dom_max = 1.2
        npts = int(round(dom_max / grid_dr))
        rmin = grid_dr / 2.
        rmax = dom_max - rmin  # mesh limits: diff than domain.
        radii = np.linspace(rmin, rmax, npts)
        # snapshot time
        tsnap = Blake.tsnap_default

        # attr_to_kmprms
        # key   = solution (recarray) attribute name.
        # value = (ndx, rtol), ndx = kamm array col index,
        #                      rtol = tolerance per key.
        attribs = ('position', 'displacement', 'stress_rr', 'stress_qq',
                   'pressure', 'stress_diff')
        rtol_scale = 1.e-15
        rtols = [rtol_scale * m for m in (1, 10, 100, 100, 200, 100)]
        values = zip(range(6), rtols)
        attr_to_kmprms = dict(zip(attribs, values))

        # Solver and solution
        brock_blk_solver = Blake()
        soln = brock_blk_solver(radii, tsnap)

        abstol = 0.0
        print '\nAbs. tolerance = ', abstol

        for ky in attr_to_kmprms:
            cmd = 'pyth = soln.' + ky
            exec(cmd, None, None)
            kamm = kamm_sph_dat[:, attr_to_kmprms[ky][0]]
            errormsg = ('Blake solver and Kamm data for: ' + ky +
                        ', DO NOT agree!')
            np.testing.assert_allclose(pyth,
                                       kamm,
                                       rtol=attr_to_kmprms[ky][1],
                                       atol=abstol,
                                       verbose=True,
                                       err_msg=errormsg)
            # If here then OK
            okmsg = ('Blake solver and Kamm data agree for: ' + ky +
                     ', \twith rel. tol. = ' + str(attr_to_kmprms[ky][1]))
            print okmsg
Exemple #8
0
import matplotlib.pyplot as plt  # could also import matplotlib.pylab
import numpy as np

# !!!!!!!!!!!!!!!!!!!! SI units ###ONLY### !!!!!!!!!!!!!!!!!!!!

# Set the grid and snapshot time
grid_dr = 0.002
dom_max = 1.0
npts = int(round(dom_max / grid_dr)) + 1
rmin = 0.1
rmax = dom_max  # mesh limits: diff than domain.
radii = np.linspace(rmin, rmax, npts)
tsnap = 1.6e-4

# All elastic params defaulted, two other params set to default values.
blkslvr = Blake(cavity_radius=rmin, pressure_scale=1.0e6)  # solver
blksoln = blkslvr(radii, tsnap)  # solution

# Output field names
soln_attrs = blksoln.dtype.names

# Plot using
plt.style.use('ggplot')
# plot fig not essential for single fig plot.
fig = plt.figure(figsize=(10, 14), dpi=100)

# Multiline overall (superior) title
fig.suptitle(
    """ExactPack Spherical Blake solver: t$_{\\rm snap} = 1.6E-4\\,{\\rm s}$
    \npressure_scale = 1.0E6""",
    linespacing=0.5,