From 2dca66c55f7c890ef3905f4e0aff5f20ef189acb Mon Sep 17 00:00:00 2001 From: Behzad Safaei <iwia103h@alex1.nhr.fau.de> Date: Mon, 10 Feb 2025 11:44:55 +0100 Subject: [PATCH] Add flags and shapes namespaces --- runtime/create_body.cpp | 6 +++--- runtime/pairs_common.hpp | 17 +++++++++++++---- runtime/read_from_file.cpp | 4 ++-- runtime/vtk.cpp | 8 ++++---- 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/runtime/create_body.cpp b/runtime/create_body.cpp index de60041..6c431f6 100644 --- a/runtime/create_body.cpp +++ b/runtime/create_body.cpp @@ -16,9 +16,9 @@ id_t create_halfspace(PairsRuntime *pr, auto positions = pr->getAsVectorProperty(pr->getPropertyByName("position")); auto normals = pr->getAsVectorProperty(pr->getPropertyByName("normal")); - if(pr->getDomainPartitioner()->isWithinSubdomain(x, y, z) || flag & (FLAGS_INFINITE | FLAGS_FIXED | FLAGS_GLOBAL) ){ + if(pr->getDomainPartitioner()->isWithinSubdomain(x, y, z) || flag & (flags::INFINITE | flags::GLOBAL) ){ int n = pr->getTrackedVariableAsInteger("nlocal"); - uid = (flag & FLAGS_GLOBAL) ? UniqueID::createGlobal(pr) : UniqueID::create(pr); + uid = (flag & flags::GLOBAL) ? UniqueID::createGlobal(pr) : UniqueID::create(pr); uids(n) = uid; positions(n, 0) = x; positions(n, 1) = y; @@ -53,7 +53,7 @@ id_t create_sphere(PairsRuntime *pr, if(pr->getDomainPartitioner()->isWithinSubdomain(x, y, z)) { int n = pr->getTrackedVariableAsInteger("nlocal"); - uid = (flag & FLAGS_GLOBAL) ? UniqueID::createGlobal(pr) : UniqueID::create(pr); + uid = (flag & flags::GLOBAL) ? UniqueID::createGlobal(pr) : UniqueID::create(pr); uids(n) = uid; radii(n) = radius; masses(n) = ((4.0 / 3.0) * M_PI) * radius * radius * radius * density; diff --git a/runtime/pairs_common.hpp b/runtime/pairs_common.hpp index 73c9f7b..ba2c56c 100644 --- a/runtime/pairs_common.hpp +++ b/runtime/pairs_common.hpp @@ -15,11 +15,20 @@ namespace pairs { #define PAIRS_ATTR_HOST_DEVICE #endif -constexpr int FLAGS_INFINITE = 1 << 0 ; -constexpr int FLAGS_GHOST = 1 << 1 ; -constexpr int FLAGS_FIXED = 1 << 2 ; -constexpr int FLAGS_GLOBAL = 1 << 3 ; +namespace flags{ + constexpr int INFINITE = 1 << 0 ; + constexpr int GHOST = 1 << 1 ; + constexpr int FIXED = 1 << 2 ; + constexpr int GLOBAL = 1 << 3 ; +} +namespace shapes{ + enum Type { + Sphere = 0, + Halfspace = 1, + PointMass = 2 + }; +} //#ifdef USE_DOUBLE_PRECISION typedef double real_t; //#else diff --git a/runtime/read_from_file.cpp b/runtime/read_from_file.cpp index 39e9bef..25dcc97 100644 --- a/runtime/read_from_file.cpp +++ b/runtime/read_from_file.cpp @@ -114,8 +114,8 @@ size_t read_particle_data( i++; } - if(within_domain || flags & (FLAGS_INFINITE | FLAGS_FIXED | FLAGS_GLOBAL)) { - uid_ptr(n) = (flags & FLAGS_GLOBAL) ? UniqueID::createGlobal(ps) : UniqueID::create(ps); + if(within_domain || flags & (flags::INFINITE | flags::FIXED | flags::GLOBAL)) { + uid_ptr(n) = (flags & flags::GLOBAL) ? UniqueID::createGlobal(ps) : UniqueID::create(ps); shape_ptr(n++) = shape_id; } } diff --git a/runtime/vtk.cpp b/runtime/vtk.cpp index f7d1e23..43502b0 100644 --- a/runtime/vtk.cpp +++ b/runtime/vtk.cpp @@ -34,7 +34,7 @@ void vtk_write_data( ps->copyPropertyToHost(flags, ReadOnly); for(int i = start; i < end; i++) { - if(flags(i) & FLAGS_INFINITE) { + if(flags(i) & flags::INFINITE) { n--; } } @@ -47,7 +47,7 @@ void vtk_write_data( out_file << "POINTS " << n << " double\n"; for(int i = start; i < end; i++) { - if(!(flags(i) & FLAGS_INFINITE)) { + if(!(flags(i) & flags::INFINITE)) { out_file << std::fixed << std::setprecision(prec) << positions(i, 0) << " "; out_file << std::fixed << std::setprecision(prec) << positions(i, 1) << " "; out_file << std::fixed << std::setprecision(prec) << positions(i, 2) << "\n"; @@ -63,7 +63,7 @@ void vtk_write_data( out_file << "\n\n"; out_file << "CELL_TYPES " << n << "\n"; for(int i = start; i < end; i++) { - if(!(flags(i) & FLAGS_INFINITE)) { + if(!(flags(i) & flags::INFINITE)) { out_file << "1\n"; } } @@ -73,7 +73,7 @@ void vtk_write_data( out_file << "SCALARS mass double\n"; out_file << "LOOKUP_TABLE default\n"; for(int i = start; i < end; i++) { - if(!(flags(i) & FLAGS_INFINITE)) { + if(!(flags(i) & flags::INFINITE)) { out_file << std::fixed << std::setprecision(prec) << masses(i) << "\n"; } } -- GitLab