Commit 79186939 authored by Marco Drache's avatar Marco Drache
Browse files

feature: feed polymers from binary file

parent e81f2b42
Loading
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ public:
	const MnMw exportPolymers(double _reactionTime) const;
	const void exportPolymers(std::string _filename, uint64_t _addID, bool _writeHeader) const;
	void addPolymerMolecule(int _speciesID, Polymer* _p);
	void addPolymerMolecules(std::string _filename, int _speciesID);
	void feedMol(int _speciesID, double _mol);
	void updateMol(int _speciesID, double _mol);
	void updateVolume(double _volume);
+1 −0
Original line number Diff line number Diff line
@@ -55,6 +55,7 @@ public:
	void setRateCoeficient(int _id, double _value);
	void addMolecules(int _id, int64_t _plusmole);
	void addPolymerMolecule(int _speciesID, Polymer* _p);
	void addPolymerMolecules(std::string _filename, int _speciesID);
	Polymer* getPolymerMolecule(int _speciesID);
	std::vector<Polymer*> getAllPolymers(int _speciesID);
	void importSpecies(int indexS, int indexM, const std::string& _filename, int _format);
+4 −0
Original line number Diff line number Diff line
@@ -302,6 +302,9 @@ Polymer* SimulationController::getPolymer(const int _id) {
void SimulationController::addPolymerMolecule(int _speciesID, Polymer* _p) {
	kMC->addPolymerMolecule(_speciesID, _p);
}
void SimulationController::addPolymerMolecules(string _filename, int _speciesID) {
	kMC->addPolymerMolecules(_filename, _speciesID);
}
vector<double> SimulationController::getState() {
	vector<double> mol;
	vector<speciesObject> speciesList = currentModel->getSpecies();
@@ -465,6 +468,7 @@ void SimulationController::exportPolymers(std::string _prefixFilename, double _r
}
void SimulationController::exportPolymerSegments(std::string _filename, int _speciesID, double _molPolymerSegments) {
	uint64_t numPolymerSegments = currentState->getNumMolecules(_molPolymerSegments);
	cout << "export num Seg: " << numPolymerSegments << endl;
	kMC->exportPolymers(_speciesID, _filename, currentModel, numPolymerSegments);
}

+29 −1
Original line number Diff line number Diff line
@@ -595,6 +595,33 @@ void Simulation::addPolymerMolecule(int _speciesID, Polymer* _p) {
		solidsContentBalance.solidsContentMoleculeCounter[i] += _p->getM(int(i));
	}
}
void Simulation::addPolymerMolecules(std::string _filename, int _speciesID) {
	ifstream file;
	int size;
	file.open(_filename, ios::binary);
	if (!file.is_open()) {
		cout << "addPolymerMolecules: Failed open file " << _filename << endl;
		return;
	}
	size_t macromolSpeciesIdx = 0;
	for (size_t idx = 0; idx < macromolSpecies.size(); idx++) {
		if (macromolSpecies[idx]->getID() == _speciesID) {
			macromolSpeciesIdx = idx;
		}
	}
	file.read((char*)&size, sizeof(size_t));
	
	for (uint64_t i = 0; i < size; i++) {
		Polymer* p = new Polymer();
		moleculeCounter[_speciesID] += 1;
		p->importPolymer(&file);
		macromolSpecies[macromolSpeciesIdx]->addPolymer(p);
		for (size_t i = 0; i < solidsContentBalance.solidsContentMoleculeCounter.size(); i++) {
			solidsContentBalance.solidsContentMoleculeCounter[i] += p->getM(int(i));
		}
	}
	file.close();
}
Polymer* Simulation::getPolymerMolecule(int _speciesID) {
	if (moleculeCounter[_speciesID] == 0) {
		return nullptr;
@@ -721,7 +748,8 @@ bool Simulation::exportPolymers(int _id, const std::string& _filename, const kin
						numMonomersAll += numMonomers;
					}
				}
				polymerForExport.push_back(elem->popPolymerForTransfer(_id));
				moleculeCounter[_id] -= 1;
				polymerForExport.push_back(p);
				if (numPolymerSegmentsLeft < numMonomersAll) {
					numPolymerSegmentsLeft = 0;
				}