Example #1
0
    def _get_force_evaluator(self):
        from pysph.solver.utils import load
        from pysph.base.kernels import QuinticSpline
        from pysph.tools.sph_evaluator import SPHEvaluator
        from pysph.sph.equation import Group
        from pysph.sph.wc.transport_velocity import (
            SetWallVelocity, MomentumEquationPressureGradient,
            SolidWallNoSlipBC, VolumeSummation, MomentumEquationViscosity)
        data = load(self.output_files[0])
        solid = data['arrays']['solid']
        fluid = data['arrays']['fluid']

        prop = [
            'awhat', 'auhat', 'avhat', 'wg', 'vg', 'ug', 'V', 'uf', 'vf', 'wf',
            'wij', 'vmag'
        ]
        for p in prop:
            solid.add_property(p)
            fluid.add_property(p)
        equations = [
            Group(equations=[
                SetWallVelocity(dest='fluid', sources=['solid']),
                VolumeSummation(dest='fluid', sources=['fluid', 'solid']),
                VolumeSummation(dest='solid', sources=['fluid', 'solid']),
            ],
                  real=False),
            Group(
                equations=[
                    # Pressure gradient terms
                    MomentumEquationPressureGradient(
                        dest='solid', sources=['fluid', 'solid'], pb=p0),
                    MomentumEquationViscosity(dest='solid',
                                              sources=['fluid', 'solid'],
                                              nu=self.nu),
                    SolidWallNoSlipBC(dest='solid',
                                      sources=['fluid'],
                                      nu=self.nu),
                ],
                real=True),
        ]
        sph_eval = SPHEvaluator(arrays=[solid, fluid],
                                equations=equations,
                                dim=2,
                                kernel=QuinticSpline(dim=2))

        return sph_eval
Example #2
0
    def get_equations(self):
        from pysph.sph.wc.transport_velocity import (
            StateEquation, SetWallVelocity, SolidWallPressureBC,
            VolumeSummation, SolidWallNoSlipBC,
            MomentumEquationArtificialViscosity, ContinuitySolid)
        all = self.fluids + self.solids

        stage1 = []
        if self.solids:
            eq0 = []
            for solid in self.solids:
                eq0.append(SetWallVelocity(dest=solid, sources=self.fluids))
            stage1.append(Group(equations=eq0, real=False))

        eq1 = []
        for fluid in self.fluids:
            eq1.append(ContinuityEquationGTVF(dest=fluid, sources=self.fluids))
            if self.solids:
                eq1.append(ContinuitySolid(dest=fluid, sources=self.solids))
        stage1.append(Group(equations=eq1, real=False))

        eq2, stage2 = [], []
        for fluid in self.fluids:
            eq2.append(CorrectDensity(dest=fluid, sources=all))
        stage2.append(Group(equations=eq2, real=False))

        eq3 = []
        for fluid in self.fluids:
            eq3.append(
                StateEquation(dest=fluid,
                              sources=None,
                              p0=self.pref,
                              rho0=self.rho0,
                              b=1.0))
        stage2.append(Group(equations=eq3, real=False))

        g2_s = []
        for solid in self.solids:
            g2_s.append(VolumeSummation(dest=solid, sources=all))
            g2_s.append(
                SolidWallPressureBC(dest=solid,
                                    sources=self.fluids,
                                    b=1.0,
                                    rho0=self.rho0,
                                    p0=self.pref,
                                    gx=self.gx,
                                    gy=self.gy,
                                    gz=self.gz))
        if g2_s:
            stage2.append(Group(equations=g2_s, real=False))

        eq4 = []
        for fluid in self.fluids:
            eq4.append(
                MomentumEquationPressureGradient(dest=fluid,
                                                 sources=all,
                                                 pref=self.pref,
                                                 gx=self.gx,
                                                 gy=self.gy,
                                                 gz=self.gz))
            if self.alpha > 0.0:
                eq4.append(
                    MomentumEquationArtificialViscosity(dest=fluid,
                                                        sources=all,
                                                        c0=self.c0,
                                                        alpha=self.alpha))
            if self.nu > 0.0:
                eq4.append(
                    MomentumEquationViscosity(dest=fluid,
                                              sources=all,
                                              nu=self.nu))
                if self.solids:
                    eq4.append(
                        SolidWallNoSlipBC(dest=fluid,
                                          sources=self.solids,
                                          nu=self.nu))
            eq4.append(
                MomentumEquationArtificialStress(dest=fluid,
                                                 sources=self.fluids,
                                                 dim=self.dim))
        stage2.append(Group(equations=eq4, real=True))

        return MultiStageEquations([stage1, stage2])
