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
1=== modified file 'dolfin/fem/PeriodicBC.cpp'
2--- dolfin/fem/PeriodicBC.cpp 2012-08-20 07:18:33 +0000
3+++ dolfin/fem/PeriodicBC.cpp 2012-10-31 08:38:23 +0000
4@@ -32,6 +32,7 @@
5 #include <dolfin/function/FunctionSpace.h>
6 #include <dolfin/log/log.h>
7 #include <dolfin/la/GenericMatrix.h>
8+#include <dolfin/la/PETScMatrix.h>
9 #include <dolfin/la/GenericVector.h>
10 #include <dolfin/mesh/Cell.h>
11 #include <dolfin/mesh/Facet.h>
12@@ -214,6 +215,20 @@
13 void PeriodicBC::apply(GenericMatrix* A, GenericVector* b,
14 const GenericVector* x) const
15 {
16+
17+ // The current handling of periodic boundary conditions adds entries in the matrix that
18+ // were not accounted for in the original sparsity pattern. This causes PETSc to crash,
19+ // since by default it will not let you do this (as it requires extra memory allocation
20+ // and is very inefficient). However, until that's fixed, this hack should stay in, so
21+ // that we can run these problems at all.
22+#ifdef HAS_PETSC
23+ if (A && has_type<PETScMatrix>(*A))
24+ {
25+ PETScMatrix& petsc_A = A->down_cast<PETScMatrix>();
26+ MatSetOption(*petsc_A.mat(), MAT_NEW_NONZERO_ALLOCATION_ERR, PETSC_FALSE);
27+ }
28+#endif
29+
30 if (MPI::num_processes() > 1)
31 {
32 parallel_apply(A, b, x);
33
34=== modified file 'test/unit/fem/python/PeriodicBC.py'
35--- test/unit/fem/python/PeriodicBC.py 2012-08-18 21:37:40 +0000
36+++ test/unit/fem/python/PeriodicBC.py 2012-10-31 08:38:23 +0000
37@@ -96,7 +96,7 @@
38 bc1 = PeriodicBC(V, PeriodicBoundary2())
39 bcs = [bc0, bc1]
40
41- # Define variational problem
42+ # Define variational problem, linear formulation
43 u, v = TrialFunction(V), TestFunction(V)
44 f = Expression("sin(x[0])", degree=2)
45 a = dot(grad(u), grad(v))*dx
46@@ -108,6 +108,18 @@
47
48 self.assertAlmostEqual(u.vector().norm("l2"), 0.3567245204026249, 10)
49
50+ # Define variational problem, nonlinear formulation
51+ u, v = Function(V), TestFunction(V)
52+ f = Expression("sin(x[0])", degree=2)
53+ a = dot(grad(u), grad(v))*dx
54+ L = f*v*dx
55+ F = a - L
56+
57+ # Compute solution
58+ solve(F == 0, u, bcs)
59+
60+ self.assertAlmostEqual(u.vector().norm("l2"), 0.3567245204026249, 10)
61+
62 if __name__ == "__main__":
63 print ""
64 print "Testing Dirichlet boundary conditions"

Subscribers

People subscribed via source and target branches