Particle advection test fix
-Added a worklet to execute evaluator test on device -Fixing various compile issues
This commit is contained in:
parent
e99567fe16
commit
9714ea36fa
@ -64,7 +64,7 @@ public:
|
||||
dirBounds[2] = static_cast<FieldType>(dir[2] > 0 ? bounds.Z.Max : bounds.Z.Min);
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT
|
||||
VTKM_EXEC
|
||||
bool Evaluate(const vtkm::Vec<FieldType, 3>& pos, vtkm::Vec<FieldType, 3>& out) const
|
||||
{
|
||||
if (!bounds.Contains(pos))
|
||||
@ -108,8 +108,7 @@ public:
|
||||
dirBounds[2] = static_cast<FieldType>(dir[2] > 0 ? bounds.Z.Max : bounds.Z.Min);
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT bool Evaluate(const vtkm::Vec<FieldType, 3>& pos,
|
||||
vtkm::Vec<FieldType, 3>& out) const
|
||||
VTKM_EXEC bool Evaluate(const vtkm::Vec<FieldType, 3>& pos, vtkm::Vec<FieldType, 3>& out) const
|
||||
{
|
||||
if (!bounds.Contains(pos))
|
||||
return false;
|
||||
@ -218,7 +217,7 @@ public:
|
||||
dirBounds[2] = static_cast<FieldType>(dir[2] > 0 ? bounds.Z.Max : bounds.Z.Min);
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT
|
||||
VTKM_EXEC
|
||||
bool Evaluate(const vtkm::Vec<FieldType, 3>& pos, vtkm::Vec<FieldType, 3>& out) const
|
||||
{
|
||||
if (!bounds.Contains(pos))
|
||||
@ -385,7 +384,7 @@ public:
|
||||
dirBounds[2] = static_cast<FieldType>(dir[2] > 0 ? bounds.Z.Max : bounds.Z.Min);
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT
|
||||
VTKM_EXEC
|
||||
bool Evaluate(const vtkm::Vec<FieldType, 3>& pos, vtkm::Vec<FieldType, 3>& out) const
|
||||
{
|
||||
if (!bounds.Contains(pos))
|
||||
|
@ -170,16 +170,58 @@ void CreateConstantVectorField(vtkm::Id num,
|
||||
DeviceAlgorithm::Copy(vecConst, vecField);
|
||||
}
|
||||
|
||||
template <typename FieldType, typename Evaluator>
|
||||
class TestEvaluatorWorklet : public vtkm::worklet::WorkletMapField
|
||||
{
|
||||
public:
|
||||
TestEvaluatorWorklet(Evaluator e)
|
||||
: evaluator(e){};
|
||||
|
||||
typedef void ControlSignature(FieldIn<> inputPoint, FieldOut<> validity, FieldOut<> outputPoint);
|
||||
|
||||
typedef void ExecutionSignature(_1, _2, _3);
|
||||
|
||||
VTKM_EXEC
|
||||
void operator()(vtkm::Vec<FieldType, 3>& pointIn,
|
||||
bool& validity,
|
||||
vtkm::Vec<FieldType, 3>& pointOut) const
|
||||
{
|
||||
validity = evaluator.Evaluate(pointIn, pointOut);
|
||||
}
|
||||
|
||||
private:
|
||||
Evaluator evaluator;
|
||||
};
|
||||
|
||||
template <typename EvalType, typename FieldType>
|
||||
void ValidateEvaluator(const EvalType& eval,
|
||||
const vtkm::Vec<FieldType, 3>& p,
|
||||
const std::vector<vtkm::Vec<FieldType, 3>>& pointIns,
|
||||
const vtkm::Vec<FieldType, 3>& vec,
|
||||
const std::string& msg)
|
||||
{
|
||||
vtkm::Vec<FieldType, 3> result;
|
||||
bool val = eval.Evaluate(p, result);
|
||||
VTKM_TEST_ASSERT(val, "Error in evaluator for " + msg);
|
||||
VTKM_TEST_ASSERT(result == vec, "Error in evaluator result for " + msg);
|
||||
typedef TestEvaluatorWorklet<FieldType, EvalType> EvalTester;
|
||||
typedef vtkm::worklet::DispatcherMapField<EvalTester> EvalTesterDispatcher;
|
||||
EvalTester evalTester(eval);
|
||||
EvalTesterDispatcher evalTesterDispatcher(evalTester);
|
||||
vtkm::cont::ArrayHandle<vtkm::Vec<FieldType, 3>> pointsHandle =
|
||||
vtkm::cont::make_ArrayHandle(pointIns);
|
||||
vtkm::Id numPoints = pointsHandle.GetNumberOfValues();
|
||||
vtkm::cont::ArrayHandle<bool> evalStatus;
|
||||
vtkm::cont::ArrayHandle<vtkm::Vec<FieldType, 3>> evalResults;
|
||||
evalStatus.Allocate(numPoints);
|
||||
evalResults.Allocate(numPoints);
|
||||
evalTesterDispatcher.Invoke(pointsHandle, evalStatus, evalResults);
|
||||
auto statusPortal = evalStatus.GetPortalConstControl();
|
||||
auto resultsPortal = evalResults.GetPortalConstControl();
|
||||
for (vtkm::Id index = 0; index < numPoints; index++)
|
||||
{
|
||||
bool status = statusPortal.Get(index);
|
||||
vtkm::Vec<FieldType, 3> result = resultsPortal.Get(index);
|
||||
std::cout << "Testing : " << status << ", vec {" << result[0] << ", " << result[1] << ", "
|
||||
<< result[2] << "}" << std::endl;
|
||||
VTKM_TEST_ASSERT(status, "Error in evaluator for " + msg);
|
||||
VTKM_TEST_ASSERT(result == vec, "Error in evaluator result for " + msg);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename IntegratorType, typename FieldType>
|
||||
@ -194,7 +236,6 @@ void ValidateIntegrator(const IntegratorType& integrator,
|
||||
VTKM_TEST_ASSERT(result == q, "Error in integrator result for " + msg);
|
||||
}
|
||||
|
||||
|
||||
void TestEvaluators()
|
||||
{
|
||||
typedef VTKM_DEFAULT_DEVICE_ADAPTER_TAG DeviceAdapter;
|
||||
@ -224,7 +265,6 @@ void TestEvaluators()
|
||||
typedef vtkm::worklet::particleadvection::RK4Integrator<RectilinearEvalType, FieldType>
|
||||
RK4RectilinearType;
|
||||
|
||||
|
||||
std::vector<vtkm::Vec<FieldType, 3>> vecs;
|
||||
vecs.push_back(vtkm::Vec<FieldType, 3>(1, 0, 0));
|
||||
vecs.push_back(vtkm::Vec<FieldType, 3>(0, 1, 0));
|
||||
@ -284,11 +324,10 @@ void TestEvaluators()
|
||||
RectilinearEvalType rectEval(
|
||||
rectData.GetCoordinateSystem(), rectData.GetCellSet(0), vecField);
|
||||
RK4RectilinearType rectRK4(rectEval, stepSize);
|
||||
|
||||
std::vector<vtkm::Vec<FieldType, 3>> pointIns;
|
||||
//Create a bunch of random points in the bounds.
|
||||
for (int k = 0; k < 38; k++)
|
||||
{
|
||||
|
||||
//Generate points 2 steps inside the bounding box.
|
||||
vtkm::Bounds interiorBounds = bounds[j];
|
||||
interiorBounds.X.Min += 2 * stepSize;
|
||||
@ -297,21 +336,20 @@ void TestEvaluators()
|
||||
interiorBounds.X.Max -= 2 * stepSize;
|
||||
interiorBounds.Y.Max -= 2 * stepSize;
|
||||
interiorBounds.Z.Max -= 2 * stepSize;
|
||||
|
||||
vtkm::Vec<FieldType, 3> p;
|
||||
RandomPoint<FieldType>(interiorBounds, p);
|
||||
|
||||
//Test the result for the evaluator
|
||||
ValidateEvaluator(constEval, p, vec, "constant vector evaluator");
|
||||
ValidateEvaluator(uniformEval, p, vec, "uniform evaluator");
|
||||
ValidateEvaluator(rectEval, p, vec, "rectilinear evaluator");
|
||||
|
||||
//Test taking one step.
|
||||
vtkm::Vec<FieldType, 3> result = p + vec * stepSize;
|
||||
ValidateIntegrator(constRK4, p, result, "constant vector RK4");
|
||||
ValidateIntegrator(uniformRK4, p, result, "uniform RK4");
|
||||
ValidateIntegrator(rectRK4, p, result, "rectilinear RK4");
|
||||
pointIns.push_back(p);
|
||||
}
|
||||
//Test the result for the evaluator
|
||||
ValidateEvaluator(constEval, pointIns, vec, "constant vector evaluator");
|
||||
ValidateEvaluator(uniformEval, pointIns, vec, "uniform evaluator");
|
||||
ValidateEvaluator(rectEval, pointIns, vec, "rectilinear evaluator");
|
||||
|
||||
//Test taking one step.
|
||||
//vtkm::Vec<FieldType, 3> result = p + vec * stepSize;
|
||||
/*ValidateIntegrator(constRK4, p, result, "constant vector RK4");
|
||||
ValidateIntegrator(uniformRK4, p, result, "uniform RK4");
|
||||
ValidateIntegrator(rectRK4, p, result, "rectilinear RK4");*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user