Example #3
0
    def _get_ppe(self):
        from pysph.sph.wc.transport_velocity import VolumeSummation

        all = self.fluids + self.solids
        all_solids = self.solids

        eq, stg = [], []

        for fluid in self.fluids:
            eq.append(SummationDensity(dest=fluid, sources=all))
        stg.append(Group(equations=eq, real=False))

        eq2 = []
        for fluid in self.fluids:
            eq2.append(VolumeSummation(dest=fluid, sources=all))
            eq2.append(VelocityDivergence(dest=fluid, sources=self.fluids))
            if self.solids:
                eq2.append(VelocityDivergenceSolid(fluid, sources=self.solids))
        stg.append(Group(equations=eq2))

        solver_eqns = []
        if self.has_ghosts:
            ghost_eqns = Group(equations=[
                UpdateGhostPressure(dest=fluid, sources=None)
                for fluid in self.fluids
            ],
                               real=False)
            solver_eqns = [ghost_eqns]

        if all_solids:
            g3 = self._get_pressure_bc()
            solver_eqns.append(g3)

        eq3 = []
        for fluid in self.fluids:
            if not fluid == 'outlet':
                eq3.append(
                    PressureCoeffMatrixIterative(dest=fluid, sources=all))
                eq3.append(
                    PPESolve(dest=fluid,
                             sources=all,
                             rho0=self.rho0,
                             rho_cutoff=self.rho_cutoff,
                             tolerance=self.tolerance,
                             omega=self.omega,
                             max_iterations=self.max_iterations))
        eq3 = Group(equations=eq3)

        solver_eqns.append(eq3)

        stg.append(
            Group(equations=solver_eqns,
                  iterate=True,
                  max_iterations=self.max_iterations,
                  min_iterations=2))

        if self.has_ghosts:
            ghost_eqns = Group(equations=[
                UpdateGhostPressure(dest=fluid, sources=None)
                for fluid in self.fluids
            ],
                               real=False)
            stg.append(ghost_eqns)
        return stg
Example #4
0
    def _plot_cd_vs_t(self):
        from pysph.solver.utils import iter_output, load
        from pysph.tools.sph_evaluator import SPHEvaluator
        from pysph.sph.equation import Group
        from pysph.sph.wc.transport_velocity import (SetWallVelocity,
            MomentumEquationPressureGradient, SolidWallNoSlipBC,
            SolidWallPressureBC, VolumeSummation)

        data = load(self.output_files[0])
        solid = data['arrays']['solid']
        fluid = data['arrays']['fluid']
        x, y = solid.x.copy(), solid.y.copy()
        cx = 0.5 * L; cy = 0.5 * H
        inside = np.sqrt((x-cx)**2 + (y-cy)**2) <= a
        dest = solid.extract_particles(inside.nonzero()[0])
        # We use the same equations for this as the simulation, except that we
        # do not include the acceleration terms as these are externally
        # imposed.  The goal of these is to find the force of the fluid on the
        # cylinder, thus, gx=0.0 is used in the following.
        equations = [
            Group(
                equations=[
                    VolumeSummation(
                        dest='fluid', sources=['fluid', 'solid']
                    ),
                    VolumeSummation(
                        dest='solid', sources=['fluid', 'solid']
                    ),
                    ], real=False),

            Group(
                equations=[
                    SetWallVelocity(dest='solid', sources=['fluid']),
                    ], real=False),

            Group(
                equations=[
                    SolidWallPressureBC(dest='solid', sources=['fluid'],
                                        gx=0.0, b=1.0, rho0=rho0, p0=p0),
                    ], real=False),

            Group(
                equations=[
                    # Pressure gradient terms
                    MomentumEquationPressureGradient(
                        dest='fluid', sources=['solid'], gx=0.0, pb=pb),
                    SolidWallNoSlipBC(
                        dest='fluid', sources=['solid'], nu=nu),
                    ], real=True),
        ]

        sph_eval = SPHEvaluator(
            arrays=[dest, fluid], equations=equations, dim=2,
            kernel=QuinticSpline(dim=2)
        )

        t, cd = [], []
        for sd, fluid in iter_output(self.output_files, 'fluid'):
            fluid.remove_property('vmag2')
            t.append(sd['t'])
            sph_eval.update_particle_arrays([dest, fluid])
            sph_eval.evaluate()
            Fx = np.sum(-fluid.au*fluid.m)
            cd.append(Fx/(nu*rho0*Umax))

        t, cd = list(map(np.asarray, (t, cd)))

        # Now plot the results.
        import matplotlib
        matplotlib.use('Agg')

        from matplotlib import pyplot as plt
        f = plt.figure()
        plt.plot(t, cd)
        plt.xlabel('$t$'); plt.ylabel(r'$C_D$')
        fig = os.path.join(self.output_dir, "cd_vs_t.png")
        plt.savefig(fig, dpi=300)
        plt.close()

        return t, cd
