From ???@??? 00:00:00 1997 +0000
Received: from imag.imag.fr (imag [129.88.30.1])
	by kama.imag.fr (8.9.3+Sun/8.9.3) with ESMTP id QAA03003
	for <saramito@kama.imag.fr>; Fri, 9 Mar 2001 16:33:55 +0100 (MET)
Received: from imag.fr (tavan.imag.fr [129.88.33.86])
	by imag.imag.fr (8.9.3/8.8.6) with ESMTP id QAA12949
	for <pierre.saramito@imag.fr>; Fri, 9 Mar 2001 16:33:55 +0100 (MET)
Sender: Jerome.Monnier@imag.fr
Message-ID: <3AA8F7E3.E362E7D@imag.fr>
Date: Fri, 09 Mar 2001 16:33:55 +0100
From: Jerome Monnier <Jerome.Monnier@imag.fr>
Organization: Labo. Modelisation&Calcul / Ensimag
X-Mailer: Mozilla 4.03 [en] (X11; I; SunOS 5.7 sun4u)
MIME-Version: 1.0
To: pierre saramito <pierre.saramito@imag.fr>
Subject: code test
Content-Type: multipart/mixed; boundary="------------8EC60875ED8A52F0D9E5120A"
X-UIDL: c58708c54468af4afa963c9f57e84f9d
Status: R 
X-Status: N

This is a multi-part message in MIME format.
--------------8EC60875ED8A52F0D9E5120A
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

-- 
Jerome Monnier.
---
Laboratoire de Modelisation et Calcul / IMAG
http://www-lmc.imag.fr/lmc-edp/Jerome.Monnier
---
--------------8EC60875ED8A52F0D9E5120A
Content-Type: text/plain; charset=us-ascii; name="stokes_test_diri.c"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="stokes_test_diri.c"

/*
   Code teste ok le 08.03.01
     Attention a  -B (mat de pression)
 */

#include <fstream.h>
#include <assert.h>
#include "rheolef/rheolef.h"
#include "rheolef/stokes_asbly_2D.h"
#include "rheolef/form_manip.h"
#include "rheolef/trace.h"
#include "rheolef/uzawa_abtb.h"

// Variables relatives to B.C. --> File "physical.data"
float beta_slip ;


// ===================================================================
Float uexact_x( const point& x)
  {
    return ( 1-x[0]*x[0] * (x[1]-1.) ) ;
}
// ===================================================================
Float uexact_y( const point& x)
  {
    return ( x[0] * (x[1]-1.)*(x[1]-1.) ) ;
}
// ===================================================================
Float pexact( const point& x)
  {
    return ( -2*x[0] * (x[1]-1.) ) ;
}
// ===================================================================
Float gslip( const point& x)
  // --  Slip b.c.
  //   => Source term of the type  \int gslip * u1 ds 
  {
    return (-x[0]*x[0]) ;
}

// ===================================================================
Float ubottom_x(const point& x)
{
  return (1.+x[0]*x[0]) ;
}
// ===================================================================
Float ubottom_y(const point& x)
{
  return x[0] ;
}
// ===================================================================
Float uright_x(const point& x)
{
  return (2.-x[1]) ;
}
// ===================================================================
Float uright_y(const point& x)
{
  return (x[1]-1.)*(x[1]-1.) ;
}
// ===================================================================
Float gravity_y( const point& x)
{
  return ( -4.*x[0] ) ;
}


