Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split mesh generation into proper functions #246

Open
SeSodesa opened this issue Aug 16, 2023 · 1 comment
Open

Split mesh generation into proper functions #246

SeSodesa opened this issue Aug 16, 2023 · 1 comment
Labels
enhancement New feature or request invalid This doesn't seem right

Comments

@SeSodesa
Copy link
Collaborator

Description

Currently, the mesh generation routine utilizes Matlab-style scripts, which are simply inserted in the middle of other code when it is being compiled, making it difficult to follow where different variables come from. As an example, we might take a look at the lines 5–31 in zef_create_fem_mesh:

if nargin == 0
zef = evalin('base','zef');
end
zef_segmentation_counter_step;
x_lim = [0 0];
y_lim = [0 0];
z_lim = [0 0];
n_compartments = 0;
for k = 1 : length(reuna_p)
n_compartments = n_compartments + max(1,length(submesh_cell{k}));
if not(isequal(reuna_type{k},-1))
x_lim = [min(x_lim(1),min(reuna_p{k}(:,1))) max(x_lim(2),max(reuna_p{k}(:,1)))];
y_lim = [min(y_lim(1),min(reuna_p{k}(:,2))) max(y_lim(2),max(reuna_p{k}(:,2)))];
z_lim = [min(z_lim(1),min(reuna_p{k}(:,3))) max(z_lim(2),max(reuna_p{k}(:,3)))];
end
end
if isempty(pml_ind_aux)
x_vec = [x_lim(1):mesh_res:x_lim(2)];
y_vec = [y_lim(1):mesh_res:y_lim(2)];
z_vec = [z_lim(1):mesh_res:z_lim(2)];
[X, Y, Z] = meshgrid(x_vec,y_vec,z_vec);
n_cubes = (length(x_vec)-1)*(length(y_vec)-1)*(length(z_vec)-1);
else

Here the problem is that pml_ind_aux is not defined anywhere in this file, and is instead generated in the script zef_segmentation_counter_step, the code of which is inserted place of its invocation on line 9, when the function is being compiled. This is all completely hidden from the user, unless they realize that they should look into the mentioned script.

Expected behavior

It would be much more readable, if scripts were turned into functions, with clear input and output values. This might also make the code more optimizable for the Matlab compiler. Any other scripts than the one mentioned here should also get the same treatment.

Context

Name Value
Version bf185da Add files via upload
OS Any and all
Shell Any and all
@SeSodesa SeSodesa added enhancement New feature or request invalid This doesn't seem right labels Aug 16, 2023
@SeSodesa
Copy link
Collaborator Author

As an additional note, this also facilitates the extraction of one of the core Zeffiro Interface components, the mesh generation routine, into its own module.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request invalid This doesn't seem right
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

1 participant