void AdhesionFlexPlugin::update(CC3DXMLElement *_xmlData, bool _fullInitFlag){

	automaton = potts->getAutomaton();
	ASSERT_OR_THROW("CELL TYPE PLUGIN WAS NOT PROPERLY INITIALIZED YET. MAKE SURE THIS IS THE FIRST PLUGIN THAT YOU SET", automaton)
		set<unsigned char> cellTypesSet;


	//scanning Adhesion Molecule names

	CC3DXMLElementList adhesionMoleculeNameXMLVec=_xmlData->getElements("AdhesionMolecule");
	vector<string> adhesionMoleculeNameVec;
	set<string> adhesionMoleculeNameSet;
	moleculeNameIndexMap.clear();

	for (int i = 0 ; i<adhesionMoleculeNameXMLVec.size(); ++i){
		string moleculeName=adhesionMoleculeNameXMLVec[i]->getAttribute("Molecule");
		if (! adhesionMoleculeNameSet.insert(moleculeName).second){
			ASSERT_OR_THROW(string("Duplicate molecule Name=")+moleculeName+ " specified in AdhesionMolecule section ", false);
		}        
		adhesionMoleculeNameVec.push_back(moleculeName);
		moleculeNameIndexMap.insert(make_pair(moleculeName,i));
	}

	numberOfAdhesionMolecules=moleculeNameIndexMap.size();
	if (!sim->getRestartEnabled()){	
		adhesionMoleculeDensityVecMedium=vector<float>(numberOfAdhesionMolecules,0.0);
	}
	cerr<<"numberOfAdhesionMolecules="<<numberOfAdhesionMolecules<<endl;

	//scannning AdhesionMoleculeDensity section

	CC3DXMLElementList adhesionMoleculeDensityXMLVec=_xmlData->getElements("AdhesionMoleculeDensity");    
	typeToAdhesionMoleculeDensityMap.clear();
	std::map<int,std::vector<float> >::iterator mitr;

	for (int i = 0 ; i<adhesionMoleculeDensityXMLVec.size(); ++i){
		int typeId=automaton->getTypeId(adhesionMoleculeDensityXMLVec[i]->getAttribute("CellType"));

		cerr<<"typeId="<<typeId<<endl;


		mitr=typeToAdhesionMoleculeDensityMap.find(typeId);
		if (mitr==typeToAdhesionMoleculeDensityMap.end()){
			typeToAdhesionMoleculeDensityMap.insert(make_pair(typeId,vector<float>(numberOfAdhesionMolecules,0.0)));
			cerr<<"typeToAdhesionMoleculeDensityMap[typeId].size()="<<typeToAdhesionMoleculeDensityMap[typeId].size()<<endl;
		}


		string moleculeName=adhesionMoleculeDensityXMLVec[i]->getAttribute("Molecule");
		cerr<<"moleculeName="<<moleculeName<<endl;
		if(moleculeNameIndexMap.find(moleculeName)==moleculeNameIndexMap.end()){
			ASSERT_OR_THROW(string("Molecule Name=")+moleculeName+" was not declared in the AdhesionMolecule section",false);
		}
		cerr<<"moleculeNameIndexMap[moleculeName]="<<moleculeNameIndexMap[moleculeName]<<endl;
		cerr<<"adhesionMoleculeDensityXMLVec[i]->getAttributeAsDouble(Density)="<<adhesionMoleculeDensityXMLVec[i]->getAttributeAsDouble("Density")<<endl;
		cerr<<"typeToAdhesionMoleculeDensityMap[typeId].size()="<<typeToAdhesionMoleculeDensityMap[typeId].size()<<endl;
		typeToAdhesionMoleculeDensityMap[typeId][moleculeNameIndexMap[moleculeName]]=adhesionMoleculeDensityXMLVec[i]->getAttributeAsDouble("Density");
		cerr<<"AFTER ASSIGNING DENSITY"<<endl;
	}


	//scanning BindingFormula section

	CC3DXMLElement * bindingFormulaXMLElem=_xmlData->getFirstElement("BindingFormula");

	formulaString=bindingFormulaXMLElem->getFirstElement("Formula")->getText(); //formula string

	CC3DXMLElement * variablesSectionXMLElem=bindingFormulaXMLElem->getFirstElement("Variables");
	//cerr<<"formulaString="<<formulaString<<endl;


	//here we can add options depending on variables input - for now it is har-coded to accept only matrix of bindingParameters
	bindingParameters.clear() ; //have to clear binding parameters
	CC3DXMLElement * adhesionInteractionMatrixXMLElem = variablesSectionXMLElem->getFirstElement("AdhesionInteractionMatrix");
	CC3DXMLElementList bindingParameterXMLVec = adhesionInteractionMatrixXMLElem->getElements("BindingParameter");
	for (int i = 0 ; i<bindingParameterXMLVec.size(); ++i){		
		setBindingParameter(bindingParameterXMLVec[i]->getAttribute("Molecule1") , bindingParameterXMLVec[i]->getAttribute("Molecule2"), bindingParameterXMLVec[i]->getDouble());
	}


    //vectorized variables for convenient parallel access 
   unsigned int maxNumberOfWorkNodes=pUtils->getMaxNumberOfWorkNodesPotts();
   molecule1Vec.assign(maxNumberOfWorkNodes,0.0);
   molecule2Vec.assign(maxNumberOfWorkNodes,0.0);
   pVec.assign(maxNumberOfWorkNodes,mu::Parser());    

   for (int i  = 0 ; i< maxNumberOfWorkNodes ; ++i){
    pVec[i].DefineVar("Molecule1",&molecule1Vec[i]);
    pVec[i].DefineVar("Molecule2",&molecule2Vec[i]);
    pVec[i].SetExpr(formulaString);
   }

	// p=mu::Parser(); //using new parser
	// //setting up muParser
	// p.DefineVar("Molecule1", &molecule1);
	// p.DefineVar("Molecule2", &molecule2);	
	// p.SetExpr(formulaString);





	//scanning NeighborOrder or Depth
	//Here I initialize max neighbor index for direct acces to the list of neighbors 
	boundaryStrategy=BoundaryStrategy::getInstance();
	maxNeighborIndex=0;

	if(_xmlData->getFirstElement("Depth")){
		maxNeighborIndex=boundaryStrategy->getMaxNeighborIndexFromDepth(_xmlData->getFirstElement("Depth")->getDouble());
		//cerr<<"got here will do depth"<<endl;
	}else{
		//cerr<<"got here will do neighbor order"<<endl;
		if(_xmlData->getFirstElement("NeighborOrder")){

			maxNeighborIndex=boundaryStrategy->getMaxNeighborIndexFromNeighborOrder(_xmlData->getFirstElement("NeighborOrder")->getUInt());	
			cerr<<"maxNeighborIndex="<<maxNeighborIndex<<endl;
		}else{
			maxNeighborIndex=boundaryStrategy->getMaxNeighborIndexFromNeighborOrder(1);

		}

	}


	cerr<<"sizeBindingArray="<<moleculeNameIndexMap.size()<<endl;
	//initializing binding parameter array
	int sizeBindingArray=moleculeNameIndexMap.size();

	int indexBindingArray ;
	bindingParameterArray.clear();
	bindingParameterArray.assign(sizeBindingArray,vector<double>(sizeBindingArray,0.0));
	bindingParameters_t::iterator bmitr;
	
	for(int i = 0 ; i < sizeBindingArray ; ++i)
		for(int j = 0 ; j < sizeBindingArray ; ++j){

			indexBindingArray= getIndex(i,j);

			bmitr=bindingParameters.find(indexBindingArray);

			if(bmitr!=bindingParameters.end()){
				bindingParameterArray[i][j] = bmitr->second;
			}


		}

		for(int i = 0 ; i < sizeBindingArray ; ++i)
			for(int j = 0 ; j < sizeBindingArray ; ++j){

				cerr<<"bindingParameterArray["<<i<<"]["<<j<<"]="<<bindingParameterArray[i][j]<<endl;

			}    

			


}
Beispiel #2
0
void FiPySolver::update(CC3DXMLElement *_xmlData, bool _fullInitFlag){
	
	//notice, only basic steering is enabled for PDE solvers - changing diffusion constants, do -not-diffuse to types etc...
	// Coupling coefficients cannot be changed and also there is no way to allocate extra fields while simulation is running

	if(potts->getDisplayUnitsFlag()){
		Unit diffConstUnit=powerUnit(potts->getLengthUnit(),2)/potts->getTimeUnit();
		Unit decayConstUnit=1/potts->getTimeUnit();
		Unit secretionConstUnit=1/potts->getTimeUnit();

		CC3DXMLElement * unitsElem=_xmlData->getFirstElement("Units"); 
		if (!unitsElem){ //add Units element
			unitsElem=_xmlData->attachElement("Units");
		}

		if(unitsElem->getFirstElement("DiffusionConstantUnit")){
			unitsElem->getFirstElement("DiffusionConstantUnit")->updateElementValue(diffConstUnit.toString());
		}else{
			unitsElem->attachElement("DiffusionConstantUnit",diffConstUnit.toString());
		}

		if(unitsElem->getFirstElement("DecayConstantUnit")){
			unitsElem->getFirstElement("DecayConstantUnit")->updateElementValue(decayConstUnit.toString());
		}else{
			unitsElem->attachElement("DecayConstantUnit",decayConstUnit.toString());
		}

		if(unitsElem->getFirstElement("DeltaXUnit")){
			unitsElem->getFirstElement("DeltaXUnit")->updateElementValue(potts->getLengthUnit().toString());
		}else{
			unitsElem->attachElement("DeltaXUnit",potts->getLengthUnit().toString());
		}

		if(unitsElem->getFirstElement("DeltaTUnit")){
			unitsElem->getFirstElement("DeltaTUnit")->updateElementValue(potts->getTimeUnit().toString());
		}else{
			unitsElem->attachElement("DeltaTUnit",potts->getTimeUnit().toString());
		}

		if(unitsElem->getFirstElement("CouplingCoefficientUnit")){
			unitsElem->getFirstElement("CouplingCoefficientUnit")->updateElementValue(decayConstUnit.toString());
		}else{
			unitsElem->attachElement("CouplingCoefficientUnit",decayConstUnit.toString());
		}



		if(unitsElem->getFirstElement("SecretionUnit")){
			unitsElem->getFirstElement("SecretionUnit")->updateElementValue(secretionConstUnit.toString());
		}else{
			unitsElem->attachElement("SecretionUnit",secretionConstUnit.toString());
		}

		if(unitsElem->getFirstElement("SecretionOnContactUnit")){
			unitsElem->getFirstElement("SecretionOnContactUnit")->updateElementValue(secretionConstUnit.toString());
		}else{
			unitsElem->attachElement("SecretionOnContactUnit",secretionConstUnit.toString());
		}

		if(unitsElem->getFirstElement("ConstantConcentrationUnit")){
			unitsElem->getFirstElement("ConstantConcentrationUnit")->updateElementValue(secretionConstUnit.toString());
		}else{
			unitsElem->attachElement("ConstantConcentrationUnit",secretionConstUnit.toString());
		}

		if(unitsElem->getFirstElement("DecayConstantUnit")){
			unitsElem->getFirstElement("DecayConstantUnit")->updateElementValue(decayConstUnit.toString());
		}else{
			unitsElem->attachElement("DecayConstantUnit",decayConstUnit.toString());
		}

		if(unitsElem->getFirstElement("DeltaXUnit")){
			unitsElem->getFirstElement("DeltaXUnit")->updateElementValue(potts->getLengthUnit().toString());
		}else{
			unitsElem->attachElement("DeltaXUnit",potts->getLengthUnit().toString());
		}

		if(unitsElem->getFirstElement("DeltaTUnit")){
			unitsElem->getFirstElement("DeltaTUnit")->updateElementValue(potts->getTimeUnit().toString());
		}else{
			unitsElem->attachElement("DeltaTUnit",potts->getTimeUnit().toString());
		}

		if(unitsElem->getFirstElement("CouplingCoefficientUnit")){
			unitsElem->getFirstElement("CouplingCoefficientUnit")->updateElementValue(decayConstUnit.toString());
		}else{
			unitsElem->attachElement("CouplingCoefficientUnit",decayConstUnit.toString());
		}

		if(unitsElem->getFirstElement("UptakeUnit")){
			unitsElem->getFirstElement("UptakeUnit")->updateElementValue(decayConstUnit.toString());
		}else{
			unitsElem->attachElement("UptakeUnit",decayConstUnit.toString());
		}

		if(unitsElem->getFirstElement("RelativeUptakeUnit")){
			unitsElem->getFirstElement("RelativeUptakeUnit")->updateElementValue(decayConstUnit.toString());
		}else{
			unitsElem->attachElement("RelativeUptakeUnit",decayConstUnit.toString());
		}

		if(unitsElem->getFirstElement("MaxUptakeUnit")){
			unitsElem->getFirstElement("MaxUptakeUnit")->updateElementValue(decayConstUnit.toString());
		}else{
			unitsElem->attachElement("MaxUptakeUnit",decayConstUnit.toString());
		}



	}


	diffSecrFieldTuppleVec.clear();
	bcSpecVec.clear();
	bcSpecFlagVec.clear();

	CC3DXMLElementList diffFieldXMLVec=_xmlData->getElements("DiffusionField");
	for(unsigned int i = 0 ; i < diffFieldXMLVec.size() ; ++i ){
		diffSecrFieldTuppleVec.push_back(DiffusionSecretionFiPyFieldTupple());
		DiffusionData & diffData=diffSecrFieldTuppleVec[diffSecrFieldTuppleVec.size()-1].diffData;
		SecretionData & secrData=diffSecrFieldTuppleVec[diffSecrFieldTuppleVec.size()-1].secrData;

		if(diffFieldXMLVec[i]->findElement("DiffusionData"))
			diffData.update(diffFieldXMLVec[i]->getFirstElement("DiffusionData"));

		if(diffFieldXMLVec[i]->findElement("SecretionData"))
			secrData.update(diffFieldXMLVec[i]->getFirstElement("SecretionData"));

		if(diffFieldXMLVec[i]->findElement("ReadFromFile"))
			readFromFileFlag=true;

		//boundary conditions parsing
		bcSpecFlagVec.push_back(false);
		bcSpecVec.push_back(BoundaryConditionSpecifier());

		if (diffFieldXMLVec[i]->findElement("BoundaryConditions")){
			bcSpecFlagVec[bcSpecFlagVec.size()-1]=true;
			BoundaryConditionSpecifier & bcSpec = bcSpecVec[bcSpecVec.size()-1];

			CC3DXMLElement * bcSpecElem = diffFieldXMLVec[i]->getFirstElement("BoundaryConditions");
			CC3DXMLElementList planeVec = bcSpecElem->getElements("Plane");



			for(unsigned int ip = 0 ; ip < planeVec.size() ; ++ip ){
				ASSERT_OR_THROW ("Boundary Condition specification Plane element is missing Axis attribute",planeVec[ip]->findAttribute("Axis"));
				string axisName=planeVec[ip]->getAttribute("Axis");
				int index=0;
				if (axisName=="x" ||axisName=="X" ){
					index=0;
				}
				if (axisName=="y" ||axisName=="Y" ){
					index=2;
				}
				if (axisName=="z" ||axisName=="Z" ){
					index=4;
				}

				if (planeVec[ip]->findElement("Periodic")){
					bcSpec.planePositions[index]=BoundaryConditionSpecifier::PERIODIC;
					bcSpec.planePositions[index+1]=BoundaryConditionSpecifier::PERIODIC;
				}else {
					//if (planeVec[ip]->findElement("ConstantValue")){
					CC3DXMLElementList cvVec=planeVec[ip]->getElements("ConstantValue");
					CC3DXMLElementList cdVec=planeVec[ip]->getElements("ConstantDerivative");

					for (unsigned int v = 0 ; v < cvVec.size() ; ++v ){
						string planePos=cvVec[v]->getAttribute("PlanePosition");
						double value=cvVec[v]->getAttributeAsDouble("Value");
						changeToLower(planePos);
						if (planePos=="min"){
							bcSpec.planePositions[index]=BoundaryConditionSpecifier::CONSTANT_VALUE;
							bcSpec.values[index]=value;

						}else if (planePos=="max"){
							bcSpec.planePositions[index+1]=BoundaryConditionSpecifier::CONSTANT_VALUE;
							bcSpec.values[index+1]=value;
						}else{
							ASSERT_OR_THROW("PlanePosition attribute has to be either max on min",false);
						}

					}
					if (cvVec.size()<=1){
						for (unsigned int d = 0 ; d < cdVec.size() ; ++d ){
							string planePos=cdVec[d]->getAttribute("PlanePosition");
							double value=cdVec[d]->getAttributeAsDouble("Value");
							changeToLower(planePos);
							if (planePos=="min"){
								bcSpec.planePositions[index]=BoundaryConditionSpecifier::CONSTANT_DERIVATIVE;
								bcSpec.values[index]=value;

							}else if (planePos=="max"){
								bcSpec.planePositions[index+1]=BoundaryConditionSpecifier::CONSTANT_DERIVATIVE;
								bcSpec.values[index+1]=value;
							}else{
								ASSERT_OR_THROW("PlanePosition attribute has to be either max on min",false);
							}

						}
					}

				}

			}

		}
	}
	if(_xmlData->findElement("Serialize")){
		serializeFlag=true;
		if(_xmlData->getFirstElement("Serialize")->findAttribute("Frequency")){
			serializeFrequency=_xmlData->getFirstElement("Serialize")->getAttributeAsUInt("Frequency");
		}
		cerr<<"serialize Flag="<<serializeFlag<<endl;
	}

	if(_xmlData->findElement("ReadFromFile")){
		readFromFileFlag=true;
		cerr<<"readFromFileFlag="<<readFromFileFlag<<endl;
	}

	for(int i = 0 ; i < diffSecrFieldTuppleVec.size() ; ++i){
		diffSecrFieldTuppleVec[i].diffData.setAutomaton(automaton);
		diffSecrFieldTuppleVec[i].secrData.setAutomaton(automaton);
		diffSecrFieldTuppleVec[i].diffData.initialize(automaton);
		diffSecrFieldTuppleVec[i].secrData.initialize(automaton);
	}

	///assigning member method ptrs to the vector
	for(unsigned int i = 0 ; i < diffSecrFieldTuppleVec.size() ; ++i){

		diffSecrFieldTuppleVec[i].secrData.secretionFcnPtrVec.assign(diffSecrFieldTuppleVec[i].secrData.secrTypesNameSet.size(),0);
		unsigned int j=0;
		for(set<string>::iterator sitr=diffSecrFieldTuppleVec[i].secrData.secrTypesNameSet.begin() ; sitr != diffSecrFieldTuppleVec[i].secrData.secrTypesNameSet.end()  ; ++sitr){

			if((*sitr)=="Secretion"){
				diffSecrFieldTuppleVec[i].secrData.secretionFcnPtrVec[j]=&FiPySolver::secreteSingleField;
				++j;
			}
			else if((*sitr)=="SecretionOnContact"){
				diffSecrFieldTuppleVec[i].secrData.secretionFcnPtrVec[j]=&FiPySolver::secreteOnContactSingleField;
				++j;
			}
			else if((*sitr)=="ConstantConcentration"){
				diffSecrFieldTuppleVec[i].secrData.secretionFcnPtrVec[j]=&FiPySolver::secreteConstantConcentrationSingleField;
				++j;
			}
		}
	}
}