AgentSkillsCN

Add New Source

按照 FLEKS 项目约定与编码规范,新建 .cpp/.h 文件。

SKILL.md
--- frontmatter
name: Add New Source
description: Create new .cpp/.h files following FLEKS project conventions and coding standards

Add New Source

This skill creates new source files following FLEKS conventions.

File Locations

File TypeDirectory
Headers (.h)include/
Implementation (.cpp)src/
Interface codesrcInterface/

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

  1. Use nullptr instead of NULL
  2. Use smart pointers (unique_ptr, shared_ptr) for ownership
  3. Use const wherever possible
  4. No using namespace in header files
  5. Follow 80-column limit (enforced by .clang-format)

Integrating with Existing Classes

If your new class needs to work with existing code:

  1. Check if there's a base class or interface to inherit from
  2. Look at similar classes for patterns (e.g., Grid.h, Domain.h)
  3. 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 namespace in header
  • const used where applicable
  • Smart pointers for ownership
  • Code compiles without warnings
  • compile_commands.json updated