MAIA bb96820c
Multiphysics at AIA
Loading...
Searching...
No Matches
pointbox.h
Go to the documentation of this file.
1// Copyright (C) 2024 The m-AIA AUTHORS
2//
3// This file is part of m-AIA (https://git.rwth-aachen.de/aia/m-AIA/m-AIA)
4//
5// SPDX-License-Identifier: LGPL-3.0-only
6
7#ifndef POINTBOX_DEFINED
8#define POINTBOX_DEFINED
9
10#include <cmath>
11#include "INCLUDE/maiatypes.h"
19template <MInt DIM>
20struct Point {
21 MFloat x[DIM]{};
23 Point(const Point& p) {
24 for(MInt i = 0; i < DIM; i++)
25 x[i] = p.x[i];
26 cellId = p.cellId;
27 }
28 Point& operator=(const Point& p) {
29 for(MInt i = 0; i < DIM; i++)
30 x[i] = p.x[i];
31 cellId = p.cellId;
32 return *this;
33 }
34 MBool operator==(const Point& p) const {
35 for(MInt i = 0; i < DIM; i++)
36 if(x[i] != p.x[i]) return false;
37 return true;
38 }
39 explicit Point(MFloat x0 = 0.0, MFloat x1 = 0.0, MFloat x2 = 0.0, MInt id = -1) {
40 x[0] = x0;
41 cellId = id;
42 if(DIM > 1) x[1] = x1;
43 if(DIM > 2) x[2] = x2;
44 // if (DIM > 3) throw("Point not implemented for DIM > 3");
45 }
46};
47template <MInt DIM>
48struct Box {
50 Box() = default;
51 Box(const Point<DIM>& mylo, const Point<DIM>& myhi) : lo(mylo), hi(myhi) {}
52};
53template <MInt DIM>
54MFloat dist(const Point<DIM>& p, const Point<DIM>& q) {
55 MFloat dd = 0.0;
56 for(MInt j = 0; j < DIM; j++) {
57 dd += std::pow(q.x[j] - p.x[j], 2);
58 }
59 return std::sqrt(dd);
60}
61template <MInt DIM>
62MFloat dist(const Box<DIM>& b, const Point<DIM>& p) {
63 MFloat dd = 0;
64 for(MInt i = 0; i < DIM; i++) {
65 if(p.x[i] < b.lo.x[i]) dd += std::pow(p.x[i] - b.lo.x[i], 2);
66 if(p.x[i] > b.hi.x[i]) dd += std::pow(p.x[i] - b.hi.x[i], 2);
67 }
68 return std::sqrt(dd);
69}
70
71#endif
int32_t MInt
Definition: maiatypes.h:62
double MFloat
Definition: maiatypes.h:52
bool MBool
Definition: maiatypes.h:58
MInt id
Definition: maiatypes.h:71
MFloat dist(const Point< DIM > &p, const Point< DIM > &q)
Definition: pointbox.h:54
Definition: pointbox.h:48
Point< DIM > lo
Definition: pointbox.h:49
Box()=default
Box(const Point< DIM > &mylo, const Point< DIM > &myhi)
Definition: pointbox.h:51
Point< DIM > hi
Definition: pointbox.h:49
Definition: pointbox.h:20
Point & operator=(const Point &p)
Definition: pointbox.h:28
MBool operator==(const Point &p) const
Definition: pointbox.h:34
Point(const Point &p)
Definition: pointbox.h:23
Point(MFloat x0=0.0, MFloat x1=0.0, MFloat x2=0.0, MInt id=-1)
Definition: pointbox.h:39
MFloat x[DIM]
Definition: pointbox.h:21
MInt cellId
Definition: pointbox.h:22