]> Devoid-pointer.net GitWeb - Nine-Q.git/commitdiff
Implement walkthrough equation generators for solubility V_F_KS_G
authorMichal Malý <madcatxster@devoid-pointer.net>
Wed, 7 Jan 2015 13:38:21 +0000 (14:38 +0100)
committerMichal Malý <madcatxster@devoid-pointer.net>
Wed, 7 Jan 2015 13:38:21 +0000 (14:38 +0100)
src/problem_generators/problem_generator-solubility_suite.adb
src/problem_generators/problem_generator.ads
src/problem_generators/problem_generator_syswides.ads

index d95453201552d8469cc14f74b17c969d63b25494..85e884ff016976c034a728f1bd3b1e0368ef3917 100644 (file)
@@ -3,6 +3,7 @@ with Ada.Numerics.Float_Random;
 with Ada.Numerics.Generic_Elementary_Functions;
 with Ada.Strings.Fixed;
 with Ada.Text_IO;
+with AWS.Templates;
 with Formatting_Helpers;
 
 separate(Problem_Generator)
@@ -288,7 +289,16 @@ package body Solubility_Suite is
 
   function Get_Walkthrough(Problem: in out Solubility_Problem; Walkthrough: out Walkthrough_Info.Map) return RetCode is
   begin
-    return E_NOTIMPL;
+    case Problem.Prob_Data.Option is
+      when V_FROM_G_KS =>
+       return Gen_Walkthrough_V_FROM_G_KS(Problem, Walkthrough);
+      when KS_FROM_G_V =>
+       return Gen_Walkthrough_KS_FROM_G_V(Problem, Walkthrough);
+      when C_FROM_KS_DIFFERENT_IONS =>
+       return Gen_Walkthrough_C_FROM_KS_DIFFERENT_IONS(Problem, Walkthrough);
+      when C_FROM_KS_SHARED_ION =>
+       return Gen_Walkthrough_C_FROM_KS_SHARED_ION(Problem, Walkthrough);
+    end case;
   end Get_Walkthrough;
 
   function Set_Parameters(Problem: in out Solubility_Problem; Parameters: in Parameters_Info.Map) return RetCode is
@@ -501,6 +511,168 @@ package body Solubility_Suite is
     return ((Prob_Data.M * C * GM) ** Prob_Data.M) * ((Prob_Data.N * C * GN) ** Prob_Data.N);
   end Calculate_Solubility_Product;
 
