[cig-commits] commit by bangerth to /var/svn/dealii/aspect

dealii.demon at gmail.com dealii.demon at gmail.com
Sat Aug 17 20:34:33 PDT 2013


Revision 1844

More reworking.

U   trunk/aspect/include/aspect/particle/integrator.h
U   trunk/aspect/include/aspect/particle/output.h
U   trunk/aspect/include/aspect/particle/particle.h
U   trunk/aspect/include/aspect/particle/world.h
U   trunk/aspect/source/particle/output.cc
A   trunk/aspect/source/particle/particle.cc


http://www.dealii.org/websvn/revision.php?repname=Aspect+Repository&path=%2F&rev=1844&peg=1844

Diff:
Modified: trunk/aspect/include/aspect/particle/integrator.h
===================================================================
--- trunk/aspect/include/aspect/particle/integrator.h	2013-08-18 03:20:02 UTC (rev 1843)
+++ trunk/aspect/include/aspect/particle/integrator.h	2013-08-18 03:33:45 UTC (rev 1844)
@@ -56,7 +56,7 @@
 
         // Read integration related data for a particle specified by id_num
         // Returns the data pointer updated to point to the next unwritten byte
-        virtual char *read_data(ParticleDataFormat format, double id_num, char *data) = 0;
+        virtual const char *read_data(ParticleDataFormat format, double id_num, const char *data) = 0;
 
         // Write integration related data for a particle specified by id_num
         // Returns the data pointer updated to point to the next unwritten byte
@@ -76,8 +76,8 @@
 
           for (it=particles.begin(); it!=particles.end(); ++it)
             {
-              loc = it->second.location();
-              vel = it->second.velocity();
+              loc = it->second.get_location();
+              vel = it->second.get_velocity();
               it->second.set_location(loc + dt*vel);
             }
 
@@ -88,7 +88,7 @@
         {
           return 0;
         };
-        virtual char *read_data(ParticleDataFormat format, double id_num, char *data)
+        virtual const char *read_data(ParticleDataFormat format, double id_num, const char *data)
         {
           return data;
         };
