double TransportGradientPeriodic :: giveUnknown(ValueModeType mode, TimeStep *tStep, ActiveDof *dof) { if ( this->isGradDof(dof) ) { int ind = grad_ids.findFirstIndexOf(dof->giveDofID()) - 1; return this->mGradient(ind) * this->giveTimeFunction()->evaluateAtTime(tStep->giveTargetTime()); } DofManager *master = this->domain->giveDofManager(this->slavemap[dof->giveDofManager()->giveNumber()]); if ( mode == VM_Incremental ) { double val = master->giveDofWithID(dof->giveDofID())->giveUnknown(mode, tStep); return this->giveUnknown(val, mode, tStep, dof); } double val = master->giveDofWithID(dof->giveDofID())->giveUnknown(mode, tStep); return this->giveUnknown(val, mode, tStep, dof); }
bool NodeErrorCheckingRule :: check(Domain *domain, TimeStep *tStep) { // Rule doesn't apply yet. if ( tStep->giveNumber() != tstep ) { return true; } DofManager *dman = domain->giveGlobalDofManager(number); if ( !dman ) { if ( domain->giveEngngModel()->isParallel() ) { return true; } else { OOFEM_WARNING("Dof manager %d not found.", number); return false; } } if ( dman->giveParallelMode() == DofManager_remote || dman->giveParallelMode() == DofManager_null ) { return true; } Dof *dof = dman->giveDofWithID(dofid); double dmanValue = dof->giveUnknown(mode, tStep); bool check = checkValue(dmanValue); if ( !check ) { OOFEM_WARNING("Check failed in: tstep %d, node %d, dof %d, mode %d:\n" "value is %.8e, but should be %.8e ( error is %e but tolerance is %e )", tstep, number, dofid, mode, dmanValue, value, fabs(dmanValue-value), tolerance ); } return check; }
void SolutionbasedShapeFunction :: copyDofManagersToSurfaceData(modeStruct *mode, IntArray nodeList, bool isPlus, bool isMinus, bool isZeroBoundary) { for ( int i = 1; i <= nodeList.giveSize(); i++ ) { FloatArray values; DofManager *dman = mode->myEngngModel->giveDomain(1)->giveDofManager( nodeList.at(i) ); computeBaseFunctionValueAt(values, * dman->giveCoordinates(), this->dofs, * mode->myEngngModel); for ( int j = 1; j <= this->dofs.giveSize(); j++ ) { SurfaceDataStruct *surfaceData = new(SurfaceDataStruct); Dof *d = dman->giveDofWithID( dofs.at(j) ); surfaceData->DofID = ( DofIDItem ) this->dofs.at(j); surfaceData->DofMan = dman; surfaceData->isPlus = isPlus; surfaceData->isMinus = isMinus; surfaceData->isZeroBoundary = isZeroBoundary; surfaceData->isFree = d->giveBcId() == 0; surfaceData->value = values.at(j); mode->SurfaceData.push_back(surfaceData); } } }
void SolutionbasedShapeFunction :: updateModelWithFactors(modeStruct *m) { //Update values with correction factors for ( size_t j = 0; j < m->SurfaceData.size(); j++ ) { SurfaceDataStruct *sd = m->SurfaceData.at(j); DofManager *dman = sd->DofMan; Dof *d = dman->giveDofWithID(sd->DofID); double factor = 1.0; factor = m->SurfaceData.at(j)->isPlus ? m->ap : factor; factor = m->SurfaceData.at(j)->isMinus ? m->am : factor; factor = m->SurfaceData.at(j)->isZeroBoundary ? 1.0 : factor; if ( dynamic_cast< MasterDof * >(d) && m->SurfaceData.at(j)->isFree ) { double u = m->SurfaceData.at(j)->value; this->setBoundaryConditionOnDof(dman->giveDofWithID(m->SurfaceData.at(j)->DofID), u * factor); } } }
double PrescribedGradientBCPeriodic :: giveUnknown(PrimaryField &field, ValueModeType mode, TimeStep *tStep, ActiveDof *dof) { if ( this->isStrainDof(dof) ) { int ind = strain_id.findFirstIndexOf(dof->giveDofID()) - 1; return this->mGradient(ind % 3, ind / 3) * this->giveTimeFunction()->evaluateAtTime(tStep->giveTargetTime()); } DofManager *master = this->domain->giveDofManager(this->slavemap[dof->giveDofManager()->giveNumber()]); double val = master->giveDofWithID(dof->giveDofID())->giveUnknown(field, mode, tStep); return this->giveUnknown(val, mode, tStep, dof); }
void PhaseFieldElement :: computeLocationArrayOfDofIDs( const IntArray &dofIdArray, IntArray &answer ) { // Routine to extract compute the location array an element given an dofid array. answer.clear(); NLStructuralElement *el = this->giveElement(); int k = 0; for ( int i = 1; i <= el->giveNumberOfDofManagers(); i++ ) { DofManager *dMan = el->giveDofManager( i ); for ( int j = 1; j <= dofIdArray.giveSize( ); j++ ) { if ( dMan->hasDofID( (DofIDItem) dofIdArray.at( j ) ) ) { Dof *d = dMan->giveDofWithID( dofIdArray.at( j ) ); answer.followedBy( k + d->giveNumber( ) ); } } k += dMan->giveNumberOfDofs( ); } }
void CoupledFieldsElement :: computeLocationArrayOfDofIDs(const IntArray &dofIdArray, IntArray &answer) { // Routine to extract compute the location array an element given an dofid array. answer.resize(0); int k = 0; for ( int i = 1; i <= numberOfDofMans; i++ ) { DofManager *dMan = this->giveDofManager(i); for (int j = 1; j <= dofIdArray.giveSize(); j++ ) { if ( dMan->hasDofID( (DofIDItem) dofIdArray.at(j) ) ) { Dof *d = dMan->giveDofWithID( dofIdArray.at(j) ); answer.followedBy( k + d->giveNumber() ); //answer.followedBy( k + j ); } } k += dMan->giveNumberOfDofs( ); } }
void CoupledFieldsElement :: computeVectorOfDofIDs(const IntArray &dofIdArray, ValueModeType valueMode, TimeStep *stepN, FloatArray &answer) { // Routine to extract the solution vector for an element given an dofid array. // Size will be numberOfDofs and if a certain dofId does not exist a zero is used as value. answer.resize( numberOfDofMans * dofIdArray.giveSize() ); // equal number of nodes for all fields answer.zero(); int k = 1; for ( int i = 1; i <= numberOfDofMans; i++ ) { DofManager *dMan = this->giveDofManager(i); for (int j = 1; j <= dofIdArray.giveSize(); j++ ) { if ( dMan->hasDofID( (DofIDItem) dofIdArray.at(j) ) ) { Dof *d = dMan->giveDofWithID( dofIdArray.at(j) ); answer.at(k) = d->giveUnknown(valueMode, stepN); } k++; } } }
void IncrementalLinearStatic :: solveYourselfAt(TimeStep *tStep) { Domain *d = this->giveDomain(1); // Creates system of governing eq's and solves them at given time step // >>> beginning PH // The following piece of code updates assignment of boundary conditions to dofs // (this allows to have multiple boundary conditions assigned to one dof // which can be arbitrarily turned on and off in time) // Almost the entire section has been copied from domain.C std :: vector< std :: map< int, int > > dof_bc( d->giveNumberOfDofManagers() ); for ( int i = 1; i <= d->giveNumberOfBoundaryConditions(); ++i ) { GeneralBoundaryCondition *gbc = d->giveBc(i); if ( gbc->isImposed(tStep) ) { if ( gbc->giveSetNumber() > 0 ) { ///@todo This will eventually not be optional. // Loop over nodes in set and store the bc number in each dof. Set *set = d->giveSet( gbc->giveSetNumber() ); ActiveBoundaryCondition *active_bc = dynamic_cast< ActiveBoundaryCondition * >(gbc); BoundaryCondition *bc = dynamic_cast< BoundaryCondition * >(gbc); if ( bc || ( active_bc && active_bc->requiresActiveDofs() ) ) { const IntArray &appliedDofs = gbc->giveDofIDs(); const IntArray &nodes = set->giveNodeList(); for ( int inode = 1; inode <= nodes.giveSize(); ++inode ) { for ( int idof = 1; idof <= appliedDofs.giveSize(); ++idof ) { if ( dof_bc [ nodes.at(inode) - 1 ].find( appliedDofs.at(idof) ) == dof_bc [ nodes.at(inode) - 1 ].end() ) { // is empty dof_bc [ nodes.at(inode) - 1 ] [ appliedDofs.at(idof) ] = i; DofManager * dofman = d->giveDofManager( nodes.at(inode) ); Dof * dof = dofman->giveDofWithID( appliedDofs.at(idof) ); dof->setBcId(i); } else { // another bc has been already prescribed at this time step to this dof OOFEM_WARNING("More than one boundary condition assigned at time %f to node %d dof %d. Considering boundary condition %d", tStep->giveTargetTime(), nodes.at(inode), appliedDofs.at(idof), dof_bc [ nodes.at(inode) - 1 ] [appliedDofs.at(idof)] ); } } } } } } } // to get proper number of equations this->forceEquationNumbering(); // <<< end PH // Initiates the total displacement to zero. if ( tStep->isTheFirstStep() ) { for ( auto &dofman : d->giveDofManagers() ) { for ( Dof *dof: *dofman ) { dof->updateUnknownsDictionary(tStep->givePreviousStep(), VM_Total, 0.); dof->updateUnknownsDictionary(tStep, VM_Total, 0.); } } for ( auto &bc : d->giveBcs() ) { ActiveBoundaryCondition *abc; if ( ( abc = dynamic_cast< ActiveBoundaryCondition * >(bc.get()) ) ) { int ndman = abc->giveNumberOfInternalDofManagers(); for ( int i = 1; i <= ndman; i++ ) { DofManager *dofman = abc->giveInternalDofManager(i); for ( Dof *dof: *dofman ) { dof->updateUnknownsDictionary(tStep->givePreviousStep(), VM_Total, 0.); dof->updateUnknownsDictionary(tStep, VM_Total, 0.); } } } } } // Apply dirichlet b.c's on total values for ( auto &dofman : d->giveDofManagers() ) { for ( Dof *dof: *dofman ) { double tot = dof->giveUnknown( VM_Total, tStep->givePreviousStep() ); if ( dof->hasBc(tStep) ) { tot += dof->giveBcValue(VM_Incremental, tStep); } dof->updateUnknownsDictionary(tStep, VM_Total, tot); } } int neq = this->giveNumberOfDomainEquations( 1, EModelDefaultEquationNumbering() ); #ifdef VERBOSE OOFEM_LOG_RELEVANT("Solving [step number %8d, time %15e, equations %d]\n", tStep->giveNumber(), tStep->giveTargetTime(), neq); #endif if ( neq == 0 ) { // Allows for fully prescribed/empty problems. return; } incrementOfDisplacementVector.resize(neq); incrementOfDisplacementVector.zero(); #ifdef VERBOSE OOFEM_LOG_INFO("Assembling load\n"); #endif // Assembling the element part of load vector internalLoadVector.resize(neq); internalLoadVector.zero(); this->assembleVector( internalLoadVector, tStep, InternalForceAssembler(), VM_Total, EModelDefaultEquationNumbering(), this->giveDomain(1) ); loadVector.resize(neq); loadVector.zero(); this->assembleVector( loadVector, tStep, ExternalForceAssembler(), VM_Total, EModelDefaultEquationNumbering(), this->giveDomain(1) ); loadVector.subtract(internalLoadVector); this->updateSharedDofManagers(loadVector, EModelDefaultEquationNumbering(), ReactionExchangeTag); #ifdef VERBOSE OOFEM_LOG_INFO("Assembling stiffness matrix\n"); #endif stiffnessMatrix.reset( classFactory.createSparseMtrx(sparseMtrxType) ); if ( !stiffnessMatrix ) { OOFEM_ERROR("sparse matrix creation failed"); } stiffnessMatrix->buildInternalStructure( this, 1, EModelDefaultEquationNumbering() ); stiffnessMatrix->zero(); this->assemble( *stiffnessMatrix, tStep, TangentAssembler(TangentStiffness), EModelDefaultEquationNumbering(), this->giveDomain(1) ); #ifdef VERBOSE OOFEM_LOG_INFO("Solving ...\n"); #endif this->giveNumericalMethod( this->giveCurrentMetaStep() ); NM_Status s = nMethod->solve(*stiffnessMatrix, loadVector, incrementOfDisplacementVector); if ( !( s & NM_Success ) ) { OOFEM_ERROR("No success in solving system."); } }
void GnuplotExportModule::outputBoundaryCondition(PrescribedGradientBCWeak &iBC, TimeStep *tStep) { FloatArray stress; iBC.computeField(stress, tStep); printf("Mean stress computed in Gnuplot export module: "); stress.printYourself(); double time = 0.0; TimeStep *ts = emodel->giveCurrentStep(); if ( ts != NULL ) { time = ts->giveTargetTime(); } int bcIndex = iBC.giveNumber(); std :: stringstream strMeanStress; strMeanStress << "PrescribedGradientGnuplotMeanStress" << bcIndex << "Time" << time << ".dat"; std :: string nameMeanStress = strMeanStress.str(); std::vector<double> componentArray, stressArray; for(int i = 1; i <= stress.giveSize(); i++) { componentArray.push_back(i); stressArray.push_back(stress.at(i)); } XFEMDebugTools::WriteArrayToGnuplot(nameMeanStress, componentArray, stressArray); // Homogenized strain FloatArray grad; iBC.giveGradientVoigt(grad); outputGradient(iBC.giveNumber(), *iBC.giveDomain(), grad, tStep); #if 0 FloatArray grad; iBC.giveGradientVoigt(grad); double timeFactor = iBC.giveTimeFunction()->evaluate(ts, VM_Total); printf("timeFactor: %e\n", timeFactor ); grad.times(timeFactor); printf("Mean grad computed in Gnuplot export module: "); grad.printYourself(); std :: stringstream strMeanGrad; strMeanGrad << "PrescribedGradientGnuplotMeanGrad" << bcIndex << "Time" << time << ".dat"; std :: string nameMeanGrad = strMeanGrad.str(); std::vector<double> componentArrayGrad, gradArray; for(int i = 1; i <= grad.giveSize(); i++) { componentArrayGrad.push_back(i); gradArray.push_back(grad.at(i)); } XFEMDebugTools::WriteArrayToGnuplot(nameMeanGrad, componentArrayGrad, gradArray); #endif if(mExportBoundaryConditionsExtra) { // Traction node coordinates std::vector< std::vector<FloatArray> > nodePointArray; size_t numTracEl = iBC.giveNumberOfTractionElements(); for(size_t i = 0; i < numTracEl; i++) { std::vector<FloatArray> points; FloatArray xS, xE; iBC.giveTractionElCoord(i, xS, xE); points.push_back(xS); points.push_back(xE); nodePointArray.push_back(points); } std :: stringstream strTractionNodes; strTractionNodes << "TractionNodesGnuplotTime" << time << ".dat"; std :: string nameTractionNodes = strTractionNodes.str(); WritePointsToGnuplot(nameTractionNodes, nodePointArray); // Traction element normal direction std::vector< std::vector<FloatArray> > nodeNormalArray; for(size_t i = 0; i < numTracEl; i++) { std::vector<FloatArray> points; FloatArray n,t; iBC.giveTractionElNormal(i, n,t); points.push_back(n); points.push_back(n); nodeNormalArray.push_back(points); } std :: stringstream strTractionNodeNormals; strTractionNodeNormals << "TractionNodeNormalsGnuplotTime" << time << ".dat"; std :: string nameTractionNodeNormals = strTractionNodeNormals.str(); WritePointsToGnuplot(nameTractionNodeNormals, nodeNormalArray); // Traction (x,y) std::vector< std::vector<FloatArray> > nodeTractionArray; for(size_t i = 0; i < numTracEl; i++) { std::vector<FloatArray> tractions; FloatArray tS, tE; iBC.giveTraction(i, tS, tE, VM_Total, tStep); tractions.push_back(tS); tractions.push_back(tE); nodeTractionArray.push_back(tractions); } std :: stringstream strTractions; strTractions << "TractionsGnuplotTime" << time << ".dat"; std :: string nameTractions = strTractions.str(); WritePointsToGnuplot(nameTractions, nodeTractionArray); // Arc position along the boundary std::vector< std::vector<FloatArray> > arcPosArray; for(size_t i = 0; i < numTracEl; i++) { std::vector<FloatArray> arcPos; double xiS = 0.0, xiE = 0.0; iBC.giveTractionElArcPos(i, xiS, xiE); arcPos.push_back( FloatArray{xiS} ); arcPos.push_back( FloatArray{xiE} ); arcPosArray.push_back(arcPos); } std :: stringstream strArcPos; strArcPos << "ArcPosGnuplotTime" << time << ".dat"; std :: string nameArcPos = strArcPos.str(); WritePointsToGnuplot(nameArcPos, arcPosArray); // Traction (normal, tangent) std::vector< std::vector<FloatArray> > nodeTractionNTArray; for(size_t i = 0; i < numTracEl; i++) { std::vector<FloatArray> tractions; FloatArray tS, tE; iBC.giveTraction(i, tS, tE, VM_Total, tStep); FloatArray n,t; iBC.giveTractionElNormal(i, n, t); double tSn = tS.dotProduct(n,2); double tSt = tS.dotProduct(t,2); tractions.push_back( {tSn ,tSt} ); double tEn = tE.dotProduct(n,2); double tEt = tE.dotProduct(t,2); tractions.push_back( {tEn, tEt} ); nodeTractionNTArray.push_back(tractions); } std :: stringstream strTractionsNT; strTractionsNT << "TractionsNormalTangentGnuplotTime" << time << ".dat"; std :: string nameTractionsNT = strTractionsNT.str(); WritePointsToGnuplot(nameTractionsNT, nodeTractionNTArray); // Boundary points and displacements IntArray boundaries, bNodes; iBC.giveBoundaries(boundaries); std::vector< std::vector<FloatArray> > bndNodes; for ( int pos = 1; pos <= boundaries.giveSize() / 2; ++pos ) { Element *e = iBC.giveDomain()->giveElement( boundaries.at(pos * 2 - 1) ); int boundary = boundaries.at(pos * 2); e->giveInterpolation()->boundaryGiveNodes(bNodes, boundary); std::vector<FloatArray> bndSegNodes; // Add the start and end nodes of the segment DofManager *startNode = e->giveDofManager( bNodes[0] ); FloatArray xS = *(startNode->giveCoordinates()); Dof *dSu = startNode->giveDofWithID(D_u); double dU = dSu->giveUnknown(VM_Total, tStep); xS.push_back(dU); Dof *dSv = startNode->giveDofWithID(D_v); double dV = dSv->giveUnknown(VM_Total, tStep); xS.push_back(dV); bndSegNodes.push_back(xS); DofManager *endNode = e->giveDofManager( bNodes[1] ); FloatArray xE = *(endNode->giveCoordinates()); Dof *dEu = endNode->giveDofWithID(D_u); dU = dEu->giveUnknown(VM_Total, tStep); xE.push_back(dU); Dof *dEv = endNode->giveDofWithID(D_v); dV = dEv->giveUnknown(VM_Total, tStep); xE.push_back(dV); bndSegNodes.push_back(xE); bndNodes.push_back(bndSegNodes); } std :: stringstream strBndNodes; strBndNodes << "BndNodesGnuplotTime" << time << ".dat"; std :: string nameBndNodes = strBndNodes.str(); WritePointsToGnuplot(nameBndNodes, bndNodes); } }
///////////////////////////////////////////////// // Help functions void GnuplotExportModule::outputReactionForces(TimeStep *tStep) { // Add sum of reaction forces to arrays // Compute sum of reaction forces for each BC number Domain *domain = emodel->giveDomain(1); StructuralEngngModel *seMod = dynamic_cast<StructuralEngngModel* >(emodel); if(seMod == NULL) { OOFEM_ERROR("failed to cast to StructuralEngngModel."); } IntArray ielemDofMask; FloatArray reactions; IntArray dofManMap, dofidMap, eqnMap; // test if solution step output is active if ( !testTimeStepOutput(tStep) ) { return; } // map contains corresponding dofmanager and dofs numbers corresponding to prescribed equations // sorted according to dofmanger number and as a minor crit. according to dof number // this is necessary for extractor, since the sorted output is expected seMod->buildReactionTable(dofManMap, dofidMap, eqnMap, tStep, 1); // compute reaction forces seMod->computeReaction(reactions, tStep, 1); // Find highest index of prescribed dofs int maxIndPresDof = 0; for ( int i = 1; i <= dofManMap.giveSize(); i++ ) { maxIndPresDof = std::max(maxIndPresDof, dofidMap.at(i)); } int numBC = domain->giveNumberOfBoundaryConditions(); while ( mReactionForceHistory.size() < size_t(numBC) ) { std::vector<FloatArray> emptyArray; mReactionForceHistory.push_back( emptyArray ); } maxIndPresDof = domain->giveNumberOfSpatialDimensions(); while ( mDispHist.size() < size_t(numBC) ) { std::vector<double> emptyArray; mDispHist.push_back( emptyArray ); } for(int bcInd = 0; bcInd < numBC; bcInd++) { FloatArray fR(maxIndPresDof), disp(numBC); fR.zero(); for ( int i = 1; i <= dofManMap.giveSize(); i++ ) { DofManager *dMan = domain->giveDofManager( dofManMap.at(i) ); Dof *dof = dMan->giveDofWithID( dofidMap.at(i) ); if ( dof->giveBcId() == bcInd+1 ) { fR.at( dofidMap.at(i) ) += reactions.at( eqnMap.at(i) ); // Slightly dirty BoundaryCondition *bc = dynamic_cast<BoundaryCondition*> (domain->giveBc(bcInd+1)); if ( bc != NULL ) { disp.at(bcInd+1) = bc->give(dof, VM_Total, tStep->giveTargetTime()); } ///@todo This function should be using the primaryfield instead of asking BCs directly. / Mikael } } mDispHist[bcInd].push_back(disp.at(bcInd+1)); mReactionForceHistory[bcInd].push_back(fR); // X FILE * pFileX; char fileNameX[100]; sprintf(fileNameX, "ReactionForceGnuplotBC%dX.dat", bcInd+1); pFileX = fopen ( fileNameX , "wb" ); fprintf(pFileX, "#u Fx\n"); for ( size_t j = 0; j < mDispHist[bcInd].size(); j++ ) { fprintf(pFileX, "%e %e\n", mDispHist[bcInd][j], mReactionForceHistory[bcInd][j].at(1) ); } fclose(pFileX); // Y FILE * pFileY; char fileNameY[100]; sprintf(fileNameY, "ReactionForceGnuplotBC%dY.dat", bcInd+1); pFileY = fopen ( fileNameY , "wb" ); fprintf(pFileY, "#u Fx\n"); for ( size_t j = 0; j < mDispHist[bcInd].size(); j++ ) { if( mReactionForceHistory[bcInd][j].giveSize() >= 2 ) { fprintf(pFileY, "%e %e\n", mDispHist[bcInd][j], mReactionForceHistory[bcInd][j].at(2) ); } } fclose(pFileY); } }