Example #5
0
    def _get_external_flow_equations(self):

        from pysph.sph.basic_equations import XSPHCorrection
        from pysph.sph.wc.transport_velocity import (
            VolumeSummation, SolidWallNoSlipBC, SummationDensity,
            MomentumEquationArtificialViscosity, MomentumEquationViscosity)
        all_solids = self.solids + self.inviscid_solids
        all = self.fluids + all_solids

        edac_nu = self._get_edac_nu()
        equations = []
        group1 = []
        for fluid in self.fluids:
            group1.append(SummationDensity(dest=fluid, sources=all))
        for solid in self.solids:
            group1.extend([
                SourceNumberDensity(dest=solid, sources=self.fluids),
                VolumeSummation(dest=solid, sources=all),
                SolidWallPressureBC(dest=solid,
                                    sources=self.fluids,
                                    gx=self.gx,
                                    gy=self.gy,
                                    gz=self.gz),
                SetWallVelocity(dest=solid, sources=self.fluids),
            ])
            if self.clamp_p:
                group1.append(ClampWallPressure(dest=solid, sources=None))

        for solid in self.inviscid_solids:
            group1.extend([
                SourceNumberDensity(dest=solid, sources=self.fluids),
                NoSlipVelocityExtrapolation(dest=solid, sources=self.fluids),
                VolumeSummation(dest=solid, sources=all),
                SolidWallPressureBC(dest=solid,
                                    sources=self.fluids,
                                    gx=self.gx,
                                    gy=self.gy,
                                    gz=self.gz)
            ])

        equations.append(Group(equations=group1, real=False))

        group2 = []
        for fluid in self.fluids:
            group2.append(
                MomentumEquation(dest=fluid,
                                 sources=all,
                                 gx=self.gx,
                                 gy=self.gy,
                                 gz=self.gz,
                                 c0=self.c0,
                                 tdamp=self.tdamp))
            if self.alpha > 0.0:
                group2.append(
                    MomentumEquationArtificialViscosity(dest=fluid,
                                                        sources=all,
                                                        alpha=self.alpha,
                                                        c0=self.c0))
            if self.nu > 0.0:
                group2.append(
                    MomentumEquationViscosity(dest=fluid,
                                              sources=self.fluids,
                                              nu=self.nu))
            if len(self.solids) > 0 and self.nu > 0.0:
                group2.append(
                    SolidWallNoSlipBC(dest=fluid,
                                      sources=self.solids,
                                      nu=self.nu))
            group2.extend([
                EDACEquation(dest=fluid,
                             sources=all,
                             nu=edac_nu,
                             cs=self.c0,
                             rho0=self.rho0),
                XSPHCorrection(dest=fluid, sources=[fluid], eps=self.eps)
            ])
        equations.append(Group(equations=group2))

        return equations
