-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCKSInverse.cpp
375 lines (332 loc) · 8.25 KB
/
CKSInverse.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
// CKSInverse.cpp : implementation file
//
// $Id$
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "resource.h"
#include "CKSInverse.h"
#include "Util.h"
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCKSInverse
IMPLEMENT_DYNAMIC(CCKSInverse, baseCKSInverse)
CCKSInverse::CCKSInverse(CWnd* pWndParent, CTreeCtrlNode simNode)
: baseCKSInverse(IDS_PROPSHT_CAPTION14, pWndParent)
, m_ranges(simNode)
{
// default to no final soln
m_invSolFinal.nSol = -1;
// create soln range
m_strNumFormat = CUtil::CreateRange(m_setSolutions, m_ranges[CKeyword::K_SOLUTION]);
// Add all of the property pages here. Note that
// the order that they appear in here will be
// the order they appear in on screen. By default,
// the first page of the set is the active one.
// One way to make a different property page the
// active one is to call SetActivePage().
AddPage(&m_Page1A);
AddPage(&m_Page1B);
AddPage(&m_Page2);
AddPage(&m_Page3);
}
CCKSInverse::~CCKSInverse()
{
}
BEGIN_MESSAGE_MAP(CCKSInverse, baseCKSInverse)
//{{AFX_MSG_MAP(CCKSInverse)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCKSInverse message handlers
CString CCKSInverse::GetString()
{
/*
Line 0: INVERSE_MODELING 1
Line 1: -solutions 10 3 5
Line 2: -uncertainty 0.02 0.04
Line 3: -phases
Line 4a: Calcite force pre 13C -1.0 1
Line 4b: Anhydrite force dis 34S 13.5 2
Line 4c: CaX2
Line 4d: NaX
Line 5: -balances
Line 6a pH 0.1
Line 6b: Ca 0.01 -0.005
Line 6c: Alkalinity -1.0e-6
Line 6d: Fe 0.05 0.1 0.2
Line 7: -isotopes
Line 8a: 13C 0.05 0.1 0.05
Line 8b: 34S 1.0
Line 9: -range 10000
Line 10: -minimal
Line 11: -tolerance 1e-10
Line 12: -force_solutions true false
Line 13: -uncertainty_water 0.55 # moles (~1%)
Line 14: -mineral_water false
New: -lon_netpath prefix
New: -pat_netpath prefix
*/
CString strLines;
CString strFormat;
// Line 0
strLines = GetLineZero(CKeyword::K_INVERSE_MODELING);
// Line 1
std::list<InvSol>::iterator iterInvSol;
iterInvSol = m_listInvSol.begin();
if (iterInvSol != m_listInvSol.end())
{
strFormat.Format(_T("%s%4c-solutions "),
(LPCTSTR)s_strNewLine,
_T(' ')
);
CString strNums;
for (; iterInvSol != m_listInvSol.end(); ++iterInvSol)
{
strNums.Format(_T(" %-*ld"), 8, iterInvSol->nSol);
strFormat += strNums;
}
// final soln
strNums.Format(_T(" %-*ld"), 8, m_invSolFinal.nSol);
strNums.TrimRight();
strFormat += strNums;
strLines += strFormat;
}
// Line 2
iterInvSol = m_listInvSol.begin();
if (iterInvSol != m_listInvSol.end())
{
strFormat.Format(_T("%s%4c-uncertainty "),
(LPCTSTR)s_strNewLine,
_T(' ')
);
CString strNums;
for (; iterInvSol != m_listInvSol.end(); ++iterInvSol)
{
strNums.Format(_T(" %-*.*g"), 8, DBL_DIG, iterInvSol->dUncertainty);
strFormat += strNums;
}
// final soln
strNums.Format(_T(" %-*.*g"), 8, DBL_DIG, m_invSolFinal.dUncertainty);
strNums.TrimRight();
strFormat += strNums;
strLines += strFormat;
}
// Line 3
if (m_Page1B.m_listInvPhase.size() != 0)
{
strFormat.Format(_T("%s%4c-phases"),
(LPCTSTR)s_strNewLine,
_T(' ')
);
strLines += strFormat;
// find longest phase name
int c = 11;
std::list<CInvPhase>::iterator iterInvPhase = m_Page1B.m_listInvPhase.begin();
for (; iterInvPhase != m_Page1B.m_listInvPhase.end(); ++iterInvPhase)
{
c = max(c, iterInvPhase->m_strName.GetLength());
}
// Line 4
iterInvPhase = m_Page1B.m_listInvPhase.begin();
for (; iterInvPhase != m_Page1B.m_listInvPhase.end(); ++iterInvPhase)
{
strFormat.Format(_T("%s%4c%s"),
(LPCTSTR)s_strNewLine,
_T(' '),
iterInvPhase->GetString(c)
);
strFormat.TrimRight();
strLines += strFormat;
}
}
// Line 5
if (m_listInvElem.size() != 0)
{
strFormat.Format(_T("%s%4c-balances"),
(LPCTSTR)s_strNewLine,
_T(' ')
);
strLines += strFormat;
// Line 6
// MAYBE: check if pH needs to be output
std::list<CInvElem>::iterator iterInvElem = m_listInvElem.begin();
for (; iterInvElem != m_listInvElem.end(); ++iterInvElem)
{
strFormat.Format(_T("%s%4c%s"),
(LPCTSTR)s_strNewLine,
_T(' '),
iterInvElem->GetString(m_listInvSol, m_invSolFinal)
);
strLines += strFormat;
}
}
// Line 7
if (m_Page3.m_listInvIsotopes.size() != 0)
{
strFormat.Format(_T("%s%4c-isotopes"),
(LPCTSTR)s_strNewLine,
_T(' ')
);
strLines += strFormat;
// Line 8
std::list<CInvIsotope>::iterator iterInvIsotope = m_Page3.m_listInvIsotopes.begin();
for (; iterInvIsotope != m_Page3.m_listInvIsotopes.end(); ++iterInvIsotope)
{
strFormat.Format(_T("%s%4c%s"),
(LPCTSTR)s_strNewLine,
_T(' '),
iterInvIsotope->GetString(m_listInvSol, m_invSolFinal, m_Page3.m_mapIso2DefaultUnc)
);
strLines += strFormat;
}
}
// Line 9
if (m_Page1A.m_bRange)
{
strFormat.Format(_T("%s%4c-range %.*g"),
(LPCTSTR)s_strNewLine,
_T(' '),
DBL_DIG,
m_Page1A.m_dRange
);
strFormat.TrimRight();
strLines += strFormat;
}
// Line 10
if (m_Page1A.m_bMinimal)
{
strFormat.Format(_T("%s%4c-minimal"),
(LPCTSTR)s_strNewLine,
_T(' ')
);
strFormat.TrimRight();
strLines += strFormat;
}
// Line 11
strFormat.Format(_T("%s%4c-tolerance %.*g"),
(LPCTSTR)s_strNewLine,
_T(' '),
DBL_DIG,
m_Page1A.m_dTol
);
strFormat.TrimRight();
strLines += strFormat;
// Line 12
bool bAtLeastOneTrue = false;
iterInvSol = m_listInvSol.begin();
if (iterInvSol != m_listInvSol.end())
{
strFormat.Format(_T("%s%4c-force_solutions "),
(LPCTSTR)s_strNewLine,
_T(' ')
);
CString strTorF;
for (; iterInvSol != m_listInvSol.end(); ++iterInvSol)
{
if (iterInvSol->bForce)
bAtLeastOneTrue = true;
strFormat += (iterInvSol->bForce) ? _T(" true") : _T(" false");
}
// final soln
if (m_invSolFinal.bForce)
bAtLeastOneTrue = true;
strFormat += (m_invSolFinal.bForce) ? _T(" true") : _T(" false");
if (bAtLeastOneTrue)
strLines += strFormat;
}
// Line 13
if (m_Page2.m_bWaterUncert)
{
strFormat.Format(_T("%s%4c-uncertainty_water %.*g"),
(LPCTSTR)s_strNewLine,
_T(' '),
DBL_DIG,
m_Page2.m_dWaterUncert
);
strFormat.TrimRight();
strLines += strFormat;
}
// Line 14
if (m_Page1A.m_bMineralWater)
{
strFormat.Format(_T("%s%4c-mineral_water true"),
(LPCTSTR)s_strNewLine,
_T(' ')
);
strLines += strFormat;
}
else
{
strFormat.Format(_T("%s%4c-mineral_water false"),
(LPCTSTR)s_strNewLine,
_T(' ')
);
strLines += strFormat;
}
if (m_Page1A.m_bMPSolve)
{
// -multiple_precision
strFormat.Format(_T("%s%4c-multiple_precision true"),
(LPCTSTR)s_strNewLine,
_T(' ')
);
strLines += strFormat;
// -mp_tolerance
strFormat.Format(_T("%s%4c-mp_tolerance %.*g"),
(LPCTSTR)s_strNewLine,
_T(' '),
DBL_DIG,
m_Page1A.m_dMPTol
);
strFormat.TrimRight();
strLines += strFormat;
// -censor_mp
strFormat.Format(_T("%s%4c-censor_mp %.*g"),
(LPCTSTR)s_strNewLine,
_T(' '),
DBL_DIG,
m_Page1A.m_dMPCensor
);
strFormat.TrimRight();
strLines += strFormat;
}
if (m_Page1A.m_bLonNetpath)
{
// -lon_netpath
strFormat.Format(_T("%s%4c-lon_netpath %s"),
(LPCTSTR)s_strNewLine,
_T(' '),
(LPCTSTR)m_Page1A.m_sLonPrefix
);
strLines += strFormat;
}
if (m_Page1A.m_bPatNetpath)
{
// -pat_netpath
strFormat.Format(_T("%s%4c-pat_netpath %s"),
(LPCTSTR)s_strNewLine,
_T(' '),
(LPCTSTR)m_Page1A.m_sPatPrefix
);
strLines += strFormat;
}
return strLines + s_strNewLine;
}
void CCKSInverse::Edit(CString& rStr)
{
try
{
PhreeqcI p(rStr);
p.GetData(this);
}
catch (...)
{
CString strResource;
strResource.LoadString(IDS_EXCEPTION_ACCESS_VIOLATION);
::MessageBox(NULL, strResource, _T("Unhandled Exception"), MB_OK|MB_ICONERROR);
}
}