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

feature: exportPolymerSegments as polmers to binary file

parent d6081bbf
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -74,6 +74,7 @@ public:
	void exportConcentrationNumMolecules(double _reactionTime) const;
	void exportReactionsCount(double _reactionTime) const;
	void exportPolymers(std::string _prefixFilename, double _reactionTime, bool _binaryExport, bool _writeHeader);
	void exportPolymerSegments(std::string _filename, int _speciesID, double _molPolymerSegments);
	void exportLabeledPolymers(std::string _prefixFilename, int _id1, int _id2, uint64_t _filter, double _reactionTime, bool _writeHeader);
	
protected:
+1 −0
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ public:
	void updateMCRates();

	bool exportPolymerSpecies(int _id, const std::string& _filename, FileTypePolymerSpecies _fileType, const kineticModel* _mcPolymerModel) const;
	bool exportPolymers(int _id, const std::string& _filename, const kineticModel* _mcPolymerModel, uint64_t _numPolymerSegments);
	const MnMw exportPolymersCLD(const std::string& _filename, const kineticModel* _mcPolymerModel) const;
	const MnMw exportPolymersCLDHompolymerization(const std::string& _filename, const kineticModel* _mcPolymerModel) const;
	bool exportPolymersBinary(const std::string& _filename, const kineticModel* _mcPolymerModel) const;
+5 −0
Original line number Diff line number Diff line
@@ -463,6 +463,11 @@ void SimulationController::exportPolymers(std::string _prefixFilename, double _r
		kMC->exportPolymersCLD(simulationParameter.outputdir + "/" + "Polymers." + to_string(_reactionTime), currentModel);
	}
}
void SimulationController::exportPolymerSegments(std::string _filename, int _speciesID, double _molPolymerSegments) {
	uint64_t numPolymerSegments = currentState->getNumMolecules(_molPolymerSegments);
	kMC->exportPolymers(_speciesID, _filename, currentModel, numPolymerSegments);
}

void SimulationController::exportLabeledPolymers(std::string _prefixFilename, int _id1, int _id2, uint64_t _filter, double _reactionTime, bool _writeHeader) {
	string filename = simulationParameter.outputdir + "/" + _prefixFilename + "Polymers." + to_string(_reactionTime);
	string filenameFilter = simulationParameter.outputdir + "/" + _prefixFilename + "PolymersFilter." + to_string(_reactionTime);
+37 −0
Original line number Diff line number Diff line
@@ -703,6 +703,43 @@ bool Simulation::exportPolymerSpecies(int _id, const std::string& _filename, Fil
	}
	return false;
}
bool Simulation::exportPolymers(int _id, const std::string& _filename, const kineticModel* _mcPolymerModel, uint64_t _numPolymerSegments) {
	int indexMacro = 0;
	for (auto& elem : macromolSpecies) {
		if (elem->getID() == _id) {
			string filenamebin = _filename;
			ofstream binfile(filenamebin, ofstream::out | ofstream::binary);
			uint64_t numPolymerSegmentsLeft = _numPolymerSegments;
			vector<Polymer*> polymerForExport;
			do {
				Polymer* p = elem->popPolymerForTransfer(_id);
				uint64_t numMonomersAll = 0;
				if (p != nullptr) {
					for (size_t i = 0; i < solidsContentBalance.solidsContentMoleculeCounter.size(); i++) {
						uint64_t numMonomers = p->getM(int(i));
						uint64_t& currentCount = solidsContentBalance.solidsContentMoleculeCounter[i] -= numMonomers;
						numMonomersAll += numMonomers;
					}
				}
				polymerForExport.push_back(elem->popPolymerForTransfer(_id));
				if (numPolymerSegmentsLeft < numMonomersAll) {
					numPolymerSegmentsLeft = 0;
				}
				else {
					numPolymerSegmentsLeft -= numMonomersAll;
				}
			} while (numPolymerSegmentsLeft > 0);
			size_t numPolymers = polymerForExport.size();
			binfile.write((const char*)&numPolymers, sizeof(size_t));
			for (size_t i = 0; i < polymerForExport.size(); i++) {
				polymerForExport.at(i)->exportPolymer(&binfile);
			}
			return true;
		}
		++indexMacro;
	}
	return false;
}
const MnMw Simulation::exportPolymersCLDHompolymerization(const string& _filename, const kineticModel* _mcPolymerModel) const {
	const vector<speciesObject> speciesObjects = _mcPolymerModel->getSpecies();
	vector<string> monomerName;