Note
Go to the end to download the full example code or to run this example in your browser via Binder.
Materials and Media#
NB! This example demonstrates the stable HEAT_CONDUCTION path.
This example shows how to build OpenGeoSys media definitions directly
from a YAML-based Material Library using
MaterialManager
and MediaSet.
The YAML schema defines materials with:
name - unique material identifier
domains - grouped medium / phase / component property blocks
properties - sets of constitutive relations (with type and parameters)
Together with the built-in process schemas (e.g. HEAT_CONDUCTION),
these building blocks allow you to construct full Media definitions
including phases and components, and import them into an OGS project XML
via set_media().
import ogstools as ot
model_dir = ot.definitions.temp_dir("materiallib", "user-guide")
Example materials#
Materials are provided as YAML files in the built-in Material Library. For example, here are the definitions of “opalinus_clay” (solid) and “water” (fluid):
print(
(ot.definitions.MATERIALS_DIR / "opalinus.yml").read_text(encoding="utf-8")
)
print((ot.definitions.MATERIALS_DIR / "water.yml").read_text(encoding="utf-8"))
group: medium
name: opalinus_clay
domains:
- domain: medium
properties:
biot_coefficient:
- type: Constant
value: 0.6
unit: 1
bishops_effective_stress:
- type: BishopsPowerLaw
exponent: 1
unit: 1
density:
- type: Constant
value: 2600
unit: kg/m³
permeability:
- type: Constant
value: 1.e-21
unit: m²
poisson_ratio:
- type: Constant
value: 0.23
unit: 1
porosity:
- type: Constant
value: 0.15
unit: 1
storage:
- type: Constant
value: 2e-10
unit: kg/(m²Pa)
reference_temperature:
- type: Constant
value: 293.15
unit: K
saturation:
- type: SaturationVanGenuchten
exponent: 0.2
p_b: 48000000
residual_gas_saturation: 0.01
residual_liquid_saturation: 0.01
specific_heat_capacity:
- type: Constant
value: 995
unit: J/(kg·K)
thermal_conductivity:
- type: SaturationWeightedThermalConductivity
mean_type: arithmetic_squareroot
dry_thermal_conductivity: 1.36
wet_thermal_conductivity: 1.7
unit: W/(m·K)
- type: EffectiveThermalConductivityPorosityMixing
unit: W/(m·K)
- type: Constant
value: 1.7
unit: W/(m·K)
thermal_expansivity:
- type: Constant
value: 1.7e-5
unit: 1/K
thermal_longitudinal_dispersivity:
- type: Constant
value: 0
unit: m
thermal_transversal_dispersivity:
- type: Constant
value: 0
unit: m
tortuosity:
- type: Constant
value: 1
unit: 1
youngs_modulus:
- type: Constant
value: 6500000000
unit: Pa
relative_permeability:
- type: RelativePermeabilityVanGenuchten
residual_liquid_saturation: 0.01
residual_gas_saturation: 0.01
exponent: 0.2
minimum_relative_permeability_liquid: 1e-12
unit: 1
relative_permeability_nonwetting_phase:
- type: RelativePermeabilityNonWettingPhaseVanGenuchtenMualem
residual_liquid_saturation: 0.01
residual_gas_saturation: 0.01
exponent: 0.2
min_relative_permeability: 1e-5
unit: 1
- domain: phase
properties:
density:
- type: Constant
value: 2600
unit: kg/m³
specific_heat_capacity:
- type: Constant
value: 995
unit: J/(kg·K)
thermal_conductivity:
- type: Constant
value: 1.7
unit: W/(m·K)
thermal_expansivity:
- type: Constant
value: 1.7e-5
unit: 1/K
storage:
- type: Constant
value: 2e-10
unit: kg/(m²Pa)
name: water
group: liquid
type: phase
domains:
- domain: phase
properties:
molar_mass:
- type: Constant
value: 0.018016
unit: kg/mol
source: "CODATA 2018 recommended values"
specific_heat_capacity:
- type: Constant
value: 4187
unit: J/(kg·K)
source: "CRC Handbook of Chemistry and Physics"
thermal_conductivity:
- type: Constant
value: 0.6
unit: W/(m·K)
source: "CRC Handbook of Chemistry and Physics"
density:
- type: Constant
value: 1000
unit: kg/m³
source: "at 4 °C, standard value"
- type: Linear
reference_value: 1000
independent_variables:
concentration:
reference_condition: 0.0
slope: 2.0e-6
temperature:
reference_condition: 293.15
slope: 1.5e-5
source: "CRC Handbook of Chemistry and Physics"
- type: WaterDensityIAPWSIF97Region1
unit: kg/m³
viscosity:
- type: Constant
value: 1.0e-3
unit: Pa·s
source: "at 20 °C, standard value"
vapour_pressure:
- type: ClausiusClapeyron
triple_temperature: 273.16
triple_pressure: 611.66
critical_temperature: 647.096
critical_pressure: 22.064e6
reference_temperature: 373.15
reference_pressure: 101325
source: "IAPWS, 1995 formulation"
diffusion:
- type: Constant
value: 1.0e-9
unit: m²/s
source: "typical value for water in porous media"
specific_latent_heat:
- type: Constant
value: 2268000.0
unit: J/kg
source: "at 100 °C, standard value"
- domain: component
properties:
molar_mass:
- type: Constant
value: 0.018016
unit: kg/mol
source: "CODATA 2018 recommended values"
specific_heat_capacity:
- type: Constant
value: 4187
unit: J/(kg·K)
source: "CRC Handbook of Chemistry and Physics"
thermal_conductivity:
- type: Constant
value: 0.6
unit: W/(m·K)
source: "CRC Handbook of Chemistry and Physics"
density:
- type: Constant
value: 1000
unit: kg/m³
source: "at 4 °C, standard value"
- type: Linear
reference_value: 1000
independent_variables:
concentration:
reference_condition: 0.0
slope: 2.0e-6
temperature:
reference_condition: 293.15
slope: 1.5e-5
source: "CRC Handbook of Chemistry and Physics"
- type: WaterDensityIAPWSIF97Region1
unit: kg/m³
viscosity:
- type: Constant
value: 1.0e-3
unit: Pa·s
source: "at 20 °C, standard value"
vapour_pressure:
- type: ClausiusClapeyron
triple_temperature: 273.16
triple_pressure: 611.66
critical_temperature: 647.096
critical_pressure: 22.064e6
reference_temperature: 373.15
reference_pressure: 101325
source: "IAPWS, 1995 formulation"
diffusion:
- type: Constant
value: 1.0e-9
unit: m²/s
source: "typical value for water in porous media"
specific_latent_heat:
- type: Constant
value: 2268000.0
unit: J/kg
source: "at 100 °C, standard value"
Media creation#
We build a MaterialManager from the built-in library, filter it with a schema, and construct a MediaSet object.
subdomain: the subdomain name (string, one per entry)material: must match thenamein the YAML filematerial_ids: list of integers corresponding to the MatIDs in the mesh (allows grouping several mesh regions under one subdomain name)
db = ot.MaterialManager()
subdomains = [
{
"subdomain": "host_rock",
"material": "opalinus_clay",
"material_ids": [0, 1, 2, 3, 4],
}
]
filtered = db.filter(
process="HEAT_CONDUCTION", subdomains=subdomains, fluids={}
)
media = ot.MediaSet(filtered)
Export to OGS Project XML#
The MediaSet is imported into an OGS Project instance
via Project.set_media().
prj = ot.Project()
prj.set_media(media)
xml_file = model_dir / "material_test.prj"
prj.write_input(xml_file)
print(xml_file.read_text())
<?xml version='1.0' encoding='ISO-8859-1'?>
<OpenGeoSysProject>
<mesh/>
<processes>
<process/>
</processes>
<time_loop>
<processes/>
</time_loop>
<parameters/>
<process_variables/>
<nonlinear_solvers/>
<linear_solvers/>
<media>
<medium id="0">
<properties>
<property>
<name>density</name>
<type>Constant</type>
<value>2600</value>
</property>
<property>
<name>specific_heat_capacity</name>
<type>Constant</type>
<value>995</value>
</property>
<property>
<name>thermal_conductivity</name>
<type>SaturationWeightedThermalConductivity</type>
<mean_type>arithmetic_squareroot</mean_type>
<dry_thermal_conductivity>1.36</dry_thermal_conductivity>
<wet_thermal_conductivity>1.7</wet_thermal_conductivity>
</property>
<property>
<name>thermal_conductivity</name>
<type>EffectiveThermalConductivityPorosityMixing</type>
</property>
<property>
<name>thermal_conductivity</name>
<type>Constant</type>
<value>1.7</value>
</property>
</properties>
</medium>
<medium id="1">
<properties>
<property>
<name>density</name>
<type>Constant</type>
<value>2600</value>
</property>
<property>
<name>specific_heat_capacity</name>
<type>Constant</type>
<value>995</value>
</property>
<property>
<name>thermal_conductivity</name>
<type>SaturationWeightedThermalConductivity</type>
<mean_type>arithmetic_squareroot</mean_type>
<dry_thermal_conductivity>1.36</dry_thermal_conductivity>
<wet_thermal_conductivity>1.7</wet_thermal_conductivity>
</property>
<property>
<name>thermal_conductivity</name>
<type>EffectiveThermalConductivityPorosityMixing</type>
</property>
<property>
<name>thermal_conductivity</name>
<type>Constant</type>
<value>1.7</value>
</property>
</properties>
</medium>
<medium id="2">
<properties>
<property>
<name>density</name>
<type>Constant</type>
<value>2600</value>
</property>
<property>
<name>specific_heat_capacity</name>
<type>Constant</type>
<value>995</value>
</property>
<property>
<name>thermal_conductivity</name>
<type>SaturationWeightedThermalConductivity</type>
<mean_type>arithmetic_squareroot</mean_type>
<dry_thermal_conductivity>1.36</dry_thermal_conductivity>
<wet_thermal_conductivity>1.7</wet_thermal_conductivity>
</property>
<property>
<name>thermal_conductivity</name>
<type>EffectiveThermalConductivityPorosityMixing</type>
</property>
<property>
<name>thermal_conductivity</name>
<type>Constant</type>
<value>1.7</value>
</property>
</properties>
</medium>
<medium id="3">
<properties>
<property>
<name>density</name>
<type>Constant</type>
<value>2600</value>
</property>
<property>
<name>specific_heat_capacity</name>
<type>Constant</type>
<value>995</value>
</property>
<property>
<name>thermal_conductivity</name>
<type>SaturationWeightedThermalConductivity</type>
<mean_type>arithmetic_squareroot</mean_type>
<dry_thermal_conductivity>1.36</dry_thermal_conductivity>
<wet_thermal_conductivity>1.7</wet_thermal_conductivity>
</property>
<property>
<name>thermal_conductivity</name>
<type>EffectiveThermalConductivityPorosityMixing</type>
</property>
<property>
<name>thermal_conductivity</name>
<type>Constant</type>
<value>1.7</value>
</property>
</properties>
</medium>
<medium id="4">
<properties>
<property>
<name>density</name>
<type>Constant</type>
<value>2600</value>
</property>
<property>
<name>specific_heat_capacity</name>
<type>Constant</type>
<value>995</value>
</property>
<property>
<name>thermal_conductivity</name>
<type>SaturationWeightedThermalConductivity</type>
<mean_type>arithmetic_squareroot</mean_type>
<dry_thermal_conductivity>1.36</dry_thermal_conductivity>
<wet_thermal_conductivity>1.7</wet_thermal_conductivity>
</property>
<property>
<name>thermal_conductivity</name>
<type>EffectiveThermalConductivityPorosityMixing</type>
</property>
<property>
<name>thermal_conductivity</name>
<type>Constant</type>
<value>1.7</value>
</property>
</properties>
</medium>
</media>
</OpenGeoSysProject>
Total running time of the script: (0 minutes 0.024 seconds)