Example #6
0
    def _get_internal_flow_equations(self):
        from pysph.sph.wc.transport_velocity import (
            VolumeSummation, SolidWallNoSlipBC, SummationDensity,
            MomentumEquationArtificialStress,
            MomentumEquationArtificialViscosity, MomentumEquationViscosity)
        edac_nu = self._get_edac_nu()

        iom = self.inlet_outlet_manager
        fluids_with_io = self.fluids
        all_solids = self.solids + self.inviscid_solids
        if iom is not None:
            fluids_with_io = self.fluids + iom.get_io_names()
        all = fluids_with_io + all_solids

        equations = []
        # inlet-outlet
        if iom is not None:
            io_eqns = iom.get_equations(self)
            for grp in io_eqns:
                equations.append(grp)

        group1 = []
        avg_p_group = []
        has_solids = len(all_solids) > 0
        for fluid in fluids_with_io:
            group1.append(SummationDensity(dest=fluid, sources=all))
            if self.bql:
                eq = ComputeAveragePressure(dest=fluid, sources=all)
                if has_solids:
                    avg_p_group.append(eq)
                else:
                    group1.append(eq)

        for solid in self.solids:
            group1.extend([
                SourceNumberDensity(dest=solid, sources=fluids_with_io),
                VolumeSummation(dest=solid, sources=all),
                SolidWallPressureBC(dest=solid,
                                    sources=fluids_with_io,
                                    gx=self.gx,
                                    gy=self.gy,
                                    gz=self.gz),
                SetWallVelocity(dest=solid, sources=fluids_with_io),
            ])
        for solid in self.inviscid_solids:
            group1.extend([
                SourceNumberDensity(dest=solid, sources=fluids_with_io),
                NoSlipVelocityExtrapolation(dest=solid,
                                            sources=fluids_with_io),
                NoSlipAdvVelocityExtrapolation(dest=solid,
                                               sources=fluids_with_io),
                VolumeSummation(dest=solid, sources=all),
                SolidWallPressureBC(dest=solid,
                                    sources=fluids_with_io,
                                    gx=self.gx,
                                    gy=self.gy,
                                    gz=self.gz)
            ])

        equations.append(Group(equations=group1, real=False))

        # Compute average pressure *after* the wall pressure is setup.
        if self.bql and has_solids:
            equations.append(Group(equations=avg_p_group, real=True))

        group2 = []
        for fluid in self.fluids:
            group2.append(
                MomentumEquationPressureGradient(dest=fluid,
                                                 sources=all,
                                                 pb=self.pb,
                                                 gx=self.gx,
                                                 gy=self.gy,
                                                 gz=self.gz,
                                                 tdamp=self.tdamp))
            if self.alpha > 0.0:
                sources = fluids_with_io + self.solids
                group2.append(
                    MomentumEquationArtificialViscosity(dest=fluid,
                                                        sources=sources,
                                                        alpha=self.alpha,
                                                        c0=self.c0))
            if self.nu > 0.0:
                group2.append(
                    MomentumEquationViscosity(dest=fluid,
                                              sources=fluids_with_io,
                                              nu=self.nu))
            if len(self.solids) > 0 and self.nu > 0.0:
                group2.append(
                    SolidWallNoSlipBC(dest=fluid,
                                      sources=self.solids,
                                      nu=self.nu))
            group2.extend([
                MomentumEquationArtificialStress(dest=fluid,
                                                 sources=fluids_with_io),
                EDACEquation(dest=fluid,
                             sources=all,
                             nu=edac_nu,
                             cs=self.c0,
                             rho0=self.rho0),
            ])
        equations.append(Group(equations=group2))

        print(equations)
        return equations
    def get_equations(self):
        from pysph.sph.equation import Group
        from pysph.sph.wc.basic import TaitEOS
        from pysph.sph.basic_equations import XSPHCorrection
        from pysph.sph.wc.transport_velocity import (
            ContinuityEquation, MomentumEquationPressureGradient,
            MomentumEquationViscosity, MomentumEquationArtificialViscosity,
            SolidWallPressureBC, SolidWallNoSlipBC, SetWallVelocity,
            VolumeSummation)

        equations = []
        all = self.fluids + self.solids

        g2 = []
        for fluid in self.fluids:
            g2.append(VolumeSummation(dest=fluid, sources=all))
            g2.append(
                TaitEOS(dest=fluid,
                        sources=None,
                        rho0=self.rho0,
                        c0=self.c0,
                        gamma=self.gamma,
                        p0=self.p0))
        for solid in self.solids:
            g2.append(VolumeSummation(dest=solid, sources=all))
            g2.append(SetWallVelocity(dest=solid, sources=self.fluids))

        equations.append(Group(equations=g2, real=False))

        g3 = []
        for solid in self.solids:
            g3.append(
                SolidWallPressureBC(dest=solid,
                                    sources=self.fluids,
                                    b=1.0,
                                    rho0=self.rho0,
                                    p0=self.B,
                                    gx=self.gx,
                                    gy=self.gy,
                                    gz=self.gz))

        equations.append(Group(equations=g3, real=False))

        g4 = []
        for fluid in self.fluids:
            g4.append(ContinuityEquation(dest=fluid, sources=all))
            g4.append(
                MomentumEquationPressureGradient(dest=fluid,
                                                 sources=all,
                                                 pb=0.0,
                                                 gx=self.gx,
                                                 gy=self.gy,
                                                 gz=self.gz,
                                                 tdamp=self.tdamp))
            if self.alpha > 0.0:
                g4.append(
                    MomentumEquationArtificialViscosity(dest=fluid,
                                                        sources=all,
                                                        c0=self.c0,
                                                        alpha=self.alpha))
            if self.nu > 0.0:
                g4.append(
                    MomentumEquationViscosity(dest=fluid,
                                              sources=self.fluids,
                                              nu=self.nu))
                if len(self.solids) > 0:
                    g4.append(
                        SolidWallNoSlipBC(dest=fluid,
                                          sources=self.solids,
                                          nu=self.nu))
            g4.append(XSPHCorrection(dest=fluid, sources=[fluid]))

        equations.append(Group(equations=g4))
        return equations
