# Advantages of Basilisk Over Vanilla C for Computational Fluid Dynamics
After examining the implementation of heat conduction problems in both vanilla C and Basilisk, several significant advantages of using Basilisk become apparent. This document outlines these benefits to help new users understand why Basilisk is a powerful tool for computational fluid dynamics (CFD) simulations.
## 1. Simplified Domain and Grid Management
Vanilla C:
- Requires manual definition of grid points, cell spacings, and domain extents
- Needs explicit calculation of physical coordinates for each point
- Requires manual array allocation and deallocation
Basilisk:
- Simple declaration of domain parameters (`L0`, `X0`, `N`)
- Automatic grid generation and management
- No need for explicit memory allocation/deallocation for grid points
## 2. Declarative Boundary Conditions
Vanilla C:
- Requires explicit functions to apply boundary conditions
- Boundary conditions must be repeatedly applied during solution
- Error-prone due to manual indexing
Basilisk:
- Declarative boundary conditions using a simple, intuitive syntax:
```c
T[left] = dirichlet(0.0);
T[right] = dirichlet(1.0);
```
- Applied automatically during computation
## 3. Event-Based Programming Model
Vanilla C:
- Procedural, sequential code execution
- Complex control flow for time-stepping, initialization, and output
- Difficult to separate logical components
Basilisk:
- Event-based programming model that separates concerns:
- `event init` for initialization
- `event integration/marching` for time stepping
- `event end` for final output
- Events can be scheduled to occur at specific times or intervals
- Cleaner, more modular code structure
## 4. Automatic Time Step Management
Vanilla C:
- Manual implementation of time step calculations
- Explicit checks to ensure numerical stability (CFL condition)
- Manual logic to hit specific output times exactly
Basilisk:
- Automatic time step management with `dtnext(DT)`
- Built-in tools for maintaining numerical stability
- Events can be scheduled at specific times with `t += tsnap`
## 5. Stencil Operations and Spatial Discretization
Vanilla C:
- Explicit array indexing for neighbor access
- Manual implementation of finite difference/volume stencils
- Error-prone due to index arithmetic
Basilisk:
- Intuitive stencil notation: `T[1]`, `T[-1]` for neighbors
- `foreach()` iterator for grid traversal without manual indexing
- Automatic handling of boundary conditions during stencil operations
## 6. Reduced Boilerplate Code
Vanilla C:
- Lengthy implementations even for simple problems
- Requires explicit implementations of utility functions
- Verbose memory management
Basilisk:
- Significantly shorter code for equivalent functionality
- Built-in functions for common operations
- Less cognitive load due to reduced complexity
## 7. Scalar Field Declaration and Management
Vanilla C:
- Manual array allocation for each field
- Explicit memory management to prevent leaks
- No standard methods for field operations
Basilisk:
- Simple scalar field declaration: `scalar T[]`
- Automatic memory management
- Built-in methods for field operations
## 8. Flux Computation and Conservative Formulation
Vanilla C:
- Manual flux computation at interfaces
- Error-prone implementation of conservation laws
- Complex indexing for interface values
Basilisk:
- Simplified flux computation with stencil notation
- Natural expression of conservation laws
- Automatic handling of flux boundary conditions
## 9. Extensibility and Library Integration
Vanilla C:
- Limited reusability of code components
- Need to reimplement common algorithms
- Difficult to extend to more complex problems
Basilisk:
- Modular design allows easy extension
- Rich library of pre-implemented physics modules
- Natural pathway to more complex simulations
## Conclusion
The Basilisk computational environment provides significant advantages over vanilla C for fluid dynamics simulations. By abstracting away the implementation details of grid management, boundary conditions, and numerical methods, Basilisk allows researchers and engineers to focus on the physics of their problems rather than the computational details. This leads to more readable, maintainable, and correct code with significantly less development effort.
The comparison of the heat conduction examples shows that equivalent problems can be solved with much less code in Basilisk, while simultaneously providing a more intuitive and robust framework for extending to more complex physical phenomena.