+  function Gen_Walkthrough_V_FROM_G_KS(Problem: in out Solubility_Problem; Walkthrough: out Walkthrough_Info.Map) return RetCode is
+    package MEF is new Ada.Numerics.Generic_Elementary_Functions(SS_Float);
+    package FH is new Formatting_Helpers(SS_Float);
+    use AWS.Templates;
+    use MEF;
+
+    PRP_Fixed: constant String := UB_Text_To_Fixed_String(Problem.Resource_Prefix);
+    --
+    Ks_Div_MPN: constant SS_Float := Problem.Prob_Data.V_Ks / ((Problem.Prob_Data.M ** Problem.Prob_Data.M) * (Problem.Prob_Data.N ** Problem.Prob_Data.N));
+    -- Values used in context multiple formulas
+    Diss_C: constant SS_Float := (Problem.Prob_Data.V_Ks / ((Problem.Prob_Data.M ** Problem.Prob_Data.M) * (Problem.Prob_Data.N ** Problem.Prob_Data.N))) ** (1.0 / (Problem.Prob_Data.M + Problem.Prob_Data.N));
+    DC_Int_Str: UB_Text;
+    DC_Dec_Str: UB_Text;
+    DC_Exp_Str: UB_Text;
+
+    M_Int: Integer := Integer(Problem.Prob_Data.M);
+    N_Int: Integer := Integer(Problem.Prob_Data.N);
+    Final_Trans: Translate_Set;
+    TeXCode: UB_Text;
+    Ret: RetCode;
+  begin
+    -- Init multicontext data
+    FH.Split_Integer_Decimal_Exponent_Strs(Diss_C, DECIMALS, DC_Int_Str, DC_Dec_Str, DC_Exp_Str);
+
+    -- Plug the numbers into the raw equation for dissolved concentration
+    declare
+      M_Str: String := Integer'Image(M_Int);
+      N_Str: String := Integer'Image(N_Int);
+      Ks_Int_Str: UB_Text;
+      Ks_Dec_Str: UB_Text;
+      Ks_Exp_Str: UB_Text;
+
+      Trans: Translate_Set;
+    begin
+      FH.Split_Integer_Decimal_Exponent_Strs(Problem.Prob_Data.V_Ks, DECIMALS, Ks_Int_Str, Ks_Dec_Str, Ks_Exp_Str);
+      Insert(Trans, Assoc(WT_KS_INT_KEY, Ks_Int_Str));
+      Insert(Trans, Assoc(WT_KS_DEC_KEY, Ks_Dec_Str));
+      Insert(Trans, Assoc(WT_KS_EXP_KEY, Ks_Exp_Str));
+      Insert(Trans, Assoc(WT_M_KEY, M_Str));
+      Insert(Trans, Assoc(WT_N_KEY, N_Str));
+
+      TeXCode := Parse(Filename => WT_T_PREFIX & "v_plug_numbers.ttex", Translations => Trans);
+      Ret := TeX_To_PNG(TeXCode, WT_F_V_PLUGNUMS, Problem.Resource_Prefix);
+      if Ret /= OK then
+       return Ret;
+      end if;
+      Problem.Add_Tracked_Resource(WT_F_V_PLUGNUMS & WT_F_EXTENSION);
+      Insert(Final_Trans, Assoc(WT_V_PLUG_C_RESULT_KEY, PRP_Fixed & WT_F_V_PLUGNUMS & WT_F_EXTENSION));
+    end;
+
+    -- Show the result just before root extraction
+    declare
+      MPN_Str: constant String := Integer'Image(M_Int + N_Int);
+      KDMN_Int_Str: UB_Text;
+      KDMN_Dec_Str: UB_Text;
+      KDMN_Exp_Str: UB_Text;
+
+      Trans: Translate_Set;
+    begin
+      FH.Split_Integer_Decimal_Exponent_Strs(Ks_Div_MPN, DECIMALS, KDMN_Int_Str, KDMN_Dec_Str, KDMN_Exp_Str);
+      Insert(Trans, Assoc(WT_KDMN_INT_KEY, KDMN_Int_Str));
+      Insert(Trans, Assoc(WT_KDMN_DEC_KEY, KDMN_Dec_Str));
+      Insert(Trans, Assoc(WT_KDMN_EXP_KEY, KDMN_Exp_Str));
+      Insert(Trans, Assoc(WT_MPN_KEY, MPN_Str));
+
+      TeXCode := Parse(Filename => WT_T_PREFIX & "v_pre_radex.ttex", Translations => Trans);
+      Ret := TeX_To_PNG(TeXCode, WT_F_V_PRE_RADEX, Problem.Resource_Prefix);
+      if Ret /= OK then
+       return Ret;
+      end if;
+      Problem.Add_Tracked_Resource(WT_F_V_PRE_RADEX & WT_F_EXTENSION);
+      Insert(Final_Trans, Assoc(WT_V_PRE_RADEX_RESULT_KEY, PRP_Fixed & WT_F_V_PRE_RADEX & WT_F_EXTENSION));
+    end;
+
+    -- Dissolved concentration
+    declare
+
+      Trans: Translate_Set;
+    begin
+      Insert(Trans, Assoc(WT_DC_INT_KEY, DC_Int_Str));
+      Insert(Trans, Assoc(WT_DC_DEC_KEY, DC_Dec_Str));
+      Insert(Trans, Assoc(WT_DC_EXP_KEY, DC_Exp_Str));
+
+      TeXCode := Parse(Filename => WT_T_PREFIX & "v_diss_c.ttex", Translations => Trans);
+      Ret := TeX_To_PNG(TeXCode, WT_F_V_PRE_RADEX, Problem.Resource_Prefix);
+      if Ret /= OK then
+       return Ret;
+      end if;
+      Problem.Add_Tracked_Resource(WT_F_V_DISS_C & WT_F_EXTENSION);
+      Insert(Final_Trans, Assoc(WT_V_DISS_C_RESULT_KEY, PRP_Fixed & WT_F_V_PRE_RADEX & WT_F_EXTENSION));
+    end;
+
+    -- Plug the numbers into the volume calculation
+    declare
+      G_Int_Str: UB_Text;
+      G_Dec_Str: UB_Text;
+      MW_Int_Str: UB_Text;
+      MW_Dec_Str: UB_Text;
+
+      Trans: Translate_Set;
+    begin
+      FH.Split_Integer_Decimal_Unscaled_Strs(Problem.Prob_Data.V_G, DECIMALS, G_Int_Str, G_Dec_Str);
+      FH.Split_Integer_Decimal_Unscaled_Strs(Problem.Prob_Data.V_MW, DECIMALS, MW_Int_Str, MW_Dec_Str);
+
+      Insert(Trans, Assoc(WT_G_INT_KEY, G_Int_Str));
+      Insert(Trans, Assoc(WT_G_DEC_KEY, G_Dec_Str));
+      Insert(Trans, Assoc(WT_MW_INT_KEY, MW_Int_Str));
+      Insert(Trans, Assoc(WT_MW_DEC_KEY, MW_Dec_Str));
+      Insert(Trans, Assoc(WT_DC_INT_KEY, DC_Int_Str));
+      Insert(Trans, Assoc(WT_DC_DEC_KEY, DC_Dec_Str));
+      Insert(Trans, Assoc(WT_DC_EXP_KEY, DC_Exp_Str));
+
+      TeXCode := Parse(Filename => WT_T_PREFIX & "v_volume_plug.ttex", Translations => Trans);
+      Ret := TeX_To_PNG(TeXCode, WT_F_V_PLUG, Problem.Resource_Prefix);
+      if Ret /= OK then
+       return Ret;
+      end if;
+      Problem.Add_Tracked_Resource(WT_F_V_PLUG & WT_F_EXTENSION);
+      Insert(Final_Trans, Assoc(WT_V_PLUG_VOLUME_RESULT_KEY, PRP_Fixed & WT_F_V_PLUG & WT_F_EXTENSION));
+    end;
+
+    -- Display the final result
+    declare
+      Res_Int_Str: UB_Text;
+      Res_Dec_Str: UB_Text;
+      Res_Exp_Str: UB_Text;
+
+      Trans: Translate_Set;
+    begin
+      FH.Split_Integer_Decimal_Exponent_Strs(Problem.Answer_Num, DECIMALS, Res_Int_Str, Res_Dec_Str, Res_Exp_Str);
+
+      Insert(Trans, Assoc(WT_RES_INT_KEY, Res_Int_Str));
+      Insert(Trans, Assoc(WT_RES_DEC_KEY, Res_Dec_Str));
+      Insert(Trans, Assoc(WT_RES_EXP_KEY, Res_Exp_Str));
+
+      TeXCode := Parse(Filename => WT_T_PREFIX & "v_answer.ttex", Translations => Trans);
+      Ret := TeX_To_PNG(TeXCode, WT_F_ANSWER, Problem.Resource_Prefix);
+      if Ret /= OK then
+       return Ret;
+      end if;
+      Problem.Add_Tracked_Resource(WT_F_ANSWER & WT_F_EXTENSION);
+      Insert(Final_Trans, Assoc(WT_ANSWER_RESULT_KEY, PRP_Fixed & WT_F_ANSWER & WT_F_EXTENSION));
+    end;
+
+    return OK;
+  end Gen_Walkthrough_V_FROM_G_KS;
+
+  function Gen_Walkthrough_KS_FROM_G_V(Problem: in out Solubility_Problem; Walkthrough: out Walkthrough_Info.Map) return RetCode is
+  begin
+    return E_NOTIMPL;
+  end Gen_Walkthrough_KS_FROM_G_V;
+
+  function Gen_Walkthrough_C_FROM_KS_DIFFERENT_IONS(Problem: in out Solubility_Problem; Walkthrough: out Walkthrough_Info.Map) return RetCode is
+  begin
+    return E_NOTIMPL;
+  end Gen_Walkthrough_C_FROM_KS_DIFFERENT_IONS;
+
+  function Gen_Walkthrough_C_FROM_KS_SHARED_ION(Problem: in out Solubility_Problem; Walkthrough: out Walkthrough_Info.Map) return RetCode is
+  begin
+    return E_NOTIMPL;
+  end Gen_Walkthrough_C_FROM_KS_SHARED_ION;
+
   function Generate_Electrolyte_Concentration return SS_Float is
     package MEF is new Ada.Numerics.Generic_Elementary_Functions(SS_Float);
     use Ada.Numerics.Float_Random;