Example #8
0
File: edac.py Project: Duigi/pysph
    def _get_internal_flow_equations(self):
        from pysph.sph.wc.transport_velocity import (
            VolumeSummation, SolidWallNoSlipBC, SummationDensity,
            MomentumEquationArtificialStress,
            MomentumEquationArtificialViscosity, MomentumEquationViscosity)
        edac_nu = self._get_edac_nu()
        all = self.fluids + self.solids
        equations = []
        group1 = []
        avg_p_group = []
        has_solids = len(self.solids) > 0
        for fluid in self.fluids:
            group1.append(SummationDensity(dest=fluid, sources=all))
            if self.bql:
                eq = ComputeAveragePressure(dest=fluid, sources=all)
                if has_solids:
                    avg_p_group.append(eq)
                else:
                    group1.append(eq)

        for solid in self.solids:
            group1.extend([
                VolumeSummation(dest=solid, sources=all),
                SolidWallPressureBC(dest=solid,
                                    sources=self.fluids,
                                    gx=self.gx,
                                    gy=self.gy,
                                    gz=self.gz),
                SetWallVelocity(dest=solid, sources=self.fluids),
            ])

        equations.append(Group(equations=group1, real=False))

        # Compute average pressure *after* the wall pressure is setup.
        if self.bql and has_solids:
            equations.append(Group(equations=avg_p_group, real=True))

        group2 = []
        for fluid in self.fluids:
            group2.append(
                MomentumEquationPressureGradient(dest=fluid,
                                                 sources=all,
                                                 pb=self.pb,
                                                 gx=self.gx,
                                                 gy=self.gy,
                                                 gz=self.gz,
                                                 tdamp=self.tdamp))
            if self.alpha > 0.0:
                group2.append(
                    MomentumEquationArtificialViscosity(dest=fluid,
                                                        sources=all,
                                                        alpha=self.alpha,
                                                        c0=self.c0))
            if self.nu > 0.0:
                group2.append(
                    MomentumEquationViscosity(dest=fluid,
                                              sources=self.fluids,
                                              nu=self.nu))
            if len(self.solids) > 0 and self.nu > 0.0:
                group2.append(
                    SolidWallNoSlipBC(dest=fluid,
                                      sources=self.solids,
                                      nu=self.nu))
            group2.extend([
                MomentumEquationArtificialStress(dest=fluid,
                                                 sources=self.fluids),
                EDACEquation(dest=fluid,
                             sources=all,
                             nu=edac_nu,
                             cs=self.c0,
                             rho0=self.rho0),
            ])
        equations.append(Group(equations=group2))

        return equations
