mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-08 13:23:51 +00:00
Move NewtonsMethod to the vtkm package
All the other math functions are in the vtkm package. This one was in vtkm::exec because it uses a callback method. This can be problematic on CUDA the the declaration of NewtonsMethod does not match the callback method. However, we now have a VTKM_SUPPRESS_EXEC_WARNINGS macro that allows a VTKM_EXEC_CONT_EXPORT function (like NewtonsMethod) to call either a VTKM_EXEC_EXPORT or VTKM_CONT_EXPORT without a warning.
This commit is contained in:
parent
331759099a
commit
c503e0ce8a
@ -29,6 +29,7 @@ set(headers
|
||||
ListTag.h
|
||||
Math.h
|
||||
Matrix.h
|
||||
NewtonsMethod.h
|
||||
Pair.h
|
||||
StaticAssert.h
|
||||
TopologyElementTag.h
|
||||
|
@ -17,14 +17,13 @@
|
||||
// Laboratory (LANL), the U.S. Government retains certain rights in
|
||||
// this software.
|
||||
//============================================================================
|
||||
#ifndef vtk_m_exec_NewtonsMethod_h
|
||||
#define vtk_m_exec_NewtonsMethod_h
|
||||
#ifndef vtk_m_NewtonsMethod_h
|
||||
#define vtk_m_NewtonsMethod_h
|
||||
|
||||
#include <vtkm/Math.h>
|
||||
#include <vtkm/Matrix.h>
|
||||
|
||||
namespace vtkm {
|
||||
namespace exec {
|
||||
|
||||
/// Uses Newton's method (a.k.a. Newton-Raphson method) to solve a nonlinear
|
||||
/// system of equations. This function assumes that the number of variables
|
||||
@ -36,11 +35,12 @@ namespace exec {
|
||||
/// that evaluates to the desired output, or the closest point found, is
|
||||
/// returned.
|
||||
///
|
||||
VTKM_SUPPRESS_EXEC_WARNINGS
|
||||
template<typename ScalarType,
|
||||
vtkm::IdComponent Size,
|
||||
typename JacobianFunctor,
|
||||
typename FunctionFunctor>
|
||||
VTKM_EXEC_EXPORT
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
vtkm::Vec<ScalarType,Size>
|
||||
NewtonsMethod(JacobianFunctor jacobianEvaluator,
|
||||
FunctionFunctor functionEvaluator,
|
||||
@ -92,7 +92,6 @@ NewtonsMethod(JacobianFunctor jacobianEvaluator,
|
||||
return x;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace vtkm::exec
|
||||
} // namespace vtkm
|
||||
|
||||
#endif //vtk_m_exec_NewtonsMethod_h
|
||||
#endif //vtk_m_NewtonsMethod_h
|
@ -29,7 +29,6 @@ set(headers
|
||||
ExecutionObjectBase.h
|
||||
ExecutionWholeArray.h
|
||||
FunctorBase.h
|
||||
NewtonsMethod.h
|
||||
ParametricCoordinates.h
|
||||
)
|
||||
|
||||
|
@ -22,12 +22,12 @@
|
||||
|
||||
#include <vtkm/CellShape.h>
|
||||
#include <vtkm/Math.h>
|
||||
#include <vtkm/NewtonsMethod.h>
|
||||
#include <vtkm/VecRectilinearPointCoordinates.h>
|
||||
#include <vtkm/exec/Assert.h>
|
||||
#include <vtkm/exec/CellDerivative.h>
|
||||
#include <vtkm/exec/CellInterpolate.h>
|
||||
#include <vtkm/exec/FunctorBase.h>
|
||||
#include <vtkm/exec/NewtonsMethod.h>
|
||||
|
||||
namespace vtkm {
|
||||
namespace exec {
|
||||
@ -644,7 +644,7 @@ WorldCoordinatesToParametricCoordinates3D(
|
||||
CellShapeTag,
|
||||
const vtkm::exec::FunctorBase &worklet)
|
||||
{
|
||||
return vtkm::exec::NewtonsMethod(
|
||||
return vtkm::NewtonsMethod(
|
||||
JacobianFunctor3DCell<WorldCoordVector,CellShapeTag>(&pointWCoords),
|
||||
CoordinatesFunctor3DCell<WorldCoordVector,CellShapeTag>(&pointWCoords, &worklet),
|
||||
wcoords,
|
||||
@ -917,7 +917,7 @@ WorldCoordinatesToParametricCoordinates(
|
||||
pointWCoords[0], pointWCoords[1], pointWCoords[3]);
|
||||
|
||||
Vector2 pcoords =
|
||||
vtkm::exec::NewtonsMethod(
|
||||
vtkm::NewtonsMethod(
|
||||
detail::JacobianFunctorQuad<WorldCoordVector,vtkm::CellShapeTagQuad>(&pointWCoords, &space),
|
||||
detail::CoordinatesFunctorQuad<WorldCoordVector,vtkm::CellShapeTagQuad>(&pointWCoords, &space, &worklet),
|
||||
space.ConvertCoordToSpace(wcoords),
|
||||
|
@ -23,7 +23,6 @@
|
||||
set(unit_tests
|
||||
UnitTestCellDerivative.cxx
|
||||
UnitTestCellInterpolate.cxx
|
||||
UnitTestNewtonsMethod.cxx
|
||||
UnitTestParametricCoordinates.cxx
|
||||
)
|
||||
vtkm_unit_tests(SOURCES ${unit_tests})
|
||||
|
@ -36,6 +36,7 @@ set(unit_tests
|
||||
UnitTestListTag.cxx
|
||||
UnitTestMath.cxx
|
||||
UnitTestMatrix.cxx
|
||||
UnitTestNewtonsMethod.cxx
|
||||
UnitTestPair.cxx
|
||||
UnitTestTesting.cxx
|
||||
UnitTestTypeListTag.cxx
|
||||
|
@ -18,7 +18,7 @@
|
||||
// this software.
|
||||
//============================================================================
|
||||
|
||||
#include <vtkm/exec/NewtonsMethod.h>
|
||||
#include <vtkm/NewtonsMethod.h>
|
||||
|
||||
#include <vtkm/testing/Testing.h>
|
||||
|
||||
@ -37,7 +37,7 @@ struct EvaluateFunctions
|
||||
{
|
||||
typedef vtkm::Vec<T,3> Vector3;
|
||||
|
||||
VTKM_EXEC_EXPORT
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
Vector3 operator()(Vector3 x) const
|
||||
{
|
||||
Vector3 fx;
|
||||
@ -53,7 +53,7 @@ struct EvaluateJacobian
|
||||
typedef vtkm::Vec<T,3> Vector3;
|
||||
typedef vtkm::Matrix<T,3,3> Matrix3x3;
|
||||
|
||||
VTKM_EXEC_EXPORT
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
Matrix3x3 operator()(Vector3 x) const {
|
||||
Matrix3x3 jacobian;
|
||||
jacobian(0,0) = 2*x[0]; jacobian(0,1) = 2*x[1]; jacobian(0,2) = 2*x[2];
|
||||
@ -84,11 +84,11 @@ void TestNewtonsMethodTemplate()
|
||||
std::cout << " " << initialGuess << std::endl;
|
||||
|
||||
Vector3 solution =
|
||||
vtkm::exec::NewtonsMethod(EvaluateJacobian<T>(),
|
||||
EvaluateFunctions<T>(),
|
||||
desiredOutput,
|
||||
initialGuess,
|
||||
T(1e-6));
|
||||
vtkm::NewtonsMethod(EvaluateJacobian<T>(),
|
||||
EvaluateFunctions<T>(),
|
||||
desiredOutput,
|
||||
initialGuess,
|
||||
T(1e-6));
|
||||
|
||||
VTKM_TEST_ASSERT(test_equal(solution, expected1)
|
||||
|| test_equal(solution, expected2),
|
Loading…
Reference in New Issue
Block a user