~esys-p-dev/esys-particle/trunk

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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/////////////////////////////////////////////////////////////
//                                                         //
// Copyright (c) 2003-2014 by The University of Queensland //
// Centre for Geoscience Computing                         //
// http://earth.uq.edu.au/centre-geoscience-computing      //
//                                                         //
// Primary Business: Brisbane, Queensland, Australia       //
// Licensed under the Open Software License version 3.0    //
// http://www.opensource.org/licenses/osl-3.0.php          //
//                                                         //
/////////////////////////////////////////////////////////////


#include "ppa/src/pp_array.h"
#include <math.h>

namespace esys
{
  namespace lsm
  {
    template <class TmplParticle>
    BodyForceGroup<TmplParticle>::BodyForceGroup(
      const BodyForceIGP &prms,
      ParticleArray &particleArray
    )
      : m_acceleration(prms.getAcceleration()),
        m_pParticleArray(&particleArray)
    {
    }

    template <class TmplParticle>
    BodyForceGroup<TmplParticle>::~BodyForceGroup()
    {
    }

    template <class TmplParticle>
    void BodyForceGroup<TmplParticle>::Update(ParallelParticleArray<TmplParticle> *particleArray)
    {
    }

    template <class TmplParticle>
    Vec3 BodyForceGroup<TmplParticle>::getForce(double mass) const
    {
      return m_acceleration*mass;
    }

    template <class TmplParticle>
    void BodyForceGroup<TmplParticle>::applyForce(TmplParticle &particle) const
    {
      particle.applyForce(getForce(particle.getMass()), particle.getPos());
    }

    template <class TmplParticle>
    void BodyForceGroup<TmplParticle>::calcForces()
    {
      typename ParticleArray::ParticleListHandle plh = m_pParticleArray->getAllParticles();
      for (
        ParticleIterator it = plh->begin();
        it != plh->end();
        it++
      )
      {
        applyForce(*(*it));
      }
    }

    template <class TmplParticle>
    BuoyancyForceGroup<TmplParticle>::BuoyancyForceGroup(
      const BuoyancyIGP &prms,
      ParticleArray &particleArray
    )
      : m_acceleration(prms.getAcceleration()),
        m_pParticleArray(&particleArray) , 
        m_fluidDensity(prms.getFluidDensity()),
        m_fluidHeight(prms.getFluidHeight())
    {
    }

    template <class TmplParticle>
    BuoyancyForceGroup<TmplParticle>::~BuoyancyForceGroup()
    {
    }

    template <class TmplParticle>
    Vec3 BuoyancyForceGroup<TmplParticle>::getForce(double volume) const
    {
      Vec3 force;
      
      force = -1.0*m_acceleration*m_fluidDensity*volume;

      return force;
    }

    template <class TmplParticle>
    void BuoyancyForceGroup<TmplParticle>::applyForce(TmplParticle &particle) const
    {
      double volume, radius, height;
      double theta, d;

      radius = particle.getRad();
      height = -1.0*particle.getPos() * m_acceleration.unit();
      if(particle.getDo2dCalculations()){
         if (m_fluidHeight >= height + radius) {
	    // completely submerged
            volume = M_PI*radius*radius;
         }
         else if (m_fluidHeight >= height - radius) {
	    // partially submerged
            if (m_fluidHeight < height) {
               d = height - m_fluidHeight;
               theta = 2.0 * acos (d / radius);
               volume = 0.5*radius*radius*(theta - sin (theta));
            }
            else {
               d = m_fluidHeight - height;
               theta = 2.0 * acos (d / radius);
               volume = M_PI*radius*radius*(M_PI - 0.5*(theta - sin (theta)));
            }
         }
         else {
            // not submerged
            volume = 0.0;
         }
      }
      else {
         if (m_fluidHeight >= height + radius) {
            // completely submerged
            volume = 4.0*M_PI*radius*radius*radius/3.0;
         }
         else if (m_fluidHeight >= height - radius) {
            // partially submerged
            if (m_fluidHeight < height) {
               d = radius - (height - m_fluidHeight);
               volume = M_PI*d*d*(3.0*radius - d)/3.0;
            }
            else {
               d = radius - (m_fluidHeight - height);
               volume = M_PI*(4.0*radius*radius*radius - d*d*(3.0*radius - d))/3.0;
            }
         }
         else {
            // not submerged
            volume = 0.0;
         }
      }
      particle.applyForce(getForce(volume), particle.getPos());
    }

    template <class TmplParticle>
    void BuoyancyForceGroup<TmplParticle>::calcForces()
    {
      typename ParticleArray::ParticleListHandle plh = m_pParticleArray->getAllParticles();
      for (
        ParticleIterator it = plh->begin();
        it != plh->end();
        it++
      )
      {
        applyForce(*(*it));
      }
    }

    template <class TmplParticle>
    void BuoyancyForceGroup<TmplParticle>::Update(ParallelParticleArray<TmplParticle> *particleArray)
    {
    }
  }
}