int YMODEMCLASS::EndOrContinueSendBinaryFile (void) { OFSTRUCT of ; int rVal ; if (filename) filename +=lstrlen(filename)+1 ; if(--fileCount>0) { hFile = CreateFile (filename, &of, OF_READ) ; Initiation(TRUE) ; lErrorCount =0 ; bSeq = 0 ; fCRC = TRUE ; dataBlock0 = TRUE ; fltr_state = YMODEM_INIT ; return FT_SUCCESS ; } if(fileCount==0) { if (handshake==XONXOFF) CommSetHandShake (oiConn, handshake) ; fltr_state = YMODEM_INIT ; return FT_SUCCESS ; } if(fileCount<0) { rVal = FT_FILEEND ; //AEvtPostSignalAtMark (oiFT, 1) ; //AEvtPostStandard (oiFT, activeIdle, 0, AEVT_ATTAIL) ; } return rVal ; }
FullOrderNonlinearMaterialCache CorotationalPlasticMaterial::getPrecomputes(const Reference<Mesh> &mesh) const { CorotationalPlasticElement *element = dynamic_cast<CorotationalPlasticElement *>(mesh->getMaterialElement(type)); const int elementCount = mesh->getElementCount(); const int subMatEntry = element->getInitSubStiffMatEntryCount(); const int deformGradientEntry = element->getDeformGradientsPreEntryCount(); const int drivativeEntry = element->getDirvateEntryCount(); const int plasticStrainEntry = element->getQuadraturePointCount() * 9; const int byteCount = sizeof(Scalar) * elementCount * (subMatEntry + deformGradientEntry + drivativeEntry + plasticStrainEntry); FullOrderNonlinearMaterialCache cache(byteCount); Scalar *precomputes = (Scalar *)cache.getMemoryBlock(); Scalar *initSubStiffMat = precomputes; Scalar *deformationGradientPrecomputed = precomputes + elementCount * subMatEntry; Scalar *drivativePrecomputed = deformationGradientPrecomputed + elementCount * deformGradientEntry; for (int i = 0; i < elementCount; i++) { element->setNodeIndices(i); element->getPrecomputes(D, initSubStiffMat + i * subMatEntry, deformationGradientPrecomputed + i * deformGradientEntry, drivativePrecomputed + i * drivativeEntry); } Scalar *plasticStrainsCache = drivativePrecomputed + elementCount * drivativeEntry; Initiation(plasticStrainsCache, elementCount * plasticStrainEntry); delete element; return cache; }
void CGSolver::solveLinearSystem(const Scalar *rhs, Scalar *result) { const int width = this->mat->getNumColumns(); Scalar *memory = new Scalar[3 * width]; Initiation(memory, 3 * width); Scalar *remainder = memory, *direction = memory + width, *temp = memory + 2 * width; // remainder = rhs - mat * result SpMDV(*(this->mat), result, remainder); for (int i = 0; i < width; i++) remainder[i] = rhs[i] - remainder[i]; preconditioner->Preprocess(*this->mat); //M * d = r preconditioner->solvePreconditionerSystem(width, remainder, direction); Scalar delta = Dot(width, remainder, direction); Scalar epsilon = Dot(width, rhs, rhs) * tolerant * tolerant; Scalar remainderNorm2 = Dot(width, remainder, remainder); int iter = 0; while (iter++ < maxIteration && remainderNorm2 > epsilon) { // q = mat * direction Initiation(temp, width); SpMDV(*(this->mat), direction, temp); Scalar alpha = delta / Dot(width, direction, temp); //result = result + alpha * direction //remainder = remainder - alpha * q for (int i = 0; i < width; i++){ result[i] += alpha * direction[i]; remainder[i] -= alpha * temp[i]; } // M * z = remainder preconditioner->solvePreconditionerSystem(width, remainder, temp); Scalar preDelta = delta; delta = Dot(width, remainder, temp); Scalar beta = delta / preDelta; //direction = beta * direction + z for (int i = 0; i < width; i++) direction[i] = beta * direction[i] + temp[i]; remainderNorm2 = Dot(width, remainder, remainder); } delete[] memory; }
void YMODEMCLASS::StartProtocol (OBJECTID oiFT, int sendOrReceive) { int rVal ; if (sendOrReceive==SENDFILE) { fltr_state = YMODEM_INIT ; rVal = Initiation (TRUE) ; } else { fltr_state = SEND_INIT ; rVal = Initiation (FALSE) ; ReceiveBinaryFile () ; SendInitChar () ; } if (rVal==FT_SUCCESS) { SetTimerEvent (oiFT, setPollTimer, 15) ; SetTimerEvent (oiFT, setDataTimer, maxTimeout) ; } else AEvtPostSignalAtMark(oiFT, 6) ; }
void InvertibleStVKMaterial::getEnergyHassian(const double *invariants, double *hassian) const { Initiation(hassian, 6); hassian[0] = 0.25 * lambda; }
void CorotationalPlasticMaterial::generateMatrixAndVirtualWorks(const Reference<Mesh> &mesh, const Reference<NodeIndexer> &indexer, const FullOrderNonlinearMaterialCache& cache, const SparseSymMatrixIndicesPerElementCache& matrixIndices, BlockedSymSpMatrix& matrix, Scalar *vws) const { CorotationalPlasticElement *element = dynamic_cast<CorotationalPlasticElement *>(mesh->getMaterialElement(type)); const int elementCount = mesh->getElementCount(); const int nodePerElementCount = mesh->getNodePerElementCount(); const int initSubMatEntry = element->getInitSubStiffMatEntryCount(); const int deformGradientEntry = element->getDeformGradientsPreEntryCount(); const int drivativeEntry = element->getDirvateEntryCount(); const int quadratureCount = element->getQuadraturePointCount(); const int subMatrixEntryCount = ((3 * nodePerElementCount + 1) * 3 * nodePerElementCount) / 2; const int workingEntryCount = subMatrixEntryCount + 3 * nodePerElementCount + (9 + 9 + 9) * quadratureCount; Scalar *memory = new Scalar[workingEntryCount]; Initiation(memory, workingEntryCount); Scalar *subMat = memory; Scalar *subVirtualWorks = memory + subMatrixEntryCount; Scalar *orthoMats = subVirtualWorks + 3 * nodePerElementCount; Scalar *factoredParts = orthoMats + 9 * quadratureCount; Scalar *elasticStresses = factoredParts + 9 * quadratureCount; Scalar *precomputes = (Scalar *)cache.getMemoryBlock(); const Scalar *initSubStiffMats = precomputes; const Scalar *deformationGradientPrecomputed = precomputes + elementCount * initSubMatEntry; const Scalar *drivativePrecomputed = deformationGradientPrecomputed + elementCount * deformGradientEntry; Scalar *plasticStrainsCache = (Scalar *)drivativePrecomputed + elementCount * drivativeEntry; int *elementNodeIndices = (int *)alloca(3 * nodePerElementCount * sizeof(int)); for (int elementIndex = 0; elementIndex < elementCount; elementIndex++) { element->setNodeIndices(elementIndex); indexer->getElementNodesGlobalIndices(*element, nodePerElementCount, elementNodeIndices); const Scalar *gradientPre = deformationGradientPrecomputed + elementIndex * deformGradientEntry; const Scalar *subMatPre = initSubStiffMats + elementIndex * initSubMatEntry; const Scalar *drivatePre = drivativePrecomputed + elementIndex * drivativeEntry; Scalar *plasticStrains = plasticStrainsCache + elementIndex * (9 * quadratureCount); element->generateDecomposedDeformationGradient(gradientPre, threshold, orthoMats, factoredParts); for (int quadrature = 0; quadrature < quadratureCount; quadrature++) computeElasticStress(orthoMats + 9 * quadrature, factoredParts + 9 * quadrature, plasticStrains + 9 * quadrature, elasticStresses + 9 * quadrature); //generate submat element->generateSubStiffnessMatrix(orthoMats, subMatPre, subMat); //assmeble to the matrix int entryIndex = 0; const int *localIndices = matrixIndices.getElementMatIndices(elementIndex); for (int subCol = 0; subCol < nodePerElementCount * 3; subCol++) { if (elementNodeIndices[subCol] >= 0) { for (int subRow = subCol; subRow < nodePerElementCount * 3; subRow++) { if (elementNodeIndices[subRow] >= 0) matrix.addEntry(localIndices[entryIndex], subMat[entryIndex]); entryIndex += 1; } } else entryIndex += nodePerElementCount * 3 - subCol; } //generate virtual works element->generateNodalVirtualWorks(drivatePre, elasticStresses, subVirtualWorks); for (int localIndex = 0; localIndex < nodePerElementCount * 3; localIndex++) { int globalIndex = elementNodeIndices[localIndex]; if (globalIndex >= 0) vws[globalIndex] += subVirtualWorks[localIndex]; } } delete element; delete[] memory; }
void InvertibleHyperelasticMaterial::generateMatrixAndVirtualWorks(const Reference<Mesh> &mesh, const Reference<NodeIndexer> &indexer, const FullOrderNonlinearMaterialCache &cahce, const SparseSymMatrixIndicesPerElementCache &matrixIndices, BlockedSymSpMatrix& matrix, Scalar *vws) const { InvertibleHyperelasticElement *element = dynamic_cast<InvertibleHyperelasticElement *>(mesh->getMaterialElement(type)); const int elementCount = mesh->getElementCount(); const int nodePerElementCount = mesh->getNodePerElementCount(); const int drivativeEntry = element->getDirvateEntryCount(); const int deformGradientEntry = element->getDeformGradientsPreEntryCount(); const int quadratureCount = element->getQuadraturePointCount(); const int subMatrixEntryCount = ((3 * nodePerElementCount + 1) * 3 * nodePerElementCount) / 2; const int workingEntryCount = subMatrixEntryCount + 3 * nodePerElementCount + (9 + 3 + 9 + 9 + 3 + 6 + 9) * quadratureCount; Scalar *memory = new Scalar[workingEntryCount]; Initiation(memory, workingEntryCount); Scalar *subMatrix = memory; Scalar *subVirtualWorks = subMatrix + subMatrixEntryCount; Scalar *gradients = subVirtualWorks + 3 * nodePerElementCount; Scalar *diags = gradients + 9 * quadratureCount; Scalar *leftOrthoMats = diags + 3 * quadratureCount; Scalar *rightOrthoMats = leftOrthoMats + 9 * quadratureCount; Scalar *energyGradient = rightOrthoMats + 9 * quadratureCount; Scalar *energyHassian = energyGradient + 3 * quadratureCount; Scalar *stresses = energyHassian + 6 * quadratureCount; const Scalar *precomputes = (const Scalar *)cahce.getMemoryBlock(); const Scalar *shapeFunctionDrivativesPrecomputed = precomputes; const Scalar *deformationGradientPrecomputed = precomputes + elementCount * drivativeEntry; int *elementNodeIndices = (int *)alloca(3 * nodePerElementCount * sizeof(int)); for (int elementIndex = 0; elementIndex < elementCount; elementIndex++) { element->setNodeIndices(elementIndex); indexer->getElementNodesGlobalIndices(*element, nodePerElementCount, elementNodeIndices); const Scalar *drivatePre = shapeFunctionDrivativesPrecomputed + elementIndex * drivativeEntry; const Scalar *gradientPre = deformationGradientPrecomputed + elementIndex * deformGradientEntry; element->generateDeformationGradient(gradientPre, gradients); for (int quadrature = 0; quadrature < quadratureCount; quadrature++) { modifiedDeformGradient(gradients + quadrature * 9, diags + quadrature * 3, leftOrthoMats + quadrature * 3, rightOrthoMats + quadrature * 3); Scalar invarients[3]; getInvariants(diags + quadrature * 3, invarients); getEnergyGradient(invarients, energyGradient + 3 * quadrature); getEnergyHassian(invarients, energyHassian + 6 * quadrature); getPiolaKirchhoffStress(diags + quadrature * 3, leftOrthoMats + quadrature * 3, rightOrthoMats + quadrature * 3, invarients, energyGradient + 3 * quadrature, stresses + 9 * quadrature); } //generate stifness matrix Initiation(subMatrix, subMatrixEntryCount); element->generateSubStiffnessMatrix(drivatePre, diags, leftOrthoMats, rightOrthoMats, energyGradient, energyHassian, subMatrix); //add matrix entries int entryIndex = 0; const int *localIndices = matrixIndices.getElementMatIndices(elementIndex); for (int subCol = 0; subCol < nodePerElementCount * 3; subCol++) { if (elementNodeIndices[subCol] >= 0) { for (int subRow = subCol; subRow < nodePerElementCount * 3; subRow++) { if (elementNodeIndices[subRow] >= 0) matrix.addEntry(localIndices[entryIndex], subMatrix[entryIndex]); entryIndex += 1; } } else entryIndex += nodePerElementCount * 3 - subCol; } //generate virtual works element->generateNodalVirtualWorks(drivatePre, stresses, subVirtualWorks); for (int localIndex = 0; localIndex < nodePerElementCount * 3; localIndex++) { int globalIndex = elementNodeIndices[localIndex]; if (globalIndex >= 0) vws[globalIndex] += subVirtualWorks[localIndex]; } } delete element; delete[] memory; }