示例#1
0
bool FindStressFromODB(map<string, StructuralResults>& results)
{
	cout << gPath << endl;
	if (gPath.find(".odb") == std::string::npos)
	{
		cout << "Invalid ODB file name!" << endl;
		return 0;
	}

	odb_initializeAPI();
	odb_Odb& odb = openOdb(gPath.c_str(), true);
	bool isClosed = odb.isClosed();
//		odb_String eType = "ALL ELEMENT";
	odb_Assembly& assembly = odb.rootAssembly();
		
	odb_Instance& instance = assembly.instances()["PART-1-1"];

	map <string, string>::const_iterator ci = gElementSets.begin();
	for (; ci != gElementSets.end(); ci++)
	{
		gFile << "[" << ci->first << ":" << ci->second << "]\n";
		StructuralResults result;

		odb_Set& cadComponentElementSet = instance.elementSets()[ci->second.c_str()];		
		odb_StepRepository& sRep1 = odb.steps();        
		odb_StepRepositoryIT sIter1 (sRep1);

		float mises = 0, 
			tresca = 0, 
			press = 0,
			maxPrinciple = 0, 
			minPrinciple = 0, 
			midPrinciple = 0, 
			maxInPlane = 0,
			minInPlane = 0,
			outPlane = 0,
			maxDisplacement = 0;

		for (sIter1.first(); !sIter1.isDone(); sIter1.next())
		{
			odb_Step& step = sRep1[sIter1.currentKey()];
			cout<<"Processing Step: "<<step.name().CStr()<<endl;
			//file<<"\nProcessing Step: "<<step.name().CStr()<<"\n";
			odb_SequenceFrame& frameSequence = step.frames();
			int numFrames = frameSequence.size();   

			odb_Frame& frame = frameSequence[numFrames-1];			// last frame
			//file << "Frame -  " << " Description[" << frame.description().CStr() << "]   LoadCase[" << frame.loadCase().name().CStr() << "]\n";

			// GETTING STRESS VALUES
			odb_FieldOutput& fieldOutput = frame.fieldOutputs()[STRESS_COMP];

			//cout<< " Total StressField:" << fieldOutput.values().size() << endl;
			odb_FieldOutput stressOutput = fieldOutput.getSubset(cadComponentElementSet);
			odb_SequenceInvariant invariants = stressOutput.validInvariants();
			int invariantSize = invariants.size();
			//file<< "ValidInvariants Size:" << invariantSize << "\n";
			bool bmises = invariants.isMember(odb_Enum::MISES),
				btresca = invariants.isMember(odb_Enum::TRESCA),
				bpress = invariants.isMember(odb_Enum::PRESS),
				bmaxPrinciple = invariants.isMember(odb_Enum::MAX_PRINCIPAL),
				bminPrinciple = invariants.isMember(odb_Enum::MIN_PRINCIPAL),
				bmidPrinciple = invariants.isMember(odb_Enum::MID_PRINCIPAL),
				bmaxInPlane = invariants.isMember(odb_Enum::MAX_INPLANE_PRINCIPAL),
				bminInPlane = invariants.isMember(odb_Enum::MIN_INPLANE_PRINCIPAL),
				boutPlane = invariants.isMember(odb_Enum::OUTOFPLANE_PRINCIPAL);

#if 0
			file<<bmises << " " << btresca 
				<< " " << bpress 
				<< " " << bmaxPrinciple 
				<< " " << bminPrinciple 
				<< " " << bmidPrinciple 
				<< " " << bmaxInPlane
				<< " " << bminInPlane
				<< " " << boutPlane
				<< "\n";
#endif
				
			const odb_SequenceFieldValue& seqVal = stressOutput.values();
			int numValues = seqVal.size();
			int totalValues = fieldOutput.values().size();


			cout << "Stress Fields for ELSET[" << ci->second << "]: " << numValues << "		TOTAL Stress Fields Size: " << totalValues << endl;
				
			result.hasMises = bmises;
			result.hasTresca = btresca;
			result.hasPress = bpress;

			for (int i = 0; i < numValues; i++)
			{
				float tmp = 0;
				const odb_FieldValue val = seqVal[i];
				if (bmises)
				{
					tmp = val.mises();
					//file<< "Mises: " << tmp;
					if (tmp > mises)
						mises = tmp;
				}
				
				tmp = 0;
				//file << "		";
				if (bpress)
				{
					tmp = val.press();
					//file<< "Pressure: " << tmp;
					if (tmp > press)
						press = tmp;
				}

				tmp = 0;
				//file << "		";
				if (btresca)
				{
					tmp = val.tresca();
					//file<< "Tresca: " << tmp;
					if (tmp > tresca)
						tresca = tmp;
				}

				tmp = 0;
#if 0					//file << "		";
				if (bmaxPrinciple)
				{
					tmp = val.maxPrincipal();
					//file<< "MaxPrinciple: " << tmp;
					if (tmp > maxPrinciple)
						maxPrinciple = tmp;
				}

				tmp = 0;
				//file << "		";
				if (bminPrinciple)
				{
					tmp = val.minPrincipal();
				//	file << "MinPrinciple: " << tmp;
					if (tmp < minPrinciple)
						minPrinciple = tmp;
				}
					
				tmp = 0;
				//file << "		";
				if (bmidPrinciple)
				{
					tmp = val.midPrincipal();
					//file << "MidPrinciple: " << tmp;
				}

				tmp = 0;
				//file << "		";
				if (bmaxInPlane)
				{
					tmp = val.maxInPlanePrincipal();
					//file << "MaxInPlane: " << tmp;
					file << tmp << "\n";
					if (tmp > maxInPlane)
						maxInPlane = tmp;
				}
					
				tmp = 0;
				//file << "		";
				if (bminInPlane)
				{
					tmp = val.minInPlanePrincipal();
					//file << "MinInPlane: " << tmp;
					if (tmp < minInPlane)
						minInPlane = tmp;
				}

				tmp = 0;
				//file << "		";
				if (boutPlane)
				{
					tmp = val.outOfPlanePrincipal();
				//	file << "OutOfPlane: " << tmp;
				}
#endif
				//file<<"\n";
			}

			
			// GETTING MAX DISPLACEMENT VALUE
			odb_FieldOutput& displacement_fieldOutput = frame.fieldOutputs()[DISP_COMP];
			odb_FieldOutput displacementOutput = displacement_fieldOutput.getSubset(cadComponentElementSet);
			odb_SequenceInvariant displacementInvariants = displacementOutput.validInvariants();
			invariantSize = displacementInvariants.size();
			bool bMag = displacementInvariants.isMember(odb_Enum::MAGNITUDE);
			const odb_SequenceFieldValue& displacementVal= displacementOutput.values();
			numValues = displacementVal.size();
				
			result.hasDisplacement = bMag;

			for (int i = 0; i < numValues; i++)
			{
				float tmp = 0;
				const odb_FieldValue val = displacementVal[i];
				if (bMag)
				{
					tmp = val.magnitude();
					//file<< "MaxDisplacement: " << tmp;
					if (tmp > maxDisplacement)
						maxDisplacement = tmp;
				}
			}

		} //end step
		result.mises = mises;
		result.press = press;
		result.tresca = tresca;
		result.maxDisplacement = maxDisplacement;

		results[ci->first] = result;
		gFile<< "Mises Max: " << mises << " Tresca Max: " << tresca << "	Press Max: " << press << "\n";

	} // end elementSet

	return 1;
}
示例#2
0
void SimuliaODB::openFile() {

#ifdef SIMULIA_ODB_API
	try {
#ifdef DEBUG_OUTPUT_SIMULIA_ODB
		infoOut << "Open OBD file: " << myFileName << std::endl;
#endif
		odb_Odb& odb = openOdb(odb_String(myFileName.c_str()));
#ifdef DEBUG_OUTPUT_SIMULIA_ODB
		infoOut << odb.name().CStr() << " '__________" << std::endl;
		infoOut << "analysisTitle: " << odb.analysisTitle().CStr() << std::endl;
		infoOut << "description: " << odb.description().CStr() << std::endl;
#endif
		odb_InstanceRepository& instanceRepo = odb.rootAssembly().instances();
		odb_InstanceRepositoryIT iter(instanceRepo);

		for (iter.first(); !iter.isDone(); iter.next())
		{
			odb_Instance& inst = instanceRepo[iter.currentKey()];
			const odb_SequenceNode& nodes = inst.nodes();
			int numOfNodes = nodes.size();
			const odb_SequenceElement& elements = inst.elements();
			int numOfElements = elements.size();

			// Check for Imports
			STACCATO_XML::PARTS_const_iterator iterParts(MetaDatabase::getInstance()->xmlHandle->PARTS().begin());

			for (int iImport = 0; iImport < iterParts->PART()[myPartId].FILEIMPORT().begin()->IMPORT().size(); iImport++) {
				std::string importType = iterParts->PART()[myPartId].FILEIMPORT().begin()->IMPORT()[iImport].Type()->c_str();

				if (importType == "Nodes") {
					if (std::string(iterParts->PART()[myPartId].FILEIMPORT().begin()->IMPORT()[iImport].LIST()->c_str()) == "ALL") {
						//Nodes
#ifdef DEBUG_OUTPUT_SIMULIA_ODB
						infoOut << "Total number of nodes: " << numOfNodes << std::endl;
#endif
						for (int i = 0; i < numOfNodes; i++)
						{
							const odb_Node aNode = nodes.node(i);
							const float * const coords = aNode.coordinates();
#ifdef DEBUG_OUTPUT_SIMULIA_ODB
							char formattedOut[256];
							sprintf(formattedOut, " %9d [%10.6f %10.6f %10.6f]", aNode.label(),
								coords[0], coords[1], coords[2]);
							infoOut << formattedOut << std::endl;
#endif
							myHMesh->addNode(aNode.label(), coords[0], coords[1], coords[2]);
						}
					}
					else
						std::cerr << "Unrecognized Node Import List.\n";
				}
				else if (importType == "Elements") {

					std::string translateSource = iterParts->PART()[myPartId].FILEIMPORT().begin()->IMPORT()[iImport].TRANSLATETO().begin()->Source()->c_str();
					std::string translateTarget = iterParts->PART()[myPartId].FILEIMPORT().begin()->IMPORT()[iImport].TRANSLATETO().begin()->Target()->c_str();

					if (std::string(iterParts->PART()[myPartId].FILEIMPORT().begin()->IMPORT()[iImport].LIST()->c_str()) == "ALL") {

						//Elements
#ifdef DEBUG_OUTPUT_SIMULIA_ODB
						infoOut << "Total number of elements: " << numOfElements << std::endl;
#endif
						for (int i = 0; i < numOfElements; i++)
						{
							const odb_Element aElement = elements.element(i);



#ifdef DEBUG_OUTPUT_SIMULIA_ODB
							infoOut << aElement.label() << " " << aElement.type().CStr() << " [";
#endif
							int elemConSize;
							const int* const conn = aElement.connectivity(elemConSize);
							std::vector<int> elementTopo;
							elementTopo.resize(elemConSize);
							for (int j = 0; j < elemConSize; j++) {
#ifdef DEBUG_OUTPUT_SIMULIA_ODB
								infoOut << " " << conn[j];
#endif
								elementTopo[j] = conn[j];
							}
#ifdef DEBUG_OUTPUT_SIMULIA_ODB
							infoOut << " ] " << std::endl;

#endif
							if (std::string(aElement.type().CStr()) == translateSource) {
								if (translateTarget == "STACCATO_Tetrahedron10Node3D")
									myHMesh->addElement(aElement.label(), STACCATO_Tetrahedron10Node3D, elementTopo);
								else if (translateTarget == "STACCATO_PlainStress4Node2D")
									myHMesh->addElement(aElement.label(), STACCATO_PlainStress4Node2D, elementTopo);
								else
									std::cerr << "STACCATO cannot recognize this element: " << translateTarget << std::endl;
							}
						}
					}
					else
						std::cerr << "Unrecognized Element Import List.\n";
				}
				else if (importType == "Sets") {
					// SETS
					// NODES
					std::cout << ">> Found Odb sets: ";
					for (int i = 0; i < iterParts->PART()[myPartId].FILEIMPORT().begin()->IMPORT()[iImport].NODE().begin()->TRANSLATETO().size(); i++) {

						std::string translateSource = iterParts->PART()[myPartId].FILEIMPORT().begin()->IMPORT()[iImport].NODE().begin()->TRANSLATETO()[i].Source()->c_str();
						std::string translateTarget = iterParts->PART()[myPartId].FILEIMPORT().begin()->IMPORT()[iImport].NODE().begin()->TRANSLATETO()[i].Target()->c_str();

						odb_SetRepositoryIT setIter(odb.rootAssembly().nodeSets());
						for (setIter.first(); !setIter.isDone() && setIter.currentValue().type() == odb_Enum::NODE_SET; setIter.next()) {

							odb_Set set = setIter.currentValue();
							int setSize = set.size();

							if (std::string(set.name().CStr()) == translateSource) {
								odb_SequenceString names = set.instanceNames();
								int numInstances = names.size();

								int i;
								for (i = 0; i < numInstances; i++)
								{
									odb_String name = names.constGet(i);
									const odb_SequenceNode& nodesInMySet = set.nodes(name);
									int n_max = nodesInMySet.size();
									std::vector<int> nodeLabels;
									for (int n = 0; n < n_max; n++) {
										nodeLabels.push_back(nodesInMySet.node(n).label());
									}
									std::cout << translateTarget << " with " << nodeLabels.size() << " nodes. ";
									myHMesh->addNodeSet(translateTarget, nodeLabels);
								}
							}
						}
					}
					std::cout << std::endl;
					// ELEMENTS
					for (int i = 0; i < iterParts->PART()[myPartId].FILEIMPORT().begin()->IMPORT()[iImport].ELEMENT().begin()->TRANSLATETO().size(); i++) {

						std::string translateSource = iterParts->PART()[myPartId].FILEIMPORT().begin()->IMPORT()[iImport].ELEMENT().begin()->TRANSLATETO()[i].Source()->c_str();
						std::string translateTarget = iterParts->PART()[myPartId].FILEIMPORT().begin()->IMPORT()[iImport].ELEMENT().begin()->TRANSLATETO()[i].Target()->c_str();

						odb_SetRepositoryIT setIter(odb.rootAssembly().nodeSets());

						for (setIter.first(); !setIter.isDone() && setIter.currentValue().type() == odb_Enum::ELEMENT_SET; setIter.next()) {

							odb_Set set = setIter.currentValue();
							int setSize = set.size();

							if (std::string(set.name().CStr()) == translateSource) {
								odb_SequenceString names = set.instanceNames();
								int numInstances = names.size();

								int i;
								for (i = 0; i < numInstances; i++)
								{
									odb_String name = names.constGet(i);

									const odb_SequenceElement& elemsInMySet = set.elements(name);
									int n_max = elemsInMySet.size();
									for (int n = 0; n < n_max; n++)
									{
										int elemConSize;
										const int* const conn = elemsInMySet.element(n).connectivity(elemConSize);
										std::vector<int> elemLabels;
										for (int j = 0; j < elemConSize; j++)
											elemLabels.push_back(elemsInMySet.element(n).label());
										myHMesh->addElemSet(translateTarget, elemLabels);
									}
								}
							}
						}
					}
				}
				else
					std::cerr << importType << " is not yet Supported or is Incorrect.\n";
			}

		}
		debugOut << "SimuliaODB::openODBFile: " << "Current physical memory consumption: " << memWatcher.getCurrentUsedPhysicalMemory() / 1000000 << " Mb" << std::endl;
		odb.close();//Change datastrc here HMesh should node be a member of odb

	}
	catch (odb_BaseException& exc) {
		errorOut << "odbBaseException caught" << std::endl;
		errorOut << "Abaqus error message: " << exc.UserReport().CStr() << std::endl;
		qFatal(exc.UserReport().CStr());
		//ToDo add error handling
	}
	catch (...) {
		errorOut << "Unknown Exception." << std::endl;
	}
#endif 
}