← Back to team overview

dolfin team mailing list archive

Re: Nonlinear Coupled PDEs, Newton Solver

 

Hi Hatef,

It sounds as if you are interested in the Navier-Stokes equations, or
similar? If so, you may want to check out the Unicorn solver:
http://www.fenics.org/wiki/Unicorn

Direct any Unicorn questions to: unicorn-dev@xxxxxxxxxx

Best,
Johan


> <p>Hi</p><p>I installed the new version of dolfin (0.9.0) as you wanted
> and am trying to model a coupled set of PDEs which are nonlinear. As I
> told in my previous emails, there are currenlty not much documents on
> nonlinear problems. so based on what I have seen on the demos I came up
> with the following code which does not seem to be working. I would
> appreciate if anyone could suggest any material or hint on modeling these
> kind of problems in which there are more that one variable. in my case
> there is a vector variable (Velocity) and a scalar one (Pressure) and
> Nonlinearity is only due to the term (u.grad)u and I am trying to use
> Newton's solver&nbsp; for nonlinear iterations.</p><p><br /><br
> />Thanks</p><p>Hatef</p><p>//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////<br
> />//Noslip function<br /><br />class VelNoslip : public Function<br
> />&nbsp; {<br />&nbsp; public:<br /><br />&nbsp;&nbsp;&nbsp; void
> eval(real* values, const real* x) const<br />&nbsp;&nbsp;&nbsp; {<br
> />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br
> />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
> values[0]=0.0&nbsp; ;<br
> />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
> values[1]=0.0&nbsp; ;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br
> />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br /><br
> />&nbsp; };<br /><br
> />////////////////////////////////////////////////////////////////////////////////////<br
> />//-Noslip BC subdomain<br />class Noslip_boundary_end : public
> SubDomain<br />&nbsp; {<br />&nbsp;&nbsp;&nbsp; bool inside(const real* x,
> bool on_boundary) const<br />&nbsp;&nbsp;&nbsp; {<br
> />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return <br
> />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
> (x[0]&gt;1.0-DOLFIN_EPS) &amp;&amp; on_boundary;<br
> />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;
> };<br /><br />class Noslip_boundary_side : public SubDomain<br />&nbsp;
> {<br />&nbsp;&nbsp;&nbsp; bool inside(const real* x, bool on_boundary)
> const<br />&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return
> <br
> />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
> (x[0]&gt;DOLFIN_EPS &amp;&amp; x[0]&lt;1.0-DOLFIN_EPS) &amp;&amp;
> on_boundary;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp;
> }<br />&nbsp; };<br /><br /><br />// define subdomain for inflow<br
> />class Inflow_boundary : public SubDomain<br />&nbsp; {<br
> />&nbsp;&nbsp;&nbsp; bool inside(const real* x, bool on_boundary) const<br
> />&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return <br
> />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
> x[0]&lt; DOLFIN_EPS &amp;&amp; on_boundary;<br
> />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;
> };<br /><br
> />////////////////////////////////////////////////////////////////////////////////////////////<br
> />int main()<br />{<br /><br /><br />//Read Mesh and Subdomain marker and
> define function space<br />UnitSquare&nbsp; mesh(32,32);</p><p>//Define
> fuction space<br />&nbsp; NSWEFunctionSpace V(mesh);<br />&nbsp; SubSpace
> velocity(V,0);<br />&nbsp; SubSpace pressure(V,1);</p><p><br /><br
> />MeshFunction &lt;unsigned int&gt; sub_domains(mesh,
> mesh.topology().dim() -1);<br /><br /><br />// Mark all facets as sub
> domain 3<br />&nbsp; sub_domains = 3;<br />// Mark end Noslip subdomain<br
> />&nbsp; Noslip_boundary_end noslip_boundary_end;<br />&nbsp;
> noslip_boundary_end.mark(sub_domains,0);<br /><br /><br />// mark side
> noslip subdomain<br />&nbsp; Noslip_boundary_side noslip_boundary_side;<br
> />&nbsp; noslip_boundary_side.mark(sub_domains,1);<br /><br /><br />//mark
> Inflow subdomain<br />&nbsp; Inflow_boundary inflow_boundary;<br />&nbsp;
> inflow_boundary.mark(sub_domains,2);<br />&nbsp; //pseudo time<br />&nbsp;
> real t = 0.0;<br />&nbsp; <br />&nbsp; //solution vector<br />&nbsp;
> Function v(V);<br />&nbsp; Function U(velocity);<br />&nbsp; Function
> P(pressure); <br />&nbsp;<br />&nbsp; Function Un(velocity);<br />&nbsp;
> Un.vector().zero();<br />&nbsp; Function Pn(pressure);<br />&nbsp;
> Pn.vector().zero();<br />&nbsp; <br />&nbsp; <br />&nbsp; Constant
> f(2,0.0);<br />&nbsp; VelNoslip&nbsp; velnoslip;<br />&nbsp; Constant
> inflow(0.1);<br />&nbsp; <br />&nbsp; <br /><br />&nbsp; <br />&nbsp;<br
> />&nbsp; //set up Forms<br />&nbsp; NSWEBilinearForm a(V,V) ;<br />&nbsp;
> a.U0=U;<br />&nbsp; NSWELinearForm L(V);<br />&nbsp; L.Un=Un; L.Pn=Pn ;
> L.F=f; L.U0=U; L.P0=P;<br />&nbsp; <br />&nbsp; <br />&nbsp; //set up
> boundary condition<br />&nbsp; <br />&nbsp; DirichletBC bc0(velocity,
> velnoslip,sub_domains,0);<br />&nbsp; DirichletBC bc1(velocity,
> velnoslip,sub_domains,1);<br />&nbsp; DirichletBC bc2(velocity,
> velnoslip,sub_domains,2);<br />&nbsp; DirichletBC bc3(pressure,
> inflow,sub_domains,2);<br />&nbsp; //collect all the BCs<br />&nbsp;
> Array&lt;BoundaryCondition*&gt;
> bcs(&amp;bc0,&amp;bc1,&amp;bc2,&amp;bc3);<br />&nbsp; <br />&nbsp;
> //parameters for time stepping<br /><br />&nbsp; real T = 0.005;<br
> />&nbsp; real k = 0.001;<br />&nbsp; <br />&nbsp; <br />&nbsp; <br
> />&nbsp; File file_2(&quot;Pressure.pvd&quot;);<br />&nbsp; File
> file_1(&quot;Velocity.pvd&quot;);<br /><br />&nbsp;<br /><br />&nbsp;
> //time stepping<br />&nbsp; Progress prg(&quot;Time-stepping&quot;);<br
> />&nbsp; while ( t &lt; T )<br />&nbsp; {&nbsp; <br />&nbsp;<br />&nbsp;
> VariationalProblem nlpde(a,L,bcs,true);<br />&nbsp; <br />&nbsp;
> nlpde.solve(v);<br />&nbsp; <br />&nbsp; U = v[0];<br />&nbsp; P =
> v[1];</p><p><br />&nbsp; // Save the solution to file<br />&nbsp; file_2
> &lt;&lt; P;<br />&nbsp; file_1 &lt;&lt; U;<br />&nbsp; <br />&nbsp; //
> Move to the next interval&nbsp;</p><p>&nbsp; Un.vector()=U.vector() ; <br
> />&nbsp; Pn.vector()=P.vector() ; <br />&nbsp; prg = t / T;<br />&nbsp; t
> += k;<br />&nbsp;<br />&nbsp; }<br /><br />}</p>
> _______________________________________________
> DOLFIN-dev mailing list
> DOLFIN-dev@xxxxxxxxxx
> http://www.fenics.org/mailman/listinfo/dolfin-dev
>




References