packing and unpacking cxx classes for mpi is running

need to check result.

changed SurfComp.h SurfaceComp.h
changed SurfComp.cxx SurfaceComp.cxx

changed SurfCharge.h SurfaceCharge.h
changed SurfCharge.cxx SurfaceCharge.cxx

Added Dictionary.cxx and Dictionary.h




git-svn-id: svn://136.177.114.72/svn_GW/phreeqcpp/trunk@894 1feff8c3-07ed-0310-ac33-dd36852eb9cd
This commit is contained in:
David L Parkhurst 2006-05-04 00:02:01 +00:00
parent 297744eafa
commit 11431ae291
31 changed files with 1131 additions and 99 deletions

View File

@ -4,7 +4,7 @@
#ifdef _DEBUG
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
#endif
#include <iostream> // std::cout std::cerr
#include "Utils.h" // define first
#include "ExchComp.h"
#define EXTERNAL extern
@ -57,7 +57,6 @@ totals(exch_comp_ptr->totals)
cxxExchComp::~cxxExchComp()
{
}
#include <iostream> // std::cout std::cerr
struct master *cxxExchComp::get_master()
{
@ -383,3 +382,38 @@ void cxxExchComp::read_raw(CParser& parser)
parser.error_msg("Formula_z not defined for ExchComp input.", CParser::OT_CONTINUE);
}
}
#ifdef USE_MPI
#include "Dictionary.h"
void cxxExchComp::mpi_pack(std::vector<int>& ints, std::vector<double>& doubles)
{
extern cxxDictionary dictionary;
ints.push_back(dictionary.string2int(this->formula));
doubles.push_back(this->moles);
this->formula_totals.mpi_pack(ints, doubles);
this->totals.mpi_pack(ints, doubles);
doubles.push_back(this->la);
doubles.push_back(this->charge_balance);
ints.push_back(dictionary.string2int(this->phase_name));
doubles.push_back(this->phase_proportion);
ints.push_back(dictionary.string2int(this->rate_name));
doubles.push_back(this->formula_z);
}
void cxxExchComp::mpi_unpack(int *ints, int *ii, double *doubles, int *dd)
{
extern cxxDictionary dictionary;
int i = *ii;
int d = *dd;
this->formula = dictionary.int2char(ints[i++]);
this->moles = doubles[d++];
this->formula_totals.mpi_unpack(ints, &i, doubles, &d);
this->totals.mpi_unpack(ints, &i, doubles, &d);
this->la = doubles[d++];
this->charge_balance = doubles[d++];
this->phase_name = dictionary.int2char(ints[i++]);
this->phase_proportion = doubles[d++];
this->rate_name = dictionary.int2char(ints[i++]);
this->formula_z = doubles[d++];
*ii = i;
*dd = d;
}
#endif

View File

@ -22,6 +22,7 @@ public:
struct master *get_master();
char *get_formula()const {return this->formula;}
char *get_phase_name()const {return this->phase_name;}
char *get_rate_name()const {return this->rate_name;}
@ -33,6 +34,10 @@ public:
void read_raw(CParser& parser);
#ifdef USE_MPI
void mpi_pack(std::vector<int>& ints, std::vector<double>& doubles);
void mpi_unpack(int *ints, int *ii, double *doubles, int *dd);
#endif
protected:
char * formula;
double moles;

View File

@ -5,6 +5,7 @@
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
#endif
#include <iostream> // std::cout std::cerr
#include "Utils.h" // define first
#include "Exchange.h"
#include "ExchComp.h"
@ -220,3 +221,41 @@ void cxxExchange::read_raw(CParser& parser)
parser.error_msg("Pitzer_exchange_gammsa not defined for EXCHANGE_RAW input.", CParser::OT_CONTINUE);
}
}
#ifdef USE_MPI
/* ---------------------------------------------------------------------- */
void cxxExchange::mpi_pack(std::vector<int>& ints, std::vector<double>& doubles)
/* ---------------------------------------------------------------------- */
{
/* int n_user; */
ints.push_back(this->n_user);
ints.push_back((int) this->pitzer_exchange_gammas);
ints.push_back(this->exchComps.size());
for (std::list<cxxExchComp>::iterator it = this->exchComps.begin(); it != this->exchComps.end(); it++) {
it->mpi_pack(ints, doubles);
}
}
/* ---------------------------------------------------------------------- */
void cxxExchange::mpi_unpack(int *ints, int *ii, double *doubles, int *dd)
/* ---------------------------------------------------------------------- */
{
int i = *ii;
int d = *dd;
/* int n_user; */
this->n_user = ints[i++];
this->n_user_end = this->n_user;
this->description = " ";
this->pitzer_exchange_gammas = (bool) ints[i++];
int count = ints[i++];
this->exchComps.clear();
for (int n = 0; n < count; n++) {
cxxExchComp ec;
ec.mpi_unpack(ints, &i, doubles, &d);
this->exchComps.push_back(ec);
}
*ii = i;
*dd = d;
}
#endif

View File

@ -35,6 +35,10 @@ public:
bool get_related_rate(void);
#ifdef USE_MPI
void cxxExchange::mpi_pack(std::vector<int>& ints, std::vector<double>& doubles);
void cxxExchange::mpi_unpack(int *ints, int *ii, double *doubles, int *dd);
#endif
protected:
std::list<cxxExchComp> exchComps;
bool pitzer_exchange_gammas;

View File

@ -282,3 +282,36 @@ void cxxGasPhase::read_raw(CParser& parser)
parser.error_msg("Volume not defined for GAS_PHASE_RAW input.", CParser::OT_CONTINUE);
}
}
#ifdef USE_MPI
void cxxGasPhase::mpi_pack(std::vector<int>& ints, std::vector<double>& doubles)
{
ints.push_back(this->n_user);
this->gasPhaseComps.mpi_pack(ints, doubles);
if (this->type == cxxGasPhase::GP_PRESSURE) {
ints.push_back(0);
} else {
ints.push_back(1);
}
doubles.push_back(this->total_p);
doubles.push_back(this->volume);
}
void cxxGasPhase::mpi_unpack(int *ints, int *ii, double *doubles, int *dd)
{
int i = *ii;
int d = *dd;
this->n_user = ints[i++];
this->n_user_end = this->n_user;
this->description = " ";
this->gasPhaseComps.mpi_unpack(ints, &i, doubles, &d);
int n = ints[i++];
if (n == 0) {
this->type = cxxGasPhase::GP_PRESSURE;
} else {
this->type = cxxGasPhase::GP_VOLUME;
}
this->total_p = doubles[d++];
this->volume = doubles[d++];
*ii = i;
*dd = d;
}
#endif

View File

@ -36,7 +36,10 @@ public:
void read_raw(CParser& parser);
#ifdef USE_MPI
void cxxGasPhase::mpi_pack(std::vector<int>& ints, std::vector<double>& doubles);
void cxxGasPhase::mpi_unpack(int *ints, int *ii, double *doubles, int *dd);
#endif
protected:
cxxNameDouble gasPhaseComps;
GP_TYPE type;

View File

@ -309,3 +309,39 @@ void cxxKineticsComp::read_raw(CParser& parser)
parser.error_msg("Moles not defined for KineticsComp input.", CParser::OT_CONTINUE);
}
}
#ifdef USE_MPI
#include "Dictionary.h"
void cxxKineticsComp::mpi_pack(std::vector<int>& ints, std::vector<double>& doubles)
{
extern cxxDictionary dictionary;
ints.push_back(dictionary.string2int(this->rate_name));
this->namecoef.mpi_pack(ints, doubles);
doubles.push_back(this->tol);
doubles.push_back(this->m);
doubles.push_back(this->m0);
doubles.push_back(this->moles);
ints.push_back(this->d_params.size());
for (std::vector<double>::iterator it = this->d_params.begin(); it != this->d_params.end(); it++) {
doubles.push_back(*it);
}
}
void cxxKineticsComp::mpi_unpack(int *ints, int *ii, double *doubles, int *dd)
{
extern cxxDictionary dictionary;
int i = *ii;
int d = *dd;
this->rate_name = dictionary.int2char(ints[i++]);
this->namecoef.mpi_unpack(ints, &i, doubles, &d);
this->tol = doubles[d++];
this->m = doubles[d++];
this->m0 = doubles[d++];
this->moles = doubles[d++];
int n = ints[i++];
this->d_params.clear();
for (int j = 0; j < n; j++) {
this->d_params.push_back(doubles[d++]);
}
*ii = i;
*dd = d;
}
#endif

