v0.15.0
Loading...
Searching...
No Matches
Functions
adol-c_atom.cpp File Reference
#include <adolc/adolc.h>
#include <iostream>

Go to the source code of this file.

Functions

adouble power (adouble x, int n)
 
int main ()
 

Function Documentation

◆ main()

int main ( )
Examples
ep.cpp, mofem/atom_tests/add_blockset.cpp, mofem/atom_tests/add_cubit_meshsets.cpp, mofem/atom_tests/bernstein_bezier_generate_base.cpp, mofem/atom_tests/boundary_marker.cpp, mofem/atom_tests/build_composite_problem.cpp, mofem/atom_tests/build_large_problem.cpp, mofem/atom_tests/build_problems.cpp, mofem/atom_tests/child_and_parent.cpp, mofem/atom_tests/continuity_check_on_contact_prism_side_ele.cpp, mofem/atom_tests/continuity_check_on_skeleton_3d.cpp, mofem/atom_tests/continuity_check_on_skeleton_with_simple_2d_for_h1.cpp, mofem/atom_tests/continuity_check_on_skeleton_with_simple_2d_for_hcurl.cpp, mofem/atom_tests/continuity_check_on_skeleton_with_simple_2d_for_hdiv.cpp, mofem/atom_tests/cubit_bc_test.cpp, mofem/atom_tests/dg_projection.cpp, mofem/atom_tests/dm_build_partitioned_mesh.cpp, mofem/atom_tests/dm_create_subdm.cpp, mofem/atom_tests/dm_partitioned_no_field.cpp, mofem/atom_tests/edge_and_bubble_shape_functions_on_quad.cpp, mofem/atom_tests/field_blas.cpp, mofem/atom_tests/field_blas_axpy.cpp, mofem/atom_tests/field_evaluator.cpp, mofem/atom_tests/find_local_coordinates.cpp, mofem/atom_tests/forces_and_sources_testing_edge_element.cpp, mofem/atom_tests/forces_and_sources_testing_flat_prism_element.cpp, mofem/atom_tests/forces_and_sources_testing_users_base.cpp, mofem/atom_tests/gauss_points_on_outer_product.cpp, mofem/atom_tests/hanging_node_approx.cpp, mofem/atom_tests/hcurl_check_approx_in_2d.cpp, mofem/atom_tests/hcurl_curl_operator.cpp, mofem/atom_tests/hcurl_divergence_operator_2d.cpp, mofem/atom_tests/hdiv_check_approx_in_3d.cpp, mofem/atom_tests/hdiv_divergence_operator.cpp, mofem/atom_tests/higher_derivatives.cpp, mofem/atom_tests/log.cpp, mofem/atom_tests/loop_entities.cpp, mofem/atom_tests/matrix_function.cpp, mofem/atom_tests/mesh_insert_interface_atom.cpp, mofem/atom_tests/node_merge.cpp, mofem/atom_tests/operators_tests.cpp, mofem/atom_tests/partition_mesh.cpp, mofem/atom_tests/petsc_smart_ptr_objects.cpp, mofem/atom_tests/prism_elements_from_surface.cpp, mofem/atom_tests/prism_polynomial_approximation.cpp, mofem/atom_tests/quad_polynomial_approximation.cpp, mofem/atom_tests/remove_entities_from_problem.cpp, mofem/atom_tests/remove_entities_from_problem_not_partitioned.cpp, mofem/atom_tests/scalar_check_approximation.cpp, mofem/atom_tests/schur_test_diag_mat.cpp, mofem/atom_tests/simple_interface.cpp, mofem/atom_tests/simple_l2_only.cpp, mofem/atom_tests/tensor_divergence_operator.cpp, mofem/atom_tests/test_broken_space.cpp, mofem/atom_tests/test_cache_on_entities.cpp, mofem/tools/delete_ho_nodes.cpp, mofem/tools/extrude_prisms.cpp, mofem/tools/field_to_vertices.cpp, mofem/tools/mesh_cut.cpp, mofem/tools/mesh_smoothing.cpp, mofem/tools/meshset_to_vtk.cpp, mofem/tools/remove_mofem_meshsets.cpp, mofem/tools/split_sideset.cpp, mofem/tutorials/adv-0/plastic.cpp, mofem/tutorials/adv-2/thermo_elastic.cpp, mofem/tutorials/adv-3/level_set.cpp, mofem/tutorials/adv-4/dynamic_first_order_con_law.cpp, mofem/tutorials/adv-5/seepage.cpp, mofem/tutorials/clx-0/helmholtz.cpp, mofem/tutorials/cor-0to1/unsaturated_transport.cpp, mofem/tutorials/cor-10/navier_stokes.cpp, mofem/tutorials/cor-2to5/analytical_nonlinear_poisson.cpp, mofem/tutorials/cor-2to5/analytical_poisson.cpp, mofem/tutorials/cor-2to5/analytical_poisson_field_split.cpp, mofem/tutorials/cor-6/simple_elasticity.cpp, mofem/tutorials/cor-7/elasticity_mixed_formulation.cpp, mofem/tutorials/cor-9/reaction_diffusion.cpp, mofem/tutorials/fun-0/hello_world.cpp, mofem/tutorials/fun-1/integration.cpp, mofem/tutorials/fun-2/plot_base.cpp, mofem/tutorials/max-0/magnetostatic.cpp, mofem/tutorials/max-1/lorentz_force.cpp, mofem/tutorials/mix-0/mixed_poisson.cpp, mofem/tutorials/mix-1/phase.cpp, mofem/tutorials/scl-0/approximaton.cpp, mofem/tutorials/scl-1/poisson_2d_homogeneous.cpp, mofem/tutorials/scl-10/initial_diffusion.cpp, mofem/tutorials/scl-10/photon_diffusion.cpp, mofem/tutorials/scl-11/poisson_2d_dis_galerkin.cpp, mofem/tutorials/scl-12/electrostatics.cpp, mofem/tutorials/scl-6/heat_equation.cpp, mofem/tutorials/scl-7/wave_equation.cpp, mofem/tutorials/scl-8/radiation.cpp, mofem/tutorials/scl-9/heat_method.cpp, mofem/tutorials/vec-0/elastic.cpp, mofem/tutorials/vec-1/eigen_elastic.cpp, mofem/tutorials/vec-10/schur_elastic.cpp, mofem/tutorials/vec-2/nonlinear_elastic.cpp, mofem/tutorials/vec-3/nonlinear_dynamic_elastic.cpp, mofem/tutorials/vec-4/approx_sphere.cpp, mofem/tutorials/vec-4/shallow_wave.cpp, mofem/tutorials/vec-5/free_surface.cpp, mofem/tutorials/vec-6/plate.cpp, mofem/tutorials/vec-7/adjoint.cpp, mofem/tutorials/vec-9/arc_length.cpp, mofem/users_modules/adolc-plasticity/adolc_plasticity.cpp, mofem/users_modules/basic_finite_elements/atom_tests/testing_jacobian_of_hook_element.cpp, mofem/users_modules/basic_finite_elements/atom_tests/testing_jacobian_of_hook_scaled_with_density_element.cpp, mofem/users_modules/basic_finite_elements/elasticity/elasticity.cpp, mofem/users_modules/basic_finite_elements/nonlinear_elasticity/nonlinear_dynamics.cpp, mofem/users_modules/bone_remodelling/bone_adaptation.cpp, mofem/users_modules/eshelbian_plasticity/ep.cpp, and mofem/users_modules/minimal_surface_equation/minimal_surface_area.cpp.

Definition at line 46 of file adol-c_atom.cpp.

46 {
47 int i,tag = 1;
48 int n = 6;
49
50 //cout << "COMPUTATION OF N-TH POWER (ADOL-C Documented Example)\n\n";
51 //cout << "monomial degree=? \n"; /* input the desired degree */
52 //cin >> n;
53 /* allocations and initializations */
54 double** X;
55 double** Y;
56 X = myalloc2(1,n+4);
57 Y = myalloc2(1,n+4);
58 X[0][0] = 0.5; /* function value = 0. coefficient */
59 X[0][1] = 1.0; /* first derivative = 1. coefficient */
60 for(i=0; i<n+2; i++)
61 X[0][i+2] = 0; /* further coefficients */
62 double** Z; /* used for checking consistency */
63 Z = myalloc2(1,n+2); /* between forward and reverse */
64
65 adouble y,x; /* declare active variables */
66 /* beginning of active section */
67 trace_on(tag); /* tag = 1 and keep = 0 */
68 x <<= X[0][0]; /* only one independent var */
69 y = power(x,n); /* actual function call */
70 y >>= Y[0][0]; /* only one dependent adouble */
71 trace_off(); /* no global adouble has died */
72 /* end of active section */
73 double u[1]; /* weighting vector */
74 u[0]=1; /* for reverse call */
75 for(i=0; i<n+2; i++) /* note that keep = i+1 in call */
76 { forward(tag,1,1,i,i+1,X,Y); /* evaluate the i-the derivative */
77 if (i==0)
78 cout << Y[0][i] << " - " << y.value() << " = " << Y[0][i]-y.value()
79 << " (should be 0)\n";
80 else {
81 Z[0][i] = Z[0][i-1]/i; /* scale derivative to Taylorcoeff. */
82 cout << Y[0][i] << " - " << Z[0][i] << " = " << Y[0][i]-Z[0][i]
83 << " (should be 0)\n";
84 }
85 reverse(tag,1,1,i,u,Z); /* evaluate the (i+1)-st deriv. */
86 } /* end for */
87
88 return 0;
89} /* end main */
adouble power(adouble x, int n)
FTensor::Index< 'i', SPACE_DIM > i
const double n
refractive index of diffusive medium

◆ power()

adouble power ( adouble  x,
int  n 
)

Definition at line 25 of file adol-c_atom.cpp.

25 {
26 adouble z = 1;
27
28 if (n>0) /* Recursion and branches */
29 { int nh = n/2; /* that do not depend on */
30 z = power(x,nh); /* adoubles are fine !!!! */
31 z *= z;
32 if (2*nh != n)
33 z *= x;
34 return z;
35 } /* end if */
36 else {
37 if (n==0) /* The local adouble z dies */
38 return z; /* as it goes out of scope. */
39 else
40 return 1/power(x,-n);
41 } /* end else */
42} /* end power */