Merge lp:~pefarrell/dolfin/periodic-malloc into lp:~fenics-core/dolfin/trunk

Proposed by Patrick Farrell
Status: Merged
Merged at revision: 7061
Proposed branch: lp:~pefarrell/dolfin/periodic-malloc
Merge into: lp:~fenics-core/dolfin/trunk
Diff against target: 64 lines (+28/-1)
2 files modified
dolfin/fem/PeriodicBC.cpp (+15/-0)
test/unit/fem/python/PeriodicBC.py (+13/-1)
To merge this branch: bzr merge lp:~pefarrell/dolfin/periodic-malloc
Reviewer Review Type Date Requested Status
Anders Logg Pending
Review via email: mp+132257@code.launchpad.net

Description of the change

Implement Anders' temporary fix for nonlinear periodic boundary conditions crashing, as discussed in
https://answers.launchpad.net/dolfin/+question/212407 .

This should only live until periodic boundary conditions are "properly fixed" so that the correct sparsity is generated. In the meantime, this works (but is inefficient).

I also added a snippet to the PeriodicBC.py unit test which fails on the current trunk, but which passes on this branch.

To post a comment you must log in.
Revision history for this message
Garth Wells (garth-wells) wrote :

Looks like this breaks with the Epetra backed again. It should be fixed properly.

Revision history for this message
Patrick Farrell (pefarrell) wrote :
Revision history for this message
Anders Logg (logg) wrote :

On Thu, Nov 01, 2012 at 03:39:22PM -0000, Garth Wells wrote:
> Looks like this breaks with the Epetra backed again. It should be fixed properly.

How will this patch affect the Epetra backend? The patch only
introduces a fix that makes PeriodicBC run again with PETSc.

--
Anders

Revision history for this message
Garth Wells (garth-wells) wrote :

On Thu, Nov 1, 2012 at 5:52 PM, Anders Logg <email address hidden> wrote:
> On Thu, Nov 01, 2012 at 03:39:22PM -0000, Garth Wells wrote:
>> Looks like this breaks with the Epetra backed again. It should be fixed properly.
>
> How will this patch affect the Epetra backend? The patch only
> introduces a fix that makes PeriodicBC run again with PETSc.
>

That's not the case. The added test in this change in

   test/unit/fem/python/PeriodicBC.py

does not work with Epetra for the same reason the code did not work
with PETSc, and which is why a proper fix is needed.

Garth

> --
> Anders
>
> --
> https://code.launchpad.net/~pefarrell/dolfin/periodic-malloc/+merge/132257
> Your team DOLFIN Core Team is subscribed to branch lp:dolfin.

Revision history for this message
Patrick Farrell (pefarrell) wrote :

Garth: can you sketch what a "proper fix" might entail?

Revision history for this message
Garth Wells (garth-wells) wrote :

On Thu, Nov 1, 2012 at 9:55 PM, Patrick Farrell
<email address hidden> wrote:
> Garth: can you sketch what a "proper fix" might entail?

Creating a periodic FunctionSpace. This would involve passing the
periodic boundaries though the FunctionSpace constructor and to the
dof map builder. The dof map would just have to make sure that the
'slave' dofs map to the master dofs (i.e. there will be no 'master'
and 'slave' in practice). With this in place, the sparsity pattern and
all the rest will work without needing to be aware of the periodic
boundaries, any symmetry will be preserved and preconditioners won't
get screwed up.

Garth

> --
> https://code.launchpad.net/~pefarrell/dolfin/periodic-malloc/+merge/132257
> Your team DOLFIN Core Team is subscribed to branch lp:dolfin.

Revision history for this message
Anders Logg (logg) wrote :

On Thu, Nov 01, 2012 at 06:22:18PM -0000, Garth Wells wrote:
> On Thu, Nov 1, 2012 at 5:52 PM, Anders Logg <email address hidden> wrote:
> > On Thu, Nov 01, 2012 at 03:39:22PM -0000, Garth Wells wrote:
> >> Looks like this breaks with the Epetra backed again. It should be fixed properly.
> >
> > How will this patch affect the Epetra backend? The patch only
> > introduces a fix that makes PeriodicBC run again with PETSc.
> >
>
> That's not the case. The added test in this change in
>
> test/unit/fem/python/PeriodicBC.py
>
> does not work with Epetra for the same reason the code did not work
> with PETSc, and which is why a proper fix is needed.

