OOFEM 3.0
Loading...
Searching...
No Matches
matlabexportmodule.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#include <algorithm>
36#include <vector>
37#include <string>
38#include <iostream>
39#include <sstream>
40#include <iterator>
41
42#include "matlabexportmodule.h"
43#include "engngm.h"
44#include "node.h"
45#include "mathfem.h"
46#include "gausspoint.h"
47#include "weakperiodicbc.h"
49#include "timestep.h"
50#include "classfactory.h"
51#include "set.h"
53#include "prescribedmean.h"
54#include "feinterpol.h"
55
56#ifdef __FM_MODULE
57#include "fm/tr21stokes.h"
58#include "fm/tet21stokes.h"
59#include "fm/stokesflow.h"
60#endif
61
62#ifdef __SM_MODULE
69#endif
70
71
72namespace oofem {
73
75
76MatlabExportModule :: MatlabExportModule(int n, EngngModel *e) : ExportModule(n, e), internalVarsToExport(), primaryVarsToExport()
77{
78 exportMesh = false;
79 exportData = false;
80 exportArea = false;
81 exportSpecials = false;
82 exportReactionForces = false;
83 reactionForcesDofManList.clear();
84 dataDofManList.clear();
85 exportIntegrationPointFields = false;
86 elList.clear();
87 reactionForcesNodeSet = 0;
88 dataNodeSet = 0;
89 IPFieldsElSet = 0;
90 noscaling = false;
91}
92
93
94MatlabExportModule :: ~MatlabExportModule()
95{ }
96
97
98void
99MatlabExportModule :: initializeFrom(InputRecord &ir)
100{
101 ExportModule :: initializeFrom(ir);
102
104
106 if ( exportData ) {
108 }
109
113
114
116 reactionForcesDofManList.resize(0);
117 if ( exportReactionForces ) {
119 this->reactionForcesNodeSet = 0;
121 }
122
124 elList.resize(0);
128 IPFieldsElSet = 0;
130 }
131
133
134}
135
136
137
138void
139MatlabExportModule :: computeArea(TimeStep *tStep)
140{
141 Domain *domain = emodel->giveDomain(1);
142
143 smax.clear();
144 smin.clear();
145
146 for (int i = 1; i <= domain->giveNumberOfSpatialDimensions(); i++) {
147 smax.push_back(domain->giveDofManager(1)->giveCoordinate(i));
148 smin.push_back(domain->giveDofManager(1)->giveCoordinate(i));
149 }
150
151 for ( int i = 0; i < domain->giveNumberOfDofManagers(); i++ ) {
152 for (int j = 0; j < domain->giveNumberOfSpatialDimensions(); j++) {
153 smax.at(j)=max(smax.at(j), domain->giveDofManager(i+1)->giveCoordinate(j+1));
154 smin.at(j)=min(smin.at(j), domain->giveDofManager(i+1)->giveCoordinate(j+1));
155 }
156 }
157
158 Area = 0;
159 Volume = 0;
160
161 if ( domain->giveNumberOfSpatialDimensions() == 2 ) {
162 for ( auto &elem : domain->giveElements() ) {
163 Area += elem->computeArea();
164 }
165 } else {
166
167 for (size_t i = 0; i < partVolume.size(); i++ ) {
168 partVolume.at(i) = 0.0;
169 }
170
171 for ( auto &elem : domain->giveElements() ) {
172 //
173 double v;
174#ifdef __SM_MODULE
175 if ( NLStructuralElement *e = dynamic_cast< NLStructuralElement *>( elem.get() ) ) {
176 v = e->computeCurrentVolume(tStep);
177 } else {
178#endif
179 v = elem->computeVolume();
180#ifdef __SM_MODULE
181 }
182#endif
183
184 std :: string eName ( elem->giveClassName() );
185 int j = -1;
186
187 //printf("%s\n", eName.c_str());
188
189 for ( size_t k = 0; k < partName.size(); k++ ) {
190 //printf("partName.at(%u) = %s\n", k, partName.at(k).c_str() );
191 if ( eName.compare(partName.at(k)) == 0 ) {
192 j = k;
193 break;
194 }
195 }
196
197 if ( j == -1 ) {
198 partName.push_back( elem->giveClassName() );
199 partVolume.push_back( v );
200 } else {
201 partVolume.at(j) += v;
202 }
203
204 Volume += v;
205
206 }
207 }
208
209}
210
211
212void
213MatlabExportModule :: doOutput(TimeStep *tStep, bool forcedOutput)
214{
215 if ( !( testTimeStepOutput(tStep) || forcedOutput ) ) {
216 return;
217 }
218
219
220 int nelem = this->elList.giveSize();
221 if ( nelem == 0 ) { // no list given, export all elements
222 this->elList.enumerate(this->emodel->giveDomain(1)->giveNumberOfElements());
223 }
224
225 FILE *FID;
226 FID = giveOutputStream(tStep);
227 Domain *domain = emodel->giveDomain(1);
229
230 // Output header
231 fprintf( FID, "%%%% OOFEM generated export file \n");
232 fprintf( FID, "%% Output for time %f\n", tStep->giveTargetTime() );
233
234
235 fprintf( FID, "function [mesh area data specials ReactionForces IntegrationPointFields]=%s\n\n", functionname.c_str() );
236
237 if ( exportMesh ) {
238 doOutputMesh(tStep, FID);
239 } else {
240 fprintf(FID, "\tmesh=[];\n");
241 }
242
243 if ( exportData ) {
244 doOutputData(tStep, FID);
245 } else {
246 fprintf(FID, "\tdata=[];\n");
247 }
248
249 if ( exportArea ) {
250 computeArea(tStep);
251 fprintf(FID, "\tarea.xmax=%f;\n", smax.at(0));
252 fprintf(FID, "\tarea.xmin=%f;\n", smin.at(0));
253 fprintf(FID, "\tarea.ymax=%f;\n", smax.at(1));
254 fprintf(FID, "\tarea.ymin=%f;\n", smin.at(1));
255 if ( ndim == 2 ) {
256 fprintf(FID, "\tarea.area=%f;\n", Area);
257 fprintf(FID, "\tvolume=[];\n");
258 } else {
259 fprintf(FID, "\tarea.zmax=%f;\n", smax.at(2));
260 fprintf(FID, "\tarea.zmin=%f;\n", smin.at(2));
261 fprintf(FID, "\tarea.area=[];\n");
262 fprintf(FID, "\tarea.volume=%f;\n", Volume);
263 for (size_t i=0; i<this->partName.size(); i++) {
264 fprintf(FID, "\tarea.volume_%s=%f;\n", partName.at(i).c_str(), partVolume.at(i));
265 }
266 }
267 } else {
268 fprintf(FID, "\tarea.area=[];\n");
269 fprintf(FID, "\tarea.volume=[];\n");
270 }
271
272 if ( exportSpecials ) {
273 if ( !exportArea ) {
274 computeArea(tStep);
275 }
276
277 doOutputSpecials(tStep, FID);
278 } else {
279 fprintf(FID, "\tspecials=[];\n");
280 }
281
282 // Reaction forces
283 if ( exportReactionForces ) {
284 doOutputReactionForces(tStep, FID);
285 } else {
286 fprintf(FID, "\tReactionForces=[];\n");
287 }
288
289 // Internal variables in integration points
292 } else {
293 fprintf(FID, "\tIntegrationPointFields=[];\n");
294 }
295
296 // Homogenized quantities
297 if ( exportHomogenizeIST ) {
298 doOutputHomogenizeDofIDs(tStep, FID);
299 }
300
301 fprintf(FID, "\nend\n");
302 fclose(FID);
303}
304
305
306void
307MatlabExportModule :: doOutputMesh(TimeStep *tStep, FILE *FID)
308{
309 Domain *domain = emodel->giveDomain(1);
310
311 fprintf(FID, "\tmesh.p=[");
312 for ( auto &dman : domain->giveDofManagers() ) {
313 for ( int j = 1; j <= domain->giveNumberOfSpatialDimensions(); j++) {
314 double c = dman->giveCoordinate(j);
315 fprintf(FID, "%f, ", c);
316 }
317 fprintf(FID, "; ");
318 }
319
320 fprintf(FID, "]';\n");
321
322 int numberOfDofMans=domain->giveElement(1)->giveNumberOfDofManagers();
323
324 fprintf(FID, "\tmesh.t=[");
325 for ( auto &elem : domain->giveElements() ) {
326 if ( elem->giveNumberOfDofManagers() == numberOfDofMans ) {
327 for ( int j = 1; j <= elem->giveNumberOfDofManagers(); j++ ) {
328 fprintf( FID, "%d,", elem->giveDofManagerNumber(j) );
329 }
330 }
331 fprintf(FID, ";");
332 }
333
334 fprintf(FID, "]';\n");
335}
336
337
338void
339MatlabExportModule :: doOutputData(TimeStep *tStep, FILE *FID)
340{
341 Domain *domain = emodel->giveDomain(1);
342 std :: vector< int >DofIDList;
343 std :: vector< int > :: iterator it;
344 std :: vector< std :: vector< double > >valuesList;
345
346 if ( this->dataNodeSet > 0 ) {
347 // Export data based on node set
348 Set *set = domain->giveSet( this->dataNodeSet );
350 for (auto iDM : dataDofManList) {
351 DofManager *dman = domain->giveDofManager(iDM);
352 for ( Dof *thisDof: *dman ) {
353 it = std :: find( DofIDList.begin(), DofIDList.end(), thisDof->giveDofID() );
354
355 double value = thisDof->giveUnknown(VM_Total, tStep);
356 if ( it == DofIDList.end() ) {
357 DofIDList.push_back( thisDof->giveDofID() );
358 valuesList.push_back({value});
359 } else {
360 std::size_t pos = it - DofIDList.begin();
361 valuesList[pos].push_back(value);
362 }
363 }
364 }
365 } else {
366 // Export data from all dofmanagers
367 for ( auto &dman : domain->giveDofManagers() ) {
368 for ( Dof *thisDof: *dman ) {
369 it = std :: find( DofIDList.begin(), DofIDList.end(), thisDof->giveDofID() );
370
371 double value = thisDof->giveUnknown(VM_Total, tStep);
372 if ( it == DofIDList.end() ) {
373 DofIDList.push_back( thisDof->giveDofID() );
374 valuesList.push_back({value});
375 } else {
376 std::size_t pos = it - DofIDList.begin();
377 valuesList[pos].push_back(value);
378 }
379 }
380 }
381 }
382
383
384
385 fprintf(FID, "\tdata.DofIDs=[");
386 for ( auto &dofid : DofIDList ) {
387 fprintf( FID, "%d, ", dofid );
388 }
389
390 fprintf(FID, "];\n");
391
392 for ( size_t i = 0; i < valuesList.size(); i++ ) {
393 fprintf(FID, "\tdata.a{%lu}=[", static_cast< long unsigned int >(i) + 1);
394 for ( double val: valuesList[i] ) {
395 fprintf( FID, "%f,", val );
396 }
397
398 fprintf(FID, "];\n");
399 }
400
401}
402
403
404void
405MatlabExportModule :: doOutputSpecials(TimeStep *tStep, FILE *FID)
406{
407// FloatArray v_hat, GradPTemp, v_hatTemp;
408
409 Domain *domain = emodel->giveDomain(1);
410/*
411 v_hat.clear();
412
414#if 0
415 for ( auto &elem : domain->giveElements() ) {
416#ifdef __FM_MODULE
417
418 if ( Tr21Stokes *Tr = dynamic_cast< Tr21Stokes * >( elem.get() ) ) {
419 Tr->giveIntegratedVelocity(v_hatTemp, tStep);
420 v_hat.add(v_hatTemp);
421 } else if ( Tet21Stokes *Tet = dynamic_cast< Tet21Stokes * >( elem.get() ) ) {
422 Tet->giveIntegratedVelocity(v_hatTemp, tStep);
423 v_hat.add(v_hatTemp);
424 }
425
426#endif
427 }
428#endif
429
430 // Compute intrinsic area/volume
431 double intrinsicSize = 1.0;
432
433 std :: vector <double> V;
434
435 for ( int i = 0; i < (int)smax.size(); i++ ) {
436 intrinsicSize *= ( smax.at(i) - smin.at(i) );
437 }
438
439 for ( double vh: v_hat ) {
440 V.push_back(vh);
441 }
442
443 fprintf(FID, "\tspecials.velocitymean=[");
444 if (V.size()>0) {
445 for (int i=0; i<ndim; i++) {
446 fprintf(FID, "%e", V.at(i));
447 if (i!=(ndim-1)) fprintf (FID, ", ");
448 }
449 fprintf(FID, "];\n");
450 } else {
451 fprintf(FID, "]; %% No velocities\n");
452 }
453
454 */
455
456 // Output weak periodic boundary conditions
457 unsigned int wpbccount = 1, sbsfcount = 1, mcount = 1, pdsdcount=1, pdsncount=1, trccount=1;
458 [[maybe_unused]] unsigned int pdsmcount=1;
459
460 for ( auto &gbc : domain->giveBcs() ) {
461 WeakPeriodicBoundaryCondition *wpbc = dynamic_cast< WeakPeriodicBoundaryCondition * >( gbc.get() );
462 if ( wpbc ) {
463 for ( int j = 1; j <= wpbc->giveNumberOfInternalDofManagers(); j++ ) {
464 fprintf(FID, "\tspecials.weakperiodic{%u}.descType=%u;\n", wpbccount, wpbc->giveBasisType() );
465 fprintf(FID, "\tspecials.weakperiodic{%u}.coefficients=[", wpbccount);
466 for ( Dof *dof: *wpbc->giveInternalDofManager(j) ) {
467 double X = dof->giveUnknown(VM_Total, tStep);
468 fprintf(FID, "%e\t", X);
469 }
470
471 fprintf(FID, "];\n");
472 wpbccount++;
473 }
474 }
475 SolutionbasedShapeFunction *sbsf = dynamic_cast< SolutionbasedShapeFunction *>( gbc.get());
476 if (sbsf) {
477 fprintf(FID, "\tspecials.solutionbasedsf{%u}.values=[", sbsfcount);
478 for ( Dof *dof: *sbsf->giveInternalDofManager(1) ) { // Only one internal dof manager
479 double X = dof->giveUnknown(VM_Total, tStep);
480 fprintf(FID, "%e\t", X);
481 }
482 fprintf(FID, "];\n");
483 sbsfcount++;
484 }
485 PrescribedMean *m = dynamic_cast<PrescribedMean *> ( gbc.get() );
486 if (m) {
487 fprintf(FID, "\tspecials.prescribedmean{%u}.value=[", mcount);
488 for ( Dof *dof: *m->giveInternalDofManager(1)) {
489 double X = dof->giveUnknown(VM_Total, tStep);
490 fprintf(FID, "%e\t", X);
491 }
492 fprintf(FID, "];\n");
493 mcount++;
494 }
495#ifdef __SM_MODULE
496 PrescribedDispSlipBCDirichletRC *pdsd = dynamic_cast<PrescribedDispSlipBCDirichletRC *>( gbc.get() );
497 if (pdsd) {
498 FloatArray stress, bStress, rStress;
499 pdsd->computeStress(stress, tStep);
500 pdsd->computeTransferStress(bStress, tStep);
501 pdsd->computeReinfStress(rStress, tStep);
502 fprintf(FID, "\tspecials.prescribeddispslipbcdirichletrc{%u}.stress=[", pdsdcount);
503 for ( auto i : stress ) {
504 fprintf(FID, "%e\t", i);
505 }
506 fprintf(FID, "];\n");
507 fprintf(FID, "\tspecials.prescribeddispslipbcdirichletrc{%u}.transferstress=[", pdsdcount);
508 for ( auto i : bStress ) {
509 fprintf(FID, "%e\t", i);
510 }
511 fprintf(FID, "];\n");
512 fprintf(FID, "\tspecials.prescribeddispslipbcdirichletrc{%u}.reinfstress=[", pdsdcount);
513 for ( auto i : rStress ) {
514 fprintf(FID, "%e\t", i);
515 }
516 fprintf(FID, "];\n");
517 pdsdcount++;
518 }
519 PrescribedDispSlipBCNeumannRC *pdsn = dynamic_cast<PrescribedDispSlipBCNeumannRC *>( gbc.get() );
520 if (pdsn) {
521 FloatArray stress, bStress, rStress;
522 pdsn->computeStress(stress, tStep);
523 pdsn->computeTransferStress(bStress, tStep);
524 pdsn->computeReinfStress(rStress, tStep);
525 fprintf(FID, "\tspecials.prescribeddispslipbcneumannrc{%u}.stress=[", pdsncount);
526 for ( auto i : stress ) {
527 fprintf(FID, "%e\t", i);
528 }
529 fprintf(FID, "];\n");
530 fprintf(FID, "\tspecials.prescribeddispslipbcneumannrc{%u}.transferstress=[", pdsncount);
531 for ( auto i : bStress ) {
532 fprintf(FID, "%e\t", i);
533 }
534 fprintf(FID, "];\n");
535 fprintf(FID, "\tspecials.prescribeddispslipbcneumannrc{%u}.reinfstress=[", pdsncount);
536 for ( auto i : rStress ) {
537 fprintf(FID, "%e\t", i);
538 }
539 fprintf(FID, "];\n");
540 pdsncount++;
541 }
542 PrescribedDispSlipMultiple *pdsm = dynamic_cast<PrescribedDispSlipMultiple *>( gbc.get() );
543 if (pdsm) {
544 FloatArray stress, bStress, rStress;
545 pdsm->computeStress(stress, tStep);
546 pdsm->computeTransferStress(bStress, tStep);
547 pdsm->computeReinfStress(rStress, tStep);
548 fprintf(FID, "\tspecials.prescribeddispslipmultiple{%u}.stress=[", pdsncount);
549 for ( auto i : stress ) {
550 fprintf(FID, "%e\t", i);
551 }
552 fprintf(FID, "];\n");
553 fprintf(FID, "\tspecials.prescribeddispslipmultiple{%u}.transferstress=[", pdsncount);
554 for ( auto i : bStress ) {
555 fprintf(FID, "%e\t", i);
556 }
557 fprintf(FID, "];\n");
558 fprintf(FID, "\tspecials.prescribeddispslipmultiple{%u}.reinfstress=[", pdsncount);
559 for ( auto i : rStress ) {
560 fprintf(FID, "%e\t", i);
561 }
562 fprintf(FID, "];\n");
563 pdsmcount++;
564 }
565 TransverseReinfConstraint *trc = dynamic_cast<TransverseReinfConstraint *> ( gbc.get() );
566 if (trc) {
567 FloatArray lambda;
568 trc->computeField(lambda, tStep);
569 fprintf(FID, "\tspecials.transversereinfconstraint{%u}.stress=[", trccount);
570 for ( auto i : lambda ) {
571 fprintf(FID, "%e\t", i);
572 }
573 fprintf(FID, "];\n");
574 trccount++;
575 }
576#endif
577 }
578}
579
580
581void
582MatlabExportModule :: doOutputReactionForces(TimeStep *tStep, FILE *FID)
583{
584
585 int domainIndex = 1;
586 Domain *domain = emodel->giveDomain( domainIndex );
587
588 FloatArray reactions;
589 IntArray dofManMap, dofidMap, eqnMap;
590#ifdef __SM_MODULE
591 StructuralEngngModel *strEngMod = dynamic_cast< StructuralEngngModel * >(emodel);
592 if ( strEngMod ) {
593 strEngMod->buildReactionTable(dofManMap, dofidMap, eqnMap, tStep, domainIndex);
594 strEngMod->computeReaction(reactions, tStep, 1);
595 } else
596#endif
597 {
598 OOFEM_ERROR("Cannot export reaction forces - only implemented for structural problems.");
599 }
600
601 // Set the nodes and elements to export based on sets
602 if ( this->reactionForcesNodeSet > 0 ) {
603 Set *set = domain->giveSet( this->reactionForcesNodeSet );
605 }
606
607
608 int numDofManToExport = this->reactionForcesDofManList.giveSize();
609 if ( numDofManToExport == 0 ) { // No dofMan's given - export every dMan with reaction forces
610
611 for (int i = 1; i <= domain->giveNumberOfDofManagers(); i++) {
612 if ( dofManMap.contains(i) ) {
613 this->reactionForcesDofManList.followedBy(i);
614 }
615 }
616 numDofManToExport = this->reactionForcesDofManList.giveSize();
617 }
618
619
620 // Output header
621 fprintf( FID, "\n %%%% Export of reaction forces \n\n" );
622
623 // Output the dofMan numbers that are exported
624 fprintf( FID, "\tReactionForces.DofManNumbers = [" );
625 for ( int i = 1; i <= numDofManToExport; i++ ) {
626 fprintf( FID, "%i ", this->reactionForcesDofManList.at(i) );
627 }
628 fprintf( FID, "];\n" );
629
630
631 // Define the reaction forces as a cell object
632 fprintf( FID, "\tReactionForces.ReactionForces = cell(%i,1); \n", numDofManToExport );
633 fprintf( FID, "\tReactionForces.DofIDs = cell(%i,1); \n", numDofManToExport );
634
635
636 // Output the reaction forces for each dofMan. If a certain dof is not prescribed zero is exported.
637 IntArray dofIDs;
638 for ( int i = 1; i <= numDofManToExport; i++ ) {
639 int dManNum = this->reactionForcesDofManList.at(i);
640
641 fprintf(FID, "\tReactionForces.ReactionForces{%i} = [", i);
642 if ( dofManMap.contains( dManNum ) ) {
643
644 DofManager *dofMan = domain->giveDofManager( dManNum );
645 dofIDs.clear();
646
647 for ( Dof *dof: *dofMan ) {
648 int num = dof->giveEquationNumber( EModelDefaultPrescribedEquationNumbering() );
649 int pos = eqnMap.findFirstIndexOf( num );
650 dofIDs.followedBy(dof->giveDofID());
651 if ( pos > 0 ) {
652 fprintf(FID, "%e ", reactions.at(pos));
653 } else {
654 fprintf( FID, "%e ", 0.0 ); // if not prescibed output zero
655 }
656 }
657 }
658 fprintf(FID, "];\n");
659
660 // Output dof ID's
661
662 fprintf( FID, "\tReactionForces.DofIDs{%i} = [", i);
663 if ( dofManMap.contains( dManNum ) ) {
664 for ( int id: dofIDs ) {
665 fprintf( FID, "%i ", id );
666 }
667 }
668 fprintf(FID, "];\n");
669 }
670
671 // Output the current load level (useful for CALM solver)
672 double loadLevel = domain->giveEngngModel()->giveLoadLevel();
673 fprintf( FID, "\tReactionForces.LoadLevel = [" );
674 fprintf( FID, "%.9e", loadLevel);
675 fprintf( FID, "];\n" );
676}
677
678
679void
680MatlabExportModule :: doOutputIntegrationPointFields(TimeStep *tStep, FILE *FID)
681{
682
683 int domainIndex = 1;
684 Domain *domain = emodel->giveDomain( domainIndex );
685
686 // Output header
687 fprintf( FID, "\n %%%% Export of internal variables in integration points \n\n" );
688 fprintf( FID, "\n %% for interpretation of internal var. numbers see internalstatetype.h\n");
689
690
691 int numVars = this->internalVarsToExport.giveSize();
692 // Output the internalVarsToExport-list
693 fprintf( FID, "\tIntegrationPointFields.InternalVarsToExport = [" );
694 for ( int i = 1; i <= numVars; i++ ) {
695 fprintf( FID, "%i ", this->internalVarsToExport.at(i) );
696 }
697 fprintf( FID, "];\n" );
698
699
700
701
702 if ( this->IPFieldsElSet > 0 ) {
703 Set *set = domain->giveSet( this->IPFieldsElSet );
704 elList = set->giveElementList();
705 }
706
707
708 FloatArray valueArray;
709
710 int nelem = this->elList.giveSize();
711
712 fprintf( FID, "\tIntegrationPointFields.Elements = cell(%i,1); \n", nelem );
713
714 for ( int ielem = 1; ielem <= nelem; ielem++ ) {
715 Element *el = domain->giveElement( this->elList.at(ielem) );
716 fprintf( FID, "\tIntegrationPointFields.Elements{%i}.elementNumber = %i; \n", ielem, el->giveNumber());
717
718 int numIntRules = el->giveNumberOfIntegrationRules();
719 fprintf( FID, "\tIntegrationPointFields.Elements{%i}.integrationRule = cell(%i,1); \n", ielem, numIntRules);
720 for ( int i = 1; i <= numIntRules; i++ ) {
721 IntegrationRule *iRule = el->giveIntegrationRule(i-1);
722
723 fprintf( FID, "\tIntegrationPointFields.Elements{%i}.integrationRule{%i}.ip = cell(%i,1); \n ",
724 ielem, i, iRule->giveNumberOfIntegrationPoints() );
725
726 // Loop over integration points
727 for ( GaussPoint *ip: *iRule ) {
728
729 double weight = ip->giveWeight();
730
731 fprintf( FID, "\tIntegrationPointFields.Elements{%i}.integrationRule{%i}.ip{%i}.ipWeight = %e; \n ",
732 ielem, i, ip->giveNumber(), weight);
733
734
735 // export Gauss point coordinates
736 fprintf( FID, "\tIntegrationPointFields.Elements{%i}.integrationRule{%i}.ip{%i}.coords = [",
737 ielem, i, ip->giveNumber());
738
739 FloatArray coords;
740 el->computeGlobalCoordinates( coords, ip->giveNaturalCoordinates() );
741 for ( int ic = 1; ic <= coords.giveSize(); ic++ ) {
742 fprintf( FID, "%e ", coords.at(ic) );
743 }
744 fprintf( FID, "]; \n" );
745
746 //export volume around Gauss point
747 fprintf( FID, "\tIntegrationPointFields.Elements{%i}.integrationRule{%i}.ip{%i}.volume = %e; \n ",
748 ielem, i, ip->giveNumber(), el->computeVolumeAround(ip));
749
750 // export internal variables
751 fprintf( FID, "\tIntegrationPointFields.Elements{%i}.integrationRule{%i}.ip{%i}.valArray = cell(%i,1); \n",
752 ielem, i, ip->giveNumber(), numVars);
753
754 for ( int iv = 1; iv <= numVars; iv++ ) {
755 fprintf( FID, "\tIntegrationPointFields.Elements{%i}.integrationRule{%i}.ip{%i}.valArray{%i} = [",
756 ielem, i, ip->giveNumber(), iv);
758 el->giveIPValue(valueArray, ip, vartype, tStep);
759 int nv = valueArray.giveSize();
760 for ( int ic = 1; ic <= nv; ic++ ) {
761 fprintf( FID, "%.6e ", valueArray.at(ic) );
762 }
763 fprintf( FID, "]; \n" );
764 }
765 }
766
767 }
768 }
769
770}
771
772
773void
774MatlabExportModule :: initialize()
775{
776 ExportModule :: initialize();
777}
778
779
780void
781MatlabExportModule :: terminate()
782{ }
783
784
785FILE *
786MatlabExportModule :: giveOutputStream(TimeStep *tStep)
787{
788 FILE *answer;
789
790 char fext[100];
791 sprintf( fext, "_m%d_%d", this->number, tStep->giveNumber() );
792
793 if ( this->testSubStepOutput() ) {
794 // include tStep version in output file name
795 if ( this->emodel->isParallel() && this->emodel->giveNumberOfProcesses() > 1 ) {
796 sprintf( fext, "_%03d_m%d_%d_%d", emodel->giveRank(), this->number, tStep->giveNumber(), tStep->giveSubStepNumber() );
797 } else {
798 sprintf( fext, "_m%d_%d_%d", this->number, tStep->giveNumber(), tStep->giveSubStepNumber() );
799 }
800 } else {
801 if ( this->emodel->isParallel() && this->emodel->giveNumberOfProcesses() > 1 ) {
802 sprintf( fext, "_%03d_m%d_%d", emodel->giveRank(), this->number, tStep->giveNumber() );
803 } else {
804 sprintf( fext, "_m%d_%d", this->number, tStep->giveNumber() );
805 }
806 }
807
808 std :: string fileName;
809
810 fileName = this->emodel->giveOutputBaseFileName();
811
812 size_t foundDot;
813 foundDot = fileName.rfind(".");
814
815 // CARL
816 while (foundDot != std :: string :: npos) {
817 fileName.replace(foundDot, 1, "_");
818 foundDot = fileName.rfind(".");
819// printf("%s\n", fileName.c_str());
820 }
821
822 fileName += fext;
823
824 std :: string temp;
825 temp = fileName;
826 size_t backslash = temp.rfind("/");
827
828 if (backslash != std :: string :: npos ) {
829 functionname = temp.substr(backslash+1, std :: string :: npos);
830 } else {
831 functionname = temp;
832 }
833
834 fileName += ".m";
835
836 if ( ( answer = fopen(fileName.c_str(), "w") ) == NULL ) {
837 OOFEM_ERROR("failed to open file %s", fileName.c_str() );
838 }
839
840 return answer;
841}
842
843void
844MatlabExportModule :: doOutputHomogenizeDofIDs(TimeStep *tStep, FILE *FID)
845{
846 std :: vector <FloatArray> HomQuantities;
847 double vol = 0.0;
848
849 // Initialize vector of arrays constaining homogenized quantities
850 HomQuantities.resize(internalVarsToExport.giveSize());
851
852 int nelem = this->elList.giveSize();
853 for (int i = 1; i<=nelem; i++) {
854 Element *e = this->emodel->giveDomain(1)->giveElement(elList.at(i));
855 FEInterpolation *Interpolation = e->giveInterpolation();
856
857 vol += e->computeVolumeAreaOrLength();
858
859 for ( auto &gp: *e->giveDefaultIntegrationRulePtr() ) {
860
861 for (int j=0; j<internalVarsToExport.giveSize(); j++) {
862 FloatArray elementValues;
863 e->giveIPValue(elementValues, gp, (InternalStateType) internalVarsToExport[j], tStep);
864 double detJ=fabs(Interpolation->giveTransformationJacobian( gp->giveNaturalCoordinates(), FEIElementGeometryWrapper(e)));
865
866 elementValues.times(gp->giveWeight()*detJ);
867 if (HomQuantities[j].giveSize() == 0) {
868 HomQuantities[j].resize(elementValues.giveSize());
869 };
870 HomQuantities[j].add(elementValues);
871 }
872 }
873 }
874
875 if (noscaling) vol = 1.0;
876
877 for ( std :: size_t i = 0; i < HomQuantities.size(); i ++) {
878 FloatArray &thisIS = HomQuantities[i];
879 thisIS.times(1.0/vol);
880 fprintf(FID, "\tspecials.%s = [", __InternalStateTypeToString ( (InternalStateType) internalVarsToExport[i] ) );
881
882 for (int j = 0; j<thisIS.giveSize(); j++) {
883 fprintf(FID, "%e", thisIS.at(j+1));
884 if (j!=(thisIS.giveSize()-1) ) {
885 fprintf(FID, ", ");
886 }
887 }
888 fprintf(FID, "];\n");
889 }
890
891}
892
893} // end namespace oofem
#define REGISTER_ExportModule(class)
double giveCoordinate(int i) const
Definition dofmanager.h:383
Set * giveSet(int n)
Definition domain.C:366
std ::vector< std ::unique_ptr< DofManager > > & giveDofManagers()
Definition domain.h:427
int giveNumberOfDofManagers() const
Returns number of dof managers in domain.
Definition domain.h:461
std ::vector< std ::unique_ptr< GeneralBoundaryCondition > > & giveBcs()
Definition domain.h:349
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
EngngModel * giveEngngModel()
Definition domain.C:419
std ::vector< std ::unique_ptr< Element > > & giveElements()
Definition domain.h:294
virtual int computeGlobalCoordinates(FloatArray &answer, const FloatArray &lcoords)
Definition element.C:1225
virtual FEInterpolation * giveInterpolation() const
Definition element.h:648
virtual double computeVolumeAreaOrLength()
Computes the volume, area or length of the element depending on its spatial dimension.
Definition element.C:1081
int giveNumberOfIntegrationRules()
Definition element.h:894
virtual IntegrationRule * giveIntegrationRule(int i)
Definition element.h:899
virtual int giveNumberOfDofManagers() const
Definition element.h:695
virtual IntegrationRule * giveDefaultIntegrationRulePtr()
Definition element.h:886
virtual int giveIPValue(FloatArray &answer, GaussPoint *gp, InternalStateType type, TimeStep *tStep)
Definition element.C:1298
virtual double computeVolumeAround(GaussPoint *gp)
Definition element.h:530
virtual double giveLoadLevel()
Returns the current load level.
Definition engngm.h:553
int number
Component number.
EngngModel * emodel
Problem pointer.
bool testTimeStepOutput(TimeStep *tStep)
virtual double giveTransformationJacobian(const FloatArray &lcoords, const FEICellGeometry &cellgeo) const
Definition feinterpol.C:81
int giveNumber() const
Definition femcmpnn.h:104
double & at(Index i)
Definition floatarray.h:202
Index giveSize() const
Returns the size of receiver.
Definition floatarray.h:261
void times(double s)
Definition floatarray.C:834
virtual bool hasField(InputFieldType id)=0
Returns true if record contains field identified by idString keyword.
void followedBy(const IntArray &b, int allocChunk=0)
Definition intarray.C:94
bool contains(int value) const
Definition intarray.h:292
int findFirstIndexOf(int value) const
Definition intarray.C:280
int giveNumberOfIntegrationPoints() const
FILE * giveOutputStream(TimeStep *)
std ::vector< double > smin
void computeArea(TimeStep *tStep)
void doOutputMesh(TimeStep *tStep, FILE *FID)
void doOutputHomogenizeDofIDs(TimeStep *tStep, FILE *FID)
std ::vector< std ::string > partName
void doOutputData(TimeStep *tStep, FILE *FID)
IntArray internalVarsToExport
list of InternalStateType values, identifying the selected vars for export
void doOutputSpecials(TimeStep *tStep, FILE *FID)
void doOutputReactionForces(TimeStep *tStep, FILE *FID)
std ::vector< double > smax
std ::vector< double > partVolume
void doOutputIntegrationPointFields(TimeStep *tStep, FILE *FID)
void computeStress(FloatArray &sigma, TimeStep *tStep) override
void computeReinfStress(FloatArray &rStress, TimeStep *tStep) override
void computeTransferStress(FloatArray &bStress, TimeStep *tStep) override
void computeStress(FloatArray &sigma, TimeStep *tStep) override
void computeReinfStress(FloatArray &rStress, TimeStep *tStep) override
void computeTransferStress(FloatArray &bStress, TimeStep *tStep) override
void computeTransferStress(FloatArray &bStress, TimeStep *tStep) override
void computeStress(FloatArray &stress, TimeStep *tStep) override
void computeReinfStress(FloatArray &rStress, TimeStep *tStep) override
DofManager * giveInternalDofManager(int i) override
Gives an internal dof manager from receiver.
const IntArray & giveElementList()
Definition set.C:158
const IntArray & giveNodeList()
Definition set.C:168
DofManager * giveInternalDofManager(int i) override
Gives an internal dof manager from receiver.
void buildReactionTable(IntArray &restrDofMans, IntArray &restrDofs, IntArray &eqn, TimeStep *tStep, int di)
void computeReaction(FloatArray &answer, TimeStep *tStep, int di)
double giveTargetTime()
Returns target time.
Definition timestep.h:164
int giveNumber()
Returns receiver's number.
Definition timestep.h:144
int giveSubStepNumber()
Returns receiver's substep number.
Definition timestep.h:155
void computeField(FloatArray &lambda, TimeStep *tStep)
DofManager * giveInternalDofManager(int i) override
Gives an internal dof manager from receiver.
int giveNumberOfInternalDofManagers() override
Gives the number of internal dof managers.
#define OOFEM_ERROR(...)
Definition error.h:79
#define IR_GIVE_OPTIONAL_FIELD(__ir, __value, __id)
Definition inputrecord.h:75
#define _IFT_MatlabExportModule_mesh
#define _IFT_MatlabExportModule_area
#define _IFT_MatlabExportModule_ReactionForces
#define _IFT_MatlabExportModule_IntegrationPoints
#define _IFT_MatlabExportModule_DataNodeSet
#define _IFT_MatlabExportModule_homogenizeInternalVars
#define _IFT_MatlabExportModule_ReactionForcesNodeSet
#define _IFT_MatlabExportModule_data
#define _IFT_MatlabExportModule_ElementList
#define _IFT_MatlabExportModule_internalVarsToExport
#define _IFT_MatlabExportModule_noScaledHomogenization
#define _IFT_MatlabExportModule_IPFieldsElSet
#define _IFT_MatlabExportModule_DofManList
#define _IFT_MatlabExportModule_specials
const char * __InternalStateTypeToString(InternalStateType _value)
Definition cltypes.C:309
FloatArrayF< N > min(const FloatArrayF< N > &a, const FloatArrayF< N > &b)
FloatArrayF< N > max(const FloatArrayF< N > &a, const FloatArrayF< N > &b)

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