View File

@ -28,6 +28,10 @@ public:
void read_raw(CParser& parser);
#ifdef USE_MPI
void mpi_unpack(int *ints, int *ii, double *doubles, int *dd);
void mpi_pack(std::vector<int>& ints, std::vector<double>& doubles);
#endif
protected:
char * rate_name;
cxxNameDouble namecoef;

View File

@ -345,3 +345,48 @@ void cxxKinetics::read_raw(CParser& parser)
parser.error_msg("Use_cvode not defined for KINETICS_RAW input.", CParser::OT_CONTINUE);
}
}
#ifdef USE_MPI
void cxxKinetics::mpi_pack(std::vector<int>& ints, std::vector<double>& doubles)
{
ints.push_back(this->n_user);
ints.push_back(this->kineticsComps.size());
for (std::list<cxxKineticsComp>::iterator it = this->kineticsComps.begin(); it != this->kineticsComps.end(); it++) {
it->mpi_pack(ints, doubles);
}
ints.push_back(this->steps.size());
for (std::vector<double>::iterator it = this->steps.begin(); it != this->steps.end(); it++) {
doubles.push_back(*it);
}
doubles.push_back(this->step_divide);
ints.push_back(this->rk);
ints.push_back(this->bad_step_max);
ints.push_back(this->use_cvode);
}
void cxxKinetics::mpi_unpack(int *ints, int *ii, double *doubles, int *dd)
{
int i = *ii;
int d = *dd;
this->n_user = ints[i++];
this->n_user_end = this->n_user;
this->description = " ";
int n = ints[i++];
this->kineticsComps.clear();
for (int j = 0; j < n; j++) {
cxxKineticsComp kc;
kc.mpi_unpack(ints, &i, doubles, &d);
this->kineticsComps.push_back(kc);
}
n = ints[i++];
this->steps.clear();
for (int j = 0; j < n; j++) {
this->steps.push_back(doubles[d++]);
}
this->step_divide = doubles[d++];
this->rk = ints[i++];
this->bad_step_max = ints[i++];
this->use_cvode = (bool) ints[i++];
*ii = i;
*dd = d;
}
#endif

View File

@ -35,6 +35,11 @@ public:
bool get_related_rate(void);
#ifdef USE_MPI
void cxxKinetics::mpi_unpack(int *ints, int *ii, double *doubles, int *dd);
void cxxKinetics::mpi_pack(std::vector<int>& ints, std::vector<double>& doubles);
#endif
protected:
std::list<cxxKineticsComp> kineticsComps;
std::vector<double> steps;

View File

@ -5,10 +5,12 @@
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
#endif
#include <iostream> // std::cout std::cerr
#include "Utils.h" // define first
#include "NameDouble.h"
#define EXTERNAL extern
#include "global.h"
#include "output.h"
#include "phqalloc.h"
#include "phrqproto.h"
#include <cassert> // assert
@ -288,3 +290,56 @@ void cxxNameDouble::add(const cxxNameDouble &old, double factor)
}
}
#ifdef USE_MPI
#include "Dictionary.h"
void cxxNameDouble::mpi_pack(std::vector<int>& ints, std::vector<double>& doubles) {
extern cxxDictionary dictionary;
ints.push_back( (*this).size() );
for (const_iterator it = (*this).begin(); it != (*this).end(); it++) {
assert(it->first != NULL);
int n = dictionary.string2int(it->first);
ints.push_back(n);
doubles.push_back(it->second);
}
}
void cxxNameDouble::mpi_pack(int *ints, int *ii, double *doubles, int *dd)
{
int i = *ii;
int d = *dd;
extern cxxDictionary dictionary;
//ints.push_back( (*this).size() );
ints[i++] = this->size();
for (const_iterator it = this->begin(); it != this->end(); it++) {
int n = dictionary.string2int(it->first);
if (n < 0) {
std::cerr << it->first << std::endl;
error_msg("Name in NameDouble was not defined in dictionary?\n", STOP);
}
//ints.push_back(n);
ints[i++] = n;
//doubles.push_back(it->second);
doubles[d++] = it->second;
}
*ii = i;
*dd = d;
}
void cxxNameDouble::mpi_unpack(int *ints, int *ii, double *doubles, int *dd)
{
int i = *ii;
int d = *dd;
extern cxxDictionary dictionary;
this->clear();
int count = ints[i++];
for (int j = 0; j < count; j++) {
int n = ints[i++];
assert(n >= 0);
std::string *str = dictionary.int2string(n);
if (str != NULL) {
char *cstr = string_hsave(str->c_str());
(*this)[cstr] = doubles[d++];
}
}
*ii = i;
*dd = d;
}
#endif

View File

@ -2,13 +2,13 @@
#define NAMEDOUBLE_H_INCLUDED
#define EXTERNAL extern
#include "global.h"
#include <cassert> // assert
#include <map> // std::map
#include <string> // std::string
#include <list> // std::list
#include <vector> // std::vector
#include "global.h"
#include "char_star.h"
#include "Parser.h"
class cxxNameDouble : public std::map <char *, double, CHARSTAR_LESS>
@ -46,6 +46,11 @@ public:
void add(const cxxNameDouble &old, double factor);
void mpi_pack(std::vector<int>& ints, std::vector<double>& doubles);
void mpi_pack(int *ints, int *ii, double *doubles, int *dd);
void mpi_unpack(int *ints, int *ii, double *doubles, int *dd);
enum ND_TYPE type;
protected:

View File

@ -189,3 +189,39 @@ void cxxPPassemblage::read_raw(CParser& parser)
}
// members that must be defined
}
#ifdef USE_MPI
/* ---------------------------------------------------------------------- */
void cxxPPassemblage::mpi_pack(std::vector<int>& ints, std::vector<double>& doubles)
/* ---------------------------------------------------------------------- */
{
/* int n_user; */
ints.push_back(this->n_user);
ints.push_back(this->ppAssemblageComps.size());
for (std::list<cxxPPassemblageComp>::iterator it = this->ppAssemblageComps.begin(); it != this->ppAssemblageComps.end(); it++) {
it->mpi_pack(ints, doubles);
}
this->eltList.mpi_pack(ints, doubles);
}
/* ---------------------------------------------------------------------- */
void cxxPPassemblage::mpi_unpack(int *ints, int *ii, double *doubles, int *dd)
/* ---------------------------------------------------------------------- */
{
int i = *ii;
int d = *dd;
/* int n_user; */
this->n_user = ints[i++];
this->n_user_end = this->n_user;
this->description = " ";
int count = ints[i++];
this->ppAssemblageComps.clear();
for (int n = 0; n < count; n++) {
cxxPPassemblageComp ppc;
ppc.mpi_unpack(ints, &i, doubles, &d);
this->ppAssemblageComps.push_back(ppc);
}
this->eltList.mpi_unpack(ints, &i, doubles, &d);
*ii = i;
*dd = d;
}
#endif

View File

@ -31,6 +31,11 @@ public:
void read_raw(CParser& parser);
#ifdef USE_MPI
void mpi_pack(std::vector<int>& ints, std::vector<double>& doubles);
void mpi_unpack(int *ints, int *ii, double *doubles, int *dd);
#endif
protected:
std::list<cxxPPassemblageComp> ppAssemblageComps;
cxxNameDouble eltList;

View File

@ -276,3 +276,33 @@ void cxxPPassemblageComp::read_raw(CParser& parser)
}
}
#ifdef USE_MPI
#include "Dictionary.h"
void cxxPPassemblageComp::mpi_pack(std::vector<int>& ints, std::vector<double>& doubles)
{
extern cxxDictionary dictionary;
ints.push_back(dictionary.string2int(this->name));
ints.push_back(dictionary.string2int(this->add_formula));
doubles.push_back(this->si);
doubles.push_back(this->moles);
doubles.push_back(this->delta);
doubles.push_back(this->initial_moles);
ints.push_back((int) this->dissolve_only);
}
void cxxPPassemblageComp::mpi_unpack(int *ints, int *ii, double *doubles, int *dd)
{
extern cxxDictionary dictionary;
int i = *ii;
int d = *dd;
this->name = dictionary.int2char(ints[i++]);
this->add_formula = dictionary.int2char(ints[i++]);
this->si = doubles[d++];
this->moles = doubles[d++];
this->delta = doubles[d++];
this->initial_moles = doubles[d++];
this->dissolve_only = (bool) ints[i++];
*ii = i;
*dd = d;
}
#endif