index edfd1ee8369807c1c305c19e17bdb9bb17e30325..8169b59866ae735ea1303e22d8216696758a1a71 100644 (file)
@@ -33,6 +33,7 @@ private
   procedure Add_Tracked_Resource(Problem: in out Chem_Problem; Name: in String);
   procedure Free_Tracked_Resources(Problem: in out Chem_Problem);
 
+  WT_F_EXTENSION: constant String := ".png";
   WALKTHROUGH_TEMPLATES_PATH: constant String := "walkthrough_templates/";
 
   package Acidobazic_Suite is
@@ -119,7 +120,6 @@ private
       WT_ANSWER_PH_INT_KEY: constant String := "WT_ANSWER_PH_INT";
       WT_ANSWER_PH_DEC_KEY: constant String := "WT_ANSWER_PH_DEC";
       --
-      WT_F_EXTENSION: constant String := ".png";
       WT_F_RESULT: constant String := "result";
       WT_F_ION_CONC: constant String := "ion_conc";
       WT_F_CHECK_ATPR: constant String := "check_atpr";
@@ -148,20 +148,6 @@ private
     type SS_Float is digits 17;
     subtype Stochiometric_Count is Positive range 1 .. 5;
 
-    ELECTROLYTE_CONCENTRATION_LOG_MAX: constant SS_Float := -2.0;
-    ELECTROLYTE_CONCENTRATION_LOG_MIN: constant SS_Float := -4.5;
-    MOLAR_WEIGHT_MAX: constant SS_Float := 450.0;
-    MOLAR_WEIGHT_MIN: constant SS_Float := 45.0;
-    PKS_MAX: constant SS_Float := 54.0;
-    PKS_MIN: constant SS_Float := 10.0;
-    SAMPLE_VOLUME_LOG_MAX: constant SS_Float := 10.0;
-    SAMPLE_VOLUME_LOG_MIN: constant SS_Float := -0.3;
-    SAMPLE_WEIGHT_MAX: constant SS_Float := 1.5;
-    SAMPLE_WEIGHT_MIN: constant SS_Float := 0.1;
-    DECIMALS: constant Natural := 3;
-    DECIMALS_MW: constant Natural := 2;
-    PRECISION: constant SS_Float := 1.0E2;
-
     type Ion is
       record
        Concentration: SS_Float;
