PhreeqcUsers Discussion Forum

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 

  • Forum Home
  • Login
  • Register

  • PhreeqcUsers Discussion Forum »
  • Solubility »
  • Dissolution/precipitation »
  • Precipitated mineral volume
« previous next »
  • Print
Pages: [1]   Go Down

Author Topic: Precipitated mineral volume  (Read 1584 times)

srohmen

  • Contributor
  • Posts: 5
Precipitated mineral volume
« on: June 02, 2016, 07:56:39 AM »
Dear users,

as already mentioned in the subject title I want to determine the volume of each precipitated mineral. Since PhreeqC provides information about the molar amount of each precipitated mineral this is achievable with help of the molar volume ( = mineral molar mass / mineral density). This information is available for each mineral phase in the databases of PhreeqC. However, I am using PhreeqcRM as chemical code inside of my application I tried to access these information programmatically via the PhreeqcRM interface. The only solution I found so far was to breach the encapsulation. It is like:

Code: [Select]
    IPhreeqc* iphreeqc = m_phreeqcRM.GetIPhreeqcPointer(0);
    IPhreeqcPhast* iphreeqcPhast = dynamic_cast<IPhreeqcPhast*>(iphreeqc);
    assert(iphreeqc);
    Phreeqc* internalPhreeqc = iphreeqcPhast->Get_PhreeqcPtr();

    int pos;
    phase* ph = internalPhreeqc->phase_bsearch("Witherite", &pos, false);

    const double molVol = ph->logk[vm0];
    std::cout << molVol << std::endl;

This solution is really ugly and relies on the fact that I know about the internal structure of PhreeqC. Therefore, I want to ask if there is a better solution? Otherwise: I intend to make a patch for PhreeqcRM which changes the interface in a way that I can obtain the informations I need. Would you (the developer?) accept such a patch for upstream in the next Phreeqc(RM) version?

Best regards,
Stephan
Logged

dlparkhurst

  • Top Contributor
  • Posts: 1270
Re: Precipitated mineral volume
« Reply #1 on: June 02, 2016, 02:38:39 PM »
Seems like there are two options: (1) A Basic function, say VM_PHASE("Calcite") could be added that would allow you to get the volumes through USER_PUNCH output, or (2) some new method for PhreeqcRM, but I am not sure how that would work, one mineral at a time, or all minerals in the database?

I can add the first easily. To be honest, adding methods to PhreeqcRM is a nuisance, not so much for the programming, but for the documentation.
Logged

srohmen

  • Contributor
  • Posts: 5
Re: Precipitated mineral volume
« Reply #2 on: June 03, 2016, 08:27:15 AM »
Thank you for your quick reply!

Since I am using SELECTED_OUTPUT anyway for retrieving the amount of the phases a new USER_PUNCH keyword for  the PhreeqC input would be really nice. If this is easier for you now that should be the way to go.

BTW: You are mentioning that it is unclear which phase information a PhreeqcRM interface should provide. I would have expected that I would get only informations about phases which can be formed by the species currently present in the cells system. This leads me to another question: Can I retrieve somehow a list of all possible phases from PhreeqcRM for the current configuration?

Thanks in advance!
Stephan
Logged

dlparkhurst

  • Top Contributor
  • Posts: 1270
Re: Precipitated mineral volume
« Reply #3 on: June 03, 2016, 03:49:40 PM »
OK. I will add a basic function, probably PHASE_VM("Calcite").

The Basic function SYS can be used to determine all of the phases appropriate for the current set of elements. Note the results are only for the current calculation or cell.

SYS("phases", count, name$, type$, phase_si)

returns the number of phases for which saturation indices can be calculated, an array of the phase names (name$), type is a list with all values "phase", and phase_si is an array of saturation indices.

SYS("equi", ...) retrieves all of the equilibrium phases in the current cell.

SYS("s_s", ...) retrieves all of the solid solution components.

Other uses retrieve GAS_PHASE components, exchangers, surfaces, aqueous species, and the total moles of an element in all of the cell's phases.

Logged

srohmen

  • Contributor
  • Posts: 5
Re: Precipitated mineral volume
« Reply #4 on: June 13, 2016, 10:15:51 AM »
thank you for your reply. I am looking forward to use the PHASE_VM functionality.

I checked with the recommended SYS("phases", ...) function. From the CLI interface point of view this is of course working. I could punch all phases and the corresponding informations to the selected output file. Unfortunately, I can not use this feature appropriately with PhreeqcRM. Internally PhreeqC handles selected_output data as 2D array of CVar. Then there is this CSelectedOutput::Doublize() function which converts all CVar data into doubles before copying it into the output (vector<double>). Of cource this makes sense because the output vector does only contain double values. Thus, the function Doublize() does for strings (char array, which phase names actually are) the following "conversion":
Code: [Select]
case TT_STRING:
doubles.push_back((double) INACTIVE_CELL_VALUE);
break;
Now I am thinking about "tinkering" with BASIC function an "phase name string -> char array -> double value" feature with bit-shifting or otherwise writing out the selected_output file and reading it and parsing it again. Both ideas are not optimal from the maintainability and performance point of view.

Have I overlooked a possibility?

Best regards,
Stephan


EDIT:
I found another possiblity. but again breaching encapsulation?
Code: [Select]

    IPhreeqcPhast* internalPhreeqc = phreeqc.GetWorkers().front();

    VAR pVar;
    pVar.type = TT_STRING;
    pVar.sVal = nullptr;
    const size_t col = 0;
    const size_t row = 0;
    internalPhreeqc->GetSelectedOutputValue(row, col, &pVar);
    std::cout << pVar.sVal << std::endl;
« Last Edit: June 13, 2016, 11:49:50 AM by srohmen »
Logged

dlparkhurst

  • Top Contributor
  • Posts: 1270
Re: Precipitated mineral volume
« Reply #5 on: June 13, 2016, 03:37:36 PM »
Right, the characters cannot be passed back through selected output in PhreeqcRM, although it is possible with IPhreeqc. The Variant structure does not translate well for Fortran, so it was simpler just to return doubles.

This gets a little obscure, but if you are not printing to the output stream (long detailed printout for cells), you can get the IPhreeqc an instance  GetIPhreeqcPointer (int i) and get the IPhreeqc version of the selected output, which uses Variants.

One solution would be to add a SYS-like method to PhreeqcRM. There is a point where the elements defined in the initial conditions are accumulated (FindComponents()). I should probably accumulate all of the exchangers, equilibrium phases, surfaces, kinetics etc and make them available.

I guess alternatively, I could implement a variant version of the selected output.

I'll consider it, but either option would probably not be implemented for quite a while.
Logged

  • Print
Pages: [1]   Go Up
« previous next »
  • PhreeqcUsers Discussion Forum »
  • Solubility »
  • Dissolution/precipitation »
  • Precipitated mineral volume
 

  • SMF 2.0.3 | SMF © 2011, Simple Machines
  • XHTML
  • RSS
  • WAP2