Skip to content

Boundary conditions#1

Open
igirault wants to merge 7 commits intomhdfrom
boundary_conditions
Open

Boundary conditions#1
igirault wants to merge 7 commits intomhdfrom
boundary_conditions

Conversation

@igirault
Copy link
Owner

Start implementing boundary conditions

@igirault igirault force-pushed the boundary_conditions branch 3 times, most recently from 6dddb01 to ae3e40c Compare December 11, 2025 15:02
@igirault igirault force-pushed the boundary_conditions branch 4 times, most recently from 7128979 to 34d516c Compare January 26, 2026 10:20
@igirault igirault changed the base branch from master to mhd January 26, 2026 18:41
@igirault igirault force-pushed the boundary_conditions branch 5 times, most recently from 54e693d to c00493e Compare January 28, 2026 15:38
@igirault igirault force-pushed the boundary_conditions branch 10 times, most recently from 725bf56 to 4024d87 Compare February 5, 2026 22:06
@igirault igirault force-pushed the boundary_conditions branch 5 times, most recently from f8780d7 to 5945639 Compare February 10, 2026 15:21
post rebase
Squashed commits

WIP scalar -> scalar or tensor

Add documentation

Remove attributes relative to boundary location and physical quantity in field boundary condition definition.

fix some merging issues

WIP

move some definitions, cosmetic changes

WIP
@igirault igirault force-pushed the boundary_conditions branch from 3378ce7 to 99c4652 Compare February 19, 2026 12:48
@igirault igirault force-pushed the boundary_conditions branch 2 times, most recently from 08288b4 to 920dcb1 Compare February 24, 2026 10:22
@igirault igirault force-pushed the boundary_conditions branch from 920dcb1 to db16aa1 Compare February 24, 2026 12:04
Comment on lines +4 to +5
#include "SAMRAI/geom/CartesianPatchGeometry.h"
#include "SAMRAI/hier/PatchGeometry.h"
Copy link

@PhilipDeegan PhilipDeegan Feb 24, 2026

Choose a reason for hiding this comment

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

typically SAMRAI headers should come after our amr headers

we want to find mpi before samrai does so we can ignore certain warnings and override somethings (see: src/core/def/phare_mpi.hpp)

this file is a good example

so we can spot duplicates the group ordering should be from shortest line to longest and lines of the same length organised alphabetically from first differing character

Copy link
Owner Author

Choose a reason for hiding this comment

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

Yeah I have not been very rigorous and clean on header includes up to now. I agree they must be sorted in some way, but sorting by length has the disadvantage of breaking logical grouping like here

Couldn't we switch to alphabetical order within groups of headers, with groups ordering ( 1 PHARE namespaces, 2 SAMRAI, 3 STL) and enforce everything via clang-format ?

Choose a reason for hiding this comment

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

we don't let clang-format sort includes