@@ -209,11 +195,56 @@ private
     function Calculate_Sat_Concentration_Shared(Prob_Data: in Solubility_Problem_Data; Ionic_Strength: in Boolean) return SS_Float;
     function Calculate_Sample_Volume(Prob_Data: in Solubility_Problem_Data; Ionic_Strength: in Boolean) return SS_Float;
     function Calculate_Solubility_Product(Prob_Data: in Solubility_Problem_Data; Ionic_Strength: in Boolean) return SS_Float;
+    function Gen_Walkthrough_V_FROM_G_KS(Problem: in out Solubility_Problem; Walkthrough: out Walkthrough_Info.Map) return RetCode;
+    function Gen_Walkthrough_KS_FROM_G_V(Problem: in out Solubility_Problem; Walkthrough: out Walkthrough_Info.Map) return RetCode;
+    function Gen_Walkthrough_C_FROM_KS_DIFFERENT_IONS(Problem: in out Solubility_Problem; Walkthrough: out Walkthrough_Info.Map) return RetCode;
+    function Gen_Walkthrough_C_FROM_KS_SHARED_ION(Problem: in out Solubility_Problem; Walkthrough: out Walkthrough_Info.Map) return RetCode;
     function Generate_Electrolyte_Concentration return SS_Float;
     function Generate_Sample_Volume return SS_Float;
     function Generate_Solubility_Product return SS_Float;
     procedure Get_Precise_Answer_String(Message: in out UB_Text; P_Subtype: in Problem_Subtype; Answer: in SS_Float);
 
