Add New Source
This skill creates new source files following FLEKS conventions.
File Locations
| File Type | Directory |
|---|---|
Headers (.h) | include/ |
Implementation (.cpp) | src/ |
| Interface code | srcInterface/ |
Naming Conventions
- •File names:
PascalCase(e.g.,NewFeature.cpp,NewFeature.h) - •Class names:
PascalCase(e.g.,class NewFeature) - •Function names:
snake_case(e.g.,void do_something()) - •Variable names:
camelCase(e.g.,int myVariable)
Header File Template
Create include/NewFeature.h:
cpp
#ifndef _NEWFEATURE_H_
#define _NEWFEATURE_H_
// Standard headers
#include <memory>
#include <vector>
// AMReX headers
#include <AMReX.H>
// User headers
#include "Utility.h"
class NewFeature {
public:
NewFeature() = default;
~NewFeature() = default;
// Public methods
void initialize();
void do_something();
// Getters (use const)
int get_value() const { return value_; }
private:
// Member variables (trailing underscore)
int value_ = 0;
};
#endif // _NEWFEATURE_H_
Implementation File Template
Create src/NewFeature.cpp:
cpp
#include "NewFeature.h"
// Standard headers
#include <iostream>
// AMReX headers (can use 'using namespace amrex' in .cpp only)
using namespace amrex;
void NewFeature::initialize() {
// Implementation
}
void NewFeature::do_something() {
// Implementation
}
Steps to Add a New File
1. Create Header File
bash
touch include/NewFeature.h
Add the header template with proper include guards.
2. Create Implementation File
bash
touch src/NewFeature.cpp
Add the implementation template.
3. Update Makefile Dependencies
The Makefile.DEPEND files are auto-generated, but ensure your .cpp file is in src/.
4. Rebuild and Verify
bash
make FLEKS -j8
5. Regenerate compile_commands.json
This happens automatically with the build, but you can force it:
bash
make compile_commands
Header Order Standard
Always order includes as:
cpp
// 1. Standard library headers #include <algorithm> #include <memory> #include <vector> // 2. AMReX headers #include <AMReX.H> #include <AMReX_MultiFab.H> // 3. Project headers #include "Grid.h" #include "Utility.h"
Key Reminders
- •Use
nullptrinstead ofNULL - •Use smart pointers (
unique_ptr,shared_ptr) for ownership - •Use
constwherever possible - •No
using namespacein header files - •Follow 80-column limit (enforced by
.clang-format)
Integrating with Existing Classes
If your new class needs to work with existing code:
- •Check if there's a base class or interface to inherit from
- •Look at similar classes for patterns (e.g.,
Grid.h,Domain.h) - •Common base classes:
- •
FluidInterface- for fluid coupling - •
SourceInterface- for source terms
- •
Verification Checklist
- • Header has include guards
- • File names follow
PascalCase - • Class name matches file name
- • Header order is correct (std → AMReX → user)
- • No
using namespacein header - •
constused where applicable - • Smart pointers for ownership
- • Code compiles without warnings
- •
compile_commands.jsonupdated