@@ -123,8 +123,8 @@
           for (it=particles.begin(); it!=particles.end(); ++it)
             {
               id_num = it->second.id_num();
-              loc = it->second.location();
-              vel = it->second.velocity();
+              loc = it->second.get_location();
+              vel = it->second.get_velocity();
               if (_step == 0)
                 {
                   _loc0[id_num] = loc;
@@ -164,9 +164,9 @@
           return 0;
         };
 
-        virtual char *read_data(ParticleDataFormat format, double id_num, char *data)
+        virtual const char *read_data(ParticleDataFormat format, double id_num, const char *data)
         {
-          char            *p = data;
+          const char     *p = data;
           unsigned int    i;
 
           switch (format)
@@ -235,8 +235,8 @@
           for (it=particles.begin(); it!=particles.end(); ++it)
             {
               id_num = it->second.id_num();
-              loc = it->second.location();
-              vel = it->second.velocity();
+              loc = it->second.get_location();
+              vel = it->second.get_velocity();
               if (_step == 0)
                 {
                   _loc0[id_num] = loc;
@@ -297,9 +297,9 @@
           return 0;
         };
 
-        virtual char *read_data(ParticleDataFormat format, double id_num, char *data)
+        virtual const char *read_data(ParticleDataFormat format, double id_num, const char *data)
         {
-          char            *p = data;
+          const char     *p = data;
           unsigned int    i;
 
           switch (format)
@@ -469,8 +469,8 @@
           for (it=particles.begin(); it!=particles.end(); ++it)
             {
               id_num = it->second.id_num();
-              loc = it->second.location();
-              vel = it->second.velocity();
+              loc = it->second.get_location();
+              vel = it->second.get_velocity();
               switch (_scheme[id_num])
                 {
                   case SCHEME_EULER:
@@ -556,9 +556,9 @@
           return 0;
         };
 
-        virtual char *read_data(ParticleDataFormat format, double id_num, char *data)
+        virtual const char *read_data(ParticleDataFormat format, double id_num, const char *data)
         {
-          char            *p = data;
+          const char     *p = data;
           unsigned int    i;
 
           switch (format)

Modified: trunk/aspect/include/aspect/particle/output.h
===================================================================
--- trunk/aspect/include/aspect/particle/output.h	2013-08-18 03:20:02 UTC (rev 1843)
+++ trunk/aspect/include/aspect/particle/output.h	2013-08-18 03:33:45 UTC (rev 1844)
@@ -71,6 +71,12 @@
             file_index (0)
           {}
 
+          /**
+           * Destructor. Made virtual so that derived classes can be created
+           * and destroyed through pointers to the base class.
+           */
+          virtual ~Interface () {}
+
           void set_mpi_comm(MPI_Comm new_comm_world)
           {
             communicator = new_comm_world;

Modified: trunk/aspect/include/aspect/particle/particle.h
===================================================================
--- trunk/aspect/include/aspect/particle/particle.h	2013-08-18 03:20:02 UTC (rev 1843)
+++ trunk/aspect/include/aspect/particle/particle.h	2013-08-18 03:33:45 UTC (rev 1844)
@@ -63,150 +63,82 @@
     {
       private:
         // Current particle location
-        Point<dim>      _loc;
+        Point<dim>      location;
 
         // Current particle velocity
-        Point<dim>      _vel;
+        Point<dim>      velocity;
 
         // Globally unique ID of particle
         double          _id;
 
         // Whether this particle is in the local subdomain or not
-        bool            _local;
+        bool            is_local;
 
         // Whether to check the velocity of this particle
         // This is used for integration schemes which require multiple
         // integration steps for some particles, but not for others
-        bool            _check_vel;
+        bool            check_vel;
 
       public:
-        BaseParticle(void) : _loc(), _vel(), _id(0), _local(true), _check_vel(true) {};
+        BaseParticle ();
 
-        BaseParticle(const Point<dim> &new_loc, const double &new_id) : _loc(new_loc), _id(new_id), _local(true), _check_vel(true) {};
+        BaseParticle (const Point<dim>& new_loc,
+                      const double& new_id);
 
-        virtual ~BaseParticle(void) {};
+        virtual
+        ~BaseParticle ();
 
-        static unsigned int data_len(ParticleDataFormat format)
-        {
-          switch (format)
-            {
-              case MPI_DATA:
-              case HDF5_DATA:
-                return (dim+dim+1)*sizeof(double);
-            }
-          return 0;
-        };
-        virtual char *read_data(ParticleDataFormat format, char *data)
-        {
-          char            *p = data;
-          unsigned int    i;
+        static unsigned int
+        data_len (ParticleDataFormat format);
 
-          switch (format)
-            {
-              case MPI_DATA:
-              case HDF5_DATA:
-                // Read location data
-                for (i=0; i<dim; ++i)
-                  {
-                    double val;
-                    memcpy (&val, p, sizeof(double));
-                    _loc(i) = val;
-                    p += sizeof(double);
-                  }
-                // Write velocity data
-                for (i=0; i<dim; ++i)
-                  {
-                    double val;
-                    memcpy (&val, p, sizeof(double));
-                    _vel(i) = val;
-                    p += sizeof(double);
-                  }
+        virtual const char*
+        read_data (ParticleDataFormat format,
+                   const char* data);
 
-                double val;
-                memcpy (&val, p, sizeof(double));
-                _id = val;
-                p += sizeof(double);
 
-                break;
-            }
+        virtual char*
+        write_data (ParticleDataFormat format,
+                    char* data) const;
 
-          return p;
-        };
+        void
+        set_location (const Point<dim> &new_loc);
 
-        virtual char *write_data(ParticleDataFormat format, char *data) const
+        Point<dim> get_location() const
         {
-          char          *p = data;
-          unsigned int  i;
+          return location;
+        }
 
-          // Then write our data in the appropriate format
-          switch (format)
-            {
-              case MPI_DATA:
-              case HDF5_DATA:
-                // Write location data
-                for (i=0; i<dim; ++i)
-                  {
-                    double val = _loc(i);
-                    memcpy (p, &val, sizeof(double));
-                    p += sizeof(double);
-                  }
-                // Write velocity data
-                for (i=0; i<dim; ++i)
-                  {
-                    double val = _vel(i);
-                    memcpy (p, &val, sizeof(double));
-                    p += sizeof(double);
-                  }
-
-                double val = _id;
-                memcpy (p, &val, sizeof(double));
-                p += sizeof(double);
-                break;
-            }
-
-          return p;
-        };
-
-        void set_location(Point<dim> new_loc)
-        {
-          _loc = new_loc;
-        };
-        Point<dim> location(void) const
-        {
-          return _loc;
-        };
-
         void set_velocity(Point<dim> new_vel)
         {
-          _vel = new_vel;
-        };
-        Point<dim> velocity(void) const
+          velocity = new_vel;
+        }
+        Point<dim> get_velocity() const
         {
-          return _vel;
-        };
+          return velocity;
+        }
 
-        double id_num(void) const
+        double id_num() const
         {
           return _id;
-        };
+        }
 
-        bool local(void) const
+        bool local() const
         {
-          return _local;
-        };
+          return is_local;
+        }
         void set_local(bool new_local)
         {
-          _local = new_local;
-        };
+          is_local = new_local;
+        }
 
-        bool vel_check(void) const
+        bool vel_check() const
         {
-          return _check_vel;
-        };
+          return check_vel;
+        }
         void set_vel_check(bool new_vel_check)
         {
-          _check_vel = new_vel_check;
-        };
+          check_vel = new_vel_check;
+        }
 
         static void add_mpi_types(std::vector<MPIDataInfo> &data_info)
         {
@@ -214,7 +146,7 @@
           data_info.push_back(MPIDataInfo("pos", dim, MPI_DOUBLE, sizeof(double)));
           data_info.push_back(MPIDataInfo("velocity", dim, MPI_DOUBLE, sizeof(double)));
           data_info.push_back(MPIDataInfo("id", 1, MPI_DOUBLE, sizeof(double)));
-        };
+        }
     };
 
     // A particle with associated values, such as scalars, vectors or tensors
