LCOV - code coverage report
Current view: top level - src/cpu/analytical-fields - velocity.cc (source / functions) Hit Total Coverage
Test: coverage.info Lines: 29 29 100.0 %
Date: 2019-07-29 15:26:30 Functions: 5 11 45.5 %

          Line data    Source code
       1             : ///////////////////////////////////////////////////////////////////////////////
       2             : // Copyright 2019 Lakshman Anumolu, Raunak Bardia.
       3             : //
       4             : // Redistribution and use in source and binary forms, with or without
       5             : // modification, are permitted provided that the following conditions are
       6             : // met:
       7             : //
       8             : // 1. Redistributions of source code must retain the above copyright notice,
       9             : // this list of conditions and the following disclaimer.
      10             : //
      11             : // 2. Redistributions in binary form must reproduce the above copyright notice,
      12             : // this list of conditions and the following disclaimer in the documentation
      13             : // and/or other materials provided with the distribution.
      14             : //
      15             : // 3. Neither the name of the copyright holder nor the names of its contributors
      16             : // may be used to endorse or promote products derived from this software without
      17             : // specific prior written permission.
      18             : //
      19             : // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
      20             : // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
      21             : // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
      22             : // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
      23             : // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
      24             : // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
      25             : // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
      26             : // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
      27             : // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
      28             : // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
      29             : // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
      30             : ///////////////////////////////////////////////////////////////////////////////
      31             : 
      32             : #include "gals/analytical-fields/velocity.h"
      33             : 
      34             : #include <string>
      35             : 
      36             : #include "gals/utilities/utilities.h"
      37             : 
      38             : template <typename T_GRID, typename T>
      39           1 : GALS::ANALYTICAL_FIELDS::Velocity<T_GRID, T>::Velocity(const T_GRID& grid, const GALS::INPUT_FIELDS::Velocity& inputs)
      40           1 :     : m_grid(grid), m_inputs(inputs)
      41             : {
      42           1 : }
      43             : 
      44             : template <typename T_GRID, typename T>
      45           1 : GALS::ANALYTICAL_FIELDS::Velocity<T_GRID, T>::~Velocity()
      46             : {
      47           1 : }
      48             : 
      49             : template <typename T_GRID, typename T>
      50           1 : void GALS::ANALYTICAL_FIELDS::Velocity<T_GRID, T>::compute(
      51             :     const GALS::CPU::Array<T_GRID, GALS::CPU::Vec3<T>>& positions, const T time,
      52             :     GALS::CPU::LevelsetVelocity<T_GRID, T>& levelset_velocity)
      53             : {
      54           2 :   const GALS::CPU::Vec3<int> num_cells = positions.numCells();
      55           1 :   const auto& velocity_name = m_inputs.name;
      56             : 
      57           1 :   switch (velocity_name_map[velocity_name]) {
      58             :     case VelocityFieldNames::CIRCULAR: {
      59             :       auto& velocity = levelset_velocity.velocity();
      60             : 
      61             :       if (T_GRID::dim == 1)
      62             :         GALS_FUNCTION_NOT_IMPLEMENTED(
      63             :             "GALS::ANALYTICAL_FIELDS::Velocity::compute: CIRCULAR velocity field for 1D grid.");
      64             : 
      65             :       T coeff = pi() / static_cast<T>(3.15);
      66           2 :       GALS::CPU::Vec3<T> velocity_node;
      67             : 
      68          21 :       for (int i = 0; i < num_cells[0]; ++i)
      69         210 :         for (int j = 0; j < num_cells[1]; ++j)
      70         300 :           for (int k = 0; k < num_cells[2]; ++k) {
      71         500 :             for (int cmpt = 0; cmpt < T_GRID::dim; ++cmpt) {
      72         300 :               if (cmpt == 0) velocity_node[cmpt] = coeff * (m_inputs.center[cmpt] - positions(i, j, k)[cmpt + 1]);
      73         300 :               if (cmpt == 1) velocity_node[cmpt] = coeff * (positions(i, j, k)[cmpt - 1] - m_inputs.center[cmpt]);
      74             :             }
      75             : 
      76         100 :             velocity(i, j, k) = velocity_node;
      77             :           }
      78             : 
      79             :       // Compute velocity gradient using analytical expressions.
      80           2 :       if (!strcmp(m_inputs.gradient_scheme.c_str(), "ANALYTICAL")) {
      81             :         auto& velocity_gradient = levelset_velocity.velocityGradient();
      82             : 
      83          21 :         for (int i = 0; i < num_cells[0]; ++i)
      84         210 :           for (int j = 0; j < num_cells[1]; ++j)
      85         300 :             for (int k = 0; k < num_cells[2]; ++k) {
      86         500 :               for (int cmpt = 0; cmpt < T_GRID::dim; ++cmpt) {
      87        1000 :                 for (int derv = 0; derv < T_GRID::dim; ++derv) {
      88         400 :                   if (cmpt == 0 && derv == 0) velocity_gradient[cmpt][derv] = static_cast<T>(0);
      89         400 :                   if (cmpt == 0 && derv == 1) velocity_gradient[cmpt][derv] = -coeff;
      90         400 :                   if (cmpt == 1 && derv == 0) velocity_gradient[cmpt][derv] = coeff;
      91         400 :                   if (cmpt == 1 && derv == 1) velocity_gradient[cmpt][derv] = static_cast<T>(0);
      92             :                 }
      93             :               }
      94             :             }
      95             :       }
      96             : 
      97             :       break;
      98             :     }
      99             : 
     100             :     default:
     101             :       break;
     102             :   }
     103           1 : }
     104             : 
     105             : template class GALS::ANALYTICAL_FIELDS::Velocity<GALS::CPU::Grid<double, 1>, double>;
     106             : template class GALS::ANALYTICAL_FIELDS::Velocity<GALS::CPU::Grid<double, 2>, double>;
     107           3 : template class GALS::ANALYTICAL_FIELDS::Velocity<GALS::CPU::Grid<double, 3>, double>;

Generated by: LCOV version 1.12