TERRA
Documentation for TERRA.
TERRA.ApiLayoutTERRA.AxialChainProfileTERRA.AxialMarchingConfigTERRA.ChainCellResultTERRA.ChainMetadataTERRA.ChainProfileInletTERRA.ChainProfileInletCompositionTERRA.ChainSimulationResultTERRA.ChainWallProfileTERRA.ConfigTERRA.ModelConfigTERRA.NativeRampLimiterTERRA.NativeRampLimiterTERRA.NumericsConfigTERRA.ODESolverConfigTERRA.PhysicsConfigTERRA.ProcessConfigTERRA.ReactorCompositionTERRA.ReactorConfigTERRA.ReactorFrameTERRA.ReactorResultTERRA.ReactorStateCacheTERRA.ReactorThermalStateTERRA.ResidenceTimeConfigTERRA.RuntimeConfigTERRA.SourceTermsConfigTERRA.SpaceConfigTERRA.SpeciesWallModelTERRA.TimeConfigTERRA.WallLossConfigTERRA._solve_terra_0d_internalTERRA.calculate_electron_electronic_energy_wrapperTERRA.calculate_rhs_api_isothermal_teex_wrapper!TERRA.calculate_rhs_api_wrapper!TERRA.calculate_sources_wrapperTERRA.calculate_temperatures_wrapperTERRA.calculate_total_energy_wrapperTERRA.calculate_vibrational_energy_wrapperTERRA.calculate_vibrational_temperature_wrapperTERRA.close_api_output_files_wrapperTERRA.close_terra_libraryTERRA.compute_mixture_pressureTERRA.convert_config_unitsTERRA.convert_density_cgs_to_siTERRA.convert_density_si_to_cgsTERRA.convert_energy_density_cgs_to_siTERRA.convert_energy_density_si_to_cgsTERRA.convert_number_density_cgs_to_siTERRA.convert_number_density_si_to_cgsTERRA.convert_pressure_cgs_to_siTERRA.convert_pressure_si_to_cgsTERRA.convert_sources_cgs_to_siTERRA.convert_state_cgs_to_siTERRA.convert_state_si_to_cgsTERRA.create_species_mappingTERRA.energy_from_enthalpy_isothermal_teex_wrapperTERRA.enthalpy_from_energyTERRA.finalize_api_wrapperTERRA.finalize_terraTERRA.generate_input_filesTERRA.generate_prob_setup_fileTERRA.generate_sources_setup_fileTERRA.generate_tau_scaling_fileTERRA.get_api_layoutTERRA.get_api_layout_wrapperTERRA.get_max_number_of_atomic_electronic_states_wrapperTERRA.get_max_number_of_molecular_electronic_states_wrapperTERRA.get_max_number_of_species_wrapperTERRA.get_max_vibrational_quantum_number_wrapperTERRA.get_molecular_weightsTERRA.get_number_of_active_species_wrapperTERRA.get_number_of_dimensions_wrapperTERRA.get_runtime_flagsTERRA.get_species_gas_constants_wrapperTERRA.get_species_names_wrapperTERRA.get_terra_lib_pathTERRA.has_electronic_sts_wrapperTERRA.has_vibrational_sts_wrapperTERRA.initialize_api_wrapperTERRA.initialize_terraTERRA.is_api_initialized_wrapperTERRA.is_terra_initializedTERRA.is_terra_loadedTERRA.load_chain_profileTERRA.load_results_chainTERRA.load_terra_library!TERRA.load_terra_library!TERRA.mass_densities_to_mole_fractionsTERRA.mole_fractions_to_mass_densitiesTERRA.native_ramp_callbackTERRA.native_ramp_conditionTERRA.native_ramp_initializeTERRA.nitrogen_10ev_configTERRA.nitrogen_10ev_exampleTERRA.open_api_output_files_wrapperTERRA.pack_state_vectorTERRA.pack_state_vector!TERRA.resolve_terra_library_pathTERRA.save_resultsTERRA.save_resultsTERRA.set_api_finalize_mpi_wrapperTERRA.set_electronic_boltzmann_wrapperTERRA.set_vibrational_boltzmann_wrapperTERRA.set_wrapper_debug!TERRA.solve_terra_chain_steadyTERRA.solve_terra_chain_steadyTERRA.terra_ode_system!TERRA.unpack_state_vectorTERRA.validate_array_dimensionsTERRA.validate_axial_chain_profileTERRA.validate_axial_marching_configTERRA.validate_config_against_terraTERRA.validate_resultsTERRA.validate_species_against_terra_databaseTERRA.validate_species_dataTERRA.validate_species_in_databaseTERRA.with_case_pathTERRA.with_runtimeTERRA.with_timeTERRA.write_api_outputs_wrapper
TERRA.ApiLayout — Type
Compact API layout information for the Fortran rhs_api / calculate_rhs_api state vectors.
This describes the compact ordering used internally by TERRA: [rho_vib_states, rho_elec_states, rho_species, rho_u..., rho_etot, rho_eeex?, rho_erot?, rho_evib?].
TERRA.AxialChainProfile — Type
Normalized axial chain profile used by the TERRA chain-of-CSTR interface.
Fields
z_m::Vector{Float64}: Axial coordinate points (m), strictly increasingdx_m::Vector{Float64}: Point-aligned control-volume lengths (m), strictly positivete_K::Vector{Float64}: Electron temperature profile (K), strictly positivespecies_u_m_s::Dict{String, Vector{Float64}}: Per-species convective velocities (m/s), strictly positivewall_profile::Union{Nothing, ChainWallProfile}: Optional validated wall-profile inputs for wall-loss source termsinlet::ChainProfileInlet: Self-contained segment-1 inlet statediagnostics::Dict{String, Vector{Float64}}: Optional diagnostics arraysgenerator::Dict{String, Any}: Generator metadata from interchange artifactselection::Dict{String, Any}: Selection metadata from interchange artifactschema_version::String: Interchange schema versionsource_snapshot::Union{Nothing, Dict{String, Any}}: Optional source provenance snapshot
TERRA.AxialMarchingConfig — Type
Controls for the axial-marching chain-of-CSTR solver.
Fields
handoff_mode::Symbol: Segment handoff mode (:reinitializeor:full_state)termination_mode::Symbol: Segment termination mode (:final_timeor:steady_state)override_tt_K::Union{Nothing, Float64}: Optional translational temperature override (K)override_tv_K::Union{Nothing, Float64}: Optional vibrational temperature override (K)is_isothermal_teex::Bool: Whether chain segments enforce the profileTe(x)isothermally
TERRA.ChainCellResult — Type
Per-cell chain result, including cell-aligned profile inputs and reactor time history.
TERRA.ChainMetadata — Type
Metadata for chain-level result organization and segmentation provenance.
TERRA.ChainProfileInlet — Type
Self-contained inlet state used to initialize segment 1 of the chain solver.
TERRA.ChainProfileInletComposition — Type
Composition payload for the self-contained chain-profile inlet.
TERRA.ChainSimulationResult — Type
Results container for axial-marching chain-of-CSTR simulations.
Fields
cells::Vector{ChainCellResult}: Solved chain cells (compact retained indexing)metadata::ChainMetadata: Chain-level metadata, diagnostics, and index mappingsuccess::Bool: Overall chain success flagfailed_cell::Union{Nothing, Int}: First failing retained-cell index, if anymessage::String: Overall status message
TERRA.ChainWallProfile — Type
Normalized wall-geometry/profile inputs for chain-driven wall losses.
TERRA.Config — Type
Top-level configuration for refactored TERRA workflows.
TERRA.ModelConfig — Type
Physics/process model configuration.
TERRA.NativeRampLimiter — Type
Integrate the 0D system over time using the Fortran rhs_api layout.
This uses terra_ode_system! and constructs a y vector that matches the ordering returned by get_api_layout().
Notes:
- Vibrational STS is not yet supported in this wrapper (vibrational mode energy is supported).
- For isothermal Teex cases, the stored energy slot in
uisrho_rem(legacy semantics), and the workingypassed to Fortran is reconstructed each call. - Wrapper-managed additive source terms are prepared from
config.sourcesor an explicitsourcesoverride.
TERRA.NativeRampLimiter — Method
Apply the native TERRA ramp limiter update to the integrator.
Arguments
integrator: DifferentialEquations.jl integrator being stepped
Returns
Nothing
TERRA.NumericsConfig — Type
Solver and discretization controls for the wrapper runtime.
TERRA.ODESolverConfig — Type
ODE-solver controls managed by the Julia wrapper.
TERRA.PhysicsConfig — Type
Physics modeling configuration for TERRA simulation.
Fields
bbh_model::Int: Bound-bound heavy particle modelesc_model::Int: Escape modelar_et_model::Int: Ar-ET modeleex_noneq::Int: Electron-electronic nonequilibrium flagev_relax_set::Int: Electron-vibrational relaxation setet_relax_set::Int: Electron-translational relaxation setradiation_length::Float64: Radiation length scale (cm)get_electron_density_by_charge_balance::Bool: Electron density by charge balancemin_sts_frac::Float64: Minimum state-to-state fractionis_isothermal_teex::Bool: Isothermal electron-electronic flagenergy_loss_per_eii::Float64: Average electron energy loss per EII event (× E_ion)
TERRA.ProcessConfig — Type
Process flags configuration for TERRA simulation.
Fields
consider_elec_bbe::Int: Consider electron bound-bound excitationconsider_elec_bfe::Int: Consider electron bound-free excitationconsider_elec_bbh::Int: Consider electron bound-bound heavyconsider_elec_bfh::Int: Consider electron bound-free heavyconsider_rad::Int: Consider radiationconsider_rdr::Int: Consider RDRconsider_chem::Int: Consider chemistry
TERRA.ReactorComposition — Type
Reactor composition inputs for a simulation case.
Fields
species::Vector{String}: Species namesmole_fractions::Vector{Float64}: Species mole fractions (must sum to 1)total_number_density::Float64: Total number density
TERRA.ReactorConfig — Type
Combined reactor-state configuration.
TERRA.ReactorFrame — Type
Time-frame result for a single reactor solve.
Fields
t::Float64: Frame timestampspecies_densities::Vector{Float64}: Species mass densities at this frametemperatures::NamedTuple: Temperature state at this frametotal_energy::Float64: Total energy density at this framesource_terms::Union{NamedTuple, Nothing}: Optional source-term snapshotdiagnostics::Dict{String, Any}: Optional frame-level diagnostics
TERRA.ReactorResult — Type
Time-history container for one reactor (one chain cell).
Fields
t::Vector{Float64}: Saved timesframes::Vector{ReactorFrame}: Saved per-time reactor framessuccess::Bool: Reactor success flagmessage::String: Reactor status messagesource_terms::Union{NamedTuple, Nothing}: Optional source history payloadmetadata::Dict{String, Any}: Optional reactor metadata
Notes
- Supports HallThruster-like slicing:
reactor[i]returns a one-frameReactorResult.
TERRA.ReactorStateCache — Type
Convert nested Config to initial state vectors for TERRA.
TERRA.ReactorThermalState — Type
Thermal state for the reactor.
Fields
Tt::Float64: Translational temperature (K)Tv::Float64: Vibrational temperature (K)Tee::Float64: Electron-electronic temperature (K)Te::Float64: Electron temperature (K)
TERRA.ResidenceTimeConfig — Type
Residence-time (CSTR / flow-through) model controls.
TERRA.RuntimeConfig — Type
Runtime and I/O configuration controls.
TERRA.SourceTermsConfig — Type
Wrapper-managed additive source-term configuration.
TERRA.SpaceConfig — Type
Spatial-discretization metadata.
TERRA.SpeciesWallModel — Type
Per-species wall-interaction closure for wrapper-managed wall losses.
TERRA.TimeConfig — Type
Numerical time-integration controls.
Fields
dt::Float64: Time step (seconds)dt_output::Float64: Native-output time step (seconds)duration::Float64: Final time (seconds)nstep::Int: Maximum number of time stepsmethod::Int: Integration method (0=forward Euler, 1=high order explicit, 2=implicit)
TERRA.WallLossConfig — Type
Wrapper-managed wall-loss configuration.
TERRA._solve_terra_0d_internal — Method
_solve_terra_0d_internal(
config;
sources,
wall_inputs,
state_cache
)
Solve a 0D TERRA simulation.
This is the main high-level interface for running TERRA simulations. It handles all the complexity of data conversion, Fortran interfacing, and result processing.
Arguments
config::Config: Configuration for the simulation
Returns
ReactorResult: Results of the simulation
Throws
ErrorExceptionif TERRA not initialized or simulation fails
TERRA.calculate_electron_electronic_energy_wrapper — Method
calculate_electron_electronic_energy_wrapper(
teex,
tvib,
rho_sp
)
Calculate electron-electronic energy from state variables.
Arguments
teex::Float64: Electron-electronic temperature (K)tvib::Float64: Vibrational temperature (K)rho_sp::Vector{Float64}: Species densities (mass/volume)
Returns
Float64: Electron-electronic energy density
Throws
ErrorException: If TERRA library is not loaded or not initializedArgumentError: If teex ≤ 0, tvib ≤ 0, or arrays are invalid
TERRA.calculate_rhs_api_isothermal_teex_wrapper! — Method
calculate_rhs_api_isothermal_teex_wrapper!(
du,
u,
teex_const;
tex
)
Compute du = rhs_api(u) for a u vector in isothermal Teex mode, using the rhs_api layout.
This calls the Fortran API routine calculate_rhs_api_isothermal_teex, which expects:
- Ordering from
get_api_layout_wrapper() u[idx_etot]stores the legacy enthalpy remainderrho_remu[idx_eeex]is treated as a dummy;du[idx_eeex]is forced to zero
Optional inputs:
tex: per-species electronic temperatures passed to the Tvib inversion (lengthnsp)
TERRA.calculate_rhs_api_wrapper! — Method
calculate_rhs_api_wrapper!(dy, y)
Compute dy = rhs_api(y) for a y vector using the rhs_api layout.
y and dy must use the ordering returned by get_api_layout_wrapper().
TERRA.calculate_sources_wrapper — Method
calculate_sources_wrapper(
rho_sp,
rho_etot;
rho_ex,
rho_vx,
rho_u,
rho_v,
rho_w,
rho_erot,
rho_eeex,
rho_evib
)
Calculate nonequilibrium source terms.
Arguments
rho_sp::Vector{Float64}: Species densities (mass/volume)rho_etot::Float64: Total energy densityrho_ex::Matrix{Float64}: Electronic state densities (optional)rho_vx::Array{Float64,3}: Vibrational state densities (optional)rho_erot::Float64: Rotational energy density (optional)rho_eeex::Float64: Electron-electronic energy density (optional)rho_evib::Float64: Vibrational energy density (optional)
Returns
- Tuple of derivative arrays corresponding to input arrays
Throws
ErrorException: If TERRA library is not loaded or not initialized
TERRA.calculate_temperatures_wrapper — Method
calculate_temperatures_wrapper(
rho_sp,
rho_etot;
rho_ex,
rho_vx,
rho_u,
rho_v,
rho_w,
rho_erot,
rho_eeex,
rho_evib
)
Calculate temperatures from thermodynamic state.
Arguments
rho_sp::Vector{Float64}: Species densitiesrho_etot::Float64: Total energy density- Additional optional energy components
Returns
- Named tuple with temperatures (tt, trot, teex, tvib, tex, tvx)
Throws
ErrorException: If TERRA library is not loaded or not initialized
TERRA.calculate_total_energy_wrapper — Method
calculate_total_energy_wrapper(
tt,
rho_sp;
rho_ex,
rho_vx,
u,
v,
w,
rho_erot,
rho_eeex,
rho_evib
)
Calculate total energy from state variables.
Arguments
tt::Float64: Translational temperature (K)rho_sp::Vector{Float64}: Species densities (mass/volume)rho_ex::Matrix{Float64}: Electronic state densities (optional)rho_vx::Array{Float64,3}: Vibrational state densities (optional)u::Float64: x-velocity component (optional)v::Float64: y-velocity component (optional)w::Float64: z-velocity component (optional)rho_erot::Float64: Rotational energy density (optional)rho_eeex::Float64: Electron-electronic energy density (optional)rho_evib::Float64: Vibrational energy density (optional)
Returns
Float64: Total energy density
Throws
ErrorException: If TERRA library is not loaded or not initialized
TERRA.calculate_vibrational_energy_wrapper — Method
calculate_vibrational_energy_wrapper(
tvib,
rho_sp;
rho_ex,
tex,
teex
)
Calculate vibrational energy from state variables.
Arguments
tvib::Float64: Vibrational temperature (K)rho_sp::Vector{Float64}: Species densities (mass/volume)rho_ex::Matrix{Float64}: Electronic state densities (optional)tex::Vector{Float64}: Electronic temperatures per species (optional)teex::Float64: Electron-electronic temperature (optional)
Returns
Float64: Vibrational energy density
Throws
ErrorException: If TERRA library is not loaded or not initialized
TERRA.calculate_vibrational_temperature_wrapper — Method
calculate_vibrational_temperature_wrapper(
rho_evib,
rho_sp;
rho_ex,
tex
)
Calculate vibrational temperature from vibrational energy density and species densities.
Arguments
rho_evib::Float64: Vibrational energy density (erg/cm^3)rho_sp::Vector{Float64}: Species mass densities (g/cm^3)rho_ex::Union{Matrix{Float64}, Nothing}: Optional electronic state densities (layout: mnex × nsp)tex::Union{Vector{Float64}, Nothing}: Optional species electronic temperatures (K)
Returns
Float64: Vibrational temperature (K)
Throws
ErrorException: If TERRA library is not loaded or not initializedArgumentError: If inputs are invalid or dimensions exceed library maxima
TERRA.close_api_output_files_wrapper — Method
close_api_output_files_wrapper()
Close the native TERRA output files opened through the API wrappers.
TERRA.close_terra_library — Method
close_terra_library()
Close the TERRA library and free resources.
TERRA.compute_mixture_pressure — Method
compute_mixture_pressure(
rho_sp,
gas_constants,
species_names,
molecular_weights,
tt,
te
)
Compute the mixture pressure using translational and electron temperatures.
Arguments
rho_sp::AbstractVector{<:Real}: Species mass densities in CGS unitsgas_constants::AbstractVector{<:Real}: Species-specific gas constantsspecies_names::AbstractVector{<:AbstractString}: Species identifiers used to detect electronsmolecular_weights::AbstractVector{<:Real}: Species molecular weightstt::Real: Translational (heavy-particle) temperaturete::Real: Electron temperature applied to electron species
Returns
Float64: Mixture pressure consistent with TERRA conventions
TERRA.convert_config_units — Method
convert_config_units(config, target_unit_system)
Convert nested Config units if needed.
Arguments
config::Config: Configuration to converttarget_unit_system::Symbol: Target unit system (:SI or :CGS)
Returns
Config: Configuration with converted units
TERRA.convert_density_cgs_to_si — Method
convert_density_cgs_to_si(rho_cgs)
Convert species densities from CGS (g/cm³) to SI (kg/m³) units.
TERRA.convert_density_si_to_cgs — Method
convert_density_si_to_cgs(rho_si)
Convert species densities from SI (kg/m³) to CGS (g/cm³) units.
TERRA.convert_energy_density_cgs_to_si — Method
convert_energy_density_cgs_to_si(energy_cgs)
Convert energy density from CGS (erg/cm³) to SI (J/m³) units.
TERRA.convert_energy_density_si_to_cgs — Method
convert_energy_density_si_to_cgs(energy_si)
Convert energy density from SI (J/m³) to CGS (erg/cm³) units.
TERRA.convert_number_density_cgs_to_si — Method
convert_number_density_cgs_to_si(n_cgs)
Convert number density from CGS (1/cm³) to SI (1/m³) units.
TERRA.convert_number_density_si_to_cgs — Method
convert_number_density_si_to_cgs(n_si)
Convert number density from SI (1/m³) to CGS (1/cm³) units.
TERRA.convert_pressure_cgs_to_si — Method
convert_pressure_cgs_to_si(pressure_cgs)
Convert pressure from CGS (dyne/cm²) to SI (Pa) units.
TERRA.convert_pressure_si_to_cgs — Method
convert_pressure_si_to_cgs(pressure_si)
Convert pressure from SI (Pa) to CGS (dyne/cm²) units.
TERRA.convert_sources_cgs_to_si — Method
convert_sources_cgs_to_si(
drho_sp_cgs,
drho_etot_cgs;
drho_erot_cgs,
drho_eeex_cgs,
drho_evib_cgs
)
Convert source terms from CGS to SI units.
Arguments
drho_sp_cgs::Vector{Float64}: Species source terms in CGS units (g/cm³/s)drho_etot_cgs::Float64: Energy source term in CGS units (erg/cm³/s)- Additional optional source terms in CGS units
Returns
- Named tuple with all source terms converted to SI units
TERRA.convert_state_cgs_to_si — Method
convert_state_cgs_to_si(
rho_sp_cgs,
rho_etot_cgs;
rho_erot_cgs,
rho_eeex_cgs,
rho_evib_cgs
)
Convert a complete state vector from CGS to SI units from TERRA output.
Arguments
rho_sp_cgs::Vector{Float64}: Species densities in CGS units (g/cm³)rho_etot_cgs::Float64: Total energy density in CGS units (erg/cm³)- Additional optional energy components in CGS units
Returns
- Named tuple with all quantities converted to SI units
TERRA.convert_state_si_to_cgs — Method
convert_state_si_to_cgs(
rho_sp_si,
rho_etot_si,
number_density_si;
rho_erot_si,
rho_eeex_si,
rho_evib_si
)
Convert a complete state vector from SI to CGS units for TERRA input.
Arguments
rho_sp_si::Vector{Float64}: Species densities in SI units (kg/m³)rho_etot_si::Float64: Total energy density in SI units (J/m³)number_density_si::Float64: Total number density in SI units (1/m³)- Additional optional energy components in SI units
Returns
- Named tuple with all quantities converted to CGS units
TERRA.create_species_mapping — Method
create_species_mapping(ht_species, terra_species)
Create species mapping between HallThruster.jl and TERRA conventions.
Arguments
ht_species::Vector{String}: Species names in HallThruster.jl formatterra_species::Vector{String}: Species names in TERRA format
Returns
- Dictionary mapping HallThruster.jl species names to TERRA species names
TERRA.energy_from_enthalpy_isothermal_teex_wrapper — Method
energy_from_enthalpy_isothermal_teex_wrapper(
rho_enth,
rho_sp,
teex_const;
rho_ex,
rho_erot,
rho_eeex,
rho_evib
)
Convert total enthalpy density to total energy density for 0D isothermal Teex cases.
This calls the Fortran API routine energy_from_enthalpy_isothermal_teex_api, which performs the closed-form enthalpy→energy inversion used by the isothermal Teex API RHS.
Returns
- Named tuple with
rho_etot,pressure, andtt(all CGS units;ttin K).
TERRA.enthalpy_from_energy — Method
enthalpy_from_energy(
rho_etot,
rho_sp,
gas_constants,
species_names,
molecular_weights,
tt,
te
)
Convert total energy density into enthalpy density using the ideal-gas closure.
Arguments
rho_etot::Float64: Total energy density (CGS units)rho_sp::AbstractVector{<:Real}: Species mass densitiesgas_constants::AbstractVector{<:Real}: Species-specific gas constantsspecies_names::AbstractVector{<:AbstractString}: Species names used to detect electronsmolecular_weights::AbstractVector{<:Real}: Species molecular weightstt::Real: Translational temperature applied to heavy specieste::Real: Electron temperature applied to electron species
Returns
Tuple{Float64, Float64}: Enthalpy density and corresponding pressure
TERRA.finalize_api_wrapper — Method
finalize_api_wrapper()
Finalize the TERRA API system and clean up resources.
TERRA.finalize_terra — Method
finalize_terra()
Finalize the TERRA system and clean up resources.
This function should be called when TERRA is no longer needed to properly clean up memory and resources.
Arguments
- None
Returns
Nothing
TERRA.generate_input_files — Function
generate_input_files(config)
generate_input_files(config, case_path)
Generate TERRA input files from configuration with proper directory structure.
This function creates the directory structure required by the Fortran wrapper:
- case_path/input/ (input files)
- case_path/output/ (output files)
- case_path/output/sources/ (source term outputs)
- case_path/output/states/ (state outputs)
Arguments
config::Config: TERRA configurationcase_path::String: Case directory path (default:config.runtime.case_path)
Returns
trueif files generated successfully
Throws
ErrorExceptionif file generation fails
TERRA.generate_prob_setup_file — Method
generate_prob_setup_file(config, filepath)
Generate prob_setup.inp file from configuration.
TERRA.generate_sources_setup_file — Method
generate_sources_setup_file(config, filepath)
Generate sources_setup.inp file from configuration.
TERRA.generate_tau_scaling_file — Method
generate_tau_scaling_file(config, filepath)
Generate tau_scaling.inp file from configuration.
TERRA.get_api_layout — Method
get_api_layout()
Query the Fortran API for the current y/dy layout.
TERRA.get_api_layout_wrapper — Method
get_api_layout_wrapper()
Get the API layout for the y/dy vectors used by the Fortran rhs_api.
This calls the Fortran get_api_layout() routine and returns sizes, flags, and species/state metadata needed to construct an ODE state in the rhs_api ordering on the Julia side.
TERRA.get_max_number_of_atomic_electronic_states_wrapper — Method
get_max_number_of_atomic_electronic_states_wrapper()
Get the maximum number of electronic states per atomic species supported by TERRA.
Returns
Int32: Maximum number of atomic electronic states
Throws
ErrorException: If TERRA library is not loaded
TERRA.get_max_number_of_molecular_electronic_states_wrapper — Method
get_max_number_of_molecular_electronic_states_wrapper()
Get the maximum number of electronic states per molecular species supported by TERRA.
Returns
Int32: Maximum number of molecular electronic states
Throws
ErrorException: If TERRA library is not loaded
TERRA.get_max_number_of_species_wrapper — Method
get_max_number_of_species_wrapper()
Get the maximum number of species supported by TERRA.
Returns
Int32: Maximum number of species
Throws
ErrorException: If TERRA library is not loaded
TERRA.get_max_vibrational_quantum_number_wrapper — Method
get_max_vibrational_quantum_number_wrapper()
Get the maximum vibrational quantum number supported by TERRA.
Returns
Int32: Maximum vibrational quantum number (mnv from Fortran parameters)
Throws
ErrorException: If TERRA library is not loaded
TERRA.get_molecular_weights — Method
get_molecular_weights(species)
Get molecular weights for common species (g/mol).
Arguments
species::Vector{String}: Species names
Returns
Vector{Float64}: Molecular weights in g/mol
TERRA.get_number_of_active_species_wrapper — Method
get_number_of_active_species_wrapper()
Get the active number of species (nsp) from TERRA.
Returns
Int32: Active species count
TERRA.get_number_of_dimensions_wrapper — Method
get_number_of_dimensions_wrapper()
Get the number of spatial dimensions (nd) from TERRA.
Returns
Int32: Number of spatial dimensions
TERRA.get_runtime_flags — Method
get_runtime_flags()
Get runtime setup flags from TERRA (for verification).
TERRA.get_species_gas_constants_wrapper — Method
get_species_gas_constants_wrapper()
Retrieve per-species gas constants from TERRA.
Values are returned in CGS units (erg/(g·K)) to maintain consistency with the rest of the wrapper.
TERRA.get_species_names_wrapper — Method
get_species_names_wrapper()
Get species names from TERRA.
Returns
Vector{String}: Array of species names
Throws
ErrorException: If TERRA library is not loaded
TERRA.get_terra_lib_path — Method
get_terra_lib_path()
Get the path to the loaded TERRA library.
Returns
String: Path to the loaded library
Throws
ErrorException: If no library is loaded
TERRA.has_electronic_sts_wrapper — Method
has_electronic_sts_wrapper()
Report whether the current TERRA setup includes electronic state-to-state data.
TERRA.has_vibrational_sts_wrapper — Method
has_vibrational_sts_wrapper()
Report whether the current TERRA setup includes vibrational state-to-state data.
TERRA.initialize_api_wrapper — Method
initialize_api_wrapper(; case_path)
Initialize the TERRA API system.
Arguments
case_path::String: Path to directory containing input/ subdirectory (default: current directory)
Returns
NamedTuple: Containsnum_speciesandnum_dimensionsas determined by TERRA from input files
Throws
ErrorException: If case_path doesn't exist, input file is missing, or Fortran call fails
TERRA.initialize_terra — Function
initialize_terra(config)
initialize_terra(config, case_path)
Initialize the TERRA system.
This function must be called before any TERRA calculations can be performed. It sets up the Fortran library, initializes internal data structures, and prepares the system for simulation. The TERRA shared library is obtained from the TERRA_LIB_PATH environment variable when it is not already loaded.
Arguments
config::Config: Configuration for initializationcase_path::String: Case directory path (optional, defaults toconfig.runtime.case_path)
Returns
trueif initialization successful
Throws
ErrorExceptionif initialization fails
TERRA.is_api_initialized_wrapper — Method
is_api_initialized_wrapper()
Return whether the TERRA Fortran API reports itself initialized.
Returns
Bool: True if Fortran side is initialized, false otherwise
TERRA.is_terra_initialized — Method
is_terra_initialized()
Check if TERRA is properly initialized.
Arguments
- None
Returns
trueif TERRA is initialized and ready for use
TERRA.is_terra_loaded — Method
is_terra_loaded()
Check if the TERRA library is currently loaded.
Returns
Bool: True if library is loaded, false otherwise
TERRA.load_chain_profile — Method
load_chain_profile(path)
Load a chain profile JSON artifact into normalized AxialChainProfile.
Arguments
path::AbstractString: Path tochain_profile_v4.json
Returns
AxialChainProfile
Throws
ArgumentErroron file, schema, or data validation failures
TERRA.load_results_chain — Method
load_results_chain(filename)
Load chain simulation results from a JSON file generated by save_results.
Arguments
filename::String: Input JSON filename
Returns
ChainSimulationResult
TERRA.load_terra_library! — Method
load_terra_library!(path)
Set the path to the TERRA shared library and load it.
Arguments
path::String: Path to the TERRA shared library file
Throws
ErrorException: If the library cannot be loaded
TERRA.load_terra_library! — Method
load_terra_library!()
Load the TERRA shared library using the TERRA_LIB_PATH environment variable.
Throws an error if the environment variable is not set or does not point to an existing file.
TERRA.mass_densities_to_mole_fractions — Method
mass_densities_to_mole_fractions(
mass_densities,
molecular_weights
)
Convert mass densities to mole fractions.
Arguments
mass_densities::Vector{Float64}: Species mass densities (g/cm³)molecular_weights::Vector{Float64}: Species molecular weights (g/mol)
Returns
- Vector of mole fractions
TERRA.mole_fractions_to_mass_densities — Method
mole_fractions_to_mass_densities(
mole_fractions,
molecular_weights,
total_number_density
)
Convert mole fractions to mass densities.
Arguments
mole_fractions::Vector{Float64}: Species mole fractionsmolecular_weights::Vector{Float64}: Species molecular weights (g/mol)total_number_density::Float64: Total number density (1/cm³)
Returns
- Vector of mass densities (g/cm³)
TERRA.native_ramp_callback — Method
native_ramp_callback(
initial_dt;
understep_ratio,
history_steps
)
Create the native TERRA step-size ramp callback.
Arguments
initial_dt: Baseline time step used after the ramp is completeunderstep_ratio: Optional ratio controlling the initial under-steppinghistory_steps: Optional number of accepted steps to maintain the ramp
Returns
DiscreteCallback: Callback implementing the ramp behaviour
TERRA.native_ramp_condition — Method
native_ramp_condition(u, t, integrator)
Condition function for the native ramp callback (always triggers).
Arguments
u: Current state vector (unused)t: Current simulation time (unused)integrator: DifferentialEquations.jl integrator (unused)
Returns
true
TERRA.native_ramp_initialize — Method
native_ramp_initialize(cb, u, t, integrator)
Initializer for the native ramp callback.
Arguments
cb: Callback instance containing the ramp limiteru: Current state vector (unused)t: Current simulation time (unused)integrator: DifferentialEquations.jl integrator instance
Returns
Nothing
TERRA.nitrogen_10ev_config — Method
nitrogen_10ev_config(; isothermal)
Create a default configuration for the 0D Nitrogen Te=10eV example.
Returns
Config: Configuration matching the example case
Throws
ErrorExceptionifTERRA_LIB_PATHis unset/invalid or if required database paths do not exist
TERRA.nitrogen_10ev_example — Function
nitrogen_10ev_example(; ...)
nitrogen_10ev_example(case_path; isothermal)
Run the 0D Nitrogen Te=10eV example case.
This function provides a convenient way to run the reference test case that matches the TERRA example in /terra/examples/0D_Nitrogen_Te_10eV. Requires the TERRA_LIB_PATH environment variable to point to the TERRA shared library.
Arguments
case_path::String: Case directory path (optional, creates temp directory if not provided)
Returns
ReactorResult: Results of the simulation
Example
results = nitrogen_10ev_example()TERRA.open_api_output_files_wrapper — Method
open_api_output_files_wrapper()
Open native TERRA Tecplot-style output files for the current API session.
Requires a successful call to initialize_api_wrapper so the case path is tracked.
TERRA.pack_state_vector! — Method
pack_state_vector!(
y,
layout,
rho_sp,
rho_etot;
rho_ex,
rho_vx,
rho_u,
rho_v,
rho_w,
rho_erot,
rho_eeex,
rho_evib
)
In-place variant of pack_state_vector.
TERRA.pack_state_vector — Method
pack_state_vector(
layout,
rho_sp,
rho_etot;
rho_ex,
rho_vx,
rho_u,
rho_v,
rho_w,
rho_erot,
rho_eeex,
rho_evib
)
Pack state components into the y vector ordering used by Fortran rhs_api.
TERRA.resolve_terra_library_path — Method
resolve_terra_library_path()
Resolve the TERRA shared library path from the TERRA_LIB_PATH environment variable.
Returns
String: Validated absolute path to the TERRA shared library
Throws
ErrorException: If the environment variable is unset or points to a missing file
TERRA.save_results — Method
save_results(results, filename)
Save chain simulation results to a JSON file.
Arguments
results::ChainSimulationResult: Chain results to savefilename::String: Output JSON filename
Returns
trueif save successful
TERRA.save_results — Method
save_results(results, filename)
Save TERRA results to file.
Arguments
results::ReactorResult: Results to savefilename::String: Output filename (CSV format)
Returns
trueif save successful
TERRA.set_api_finalize_mpi_wrapper — Method
set_api_finalize_mpi_wrapper(enable)
Control whether finalizeapi() will call MPIFinalize on the Fortran side. Default is true; tests may disable it to allow reinitialization in one process.
TERRA.set_electronic_boltzmann_wrapper — Method
set_electronic_boltzmann_wrapper(rho_sp, tex, trot, tvib)
Set electronic state densities to Boltzmann distribution.
Arguments
rho_sp::Vector{Float64}: Species densities (mass/volume)tex::Float64: Electronic temperature (K)trot::Float64: Rotational temperature (K)tvib::Float64: Vibrational temperature (K)
Returns
Matrix{Float64}: Electronic state densities in Boltzmann distribution
Throws
ErrorException: If TERRA library is not loaded or not initializedArgumentError: If temperatures ≤ 0 or arrays are invalid
TERRA.set_vibrational_boltzmann_wrapper — Method
set_vibrational_boltzmann_wrapper(rho_ex, tex, trot, tvib)
Set vibrational state densities to a Boltzmann distribution given rho_ex.
Arguments
rho_ex::Matrix{Float64}: Electronic state densities (mass/volume)tex::Float64: Electronic temperature (K)trot::Float64: Rotational temperature (K)tvib::Float64: Vibrational temperature (K)
Returns
Array{Float64,3}: Vibrational state densities (0:mnv, mmnex, mnsp)
Throws
ErrorException: If TERRA library is not loaded or not initializedArgumentError: If temperatures ≤ 0 or arrays are invalid
TERRA.set_wrapper_debug! — Method
set_wrapper_debug!(flag)
Enable or disable verbose wrapper debug logging.
TERRA.solve_terra_chain_steady — Method
solve_terra_chain_steady(config, profile_path; marching)
Load a profile from disk and solve the steady axial chain of CSTR segments.
TERRA.solve_terra_chain_steady — Method
solve_terra_chain_steady(config, profile; marching)
Solve a steady axial chain of CSTR segments using the TERRA 0D solver.
This implementation supports:
handoff_mode = :reinitializehandoff_mode = :full_statetermination_mode = :final_time
Arguments
config::Config: Base TERRA config for models, sources, solver controls, and inlet stateprofile::AxialChainProfile: Axial chain profile
Keyword Arguments
marching::AxialMarchingConfig: Axial marching controls
Returns
ChainSimulationResult
TERRA.terra_ode_system! — Method
terra_ode_system!(du, u, p, t)
ODE system that calls the Fortran rhs_api directly (via calculate_rhs_api).
Assumptions about the state u:
- Non-isothermal (
config.models.physics.is_isothermal_teex == false):umatches the Fortranrhs_apiylayout and stores total energy density atlayout.idx_etot. - Isothermal Teex (
== true):u[layout.idx_etot]stores the remainder energyrho_rem = rho_h - rho_eeex - rho_e * R_e * Teex. Therho_eeexslot is treated as a dummy (its derivative is forced to zero). The Fortran call uses a working vector withrho_eeexrecomputed from the prescribed Teex, and withrho_etotreconstructed fromrho_remby converting total enthalpy back to energy.
TERRA.unpack_state_vector — Method
unpack_state_vector(y, layout)
Unpack a compact y vector into component arrays.
This returns rho_sp for all active species (including charge-balanced electrons when enabled), plus rho_ex/rho_vx when the corresponding STS modes are active.
TERRA.validate_array_dimensions — Method
validate_array_dimensions(config)
Validate that configuration arrays match TERRA Fortran expectations.
Arguments
config::Config: Configuration to validate
Returns
trueif validation passes
Throws
ErrorExceptionif array dimensions exceed TERRA limits
TERRA.validate_axial_chain_profile — Method
validate_axial_chain_profile(profile)
Validate an AxialChainProfile against the chain-profile contract.
Arguments
profile::AxialChainProfile: Profile to validate
Returns
trueif validation passes
Throws
ArgumentErrorif the profile is invalid
TERRA.validate_axial_marching_config — Method
validate_axial_marching_config(marching)
Validate an AxialMarchingConfig for the current chain solver capabilities.
Arguments
marching::AxialMarchingConfig: Marching controls to validate
Returns
trueif validation passes
Throws
ArgumentErrorif unsupported modes are requested
TERRA.validate_config_against_terra — Method
validate_config_against_terra(config)
Validate configuration parameters against loaded TERRA library capabilities.
This function checks that the configuration is compatible with the loaded TERRA library, including array dimensions and species availability.
Arguments
config::Config: Configuration to validate
Returns
trueif validation passes
Throws
ErrorExceptionif validation fails or library not loaded
TERRA.validate_results — Method
validate_results(results)
Validate simulation results for physical consistency.
Arguments
results::ReactorResult: Simulation results to validate
Returns
trueif results pass validation,falseotherwise
TERRA.validate_species_against_terra_database — Method
validate_species_against_terra_database(config)
Validate species against TERRA database (requires loaded library).
This function uses the fortran_wrapper to query the TERRA database for available species and validates the configuration species against it.
Arguments
config::Config: Configuration to validate
Returns
trueif validation passes
Throws
ErrorExceptionif species validation fails or library not loaded
TERRA.validate_species_data — Method
validate_species_data(
species_names,
terra_species,
densities
)
Validate species data consistency between Julia and TERRA.
Arguments
species_names::Vector{String}: Species names from configurationterra_species::Vector{String}: Species names from TERRAdensities::Vector{Float64}: Species densities
Returns
trueif validation passes, throws error otherwise
TERRA.validate_species_in_database — Method
validate_species_in_database(config)
Validate that all species in configuration exist in the TERRA database.
Arguments
config::Config: Configuration to validate
Returns
trueif validation passes
Throws
ErrorExceptionif any species are not found in database
TERRA.with_case_path — Method
with_case_path(config, case_path)
Return a copy of config with an updated case path.
TERRA.with_runtime — Method
with_runtime(
config;
database_path,
case_path,
unit_system,
validate_species_against_terra,
print_source_terms,
write_native_outputs,
print_integration_output
)
Return a copy of config with an updated runtime block.
TERRA.with_time — Method
with_time(config; dt, dt_output, duration, nstep, method)
Return a copy of config with updated time-integration controls.
TERRA.write_api_outputs_wrapper — Method
write_api_outputs_wrapper(istep, time, dt, state; dist, dx)
Write a snapshot of the current API state to the native TERRA output files, using the y layout expected by rhs_api.