]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Initial CompositionManifold.
authorLuca Heltai <luca.heltai@sissa.it>
Thu, 24 Mar 2016 18:10:52 +0000 (19:10 +0100)
committerLuca Heltai <luca.heltai@sissa.it>
Mon, 11 Apr 2016 07:41:41 +0000 (09:41 +0200)
include/deal.II/grid/manifold_tools.h [new file with mode: 0644]
source/grid/CMakeLists.txt
source/grid/manifold_tools.cc [new file with mode: 0644]
source/grid/manifold_tools.inst.in [new file with mode: 0644]
tests/manifold/composition_manifold_01.cc [new file with mode: 0644]
tests/manifold/composition_manifold_01.with_muparser=true.output [new file with mode: 0644]
tests/manifold/composition_manifold_02.cc [new file with mode: 0644]
tests/manifold/composition_manifold_02.with_muparser=true.output [new file with mode: 0644]

diff --git a/include/deal.II/grid/manifold_tools.h b/include/deal.II/grid/manifold_tools.h
new file mode 100644 (file)
index 0000000..21341d3
--- /dev/null
@@ -0,0 +1,115 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2016 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+#ifndef dealii__manifold_tools_h
+#define dealii__manifold_tools_h
+
+
+/*----------------------------   manifold_tools.h     -----------------*/
+
+#include <deal.II/base/config.h>
+#include <deal.II/base/subscriptor.h>
+#include <deal.II/base/quadrature_lib.h>
+#include <deal.II/base/thread_management.h>
+#include <deal.II/base/point.h>
+#include <deal.II/base/derivative_form.h>
+#include <deal.II/grid/tria.h>
+#include <deal.II/grid/manifold.h>
+
+DEAL_II_NAMESPACE_OPEN
+
+/**
+ * CompositionManifold.  Take two ChartManifold objects, and make
+ * their composition. The CompositionManifold object is a
+ * ChartManifold going from the chart of the first ChartManifold to
+ * the embedding space of the second ChartManifold.
+ *
+ * This class only works for dim <= chartdim <= intermediate_spacedim
+ * <= spacedim. If you try to instantiate anything different, an
+ * Exception will be thrown in one of the ChartManifold classes that
+ * violates this condition.
+ *
+ * Given the ChartManifold F and the ChartManifold G, this class
+ * represents the composition of G after F.
+ *
+ * The template parameters have the following meaning:
+ *
+ * @tparam dim The dimension of the resulting ChartManifold
+ * @tparam spacedim The space dimension of the resulting ChartManifold
+ * @tparam chartdim The chart dimension of the resulting ChartManifold
+ * @tparam intermediate_dim The space dimension of the first ChartManifold
+ * @tparam dim1 The dimension of the first ChartManifold, which coincides also
+ * with the chart dimension of the second ChartManifold
+ * @tparam dim2 The dimension of the second ChartManifold
+ *
+ * @ingroup manifold
+ * @author Luca Heltai, Timo Heister, 2016
+ */
+template <int dim, int spacedim=dim, int chartdim=dim,
+          int intermediate_dim=dim, int dim1=dim, int dim2=dim>
+class CompositionManifold : public ChartManifold<dim, spacedim, chartdim>
+{
+public:
+
+  /**
+   * Construct the composition of the two given manifolds.
+   */
+  CompositionManifold(const ChartManifold<dim1, intermediate_dim, chartdim> &F,
+                      const ChartManifold<dim2, spacedim, intermediate_dim> &G);
+
+  /**
+   * Pull back the given point in spacedim to the Euclidean chartdim
+   * dimensional space. This function calls the pull_back() function
+   * of G, and then the pull_back() function of F.
+   */
+  virtual
+  Point<chartdim>
+  pull_back(const Point<spacedim> &space_point) const;
+
+
+  /**
+   * Push forward the chartdim dimensional point to a spacedim
+   * Euclidean point. The function calls first the push_forward() of
+   * F, and then the push_foward() of G.
+   */
+  virtual
+  Point<spacedim>
+  push_forward(const Point<chartdim> &chart_point) const;
+
+  /**
+   * Return the derivative of the composition of G after F.
+   */
+  virtual
+  DerivativeForm<1,chartdim,spacedim>
+  push_forward_gradient(const Point<chartdim> &chart_point) const;
+
+private:
+  /**
+   * The first ChartManifold.
+   */
+  SmartPointer<const ChartManifold<dim1, intermediate_dim, chartdim>,
+               CompositionManifold<dim,spacedim,chartdim,dim1,dim2,intermediate_dim> > F;
+
+
+  /**
+   * The second ChartManifold.
+   */
+  SmartPointer<const ChartManifold<dim2, spacedim, intermediate_dim>,
+               CompositionManifold<dim,spacedim,chartdim,dim1,dim2,intermediate_dim> > G;
+};
+
+DEAL_II_NAMESPACE_CLOSE
+
+#endif
index 8279350bf27ab47b9fd7994a23b8f81f983d743e..18abd372114d0f7b99f2e88fa45cc820442c5a77 100644 (file)
@@ -26,6 +26,7 @@ SET(_src
   intergrid_map.cc
   manifold.cc
   manifold_lib.cc
+  manifold_tools.cc
   persistent_tria.cc
   tria_accessor.cc
   tria_boundary.cc
@@ -45,6 +46,7 @@ SET(_inst
   intergrid_map.inst.in
   manifold.inst.in
   manifold_lib.inst.in
+  manifold_tools.inst.in
   tria_accessor.inst.in
   tria_boundary.inst.in
   tria_boundary_lib.inst.in
diff --git a/source/grid/manifold_tools.cc b/source/grid/manifold_tools.cc
new file mode 100644 (file)
index 0000000..5cb2219
--- /dev/null
@@ -0,0 +1,83 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 1998 - 2016 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+#include <deal.II/base/tensor.h>
+#include <deal.II/grid/tria.h>
+#include <deal.II/grid/tria_iterator.h>
+#include <deal.II/grid/tria_accessor.h>
+#include <deal.II/grid/manifold_tools.h>
+#include <deal.II/fe/fe_q.h>
+#include <cmath>
+
+DEAL_II_NAMESPACE_OPEN
+
+
+/* -------------------------- CompositionManifold --------------------- */
+
+
+
+template <int dim, int spacedim, int chartdim, int intermediate_dim,
+          int dim1, int dim2>
+CompositionManifold<dim,spacedim,chartdim,intermediate_dim,dim1,dim2>::CompositionManifold
+(const ChartManifold<dim1, intermediate_dim, chartdim> &F,
+ const ChartManifold<dim2, spacedim, intermediate_dim> &G) :
+  F(&F),
+  G(&G)
+{}
+
+template <int dim, int spacedim, int chartdim, int intermediate_dim,
+          int dim1, int dim2>
+Point<chartdim>
+CompositionManifold<dim,spacedim,chartdim,intermediate_dim,dim1,dim2>::pull_back(const Point<spacedim> &space_point) const
+{
+  return F->pull_back(G->pull_back(space_point));
+}
+
+template <int dim, int spacedim, int chartdim, int intermediate_dim,
+          int dim1, int dim2>
+Point<spacedim>
+CompositionManifold<dim,spacedim,chartdim,intermediate_dim,dim1,dim2>::push_forward(const Point<chartdim> &chart_point) const
+{
+  return G->push_forward(F->push_forward(chart_point));
+}
+
+
+template <int dim, int spacedim, int chartdim, int intermediate_dim,
+          int dim1, int dim2>
+DerivativeForm<1,chartdim,spacedim>
+CompositionManifold<dim,spacedim,chartdim,intermediate_dim,dim1,dim2>::push_forward_gradient(const Point<chartdim> &chart_point) const
+{
+  DerivativeForm<1,chartdim,intermediate_dim> DF =
+    F->push_forward_gradient(chart_point);
+
+  DerivativeForm<1,intermediate_dim,spacedim> DG =
+    G->push_forward_gradient(F->push_forward(chart_point));
+
+  DerivativeForm<1,chartdim,spacedim> DF_DG;
+
+  for (unsigned int d=0; d<spacedim; ++d)
+    for (unsigned int c=0; c<chartdim; ++c)
+      for (unsigned int s=0; s<intermediate_dim; ++s)
+        DF_DG[d][c] += DG[d][s]*DF[s][c];
+
+  return DF_DG;
+}
+
+
+// explicit instantiations
+#include "manifold_tools.inst"
+
+DEAL_II_NAMESPACE_CLOSE
+
diff --git a/source/grid/manifold_tools.inst.in b/source/grid/manifold_tools.inst.in
new file mode 100644 (file)
index 0000000..54684d5
--- /dev/null
@@ -0,0 +1,24 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 1999 - 2014 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+
+for (d : DIMENSIONS; d1 : DIMENSIONS; d2: DIMENSIONS; 
+     c : SPACE_DIMENSIONS ; s : SPACE_DIMENSIONS; s1 : SPACE_DIMENSIONS)
+  {
+#if d <= s && c <= s1 && s1 <= s && d1 <= s1 && d2 <= s
+    template class CompositionManifold<d,s,c,s1,d1,d2>;
+#endif
+  }
+
diff --git a/tests/manifold/composition_manifold_01.cc b/tests/manifold/composition_manifold_01.cc
new file mode 100644 (file)
index 0000000..19af463
--- /dev/null
@@ -0,0 +1,75 @@
+//----------------------------  function_manifold_chart ---------------------------
+//    Copyright (C) 2011 - 2015 by the mathLab team.
+//
+//    This file is subject to LGPL and may not be  distributed
+//    without copyright and license information. Please refer
+//    to the file deal.II/doc/license.html for the  text  and
+//    further information on this license.
+//
+//---------------------------- composition_manifold ---------------------------
+
+
+// Test the combination of simple ChartManifolds: parabolic + translation
+
+#include "../tests.h"
+#include <fstream>
+#include <deal.II/base/logstream.h>
+
+
+// all include files you need here
+#include <deal.II/grid/manifold_lib.h>
+#include <deal.II/grid/manifold_tools.h>
+
+
+int main ()
+{
+  initlog();
+
+  const int dim=2, spacedim=2;
+
+  FunctionManifold<dim,spacedim,1>    F("x;x^2", "x");
+  FunctionManifold<dim,spacedim,spacedim> G("x;y+1", "x;y-1");
+
+  CompositionManifold<dim,spacedim,1,dim,dim,spacedim> manifold(F,G);
+
+  // Chart points.
+  Point<1> cp[2];
+  cp[1][0] = 1.0;
+
+  // Spacedim points
+  std::vector<Point<spacedim> > sp(2);
+
+  // Weights
+  std::vector<double> w(2);
+
+  sp[0] = manifold.push_forward(cp[0]);
+  sp[1] = manifold.push_forward(cp[1]);
+
+  for (unsigned int d=0; d<2; ++d)
+    if (cp[d].distance(manifold.pull_back(sp[d])) > 1e-10)
+      deallog << "Error!" << std::endl;
+
+  unsigned int n_intermediates = 16;
+
+  deallog << "P0: " << sp[0]
+          << ", P1: " << sp[1] << std::endl;
+
+  for (unsigned int i=0; i<n_intermediates+1; ++i)
+    {
+      w[0] = 1.0-(double)i/((double)n_intermediates);
+      w[1] = 1.0 - w[0];
+
+      Point<spacedim> ip = manifold.get_new_point(Quadrature<spacedim>(sp, w));
+      Tensor<1,spacedim> t1 = manifold.get_tangent_vector(ip, sp[0]);
+      Tensor<1,spacedim> t2 = manifold.get_tangent_vector(ip, sp[1]);
+
+      deallog << "P: " << ip
+              << ", T(P, P0): " << t1
+              << ", T(P, P1): " << t2 << std::endl;
+
+    }
+
+
+  return 0;
+}
+
diff --git a/tests/manifold/composition_manifold_01.with_muparser=true.output b/tests/manifold/composition_manifold_01.with_muparser=true.output
new file mode 100644 (file)
index 0000000..3b65170
--- /dev/null
@@ -0,0 +1,19 @@
+
+DEAL::P0: 0.00000 1.00000, P1: 1.00000 2.00000
+DEAL::P: 0.00000 1.00000, T(P, P0): 0.00000 0.00000, T(P, P1): 1.00000 0.00000
+DEAL::P: 0.0625000 1.00391, T(P, P0): -0.0625000 -0.00781250, T(P, P1): 0.937500 0.117187
+DEAL::P: 0.125000 1.01562, T(P, P0): -0.125000 -0.0312500, T(P, P1): 0.875000 0.218750
+DEAL::P: 0.187500 1.03516, T(P, P0): -0.187500 -0.0703125, T(P, P1): 0.812500 0.304687
+DEAL::P: 0.250000 1.06250, T(P, P0): -0.250000 -0.125000, T(P, P1): 0.750000 0.375000
+DEAL::P: 0.312500 1.09766, T(P, P0): -0.312500 -0.195312, T(P, P1): 0.687500 0.429687
+DEAL::P: 0.375000 1.14062, T(P, P0): -0.375000 -0.281250, T(P, P1): 0.625000 0.468750
+DEAL::P: 0.437500 1.19141, T(P, P0): -0.437500 -0.382812, T(P, P1): 0.562500 0.492187
+DEAL::P: 0.500000 1.25000, T(P, P0): -0.500000 -0.500000, T(P, P1): 0.500000 0.500000
+DEAL::P: 0.562500 1.31641, T(P, P0): -0.562500 -0.632812, T(P, P1): 0.437500 0.492187
+DEAL::P: 0.625000 1.39062, T(P, P0): -0.625000 -0.781250, T(P, P1): 0.375000 0.468750
+DEAL::P: 0.687500 1.47266, T(P, P0): -0.687500 -0.945312, T(P, P1): 0.312500 0.429687
+DEAL::P: 0.750000 1.56250, T(P, P0): -0.750000 -1.12500, T(P, P1): 0.250000 0.375000
+DEAL::P: 0.812500 1.66016, T(P, P0): -0.812500 -1.32031, T(P, P1): 0.187500 0.304688
+DEAL::P: 0.875000 1.76562, T(P, P0): -0.875000 -1.53125, T(P, P1): 0.125000 0.218750
+DEAL::P: 0.937500 1.87891, T(P, P0): -0.937500 -1.75781, T(P, P1): 0.0625000 0.117187
+DEAL::P: 1.00000 2.00000, T(P, P0): -1.00000 -2.00000, T(P, P1): 0.00000 0.00000
diff --git a/tests/manifold/composition_manifold_02.cc b/tests/manifold/composition_manifold_02.cc
new file mode 100644 (file)
index 0000000..095f0a7
--- /dev/null
@@ -0,0 +1,81 @@
+//----------------------------  function_manifold_chart ---------------------------
+//    Copyright (C) 2011 - 2015 by the mathLab team.
+//
+//    This file is subject to LGPL and may not be  distributed
+//    without copyright and license information. Please refer
+//    to the file deal.II/doc/license.html for the  text  and
+//    further information on this license.
+//
+//---------------------------- composition_manifold ---------------------------
+
+
+// Test the combination of simple ChartManifolds: SphericalManifold +
+// Translation
+
+#include "../tests.h"
+#include <fstream>
+#include <deal.II/base/logstream.h>
+
+
+// all include files you need here
+#include <deal.II/grid/manifold_lib.h>
+#include <deal.II/grid/manifold_tools.h>
+
+
+int main ()
+{
+  initlog();
+  std::ostream &out = deallog.get_file_stream();
+
+  const int dim=2, spacedim=2;
+
+  SphericalManifold<1,2>    F;
+  FunctionManifold<2,2,2> G("x;y+1", "x;y-1");
+
+  CompositionManifold<2,2,2,2,1> manifold(F,G);
+
+  // Chart points.
+  Point<2> cp[2];
+  cp[0][0] = 1.0;
+  cp[1][0] = 1.0;
+  cp[1][1] = numbers::PI/2;
+
+  // Spacedim points
+  std::vector<Point<spacedim> > sp(2);
+
+  // Weights
+  std::vector<double> w(2);
+
+  sp[0] = manifold.push_forward(cp[0]);
+  sp[1] = manifold.push_forward(cp[1]);
+
+  for (unsigned int d=0; d<2; ++d)
+    if (cp[d].distance(manifold.pull_back(sp[d])) > 1e-10)
+      deallog << "Error!" << std::endl;
+
+  unsigned int n_intermediates = 16;
+
+  out << "set size ratio -1" << std::endl
+      << "plot '-' with vectors " << std::endl;
+
+  for (unsigned int i=0; i<n_intermediates+1; ++i)
+    {
+      w[0] = 1.0-(double)i/((double)n_intermediates);
+      w[1] = 1.0 - w[0];
+
+      Point<spacedim> ip = manifold.get_new_point(Quadrature<spacedim>(sp, w));
+      Tensor<1,spacedim> t1 = manifold.get_tangent_vector(ip, sp[0]);
+      Tensor<1,spacedim> t2 = manifold.get_tangent_vector(ip, sp[1]);
+
+      out << ip << " "
+          << t2 << std::endl
+          // << ip << " "
+          // << t2 << std::endl
+          ;
+    }
+
+  out << "e" << std::endl;
+
+  return 0;
+}
+
diff --git a/tests/manifold/composition_manifold_02.with_muparser=true.output b/tests/manifold/composition_manifold_02.with_muparser=true.output
new file mode 100644 (file)
index 0000000..c54d0d7
--- /dev/null
@@ -0,0 +1,21 @@
+
+set size ratio -1
+plot '-' with vectors 
+1.00000 1.00000 0.00000 1.57080
+0.995185 1.09802 -0.144342 1.46553
+0.980785 1.19509 -0.268141 1.34804
+0.956940 1.29028 -0.370482 1.22132
+0.923880 1.38268 -0.450838 1.08842
+0.881921 1.47140 -0.509072 0.952407
+0.831470 1.55557 -0.545430 0.816293
+0.773010 1.63439 -0.560533 0.683011
+0.707107 1.70711 -0.555360 0.555360
+0.634393 1.77301 -0.531231 0.435970
+0.555570 1.83147 -0.489776 0.327258
+0.471397 1.88192 -0.432912 0.231396
+0.382683 1.92388 -0.362807 0.150279
+0.290285 1.95694 -0.281842 0.0854959
+0.195090 1.98079 -0.192577 0.0383059
+0.0980171 1.99518 -0.0977020 0.00962281
+6.12323e-17 2.00000 0.00000 0.00000
+e

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.