@@ -248,9 +180,9 @@
           return 0;
         };
 
-        virtual char *read_data(ParticleDataFormat format, char *data)
+        virtual const char *read_data(ParticleDataFormat format, const char *data)
         {
-          char          *p = data;
+          const char          *p = data;
           unsigned int  i;
 
           // Read the parent data first
@@ -302,31 +234,28 @@
         };
 
         // Returns a vector from the first dim components of _val
-        Point<dim> get_vector(void) const
-        {
-          AssertThrow(data_dim>=dim, std::out_of_range("get_vector"));
-          Point<dim>  p;
-          for (unsigned int i=0; i<dim; ++i)
-            p(i) = _val[i];
-        };
+        Point<dim>
+        get_vector () const;
+        
         // Sets the first dim components of _val to the specified vector value
         void set_vector(Point<dim> new_vec)
         {
           AssertThrow(data_dim>=dim, std::out_of_range("set_vector"));
           for (unsigned int i=0; i<dim; ++i)
             _val[i] = new_vec(i);
-        };
+        }
 
         double &operator[](const unsigned int &ind)
         {
           AssertThrow(data_dim>ind, std::out_of_range("DataParticle[]"));
           return _val[ind];
-        };
+        }
+
         double operator[](const unsigned int &ind) const
         {
           AssertThrow(data_dim>ind, std::out_of_range("DataParticle[]"));
           return _val[ind];
-        };
+        }
 
         static void add_mpi_types(std::vector<MPIDataInfo> &data_info)
         {
@@ -337,6 +266,18 @@
           data_info.push_back(MPIDataInfo("data", data_dim, MPI_DOUBLE, sizeof(double)));
         };
     };
