void generate_stellar_system() { planet_pointer planet; radians_per_rotation = 2.0 * PI; stellar_mass_ratio = random_number(0.6,1.3); stellar_luminosity_ratio = luminosity(stellar_mass_ratio); planet = distribute_planetary_masses(stellar_mass_ratio,stellar_luminosity_ratio,0.0,stellar_dust_limit(stellar_mass_ratio)); main_seq_life = 1.0E10 * (stellar_mass_ratio / stellar_luminosity_ratio); if ((main_seq_life >= 6.0E9)) age = random_number(1.0E9,6.0E9); else age = random_number(1.0E9,main_seq_life); r_ecosphere = sqrt(stellar_luminosity_ratio); r_greenhouse = r_ecosphere * GREENHOUSE_EFFECT_CONST; while (planet != NULL) { planet->orbit_zone = orbital_zone(planet->a); if (planet->gas_giant) { planet->density = empirical_density(planet->mass,planet->a,planet->gas_giant); planet->radius = volume_radius(planet->mass,planet->density); } else { planet->radius = kothari_radius(planet->mass,planet->a,planet->gas_giant,planet->orbit_zone); planet->density = volume_density(planet->mass,planet->radius); } planet->orbital_period = period(planet->a,planet->mass,stellar_mass_ratio); planet->day = day_length(planet->mass,planet->radius,planet->orbital_period,planet->e,planet->gas_giant); planet->resonant_period = spin_resonance; planet->axial_tilt = inclination(planet->a); planet->escape_velocity = escape_vel(planet->mass,planet->radius); planet->surface_accel = acceleration(planet->mass,planet->radius); planet->rms_velocity = rms_vel(MOLECULAR_NITROGEN,planet->a); planet->molecule_weight = molecule_limit(planet->a,planet->mass,planet->radius); if ((planet->gas_giant)) { planet->surface_grav = INCREDIBLY_LARGE_NUMBER; planet->greenhouse_effect = FALSE; planet->volatile_gas_inventory = INCREDIBLY_LARGE_NUMBER; planet->surface_pressure = INCREDIBLY_LARGE_NUMBER; planet->boil_point = INCREDIBLY_LARGE_NUMBER; planet->hydrosphere = INCREDIBLY_LARGE_NUMBER; planet->albedo = about(GAS_GIANT_ALBEDO,0.1); planet->surface_temp = INCREDIBLY_LARGE_NUMBER; } else { planet->surface_grav = gravity(planet->surface_accel); planet->greenhouse_effect = greenhouse(planet->orbit_zone,planet->a,r_greenhouse); planet->volatile_gas_inventory = vol_inventory(planet->mass,planet->escape_velocity,planet->rms_velocity,stellar_mass_ratio,planet->orbit_zone,planet->greenhouse_effect); planet->surface_pressure = pressure(planet->volatile_gas_inventory,planet->radius,planet->surface_grav); if ((planet->surface_pressure == 0.0)) planet->boil_point = 0.0; else planet->boil_point = boiling_point(planet->surface_pressure); iterate_surface_temp(&(planet)); } planet = planet->next_planet; } display_system( ); }
timeVaryingSolidTractionFvPatchVectorField:: timeVaryingSolidTractionFvPatchVectorField ( const fvPatch& p, const DimensionedField<vector, volMesh>& iF, const dictionary& dict ) : solidTractionFvPatchVectorField(p, iF), timeSeries_(dict) { fieldName() = dimensionedInternalField().name(); traction() = vector::zero; pressure() = 0.0; nonLinear() = nonLinearGeometry::nonLinearNames_.read(dict.lookup("nonLinear")); //- the leastSquares has zero non-orthogonal correction //- on the boundary //- so the gradient scheme should be extendedLeastSquares if ( Foam::word ( dimensionedInternalField().mesh().schemesDict().gradScheme ( "grad(" + fieldName() + ")" ) ) != "extendedLeastSquares" ) { Warning << "The gradScheme for " << fieldName() << " should be \"extendedLeastSquares 0\" for the boundary " << "non-orthogonal correction to be right" << endl; } }
void main () { char buf[20]; int i; int buflen; ADCON1= 0x20; // CONFIGURE ADC --- AN2 TRISA = 0xFF; // MAKE PORTA AS INPUT usart_init(2400); // initialize the usart do { depth=pressure(); itoa(buf, depth); buflen=strlen(buf); for(i=buflen-1; i>=0; i--) { Usart_Write(buf[i]); // write the data } Usart_Write(0x0D); Usart_Write(0x0A) ; } while(1); }
doublereal MixtureFugacityTP::z() const { return pressure() * meanMolecularWeight() / (density() * _RT()); }
void MetalSHEelectrons::getEntropy_R(doublereal* sr) const { getEntropy_R_ref(sr); doublereal tmp = log(pressure() / m_p0); sr[0] -= tmp; }
/* * Format a summary of the mixture state for output. */ void MolalityVPSSTP::reportCSV(std::ofstream& csvFile) const { csvFile.precision(3); int tabS = 15; int tabM = 30; int tabL = 40; try { if (name() != "") { csvFile << "\n"+name()+"\n\n"; } csvFile << setw(tabL) << "temperature (K) =" << setw(tabS) << temperature() << endl; csvFile << setw(tabL) << "pressure (Pa) =" << setw(tabS) << pressure() << endl; csvFile << setw(tabL) << "density (kg/m^3) =" << setw(tabS) << density() << endl; csvFile << setw(tabL) << "mean mol. weight (amu) =" << setw(tabS) << meanMolecularWeight() << endl; csvFile << setw(tabL) << "potential (V) =" << setw(tabS) << electricPotential() << endl; csvFile << endl; csvFile << setw(tabL) << "enthalpy (J/kg) = " << setw(tabS) << enthalpy_mass() << setw(tabL) << "enthalpy (J/kmol) = " << setw(tabS) << enthalpy_mole() << endl; csvFile << setw(tabL) << "internal E (J/kg) = " << setw(tabS) << intEnergy_mass() << setw(tabL) << "internal E (J/kmol) = " << setw(tabS) << intEnergy_mole() << endl; csvFile << setw(tabL) << "entropy (J/kg) = " << setw(tabS) << entropy_mass() << setw(tabL) << "entropy (J/kmol) = " << setw(tabS) << entropy_mole() << endl; csvFile << setw(tabL) << "Gibbs (J/kg) = " << setw(tabS) << gibbs_mass() << setw(tabL) << "Gibbs (J/kmol) = " << setw(tabS) << gibbs_mole() << endl; csvFile << setw(tabL) << "heat capacity c_p (J/K/kg) = " << setw(tabS) << cp_mass() << setw(tabL) << "heat capacity c_p (J/K/kmol) = " << setw(tabS) << cp_mole() << endl; csvFile << setw(tabL) << "heat capacity c_v (J/K/kg) = " << setw(tabS) << cv_mass() << setw(tabL) << "heat capacity c_v (J/K/kmol) = " << setw(tabS) << cv_mole() << endl; csvFile.precision(8); vector<std::string> pNames; vector<vector_fp> data; vector_fp temp(nSpecies()); getMoleFractions(&temp[0]); pNames.push_back("X"); data.push_back(temp); try { getMolalities(&temp[0]); pNames.push_back("Molal"); data.push_back(temp); } catch (CanteraError& err) { err.save(); } try { getChemPotentials(&temp[0]); pNames.push_back("Chem. Pot. (J/kmol)"); data.push_back(temp); } catch (CanteraError& err) { err.save(); } try { getStandardChemPotentials(&temp[0]); pNames.push_back("Chem. Pot. SS (J/kmol)"); data.push_back(temp); } catch (CanteraError& err) { err.save(); } try { getMolalityActivityCoefficients(&temp[0]); pNames.push_back("Molal Act. Coeff."); data.push_back(temp); } catch (CanteraError& err) { err.save(); } try { getActivities(&temp[0]); pNames.push_back("Molal Activity"); data.push_back(temp); size_t iHp = speciesIndex("H+"); if (iHp != npos) { double pH = -log(temp[iHp]) / log(10.0); csvFile << setw(tabL) << "pH = " << setw(tabS) << pH << endl; } } catch (CanteraError& err) { err.save(); } try { getPartialMolarEnthalpies(&temp[0]); pNames.push_back("Part. Mol Enthalpy (J/kmol)"); data.push_back(temp); } catch (CanteraError& err) { err.save(); } try { getPartialMolarEntropies(&temp[0]); pNames.push_back("Part. Mol. Entropy (J/K/kmol)"); data.push_back(temp); } catch (CanteraError& err) { err.save(); } try { getPartialMolarIntEnergies(&temp[0]); pNames.push_back("Part. Mol. Energy (J/kmol)"); data.push_back(temp); } catch (CanteraError& err) { err.save(); } try { getPartialMolarCp(&temp[0]); pNames.push_back("Part. Mol. Cp (J/K/kmol"); data.push_back(temp); } catch (CanteraError& err) { err.save(); } try { getPartialMolarVolumes(&temp[0]); pNames.push_back("Part. Mol. Cv (J/K/kmol)"); data.push_back(temp); } catch (CanteraError& err) { err.save(); } csvFile << endl << setw(tabS) << "Species,"; for (size_t i = 0; i < pNames.size(); i++) { csvFile << setw(tabM) << pNames[i] << ","; } csvFile << endl; /* csvFile.fill('-'); csvFile << setw(tabS+(tabM+1)*pNames.size()) << "-\n"; csvFile.fill(' '); */ for (size_t k = 0; k < nSpecies(); k++) { csvFile << setw(tabS) << speciesName(k) + ","; if (data[0][k] > SmallNumber) { for (size_t i = 0; i < pNames.size(); i++) { csvFile << setw(tabM) << data[i][k] << ","; } csvFile << endl; } else { for (size_t i = 0; i < pNames.size(); i++) { csvFile << setw(tabM) << 0 << ","; } csvFile << endl; } } } catch (CanteraError& err) { err.save(); } }
int main(int argc, char* argv[]) { // Load the mesh. Mesh mesh; H2DReader mloader; mloader.load("channel.mesh", &mesh); // Perform initial mesh refinements. for (int i = 0; i < INIT_REF_NUM; i++) mesh.refine_all_elements(2); //mesh.refine_towards_boundary(BDY_SOLID_WALL_BOTTOM, 2); // Initialize boundary condition types and spaces with default shapesets. L2Space space_rho(&mesh, P_INIT); L2Space space_rho_v_x(&mesh, P_INIT); L2Space space_rho_v_y(&mesh, P_INIT); L2Space space_e(&mesh, P_INIT); int ndof = Space::get_num_dofs(Hermes::vector<Space*>(&space_rho, &space_rho_v_x, &space_rho_v_y, &space_e)); info("ndof: %d", ndof); // Initialize solutions, set initial conditions. InitialSolutionEulerDensity prev_rho(&mesh, RHO_EXT); InitialSolutionEulerDensityVelX prev_rho_v_x(&mesh, RHO_EXT * V1_EXT); InitialSolutionEulerDensityVelY prev_rho_v_y(&mesh, RHO_EXT * V2_EXT); InitialSolutionEulerDensityEnergy prev_e(&mesh, QuantityCalculator::calc_energy(RHO_EXT, RHO_EXT * V1_EXT, RHO_EXT * V2_EXT, P_EXT, KAPPA)); // Numerical flux. StegerWarmingNumericalFlux num_flux(KAPPA); // Initialize weak formulation. EulerEquationsWeakFormExplicitMultiComponentSemiImplicit wf(&num_flux, KAPPA, RHO_EXT, V1_EXT, V2_EXT, P_EXT, BDY_SOLID_WALL_BOTTOM, BDY_SOLID_WALL_TOP, BDY_INLET, BDY_OUTLET, &prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e); // Initialize the FE problem. bool is_linear = true; DiscreteProblem dp(&wf, Hermes::vector<Space*>(&space_rho, &space_rho_v_x, &space_rho_v_y, &space_e), is_linear); // If the FE problem is in fact a FV problem. //if(P_INIT == 0) dp.set_fvm(); // Filters for visualization of Mach number, pressure and entropy. MachNumberFilter Mach_number(Hermes::vector<MeshFunction*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), KAPPA); PressureFilter pressure(Hermes::vector<MeshFunction*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), KAPPA); EntropyFilter entropy(Hermes::vector<MeshFunction*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), KAPPA, RHO_EXT, P_EXT); ScalarView pressure_view("Pressure", new WinGeom(0, 0, 600, 300)); ScalarView Mach_number_view("Mach number", new WinGeom(700, 0, 600, 300)); ScalarView entropy_production_view("Entropy estimate", new WinGeom(0, 400, 600, 300)); ScalarView s1("1", new WinGeom(0, 0, 600, 300)); ScalarView s2("2", new WinGeom(700, 0, 600, 300)); ScalarView s3("3", new WinGeom(0, 400, 600, 300)); ScalarView s4("4", new WinGeom(700, 400, 600, 300)); // Set up the solver, matrix, and rhs according to the solver selection. SparseMatrix* matrix = create_matrix(matrix_solver); Vector* rhs = create_vector(matrix_solver); Solver* solver = create_linear_solver(matrix_solver, matrix, rhs); // Set up CFL calculation class. CFLCalculation CFL(CFL_NUMBER, KAPPA); int iteration = 0; double t = 0; for(t = 0.0; t < 3.0; t += time_step) { info("---- Time step %d, time %3.5f.", iteration++, t); // Set the current time step. wf.set_time_step(time_step); bool rhs_only = (iteration == 1 ? false : true); // Assemble stiffness matrix and rhs or just rhs. if (rhs_only == false) { info("Assembling the stiffness matrix and right-hand side vector."); dp.assemble(matrix, rhs); } else { info("Assembling the right-hand side vector (only)."); dp.assemble(NULL, rhs); } // Solve the matrix problem. info("Solving the matrix problem."); scalar* solution_vector = NULL; if(solver->solve()) { solution_vector = solver->get_solution(); Solution::vector_to_solutions(solution_vector, Hermes::vector<Space *>(&space_rho, &space_rho_v_x, &space_rho_v_y, &space_e), Hermes::vector<Solution *>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e)); } else error ("Matrix solver failed.\n"); if(SHOCK_CAPTURING) { DiscontinuityDetector discontinuity_detector(Hermes::vector<Space *>(&space_rho, &space_rho_v_x, &space_rho_v_y, &space_e), Hermes::vector<Solution *>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e)); std::set<int> discontinuous_elements = discontinuity_detector.get_discontinuous_element_ids(DISCONTINUITY_DETECTOR_PARAM); FluxLimiter flux_limiter(solution_vector, Hermes::vector<Space *>(&space_rho, &space_rho_v_x, &space_rho_v_y, &space_e), Hermes::vector<Solution *>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e)); flux_limiter.limit_according_to_detector(discontinuous_elements); } if((iteration - 1) % CFL_CALC_FREQ == 0) CFL.calculate(Hermes::vector<Solution *>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), &mesh, time_step); // Visualization. /* Mach_number.reinit(); pressure.reinit(); entropy.reinit(); pressure_view.show(&pressure); entropy_production_view.show(&entropy); Mach_number_view.show(&Mach_number); */ s1.show(&prev_rho); s2.show(&prev_rho_v_x); s3.show(&prev_rho_v_y); s4.show(&prev_e); View::wait(); } pressure_view.close(); entropy_production_view.close(); Mach_number_view.close(); s1.close(); s2.close(); s3.close(); s4.close(); return 0; }
doublereal IdealGasPhase::entropy_mole() const { return GasConstant * (mean_X(entropy_R_ref()) - sum_xlogx() - std::log(pressure() / m_spthermo->refPressure())); }
void ZeroLengthInterface2D::formLocalResidAndTangent( int tang_flag , int slave, int master1, int master2, int stage) { // trial frictional force vectors (in local coordinate) double t_trial; double TtrNorm; // Coulomb friction law surface double Phi; int i, j; // set the first value to zero pressure(slave) = 0; t_trial=0; // int IsContact; // detect contact and set flag ContactFlag = contactDetect(slave,master1,master2, stage); if (ContactFlag == 1) // contacted { // create a vector for converting local matrix to global GlobalResidAndTangentOrder(slave, master1, master2); // contact presure; pressure(slave) = Kn * normal_gap(slave); // pressure is positive if in contact double ng = normal_gap(slave); t_trial = Kt * (shear_gap(slave) - stored_shear_gap(slave)); // trial shear force // Coulomb friction law, trial state //TtrNorm=t_trial.Norm(); TtrNorm = sqrt(t_trial * t_trial); Phi = TtrNorm - fc * pressure(slave); if (Phi <= 0 ) { // stick case if ( tang_flag == 1 ) { // stiff for (i = 0; i < 6; i++) { for (j = 0; j < 6; j++) { stiff(loctoglob[i],loctoglob[j]) += Kn * (N(i) * N(j)) + Kt * (T(i) * T(j)); //2D } } } //endif tang_flag // force for (i = 0; i < 6; i++) resid(loctoglob[i]) += pressure(slave) * N(i) + t_trial * T(i); //2D } // end if stick else { // slide case, non-symmetric stiff ContactFlag=2; // set the contactFlag for sliding if ( tang_flag == 1 ) { // stiff for (i = 0; i < 6; i++) { for (j = 0; j < 6; j++) { stiff(loctoglob[i],loctoglob[j]) += Kn * (N(i) * N(j)) - fc * Kn * (t_trial / TtrNorm) * T(i) * N(j); //2D } //endfor i } //endfor j // force } // endif tang_flag double shear = fc * pressure(slave) * (t_trial/TtrNorm); for (i = 0; i < 6; i++) resid(loctoglob[i]) += (pressure(slave) * N(i)) + (shear * T(i)) ; //2D } //endif slide } // endif ContactFlag==1 }
int main(int argc, char* argv[]) { // Load the mesh. Mesh mesh; H2DReader mloader; mloader.load("GAMM-channel.mesh", &mesh); // Perform initial mesh refinements. for (int i = 0; i < INIT_REF_NUM; i++) mesh.refine_all_elements(); mesh.refine_towards_boundary(1, 1); mesh.refine_element(1053); mesh.refine_element(1054); mesh.refine_element(1087); mesh.refine_element(1088); mesh.refine_element(1117); mesh.refine_element(1118); mesh.refine_element(1151); mesh.refine_element(1152); // Enter boundary markers. BCTypes bc_types; bc_types.add_bc_neumann(Hermes::Tuple<int>(BDY_SOLID_WALL, BDY_INLET_OUTLET)); // Create L2 spaces with default shapesets. L2Space space_rho(&mesh, &bc_types, P_INIT); L2Space space_rho_v_x(&mesh, &bc_types, P_INIT); L2Space space_rho_v_y(&mesh, &bc_types, P_INIT); L2Space space_e(&mesh, &bc_types, P_INIT); // Initialize solutions, set initial conditions. Solution sln_rho, sln_rho_v_x, sln_rho_v_y, sln_e, prev_rho, prev_rho_v_x, prev_rho_v_y, prev_e; sln_rho.set_exact(&mesh, ic_density); sln_rho_v_x.set_exact(&mesh, ic_density_vel_x); sln_rho_v_y.set_exact(&mesh, ic_density_vel_y); sln_e.set_exact(&mesh, ic_energy); prev_rho.set_exact(&mesh, ic_density); prev_rho_v_x.set_exact(&mesh, ic_density_vel_x); prev_rho_v_y.set_exact(&mesh, ic_density_vel_y); prev_e.set_exact(&mesh, ic_energy); // Initialize weak formulation. WeakForm wf(4); // Bilinear forms coming from time discretization by explicit Euler's method. wf.add_matrix_form(0, 0, callback(bilinear_form_0_0_time)); wf.add_matrix_form(1, 1, callback(bilinear_form_1_1_time)); wf.add_matrix_form(2, 2, callback(bilinear_form_2_2_time)); wf.add_matrix_form(3, 3, callback(bilinear_form_3_3_time)); // Volumetric linear forms. // Linear forms coming from the linearization by taking the Eulerian fluxes' Jacobian matrices // from the previous time step. // First flux. // Unnecessary for FVM. if(P_INIT.order_h > 0 || P_INIT.order_v > 0) { wf.add_vector_form(0, callback(linear_form_0_1), HERMES_ANY, Hermes::Tuple<MeshFunction*>(&prev_rho_v_x)); wf.add_vector_form(1, callback(linear_form_1_0_first_flux), HERMES_ANY, Hermes::Tuple<MeshFunction*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y)); wf.add_vector_form(1, callback(linear_form_1_1_first_flux), HERMES_ANY, Hermes::Tuple<MeshFunction*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y)); wf.add_vector_form(1, callback(linear_form_1_2_first_flux), HERMES_ANY, Hermes::Tuple<MeshFunction*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y)); wf.add_vector_form(1, callback(linear_form_1_3_first_flux), HERMES_ANY, Hermes::Tuple<MeshFunction*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e)); wf.add_vector_form(2, callback(linear_form_2_0_first_flux), HERMES_ANY, Hermes::Tuple<MeshFunction*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y)); wf.add_vector_form(2, callback(linear_form_2_1_first_flux), HERMES_ANY, Hermes::Tuple<MeshFunction*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y)); wf.add_vector_form(2, callback(linear_form_2_2_first_flux), HERMES_ANY, Hermes::Tuple<MeshFunction*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y)); wf.add_vector_form(2, callback(linear_form_2_3_first_flux), HERMES_ANY, Hermes::Tuple<MeshFunction*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e)); wf.add_vector_form(3, callback(linear_form_3_0_first_flux), HERMES_ANY, Hermes::Tuple<MeshFunction*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e)); wf.add_vector_form(3, callback(linear_form_3_1_first_flux), HERMES_ANY, Hermes::Tuple<MeshFunction*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e)); wf.add_vector_form(3, callback(linear_form_3_2_first_flux), HERMES_ANY, Hermes::Tuple<MeshFunction*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e)); wf.add_vector_form(3, callback(linear_form_3_3_first_flux), HERMES_ANY, Hermes::Tuple<MeshFunction*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e)); // Second flux. wf.add_vector_form(0, callback(linear_form_0_2), HERMES_ANY, Hermes::Tuple<MeshFunction*>(&prev_rho_v_y)); wf.add_vector_form(1, callback(linear_form_1_0_second_flux), HERMES_ANY, Hermes::Tuple<MeshFunction*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y)); wf.add_vector_form(1, callback(linear_form_1_1_second_flux), HERMES_ANY, Hermes::Tuple<MeshFunction*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y)); wf.add_vector_form(1, callback(linear_form_1_2_second_flux), HERMES_ANY, Hermes::Tuple<MeshFunction*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y)); wf.add_vector_form(1, callback(linear_form_1_3_second_flux), HERMES_ANY, Hermes::Tuple<MeshFunction*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e)); wf.add_vector_form(2, callback(linear_form_2_0_second_flux), HERMES_ANY, Hermes::Tuple<MeshFunction*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y)); wf.add_vector_form(2, callback(linear_form_2_1_second_flux), HERMES_ANY, Hermes::Tuple<MeshFunction*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y)); wf.add_vector_form(2, callback(linear_form_2_2_second_flux), HERMES_ANY, Hermes::Tuple<MeshFunction*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y)); wf.add_vector_form(2, callback(linear_form_2_3_second_flux), HERMES_ANY, Hermes::Tuple<MeshFunction*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e)); wf.add_vector_form(3, callback(linear_form_3_0_second_flux), HERMES_ANY, Hermes::Tuple<MeshFunction*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e)); wf.add_vector_form(3, callback(linear_form_3_1_second_flux), HERMES_ANY, Hermes::Tuple<MeshFunction*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e)); wf.add_vector_form(3, callback(linear_form_3_2_second_flux), HERMES_ANY, Hermes::Tuple<MeshFunction*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e)); wf.add_vector_form(3, callback(linear_form_3_3_second_flux), HERMES_ANY, Hermes::Tuple<MeshFunction*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e)); } // Volumetric linear forms coming from the time discretization. #ifdef HERMES_USE_VECTOR_VALUED_FORMS wf.add_vector_form(0, linear_form_vector, linear_form_order, HERMES_ANY, Hermes::Tuple<MeshFunction*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e)); wf.add_vector_form(1, linear_form_vector, linear_form_order, HERMES_ANY, Hermes::Tuple<MeshFunction*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e)); wf.add_vector_form(2, linear_form_vector, linear_form_order, HERMES_ANY, Hermes::Tuple<MeshFunction*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e)); wf.add_vector_form(3, linear_form_vector, linear_form_order, HERMES_ANY, Hermes::Tuple<MeshFunction*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e)); #else wf.add_vector_form(0, linear_form, linear_form_order, HERMES_ANY, &prev_rho); wf.add_vector_form(1, linear_form, linear_form_order, HERMES_ANY, &prev_rho_v_x); wf.add_vector_form(2, linear_form, linear_form_order, HERMES_ANY, &prev_rho_v_y); wf.add_vector_form(3, linear_form, linear_form_order, HERMES_ANY, &prev_e); #endif // Surface linear forms - inner edges coming from the DG formulation. #ifdef HERMES_USE_VECTOR_VALUED_FORMS wf.add_vector_form_surf(0, linear_form_interface_vector, linear_form_order, H2D_DG_INNER_EDGE, Hermes::Tuple<MeshFunction*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e)); wf.add_vector_form_surf(1, linear_form_interface_vector, linear_form_order, H2D_DG_INNER_EDGE, Hermes::Tuple<MeshFunction*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e)); wf.add_vector_form_surf(2, linear_form_interface_vector, linear_form_order, H2D_DG_INNER_EDGE, Hermes::Tuple<MeshFunction*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e)); wf.add_vector_form_surf(3, linear_form_interface_vector, linear_form_order, H2D_DG_INNER_EDGE, Hermes::Tuple<MeshFunction*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e)); #else wf.add_vector_form_surf(0, linear_form_interface_0, linear_form_order, H2D_DG_INNER_EDGE, Hermes::Tuple<MeshFunction*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e)); wf.add_vector_form_surf(1, linear_form_interface_1, linear_form_order, H2D_DG_INNER_EDGE, Hermes::Tuple<MeshFunction*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e)); wf.add_vector_form_surf(2, linear_form_interface_2, linear_form_order, H2D_DG_INNER_EDGE, Hermes::Tuple<MeshFunction*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e)); wf.add_vector_form_surf(3, linear_form_interface_3, linear_form_order, H2D_DG_INNER_EDGE, Hermes::Tuple<MeshFunction*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e)); #endif // Surface linear forms - inlet / outlet edges. #ifdef HERMES_USE_VECTOR_VALUED_FORMS wf.add_vector_form_surf(0, bdy_flux_inlet_outlet_comp_vector, linear_form_order, BDY_INLET_OUTLET, Hermes::Tuple<MeshFunction*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e)); wf.add_vector_form_surf(1, bdy_flux_inlet_outlet_comp_vector, linear_form_order, BDY_INLET_OUTLET, Hermes::Tuple<MeshFunction*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e)); wf.add_vector_form_surf(2, bdy_flux_inlet_outlet_comp_vector, linear_form_order, BDY_INLET_OUTLET, Hermes::Tuple<MeshFunction*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e)); wf.add_vector_form_surf(3, bdy_flux_inlet_outlet_comp_vector, linear_form_order, BDY_INLET_OUTLET, Hermes::Tuple<MeshFunction*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e)); #else wf.add_vector_form_surf(0, bdy_flux_inlet_outlet_comp_0, linear_form_order, BDY_INLET_OUTLET, Hermes::Tuple<MeshFunction*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e)); wf.add_vector_form_surf(1, bdy_flux_inlet_outlet_comp_1, linear_form_order, BDY_INLET_OUTLET, Hermes::Tuple<MeshFunction*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e)); wf.add_vector_form_surf(2, bdy_flux_inlet_outlet_comp_2, linear_form_order, BDY_INLET_OUTLET, Hermes::Tuple<MeshFunction*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e)); wf.add_vector_form_surf(3, bdy_flux_inlet_outlet_comp_3, linear_form_order, BDY_INLET_OUTLET, Hermes::Tuple<MeshFunction*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e)); #endif // Surface linear forms - Solid wall edges. #ifdef HERMES_USE_VECTOR_VALUED_FORMS wf.add_vector_form_surf(0, bdy_flux_solid_wall_comp_vector, linear_form_order, BDY_SOLID_WALL, Hermes::Tuple<MeshFunction*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e)); wf.add_vector_form_surf(1, bdy_flux_solid_wall_comp_vector, linear_form_order, BDY_SOLID_WALL, Hermes::Tuple<MeshFunction*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e)); wf.add_vector_form_surf(2, bdy_flux_solid_wall_comp_vector, linear_form_order, BDY_SOLID_WALL, Hermes::Tuple<MeshFunction*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e)); wf.add_vector_form_surf(3, bdy_flux_solid_wall_comp_vector, linear_form_order, BDY_SOLID_WALL, Hermes::Tuple<MeshFunction*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e)); #else wf.add_vector_form_surf(0, bdy_flux_solid_wall_comp_0, linear_form_order, BDY_SOLID_WALL, Hermes::Tuple<MeshFunction*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e)); wf.add_vector_form_surf(1, bdy_flux_solid_wall_comp_1, linear_form_order, BDY_SOLID_WALL, Hermes::Tuple<MeshFunction*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e)); wf.add_vector_form_surf(2, bdy_flux_solid_wall_comp_2, linear_form_order, BDY_SOLID_WALL, Hermes::Tuple<MeshFunction*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e)); wf.add_vector_form_surf(3, bdy_flux_solid_wall_comp_3, linear_form_order, BDY_SOLID_WALL, Hermes::Tuple<MeshFunction*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e)); #endif // Initialize the FE problem. bool is_linear = true; DiscreteProblem dp(&wf, Hermes::Tuple<Space*>(&space_rho, &space_rho_v_x, &space_rho_v_y, &space_e), is_linear); // If the FE problem is in fact a FV problem. if(P_INIT.order_h == 0 && P_INIT.order_v == 0) dp.set_fvm(); #ifdef HERMES_USE_VECTOR_VALUED_FORMS dp.use_vector_valued_forms(); #endif // Filters for visualization of pressure and the two components of velocity. SimpleFilter pressure(calc_pressure_func, Hermes::Tuple<MeshFunction*>(&sln_rho, &sln_rho_v_x, &sln_rho_v_y, &sln_e)); SimpleFilter u(calc_u_func, Hermes::Tuple<MeshFunction*>(&sln_rho, &sln_rho_v_x, &sln_rho_v_y, &sln_e)); SimpleFilter w(calc_w_func, Hermes::Tuple<MeshFunction*>(&sln_rho, &sln_rho_v_x, &sln_rho_v_y, &sln_e)); SimpleFilter Mach_number(calc_Mach_func, Hermes::Tuple<MeshFunction*>(&sln_rho, &sln_rho_v_x, &sln_rho_v_y, &sln_e)); SimpleFilter entropy_estimate(calc_entropy_estimate_func, Hermes::Tuple<MeshFunction*>(&sln_rho, &sln_rho_v_x, &sln_rho_v_y, &sln_e)); ScalarView pressure_view("Pressure", new WinGeom(0, 0, 600, 300)); ScalarView Mach_number_view("Mach number", new WinGeom(700, 0, 600, 300)); ScalarView entropy_production_view("Entropy estimate", new WinGeom(0, 400, 600, 300)); VectorView vview("Velocity", new WinGeom(700, 400, 600, 300)); // Iteration number. int iteration = 0; // Set up the solver, matrix, and rhs according to the solver selection. SparseMatrix* matrix = create_matrix(matrix_solver); Vector* rhs = create_vector(matrix_solver); Solver* solver = create_linear_solver(matrix_solver, matrix, rhs); // Output of the approximate time derivative. std::ofstream time_der_out("time_der"); for(t = 0.0; t < 10; t += TAU) { info("---- Time step %d, time %3.5f.", iteration, t); iteration++; bool rhs_only = (iteration == 1 ? false : true); // Assemble stiffness matrix and rhs or just rhs. if (rhs_only == false) info("Assembling the stiffness matrix and right-hand side vector."); else info("Assembling the right-hand side vector (only)."); dp.assemble(matrix, rhs, rhs_only); // Solve the matrix problem. info("Solving the matrix problem."); if(solver->solve()) Solution::vector_to_solutions(solver->get_solution(), Hermes::Tuple<Space *>(&space_rho, &space_rho_v_x, &space_rho_v_y, &space_e), Hermes::Tuple<Solution *>(&sln_rho, &sln_rho_v_x, &sln_rho_v_y, &sln_e)); else error ("Matrix solver failed.\n"); // Approximate the time derivative of the solution. if(CALC_TIME_DER) { Adapt *adapt_for_time_der_calc = new Adapt(Hermes::Tuple<Space *>(&space_rho, &space_rho_v_x, &space_rho_v_y, &space_e)); bool solutions_for_adapt = false; double difference = iteration == 1 ? 0 : adapt_for_time_der_calc->calc_err_est(Hermes::Tuple<Solution *>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), Hermes::Tuple<Solution *>(&sln_rho, &sln_rho_v_x, &sln_rho_v_y, &sln_e), (Hermes::Tuple<double>*) NULL, solutions_for_adapt, HERMES_TOTAL_ERROR_ABS | HERMES_ELEMENT_ERROR_ABS) / TAU; delete adapt_for_time_der_calc; // Info about the approximate time derivative. if(iteration > 1) { info("Approximate the norm time derivative : %g.", difference); time_der_out << iteration << '\t' << difference << std::endl; } } // Determine the time step according to the CFL condition. // Only mean values on an element of each solution component are taken into account. double *solution_vector = solver->get_solution(); double min_condition = 0; Element *e; for (int _id = 0, _max = mesh.get_max_element_id(); _id < _max; _id++) \ if (((e) = mesh.get_element_fast(_id))->used) \ if ((e)->active) { AsmList al; space_rho.get_element_assembly_list(e, &al); double rho = solution_vector[al.dof[0]]; space_rho_v_x.get_element_assembly_list(e, &al); double v1 = solution_vector[al.dof[0]] / rho; space_rho_v_y.get_element_assembly_list(e, &al); double v2 = solution_vector[al.dof[0]] / rho; space_e.get_element_assembly_list(e, &al); double energy = solution_vector[al.dof[0]]; double condition = e->get_area() / (std::sqrt(v1*v1 + v2*v2) + calc_sound_speed(rho, rho*v1, rho*v2, energy)); if(condition < min_condition || min_condition == 0.) min_condition = condition; } if(TAU > min_condition) TAU = min_condition; if(TAU < min_condition * 0.9) TAU = min_condition; // Copy the solutions into the previous time level ones. prev_rho.copy(&sln_rho); prev_rho_v_x.copy(&sln_rho_v_x); prev_rho_v_y.copy(&sln_rho_v_y); prev_e.copy(&sln_e); // Visualization. pressure.reinit(); u.reinit(); w.reinit(); Mach_number.reinit(); entropy_estimate.reinit(); pressure_view.show(&pressure); entropy_production_view.show(&entropy_estimate); Mach_number_view.show(&Mach_number); vview.show(&u, &w); // If used, we need to clean the vector valued form caches. #ifdef HERMES_USE_VECTOR_VALUED_FORMS DiscreteProblem::empty_form_caches(); #endif } time_der_out.close(); return 0; }
float MS5837::altitude() { return (1-pow((pressure()/1013.25),.190284))*145366.45*.3048; }
float MS5837::depth() { return (pressure(MS5837::Pa)-101300)/(fluidDensity*9.80665); }
doublereal ConstDensityThermo::enthalpy_mole() const { doublereal p0 = m_spthermo->refPressure(); return GasConstant * temperature() * mean_X(&enthalpy_RT()[0]) + (pressure() - p0)/molarDensity(); }
int main(int argc, char** argv) { #ifdef HAVE_LIBMESH libMesh::LibMeshInit init(argc,argv); #else FemusInit init(argc,argv); #endif // ======= Files ======================== Files files; files.ConfigureRestart(); files.CheckIODirectories(); files.CopyInputFiles(); files.RedirectCout(); // ======= Physics Input Parser ======================== FemusInputParser<double> physics_map("Physics",files.GetOutputPath()); const double rhof = physics_map.get("rho0"); const double Uref = physics_map.get("Uref"); const double Lref = physics_map.get("Lref"); const double muf = physics_map.get("mu0"); const double _pref = rhof*Uref*Uref; physics_map.set("pref",_pref); const double _Re = (rhof*Uref*Lref)/muf; physics_map.set("Re",_Re); const double _Fr = (Uref*Uref)/(9.81*Lref); physics_map.set("Fr",_Fr); const double _Pr = muf/rhof; physics_map.set("Pr",_Pr); // ======= Mesh ===== const unsigned NoLevels = 3; const unsigned dim = 2; const GeomElType geomel_type = QUAD; GenCase mesh(NoLevels,dim,geomel_type,"inclQ2D2x2.gam"); mesh.SetLref(1.); // ======= MyDomainShape (optional, implemented as child of Domain) ==================== FemusInputParser<double> box_map("Box",files.GetOutputPath()); Box mybox(mesh.get_dim(),box_map); mybox.InitAndNondimensionalize(mesh.get_Lref()); mesh.SetDomain(&mybox); mesh.GenerateCase(files.GetOutputPath()); mesh.SetLref(Lref); mybox.InitAndNondimensionalize(mesh.get_Lref()); XDMFWriter::ReadMeshAndNondimensionalizeBiquadraticHDF5(files.GetOutputPath(),mesh); XDMFWriter::PrintMeshXDMF(files.GetOutputPath(),mesh,BIQUADR_FE); XDMFWriter::PrintMeshLinear(files.GetOutputPath(),mesh); //gencase is dimensionalized, meshtwo is nondimensionalized //since the meshtwo is nondimensionalized, all the BC and IC are gonna be implemented on a nondimensionalized mesh //now, a mesh may or may not have an associated domain //moreover, a mesh may or may not be read from file //the generation is dimensional, the nondimensionalization occurs later //Both the Mesh and the optional domain must be nondimensionalized //first, we have to say if the mesh has a shape or not //that depends on the application, it must be put at the main level //then, after you know the shape, you may or may not generate the mesh with that shape //the two things are totally independent, and related to the application, not to the library // ===== QuantityMap : this is like the MultilevelSolution ========================================= QuantityMap qty_map; qty_map.SetMeshTwo(&mesh); qty_map.SetInputParser(&physics_map); Pressure pressure("Qty_Pressure",qty_map,1,LL); qty_map.AddQuantity(&pressure); VelocityX velocityX("Qty_Velocity0",qty_map,1,QQ); qty_map.AddQuantity(&velocityX); VelocityY velocityY("Qty_Velocity1",qty_map,1,QQ); qty_map.AddQuantity(&velocityY); Temperature temperature("Qty_Temperature",qty_map,1,QQ); qty_map.AddQuantity(&temperature); TempLift templift("Qty_TempLift",qty_map,1,QQ); qty_map.AddQuantity(&templift); TempAdj tempadj("Qty_TempAdj",qty_map,1,QQ); qty_map.AddQuantity(&tempadj); // ===== end QuantityMap ========================================= // ====== Start new main ================================= MultiLevelMesh ml_msh; ml_msh.GenerateCoarseBoxMesh(8,8,0,0,1,0,2,0,0,QUAD9,"fifth"); // ml_msh.GenerateCoarseBoxMesh(numelemx,numelemy,numelemz,xa,xb,ya,yb,za,zb,elemtype,"fifth"); ml_msh.RefineMesh(NoLevels,NoLevels,NULL); ml_msh.PrintInfo(); ml_msh.SetWriter(XDMF); //ml_msh.GetWriter()->write(files.GetOutputPath(),"biquadratic"); ml_msh.SetDomain(&mybox); MultiLevelSolution ml_sol(&ml_msh); ml_sol.AddSolution("Qty_Temperature",LAGRANGE,SECOND,0); ml_sol.AddSolution("Qty_TempLift",LAGRANGE,SECOND,0); ml_sol.AddSolution("Qty_TempAdj",LAGRANGE,SECOND,0); ml_sol.AddSolutionVector(ml_msh.GetDimension(),"Qty_Velocity",LAGRANGE,SECOND,0); ml_sol.AddSolution("Qty_Pressure",LAGRANGE,FIRST,0); ml_sol.AddSolution("Qty_TempDes",LAGRANGE,SECOND,0,false); //this is not going to be an Unknown! //moreover, this is not going to need any BC (i think they are excluded with "false") // I would like to have a Solution that is NOT EVEN related to the mesh at all... just like a function "on-the-fly" // ******* Set problem ******* MultiLevelProblem ml_prob(&ml_sol); ml_prob.SetMeshTwo(&mesh); ml_prob.SetQruleAndElemType("fifth"); ml_prob.SetInputParser(&physics_map); ml_prob.SetQtyMap(&qty_map); // ******* Initial condition ******* ml_sol.InitializeMLProb(&ml_prob,"Qty_Temperature",SetInitialCondition); ml_sol.InitializeMLProb(&ml_prob,"Qty_TempLift",SetInitialCondition); ml_sol.InitializeMLProb(&ml_prob,"Qty_TempAdj",SetInitialCondition); ml_sol.InitializeMLProb(&ml_prob,"Qty_Velocity0",SetInitialCondition); ml_sol.InitializeMLProb(&ml_prob,"Qty_Velocity1",SetInitialCondition); ml_sol.InitializeMLProb(&ml_prob,"Qty_Pressure",SetInitialCondition); ml_sol.InitializeMLProb(&ml_prob,"Qty_TempDes",SetInitialCondition); /// @todo you have to call this before you can print /// @todo I can also call it after instantiation MLProblem /// @todo I cannot call it with "All" and with a FUNCTION, because I need the string for "All" as a variable /// @todo Have to say that you have to call this initialize BEFORE the generation of the boundary conditions; /// if you called this after, it would superimpose the BOUNDARY VALUES /// @todo you have to initialize also those variables which are NOT unknowns! // ******* Set boundary function function ******* ml_sol.AttachSetBoundaryConditionFunctionMLProb(SetBoundaryCondition); // ******* Generate boundary conditions ******* ml_sol.GenerateBdc("Qty_Temperature","Steady",&ml_prob); ml_sol.GenerateBdc("Qty_TempLift","Steady",&ml_prob); ml_sol.GenerateBdc("Qty_TempAdj","Steady",&ml_prob); ml_sol.GenerateBdc("Qty_Velocity0","Steady",&ml_prob); ml_sol.GenerateBdc("Qty_Velocity1","Steady",&ml_prob); ml_sol.GenerateBdc("Qty_Pressure","Steady",&ml_prob); // ******* Debug ******* ml_sol.SetWriter(VTK); std::vector<std::string> print_vars(1); print_vars[0] = "All"; // we should find a way to make this easier ml_sol.GetWriter()->write(files.GetOutputPath(),"biquadratic",print_vars); //=============================================== //================== Add EQUATIONS AND ====================== //========= associate an EQUATION to QUANTITIES ======== //======================================================== // not all the Quantities need to be unknowns of an equation SystemTwo & eqnNS = ml_prob.add_system<SystemTwo>("Eqn_NS"); eqnNS.AddSolutionToSystemPDEVector(ml_msh.GetDimension(),"Qty_Velocity"); eqnNS.AddSolutionToSystemPDE("Qty_Pressure"); eqnNS.AddUnknownToSystemPDE(&velocityX); eqnNS.AddUnknownToSystemPDE(&velocityY); eqnNS.AddUnknownToSystemPDE(&pressure); eqnNS.SetAssembleFunction(GenMatRhsNS); SystemTwo & eqnT = ml_prob.add_system<SystemTwo>("Eqn_T"); eqnT.AddSolutionToSystemPDE("Qty_Temperature"); eqnT.AddSolutionToSystemPDE("Qty_TempLift"); eqnT.AddSolutionToSystemPDE("Qty_TempAdj"); eqnT.AddUnknownToSystemPDE(&temperature); eqnT.AddUnknownToSystemPDE(&templift); eqnT.AddUnknownToSystemPDE(&tempadj); //the order in which you add defines the order in the matrix as well, so it is in tune with the assemble function eqnT.SetAssembleFunction(GenMatRhsT); //================================ //========= End add EQUATIONS and ======== //========= associate an EQUATION to QUANTITIES ======== //================================ //Ok now that the mesh file is there i want to COMPUTE the MG OPERATORS... but I want to compute them ONCE and FOR ALL, //not for every equation... but the functions belong to the single equation... I need to make them EXTERNAL // then I'll have A from the equation, PRL and REST from a MG object. //So somehow i'll have to put these objects at a higher level... but so far let us see if we can COMPUTE and PRINT from HERE and not from the gencase //once you have the list of the equations, you loop over them to initialize everything for (MultiLevelProblem::const_system_iterator eqn = ml_prob.begin(); eqn != ml_prob.end(); eqn++) { SystemTwo* sys = static_cast<SystemTwo*>(eqn->second); // ******* set MG-Solver ******* sys->SetMgType(F_CYCLE); sys->SetLinearConvergenceTolerance(1.e-10); sys->SetNonLinearConvergenceTolerance(1.e-10);//1.e-5 sys->SetNumberPreSmoothingStep(1); sys->SetNumberPostSmoothingStep(1); sys->SetMaxNumberOfLinearIterations(8); //2 sys->SetMaxNumberOfNonLinearIterations(15); //10 // ******* Set Preconditioner ******* sys->SetMgSmoother(GMRES_SMOOTHER);//ASM_SMOOTHER,VANKA_SMOOTHER // ******* init ******* sys->init(); // ******* Set Smoother ******* sys->SetSolverFineGrids(GMRES); sys->SetPreconditionerFineGrids(ILU_PRECOND); sys->SetTolerances(1.e-12,1.e-20,1.e+50,20); /// what the heck do these parameters mean? // ******* Add variables to be solved ******* /// do we always need this? sys->ClearVariablesToBeSolved(); sys->AddVariableToBeSolved("All"); // ******* For Gmres Preconditioner only ******* sys->SetDirichletBCsHandling(ELIMINATION); // ******* For Gmres Preconditioner only ******* // sys->solve(); //===================== sys -> init_two(); //the dof map is built here based on all the solutions associated with that system sys -> _LinSolver[0]->set_solver_type(GMRES); //if I keep PREONLY it doesn't run //===================== sys -> init_unknown_vars(); //===================== sys -> _dofmap.ComputeMeshToDof(); //===================== sys -> initVectors(); //===================== sys -> Initialize(); ///===================== sys -> _bcond.GenerateBdc(); //===================== GenCase::ReadMGOps(files.GetOutputPath(),sys); } // ======== Loop =================================== FemusInputParser<double> loop_map("TimeLoop",files.GetOutputPath()); OptLoop opt_loop(files, loop_map); opt_loop.TransientSetup(ml_prob); // reset the initial state (if restart) and print the Case opt_loop.optimization_loop(ml_prob); // at this point, the run has been completed files.PrintRunForRestart(DEFAULT_LAST_RUN); files.log_petsc(); // ============ clean ================================ ml_prob.clear(); mesh.clear(); return 0; }
std::string MolarityIonicVPSSTP::report(bool show_thermo) const { char p[800]; string s = ""; try { if (name() != "") { sprintf(p, " \n %s:\n", name().c_str()); s += p; } sprintf(p, " \n temperature %12.6g K\n", temperature()); s += p; sprintf(p, " pressure %12.6g Pa\n", pressure()); s += p; sprintf(p, " density %12.6g kg/m^3\n", density()); s += p; sprintf(p, " mean mol. weight %12.6g amu\n", meanMolecularWeight()); s += p; doublereal phi = electricPotential(); sprintf(p, " potential %12.6g V\n", phi); s += p; size_t kk = nSpecies(); vector_fp x(kk); vector_fp molal(kk); vector_fp mu(kk); vector_fp muss(kk); vector_fp acMolal(kk); vector_fp actMolal(kk); getMoleFractions(&x[0]); getChemPotentials(&mu[0]); getStandardChemPotentials(&muss[0]); getActivities(&actMolal[0]); if (show_thermo) { sprintf(p, " \n"); s += p; sprintf(p, " 1 kg 1 kmol\n"); s += p; sprintf(p, " ----------- ------------\n"); s += p; sprintf(p, " enthalpy %12.6g %12.4g J\n", enthalpy_mass(), enthalpy_mole()); s += p; sprintf(p, " internal energy %12.6g %12.4g J\n", intEnergy_mass(), intEnergy_mole()); s += p; sprintf(p, " entropy %12.6g %12.4g J/K\n", entropy_mass(), entropy_mole()); s += p; sprintf(p, " Gibbs function %12.6g %12.4g J\n", gibbs_mass(), gibbs_mole()); s += p; sprintf(p, " heat capacity c_p %12.6g %12.4g J/K\n", cp_mass(), cp_mole()); s += p; try { sprintf(p, " heat capacity c_v %12.6g %12.4g J/K\n", cv_mass(), cv_mole()); s += p; } catch (CanteraError& e) { e.save(); sprintf(p, " heat capacity c_v <not implemented> \n"); s += p; } } } catch (CanteraError& e) { e.save(); } return s; }
/* Construct Packet */ void Construct_Packet(void) { //Serial.println("construct packet top"); //Variable for Index and uptime unsigned long uptime_ms; //Put schema number in packet G_packet.schema = 297; //Update data uptime_ms = millis(); //Put uptime in packet G_packet.uptime_ms = uptime_ms; //Poll and put battery and panel data in packet for(int p = 0; p < 6; p++) { G_packet.batt_mv[p] = battery(); G_packet.panel_mv[p] = panel(); delay(400); } //Poll and put panel data in packet /*for(int p = 0; p < 6; p++) { G_packet.panel_mv[p] = panel(); delay(400); }*/ G_packet.bmp185_press_pa = pressure(); G_packet.bmp185_temp_decic = temp(); G_packet.humidity_centi_pct = humidity(); //Poll and put irradiance data in packet for(int i = 0; i < 20; i++) { G_packet.solar_irr_w_m2[i] = irradiance(); delay(300); } /*//Hardcoded Test Packet G_packet.uptime_ms = 1; for(int p = 0; p <= 4; p++) { G_packet.batt_mv[p] = 1; Serial.print("Battery"); Serial.println(G_packet.batt_mv[p]); delay(400); } for(int p = 0; p <= 4; p++) { G_packet.panel_mv[p] = 2; Serial.print("Panel"); Serial.println(G_packet.panel_mv[p]); delay(400); } G_packet.bmp185_press_pa = 3; Serial.print("Pressure"); Serial.println(G_packet.bmp185_press_pa); G_packet.bmp185_temp_decic = 4; Serial.print("Temp"); Serial.println(G_packet.bmp185_temp_decic); G_packet.humidity_centi_pct = 5; Serial.print("Humidity"); Serial.println(G_packet.humidity_centi_pct); for(int i = 0; i <= 14; i++) { G_packet.solar_irr_w_m2[i] = 6; Serial.print("Solar"); Serial.println(G_packet.solar_irr_w_m2[i]); delay(1000); }*/ }
void Hydrostatic_Velocity<EvalT, Traits>:: evaluateFields(typename Traits::EvalData workset) { time = workset.current_time; #ifndef ALBANY_KOKKOS_UNDER_DEVELOPMENT //*out << "Aeras::Hydrostatic_Velocity time = " << time << std::endl; switch (adv_type) { case UNKNOWN: //velocity is an unknown that we solve for (not prescribed) { for (int cell=0; cell < workset.numCells; ++cell) for (int node=0; node < numNodes; ++node) for (int level=0; level < numLevels; ++level) for (int dim=0; dim < numDims; ++dim) Velocity(cell,node,level,dim) = Velx(cell,node,level,dim); } break; case PRESCRIBED_1_1: //velocity is prescribed to that of 1-1 test { for (int cell=0; cell < workset.numCells; ++cell) { for (int node=0; node < numNodes; ++node) { const MeshScalarT lambda = sphere_coord(cell, node, 0); const MeshScalarT theta = sphere_coord(cell, node, 1); ScalarT lambdap = lambda - 2.0*PI*time/tau; for (int level=0; level < numLevels; ++level) { ScalarT Ua = k*sin(lambdap)*sin(lambdap)*sin(2.0*theta)*cos(PI*time/tau) + (2.0*PI*earthRadius/tau)*cos(theta); ScalarT Va = k*sin(2.0*lambdap)*cos(theta)*cos(PI*time/tau); ScalarT B = E.B(level); ScalarT p = pressure(cell,node,level); ScalarT taper = - exp( (p - p0)/(B*ptop) ) + exp( (ptop - p )/(B*ptop) ); ScalarT Ud = (omega0*earthRadius)/(B*ptop) *cos(lambdap)*cos(theta)*cos(theta)*cos(2.0*PI*time/tau)*taper; Velocity(cell,node,level,0) = Ua + Ud; Velocity(cell,node,level,1) = Va; } } } } break; case PRESCRIBED_1_2: //velocity is prescribed to that of 1-2 test { //FIXME: Pete, Tom - please fill in for (int cell=0; cell < workset.numCells; ++cell) { for (int node=0; node < numNodes; ++node) { const MeshScalarT lambda = sphere_coord(cell, node, 0); const MeshScalarT theta = sphere_coord(cell, node, 1); for (int level=0; level < numLevels; ++level) { for (int dim=0; dim < numDims; ++dim) { Velocity(cell,node,level,dim) = 0.0; //FIXME } } } } } break; } #else switch (adv_type) { case UNKNOWN: //velocity is an unknown that we solve for (not prescribed) { Kokkos::parallel_for(Hydrostatic_Velocity_Policy(0,workset.numCells),*this); cudaCheckError(); break; } case PRESCRIBED_1_1: //velocity is prescribed to that of 1-1 test { Kokkos::parallel_for(Hydrostatic_Velocity_PRESCRIBED_1_1_Policy(0,workset.numCells),*this); cudaCheckError(); break; } case PRESCRIBED_1_2: //velocity is prescribed to that of 1-2 test { Kokkos::parallel_for(Hydrostatic_Velocity_PRESCRIBED_1_2_Policy(0,workset.numCells),*this); cudaCheckError(); break; } } #endif }
doublereal LatticePhase::enthalpy_mole() const { return RT() * mean_X(enthalpy_RT_ref()) + (pressure() - m_Pref)/molarDensity(); }
std::string ThermoPhase::report(bool show_thermo, doublereal threshold) const { fmt::MemoryWriter b; try { if (name() != "") { b.write("\n {}:\n", name()); } b.write("\n"); b.write(" temperature {:12.6g} K\n", temperature()); b.write(" pressure {:12.6g} Pa\n", pressure()); b.write(" density {:12.6g} kg/m^3\n", density()); b.write(" mean mol. weight {:12.6g} amu\n", meanMolecularWeight()); doublereal phi = electricPotential(); if (phi != 0.0) { b.write(" potential {:12.6g} V\n", phi); } if (show_thermo) { b.write("\n"); b.write(" 1 kg 1 kmol\n"); b.write(" ----------- ------------\n"); b.write(" enthalpy {:12.5g} {:12.4g} J\n", enthalpy_mass(), enthalpy_mole()); b.write(" internal energy {:12.5g} {:12.4g} J\n", intEnergy_mass(), intEnergy_mole()); b.write(" entropy {:12.5g} {:12.4g} J/K\n", entropy_mass(), entropy_mole()); b.write(" Gibbs function {:12.5g} {:12.4g} J\n", gibbs_mass(), gibbs_mole()); b.write(" heat capacity c_p {:12.5g} {:12.4g} J/K\n", cp_mass(), cp_mole()); try { b.write(" heat capacity c_v {:12.5g} {:12.4g} J/K\n", cv_mass(), cv_mole()); } catch (NotImplementedError&) { b.write(" heat capacity c_v <not implemented> \n"); } } vector_fp x(m_kk); vector_fp y(m_kk); vector_fp mu(m_kk); getMoleFractions(&x[0]); getMassFractions(&y[0]); getChemPotentials(&mu[0]); int nMinor = 0; doublereal xMinor = 0.0; doublereal yMinor = 0.0; b.write("\n"); if (show_thermo) { b.write(" X " " Y Chem. Pot. / RT\n"); b.write(" ------------- " "------------ ------------\n"); for (size_t k = 0; k < m_kk; k++) { if (abs(x[k]) >= threshold) { if (abs(x[k]) > SmallNumber) { b.write("{:>18s} {:12.6g} {:12.6g} {:12.6g}\n", speciesName(k), x[k], y[k], mu[k]/RT()); } else { b.write("{:>18s} {:12.6g} {:12.6g}\n", speciesName(k), x[k], y[k]); } } else { nMinor++; xMinor += x[k]; yMinor += y[k]; } } } else { b.write(" X Y\n"); b.write(" ------------- ------------\n"); for (size_t k = 0; k < m_kk; k++) { if (abs(x[k]) >= threshold) { b.write("{:>18s} {:12.6g} {:12.6g}\n", speciesName(k), x[k], y[k]); } else { nMinor++; xMinor += x[k]; yMinor += y[k]; } } } if (nMinor) { b.write(" [{:+5d} minor] {:12.6g} {:12.6g}\n", nMinor, xMinor, yMinor); } } catch (CanteraError& err) { return b.str() + err.what(); } return b.str(); }
EXPORT void g_verbose_fprint_state( FILE *file, const char *name, Locstate state) { bool bin_out; int i, dim; float p, c, S, v[SMAXD], speed; static char vname[3][3] = { "vx", "vy", "vz"}; static char mname[3][3] = { "mx", "my", "mz"}; if (name == NULL) name = ""; (void) fprintf(file,"\n%s:\n",name); (void) fprintf(file,"address %p\n",state); if (state == NULL || is_obstacle_state(state)) { (void) fprintf(file,"(OBSTACLE STATE)\n\n"); return; } dim = Params(state)->dim; p = pressure(state); c = sound_speed(state); S = entropy(state); (void) fprintf(file,"%-24s = %-"FFMT" %-24s = %-"FFMT"\n", "density",Dens(state), "specific internal energy", specific_internal_energy(state)); (void) fprintf(file,"%-24s = %-"FFMT" %-24s = %-"FFMT"\n","pressure",p, "sound speed",c); (void) fprintf(file,"%-24s = %-"FFMT" %-24s = %-"FFMT"\n","temperature", temperature(state),"specific entropy",S); speed = 0.0; for (i = 0; i < dim; i++) { v[i] = vel(i,state); speed += sqr(v[i]); (void) fprintf(file,"%-24s = %-"FFMT" %-24s = %-"FFMT"\n", mname[i],mom(i,state),vname[i],v[i]); } speed = sqrt(speed); (void) fprintf(file,"%-24s = %-"FFMT"","total energy",energy(state)); if (c > 0. && Dens(state) > 0.) (void) fprintf(file," %-24s = %-"FFMT"\n","Mach number",speed / c); else (void) fprintf(file,"\n"); #if defined(TWOD) if (dim == 2) (void) fprintf(file,"%-24s = %-"FFMT"\n","velocity angle", degrees(angle(v[0],v[1]))); #endif /* defined(TWOD) */ fprint_state_type(file,"State type = ",state_type(state)); (void) fprintf(file,"Params state = %llu\n", gas_param_number(Params(state))); bin_out = is_binary_output(); set_binary_output(NO); if (debugging("prt_params")) fprint_Gas_param(file,Params(state)); else (void) fprintf(file,"Gas_param = %llu\n", gas_param_number(Params(state))); set_binary_output(bin_out); //if(p< -2000 || p>10000) //{ // printf("#huge pressure\n"); // clean_up(0); //} #if !defined(COMBUSTION_CODE) (void) fprintf(file,"\n"); #else /* !defined(COMBUSTION_CODE) */ if (Composition_type(state) == PURE_NON_REACTIVE) { (void) fprintf(file,"\n"); return; } (void) fprintf(file,"%-24s = %-12s %-24s = %-"FFMT"\n","burned", Burned(state) ? "BURNED" : "UNBURNED", "q",Params(state)->q); (void) fprintf(file,"%-24s = %-"FFMT"\n","t_crit", Params(state)->critical_temperature); if (Composition_type(state) == PTFLAME) { (void) fprintf(file,"\n"); return; } (void) fprintf(file,"%-24s = %-"FFMT"\n","product density",Prod(state)); (void) fprintf(file,"%-24s = %-"FFMT"\n", "reaction progress",React(state)); if (Composition_type(state) == ZND) { (void) fprintf(file,"\n"); return; } (void) fprintf(file,"%-24s = %-"FFMT"\n","rho1",Dens1(state)); #endif /* !defined(COMBUSTION_CODE) */ (void) fprintf(file,"%-24s = %-24s %-24s = %-"FFMT"\n\n","gamma_set", Local_gamma_set(state)?"YES" : "NO","local_gamma", Local_gamma(state)); if(g_composition_type() == MULTI_COMP_NON_REACTIVE) { if(Params(state) != NULL && Params(state)->n_comps != 1) { for(i = 0; i < Params(state)->n_comps; i++) (void) fprintf(file,"partial density[%2d] = %"FFMT"\n", i,pdens(state)[i]); (void) fprintf(file,"\n"); /* TMP the following print is for the debuging display purpose */ for(i = 0; i < Params(state)->n_comps; i++) (void) fprintf(file,"[%d]Mass fraction = %-"FFMT"\n", i, pdens(state)[i]/Dens(state)); (void) fprintf(file,"\n"); } } } /*end g_verbose_fprint_state*/
int tester() { //description std::vector<std::string> neutrals; std::vector<std::string> ions; neutrals.push_back("N2"); neutrals.push_back("CH4"); neutrals.push_back("C2H"); //ionic system contains neutral system ions = neutrals; ions.push_back("N2+"); Scalar MN(14.008L), MC(12.011), MH(1.008L); Scalar MN2 = 2.L*MN , MCH4 = MC + 4.L*MH, MC2H = 2.L * MC + MH; std::vector<Scalar> Mm; Mm.push_back(MN2); Mm.push_back(MCH4); Mm.push_back(MC2H); //densities std::vector<Scalar> molar_frac; molar_frac.push_back(0.95999L); molar_frac.push_back(0.04000L); molar_frac.push_back(0.00001L); molar_frac.push_back(0.L); Scalar dens_tot(1e12L); //hard sphere radius std::vector<Scalar> hard_sphere_radius; hard_sphere_radius.push_back(2.0675e-8L * 1e-2L); //N2 in cm -> m hard_sphere_radius.push_back(2.3482e-8L * 1e-2L); //CH4 in cm -> m hard_sphere_radius.push_back(0.L); //C2H //zenith angle //not necessary //photon flux //not necessary ////cross-section //not necessary //altitudes Scalar zmin(600.),zmax(1400.),zstep(10.); //binary diffusion Scalar bCN1(1.04e-5 * 1e-4),bCN2(1.76); //cm2 -> m2 Planet::DiffusionType CN_model(Planet::DiffusionType::Wakeham); Scalar bCC1(5.73e16 * 1e-4),bCC2(0.5); //cm2 -> m2 Planet::DiffusionType CC_model(Planet::DiffusionType::Wilson); Scalar bNN1(0.1783 * 1e-4),bNN2(1.81); //cm2 -> m2 Planet::DiffusionType NN_model(Planet::DiffusionType::Massman); /************************ * first level ************************/ //altitude Planet::Altitude<Scalar,std::vector<Scalar> > altitude(zmin,zmax,zstep); //neutrals Antioch::ChemicalMixture<Scalar> neutral_species(neutrals); //ions Antioch::ChemicalMixture<Scalar> ionic_species(ions); //chapman //not needed //binary diffusion Planet::BinaryDiffusion<Scalar> N2N2( Antioch::Species::N2, Antioch::Species::N2 , bNN1, bNN2, NN_model); Planet::BinaryDiffusion<Scalar> N2CH4( Antioch::Species::N2, Antioch::Species::CH4, bCN1, bCN2, CN_model); Planet::BinaryDiffusion<Scalar> CH4CH4( Antioch::Species::CH4, Antioch::Species::CH4, bCC1, bCC2, CC_model); Planet::BinaryDiffusion<Scalar> N2C2H( Antioch::Species::N2, Antioch::Species::C2H); Planet::BinaryDiffusion<Scalar> CH4C2H( Antioch::Species::CH4, Antioch::Species::C2H); std::vector<std::vector<Planet::BinaryDiffusion<Scalar> > > bin_diff_coeff; bin_diff_coeff.resize(2); bin_diff_coeff[0].push_back(N2N2); bin_diff_coeff[0].push_back(N2CH4); bin_diff_coeff[0].push_back(N2C2H); bin_diff_coeff[1].push_back(N2CH4); bin_diff_coeff[1].push_back(CH4CH4); bin_diff_coeff[1].push_back(CH4C2H); /************************ * second level ************************/ //temperature std::vector<Scalar> T0,Tz; read_temperature<Scalar>(T0,Tz,"input/temperature.dat"); std::vector<Scalar> neutral_temperature; linear_interpolation(T0,Tz,altitude.altitudes(),neutral_temperature); Planet::AtmosphericTemperature<Scalar, std::vector<Scalar> > temperature(neutral_temperature, neutral_temperature, altitude); //photon opacity //not needed //reaction sets //not needed /************************ * third level ************************/ //atmospheric mixture Planet::AtmosphericMixture<Scalar,std::vector<Scalar>, std::vector<std::vector<Scalar> > > composition(neutral_species, ionic_species, altitude, temperature); composition.init_composition(molar_frac,dens_tot); composition.set_hard_sphere_radius(hard_sphere_radius); composition.initialize(); //kinetics evaluators //not needed /************************ * fourth level ************************/ //photon evaluator //not needed //molecular diffusion Planet::MolecularDiffusionEvaluator<Scalar,std::vector<Scalar>, std::vector<std::vector<Scalar> > > molecular_diffusion(bin_diff_coeff, composition, altitude, temperature); molecular_diffusion.make_molecular_diffusion(); //eddy diffusion //not needed /************************ * checks ************************/ molar_frac.pop_back();//get the ion outta here Scalar Matm(0.L); for(unsigned int s = 0; s < molar_frac.size(); s++) { Matm += molar_frac[s] * composition.neutral_composition().M(s); } Matm *= 1e-3L; //to kg std::vector<std::vector<Scalar> > densities; calculate_densities(densities, dens_tot, molar_frac, zmin,zmax,zstep, temperature.neutral_temperature(), Mm); //N2, CH4, C2H std::vector<std::vector<Scalar> > Dij; Dij.resize(2); Dij[0].resize(3,0.L); Dij[1].resize(3,0.L); int return_flag(0); for(unsigned int iz = 0; iz < altitude.altitudes().size(); iz++) { Scalar P = pressure(composition.total_density()[iz],temperature.neutral_temperature()[iz]); Scalar T = temperature.neutral_temperature()[iz]; Dij[0][0] = binary_coefficient(T,P,bNN1,bNN2); //N2 N2 Dij[1][1] = binary_coefficient(T,P,bCC1 * Antioch::ant_pow(Planet::Constants::Convention::T_standard<Scalar>(),bCC2 + Scalar(1.L)) * Planet::Constants::Universal::kb<Scalar>() / Planet::Constants::Convention::P_normal<Scalar>(),bCC2 + Scalar(1.L)); //CH4 CH4 Dij[0][1] = binary_coefficient(T,P,bCN1 * Antioch::ant_pow(Planet::Constants::Convention::T_standard<Scalar>(),bCN2),bCN2); //N2 CH4 Dij[0][2] = binary_coefficient(Dij[0][0],Mm[0],Mm[2]); //N2 C2H Dij[1][2] = binary_coefficient(Dij[1][1],Mm[1],Mm[2]); //CH4 C2H Dij[1][0] = Dij[0][1]; //CH4 N2 for(unsigned int s = 0; s < molar_frac.size(); s++) { Scalar tmp(0.L); Scalar M_diff(0.L); for(unsigned int medium = 0; medium < 2; medium++) { if(s == medium)continue; tmp += densities[medium][iz]/Dij[medium][s]; } Scalar Ds = (barometry(zmin,altitude.altitudes()[iz],neutral_temperature[iz],Matm,dens_tot) - densities[s][iz]) / tmp; for(unsigned int j = 0; j < molar_frac.size(); j++) { if(s == j)continue; M_diff += composition.total_density()[iz] * composition.neutral_molar_fraction()[j][iz] * composition.neutral_composition().M(j); } M_diff /= Scalar(molar_frac.size() - 1); Scalar Dtilde = Ds / (Scalar(1.L) - composition.neutral_molar_fraction()[s][iz] * (Scalar(1.L) - composition.neutral_composition().M(s)/M_diff)); return_flag = return_flag || check_test(Dtilde,molecular_diffusion.Dtilde()[s][iz],"D tilde of species at altitude"); } return_flag = return_flag || check_test(Dij[0][0],molecular_diffusion.binary_coefficient(0,0,T,P),"binary molecular coefficient N2 N2 at altitude") || check_test(Dij[0][1],molecular_diffusion.binary_coefficient(0,1,T,P),"binary molecular coefficient N2 CH4 at altitude") || check_test(Dij[0][2],molecular_diffusion.binary_coefficient(0,2,T,P),"binary molecular coefficient N2 C2H at altitude") || check_test(Dij[1][1],molecular_diffusion.binary_coefficient(1,1,T,P),"binary molecular coefficient CH4 CH4 at altitude") || check_test(Dij[1][2],molecular_diffusion.binary_coefficient(1,2,T,P),"binary molecular coefficient CH4 C2H at altitude"); } return return_flag; }
LOCAL void set_prt_node_sts_params( RP_DATA *RP, int n_type, int *num_sts, int *nangs, const char **ang_names, int *ist, int *iang) { float p[4]; int i; switch (n_type) { case DIFFRACTION_NODE: case TOT_INT_REFL_NODE: *num_sts = 7; for (i = 0; i < *num_sts; i++) ist[i] = i; ang_names[0] = "Incident shock angle"; ang_names[1] = "Reflected rarefaction leading edge angle"; ang_names[2] = "Reflected shock angle"; ang_names[3] = "Reflected rarefaction trailing edge angle"; ang_names[4] = "Downstream contact angle"; ang_names[5] = "Transmitted shock angle"; ang_names[6] = "Upstream contact angle"; iang[0] = 0; if (pressure(RP->state[4]) < pressure(RP->state[1])) { *nangs = 6; iang[1] = 1; iang[2] = 3; iang[3] = 4; iang[4] = 5; iang[5] = 6; } else { *nangs = 5; iang[1] = 2; iang[2] = 4; iang[3] = 5; iang[4] = 6; } break; case TRANSMISSION_NODE: *num_sts = 4; ist[0] = 0; ist[1] = 1; ist[2] = 3; ist[3] = 4; *nangs = 4; iang[0] = 0; iang[1] = 1; iang[2] = 3; iang[3] = 4; ang_names[0] = "Upstream contact angle"; ang_names[1] = "Incident shock angle"; ang_names[2] = "Downstream contact angle"; ang_names[3] = "Downstream contact angle"; ang_names[4] = "Transmitted shock angle"; break; case CROSS_NODE: *num_sts = 5; for (i = 0; i < 5; i++) ist[i] = i; for (i = 0; i < 4; i++) p[i] = pressure(RP->state[i+1]); ang_names[0] = "Incident shock angle"; iang[0] = 0; if (p[1] < p[0]) { *nangs = 6; iang[1] = 5; ang_names[1] = "Reflected rarefaction leading edge angle"; iang[2] = 6; ang_names[2] = "Reflected rarefaction trailing edge angle"; iang[3] = 2; ang_names[3] = "Contact angle"; iang[4] = 3; ang_names[4] = "Reflected shock angle"; iang[5] = 4; ang_names[5] = "Incident shock angle"; } else if (p[2] < p[3]) { *nangs = 6; iang[1] = 1; ang_names[1] = "Reflected shock angle"; iang[2] = 2; ang_names[2] = "Contact angle"; iang[3] = 5; ang_names[3] = "Reflected rarefaction leading edge angle"; iang[4] = 6; ang_names[4] = "Reflected rarefaction trailing edge angle"; iang[5] = 4; ang_names[5] = "Incident shock angle"; } else { *nangs = 5; for (i = 1; i < *nangs; i++) iang[i] = i; ang_names[1] = "Reflected shock angle"; ang_names[2] = "Contact angle"; ang_names[3] = "Reflected shock angle"; ang_names[4] = "Incident shock angle"; } break; case OVERTAKE_NODE: *num_sts = 7; for (i = 0; i < *num_sts; i++) ist[i] = i; iang[0] = 0; ang_names[0] = "Ahead incident shock angle"; iang[1] = 1; ang_names[1] = "Overtaking incident shock angle"; iang[0] = 0; if (pressure(RP->state[5]) < pressure(RP->state[2])) { *nangs = 6; iang[2] = 2; ang_names[2] = "Reflected rarefaction leading edge angle"; iang[3] = 4; ang_names[3] = "Reflected rarefaction trailing edge angle"; iang[4] = 5; ang_names[4] = "Contact angle"; iang[5] = 6; ang_names[5] = "Transmitted shock angle"; } else { *nangs = 5; iang[2] = 2; ang_names[2] = "Reflected shock angle"; iang[3] = 5; ang_names[4] = "Contact angle"; iang[4] = 6; ang_names[5] = "Transmitted shock angle"; } break; case MACH_NODE: *num_sts = 4; for (i = 0; i < *num_sts; i++) ist[i] = i; *nangs = 4; for (i = 0; i < *nangs; i++) iang[i] = i; ang_names[0] = "Incident shock angle"; ang_names[1] = "Reflected shock angle"; ang_names[2] = "Contact angle"; ang_names[3] = "Mach stem angle"; break; case B_REFLECT_NODE: *num_sts = 3; for (i = 0; i < *num_sts; i++) ist[i] = i; *nangs = 4; for (i = 0; i < *nangs; i++) iang[i] = i; ang_names[0] = "Upstream wall angle"; ang_names[1] = "Incident shock angle"; ang_names[2] = "Reflected shock angle"; ang_names[3] = "Downstream wall angle"; break; default: return; } } /*end print_node_sts_params*/
doublereal IdealGasPhase::standardConcentration(size_t k) const { return pressure() / (GasConstant * temperature()); }
EXPORT bool output_spectral_analysis( char *basename, Wave *wave, Front *front) { COMPONENT comp; Locstate state; float *coords; float *L = wave->rect_grid->L; float *U = wave->rect_grid->U; float *h = wave->rect_grid->h; int icoords[MAXD]; int dim = wave->rect_grid->dim; int status; int step = front->step; char energy_name[100],vorticity_name[100], enstrophy_name[100],dens_name[100],pres_name[100]; FILE *energy_file,*vorticity_file, *enstrophy_file,*dens_file,*pres_file; debug_print("fft","Entered fft_energy_spectral()\n"); (void) sprintf(energy_name,"%s.energy%s.dat",basename, right_flush(step,TSTEP_FIELD_WIDTH)); (void) sprintf(vorticity_name,"%s.vorticity%s.dat",basename, right_flush(step,TSTEP_FIELD_WIDTH)); (void) sprintf(enstrophy_name,"%s.enstrophy%s.dat",basename, right_flush(step,TSTEP_FIELD_WIDTH)); (void) sprintf(dens_name,"%s.density%s.dat",basename, right_flush(step,TSTEP_FIELD_WIDTH)); (void) sprintf(pres_name,"%s.pressure%s.dat",basename, right_flush(step,TSTEP_FIELD_WIDTH)); energy_file = fopen(energy_name,"w"); vorticity_file = fopen(vorticity_name,"w"); enstrophy_file = fopen(enstrophy_name,"w"); dens_file = fopen(dens_name,"w"); pres_file = fopen(pres_name,"w"); if (wave->sizest == 0) { debug_print("fft","Left fft_energy_spectral()\n"); return FUNCTION_FAILED; } switch (dim) { #if defined(ONED) case 1: { int ix; int xmax; COMPLEX *mesh_energy; xmax = wave->rect_grid->gmax[0]; uni_array(&mesh_energy,xmax,sizeof(COMPLEX)); for (ix = 0; ix < xmax; ++ix) { icoords[0] = ix; coords = Rect_coords(icoords,wave); comp = Rect_comp(icoords,wave); state = Rect_state(icoords,wave); mesh_energy[ix].real = Energy(state); mesh_energy[ix].imag = 0.0; } break; } #endif /* defined(ONED) */ #if defined(TWOD) case 2: { int ix, iy; int xmax, ymax, mx, my, dummy; COMPLEX **mesh_energy,**mesh_vorticity,**mesh_enstrophy; Locstate lstate,rstate,bstate,tstate; float kk,kx,ky,dk; xmax = wave->rect_grid->gmax[0]; ymax = wave->rect_grid->gmax[1]; if (!Powerof2(xmax,&mx,&dummy) || !Powerof2(ymax,&my,&dummy)) { screen("fft_energy_spectral() cannot analyze " "mesh not power of 2\n"); screen("xmax = %d ymax = %d\n",xmax,ymax); return FUNCTION_FAILED; } bi_array(&mesh_energy,xmax,ymax,sizeof(COMPLEX)); bi_array(&mesh_vorticity,xmax,ymax,sizeof(COMPLEX)); fprintf(energy_file,"zone i=%d, j=%d\n",xmax,ymax); fprintf(vorticity_file,"zone i=%d, j=%d\n",xmax,ymax); fprintf(dens_file,"zone i=%d, j=%d\n",xmax,ymax); fprintf(pres_file,"zone i=%d, j=%d\n",xmax,ymax); fprintf(enstrophy_file,"zone i=%d, j=%d\n",xmax,ymax); for (iy = 0; iy < ymax; ++iy) { for (ix = 0; ix < xmax; ++ix) { icoords[0] = ix; icoords[1] = iy; coords = Rect_coords(icoords,wave); comp = Rect_comp(icoords,wave); state = Rect_state(icoords,wave); mesh_energy[ix][iy].real = kinetic_energy(state); mesh_energy[ix][iy].imag = 0.0; if (ix != 0) icoords[0] = ix - 1; else icoords[0] = ix; lstate = Rect_state(icoords,wave); if (ix != xmax-1) icoords[0] = ix + 1; else icoords[0] = ix; rstate = Rect_state(icoords,wave); icoords[0] = ix; if (iy != 0) icoords[1] = iy - 1; else icoords[1] = iy; bstate = Rect_state(icoords,wave); if (iy != ymax-1) icoords[1] = iy + 1; else icoords[1] = iy; tstate = Rect_state(icoords,wave); mesh_vorticity[ix][iy].real = (Mom(rstate)[1]/Dens(rstate) - Mom(lstate)[1]/Dens(lstate))/h[0] - (Mom(tstate)[0]/Dens(tstate) - Mom(bstate)[0]/Dens(bstate))/h[1]; mesh_vorticity[ix][iy].imag = 0.0; fprintf(energy_file,"%lf\n",kinetic_energy(state)); fprintf(vorticity_file,"%lf\n",mesh_vorticity[ix][iy].real); fprintf(enstrophy_file,"%lf\n", sqr(mesh_vorticity[ix][iy].real)); fprintf(dens_file,"%lf\n",Dens(state)); fprintf(pres_file,"%lf\n",pressure(state)); } } fft_output2d(basename,"energy",step,wave->rect_grid, mesh_energy); fft_output2d(basename,"vorticity",step,wave->rect_grid, mesh_vorticity); free_these(2,mesh_energy,mesh_vorticity); break; } #endif /* defined(TWOD) */ #if defined(THREED) case 3: { int ix, iy, iz; int xmax, ymax, zmax; COMPLEX ***mesh_energy; xmax = wave->rect_grid->gmax[0]; ymax = wave->rect_grid->gmax[1]; zmax = wave->rect_grid->gmax[2]; tri_array(&mesh_energy,xmax,ymax,zmax,sizeof(COMPLEX)); for (iz = 0; iz < zmax; ++iz) { icoords[2] = iz; for (iy = 0; iy < ymax; ++iy) { icoords[1] = iy; for (ix = 0; ix < xmax; ++ix) { icoords[0] = ix; coords = Rect_coords(icoords,wave); comp = Rect_comp(icoords,wave); state = Rect_state(icoords,wave); mesh_energy[ix][iy][iz].real = Energy(state); mesh_energy[ix][iy][iz].imag = 0.0; } } } break; } #endif /* defined(THREED) */ } fclose(energy_file); fclose(vorticity_file); fclose(enstrophy_file); fclose(dens_file); fclose(pres_file); debug_print("fft","Left fft_energy_spectral()\n"); return FUNCTION_SUCCEEDED; } /*end fft_energy_spectral*/
/** * Format a summary of the mixture state for output. */ std::string MolalityVPSSTP::report(bool show_thermo) const { char p[800]; string s = ""; try { if (name() != "") { sprintf(p, " \n %s:\n", name().c_str()); s += p; } sprintf(p, " \n temperature %12.6g K\n", temperature()); s += p; sprintf(p, " pressure %12.6g Pa\n", pressure()); s += p; sprintf(p, " density %12.6g kg/m^3\n", density()); s += p; sprintf(p, " mean mol. weight %12.6g amu\n", meanMolecularWeight()); s += p; doublereal phi = electricPotential(); sprintf(p, " potential %12.6g V\n", phi); s += p; size_t kk = nSpecies(); vector_fp x(kk); vector_fp molal(kk); vector_fp mu(kk); vector_fp muss(kk); vector_fp acMolal(kk); vector_fp actMolal(kk); getMoleFractions(&x[0]); getMolalities(&molal[0]); getChemPotentials(&mu[0]); getStandardChemPotentials(&muss[0]); getMolalityActivityCoefficients(&acMolal[0]); getActivities(&actMolal[0]); size_t iHp = speciesIndex("H+"); if (iHp != npos) { double pH = -log(actMolal[iHp]) / log(10.0); sprintf(p, " pH %12.4g \n", pH); s += p; } if (show_thermo) { sprintf(p, " \n"); s += p; sprintf(p, " 1 kg 1 kmol\n"); s += p; sprintf(p, " ----------- ------------\n"); s += p; sprintf(p, " enthalpy %12.6g %12.4g J\n", enthalpy_mass(), enthalpy_mole()); s += p; sprintf(p, " internal energy %12.6g %12.4g J\n", intEnergy_mass(), intEnergy_mole()); s += p; sprintf(p, " entropy %12.6g %12.4g J/K\n", entropy_mass(), entropy_mole()); s += p; sprintf(p, " Gibbs function %12.6g %12.4g J\n", gibbs_mass(), gibbs_mole()); s += p; sprintf(p, " heat capacity c_p %12.6g %12.4g J/K\n", cp_mass(), cp_mole()); s += p; try { sprintf(p, " heat capacity c_v %12.6g %12.4g J/K\n", cv_mass(), cv_mole()); s += p; } catch (CanteraError& err) { err.save(); sprintf(p, " heat capacity c_v <not implemented> \n"); s += p; } } sprintf(p, " \n"); s += p; if (show_thermo) { sprintf(p, " X " " Molalities Chem.Pot. ChemPotSS ActCoeffMolal\n"); s += p; sprintf(p, " " " (J/kmol) (J/kmol) \n"); s += p; sprintf(p, " ------------- " " ------------ ------------ ------------ ------------\n"); s += p; for (size_t k = 0; k < kk; k++) { if (x[k] > SmallNumber) { sprintf(p, "%18s %12.6g %12.6g %12.6g %12.6g %12.6g\n", speciesName(k).c_str(), x[k], molal[k], mu[k], muss[k], acMolal[k]); } else { sprintf(p, "%18s %12.6g %12.6g N/A %12.6g %12.6g \n", speciesName(k).c_str(), x[k], molal[k], muss[k], acMolal[k]); } s += p; } } else { sprintf(p, " X" "Molalities\n"); s += p; sprintf(p, " -------------" " ------------\n"); s += p; for (size_t k = 0; k < kk; k++) { sprintf(p, "%18s %12.6g %12.6g\n", speciesName(k).c_str(), x[k], molal[k]); s += p; } } } catch (CanteraError& err) { err.save(); } return s; }
/* * Returns the standard concentration \f$ C^0_k \f$, which is used to normalize * the generalized concentration. */ doublereal PecosGasPhase::standardConcentration(int k) const { double p = pressure(); return p/(GasConstant * temperature()); }
doublereal MetalSHEelectrons::isothermalCompressibility() const { return 1.0/pressure(); }
/* * Returns the natural logarithm of the standard * concentration of the kth species */ doublereal PecosGasPhase::logStandardConc(int k) const { _updateThermo(); double p = pressure(); double lc = std::log (p / (GasConstant * temperature())); return lc; }
void MetalSHEelectrons::getGibbs_RT(doublereal* grt) const { getGibbs_RT_ref(grt); doublereal tmp = log(pressure() / m_p0); grt[0] += tmp; }
int main() { quan::length::m length(1); quan::time::s time(1); quan::mass::kg mass(1); quan::temperature::K temperature(1); quan::current::A current(1); quan::substance::mol subst(1); quan::intensity::cd intensity(1); quan::energy::J energy(1); quan::area::m2 area(1); quan::force::N force(1); quan::volume::m3 volume(1); quan::power::W power(1); quan::pressure::Pa pressure(1); #if (1) std::ostream & os = std::cout; #else std::ofstream os("db_dims.csv"); #endif os << "abstract quantity name ,"; for (int i = 0 ; i < 7 ; ++i){ os << ar[i] << ','; } os << "upf_pre_sym,upf_sym,offset,extent,non-prog name,upf_out_sym" << '\n'; show(os, "volume_flow" , // name "volume flow" , //out name volume/time, //dim "m3_per_s", // prog sym "m3.s-1" //upf_out_sym ); show(os, "force_per_mass" , // name "force divided by mass" , //out name force/mass, //dim "N_per_kg", // prog sym "N.kg-1" //upf_out_sym ); show(os, "energy_per_area_time" , // name "energy divided by area time" , //out name energy / (area * time), //dim "W_per_m2", // prog sym "W.m-2" //upf_out_sym ); show(os, "force_per_length" , // name "force divided by length" , //out name force / length, //dim "N_per_m", // prog sym "N.m-1" //upf_out_sym ); show(os, "energy_per_volume" , // name "energy divided by volume" , //out name energy / volume, //dim "J_per_m3", // prog sym "J.m-3" //upf_out_sym ); show(os, "energy_per_mass" , // name "energy divided by mass" , //out name energy / mass, //dim "J_per_kg", // prog sym "J.kg-1" //upf_out_sym ); show(os, "heat_transfer_coefficient" , // name "heat transfer coefficient" , //out name power / (area * temperature), //dim "W_per_m2_K", // prog sym "W.m-2.K-1" //upf_out_sym ); show(os, "heat_density" , // name "heat density" , //out name energy / area, //dim "J_per_m2", // prog sym "J.m-2" //upf_out_sym ); show(os, "heat_flow_density" , // name "heat flow density" , //out name power / area, //dim "W_per_m2", // prog sym "W.m-2" //upf_out_sym ); show(os, "volume_per_energy" , // name "volume divided by energy" , //out name volume / energy, //dim "m3_per_J", // prog sym "m3.J-1" //upf_out_sym ); show(os, "fuel_consumption" , // name "fuel consumption" , //out name length / volume, //dim "m_per_m3", // prog sym "m.m-3" //upf_out_sym ); show(os, "entropy" , // name "entropy" , //out name energy / temperature, //dim "J_per_K", // prog sym "J.K-1" //upf_out_sym ); show(os, "heat_flow" , // name "heat flow" , //out name power, //dim "W", // prog sym "W" //upf_out_sym ); show(os, "specific_entropy" , // name "specific entropy" , //out name energy / ( mass * temperature), //dim "J_per_kg_K", // prog sym "J.kg-1.K-1" //upf_out_sym ); ///////////WRONG////////////////// show(os, "thermal_conductivity" , // name "thermal conductivity" , //out name //////////////// power / ( length * temperature), //dim "W_per_m_K", // prog sym "W.m-1.K-1" //upf_out_sym ); //////////////////// show(os, "thermal_diffusivity" , // name "thermal diffusivity" , //out name area / time, //dim "m2_per_s", // prog sym "m2.s-1" //upf_out_sym ); show(os, "thermal_insulance" , // name "thermal insulance" , //out name area * temperature / power, //dim "m2_K_per_W", // prog sym "m2.K.W-1" //upf_out_sym ); show(os, "thermal_resistance" , // name "thermal resistance" , //out name temperature / power, //dim "K_per_W", // prog sym "K.W-1" //upf_out_sym ); show(os, "thermal_resistivity" , // name "thermal resistivity" , //out name (length * temperature) / power, //dim "m_K_per_W", // prog sym "m.K.W-1" //upf_out_sym ); // in fact are 3 types of permeability show(os, "permeability" , // name "permeability" , //out name mass /( pressure * time * area), //dim "g_per_Pa_s_m2", // prog sym "g.Pa-1.s-1.m-2", //upf_out_sym, "null",3 ); }