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,733 @@
|
|
|
1
|
+
#ifndef FILE_AUTODIFFDIFF
|
|
2
|
+
#define FILE_AUTODIFFDIFF
|
|
3
|
+
|
|
4
|
+
/**************************************************************************/
|
|
5
|
+
/* File: autodiffdiff.hpp */
|
|
6
|
+
/* Author: Joachim Schoeberl */
|
|
7
|
+
/* Date: 13. June. 05 */
|
|
8
|
+
/**************************************************************************/
|
|
9
|
+
|
|
10
|
+
namespace ngcore
|
|
11
|
+
{
|
|
12
|
+
using ngcore::IfPos;
|
|
13
|
+
|
|
14
|
+
// Automatic second differentiation datatype
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
Datatype for automatic differentiation. Contains function value,
|
|
19
|
+
D first derivatives, and D*D second derivatives. Algebraic operations are
|
|
20
|
+
overloaded by using product-rule etc. etc.
|
|
21
|
+
**/
|
|
22
|
+
template <int D, typename SCAL = double>
|
|
23
|
+
class AutoDiffDiff
|
|
24
|
+
{
|
|
25
|
+
SCAL val;
|
|
26
|
+
SCAL dval[D?D:1];
|
|
27
|
+
SCAL ddval[D?D*D:1];
|
|
28
|
+
public:
|
|
29
|
+
|
|
30
|
+
typedef AutoDiffDiff<D, SCAL> TELEM;
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
/// elements are undefined
|
|
34
|
+
AutoDiffDiff () throw() { ; }
|
|
35
|
+
|
|
36
|
+
/// copy constructor
|
|
37
|
+
AutoDiffDiff (const AutoDiffDiff & ad2) throw()
|
|
38
|
+
{
|
|
39
|
+
val = ad2.val;
|
|
40
|
+
for (int i = 0; i < D; i++)
|
|
41
|
+
dval[i] = ad2.dval[i];
|
|
42
|
+
for (int i = 0; i < D*D; i++)
|
|
43
|
+
ddval[i] = ad2.ddval[i];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/// initial object with constant value
|
|
47
|
+
AutoDiffDiff (SCAL aval) throw()
|
|
48
|
+
{
|
|
49
|
+
val = aval;
|
|
50
|
+
for (int i = 0; i < D; i++)
|
|
51
|
+
dval[i] = 0;
|
|
52
|
+
for (int i = 0; i < D*D; i++)
|
|
53
|
+
ddval[i] = 0;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/// initial object with value and derivative
|
|
57
|
+
AutoDiffDiff (const AutoDiff<D, SCAL> & ad2) throw()
|
|
58
|
+
{
|
|
59
|
+
val = ad2.Value();
|
|
60
|
+
for (int i = 0; i < D; i++)
|
|
61
|
+
dval[i] = ad2.DValue(i);
|
|
62
|
+
for (int i = 0; i < D*D; i++)
|
|
63
|
+
ddval[i] = 0;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/// init object with (val, e_diffindex)
|
|
67
|
+
AutoDiffDiff (SCAL aval, int diffindex) throw()
|
|
68
|
+
{
|
|
69
|
+
val = aval;
|
|
70
|
+
for (int i = 0; i < D; i++)
|
|
71
|
+
dval[i] = 0;
|
|
72
|
+
for (int i = 0; i < D*D; i++)
|
|
73
|
+
ddval[i] = 0;
|
|
74
|
+
dval[diffindex] = 1;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
NETGEN_INLINE AutoDiffDiff (SCAL aval, const SCAL * grad)
|
|
78
|
+
{
|
|
79
|
+
val = aval;
|
|
80
|
+
LoadGradient (grad);
|
|
81
|
+
for (int i = 0; i < D*D; i++)
|
|
82
|
+
ddval[i] = 0;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
NETGEN_INLINE AutoDiffDiff (SCAL aval, const SCAL * grad, const SCAL * hesse)
|
|
86
|
+
{
|
|
87
|
+
val = aval;
|
|
88
|
+
LoadGradient (grad);
|
|
89
|
+
LoadHessian (hesse);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/// assign constant value
|
|
93
|
+
AutoDiffDiff & operator= (SCAL aval) throw()
|
|
94
|
+
{
|
|
95
|
+
val = aval;
|
|
96
|
+
for (int i = 0; i < D; i++)
|
|
97
|
+
dval[i] = 0;
|
|
98
|
+
for (int i = 0; i < D*D; i++)
|
|
99
|
+
ddval[i] = 0;
|
|
100
|
+
return *this;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
NETGEN_INLINE void StoreGradient (SCAL * p) const
|
|
104
|
+
{
|
|
105
|
+
for (int i = 0; i < D; i++)
|
|
106
|
+
p[i] = dval[i];
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
NETGEN_INLINE void LoadGradient (const SCAL * p)
|
|
110
|
+
{
|
|
111
|
+
for (int i = 0; i < D; i++)
|
|
112
|
+
dval[i] = p[i];
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
NETGEN_INLINE void StoreHessian (SCAL * p) const
|
|
116
|
+
{
|
|
117
|
+
for (int i = 0; i < D*D; i++)
|
|
118
|
+
p[i] = ddval[i];
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
NETGEN_INLINE void LoadHessian (const SCAL * p)
|
|
122
|
+
{
|
|
123
|
+
for (int i = 0; i < D*D; i++)
|
|
124
|
+
ddval[i] = p[i];
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/// returns value
|
|
128
|
+
SCAL Value() const throw() { return val; }
|
|
129
|
+
|
|
130
|
+
/// returns partial derivative
|
|
131
|
+
SCAL DValue (int i) const throw() { return dval[i]; }
|
|
132
|
+
|
|
133
|
+
AutoDiff<D,SCAL> DValueAD (int i) const
|
|
134
|
+
{
|
|
135
|
+
AutoDiff<D,SCAL> r(dval[i]);
|
|
136
|
+
for (int j = 0; j < D; j++)
|
|
137
|
+
r.DValue(j) = ddval[i*D+j];
|
|
138
|
+
return r;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/// returns partial derivative
|
|
142
|
+
SCAL DDValue (int i) const throw() { return ddval[i]; }
|
|
143
|
+
|
|
144
|
+
/// returns partial derivative
|
|
145
|
+
SCAL DDValue (int i, int j) const throw() { return ddval[i*D+j]; }
|
|
146
|
+
|
|
147
|
+
/// access value
|
|
148
|
+
SCAL & Value() throw() { return val; }
|
|
149
|
+
|
|
150
|
+
/// accesses partial derivative
|
|
151
|
+
SCAL & DValue (int i) throw() { return dval[i]; }
|
|
152
|
+
|
|
153
|
+
/// accesses partial derivative
|
|
154
|
+
SCAL & DDValue (int i) throw() { return ddval[i]; }
|
|
155
|
+
|
|
156
|
+
/// accesses partial derivative
|
|
157
|
+
SCAL & DDValue (int i, int j) throw() { return ddval[i*D+j]; }
|
|
158
|
+
|
|
159
|
+
explicit operator AutoDiff<D,SCAL> () const
|
|
160
|
+
{ return AutoDiff<D,SCAL> (val, &dval[0]); }
|
|
161
|
+
|
|
162
|
+
/// add autodiffdiff object
|
|
163
|
+
AutoDiffDiff<D, SCAL> & operator+= (const AutoDiffDiff<D, SCAL> & y) throw()
|
|
164
|
+
{
|
|
165
|
+
val += y.val;
|
|
166
|
+
for (int i = 0; i < D; i++)
|
|
167
|
+
dval[i] += y.dval[i];
|
|
168
|
+
for (int i = 0; i < D*D; i++)
|
|
169
|
+
ddval[i] += y.ddval[i];
|
|
170
|
+
return *this;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/// subtract autodiffdiff object
|
|
174
|
+
AutoDiffDiff<D, SCAL> & operator-= (const AutoDiffDiff<D, SCAL> & y) throw()
|
|
175
|
+
{
|
|
176
|
+
val -= y.val;
|
|
177
|
+
for (int i = 0; i < D; i++)
|
|
178
|
+
dval[i] -= y.dval[i];
|
|
179
|
+
for (int i = 0; i < D*D; i++)
|
|
180
|
+
ddval[i] -= y.ddval[i];
|
|
181
|
+
return *this;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/// multiply with autodiffdiff object
|
|
185
|
+
AutoDiffDiff<D, SCAL> & operator*= (const AutoDiffDiff<D, SCAL> & y) throw()
|
|
186
|
+
{
|
|
187
|
+
for (int i = 0; i < D*D; i++)
|
|
188
|
+
ddval[i] = val * y.ddval[i] + y.val * ddval[i];
|
|
189
|
+
|
|
190
|
+
for (int i = 0; i < D; i++)
|
|
191
|
+
for (int j = 0; j < D; j++)
|
|
192
|
+
ddval[i*D+j] += dval[i] * y.dval[j] + dval[j] * y.dval[i];
|
|
193
|
+
|
|
194
|
+
for (int i = 0; i < D; i++)
|
|
195
|
+
{
|
|
196
|
+
dval[i] *= y.val;
|
|
197
|
+
dval[i] += val * y.dval[i];
|
|
198
|
+
}
|
|
199
|
+
val *= y.val;
|
|
200
|
+
return *this;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/// multiply with scalar
|
|
204
|
+
AutoDiffDiff<D, SCAL> & operator*= (const SCAL & y) throw()
|
|
205
|
+
{
|
|
206
|
+
for ( int i = 0; i < D*D; i++ )
|
|
207
|
+
ddval[i] *= y;
|
|
208
|
+
for (int i = 0; i < D; i++)
|
|
209
|
+
dval[i] *= y;
|
|
210
|
+
val *= y;
|
|
211
|
+
return *this;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/// divide by scalar
|
|
215
|
+
AutoDiffDiff<D, SCAL> & operator/= (const SCAL & y) throw()
|
|
216
|
+
{
|
|
217
|
+
SCAL iy = 1.0 / y;
|
|
218
|
+
for ( int i = 0; i < D*D; i++ )
|
|
219
|
+
ddval[i] *= iy;
|
|
220
|
+
for (int i = 0; i < D; i++)
|
|
221
|
+
dval[i] *= iy;
|
|
222
|
+
val *= iy;
|
|
223
|
+
return *this;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/// same value
|
|
227
|
+
bool operator== (SCAL val2) throw()
|
|
228
|
+
{
|
|
229
|
+
return val == val2;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/// different values
|
|
233
|
+
bool operator!= (SCAL val2) throw()
|
|
234
|
+
{
|
|
235
|
+
return val != val2;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/// less
|
|
239
|
+
bool operator< (SCAL val2) throw()
|
|
240
|
+
{
|
|
241
|
+
return val < val2;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/// greater
|
|
245
|
+
bool operator> (SCAL val2) throw()
|
|
246
|
+
{
|
|
247
|
+
return val > val2;
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
//@{ AutoDiff helper functions.
|
|
253
|
+
|
|
254
|
+
/// Prints AudoDiffDiff
|
|
255
|
+
template<int D, typename SCAL>
|
|
256
|
+
inline ostream & operator<< (ostream & ost, const AutoDiffDiff<D, SCAL> & x)
|
|
257
|
+
{
|
|
258
|
+
ost << x.Value() << ", D = ";
|
|
259
|
+
for (int i = 0; i < D; i++)
|
|
260
|
+
ost << x.DValue(i) << " ";
|
|
261
|
+
ost << ", DD = ";
|
|
262
|
+
for (int i = 0; i < D*D; i++)
|
|
263
|
+
ost << x.DDValue(i) << " ";
|
|
264
|
+
return ost;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
///
|
|
268
|
+
template<int D, typename SCAL>
|
|
269
|
+
inline AutoDiffDiff<D, SCAL> operator+ (const AutoDiffDiff<D, SCAL> & x, const AutoDiffDiff<D, SCAL> & y) throw()
|
|
270
|
+
{
|
|
271
|
+
AutoDiffDiff<D, SCAL> res;
|
|
272
|
+
res.Value () = x.Value()+y.Value();
|
|
273
|
+
for (int i = 0; i < D; i++)
|
|
274
|
+
res.DValue(i) = x.DValue(i) + y.DValue(i);
|
|
275
|
+
for (int i = 0; i < D*D; i++)
|
|
276
|
+
res.DDValue(i) = x.DDValue(i) + y.DDValue(i);
|
|
277
|
+
return res;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
///
|
|
282
|
+
template<int D, typename SCAL>
|
|
283
|
+
inline AutoDiffDiff<D, SCAL> operator- (const AutoDiffDiff<D, SCAL> & x, const AutoDiffDiff<D, SCAL> & y) throw()
|
|
284
|
+
{
|
|
285
|
+
AutoDiffDiff<D, SCAL> res;
|
|
286
|
+
res.Value() = x.Value()-y.Value();
|
|
287
|
+
for (int i = 0; i < D; i++)
|
|
288
|
+
res.DValue(i) = x.DValue(i) - y.DValue(i);
|
|
289
|
+
for (int i = 0; i < D*D; i++)
|
|
290
|
+
res.DDValue(i) = x.DDValue(i) - y.DDValue(i);
|
|
291
|
+
return res;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
///
|
|
296
|
+
template<int D, typename SCAL, typename SCAL2,
|
|
297
|
+
typename std::enable_if<std::is_convertible<SCAL2,SCAL>::value, int>::type = 0>
|
|
298
|
+
inline AutoDiffDiff<D, SCAL> operator+ (SCAL2 x, const AutoDiffDiff<D, SCAL> & y) throw()
|
|
299
|
+
{
|
|
300
|
+
AutoDiffDiff<D, SCAL> res;
|
|
301
|
+
res.Value() = x+y.Value();
|
|
302
|
+
for (int i = 0; i < D; i++)
|
|
303
|
+
res.DValue(i) = y.DValue(i);
|
|
304
|
+
for (int i = 0; i < D*D; i++)
|
|
305
|
+
res.DDValue(i) = y.DDValue(i);
|
|
306
|
+
return res;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
///
|
|
310
|
+
template<int D, typename SCAL, typename SCAL2,
|
|
311
|
+
typename std::enable_if<std::is_convertible<SCAL2,SCAL>::value, int>::type = 0>
|
|
312
|
+
inline AutoDiffDiff<D, SCAL> operator+ (const AutoDiffDiff<D, SCAL> & y, SCAL2 x) throw()
|
|
313
|
+
{
|
|
314
|
+
AutoDiffDiff<D, SCAL> res;
|
|
315
|
+
res.Value() = x+y.Value();
|
|
316
|
+
for (int i = 0; i < D; i++)
|
|
317
|
+
res.DValue(i) = y.DValue(i);
|
|
318
|
+
for (int i = 0; i < D*D; i++)
|
|
319
|
+
res.DDValue(i) = y.DDValue(i);
|
|
320
|
+
return res;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
///
|
|
325
|
+
template<int D, typename SCAL>
|
|
326
|
+
inline AutoDiffDiff<D, SCAL> operator- (const AutoDiffDiff<D, SCAL> & x) throw()
|
|
327
|
+
{
|
|
328
|
+
AutoDiffDiff<D, SCAL> res;
|
|
329
|
+
res.Value() = -x.Value();
|
|
330
|
+
for (int i = 0; i < D; i++)
|
|
331
|
+
res.DValue(i) = -x.DValue(i);
|
|
332
|
+
for (int i = 0; i < D*D; i++)
|
|
333
|
+
res.DDValue(i) = -x.DDValue(i);
|
|
334
|
+
return res;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
///
|
|
338
|
+
template<int D, typename SCAL, typename SCAL2,
|
|
339
|
+
typename std::enable_if<std::is_convertible<SCAL2,SCAL>::value, int>::type = 0>
|
|
340
|
+
inline AutoDiffDiff<D, SCAL> operator- (const AutoDiffDiff<D, SCAL> & x, SCAL2 y) throw()
|
|
341
|
+
{
|
|
342
|
+
AutoDiffDiff<D, SCAL> res;
|
|
343
|
+
res.Value() = x.Value()-y;
|
|
344
|
+
for (int i = 0; i < D; i++)
|
|
345
|
+
res.DValue(i) = x.DValue(i);
|
|
346
|
+
for (int i = 0; i < D*D; i++)
|
|
347
|
+
res.DDValue(i) = x.DDValue(i);
|
|
348
|
+
return res;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
///
|
|
352
|
+
template<int D, typename SCAL, typename SCAL2,
|
|
353
|
+
typename std::enable_if<std::is_convertible<SCAL2,SCAL>::value, int>::type = 0>
|
|
354
|
+
inline AutoDiffDiff<D, SCAL> operator- (SCAL2 x, const AutoDiffDiff<D, SCAL> & y) throw()
|
|
355
|
+
{
|
|
356
|
+
AutoDiffDiff<D, SCAL> res;
|
|
357
|
+
res.Value() = x-y.Value();
|
|
358
|
+
for (int i = 0; i < D; i++)
|
|
359
|
+
res.DValue(i) = -y.DValue(i);
|
|
360
|
+
for (int i = 0; i < D*D; i++)
|
|
361
|
+
res.DDValue(i) = -y.DDValue(i);
|
|
362
|
+
return res;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
///
|
|
367
|
+
template<int D, typename SCAL, typename SCAL2,
|
|
368
|
+
typename std::enable_if<std::is_convertible<SCAL2,SCAL>::value, int>::type = 0>
|
|
369
|
+
inline AutoDiffDiff<D, SCAL> operator* (SCAL2 x, const AutoDiffDiff<D, SCAL> & y) throw()
|
|
370
|
+
{
|
|
371
|
+
AutoDiffDiff<D, SCAL> res;
|
|
372
|
+
res.Value() = x*y.Value();
|
|
373
|
+
for (int i = 0; i < D; i++)
|
|
374
|
+
res.DValue(i) = x*y.DValue(i);
|
|
375
|
+
for (int i = 0; i < D*D; i++)
|
|
376
|
+
res.DDValue(i) = x*y.DDValue(i);
|
|
377
|
+
return res;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
///
|
|
381
|
+
template<int D, typename SCAL, typename SCAL2,
|
|
382
|
+
typename std::enable_if<std::is_convertible<SCAL2,SCAL>::value, int>::type = 0>
|
|
383
|
+
inline AutoDiffDiff<D, SCAL> operator* (const AutoDiffDiff<D, SCAL> & y, SCAL2 x) throw()
|
|
384
|
+
{
|
|
385
|
+
AutoDiffDiff<D, SCAL> res;
|
|
386
|
+
res.Value() = x*y.Value();
|
|
387
|
+
for (int i = 0; i < D; i++)
|
|
388
|
+
res.DValue(i) = x*y.DValue(i);
|
|
389
|
+
for (int i = 0; i < D*D; i++)
|
|
390
|
+
res.DDValue(i) = x*y.DDValue(i);
|
|
391
|
+
return res;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
///
|
|
395
|
+
template<int D, typename SCAL>
|
|
396
|
+
inline AutoDiffDiff<D, SCAL> operator* (const AutoDiffDiff<D, SCAL> & x, const AutoDiffDiff<D, SCAL> & y) throw()
|
|
397
|
+
{
|
|
398
|
+
AutoDiffDiff<D, SCAL> res;
|
|
399
|
+
SCAL hx = x.Value();
|
|
400
|
+
SCAL hy = y.Value();
|
|
401
|
+
|
|
402
|
+
res.Value() = hx*hy;
|
|
403
|
+
for (int i = 0; i < D; i++)
|
|
404
|
+
res.DValue(i) = hx*y.DValue(i) + hy*x.DValue(i);
|
|
405
|
+
|
|
406
|
+
for (int i = 0; i < D; i++)
|
|
407
|
+
for (int j = 0; j < D; j++)
|
|
408
|
+
res.DDValue(i,j) = hx * y.DDValue(i,j) + hy * x.DDValue(i,j)
|
|
409
|
+
+ x.DValue(i) * y.DValue(j) + x.DValue(j) * y.DValue(i);
|
|
410
|
+
|
|
411
|
+
return res;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
template<int D, typename SCAL>
|
|
417
|
+
inline AutoDiffDiff<D, SCAL> Inv (const AutoDiffDiff<D, SCAL> & x)
|
|
418
|
+
{
|
|
419
|
+
AutoDiffDiff<D, SCAL> res(1.0 / x.Value());
|
|
420
|
+
for (int i = 0; i < D; i++)
|
|
421
|
+
res.DValue(i) = -x.DValue(i) / (x.Value() * x.Value());
|
|
422
|
+
|
|
423
|
+
SCAL fac1 = 2/(x.Value()*x.Value()*x.Value());
|
|
424
|
+
SCAL fac2 = 1/sqr(x.Value());
|
|
425
|
+
for (int i = 0; i < D; i++)
|
|
426
|
+
for (int j = 0; j < D; j++)
|
|
427
|
+
res.DDValue(i,j) = fac1*x.DValue(i)*x.DValue(j) - fac2*x.DDValue(i,j);
|
|
428
|
+
return res;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
template<int D, typename SCAL>
|
|
433
|
+
inline AutoDiffDiff<D, SCAL> operator/ (const AutoDiffDiff<D, SCAL> & x, const AutoDiffDiff<D, SCAL> & y)
|
|
434
|
+
{
|
|
435
|
+
return x * Inv (y);
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
template<int D, typename SCAL, typename SCAL2,
|
|
439
|
+
typename std::enable_if<std::is_convertible<SCAL2,SCAL>::value, int>::type = 0>
|
|
440
|
+
inline AutoDiffDiff<D, SCAL> operator/ (const AutoDiffDiff<D, SCAL> & x, SCAL2 y)
|
|
441
|
+
{
|
|
442
|
+
return (1/y) * x;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
template<int D, typename SCAL, typename SCAL2,
|
|
446
|
+
typename std::enable_if<std::is_convertible<SCAL2,SCAL>::value, int>::type = 0>
|
|
447
|
+
inline AutoDiffDiff<D, SCAL> operator/ (SCAL2 x, const AutoDiffDiff<D, SCAL> & y)
|
|
448
|
+
{
|
|
449
|
+
return x * Inv(y);
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
|
|
453
|
+
template<int D, typename SCAL>
|
|
454
|
+
inline AutoDiffDiff<D, SCAL> sqrt (const AutoDiffDiff<D, SCAL> & x)
|
|
455
|
+
{
|
|
456
|
+
AutoDiffDiff<D, SCAL> res;
|
|
457
|
+
res.Value() = sqrt(x.Value());
|
|
458
|
+
for (int j = 0; j < D; j++)
|
|
459
|
+
res.DValue(j) = IfZero(x.DValue(j),SCAL{0.},0.5 / res.Value() * x.DValue(j));
|
|
460
|
+
|
|
461
|
+
|
|
462
|
+
for (int i = 0; i < D; i++)
|
|
463
|
+
for (int j = 0; j < D; j++)
|
|
464
|
+
res.DDValue(i,j) = IfZero(x.DDValue(i,j)+x.DValue(i) * x.DValue(j),SCAL{0.},0.5/res.Value() * x.DDValue(i,j) - 0.25 / (x.Value()*res.Value()) * x.DValue(i) * x.DValue(j));
|
|
465
|
+
|
|
466
|
+
return res;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
// df(u)/dx = exp(x) * du/dx
|
|
470
|
+
// d^2 f(u) / dx^2 = exp(x) * (du/dx)^2 + exp(x) * d^2u /dx^2
|
|
471
|
+
template <int D, typename SCAL>
|
|
472
|
+
NETGEN_INLINE AutoDiffDiff<D, SCAL> exp (AutoDiffDiff<D, SCAL> x)
|
|
473
|
+
{
|
|
474
|
+
AutoDiffDiff<D, SCAL> res;
|
|
475
|
+
res.Value() = exp(x.Value());
|
|
476
|
+
for (int k = 0; k < D; k++)
|
|
477
|
+
res.DValue(k) = x.DValue(k) * res.Value();
|
|
478
|
+
for (int k = 0; k < D; k++)
|
|
479
|
+
for (int l = 0; l < D; l++)
|
|
480
|
+
res.DDValue(k,l) = (x.DValue(k) * x.DValue(l)+x.DDValue(k,l)) * res.Value();
|
|
481
|
+
return res;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
using std::pow;
|
|
485
|
+
template <int D, typename SCAL>
|
|
486
|
+
NETGEN_INLINE AutoDiffDiff<D,SCAL> pow (AutoDiffDiff<D,SCAL> x, AutoDiffDiff<D,SCAL> y )
|
|
487
|
+
{
|
|
488
|
+
return exp(log(x)*y);
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
template <int D, typename SCAL>
|
|
492
|
+
NETGEN_INLINE AutoDiffDiff<D, SCAL> log (AutoDiffDiff<D, SCAL> x)
|
|
493
|
+
{
|
|
494
|
+
AutoDiffDiff<D, SCAL> res;
|
|
495
|
+
res.Value() = log(x.Value());
|
|
496
|
+
SCAL xinv = 1.0/x.Value();
|
|
497
|
+
for (int k = 0; k < D; k++)
|
|
498
|
+
res.DValue(k) = x.DValue(k) * xinv;
|
|
499
|
+
for (int k = 0; k < D; k++)
|
|
500
|
+
for (int l = 0; l < D; l++)
|
|
501
|
+
res.DDValue(k,l) = -xinv*xinv*x.DValue(k) * x.DValue(l) + xinv * x.DDValue(k,l);
|
|
502
|
+
return res;
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
|
|
506
|
+
|
|
507
|
+
template <int D, typename SCAL>
|
|
508
|
+
NETGEN_INLINE AutoDiffDiff<D, SCAL> sin (AutoDiffDiff<D, SCAL> x)
|
|
509
|
+
{
|
|
510
|
+
AutoDiffDiff<D, SCAL> res;
|
|
511
|
+
SCAL s = sin(x.Value());
|
|
512
|
+
SCAL c = cos(x.Value());
|
|
513
|
+
|
|
514
|
+
res.Value() = s;
|
|
515
|
+
for (int k = 0; k < D; k++)
|
|
516
|
+
res.DValue(k) = x.DValue(k) * c;
|
|
517
|
+
for (int k = 0; k < D; k++)
|
|
518
|
+
for (int l = 0; l < D; l++)
|
|
519
|
+
res.DDValue(k,l) = -s * x.DValue(k) * x.DValue(l) + c * x.DDValue(k,l);
|
|
520
|
+
return res;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
|
|
524
|
+
template <int D, typename SCAL>
|
|
525
|
+
NETGEN_INLINE AutoDiffDiff<D, SCAL> cos (AutoDiffDiff<D, SCAL> x)
|
|
526
|
+
{
|
|
527
|
+
AutoDiffDiff<D, SCAL> res;
|
|
528
|
+
SCAL s = sin(x.Value());
|
|
529
|
+
SCAL c = cos(x.Value());
|
|
530
|
+
|
|
531
|
+
res.Value() = c;
|
|
532
|
+
for (int k = 0; k < D; k++)
|
|
533
|
+
res.DValue(k) = -s * x.DValue(k);
|
|
534
|
+
for (int k = 0; k < D; k++)
|
|
535
|
+
for (int l = 0; l < D; l++)
|
|
536
|
+
res.DDValue(k,l) = -c * x.DValue(k) * x.DValue(l) - s * x.DDValue(k,l);
|
|
537
|
+
return res;
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
template <int D, typename SCAL>
|
|
541
|
+
NETGEN_INLINE AutoDiffDiff<D, SCAL> tan (AutoDiffDiff<D, SCAL> x)
|
|
542
|
+
{ return sin(x) / cos(x); }
|
|
543
|
+
|
|
544
|
+
|
|
545
|
+
template <int D, typename SCAL>
|
|
546
|
+
NETGEN_INLINE AutoDiffDiff<D, SCAL> atan (AutoDiffDiff<D, SCAL> x)
|
|
547
|
+
{
|
|
548
|
+
AutoDiffDiff<D, SCAL> res;
|
|
549
|
+
SCAL a = atan(x.Value());
|
|
550
|
+
res.Value() = a;
|
|
551
|
+
for (int k = 0; k < D; k++)
|
|
552
|
+
res.DValue(k) = x.DValue(k)/(1+x.Value()*x.Value()) ;
|
|
553
|
+
for (int k = 0; k < D; k++)
|
|
554
|
+
for (int l = 0; l < D; l++)
|
|
555
|
+
res.DDValue(k,l) = -2*x.Value()/((1+x.Value()*x.Value())*(1+x.Value()*x.Value())) * x.DValue(k) * x.DValue(l) + x.DDValue(k,l)/(1+x.Value()*x.Value());
|
|
556
|
+
return res;
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
template <int D, typename SCAL>
|
|
560
|
+
NETGEN_INLINE AutoDiffDiff<D, SCAL> atan2 (AutoDiffDiff<D, SCAL> x,AutoDiffDiff<D, SCAL> y)
|
|
561
|
+
{
|
|
562
|
+
AutoDiffDiff<D, SCAL> res;
|
|
563
|
+
SCAL a = atan2(x.Value(), y.Value());
|
|
564
|
+
res.Value() = a;
|
|
565
|
+
for (int k = 0; k < D; k++)
|
|
566
|
+
res.DValue(k) = (x.Value()*y.DValue(k)-y.Value()*x.DValue(k))/(y.Value()*y.Value()+x.Value()*x.Value());
|
|
567
|
+
|
|
568
|
+
for (int k = 0; k < D; k++)
|
|
569
|
+
for (int l = 0; l < D; l++)
|
|
570
|
+
res.DDValue(k,l) = (x.DValue(k)*y.DValue(l)+x.Value()*y.DDValue(l,k) - y.DValue(k)*x.DValue(l) - y.Value()*x.DDValue(l,k))/(y.Value()*y.Value()+x.Value()*x.Value()) - 2 * (x.Value()*y.DValue(k)-y.Value()*x.DValue(k)) * (x.Value()*x.DValue(k) + y.Value()*y.DValue(k))/( (y.Value()*y.Value()+x.Value()*x.Value()) * (y.Value()*y.Value()+x.Value()*x.Value()) );
|
|
571
|
+
return res;
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
|
|
575
|
+
|
|
576
|
+
using std::acos;
|
|
577
|
+
template <int D, typename SCAL>
|
|
578
|
+
NETGEN_INLINE AutoDiffDiff<D,SCAL> acos (AutoDiffDiff<D,SCAL> x)
|
|
579
|
+
{
|
|
580
|
+
AutoDiffDiff<D,SCAL> res;
|
|
581
|
+
SCAL a = acos(x.Value());
|
|
582
|
+
res.Value() = a;
|
|
583
|
+
auto omaa = 1-x.Value()*x.Value();
|
|
584
|
+
auto s = sqrt(omaa);
|
|
585
|
+
SCAL da = -1 / s;
|
|
586
|
+
SCAL dda = -x.Value() / (s*omaa);
|
|
587
|
+
for (int k = 0; k < D; k++)
|
|
588
|
+
res.DValue(k) = x.DValue(k)*da;
|
|
589
|
+
for (int k = 0; k < D; k++)
|
|
590
|
+
for (int l = 0; l < D; l++)
|
|
591
|
+
res.DDValue(k,l) = dda * x.DValue(k) * x.DValue(l) + da * x.DDValue(k,l);
|
|
592
|
+
|
|
593
|
+
return res;
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
|
|
597
|
+
using std::acos;
|
|
598
|
+
template <int D, typename SCAL>
|
|
599
|
+
NETGEN_INLINE AutoDiffDiff<D,SCAL> asin (AutoDiffDiff<D,SCAL> x)
|
|
600
|
+
{
|
|
601
|
+
AutoDiffDiff<D,SCAL> res;
|
|
602
|
+
SCAL a = asin(x.Value());
|
|
603
|
+
res.Value() = a;
|
|
604
|
+
auto omaa = 1-x.Value()*x.Value();
|
|
605
|
+
auto s = sqrt(omaa);
|
|
606
|
+
SCAL da = 1 / s;
|
|
607
|
+
SCAL dda = x.Value() / (s*omaa);
|
|
608
|
+
for (int k = 0; k < D; k++)
|
|
609
|
+
res.DValue(k) = x.DValue(k)*da;
|
|
610
|
+
for (int k = 0; k < D; k++)
|
|
611
|
+
for (int l = 0; l < D; l++)
|
|
612
|
+
res.DDValue(k,l) = dda * x.DValue(k) * x.DValue(l) + da * x.DDValue(k,l);
|
|
613
|
+
|
|
614
|
+
return res;
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
|
|
618
|
+
template <int D, typename SCAL>
|
|
619
|
+
NETGEN_INLINE AutoDiffDiff<D, SCAL> sinh (AutoDiffDiff<D, SCAL> x)
|
|
620
|
+
{
|
|
621
|
+
AutoDiffDiff<D, SCAL> res;
|
|
622
|
+
SCAL sh = sinh(x.Value());
|
|
623
|
+
SCAL ch = cosh(x.Value());
|
|
624
|
+
|
|
625
|
+
res.Value() = sh;
|
|
626
|
+
for (int k = 0; k < D; k++)
|
|
627
|
+
res.DValue(k) = x.DValue(k) * ch;
|
|
628
|
+
for (int k = 0; k < D; k++)
|
|
629
|
+
for (int l = 0; l < D; l++)
|
|
630
|
+
res.DDValue(k,l) = sh * x.DValue(k) * x.DValue(l) + ch * x.DDValue(k,l);
|
|
631
|
+
return res;
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
|
|
635
|
+
template <int D, typename SCAL>
|
|
636
|
+
NETGEN_INLINE AutoDiffDiff<D, SCAL> cosh (AutoDiffDiff<D, SCAL> x)
|
|
637
|
+
{
|
|
638
|
+
AutoDiffDiff<D, SCAL> res;
|
|
639
|
+
SCAL sh = sinh(x.Value());
|
|
640
|
+
SCAL ch = cosh(x.Value());
|
|
641
|
+
|
|
642
|
+
res.Value() = ch;
|
|
643
|
+
for (int k = 0; k < D; k++)
|
|
644
|
+
res.DValue(k) = sh * x.DValue(k);
|
|
645
|
+
for (int k = 0; k < D; k++)
|
|
646
|
+
for (int l = 0; l < D; l++)
|
|
647
|
+
res.DDValue(k,l) = ch * x.DValue(k) * x.DValue(l) + sh * x.DDValue(k,l);
|
|
648
|
+
return res;
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
template <int D, typename SCAL>
|
|
652
|
+
NETGEN_INLINE AutoDiffDiff<D, SCAL> erf (AutoDiffDiff<D, SCAL> x)
|
|
653
|
+
{
|
|
654
|
+
AutoDiffDiff<D, SCAL> res;
|
|
655
|
+
SCAL derf = 2. / sqrt(M_PI) * exp(- x.Value() * x.Value());
|
|
656
|
+
|
|
657
|
+
res.Value() = erf(x.Value());
|
|
658
|
+
for (int k = 0; k < D; k++)
|
|
659
|
+
res.DValue(k) = - derf * x.DValue(k);
|
|
660
|
+
for (int k = 0; k < D; k++)
|
|
661
|
+
for (int l = 0; l < D; l++)
|
|
662
|
+
res.DDValue(k,l) = derf * (x.DDValue(k, l) - 2 * x.Value() * x.DValue(k) * x.DValue(l));
|
|
663
|
+
return res;
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
using std::floor;
|
|
667
|
+
template<int D, typename SCAL>
|
|
668
|
+
NETGEN_INLINE AutoDiffDiff<D,SCAL> floor (const AutoDiffDiff<D,SCAL> & x)
|
|
669
|
+
{
|
|
670
|
+
return floor(x.Value());
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
using std::ceil;
|
|
674
|
+
template<int D, typename SCAL>
|
|
675
|
+
NETGEN_INLINE AutoDiffDiff<D,SCAL> ceil (const AutoDiffDiff<D,SCAL> & x)
|
|
676
|
+
{
|
|
677
|
+
return ceil(x.Value());
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
|
|
681
|
+
template <int D, typename SCAL, typename TB, typename TC>
|
|
682
|
+
auto IfPos (AutoDiffDiff<D,SCAL> a, TB b, TC c) -> decltype(IfPos (a.Value(), b, c))
|
|
683
|
+
{
|
|
684
|
+
return IfPos (a.Value(), b, c);
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
template <int D, typename SCAL>
|
|
688
|
+
NETGEN_INLINE AutoDiffDiff<D,SCAL> IfPos (SCAL /* SIMD<double> */ a, AutoDiffDiff<D,SCAL> b, AutoDiffDiff<D,SCAL> c)
|
|
689
|
+
{
|
|
690
|
+
AutoDiffDiff<D,SCAL> res;
|
|
691
|
+
res.Value() = IfPos (a, b.Value(), c.Value());
|
|
692
|
+
for (int j = 0; j < D; j++)
|
|
693
|
+
{
|
|
694
|
+
res.DValue(j) = IfPos (a, b.DValue(j), c.DValue(j));
|
|
695
|
+
res.DDValue(j) = IfPos (a, b.DDValue(j), c.DDValue(j));
|
|
696
|
+
}
|
|
697
|
+
return res;
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
template <int D, typename SCAL, typename TC>
|
|
701
|
+
NETGEN_INLINE AutoDiffDiff<D,SCAL> IfPos (SCAL /* SIMD<double> */ a, AutoDiffDiff<D,SCAL> b, TC c)
|
|
702
|
+
{
|
|
703
|
+
return IfPos (a, b, AutoDiffDiff<D,SCAL> (c));
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
|
|
707
|
+
|
|
708
|
+
|
|
709
|
+
//@}
|
|
710
|
+
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
|
|
714
|
+
namespace ngbla
|
|
715
|
+
{
|
|
716
|
+
template <typename T> struct is_scalar_type;
|
|
717
|
+
template <int D, typename T>
|
|
718
|
+
struct is_scalar_type<ngcore::AutoDiffDiff<D,T>> { static constexpr bool value = true; };
|
|
719
|
+
|
|
720
|
+
|
|
721
|
+
// not meaningful for AutoDiff<D,Complex>, since this is
|
|
722
|
+
// not (complex) differentiable anyway
|
|
723
|
+
template<int D, typename SCAL>
|
|
724
|
+
inline auto L2Norm2 (const ngcore::AutoDiffDiff<D,SCAL> & x)
|
|
725
|
+
{
|
|
726
|
+
return x*x;
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
|
|
732
|
+
|
|
733
|
+
#endif
|