Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Activity State #92

Merged
merged 34 commits into from
Feb 7, 2022
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
50a90f0
remove @brief
FG-TUM Jan 17, 2022
5f423c0
extend Particle by ActivityState:
FG-TUM Jan 18, 2022
13dc91f
update propagator to temporary commit that includes change for accele…
FG-TUM Jan 18, 2022
138c03f
formatting and missing new constructor arguments in tests
FG-TUM Jan 18, 2022
ccab314
mass and radius for particles
FG-TUM Jan 18, 2022
371ce7d
only register conjunctions if they involve two passive or one passive…
FG-TUM Jan 18, 2022
0bec337
fix mistake in exclusion logic and add missing cases to ActivityState…
FG-TUM Jan 18, 2022
e4c01b0
update propagator and switch it to new fork
FG-TUM Jan 18, 2022
14d537a
move HDF5 definitions from writer to dedicated file
FG-TUM Jan 19, 2022
ba026ea
update propagator (minor variable rename)
FG-TUM Jan 20, 2022
b660fa7
proper equality operator for Particle
FG-TUM Jan 20, 2022
2758077
read and write static particle data to HDF5 + tests
FG-TUM Jan 20, 2022
817bf71
extend Particle constructor by mass and radius
FG-TUM Jan 20, 2022
923e7b5
don't try to write when there is nothing to write
FG-TUM Jan 20, 2022
030b1d5
constellations are evasivePreserving by default
FG-TUM Jan 21, 2022
598c186
formatting
FG-TUM Jan 21, 2022
a6da895
change > to != which is the same here
FG-TUM Jan 25, 2022
693dbe1
doc
FG-TUM Jan 25, 2022
8053386
remove now unnecessary explicit
FG-TUM Jan 25, 2022
958be69
rename StaticData -> ConstantProperties
FG-TUM Jan 25, 2022
bb529b2
typo
FG-TUM Jan 25, 2022
cacab21
rename StaticData -> ConstantProperties in some more comments
FG-TUM Jan 25, 2022
50ae026
doc
FG-TUM Jan 25, 2022
b2c3cdd
resolve todo via note
FG-TUM Jan 25, 2022
83b84d3
update hdf5 documentation
FG-TUM Jan 25, 2022
964ab02
notes about units
FG-TUM Jan 25, 2022
9010ae2
set aom correctly
FG-TUM Jan 25, 2022
47e3287
use constructor instead of setter
FG-TUM Jan 25, 2022
cd81dd7
add coefficientOfDrag to calculate bc_inv in particles
FG-TUM Jan 31, 2022
de8c77f
remove unused default values and add documentation about units
FG-TUM Jan 31, 2022
bedd58c
fix wrong formulas for area and unit conversion
FG-TUM Jan 31, 2022
a3cf7b5
Merge branch 'mergeBranch' into ActivityState
FG-TUM Feb 3, 2022
9f45179
YAML Reader: if a fallback value is used store it in the yaml structu…
FG-TUM Feb 3, 2022
2fce20d
coefficientOfDrag as optional yaml parameter:
FG-TUM Feb 3, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions cmake/modules/propagator.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ message(STATUS "Adding Propagator.")
include(FetchContent)

