Skip to content
This repository has been archived by the owner on Mar 1, 2023. It is now read-only.

apply JuliaFormatter.jl #536

Merged
merged 3 commits into from
May 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions .dev/format.jl

This file was deleted.

2 changes: 1 addition & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ A clear and concise description of the code with usage.
I have

- [ ] Written and run all necessary tests with CLIMA by including `tests/runtests.jl`
- [ ] Followed all necessary [style guidelines](https://CliMA.github.io/CLIMA/latest/CodingConventions.html) and run `julia .dev/format.jl`
- [ ] Followed all necessary [style guidelines](https://CliMA.github.io/CLIMA/latest/CodingConventions.html) and run `julia .dev/climaformat.jl .`
- [ ] Updated the documentation to reflect changes from this PR.

<!--- Please leave the following section --->
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/JuliaFormatter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
version: 1.3
- name: Apply JuliaFormatter
run: |
julia --project=.dev .dev/format.jl origin/master
julia --project=.dev .dev/climaformat.jl .
- name: Check formatting diff
run: |
git diff --color=always --exit-code
7 changes: 0 additions & 7 deletions docs/src/HowToGuides/Contributing/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,6 @@ For the most part, we follow the [YASGuide](https://github.com/jrevels/YASGuide)

In addition to this, once you are happy with your PR, please apply [JuliaFormatter.jl](https://github.com/domluna/JuliaFormatter.jl) to all changed files in the repository.

To apply our formatter settings to all changed files, run:
```
julia .dev/format.jl
```

Formatting changes should be done as a separate commit, ideally the last commit of the pull request (you may want to leave it until all other changes have been approved).

### Formatting utility

A convenience utility is located at `.dev/climaformat.jl` that will format the julia files in the given path. For example, from the top-level ClimateMachine directory
Expand Down
163 changes: 101 additions & 62 deletions src/InputOutput/VTK/writemesh.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,85 +3,124 @@ using WriteVTK
#=
This is the 1D WriteMesh routine
=#
function writemesh(base_name, x1; fields=(), realelems=1:size(x1)[end])
(Nqr, _) = size(x1)
Nsubcells = (Nqr-1)
function writemesh(base_name, x1; fields = (), realelems = 1:size(x1)[end])
(Nqr, _) = size(x1)
Nsubcells = (Nqr - 1)

cells = Array{MeshCell{Array{Int,1}}, 1}(undef, Nsubcells * length(realelems))
for e ∈ realelems
offset = (e-1) * Nqr
for i = 1:Nqr-1
cells[i + (e-1)*Nsubcells] =
MeshCell(VTKCellTypes.VTK_LINE, offset .+ [i, i+1])
cells =
Array{MeshCell{Array{Int, 1}}, 1}(undef, Nsubcells * length(realelems))
for e in realelems
offset = (e - 1) * Nqr
for i in 1:(Nqr - 1)
cells[i + (e - 1) * Nsubcells] =
MeshCell(VTKCellTypes.VTK_LINE, offset .+ [i, i + 1])
end
end
end

vtkfile = vtk_grid("$(base_name)", @view(x1[:]), cells; compress=false)
for (name, v) fields
vtk_point_data(vtkfile, v, name)
end
outfiles = vtk_save(vtkfile)
vtkfile = vtk_grid("$(base_name)", @view(x1[:]), cells; compress = false)
for (name, v) in fields
vtk_point_data(vtkfile, v, name)
end
outfiles = vtk_save(vtkfile)
end

#=
This is the 2D WriteMesh routine
=#
function writemesh(base_name, x1, x2; x3=nothing, fields=(), realelems=1:size(x1)[end])
@assert size(x1) == size(x2)
(Nqr, Nqs, _) = size(x1)
Nsubcells = (Nqr-1) * (Nqs-1)
function writemesh(
base_name,
x1,
x2;
x3 = nothing,
fields = (),
realelems = 1:size(x1)[end],
)
@assert size(x1) == size(x2)
(Nqr, Nqs, _) = size(x1)
Nsubcells = (Nqr - 1) * (Nqs - 1)

cells = Array{MeshCell{Array{Int,1}}, 1}(undef, Nsubcells * length(realelems))
ind = LinearIndices((1:Nqr, 1:Nqs))
for e ∈ realelems
offset = (e-1) * Nqr * Nqs
for j = 1:Nqs-1
for i = 1:Nqr-1
cells[i + (j-1)*(Nqr-1) + (e-1)*Nsubcells] =
MeshCell(VTKCellTypes.VTK_PIXEL, offset .+ ind[i:i+1,j:j+1][:])
end
cells =
Array{MeshCell{Array{Int, 1}}, 1}(undef, Nsubcells * length(realelems))
ind = LinearIndices((1:Nqr, 1:Nqs))
for e in realelems
offset = (e - 1) * Nqr * Nqs
for j in 1:(Nqs - 1)
for i in 1:(Nqr - 1)
cells[i + (j - 1) * (Nqr - 1) + (e - 1) * Nsubcells] = MeshCell(
VTKCellTypes.VTK_PIXEL,
offset .+ ind[i:(i + 1), j:(j + 1)][:],
)
end
end
end
end

if x3 == nothing
vtkfile = vtk_grid("$(base_name)", @view(x1[:]), @view(x2[:]), cells;
compress=false)
else
vtkfile = vtk_grid("$(base_name)", @view(x1[:]), @view(x2[:]), @view(x3[:]),
cells; compress=false)
end
for (name, v) ∈ fields
vtk_point_data(vtkfile, v, name)
end
outfiles = vtk_save(vtkfile)
if x3 == nothing
vtkfile = vtk_grid(
"$(base_name)",
@view(x1[:]),
@view(x2[:]),
cells;
compress = false,
)
else
vtkfile = vtk_grid(
"$(base_name)",
@view(x1[:]),
@view(x2[:]),
@view(x3[:]),
cells;
compress = false,
)
end
for (name, v) in fields
vtk_point_data(vtkfile, v, name)
end
outfiles = vtk_save(vtkfile)
end

#=
This is the 3D WriteMesh routine
=#
function writemesh(base_name, x1, x2, x3; fields=(), realelems=1:size(x1)[end])
(Nqr, Nqs, Nqt, _) = size(x1)
(Nr, Ns, Nt) = (Nqr-1, Nqs-1, Nqt-1)
Nsubcells = Nr * Ns * Nt
cells = Array{MeshCell{Array{Int,1}}, 1}(undef, Nsubcells * length(realelems))
ind = LinearIndices((1:Nqr, 1:Nqs, 1:Nqt))
for e ∈ realelems
offset = (e-1) * Nqr * Nqs * Nqt
for k = 1:Nt
for j = 1:Ns
for i = 1:Nr
cells[i + (j-1) * Nr + (k-1) * Nr * Ns + (e-1) * Nsubcells] =
MeshCell(VTKCellTypes.VTK_VOXEL,
offset .+ ind[i:i+1, j:j+1, k:k+1][:])
function writemesh(
base_name,
x1,
x2,
x3;
fields = (),
realelems = 1:size(x1)[end],
)
(Nqr, Nqs, Nqt, _) = size(x1)
(Nr, Ns, Nt) = (Nqr - 1, Nqs - 1, Nqt - 1)
Nsubcells = Nr * Ns * Nt
cells =
Array{MeshCell{Array{Int, 1}}, 1}(undef, Nsubcells * length(realelems))
ind = LinearIndices((1:Nqr, 1:Nqs, 1:Nqt))
for e in realelems
offset = (e - 1) * Nqr * Nqs * Nqt
for k in 1:Nt
for j in 1:Ns
for i in 1:Nr
cells[i + (j - 1) * Nr + (k - 1) * Nr * Ns + (e - 1) *
Nsubcells] =
MeshCell(
VTKCellTypes.VTK_VOXEL,
offset .+ ind[i:(i + 1), j:(j + 1), k:(k + 1)][:],
)
end
end
end
end
end
end

vtkfile = vtk_grid("$(base_name)", @view(x1[:]), @view(x2[:]), @view(x3[:]),
cells; compress=false)
for (name, v) ∈ fields
vtk_point_data(vtkfile, v, name)
end
outfiles = vtk_save(vtkfile)
vtkfile = vtk_grid(
"$(base_name)",
@view(x1[:]),
@view(x2[:]),
@view(x3[:]),
cells;
compress = false,
)
for (name, v) in fields
vtk_point_data(vtkfile, v, name)
end
outfiles = vtk_save(vtkfile)
end
Loading