netgen-mesher 6.2.2506.post35.dev0__cp314-cp314-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- netgen/NgOCC.py +7 -0
- netgen/__init__.py +114 -0
- netgen/__init__.pyi +22 -0
- netgen/__main__.py +53 -0
- netgen/cmake/NetgenConfig.cmake +79 -0
- netgen/cmake/netgen-targets-release.cmake +69 -0
- netgen/cmake/netgen-targets.cmake +146 -0
- netgen/config/__init__.py +1 -0
- netgen/config/__init__.pyi +52 -0
- netgen/config/__main__.py +4 -0
- netgen/config/config.py +68 -0
- netgen/config/config.pyi +54 -0
- netgen/csg.py +25 -0
- netgen/geom2d.py +178 -0
- netgen/gui.py +82 -0
- netgen/include/core/archive.hpp +1256 -0
- netgen/include/core/array.hpp +1760 -0
- netgen/include/core/autodiff.hpp +1131 -0
- netgen/include/core/autodiffdiff.hpp +733 -0
- netgen/include/core/bitarray.hpp +240 -0
- netgen/include/core/concurrentqueue.h +3619 -0
- netgen/include/core/exception.hpp +145 -0
- netgen/include/core/flags.hpp +199 -0
- netgen/include/core/hashtable.hpp +1281 -0
- netgen/include/core/localheap.hpp +318 -0
- netgen/include/core/logging.hpp +117 -0
- netgen/include/core/memtracer.hpp +221 -0
- netgen/include/core/mpi4py_pycapi.h +245 -0
- netgen/include/core/mpi_wrapper.hpp +643 -0
- netgen/include/core/ng_mpi.hpp +94 -0
- netgen/include/core/ng_mpi_generated_declarations.hpp +155 -0
- netgen/include/core/ng_mpi_native.hpp +25 -0
- netgen/include/core/ngcore.hpp +32 -0
- netgen/include/core/ngcore_api.hpp +152 -0
- netgen/include/core/ngstream.hpp +115 -0
- netgen/include/core/paje_trace.hpp +279 -0
- netgen/include/core/profiler.hpp +382 -0
- netgen/include/core/python_ngcore.hpp +457 -0
- netgen/include/core/ranges.hpp +109 -0
- netgen/include/core/register_archive.hpp +100 -0
- netgen/include/core/signal.hpp +82 -0
- netgen/include/core/simd.hpp +160 -0
- netgen/include/core/simd_arm64.hpp +407 -0
- netgen/include/core/simd_avx.hpp +394 -0
- netgen/include/core/simd_avx512.hpp +285 -0
- netgen/include/core/simd_generic.hpp +1053 -0
- netgen/include/core/simd_math.hpp +178 -0
- netgen/include/core/simd_sse.hpp +289 -0
- netgen/include/core/statushandler.hpp +37 -0
- netgen/include/core/symboltable.hpp +153 -0
- netgen/include/core/table.hpp +810 -0
- netgen/include/core/taskmanager.hpp +1161 -0
- netgen/include/core/type_traits.hpp +65 -0
- netgen/include/core/utils.hpp +385 -0
- netgen/include/core/version.hpp +102 -0
- netgen/include/core/xbool.hpp +47 -0
- netgen/include/csg/algprim.hpp +563 -0
- netgen/include/csg/brick.hpp +150 -0
- netgen/include/csg/csg.hpp +43 -0
- netgen/include/csg/csgeom.hpp +389 -0
- netgen/include/csg/csgparser.hpp +101 -0
- netgen/include/csg/curve2d.hpp +67 -0
- netgen/include/csg/edgeflw.hpp +112 -0
- netgen/include/csg/explicitcurve2d.hpp +113 -0
- netgen/include/csg/extrusion.hpp +185 -0
- netgen/include/csg/gencyl.hpp +70 -0
- netgen/include/csg/geoml.hpp +16 -0
- netgen/include/csg/identify.hpp +213 -0
- netgen/include/csg/manifold.hpp +29 -0
- netgen/include/csg/meshsurf.hpp +46 -0
- netgen/include/csg/polyhedra.hpp +121 -0
- netgen/include/csg/revolution.hpp +180 -0
- netgen/include/csg/singularref.hpp +84 -0
- netgen/include/csg/solid.hpp +295 -0
- netgen/include/csg/specpoin.hpp +194 -0
- netgen/include/csg/spline3d.hpp +99 -0
- netgen/include/csg/splinesurface.hpp +85 -0
- netgen/include/csg/surface.hpp +394 -0
- netgen/include/csg/triapprox.hpp +63 -0
- netgen/include/csg/vscsg.hpp +34 -0
- netgen/include/general/autodiff.hpp +356 -0
- netgen/include/general/autoptr.hpp +39 -0
- netgen/include/general/gzstream.h +121 -0
- netgen/include/general/hashtabl.hpp +1692 -0
- netgen/include/general/myadt.hpp +48 -0
- netgen/include/general/mystring.hpp +226 -0
- netgen/include/general/netgenout.hpp +205 -0
- netgen/include/general/ngarray.hpp +797 -0
- netgen/include/general/ngbitarray.hpp +149 -0
- netgen/include/general/ngpython.hpp +74 -0
- netgen/include/general/optmem.hpp +44 -0
- netgen/include/general/parthreads.hpp +138 -0
- netgen/include/general/seti.hpp +50 -0
- netgen/include/general/sort.hpp +47 -0
- netgen/include/general/spbita2d.hpp +59 -0
- netgen/include/general/stack.hpp +114 -0
- netgen/include/general/table.hpp +280 -0
- netgen/include/general/template.hpp +509 -0
- netgen/include/geom2d/csg2d.hpp +750 -0
- netgen/include/geom2d/geometry2d.hpp +280 -0
- netgen/include/geom2d/spline2d.hpp +234 -0
- netgen/include/geom2d/vsgeom2d.hpp +28 -0
- netgen/include/gprim/adtree.hpp +1392 -0
- netgen/include/gprim/geom2d.hpp +858 -0
- netgen/include/gprim/geom3d.hpp +749 -0
- netgen/include/gprim/geomfuncs.hpp +212 -0
- netgen/include/gprim/geomobjects.hpp +544 -0
- netgen/include/gprim/geomops.hpp +404 -0
- netgen/include/gprim/geomtest3d.hpp +101 -0
- netgen/include/gprim/gprim.hpp +33 -0
- netgen/include/gprim/spline.hpp +778 -0
- netgen/include/gprim/splinegeometry.hpp +73 -0
- netgen/include/gprim/transform3d.hpp +216 -0
- netgen/include/include/acisgeom.hpp +3 -0
- netgen/include/include/csg.hpp +1 -0
- netgen/include/include/geometry2d.hpp +1 -0
- netgen/include/include/gprim.hpp +1 -0
- netgen/include/include/incopengl.hpp +62 -0
- netgen/include/include/inctcl.hpp +13 -0
- netgen/include/include/incvis.hpp +6 -0
- netgen/include/include/linalg.hpp +1 -0
- netgen/include/include/meshing.hpp +1 -0
- netgen/include/include/myadt.hpp +1 -0
- netgen/include/include/mydefs.hpp +70 -0
- netgen/include/include/mystdlib.h +59 -0
- netgen/include/include/netgen_config.hpp +27 -0
- netgen/include/include/netgen_version.hpp +9 -0
- netgen/include/include/nginterface_v2_impl.hpp +395 -0
- netgen/include/include/ngsimd.hpp +1 -0
- netgen/include/include/occgeom.hpp +1 -0
- netgen/include/include/opti.hpp +1 -0
- netgen/include/include/parallel.hpp +1 -0
- netgen/include/include/stlgeom.hpp +1 -0
- netgen/include/include/visual.hpp +1 -0
- netgen/include/interface/rw_medit.hpp +11 -0
- netgen/include/interface/writeuser.hpp +80 -0
- netgen/include/linalg/densemat.hpp +414 -0
- netgen/include/linalg/linalg.hpp +29 -0
- netgen/include/linalg/opti.hpp +142 -0
- netgen/include/linalg/polynomial.hpp +47 -0
- netgen/include/linalg/vector.hpp +217 -0
- netgen/include/meshing/adfront2.hpp +274 -0
- netgen/include/meshing/adfront3.hpp +332 -0
- netgen/include/meshing/basegeom.hpp +370 -0
- netgen/include/meshing/bcfunctions.hpp +53 -0
- netgen/include/meshing/bisect.hpp +72 -0
- netgen/include/meshing/boundarylayer.hpp +113 -0
- netgen/include/meshing/classifyhpel.hpp +1984 -0
- netgen/include/meshing/clusters.hpp +46 -0
- netgen/include/meshing/curvedelems.hpp +274 -0
- netgen/include/meshing/delaunay2d.hpp +73 -0
- netgen/include/meshing/fieldlines.hpp +103 -0
- netgen/include/meshing/findip.hpp +198 -0
- netgen/include/meshing/findip2.hpp +103 -0
- netgen/include/meshing/geomsearch.hpp +69 -0
- netgen/include/meshing/global.hpp +54 -0
- netgen/include/meshing/hpref_hex.hpp +330 -0
- netgen/include/meshing/hpref_prism.hpp +3405 -0
- netgen/include/meshing/hpref_pyramid.hpp +154 -0
- netgen/include/meshing/hpref_quad.hpp +2082 -0
- netgen/include/meshing/hpref_segm.hpp +122 -0
- netgen/include/meshing/hpref_tet.hpp +4230 -0
- netgen/include/meshing/hpref_trig.hpp +848 -0
- netgen/include/meshing/hprefinement.hpp +366 -0
- netgen/include/meshing/improve2.hpp +178 -0
- netgen/include/meshing/improve3.hpp +151 -0
- netgen/include/meshing/localh.hpp +223 -0
- netgen/include/meshing/meshclass.hpp +1076 -0
- netgen/include/meshing/meshfunc.hpp +47 -0
- netgen/include/meshing/meshing.hpp +63 -0
- netgen/include/meshing/meshing2.hpp +163 -0
- netgen/include/meshing/meshing3.hpp +123 -0
- netgen/include/meshing/meshtool.hpp +90 -0
- netgen/include/meshing/meshtype.hpp +1930 -0
- netgen/include/meshing/msghandler.hpp +62 -0
- netgen/include/meshing/paralleltop.hpp +172 -0
- netgen/include/meshing/python_mesh.hpp +206 -0
- netgen/include/meshing/ruler2.hpp +172 -0
- netgen/include/meshing/ruler3.hpp +211 -0
- netgen/include/meshing/soldata.hpp +141 -0
- netgen/include/meshing/specials.hpp +17 -0
- netgen/include/meshing/surfacegeom.hpp +73 -0
- netgen/include/meshing/topology.hpp +1003 -0
- netgen/include/meshing/validate.hpp +21 -0
- netgen/include/meshing/visual_interface.hpp +71 -0
- netgen/include/mydefs.hpp +70 -0
- netgen/include/nginterface.h +474 -0
- netgen/include/nginterface_v2.hpp +406 -0
- netgen/include/nglib.h +697 -0
- netgen/include/nglib_occ.h +50 -0
- netgen/include/occ/occ_edge.hpp +47 -0
- netgen/include/occ/occ_face.hpp +52 -0
- netgen/include/occ/occ_solid.hpp +23 -0
- netgen/include/occ/occ_utils.hpp +376 -0
- netgen/include/occ/occ_vertex.hpp +30 -0
- netgen/include/occ/occgeom.hpp +659 -0
- netgen/include/occ/occmeshsurf.hpp +168 -0
- netgen/include/occ/vsocc.hpp +33 -0
- netgen/include/pybind11/LICENSE +29 -0
- netgen/include/pybind11/attr.h +722 -0
- netgen/include/pybind11/buffer_info.h +208 -0
- netgen/include/pybind11/cast.h +2361 -0
- netgen/include/pybind11/chrono.h +228 -0
- netgen/include/pybind11/common.h +2 -0
- netgen/include/pybind11/complex.h +74 -0
- netgen/include/pybind11/conduit/README.txt +15 -0
- netgen/include/pybind11/conduit/pybind11_conduit_v1.h +116 -0
- netgen/include/pybind11/conduit/pybind11_platform_abi_id.h +87 -0
- netgen/include/pybind11/conduit/wrap_include_python_h.h +72 -0
- netgen/include/pybind11/critical_section.h +56 -0
- netgen/include/pybind11/detail/class.h +823 -0
- netgen/include/pybind11/detail/common.h +1348 -0
- netgen/include/pybind11/detail/cpp_conduit.h +75 -0
- netgen/include/pybind11/detail/descr.h +226 -0
- netgen/include/pybind11/detail/dynamic_raw_ptr_cast_if_possible.h +39 -0
- netgen/include/pybind11/detail/exception_translation.h +71 -0
- netgen/include/pybind11/detail/function_record_pyobject.h +191 -0
- netgen/include/pybind11/detail/init.h +538 -0
- netgen/include/pybind11/detail/internals.h +799 -0
- netgen/include/pybind11/detail/native_enum_data.h +209 -0
- netgen/include/pybind11/detail/pybind11_namespace_macros.h +82 -0
- netgen/include/pybind11/detail/struct_smart_holder.h +378 -0
- netgen/include/pybind11/detail/type_caster_base.h +1591 -0
- netgen/include/pybind11/detail/typeid.h +65 -0
- netgen/include/pybind11/detail/using_smart_holder.h +22 -0
- netgen/include/pybind11/detail/value_and_holder.h +90 -0
- netgen/include/pybind11/eigen/common.h +9 -0
- netgen/include/pybind11/eigen/matrix.h +723 -0
- netgen/include/pybind11/eigen/tensor.h +521 -0
- netgen/include/pybind11/eigen.h +12 -0
- netgen/include/pybind11/embed.h +320 -0
- netgen/include/pybind11/eval.h +161 -0
- netgen/include/pybind11/functional.h +147 -0
- netgen/include/pybind11/gil.h +199 -0
- netgen/include/pybind11/gil_safe_call_once.h +102 -0
- netgen/include/pybind11/gil_simple.h +37 -0
- netgen/include/pybind11/iostream.h +265 -0
- netgen/include/pybind11/native_enum.h +67 -0
- netgen/include/pybind11/numpy.h +2312 -0
- netgen/include/pybind11/operators.h +202 -0
- netgen/include/pybind11/options.h +92 -0
- netgen/include/pybind11/pybind11.h +3645 -0
- netgen/include/pybind11/pytypes.h +2680 -0
- netgen/include/pybind11/stl/filesystem.h +114 -0
- netgen/include/pybind11/stl.h +666 -0
- netgen/include/pybind11/stl_bind.h +858 -0
- netgen/include/pybind11/subinterpreter.h +299 -0
- netgen/include/pybind11/trampoline_self_life_support.h +65 -0
- netgen/include/pybind11/type_caster_pyobject_ptr.h +61 -0
- netgen/include/pybind11/typing.h +298 -0
- netgen/include/pybind11/warnings.h +75 -0
- netgen/include/stlgeom/meshstlsurface.hpp +67 -0
- netgen/include/stlgeom/stlgeom.hpp +491 -0
- netgen/include/stlgeom/stlline.hpp +193 -0
- netgen/include/stlgeom/stltool.hpp +331 -0
- netgen/include/stlgeom/stltopology.hpp +419 -0
- netgen/include/stlgeom/vsstl.hpp +58 -0
- netgen/include/visualization/meshdoc.hpp +42 -0
- netgen/include/visualization/mvdraw.hpp +325 -0
- netgen/include/visualization/vispar.hpp +128 -0
- netgen/include/visualization/visual.hpp +28 -0
- netgen/include/visualization/visual_api.hpp +10 -0
- netgen/include/visualization/vssolution.hpp +399 -0
- netgen/lib/libnggui.lib +0 -0
- netgen/lib/ngcore.lib +0 -0
- netgen/lib/nglib.lib +0 -0
- netgen/lib/togl.lib +0 -0
- netgen/libnggui.dll +0 -0
- netgen/libngguipy.lib +0 -0
- netgen/libngguipy.pyd +0 -0
- netgen/libngpy/_NgOCC.pyi +1545 -0
- netgen/libngpy/__init__.pyi +7 -0
- netgen/libngpy/_csg.pyi +259 -0
- netgen/libngpy/_geom2d.pyi +323 -0
- netgen/libngpy/_meshing.pyi +1111 -0
- netgen/libngpy/_stl.pyi +131 -0
- netgen/libngpy.lib +0 -0
- netgen/libngpy.pyd +0 -0
- netgen/meshing.py +65 -0
- netgen/ngcore.dll +0 -0
- netgen/nglib.dll +0 -0
- netgen/occ.py +52 -0
- netgen/read_gmsh.py +259 -0
- netgen/read_meshio.py +22 -0
- netgen/stl.py +2 -0
- netgen/togl.dll +0 -0
- netgen/version.py +2 -0
- netgen/webgui.py +529 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/boundarycondition.geo +16 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/boxcyl.geo +32 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/circle_on_cube.geo +27 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/cone.geo +13 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/cube.geo +16 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/cubeandring.geo +55 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/cubeandspheres.geo +21 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/cubemcyl.geo +18 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/cubemsphere.geo +19 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/cylinder.geo +12 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/cylsphere.geo +12 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/doc/ng4.pdf +0 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/ellipsoid.geo +8 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/ellipticcyl.geo +10 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/extrusion.geo +99 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/fichera.geo +24 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/frame.step +11683 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/hinge.stl +8486 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/lshape3d.geo +26 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/manyholes.geo +26 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/manyholes2.geo +26 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/matrix.geo +27 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/ortho.geo +11 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/part1.stl +2662 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/period.geo +33 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/py_tutorials/exportNeutral.py +26 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/py_tutorials/mesh.py +19 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/py_tutorials/shaft.geo +65 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/revolution.geo +18 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/screw.step +1694 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/sculpture.geo +13 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/shaft.geo +65 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/shell.geo +10 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/sphere.geo +8 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/sphereincube.geo +17 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/square.in2d +35 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/squarecircle.in2d +48 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/squarehole.in2d +47 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/torus.geo +8 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/trafo.geo +57 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/twobricks.geo +15 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/twocubes.geo +18 -0
- netgen_mesher-6.2.2506.post35.dev0.data/data/share/netgen/twocyl.geo +16 -0
- netgen_mesher-6.2.2506.post35.dev0.dist-info/METADATA +15 -0
- netgen_mesher-6.2.2506.post35.dev0.dist-info/RECORD +340 -0
- netgen_mesher-6.2.2506.post35.dev0.dist-info/WHEEL +5 -0
- netgen_mesher-6.2.2506.post35.dev0.dist-info/entry_points.txt +2 -0
- netgen_mesher-6.2.2506.post35.dev0.dist-info/licenses/AUTHORS +1 -0
- netgen_mesher-6.2.2506.post35.dev0.dist-info/licenses/LICENSE +504 -0
- netgen_mesher-6.2.2506.post35.dev0.dist-info/top_level.txt +2 -0
- pyngcore/__init__.py +1 -0
- pyngcore/pyngcore.cp314-win_amd64.pyd +0 -0
|
@@ -0,0 +1,1131 @@
|
|
|
1
|
+
#ifndef FILE_AUTODIFF
|
|
2
|
+
#define FILE_AUTODIFF
|
|
3
|
+
|
|
4
|
+
/**************************************************************************/
|
|
5
|
+
/* File: autodiff.hpp */
|
|
6
|
+
/* Author: Joachim Schoeberl */
|
|
7
|
+
/* Date: 24. Oct. 02 */
|
|
8
|
+
/**************************************************************************/
|
|
9
|
+
|
|
10
|
+
namespace ngcore
|
|
11
|
+
{
|
|
12
|
+
using ngcore::IfPos;
|
|
13
|
+
|
|
14
|
+
// Automatic differentiation datatype
|
|
15
|
+
|
|
16
|
+
template <int D, typename SCAL = double> class AutoDiffRec;
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
Datatype for automatic differentiation.
|
|
21
|
+
Contains function value and D derivatives. Algebraic
|
|
22
|
+
operations are overloaded by using product-rule etc. etc.
|
|
23
|
+
**/
|
|
24
|
+
template <int D, typename SCAL = double>
|
|
25
|
+
class AutoDiffVec
|
|
26
|
+
{
|
|
27
|
+
SCAL val;
|
|
28
|
+
SCAL dval[D?D:1];
|
|
29
|
+
public:
|
|
30
|
+
|
|
31
|
+
typedef AutoDiffVec<D,SCAL> TELEM;
|
|
32
|
+
typedef SCAL TSCAL;
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
/// elements are undefined
|
|
36
|
+
// NETGEN_INLINE AutoDiffVec () throw() { };
|
|
37
|
+
AutoDiffVec() = default;
|
|
38
|
+
// { val = 0; for (int i = 0; i < D; i++) dval[i] = 0; } // !
|
|
39
|
+
|
|
40
|
+
/// copy constructor
|
|
41
|
+
AutoDiffVec (const AutoDiffVec & ad2) = default;
|
|
42
|
+
/*
|
|
43
|
+
NETGEN_INLINE AutoDiffVec (const AutoDiffVec & ad2) throw()
|
|
44
|
+
{
|
|
45
|
+
val = ad2.val;
|
|
46
|
+
for (int i = 0; i < D; i++)
|
|
47
|
+
dval[i] = ad2.dval[i];
|
|
48
|
+
}
|
|
49
|
+
*/
|
|
50
|
+
/// initial object with constant value
|
|
51
|
+
NETGEN_INLINE AutoDiffVec (SCAL aval) throw()
|
|
52
|
+
{
|
|
53
|
+
val = aval;
|
|
54
|
+
for (int i = 0; i < D; i++)
|
|
55
|
+
dval[i] = 0;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/// init object with (val, e_diffindex)
|
|
59
|
+
NETGEN_INLINE AutoDiffVec (SCAL aval, int diffindex) throw()
|
|
60
|
+
{
|
|
61
|
+
val = aval;
|
|
62
|
+
for (int i = 0; i < D; i++)
|
|
63
|
+
dval[i] = 0;
|
|
64
|
+
dval[diffindex] = 1;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
NETGEN_INLINE AutoDiffVec (SCAL aval, const SCAL * grad)
|
|
68
|
+
{
|
|
69
|
+
val = aval;
|
|
70
|
+
LoadGradient (grad);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/// assign constant value
|
|
74
|
+
NETGEN_INLINE AutoDiffVec & operator= (SCAL aval) throw()
|
|
75
|
+
{
|
|
76
|
+
val = aval;
|
|
77
|
+
for (int i = 0; i < D; i++)
|
|
78
|
+
dval[i] = 0;
|
|
79
|
+
return *this;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
AutoDiffVec & operator= (const AutoDiffVec & ad2) = default;
|
|
83
|
+
|
|
84
|
+
/// returns value
|
|
85
|
+
NETGEN_INLINE SCAL Value() const throw() { return val; }
|
|
86
|
+
|
|
87
|
+
/// returns partial derivative
|
|
88
|
+
NETGEN_INLINE SCAL DValue (int i) const throw() { return dval[i]; }
|
|
89
|
+
|
|
90
|
+
///
|
|
91
|
+
NETGEN_INLINE void StoreGradient (SCAL * p) const
|
|
92
|
+
{
|
|
93
|
+
for (int i = 0; i < D; i++)
|
|
94
|
+
p[i] = dval[i];
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
NETGEN_INLINE void LoadGradient (const SCAL * p)
|
|
98
|
+
{
|
|
99
|
+
for (int i = 0; i < D; i++)
|
|
100
|
+
dval[i] = p[i];
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/// access value
|
|
104
|
+
NETGEN_INLINE SCAL & Value() throw() { return val; }
|
|
105
|
+
|
|
106
|
+
/// accesses partial derivative
|
|
107
|
+
NETGEN_INLINE SCAL & DValue (int i) throw() { return dval[i]; }
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
//@{ AutoDiffVec helper functions.
|
|
112
|
+
|
|
113
|
+
/// prints AutoDiffVec
|
|
114
|
+
template<int D, typename SCAL>
|
|
115
|
+
inline ostream & operator<< (ostream & ost, const AutoDiffVec<D,SCAL> & x)
|
|
116
|
+
{
|
|
117
|
+
ost << x.Value() << ", D = ";
|
|
118
|
+
for (int i = 0; i < D; i++)
|
|
119
|
+
ost << x.DValue(i) << " ";
|
|
120
|
+
return ost;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/// AutoDiffVec plus AutoDiffVec
|
|
124
|
+
template<int D, typename SCAL>
|
|
125
|
+
NETGEN_INLINE AutoDiffVec<D,SCAL> operator+ (const AutoDiffVec<D,SCAL> & x, const AutoDiffVec<D,SCAL> & y) throw()
|
|
126
|
+
{
|
|
127
|
+
AutoDiffVec<D,SCAL> res;
|
|
128
|
+
res.Value () = x.Value()+y.Value();
|
|
129
|
+
// AutoDiffVec<D,SCAL> res(x.Value()+y.Value());
|
|
130
|
+
for (int i = 0; i < D; i++)
|
|
131
|
+
res.DValue(i) = x.DValue(i) + y.DValue(i);
|
|
132
|
+
return res;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
/// AutoDiffVec minus AutoDiffVec
|
|
137
|
+
template<int D, typename SCAL>
|
|
138
|
+
NETGEN_INLINE AutoDiffVec<D,SCAL> operator- (const AutoDiffVec<D,SCAL> & x, const AutoDiffVec<D,SCAL> & y) throw()
|
|
139
|
+
{
|
|
140
|
+
AutoDiffVec<D,SCAL> res;
|
|
141
|
+
res.Value() = x.Value()-y.Value();
|
|
142
|
+
// AutoDiffVec<D,SCAL> res (x.Value()-y.Value());
|
|
143
|
+
for (int i = 0; i < D; i++)
|
|
144
|
+
res.DValue(i) = x.DValue(i) - y.DValue(i);
|
|
145
|
+
return res;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/// double plus AutoDiffVec
|
|
149
|
+
template<int D, typename SCAL, typename SCAL2,
|
|
150
|
+
typename std::enable_if<std::is_convertible<SCAL2,SCAL>::value, int>::type = 0>
|
|
151
|
+
NETGEN_INLINE AutoDiffVec<D,SCAL> operator+ (SCAL2 x, const AutoDiffVec<D,SCAL> & y) throw()
|
|
152
|
+
{
|
|
153
|
+
AutoDiffVec<D,SCAL> res;
|
|
154
|
+
res.Value() = x+y.Value();
|
|
155
|
+
for (int i = 0; i < D; i++)
|
|
156
|
+
res.DValue(i) = y.DValue(i);
|
|
157
|
+
return res;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/// AutoDiffVec plus double
|
|
161
|
+
template<int D, typename SCAL, typename SCAL2,
|
|
162
|
+
typename std::enable_if<std::is_convertible<SCAL2,SCAL>::value, int>::type = 0>
|
|
163
|
+
NETGEN_INLINE AutoDiffVec<D,SCAL> operator+ (const AutoDiffVec<D,SCAL> & y, SCAL2 x) throw()
|
|
164
|
+
{
|
|
165
|
+
AutoDiffVec<D,SCAL> res;
|
|
166
|
+
res.Value() = x+y.Value();
|
|
167
|
+
for (int i = 0; i < D; i++)
|
|
168
|
+
res.DValue(i) = y.DValue(i);
|
|
169
|
+
return res;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
/// minus AutoDiffVec
|
|
174
|
+
template<int D, typename SCAL>
|
|
175
|
+
NETGEN_INLINE AutoDiffVec<D,SCAL> operator- (const AutoDiffVec<D,SCAL> & x) throw()
|
|
176
|
+
{
|
|
177
|
+
AutoDiffVec<D,SCAL> res;
|
|
178
|
+
res.Value() = -x.Value();
|
|
179
|
+
for (int i = 0; i < D; i++)
|
|
180
|
+
res.DValue(i) = -x.DValue(i);
|
|
181
|
+
return res;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/// AutoDiffVec minus double
|
|
185
|
+
template<int D, typename SCAL, typename SCAL2,
|
|
186
|
+
typename std::enable_if<std::is_convertible<SCAL2,SCAL>::value, int>::type = 0>
|
|
187
|
+
NETGEN_INLINE AutoDiffVec<D,SCAL> operator- (const AutoDiffVec<D,SCAL> & x, SCAL2 y) throw()
|
|
188
|
+
{
|
|
189
|
+
AutoDiffVec<D,SCAL> res;
|
|
190
|
+
res.Value() = x.Value()-y;
|
|
191
|
+
for (int i = 0; i < D; i++)
|
|
192
|
+
res.DValue(i) = x.DValue(i);
|
|
193
|
+
return res;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
///
|
|
197
|
+
template<int D, typename SCAL, typename SCAL2,
|
|
198
|
+
typename std::enable_if<std::is_convertible<SCAL2,SCAL>::value, int>::type = 0>
|
|
199
|
+
NETGEN_INLINE AutoDiffVec<D,SCAL> operator- (SCAL2 x, const AutoDiffVec<D,SCAL> & y) throw()
|
|
200
|
+
{
|
|
201
|
+
AutoDiffVec<D,SCAL> res;
|
|
202
|
+
res.Value() = x-y.Value();
|
|
203
|
+
for (int i = 0; i < D; i++)
|
|
204
|
+
res.DValue(i) = -y.DValue(i);
|
|
205
|
+
return res;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
/// double times AutoDiffVec
|
|
210
|
+
template<int D, typename SCAL, typename SCAL2,
|
|
211
|
+
typename std::enable_if<std::is_convertible<SCAL2,SCAL>::value, int>::type = 0>
|
|
212
|
+
NETGEN_INLINE AutoDiffVec<D,SCAL> operator* (SCAL2 x, const AutoDiffVec<D,SCAL> & y) throw()
|
|
213
|
+
{
|
|
214
|
+
AutoDiffVec<D,SCAL> res;
|
|
215
|
+
res.Value() = x*y.Value();
|
|
216
|
+
for (int i = 0; i < D; i++)
|
|
217
|
+
res.DValue(i) = x*y.DValue(i);
|
|
218
|
+
return res;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/// AutoDiffVec times double
|
|
222
|
+
template<int D, typename SCAL, typename SCAL2,
|
|
223
|
+
typename std::enable_if<std::is_convertible<SCAL2,SCAL>::value, int>::type = 0>
|
|
224
|
+
|
|
225
|
+
NETGEN_INLINE AutoDiffVec<D,SCAL> operator* (const AutoDiffVec<D,SCAL> & y, SCAL2 x) throw()
|
|
226
|
+
{
|
|
227
|
+
AutoDiffVec<D,SCAL> res;
|
|
228
|
+
res.Value() = x*y.Value();
|
|
229
|
+
for (int i = 0; i < D; i++)
|
|
230
|
+
res.DValue(i) = x*y.DValue(i);
|
|
231
|
+
return res;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/// AutoDiffVec times AutoDiffVec
|
|
235
|
+
template<int D, typename SCAL>
|
|
236
|
+
NETGEN_INLINE AutoDiffVec<D,SCAL> operator* (const AutoDiffVec<D,SCAL> & x, const AutoDiffVec<D,SCAL> & y) throw()
|
|
237
|
+
{
|
|
238
|
+
AutoDiffVec<D,SCAL> res;
|
|
239
|
+
SCAL hx = x.Value();
|
|
240
|
+
SCAL hy = y.Value();
|
|
241
|
+
|
|
242
|
+
res.Value() = hx*hy;
|
|
243
|
+
for (int i = 0; i < D; i++)
|
|
244
|
+
res.DValue(i) = hx*y.DValue(i) + hy*x.DValue(i);
|
|
245
|
+
|
|
246
|
+
return res;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/// AutoDiffVec times AutoDiffVec
|
|
250
|
+
using ngcore::sqr;
|
|
251
|
+
template<int D, typename SCAL>
|
|
252
|
+
NETGEN_INLINE AutoDiffVec<D,SCAL> sqr (const AutoDiffVec<D,SCAL> & x) throw()
|
|
253
|
+
{
|
|
254
|
+
AutoDiffVec<D,SCAL> res;
|
|
255
|
+
SCAL hx = x.Value();
|
|
256
|
+
res.Value() = hx*hx;
|
|
257
|
+
hx *= 2;
|
|
258
|
+
for (int i = 0; i < D; i++)
|
|
259
|
+
res.DValue(i) = hx*x.DValue(i);
|
|
260
|
+
return res;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/// Inverse of AutoDiffVec
|
|
264
|
+
template<int D, typename SCAL>
|
|
265
|
+
NETGEN_INLINE AutoDiffVec<D,SCAL> Inv (const AutoDiffVec<D,SCAL> & x)
|
|
266
|
+
{
|
|
267
|
+
AutoDiffVec<D,SCAL> res(1.0 / x.Value());
|
|
268
|
+
for (int i = 0; i < D; i++)
|
|
269
|
+
res.DValue(i) = -x.DValue(i) / (x.Value() * x.Value());
|
|
270
|
+
return res;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
/// AutoDiffVec div AutoDiffVec
|
|
275
|
+
template<int D, typename SCAL>
|
|
276
|
+
NETGEN_INLINE AutoDiffVec<D,SCAL> operator/ (const AutoDiffVec<D,SCAL> & x, const AutoDiffVec<D,SCAL> & y)
|
|
277
|
+
{
|
|
278
|
+
return x * Inv (y);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/// AutoDiffVec div double
|
|
282
|
+
template<int D, typename SCAL, typename SCAL2,
|
|
283
|
+
typename std::enable_if<std::is_convertible<SCAL2,SCAL>::value, int>::type = 0>
|
|
284
|
+
NETGEN_INLINE AutoDiffVec<D,SCAL> operator/ (const AutoDiffVec<D,SCAL> & x, SCAL2 y)
|
|
285
|
+
{
|
|
286
|
+
return (1.0/y) * x;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/// double div AutoDiffVec
|
|
290
|
+
template<int D, typename SCAL, typename SCAL2,
|
|
291
|
+
typename std::enable_if<std::is_convertible<SCAL2,SCAL>::value, int>::type = 0>
|
|
292
|
+
NETGEN_INLINE AutoDiffVec<D,SCAL> operator/ (SCAL2 x, const AutoDiffVec<D,SCAL> & y)
|
|
293
|
+
{
|
|
294
|
+
return x * Inv(y);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
template <int D, typename SCAL, typename SCAL2>
|
|
301
|
+
NETGEN_INLINE AutoDiffVec<D,SCAL> & operator+= (AutoDiffVec<D,SCAL> & x, SCAL2 y) throw()
|
|
302
|
+
{
|
|
303
|
+
x.Value() += y;
|
|
304
|
+
return x;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
///
|
|
309
|
+
template <int D, typename SCAL>
|
|
310
|
+
NETGEN_INLINE AutoDiffVec<D,SCAL> & operator+= (AutoDiffVec<D,SCAL> & x, AutoDiffVec<D,SCAL> y)
|
|
311
|
+
{
|
|
312
|
+
x.Value() += y.Value();
|
|
313
|
+
for (int i = 0; i < D; i++)
|
|
314
|
+
x.DValue(i) += y.DValue(i);
|
|
315
|
+
return x;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
///
|
|
319
|
+
template <int D, typename SCAL>
|
|
320
|
+
NETGEN_INLINE AutoDiffVec<D,SCAL> & operator-= (AutoDiffVec<D,SCAL> & x, AutoDiffVec<D,SCAL> y)
|
|
321
|
+
{
|
|
322
|
+
x.Value() -= y.Value();
|
|
323
|
+
for (int i = 0; i < D; i++)
|
|
324
|
+
x.DValue(i) -= y.DValue(i);
|
|
325
|
+
return x;
|
|
326
|
+
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
template <int D, typename SCAL, typename SCAL2>
|
|
330
|
+
NETGEN_INLINE AutoDiffVec<D,SCAL> & operator-= (AutoDiffVec<D,SCAL> & x, SCAL2 y)
|
|
331
|
+
{
|
|
332
|
+
x.Value() -= y;
|
|
333
|
+
return x;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
///
|
|
337
|
+
template <int D, typename SCAL>
|
|
338
|
+
NETGEN_INLINE AutoDiffVec<D,SCAL> & operator*= (AutoDiffVec<D,SCAL> & x, AutoDiffVec<D,SCAL> y)
|
|
339
|
+
{
|
|
340
|
+
for (int i = 0; i < D; i++)
|
|
341
|
+
x.DValue(i) = x.DValue(i)*y.Value() + x.Value() * y.DValue(i);
|
|
342
|
+
x.Value() *= y.Value();
|
|
343
|
+
return x;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
///
|
|
347
|
+
template <int D, typename SCAL, typename SCAL2>
|
|
348
|
+
NETGEN_INLINE AutoDiffVec<D,SCAL> & operator*= (AutoDiffVec<D,SCAL> & x, SCAL2 y)
|
|
349
|
+
{
|
|
350
|
+
x.Value() *= y;
|
|
351
|
+
for (int i = 0; i < D; i++)
|
|
352
|
+
x.DValue(i) *= y;
|
|
353
|
+
return x;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
///
|
|
357
|
+
template <int D, typename SCAL>
|
|
358
|
+
NETGEN_INLINE AutoDiffVec<D,SCAL> & operator/= (AutoDiffVec<D,SCAL> & x, SCAL y)
|
|
359
|
+
{
|
|
360
|
+
SCAL iy = 1.0 / y;
|
|
361
|
+
x.Value() *= iy;
|
|
362
|
+
for (int i = 0; i < D; i++)
|
|
363
|
+
x.DValue(i) *= iy;
|
|
364
|
+
return x;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
///
|
|
371
|
+
template <int D, typename SCAL>
|
|
372
|
+
NETGEN_INLINE bool operator== (AutoDiffVec<D,SCAL> x, SCAL val2)
|
|
373
|
+
{
|
|
374
|
+
return x.Value() == val2;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
///
|
|
378
|
+
template <int D, typename SCAL>
|
|
379
|
+
NETGEN_INLINE bool operator!= (AutoDiffVec<D,SCAL> x, SCAL val2) throw()
|
|
380
|
+
{
|
|
381
|
+
return x.Value() != val2;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
///
|
|
385
|
+
template <int D, typename SCAL>
|
|
386
|
+
NETGEN_INLINE bool operator< (AutoDiffVec<D,SCAL> x, SCAL val2) throw()
|
|
387
|
+
{
|
|
388
|
+
return x.Value() < val2;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
///
|
|
392
|
+
template <int D, typename SCAL>
|
|
393
|
+
NETGEN_INLINE bool operator> (AutoDiffVec<D,SCAL> x, SCAL val2) throw()
|
|
394
|
+
{
|
|
395
|
+
return x.Value() > val2;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
template<int D, typename SCAL>
|
|
402
|
+
NETGEN_INLINE AutoDiffVec<D,SCAL> fabs (const AutoDiffVec<D,SCAL> & x)
|
|
403
|
+
{
|
|
404
|
+
double abs = fabs (x.Value());
|
|
405
|
+
AutoDiffVec<D,SCAL> res( abs );
|
|
406
|
+
if (abs != 0.0)
|
|
407
|
+
for (int i = 0; i < D; i++)
|
|
408
|
+
res.DValue(i) = x.Value()*x.DValue(i) / abs;
|
|
409
|
+
else
|
|
410
|
+
for (int i = 0; i < D; i++)
|
|
411
|
+
res.DValue(i) = 0.0;
|
|
412
|
+
return res;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
using std::sqrt;
|
|
416
|
+
template<int D, typename SCAL>
|
|
417
|
+
NETGEN_INLINE AutoDiffVec<D,SCAL> sqrt (const AutoDiffVec<D,SCAL> & x)
|
|
418
|
+
{
|
|
419
|
+
AutoDiffVec<D,SCAL> res;
|
|
420
|
+
res.Value() = sqrt(x.Value());
|
|
421
|
+
for (int j = 0; j < D; j++)
|
|
422
|
+
res.DValue(j) = 0.5 / res.Value() * x.DValue(j);
|
|
423
|
+
return res;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
using std::log;
|
|
427
|
+
template <int D, typename SCAL>
|
|
428
|
+
AutoDiffVec<D,SCAL> log (AutoDiffVec<D,SCAL> x)
|
|
429
|
+
{
|
|
430
|
+
AutoDiffVec<D,SCAL> res;
|
|
431
|
+
res.Value() = log(x.Value());
|
|
432
|
+
for (int k = 0; k < D; k++)
|
|
433
|
+
res.DValue(k) = x.DValue(k) / x.Value();
|
|
434
|
+
return res;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
using std::exp;
|
|
438
|
+
template <int D, typename SCAL>
|
|
439
|
+
NETGEN_INLINE AutoDiffVec<D,SCAL> exp (AutoDiffVec<D,SCAL> x)
|
|
440
|
+
{
|
|
441
|
+
AutoDiffVec<D,SCAL> res;
|
|
442
|
+
res.Value() = exp(x.Value());
|
|
443
|
+
for (int k = 0; k < D; k++)
|
|
444
|
+
res.DValue(k) = x.DValue(k) * res.Value();
|
|
445
|
+
return res;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
using std::pow;
|
|
449
|
+
template <int D, typename SCAL>
|
|
450
|
+
NETGEN_INLINE AutoDiffVec<D,SCAL> pow (AutoDiffVec<D,SCAL> x, AutoDiffVec<D,SCAL> y )
|
|
451
|
+
{
|
|
452
|
+
return exp(log(x)*y);
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
using std::sin;
|
|
456
|
+
/*
|
|
457
|
+
template <int D, typename SCAL>
|
|
458
|
+
NETGEN_INLINE AutoDiffVec<D,SCAL> sin (AutoDiffVec<D,SCAL> x)
|
|
459
|
+
{
|
|
460
|
+
AutoDiffVec<D,SCAL> res;
|
|
461
|
+
res.Value() = sin(x.Value());
|
|
462
|
+
SCAL c = cos(x.Value());
|
|
463
|
+
for (int k = 0; k < D; k++)
|
|
464
|
+
res.DValue(k) = x.DValue(k) * c;
|
|
465
|
+
return res;
|
|
466
|
+
}
|
|
467
|
+
*/
|
|
468
|
+
|
|
469
|
+
template <int D, typename SCAL>
|
|
470
|
+
NETGEN_INLINE AutoDiffVec<D,SCAL> sin (AutoDiffVec<D,SCAL> x)
|
|
471
|
+
{
|
|
472
|
+
return sin(AutoDiffRec<D,SCAL>(x));
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
using std::cos;
|
|
476
|
+
/*
|
|
477
|
+
template <int D, typename SCAL>
|
|
478
|
+
NETGEN_INLINE AutoDiffVec<D,SCAL> cos (AutoDiffVec<D,SCAL> x)
|
|
479
|
+
{
|
|
480
|
+
AutoDiffVec<D,SCAL> res;
|
|
481
|
+
res.Value() = cos(x.Value());
|
|
482
|
+
SCAL ms = -sin(x.Value());
|
|
483
|
+
for (int k = 0; k < D; k++)
|
|
484
|
+
res.DValue(k) = x.DValue(k) * ms;
|
|
485
|
+
return res;
|
|
486
|
+
}
|
|
487
|
+
*/
|
|
488
|
+
template <int D, typename SCAL>
|
|
489
|
+
NETGEN_INLINE AutoDiffVec<D,SCAL> cos (AutoDiffVec<D,SCAL> x)
|
|
490
|
+
{
|
|
491
|
+
return cos(AutoDiffRec<D,SCAL>(x));
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
using std::tan;
|
|
495
|
+
template <int D, typename SCAL>
|
|
496
|
+
NETGEN_INLINE AutoDiffVec<D,SCAL> tan (AutoDiffVec<D,SCAL> x)
|
|
497
|
+
{ return sin(x) / cos(x); }
|
|
498
|
+
|
|
499
|
+
using std::sinh;
|
|
500
|
+
template <int D, typename SCAL>
|
|
501
|
+
NETGEN_INLINE AutoDiffVec<D,SCAL> sinh (AutoDiffVec<D,SCAL> x)
|
|
502
|
+
{
|
|
503
|
+
AutoDiffVec<D,SCAL> res;
|
|
504
|
+
res.Value() = sinh(x.Value());
|
|
505
|
+
SCAL ch = cosh(x.Value());
|
|
506
|
+
for (int k = 0; k < D; k++)
|
|
507
|
+
res.DValue(k) = x.DValue(k) * ch;
|
|
508
|
+
return res;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
using std::cosh;
|
|
512
|
+
template <int D, typename SCAL>
|
|
513
|
+
NETGEN_INLINE AutoDiffVec<D,SCAL> cosh (AutoDiffVec<D,SCAL> x)
|
|
514
|
+
{
|
|
515
|
+
AutoDiffVec<D,SCAL> res;
|
|
516
|
+
res.Value() = cosh(x.Value());
|
|
517
|
+
SCAL sh = sinh(x.Value());
|
|
518
|
+
for (int k = 0; k < D; k++)
|
|
519
|
+
res.DValue(k) = x.DValue(k) * sh;
|
|
520
|
+
return res;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
using std::erf;
|
|
524
|
+
template <int D, typename SCAL>
|
|
525
|
+
NETGEN_INLINE AutoDiffVec<D,SCAL> erf (AutoDiffVec<D,SCAL> x)
|
|
526
|
+
{
|
|
527
|
+
return erf(AutoDiffRec<D,SCAL>(x));
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
using std::floor;
|
|
531
|
+
template<int D, typename SCAL>
|
|
532
|
+
NETGEN_INLINE AutoDiffVec<D,SCAL> floor (const AutoDiffVec<D,SCAL> & x)
|
|
533
|
+
{
|
|
534
|
+
AutoDiffVec<D,SCAL> res;
|
|
535
|
+
res.Value() = floor(x.Value());
|
|
536
|
+
for (int j = 0; j < D; j++)
|
|
537
|
+
res.DValue(j) = 0.0;
|
|
538
|
+
return res;
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
using std::ceil;
|
|
542
|
+
template<int D, typename SCAL>
|
|
543
|
+
NETGEN_INLINE AutoDiffVec<D,SCAL> ceil (const AutoDiffVec<D,SCAL> & x)
|
|
544
|
+
{
|
|
545
|
+
AutoDiffVec<D,SCAL> res;
|
|
546
|
+
res.Value() = ceil(x.Value());
|
|
547
|
+
for (int j = 0; j < D; j++)
|
|
548
|
+
res.DValue(j) = 0.0;
|
|
549
|
+
return res;
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
|
|
553
|
+
using std::atan;
|
|
554
|
+
/*
|
|
555
|
+
template <int D, typename SCAL>
|
|
556
|
+
NETGEN_INLINE AutoDiffVec<D,SCAL> atan (AutoDiffVec<D,SCAL> x)
|
|
557
|
+
{
|
|
558
|
+
AutoDiffVec<D,SCAL> res;
|
|
559
|
+
SCAL a = atan(x.Value());
|
|
560
|
+
res.Value() = a;
|
|
561
|
+
for (int k = 0; k < D; k++)
|
|
562
|
+
res.DValue(k) = x.DValue(k)/(1+x.Value()*x.Value()) ;
|
|
563
|
+
return res;
|
|
564
|
+
}
|
|
565
|
+
*/
|
|
566
|
+
template <int D, typename SCAL>
|
|
567
|
+
AutoDiffVec<D,SCAL> atan (AutoDiffVec<D,SCAL> x)
|
|
568
|
+
{
|
|
569
|
+
return atan (AutoDiffRec<D,SCAL> (x));
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
using std::atan2;
|
|
573
|
+
template <int D, typename SCAL>
|
|
574
|
+
NETGEN_INLINE AutoDiffVec<D,SCAL> atan2 (AutoDiffVec<D,SCAL> x, AutoDiffVec<D,SCAL> y)
|
|
575
|
+
{
|
|
576
|
+
AutoDiffVec<D,SCAL> res;
|
|
577
|
+
SCAL a = atan2(x.Value(), y.Value());
|
|
578
|
+
res.Value() = a;
|
|
579
|
+
for (int k = 0; k < D; k++)
|
|
580
|
+
res.DValue(k) = (x.Value()*y.DValue(k)-y.Value()*x.DValue(k))/(y.Value()*y.Value()+x.Value()*x.Value());
|
|
581
|
+
return res;
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
|
|
585
|
+
using std::acos;
|
|
586
|
+
template <int D, typename SCAL>
|
|
587
|
+
NETGEN_INLINE AutoDiffVec<D,SCAL> acos (AutoDiffVec<D,SCAL> x)
|
|
588
|
+
{
|
|
589
|
+
AutoDiffVec<D,SCAL> res;
|
|
590
|
+
SCAL a = acos(x.Value());
|
|
591
|
+
res.Value() = a;
|
|
592
|
+
SCAL da = -1 / sqrt(1-x.Value()*x.Value());
|
|
593
|
+
for (int k = 0; k < D; k++)
|
|
594
|
+
res.DValue(k) = x.DValue(k)*da;
|
|
595
|
+
return res;
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
|
|
599
|
+
using std::asin;
|
|
600
|
+
template <int D, typename SCAL>
|
|
601
|
+
NETGEN_INLINE AutoDiffVec<D,SCAL> asin (AutoDiffVec<D,SCAL> x)
|
|
602
|
+
{
|
|
603
|
+
AutoDiffVec<D,SCAL> res;
|
|
604
|
+
SCAL a = asin(x.Value());
|
|
605
|
+
res.Value() = a;
|
|
606
|
+
SCAL da = 1 / sqrt(1-x.Value()*x.Value());
|
|
607
|
+
for (int k = 0; k < D; k++)
|
|
608
|
+
res.DValue(k) = x.DValue(k)*da;
|
|
609
|
+
return res;
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
|
|
613
|
+
|
|
614
|
+
|
|
615
|
+
template <int D, typename SCAL, typename TB, typename TC>
|
|
616
|
+
auto IfPos (AutoDiffVec<D,SCAL> a, TB b, TC c) // -> decltype(IfPos (a.Value(), b, c))
|
|
617
|
+
{
|
|
618
|
+
return IfPos (a.Value(), b, c);
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
template <int D, typename SCAL>
|
|
622
|
+
NETGEN_INLINE AutoDiffVec<D,SCAL> IfPos (SCAL /* SIMD<double> */ a, AutoDiffVec<D,SCAL> b, AutoDiffVec<D,SCAL> c)
|
|
623
|
+
{
|
|
624
|
+
AutoDiffVec<D,SCAL> res;
|
|
625
|
+
res.Value() = IfPos (a, b.Value(), c.Value());
|
|
626
|
+
for (int j = 0; j < D; j++)
|
|
627
|
+
res.DValue(j) = IfPos (a, b.DValue(j), c.DValue(j));
|
|
628
|
+
return res;
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
template <int D, typename SCAL, typename TC>
|
|
632
|
+
NETGEN_INLINE AutoDiffVec<D,SCAL> IfPos (SCAL /* SIMD<double> */ a, AutoDiffVec<D,SCAL> b, TC c)
|
|
633
|
+
{
|
|
634
|
+
return IfPos (a, b, AutoDiffVec<D,SCAL> (c));
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
//@}
|
|
638
|
+
|
|
639
|
+
|
|
640
|
+
|
|
641
|
+
template <int D, typename SCAL>
|
|
642
|
+
class AutoDiffRec
|
|
643
|
+
{
|
|
644
|
+
AutoDiffRec<D-1, SCAL> rec;
|
|
645
|
+
SCAL last;
|
|
646
|
+
|
|
647
|
+
public:
|
|
648
|
+
NETGEN_INLINE AutoDiffRec () = default;
|
|
649
|
+
NETGEN_INLINE AutoDiffRec (const AutoDiffRec &) = default;
|
|
650
|
+
NETGEN_INLINE AutoDiffRec (AutoDiffRec<D-1,SCAL> _rec, SCAL _last) : rec(_rec), last(_last) { ; }
|
|
651
|
+
NETGEN_INLINE AutoDiffRec & operator= (const AutoDiffRec &) = default;
|
|
652
|
+
|
|
653
|
+
NETGEN_INLINE AutoDiffRec (SCAL aval) : rec(aval), last(0.0) { ; }
|
|
654
|
+
NETGEN_INLINE AutoDiffRec (SCAL aval, int diffindex) : rec(aval, diffindex), last((diffindex==D-1) ? 1.0 : 0.0) { ; }
|
|
655
|
+
NETGEN_INLINE AutoDiffRec (SCAL aval, const SCAL * grad)
|
|
656
|
+
: rec(aval, grad), last(grad[D-1]) { }
|
|
657
|
+
|
|
658
|
+
NETGEN_INLINE AutoDiffRec (const AutoDiffVec<D,SCAL> & ad)
|
|
659
|
+
{
|
|
660
|
+
Value() = ad.Value();
|
|
661
|
+
for (int i = 0; i < D; i++)
|
|
662
|
+
DValue(i) = ad.DValue(i);
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
NETGEN_INLINE AutoDiffRec & operator= (SCAL aval) { rec = aval; last = 0.0; return *this; }
|
|
666
|
+
NETGEN_INLINE SCAL Value() const { return rec.Value(); }
|
|
667
|
+
NETGEN_INLINE SCAL DValue(int i) const { return (i == D-1) ? last : rec.DValue(i); }
|
|
668
|
+
NETGEN_INLINE SCAL & Value() { return rec.Value(); }
|
|
669
|
+
NETGEN_INLINE SCAL & DValue(int i) { return (i == D-1) ? last : rec.DValue(i); }
|
|
670
|
+
NETGEN_INLINE auto Rec() const { return rec; }
|
|
671
|
+
NETGEN_INLINE auto Last() const { return last; }
|
|
672
|
+
NETGEN_INLINE auto & Rec() { return rec; }
|
|
673
|
+
NETGEN_INLINE auto & Last() { return last; }
|
|
674
|
+
NETGEN_INLINE operator AutoDiffVec<D,SCAL> () const
|
|
675
|
+
{
|
|
676
|
+
AutoDiffVec<D,SCAL> res(Value());
|
|
677
|
+
for (int i = 0; i < D; i++)
|
|
678
|
+
res.DValue(i) = DValue(i);
|
|
679
|
+
return res;
|
|
680
|
+
}
|
|
681
|
+
};
|
|
682
|
+
|
|
683
|
+
template<int D, typename SCAL>
|
|
684
|
+
ostream & operator<< (ostream & ost, AutoDiffRec<D,SCAL> ad)
|
|
685
|
+
{
|
|
686
|
+
return ost << AutoDiffVec<D,SCAL> (ad);
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
template <typename SCAL>
|
|
690
|
+
class AutoDiffRec<0,SCAL>
|
|
691
|
+
{
|
|
692
|
+
SCAL val;
|
|
693
|
+
public:
|
|
694
|
+
NETGEN_INLINE AutoDiffRec () = default;
|
|
695
|
+
NETGEN_INLINE AutoDiffRec (const AutoDiffRec &) = default;
|
|
696
|
+
NETGEN_INLINE AutoDiffRec (SCAL _val) : val(_val) { ; }
|
|
697
|
+
NETGEN_INLINE AutoDiffRec (SCAL _val, SCAL /* _dummylast */) : val(_val) { ; }
|
|
698
|
+
NETGEN_INLINE AutoDiffRec (SCAL aval, const SCAL * /* grad */)
|
|
699
|
+
: val(aval) { }
|
|
700
|
+
|
|
701
|
+
NETGEN_INLINE AutoDiffRec & operator= (const AutoDiffRec &) = default;
|
|
702
|
+
NETGEN_INLINE AutoDiffRec & operator= (SCAL aval) { val = aval; return *this; }
|
|
703
|
+
|
|
704
|
+
NETGEN_INLINE SCAL Value() const { return val; }
|
|
705
|
+
NETGEN_INLINE SCAL DValue(int /* i */) const { return SCAL(0); }
|
|
706
|
+
NETGEN_INLINE SCAL & Value() { return val; }
|
|
707
|
+
// SCAL & DValue(int i) { return val; }
|
|
708
|
+
NETGEN_INLINE auto Rec() const { return val; }
|
|
709
|
+
NETGEN_INLINE auto Last() const { return SCAL(0); }
|
|
710
|
+
NETGEN_INLINE auto & Rec() { return val; }
|
|
711
|
+
NETGEN_INLINE auto & Last() { return val; }
|
|
712
|
+
NETGEN_INLINE operator AutoDiffVec<0,SCAL> () const { return AutoDiffVec<0,SCAL>(); }
|
|
713
|
+
};
|
|
714
|
+
|
|
715
|
+
|
|
716
|
+
template <typename SCAL>
|
|
717
|
+
class AutoDiffRec<1,SCAL>
|
|
718
|
+
{
|
|
719
|
+
SCAL val;
|
|
720
|
+
SCAL last;
|
|
721
|
+
public:
|
|
722
|
+
NETGEN_INLINE AutoDiffRec () = default;
|
|
723
|
+
NETGEN_INLINE AutoDiffRec (const AutoDiffRec &) = default;
|
|
724
|
+
NETGEN_INLINE AutoDiffRec (SCAL _val) : val(_val), last(0.0) { ; }
|
|
725
|
+
NETGEN_INLINE AutoDiffRec (SCAL _val, SCAL _last) : val(_val), last(_last) { ; }
|
|
726
|
+
NETGEN_INLINE AutoDiffRec (SCAL aval, int diffindex) : val(aval), last((diffindex==0) ? 1.0 : 0.0) { ; }
|
|
727
|
+
NETGEN_INLINE AutoDiffRec (SCAL aval, const SCAL * grad)
|
|
728
|
+
: val(aval), last(grad[0]) { }
|
|
729
|
+
|
|
730
|
+
NETGEN_INLINE AutoDiffRec (const AutoDiffVec<1,SCAL> & ad)
|
|
731
|
+
{
|
|
732
|
+
Value() = ad.Value();
|
|
733
|
+
DValue(0) = ad.DValue(0);
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
NETGEN_INLINE AutoDiffRec & operator= (const AutoDiffRec &) = default;
|
|
737
|
+
NETGEN_INLINE AutoDiffRec & operator= (SCAL aval) { val = aval; last = 0.0; return *this; }
|
|
738
|
+
|
|
739
|
+
NETGEN_INLINE SCAL Value() const { return val; }
|
|
740
|
+
NETGEN_INLINE SCAL DValue(int /* i */) const { return last; }
|
|
741
|
+
NETGEN_INLINE SCAL & Value() { return val; }
|
|
742
|
+
NETGEN_INLINE SCAL & DValue(int /* i */) { return last; }
|
|
743
|
+
NETGEN_INLINE auto Rec() const { return val; }
|
|
744
|
+
NETGEN_INLINE auto Last() const { return last; }
|
|
745
|
+
NETGEN_INLINE auto & Rec() { return val; }
|
|
746
|
+
NETGEN_INLINE auto & Last() { return last; }
|
|
747
|
+
|
|
748
|
+
NETGEN_INLINE operator AutoDiffVec<1,SCAL> () const
|
|
749
|
+
{
|
|
750
|
+
AutoDiffVec<1,SCAL> res(Value());
|
|
751
|
+
res.DValue(0) = DValue(0);
|
|
752
|
+
return res;
|
|
753
|
+
}
|
|
754
|
+
};
|
|
755
|
+
|
|
756
|
+
template <int D, typename SCAL, typename SCAL2,
|
|
757
|
+
typename std::enable_if<std::is_convertible<SCAL2,SCAL>::value, int>::type = 0>
|
|
758
|
+
NETGEN_INLINE AutoDiffRec<D,SCAL> operator+ (SCAL2 a, AutoDiffRec<D,SCAL> b)
|
|
759
|
+
{
|
|
760
|
+
return AutoDiffRec<D,SCAL> (a+b.Rec(), b.Last());
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
template <int D, typename SCAL, typename SCAL2,
|
|
764
|
+
typename std::enable_if<std::is_convertible<SCAL2,SCAL>::value, int>::type = 0>
|
|
765
|
+
NETGEN_INLINE AutoDiffRec<D,SCAL> operator+ (AutoDiffRec<D,SCAL> a, SCAL2 b)
|
|
766
|
+
{
|
|
767
|
+
return AutoDiffRec<D,SCAL> (a.Rec()+b, a.Last());
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
template <int D, typename SCAL>
|
|
771
|
+
NETGEN_INLINE AutoDiffRec<D,SCAL> operator+ (AutoDiffRec<D,SCAL> a, AutoDiffRec<D,SCAL> b)
|
|
772
|
+
{
|
|
773
|
+
return AutoDiffRec<D,SCAL> (a.Rec()+b.Rec(), a.Last()+b.Last());
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
template <int D, typename SCAL, typename SCAL2,
|
|
777
|
+
typename std::enable_if<std::is_convertible<SCAL2,SCAL>::value, int>::type = 0>
|
|
778
|
+
NETGEN_INLINE AutoDiffRec<D,SCAL> operator- (SCAL2 b, AutoDiffRec<D,SCAL> a)
|
|
779
|
+
{
|
|
780
|
+
return AutoDiffRec<D,SCAL> (b-a.Rec(), -a.Last());
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
template <int D, typename SCAL, typename SCAL2,
|
|
784
|
+
typename std::enable_if<std::is_convertible<SCAL2,SCAL>::value, int>::type = 0>
|
|
785
|
+
NETGEN_INLINE AutoDiffRec<D,SCAL> operator- (AutoDiffRec<D,SCAL> a, SCAL2 b)
|
|
786
|
+
{
|
|
787
|
+
return AutoDiffRec<D,SCAL> (a.Rec()-b, a.Last());
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
template <int D, typename SCAL>
|
|
791
|
+
NETGEN_INLINE AutoDiffRec<D,SCAL> operator- (AutoDiffRec<D,SCAL> a, AutoDiffRec<D,SCAL> b)
|
|
792
|
+
{
|
|
793
|
+
return AutoDiffRec<D,SCAL> (a.Rec()-b.Rec(), a.Last()-b.Last());
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
/// minus AutoDiff
|
|
797
|
+
template<int D, typename SCAL>
|
|
798
|
+
NETGEN_INLINE AutoDiffRec<D,SCAL> operator- (AutoDiffRec<D,SCAL> a)
|
|
799
|
+
{
|
|
800
|
+
return AutoDiffRec<D,SCAL> (-a.Rec(), -a.Last());
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
template <int D, typename SCAL>
|
|
804
|
+
NETGEN_INLINE AutoDiffRec<D,SCAL> operator* (AutoDiffRec<D,SCAL> a, AutoDiffRec<D,SCAL> b)
|
|
805
|
+
{
|
|
806
|
+
return AutoDiffRec<D,SCAL> (a.Rec()*b.Rec(), a.Value()*b.Last()+b.Value()*a.Last());
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
template <int D, typename SCAL, typename SCAL1,
|
|
810
|
+
typename std::enable_if<std::is_convertible<SCAL1,SCAL>::value, int>::type = 0>
|
|
811
|
+
NETGEN_INLINE AutoDiffRec<D,SCAL> operator* (AutoDiffRec<D,SCAL> b, SCAL1 a)
|
|
812
|
+
{
|
|
813
|
+
return AutoDiffRec<D,SCAL> (a*b.Rec(), a*b.Last());
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
template <int D, typename SCAL, typename SCAL1,
|
|
817
|
+
typename std::enable_if<std::is_convertible<SCAL1,SCAL>::value, int>::type = 0>
|
|
818
|
+
NETGEN_INLINE AutoDiffRec<D,SCAL> operator* (SCAL1 a, AutoDiffRec<D,SCAL> b)
|
|
819
|
+
{
|
|
820
|
+
return AutoDiffRec<D,SCAL> (a*b.Rec(), a*b.Last());
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
template <int D, typename SCAL>
|
|
824
|
+
NETGEN_INLINE AutoDiffRec<D,SCAL> & operator+= (AutoDiffRec<D,SCAL> & a, AutoDiffRec<D,SCAL> b)
|
|
825
|
+
{
|
|
826
|
+
a.Rec() += b.Rec();
|
|
827
|
+
a.Last() += b.Last();
|
|
828
|
+
return a;
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
template <int D, typename SCAL>
|
|
832
|
+
NETGEN_INLINE AutoDiffRec<D,SCAL> & operator-= (AutoDiffRec<D,SCAL> & a, double b)
|
|
833
|
+
{
|
|
834
|
+
a.Rec() -= b;
|
|
835
|
+
return a;
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
template <int D, typename SCAL>
|
|
839
|
+
NETGEN_INLINE AutoDiffRec<D,SCAL> & operator-= (AutoDiffRec<D,SCAL> & a, AutoDiffRec<D,SCAL> b)
|
|
840
|
+
{
|
|
841
|
+
a.Rec() -= b.Rec();
|
|
842
|
+
a.Last() -= b.Last();
|
|
843
|
+
return a;
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
|
|
847
|
+
template <int D, typename SCAL>
|
|
848
|
+
NETGEN_INLINE AutoDiffRec<D,SCAL> & operator*= (AutoDiffRec<D,SCAL> & a, AutoDiffRec<D,SCAL> b)
|
|
849
|
+
{
|
|
850
|
+
a = a*b;
|
|
851
|
+
return a;
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
|
|
855
|
+
template <int D, typename SCAL, typename SCAL2>
|
|
856
|
+
NETGEN_INLINE AutoDiffRec<D,SCAL> & operator*= (AutoDiffRec<D,SCAL> & b, SCAL2 a)
|
|
857
|
+
{
|
|
858
|
+
b.Rec() *= a;
|
|
859
|
+
b.Last() *= a;
|
|
860
|
+
return b;
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
/// Inverse of AutoDiffRec
|
|
864
|
+
|
|
865
|
+
template <typename SCAL>
|
|
866
|
+
auto Inv1 (SCAL x) { return 1.0/x; }
|
|
867
|
+
|
|
868
|
+
template<int D, typename SCAL>
|
|
869
|
+
NETGEN_INLINE AutoDiffRec<D,SCAL> Inv1 (AutoDiffRec<D,SCAL> x)
|
|
870
|
+
{
|
|
871
|
+
return AutoDiffRec<D,SCAL> (Inv1(x.Rec()), (-sqr(1.0/x.Value())) * x.Last());
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
/// AutoDiffRec div AutoDiffRec
|
|
875
|
+
template<int D, typename SCAL>
|
|
876
|
+
NETGEN_INLINE AutoDiffRec<D,SCAL> operator/ (const AutoDiffRec<D,SCAL> & x, const AutoDiffRec<D,SCAL> & y)
|
|
877
|
+
{
|
|
878
|
+
return x * Inv1 (y);
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
|
|
882
|
+
/// AutoDiffVec div double
|
|
883
|
+
template<int D, typename SCAL, typename SCAL2,
|
|
884
|
+
typename std::enable_if<std::is_convertible<SCAL2,SCAL>::value, int>::type = 0>
|
|
885
|
+
NETGEN_INLINE AutoDiffRec<D,SCAL> operator/ (const AutoDiffRec<D,SCAL> & x, SCAL2 y)
|
|
886
|
+
{
|
|
887
|
+
return (1.0/y) * x;
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
|
|
891
|
+
/// double div AutoDiffVec
|
|
892
|
+
template<int D, typename SCAL, typename SCAL2,
|
|
893
|
+
typename std::enable_if<std::is_convertible<SCAL2,SCAL>::value, int>::type = 0>
|
|
894
|
+
NETGEN_INLINE AutoDiffRec<D,SCAL> operator/ (SCAL2 x, const AutoDiffRec<D,SCAL> & y)
|
|
895
|
+
{
|
|
896
|
+
return x * Inv1(y);
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
|
|
900
|
+
|
|
901
|
+
|
|
902
|
+
|
|
903
|
+
|
|
904
|
+
|
|
905
|
+
///
|
|
906
|
+
template <int D, typename SCAL>
|
|
907
|
+
NETGEN_INLINE bool operator== (AutoDiffRec<D,SCAL> x, SCAL val2)
|
|
908
|
+
{
|
|
909
|
+
return x.Value() == val2;
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
///
|
|
913
|
+
template <int D, typename SCAL>
|
|
914
|
+
NETGEN_INLINE bool operator!= (AutoDiffRec<D,SCAL> x, SCAL val2) throw()
|
|
915
|
+
{
|
|
916
|
+
return x.Value() != val2;
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
///
|
|
920
|
+
template <int D, typename SCAL>
|
|
921
|
+
NETGEN_INLINE bool operator< (AutoDiffRec<D,SCAL> x, SCAL val2) throw()
|
|
922
|
+
{
|
|
923
|
+
return x.Value() < val2;
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
///
|
|
927
|
+
template <int D, typename SCAL>
|
|
928
|
+
NETGEN_INLINE bool operator> (AutoDiffRec<D,SCAL> x, SCAL val2) throw()
|
|
929
|
+
{
|
|
930
|
+
return x.Value() > val2;
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
using std::fabs;
|
|
934
|
+
template<int D, typename SCAL>
|
|
935
|
+
NETGEN_INLINE AutoDiffRec<D,SCAL> fabs (const AutoDiffRec<D,SCAL> & x)
|
|
936
|
+
{
|
|
937
|
+
auto sign = IfPos(x.Value(), SCAL(1.0), IfPos(-x.Value(), SCAL(-1.0), SCAL(0.0)));
|
|
938
|
+
return AutoDiffRec<D,SCAL> (fabs(x.Rec()), sign*x.Last());
|
|
939
|
+
// return fabs (AutoDiffVec<D,SCAL>(x));
|
|
940
|
+
/*
|
|
941
|
+
double abs = fabs (x.Value());
|
|
942
|
+
AutoDiffVec<D,SCAL> res( abs );
|
|
943
|
+
if (abs != 0.0)
|
|
944
|
+
for (int i = 0; i < D; i++)
|
|
945
|
+
res.DValue(i) = x.Value()*x.DValue(i) / abs;
|
|
946
|
+
else
|
|
947
|
+
for (int i = 0; i < D; i++)
|
|
948
|
+
res.DValue(i) = 0.0;
|
|
949
|
+
return res;
|
|
950
|
+
*/
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
|
|
954
|
+
template<int D, typename SCAL>
|
|
955
|
+
NETGEN_INLINE auto sqrt (const AutoDiffRec<D,SCAL> & x)
|
|
956
|
+
{
|
|
957
|
+
return AutoDiffRec<D,SCAL> (sqrt(x.Rec()), (0.5/sqrt(x.Value()))*x.Last());
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
|
|
961
|
+
|
|
962
|
+
template <int D, typename SCAL>
|
|
963
|
+
auto log (AutoDiffRec<D,SCAL> x)
|
|
964
|
+
{
|
|
965
|
+
return AutoDiffRec<D,SCAL> (log(x.Rec()), (1.0/x.Value())*x.Last());
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
template <int D, typename SCAL>
|
|
969
|
+
auto exp (AutoDiffRec<D,SCAL> x)
|
|
970
|
+
{
|
|
971
|
+
return AutoDiffRec<D,SCAL> (exp(x.Rec()), exp(x.Value())*x.Last());
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
template <int D, typename SCAL>
|
|
975
|
+
NETGEN_INLINE AutoDiffRec<D,SCAL> pow (AutoDiffRec<D,SCAL> x, AutoDiffRec<D,SCAL> y )
|
|
976
|
+
{
|
|
977
|
+
return exp(log(x)*y);
|
|
978
|
+
}
|
|
979
|
+
|
|
980
|
+
|
|
981
|
+
template <int D, typename SCAL>
|
|
982
|
+
auto sin (AutoDiffRec<D,SCAL> x)
|
|
983
|
+
{
|
|
984
|
+
return AutoDiffRec<D,SCAL> (sin(x.Rec()), cos(x.Value())*x.Last());
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
template <int D, typename SCAL>
|
|
988
|
+
auto cos (AutoDiffRec<D,SCAL> x)
|
|
989
|
+
{
|
|
990
|
+
return AutoDiffRec<D,SCAL> (cos(x.Rec()), -sin(x.Value())*x.Last());
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
template <int D, typename SCAL>
|
|
994
|
+
auto tan (AutoDiffRec<D,SCAL> x)
|
|
995
|
+
{
|
|
996
|
+
return sin(x) / cos(x);
|
|
997
|
+
}
|
|
998
|
+
|
|
999
|
+
template <int D, typename SCAL>
|
|
1000
|
+
auto sinh (AutoDiffRec<D,SCAL> x)
|
|
1001
|
+
{
|
|
1002
|
+
return AutoDiffRec<D,SCAL> (sinh(x.Rec()), cosh(x.Value())*x.Last());
|
|
1003
|
+
}
|
|
1004
|
+
|
|
1005
|
+
template <int D, typename SCAL>
|
|
1006
|
+
auto cosh (AutoDiffRec<D,SCAL> x)
|
|
1007
|
+
{
|
|
1008
|
+
return AutoDiffRec<D,SCAL> (cosh(x.Rec()), sinh(x.Value())*x.Last());
|
|
1009
|
+
}
|
|
1010
|
+
|
|
1011
|
+
template <int D, typename SCAL>
|
|
1012
|
+
auto erf (AutoDiffRec<D,SCAL> x)
|
|
1013
|
+
{
|
|
1014
|
+
return AutoDiffRec<D,SCAL> (erf(x.Rec()), 2. / sqrt(M_PI) * exp(- x.Value() * x.Value())*x.Last());
|
|
1015
|
+
}
|
|
1016
|
+
|
|
1017
|
+
template <int D, typename SCAL>
|
|
1018
|
+
auto floor (AutoDiffRec<D,SCAL> x)
|
|
1019
|
+
{
|
|
1020
|
+
return AutoDiffRec<D,SCAL> (floor(x.Rec()), 0.0);
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
template <int D, typename SCAL>
|
|
1024
|
+
auto ceil (AutoDiffRec<D,SCAL> x)
|
|
1025
|
+
{
|
|
1026
|
+
return AutoDiffRec<D,SCAL> (ceil(x.Rec()), 0.0);
|
|
1027
|
+
}
|
|
1028
|
+
|
|
1029
|
+
|
|
1030
|
+
|
|
1031
|
+
template <int D, typename SCAL>
|
|
1032
|
+
auto atan (AutoDiffRec<D,SCAL> x)
|
|
1033
|
+
{
|
|
1034
|
+
return AutoDiffRec<D,SCAL> (atan(x.Rec()), (1./(1.+x.Value()*x.Value()))*x.Last());
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1037
|
+
template <int D, typename SCAL>
|
|
1038
|
+
auto atan2 (AutoDiffRec<D,SCAL> x, AutoDiffRec<D,SCAL> y)
|
|
1039
|
+
{
|
|
1040
|
+
return AutoDiffRec<D,SCAL> (atan2(x.Rec(), y.Rec()),
|
|
1041
|
+
(1./(x.Value()*x.Value()+y.Value()*y.Value()))*(x.Value()*y.Last()-y.Value()*x.Last()));
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
template <int D, typename SCAL>
|
|
1045
|
+
auto acos (AutoDiffRec<D,SCAL> x)
|
|
1046
|
+
{
|
|
1047
|
+
return AutoDiffRec<D,SCAL> (acos(x.Rec()), (-1./sqrt(1.-x.Value()*x.Value()))*x.Last());
|
|
1048
|
+
}
|
|
1049
|
+
|
|
1050
|
+
template <int D, typename SCAL>
|
|
1051
|
+
auto asin (AutoDiffRec<D,SCAL> x)
|
|
1052
|
+
{
|
|
1053
|
+
return AutoDiffRec<D,SCAL> (asin(x.Rec()), (1./sqrt(1.-x.Value()*x.Value()))*x.Last());
|
|
1054
|
+
}
|
|
1055
|
+
|
|
1056
|
+
|
|
1057
|
+
template <int D, typename SCAL, typename TB, typename TC>
|
|
1058
|
+
auto IfPos (AutoDiffRec<D,SCAL> a, TB b, TC c) // -> decltype(IfPos (a.Value(), b, c))
|
|
1059
|
+
{
|
|
1060
|
+
return IfPos (a.Value(), b, c);
|
|
1061
|
+
}
|
|
1062
|
+
|
|
1063
|
+
template <int D, typename SCAL>
|
|
1064
|
+
NETGEN_INLINE AutoDiffRec<D,SCAL> IfPos (SCAL /* SIMD<double> */ a, AutoDiffRec<D,SCAL> b, AutoDiffRec<D,SCAL> c)
|
|
1065
|
+
{
|
|
1066
|
+
/*
|
|
1067
|
+
AutoDiffRec<D,SCAL> res;
|
|
1068
|
+
res.Value() = IfPos (a, b.Value(), c.Value());
|
|
1069
|
+
for (int j = 0; j < D; j++)
|
|
1070
|
+
res.DValue(j) = IfPos (a, b.DValue(j), c.DValue(j));
|
|
1071
|
+
return res;
|
|
1072
|
+
*/
|
|
1073
|
+
return AutoDiffRec<D,SCAL> (IfPos(a, b.Rec(), c.Rec()), IfPos(a, b.Last(), c.Last()));
|
|
1074
|
+
}
|
|
1075
|
+
|
|
1076
|
+
template <int D, typename SCAL, typename TC>
|
|
1077
|
+
NETGEN_INLINE AutoDiffRec<D,SCAL> IfPos (SCAL /* SIMD<double> */ a, AutoDiffRec<D,SCAL> b, TC c)
|
|
1078
|
+
{
|
|
1079
|
+
return IfPos (a, b, AutoDiffRec<D,SCAL> (c));
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
|
|
1083
|
+
|
|
1084
|
+
template <int D, typename SCAL = double>
|
|
1085
|
+
using AutoDiff = AutoDiffRec<D,SCAL>;
|
|
1086
|
+
|
|
1087
|
+
}
|
|
1088
|
+
|
|
1089
|
+
|
|
1090
|
+
|
|
1091
|
+
namespace ngbla
|
|
1092
|
+
{
|
|
1093
|
+
template <typename T> struct is_scalar_type;
|
|
1094
|
+
template <int D, typename T>
|
|
1095
|
+
struct is_scalar_type<ngcore::AutoDiff<D,T>> { static constexpr bool value = true; };
|
|
1096
|
+
|
|
1097
|
+
// not meaningful for AutoDiff<D,Complex>, since this is
|
|
1098
|
+
// not (complex) differentiable anyway
|
|
1099
|
+
template<int D, typename SCAL>
|
|
1100
|
+
inline auto L2Norm2 (const ngcore::AutoDiff<D,SCAL> & x)
|
|
1101
|
+
{
|
|
1102
|
+
return x*x;
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
template<int D, typename SCAL>
|
|
1106
|
+
inline auto L2Norm (const ngcore::AutoDiff<D,SCAL> & x) throw()
|
|
1107
|
+
{
|
|
1108
|
+
return IfPos(x.Value(), x, -x);
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
|
|
1112
|
+
|
|
1113
|
+
template<int D, typename TAD>
|
|
1114
|
+
NETGEN_INLINE auto Conj (const ngcore::AutoDiff<D,TAD> & a)
|
|
1115
|
+
{
|
|
1116
|
+
ngcore::AutoDiff<D,TAD> b;
|
|
1117
|
+
b.Value() = conj(a.Value());
|
|
1118
|
+
|
|
1119
|
+
for(int i=0;i<D;i++)
|
|
1120
|
+
b.DValue(i) = conj(a.DValue(i));
|
|
1121
|
+
|
|
1122
|
+
return b;
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1125
|
+
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
|
|
1129
|
+
#endif
|
|
1130
|
+
|
|
1131
|
+
|