Skip to content

Branch rans-dev PR, incomplete #45

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

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
c9e7aef
first commit adding rans
Jul 8, 2020
85154b3
wrote vorticity and gradient subfunctions, added euler term
Jul 14, 2020
5f03aea
source integrator functions compile, and euler integrator flux functi…
Jul 16, 2020
94c8e95
inviscid freestream rans test works, need to check more results
Jul 24, 2020
cf54612
jacobian seems fine, but PTC results in nan residual
Jul 24, 2020
c42e577
Inviscid, LPS, and freestream BC integrators verified, but freestream…
Jul 29, 2020
500ece2
changed some options for the rans_freestream test
jehicken Jul 29, 2020
4a24318
added the CMakeList changes
Jul 29, 2020
bc48ed1
Merge branch 'rans-dev' of https://github.com/OptimalDesignLab/mach i…
Jul 29, 2020
61e2a3d
source term grad remains
Aug 13, 2020
527e764
some derivatives implemented in source terms
Aug 13, 2020
a8a1333
Merge branch 'dev' into rans-dev
Aug 17, 2020
bcb8b8d
source term mostly differentiated, other slight change needed
Aug 24, 2020
1791685
implemented velocity conversion for vorticity
Aug 25, 2020
148b9ff
fixed bugs and (I believe) have differentiation sorted with SA source…
Sep 8, 2020
88af1b4
fixed initial residual error, now convergence stagnates
Sep 13, 2020
5d44c47
rans source terms are problematic
Oct 16, 2020
dee0415
reverted some CMakelists
Oct 19, 2020
8824e74
reverted some ns changes
Oct 19, 2020
f456404
fixing tests after merge 1
Oct 19, 2020
e05189c
fixing dev merge 2
Oct 20, 2020
92fdc0b
resolved test issue, merge with dev complete
Oct 20, 2020
36462b8
added gf_error files
Oct 21, 2020
7b1003f
somewhat robust convergence now, but there are scaling hacks in mfem
Oct 30, 2020
37df9d4
started adding cfd mesh sensitivities, rans mms problem
Dec 22, 2020
a9c1f8d
somewhat accurate solution, need to implement startup solver
Jan 14, 2021
0e40b76
cleanup commit before dev merge
Feb 4, 2021
4eba54d
Merge branch 'dev' into rans-dev
Feb 4, 2021
97bfd27
Merge branch 'dev' into rans-dev
Feb 4, 2021
55b4653
last rans commit for a while, to submit for pr. no added regression test
Feb 4, 2021
a8eadcd
fix documentation for added linear solver and nonlinear solver
tuckerbabcock Apr 5, 2021
a0ee2cb
Merge branch 'dev' into rans-dev
tuckerbabcock Apr 7, 2021
ab601d5
change ctest run to only be verbose on failure
tuckerbabcock Apr 7, 2021
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
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,4 @@ jobs:
shell: bash
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest -C $BUILD_TYPE -V
run: ctest -C $BUILD_TYPE --output-on-failure
34 changes: 18 additions & 16 deletions sandbox/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,26 @@ function(create_sandbox source_list)
endfunction(create_sandbox)

set(SANDBOX_SRCS
advection2d
steady_vortex
steady_vortex_adjoint
unsteady_vortex
viscous_shock
airfoil_steady
airfoil_chaotic
magnetostatic_box
#advection2d
#steady_vortex
#steady_vortex_adjoint
#unsteady_vortex
#viscous_shock
#airfoil_steady
#airfoil_chaotic
#magnetostatic_box
magnetostatic_motor
magnetostatic_wire
navier_stokes_mms
#magnetostatic_wire
#navier_stokes_mms
thermal_square
# joule_wire
joule_box
mesh_move
mesh_move_2
surface_distance
joule_wire
#joule_wire
#joule_box
#mesh_move
#mesh_move_2
#surface_distance
#rans_freestream
rans_walltest
#rans_mms
)

create_sandbox("${SANDBOX_SRCS}")
214 changes: 214 additions & 0 deletions sandbox/rans_freestream.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
// set this const expression to true in order to use entropy variables for state (doesn't work for rans)
constexpr bool entvar = false;

#include<random>
#include "adept.h"