View File

@ -30,7 +30,10 @@ public:
void read_raw(CParser& parser);
struct phase *get_phase();
#ifdef USE_MPI
void mpi_pack(std::vector<int>& ints, std::vector<double>& doubles);
void mpi_unpack(int *ints, int *ii, double *doubles, int *dd);
#endif
protected:
char * name;
char *add_formula;

View File

@ -169,3 +169,37 @@ void cxxSSassemblage::read_raw(CParser& parser)
if (opt == CParser::OPT_EOF || opt == CParser::OPT_KEYWORD) break;
}
}
#ifdef USE_MPI
/* ---------------------------------------------------------------------- */
void cxxSSassemblage::mpi_pack(std::vector<int>& ints, std::vector<double>& doubles)
/* ---------------------------------------------------------------------- */
{
/* int n_user; */
ints.push_back(this->n_user);
ints.push_back(this->ssAssemblageSSs.size());
for (std::list<cxxSSassemblageSS>::iterator it = this->ssAssemblageSSs.begin(); it != this->ssAssemblageSSs.end(); it++) {
it->mpi_pack(ints, doubles);
}
}
/* ---------------------------------------------------------------------- */
void cxxSSassemblage::mpi_unpack(int *ints, int *ii, double *doubles, int *dd)
/* ---------------------------------------------------------------------- */
{
int i = *ii;
int d = *dd;
/* int n_user; */
this->n_user = ints[i++];
this->n_user_end = this->n_user;
this->description = " ";
int count = ints[i++];
this->ssAssemblageSSs.clear();
for (int n = 0; n < count; n++) {
cxxSSassemblageSS ssc;
ssc.mpi_unpack(ints, &i, doubles, &d);
this->ssAssemblageSSs.push_back(ssc);
}
*ii = i;
*dd = d;
}
#endif

View File

@ -31,6 +31,11 @@ public:
void read_raw(CParser& parser);
#ifdef USE_MPI
void mpi_pack(std::vector<int>& ints, std::vector<double>& doubles);
void mpi_unpack(int *ints, int *ii, double *doubles, int *dd);
#endif
protected:
std::list<cxxSSassemblageSS> ssAssemblageSSs;

View File

@ -441,3 +441,36 @@ void cxxSSassemblageSS::read_raw(CParser& parser)
}
}
#ifdef USE_MPI
#include "Dictionary.h"
void cxxSSassemblageSS::mpi_pack(std::vector<int>& ints, std::vector<double>& doubles)
{
extern cxxDictionary dictionary;
ints.push_back(dictionary.string2int(this->name));
this->comps.mpi_pack(ints, doubles);
doubles.push_back(this->a0);
doubles.push_back(this->a1);
doubles.push_back(this->ag0);
doubles.push_back(this->ag1);
ints.push_back((int) this->miscibility);
doubles.push_back(this->xb1);
doubles.push_back(this->xb2);
}
void cxxSSassemblageSS::mpi_unpack(int *ints, int *ii, double *doubles, int *dd)
{
extern cxxDictionary dictionary;
int i = *ii;
int d = *dd;
this->name = dictionary.int2char(ints[i++]);
this->comps.mpi_unpack(ints, &i, doubles, &d);
this->a0 = doubles[d++];
this->a1 = doubles[d++];
this->ag0 = doubles[d++];
this->ag1 = doubles[d++];
this->miscibility = (bool) ints[i++];
this->xb1 = doubles[d++];
this->xb2 = doubles[d++];
*ii = i;
*dd = d;
}
#endif

View File

@ -42,21 +42,18 @@ public:
void read_raw(CParser& parser);
#ifdef USE_MPI
void mpi_pack(std::vector<int>& ints, std::vector<double>& doubles);
void mpi_unpack(int *ints, int *ii, double *doubles, int *dd);
#endif
protected:
char *name;
//std::list<cxxSSassemblageSS> ppAssemblageSS;
cxxNameDouble comps;
//double total_moles;
//double dn;
double a0, a1;
double ag0, ag1;
//bool s_s_in;
bool miscibility;
//bool spinodal;
//double tk;
double xb1, xb2;
//SS_PARAMETER_TYPE type;
//double p[4];
public:

View File

