Skip to content

Commit 71c8497

Browse files
committed
Fixes #1877
1 parent 95900f1 commit 71c8497

File tree

2 files changed

+65
-47
lines changed

2 files changed

+65
-47
lines changed

src/Core/Algorithms/Field/Tests/GenerateStreamLinesTests.cc

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,22 @@ FieldHandle LoadMultiSeeds()
5050

5151
FieldHandle LoadSingleSeed()
5252
{
53-
return loadFieldFromFile(TestResources::rootDir() / "Fields/streamlines/singleSeed.fld");
53+
return loadFieldFromFile(TestResources::rootDir() / "Fields/streamlines/singleSeed.fld");
5454
}
5555

5656
FieldHandle LoadTorsoSeeds()
5757
{
58-
return loadFieldFromFile(TestResources::rootDir() / "Fields/seedPointsFromTorso.fld");
58+
return loadFieldFromFile(TestResources::rootDir() / "Fields/seedPointsFromTorso.fld");
5959
}
6060

6161
FieldHandle LoadTorso()
6262
{
63-
return loadFieldFromFile(TestResources::rootDir() / "Fields/utahtorso-lowres/gradient.fld");
63+
return loadFieldFromFile(TestResources::rootDir() / "Fields/utahtorso-lowres/gradient.fld");
6464
}
6565

6666
FieldHandle LoadVectorField()
6767
{
68-
return loadFieldFromFile(TestResources::rootDir() / "Fields/streamlines/vectorField.fld");
68+
return loadFieldFromFile(TestResources::rootDir() / "Fields/streamlines/vectorField.fld");
6969
}
7070

7171
static std::vector<std::string> methods { "AdamsBashforth", "Heun", "RungeKutta",
@@ -81,7 +81,7 @@ TEST(GenerateStreamLinesTests, SingleSeedProducesSinglePositiveStreamlineSingleT
8181
GenerateStreamLinesAlgo algo;
8282
FieldHandle output;
8383

84-
std::cout << "method: " << method << std::endl;
84+
//std::cout << "method: " << method << std::endl;
8585
algo.set(Parameters::UseMultithreading, false);
8686
algo.setOption(Parameters::StreamlineValue, "Distance from seed");
8787
algo.setOption(Parameters::StreamlineMethod, method);
@@ -94,11 +94,14 @@ TEST(GenerateStreamLinesTests, SingleSeedProducesSinglePositiveStreamlineSingleT
9494

9595
double min,max;
9696
output->vfield()->minmax(min, max);
97-
std::cout << min << " " << max << std::endl;
97+
//std::cout << min << " " << max << std::endl;
9898

9999
// streamlines contained within 8x8x8 latvol
100-
EXPECT_GT(min, 0.0);
101-
EXPECT_LT(max, 8.0);
100+
EXPECT_EQ(min, 0.0);
101+
if (method == "AdamsBashforth")
102+
EXPECT_LT(max, 65.0); // corkscrew streamlines
103+
else
104+
EXPECT_LT(max, 12.0);
102105
}
103106
}
104107

@@ -124,14 +127,18 @@ TEST(GenerateStreamLinesTests, SingleSeedProducesSinglePositiveStreamlineMultiTh
124127

125128
double min,max;
126129
output->vfield()->minmax(min, max);
127-
std::cout << min << " " << max << std::endl;
130+
//std::cout << min << " " << max << std::endl;
128131

129132
// streamlines contained within 8x8x8 latvol
130-
EXPECT_GT(min, 0.0);
131-
EXPECT_LT(max, 8.0);
133+
EXPECT_EQ(min, 0.0);
134+
if (method == "AdamsBashforth")
135+
EXPECT_LT(max, 65.0); // corkscrew streamlines
136+
else
137+
EXPECT_LT(max, 12.0);
132138
}
133139
}
134140

