call_netgen

PURPOSE ^

CALL_NETGEN: call netgen to create a vol_file from a geo_file

SYNOPSIS ^

function status= call_netgen(geo_file, vol_file, msz_file, finelevel)

DESCRIPTION ^

 CALL_NETGEN: call netgen to create a vol_file from a geo_file
 status= call_netgen(geo_file, vol_file, msz_file, finelevel)
  staus = 0 -> success , negative -> failure

 geo_file = geometry file (input)
 vol_file = FEM mesh file (output)
 msz_file = Meshsize file in netgen format

 Finelevel controls the fineness of the mesh
   default is '' -> coarse
   valid values are 'fine' or 'veryfine'

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function status= call_netgen(geo_file, vol_file, msz_file, finelevel)
0002 % CALL_NETGEN: call netgen to create a vol_file from a geo_file
0003 % status= call_netgen(geo_file, vol_file, msz_file, finelevel)
0004 %  staus = 0 -> success , negative -> failure
0005 %
0006 % geo_file = geometry file (input)
0007 % vol_file = FEM mesh file (output)
0008 % msz_file = Meshsize file in netgen format
0009 %
0010 % Finelevel controls the fineness of the mesh
0011 %   default is '' -> coarse
0012 %   valid values are 'fine' or 'veryfine'
0013 
0014 % $Id: call_netgen.m 5411 2017-04-24 11:44:22Z aadler $
0015 % (C) 2006 Andy Adler. Licensed under GPL V2
0016 
0017 if nargin<3
0018    msz_file= '';
0019 end
0020 
0021 if ~isempty(msz_file)
0022    eidors_msg('call_netgen: Warning. Using an *.msz file. This often fails.');
0023 end
0024 
0025 if nargin<4
0026    %  finelevel= '-veryfine';
0027    %  finelevel= '-fine';
0028    finelevel= '';
0029 end
0030 
0031 if  exist('OCTAVE_VERSION') % FIXME
0032    islinux =1;
0033 elseif ~strncmp(computer,'PC',2) % Don't know if we have isunix
0034    islinux =1;
0035 else
0036    islinux =0;
0037 end
0038 
0039 % Netgen executable filename
0040 cache_path = eidors_cache('cache_path');
0041 if  islinux
0042    ng_name = 'netgen';
0043 else
0044    ng_name = [cache_path,'/ng'];
0045 end
0046  
0047 while( 1 )
0048    
0049    fid= fopen('ng.opt','a'); %create ng.opt file in local dir
0050    if fid==-1
0051       error(['Netgen requires writing files in the current directory(%s). ', ...
0052          'Unfortunately, you don''t have permission. ' ...
0053          'Your options are: 1) change your working directory to one in which you have write permission, or ' ...
0054          '2) change the permissions on the current working directory.'], pwd);
0055    end
0056    if ~isempty(msz_file)
0057       %     fprintf(fid,'options.segmentsperedge 5\n'); % Another
0058       %                                                   potentially useful parameter
0059       %                                                   except netgen ignores it
0060       fprintf(fid,'options.meshsizefilename= %s\n',msz_file);
0061    end
0062    fclose(fid);
0063 
0064    if strncmp(computer,'PC',2)
0065       % on Linux, Netgen runs in the current directory
0066       % enforce this behavioud in Windows
0067       oldpath = getenv('NETGEN_USER_DIR');
0068       setenv('NETGEN_USER_DIR', cd);
0069    end
0070 
0071    if eidors_debug('query','call_netgen')
0072       sys_cmd = sprintf('"%s" %s  -geofile=%s  -meshfile=%s ', ...
0073          ng_name, finelevel,geo_file,vol_file);
0074    else
0075       sys_cmd = sprintf('"%s" %s -batchmode -geofile=%s  -meshfile=%s ', ...
0076          ng_name, finelevel,geo_file,vol_file);
0077    end
0078    status= system_cmd( sys_cmd );
0079 
0080    if status==0; break; end
0081    try
0082       if islinux
0083          global eidors_objects;
0084          ignore_errors = 0;
0085          if isfield(eidors_objects,'ng_ignore_errors');
0086             ignore_errors = eidors_objects.ng_ignore_errors;
0087          end
0088          fprintf(['It seems that netgen has not worked (on linux). ' ...
0089             'Check that netgen is installed and on the path. ' ...
0090             'Check the environment variable NETGENDIR is set. ' ...
0091             ' This can be set via the following commands:\n' ...
0092             '  setenv(''NETGENDIR'',''/path/to/netgen/bin'');\n' ...
0093             '  setenv(''PATH'',[''/path/to/netgen/bin:'',getenv(''PATH'')]);\n' ...
0094             'Please enter a new netgen file name\n' ]);
0095          if ignore_errors == 1;
0096             eidors_msg('Ignoring Netgen Error (as requested)',1);
0097             break;
0098          end
0099          ng_name = input( ...
0100            'netgen file name (with path)? [or i=ignore, e=error, a=always ignore]','s');
0101          if strcmp(ng_name,'i'); break;end
0102          if strcmp(ng_name,'a');
0103              eidors_objects.ng_ignore_errors = 1;
0104              break;
0105          end
0106          if strcmp(ng_name,'e'); error('user requested'),end;
0107       else
0108          fprintf([ ...
0109             'Netgen call failed. Is netgen installed and on the search path?\n' ...
0110             'If you are running under windows, I can attempt to create\n' ...
0111             'a batch file to access netgen.\n' ...
0112             'Please enter the directory in which to find netgen.exe.\n' ...
0113             'A typical path is "C:\\Program Files (x86)\\Netgen-5.0_x64\\bin"\n' ...
0114             'If you don''t have a copy, download it from' ...
0115             'http://sourceforge.net/projects/netgen-mesher/ \n\n']);
0116          netgen_path = input('netgen_path? [or i=ignore, e=error] ','s');
0117          if strcmp(ng_name,'i'); break;end
0118          if strcmp(ng_name,'e'); error('user requested'),end;
0119          if exist( sprintf('%s/netgen.exe',netgen_path) , 'file' ) || ...
0120                exist( sprintf('%s/bin/netgen.exe',netgen_path) , 'file' )
0121             disp('Found netgen version 4.4 or higher');
0122             netgen_exe = netgen_path;
0123             if exist( sprintf('%s/bin/netgen.exe',netgen_path) , 'file' )
0124                netgen_exe = [netgen_path '/bin'];
0125             end
0126             
0127             
0128             fid= fopen([cache_path, '/ng.bat'],'w');
0129             if fid<0; error('Unable to write to %s',cache_path); end
0130             fprintf(fid,'set TCL_LIBRARY=%s/lib/tcl8.3\n', netgen_path); % REQ for ng <= 4.4
0131             fprintf(fid,'set TIX_LIBRARY=%s/lib/tix8.1\n', netgen_path); % REQ for ng <= 4.4
0132             fprintf(fid,'set NETGENDIR=%s\n', netgen_path); % REQ for ng >= 4.9
0133             fprintf(fid,'"%s/netgen.exe" %%*\n', netgen_exe);
0134             fclose(fid);
0135          elseif exist( sprintf('%s/ng431.exe',netgen_path) , 'file' )
0136             disp('Found netgen version 4.3.1');
0137             fid= fopen([cache_path, '/ng.bat'],'w');
0138             if fid<0; error('Unable to write to %s',cache_path); end
0139             fprintf(fid,'set TCL_LIBRARY=%s/lib/tcl8.3\n', netgen_path);
0140             fprintf(fid,'set TIX_LIBRARY=%s/lib/tcl8.2\n', netgen_path);
0141             fprintf(fid,'"%s/ng431.exe" %%*\n', netgen_path);
0142             fclose(fid);
0143          else
0144             warning(['cannot find a version of netgen that I know about\n' ...
0145                'Install netgen or check the path\n']);
0146          end
0147       end
0148    catch e
0149       if strncmp(computer,'PC',2)
0150          % restore Netgen settings on Windows
0151          setenv('NETGEN_USER_DIR', oldpath);
0152       end
0153       rethrow(e)
0154    end
0155 end

Generated on Wed 21-Jun-2017 09:29:07 by m2html © 2005