@ -11,6 +11,7 @@
#include "global.h"
#include "phqalloc.h"
#include "phrqproto.h"
#include "output.h"
#include <cassert> // assert
#include <algorithm> // std::sort
@ -746,7 +747,258 @@ double cxxSolution::get_master_activity(char *string)const
return(it->second);
}
}
#ifdef USE_MPI
#include <mpi.h>
/* ---------------------------------------------------------------------- */
void cxxSolution::mpi_pack(std::vector<int>& ints, std::vector<double>& doubles)
/* ---------------------------------------------------------------------- */
{
/*
* Make list of list of ints and doubles from solution structure
* This list is not the complete structure, but only enough
* for batch-reaction, advection, and transport calculations
*/
ints.push_back(this->n_user);
doubles.push_back(this->tc);
doubles.push_back(this->ph);
doubles.push_back(this->pe);
doubles.push_back(this->mu);
doubles.push_back(this->ah2o);
doubles.push_back(this->total_h);
doubles.push_back(this->total_o);
doubles.push_back(this->cb);
doubles.push_back(this->mass_water);
doubles.push_back(this->total_alkalinity);
/*
* struct conc *totals;
*/
this->totals.mpi_pack(ints, doubles);
/*
* struct master_activity *master_activity;
*/
this->master_activity.mpi_pack(ints, doubles);
/*
* struct master_activity *species_gamma
*/
this->species_gamma.mpi_pack(ints, doubles);
/*
position = 0;
int i = ints.size();
int int_array[i];
int d = doubles.size();
double double_array[d];
for (int j = 0; j < i; j++) {
int_array[j] = ints[j];
}
for (int j = 0; j < d; j++) {
double_array[j] = ints[j];
}
MPI_Send(&max_size, 1, MPI_INT, task_number, 0, MPI_COMM_WORLD);
MPI_Pack(&i, 1, MPI_INT, buffer, max_size, &position, MPI_COMM_WORLD);
MPI_Pack(&int_array, i, MPI_INT, buffer, max_size, &position, MPI_COMM_WORLD);
MPI_Pack(&d, 1, MPI_INT, buffer, max_size, &position, MPI_COMM_WORLD);
MPI_Pack(&double_array, d, MPI_DOUBLE, buffer, max_size, &position, MPI_COMM_WORLD);
MPI_Send(buffer, position, MPI_PACKED, task_number, 0, MPI_COMM_WORLD);
buffer = (void *) free_check_null(buffer);
*/
}
/* ---------------------------------------------------------------------- */
void cxxSolution::mpi_unpack(int *ints, int *ii, double *doubles, int *dd)
/* ---------------------------------------------------------------------- */
{
int i = *ii;
int d = *dd;
this->n_user = ints[i++];
this->n_user_end = this->n_user;
this->description = " ";
this->tc = doubles[d++];
this->ph = doubles[d++];
this->pe = doubles[d++];
this->mu = doubles[d++];
this->ah2o = doubles[d++];
this->total_h = doubles[d++];
this->total_o = doubles[d++];
this->cb = doubles[d++];
this->mass_water = doubles[d++];
this->total_alkalinity = doubles[d++];
/*
* struct conc *totals;
*/
this->totals.mpi_unpack(ints, &i, doubles, &d);
/*
* struct master_activity *master_activity;
*/
this->master_activity.mpi_unpack(ints, &i, doubles, &d);
/*
* struct master_activity *species_gamma;
*/
this->species_gamma.mpi_unpack(ints, &i, doubles, &d);
*ii = i;
*dd = d;
}
/* ---------------------------------------------------------------------- */
void cxxSolution::mpi_send(int task_number)
/* ---------------------------------------------------------------------- */
{
//int count_totals, count_totals_position, count_activity, count_activity_position;
int max_size, member_size, position;
//int ints[MESSAGE_MAX_NUMBERS];
//double doubles[MESSAGE_MAX_NUMBERS];
void *buffer;
std::vector<int> ints;
std::vector<double> doubles;
/*
* Make list of list of ints and doubles from solution structure
* This list is not the complete structure, but only enough
* for batch-reaction, advection, and transport calculations
*/
ints.push_back(this->n_user);
/* int n_user_end; */
/* char *description; */
doubles.push_back(this->tc);
doubles.push_back(this->ph);
doubles.push_back(this->pe);
doubles.push_back(this->mu);
doubles.push_back(this->ah2o);
doubles.push_back(this->total_h);
doubles.push_back(this->total_o);
doubles.push_back(this->cb);
doubles.push_back(this->mass_water);
doubles.push_back(this->total_alkalinity);
/*
* struct conc *totals;
*/
this->totals.mpi_pack(ints, doubles);
/*
* struct master_activity *master_activity;
*/
this->master_activity.mpi_pack(ints, doubles);
/*
* struct master_activity *species_gamma
*/
this->species_gamma.mpi_pack(ints, doubles);
/* int count_isotopes; */
/* struct isotope *isotopes; */
if (input_error > 0) {
std::string errstr("Stopping due to errors\n");
error_msg(errstr.c_str(), STOP);
}
/*
* Malloc space for a buffer
*/
max_size = 0;
//MPI_Pack_size(MESSAGE_MAX_NUMBERS, MPI_INT, MPI_COMM_WORLD, &member_size);
MPI_Pack_size(ints.size(), MPI_INT, MPI_COMM_WORLD, &member_size);
max_size += member_size;
//MPI_Pack_size(MESSAGE_MAX_NUMBERS, MPI_DOUBLE, MPI_COMM_WORLD, &member_size);
MPI_Pack_size(doubles.size(), MPI_DOUBLE, MPI_COMM_WORLD, &member_size);
max_size += member_size + 10;
buffer = PHRQ_malloc(max_size);
if (buffer == NULL) malloc_error();
/*
* Send message to processor
*/
position = 0;
int i = ints.size();
int int_array[i];
int d = doubles.size();
double double_array[d];
for (int j = 0; j < i; j++) {
int_array[j] = ints[j];
}
for (int j = 0; j < d; j++) {
double_array[j] = doubles[j];
}
MPI_Send(&max_size, 1, MPI_INT, task_number, 0, MPI_COMM_WORLD);
MPI_Pack(&i, 1, MPI_INT, buffer, max_size, &position, MPI_COMM_WORLD);
MPI_Pack(&int_array, i, MPI_INT, buffer, max_size, &position, MPI_COMM_WORLD);
MPI_Pack(&d, 1, MPI_INT, buffer, max_size, &position, MPI_COMM_WORLD);
MPI_Pack(&double_array, d, MPI_DOUBLE, buffer, max_size, &position, MPI_COMM_WORLD);
MPI_Send(buffer, position, MPI_PACKED, task_number, 0, MPI_COMM_WORLD);
buffer = (void *) free_check_null(buffer);
}
/* ---------------------------------------------------------------------- */
void cxxSolution::mpi_recv(int task_number)
/* ---------------------------------------------------------------------- */
{
MPI_Status mpi_status;
/*
* Malloc space for a buffer
*/
int max_size;
// buffer size
MPI_Recv(&max_size, 1, MPI_INT, task_number, 0, MPI_COMM_WORLD, &mpi_status);
void *buffer = PHRQ_malloc(max_size);
if (buffer == NULL) malloc_error();
/*
* Recieve solution
*/
MPI_Recv(buffer, max_size, MPI_PACKED, task_number, 0, MPI_COMM_WORLD, &mpi_status);
int position = 0;
int msg_size;
MPI_Get_count(&mpi_status, MPI_PACKED, &msg_size);
/* Unpack ints */
int count_ints;
MPI_Unpack(buffer, msg_size, &position, &count_ints, 1, MPI_INT, MPI_COMM_WORLD);
int ints[count_ints];
MPI_Unpack(buffer, msg_size, &position, ints, count_ints, MPI_INT, MPI_COMM_WORLD);
/* Unpack doubles */
int count_doubles;
MPI_Unpack(buffer, msg_size, &position, &count_doubles, 1, MPI_INT, MPI_COMM_WORLD);
double doubles[count_doubles];
MPI_Unpack(buffer, msg_size, &position, doubles, count_doubles, MPI_DOUBLE, MPI_COMM_WORLD);
buffer = free_check_null(buffer);
/*
* Make list of list of ints and doubles from solution structure
* This list is not the complete structure, but only enough
* for batch-reaction, advection, and transport calculations
*/
int i = 0;
int d = 0;
/* int new_def; */
/* solution_ptr->new_def = FALSE; */
/* int n_user; */
this->n_user = ints[i++];
/* int n_user_end; */
this->n_user_end = this->n_user;
/*debugging*/
//this->description = (char *) free_check_null(this->description);
//this->description = string_duplicate(" ");
this->description = " ";
this->tc = doubles[d++];
this->ph = doubles[d++];
this->pe = doubles[d++];
this->mu = doubles[d++];
this->ah2o = doubles[d++];
this->total_h = doubles[d++];
this->total_o = doubles[d++];
this->cb = doubles[d++];
this->mass_water = doubles[d++];
this->total_alkalinity = 0;
/*
* struct conc *totals;
*/
this->totals.mpi_unpack(ints, &i, doubles, &d);
/*
* struct master_activity *master_activity;
*/
this->master_activity.mpi_unpack(ints, &i, doubles, &d);
/*
* struct master_activity *species_gamma;
*/
this->species_gamma.mpi_unpack(ints, &i, doubles, &d);
}
#endif
void cxxSolution::set_master_activity(char *string, double d)
{
this->master_activity[string] = d;

View File

@ -85,6 +85,12 @@ public:
void add(const cxxSolution &sol, double intensive, double extensive);
#ifdef USE_MPI
void mpi_pack(std::vector<int>& ints, std::vector<double>& doubles);
void mpi_unpack(int *ints, int *ii, double *doubles, int *dd);
void mpi_send(int task_number);
void mpi_recv(int task_number);
#endif
protected:
double tc;
double ph;

View File

@ -13,11 +13,12 @@ public:
cxxSolutionIsotope(struct isotope *isotope_ptr);
~cxxSolutionIsotope(void);
/*
enum STATUS {
ERROR = 0,
OK = 1
};
*/
//cxxSolutionIsotope::STATUS read(CParser& parser);
static struct isotope * list2isotope(std::list<cxxSolutionIsotope> &t);

View File

@ -5,6 +5,8 @@
#pragma warning(disable : 4786) // disable truncation warning (Only used by debugger)
#endif
#include <fstream>
#include <iostream> // std::cout std::cerr
#include "Utils.h" // define first
#include "StorageBin.h"
#include "Solution.h"
@ -595,3 +597,221 @@ struct system *cxxStorageBin::cxxStorageBin2system(int n)
}
return system_ptr;
}
#ifdef USE_MPI
#include <mpi.h>
void cxxStorageBin::mpi_send(int n, int task_number)
{
//
// Send data for system n to task_number
//
std::vector<int> ints;
std::vector<double> doubles;
// Solution
if (this->getSolution(n) != NULL) {
ints.push_back(1);
this->getSolution(n)->mpi_pack(ints, doubles);
} else {
ints.push_back(0);
}
//std::cerr << "Packed Solution" << std::endl;
// Exchanger
if (this->getExchange(n) != NULL) {
ints.push_back(1);
this->getExchange(n)->mpi_pack(ints, doubles);
} else {
ints.push_back(0);
}
//std::cerr << "Packed Exchange" << std::endl;
// GasPhase
if (this->getGasPhase(n) != NULL) {
ints.push_back(1);
this->getGasPhase(n)->mpi_pack(ints, doubles);
} else {
ints.push_back(0);
}
//std::cerr << "Packed GasPhase" << std::endl;
// Kinetics
if (this->getKinetics(n) != NULL) {
ints.push_back(1);
this->getKinetics(n)->mpi_pack(ints, doubles);
} else {
ints.push_back(0);
}
//std::cerr << "Packed Kinetics" << std::endl;
// PPassemblages
if (this->getPPassemblage(n) != NULL) {
ints.push_back(1);
this->getPPassemblage(n)->mpi_pack(ints, doubles);
} else {
ints.push_back(0);
}
//std::cerr << "Packed PPassemblage" << std::endl;
// SSassemblages
if (this->getSSassemblage(n) != NULL) {
ints.push_back(1);
this->getSSassemblage(n)->mpi_pack(ints, doubles);
} else {
ints.push_back(0);
}
//std::cerr << "Packed SSassemblage" << std::endl;
// Surfaces
if (this->getSurface(n) != NULL) {
ints.push_back(1);
this->getSurface(n)->mpi_pack(ints, doubles);
} else {
ints.push_back(0);
}
//std::cerr << "Packed Surface" << std::endl;
// Pack data
int max_size = 0;
int member_size = 0;
MPI_Pack_size(ints.size(), MPI_INT, MPI_COMM_WORLD, &member_size);
max_size += member_size;
MPI_Pack_size(doubles.size(), MPI_DOUBLE, MPI_COMM_WORLD, &member_size);
max_size += member_size + 10;
void *buffer = PHRQ_malloc(max_size);
if (buffer == NULL) malloc_error();
// Convert to arrays
int i = ints.size();
int int_array[i];
int d = doubles.size();
double double_array[d];
for (int j = 0; j < i; j++) {
int_array[j] = ints[j];
//std::cerr << "Sending ints " << j << " value " << ints[j] << std::endl;
}
for (int j = 0; j < d; j++) {
double_array[j] = doubles[j];
//std::cerr << "Sending doubles " << j << " value " << doubles[j] << std::endl;
}
/*
* Send message to processor
*/
int position = 0;
MPI_Send(&max_size, 1, MPI_INT, task_number, 0, MPI_COMM_WORLD);
MPI_Pack(&i, 1, MPI_INT, buffer, max_size, &position, MPI_COMM_WORLD);
MPI_Pack(&int_array, i, MPI_INT, buffer, max_size, &position, MPI_COMM_WORLD);
MPI_Pack(&d, 1, MPI_INT, buffer, max_size, &position, MPI_COMM_WORLD);
MPI_Pack(&double_array, d, MPI_DOUBLE, buffer, max_size, &position, MPI_COMM_WORLD);
MPI_Send(buffer, position, MPI_PACKED, task_number, 0, MPI_COMM_WORLD);
buffer = (void *) free_check_null(buffer);
}
/* ---------------------------------------------------------------------- */
void cxxStorageBin::mpi_recv(int task_number)
/* ---------------------------------------------------------------------- */
{
MPI_Status mpi_status;
/*
* Malloc space for a buffer
*/
int max_size;
// buffer size
MPI_Recv(&max_size, 1, MPI_INT, task_number, 0, MPI_COMM_WORLD, &mpi_status);
void *buffer = PHRQ_malloc(max_size);
if (buffer == NULL) malloc_error();
/*
* Recieve system
*/
MPI_Recv(buffer, max_size, MPI_PACKED, task_number, 0, MPI_COMM_WORLD, &mpi_status);
int position = 0;
int msg_size;
MPI_Get_count(&mpi_status, MPI_PACKED, &msg_size);
/* Unpack ints */
int count_ints;
MPI_Unpack(buffer, msg_size, &position, &count_ints, 1, MPI_INT, MPI_COMM_WORLD);
int ints[count_ints];
MPI_Unpack(buffer, msg_size, &position, ints, count_ints, MPI_INT, MPI_COMM_WORLD);
/* Unpack doubles */
int count_doubles;
MPI_Unpack(buffer, msg_size, &position, &count_doubles, 1, MPI_INT, MPI_COMM_WORLD);
double doubles[count_doubles];
MPI_Unpack(buffer, msg_size, &position, doubles, count_doubles, MPI_DOUBLE, MPI_COMM_WORLD);
buffer = free_check_null(buffer);
#ifdef SKIP
for (int j = 0; j < count_ints; j++) {
std::cerr << "Recving ints " << j << " value " << ints[j] << std::endl;
}
for (int j = 0; j < count_doubles; j++) {
std::cerr << "Recving doubles " << j << " value " << doubles[j] << std::endl;
}
#endif
/*
* Make list of list of ints and doubles from solution structure
* This list is not the complete structure, but only enough
* for batch-reaction, advection, and transport calculations
*/
int i = 0;
int d = 0;
// Solution
if (ints[i++] != 0) {
cxxSolution entity;
entity.mpi_unpack(ints, &i, doubles, &d);
this->setSolution(entity.get_n_user(), &entity);
}
//std::cerr << "Unpacked Solution" << std::endl;
// Exchanger
if (ints[i++] != 0) {
cxxExchange entity;
entity.mpi_unpack(ints, &i, doubles, &d);
this->setExchange(entity.get_n_user(), &entity);
}
//std::cerr << "Unpacked Exchange" << std::endl;
// GasPhase
if (ints[i++] != 0) {
cxxGasPhase entity;
entity.mpi_unpack(ints, &i, doubles, &d);
this->setGasPhase(entity.get_n_user(), &entity);
}
//std::cerr << "Unpacked GasPhase" << std::endl;
// Kinetics
if (ints[i++] != 0) {
cxxKinetics entity;
entity.mpi_unpack(ints, &i, doubles, &d);
this->setKinetics(entity.get_n_user(), &entity);
}
//std::cerr << "Unpacked Kinetics" << std::endl;
// PPassemblage
if (ints[i++] != 0) {
cxxPPassemblage entity;
entity.mpi_unpack(ints, &i, doubles, &d);
this->setPPassemblage(entity.get_n_user(), &entity);
}
//std::cerr << "Unpacked PPassemblage" << std::endl;
// SSassemblage
if (ints[i++] != 0) {
cxxSSassemblage entity;
entity.mpi_unpack(ints, &i, doubles, &d);
this->setSSassemblage(entity.get_n_user(), &entity);
}
//std::cerr << "Unpacked SSassemblage" << std::endl;
// Surfaces
if (ints[i++] != 0) {
cxxSurface entity;
entity.mpi_unpack(ints, &i, doubles, &d);
this->setSurface(entity.get_n_user(), &entity);
}
//std::cerr << "Unpacked Surface" << std::endl;
}
#endif

