1 function params=femwind_main(params)
3 % params=femwind_main output params structure and exit
4 % femwind_test(params) run with params specified and copy to output
7 % DO NOT EDIT THIS FILE to set params or add outputs.
8 % Instead, call the function to get the params, add or delete any fields you need, and call it again.
9 % Debugging outputs can be added to the params structure as additional field.
11 % *** all_test must pass fter any edits and before any merge ***
16 if ~exist('params','var') | isempty(params)
17 params = params_defaults
21 if params.save_files >= 0
22 diary(['femwind_',params.save_file_prefix,'_diary.txt'])
27 if isfield(params,'mesh_top')
29 disp('given params.mesh_top>0, computing params.expand')
30 nz = params.nelem3(3); % elements in the vertical direction
31 a = params.mesh_top/params.h(3); % desired height as multiple of first layer
32 params.expand = findq(a,nz);
40 for sc2 = params.sc2_all
41 for sc = params.sc_all
44 disp('setting up test case')
46 nel = sc*params.nelem3; % elements in the 3 directions
49 fprintf('mesh of %ix%ix%i cells\n',nel(1),nel(2),nel(3))
50 params.id=sprintf('%ix%ix%i',nel); % to pass around
51 string_diag_A=sprintf('%g %g %g',params.a); % for figure titles
52 A = diag(params.a.^2);
56 X = regular_mesh(nel,h,params.expand^(1/sc));
57 X = add_terrain_to_mesh(X,...
58 params.terrain_shape,params.terrain_top,params.terrain_height);
59 [CX,CH] = center_mesh(X); % get midpoints of elements
61 % initial wind at the centers of the elements
63 switch params.initial_wind
65 disp('initial wind uniform in x direction')
66 U0={ones(nel),zeros(nel),zeros(nel)};
68 % to test iterative methods with non-smooth initial error
69 disp('initial wind uniform in x direction random in z direction')
70 U0={ones(nel),zeros(nel),randn(nel)};
72 % to test iterative methods with non-smooth initial error
73 disp('initial wind uniform in x direction and z direction')
74 U0={ones(nel),zeros(nel),ones(nel)};
76 disp('initial wind log profile in x direction')
77 U0={log(max(1,CH/params.roughness_height)),zeros(nel),zeros(nel)};
79 error(['unknown initial wind ',params.initial_wind])
82 disp('graphics: problem setup')
87 title('The wind mesh, wind vector in centers, lambda in corners')
93 plot_mesh_3d(X,[1,nel(1)+1,1,nel(2)+1,1,1]), hold on,
103 plot_mesh_3d(X,[1,nel(1),1,nel(2)+1,1,1]), hold on,
104 plot_wind_3d(CX,U0,1)
107 title('Initial wind lowest layer')
110 % Plot initial streamlines
111 if params.graphics > 2
113 plot_mesh_3d(X,[1,nel(1)+1,1,nel(2)+1,2,2])
115 wind_streamlines(X, CX, U0, params);
121 if params.run_fortran && params.run_matlab
122 [W,rate(sc,sc2)]=femwind_fortran(A,X,U0,params);
123 [Wm,rate(sc,sc2)]=femwind_solve(A,X,U0,params);
124 for i=1:3, err_compare(i)=big(W{i}-Wm{i})/big(W{i});end
125 err=max(err_compare);
126 fprintf('relative max error matlab vs fortran %g\n',err)
128 warning('error too large')
130 elseif params.run_fortran
131 [W,rate(sc,sc2)]=femwind_fortran(A,X,U0,params);
133 [W,rate(sc,sc2)]=femwind_solve(A,X,U0,params);
137 disp('graphics: solution')
139 % plot resulting wind
140 figure(5),crate(sc,sc2)
141 plot_mesh_3d(X,[1,nel(1)+1,1,nel(2)+1,1,1]), hold on,
145 title(['Final wind a=',string_diag_A])
148 plot_mesh_3d(X,[1,nel(1)+1,1,nel(2)+1,1,1]), hold on,
152 title(['Final wind lowest layer a=',string_diag_A])
155 plot_mesh_3d(X,[1,nel(1)+1,1,nel(2)+1,1,1]), hold on,
156 plot_wind_3d(CX,W,1:2)
159 title(['Final wind lowest layers a=',string_diag_A])
164 disp('graphics: wind_at_h')
168 bbox=[min(X{1}(:)),max(X{1}(:)),...
169 min(X{2}(:)),max(X{2}(:)),...
171 [XH,WH]=wind_at_h(X,CX,W,[20,20,1],bbox);
174 plot_mesh_3d(X,[1,nel(1)+1,1,nel(2)+1,1,1])
177 title(['Final wind with a=',string_diag_A,' at ',num2str(height),' above terrain'])
179 if params.graphics > 2
181 plot_mesh_3d(X,[1,nel(1)+1,1,nel(2)+1,2,2])
183 wind_streamlines(X, CX, W, params)
187 if params.save_files>1,
188 sfile=[params.save_file_prefix,'_workspace.mat'];
189 disp(['saving workspace to ',sfile])
192 if params.save_files>0,
193 sfile=[params.save_file_prefix,'_params.mat'];
194 disp(['saving params to ',sfile])
195 save(sfile,'params','-v7.3')