# Select https (default) or ssh path.
set(PropagatorRepoPath https://github.com/Wombatwarrior/BA_space_debris.git)
set(PropagatorRepoPath https://github.com/FG-TUM/OrbitPropagator.git)
if (GIT_SUBMODULES_SSH)
set(PropagatorRepoPath [email protected]:Wombatwarrior/BA_space_debris.git)
set(PropagatorRepoPath [email protected]:FG-TUM/OrbitPropagator.git)
endif ()

# disable stuff we do not need
Expand All @@ -18,8 +18,8 @@ set(DebrisSim_Simulation OFF CACHE INTERNAL "")
FetchContent_Declare(
Propagatorfetch
GIT_REPOSITORY ${PropagatorRepoPath}
# branch: IntegratorComparision; OpenMP parallelization
GIT_TAG 58ebb3a7d902a5adef9c9e4a9a62bb87367aa2b9
# branch: main; latest feature: ActivityState
GIT_TAG 9f5be5c079b2ff9ff6e64e34751f1429b61c8b46
)

# Get Propagator source and binary directories from CMake project
Expand Down
20 changes: 17 additions & 3 deletions src/ladds/CollisionFunctor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@

#include <algorithm>

CollisionFunctor::CollisionFunctor(double cutoff, double dt, double minorCutoff)
: Functor(cutoff), _cutoffSquare(cutoff * cutoff), _dt(dt), _minorCutoffSquare(minorCutoff * minorCutoff) {
CollisionFunctor::CollisionFunctor(double cutoff, double dt, double minorCutoff, double minDetectionRadius)
: Functor(cutoff),
_cutoffSquare(cutoff * cutoff),
_dt(dt),
_minorCutoffSquare(minorCutoff * minorCutoff),
_minDetectionRadius(minDetectionRadius) {
_threadData.resize(autopas::autopas_get_max_threads());
}

Expand All @@ -26,10 +30,20 @@ void CollisionFunctor::AoSFunctor(Particle &i, Particle &j, bool newton3) {
using autopas::utils::ArrayMath::mulScalar;
using autopas::utils::ArrayMath::sub;

// skip interaction with deleted particles
// skip if interaction involves:
// - any deleted particles
// - two actively evasive satellites
// - one evasive and one of detectable size
if (i.isDummy() or j.isDummy()) {
return;
}
const auto &iActivity = i.getActivityState();
const auto &jActivity = j.getActivityState();
if ((iActivity > Particle::ActivityState::passive and jActivity > Particle::ActivityState::passive) or
(iActivity > Particle::ActivityState::passive and j.getRadius() >= _minDetectionRadius) or
(jActivity > Particle::ActivityState::passive and i.getRadius() >= _minDetectionRadius)) {
return;
FG-TUM marked this conversation as resolved.
Show resolved Hide resolved
}

// calculate distance between particles
const auto dr = sub(i.getR(), j.getR());
Expand Down
7 changes: 6 additions & 1 deletion src/ladds/CollisionFunctor.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
class CollisionFunctor final : public autopas::Functor<Particle, CollisionFunctor> {
public:
explicit CollisionFunctor(double cutoff, double dt, double minorCutoff);
explicit CollisionFunctor(double cutoff, double dt, double minorCutoff, double minDetectionRadius);
FG-TUM marked this conversation as resolved.
Show resolved Hide resolved

[[nodiscard]] bool isRelevantForTuning() final {
return true;
Expand Down Expand Up @@ -91,4 +91,9 @@ class CollisionFunctor final : public autopas::Functor<Particle, CollisionFuncto
const double _cutoffSquare;
const double _dt;
const double _minorCutoffSquare;
/**
* Minimal object size in meter that is assumed to be detectable.
* Objects larger than this can be evaded by evasive particles.
*/
const double _minDetectionRadius;
};
10 changes: 6 additions & 4 deletions src/ladds/Simulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ Simulation::initIntegrator(AutoPas_t &autopas, ConfigReader &config) {
OutputFile::CSV,
selectedPropagatorComponents);
auto accumulator = std::make_unique<Acceleration::AccelerationAccumulator<AutoPas_t>>(
selectedPropagatorComponents, autopas, 0.0, *csvWriter);
selectedPropagatorComponents, autopas, 0.0, csvWriter.get());
auto deltaT = config.get<double>("sim/deltaT");
auto integrator = std::make_unique<Integrator<AutoPas_t>>(autopas, *accumulator, deltaT);

Expand All @@ -150,9 +150,10 @@ void Simulation::updateConstellation(AutoPas_t &autopas,

std::tuple<CollisionFunctor::CollisionCollectionT, bool> Simulation::collisionDetection(AutoPas_t &autopas,
double deltaT,
double conjunctionThreshold) {
double conjunctionThreshold,
double minDetectionRadius) {
// pairwise interaction
CollisionFunctor collisionFunctor(autopas.getCutoff(), deltaT, conjunctionThreshold);
CollisionFunctor collisionFunctor(autopas.getCutoff(), deltaT, conjunctionThreshold, minDetectionRadius);
bool stillTuning = autopas.iteratePairwise(&collisionFunctor);
return {collisionFunctor.getCollisions(), stillTuning};
}
Expand All @@ -168,6 +169,7 @@ void Simulation::simulationLoop(AutoPas_t &autopas,
const auto progressOutputFrequency = config.get<int>("io/progressOutputFrequency", 50);
const auto deltaT = config.get<double>("sim/deltaT");
const auto conjunctionThreshold = config.get<double>("sim/conjunctionThreshold");
const auto minDetectionRadius = config.get<double>("sim/minDetectionRadius", 0.1);
std::vector<Particle> delayedInsertion;

const auto vtkWriteFrequency = config.get<size_t>("io/vtk/writeFrequency", 0ul);
Expand Down Expand Up @@ -218,7 +220,7 @@ void Simulation::simulationLoop(AutoPas_t &autopas,
// TODO Check for particles that burn up

timers.collisionDetection.start();
auto [collisions, stillTuning] = collisionDetection(autopas, deltaT, conjunctionThreshold);
auto [collisions, stillTuning] = collisionDetection(autopas, deltaT, conjunctionThreshold, minDetectionRadius);
timers.collisionDetection.stop();

if (tuningMode and not stillTuning) {
Expand Down
3 changes: 2 additions & 1 deletion src/ladds/Simulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ class Simulation {
*/
std::tuple<CollisionFunctor::CollisionCollectionT, bool> collisionDetection(AutoPas_t &autopas,
double deltaT,
double conjunctionThreshold);
double conjunctionThreshold,
double minDetectionRadius);

/**
* Updates the configuration with the latest AutoPas configuration and writes it to a new YAML file.
Expand Down
3 changes: 2 additions & 1 deletion src/ladds/io/DatasetReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ std::vector<Particle> DatasetReader::readDataset(const std::string &position_fil

const std::array<double, 3> posArray = {x, y, z};
const std::array<double, 3> velArray = {vx, vy, vz};
return Particle(posArray, velArray, particleId++);
// TODO: parse activity information and set it here!
return Particle(posArray, velArray, particleId++, Particle::ActivityState::passive, 1., 1.);
});
return particleCollection;
}
58 changes: 58 additions & 0 deletions src/ladds/io/hdf5/HDF5Definitions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* @file HDF5Definitions.h
* @author F. Gratl
* @date 19.01.22
*/

#pragma once

namespace HDF5Definitions {
constexpr auto groupParticleData = "ParticleData/";
constexpr auto datasetParticlePositions = "/Particles/Positions";
constexpr auto datasetParticleVelocities = "/Particles/Velocities";
constexpr auto datasetParticleIDs = "/Particles/IDs";
constexpr auto tableParticleStaticData = "StaticData";
FG-TUM marked this conversation as resolved.
Show resolved Hide resolved
constexpr auto groupCollisionData = "CollisionData/";
constexpr auto datasetCollisions = "/Collisions";

/**
* Type to which any floating point data will be cast before writing.
*/
using FloatType = float;
/**
* Type to which any integer data will be cast before writing.
*/
using IntType = unsigned int;

/**
* This represents one line of 3D vector data in the HDF5 file.
*/
template <class T>
struct Vec3 {
T x, y, z;
};

/**
* Type for the information of a single collision.
*/
struct CollisionInfo {
unsigned int idA, idB;
float distanceSquared;
bool operator==(const CollisionInfo &rhs) const {
return idA == rhs.idA && idB == rhs.idB && distanceSquared == rhs.distanceSquared;
}
bool operator!=(const CollisionInfo &rhs) const {
return !(rhs == *this);
}
};

/**
* Type for information of a single particle that will stay constant throughout the simulation.
* This will
*/
struct ParticleStaticData {
IntType id;
FloatType mass, radius;
int activityState;
};
} // namespace HDF5Definitions
48 changes: 34 additions & 14 deletions src/ladds/io/hdf5/HDF5Reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

#include "HDF5Reader.h"

#include "HDF5Writer.h"
#include "HDF5Definitions.h"

HDF5Reader::HDF5Reader(const std::string &filename)
#ifdef LADDS_HDF5
: file(filename, h5pp::FilePermission::READONLY)
Expand All @@ -20,36 +21,55 @@ HDF5Reader::HDF5Reader(const std::string &filename)
std::vector<Particle> HDF5Reader::readParticles(size_t iteration) const {
std::vector<Particle> particles{};
#ifdef LADDS_HDF5
const auto pos = file.readDataset<std::vector<HDF5Writer::Vec3<HDF5Writer::FloatType>>>(
HDF5Writer::groupParticleData + std::to_string(iteration) + HDF5Writer::datasetParticlePositions);
const auto vel = file.readDataset<std::vector<HDF5Writer::Vec3<HDF5Writer::FloatType>>>(
HDF5Writer::groupParticleData + std::to_string(iteration) + HDF5Writer::datasetParticleVelocities);
const auto ids = file.readDataset<std::vector<HDF5Writer::IntType>>(
HDF5Writer::groupParticleData + std::to_string(iteration) + HDF5Writer::datasetParticleIDs);
const auto pos = file.readDataset<std::vector<HDF5Definitions::Vec3<HDF5Definitions::FloatType>>>(
HDF5Definitions::groupParticleData + std::to_string(iteration) + HDF5Definitions::datasetParticlePositions);
const auto vel = file.readDataset<std::vector<HDF5Definitions::Vec3<HDF5Definitions::FloatType>>>(
HDF5Definitions::groupParticleData + std::to_string(iteration) + HDF5Definitions::datasetParticleVelocities);
const auto ids = file.readDataset<std::vector<HDF5Definitions::IntType>>(
HDF5Definitions::groupParticleData + std::to_string(iteration) + HDF5Definitions::datasetParticleIDs);
const auto pathParticleStaticData =
std::string(HDF5Definitions::groupParticleData) + HDF5Definitions::tableParticleStaticData;
const auto staticDataVec =
file.readTableRecords<std::vector<HDF5Definitions::ParticleStaticData>>(pathParticleStaticData);

// convert static data to a map for easier access
const auto staticDataMap = [&]() {
// id is redundant in this datastructure but easier maintainable this way
std::unordered_map<size_t, HDF5Definitions::ParticleStaticData> map;
map.reserve(staticDataVec.size());
for (const auto &data : staticDataVec) {
map[data.id] = data;
}
return map;
}();

particles.reserve(pos.size());
for (size_t i = 0; i < pos.size(); ++i) {
const auto &staticData = staticDataMap.at(ids[i]);
particles.emplace_back(std::array<double, 3>{pos[i].x, pos[i].y, pos[i].z},
std::array<double, 3>{vel[i].x, vel[i].y, vel[i].z},
ids[i]);
staticData.id,
static_cast<Particle::ActivityState>(staticData.activityState),
staticData.mass,
staticData.radius);
}
#endif
return particles;
}

std::vector<HDF5Writer::CollisionInfo> HDF5Reader::readCollisions(size_t iteration) const {
std::vector<HDF5Writer::CollisionInfo> collisions{};
std::vector<HDF5Definitions::CollisionInfo> HDF5Reader::readCollisions(size_t iteration) const {
std::vector<HDF5Definitions::CollisionInfo> collisions{};
#ifdef LADDS_HDF5
file.readDataset(collisions,
HDF5Writer::groupCollisionData + std::to_string(iteration) + HDF5Writer::datasetCollisions);
file.readDataset(
collisions, HDF5Definitions::groupCollisionData + std::to_string(iteration) + HDF5Definitions::datasetCollisions);
#endif
return collisions;
}

size_t HDF5Reader::readLastIterationNr() {
const auto groupStrLength = std::string(HDF5Writer::groupParticleData).size();
const auto groupStrLength = std::string(HDF5Definitions::groupParticleData).size();
// gather all ID datasets. They contain the iteration number in their path
auto allIdDatasets = file.findDatasets(HDF5Writer::datasetParticleIDs);
auto allIdDatasets = file.findDatasets(HDF5Definitions::datasetParticleIDs);
std::vector<size_t> allIterations;
allIterations.reserve(allIdDatasets.size());
// extract all iteration numbers as size_t
Expand Down
5 changes: 3 additions & 2 deletions src/ladds/io/hdf5/HDF5Reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@

#include <string>

#include "HDF5Writer.h"
#include "HDF5Definitions.h"
#include "ladds/particle/Particle.h"

class HDF5Reader {
public:
explicit HDF5Reader(const std::string &filename);

std::vector<Particle> readParticles(size_t iteration) const;

std::vector<HDF5Writer::CollisionInfo> readCollisions(size_t iteration) const;
std::vector<HDF5Definitions::CollisionInfo> readCollisions(size_t iteration) const;

/**
* Finds the last iteration that is stored in the file.
Expand Down
Loading