Skip to content

Commit

Permalink
Fix some schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
ianhbell committed Sep 6, 2023
1 parent 75fe763 commit 632c192
Show file tree
Hide file tree
Showing 2 changed files with 227 additions and 66 deletions.
81 changes: 51 additions & 30 deletions notebooks/Schema Builder.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"id": "c164c507",
"metadata": {},
"outputs": [],
Expand All @@ -17,7 +17,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"id": "e070d74d",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -61,7 +61,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"id": "3f9f0437",
"metadata": {},
"outputs": [],
Expand All @@ -73,6 +73,7 @@
" Tc: float = Field(alias=\"Tc / K\")\n",
" epsAB: float = Field(alias=\"epsABi / J/mol\")\n",
" betaAB: float = Field(alias=\"betaABi\")\n",
" class_: str = Field(alias=\"class\")\n",
" \n",
"class CPACubicEnum(str, Enum):\n",
" PR = \"PR\"\n",
Expand All @@ -81,12 +82,13 @@
"class CPA(NoExtraBaseModel):\n",
" cubic: CPACubicEnum\n",
" pures: List[CPAPure]\n",
" R: float = Field(alias=\"R_gas / J/mol/K\")"
" R: float = Field(alias=\"R_gas / J/mol/K\")\n",
" "
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"id": "6b0aee39",
"metadata": {},
"outputs": [],
Expand All @@ -101,7 +103,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"id": "ddc3c746",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -133,7 +135,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"id": "b56a28b5",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -226,7 +228,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"id": "41fd7f5b",
"metadata": {},
"outputs": [],
Expand All @@ -239,6 +241,7 @@
" rhomolar_crit: float = Field(alias=\"rhomolar_crit / mol/m^3\", annotation=\"The critical density\")\n",
" \n",
"class ECSHuberEly1994Fluid(NoExtraBaseModel):\n",
" name: Optional[str] = Field(default=None, annotation=\"The name of the fluid, could be an absolute path to the .json of a multifluid EOS\")\n",
" acentric: float = Field(annotation=\"The acentric factor\")\n",
" Z_crit: float = Field(annotation=\"The critical compressibility factor; Z = p/(rho*R*T)\")\n",
" T_crit: float = Field(alias=\"T_crit / K\", annotation=\"The critical temperature\")\n",
Expand All @@ -253,7 +256,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"id": "faebd855",
"metadata": {},
"outputs": [],
Expand All @@ -264,10 +267,10 @@
" sigma_Angstrom: float\n",
" epsilon_over_k: float\n",
" BibTeXKey: str\n",
" mustar2: Optional[float] = Field(alias='(mu^*)^2', annotation=\"The reduced dipole moment squared, as defined by Gross and co-workers. Watch out for missing factor of Coulomb's constant\")\n",
" nmu: Optional[float] = Field(annotation=\"The number of dipole moments\")\n",
" Qstar2: Optional[float] = Field(alias='(Q^*)^2', annotation=\"The reduced quadrupolar moment squared, as defined by Gross and co-workers. Watch out for missing factor of Coulomb's constant\")\n",
" nQ: Optional[float] = Field(annotation=\"The number of quadrupolar moments\")\n",
" mustar2: Optional[float] = Field(alias='(mu^*)^2', default=None, annotation=\"The reduced dipole moment squared, as defined by Gross and co-workers. Watch out for missing factor of Coulomb's constant\")\n",
" nmu: Optional[float] = Field(default=None, annotation=\"The number of dipole moments\")\n",
" Qstar2: Optional[float] = Field(default=None, alias='(Q^*)^2', annotation=\"The reduced quadrupolar moment squared, as defined by Gross and co-workers. Watch out for missing factor of Coulomb's constant\")\n",
" nQ: Optional[float] = Field(default=None, annotation=\"The number of quadrupolar moments\")\n",
" \n",
"class BasePCSAFT(NoExtraBaseModel):\n",
" kmat: Optional[List[List[float]]] = Field(default=None, annotation=\"The NxN matrix of kij factors\")\n",
Expand All @@ -283,46 +286,64 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 9,
"id": "e83a283c",
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"SAFTVRMieWithCoeffs(kmat=None, polar_model='GrayGubbins+GubbinsTwu', SAFTVRMie_flags=None, polar_flags=None, coeffs=[SAFTVRMieCoeffsigmaAngstrom(name='R1234YF', m=1.3656, epsilon_over_k=299.424, BibTeXKey='Paricaud', lambda_r=21.7779, lambda_a=6.0, mu_Cm=None, mu_D=2.2814, Q_Cm2=None, Q_DA=1.4151, nmu=1.0, nQ=1.0, sigma_Angstrom=4.5307)])"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"class SAFTVRMieCoeff(NoExtraBaseModel):\n",
"class SAFTVRMieCoeffBase(NoExtraBaseModel):\n",
" name: str\n",
" m: float\n",
" sigma_Angstrom: float\n",
" epsilon_over_k: float\n",
" BibTeXKey: str\n",
" lambda_r: float\n",
" lambda_a: float\n",
" \n",
" # Polar things\n",
" mu_Cm: Optional[float] = Field(annotation=\"The dipole moment, in Debye\")\n",
" mu_D: Optional[float] = Field(annotation=\"The dipole moment, in C*m\")\n",
" Q_Cm: Optional[float] = Field(annotation=\"The quadrupolar moment, in Debye\")\n",
" Q_D: Optional[float] = Field(annotation=\"The quadrupolar moment, in C*m\")\n",
" nmu: Optional[float] = Field(annotation=\"The number of dipole moments, consider it a weighting parameter\")\n",
" nQ: Optional[float] = Field(annotation=\"The number of quadrupolar moments, consider it a weighting parameter\")\n",
" mu_Cm: Optional[float] = Field(default=None, annotation=\"The dipole moment, in Debye\")\n",
" mu_D: Optional[float] = Field(default=None, annotation=\"The dipole moment, in C*m\")\n",
" Q_Cm2: Optional[float] = Field(default=None, annotation=\"The quadrupolar moment, in Debye\")\n",
" Q_DA: Optional[float] = Field(default=None, annotation=\"The quadrupolar moment, in C*m\")\n",
" nmu: Optional[float] = Field(default=None, annotation=\"The number of dipole moments, consider it a weighting parameter\")\n",
" nQ: Optional[float] = Field(default=None, annotation=\"The number of quadrupolar moments, consider it a weighting parameter\")\n",
" \n",
"class SAFTVRMieCoeffsigmaAngstrom(SAFTVRMieCoeffBase):\n",
" sigma_Angstrom: float\n",
"\n",
"class SAFTVRMieCoeffsigmaMeter(SAFTVRMieCoeffBase):\n",
" sigma_m: float\n",
" \n",
"class BaseSAFTVRMie(NoExtraBaseModel):\n",
" kmat: Optional[List[List[float]]] = Field(default=None, annotation=\"The NxN matrix of kij factors\")\n",
" polar_model: Optional[str]\n",
" SAFTVRMie_flags: Optional[Dict]\n",
" polar_flags: Optional[Dict]\n",
" polar_model: Optional[str] = None\n",
" SAFTVRMie_flags: Optional[Dict] = None\n",
" polar_flags: Optional[Dict] = None\n",
" \n",
"class SAFTVRMieWithNames(BaseSAFTVRMie):\n",
" names: List[str]\n",
"\n",
"class SAFTVRMieWithCoeffs(BaseSAFTVRMie):\n",
" coeffs: Optional[List[SAFTVRMieCoeff]]\n",
" coeffs: List[Union[SAFTVRMieCoeffsigmaAngstrom,SAFTVRMieCoeffsigmaMeter]]\n",
" \n",
"SAFTVRMie = TypeAdapter(Union[SAFTVRMieWithNames, SAFTVRMieWithCoeffs])"
"SAFTVRMie = TypeAdapter(Union[SAFTVRMieWithNames, SAFTVRMieWithCoeffs])\n",
"# SAFTVRMieWithCoeffs.validate({\"coeffs\":[{\"BibTeXKey\":\"me\",\"epsilon_over_k\":100,\"lambda_a\":6,\"lambda_r\": 12,\"m\":1.0,\"name\":\"Stockmayer126\",\"sigma_m\":3e-10}]})\n",
"SAFTVRMie.validate_python({\"coeffs\":[{\"BibTeXKey\":\"Paricaud\",\"Q_DA\":1.4151,\"epsilon_over_k\":299.424, \"lambda_a\":6.0,\"lambda_r\":21.7779,\"m\":1.3656,\"mu_D\":2.2814,\"nQ\":1.0,\"name\":\"R1234YF\",\"nmu\":1.0,\"sigma_Angstrom\":4.5307}],\"polar_model\":\"GrayGubbins+GubbinsTwu\"})"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 10,
"id": "3a69ada4",
"metadata": {},
"outputs": [],
Expand All @@ -331,7 +352,7 @@
" \n",
"examples = [\n",
" {\"kind\": \"vdW1\", \"model\":{\"a\": 1.0, \"b\": 2.0}},\n",
" {\"kind\": \"GenericCubic\", \"model\": {\"type\": \"PR\", \"Tcrit / K\": [190], \"pcrit / Pa\": [3.5e6], \"acentric\": [0.11], \"alpha\": [{\"type\": \"Twu\", \"c\":[1,2,3]}]}}\n",
" {\"kind\": \"GenericCubic\", \"model\": {\"type\": \"PR\", \"Tcrit / K\": [190], \"pcrit / Pa\": [3.5e6], \"acentric\": [0.11], \"alpha\": [{\"type\": \"Twu\", \"c\":[1,2,3]}]}},\n",
"]\n",
"for example in examples:\n",
" klass = locals()[example['kind']]\n",
Expand Down
Loading

0 comments on commit 632c192

Please sign in to comment.