#include "mfem.hpp"
#include "rans.hpp"
#include <fstream>
#include <iostream>

using namespace std;
using namespace mfem;
using namespace mach;

std::default_random_engine gen(std::random_device{}());
std::uniform_real_distribution<double> uniform_rand(0.0,1.0);

static double pert_fs;
static double mu;
static double mach_fs;
static double aoa_fs;
static int iroll;
static int ipitch;
static double chi_fs;
static bool mms;

/// \brief Defines the random function for the jacobian check
/// \param[in] x - coordinate of the point at which the state is needed
/// \param[out] u - conservative + SA variables stored as a 5-vector
void pert(const Vector &x, Vector& p);

/// \brief Defines the exact solution for the rans freestream problem
/// \param[in] x - coordinate of the point at which the state is needed
/// \param[out] u - conservative + SA variables stored as a 5-vector
void uexact(const Vector &x, Vector& u);

/// \brief Defines a perturbed solution for the rans freestream problem
/// \param[in] x - coordinate of the point at which the state is needed
/// \param[out] u - conservative + SA variables stored as a 5-vector
void uinit_pert(const Vector &x, Vector& u);

void uinit_pert_mms(const Vector &x, Vector& u);


int main(int argc, char *argv[])
{
const char *options_file = "rans_freestream_options.json";

// Initialize MPI
int num_procs, rank;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &num_procs);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
ostream *out = getOutStream(rank);

// Parse command-line options
OptionsParser args(argc, argv);
int degree = 2.0;
int nx = 10;
int ny = 10;
args.AddOption(&nx, "-nx", "--numx",
"Number of elements in x direction");
args.AddOption(&ny, "-ny", "--numy",
"Number of elements in y direction");
args.Parse();
if (!args.Good())
{
args.PrintUsage(*out);
return 1;
}

try
{
// construct the mesh
string opt_file_name(options_file);
nlohmann::json file_options;
std::ifstream opts(opt_file_name);
opts >> file_options;
pert_fs = 1.0 + file_options["init-pert"].template get<double>();
mu = file_options["flow-param"]["mu"].template get<double>();
mach_fs = file_options["flow-param"]["mach"].template get<double>();
aoa_fs = file_options["flow-param"]["aoa"].template get<double>()*M_PI/180;
iroll = file_options["flow-param"]["roll-axis"].template get<int>();
ipitch = file_options["flow-param"]["pitch-axis"].template get<int>();
chi_fs = file_options["flow-param"]["chi"].template get<double>();
mms = file_options["flow-param"]["rans-mms"].template get<bool>();

// generate a simple tri mesh and a distance function
std::unique_ptr<Mesh> smesh(new Mesh(nx, ny,
Element::TRIANGLE, true /* gen. edges */, 1.0,
1.0, true));
*out << "Number of elements " << smesh->GetNE() <<'\n';

// construct the solver and set initial conditions
auto solver = createSolver<RANavierStokesSolver<2, entvar>>(opt_file_name,
move(smesh));
if (mms)
solver->setInitialCondition(uinit_pert_mms);
else
solver->setInitialCondition(uinit_pert);
solver->printSolution("rans_init", 0);
solver->printResidual("rans_res_init", 0);


// get the initial density error
double l2_error_init = (static_cast<RANavierStokesSolver<2, entvar>&>(*solver)
.calcConservativeVarsL2Error(uexact, 0));
*out << "\n|| rho_h - rho ||_{L^2} init = " << l2_error_init << endl;

double res_error = solver->calcResidualNorm();
*out << "\ninitial residual norm = " << res_error << endl;
solver->checkJacobian(pert);
solver->solveForState();
solver->printSolution("rans_final",0);
// get the final density error
double l2_error_final = (static_cast<RANavierStokesSolver<2, entvar>&>(*solver)
.calcConservativeVarsL2Error(uexact, 0));
res_error = solver->calcResidualNorm();

*out << "\nfinal residual norm = " << res_error;
*out << "\n|| rho_h - rho ||_{L^2} final = " << l2_error_final << endl;
}
catch (MachException &exception)
{
exception.print_message();
}
catch (std::exception &exception)
{
cerr << exception.what() << endl;
}

