Программирование МКЭ в МATLAB. Даутов P.З. - 36 стр.

UptoLike

Составители: 

36 Глава 2. Построение сеток в MatLab
A = d12 ( 1 , : ) .
*
d13 (2 ,:) d12 ( 2 , : ) .
*
d13 ( 1 , : ) ; % A/2= a rea
i f A>0, ee ( 7 , i i )= i t 1 ; ee ( 8 , i i )= i t 2 ;
e l s e ee ( 7 , i i )= i t 2 ; ee ( 8 , i i )= i t 1 ; end
end
% s et midpoint c o o r d i n a t e s .
nep=s i z e ( ep , 2 ) ; p2=[p z e r os ( 2 , nep ) ] ;
f o r i =1: nep
i f ee (6 , i )==0
i 1=ee ( 1 , i ) ; i 2=ee ( 2 , i ) ;
p2 ( : , np+i )=(p ( : , i 1 )+p ( : , i2 ) ) / 2 ;
e l s e
% s et boundary edge " midpoint " c oo r d i na te s
[ x , y]= pdeigeom ( g , ee ( 6 , i ) , 0 . 5
*
( ee (4 , i )+ee ( 5 , i ) ) ) ;
p2 ( : , np+i )=[ x ; y ] ;
end
end
Для рисования P
2
сеток можно использовать функцию plotmeshP2;
она проста для понимания и легко может быть модифицирована.
f u n c t i o n h=plotmeshP2 ( g , p , e , t , ee , opt , f s )
% PLOTMESHP2: draw P2mesh (p , e , t ) and
% opt (1)==1 > draw p oi n t l a b e l s
% opt (2)==1 > draw t r i a n g l e l a b e l s
% opt (3)==1 > draw bord er and boundary edge segment l a b e l s
% opt (4)==1 > draw edge l a b e l s
% f s = Font S ize
np=s i z e ( p , 2 ) ; nt=s i z e ( t , 2 ) ; ne=s i z e ( e , 2 ) ; nee=s i z e ( ee , 2 ) ;
h=f i g u r e ; a x i s e q u a l ; hold on , x l a b e l ('x_1' ) , y l a b e l ('x_2' )
% get i n t e r n a l ( not bor der or boundary ) edges ( i i ) and pl o t
i i = s e t d i f f ( ee ( 1 : 2 , : ) ' , e ( 1 : 2 , : ) ' , ' rows' ) ;
X=[p ( 1 , i i ( : , 1 ) ) ; p ( 1 , i i ( : , 2 ) ) ] ; Y=[p ( 2 , i i ( : , 1 ) ) ; p ( 2 , i i ( : , 2 ) ) ] ;
l i n e (X,Y, ' Color' ,'b' ,' LineWidth' , 1 ) ;
% p l o t bor d er and boundary e d ges
npe =10; % number o f p o in t on an edge
X= [ ] ; Y= [ ] ; f o r i =1: ne ,
s=l i n s p a c e ( e ( 4 , i ) , e ( 5 , i ) , npe ) ;
[ x1 , y1]= pdeigeom ( g , e ( 6 , i ) , s ) ;
X=[X x1 NaN ] ; Y=[Y y1 NaN ] ;
end
p l o t (X, Y, ' Color' , ' r' ,' LineWidth' , 1 ) ;
% mark po i n t s
p l o t ( p ( 1 , : ) , p ( 2 , : ) , ' . k ' , ' MarkerSize' ,8 )
i f opt (1)==1 % draw p o i n t s l a b e l s
f o r i =1:np
t e x t (p ( 1 , i ) , p ( 2 , i ) , [ ' ' i n t 2 s t r ( i ) ] , ' Fo ntSi z e' , f s , ' Color' ,' k' ) ;
end
end
36                                                                            Глава 2. Построение сеток в MatLab


  A = d12 ( 1 , : ) . * d13 ( 2 , : ) − d12 ( 2 , : ) . * d13 ( 1 , : ) ; % A/2= a r e a
  i f A>0, e e ( 7 , i i )= i t 1 ; e e ( 8 , i i )= i t 2 ;
  else      e e ( 7 , i i )= i t 2 ; e e ( 8 , i i )= i t 1 ; end
end

% s e t midpoint c o o r d i n a t e s .
nep=s i z e ( ep , 2 ) ; p2=[p z e r o s ( 2 , nep ) ] ;
f o r i =1: nep
    i f e e ( 6 , i )==0
       i 1=e e ( 1 , i ) ; i 2=e e ( 2 , i ) ;
       p2 ( : , np+i )=(p ( : , i 1 )+p ( : , i 2 ) ) / 2 ;
    else
       % s e t boundary edge " midpoint " c o o r d i n a t e s
       [ x , y]= pdeigeom ( g , e e ( 6 , i ) , 0 . 5 * ( e e ( 4 , i )+ e e ( 5 , i ) ) ) ;
       p2 ( : , np+i )=[ x ; y ] ;
    end
end

Для рисования P2 сеток можно использовать функцию plotmeshP2;
она проста для понимания и легко может быть модифицирована.
f u n c t i o n h=plotmeshP2 ( g , p , e , t , ee , opt , f s )
% PLOTMESHP2: draw P2−mesh ( p , e , t ) and
% opt (1)==1 −−> draw p o i n t l a b e l s
% opt (2)==1 −−> draw t r i a n g l e l a b e l s
% opt (3)==1 −−> draw b o r d e r and boundary edge segment l a b e l s
% opt (4)==1 −−> draw edge l a b e l s
% f s = FontSize

np=s i z e ( p , 2 ) ; nt=s i z e ( t , 2 ) ; ne=s i z e ( e , 2 ) ; nee=s i z e ( ee , 2 ) ;
h=f i g u r e ; a x i s e q u a l ; h o l d on , x l a b e l ( 'x_1' ) , y l a b e l ( 'x_2' )

% g e t i n t e r n a l ( not b o r d e r o r boundary ) e d g e s ( i i ) and p l o t
i i = s e t d i f f ( e e ( 1 : 2 , : ) ' , e ( 1 : 2 , : ) ' , 'rows' ) ;
X=[p ( 1 , i i ( : , 1 ) ) ; p ( 1 , i i ( : , 2 ) ) ] ; Y=[p ( 2 , i i ( : , 1 ) ) ; p ( 2 , i i ( : , 2 ) ) ] ;
l i n e (X, Y, ' C o l o r ' , 'b' , 'LineWidth' , 1 ) ;

% p l o t b o r d e r and boundary e d g e s
npe =10; % number o f p o i n t on an edge
X= [ ] ; Y= [ ] ; f o r i =1: ne ,
    s=l i n s p a c e ( e ( 4 , i ) , e ( 5 , i ) , npe ) ;
    [ x1 , y1 ]= pdeigeom ( g , e ( 6 , i ) , s ) ;
   X=[X x1 NaN ] ; Y=[Y y1 NaN ] ;
end
p l o t (X, Y, ' C o l o r ' , ' r ' , 'LineWidth' , 1 ) ;

% mark p o i n t s
p l o t ( p ( 1 , : ) , p ( 2 , : ) , ' . k ' , ' M a rk e rS i z e ' , 8 )

i f opt (1)==1 % draw p o i n t s l a b e l s
   f o r i =1:np
       t e x t ( p ( 1 , i ) , p ( 2 , i ) , [ ' ' i n t 2 s t r ( i ) ] , ' F o n t S i z e ' , f s , ' C o l o r ' , 'k' ) ;
   end
end