Ejemplo n.º 1
0
    def test_toStr(self):
        testStr = r"\sigma"
        testFloat = 0.666
        testInt = 666

        self.assertEqual(Latex.toStr(testStr), "\\sigma")
        self.assertEqual(Latex.toStr(testFloat), '6.66 \\cdot 10^{-1}')
        self.assertEqual(Latex.toStr(testInt), '6.66 \\cdot 10^{2}')
Ejemplo n.º 2
0
 def M_max(self, pretty=False):
     M_max = np.max(self.M) * ureg.N * ureg.m**-2
     if pretty:
         pr = Latex.display(
             Latex.toStr(r"M_{max} = \max(M_{nom}) \rightarrow " +
                         Latex.toStr(M_max)))
         return [M_max, pr]
     else:
         return M_max
Ejemplo n.º 3
0
def flowrate(v, A, pretty=False):
    Q = v * A
    Q = Q.to_base_units()
    if pretty:
        pr = Latex.display(Latex.toStr(
            r"Q_{f} = v_{f} \times A \rightarrow " + Latex.toStr(v) + r" \times " + Latex.toStr(
                A) + r" = " + Latex.toStr(Q)))
        return [Q, pr]
    return Q
Ejemplo n.º 4
0
 def test_array(self):
     test_arr3_4 = [[1, 2, 3, r"\sigma_0"], [4, 5, 6, r"\sigma_1"],
                    [7, 8, 9, r"\sigma_2"]]
     test_arr1_2 = [[1], [r"\sigma_0"]]
     self.assertEqual(
         Latex.array(test_arr3_4),
         '\\begin{array}{ccc}1.00&2.00&3.00&\\sigma_0\\\\ 4.00&5.00&6.00&\\sigma_1\\\\ 7.00&8.00&9.00&\\sigma_2\\end{array}'
     )
     self.assertEqual(Latex.array(test_arr1_2),
                      '\\begin{array}{c}1.00\\\\ \\sigma_0\\end{array}')
Ejemplo n.º 5
0
 def test_combined(self):
     test_unit_n = 0.666 * ureg.N**2
     test_unit_a = 3.333 * ureg.mm**200
     test_unit_p = test_unit_n / test_unit_a
     test_result = math.sqrt(test_unit_p.magnitude) * ureg.Pa * ureg.m**-98
     self.assertEqual(
         r'$\sqrt{\frac{6.66 \cdot 10^{-1} \left[N^{2}\right]}{3.33 \left[mm^{200}\right]}} = 4.47 \cdot 10^{-1} \left[\frac{Pa}{m^{98}}\right]$',
         Latex.formulaprint(
             Latex.sqrt(Latex.frac(test_unit_n, test_unit_a)) + r" = " +
             Latex.toStr(test_result)))
Ejemplo n.º 6
0
 def M_b(self, pretty=False):
     M_b = self.M_max() * self.properties.appliancefactor.K_a
     if pretty:
         pr = Latex.display(
             Latex.toStr(r"M_{b} = K_A \max(M_{nom}) \times \rightarrow " +
                         Latex.toStr(self.properties.appliancefactor.K_a) +
                         r" \times " + Latex.toStr(self.M_max()) + r" = " +
                         Latex.toStr(self.M_b())))
         return [M_b, pr]
     else:
         return M_b
Ejemplo n.º 7
0
    def d_a(self, k: float = 0.5, pretty=False):
        if not self.properties.geometry.solved:
            self.solvegeometry()
        d_a = 3.4 * math.pow(
            self.M_b() /
            ((1 - math.pow(k, 4)) * self.properties.material.sigma_bWN),
            1 / 3) * ureg.meter

        if pretty:
            formArray = [
                [self.M_b(pretty=True)[1].data[1:-1]],
                [
                    r"d_{a} = \approx 3.4 " + Latex.sqrt(
                        Latex.frac(r"M_{b}",
                                   r"\left(1 - k^4 \right) \sigma_{bWN}"), 3) +
                    r" \rightarrow 3.4 [m] " + Latex.sqrt(
                        Latex.frac(
                            self.M_b(),
                            r"\left(1 - " + str(k) + r"^{4} " + r"\right)" +
                            Latex.toStr(self.properties.material.sigma_bWN)),
                        3) + r" \approx " + Latex.toStr(d_a)
                ]
            ]
            pr = Latex.display(Latex.array(formArray))
            return [d_a, pr]
        else:
            return d_a
