ArticleslgStudy

computer science

Pencil Code

Pencil Code is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Pencil Code rather than just read about it. In short: The Pencil Code is a high-order finite-difference code for solving partial differential equations, written in Fortran 95. The code is designed for efficient computation with massive parallelization.

Key takeaways

  • Pencil Code belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Pencil Code to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Pencil Code from memory before moving on to harder problems.

Reference excerpt

The Pencil Code is a high-order finite-difference code for solving partial differential equations, written in Fortran 95. The code is designed for efficient computation with massive parallelization. Due to its modular structure, it can be used for a large variety of physical setups like hydro- and magnetohydrodynamics relevant for, e.g., astrophysics, geophysics, cosmology, turbulence, and combustion. Many such setups are available as ready-to-run samples. Pencil Code is free software released under the GNU GPL v2.

Methods The computational scheme is finite-difference and non-conservative; the time integration is implemented by an explicit scheme. Due to the usage of the vector potential, the magnetic field is intrinsically divergence free. High-order (4th, 6th, and 10th order, as well as single-sided or upwind) derivatives are available to resolve strong variations on the grid scale. With a set of automated tests, the functionality of the code is validated on a daily basis. MPI is used for parallelization, but the code can also be run non-parallel on a simple PC. There are modules for different time-integration schemes (e.g. three-step Runge–Kutta), treatment of shocks, embedded particle dynamics, chemistry, massive parallel I/O, etc.

Applications The Pencil Code has mainly been applied to describe compressible turbulence and resistive magnetohydrodynamics. Applications include studies of planet formation, the solar dynamo, mono-chromatic radiative transfer, the coronal heating problem, debris disks, turbulent combustion of solid fuels, and others.

History The Pencil Code development was started in 2001 by Axel Brandenburg and Wolfgang Dobler during the 'Helmholtz Summer School' at the Helmholtz Research Centre for Geosciences in Potsdam. It was initially used for MHD turbulence simulations. The development was continued by a team of about ten code owners and around 90 additional developers who extended the code for their scientific research. It is used by additional users from various branches of science. The code repository was hosted at NORDITA until 2008 and was then moved to Google Developers. In April 2015 the code was migrated to GitHub. Since June 2018 the Pencil Code supports the HDF5 data format. Since 2025 the Pencil Code has been accelerated to run on GPUs .

References

External links Official website with SVN and GIT repository GitHub page with issue tracker

Worked examples

Example 1 — a first encounter with Pencil Code

Start with the simplest possible case. Write down what Pencil Code claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Pencil Code before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Pencil Code ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Pencil Code

In research
Pencil Code appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Pencil Code in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Pencil Code is common in secondary-school and first-year university syllabi. It links to neighbouring topics Computational fluid dynamics, Free astronomy software, Magnetohydrodynamics, so understanding it makes those chapters shorter.
In everyday life
Look for Pencil Code outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Pencil Code in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Pencil Code means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Pencil Code out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Pencil Code in simple terms?

The Pencil Code is a high-order finite-difference code for solving partial differential equations, written in Fortran 95. The code is designed for efficient computation with massive parallelization.

Why does Pencil Code matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Pencil Code?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Pencil Code.

Tags

  • Computational fluid dynamics
  • Free astronomy software
  • Magnetohydrodynamics
  • Parallel computing
  • Simulation software
  • Software programmed in Fortran

Keep exploring