View File

@ -139,6 +139,11 @@ public:
cxxSolution *mix_cxxSolutions(cxxMix &mixmap);
#ifdef USE_MPI
void mpi_send(int n, int task_number);
void mpi_recv(int task_number);
#endif
protected:
// Tidied classes
std::map<int, cxxSolution> Solutions;

View File

@ -7,7 +7,7 @@
#include "Utils.h" // define first
#include "Surface.h"
#include "SurfComp.h"
#include "SurfaceComp.h"
#define EXTERNAL extern
#include "global.h"
#include "phqalloc.h"
@ -52,13 +52,13 @@ cxxNumKeyword()
thickness = surface_ptr->thickness;
// Surface components
for (i = 0; i < surface_ptr->count_comps; i++) {
cxxSurfComp ec(&(surface_ptr->comps[i]));
surfComps.push_back(ec);
cxxSurfaceComp ec(&(surface_ptr->comps[i]));
surfaceComps.push_back(ec);
}
// Surface charge
for (i = 0; i < surface_ptr->count_charge; i++) {
cxxSurfCharge ec(&(surface_ptr->charge[i]));
surfCharges.push_back(ec);
cxxSurfaceCharge ec(&(surface_ptr->charge[i]));
surfaceCharges.push_back(ec);
}
}
@ -68,7 +68,7 @@ cxxSurface::~cxxSurface()
bool cxxSurface::get_related_phases()
{
for (std::list<cxxSurfComp>::const_iterator it = this->surfComps.begin(); it != this->surfComps.end(); ++it) {
for (std::list<cxxSurfaceComp>::const_iterator it = this->surfaceComps.begin(); it != this->surfaceComps.end(); ++it) {
if (it->get_phase_name() == NULL) continue;
return(true);
}
@ -77,7 +77,7 @@ bool cxxSurface::get_related_phases()
bool cxxSurface::get_related_rate()
{
for (std::list<cxxSurfComp>::const_iterator it = this->surfComps.begin(); it != this->surfComps.end(); ++it) {
for (std::list<cxxSurfaceComp>::const_iterator it = this->surfaceComps.begin(); it != this->surfaceComps.end(); ++it) {
if (it->get_rate_name() == NULL) continue;
return(true);
}
@ -95,7 +95,7 @@ struct surface *cxxSurface::cxxSurface2surface()
surface_ptr->n_user = this->n_user;
surface_ptr->n_user_end = this->n_user_end;
surface_ptr->new_def = FALSE;
surface_ptr->diffuse_layer = this->diffuse_layer;
surface_ptr->diffuse_layer = this->diffuse_layer;
surface_ptr->edl = this->edl;
surface_ptr->only_counter_ions = this->only_counter_ions;
surface_ptr->donnan = this->donnan;
@ -108,15 +108,19 @@ struct surface *cxxSurface::cxxSurface2surface()
surface_ptr->transport = FALSE;
// Surface comps
surface_ptr->count_comps = this->surfComps.size();
surface_ptr->count_comps = this->surfaceComps.size();
surface_ptr->comps = (struct surface_comp *) free_check_null(surface_ptr->comps);
surface_ptr->comps = cxxSurfComp::cxxSurfComp2surface_comp(this->surfComps);
surface_ptr->comps = cxxSurfaceComp::cxxSurfaceComp2surface_comp(this->surfaceComps);
// Surface charge
surface_ptr->count_charge = this->surfCharges.size();
surface_ptr->charge = (struct surface_charge *) free_check_null(surface_ptr->charge);
surface_ptr->charge = cxxSurfCharge::cxxSurfCharge2surface_charge(this->surfCharges);
surface_ptr->charge = (struct surface_charge *) free_check_null(surface_ptr->charge);
if (surface_ptr->edl == TRUE) {
surface_ptr->count_charge = this->surfaceCharges.size();
surface_ptr->charge = cxxSurfaceCharge::cxxSurfaceCharge2surface_charge(this->surfaceCharges);
} else {
surface_ptr->count_charge = 0;
}
return(surface_ptr);
}
@ -153,14 +157,14 @@ void cxxSurface::dump_xml(std::ostream& s_oss, unsigned int indent)const
s_oss << indent1;
s_oss << "<component " << std::endl;
{
for (std::list<cxxSurfComp>::const_iterator it = this->surfComps.begin(); it != this->surfComps.end(); ++it) {
for (std::list<cxxSurfaceComp>::const_iterator it = this->surfaceComps.begin(); it != this->surfaceComps.end(); ++it) {
it->dump_xml(s_oss, indent + 2);
}
}
// surface charge structures
s_oss << indent1;
s_oss << "<charge_component " << std::endl;
for (std::list<cxxSurfCharge>::const_iterator it = surfCharges.begin(); it != surfCharges.end(); ++it) {
for (std::list<cxxSurfaceCharge>::const_iterator it = surfaceCharges.begin(); it != surfaceCharges.end(); ++it) {
it->dump_xml(s_oss, indent + 2);
}
@ -196,15 +200,15 @@ void cxxSurface::dump_raw(std::ostream& s_oss, unsigned int indent)const
s_oss << indent1;
s_oss << "-thickness " << this->thickness << std::endl;
// surfComps structures
for (std::list<cxxSurfComp>::const_iterator it = surfComps.begin(); it != surfComps.end(); ++it) {
// surfaceComps structures
for (std::list<cxxSurfaceComp>::const_iterator it = surfaceComps.begin(); it != surfaceComps.end(); ++it) {
s_oss << indent1;
s_oss << "-component" << std::endl;
it->dump_raw(s_oss, indent + 2);
}
// surface charge structures
{
for (std::list<cxxSurfCharge>::const_iterator it = surfCharges.begin(); it != surfCharges.end(); ++it) {
for (std::list<cxxSurfaceCharge>::const_iterator it = surfaceCharges.begin(); it != surfaceCharges.end(); ++it) {
s_oss << indent1;
s_oss << "-charge_component " << std::endl;
it->dump_raw(s_oss, indent + 2);
@ -323,18 +327,18 @@ void cxxSurface::read_raw(CParser& parser)
case 5: // component
{
cxxSurfComp ec;
cxxSurfaceComp ec;
ec.read_raw(parser);
this->surfComps.push_back(ec);
this->surfaceComps.push_back(ec);
}
useLastLine = true;
break;
case 6: // charge_component
{
cxxSurfCharge ec;
cxxSurfaceCharge ec;
ec.read_raw(parser);
this->surfCharges.push_back(ec);
this->surfaceCharges.push_back(ec);
}
useLastLine = true;
break;
@ -364,3 +368,58 @@ void cxxSurface::read_raw(CParser& parser)
parser.error_msg("Thickness not defined for SURFACE_RAW input.", CParser::OT_CONTINUE);
}
}
#ifdef USE_MPI
/* ---------------------------------------------------------------------- */
void cxxSurface::mpi_pack(std::vector<int>& ints, std::vector<double>& doubles)
/* ---------------------------------------------------------------------- */
{
/* int n_user; */
ints.push_back(this->n_user);
ints.push_back(this->surfaceComps.size());
for (std::list<cxxSurfaceComp>::iterator it = this->surfaceComps.begin(); it != this->surfaceComps.end(); it++) {
it->mpi_pack(ints, doubles);
}
ints.push_back(this->surfaceCharges.size());
for (std::list<cxxSurfaceCharge>::iterator it = this->surfaceCharges.begin(); it != this->surfaceCharges.end(); it++) {
it->mpi_pack(ints, doubles);
}
ints.push_back((int) this->diffuse_layer);
ints.push_back((int) this->edl);
ints.push_back((int) this->only_counter_ions);
ints.push_back((int) this->donnan);
doubles.push_back(this->thickness);
}
/* ---------------------------------------------------------------------- */
void cxxSurface::mpi_unpack(int *ints, int *ii, double *doubles, int *dd)
/* ---------------------------------------------------------------------- */
{
int i = *ii;
int d = *dd;
/* int n_user; */
this->n_user = ints[i++];
this->n_user_end = this->n_user;
this->description = " ";
int count = ints[i++];
this->surfaceComps.clear();
for (int n = 0; n < count; n++) {
cxxSurfaceComp sc;
sc.mpi_unpack(ints, &i, doubles, &d);
this->surfaceComps.push_back(sc);
}
count = ints[i++];
this->surfaceCharges.clear();
for (int n = 0; n < count; n++) {
cxxSurfaceCharge sc;
sc.mpi_unpack(ints, &i, doubles, &d);
this->surfaceCharges.push_back(sc);
}
this->diffuse_layer = (bool) ints[i++];
this->edl = (bool) ints[i++];
this->only_counter_ions = (bool) ints[i++];
this->donnan = (bool) ints[i++];
this->thickness = doubles[d++];
*ii = i;
*dd = d;
}
#endif

View File

@ -11,8 +11,8 @@
#include <vector> // std::vector
#include "char_star.h"
#include "SurfComp.h"
#include "SurfCharge.h"
#include "SurfaceComp.h"
#include "SurfaceCharge.h"
class cxxSurface : public cxxNumKeyword
{
@ -24,7 +24,7 @@ public:
struct surface *cxxSurface2surface();
struct surf_comp *cxxSurfComp2surf_comp();
struct surf_comp *cxxSurfaceComp2surf_comp();
void dump_xml(std::ostream& os, unsigned int indent = 0)const;
@ -36,10 +36,14 @@ public:
bool get_related_rate(void);
#ifdef USE_MPI
void mpi_pack(std::vector<int>& ints, std::vector<double>& doubles);
void mpi_unpack(int *ints, int *ii, double *doubles, int *dd);
#endif
protected:
std::list<cxxSurfComp> surfComps;
std::list<cxxSurfCharge> surfCharges;
std::list<cxxSurfaceComp> surfaceComps;
std::list<cxxSurfaceCharge> surfaceCharges;
bool diffuse_layer;
bool edl;
bool only_counter_ions;

View File

@ -1,4 +1,4 @@
// SurfCharge.cxx: implementation of the cxxSurfCharge class.
// SurfaceCharge.cxx: implementation of the cxxSurfaceCharge class.
//
//////////////////////////////////////////////////////////////////////
#ifdef _DEBUG
@ -6,7 +6,7 @@
#endif
#include "Utils.h" // define first
#include "SurfCharge.h"
#include "SurfaceCharge.h"
#define EXTERNAL extern
#include "global.h"
#include "output.h"
@ -19,9 +19,9 @@
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
cxxSurfCharge::cxxSurfCharge()
cxxSurfaceCharge::cxxSurfaceCharge()
//
// default constructor for cxxSurfCharge
// default constructor for cxxSurfaceCharge
//
{
name = NULL;
@ -33,9 +33,9 @@ cxxSurfCharge::cxxSurfCharge()
diffuse_layer_totals.type = cxxNameDouble::ND_ELT_MOLES;
}
cxxSurfCharge::cxxSurfCharge(struct surface_charge *surf_charge_ptr)
cxxSurfaceCharge::cxxSurfaceCharge(struct surface_charge *surf_charge_ptr)
//
// constructor for cxxSurfCharge from struct surface_charge
// constructor for cxxSurfaceCharge from struct surface_charge
//
:
diffuse_layer_totals(surf_charge_ptr->diffuse_layer_totals)
@ -48,11 +48,11 @@ diffuse_layer_totals(surf_charge_ptr->diffuse_layer_totals)
la_psi = surf_charge_ptr->la_psi;
}
cxxSurfCharge::~cxxSurfCharge()
cxxSurfaceCharge::~cxxSurfaceCharge()
{
}
struct master *cxxSurfCharge::get_psi_master()
struct master *cxxSurfaceCharge::get_psi_master()
{
struct master *master_ptr = NULL;
std::string str = this->name;
@ -68,16 +68,16 @@ struct master *cxxSurfCharge::get_psi_master()
return(master_ptr);
}
struct surface_charge *cxxSurfCharge::cxxSurfCharge2surface_charge(std::list<cxxSurfCharge>& el)
struct surface_charge *cxxSurfaceCharge::cxxSurfaceCharge2surface_charge(std::list<cxxSurfaceCharge>& el)
//
// Builds surface_charge structure from of cxxSurfCharge
// Builds surface_charge structure from of cxxSurfaceCharge
//
{
struct surface_charge *surf_charge_ptr = (struct surface_charge *) PHRQ_malloc((size_t) (el.size() * sizeof(struct surface_charge)));
if (surf_charge_ptr == NULL) malloc_error();
int i = 0;
for (std::list<cxxSurfCharge>::iterator it = el.begin(); it != el.end(); ++it) {
for (std::list<cxxSurfaceCharge>::iterator it = el.begin(); it != el.end(); ++it) {
surf_charge_ptr[i].name = it->name;
surf_charge_ptr[i].specific_area = it->specific_area;
surf_charge_ptr[i].grams = it->grams;
@ -93,7 +93,7 @@ struct surface_charge *cxxSurfCharge::cxxSurfCharge2surface_charge(std::list<cxx
return(surf_charge_ptr);
}
void cxxSurfCharge::dump_xml(std::ostream& s_oss, unsigned int indent)const
void cxxSurfaceCharge::dump_xml(std::ostream& s_oss, unsigned int indent)const
{
//const char ERR_MESSAGE[] = "Packing surf_charge message: %s, element not found\n";
unsigned int i;
@ -119,7 +119,7 @@ void cxxSurfCharge::dump_xml(std::ostream& s_oss, unsigned int indent)const
}
void cxxSurfCharge::dump_raw(std::ostream& s_oss, unsigned int indent)const
void cxxSurfaceCharge::dump_raw(std::ostream& s_oss, unsigned int indent)const
{
//const char ERR_MESSAGE[] = "Packing surf_charge message: %s, element not found\n";
unsigned int i;
@ -145,7 +145,7 @@ void cxxSurfCharge::dump_raw(std::ostream& s_oss, unsigned int indent)const
}
void cxxSurfCharge::read_raw(CParser& parser)
void cxxSurfaceCharge::read_raw(CParser& parser)
{
std::string str;
@ -264,7 +264,7 @@ void cxxSurfCharge::read_raw(CParser& parser)
case 6: // diffuse_layer_totals
if ( this->diffuse_layer_totals.read_raw(parser, next_char) != CParser::PARSER_OK) {
parser.incr_input_error();
parser.error_msg("Expected element name and molality for SurfCharge diffuse_layer_totals.", CParser::OT_CONTINUE);
parser.error_msg("Expected element name and molality for SurfaceCharge diffuse_layer_totals.", CParser::OT_CONTINUE);
}
opt_save = 6;
break;
@ -275,26 +275,56 @@ void cxxSurfCharge::read_raw(CParser& parser)
// members that must be defined
if (name_defined == false) {
parser.incr_input_error();
parser.error_msg("Name not defined for SurfCharge input.", CParser::OT_CONTINUE);
parser.error_msg("Name not defined for SurfaceCharge input.", CParser::OT_CONTINUE);
}
if (specific_area_defined == false) {
parser.incr_input_error();
parser.error_msg("Specific_area not defined for SurfCharge input.", CParser::OT_CONTINUE);
parser.error_msg("Specific_area not defined for SurfaceCharge input.", CParser::OT_CONTINUE);
}
if (grams_defined == false) {
parser.incr_input_error();
parser.error_msg("Grams not defined for SurfCharge input.", CParser::OT_CONTINUE);
parser.error_msg("Grams not defined for SurfaceCharge input.", CParser::OT_CONTINUE);
}
if (charge_balance_defined == false) {
parser.incr_input_error();
parser.error_msg("Charge_balance not defined for SurfCharge input.", CParser::OT_CONTINUE);
parser.error_msg("Charge_balance not defined for SurfaceCharge input.", CParser::OT_CONTINUE);
}
if (mass_water_defined == false) {
parser.incr_input_error();
parser.error_msg("Mass_water not defined for SurfCharge input.", CParser::OT_CONTINUE);
parser.error_msg("Mass_water not defined for SurfaceCharge input.", CParser::OT_CONTINUE);
}
if (la_psi_defined == false) {
parser.incr_input_error();
parser.error_msg("La_psi not defined for SurfCharge input.", CParser::OT_CONTINUE);
parser.error_msg("La_psi not defined for SurfaceCharge input.", CParser::OT_CONTINUE);
}
}
#ifdef USE_MPI
#include "Dictionary.h"
void cxxSurfaceCharge::mpi_pack(std::vector<int>& ints, std::vector<double>& doubles)
{
extern cxxDictionary dictionary;
ints.push_back(dictionary.string2int(this->name));
doubles.push_back(this->specific_area);
doubles.push_back(this->grams);
doubles.push_back(this->charge_balance);
doubles.push_back(this->mass_water);
doubles.push_back(this->la_psi);
this->diffuse_layer_totals.mpi_pack(ints, doubles);
}
void cxxSurfaceCharge::mpi_unpack(int *ints, int *ii, double *doubles, int *dd)
{
extern cxxDictionary dictionary;
int i = *ii;
int d = *dd;
this->name = dictionary.int2char(ints[i++]);
this->specific_area = doubles[d++];
this->grams = doubles[d++];
this->charge_balance = doubles[d++];
this->mass_water = doubles[d++];
this->la_psi = doubles[d++];
this->diffuse_layer_totals.mpi_unpack(ints, &i, doubles, &d);
*ii = i;
*dd = d;
}
#endif

View File

@ -1,5 +1,5 @@
#if !defined(SURFCHARGE_H_INCLUDED)
#define SURFCHARGE_H_INCLUDED
#if !defined(SURFACECHARGE_H_INCLUDED)
#define SURFACECHARGE_H_INCLUDED
#include "NameDouble.h"
#define EXTERNAL extern
@ -12,19 +12,19 @@
#include "char_star.h"
class cxxSurfCharge
class cxxSurfaceCharge
{
public:
cxxSurfCharge();
cxxSurfCharge(struct surface_charge *);
~cxxSurfCharge();
cxxSurfaceCharge();
cxxSurfaceCharge(struct surface_charge *);
~cxxSurfaceCharge();
struct master *get_psi_master();
static struct surface_charge *cxxSurfCharge2surface_charge(std::list<cxxSurfCharge>& el);
static struct surface_charge *cxxSurfaceCharge2surface_charge(std::list<cxxSurfaceCharge>& el);
void dump_xml(std::ostream& os, unsigned int indent = 0)const;
@ -32,6 +32,11 @@ public:
void read_raw(CParser& parser);
#ifdef USE_MPI
void mpi_pack(std::vector<int>& ints, std::vector<double>& doubles);
void mpi_unpack(int *ints, int *ii, double *doubles, int *dd);
#endif
protected:
char * name;
double specific_area;
@ -47,4 +52,4 @@ public:
};
#endif // !defined(SURFCHARGE_H_INCLUDED)
#endif // !defined(SURFACECHARGE_H_INCLUDED)

View File

@ -1,4 +1,4 @@
// SurfComp.cxx: implementation of the cxxSurfComp class.
// SurfaceComp.cxx: implementation of the cxxSurfaceComp class.
//
//////////////////////////////////////////////////////////////////////
#ifdef _DEBUG
@ -6,7 +6,7 @@
#endif
#include "Utils.h" // define first
#include "SurfComp.h"
#include "SurfaceComp.h"
#define EXTERNAL extern
#include "global.h"
#include "phqalloc.h"
@ -19,9 +19,9 @@
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
cxxSurfComp::cxxSurfComp()
cxxSurfaceComp::cxxSurfaceComp()
//
// default constructor for cxxSurfComp
// default constructor for cxxSurfaceComp
//
{
formula = NULL;
@ -35,9 +35,9 @@ cxxSurfComp::cxxSurfComp()
rate_name = NULL;
}
cxxSurfComp::cxxSurfComp(struct surface_comp *surf_comp_ptr)
cxxSurfaceComp::cxxSurfaceComp(struct surface_comp *surf_comp_ptr)
//
// constructor for cxxSurfComp from struct surface_comp
// constructor for cxxSurfaceComp from struct surface_comp
//
:
totals(surf_comp_ptr->totals)
@ -52,11 +52,11 @@ totals(surf_comp_ptr->totals)
rate_name = surf_comp_ptr->rate_name;
}
cxxSurfComp::~cxxSurfComp()
cxxSurfaceComp::~cxxSurfaceComp()
{
}
struct master *cxxSurfComp::get_master()
struct master *cxxSurfaceComp::get_master()
{
struct master *master_ptr = NULL;
//for (std::map <char *, double, CHARSTAR_LESS>::iterator it = totals.begin(); it != totals.end(); it++) {
@ -84,16 +84,16 @@ struct master *cxxSurfComp::get_master()
return(master_ptr);
}
struct surface_comp *cxxSurfComp::cxxSurfComp2surface_comp(std::list<cxxSurfComp>& el)
struct surface_comp *cxxSurfaceComp::cxxSurfaceComp2surface_comp(std::list<cxxSurfaceComp>& el)
//
// Builds surface_comp structure from of cxxSurfComp
// Builds surface_comp structure from of cxxSurfaceComp
//
{
struct surface_comp *surf_comp_ptr = (struct surface_comp *) PHRQ_malloc((size_t) (el.size() * sizeof(struct surface_comp)));
if (surf_comp_ptr == NULL) malloc_error();
int i = 0;
for (std::list<cxxSurfComp>::iterator it = el.begin(); it != el.end(); ++it) {
for (std::list<cxxSurfaceComp>::iterator it = el.begin(); it != el.end(); ++it) {
surf_comp_ptr[i].formula = it->formula;
surf_comp_ptr[i].moles = it->moles;
surf_comp_ptr[i].master = it->get_master();
@ -110,7 +110,7 @@ struct surface_comp *cxxSurfComp::cxxSurfComp2surface_comp(std::list<cxxSurfComp
return(surf_comp_ptr);
}
void cxxSurfComp::dump_xml(std::ostream& s_oss, unsigned int indent)const
void cxxSurfaceComp::dump_xml(std::ostream& s_oss, unsigned int indent)const
{
//const char ERR_MESSAGE[] = "Packing surf_comp message: %s, element not found\n";
unsigned int i;
@ -142,7 +142,7 @@ void cxxSurfComp::dump_xml(std::ostream& s_oss, unsigned int indent)const
}
void cxxSurfComp::dump_raw(std::ostream& s_oss, unsigned int indent)const
void cxxSurfaceComp::dump_raw(std::ostream& s_oss, unsigned int indent)const
{
//const char ERR_MESSAGE[] = "Packing surf_comp message: %s, element not found\n";
unsigned int i;
@ -174,7 +174,7 @@ void cxxSurfComp::dump_raw(std::ostream& s_oss, unsigned int indent)const
}
void cxxSurfComp::read_raw(CParser& parser)
void cxxSurfaceComp::read_raw(CParser& parser)
{
std::string str;
@ -312,7 +312,7 @@ void cxxSurfComp::read_raw(CParser& parser)
case 8: // totals
if ( this->totals.read_raw(parser, next_char) != CParser::PARSER_OK) {
parser.incr_input_error();
parser.error_msg("Expected element name and molality for SurfComp totals.", CParser::OT_CONTINUE);
parser.error_msg("Expected element name and molality for SurfaceComp totals.", CParser::OT_CONTINUE);
}
opt_save = 8;
break;
@ -323,22 +323,56 @@ void cxxSurfComp::read_raw(CParser& parser)
// members that must be defined
if (formula_defined == false) {
parser.incr_input_error();
parser.error_msg("Formula not defined for SurfComp input.", CParser::OT_CONTINUE);
parser.error_msg("Formula not defined for SurfaceComp input.", CParser::OT_CONTINUE);
}
if (moles_defined == false) {
parser.incr_input_error();
parser.error_msg("Moles not defined for SurfComp input.", CParser::OT_CONTINUE);
parser.error_msg("Moles not defined for SurfaceComp input.", CParser::OT_CONTINUE);
}
if (la_defined == false) {
parser.incr_input_error();
parser.error_msg("La not defined for SurfComp input.", CParser::OT_CONTINUE);
parser.error_msg("La not defined for SurfaceComp input.", CParser::OT_CONTINUE);
}
if (charge_number_defined == false) {
parser.incr_input_error();
parser.error_msg("Charge_number not defined for SurfComp input.", CParser::OT_CONTINUE);
parser.error_msg("Charge_number not defined for SurfaceComp input.", CParser::OT_CONTINUE);
}
if (charge_balance_defined == false) {
parser.incr_input_error();
parser.error_msg("Charge_balance not defined for SurfComp input.", CParser::OT_CONTINUE);
parser.error_msg("Charge_balance not defined for SurfaceComp input.", CParser::OT_CONTINUE);
}
}
#ifdef USE_MPI
#include "Dictionary.h"
void cxxSurfaceComp::mpi_pack(std::vector<int>& ints, std::vector<double>& doubles)
{
extern cxxDictionary dictionary;
ints.push_back(dictionary.string2int(this->formula));
doubles.push_back(this->moles);
this->totals.mpi_pack(ints, doubles);
doubles.push_back(this->la);
ints.push_back(charge_number);
doubles.push_back(this->charge_balance);
ints.push_back(dictionary.string2int(this->phase_name));
doubles.push_back(this->phase_proportion);
ints.push_back(dictionary.string2int(this->rate_name));
}
void cxxSurfaceComp::mpi_unpack(int *ints, int *ii, double *doubles, int *dd)
{
extern cxxDictionary dictionary;
int i = *ii;
int d = *dd;
this->formula = dictionary.int2char(ints[i++]);
this->moles = doubles[d++];
this->totals.mpi_unpack(ints, &i, doubles, &d);
this->la = doubles[d++];
this->charge_number = ints[i++];
this->charge_balance = doubles[d++];
this->phase_name = dictionary.int2char(ints[i++]);
this->phase_proportion = doubles[d++];
this->rate_name = dictionary.int2char(ints[i++]);
*ii = i;
*dd = d;
}
#endif

View File

@ -1,5 +1,5 @@
#if !defined(SURFCOMP_H_INCLUDED)
#define SURFCOMP_H_INCLUDED
#if !defined(SURFACECOMP_H_INCLUDED)
#define SURFACECOMP_H_INCLUDED
#include "NameDouble.h"
#define EXTERNAL extern
@ -12,21 +12,21 @@
#include "char_star.h"
class cxxSurfComp
class cxxSurfaceComp
{
public:
cxxSurfComp();
cxxSurfComp(struct surface_comp *);
~cxxSurfComp();
cxxSurfaceComp();
cxxSurfaceComp(struct surface_comp *);
~cxxSurfaceComp();
struct master *get_master();
char *get_phase_name()const {return this->phase_name;}
char *get_rate_name()const {return this->rate_name;}
static struct surface_comp *cxxSurfComp2surface_comp(std::list<cxxSurfComp>& el);
static struct surface_comp *cxxSurfaceComp2surface_comp(std::list<cxxSurfaceComp>& el);
void dump_xml(std::ostream& os, unsigned int indent = 0)const;
@ -34,6 +34,11 @@ public:
void read_raw(CParser& parser);
#ifdef USE_MPI
void mpi_pack(std::vector<int>& ints, std::vector<double>& doubles);
void mpi_unpack(int *ints, int *ii, double *doubles, int *dd);
#endif
protected:
char * formula;
double moles;
@ -49,4 +54,4 @@ public:
};
#endif // !defined(SURFCOMP_H_INCLUDED)
#endif // !defined(SURFACECOMP_H_INCLUDED)