Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AD Strong DG - Implicit Inviscid - Computes Jacobians #261

Draft
wants to merge 37 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
02c2450
Added assemble_cell_residual_derivative()
PranshulThakur May 17, 2024
61cfe46
created cell_residual_derivatives
May 21, 2024
9f911d8
Added code of volume term.
PranshulThakur May 21, 2024
1b4f2aa
Added code.
May 22, 2024
8f2e84d
Added more code.
PranshulThakur May 22, 2024
6d64a72
Added code.
May 23, 2024
6551bf9
Added code.
May 23, 2024
b4179ae
Added code.
PranshulThakur May 23, 2024
de75177
Added code.
PranshulThakur May 23, 2024
a4275e4
Added code.
May 24, 2024
338c744
Added code.
May 24, 2024
31d9035
Added code.
PranshulThakur May 24, 2024
cf6e592
Added code.
PranshulThakur May 24, 2024
d93adc9
Restructured code.
Jun 3, 2024
2f888a7
Fixed compile errors.
PranshulThakur Jun 3, 2024
50b0448
Added code.
PranshulThakur Jun 4, 2024
fc758fd
Working AD which is moved out.
Jun 10, 2024
e0c2a59
Added test to look at derivatives. To be removed later.
PranshulThakur Jun 10, 2024
451673b
Updated DGBase with position-based AD tape evaluation.
PranshulThakur Jun 11, 2024
a85a877
Removed old test files.
PranshulThakur Jun 11, 2024
3f088e8
Renamed functions.
PranshulThakur Jun 13, 2024
7878659
Merged latest master.
PranshulThakur Jun 13, 2024
419d41d
Moved volume and boundary fe values in weak dg. Still need to do it f…
PranshulThakur Jun 14, 2024
9465e53
Added additional parameters to volume residual ad function
Jun 16, 2024
4b460c1
Moved fe_values in weakDG.
PranshulThakur Jun 17, 2024
488f9d5
Renamed tape position.
PranshulThakur Jun 18, 2024
9d7c2f2
Templated operators for all AD type and restructured it for the opera…
AlexanderCicchino Jun 18, 2024
fca9e77
Restructured header functions in header files for DG/DG_Weak/DG_Stron…
AlexanderCicchino Jun 22, 2024
6698ae3
Restructured DG/DG Strong for AD variables with operators class--comp…
AlexanderCicchino Jun 27, 2024
e4b18de
Added a few tests showcasing the AD Jacobian works for DG strong with…
AlexanderCicchino Jun 27, 2024
d4d8185
Added strong form finite difference vs AD unit tests.
AlexanderCicchino Jun 27, 2024
c73c82f
dRdX for strong works now with sensitivity unit tests to verify.
AlexanderCicchino Jun 27, 2024
288b4c7
D2R for strong dg.
AlexanderCicchino Jun 27, 2024
eeb1977
Cleaned up DG/DGStrong/DGWeak from deprecated functions.
AlexanderCicchino Jun 27, 2024
f72b78b
Merge branch 'dougshidong:master' into ad_strong_weak_dg
AlexanderCicchino Jul 3, 2024
817730e
Fixed issue with auxiliary RHS test.
AlexanderCicchino Jul 3, 2024
6ee3660
Fixed assert issues when compile with debug.
AlexanderCicchino Jul 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/ADTypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ using codi_HessianComputationType = codi::RealReversePrimalIndexGen< codi::Real
//using RadFadType = codi_JacobianComputationType; ///< Reverse only mode that only allows Jacobian computation.
using RadType = codi_JacobianComputationType; ///< CoDiPaco reverse-AD type for first derivatives.
using RadFadType = codi_HessianComputationType ; ///< Nested reverse-forward mode type for Jacobian and Hessian computation using TapeHelper.

/// Tape helper class derived from CoDiPack
template<typename adtype>
class codi_TapeHelper : public codi::TapeHelper<adtype>
{
public:
/// Returns reference to codi::TapeHelper<adtype>::inputValues which can be used in PHiLiP to add inputs that have already been registered in the global tape.
std::vector<typename adtype::GradientData>& getinputValues() {return this->inputValues;}
};
} // PHiLiP namespace

#endif
1,549 changes: 1,369 additions & 180 deletions src/dg/dg_base.cpp

Large diffs are not rendered by default.

713 changes: 485 additions & 228 deletions src/dg/dg_base.hpp

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/dg/dg_base_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ void DGBaseState<dim, nstate, real, MeshType>::update_model_variables() {

template <int dim, int nstate, typename real, typename MeshType>
void DGBaseState<dim, nstate, real, MeshType>::set_use_auxiliary_eq() {
this->use_auxiliary_eq = pde_physics_double->has_nonzero_diffusion;
this->use_auxiliary_eq = (pde_physics_double->has_nonzero_diffusion && !this->all_parameters->use_weak_form) ? true : false;
}

template <int dim, int nstate, typename real, typename MeshType>
Expand Down Expand Up @@ -236,4 +236,4 @@ BOOST_PP_SEQ_FOR_EACH(INSTANTIATE_SHARED, _, POSSIBLE_NSTATE)
template class DGBaseState <PHILIP_DIM, index, double, dealii::Triangulation<PHILIP_DIM>>;
BOOST_PP_SEQ_FOR_EACH(INSTANTIATE_TRIA, _, POSSIBLE_NSTATE)

} // namespace PHiLiP
} // namespace PHiLiP
1 change: 1 addition & 0 deletions src/dg/dg_base_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class DGBaseState : public DGBase<dim, real, MeshType>
/** Usually called after setting physics.
*/
void reset_numerical_fluxes();

}; // end of DGBaseState class

} // namespace PHiLiP
Expand Down
1,969 changes: 751 additions & 1,218 deletions src/dg/strong_dg.cpp

Large diffs are not rendered by default.

1,058 changes: 831 additions & 227 deletions src/dg/strong_dg.hpp

Large diffs are not rendered by default.

3,359 changes: 725 additions & 2,634 deletions src/dg/weak_dg.cpp

Large diffs are not rendered by default.

1,075 changes: 762 additions & 313 deletions src/dg/weak_dg.hpp

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ void LimiterConvergenceTests<dim, nstate>::check_limiter_principle(DGBase<dim, d
const unsigned int init_grid_degree = dg.max_grid_degree;
const unsigned int poly_degree = this->all_param.flow_solver_param.poly_degree;
//Constructor for the operators
OPERATOR::basis_functions<dim, 2 * dim, double> soln_basis(1, poly_degree, init_grid_degree);
OPERATOR::vol_projection_operator<dim, 2 * dim, double> soln_basis_projection_oper(1, dg.max_degree, init_grid_degree);
OPERATOR::basis_functions<dim, 2 * dim> soln_basis(1, poly_degree, init_grid_degree);
OPERATOR::vol_projection_operator<dim, 2 * dim> soln_basis_projection_oper(1, dg.max_degree, init_grid_degree);


// Build the oneD operator to perform interpolation/projection
Expand Down Expand Up @@ -217,4 +217,4 @@ void LimiterConvergenceTests<dim, nstate>::compute_unsteady_data_and_write_to_ta
#endif

}
}
}
6 changes: 3 additions & 3 deletions src/flow_solver/flow_solver_cases/non_periodic_cube_flow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ void NonPeriodicCubeFlow<dim, nstate>::check_positivity_density(DGBase<dim, doub
const unsigned int init_grid_degree = dg.max_grid_degree;
const unsigned int poly_degree = this->all_param.flow_solver_param.poly_degree;
//Constructor for the operators
OPERATOR::basis_functions<dim, 2 * dim, double> soln_basis(1, poly_degree, init_grid_degree);
OPERATOR::vol_projection_operator<dim, 2 * dim, double> soln_basis_projection_oper(1, dg.max_degree, init_grid_degree);
OPERATOR::basis_functions<dim, 2 * dim> soln_basis(1, poly_degree, init_grid_degree);
OPERATOR::vol_projection_operator<dim, 2 * dim> soln_basis_projection_oper(1, dg.max_degree, init_grid_degree);


// Build the oneD operator to perform interpolation/projection
Expand Down Expand Up @@ -164,4 +164,4 @@ void NonPeriodicCubeFlow<dim, nstate>::compute_unsteady_data_and_write_to_table(
template class NonPeriodicCubeFlow <PHILIP_DIM,PHILIP_DIM+2>;
#endif
} // FlowSolver namespace
} // PHiLiP namespace
} // PHiLiP namespace
4 changes: 2 additions & 2 deletions src/flow_solver/flow_solver_cases/periodic_entropy_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ double PeriodicEntropyTests<dim, nstate>::compute_integrated_quantities(DGBase<d
const unsigned int n_quad_pts = n_quad_pts_;

// Construct the basis functions and mapping shape functions.
OPERATOR::basis_functions<dim,2*dim,double> soln_basis(1, poly_degree, grid_degree);
OPERATOR::mapping_shape_functions<dim,2*dim,double> mapping_basis(1, poly_degree, grid_degree);
OPERATOR::basis_functions<dim,2*dim> soln_basis(1, poly_degree, grid_degree);
OPERATOR::mapping_shape_functions<dim,2*dim> mapping_basis(1, poly_degree, grid_degree);
// Build basis function volume operator and gradient operator from 1D finite element for 1 state.
soln_basis.build_1D_volume_operator(dg.oneD_fe_collection_1state[poly_degree], quad_1D);
soln_basis.build_1D_gradient_operator(dg.oneD_fe_collection_1state[poly_degree], quad_1D);
Expand Down
14 changes: 7 additions & 7 deletions src/flow_solver/flow_solver_cases/periodic_turbulence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,12 @@ void PeriodicTurbulence<dim, nstate>::output_velocity_field(
dealii::FE_DGQArbitraryNodes<1,1> equidistant_finite_element(vol_quad_equidistant_1D);

const unsigned int init_grid_degree = dg->high_order_grid->fe_system.tensor_degree();
OPERATOR::basis_functions<dim,2*dim,double> soln_basis(1, dg->max_degree, init_grid_degree);
OPERATOR::basis_functions<dim,2*dim> soln_basis(1, dg->max_degree, init_grid_degree);
soln_basis.build_1D_volume_operator(dg->oneD_fe_collection_1state[dg->max_degree], vol_quad_equidistant_1D);
soln_basis.build_1D_gradient_operator(dg->oneD_fe_collection_1state[dg->max_degree], vol_quad_equidistant_1D);

// mapping basis for the equidistant node set because we output the physical coordinates
OPERATOR::mapping_shape_functions<dim,2*dim,double> mapping_basis_at_equidistant(1, dg->max_degree, init_grid_degree);
OPERATOR::mapping_shape_functions<dim,2*dim> mapping_basis_at_equidistant(1, dg->max_degree, init_grid_degree);
mapping_basis_at_equidistant.build_1D_shape_functions_at_grid_nodes(dg->high_order_grid->oneD_fe_system, dg->high_order_grid->oneD_grid_nodes);
mapping_basis_at_equidistant.build_1D_shape_functions_at_flux_nodes(dg->high_order_grid->oneD_fe_system, vol_quad_equidistant_1D, dg->oneD_face_quadrature);

Expand Down Expand Up @@ -340,8 +340,8 @@ void PeriodicTurbulence<dim, nstate>::compute_and_update_integrated_quantities(D
const unsigned int grid_degree = dg.high_order_grid->fe_system.tensor_degree();
const unsigned int poly_degree = dg.max_degree;
// Construct the basis functions and mapping shape functions.
OPERATOR::basis_functions<dim,2*dim,double> soln_basis(1, poly_degree, grid_degree);
OPERATOR::mapping_shape_functions<dim,2*dim,double> mapping_basis(1, poly_degree, grid_degree);
OPERATOR::basis_functions<dim,2*dim> soln_basis(1, poly_degree, grid_degree);
OPERATOR::mapping_shape_functions<dim,2*dim> mapping_basis(1, poly_degree, grid_degree);
// Build basis function volume operator and gradient operator from 1D finite element for 1 state.
soln_basis.build_1D_volume_operator(dg.oneD_fe_collection_1state[poly_degree], quad_extra_1D);
soln_basis.build_1D_gradient_operator(dg.oneD_fe_collection_1state[poly_degree], quad_extra_1D);
Expand Down Expand Up @@ -560,14 +560,14 @@ double PeriodicTurbulence<dim, nstate>::compute_current_integrated_numerical_ent
const unsigned int n_quad_pts = dg->volume_quadrature_collection[poly_degree].size();
const unsigned int n_shape_fns = n_dofs_cell / nstate;

OPERATOR::vol_projection_operator<dim,2*dim,double> vol_projection(1, poly_degree, dg->max_grid_degree);
OPERATOR::vol_projection_operator<dim,2*dim> vol_projection(1, poly_degree, dg->max_grid_degree);
vol_projection.build_1D_volume_operator(dg->oneD_fe_collection_1state[poly_degree], dg->oneD_quadrature_collection[poly_degree]);

// Construct the basis functions and mapping shape functions.
OPERATOR::basis_functions<dim,2*dim,double> soln_basis(1, poly_degree, dg->max_grid_degree);
OPERATOR::basis_functions<dim,2*dim> soln_basis(1, poly_degree, dg->max_grid_degree);
soln_basis.build_1D_volume_operator(dg->oneD_fe_collection_1state[poly_degree], dg->oneD_quadrature_collection[poly_degree]);

OPERATOR::mapping_shape_functions<dim,2*dim,double> mapping_basis(1, poly_degree, dg->max_grid_degree);
OPERATOR::mapping_shape_functions<dim,2*dim> mapping_basis(1, poly_degree, dg->max_grid_degree);
mapping_basis.build_1D_shape_functions_at_grid_nodes(dg->high_order_grid->oneD_fe_system, dg->high_order_grid->oneD_grid_nodes);
mapping_basis.build_1D_shape_functions_at_flux_nodes(dg->high_order_grid->oneD_fe_system, dg->oneD_quadrature_collection[poly_degree], dg->oneD_face_quadrature);

Expand Down
6 changes: 3 additions & 3 deletions src/limiter/maximum_principle_limiter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ void MaximumPrincipleLimiter<dim, nstate, real>::limit(
//modal coefficients.
const unsigned int init_grid_degree = grid_degree;
//Constructor for the operators
OPERATOR::basis_functions<dim, 2 * dim, real> soln_basis(1, max_degree, init_grid_degree);
OPERATOR::vol_projection_operator<dim, 2 * dim, real> soln_basis_projection_oper(1, max_degree, init_grid_degree);
OPERATOR::basis_functions<dim, 2 * dim> soln_basis(1, max_degree, init_grid_degree);
OPERATOR::vol_projection_operator<dim, 2 * dim> soln_basis_projection_oper(1, max_degree, init_grid_degree);


// Build the oneD operator to perform interpolation/projection
Expand Down Expand Up @@ -229,4 +229,4 @@ template class MaximumPrincipleLimiter <PHILIP_DIM, 3, double>;
template class MaximumPrincipleLimiter <PHILIP_DIM, 4, double>;
template class MaximumPrincipleLimiter <PHILIP_DIM, 5, double>;
template class MaximumPrincipleLimiter <PHILIP_DIM, 6, double>;
} // PHiLiP namespace
} // PHiLiP namespace
6 changes: 3 additions & 3 deletions src/limiter/positivity_preserving_limiter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ void PositivityPreservingLimiter<dim, nstate, real>::limit(
const unsigned int init_grid_degree = grid_degree;

// Constructor for the operators
OPERATOR::basis_functions<dim, 2 * dim, real> soln_basis(1, max_degree, init_grid_degree);
OPERATOR::vol_projection_operator<dim, 2 * dim, real> soln_basis_projection_oper(1, max_degree, init_grid_degree);
OPERATOR::basis_functions<dim, 2 * dim> soln_basis(1, max_degree, init_grid_degree);
OPERATOR::vol_projection_operator<dim, 2 * dim> soln_basis_projection_oper(1, max_degree, init_grid_degree);

// Build the oneD operator to perform interpolation/projection
soln_basis.build_1D_volume_operator(oneD_fe_collection_1state[max_degree], oneD_quadrature_collection[max_degree]);
Expand Down Expand Up @@ -333,4 +333,4 @@ template class PositivityPreservingLimiter <PHILIP_DIM, 3, double>;
template class PositivityPreservingLimiter <PHILIP_DIM, 4, double>;
template class PositivityPreservingLimiter <PHILIP_DIM, 5, double>;
template class PositivityPreservingLimiter <PHILIP_DIM, 6, double>;
} // PHiLiP namespace
} // PHiLiP namespace
8 changes: 4 additions & 4 deletions src/limiter/tvb_limiter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ std::array<real, nstate> TVBLimiter<dim, nstate, real>::get_neighbour_cell_avg(
const dealii::LinearAlgebra::distributed::Vector<double>& solution,
const dealii::hp::FECollection<dim>& fe_collection,
const dealii::hp::QCollection<dim>& volume_quadrature_collection,
OPERATOR::basis_functions<dim, 2 * dim, real> soln_basis,
OPERATOR::basis_functions<dim, 2 * dim> soln_basis,
const int poly_degree,
const std::vector<dealii::types::global_dof_index>& neigh_dofs_indices,
const unsigned int n_dofs_neigh_cell)
Expand Down Expand Up @@ -193,8 +193,8 @@ void TVBLimiter<dim, nstate, real>::limit(
//modal coefficients.
const unsigned int init_grid_degree = grid_degree;
//Constructor for the operators
OPERATOR::basis_functions<dim, 2 * dim, real> soln_basis(1, max_degree, init_grid_degree);
OPERATOR::vol_projection_operator<dim, 2 * dim, real> soln_basis_projection_oper(1, max_degree, init_grid_degree);
OPERATOR::basis_functions<dim, 2 * dim> soln_basis(1, max_degree, init_grid_degree);
OPERATOR::vol_projection_operator<dim, 2 * dim> soln_basis_projection_oper(1, max_degree, init_grid_degree);


//build the oneD operator to perform interpolation/projection
Expand Down Expand Up @@ -306,4 +306,4 @@ template class TVBLimiter <PHILIP_DIM, 4, double>;
template class TVBLimiter <PHILIP_DIM, 5, double>;
template class TVBLimiter <PHILIP_DIM, 6, double>;
#endif
} // PHiLiP namespace
} // PHiLiP namespace
2 changes: 1 addition & 1 deletion src/limiter/tvb_limiter.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class TVBLimiter : public BoundPreservingLimiterState <dim, nstate, real>
const dealii::LinearAlgebra::distributed::Vector<double>& solution,
const dealii::hp::FECollection<dim>& fe_collection,
const dealii::hp::QCollection<dim>& volume_quadrature_collection,
OPERATOR::basis_functions<dim, 2 * dim, real> soln_basis,
OPERATOR::basis_functions<dim, 2 * dim> soln_basis,
const int poly_degree,
const std::vector<dealii::types::global_dof_index>& neigh_dofs_indices,
const unsigned int n_dofs_neigh_cell);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,16 +239,16 @@ real RootFindingRRKODESolver<dim,real,MeshType>::compute_integrated_numerical_en
const unsigned int n_quad_pts = dg->volume_quadrature_collection[poly_degree].size();
const unsigned int n_shape_fns = n_dofs_cell / nstate;

OPERATOR::vol_projection_operator<dim,2*dim,double> vol_projection(1, poly_degree, dg->max_grid_degree);
OPERATOR::vol_projection_operator<dim,2*dim> vol_projection(1, poly_degree, dg->max_grid_degree);
vol_projection.build_1D_volume_operator(dg->oneD_fe_collection_1state[poly_degree],
dg->oneD_quadrature_collection[poly_degree]);

// Construct the basis functions and mapping shape functions.
OPERATOR::basis_functions<dim,2*dim,double> soln_basis(1, poly_degree, dg->max_grid_degree);
OPERATOR::basis_functions<dim,2*dim> soln_basis(1, poly_degree, dg->max_grid_degree);
soln_basis.build_1D_volume_operator(dg->oneD_fe_collection_1state[poly_degree],
dg->oneD_quadrature_collection[poly_degree]);

OPERATOR::mapping_shape_functions<dim,2*dim,double> mapping_basis(1, poly_degree, dg->max_grid_degree);
OPERATOR::mapping_shape_functions<dim,2*dim> mapping_basis(1, poly_degree, dg->max_grid_degree);
mapping_basis.build_1D_shape_functions_at_grid_nodes(dg->high_order_grid->oneD_fe_system,
dg->high_order_grid->oneD_grid_nodes);
mapping_basis.build_1D_shape_functions_at_flux_nodes(dg->high_order_grid->oneD_fe_system,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ dealii::LinearAlgebra::distributed::Vector<double> RKNumEntropy<dim,real,MeshTyp
const unsigned int n_quad_pts = dg->volume_quadrature_collection[poly_degree].size();
const unsigned int n_shape_fns = n_dofs_cell / nstate;
//We have to project the vector of entropy variables because the mass matrix has an interpolation from solution nodes built into it.
OPERATOR::vol_projection_operator<dim,2*dim,double> vol_projection(1, poly_degree, dg->max_grid_degree);
OPERATOR::vol_projection_operator<dim,2*dim> vol_projection(1, poly_degree, dg->max_grid_degree);
vol_projection.build_1D_volume_operator(dg->oneD_fe_collection_1state[poly_degree], dg->oneD_quadrature_collection[poly_degree]);

OPERATOR::basis_functions<dim,2*dim,double> soln_basis(1, poly_degree, dg->max_grid_degree);
OPERATOR::basis_functions<dim,2*dim> soln_basis(1, poly_degree, dg->max_grid_degree);
soln_basis.build_1D_volume_operator(dg->oneD_fe_collection_1state[poly_degree], dg->oneD_quadrature_collection[poly_degree]);

dealii::LinearAlgebra::distributed::Vector<double> entropy_var_hat_global(dg->right_hand_side);
Expand Down
Loading