+    ELECTROLYTE_CONCENTRATION_LOG_MAX: constant SS_Float := -2.0;
+    ELECTROLYTE_CONCENTRATION_LOG_MIN: constant SS_Float := -4.5;
+    MOLAR_WEIGHT_MAX: constant SS_Float := 450.0;
+    MOLAR_WEIGHT_MIN: constant SS_Float := 45.0;
+    PKS_MAX: constant SS_Float := 54.0;
+    PKS_MIN: constant SS_Float := 10.0;
+    SAMPLE_VOLUME_LOG_MAX: constant SS_Float := 10.0;
+    SAMPLE_VOLUME_LOG_MIN: constant SS_Float := -0.3;
+    SAMPLE_WEIGHT_MAX: constant SS_Float := 1.5;
+    SAMPLE_WEIGHT_MIN: constant SS_Float := 0.1;
+    DECIMALS: constant Natural := 3;
+    DECIMALS_MW: constant Natural := 2;
+    PRECISION: constant SS_Float := 1.0E2;
+    --
+    WT_T_PREFIX: constant String := WALKTHROUGH_TEMPLATES_PATH & "solubility_suite/";
+    WT_F_ANSWER: constant String := "answer";
+    WT_F_V_DISS_C: constant String := "v_diss_c";
+    WT_F_V_PLUGNUMS: constant String := "v_plug_nums";
+    WT_F_V_PRE_RADEX: constant String := "v_pre_radex";
+    WT_F_V_PLUG: constant String := "v_plug";
+    --
+    WT_DC_INT_KEY: constant String := "WT_DC_INT";
+    WT_DC_DEC_KEY: constant String := "WT_DC_DEC";
+    WT_DC_EXP_KEY: constant String := "WT_DC_EXP";
+    WT_G_INT_KEY: constant String := "WT_G_INT";
+    WT_G_DEC_KEY: constant String := "WT_G_DEC";
+    WT_KDMN_INT_KEY: constant String := "WT_KDMN_INT";
+    WT_KDMN_DEC_KEY: constant String := "WT_KDMN_DEC";
+    WT_KDMN_EXP_KEY: constant String := "WT_KDMN_EXP";
+    WT_KS_INT_KEY: constant String := "WT_KS_INT";
+    WT_KS_DEC_KEY: constant String := "WT_KS_DEC";
+    WT_KS_EXP_KEY: constant String := "WT_KS_EXP";
+    WT_M_KEY: constant String := "WT_M";
+    WT_N_KEY: constant String := "WT_N";
+    WT_MPN_KEY: constant String := "WT_MPN";
+    WT_MW_INT_KEY: constant String := "WT_MW_INT_KEY";
+    WT_MW_DEC_KEY: constant String := "WT_MW_DEC_KEY";
+    WT_RES_INT_KEY: constant String := "WT_RES_INT_KEY";
+    WT_RES_DEC_KEY: constant String := "WT_RES_DEC_KEY";
+    WT_RES_EXP_KEY: constant String := "WT_RES_EXP_KEY";
+
   end Solubility_Suite;
 
   package Titration_Curve_Suite is
index b26667a716202e6cb9abb59bd23707500e03eda7..fc7df852eff5d579c0375efe60ffe33951fad8dd 100644 (file)
@@ -98,6 +98,12 @@ package Problem_Generator_Syswides is
     PARAMETER_PROBLEM_SUBTYPE_KEY: constant String := "PARAMETER_PROBLEM_SUBTYPE";
     --
     FILLIN_ANSWER_KEY: constant String := "FILLIN_ANSWER";
+    --
+    WT_ANSWER_RESULT_KEY: constant String := "WT_ANSWER_RESULT_KEY";
+    WT_V_DISS_C_RESULT_KEY: constant String := "WT_V_DISS_C_RESULT_KEY"; 
+    WT_V_PLUG_C_RESULT_KEY: constant String := "WT_V_PLUG_C_RESULT";
+    WT_V_PLUG_VOLUME_RESULT_KEY: constant String := "WT_V_PLUG_VOLUME_RESULT";
+    WT_V_PRE_RADEX_RESULT_KEY: constant String := "WT_V_PRE_RADEX_RESULT";
 
   end Solubility_Suite;