FEATool  v1.8
Finite Element Analysis Toolbox
 All Files Functions Pages
ex_periodic1.m File Reference

Description

EX_PERIODIC1 1D Example of pulse in a periodic line.

[ FEA, OUT ] = EX_PERIODIC1( VARARGIN ) Moving 1D pulse in a periodic domain. Accepts the following property/value pairs.

Input       Value/{Default}        Description
-----------------------------------------------------------------------------------
init        string <tt>(x>=0.4)*(x<=0.6)</tt>   Initial shape of pulse
iplot       scalar 0/{1}           Plot solution and error (=1)
                                                                                  .
Output      Value/(Size)           Description
-----------------------------------------------------------------------------------
fea         struct                 Problem definition struct
out         struct                 Output struct

Code listing

 cOptDef = { 'init',     '(x>=0.4)*(x<=0.6)';
             'iplot',    1;
             'fid',      1 };
 [got,opt] = parseopt(cOptDef,varargin{:});
 fid       = opt.fid;

 fea.sdim = {'x'};
 fea.grid = linegrid( 100 );

 fea = addphys( fea, @convectiondiffusion );
 fea.phys.cd.eqn.coef{3,end} = { 1 };
 fea.phys.cd.eqn.coef{2,end} = { 0.002 };
 fea = parsephys( fea );

 fea.bdr.d{1} = { [] [] };
 fea.bdr.n{1}{2} = 'solve_hook_periodic_bc';


% Save pediodic boundary function to file.
 s_file = fileread( [mfilename('fullpath'),'.m'] );
 ix = strfind( s_file, 'function' );
 s_fcn = s_file(ix(end):end);
 ix1 = find( s_fcn == '=', 1 );
 ix2 = find( s_fcn == '(', 1 );
 s_fname = strtrim(s_fcn(ix1+1:ix2-1));
 fid_tmp = fopen( [s_fname,'.m'], 'w' );
 fprintf( fid_tmp, '%s', s_fcn );
 fclose( fid_tmp );


% Parse and solve problem.
 fea = parseprob( fea );
 fea.sol.u = solvetime( fea, 'init', opt.init, 'tstep', 0.005, 'tmax', 1, 'fid', opt.fid );


% Postprocessing.
 if( opt.iplot>0 )
   postplot( fea, 'surfexpr', 'c', 'solnum', 1, 'color', 'b' )
   postplot( fea, 'surfexpr', 'c', 'solnum', floor(size(fea.sol.u,2)/4), 'color', 'c' )
   postplot( fea, 'surfexpr', 'c', 'solnum', floor(size(fea.sol.u,2)/2), 'color', 'm' )
   postplot( fea, 'surfexpr', 'c', 'solnum', floor(size(fea.sol.u,2)*3/4), 'color', 'g' )
   postplot( fea, 'surfexpr', 'c', 'solnum', size(fea.sol.u,2) )
   axis( [0 1 0 1] )
   grid on
 end


% Error checking.
 if( strcmp(opt.init,'(x>=0.4)*(x<=0.6)') )
   i_ref  = 0.2;
   i_calc = intsubd( 'c*(x>=0.4)*(x<=0.6)', fea );
   err = abs(i_calc-i_ref)/i_ref;

   if( ~isempty(fid) )
     fprintf(fid,'\nError: %f\n',err)
     fprintf(fid,'\n\n')
   end
 end


 out.err  = err;
 out.pass = err<0.3;
 if ( nargout==0 )
   clear fea out
 end


%