Fixed now.

--
Anders

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'dolfin/fem/PeriodicBC.cpp'
--- dolfin/fem/PeriodicBC.cpp 2012-08-20 07:18:33 +0000
+++ dolfin/fem/PeriodicBC.cpp 2012-10-31 08:38:23 +0000
@@ -32,6 +32,7 @@
32#include <dolfin/function/FunctionSpace.h>32#include <dolfin/function/FunctionSpace.h>
33#include <dolfin/log/log.h>33#include <dolfin/log/log.h>
34#include <dolfin/la/GenericMatrix.h>34#include <dolfin/la/GenericMatrix.h>
35#include <dolfin/la/PETScMatrix.h>
35#include <dolfin/la/GenericVector.h>36#include <dolfin/la/GenericVector.h>
36#include <dolfin/mesh/Cell.h>37#include <dolfin/mesh/Cell.h>
37#include <dolfin/mesh/Facet.h>38#include <dolfin/mesh/Facet.h>
@@ -214,6 +215,20 @@
214void PeriodicBC::apply(GenericMatrix* A, GenericVector* b,215void PeriodicBC::apply(GenericMatrix* A, GenericVector* b,
215 const GenericVector* x) const216 const GenericVector* x) const
216{217{
218
219 // The current handling of periodic boundary conditions adds entries in the matrix that
220 // were not accounted for in the original sparsity pattern. This causes PETSc to crash,
221 // since by default it will not let you do this (as it requires extra memory allocation
222 // and is very inefficient). However, until that's fixed, this hack should stay in, so
223 // that we can run these problems at all.
224#ifdef HAS_PETSC
225 if (A && has_type<PETScMatrix>(*A))
226 {
227 PETScMatrix& petsc_A = A->down_cast<PETScMatrix>();
228 MatSetOption(*petsc_A.mat(), MAT_NEW_NONZERO_ALLOCATION_ERR, PETSC_FALSE);
229 }
230#endif
231
217 if (MPI::num_processes() > 1)232 if (MPI::num_processes() > 1)
218 {233 {
219 parallel_apply(A, b, x);234 parallel_apply(A, b, x);
220235
=== modified file 'test/unit/fem/python/PeriodicBC.py'
--- test/unit/fem/python/PeriodicBC.py 2012-08-18 21:37:40 +0000
+++ test/unit/fem/python/PeriodicBC.py 2012-10-31 08:38:23 +0000
@@ -96,7 +96,7 @@
96 bc1 = PeriodicBC(V, PeriodicBoundary2())96 bc1 = PeriodicBC(V, PeriodicBoundary2())
97 bcs = [bc0, bc1]97 bcs = [bc0, bc1]
9898
99 # Define variational problem99 # Define variational problem, linear formulation
100 u, v = TrialFunction(V), TestFunction(V)100 u, v = TrialFunction(V), TestFunction(V)
101 f = Expression("sin(x[0])", degree=2)101 f = Expression("sin(x[0])", degree=2)
102 a = dot(grad(u), grad(v))*dx102 a = dot(grad(u), grad(v))*dx
@@ -108,6 +108,18 @@
108108
109 self.assertAlmostEqual(u.vector().norm("l2"), 0.3567245204026249, 10)109 self.assertAlmostEqual(u.vector().norm("l2"), 0.3567245204026249, 10)
110110
111 # Define variational problem, nonlinear formulation
112 u, v = Function(V), TestFunction(V)
113 f = Expression("sin(x[0])", degree=2)
114 a = dot(grad(u), grad(v))*dx
115 L = f*v*dx
116 F = a - L
117
118 # Compute solution
119 solve(F == 0, u, bcs)
120
121 self.assertAlmostEqual(u.vector().norm("l2"), 0.3567245204026249, 10)
122
111if __name__ == "__main__":123if __name__ == "__main__":
112 print ""124 print ""
113 print "Testing Dirichlet boundary conditions"125 print "Testing Dirichlet boundary conditions"

Subscribers

People subscribed via source and target branches