25 #include "grins_config.h"
27 #ifdef GRINS_HAVE_CPPUNIT
29 #ifdef GRINS_HAVE_ANTIOCH
31 #include <libmesh/ignore_warnings.h>
32 #include <cppunit/extensions/HelperMacros.h>
33 #include <cppunit/TestCase.h>
34 #include <libmesh/restore_warnings.h>
37 #include "grins_test_paths.h"
53 #include "libmesh/parsed_function.h"
56 #include <libmesh/ignore_warnings.h>
81 const std::string filename = std::string(GRINS_TEST_UNIT_INPUT_SRCDIR)+
"/spectroscopic_absorption_qoi.in";
82 libMesh::Real calc_answer = 0.520403290868787;
84 this->
run_test(filename,calc_answer);
90 const std::string filename = std::string(GRINS_TEST_UNIT_INPUT_SRCDIR)+
"/spectroscopic_absorption_qoi_fine.in";
91 libMesh::Real calc_answer = 0.520403290868787;
93 this->
run_test(filename,calc_answer);
98 const std::string filename = std::string(GRINS_TEST_UNIT_INPUT_SRCDIR)+
"/spectroscopic_absorption_qoi.in";
101 std::string material =
"TestMaterial";
102 std::string hitran_data =
"./test_data/CO2_data.dat";
103 std::string hitran_partition =
"./test_data/CO2_partition_function.dat";
104 libMesh::Real T_min = 290.0,
107 GRINS::SharedPtr<GRINS::HITRAN> hitran(
new GRINS::HITRAN(hitran_data,hitran_partition,T_min,T_max,T_step) );
109 std::string species =
"CO2";
110 libMesh::Real thermo_pressure = 5066.25;
111 libMesh::Real nu_desired = 3682.7649;
112 libMesh::Real nu_min = 3682.69;
113 libMesh::Real nu_max = 3682.8;
115 libMesh::UniquePtr<GRINS::AntiochChemistry> chem_ptr;
117 GRINS::SharedPtr<GRINS::AntiochChemistry> chem(chem_ptr.release());
120 libMesh::Real T = 300.0;
121 libMesh::Real P = 5066.25;
123 std::vector<libMesh::Real> Y = {0.0763662233, 0.9236337767};
125 for (
unsigned int i=0; i<33; ++i)
135 const std::string filename = std::string(GRINS_TEST_UNIT_INPUT_SRCDIR)+
"/spectroscopic_absorption_qoi.in";
144 context->pre_fe_reinit(*system,system->get_mesh().elem_ptr(0));
149 libMesh::DifferentiableQoI * qoi = system->get_qoi();
150 qoi->element_qoi_derivative(*context,qs);
158 GRINS::SharedPtr<GRINS::Simulation>
_sim;
162 void run_test(
const std::string filename, libMesh::Real calc_answer)
168 CPPUNIT_ASSERT_DOUBLES_EQUAL( calc_answer, _sim->get_qoi_value(0),libMesh::TOLERANCE );
174 _input.reset(
new GetPot(filename));
176 const char *
const argv =
"unit_driver";
177 GetPot empty_command_line( (
const int)1,&argv );
188 libMesh::Real delta = 1.0e-6;
190 std::vector<libMesh::Real> T_analytic;
191 T_analytic.push_back(absorb->dS_dT(T,P,i));
192 T_analytic.push_back(absorb->d_nuC_dT(T,P,Y,i));
193 T_analytic.push_back(absorb->d_nuD_dT(T,P,i));
194 T_analytic.push_back(absorb->d_voigt_a_dT(T,P,Y,i));
195 T_analytic.push_back(absorb->d_voigt_w_dT(T,P,i));
196 T_analytic.push_back(absorb->d_voigt_dT(T,P,Y,i));
197 T_analytic.push_back(absorb->d_kv_dT(T,P,Y,i));
199 std::vector<libMesh::Real> fd_plus;
200 fd_plus.push_back(absorb->Sw(T+delta,P,i));
201 fd_plus.push_back(absorb->nu_C(T+delta,P,Y,i));
202 fd_plus.push_back(absorb->nu_D(T+delta,P,i));
203 fd_plus.push_back(absorb->voigt_a(T+delta,P,Y,i));
204 fd_plus.push_back(absorb->voigt_w(T+delta,P,i));
205 fd_plus.push_back(absorb->voigt(T+delta,P,Y,i));
206 fd_plus.push_back(absorb->kv(T+delta,P,Y,i));
208 std::vector<libMesh::Real> fd_minus;
209 fd_minus.push_back(absorb->Sw(T-delta,P,i));
210 fd_minus.push_back(absorb->nu_C(T-delta,P,Y,i));
211 fd_minus.push_back(absorb->nu_D(T-delta,P,i));
212 fd_minus.push_back(absorb->voigt_a(T-delta,P,Y,i));
213 fd_minus.push_back(absorb->voigt_w(T-delta,P,i));
214 fd_minus.push_back(absorb->voigt(T-delta,P,Y,i));
215 fd_minus.push_back(absorb->kv(T-delta,P,Y,i));
222 libMesh::Real delta = 1.0e-3;
224 std::vector<libMesh::Real> P_analytic;
225 P_analytic.push_back(absorb->dS_dP(T,P,i));
226 P_analytic.push_back(absorb->d_nuC_dP(T,Y,i));
227 P_analytic.push_back(absorb->d_nuD_dP(T,i));
228 P_analytic.push_back(absorb->d_voigt_a_dP(T,P,Y,i));
229 P_analytic.push_back(absorb->d_voigt_w_dP(T,P,i));
230 P_analytic.push_back(absorb->d_voigt_dP(T,P,Y,i));
231 P_analytic.push_back(absorb->d_kv_dP(T,P,Y,i));
233 std::vector<libMesh::Real> fd_plus;
234 fd_plus.push_back(absorb->Sw(T,P+delta,i));
235 fd_plus.push_back(absorb->nu_C(T,P+delta,Y,i));
236 fd_plus.push_back(absorb->nu_D(T,P+delta,i));
237 fd_plus.push_back(absorb->voigt_a(T,P+delta,Y,i));
238 fd_plus.push_back(absorb->voigt_w(T,P+delta,i));
239 fd_plus.push_back(absorb->voigt(T,P+delta,Y,i));
240 fd_plus.push_back(absorb->kv(T,P+delta,Y,i));
242 std::vector<libMesh::Real> fd_minus;
243 fd_minus.push_back(absorb->Sw(T,P-delta,i));
244 fd_minus.push_back(absorb->nu_C(T,P-delta,Y,i));
245 fd_minus.push_back(absorb->nu_D(T,P-delta,i));
246 fd_minus.push_back(absorb->voigt_a(T,P-delta,Y,i));
247 fd_minus.push_back(absorb->voigt_w(T,P-delta,i));
248 fd_minus.push_back(absorb->voigt(T,P-delta,Y,i));
249 fd_minus.push_back(absorb->kv(T,P-delta,Y,i));
256 libMesh::Real delta = 1.0e-8;
258 libMesh::Real y_base = Y[0];
259 std::vector<libMesh::Real> Y_analytic;
260 Y_analytic.push_back(absorb->dX_dY(Y));
261 Y_analytic.push_back(absorb->d_nuC_dY(T,P,Y,i));
262 Y_analytic.push_back(absorb->d_voigt_a_dY(T,P,Y,i));
263 Y_analytic.push_back(absorb->d_voigt_dY(T,P,Y,i));
264 Y_analytic.push_back(absorb->d_kv_dY(T,P,Y,i));
266 std::vector<libMesh::Real> fd_plus;
267 Y[0] = y_base + delta;
268 fd_plus.push_back(absorb->_chemistry->X(absorb->_species_idx,absorb->_chemistry->M_mix(Y),Y[absorb->_species_idx]));
269 fd_plus.push_back(absorb->nu_C(T,P,Y,i));
270 fd_plus.push_back(absorb->voigt_a(T,P,Y,i));
271 fd_plus.push_back(absorb->voigt(T,P,Y,i));
272 fd_plus.push_back(absorb->kv(T,P,Y,i));
274 std::vector<libMesh::Real> fd_minus;
275 Y[0] = y_base - delta;
276 fd_minus.push_back(absorb->_chemistry->X(absorb->_species_idx,absorb->_chemistry->M_mix(Y),Y[absorb->_species_idx]));
277 fd_minus.push_back(absorb->nu_C(T,P,Y,i));
278 fd_minus.push_back(absorb->voigt_a(T,P,Y,i));
279 fd_minus.push_back(absorb->voigt(T,P,Y,i));
280 fd_minus.push_back(absorb->kv(T,P,Y,i));
287 void check_param_derivatives(std::vector<libMesh::Real> & analytic, std::vector<libMesh::Real> & fd_plus, std::vector<libMesh::Real> & fd_minus, libMesh::Real delta)
289 for (
unsigned int d=0; d<analytic.size(); ++d)
291 libMesh::Real f_analytic = analytic[d];
292 libMesh::Real fd_approx = (fd_plus[d] - fd_minus[d])/(2.0*delta);
294 CPPUNIT_ASSERT_DOUBLES_EQUAL(fd_approx,f_analytic,libMesh::TOLERANCE);
300 GRINS::PrimitiveTempFEVariables T_var( GRINS::GRINSPrivate::VariableWarehouse::get_variable_subclass<GRINS::PrimitiveTempFEVariables>(
"Temperature") );
301 libMesh::Real delta = 1e-6;
307 GRINS::PressureFEVariable P_var( GRINS::GRINSPrivate::VariableWarehouse::get_variable_subclass<GRINS::PressureFEVariable>(
"Pressure") );
308 libMesh::Real delta = 1e-3;
315 libMesh::Real delta = 1e-8;
321 libMesh::DifferentiableQoI * qoi = system->get_qoi();
322 libMesh::Number & qoi_value = context->get_qois()[0];
328 libMesh::DenseSubVector<libMesh::Number> deriv = context->get_qoi_derivatives(0,var_index);
329 libMesh::DenseSubVector<libMesh::Number> & solution = context->get_elem_solution(var_index);
331 for (
unsigned int d=0; d<solution.size(); ++d)
333 libMesh::Number soln = solution.el(d);
335 solution(d) = soln+delta;
336 qoi->element_qoi(*context,qs);
337 libMesh::Number qoi_p1 = qoi_value;
340 solution(d) = soln-delta;
341 qoi->element_qoi(*context,qs);
342 libMesh::Number qoi_m1= qoi_value;
347 libMesh::Real fd_approx = (qoi_p1 - qoi_m1)/(2.0*delta);
349 CPPUNIT_ASSERT_DOUBLES_EQUAL(fd_approx,deriv(d),libMesh::TOLERANCE);
359 #endif // GRINS_HAVE_ANTIOCH
360 #endif // GRINS_HAVE_CPPUNIT
CPPUNIT_TEST_SUITE_REGISTRATION(AntiochAirNASA9ThermoTest)
void Y_param_derivatives(GRINS::SharedPtr< AbsorptionCoeffTesting< GRINS::AntiochChemistry > >absorb, libMesh::Real T, libMesh::Real P, std::vector< libMesh::Real > &Y, unsigned int i)
VariableIndex species(unsigned int species) const
void P_param_derivatives(GRINS::SharedPtr< AbsorptionCoeffTesting< GRINS::AntiochChemistry > >absorb, libMesh::Real T, libMesh::Real P, std::vector< libMesh::Real > &Y, unsigned int i)
GRINS::SharedPtr< GRINS::Simulation > _sim
GRINS::SharedPtr< GetPot > _input
CPPUNIT_TEST(single_elem_mesh)
libMesh::Parallel::Communicator * TestCommWorld
void multi_elem_mesh()
10x10 mesh, uniform T,P,Y
void test_var_elem_derivs(GRINS::MultiphysicsSystem *system, GRINS::AssemblyContext *context, unsigned int var_index, libMesh::Real delta)
void run_test(const std::string filename, libMesh::Real calc_answer)
Run the test on a given input file and calculated answer.
void check_param_derivatives(std::vector< libMesh::Real > &analytic, std::vector< libMesh::Real > &fd_plus, std::vector< libMesh::Real > &fd_minus, libMesh::Real delta)
void T_param_derivatives(GRINS::SharedPtr< AbsorptionCoeffTesting< GRINS::AntiochChemistry > >absorb, libMesh::Real T, libMesh::Real P, std::vector< libMesh::Real > &Y, unsigned int i)
void T_elem_derivative(GRINS::MultiphysicsSystem *system, GRINS::AssemblyContext *context)
virtual libMesh::UniquePtr< libMesh::DiffContext > build_context()
Override FEMSystem::build_context in order to use our own AssemblyContext.
Interface with libMesh for solving Multiphysics problems.
void build_chemistry(const GetPot &input, const std::string &material, libMesh::UniquePtr< ChemistryType > &chem_ptr)
void elem_qoi_derivatives()
void P_elem_derivative(GRINS::MultiphysicsSystem *system, GRINS::AssemblyContext *context)
static void clear()
Clears the var_map()
void single_elem_mesh()
Single QUAD4 elem, uniform T,P,Y.
void Y_elem_derivative(GRINS::MultiphysicsSystem *system, GRINS::AssemblyContext *context)
virtual void init_context(libMesh::DiffContext &context)
Context initialization. Calls each physics implementation of init_context()
void init_sim(const std::string &filename)
Initialize the GetPot and Simulation class objects.
CPPUNIT_TEST_SUITE(SpectroscopicAbsorptionTest)