Ejemplo n.º 8
0
 def test_unit(self):
     test_unit_n = 0.666 * ureg.N
     test_unit_a = 3.333 * ureg.mm**2
     test_unit = test_unit_n / test_unit_a
     self.assertEqual(
         Latex.toStr(test_unit),
         '2.00 \\cdot 10^{-1} \\left[\\frac{N}{mm^{2}}\\right]')
Ejemplo n.º 9
0
    def d_prime(self, pretty=False):
        if not self.properties.geometry.solved:
            self.solvegeometry()
        d_prime = 3.4 * math.pow(
            self.M_b() / self.properties.material.sigma_bWN,
            1 / 3) * ureg.meter

        if pretty:
            formArray = [
                [self.M_b(pretty=True)[1].data[1:-1]],
                [
                    r"d^{'} = \approx 3.4 " +
                    Latex.sqrt(Latex.frac(r"M_{b}", r"\sigma_{bWN}"), 3) +
                    r" \rightarrow 3.4 [m] " + Latex.sqrt(
                        Latex.frac(self.M_b(),
                                   self.properties.material.sigma_bWN), 3) +
                    r" \approx " + Latex.toStr(d_prime)
                ]
            ]
            pr = Latex.display(Latex.array(formArray))
            return [d_prime, pr]
        else:
            return d_prime
Ejemplo n.º 10
0
 def __str__(self):
     return 'Name: ' + str(self.name) + ' at ' + Latex.formulaprint(
         self.TdegC) + '<br/> Density: ' + Latex.formulaprint(self.rho)
Ejemplo n.º 11
0
def Reynolds(v, D, rho=None, mu=None, nu=None, fluid=None, pretty=False):
    if mu is not None and rho is not None:
        Re = (v * D * rho) / mu
        Re = Re.to_base_units()
        if pretty:
            pr = Latex.display(
                Latex.toStr(r"Re = \frac{v{f} \times D_i \times \rho_{f}}{\mu_{f}} \rightarrow \frac{" + Latex.toStr(
                    v) + r" \times " + Latex.toStr(D) + r" \times " + Latex.toStr(rho) + r"}{" + Latex.toStr(
                    mu) + r"} = " + Latex.toStr(Re)))
            return [Re, pr]
        else:
            return Re
    elif nu is not None:
        Re = (v * D) / nu
        Re = Re.to_base_units()
        if pretty:
            pr = Latex.display(
                Latex.toStr(r"Re = \frac{v{f} \times D_{i}}{\nu_{f}} \rightarrow \frac{" + Latex.toStr(
                    v) + r" \times " + Latex.toStr(D) + r" \times " + Latex.toStr(rho) + r"}{" + Latex.toStr(
                    mu) + r"} = " + Latex.toStr(Re)))
            return [Re, pr]
        else:
            return Re
    elif fluid is not None:
        Re = (v * D.to('m') * fluid.rho) / fluid.mu
        Re = Re.to_base_units()
        if pretty:
            pr = Latex.display(Latex.toStr(
                r"Re = \frac{v{f} \times D_i \times \rho_{f}}{\mu_{f}} \rightarrow \frac{" + Latex.toStr(
                    v) + r" \times " + Latex.toStr(D) + r" \times " + Latex.toStr(fluid.rho) + r"}{" + Latex.toStr(
                    fluid.mu) + r"} = " + Latex.toStr(Re)))
            return [Re, pr]
        else:
            return Re
    else:
        print('Error! Either fill in mu, nu or a fluid')
        return None
    return Re
Ejemplo n.º 12
0
 def test_sqrt(self):
     self.assertEqual(Latex.sqrt(5), '\\sqrt{5.00}')
     self.assertEqual(Latex.sqrt(5, 3), '\\sqrt[3]{5.00}')
Ejemplo n.º 13
0
 def __str__(self):
     return Material.__str__(self) + '<br/>Gamma: ' + Latex.formulaprint(
         self.gamma) + '<br/>Dynamic viscosity: ' + Latex.formulaprint(
         self.mu) + '<br/>Kinematic viscosity: ' + Latex.formulaprint(self.nu)