aboutsummaryrefslogtreecommitdiff
path: root/Source/Initialization/GetVelocity.H
blob: 7b1d5f21350633808b96e13acd6bc015d2356e77 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/* Copyright 2021 Hannah Klion
 *
 * This file is part of WarpX.
 *
 * License: BSD-3-Clause-LBNL
 */

#ifndef GET_VELOCITY_H_
#define GET_VELOCITY_H_

#include "VelocityProperties.H"

/** Get velocity at a point on the grid
 *
 * Class to get velocity at a point on the grid, either constant (m_velocity)
 * or a spatially varying value computed using the parser function (m_velocity_parser).
 * It also stores the direction of the velocity field. It provides the velocity information
 * held by the VelocityProperties instance passed to the constructor.
 */
struct GetVelocity
{
    /* Type of velocity initialization */
    VelocityInitType m_type;

    /* Velocity direction */
    int m_dir; //! Index x=0, y=1, z=2
    int m_sign_dir; //! Sign of the velocity direction positive=1, negative=-1

    /** Constant velocity value, if m_type == VelConstantValue */
    amrex::Real m_velocity;
    /** Velocity parser function, if m_type == VelParserFunction */
    amrex::ParserExecutor<3> m_velocity_parser;

    /**
     * \brief Construct the functor with information provided by vel
     *
     * \param[in] vel: const reference to the VelocityProperties object that will be used to
     * populate the functor
     */
    GetVelocity (VelocityProperties const& vel) noexcept;

    /**
     * \brief Functor call. Returns the value of velocity at the location (x,y,z)
     *
     * \param[in] x x-coordinate of given location
     * \param[in] y y-coordinate of given location
     * \param[in] z z-cooridnate of given location
     *
     *\return value of velocity at (x,y,z).
     *        m_velocity if m_type is VelConstantValue
     *        m_velocity_parser(x,y,z) if m_type is VelParserFunction
     */
    AMREX_GPU_HOST_DEVICE
    amrex::Real operator() (amrex::Real const x, amrex::Real const y, amrex::Real const z) const noexcept
    {
        switch (m_type)
        {
            case (VelConstantValue):
            {
                return m_sign_dir * m_velocity;
            }
            case (VelParserFunction):
            {
                return m_sign_dir * m_velocity_parser(x,y,z);
            }
            default:
            {
                amrex::Abort("Get initial velocity: unknown type");
                return 0.0;
            }
        }
    }

    /**
     * \brief Returns the index of the direction of the bulk velocity
     *
     *\return index of direction of velocity.
     *        0: x
     *        1: y
     *        2: z
     */
    AMREX_GPU_HOST_DEVICE
    int direction () const noexcept
    {
        return m_dir;
    }
};
#endif