Skip to content

Commit

Permalink
reconnector activities corrected + make tests running
Browse files Browse the repository at this point in the history
  • Loading branch information
chrxh committed Oct 20, 2023
1 parent c1b7bd1 commit 94948ce
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 7 deletions.
6 changes: 4 additions & 2 deletions source/EngineGpuKernels/ReconnectorProcessor.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ ReconnectorProcessor::tryEstablishConnection(SimulationData& data, SimulationSta
}
});

activity.channels[1] = 0;
activity.channels[0] = 0;
if (closestCell) {
SystemDoubleLock lock;
lock.init(&cell->locked, &closestCell->locked);
Expand All @@ -78,18 +78,20 @@ ReconnectorProcessor::tryEstablishConnection(SimulationData& data, SimulationSta
cell->maxConnections = min(max(cell->maxConnections, cell->numConnections + 1), MAX_CELL_BONDS);
CellConnectionProcessor::scheduleAddConnectionPair(data, cell, closestCell);
lock.releaseLock();
activity.channels[1] = 1;
activity.channels[0] = 1;
}
}
}

__inline__ __device__ void ReconnectorProcessor::removeConnections(SimulationData& data, SimulationStatistics& statistics, Cell* cell, Activity& activity)
{
activity.channels[0] = 0;
if (cell->tryLock()) {
for (int i = 0; i < cell->numConnections; ++i) {
auto connectedCell = cell->connections[i].cell;
if (connectedCell->creatureId != cell->creatureId) {
CellConnectionProcessor::scheduleDeleteConnectionPair(data, cell, connectedCell);
activity.channels[0] = 1;
}
}
cell->releaseLock();
Expand Down
2 changes: 1 addition & 1 deletion source/EngineGpuKernels/SimulationKernels.cu
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ __global__ void cudaNextTimestep_cellFunction_sensor(SimulationData data, Simula
SensorProcessor::process(data, statistics);
}

__global__ void cudaNextTimestep_cellFunction_reconector(SimulationData data, SimulationStatistics statistics)
__global__ void cudaNextTimestep_cellFunction_reconnector(SimulationData data, SimulationStatistics statistics)
{
ReconnectorProcessor::process(data, statistics);
}
Expand Down
2 changes: 1 addition & 1 deletion source/EngineGpuKernels/SimulationKernels.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ __global__ void cudaNextTimestep_cellFunction_defender(SimulationData data, Simu
__global__ void cudaNextTimestep_cellFunction_transmitter(SimulationData data, SimulationStatistics statistics);
__global__ void cudaNextTimestep_cellFunction_muscle(SimulationData data, SimulationStatistics statistics);
__global__ void cudaNextTimestep_cellFunction_sensor(SimulationData data, SimulationStatistics statistics);
__global__ void cudaNextTimestep_cellFunction_reconector(SimulationData data, SimulationStatistics statistics);
__global__ void cudaNextTimestep_cellFunction_reconnector(SimulationData data, SimulationStatistics statistics);
__global__ void cudaNextTimestep_physics_substep7_innerFriction(SimulationData data);
__global__ void cudaNextTimestep_physics_substep8(SimulationData data);
__global__ void cudaNextTimestep_structuralOperations_substep1(SimulationData data);
Expand Down
2 changes: 1 addition & 1 deletion source/EngineGpuKernels/SimulationKernelsLauncher.cu
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ void _SimulationKernelsLauncher::calcTimestep(Settings const& settings, Simulati
KERNEL_CALL(cudaNextTimestep_cellFunction_transmitter, data, statistics);
KERNEL_CALL(cudaNextTimestep_cellFunction_muscle, data, statistics);
KERNEL_CALL(cudaNextTimestep_cellFunction_sensor, data, statistics);
KERNEL_CALL(cudaNextTimestep_cellFunction_reconector, data, statistics);
KERNEL_CALL(cudaNextTimestep_cellFunction_reconnector, data, statistics);

if (considerInnerFriction) {
KERNEL_CALL(cudaNextTimestep_physics_substep7_innerFriction, data);
Expand Down
51 changes: 49 additions & 2 deletions source/EngineTests/ReconnectorTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ReconnectorTests : public IntegrationTestFramework
~ReconnectorTests() = default;
};

TEST_F(ReconnectorTests, nothingFound)
TEST_F(ReconnectorTests, establishConnection_nothingFound)
{
DataDescription data;
data.addCells(
Expand All @@ -54,11 +54,12 @@ TEST_F(ReconnectorTests, nothingFound)
auto actualReconnectorCell = getCell(actualData, 1);

EXPECT_EQ(2, actualData.cells.size());
EXPECT_TRUE(std::abs(actualReconnectorCell.activity.channels[0]) < NEAR_ZERO);
EXPECT_TRUE(approxCompare(getEnergy(data), getEnergy(actualData)));
EXPECT_TRUE(approxCompare(0.0f, actualReconnectorCell.activity.channels[0]));
}

TEST_F(ReconnectorTests, success)
TEST_F(ReconnectorTests, establishConnection_success)
{
DataDescription data;
data.addCells({
Expand Down Expand Up @@ -96,3 +97,49 @@ TEST_F(ReconnectorTests, success)
EXPECT_TRUE(hasConnection(actualData, 1, 3));
EXPECT_TRUE(approxCompare(getEnergy(data), getEnergy(actualData)));
}

TEST_F(ReconnectorTests, deleteConnections_success)
{
DataDescription data;
data.addCells({
CellDescription()
.setId(1)
.setPos({10.0f, 10.0f})
.setMaxConnections(3)
.setExecutionOrderNumber(0)
.setInputExecutionOrderNumber(5)
.setCellFunction(ReconnectorDescription())
.setCreatureId(1),
CellDescription()
.setId(2)
.setPos({11.0f, 10.0f})
.setMaxConnections(1)
.setExecutionOrderNumber(5)
.setCellFunction(NerveDescription())
.setActivity({-1, 0, 0, 0, 0, 0, 0, 0})
.setCreatureId(1),
CellDescription().setId(3).setPos({9.0f, 10.0f}).setMaxConnections(1).setCreatureId(3),
CellDescription().setId(4).setPos({9.0f, 11.0f}).setMaxConnections(1).setCreatureId(4),
});
data.addConnection(1, 2);
data.addConnection(1, 3);
data.addConnection(1, 4);

_simController->setSimulationData(data);
_simController->calcTimesteps(1);

auto actualData = _simController->getSimulationData();
ASSERT_EQ(4, actualData.cells.size());

auto actualReconnectorCell = getCell(actualData, 1);

auto actualTargetCell1 = getCell(actualData, 3);
auto actualTargetCell2 = getCell(actualData, 4);

EXPECT_TRUE(actualReconnectorCell.activity.channels[0] > NEAR_ZERO);
EXPECT_EQ(1, actualReconnectorCell.connections.size());
EXPECT_TRUE(actualTargetCell1.connections.empty());
EXPECT_TRUE(actualTargetCell2.connections.empty());
EXPECT_TRUE(hasConnection(actualData, 1, 2));
EXPECT_TRUE(approxCompare(getEnergy(data), getEnergy(actualData)));
}

0 comments on commit 94948ce

Please sign in to comment.