Comments (2)
For newcomers to this issue, the idea is as follows:
Say we're using a really simple time stepper to update the velocity of the particles stored in a vector v
. To start out, we could initialize the vector v
as:
v = zeros(Float64, 3, nparticles)
dvdt = rand(3,3)
dt = 0.5
Then the time stepper could be written as:
for i in eachindex(v)
v[1, i] += dvdt[1] #X coordinate of velocity
v[2, i] += dvdt[2] #Y coordinate of velocity
v[3, i] += dvdt[3] #Z coordinate of velocity
end
We could collapse this with another for-loop like
for i in eachindex(v)
for pos in 1:3
v[pos, i] += dvdt[pos] #X coordinate of velocity
end
but in Julia, we can do better. Suppose instead we initialize our array of velocities as precisely that: an array of velocity vectors. Note that we are using SVectors so the compiler will make our tiny loops unroll and be fast.
We would initialize as
using StaticArrays
v = zeros(SVector{3, Float64}, 3, nparticles)
dvdt = SVector{3, Float64}(rand(3))
dt = 0.5
Then we can write our loop as
for i in eachindex(v)
v[i] += dvdt * dt #forward euler step of velocity
end
This works because +
is defined on two vector types and *
is defined between scalar and vector types! Way cool!
from climatemachine.jl.
Right now we are waiting for JuliaGPU/CUDAnative.jl#340 before we can start creating device arrays.
from climatemachine.jl.
Related Issues (20)
- Modify RHS parameter functions
- Missing documentation and errors in SurfaceFluxes.get_flux_coefficients HOT 4
- Implement driver for point jet on sphere
- Implement driver for shallow water setup on the sphere
- Bring triply-period do-nothing box flow driver into master
- Implement driver for dry baroclinic wave in a channel HOT 1
- Perform quality checks on current benchmarks & bring them into QA pipeline
- Single stack diagnostics clobbers some quantities
- Some ocean variables have characters that don't always render
- Slow AtmosModel when using balance-law problems HOT 6
- Inconsistent maxiter values in thermo dispatchers and inner constructors
- Enforce initialization of state.ρ as aux.ref_state.ρ in Anelastic1D model. HOT 3
- Grid imprinting in specific variables (per unit mass) due to filtering, and energy-momentum leakage HOT 2
- Burgers single stack tutorials all show the same figures
- Shear used in EDMF sources from precomputed args becomes negative HOT 7
- fall back on BalanceLaw method for eq_tends HOT 1
- Computation of gradients in a compressible SingleStack HOT 7
- calculation of soil properties
- update language in tutorials
- OrdinaryDiffEq.jl v6 LinearSolve.jl HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from climatemachine.jl.