// ===================================================================
void stokes_asbly_2D_test(
    const geo& omega ,
    const space& V0        ,
    const space& V1        ,
    const space& Vb        , 
    form&        Ah        ,
    form&        Bh        ,
    form&        Ieh       )
{
  space Vh=V0*V1;
  space Mh = Bh.get_second_space() ;

  // ------ form Ie(Vh,Vh)
  form      Iv0(V0,V0, "mass") ;
  form      Iv1(V1,V1, "mass") ;
  form I0 ; I0 = form_nul(V1,V0) ;
  form      Ie(Vh,Vh) ;
  form_manip Ie_manip ;
  Ie_manip << size(2,2)
	   << Iv0       << I0
	   << trans(I0) << Iv1 ;
  Ie_manip >> Ie ;

  // ------ form A(Vh,Vh)
  form a11(V0,V0,"D_D_00") ; 
  form a12(V1,V0,"D_D_01") ;
  form a22(V1,V1,"D_D_11") ;
  /*
  // --  Slip b.c. on a part of (0,x) 
  // we have the extra term:  \int u0*v0 ds  on the bdry
  form ab(V0,V0,"mass_bdr",omega["top"]);
  a11 = a11 + ab;
  */
  form A(Vh,Vh) ;
  form_manip a_manip ;
  a_manip << size(2,2) 
  	  <<    a11     << a12     
    	  << trans(a12) << a22 ;
  a_manip >> A ;
  
  // ------ form B(Vh,Mh)
  form b1(V0,Mh,"d_dx0") ; 
  form b2(V1,Mh,"d_dx1") ;
  form B(Vh,Mh) ;
  form_manip b_manip ;
  b_manip << size(1,2) 
	  << b1 << b2 ;
  b_manip >> B ;

  Ah  = 2*A ;
  // Caution!
  Bh  = -1. * B   ;
  Ieh = Ie  ;
}



