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 = (deprecated) Meshsize file in netgen format

 Finelevel controls the fineness of the mesh
   default is '' -> coarse
   valid values are 'fine' or 'veryfine'
 
 Finelevel can also be set using eidors_default
   eidors_default call_netgen_finelevel 'fine'

 To debug the shapes and view the netgen interface, use
   eidors_debug on call_netgen

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 = (deprecated) 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 % Finelevel can also be set using eidors_default
0015 %   eidors_default call_netgen_finelevel 'fine'
0016 %
0017 % To debug the shapes and view the netgen interface, use
0018 %   eidors_debug on call_netgen
0019 
0020 % $Id: call_netgen.m 6092 2021-03-06 16:54:41Z aadler $
0021 % (C) 2006 Andy Adler. Licensed under GPL V2
0022 
0023 if nargin<3
0024    msz_file= '';
0025 end
0026 
0027 if ~isempty(msz_file)
0028    eidors_msg('call_netgen: Warning. Using an *.msz file. netgen rarely uses this file without care. Use the MSZPOINTS option in ng_write_opt instead.');
0029 end
0030 
0031 if nargin<4
0032    %  finelevel= '-veryfine';
0033    %  finelevel= '-fine';
0034    finelevel= eidors_default('get','call_netgen_finelevel');
0035 end
0036 
0037 islinux = isunix;
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 if ~isempty(msz_file)
0048     warning('EIDORS:Deprecated', 'Use ng_write_opt instead of specifying a meshsize file');
0049     warning('Overwriting ng.opt file');
0050     fid= fopen('ng.opt','w'); %create ng.opt file in local dir
0051     if fid==-1
0052         error(['Netgen requires writing files in the current directory(%s). ', ...
0053             'Unfortunately, you don''t have permission. ' ...
0054             'Your options are: 1) change your working directory to one in which you have write permission, or ' ...
0055             '2) change the permissions on the current working directory.'], pwd);
0056     end
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     fclose(fid);
0062 end
0063 
0064 while( 1 )
0065    if ~islinux
0066       % on Linux, Netgen runs in the current directory
0067       % enforce this behaviour in Windows
0068       oldpath = getenv('NETGEN_USER_DIR');
0069       setenv('NETGEN_USER_DIR', cd);
0070    end
0071 
0072    if eidors_debug('query','call_netgen')
0073       sys_cmd = sprintf('"%s" %s  -geofile=%s  -meshfile=%s ', ...
0074          ng_name, finelevel,geo_file,vol_file);
0075    else
0076       sys_cmd = sprintf('"%s" %s -batchmode -geofile="%s"  -meshfile="%s" ', ...
0077          ng_name, finelevel,geo_file,vol_file);
0078    end
0079    status= system_cmd( sys_cmd );
0080 
0081    if status==0; break; end
0082    try
0083       if islinux
0084          global eidors_objects;
0085          ignore_errors = 0;
0086          if isfield(eidors_objects,'ng_ignore_errors');
0087             ignore_errors = eidors_objects.ng_ignore_errors;
0088          end
0089          fprintf(['It seems that netgen has not worked (on linux). ' ...
0090             'Check that netgen is installed and on the path. ' ...
0091             'Check the environment variable NETGENDIR is set. ' ...
0092             ' This can be set via the following commands:\n' ...
0093             '  setenv(''NETGENDIR'',''/path/to/netgen/bin'');\n' ...
0094             '  setenv(''PATH'',[''/path/to/netgen/bin:'',getenv(''PATH'')]);\n' ...
0095             'Please enter a new netgen file name\n' ]);
0096          if ignore_errors == 1;
0097             eidors_msg('Ignoring Netgen Error (as requested)',1);
0098             break;
0099          end
0100          ng_name = input( ...
0101            'netgen file name (with path)? [or i=ignore, e=error, a=always ignore]','s');
0102          if strcmp(ng_name,'i'); break;end
0103          if strcmp(ng_name,'a');
0104              eidors_objects.ng_ignore_errors = 1;
0105              break;
0106          end
0107          if strcmp(ng_name,'e'); error('user requested'),end;
0108       else % Windows
0109          % Check for a version of netgen shipped with eidors
0110          % Fixme if we ship a different version of netgen
0111          netgen_path = [eidors_cache('eidors_path'),'/../Netgen-5.3_x64/bin'];
0112          if exist(netgen_path)
0113             fprintf('Creating batch file to access Netgen.\n')
0114             fid= fopen([cache_path, '/ng.bat'],'w');
0115             if fid<0; error('Unable to write to %s',cache_path); end
0116             fprintf(fid,'set TCL_LIBRARY=%s/lib/tcl8.3\n', netgen_path); % REQ for ng <= 4.4
0117             fprintf(fid,'set TIX_LIBRARY=%s/lib/tix8.1\n', netgen_path); % REQ for ng <= 4.4
0118             fprintf(fid,'set NETGENDIR=%s\n', netgen_path); % REQ for ng >= 4.9
0119             fprintf(fid,'"%s/netgen.exe" %%*\n', netgen_path);
0120             fclose(fid);
0121          else
0122             fprintf([ ...
0123                'Netgen call failed. Is netgen installed and on the search path?\n' ...
0124                'If you are running under windows, I can attempt to create\n' ...
0125                'a batch file to access netgen.\n' ...
0126                'Please enter the directory in which to find netgen.exe.\n' ...
0127                'A typical path is "C:\\Program Files (x86)\\Netgen-5.0_x64\\bin"\n' ...
0128                'If you don''t have a copy, download it from' ...
0129                'http://sourceforge.net/projects/netgen-mesher/ \n\n']);
0130             netgen_path = input('netgen_path? [or i=ignore, e=error] ','s');
0131             if strcmp(ng_name,'i'); break;end
0132             if strcmp(ng_name,'e'); error('user requested'),end;
0133             if exist( sprintf('%s/netgen.exe',netgen_path) , 'file' ) || ...
0134                   exist( sprintf('%s/bin/netgen.exe',netgen_path) , 'file' )
0135                disp('Found netgen version 4.4 or higher');
0136                netgen_exe = netgen_path;
0137                if exist( sprintf('%s/bin/netgen.exe',netgen_path) , 'file' )
0138                   netgen_exe = [netgen_path '/bin'];
0139                end
0140                
0141                fid= fopen([cache_path, '/ng.bat'],'w');
0142                if fid<0; error('Unable to write to %s',cache_path); end
0143                fprintf(fid,'set TCL_LIBRARY=%s/lib/tcl8.3\n', netgen_path); % REQ for ng <= 4.4
0144                fprintf(fid,'set TIX_LIBRARY=%s/lib/tix8.1\n', netgen_path); % REQ for ng <= 4.4
0145                fprintf(fid,'set NETGENDIR=%s\n', netgen_path); % REQ for ng >= 4.9
0146                fprintf(fid,'"%s/netgen.exe" %%*\n', netgen_exe);
0147                fclose(fid);
0148             elseif exist( sprintf('%s/ng431.exe',netgen_path) , 'file' )
0149                disp('Found netgen version 4.3.1');
0150                fid= fopen([cache_path, '/ng.bat'],'w');
0151                if fid<0; error('Unable to write to %s',cache_path); end
0152                fprintf(fid,'set TCL_LIBRARY=%s/lib/tcl8.3\n', netgen_path);
0153                fprintf(fid,'set TIX_LIBRARY=%s/lib/tcl8.2\n', netgen_path);
0154                fprintf(fid,'"%s/ng431.exe" %%*\n', netgen_path);
0155                fclose(fid);
0156             else
0157                warning(['cannot find a version of netgen that I know about\n' ...
0158                   'Install netgen or check the path\n']);
0159             end
0160          end
0161       end
0162    catch e
0163       if strncmp(computer,'PC',2)
0164          % restore Netgen settings on Windows
0165          setenv('NETGEN_USER_DIR', oldpath);
0166       end
0167       rethrow(e)
0168    end
0169 end

Generated on Fri 30-Dec-2022 19:44:54 by m2html © 2005