Skip to content

Conversation

@MelReyCG
Copy link
Contributor

@MelReyCG MelReyCG commented Nov 26, 2025

GEOS Code Rules

Aims at writing down the coding standards for GEOS, focusing on type safety, error handling, parallelism, and performance. Key principles include:

  • Type System
  • Memory Management
  • Error Handling
  • Parallelism
  • Performance
  • Memory / Safety
  • Architecture
  • Testing

These rules ensure code quality, consistency, and maintainability across the GEOS codebase.

@MelReyCG MelReyCG self-assigned this Nov 28, 2025
@MelReyCG MelReyCG changed the title Docs/rey/code rules docs: Code rules Nov 28, 2025
@MelReyCG MelReyCG changed the title docs: Code rules docs: Adding Code rules page Nov 28, 2025
@MelReyCG MelReyCG marked this pull request as ready for review November 28, 2025 09:12
Copy link
Contributor

@jafranc jafranc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great ! Maybe there is the work of 2 docs there (or more 😄 )

Comment on lines 126 to 139
Use GEOS tensor types for geometric and mechanical calculations:

.. list-table:: GEOS Tensor Types
:header-rows: 1
:widths: 30 70

* - Type
- Description
* - ``R1Tensor``
- 3D vector (real64)
* - ``R1Tensor32``
- 3D vector (real32)
* - ``R2SymTensor``
- Symmetric 6-component tensor (Voigt notation)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like we can expand a bit on why tensor are in use and not their vector counter part

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have a suggestion? I have an idea but I think not precise enough.

setApplyDefaultValue( 1.0e-6 ).
setDescription( "Initial time step value. This parameter controls "
"the starting time increment for the simulation. "
"Valid range: (0, 1e-3]. See User Guide Chapter 5." );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For later, should we think of adding an optional setRange to Wrappers ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I totally agree, along with "unit" type. This is the direction I want to promote.

- **Use GoogleTest framework**.
- In GEOS, the goal of unit test is never to take position on the validity of physical results (this is the point of integrated-tests).
- Place tests in ``src/coreComponents/<component>/tests/``.
- Test GPU code paths if applicable (use ``#ifdef GEOS_USE_DEVICE``).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would look nice in the example too

wrappedStats.stats().m_productionRate );

// statistics CSV output (only if enabled and from rank 0)
if( m_writeCSV > 0 && MpiWrapper::commRank() == 0 )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not wrap this in a MACRO and advise to use it ?

Comment on lines +1013 to +1019
Additional Validation Guidelines
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

- Use ``setInputFlag()`` to mark parameters as ``REQUIRED`` or ``OPTIONAL``
- Use ``setApplyDefaultValue()`` to provide sensible defaults
- Use ``setRTTypeName()`` for runtime type validation (e.g., ``rtTypes::CustomTypes::positive``)
- Document valid ranges in ``setDescription()``
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be in the Wrapper section ?

Caliper Integration
^^^^^^^^^^^^^^^^^^^^

Use ``GEOS_MARK_FUNCTION`` and ``Timer`` for performance tracking for the main computation functions / scopes.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and GEOS_CALIPER_MARK_SCOPE() then ?

Comment on lines 1212 to 1239
Provide Views to Arrays
^^^^^^^^^^^^^^^^^^^^^^^^

- When possible, prefer provide views to arrays (to const data if possible).
- This **must** be done especially for RAJA kernels, and views must be **captured by value**.

The rule is generalizable to ``string_view`` for strings, but not applicable in GPU context.

Why Use Views?

- **No memory allocation:** Views are lightweight references
- **Mutability correctness:** Can provide ``const`` read-only access to inner data
- **GPU compatibility:** Views work seamlessly on device

.. dropdown:: Example: Views for arrays
:icon: code

.. code-block:: c++

// BAD - Creates a copy
array1d< real64 > copy = originalArray;

// GOOD - Creates a view (lightweight)
arrayView1d< real64 > view = originalArray.toView();

// GOOD - Const view for read-only access
arrayView1d< real64 const > constView = originalArray.toViewConst();

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be moved above for more visibility ?

@MelReyCG
Copy link
Contributor Author

MelReyCG commented Dec 3, 2025

Thanks @jafranc for your feedback, I'll take them into account.

Use ``GEOS_WARNING*`` macros when:

- An issue is detected but **simulation can continue**
- Simulation may be **affected but not completly invalid**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- Simulation may be **affected but not completly invalid**
- Simulation may be **affected but outcomes remain valid**

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure of what to write here.
Warning in GEOS: We know that there may an issue, but simulation can continue to proceed, and results may be right.


The rule is generalizable to ``string_view`` for strings, but not applicable in GPU context.

Why Use Views?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Why Use Views?
**Rationale:**

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't that less meaningful?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not love "Rationale" but it has been used before in the document. I just put it here again for consistency. Feel free to revert, but then keep it consistent throughout.

**Minimize mutable global states when possible.**
Prefer passing context explicitly.

Why to avoid globals:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Why to avoid globals:
**Rationale:**

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't that less meaningful?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants