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

The great formatting event #155

Merged
merged 2 commits into from
Jan 22, 2025
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
105 changes: 105 additions & 0 deletions .github/workflows/Format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
name: 'Format'

on:
pull_request_target:
paths: ['**/*.jl']
types: [opened, synchronize, reopened, ready_for_review]

permissions:
contents: read
actions: write
pull-requests: write

jobs:
runic:
runs-on: ubuntu-latest
if: github.event.pull_request.draft == false
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
ref: ${{github.event.pull_request.head.ref}}
repository: ${{github.event.pull_request.head.repo.full_name}}
fetch-depth: 0

- name: Add upstream remote
run: |
git remote add upstream https://github.com/${{ github.repository }}
git fetch upstream

- name: Setup Julia
uses: julia-actions/setup-julia@v2
with:
version: '1'
arch: 'x64'
- uses: julia-actions/cache@v2

- name: Install Runic
run: |
julia --project=@runic -e 'using Pkg; Pkg.add("Runic")'
curl -o git-runic https://raw.githubusercontent.com/fredrikekre/Runic.jl/master/bin/git-runic
chmod +x git-runic
sudo mv git-runic /usr/local/bin

- name: Run Runic
id: runic
run: |
set +e
MERGE_BASE=$(git merge-base upstream/${{ github.base_ref }} HEAD) || exit 1
DIFF=$(git runic --diff $MERGE_BASE)
EXIT_CODE=$?

echo "exit_code=$EXIT_CODE" >> $GITHUB_OUTPUT
echo "diff<<EOF" >> $GITHUB_OUTPUT
echo "$DIFF" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT

# if Runic failed, bail out
[ $EXIT_CODE -eq 2 ] && exit 1 || exit 0

- name: Find comment
uses: peter-evans/find-comment@v3
id: find-comment
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: '<!-- runic-format-summary -->'

- name: Comment formatting suggestions
if: steps.runic.outputs.exit_code == 1
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.find-comment.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
<!-- runic-format-summary -->

Your PR requires formatting changes to meet the project's style guidelines.
Please consider running [Runic](https://github.com/fredrikekre/Runic.jl) (`git runic ${{ github.base_ref }}`) to apply these changes.

<details>
<summary>Click here to view the suggested changes.</summary>

```diff
${{ steps.runic.outputs.diff }}
```

</details>
edit-mode: replace

- name: Update stale comment
if: steps.runic.outputs.exit_code == 0 && steps.find-comment.outputs.comment-id
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.find-comment.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
<!-- runic-format-summary -->

Your PR no longer requires formatting changes. Thank you for your contribution!
edit-mode: replace

# XXX: if Github ever supports allow-failure (actions/runner#2347)
#- name: Propagate exit code
# run: |
# exit ${{ steps.runic.outputs.exit_code }}
1 change: 1 addition & 0 deletions .typos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Shepard = "Shepard"
arange = "arange"
iy = "iy"
nin = "nin"
tect = "tect"

[files]
extend-exclude = ["tutorials/*.pvsm","docs/paper/paper.bib"]
70 changes: 37 additions & 33 deletions ext/Chmy_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,39 +15,39 @@ println("Loading Chmy-GMG tools")

Creates a GMG `CartGrid` data structure from a `Chmy` grid object
"""
function create_CartGrid(grid::StructuredGrid; ylevel=0.0)
function create_CartGrid(grid::StructuredGrid; ylevel = 0.0)

coord1D = Vector.(coords(grid, Vertex()))
coord1D = Vector.(coords(grid, Vertex()))
coord1D_cen = Vector.(coords(grid, Center()))
N = length.(coord1D)
L = extent(grid, Vertex())
X₁ = origin(grid, Vertex())
Δ = spacing(grid)
ConstantΔ = false;
N = length.(coord1D)
L = extent(grid, Vertex())
X₁ = origin(grid, Vertex())
Δ = spacing(grid)
ConstantΔ = false
if isa(grid, UniformGrid)
ConstantΔ = true
end
if ndims(grid)==2
if ndims(grid) == 2
# we need a special treatment of this, as all GMG routines work with 3D coordinates
X₁ = (X₁[1], ylevel, X₁[2])
L = (L[1], 0.0, L[2])
Δ = (Δ[1], 0.0, Δ[2])
N = (N[1],1,N[2])
X₁ = (X₁[1], ylevel, X₁[2])
L = (L[1], 0.0, L[2])
Δ = (Δ[1], 0.0, Δ[2])
N = (N[1], 1, N[2])
coord1D = (coord1D[1], [0.0], coord1D[2])
coord1D_cen = (coord1D_cen[1], [0.0], coord1D_cen[2])
end
Xₙ = X₁ .+ L

Xₙ = X₁ .+ L

return CartGrid(ConstantΔ,N,Δ,L,X₁,Xₙ,coord1D, coord1D_cen)

return CartGrid(ConstantΔ, N, Δ, L, X₁, Xₙ, coord1D, coord1D_cen)
end

# all functions to be ported
function_names = (:add_box!, :add_sphere!, :add_ellipsoid!, :add_cylinder!, :add_layer!, :add_polygon!, :add_slab!, :add_stripes!, :add_volcano!)

for fn in function_names

@eval begin
@eval begin
"""
$($fn)( Phase::Field,
Temp::Field,
Expand All @@ -56,22 +56,24 @@ for fn in function_names

Sets `$($fn)` function for `Chmy` fields and grids.
"""
function $fn( Phase::Field,
Temp::Field,
Grid::StructuredGrid; # required input
kwargs...)
function $fn(
Phase::Field,
Temp::Field,
Grid::StructuredGrid; # required input
kwargs...
)

CartGrid = create_CartGrid(Grid)

cell = false
if all(location(Phase).==Center())
if all(location(Phase) .== Center())
cell = true
end
return ($fn)(Phase, Temp, CartGrid; cell=cell, kwargs...)

return ($fn)(Phase, Temp, CartGrid; cell = cell, kwargs...)
end
end

end


Expand All @@ -80,28 +82,30 @@ function_names = (:above_surface, :below_surface)

for fn in function_names

@eval begin
@eval begin
"""
$($fn)( Grid::StructuredGrid, field::Field, DataSurface_Cart::CartData; kwargs...)

Sets `$($fn)` function for `Chmy` grids and the field `field` which can be either on vertices or centers
"""
function $fn( Grid::StructuredGrid,
field::Field,
DataSurface_Cart::CartData;
kwargs...)
function $fn(
Grid::StructuredGrid,
field::Field,
DataSurface_Cart::CartData;
kwargs...
)

CartGrid = create_CartGrid(Grid)

cell = false
if all(location(field).==Center())
if all(location(field) .== Center())
cell = true
end

return ($fn)(CartGrid, DataSurface_Cart; cell=cell, kwargs...)
return ($fn)(CartGrid, DataSurface_Cart; cell = cell, kwargs...)
end
end

end


Expand Down
Loading
Loading