Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
simulation_domain.hpp
Go to the documentation of this file.
1// -------------------------------------------------------//
2//
3// SHAMROCK code for hydrodynamics
4// Copyright (c) 2021-2026 Timothée David--Cléris <tim.shamrock@proton.me>
5// SPDX-License-Identifier: CeCILL Free Software License Agreement v2.1
6// Shamrock is licensed under the CeCILL 2.1 License, see LICENSE for more information
7//
8// -------------------------------------------------------//
9
10#pragma once
11
20#include <memory>
21#include <optional>
22#include <vector>
23
24enum BCType { Free, Periodic, PeriodicShearing, Fixed, Ghost, FixedGradient, AntiPeriodic };
25
26template<class flt>
28 public:
29 BCType boundary_type;
30
31 using vec = sycl::vec<flt, 3>;
32 using vec_box = std::tuple<vec, vec>;
33
35
36 std::optional<u32_3> periodic_search_min_vec;
37 std::optional<u32_3> periodic_search_max_vec;
38
39 SimulationDomain(const BCType &boundary_type, vec min, vec max)
40 : box_bc(ALignedAxisBoundingBox<flt>(min, max)), boundary_type(boundary_type) {
41 check_boundary();
42 }
43
44 inline bool has_outdomain_object() {
45 switch (boundary_type) {
46 case Periodic : return true; break;
47 case PeriodicShearing: return true; break;
48 default :;
49 }
50 return false;
51 }
52
53 /*
54 * describe the schearing cd in the following way
55 * std::tuple<vec_box, u32_3, u32, vec> equivalent to [shearing vec, field id (flt type x 3),
56 * vec] applied like this : field[fid] = field[fid] + vec*dot(pvec,svec); svec is the shearing
57 * vector (argument) pvec is the vector that discribe the periodicity
58 */
59 // std::vector<std::tuple<u32_3, u32, vec>> shear_cd;
60
61 inline void check_boundary() {
62 if (boundary_type == PeriodicShearing) {
64 "[SimulationDomain] Boundary CD : Shearing periodic mode not implemented");
65 }
66
67 if (boundary_type == Fixed) {
69 "[SimulationDomain] Boundary CD : Dirichelt mode not implemented");
70 }
71
72 if (boundary_type == Ghost) {
74 "[SimulationDomain] Boundary CD : Ghost mode not implemented");
75 }
76
77 if (boundary_type == FixedGradient) {
79 "[SimulationDomain] Boundary CD : FixedGradient mode not implemented");
80 }
81
82 if (boundary_type == AntiPeriodic) {
84 "[SimulationDomain] Boundary CD : AntiPeriodic mode not implemented");
85 }
86 }
87
88 inline void set_box(const vec_box &b) {
89 box_bc = ALignedAxisBoundingBox<flt>(std::get<0>(b), std::get<1>(b));
90 }
91
92 inline vec get_periodicity_vector() const {
93 vec pvec;
94
95 if (boundary_type == Periodic || boundary_type == PeriodicShearing) {
96 pvec = box_bc.get_size();
97 } else if (boundary_type == Free) {
98 pvec = vec{0, 0, 0};
99 } else {
101 "[SimulationDomain] Can not set box size with free boundary conditions");
102 }
103
104 return pvec;
105 }
106
107 inline void set_periodic_search_range(u32_3 min, u32_3 max) {
108 if (!(has_outdomain_object())) {
110 "[SimulationDomain] Can not set periodic search range without periodic bc");
111 }
112 periodic_search_min_vec = min;
113 periodic_search_max_vec = max;
114 }
115};
This header file contains utility functions related to exception handling in the code.
void throw_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Throw an exception and append the source location to it.