// =========================================================================
//                        main program
// =========================================================================
int main(int argc, char**argv)
{
  //  initialize parameters
  // ----------------------
  char*  approx_u = "P2"  ;
  char*  approx_p = "P1"  ;
  Float r_aug = 1.e+7  ;
  Float tol = 1.e-9 ;
  int max_iter = 50     ;

   // ------ load geometry on file
  geo   omega   ;  
  omega = geo(argv[1]);

  // ------ built scalar spaces for u
  space V0 ;
  space V1 ;
  // Note: u0 and u1 spaces are a priori different
  V0 = space(omega, approx_u) ;
  V1 = space(omega, approx_u) ;  
  // Block dof for Dirichlet b.c. or slip b.c.
  V0.block("bottom")    ;
  V1.block("bottom")    ;
  V0.block("left") ; 
  V1.block("left") ;  
  V0.block("right") ; 
  V1.block("right") ;
  // 
  V0.block("top") ; 
  V1.block("top") ;
  // ----------------------------------------------------------------------
  //  build spaces ans forms
  // ----------------------------------------------------------------------
  space Vh ;
  Vh = V0*V1 ;  
  space Mh(omega, approx_p) ;
  space Vb ;
  // ------ forms for Stokes
  form      Ah (Vh,Vh) ;
  form      Bh (Vh,Mh) ;
  form      Ieh(Vh,Vh) ;
  // Necessaire si rajout de l integrale sup due au glissement
  warning_macro("stokes_asbly_2D_test...");
  stokes_asbly_2D_test(omega,V0, V1, Vb, Ah, Bh, Ieh) ;
  
  // ----------------------------------------------------------------------
  //  build fields.
  // ----------------------------------------------------------------------
  warning_macro("build fields...");
  // u=(u0,u1)
  field uh(Vh) ;
  field ph(Mh) ;
  uh = 0. ;
  ph = 0. ;
  // ------ assign boundary values of Dirichlet type
  warning_macro("assign boundary values / Dirichlet...");
  // Caution: Block the dof before...
  uh[0]["left"] = 1. ;
  uh[1]["left"] = 0. ;  
  space Vbottom = space (omega,omega["bottom"],approx_u);  
  uh[0]["bottom"] = interpolate(Vbottom,ubottom_x) ;
  uh[1]["bottom"] = interpolate(Vbottom,ubottom_y) ; 
  space Vright = space (omega,omega["right"],approx_u);
  uh[0]["right"] = interpolate(Vright,uright_x);
  uh[1]["right"] = interpolate(Vright,uright_y) ;  
  // 
  uh [0]["top"]  = 1. ; 
  uh [1]["top"]  = 0. ;
  // ------ set source term
  warning_macro("assign source terms...");
  field f0h(V0) ;
  field f1h(V1) ;
  // Slip term
  space Vtop = space (omega,omega["top"],approx_u);
  field gslip_h = interpolate(Vtop,gslip);
  form mbslip (Vtop,V0,"mass_bdr");  
  //f0h = mbslip * gslip_h ; 
  f0h = 0 ;
  // Gravity term
  field gravity_h = interpolate(V1,gravity_y);
  form mb(V1,V1,"mass");  
  f1h = mb * gravity_h ; 
  field fh = fld_cat2(f0h,f1h);

  //---------------------------------------------------------------------------
  // build and solve Stokes Pb
  //---------------------------------------------------------------------------
  warning_macro("build and solve Stokes Pb...");
  // ------ augmentation & factorisation
  warning_macro("augmentation ...");
  form Arh ;
  Arh = Ah + r_aug*trans(Bh)*Bh ;
  warning_macro("factorisation ssk...");
  ssk<Float>  fact = ldlt(Arh.uu);
  warning_macro("Size pb: fh.u.size = " << fh.u.size());
  warning_macro("Solve stokes by  Uzawa's algorithm...");
  uzawa_abtb (Arh.uu, fact, Bh.uu, uh.u, ph.u, fh.u-(Arh.ub*uh.b), -(Bh.ub*uh.b), r_aug, max_iter, tol);
  // ---------------------------------------------------------------------
  //  Vorticity
  // ---------------------------------------------------------------------  
  warning_macro("vorticity...");
  space Wh  (omega, "P1d");
  form curl  (Vh, Wh, "curl");
  form inv_m (Wh, Wh, "inv_mass");
  field wh (Wh);
  wh = inv_m * ( curl*uh );
  // ---------------------------------------------------------------------
  //  Streamlines
  // ---------------------------------------------------------------------  
  warning_macro("streamlines...");
  space Ph (omega, "P2");
  Ph.block("left");  Ph.block("bottom");  
  Ph.block("right");  Ph.block("top");
  form laplace (Ph,  Ph, "grad_grad");
  form mass_curl (Wh, Ph, "mass");
  field psih (Ph);
  psih["left"] = psih["bottom"] = 0. ;
  psih["right"] = psih["top"] = 0. ;
  ssk<Float> facto =ldlt (laplace.uu);
  psih.u = facto.solve (mass_curl.uu*wh.u + mass_curl.ub*wh.b - laplace.ub*psih.b);
  // ---------------------------------------------------------------------
  //  output
  // ---------------------------------------------------------------------    
  // ------ fields and parameters
  warning_macro("fields and parameters...");
  ofstream solution_out ("solution_test.mfield") ;
  solution_out << catchmark("u") << uh
	       << catchmark("p") << ph; 
  // ---------------------------------------------------------------------
  //  Exact solution
  // --------------------------------------------------------------------- 
  field uexact_x_h = interpolate(V0,uexact_x);  
  field uexact_y_h = interpolate(V1,uexact_y);
  field uexact_h = fld_cat2(uexact_x_h,uexact_y_h);
  // Compute the normalized exact pressure
  field pexact_h = interpolate(Mh,pexact);
  form mass_p (Mh, Mh, "mass");
  field ph_1 (Mh,1.);
  double mean_pressure =  dot(mass_p*ph_1,pexact_h) ;
  field pexact_normalized_h = pexact_h - field(Mh, mean_pressure) ;
  ofstream solution_exact_out ("solution_exact.mfield") ;
  solution_exact_out << catchmark("u") << uexact_h
		      << catchmark("p") << pexact_normalized_h; 
  // ---------------------------------------------------------------------
  //  (Exact solution - computed solution)
  // --------------------------------------------------------------------- 
  field u_uh = uexact_h - uh;
  field p_ph  = pexact_normalized_h - ph;
  ofstream error_out ("error.mfield") ; 
  error_out << catchmark("u") << u_uh
	    << catchmark("p") << p_ph;
  cout << "error_u_inf" << u_uh.max_abs() << endl;
  cout << "error_p_inf" << p_ph.max_abs() << endl ; 
}

--------------8EC60875ED8A52F0D9E5120A
Content-Type: text/plain; charset=us-ascii; name="stokes_test_slip.c"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="stokes_test_slip.c"

/*
   Code teste ok le 08.03.01
     Attention a A=2*A averc beta_slip et -B (mat de pression)
 */
#include <fstream.h>
#include <assert.h>
#include "rheolef/rheolef.h"
#include "rheolef/stokes_asbly_2D.h"
#include "rheolef/form_manip.h"
#include "rheolef/trace.h"
#include "rheolef/uzawa_abtb.h"

// Physical parameter
float beta_slip = -1. ;


// ===================================================================
Float uexact_x( const point& x)
  {
    return ( 1-x[0]*x[0] * (x[1]-1.) ) ;
}
// ===================================================================
Float uexact_y( const point& x)
  {
    return ( x[0] * (x[1]-1.)*(x[1]-1.) ) ;
}
// ===================================================================
Float pexact( const point& x)
  {
    return ( -2*x[0] * (x[1]-1.) ) ;
}
// ===================================================================
Float gslip( const point& x)
  // --  Slip b.c.
  //   => Source term of the type  \int gslip * v0 ds 
  {
    return (-x[0]*x[0] - beta_slip) ;
}

// ===================================================================
Float ubottom_x(const point& x)
{
  return (1.+x[0]*x[0]) ;
}
// ===================================================================
Float ubottom_y(const point& x)
{
  return x[0] ;
}
// ===================================================================
Float uright_x(const point& x)
{
  return (2.-x[1]) ;
}
// ===================================================================
Float uright_y(const point& x)
{
  return (x[1]-1.)*(x[1]-1.) ;
}
// ===================================================================
Float gravity_y( const point& x)
{
  return ( -4.*x[0] ) ;
}


// ===================================================================
void stokes_asbly_2D_test(
    const geo& omega ,
    const space& V0        ,
    const space& V1        ,
    const space& Vb        , 
    form&        Ah        ,
    form&        Bh        ,
    form&        Ieh       )
{
  space Vh=V0*V1;
  space Mh = Bh.get_second_space() ;

  // ------ form Ie(Vh,Vh)
  form      Iv0(V0,V0, "mass") ;
  form      Iv1(V1,V1, "mass") ;
  form I0 ; I0 = form_nul(V1,V0) ;
  form      Ie(Vh,Vh) ;
  form_manip Ie_manip ;
  Ie_manip << size(2,2)
	   << Iv0       << I0
	   << trans(I0) << Iv1 ;
  Ie_manip >> Ie ;

  // ------ form A(Vh,Vh)
  form a11(V0,V0,"D_D_00") ; 
  form a12(V1,V0,"D_D_01") ;
  form a22(V1,V1,"D_D_11") ;
  // --  Slip b.c. on a part of (0,x) 
  // we have the extra term:  - beta_slip  * \int u0*v0 ds  on the bdry
  form ab(V0,V0,"mass_bdr",omega["top"]);
  // Caution : beta/2 !!!
  a11 = a11 + (-1.*beta_slip)/2. * ab;
  form A(Vh,Vh) ;
  form_manip a_manip ;
  a_manip << size(2,2) 
  	  <<    a11     << a12     
    	  << trans(a12) << a22 ;
  a_manip >> A ;
  
  // ------ form B(Vh,Mh)
  form b1(V0,Mh,"d_dx0") ; 
  form b2(V1,Mh,"d_dx1") ;
  form B(Vh,Mh) ;
  form_manip b_manip ;
  b_manip << size(1,2) 
	  << b1 << b2 ;
  b_manip >> B ;
  // Caution !!!
  Ah  = 2*A ;
  Bh  = -1. * B   ;
  Ieh = Ie  ;
}



