← Back to team overview

dolfin team mailing list archive

[noreply@xxxxxxxxxxxxx: [Branch ~dolfin-core/dolfin/rognes] Rev 5741: Add adaption of cell functions after mesh refinement.]

 

Nice! Is it working?

--
Anders
--- Begin Message ---
------------------------------------------------------------
revno: 5741
committer: Marie E. Rognes <meg@xxxxxxxxx>
branch nick: dolfin
timestamp: Sat 2011-03-12 09:14:46 +0100
message:
  Add adaption of cell functions after mesh refinement.
modified:
  demo/undocumented/meshfunction-refinement/cpp/main.cpp
  dolfin/adaptivity/adapt.cpp
  dolfin/adaptivity/adapt.h
  dolfin/mesh/BisectionRefinement.cpp
  dolfin/mesh/RivaraRefinement.cpp


--
lp:~dolfin-core/dolfin/rognes
https://code.launchpad.net/~dolfin-core/dolfin/rognes

Your team DOLFIN Core Team is subscribed to branch lp:~dolfin-core/dolfin/rognes.
To unsubscribe from this branch go to https://code.launchpad.net/~dolfin-core/dolfin/rognes/+edit-subscription
=== modified file 'demo/undocumented/meshfunction-refinement/cpp/main.cpp'
--- demo/undocumented/meshfunction-refinement/cpp/main.cpp	2011-03-10 22:28:48 +0000
+++ demo/undocumented/meshfunction-refinement/cpp/main.cpp	2011-03-12 08:14:46 +0000
@@ -1,7 +1,7 @@
 // Copyright (C) 2011 Marie E. Rognes
 // Licensed under the GNU LGPL Version 3 or any later version
 //
-// Last changed: 2011-03-10
+// Last changed: 2011-03-12
 
 #include <dolfin.h>
 
@@ -27,24 +27,18 @@
     }
   };
 
-  UnitSquare mesh(1, 1);
+  UnitSquare mesh(5, 5);
+
+  // Create MeshFunction over cells
+  MeshFunction<unsigned int> right_cells(mesh, mesh.topology().dim(), 0);
+  Right right;
+  right.mark(right_cells, 1);
+  plot(right_cells);
 
   // Create MeshFunction over facets
   MeshFunction<unsigned int> inflow_facets(mesh, mesh.topology().dim() - 1, 0);
   Inflow inflow;
   inflow.mark(inflow_facets, 1);
-  //plot(inflow_facets);
-
-  // Create MeshFunction over cells
-  MeshFunction<unsigned int> right_cells(mesh, mesh.topology().dim(), 0);
-  Right right;
-  right.mark(right_cells, 1);
-
-  // Copy data over to mesh data (Better way?)
-  MeshFunction<unsigned int>* materials = \
-    mesh.data().create_mesh_function("material indicators", mesh.topology().dim());
-  for (CellIterator c(mesh); !c.end(); ++c)
-    (*materials)[*c] = right_cells[*c];
 
   // Mark cells for refinement
   MeshFunction<bool> cell_markers(mesh, mesh.topology().dim(), false);
@@ -55,14 +49,13 @@
       cell_markers[*c] = true;
   }
 
-  // Refine mesh -> new_mesh
-  Mesh new_mesh = refine(mesh, cell_markers);
-  plot(new_mesh);
-
-  // Extract and plot refined material indicators
-  MeshFunction<dolfin::uint>* new_materials =                   \
-    new_mesh.data().mesh_function("material indicators");
-  plot(*new_materials);
+  // Refine mesh
+  adapt(mesh, cell_markers);
+
+  // Adapt cell function to refined mesh
+  adapt(right_cells, mesh.child_shared_ptr());
+
+  //plot(right_cells.child());
 
   return 0;
 }

=== modified file 'dolfin/adaptivity/adapt.cpp'
--- dolfin/adaptivity/adapt.cpp	2011-02-25 08:19:47 +0000
+++ dolfin/adaptivity/adapt.cpp	2011-03-12 08:14:46 +0000
@@ -5,7 +5,7 @@
 // Modified by Marie E. Rognes, 2011.
 //
 // First added:  2010-02-10
-// Last changed: 2011-02-25
+// Last changed: 2011-03-12
 
 #include <boost/shared_ptr.hpp>
 
@@ -23,6 +23,7 @@
 #include <dolfin/fem/Form.h>
 #include <dolfin/fem/DirichletBC.h>
 #include <dolfin/fem/VariationalProblem.h>
+#include <dolfin/plot/plot.h>
 #include "ErrorControl.h"
 #include "SpecialFacetFunction.h"
 #include "adapt.h"
@@ -42,6 +43,43 @@
 }
 
 //-----------------------------------------------------------------------------