#ifdef MFEM_USE_PETSC
MFEMFinalizePetsc();
#endif

MPI_Finalize();
}

// perturbation function used to check the jacobian in each iteration
void pert(const Vector &x, Vector& p)
{
p.SetSize(5);
for (int i = 0; i < 5; i++)
{
p(i) = 2.0 * uniform_rand(gen) - 1.0;
}
}

// Exact solution; same as freestream bc
void uexact(const Vector &x, Vector& q)
{
// q.SetSize(4);
// Vector u(4);
q.SetSize(5);
Vector u(5);

u = 0.0;
u(0) = 1.0;
u(1) = u(0)*mach_fs*cos(aoa_fs);
u(2) = u(0)*mach_fs*sin(aoa_fs);
u(3) = 1/(euler::gamma*euler::gami) + 0.5*mach_fs*mach_fs;
u(4) = chi_fs*mu;

if (entvar == false)
{
q = u;
}
else
{
throw MachException("No entvar for this");
}
}

// initial guess perturbed from exact
void uinit_pert(const Vector &x, Vector& q)
{
q.SetSize(5);
Vector u(5);

u = 0.0;
u(0) = pert_fs*1.0;
u(1) = u(0)*mach_fs*cos(aoa_fs);
u(2) = u(0)*mach_fs*sin(aoa_fs);
u(3) = pert_fs*1/(euler::gamma*euler::gami) + 0.5*mach_fs*mach_fs;
u(4) = pert_fs*chi_fs*mu;

q = u;
}

// initial guess perturbed from exact
void uinit_pert_mms(const Vector &x, Vector& q)
{
const double rho0 = 1.0;
const double rhop = 0.05;
const double U0 = 0.5;
const double Up = 0.05;
const double T0 = 1.0;
const double Tp = 0.05;
const double chif = 100.0;
const double mu = 1.0;
q.SetSize(5);
q(0) = rho0 + rhop*pow(sin(M_PI*x(0)),2)*sin(M_PI*x(1));
q(1) = 4.0*U0*x(1)*(1.0 - x(1)) + Up*sin(2 * M_PI * x(1)) * pow(sin(M_PI * x(0)),2);
q(2) = -Up*pow(sin(2 * M_PI * x(0)),2) * sin(M_PI * x(1));
double T = T0 + Tp*(pow(x(0), 4) - 2 * pow(x(0), 3) + pow(x(0), 2)
+ pow(x(1), 4) - 2 * pow(x(1), 3) + pow(x(1), 2));
double p = q(0)*T; // T is nondimensionalized by 1/(R*a_infty^2)
q(3) = p/euler::gami + 0.5*q(0)*(q(1)*q(1) + q(2)*q(2));
q(1) *= q(0);
q(2) *= q(0);

q(4) = q(0)*chif*mu*x(1);
}
52 changes: 52 additions & 0 deletions sandbox/rans_freestream_options.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"flow-param": {
"mach": 1.0,
"aoa": 0.3,
"roll-axis": 0,
"pitch-axis": 1,
"chi": 3.0,
"Re": 1000.0,
"Pr": 0.75,
"mu": 1.0,
"rans-mms": false,
"sa-consts": [0.1355, 0.622, 0.666666666666667, 0.41, 0.3, 2, 7.1, 1.2, 0.5, 10, 16, 0.7, 0.9],
"sa-srcs": [1.0, 1.0]
},
"space-dis": {
"degree": 1,
"lps-coeff": 1.0,
"basis-type": "csbp"
},
"time-dis": {
"steady": true,
"steady-abstol": 1e-12,
"steady-restol": 1e-10,
"const-cfl": true,
"ode-solver": "PTC",
"t-final": 100,
"dt": 1e6,
"cfl": 1.0
},
"nonlin-solver": {
"abstol": 1e-12,
"maxiter": 100,
"printlevel": 1,
"reltol": 1e-2,
"type": "newton"
},
"lin-solver": {
"reltol": 1e-2,
"abstol": 1e-12,
"printlevel": 0,
"maxiter": 100
},
"bcs": {
"far-field": [1, 1, 1, 1]
},
"wall-func": {
"type": "const",
"val": 1.0
},
"file-names": "rans_free",
"init-pert": 0.0
}
Loading