mirror of
https://git.gfz-potsdam.de/naaice/iphreeqc.git
synced 2025-12-16 16:44:49 +01:00
Added time unit to advection, kinetics, transport, and run_cells
git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@6684 1feff8c3-07ed-0310-ac33-dd36852eb9cd
This commit is contained in:
parent
fc2d4425fb
commit
232bb18fad
43
Utils.cxx
43
Utils.cxx
@ -111,7 +111,50 @@ Utilities::squeeze_white(std::string & s_l)
|
||||
}
|
||||
s_l = str;
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
double
|
||||
Utilities::convert_time(double t, std::string in, std::string out)
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
{
|
||||
Utilities::str_tolower(in);
|
||||
|
||||
// convert t to seconds
|
||||
if (in.substr(0,1) == "m")
|
||||
{
|
||||
t = t * 60.;
|
||||
}
|
||||
if (in.substr(0,1) == "h")
|
||||
{
|
||||
t = t * 3600.;
|
||||
}
|
||||
if (in.substr(0,1) == "d")
|
||||
{
|
||||
t = t * 3600. * 24.;
|
||||
}
|
||||
if (in.substr(0,1) == "y")
|
||||
{
|
||||
t = t * 3600. * 24. * 365.25;
|
||||
}
|
||||
// convert to ouput units
|
||||
if (out.substr(0,1) == "m")
|
||||
{
|
||||
t = t / 60.;
|
||||
}
|
||||
if (out.substr(0,1) == "h")
|
||||
{
|
||||
t = t / 3600.;
|
||||
}
|
||||
if (out.substr(0,1) == "d")
|
||||
{
|
||||
t = t / ( 3600. * 24.);
|
||||
}
|
||||
if (out.substr(0,1) == "y")
|
||||
{
|
||||
t = t / (3600. * 24. * 365.25);
|
||||
}
|
||||
return t;
|
||||
|
||||
}
|
||||
//+NAN LDBLE: 7ff8000000000000
|
||||
//-NAN LDBLE: fff8000000000000
|
||||
/*
|
||||
|
||||
2
Utils.h
2
Utils.h
@ -22,6 +22,6 @@ namespace Utilities
|
||||
bool replace(const char *str1, const char *str2, std::string & str);
|
||||
|
||||
void squeeze_white(std::string & s_l);
|
||||
|
||||
double convert_time(double t, std::string in, std::string out);
|
||||
}
|
||||
#endif // UTILITIES_H_INCLUDED
|
||||
|
||||
126
phreeqc/read.cpp
126
phreeqc/read.cpp
@ -1999,6 +1999,7 @@ read_kinetics(void)
|
||||
temp_kinetics.Set_description(description);
|
||||
description = (char *) free_check_null(description);
|
||||
cxxKineticsComp *kinetics_comp_ptr = NULL;
|
||||
std::string stdunits;
|
||||
/*
|
||||
* Set use data to first read
|
||||
*/
|
||||
@ -2210,68 +2211,80 @@ read_kinetics(void)
|
||||
*/
|
||||
{
|
||||
int j;
|
||||
while ((j = copy_token(token, &next_char)) == DIGIT)
|
||||
while ((j = copy_token(token, &next_char)) != EMPTY)
|
||||
{
|
||||
/* Read next step increment(s) */
|
||||
/* multiple, equal timesteps 15 aug. 2005 */
|
||||
if (Utilities::replace("*", " ", token))
|
||||
if (j == DIGIT)
|
||||
{
|
||||
int k;
|
||||
if (sscanf(token.c_str(), "%d" SCANFORMAT, &k, &step) == 2)
|
||||
/* Read next step increment(s) */
|
||||
/* multiple, equal timesteps 15 aug. 2005 */
|
||||
if (Utilities::replace("*", " ", token))
|
||||
{
|
||||
for (int i = 0; i < k; i++)
|
||||
int k;
|
||||
if (sscanf(token.c_str(), "%d" SCANFORMAT, &k, &step) == 2)
|
||||
{
|
||||
temp_kinetics.Get_steps().push_back(step);
|
||||
for (int i = 0; i < k; i++)
|
||||
{
|
||||
temp_kinetics.Get_steps().push_back(step);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
input_error++;
|
||||
error_msg
|
||||
("Format error in multiple, equal KINETICS timesteps.\nCorrect is (for example): 20 4*10 2*5 3\n",
|
||||
CONTINUE);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
input_error++;
|
||||
error_msg
|
||||
("Format error in multiple, equal KINETICS timesteps.\nCorrect is (for example): 20 4*10 2*5 3\n",
|
||||
CONTINUE);
|
||||
step = strtod(token.c_str(), &ptr);
|
||||
temp_kinetics.Get_steps().push_back(step);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
step = strtod(token.c_str(), &ptr);
|
||||
temp_kinetics.Get_steps().push_back(step);
|
||||
Utilities::str_tolower(token);
|
||||
if (token.substr(0,1) == "i" )
|
||||
{
|
||||
/*
|
||||
* Read number of increments
|
||||
*/
|
||||
if (temp_kinetics.Get_steps().size() != 1)
|
||||
{
|
||||
error_msg
|
||||
("To define equal time increments, only one total time should be defined.",
|
||||
CONTINUE);
|
||||
input_error++;
|
||||
break;
|
||||
}
|
||||
temp_kinetics.Set_equalIncrements(true);
|
||||
do
|
||||
{
|
||||
int i = 1;
|
||||
j = sscanf(token.c_str(), "%d", &i);
|
||||
if (j == 1)
|
||||
{
|
||||
temp_kinetics.Set_count(abs(i));
|
||||
break;
|
||||
}
|
||||
else if (j == 1 && i < 0)
|
||||
{
|
||||
error_msg
|
||||
("Expecting positive number for number of equal "
|
||||
"time increments for kinetics.", CONTINUE);
|
||||
error_msg(line_save, CONTINUE);
|
||||
input_error++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (copy_token(token, &next_char) != EMPTY);
|
||||
}
|
||||
else
|
||||
{
|
||||
stdunits = token;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (j == EMPTY)
|
||||
break;
|
||||
/*
|
||||
* Read number of increments
|
||||
*/
|
||||
if (temp_kinetics.Get_steps().size() != 1)
|
||||
{
|
||||
error_msg
|
||||
("To define equal time increments, only one total time should be defined.",
|
||||
CONTINUE);
|
||||
input_error++;
|
||||
break;
|
||||
}
|
||||
temp_kinetics.Set_equalIncrements(true);
|
||||
do
|
||||
{
|
||||
int i = 1;
|
||||
j = sscanf(token.c_str(), "%d", &i);
|
||||
if (j == 1)
|
||||
{
|
||||
temp_kinetics.Set_count(abs(i));
|
||||
break;
|
||||
}
|
||||
else if (j == 1 && i < 0)
|
||||
{
|
||||
error_msg
|
||||
("Expecting positive number for number of equal "
|
||||
"time increments for kinetics.", CONTINUE);
|
||||
error_msg(line_save, CONTINUE);
|
||||
input_error++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (copy_token(token, &next_char) != EMPTY);
|
||||
}
|
||||
break;
|
||||
case 6: /* step_divide */
|
||||
@ -2397,6 +2410,14 @@ read_kinetics(void)
|
||||
{
|
||||
temp_kinetics.Get_steps().push_back(1.0);
|
||||
}
|
||||
else if (stdunits.size() > 0)
|
||||
{
|
||||
std::vector<double>::iterator it;
|
||||
for (it = temp_kinetics.Get_steps().begin(); it != temp_kinetics.Get_steps().end(); it++)
|
||||
{
|
||||
*it = Utilities::convert_time(*it, stdunits, "s");
|
||||
}
|
||||
}
|
||||
/*
|
||||
* set defaults for moles
|
||||
*/
|
||||
@ -7384,6 +7405,15 @@ read_advection(void)
|
||||
case 7: /* time_step */
|
||||
case 8: /* timest */
|
||||
sscanf(next_char, SCANFORMAT, &advection_kin_time);
|
||||
{
|
||||
std::string token;
|
||||
int j = copy_token(token, &next_char);
|
||||
j = copy_token(token, &next_char);
|
||||
if (j == UPPER || j == LOWER)
|
||||
{
|
||||
advection_kin_time = Utilities::convert_time(advection_kin_time, token, "s");
|
||||
}
|
||||
}
|
||||
advection_kin_time_defined = TRUE;
|
||||
opt_save = OPTION_DEFAULT;
|
||||
break;
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
typedef unsigned char boolean;
|
||||
#include "Phreeqc.h"
|
||||
#include "phqalloc.h"
|
||||
#include "Utils.h"
|
||||
|
||||
|
||||
#define OPTION_EOF -1
|
||||
@ -273,12 +274,25 @@ read_transport(void)
|
||||
}
|
||||
opt_save = OPTION_DEFAULT;
|
||||
break;
|
||||
case 5: /* timest */
|
||||
case 5: /* timest */
|
||||
case 14: /* time_step */
|
||||
if (copy_token(token, &next_char, &l) == DIGIT)
|
||||
sscanf(token, SCANFORMAT, ×t);
|
||||
if (copy_token(token, &next_char, &l) == DIGIT)
|
||||
sscanf(token, SCANFORMAT, &mcd_substeps);
|
||||
{
|
||||
std::string stdtoken;
|
||||
j = copy_token(stdtoken, &next_char);
|
||||
if (j == UPPER || j == LOWER)
|
||||
{
|
||||
timest = Utilities::convert_time(timest, stdtoken, "s");
|
||||
j = copy_token(stdtoken, &next_char);
|
||||
}
|
||||
if (j == DIGIT)
|
||||
{
|
||||
sscanf(stdtoken.c_str(), SCANFORMAT, &mcd_substeps);
|
||||
}
|
||||
}
|
||||
//if (copy_token(token, &next_char, &l) == DIGIT)
|
||||
// sscanf(token, SCANFORMAT, &mcd_substeps);
|
||||
if (mcd_substeps < 1)
|
||||
{
|
||||
mcd_substeps = 1.0;
|
||||
|
||||
19
runner.cpp
19
runner.cpp
@ -1,6 +1,7 @@
|
||||
#include "runner.h"
|
||||
#include "Parser.h"
|
||||
#include "NA.h"
|
||||
#include "Utils.h"
|
||||
runner::runner(PHRQ_io *io)
|
||||
:
|
||||
PHRQ_base(io)
|
||||
@ -99,6 +100,15 @@ bool runner::Read(CParser & parser)
|
||||
parser.error_msg("Expected start_time for RUN_CELLS.",
|
||||
PHRQ_io::OT_CONTINUE);
|
||||
parser.error_msg(parser.line().c_str(), PHRQ_io::OT_CONTINUE);
|
||||
break;
|
||||
}
|
||||
{
|
||||
std::string token;
|
||||
if (parser.get_iss() >> token)
|
||||
{
|
||||
token = trim(token);
|
||||
this->start_time = Utilities::convert_time(this->start_time, token, "s");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 3: //time_step
|
||||
@ -110,6 +120,15 @@ bool runner::Read(CParser & parser)
|
||||
parser.error_msg("Expected time_step for RUN_CELLS.",
|
||||
PHRQ_io::OT_CONTINUE);
|
||||
parser.error_msg(parser.line().c_str(), PHRQ_io::OT_CONTINUE);
|
||||
break;
|
||||
}
|
||||
{
|
||||
std::string token;
|
||||
if (parser.get_iss() >> token)
|
||||
{
|
||||
token = trim(token);
|
||||
this->time_step = Utilities::convert_time(this->time_step, token, "s");
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user