+
+    // A particle with associated values, such as scalars, vectors or tensors
+    template <int dim, int data_dim>
+    inline Point<dim>
+    DataParticle<dim,data_dim>::get_vector () const
+    {
+      AssertThrow(data_dim >= dim, std::out_of_range ("get_vector"));
+      Point < dim > p;
+      for (unsigned int i = 0; i < dim; ++i)
+        p (i) = _val[i];
+    }
+
   }
 }
 

Modified: trunk/aspect/include/aspect/particle/world.h
===================================================================
--- trunk/aspect/include/aspect/particle/world.h	2013-08-18 03:20:02 UTC (rev 1843)
+++ trunk/aspect/include/aspect/particle/world.h	2013-08-18 03:33:45 UTC (rev 1844)
@@ -180,7 +180,7 @@
 
           // If the particle is in the specified cell
           found_cell = typename parallel::distributed::Triangulation<dim>::cell_iterator(triangulation, cur_cell.first, cur_cell.second);
-          if (found_cell != triangulation->end() && found_cell->point_inside(particle.location()))
+          if (found_cell != triangulation->end() && found_cell->point_inside(particle.get_location()))
             {
               // If the cell is active, we're at the finest level of refinement and can finish
               if (found_cell->active())
@@ -452,7 +452,7 @@
           if (!triangulation_changed)
             {
               found_cell = typename parallel::distributed::Triangulation<dim>::cell_iterator(triangulation, cur_cell.first, cur_cell.second);
-              if (found_cell != triangulation->end() && found_cell->point_inside(particle.location()) && found_cell->active())
+              if (found_cell != triangulation->end() && found_cell->point_inside(particle.get_location()) && found_cell->active())
                 {
                   // If the cell is active, we're at the finest level of refinement and can finish
                   particle.set_local(found_cell->is_locally_owned());
@@ -472,7 +472,7 @@
           // coarse grid
           for (ait=triangulation->begin_active(); ait!=triangulation->end(); ++ait)
             {
-              if (ait->point_inside(particle.location()))
+              if (ait->point_inside(particle.get_location()))
                 {
                   particle.set_local(ait->is_locally_owned());
                   return std::make_pair(ait->level(), ait->index());
@@ -503,7 +503,9 @@
           unsigned int        rank;
           std::vector<T>      send_particles;
           typename std::vector<T>::const_iterator    sit;
-          char                *send_data, *recv_data, *cur_send_ptr, *cur_recv_ptr;
+          char                *send_data, *cur_send_ptr;
+          char *recv_data;
+          const char *cur_recv_ptr;
           unsigned int        integrator_data_len, particle_data_len;
 
           // Go through the particles and take out those which need to be moved to another processor
@@ -611,7 +613,7 @@
               i=0;
               while (it != particles.end() && it->first == cur_cell)
                 {
-                  if (it->second.vel_check()) particle_points[i++] = it->second.location();
+                  if (it->second.vel_check()) particle_points[i++] = it->second.get_location();
                   it++;
                 }
               result.resize(i, single_res);

Modified: trunk/aspect/source/particle/output.cc
===================================================================
--- trunk/aspect/source/particle/output.cc	2013-08-18 03:20:02 UTC (rev 1843)
+++ trunk/aspect/source/particle/output.cc	2013-08-18 03:33:45 UTC (rev 1844)
@@ -90,6 +90,7 @@
             :
             Interface<dim,T> (output_directory, communicator)
           {}
+
           /**
            * Write data about the particles specified in the first argument
            * to a file. If possible, encode the current simulation time
@@ -258,7 +259,7 @@
             for (typename std::multimap<LevelInd, T>::const_iterator
                  it=particles.begin(); it!=particles.end(); ++it)
               {
-                output << "          " << it->second.location();
+                output << "          " << it->second.get_location();
 
                 // pad with zeros since VTU format wants x/y/z coordinates
                 for (unsigned int d=dim; d<3; ++d)

Copied: trunk/aspect/source/particle/particle.cc (from rev 1842, trunk/aspect/source/particle/output.cc)
===================================================================
--- trunk/aspect/source/particle/particle.cc	                        (rev 0)
+++ trunk/aspect/source/particle/particle.cc	2013-08-18 03:33:45 UTC (rev 1844)
@@ -0,0 +1,163 @@
+/*
+ Copyright (C) 2011, 2012, 2013 by the authors of the ASPECT code.
+
+ This file is part of ASPECT.
+
+ ASPECT is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ ASPECT is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with ASPECT; see the file doc/COPYING.  If not see
+ <http://www.gnu.org/licenses/>.
+ */
+/*  $Id$  */
+
+#include <aspect/particle/particle.h>
+
+namespace aspect
+{
+  namespace Particle
+  {
+    // Base class of particles - represents a particle with position, velocity, and an ID number
+    template <int dim>
+    inline
+    BaseParticle<dim>::BaseParticle (const Point<dim>& new_loc,
+                                  const double& new_id)
+                                  :
+                                  location (new_loc),
+                                  _id (new_id),
+                                  is_local (true),
+                                  check_vel (true)
+                                  {
+                                  }
+
+    // Base class of particles - represents a particle with position, velocity, and an ID number
+    template <int dim>
+    inline
+    BaseParticle<dim>::BaseParticle ()
+    :
+    location (),
+    velocity (),
+    _id (0),
+    is_local (true),
+    check_vel (true)
+    {
+    }
+
+
+    // Base class of particles - represents a particle with position, velocity, and an ID number
+    template <int dim>
+    inline
+    BaseParticle<dim>::~BaseParticle ()
+    {
+    }
+
+
+    // Base class of particles - represents a particle with position, velocity, and an ID number
+    template <int dim>
+    void
+    BaseParticle<dim>::set_location (const Point<dim> &new_loc)
+    {
+      location = new_loc;
+    }
+
+
+    // Base class of particles - represents a particle with position, velocity, and an ID number
+    template <int dim>
+    char*
+    BaseParticle<dim>::write_data (ParticleDataFormat format,
+                                   char* data) const
+    {
+      char* p = data;
+      unsigned int i;
+      // Then write our data in the appropriate format
+      switch (format)
+      {
+      case MPI_DATA:
+      case HDF5_DATA:
+        // Write location data
+        for (i = 0; i < dim; ++i)
+          {
+            double val = location (i);
+            memcpy (p, &val, sizeof(double));
+            p += sizeof(double);
+          }
+        // Write velocity data
+        for (i = 0; i < dim; ++i)
+          {
+            double val = velocity (i);
+            memcpy (p, &val, sizeof(double));
+            p += sizeof(double);
+          }
+        double val = _id;
+        memcpy (p, &val, sizeof(double));
+        p += sizeof(double);
+        break;
+      }
+      return p;
+                                }
+
+    // Base class of particles - represents a particle with position, velocity, and an ID number
+    template <int dim>
+    const char*
+    BaseParticle<dim>::read_data (ParticleDataFormat format,
+                               const char* data)
+    {
+      const char* p = data;
+      unsigned int i;
+      switch (format)
+      {
+      case MPI_DATA:
+      case HDF5_DATA:
+        // Read location data
+        for (i = 0; i < dim; ++i)
+          {
+            double val;
+            memcpy (&val, p, sizeof(double));
+            location (i) = val;
+            p += sizeof(double);
+          }
+        // Write velocity data
+        for (i = 0; i < dim; ++i)
+          {
+            double val;
+            memcpy (&val, p, sizeof(double));
+            velocity (i) = val;
+            p += sizeof(double);
+          }
+        double val;
+        memcpy (&val, p, sizeof(double));
+        _id = val;
+        p += sizeof(double);
+        break;
+      }
+      return p;
+                               }
+
+    // Base class of particles - represents a particle with position, velocity, and an ID number
+    template <int dim>
+    unsigned int
+    BaseParticle<dim>::data_len (ParticleDataFormat format)
+    {
+      switch (format)
+      {
+      case MPI_DATA:
+      case HDF5_DATA:
+        return (dim + dim + 1) * sizeof(double);
+      }
+      return 0;
+    }
+
+
+    // explicit instantiation
+    template class BaseParticle<2>;
+    template class BaseParticle<3>;
+  }
+}


More information about the CIG-COMMITS mailing list