Example #9
0
    def _get_external_flow_equations(self):

        from pysph.sph.basic_equations import XSPHCorrection
        from pysph.sph.wc.transport_velocity import (
            VolumeSummation, SolidWallNoSlipBC, SummationDensity,
            MomentumEquationArtificialViscosity,
            MomentumEquationViscosity
        )

        iom = self.inlet_outlet_manager
        fluids_with_io = self.fluids
        all_solids = self.solids + self.inviscid_solids
        if iom is not None:
            fluids_with_io = self.fluids + iom.get_io_names()
        all = fluids_with_io + all_solids

        edac_nu = self._get_edac_nu()
        equations = []
        # inlet-outlet
        if iom is not None:
            io_eqns = iom.get_equations(self, self.use_tvf)
            for grp in io_eqns:
                equations.append(grp)

        group1 = []
        for fluid in fluids_with_io:
            group1.append(SummationDensity(dest=fluid, sources=all))
        for solid in self.solids:
            group1.extend([
                SourceNumberDensity(dest=solid, sources=fluids_with_io),
                VolumeSummation(dest=solid, sources=all),
                SolidWallPressureBC(dest=solid, sources=fluids_with_io,
                                    gx=self.gx, gy=self.gy, gz=self.gz),
                SetWallVelocity(dest=solid, sources=fluids_with_io),
            ])
            if self.clamp_p:
                group1.append(
                    ClampWallPressure(dest=solid, sources=None)
                )

        for solid in self.inviscid_solids:
            group1.extend([
                SourceNumberDensity(dest=solid, sources=fluids_with_io),
                NoSlipVelocityExtrapolation(
                    dest=solid, sources=fluids_with_io),
                VolumeSummation(dest=solid, sources=all),
                SolidWallPressureBC(dest=solid, sources=fluids_with_io,
                                    gx=self.gx, gy=self.gy, gz=self.gz)
                ])

        equations.append(Group(equations=group1, real=False))

        group2 = []
        for fluid in self.fluids:
            group2.append(
                MomentumEquation(
                    dest=fluid, sources=all, gx=self.gx, gy=self.gy,
                    gz=self.gz, c0=self.c0, tdamp=self.tdamp
                )
            )
            if self.alpha > 0.0:
                sources = fluids_with_io + self.solids
                group2.append(
                    MomentumEquationArtificialViscosity(
                        dest=fluid, sources=sources, alpha=self.alpha,
                        c0=self.c0
                    )
                )
            if self.nu > 0.0:
                group2.append(
                    MomentumEquationViscosity(
                        dest=fluid, sources=fluids_with_io, nu=self.nu
                    )
                )
            if len(self.solids) > 0 and self.nu > 0.0:
                group2.append(
                    SolidWallNoSlipBC(
                        dest=fluid, sources=self.solids, nu=self.nu
                    )
                )
            group2.extend([
                EDACEquation(
                    dest=fluid, sources=all, nu=edac_nu, cs=self.c0,
                    rho0=self.rho0
                ),
                XSPHCorrection(dest=fluid, sources=[fluid],
                               eps=self.eps)
            ])
        equations.append(Group(equations=group2))

        # inlet-outlet
        if iom is not None:
            io_eqns = iom.get_equations_post_compute_acceleration()
            for grp in io_eqns:
                equations.append(grp)

        return equations