+const dolfin::MeshFunction<dolfin::uint>& dolfin::adapt(const MeshFunction<uint>& mesh_function,
+                                                boost::shared_ptr<const Mesh> refined_mesh)
+{
+  // FIXME: MeshFunction Hierarchical ok?
+  // FIXME: Skip refinement if already refined
+  // FIXME: Update according to shared_ptr changes in MeshFunction
+
+  const Mesh& mesh = mesh_function.mesh();
+  const uint dim = mesh.topology().dim();
+  MeshFunction<uint> refined_mf(*refined_mesh, mesh_function.dim());
+
+  // Extract parent encoding from refined mesh
+  MeshFunction<uint>* parent = 0;
+  if (mesh_function.dim() == dim)
+  {
+    parent = refined_mesh->data().mesh_function("parent_cell");
+  } else if (mesh_function.dim() == (dim - 1))
+  {
+    parent = refined_mesh->data().mesh_function("parent_facet");
+  } else
+    dolfin_not_implemented();
+
+  // Check that parent info exists
+  if (!parent)
+    error("Unable to extract information about parent mesh entites");
+
+  // Map values of mesh function into refined mesh function
+  for (uint i = 0; i < refined_mf.size(); i++)
+    refined_mf[i] = mesh_function[(*parent)[i]];
+
+  plot(refined_mf);
+
+  // Return new mesh function
+  return mesh_function; // FIXME
+
+}
+//-----------------------------------------------------------------------------
 const dolfin::Mesh& dolfin::adapt(const Mesh& mesh)
 {
   // Skip refinement if already refined

=== modified file 'dolfin/adaptivity/adapt.h'
--- dolfin/adaptivity/adapt.h	2011-02-16 20:36:50 +0000
+++ dolfin/adaptivity/adapt.h	2011-03-12 08:14:46 +0000
@@ -5,7 +5,7 @@
 // Modified by Marie E. Rognes, 2011.
 //
 // First added:  2010-02-10
-// Last changed: 2011-02-16
+// Last changed: 2011-03-12
 //
 // This file defines free functions for refinement/adaption of meshes,
 // function spaces, functions etc.
@@ -53,6 +53,10 @@
   const Function& adapt(const Function& function,
                         boost::shared_ptr<const Mesh> refined_mesh);
 
+  /// Refine mesh function<uint> based on mesh
+  const MeshFunction<dolfin::uint>& adapt(const MeshFunction<uint>& mesh_function,
+                                  boost::shared_ptr<const Mesh> refined_mesh);
+
   //--- Refinement of boundary conditions ---
 
   /// Refine Dirichlet bc based on refined mesh

=== modified file 'dolfin/mesh/BisectionRefinement.cpp'
--- dolfin/mesh/BisectionRefinement.cpp	2011-02-23 09:31:13 +0000
+++ dolfin/mesh/BisectionRefinement.cpp	2011-03-12 08:14:46 +0000
@@ -5,9 +5,9 @@
 // Modified by Garth N. Wells, 2010-2011.
 //
 // First added:  2006-11-01
-// Last changed: 2011-02-22
+// Last changed: 2011-03-12
 
-#include <dolfin/math/dolfin_math.h>
+#include <dolfin/common/types.h>
 #include <dolfin/log/dolfin_log.h>
 #include "BoundaryMesh.h"
 #include "Cell.h"
@@ -29,14 +29,29 @@
                         const Mesh& mesh, const MeshFunction<bool>& cell_marker)
 {
   // Transformation maps
-  MeshFunction<dolfin::uint> cell_map;
+  MeshFunction<uint> cell_map;
   std::vector<int> facet_map;
 
   // Call Rivara refinement
   RivaraRefinement::refine(refined_mesh, mesh, cell_marker, cell_map, facet_map);
 
-  // Transform data
-  transform_data(refined_mesh, mesh, cell_map, facet_map);
+  // Store child->parent cell and facet information
+  info("Creating parent cell mapping");
+  MeshFunction<dolfin::uint>* cf;
+  cf = refined_mesh.data().create_mesh_function("parent_cell",
+                                                refined_mesh.topology().dim());
+  for(uint i = 0; i < refined_mesh.num_cells(); i++)
+    (*cf)[i] = cell_map[i];
+
+  // Create mesh function in new mesh coding parent facet information
+  MeshFunction<dolfin::uint>* ff;
+  ff = refined_mesh.data().create_mesh_function("parent_facet",
+                                               refined_mesh.topology().dim()-1);
+
+  // Fill ff from facet_map
+
+  // Transform data   // Marie says: Removed. Doesn't match new style.
+  //transform_data(refined_mesh, mesh, cell_map, facet_map);
 }
 //-----------------------------------------------------------------------------
 void BisectionRefinement::transform_data(Mesh& newmesh, const Mesh& oldmesh,

=== modified file 'dolfin/mesh/RivaraRefinement.cpp'
--- dolfin/mesh/RivaraRefinement.cpp	2011-03-10 22:28:48 +0000
+++ dolfin/mesh/RivaraRefinement.cpp	2011-03-12 08:14:46 +0000
@@ -6,7 +6,7 @@
 // Modified by Anders Logg, 2010.
 //
 // First added:  2008
-// Last changed: 2011-03-10
+// Last changed: 2011-03-12
 
 #include <dolfin/log/dolfin_log.h>
 #include <dolfin/mesh/Mesh.h>
@@ -74,7 +74,6 @@
   for (uint i = 0; i < new2old_facet_arr.size(); i++)
   {
     facet_map[i] = new2old_facet_arr[i];
-    std::cout << i << " => " << facet_map[i] << std::endl;
   }
 
 }


--- End Message ---

Follow ups