Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
ca_ghost_boundary_showcase_example.cc
Go to the documentation of this file.
1/*
2 Aleph_w
3
4 Data structures & Algorithms
5 version 2.0.0b
6 https://github.com/lrleon/Aleph-w
7
8 This file is part of Aleph-w library
9
10 Copyright (c) 2002-2026 Leandro Rabindranath Leon
11
12 Permission is hereby granted, free of charge, to any person obtaining a copy
13 of this software and associated documentation files (the "Software"), to deal
14 in the Software without restriction, including without limitation the rights
15 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16 copies of the Software, and to permit persons to whom the Software is
17 furnished to do so, subject to the following conditions:
18
19 The above copyright notice and this permission notice shall be included in all
20 copies or substantial portions of the Software.
21
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 SOFTWARE.
29*/
30
42#include <iomanip>
43#include <iostream>
44#include <string>
45
46#include <ca-traits.H>
47#include <tpl_ca_storage.H>
49
50using namespace Aleph;
51using namespace Aleph::CA;
52
53namespace
54{
55 constexpr ca_size_t INTERIOR = 4;
56 constexpr std::size_t HALO = 2;
57
59 template <typename Boundary>
62 {
64 g({ INTERIOR, INTERIOR }, 0);
67 g.set({ i, j }, static_cast<int>(i * 10 + j));
68 g.refresh_halo();
69 return g;
70 }
71
73 template <typename Boundary>
74 void render(const std::string &name,
76 {
77 const ca_index_t h = static_cast<ca_index_t>(HALO);
78 const ca_index_t n = static_cast<ca_index_t>(INTERIOR);
79
80 std::cout << "\n=== " << name << " ===\n";
81 for (ca_index_t i = -h; i < n + h; ++i)
82 {
83 for (ca_index_t j = -h; j < n + h; ++j)
84 {
85 const bool boundary_row = (j == 0 or j == n);
86 if (boundary_row)
87 std::cout << "| ";
88 std::cout << std::setw(3) << g.at_safe({ i, j }) << ' ';
89 }
90 std::cout << '\n';
91 if (i == -1 or i == n - 1)
92 {
93 // Separator row between halo and interior.
94 for (ca_index_t j = -h; j < n + h; ++j)
95 std::cout << "----";
96 std::cout << '\n';
97 }
98 }
99 }
100}
101
102int main()
103{
104 std::cout <<
105 "Ghost_Lattice boundary showcase\n"
106 "-------------------------------\n"
107 "Interior is a 4x4 lattice with cells = i*10 + j (00,01,... ,33).\n"
108 "Halo thickness is 2, so you see a 2-cell ring around the interior.\n"
109 "Vertical bars mark the user-visible borders on axis 1.\n";
110
111 render("OpenBoundary (halo = 0)",
113 render("ConstantBoundary<99> (Dirichlet)",
115 render("NeumannBoundary (clamp to border)",
117 render("PeriodicBoundary (toroidal wrap)",
119 render("ReflectiveBoundary (mirror at edge)",
121
122 return 0;
123}
long double h
Definition btreepic.C:154
Common typedefs and tag types for the Cellular Automata module.
Row-major dense storage for N-dimensional cellular automata.
Lattice with Halo ghost layers around the user-visible cells.
void set(const coord_type &c, const state_type &v)
Strict write through a user coordinate.
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
Definition Blossom.H:466
std::ptrdiff_t ca_index_t
Signed coordinate component used by lattices and neighborhoods.
Definition ca-traits.H:60
std::size_t ca_size_t
Unsigned size component used for extents and counts.
Definition ca-traits.H:63
Main namespace for Aleph-w library functions.
Definition ah-arena.H:89
Constant-value boundary.
Definition ca-traits.H:138
Ghost-layer lattice for high-performance boundary handling.
Dense, contiguous storage for cellular automata cells (1D/2D/3D).