141+
//TODO: use > 16 seeds to force multithreading
135142
TEST(GenerateStreamLinesTests, MultipleSeedsProducesMultipleStreamlinesSingleThreaded)
136143
{
137144
auto multiSeeds = LoadMultiSeeds();
@@ -154,11 +161,14 @@ TEST(GenerateStreamLinesTests, MultipleSeedsProducesMultipleStreamlinesSingleThr
154161

155162
double min,max;
156163
output->vfield()->minmax(min, max);
157-
std::cout << min << " " << max << std::endl;
164+
//std::cout << min << " " << max << std::endl;
158165

159166
// streamlines contained within 8x8x8 latvol
160-
EXPECT_GT(min, 0.0);
161-
EXPECT_LT(max, 8.0);
167+
EXPECT_EQ(min, 0.0);
168+
if (method == "AdamsBashforth")
169+
EXPECT_LT(max, 93.0); // corkscrew streamlines
170+
else
171+
EXPECT_LT(max, 17.0);
162172
}
163173
}
164174

@@ -184,11 +194,14 @@ TEST(GenerateStreamLinesTests, MultipleSeedsProducesMultipleStreamlinesMultiThre
184194

185195
double min,max;
186196
output->vfield()->minmax(min, max);
187-
std::cout << min << " " << max << std::endl;
197+
//std::cout << min << " " << max << std::endl;
188198

189199
// streamlines contained within 8x8x8 latvol
190-
EXPECT_GT(min, 0.0);
191-
EXPECT_LT(max, 8.0);
200+
EXPECT_EQ(min, 0.0);
201+
if (method == "AdamsBashforth")
202+
EXPECT_LT(max, 93.0); // corkscrew streamlines
203+
else
204+
EXPECT_LT(max, 17.0);
192205
}
193206
}
194207

@@ -215,7 +228,7 @@ TEST(GenerateStreamLinesTests, ManySeedsMultithreaded)
215228
algo.setOption(Parameters::StreamlineValue, "Distance from seed");
216229
algo.setOption(Parameters::StreamlineMethod, method);
217230

218-
std::cout << "processing real streamlines using " << method << " method." << std::endl;
231+
//std::cout << "processing real streamlines using " << method << " method." << std::endl;
219232
algo.runImpl(torso, torsoSeeds, output);
220233

221234
EXPECT_GT(output->vmesh()->num_nodes(), 0);
@@ -228,11 +241,16 @@ TEST(GenerateStreamLinesTests, ManySeedsMultithreaded)
228241

229242
double min,max;
230243
output->vfield()->minmax(min, max);
231-
std::cout << min << " " << max << std::endl;
244+
//std::cout << min << " " << max << std::endl;
232245

233246
// streamlines contained within mesh with greatest dimension <= 600
234-
EXPECT_GT(min, 0.0);
235-
EXPECT_LT(max, 600.0);
247+
EXPECT_EQ(min, 0.0);
248+
if (method == "AdamsBashforth")
249+
EXPECT_LT(max, 6300.0); // corkscrew streamlines
250+
else if (method == "CellWalk")
251+
EXPECT_LT(max, 2900.0);
252+
else
253+
EXPECT_LT(max, 600.0);
236254
}
237255
}
238256

@@ -259,12 +277,12 @@ TEST(GenerateStreamLinesTests, ManySeedsMultithreadedStreamlineLength)
259277
algo.setOption(Parameters::StreamlineValue, "Streamline length");
260278
algo.setOption(Parameters::StreamlineMethod, method);
261279

262-
std::cout << "processing real streamlines using " << method << " method." << std::endl;
280+
//std::cout << "processing real streamlines using " << method << " method." << std::endl;
263281
algo.runImpl(torso, torsoSeeds, output);
264282

265283
double min,max;
266284
output->vfield()->minmax(min, max);
267-
std::cout << min << " " << max << std::endl;
285+
//std::cout << min << " " << max << std::endl;
268286
EXPECT_NEAR(min, meshOutputByMethodTotalLength[method].first, 1e-2);
269287
EXPECT_NEAR(max, meshOutputByMethodTotalLength[method].second, 1e-1);
270288
}

