Skip to content

Commit

Permalink
WIP test for error.
Browse files Browse the repository at this point in the history
  • Loading branch information
Robadob committed Dec 12, 2023
1 parent 678b923 commit d01952b
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions tests/test_cases/runtime/messaging/test_spatial_2d.cu
Original file line number Diff line number Diff line change
Expand Up @@ -964,5 +964,83 @@ TEST(Spatial2DMessageTest, buffer_not_init) {
EXPECT_NO_THROW(c.simulate());
}

FLAMEGPU_AGENT_FUNCTION(in_wrapped_not_factor, MessageSpatial2D, MessageNone) {
const float x1 = FLAMEGPU->getVariable<float>("x");
const float y1 = FLAMEGPU->getVariable<float>("y");
unsigned int count = 0;
unsigned int id[3];
// Count how many messages we recieved (including our own)
for (const auto& message : FLAMEGPU->message_in.wrap(x1, y1)) {
id[count] = message.getVariable<unsigned int>("id");
++count;
}
printf("%u sees (%u) %u and %u\n", FLAMEGPU->getID(), count, id[0], id[1]);
FLAMEGPU->setVariable<unsigned int>("count", count);
return ALIVE;
}
TEST(Spatial2DMessageTest, wrapped_not_factor) {
// This tests that bug #1157 is fixed
// When the interaction radius is not a factor of the width
// that agent's near the max env bound all have the full interaction radius
ModelDescription m("model");
MessageSpatial2D::Description message = m.newMessage<MessageSpatial2D>("location");
message.setMin(0, 0);
message.setMax(105, 105);
message.setRadius(10);
message.newVariable<flamegpu::id_t>("id"); // unused by current test
AgentDescription agent = m.newAgent("agent");
agent.newVariable<float>("x");
agent.newVariable<float>("y");
agent.newVariable<unsigned int>("count", 0);
AgentFunctionDescription fo = agent.newFunction("out", out_mandatory2D);
fo.setMessageOutput(message);
AgentFunctionDescription fi = agent.newFunction("in", in_wrapped_not_factor);
fi.setMessageInput(message);
LayerDescription lo = m.newLayer();
lo.addAgentFunction(fo);
LayerDescription li = m.newLayer();
li.addAgentFunction(fi);
// Set pop in model
CUDASimulation c(m);
// Create an agent in the middle of each edge
AgentVector population(agent, 6);
// Initialise agents
// Vertical pair that can interact
// Bottom side
AgentVector::Agent i1 = population[0];
i1.setVariable<float>("x", 105.0f / 2);
i1.setVariable<float>("y", 99.0f);
// Bottom side boundary
AgentVector::Agent i2 = population[1];
i2.setVariable<float>("x", 105.0f / 2);
i2.setVariable<float>("y", 105.0f);
// Top side
AgentVector::Agent i3 = population[2];
i3.setVariable<float>("x", 105.0f / 2);
i3.setVariable<float>("y", 0.1f);
// Horizontal pair that can interact
// Right side
AgentVector::Agent i4 = population[3];
i4.setVariable<float>("x", 99.0f);
i4.setVariable<float>("y", 105.0f / 2);
// Right side boundary
AgentVector::Agent i5 = population[4];
i5.setVariable<float>("x", 105.0f);
i5.setVariable<float>("y", 105.0f / 2);
// Left side
AgentVector::Agent i6 = population[5];
i6.setVariable<float>("x", 0.1f);
i6.setVariable<float>("y", 105.0f / 2);
c.setPopulationData(population);
c.SimulationConfig().steps = 1;
EXPECT_NO_THROW(c.simulate());
// Recover the results and check they match what was expected
c.getPopulationData(population);
// Validate each agent has same result
for (AgentVector::Agent ai : population) {
EXPECT_EQ(3u, ai.getVariable<unsigned int>("count"));
}
}

} // namespace test_message_spatial2d
} // namespace flamegpu

0 comments on commit d01952b

Please sign in to comment.