// =========================================================================
//                        main program
// =========================================================================
int main(int argc, char**argv)
{
  //  initialize parameters
  // ----------------------
  char*  approx_u = "P2"  ;
  char*  approx_p = "P1"  ;
  Float r_aug = 1.e+7  ;
  Float tol = 1.e-9 ;
  int max_iter = 50     ;

   // ------ load geometry on file
  geo   omega   ;  
  omega = geo(argv[1]);

  // ------ built scalar spaces for u
  space V0 ;
  space V1 ;
  // Note: u0 and u1 spaces are a priori different
  V0 = space(omega, approx_u) ;
  V1 = space(omega, approx_u) ;  
  // Block dof for Dirichlet b.c. or slip b.c.
  V0.block("bottom")    ;
  V1.block("bottom")    ;
  V0.block("left") ; 
  V1.block("left") ;  
  V0.block("right") ; 
  V1.block("right") ;
  // Slip b.c // (ox)
  V1.block("top") ;
  // ----------------------------------------------------------------------
  //  build spaces ans forms
  // ----------------------------------------------------------------------
  space Vh ;
  Vh = V0*V1 ;  
  space Mh(omega, approx_p) ;
  space Vb ;
  // ------ forms for Stokes
  form      Ah (Vh,Vh) ;
  form      Bh (Vh,Mh) ;
  form      Ieh(Vh,Vh) ;
  // Necessaire si rajout de l integrale sup due au glissement
  warning_macro("stokes_asbly_2D_test...");
  stokes_asbly_2D_test(omega,V0, V1, Vb, Ah, Bh, Ieh) ;
  
  // ----------------------------------------------------------------------
  //  build fields.
  // ----------------------------------------------------------------------
  warning_macro("build fields...");
  // u=(u0,u1)
  field uh(Vh) ;
  field ph(Mh) ;
  uh = 0. ;
  ph = 0. ;
  // ------ assign boundary values of Dirichlet type
  warning_macro("assign boundary values / Dirichlet...");
  // Caution: Block the dof before...
  uh[0]["left"] = 1. ;
  uh[1]["left"] = 0. ;  
  space Vbottom = space (omega,omega["bottom"],approx_u);  
  uh[0]["bottom"] = interpolate(Vbottom,ubottom_x) ;
  uh[1]["bottom"] = interpolate(Vbottom,ubottom_y) ; 
  space Vright = space (omega,omega["right"],approx_u);
  uh[0]["right"] = interpolate(Vright,uright_x);
  uh[1]["right"] = interpolate(Vright,uright_y) ;  
  // Slip b.c. parallel to (0,x)
  uh [1]["top"]  = 0. ;
  // ------ set source term
  warning_macro("assign source terms...");
  field f0h(V0) ;
  field f1h(V1) ;
  // Slip term
  space Vtop = space (omega,omega["top"],approx_u);
  field gslip_h = interpolate(Vtop,gslip);
  form mbslip (Vtop,V0,"mass_bdr");  
  f0h = mbslip * gslip_h ; 
  // Gravity term
  field gravity_h = interpolate(V1,gravity_y);
  form mb(V1,V1,"mass");  
  f1h = mb * gravity_h ; 
  field fh = fld_cat2(f0h,f1h);

  //---------------------------------------------------------------------------
  // build and solve Stokes Pb
  //---------------------------------------------------------------------------
  warning_macro("build and solve Stokes Pb...");
  // ------ augmentation & factorisation
  warning_macro("augmentation ...");
  form Arh ;
  Arh = Ah + r_aug*trans(Bh)*Bh ;
  warning_macro("factorisation ssk...");
  ssk<Float>  fact = ldlt(Arh.uu);
  warning_macro("Size pb: fh.u.size = " << fh.u.size());
  warning_macro("Solve stokes by  Uzawa's algorithm...");
  uzawa_abtb (Arh.uu, fact, Bh.uu, uh.u, ph.u, fh.u-(Arh.ub*uh.b), -(Bh.ub*uh.b), r_aug, max_iter, tol);
  // ---------------------------------------------------------------------
  //  Vorticity
  // ---------------------------------------------------------------------  
  warning_macro("vorticity...");
  space Wh  (omega, "P1d");
  form curl  (Vh, Wh, "curl");
  form inv_m (Wh, Wh, "inv_mass");
  field wh (Wh);
  wh = inv_m * ( curl*uh );
  // ---------------------------------------------------------------------
  //  Streamlines
  // ---------------------------------------------------------------------  
  warning_macro("streamlines...");
  space Ph (omega, "P2");
  Ph.block("left");  Ph.block("bottom");  
  Ph.block("right");  Ph.block("top");
  form laplace (Ph,  Ph, "grad_grad");
  form mass_curl (Wh, Ph, "mass");
  field psih (Ph);
  psih["left"] = psih["bottom"] = 0. ;
  psih["right"] = psih["top"] = 0. ;
  ssk<Float> facto =ldlt (laplace.uu);
  psih.u = facto.solve (mass_curl.uu*wh.u + mass_curl.ub*wh.b - laplace.ub*psih.b);
  // ---------------------------------------------------------------------
  //  output
  // ---------------------------------------------------------------------    
  // ------ fields and parameters
  warning_macro("fields and parameters...");
  ofstream solution_out ("solution_test.mfield") ;
  solution_out << catchmark("u") << uh
	       << catchmark("p") << ph; 
  // ---------------------------------------------------------------------
  //  Exact solution
  // --------------------------------------------------------------------- 
  field uexact_x_h = interpolate(V0,uexact_x);  
  field uexact_y_h = interpolate(V1,uexact_y);
  field uexact_h = fld_cat2(uexact_x_h,uexact_y_h);
 // Compute the normalized exact pressure
  field pexact_h = interpolate(Mh,pexact);
  form mass_p (Mh, Mh, "mass");
  field ph_1 (Mh,1.);
  double mean_pressure =  dot(mass_p*ph_1,pexact_h) ;
  field pexact_normalized_h = pexact_h - field(Mh, mean_pressure) ;
  ofstream solution_exact_out ("solution_exact.mfield") ;
  solution_exact_out << catchmark("u") << uexact_h
		      << catchmark("p") << pexact_normalized_h; 
  // ---------------------------------------------------------------------
  //  (Exact solution - computed solution)
  // --------------------------------------------------------------------- 
  field u_uh = uexact_h - uh;
  field p_ph  = pexact_normalized_h - ph;
  ofstream error_out ("error.mfield") ; 
  error_out << catchmark("u") << u_uh
	    << catchmark("p") << p_ph;
  cout << "error_u_inf" << u_uh.max_abs() << endl;
  cout << "error_p_inf" << p_ph.max_abs() << endl ; 
}

--------------8EC60875ED8A52F0D9E5120A
Content-Type: text/plain; charset=us-ascii; name="square_test.dmn"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="square_test.dmn"

EdgeDomainNames
	4
	bottom
	right
	top
	left

--------------8EC60875ED8A52F0D9E5120A
Content-Type: text/plain; charset=us-ascii; name="square_test.msh"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="square_test.msh"

MeshVersionFormatted 0
Dimension 2
Vertices 4
 0 0 1
 1 0 2
 1 1 2
 0 1 4
Edges 4
1 2 1
2 3 2
3 4 3
4 1 4
hVertices
0.05 0.05 0.05 0.05
 




--------------8EC60875ED8A52F0D9E5120A--