src/Core/Algorithms/Legacy/Fields/StreamLines/GenerateStreamLines.cc

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -329,46 +329,45 @@ namespace detail
329329
auto ofield = out->vfield();
330330
auto omesh = out->vmesh();
331331
const auto totalLength = calcTotalStreamlineLength(nodes);
332-
VMesh::Node::index_type n1, n2;
332+
double partialStreamlineLength = 0;
333+
int nodeIndex = 0;
334+
Point previousNode;
333335
VMesh::Node::array_type newnodes(2);
334-
auto node_iter = nodes.begin();
336+
VMesh::Node::index_type n1, n2;
335337

336-
if (node_iter != nodes.end())
338+
for (const auto& node : nodes)
337339
{
338-
auto p1 = *node_iter;
339-
n1 = omesh->add_point(p1);
340-
341-
ofield->resize_values();
342-
343-
double distanceFromSeedLength = 0;
344-
345-
if (value_ == StreamlineValue::SeedValue) ofield->copy_value(seed_field_, idx, n1);
346-
else if (value_ == StreamlineValue::SeedIndex) ofield->set_value(index_type(idx), n1);
347-
else if (value_ == StreamlineValue::IntegrationIndex) ofield->set_value(abs(cc), n1);
348-
else if (value_ == StreamlineValue::IntegrationStep) ofield->set_value(0, n1);
349-
else if (value_ == StreamlineValue::DistanceFromSeed) ofield->set_value(distanceFromSeedLength, n1);
350-
else if (value_ == StreamlineValue::StreamlineLength) ofield->set_value(totalLength, n1);
340+
if (0 == nodeIndex)
341+
{
342+
n1 = omesh->add_point(node);
343+
ofield->resize_values();
351344

352-
++node_iter;
353-
cc++;
345+
if (value_ == StreamlineValue::SeedValue) ofield->copy_value(seed_field_, idx, n1);
346+
else if (value_ == StreamlineValue::SeedIndex) ofield->set_value(index_type(idx), n1);
347+
else if (value_ == StreamlineValue::IntegrationIndex) ofield->set_value(abs(cc), n1);
348+
else if (value_ == StreamlineValue::IntegrationStep) ofield->set_value(0, n1);
349+
else if (value_ == StreamlineValue::DistanceFromSeed) ofield->set_value(partialStreamlineLength, n1);
350+
else if (value_ == StreamlineValue::StreamlineLength) ofield->set_value(totalLength, n1);
354351

355-
while (node_iter != nodes.end())
352+
cc++;
353+
}
354+
else
356355
{
357-
n2 = omesh->add_point(*node_iter);
356+
n2 = omesh->add_point(node);
358357
ofield->resize_fdata();
359358

360359
if (value_ == StreamlineValue::SeedValue) ofield->copy_value(seed_field_, idx, n2);
361360
else if (value_ == StreamlineValue::SeedIndex) ofield->set_value(index_type(idx), n2);
362361
else if (value_ == StreamlineValue::IntegrationIndex) ofield->set_value(abs(cc), n2);
363362
else if (value_ == StreamlineValue::IntegrationStep)
364363
{
365-
auto length = Vector(*node_iter - p1).length();
364+
double length = Vector(node - previousNode).length();
366365
ofield->set_value(length, n2);
367366
}
368367
else if (value_ == StreamlineValue::DistanceFromSeed)
369368
{
370-
distanceFromSeedLength += Vector(*node_iter - p1).length();
371-
ofield->set_value(distanceFromSeedLength, n2);
369+
partialStreamlineLength += Vector(node - previousNode).length();
370+
ofield->set_value(partialStreamlineLength, n2);
372371
}
373372
else if (value_ == StreamlineValue::StreamlineLength)
374373
{
@@ -380,10 +379,11 @@ namespace detail
380379

381380
omesh->add_elem(newnodes);
382381
n1 = n2;
383-
++node_iter;
384382

385383
cc++;
386384
}
385+
++nodeIndex;
386+
previousNode = node;
387387
}
388388
}
389389

0 commit comments

Comments
 (0)