OOFEM 3.0
Loading...
Searching...
No Matches
gnuplotexportmodule.C
Go to the documentation of this file.
1/*
2 *
3 * ##### ##### ###### ###### ### ###
4 * ## ## ## ## ## ## ## ### ##
5 * ## ## ## ## #### #### ## # ##
6 * ## ## ## ## ## ## ## ##
7 * ## ## ## ## ## ## ## ##
8 * ##### ##### ## ###### ## ##
9 *
10 *
11 * OOFEM : Object Oriented Finite Element Code
12 *
13 * Copyright (C) 1993 - 2025 Borek Patzak
14 *
15 *
16 *
17 * Czech Technical University, Faculty of Civil Engineering,
18 * Department of Structural Mechanics, 166 29 Prague, Czech Republic
19 *
20 * This library is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU Lesser General Public
22 * License as published by the Free Software Foundation; either
23 * version 2.1 of the License, or (at your option) any later version.
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28 * Lesser General Public License for more details.
29 *
30 * You should have received a copy of the GNU Lesser General Public
31 * License along with this library; if not, write to the Free Software
32 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
33 */
34
35/*
36 * gnuplotexportmodule.C
37 *
38 * Created on: Jan 29, 2014
39 * Author: svennine
40 */
41
42#include "gnuplotexportmodule.h"
43#include "classfactory.h"
44#include "valuemodetype.h"
46#include "outputmanager.h"
47#include "dofmanager.h"
48#include "boundarycondition.h"
49#include "xfem/enrichmentitem.h"
50#include "xfem/xfemmanager.h"
52#include "xfem/XFEMDebugTools.h"
53#include "prescribedgradient.h"
56#include "gausspoint.h"
57#include "timestep.h"
58#include "feinterpol.h"
60#include "dofmanager.h"
62#include "function.h"
65
66#include <sstream>
67
68namespace oofem {
70
72 ExportModule(n, e),
73 mExportReactionForces(false),
74 mExportBoundaryConditions(false),
75 mExportBoundaryConditionsExtra(false),
76 mExportMesh(false),
77 mExportXFEM(false),
78 mExportCrackLength(false),
79 mExportInterfaceEl(false),
80 mMonitorNodeIndex(-1),
81 mpMatForceEvaluator( new MaterialForceEvaluator() )
82{}
83
86
104
105void GnuplotExportModule::doOutput(TimeStep *tStep, bool forcedOutput)
106{
107 if (!(testTimeStepOutput(tStep) || forcedOutput)) {
108 return;
109 }
110
111 // Export the sum of reaction forces for each Dirichlet BC
114 }
115
116 Domain *domain = emodel->giveDomain(1);
117
118 // Export output from boundary conditions
120 int numBC = domain->giveNumberOfBoundaryConditions();
121
122 for(int i = 1; i <= numBC; i++) {
123
124 PrescribedGradient *presGradBC = dynamic_cast<PrescribedGradient*>( domain->giveBc(i) );
125 if(presGradBC != NULL) {
126 outputBoundaryCondition(*presGradBC, tStep);
127 }
128
129
130 PrescribedGradientBCNeumann *presGradBCNeumann = dynamic_cast<PrescribedGradientBCNeumann*>( domain->giveBc(i) );
131 if(presGradBCNeumann != NULL) {
132 outputBoundaryCondition(*presGradBCNeumann, tStep);
133 }
134
135 PrescribedGradientBCWeak *presGradBCWeak = dynamic_cast<PrescribedGradientBCWeak*>( domain->giveBc(i) );
136 if(presGradBCWeak != NULL) {
137 outputBoundaryCondition(*presGradBCWeak, tStep);
138 }
139
140 }
141 }
142
143 mTimeHist.push_back( tStep->giveTargetTime() );
144
145 if(mExportXFEM) {
146 if(domain->hasXfemManager()) {
147 XfemManager *xMan = domain->giveXfemManager();
148
149 int numEI = xMan->giveNumberOfEnrichmentItems();
150
151 std::vector< std::vector<FloatArray> > points;
152
153 for(int i = 1; i <= numEI; i++) {
154 EnrichmentItem *ei = xMan->giveEnrichmentItem(i);
155 ei->callGnuplotExportModule(*this, tStep);
156
157 GeometryBasedEI *geoEI = dynamic_cast<GeometryBasedEI*>(ei);
158 if(geoEI != NULL) {
159 std::vector<FloatArray> eiPoints;
160 geoEI->giveSubPolygon(eiPoints, 0.0, 1.0);
161 points.push_back(eiPoints);
162 }
163 }
164
165 outputXFEMGeometry(points);
166 }
167 }
168
169 if(mExportMesh) {
170 outputMesh(*domain);
171 }
172
173 if(mMonitorNodeIndex != -1) {
175 outputNodeDisp(*dMan, tStep);
176 }
177
179 outputInterfaceEl(*domain, tStep);
180 }
181}
182
184{
185 ExportModule :: initialize();
186}
187
192
194// Help functions
196{
197 // Add sum of reaction forces to arrays
198 // Compute sum of reaction forces for each BC number
199 Domain *domain = emodel->giveDomain(1);
200 StructuralEngngModel *seMod = dynamic_cast<StructuralEngngModel* >(emodel);
201 if(seMod == NULL) {
202 OOFEM_ERROR("failed to cast to StructuralEngngModel.");
203 }
204
205 FloatArray reactions;
206 IntArray dofManMap, dofidMap, eqnMap;
207
208 // test if solution step output is active
209 if ( !testTimeStepOutput(tStep) ) {
210 return;
211 }
212
213 // map contains corresponding dofmanager and dofs numbers corresponding to prescribed equations
214 // sorted according to dofmanger number and as a minor crit. according to dof number
215 // this is necessary for extractor, since the sorted output is expected
216 seMod->buildReactionTable(dofManMap, dofidMap, eqnMap, tStep, 1);
217
218 // compute reaction forces
219 seMod->computeReaction(reactions, tStep, 1);
220
221 // Find highest index of prescribed dofs
222 int maxIndPresDof = 0;
223 for ( int i = 1; i <= dofManMap.giveSize(); i++ ) {
224 maxIndPresDof = std::max(maxIndPresDof, dofidMap.at(i));
225 }
226
227 int numBC = domain->giveNumberOfBoundaryConditions();
228
229 while ( mReactionForceHistory.size() < size_t(numBC) ) {
230 std::vector<FloatArray> emptyArray;
231 mReactionForceHistory.push_back( emptyArray );
232 }
233
234 maxIndPresDof = domain->giveNumberOfSpatialDimensions();
235
236 while ( mDispHist.size() < size_t(numBC) ) {
237 std::vector<double> emptyArray;
238 mDispHist.push_back( emptyArray );
239 }
240
241 for(int bcInd = 0; bcInd < numBC; bcInd++) {
242 FloatArray fR(maxIndPresDof), disp(numBC);
243 fR.zero();
244
245
246 for ( int i = 1; i <= dofManMap.giveSize(); i++ ) {
247 DofManager *dMan = domain->giveDofManager( dofManMap.at(i) );
248 Dof *dof = dMan->giveDofWithID( dofidMap.at(i) );
249
250 if ( dof->giveBcId() == bcInd+1 ) {
251 fR.at( dofidMap.at(i) ) += reactions.at( eqnMap.at(i) );
252
253 // Slightly dirty
254 BoundaryCondition *bc = dynamic_cast<BoundaryCondition*> (domain->giveBc(bcInd+1));
255 if ( bc != NULL ) {
256 disp.at(bcInd+1) = std::max( disp.at(bcInd+1), bc->give(dof, VM_Total, tStep->giveTargetTime()) );
257 }
259 }
260 }
261
262 mDispHist[bcInd].push_back(disp.at(bcInd+1));
263 mReactionForceHistory[bcInd].push_back(fR);
264
265
266
267 // X
268 FILE * pFileX;
269 char fileNameX[100];
270 sprintf(fileNameX, "ReactionForceGnuplotBC%dX.dat", bcInd+1);
271 pFileX = fopen ( fileNameX , "wb" );
272
273 fprintf(pFileX, "#u Fx\n");
274 for ( size_t j = 0; j < mDispHist[bcInd].size(); j++ ) {
275 fprintf(pFileX, "%e %e\n", mDispHist[bcInd][j], mReactionForceHistory[bcInd][j].at(1) );
276 }
277
278 fclose(pFileX);
279
280 // Y
281 FILE * pFileY;
282 char fileNameY[100];
283 sprintf(fileNameY, "ReactionForceGnuplotBC%dY.dat", bcInd+1);
284 pFileY = fopen ( fileNameY , "wb" );
285
286 fprintf(pFileY, "#u Fx\n");
287 for ( size_t j = 0; j < mDispHist[bcInd].size(); j++ ) {
288 if( mReactionForceHistory[bcInd][j].giveSize() >= 2 ) {
289 fprintf(pFileY, "%e %e\n", mDispHist[bcInd][j], mReactionForceHistory[bcInd][j].at(2) );
290 }
291 }
292
293 fclose(pFileY);
294
295 }
296}
297
302
304{
305 const std::vector<GaussPoint*> &czGaussPoints = iCrack.giveCohesiveZoneGaussPoints();
306
307 std::vector<double> arcLengthPositions, normalJumps, tangJumps, normalTractions, tangTractions;
308
309 std::vector<double> arcLengthPositionsB = iCrack.giveCohesiveZoneArcPositions();
310
311 const BasicGeometry *bg = iCrack.giveGeometry();
312
313// for( auto *gp: czGaussPoints ) {
314//
315// StructuralInterfaceMaterialStatus *matStat = dynamic_cast<StructuralInterfaceMaterialStatus*> ( gp->giveMaterialStatus() );
316// if(matStat != NULL) {
317//
318// // Compute arc length position of the Gauss point
319// const FloatArray &coord = (gp->giveGlobalCoordinates());
320// printf("coord: "); coord.printYourself();
321// double tangDist = 0.0, arcPos = 0.0;
322// bg->computeTangentialSignDist(tangDist, coord, arcPos);
323// arcLengthPositions.push_back(arcPos);
324//
338// }
339// }
340
341#if 1
342 size_t num_cz_gp = czGaussPoints.size();
343
344// for( auto *gp: czGaussPoints ) {
345 for(size_t gp_ind = 0; gp_ind < num_cz_gp; gp_ind++) {
346// printf("gp_ind: %lu\n", gp_ind );
347 GaussPoint *gp = czGaussPoints[gp_ind];
348
349 if( gp != NULL ) {
350
352 if(matStat != NULL) {
353
354 // Compute arc length position of the Gauss point
355 const FloatArray &coord = (gp->giveGlobalCoordinates());
356 double tangDist = 0.0, arcPos = 0.0;
357 bg->computeTangentialSignDist(tangDist, coord, arcPos);
358// printf("arcPos: %e\n", arcPos );
359 arcLengthPositions.push_back(arcPos);
360
361 // Compute displacement jump in normal and tangential direction
362 // Local numbering: (tang_z, tang, normal)
363 const FloatArray &jumpLoc = matStat->giveJump();
364
365 double normalJump = jumpLoc.at(3);
366 normalJumps.push_back(normalJump);
367
368
369 tangJumps.push_back( jumpLoc.at(2) );
370
371
372 const FloatArray &trac = matStat->giveFirstPKTraction();
373 normalTractions.push_back(trac.at(3));
374
375 tangTractions.push_back(trac.at(2));
376 }
377 else {
379
380 if(fe2ms != NULL) {
381// printf("Casted to StructuralFE2MaterialStatus.\n");
382
383 const FloatArray &coord = (gp->giveGlobalCoordinates());
384 double tangDist = 0.0, arcPos = 0.0;
385 bg->computeTangentialSignDist(tangDist, coord, arcPos);
386 // printf("arcPos: %e\n", arcPos );
387 arcLengthPositions.push_back(arcPos);
388
389 const FloatArray &n = fe2ms->giveNormal();
390// printf("n: "); n.printYourself();
391
392 const FloatArray &sig_v = fe2ms->giveStressVector();
393// printf("sig_v: "); sig_v.printYourself();
394
395 FloatMatrix sig_m(2,2);
396 sig_m(0,0) = sig_v(0);
397 sig_m(1,1) = sig_v(1);
398 sig_m(0,1) = sig_m(1,0) = sig_v( sig_v.giveSize()-1 );
399
400 FloatArray trac(2);
401 trac(0) = sig_m(0,0)*n(0) + sig_m(0,1)*n(1);
402 trac(1) = sig_m(1,0)*n(0) + sig_m(1,1)*n(1);
403 double trac_n = trac(0)*n(0) + trac(1)*n(1);
404 normalTractions.push_back(trac_n);
405
406 const FloatArray t = Vec2(-n(1), n(0));
407 double trac_t = trac(0)*t(0) + trac(1)*t(1);
408 tangTractions.push_back(trac_t);
409
410
411 }
412
413 }
414 }
415 }
416#endif
417
418
419
420 Domain *domain = emodel->giveDomain(1);
421 XfemManager *xMan = domain->giveXfemManager();
422 if ( xMan != NULL ) {
423 double time = 0.0;
424
425 TimeStep *ts = emodel->giveCurrentStep();
426 if ( ts != NULL ) {
427 time = ts->giveTargetTime();
428 }
429
430 int eiIndex = iCrack.giveNumber();
431
432 std :: stringstream strNormalJump;
433 strNormalJump << "NormalJumpGnuplotEI" << eiIndex << "Time" << time << ".dat";
434 std :: string nameNormalJump = strNormalJump.str();
435 XFEMDebugTools::WriteArrayToGnuplot(nameNormalJump, arcLengthPositions, normalJumps);
436
437 std :: stringstream strTangJump;
438 strTangJump << "TangJumpGnuplotEI" << eiIndex << "Time" << time << ".dat";
439 std :: string nameTangJump = strTangJump.str();
440 XFEMDebugTools::WriteArrayToGnuplot(nameTangJump, arcLengthPositions, tangJumps);
441
442 std :: stringstream strNormalTrac;
443 strNormalTrac << "NormalTracGnuplotEI" << eiIndex << "Time" << time << ".dat";
444 std :: string nameNormalTrac = strNormalTrac.str();
445 XFEMDebugTools::WriteArrayToGnuplot(nameNormalTrac, arcLengthPositions, normalTractions);
446
447 std :: stringstream strTangTrac;
448 strTangTrac << "TangTracGnuplotEI" << eiIndex << "Time" << time << ".dat";
449 std :: string nameTangTrac = strTangTrac.str();
450 XFEMDebugTools::WriteArrayToGnuplot(nameTangTrac, arcLengthPositions, tangTractions);
451
452
453 std::vector<FloatArray> matForcesStart, matForcesEnd;
454 std::vector<double> radii;
455
456 // Material forces
457 for(double matForceRadius : mMatForceRadii) {
458
459 radii.push_back(matForceRadius);
460
461 EnrichmentFront *efStart = iCrack.giveEnrichmentFrontStart();
462 const TipInfo &tipInfoStart = efStart->giveTipInfo();
463
464 FloatArray matForceStart;
465 mpMatForceEvaluator->computeMaterialForce(matForceStart, *domain, tipInfoStart, tStep, matForceRadius);
466
467 if(matForceStart.giveSize() > 0) {
468 matForcesStart.push_back(matForceStart);
469 }
470 else {
471 matForcesStart.push_back(Vec2(0.0,0.0));
472 }
473
474
475 EnrichmentFront *efEnd = iCrack.giveEnrichmentFrontEnd();
476 const TipInfo &tipInfoEnd = efEnd->giveTipInfo();
477
478 FloatArray matForceEnd;
479 mpMatForceEvaluator->computeMaterialForce(matForceEnd, *domain, tipInfoEnd, tStep, matForceRadius);
480
481 if(matForceEnd.giveSize() > 0) {
482 matForcesEnd.push_back(matForceEnd);
483 }
484 else {
485 matForcesEnd.push_back(Vec2(0.0,0.0));
486 }
487
488 }
489
490 std::vector< std::vector<FloatArray> > matForcesStartArray, matForcesEndArray;
491 matForcesStartArray.push_back(matForcesStart);
492 matForcesEndArray.push_back(matForcesEnd);
493
494
495 std :: stringstream strRadii;
496 strRadii << "MatForceRadiiGnuplotTime" << time << "Crack" << iCrack.giveNumber() << ".dat";
497 XFEMDebugTools::WriteArrayToGnuplot(strRadii.str(), radii, radii);
498
499
500 std :: stringstream strMatForcesStart;
501 strMatForcesStart << "MatForcesStartGnuplotTime" << time << "Crack" << iCrack.giveNumber() << ".dat";
502 WritePointsToGnuplot(strMatForcesStart.str(), matForcesStartArray);
503
504
505 std :: stringstream strMatForcesEnd;
506 strMatForcesEnd << "MatForcesEndGnuplotTime" << time << "Crack" << iCrack.giveNumber() << ".dat";
507 WritePointsToGnuplot(strMatForcesEnd.str(), matForcesEndArray);
508
509 double crackLength = iCrack.computeLength();
510 // printf("crackLength: %e\n", crackLength );
511 mCrackLengthHist[eiIndex].push_back(crackLength);
512 std :: stringstream strCrackLength;
513 strCrackLength << "CrackLengthGnuplotEI" << eiIndex << "Time" << time << ".dat";
514 XFEMDebugTools::WriteArrayToGnuplot(strCrackLength.str(), mTimeHist, mCrackLengthHist[eiIndex]);
515 }
516}
517
518void GnuplotExportModule::outputXFEMGeometry(const std::vector< std::vector<FloatArray> > &iEnrItemPoints)
519{
520 double time = 0.0;
521
522 TimeStep *ts = emodel->giveCurrentStep();
523 if ( ts != NULL ) {
524 time = ts->giveTargetTime();
525 }
526
527 std :: stringstream strCracks;
528 strCracks << "CracksTime" << time << ".dat";
529 std :: string nameCracks = strCracks.str();
530 WritePointsToGnuplot(nameCracks, iEnrItemPoints);
531}
532
533void GnuplotExportModule :: outputBoundaryCondition(PrescribedGradient &iBC, TimeStep *tStep)
534{
535 FloatArray stress;
536 iBC.computeField(stress, tStep);
537 printf("Mean stress computed in Gnuplot export module: "); stress.printYourself();
538
539 double time = 0.0;
540
541 TimeStep *ts = emodel->giveCurrentStep();
542 if ( ts != NULL ) {
543 time = ts->giveTargetTime();
544 }
545
546 int bcIndex = iBC.giveNumber();
547
548 // Homogenized stress
549 std :: stringstream strMeanStress;
550 strMeanStress << "PrescribedGradientGnuplotMeanStress" << bcIndex << "Time" << time << ".dat";
551 std :: string nameMeanStress = strMeanStress.str();
552 std::vector<double> componentArray, stressArray;
553
554 for(int i = 1; i <= stress.giveSize(); i++) {
555 componentArray.push_back(i);
556 stressArray.push_back(stress.at(i));
557 }
558
559 XFEMDebugTools::WriteArrayToGnuplot(nameMeanStress, componentArray, stressArray);
560
561 FloatArray grad;
562 iBC.giveGradientVoigt(grad);
563 outputGradient(iBC.giveNumber(), *iBC.giveDomain(), grad, tStep);
564}
565
567{
568 FloatArray stress;
569 iBC.computeField(stress, tStep);
570
571 printf("Mean stress computed in Gnuplot export module: "); stress.printYourself();
572
573 double time = 0.0;
574
575 TimeStep *ts = emodel->giveCurrentStep();
576 if ( ts != NULL ) {
577 time = ts->giveTargetTime();
578 }
579
580 int bcIndex = iBC.giveNumber();
581
582 std :: stringstream strMeanStress;
583 strMeanStress << "PrescribedGradientGnuplotMeanStress" << bcIndex << "Time" << time << ".dat";
584 std :: string nameMeanStress = strMeanStress.str();
585 std::vector<double> componentArray, stressArray;
586
587 for(int i = 1; i <= stress.giveSize(); i++) {
588 componentArray.push_back(i);
589 stressArray.push_back(stress.at(i));
590 }
591
592 XFEMDebugTools::WriteArrayToGnuplot(nameMeanStress, componentArray, stressArray);
593
594 // Homogenized strain
595
596 FloatArray grad;
597 iBC.giveGradientVoigt(grad);
598 outputGradient(iBC.giveNumber(), *iBC.giveDomain(), grad, tStep);
599}
600
602{
603 FloatArray stress;
604 iBC.computeField(stress, tStep);
605
606 printf("Mean stress computed in Gnuplot export module: "); stress.printYourself();
607 printf("sigXX: %.12e\n", stress(0) );
608
609 double time = 0.0;
610
611 TimeStep *ts = emodel->giveCurrentStep();
612 if ( ts != NULL ) {
613 time = ts->giveTargetTime();
614 }
615
616 int bcIndex = iBC.giveNumber();
617
618 std :: stringstream strMeanStress;
619 strMeanStress << "PrescribedGradientGnuplotMeanStress" << bcIndex << "Time" << time << ".dat";
620 std :: string nameMeanStress = strMeanStress.str();
621 std::vector<double> componentArray, stressArray;
622
623 for(int i = 1; i <= stress.giveSize(); i++) {
624 componentArray.push_back(i);
625 stressArray.push_back(stress.at(i));
626 }
627
628 XFEMDebugTools::WriteArrayToGnuplot(nameMeanStress, componentArray, stressArray);
629
630
631 // Homogenized strain
632 FloatArray grad;
633 iBC.giveGradientVoigt(grad);
634 outputGradient(iBC.giveNumber(), *iBC.giveDomain(), grad, tStep);
635
636#if 0
637 FloatArray grad;
638 iBC.giveGradientVoigt(grad);
639 double timeFactor = iBC.giveTimeFunction()->evaluate(ts, VM_Total);
640 printf("timeFactor: %e\n", timeFactor );
641 grad.times(timeFactor);
642 printf("Mean grad computed in Gnuplot export module: "); grad.printYourself();
643
644 std :: stringstream strMeanGrad;
645 strMeanGrad << "PrescribedGradientGnuplotMeanGrad" << bcIndex << "Time" << time << ".dat";
646 std :: string nameMeanGrad = strMeanGrad.str();
647 std::vector<double> componentArrayGrad, gradArray;
648
649 for(int i = 1; i <= grad.giveSize(); i++) {
650 componentArrayGrad.push_back(i);
651 gradArray.push_back(grad.at(i));
652 }
653
654 XFEMDebugTools::WriteArrayToGnuplot(nameMeanGrad, componentArrayGrad, gradArray);
655#endif
656
658
659 // Traction node coordinates
660 std::vector< std::vector<FloatArray> > nodePointArray;
661 size_t numTracEl = iBC.giveNumberOfTractionElements();
662 for(size_t i = 0; i < numTracEl; i++) {
663
664 std::vector<FloatArray> points;
665 FloatArray xS, xE;
666 iBC.giveTractionElCoord(i, xS, xE);
667 points.push_back(xS);
668 points.push_back(xE);
669
670 nodePointArray.push_back(points);
671 }
672
673 std :: stringstream strTractionNodes;
674 strTractionNodes << "TractionNodesGnuplotTime" << time << ".dat";
675 std :: string nameTractionNodes = strTractionNodes.str();
676
677 WritePointsToGnuplot(nameTractionNodes, nodePointArray);
678
679
680
681 // Traction element normal direction
682 std::vector< std::vector<FloatArray> > nodeNormalArray;
683 for(size_t i = 0; i < numTracEl; i++) {
684
685 std::vector<FloatArray> points;
686 FloatArray n,t;
687 iBC.giveTractionElNormal(i, n,t);
688 points.push_back(n);
689 points.push_back(n);
690
691 nodeNormalArray.push_back(points);
692 }
693
694 std :: stringstream strTractionNodeNormals;
695 strTractionNodeNormals << "TractionNodeNormalsGnuplotTime" << time << ".dat";
696 std :: string nameTractionNodeNormals = strTractionNodeNormals.str();
697
698 WritePointsToGnuplot(nameTractionNodeNormals, nodeNormalArray);
699
700
701
702 // Traction (x,y)
703 std::vector< std::vector<FloatArray> > nodeTractionArray;
704 for(size_t i = 0; i < numTracEl; i++) {
705
706 std::vector<FloatArray> tractions;
707 FloatArray tS, tE;
708
709 iBC.giveTraction(i, tS, tE, VM_Total, tStep);
710
711 tractions.push_back(tS);
712 tractions.push_back(tE);
713 nodeTractionArray.push_back(tractions);
714 }
715
716 std :: stringstream strTractions;
717 strTractions << "TractionsGnuplotTime" << time << ".dat";
718 std :: string nameTractions = strTractions.str();
719
720 WritePointsToGnuplot(nameTractions, nodeTractionArray);
721
722
723
724 // Arc position along the boundary
725 std::vector< std::vector<FloatArray> > arcPosArray;
726 for(size_t i = 0; i < numTracEl; i++) {
727 std::vector<FloatArray> arcPos;
728 double xiS = 0.0, xiE = 0.0;
729 iBC.giveTractionElArcPos(i, xiS, xiE);
730 arcPos.push_back( Vec1(xiS) );
731 arcPos.push_back( Vec1(xiE) );
732
733 arcPosArray.push_back(arcPos);
734 }
735
736 std :: stringstream strArcPos;
737 strArcPos << "ArcPosGnuplotTime" << time << ".dat";
738 std :: string nameArcPos = strArcPos.str();
739
740 WritePointsToGnuplot(nameArcPos, arcPosArray);
741
742
743 // Traction (normal, tangent)
744 std::vector< std::vector<FloatArray> > nodeTractionNTArray;
745 for(size_t i = 0; i < numTracEl; i++) {
746
747 std::vector<FloatArray> tractions;
748 FloatArray tS, tE;
749
750 iBC.giveTraction(i, tS, tE, VM_Total, tStep);
751 FloatArray n,t;
752 iBC.giveTractionElNormal(i, n, t);
753
754
755 double tSn = tS.dotProduct(n,2);
756 double tSt = tS.dotProduct(t,2);
757 tractions.push_back(Vec2(tSn ,tSt));
758
759 double tEn = tE.dotProduct(n,2);
760 double tEt = tE.dotProduct(t,2);
761 tractions.push_back(Vec2(tEn, tEt));
762 nodeTractionNTArray.push_back(tractions);
763 }
764
765 std :: stringstream strTractionsNT;
766 strTractionsNT << "TractionsNormalTangentGnuplotTime" << time << ".dat";
767 std :: string nameTractionsNT = strTractionsNT.str();
768
769 WritePointsToGnuplot(nameTractionsNT, nodeTractionNTArray);
770
771
772
773 // Boundary points and displacements
774 IntArray boundaries;
775 iBC.giveBoundaries(boundaries);
776
777 std::vector< std::vector<FloatArray> > bndNodes;
778
779 for ( int pos = 1; pos <= boundaries.giveSize() / 2; ++pos ) {
780
781 Element *e = iBC.giveDomain()->giveElement( boundaries.at(pos * 2 - 1) );
782 int boundary = boundaries.at(pos * 2);
783
784 const auto &bNodes = e->giveInterpolation()->boundaryGiveNodes(boundary, e->giveGeometryType());
785
786 std::vector<FloatArray> bndSegNodes;
787
788 // Add the start and end nodes of the segment
789 DofManager *startNode = e->giveDofManager( bNodes[0] );
790
791 Dof *dSu = startNode->giveDofWithID(D_u);
792 double dU = dSu->giveUnknown(VM_Total, tStep);
793
794 Dof *dSv = startNode->giveDofWithID(D_v);
795 double dV = dSv->giveUnknown(VM_Total, tStep);
796
797 bndSegNodes.push_back(FloatArray::fromConcatenated({startNode->giveCoordinates(),Vec2(dU,dV)}));
798
799 DofManager *endNode = e->giveDofManager( bNodes[1] );
800
801 Dof *dEu = endNode->giveDofWithID(D_u);
802 dU = dEu->giveUnknown(VM_Total, tStep);
803
804 Dof *dEv = endNode->giveDofWithID(D_v);
805 dV = dEv->giveUnknown(VM_Total, tStep);
806
807 bndSegNodes.push_back(FloatArray::fromConcatenated({endNode->giveCoordinates(),Vec2(dU,dV)}));
808
809 bndNodes.push_back(bndSegNodes);
810 }
811
812 std :: stringstream strBndNodes;
813 strBndNodes << "BndNodesGnuplotTime" << time << ".dat";
814 std :: string nameBndNodes = strBndNodes.str();
815
816 WritePointsToGnuplot(nameBndNodes, bndNodes);
817
818 }
819}
820
822{
823 // Homogenized strain
824 double timeFactor = d.giveBc(bc)->giveTimeFunction()->evaluateAtTime(tStep->giveTargetTime());
825 printf("timeFactor: %e\n", timeFactor );
826 grad.times(timeFactor);
827 printf("Mean grad computed in Gnuplot export module: "); grad.printYourself();
828
829 double time = tStep->giveTargetTime();
830
831
832 std :: stringstream strMeanGrad;
833 strMeanGrad << "PrescribedGradientGnuplotMeanGrad" << bc << "Time" << time << ".dat";
834 std :: string nameMeanGrad = strMeanGrad.str();
835 std::vector<double> componentArrayGrad, gradArray;
836
837 for(int i = 1; i <= grad.giveSize(); i++) {
838 componentArrayGrad.push_back(i);
839 gradArray.push_back(grad.at(i));
840 }
841
842 XFEMDebugTools::WriteArrayToGnuplot(nameMeanGrad, componentArrayGrad, gradArray);
843}
844
846{
847 std::vector< std::vector<FloatArray> > pointArray;
848
849 if(iDomain.giveNumberOfSpatialDimensions() == 2) {
850 // Write all element edges to gnuplot
851 for ( auto &el : iDomain.giveElements() ) {
852 int numEdges = el->giveNumberOfNodes();
853
854
855 for ( int edgeIndex = 1; edgeIndex <= numEdges; edgeIndex++ ) {
856 std::vector<FloatArray> points;
857
858 const auto &bNodes = el->giveInterpolation()->boundaryGiveNodes(edgeIndex, el->giveGeometryType());
859
860 int niLoc = bNodes.at(1);
861 const auto &xS = el->giveNode(niLoc)->giveCoordinates();
862 points.push_back(xS);
863
864 int njLoc = bNodes.at( bNodes.giveSize() );
865 const auto &xE = el->giveNode(njLoc)->giveCoordinates();
866 points.push_back(xE);
867
868 pointArray.push_back(points);
869 }
870
871 }
872
873
874 double time = 0.0;
875
876 TimeStep *ts = emodel->giveCurrentStep();
877 if ( ts != NULL ) {
878 time = ts->giveTargetTime();
879 }
880
881 std :: stringstream strMesh;
882 strMesh << "MeshGnuplotTime" << time << ".dat";
883 std :: string nameMesh = strMesh.str();
884
885 WritePointsToGnuplot(nameMesh, pointArray);
886 }
887}
888
889void GnuplotExportModule :: outputNodeDisp(DofManager &iDMan, TimeStep *tStep)
890{
891 // Append node solution to history
892 FloatArray nodeSol;
893 iDMan.giveCompleteUnknownVector(nodeSol, VM_Total, tStep);
894
895 mMonitorNodeDispHist.push_back(nodeSol);
896
897
898 // Write to file
899 std::vector< std::vector<FloatArray> > nodeDispHist;
900 nodeDispHist.push_back(mMonitorNodeDispHist);
901
902 std :: string name = "MonitorNodeSolGnuplot.dat";
903 WritePointsToGnuplot(name, nodeDispHist);
904}
905
906void GnuplotExportModule :: outputInterfaceEl(Domain &d, TimeStep *tStep) {
907// printf("Exporting interface el.\n");
908
909 std::vector<FloatArray> points, tractions, tractionsProj;
910
911 int numEl = d.giveNumberOfElements();
912 for(int i = 1; i <= numEl; i++) {
913 Element *el = d.giveElement(i);
914
915 StructuralInterfaceElement *intEl = dynamic_cast<StructuralInterfaceElement*>(el);
916
917 if(intEl) {
918 printf("Found StructuralInterfaceElement.\n");
919
921
922 int numGP = ir->giveNumberOfIntegrationPoints();
923// printf("numGP: %d\n", numGP );
924
925 for(int gpInd = 0; gpInd < numGP; gpInd++ ) {
926 GaussPoint *gp = ir->getIntegrationPoint(gpInd);
927// gp->giveGlobalCoordinates().printYourself();
928
929 points.push_back( (gp->giveGlobalCoordinates()) );
930
931 MaterialStatus *ms = static_cast< MaterialStatus * >( gp->giveMaterialStatus() );
933
934 FloatArray traction = ims->giveTraction();
935// printf("traction: "); traction.printYourself();
936 tractions.push_back(traction);
937
938
939 FloatArray tractionProj = ims->giveProjectedTraction();
940 tractionsProj.push_back(tractionProj);
941
942 }
943
944 }
945 }
946
947 // Export x vs normal traction
948
949 double time = 0.0;
950
951 TimeStep *ts = emodel->giveCurrentStep();
952 if ( ts != NULL ) {
953 time = ts->giveTargetTime();
954 }
955
956 FILE * pFileX;
957 std :: stringstream strFileNameX;
958 strFileNameX << "NormalTractionVsXTime" << time << ".dat";
959 std :: string nameStringX = strFileNameX.str();
960
961 pFileX = fopen ( nameStringX.c_str() , "wb" );
962
963 fprintf(pFileX, "#x tn\n");
964 for ( size_t j = 0; j < points.size(); j++ ) {
965 fprintf(pFileX, "%e %e\n", points[j][0], tractions[j].at(3) );
966 }
967
968 fclose(pFileX);
969
970
971// FILE * pFileXProj;
972// std :: stringstream strFileNameXProj;
973// strFileNameXProj << "NormalTractionProjVsXTime" << time << ".dat";
974// std :: string nameStringXProj = strFileNameXProj.str();
975//
976// pFileXProj = fopen ( nameStringXProj.c_str() , "wb" );
977//
978// fprintf(pFileXProj, "#x tn\n");
979// for ( size_t j = 0; j < points.size(); j++ ) {
981// fprintf(pFileXProj, "%e %e\n", points[j][0], tractionsProj[j].at(3) );
982// }
983//
984// fclose(pFileXProj);
985
986
987 // Export x vs shear traction
988
989 FILE * pFileXshear;
990 std :: stringstream strFileNameXshear;
991 strFileNameXshear << "ShearTractionVsXTime" << time << ".dat";
992 std :: string nameStringXshear = strFileNameXshear.str();
993
994 pFileXshear = fopen ( nameStringXshear.c_str() , "wb" );
995
996 fprintf(pFileXshear, "#x tn\n");
997 for ( size_t j = 0; j < points.size(); j++ ) {
998 fprintf(pFileXshear, "%e %e\n", points[j][0], tractions[j].at(1) );
999 }
1000
1001 fclose(pFileXshear);
1002
1003
1004
1005
1006 // Export y vs normal traction
1007 FILE * pFileY;
1008 std :: stringstream strFileNameY;
1009 strFileNameY << "NormalTractionVsYTime" << time << ".dat";
1010 std :: string nameStringY = strFileNameY.str();
1011
1012 pFileY = fopen ( nameStringY.c_str() , "wb" );
1013
1014 fprintf(pFileY, "#y tn\n");
1015 for ( size_t j = 0; j < points.size(); j++ ) {
1016 fprintf(pFileY, "%e %e\n", points[j][1], tractions[j].at(3) );
1017 }
1018
1019 fclose(pFileY);
1020
1021
1022
1023
1024 // Export y vs shear traction
1025 FILE * pFileYshear;
1026 std :: stringstream strFileNameYshear;
1027 strFileNameYshear << "ShearTractionVsYTime" << time << ".dat";
1028 std :: string nameStringYshear = strFileNameYshear.str();
1029
1030 pFileYshear = fopen ( nameStringYshear.c_str() , "wb" );
1031
1032 fprintf(pFileYshear, "#y tn\n");
1033 for ( size_t j = 0; j < points.size(); j++ ) {
1034 fprintf(pFileYshear, "%e %e\n", points[j][1], tractions[j].at(1) );
1035 }
1036
1037 fclose(pFileYshear);
1038
1039}
1040
1041
1042void GnuplotExportModule :: WritePointsToGnuplot(const std :: string &iName, const std :: vector< std::vector<FloatArray> > &iPoints)
1043{
1044 std :: ofstream file;
1045 file.open( iName.data() );
1046
1047 // Set some output options
1048 file << std :: scientific;
1049
1050 file << "# x y\n";
1051
1052 for(auto posVec: iPoints) {
1053 for(auto pos: posVec) {
1054
1055 for(int i = 0; i < pos.giveSize(); i++) {
1056 file << pos[i] << " ";
1057 }
1058 file << "\n";
1059
1060// file << pos[0] << " " << pos[1] << "\n";
1061 }
1062 file << "\n";
1063 }
1064
1065 file.close();
1066
1067}
1068
1069
1070} // end namespace oofem
#define REGISTER_ExportModule(class)
virtual void computeTangentialSignDist(double &oDist, const FloatArray &iPoint, double &oMinDistArcPos) const =0
virtual double give(Dof *dof, ValueModeType mode, TimeStep *tStep)
const std ::vector< GaussPoint * > & giveCohesiveZoneGaussPoints() const
Definition crack.h:68
const std ::vector< double > & giveCohesiveZoneArcPositions() const
Definition crack.h:69
double computeLength()
Definition crack.C:149
const FloatArray & giveCoordinates() const
Definition dofmanager.h:390
Dof * giveDofWithID(int dofID) const
Definition dofmanager.C:127
void giveCompleteUnknownVector(FloatArray &answer, ValueModeType mode, TimeStep *tStep)
Definition dofmanager.C:709
virtual double giveUnknown(ValueModeType mode, TimeStep *tStep)=0
virtual int giveBcId()=0
int giveNumberOfBoundaryConditions() const
Returns number of boundary conditions in domain.
Definition domain.h:469
int giveNumberOfElements() const
Returns number of elements in domain.
Definition domain.h:463
DofManager * giveDofManager(int n)
Definition domain.C:317
Element * giveElement(int n)
Definition domain.C:165
int giveNumberOfSpatialDimensions()
Returns number of spatial dimensions.
Definition domain.C:1137
GeneralBoundaryCondition * giveBc(int n)
Definition domain.C:246
std ::vector< std ::unique_ptr< Element > > & giveElements()
Definition domain.h:294
XfemManager * giveXfemManager()
Definition domain.C:378
bool hasXfemManager()
Definition domain.C:389
virtual FEInterpolation * giveInterpolation() const
Definition element.h:648
DofManager * giveDofManager(int i) const
Definition element.C:553
virtual IntegrationRule * giveDefaultIntegrationRulePtr()
Definition element.h:886
virtual Element_Geometry_Type giveGeometryType() const =0
const TipInfo & giveTipInfo() const
EnrichmentFront * giveEnrichmentFrontStart()
virtual void callGnuplotExportModule(GnuplotExportModule &iExpMod, TimeStep *tStep)
EnrichmentFront * giveEnrichmentFrontEnd()
virtual void initializeFrom(InputRecord &ir)
Initializes receiver according to object description stored in input record.
EngngModel * emodel
Problem pointer.
bool testTimeStepOutput(TimeStep *tStep)
virtual IntArray boundaryGiveNodes(int boundary, const Element_Geometry_Type) const =0
Domain * giveDomain() const
Definition femcmpnn.h:97
int giveNumber() const
Definition femcmpnn.h:104
double & at(Index i)
Definition floatarray.h:202
double dotProduct(const FloatArray &x) const
Definition floatarray.C:524
Index giveSize() const
Returns the size of receiver.
Definition floatarray.h:261
virtual void printYourself() const
Definition floatarray.C:762
static FloatArray fromConcatenated(std::initializer_list< FloatArray > ini)
Definition floatarray.C:146
void times(double s)
Definition floatarray.C:834
virtual double evaluateAtTime(double t)
Definition function.C:78
virtual double evaluate(TimeStep *tStep, ValueModeType mode)
Definition function.C:57
const FloatArray & giveGlobalCoordinates()
Definition gausspoint.h:159
IntegrationPointStatus * giveMaterialStatus(IntegrationPointStatusIDType key=IPSID_Default)
Definition gausspoint.h:204
void giveSubPolygon(std ::vector< FloatArray > &oPoints, const double &iXiStart, const double &iXiEnd) const
BasicGeometry * giveGeometry()
void outputNodeDisp(DofManager &iDMan, TimeStep *tStep)
std::unordered_map< int, std::vector< double > > mCrackLengthHist
std::vector< FloatArray > mMonitorNodeDispHist
GnuplotExportModule(int n, EngngModel *e)
void outputGradient(int bc, Domain &d, FloatArray &grad, TimeStep *tStep)
void outputXFEM(EnrichmentItem &iEI, TimeStep *tStep)
static void WritePointsToGnuplot(const std ::string &iName, const std ::vector< std::vector< FloatArray > > &iPoints)
void outputMesh(Domain &iDomain)
void outputInterfaceEl(Domain &d, TimeStep *tStep)
std::vector< std::vector< double > > mDispHist
std::vector< double > mTimeHist
std::vector< std::vector< FloatArray > > mReactionForceHistory
void outputReactionForces(TimeStep *tStep)
void doOutput(TimeStep *tStep, bool forcedOutput=false) override
void initializeFrom(InputRecord &ir) override
Initializes receiver according to object description stored in input record.
void outputBoundaryCondition(PrescribedGradient &iBC, TimeStep *tStep)
std ::unique_ptr< MaterialForceEvaluator > mpMatForceEvaluator
void outputXFEMGeometry(const std::vector< std::vector< FloatArray > > &iEnrItemPoints)
virtual bool hasField(InputFieldType id)=0
Returns true if record contains field identified by idString keyword.
void giveOptionalField(T &answer, InputFieldType id)
int & at(std::size_t i)
Definition intarray.h:104
int giveSize() const
Definition intarray.h:211
int giveNumberOfIntegrationPoints() const
GaussPoint * getIntegrationPoint(int n)
void computeField(FloatArray &sigma, TimeStep *tStep) override
void giveTractionElArcPos(size_t iElInd, double &oXiStart, double &oXiEnd) const
void giveBoundaries(IntArray &oBoundaries)
void giveTractionElCoord(size_t iElInd, FloatArray &oStartCoord, FloatArray &oEndCoord) const
void computeField(FloatArray &sigma, TimeStep *tStep) override
void giveTractionElNormal(size_t iElInd, FloatArray &oNormal, FloatArray &oTangent) const
void giveTraction(size_t iElInd, FloatArray &oStartTraction, FloatArray &oEndTraction, ValueModeType mode, TimeStep *tStep)
void computeField(FloatArray &sigma, TimeStep *tStep) override
void buildReactionTable(IntArray &restrDofMans, IntArray &restrDofs, IntArray &eqn, TimeStep *tStep, int di)
void computeReaction(FloatArray &answer, TimeStep *tStep, int di)
const FloatArray & giveNormal() const
const FloatArrayF< 3 > & giveJump() const
Returns the const pointer to receiver's jump.
const FloatArrayF< 3 > & giveFirstPKTraction() const
Returns the const pointer to receiver's first Piola-Kirchhoff traction vector.
const FloatArrayF< 2 > & giveProjectedTraction() const
Returns the projected traction.
const FloatArrayF< 3 > & giveTraction() const
Returns the const pointer to receiver's traction vector.
const FloatArray & giveStressVector() const
Returns the const pointer to receiver's stress vector.
double giveTargetTime()
Returns target time.
Definition timestep.h:164
static void WriteArrayToGnuplot(const std ::string &iName, const std ::vector< double > &iX, const std ::vector< double > &iY)
EnrichmentItem * giveEnrichmentItem(int n)
int giveNumberOfEnrichmentItems() const
#define OOFEM_ERROR(...)
Definition error.h:79
#define _IFT_GnuplotExportModule_cracklength
#define _IFT_GnuplotExportModule_BoundaryConditionsExtra
#define _IFT_GnuplotExportModule_mesh
#define _IFT_GnuplotExportModule_xfem
#define _IFT_GnuplotExportModule_BoundaryConditions
#define _IFT_GnuplotExportModule_ReactionForces
#define _IFT_GnuplotExportModule_materialforceradii
#define _IFT_GnuplotExportModule_interface_el
#define _IFT_GnuplotExportModule_monitornode
static FloatArray Vec2(const double &a, const double &b)
Definition floatarray.h:606
static FloatArray Vec1(const double &a)
Definition floatarray.h:605

This page is part of the OOFEM-3.0 documentation. Copyright Copyright (C) 1994-2025 Borek Patzak Bořek Patzák
Project e-mail: oofem@fsv.cvut.cz
Generated at for OOFEM by doxygen 1.15.0 written by Dimitri van Heesch, © 1997-2011