namespace PHARE::amr
{
using core::dirX;
Copy link

@PhilipDeegan PhilipDeegan Feb 24, 2026

Choose a reason for hiding this comment

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

I don't think you're using this, but also try to avoid using statements at namespace scope, there can be unintended side affects

Comment on lines +8 to +11
namespace PHARE
{
namespace amr
{

Choose a reason for hiding this comment

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

new files namespacing should use namespace PHARE::amr to minimize indentation

#include "amr/data/field/refine/field_moments_refiner.hpp"
#include "amr/data/field/refine/field_refine_operator.hpp"
#include "amr/data/field/refine/electric_field_refiner.hpp"
#include "amr/data/field/refine/magnetic_field_init_refiner.hpp"

Choose a reason for hiding this comment

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

not sure if this was you, but it is a duplicate you will spot if you consider the organising I suggested

Comment on lines +136 to +137
EalgoPatchGhost.registerRefine(*e_id, *e_id, *e_id, EfieldRefineOp_,
nonOverwriteInteriorTFfillPattern);

Choose a reason for hiding this comment

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

you should check if @UCaromel has these changes


#include "core/data/grid/gridlayoutdefs.hpp"

#include "unordered_map"

Choose a reason for hiding this comment

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

system includes use <>

Comment on lines +138 to +141
auto it = typeMap_.find(name);
if (it == typeMap_.end())
throw std::runtime_error("Wrong boundary location name = " + name);
return it->second;
Copy link

@PhilipDeegan PhilipDeegan Feb 24, 2026

Choose a reason for hiding this comment

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

if (auto it = typeMap_.find(name); it != typeMap_.end())
    return it->second;
throw std::runtime_error("Wrong boundary location name = " + name);

or it could be

if (typeMap_.count(name))
    return typeMap_.at(name);
throw std::runtime_error("Wrong boundary location name = " + name);

iterators are not deprecated, but kinda verbose

{ field.name() } -> std::convertible_to<std::string const&>;
{ field.physicalQuantity() } -> std::same_as<typename T::physical_quantity_type const&>;

{ field.isUsable() } -> std::same_as<bool>;
Copy link

@PhilipDeegan PhilipDeegan Feb 24, 2026

Choose a reason for hiding this comment

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

I don't think this should be here, this is more about samrai and how we set buffers
but a field should just be about data/size/shape/etc tbh

Box<std::uint32_t, dimension> const& localGhostBox,
GridLayoutT const& gridLayout, double const time)
{
constexpr std::array<QtyCentering, N> centerings = {Centerings...};
Copy link

@PhilipDeegan PhilipDeegan Feb 24, 2026

Choose a reason for hiding this comment

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

99% sure you don't need the <QtyCentering, N> whether you do remove it I'll leave to you

Copy link
Owner Author

@igirault igirault Feb 25, 2026

Choose a reason for hiding this comment

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

I need it here to pass the direction as template parameter to apply_specialized

Choose a reason for hiding this comment

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

what I meant specifically, initially, is the array could also look like

constexpr static std::array centerings{Centerings...}; the templates can be inferred.

Copy link
Owner Author

Choose a reason for hiding this comment

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

ohhhh okay

* @brief Define comparison of field boundary conditions based on the enum @c
* ScalarOrTensorFieldT.
*/
std::strong_ordering operator<=>(This const& other) const

Choose a reason for hiding this comment

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

👽

Copy link
Owner Author

Choose a reason for hiding this comment

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

Yeah this will disappear as it is actually not necessary

Choose a reason for hiding this comment

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

it would have been our first operator of this kind, I hadn't really understood what it was for just yet

Copy link
Owner Author

Choose a reason for hiding this comment

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

It defines all comparison operators right away without manually defining <,>,>=,<=,==,!=

Choose a reason for hiding this comment

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

yeah I know it as the "spaceship" operator, I meant your usage in the current context ;)

Copy link
Owner Author

Choose a reason for hiding this comment

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

I see sorry it was to define priorities between boundary conditions at corner and edges



template<auto direction, auto offset>
NO_DISCARD constexpr auto neighbor() const

Choose a reason for hiding this comment

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

not sure I like this, something to discuss with nico maybe

I would suggest something like but for a point, not sure I see the benefit to the template params

Copy link
Owner Author

@igirault igirault Feb 25, 2026

Choose a reason for hiding this comment

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

used here for instance. Isn't it useful (more efficient) in a context where the offset and the direction are known at compile time ?

Choose a reason for hiding this comment

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

result[d] += static_cast<Type>(offset);

I think at this point, there is implicit runtime copies, so it's kinda just delaying the inevitable.

cmake_minimum_required (VERSION 3.20.1)
project(test-tensor-field-data)

set(SOURCES_INC

Choose a reason for hiding this comment

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

if you end up with more than one test file you might want something more like this



protected:
/// Reference to the resources manager.

Choose a reason for hiding this comment

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

seems a bit redundant

{
using core::dirX;
using core::dirY;
using core::dirZ;

Choose a reason for hiding this comment

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

could probably be moved at private class scope as @PhilipDeegan suggested

*
* @see GridLayout
*
*/

Choose a reason for hiding this comment

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

Could we want more minimal concepts to make maintenance easier ? Not sure if LSP can understand less explicit concepts tho.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Sure there are choices to be made about what should be in the concept or not. But if a definition is missing, code editors like VSCode will not provide hints, auto-completion, definition overview, etc...

Choose a reason for hiding this comment

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

something like this could be simpler than manually listing all the functions expected, assuming it works for LSP

}();

for_N<N>([&](auto i) {
constexpr QtyCentering centering = centerings[i];

Choose a reason for hiding this comment

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

and this can be auto if you like, I think it's clear what centerings are

}
}

NO_DISCARD auto rbegin() { return reverse_iterator{this, upper}; }

Choose a reason for hiding this comment

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

we're trying to minimize the use of the box iterator for performance reasons

we should talk about why you need this to see if we can not use it

Copy link
Owner Author

Choose a reason for hiding this comment

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

This is because for some boundary conditions (cf FieldDivergenceFreeTransverseNeumanBoundaryCondition) I need to fill ghost cells in a particular order.

I actually let Gemini write this reverse iterator by showing it the direct one to spare my time. I just wanted something that works for now, regardless of performance.

Don't you agree that we should be able to write an iterator that is efficient ?

Choose a reason for hiding this comment

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

I've demonstrated that the new version is more efficient, in some contexts at least, it should work for reverse iteration, and hopefully never need std::uint{-1} by using something like this

{
// Point precisely to the index that index_[0]-- creates after passing 'lower'
auto end_idx = lower;
end_idx[0]--;
Copy link

@PhilipDeegan PhilipDeegan Feb 26, 2026

Choose a reason for hiding this comment

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

end_idx[0]--; has an implicit copy which I'm not positive can be optimized out

so you should aim for --end_idx[0]; when possible (like here)

Comment on lines +259 to +260
using signed_t = std::make_signed_t<Type>;
if (static_cast<signed_t>(index_[0]) >= static_cast<signed_t>(box_->lower[0]))

Choose a reason for hiding this comment

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

you're going to need to explain this to me, I don't see how whether it's signed or unsigned should matter

Copy link

@PhilipDeegan PhilipDeegan Feb 26, 2026

Choose a reason for hiding this comment

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

is for Box<std::uint32_t. dim>::lower[0] == 0 ?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Yes exactly

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants