-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Time Refinement Study using flow_solver (#138)
* First commit for creating a time refinement study based on the flow_solver framework [does not build] * Flow solver runs 1D advection for one time-step size * Time refinement implemented and working * Writing convergence summary at each refinement * Bug fixes - test now runs as before * Adding exact solution [has bugs] * Bug fixes from previous commit * Results replicate 1D_explicit_ode_solver * Reorganized files and removed 1D_explicit_ode_solver test by removing directory from CMakeLists.txt * clean files/comments/naming * Renamed calculate_L2_error_at_final_time() --> calculate_L2_error_at_final_time_wrt_function() in anticipation of comparing to a reference solution' * Moved grid generation into straight_periodic_cube.cppw * Minor changes (comments, naming, minor functional changes) according to PR comments * Changed tolerance to 1E-13 rather than 0.5 dt for exiting the while loop in run_test() * Periodic1DFlow class now derives from PeriodicCubeFlow. Removed periodic_1D_flow.<cpp/h>. * Update src/testing/time_refinement_study_advection.cpp Co-authored-by: Julien Brillon <43619715+jbrillon@users.noreply.github.com> * Renamed TimeRefinementStudyAdvection --> TimeRefinementStudy * Moved calculate_L2_error_at_final_time_wrt_function() into TimeRefinementStudy * Added error check that initial_time_step evenly divides final_time * Renaming files and small changes as per PR comments * Added time refinement study section to parameters; only passing FlowSolverParams in create_ExactSolutionFunction() * Fixed as per PR comments: createExactSolution now takes time argument; Periodic1DUnsteady renamed and moved into separate files; a few minor fixes * Bug fixes from merge * Update src/testing/time_refinement_study.cpp Co-authored-by: Julien Brillon <43619715+jbrillon@users.noreply.github.com> * Update src/mesh/grids/straight_periodic_cube.cpp Co-authored-by: Julien Brillon <43619715+jbrillon@users.noreply.github.com> * Changes as per PR comments: remove extra #include lines, initialize t in member initializer list, fix comments Co-authored-by: Julien Brillon <43619715+jbrillon@users.noreply.github.com>
- Loading branch information
Showing
27 changed files
with
648 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
add_subdirectory(initial_conditions) | ||
add_subdirectory(exact_solutions) | ||
|
||
SET(SOURCE | ||
physics_factory.cpp | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
set(SOURCE | ||
exact_solution.cpp | ||
) | ||
|
||
foreach(dim RANGE 1 3) | ||
# Output library | ||
string(CONCAT ExactSolutionsLib ExactSolutions_${dim}D) | ||
add_library(${ExactSolutionsLib} STATIC ${SOURCE}) | ||
# Link with PhysicsLib | ||
string(CONCAT PhysicsLib Physics_${dim}D) | ||
target_link_libraries(${ExactSolutionsLib} ${PhysicsLib}) | ||
|
||
target_compile_definitions(${ExactSolutionsLib} PRIVATE PHILIP_DIM=${dim}) | ||
unset(PhysicsLib) | ||
|
||
# Setup target with deal.II | ||
if(NOT DOC_ONLY) | ||
DEAL_II_SETUP_TARGET(${ExactSolutionsLib}) | ||
endif() | ||
|
||
unset(ExactSolutionsLib) | ||
endforeach() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
#include <deal.II/base/function.h> | ||
#include "exact_solution.h" | ||
|
||
namespace PHiLiP { | ||
|
||
// ======================================================== | ||
// ZERO -- Returns zero everywhere; used a placeholder when no exact solution is defined. | ||
// ======================================================== | ||
template <int dim, int nstate, typename real> | ||
ExactSolutionFunction_Zero<dim,nstate,real> | ||
::ExactSolutionFunction_Zero(double time_compare) | ||
: ExactSolutionFunction<dim,nstate,real>() | ||
, t(time_compare) | ||
{ | ||
} | ||
|
||
template <int dim, int nstate, typename real> | ||
inline real ExactSolutionFunction_Zero<dim,nstate,real> | ||
::value(const dealii::Point<dim,real> &/*point*/, const unsigned int /*istate*/) const | ||
{ | ||
real value = 0; | ||
return value; | ||
} | ||
|
||
// ======================================================== | ||
// 1D SINE -- Exact solution for advection_explicit_time_study | ||
// ======================================================== | ||
template <int dim, int nstate, typename real> | ||
ExactSolutionFunction_1DSine<dim,nstate,real> | ||
::ExactSolutionFunction_1DSine (double time_compare) | ||
: ExactSolutionFunction<dim,nstate,real>() | ||
, t(time_compare) | ||
{ | ||
} | ||
|
||
template <int dim, int nstate, typename real> | ||
inline real ExactSolutionFunction_1DSine<dim,nstate,real> | ||
::value(const dealii::Point<dim,real> &point, const unsigned int /*istate*/) const | ||
{ | ||
double x_adv_speed = 1.0; | ||
|
||
real value = 0; | ||
real pi = dealii::numbers::PI; | ||
if(point[0] >= 0.0 && point[0] <= 2.0){ | ||
value = sin(2*pi*(point[0] - x_adv_speed * t)/2.0); | ||
} | ||
return value; | ||
} | ||
|
||
|
||
//========================================================= | ||
// FLOW SOLVER -- Exact Solution Base Class + Factory | ||
//========================================================= | ||
template <int dim, int nstate, typename real> | ||
ExactSolutionFunction<dim,nstate,real> | ||
::ExactSolutionFunction () | ||
: dealii::Function<dim,real>(nstate) | ||
{ | ||
//do nothing | ||
} | ||
|
||
template <int dim, int nstate, typename real> | ||
std::shared_ptr<ExactSolutionFunction<dim, nstate, real>> | ||
ExactSolutionFactory<dim,nstate, real>::create_ExactSolutionFunction( | ||
const Parameters::FlowSolverParam& flow_solver_parameters, | ||
const double time_compare) | ||
{ | ||
// Get the flow case type | ||
const FlowCaseEnum flow_type = flow_solver_parameters.flow_case_type; | ||
if (flow_type == FlowCaseEnum::advection_periodic) { | ||
if constexpr (dim==1 && nstate==dim) return std::make_shared<ExactSolutionFunction_1DSine<dim,nstate,real> > (time_compare); | ||
} else { | ||
// Select zero function if there is no exact solution defined | ||
return std::make_shared<ExactSolutionFunction_Zero<dim,nstate,real>> (time_compare); | ||
} | ||
return nullptr; | ||
} | ||
|
||
template class ExactSolutionFunction <PHILIP_DIM,PHILIP_DIM, double>; | ||
template class ExactSolutionFunction <PHILIP_DIM,PHILIP_DIM+2, double>; | ||
template class ExactSolutionFactory <PHILIP_DIM, PHILIP_DIM+2, double>; | ||
template class ExactSolutionFactory <PHILIP_DIM, PHILIP_DIM, double>; | ||
template class ExactSolutionFunction_Zero <PHILIP_DIM,1, double>; | ||
template class ExactSolutionFunction_Zero <PHILIP_DIM,2, double>; | ||
template class ExactSolutionFunction_Zero <PHILIP_DIM,3, double>; | ||
template class ExactSolutionFunction_Zero <PHILIP_DIM,4, double>; | ||
template class ExactSolutionFunction_Zero <PHILIP_DIM,5, double>; | ||
|
||
} // PHiLiP namespace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#ifndef __EXACT_SOLUTION_H__ | ||
#define __EXACT_SOLUTION_H__ | ||
|
||
// for the exact_solution function | ||
#include <deal.II/lac/vector.h> | ||
#include <deal.II/base/function.h> | ||
#include "parameters/all_parameters.h" | ||
|
||
namespace PHiLiP { | ||
|
||
/// Initial condition function used to initialize a particular flow setup/case | ||
template <int dim, int nstate, typename real> | ||
class ExactSolutionFunction : public dealii::Function<dim,real> | ||
{ | ||
protected: | ||
using dealii::Function<dim,real>::value; ///< dealii::Function we are templating on | ||
|
||
public: | ||
/// Constructor | ||
ExactSolutionFunction(); | ||
/// Destructor | ||
~ExactSolutionFunction() {}; | ||
|
||
/// Value of the initial condition | ||
virtual real value (const dealii::Point<dim,real> &point, const unsigned int istate = 0) const = 0; | ||
}; | ||
|
||
/// Initial Condition Function: Zero Function; used as a placeholder when there is no exact solution | ||
template <int dim, int nstate, typename real> | ||
class ExactSolutionFunction_Zero | ||
: public ExactSolutionFunction<dim,nstate,real> | ||
{ | ||
protected: | ||
using dealii::Function<dim,real>::value; ///< dealii::Function we are templating on | ||
|
||
public: | ||
/// Constructor for InitialConditionFunction_Zero | ||
ExactSolutionFunction_Zero (double time_compare); | ||
|
||
/// Time at which to compute the exact solution | ||
double t; | ||
|
||
/// Value of initial condition | ||
real value (const dealii::Point<dim,real> &point, const unsigned int istate = 0) const override; | ||
}; | ||
|
||
/// Initial Condition Function: 1D Sine Function; used for temporal convergence | ||
template <int dim, int nstate, typename real> | ||
class ExactSolutionFunction_1DSine | ||
: public ExactSolutionFunction<dim,nstate,real> | ||
{ | ||
protected: | ||
using dealii::Function<dim,real>::value; ///< dealii::Function we are templating on | ||
|
||
public: | ||
/// Constructor for InitialConditionFunction_1DSine | ||
/** Calls the Function(const unsigned int n_components) constructor in deal.II*/ | ||
ExactSolutionFunction_1DSine (double time_compare); | ||
|
||
/// Time at which to compute the exact solution | ||
double t; | ||
|
||
/// Value of initial condition | ||
real value (const dealii::Point<dim,real> &point, const unsigned int istate = 0) const override; | ||
}; | ||
|
||
|
||
/// Initial condition function factory | ||
template <int dim, int nstate, typename real> | ||
class ExactSolutionFactory | ||
{ | ||
protected: | ||
/// Enumeration of all flow solver initial conditions types defined in the Parameters class | ||
using FlowCaseEnum = Parameters::FlowSolverParam::FlowCaseType; | ||
|
||
public: | ||
/// Construct InitialConditionFunction object from global parameter file | ||
static std::shared_ptr<ExactSolutionFunction<dim,nstate,real>> | ||
create_ExactSolutionFunction(const Parameters::FlowSolverParam& flow_solver_parameters, const double time_compare); | ||
}; | ||
|
||
} // PHiLiP namespace | ||
#endif |
Oops, something went wrong.