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

Allow setting iout?d to 0 for no output. #128

Merged
merged 3 commits into from
Nov 20, 2024
Merged

Conversation

soaringxmc
Copy link
Contributor

@soaringxmc soaringxmc commented Nov 18, 2024

This PR disables output when iout[0-3]d, icheck, or isave are set to 0.

Closes #121, #127.

@p-costa p-costa changed the title set iout1d to 0 for no output Allow setting iout?d to 0 for no output. Nov 18, 2024
@p-costa
Copy link
Collaborator

p-costa commented Nov 18, 2024

Excellent, thanks Mao @soaringxmc!

This sounds good, I just want to do some small checks because evaluating mod(istep,0) may break a run, as it is undefined. I'll get back to you soon.

@soaringxmc
Copy link
Contributor Author

Hi, Pedro!
The implementation should be safe, because

When iout0d=0:
First part iout0d > 0 evaluates to FALSE
Due to Fortran's short-circuit evaluation of .and., the second part mod(istep,iout0d) is never evaluated
Therefore, the potential division by zero is avoided

My tests show this does not cause problems.

@p-costa
Copy link
Collaborator

p-costa commented Nov 18, 2024

This program does breaks for me:

  integer :: a,i
  a = 0
  i = 10
  if (a > 0.and.mod(i,a) == 0) then
    print *, '1'
  else
    print *, '2'
  end if
end

when compiled with gfortran -fcheck=all test.f90 && ./a.out. A solution without resorting to nested ifs could be evaluating mod(istep,max(1,out1d)).

@soaringxmc
Copy link
Contributor Author

You are right! I also think mod(istep,max(1,out1d)) is a good solution.

@p-costa
Copy link
Collaborator

p-costa commented Nov 19, 2024

Sounds good, do you want to update your PR with this change? We should also allow for masking the post-processing of the initial conditions when the simulation starts: https://github.com/CaNS-World/CaNS/blob/main/src/main.f90#L328,L330.

@soaringxmc
Copy link
Contributor Author

Okay. I will update my PR.

@p-costa
Copy link
Collaborator

p-costa commented Nov 19, 2024

Thanks! I see now that I can also push to your fork, so if you'd like, I can also make the changes.

@soaringxmc
Copy link
Contributor Author

Hi, Pedro! I have updated the PR.

@p-costa
Copy link
Collaborator

p-costa commented Nov 20, 2024

Thanks Mao! I pushed some minor changes. I think this PR now also nicely addresses #121 more elegantly.

@p-costa p-costa self-requested a review November 20, 2024 10:58
@p-costa p-costa merged commit 84d26c6 into CaNS-World:main Nov 20, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add SKIP_IO pre-processor maco.
2 participants