OOFEM  2.4
OOFEM.org - Object Oriented Finite Element Solver
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 - 2013 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"
52 #include "unknownnumberingscheme.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
63 #include "../sm/Elements/nlstructuralelement.h"
64 #include "../sm/EngineeringModels/structengngmodel.h"
65 #endif
66 
67 
68 namespace oofem {
69 
71 
72 MatlabExportModule :: MatlabExportModule(int n, EngngModel *e) : ExportModule(n, e), internalVarsToExport(), primaryVarsToExport()
73 {
74  exportMesh = false;
75  exportData = false;
76  exportArea = false;
77  exportSpecials = false;
78  exportReactionForces = false;
79  reactionForcesDofManList.clear();
80  dataDofManList.clear();
81  exportIntegrationPointFields = false;
82  elList.clear();
83  reactionForcesNodeSet = 0;
84  dataNodeSet = 0;
85  IPFieldsElSet = 0;
86  noscaling = false;
87 }
88 
89 
91 { }
92 
93 
96 {
97  IRResultType result; // Required by IR_GIVE_FIELD macro
98 
100 
102 
104  if ( exportData ) {
106  }
107 
111 
112 
115  if ( exportReactionForces ) {
117  this->reactionForcesNodeSet = 0;
119  }
120 
122  elList.resize(0);
126  IPFieldsElSet = 0;
128  }
129 
131 
133 }
134 
135 
136 
137 void
139 {
140  Domain *domain = emodel->giveDomain(1);
141 
142  smax.clear();
143  smin.clear();
144 
145  for (int i = 1; i <= domain->giveNumberOfSpatialDimensions(); i++) {
146  smax.push_back(domain->giveDofManager(1)->giveCoordinate(i));
147  smin.push_back(domain->giveDofManager(1)->giveCoordinate(i));
148  }
149 
150  for ( int i = 0; i < domain->giveNumberOfDofManagers(); i++ ) {
151  for (int j = 0; j < domain->giveNumberOfSpatialDimensions(); j++) {
152  smax.at(j)=max(smax.at(j), domain->giveDofManager(i+1)->giveCoordinate(j+1));
153  smin.at(j)=min(smin.at(j), domain->giveDofManager(i+1)->giveCoordinate(j+1));
154  }
155  }
156 
157  Area = 0;
158  Volume = 0;
159 
160  if ( domain->giveNumberOfSpatialDimensions() == 2 ) {
161  for ( auto &elem : domain->giveElements() ) {
162  Area += elem->computeArea();
163  }
164  } else {
165 
166  for (size_t i = 0; i < partVolume.size(); i++ ) {
167  partVolume.at(i) = 0.0;
168  }
169 
170  for ( auto &elem : domain->giveElements() ) {
171  //
172  double v;
173 #ifdef __SM_MODULE
174  if ( NLStructuralElement *e = dynamic_cast< NLStructuralElement *>( elem.get() ) ) {
175  v = e->computeCurrentVolume(tStep);
176  } else {
177 #endif
178  v = elem->computeVolume();
179 #ifdef __SM_MODULE
180  }
181 #endif
182 
183  std :: string eName ( elem->giveClassName() );
184  int j = -1;
185 
186  //printf("%s\n", eName.c_str());
187 
188  for ( size_t k = 0; k < partName.size(); k++ ) {
189  //printf("partName.at(%u) = %s\n", k, partName.at(k).c_str() );
190  if ( eName.compare(partName.at(k)) == 0 ) {
191  j = k;
192  break;
193  }
194  }
195 
196  if ( j == -1 ) {
197  partName.push_back( elem->giveClassName() );
198  partVolume.push_back( v );
199  } else {
200  partVolume.at(j) += v;
201  }
202 
203  Volume += v;
204 
205  }
206  }
207 
208 }
209 
210 
211 void
212 MatlabExportModule :: doOutput(TimeStep *tStep, bool forcedOutput)
213 {
214  if ( !( testTimeStepOutput(tStep) || forcedOutput ) ) {
215  return;
216  }
217 
218 
219  int nelem = this->elList.giveSize();
220  if ( nelem == 0 ) { // no list given, export all elements
222  }
223 
224  FILE *FID;
225  FID = giveOutputStream(tStep);
226  Domain *domain = emodel->giveDomain(1);
228 
229  // Output header
230  fprintf( FID, "%%%% OOFEM generated export file \n");
231  fprintf( FID, "%% Output for time %f\n", tStep->giveTargetTime() );
232 
233 
234  fprintf( FID, "function [mesh area data specials ReactionForces IntegrationPointFields]=%s\n\n", functionname.c_str() );
235 
236  if ( exportMesh ) {
237  doOutputMesh(tStep, FID);
238  } else {
239  fprintf(FID, "\tmesh=[];\n");
240  }
241 
242  if ( exportData ) {
243  doOutputData(tStep, FID);
244  } else {
245  fprintf(FID, "\tdata=[];\n");
246  }
247 
248  if ( exportArea ) {
249  computeArea(tStep);
250  fprintf(FID, "\tarea.xmax=%f;\n", smax.at(0));
251  fprintf(FID, "\tarea.xmin=%f;\n", smin.at(0));
252  fprintf(FID, "\tarea.ymax=%f;\n", smax.at(1));
253  fprintf(FID, "\tarea.ymin=%f;\n", smin.at(1));
254  if ( ndim == 2 ) {
255  fprintf(FID, "\tarea.area=%f;\n", Area);
256  fprintf(FID, "\tvolume=[];\n");
257  } else {
258  fprintf(FID, "\tarea.zmax=%f;\n", smax.at(2));
259  fprintf(FID, "\tarea.zmin=%f;\n", smin.at(2));
260  fprintf(FID, "\tarea.area=[];\n");
261  fprintf(FID, "\tarea.volume=%f;\n", Volume);
262  for (size_t i=0; i<this->partName.size(); i++) {
263  fprintf(FID, "\tarea.volume_%s=%f;\n", partName.at(i).c_str(), partVolume.at(i));
264  }
265  }
266  } else {
267  fprintf(FID, "\tarea.area=[];\n");
268  fprintf(FID, "\tarea.volume=[];\n");
269  }
270 
271  if ( exportSpecials ) {
272  if ( !exportArea ) {
273  computeArea(tStep);
274  }
275 
276  doOutputSpecials(tStep, FID);
277  } else {
278  fprintf(FID, "\tspecials=[];\n");
279  }
280 
281  // Reaction forces
282  if ( exportReactionForces ) {
283  doOutputReactionForces(tStep, FID);
284  } else {
285  fprintf(FID, "\tReactionForces=[];\n");
286  }
287 
288  // Internal variables in integration points
290  doOutputIntegrationPointFields(tStep, FID);
291  } else {
292  fprintf(FID, "\tIntegrationPointFields=[];\n");
293  }
294 
295  // Homogenized quantities
296  if ( exportHomogenizeIST ) {
297  doOutputHomogenizeDofIDs(tStep, FID);
298  }
299 
300  fprintf(FID, "\nend\n");
301  fclose(FID);
302 }
303 
304 
305 void
307 {
308  Domain *domain = emodel->giveDomain(1);
309 
310  fprintf(FID, "\tmesh.p=[");
311  for ( auto &dman : domain->giveDofManagers() ) {
312  for ( int j = 1; j <= domain->giveNumberOfSpatialDimensions(); j++) {
313  double c = dman->giveCoordinate(j);
314  fprintf(FID, "%f, ", c);
315  }
316  fprintf(FID, "; ");
317  }
318 
319  fprintf(FID, "]';\n");
320 
321  int numberOfDofMans=domain->giveElement(1)->giveNumberOfDofManagers();
322 
323  fprintf(FID, "\tmesh.t=[");
324  for ( auto &elem : domain->giveElements() ) {
325  if ( elem->giveNumberOfDofManagers() == numberOfDofMans ) {
326  for ( int j = 1; j <= elem->giveNumberOfDofManagers(); j++ ) {
327  fprintf( FID, "%d,", elem->giveDofManagerNumber(j) );
328  }
329  }
330  fprintf(FID, ";");
331  }
332 
333  fprintf(FID, "]';\n");
334 }
335 
336 
337 void
339 {
340  Domain *domain = emodel->giveDomain(1);
341  std :: vector< int >DofIDList;
342  std :: vector< int > :: iterator it;
343  std :: vector< std :: vector< double > >valuesList;
344 
345  if ( this->dataNodeSet > 0 ) {
346  // Export data based on node set
347  Set *set = domain->giveSet( this->dataNodeSet );
348  dataDofManList = set->giveNodeList();
349  for (auto iDM : dataDofManList) {
350  DofManager *dman = domain->giveDofManager(iDM);
351  for ( Dof *thisDof: *dman ) {
352  it = std :: find( DofIDList.begin(), DofIDList.end(), thisDof->giveDofID() );
353 
354  double value = thisDof->giveUnknown(VM_Total, tStep);
355  if ( it == DofIDList.end() ) {
356  DofIDList.push_back( thisDof->giveDofID() );
357  valuesList.push_back({value});
358  } else {
359  std::size_t pos = it - DofIDList.begin();
360  valuesList[pos].push_back(value);
361  }
362  }
363  }
364  } else {
365  // Export data from all dofmanagers
366  for ( auto &dman : domain->giveDofManagers() ) {
367  for ( Dof *thisDof: *dman ) {
368  it = std :: find( DofIDList.begin(), DofIDList.end(), thisDof->giveDofID() );
369 
370  double value = thisDof->giveUnknown(VM_Total, tStep);
371  if ( it == DofIDList.end() ) {
372  DofIDList.push_back( thisDof->giveDofID() );
373  valuesList.push_back({value});
374  } else {
375  std::size_t pos = it - DofIDList.begin();
376  valuesList[pos].push_back(value);
377  }
378  }
379  }
380  }
381 
382 
383 
384  fprintf(FID, "\tdata.DofIDs=[");
385  for ( auto &dofid : DofIDList ) {
386  fprintf( FID, "%d, ", dofid );
387  }
388 
389  fprintf(FID, "];\n");
390 
391  for ( size_t i = 0; i < valuesList.size(); i++ ) {
392  fprintf(FID, "\tdata.a{%lu}=[", static_cast< long unsigned int >(i) + 1);
393  for ( double val: valuesList[i] ) {
394  fprintf( FID, "%f,", val );
395  }
396 
397  fprintf(FID, "];\n");
398  }
399 
400 }
401 
402 
403 void
405 {
406 // FloatArray v_hat, GradPTemp, v_hatTemp;
407 
408  Domain *domain = emodel->giveDomain(1);
409 /*
410  v_hat.clear();
411 
413 #if 0
414  for ( auto &elem : domain->giveElements() ) {
415 #ifdef __FM_MODULE
416 
417  if ( Tr21Stokes *Tr = dynamic_cast< Tr21Stokes * >( elem.get() ) ) {
418  Tr->giveIntegratedVelocity(v_hatTemp, tStep);
419  v_hat.add(v_hatTemp);
420  } else if ( Tet21Stokes *Tet = dynamic_cast< Tet21Stokes * >( elem.get() ) ) {
421  Tet->giveIntegratedVelocity(v_hatTemp, tStep);
422  v_hat.add(v_hatTemp);
423  }
424 
425 #endif
426  }
427 #endif
428 
429  // Compute intrinsic area/volume
430  double intrinsicSize = 1.0;
431 
432  std :: vector <double> V;
433 
434  for ( int i = 0; i < (int)smax.size(); i++ ) {
435  intrinsicSize *= ( smax.at(i) - smin.at(i) );
436  }
437 
438  for ( double vh: v_hat ) {
439  V.push_back(vh);
440  }
441 
442  fprintf(FID, "\tspecials.velocitymean=[");
443  if (V.size()>0) {
444  for (int i=0; i<ndim; i++) {
445  fprintf(FID, "%e", V.at(i));
446  if (i!=(ndim-1)) fprintf (FID, ", ");
447  }
448  fprintf(FID, "];\n");
449  } else {
450  fprintf(FID, "]; %% No velocities\n");
451  }
452 
453  */
454 
455  // Output weak periodic boundary conditions
456  unsigned int wpbccount = 1, sbsfcount = 1, mcount = 1;
457 
458  for ( auto &gbc : domain->giveBcs() ) {
459  WeakPeriodicBoundaryCondition *wpbc = dynamic_cast< WeakPeriodicBoundaryCondition * >( gbc.get() );
460  if ( wpbc ) {
461  for ( int j = 1; j <= wpbc->giveNumberOfInternalDofManagers(); j++ ) {
462  fprintf(FID, "\tspecials.weakperiodic{%u}.descType=%u;\n", wpbccount, wpbc->giveBasisType() );
463  fprintf(FID, "\tspecials.weakperiodic{%u}.coefficients=[", wpbccount);
464  for ( Dof *dof: *wpbc->giveInternalDofManager(j) ) {
465  double X = dof->giveUnknown(VM_Total, tStep);
466  fprintf(FID, "%e\t", X);
467  }
468 
469  fprintf(FID, "];\n");
470  wpbccount++;
471  }
472  }
473  SolutionbasedShapeFunction *sbsf = dynamic_cast< SolutionbasedShapeFunction *>( gbc.get());
474  if (sbsf) {
475  fprintf(FID, "\tspecials.solutionbasedsf{%u}.values=[", sbsfcount);
476  for ( Dof *dof: *sbsf->giveInternalDofManager(1) ) { // Only one internal dof manager
477  double X = dof->giveUnknown(VM_Total, tStep);
478  fprintf(FID, "%e\t", X);
479  }
480  fprintf(FID, "];\n");
481  sbsfcount++;
482  }
483  PrescribedMean *m = dynamic_cast<PrescribedMean *> ( gbc.get() );
484  if (m) {
485  fprintf(FID, "\tspecials.prescribedmean{%u}.value=[", mcount);
486  for ( Dof *dof: *m->giveInternalDofManager(1)) {
487  double X = dof->giveUnknown(VM_Total, tStep);
488  fprintf(FID, "%e\t", X);
489  }
490  fprintf(FID, "];\n");
491  mcount++;
492  }
493  }
494 }
495 
496 
497 void
499 {
500 
501  int domainIndex = 1;
502  Domain *domain = emodel->giveDomain( domainIndex );
503 
504  FloatArray reactions;
505  IntArray dofManMap, dofidMap, eqnMap;
506 #ifdef __SM_MODULE
507  StructuralEngngModel *strEngMod = dynamic_cast< StructuralEngngModel * >(emodel);
508  if ( strEngMod ) {
509  strEngMod->buildReactionTable(dofManMap, dofidMap, eqnMap, tStep, domainIndex);
510  strEngMod->computeReaction(reactions, tStep, 1);
511  } else
512 #endif
513  {
514  OOFEM_ERROR("Cannot export reaction forces - only implemented for structural problems.");
515  }
516 
517  // Set the nodes and elements to export based on sets
518  if ( this->reactionForcesNodeSet > 0 ) {
519  Set *set = domain->giveSet( this->reactionForcesNodeSet );
520  reactionForcesDofManList = set->giveNodeList();
521  }
522 
523 
524  int numDofManToExport = this->reactionForcesDofManList.giveSize();
525  if ( numDofManToExport == 0 ) { // No dofMan's given - export every dMan with reaction forces
526 
527  for (int i = 1; i <= domain->giveNumberOfDofManagers(); i++) {
528  if ( dofManMap.contains(i) ) {
530  }
531  }
532  numDofManToExport = this->reactionForcesDofManList.giveSize();
533  }
534 
535 
536  // Output header
537  fprintf( FID, "\n %%%% Export of reaction forces \n\n" );
538 
539  // Output the dofMan numbers that are exported
540  fprintf( FID, "\tReactionForces.DofManNumbers = [" );
541  for ( int i = 1; i <= numDofManToExport; i++ ) {
542  fprintf( FID, "%i ", this->reactionForcesDofManList.at(i) );
543  }
544  fprintf( FID, "];\n" );
545 
546 
547  // Define the reaction forces as a cell object
548  fprintf( FID, "\tReactionForces.ReactionForces = cell(%i,1); \n", numDofManToExport );
549  fprintf( FID, "\tReactionForces.DofIDs = cell(%i,1); \n", numDofManToExport );
550 
551 
552  // Output the reaction forces for each dofMan. If a certain dof is not prescribed zero is exported.
553  IntArray dofIDs;
554  for ( int i = 1; i <= numDofManToExport; i++ ) {
555  int dManNum = this->reactionForcesDofManList.at(i);
556 
557  fprintf(FID, "\tReactionForces.ReactionForces{%i} = [", i);
558  if ( dofManMap.contains( dManNum ) ) {
559 
560  DofManager *dofMan = domain->giveDofManager( dManNum );
561  dofIDs.clear();
562 
563  for ( Dof *dof: *dofMan ) {
564  int num = dof->giveEquationNumber( EModelDefaultPrescribedEquationNumbering() );
565  int pos = eqnMap.findFirstIndexOf( num );
566  dofIDs.followedBy(dof->giveDofID());
567  if ( pos > 0 ) {
568  fprintf(FID, "%e ", reactions.at(pos));
569  } else {
570  fprintf( FID, "%e ", 0.0 ); // if not prescibed output zero
571  }
572  }
573  }
574  fprintf(FID, "];\n");
575 
576  // Output dof ID's
577 
578  fprintf( FID, "\tReactionForces.DofIDs{%i} = [", i);
579  if ( dofManMap.contains( dManNum ) ) {
580  for ( int id: dofIDs ) {
581  fprintf( FID, "%i ", id );
582  }
583  }
584  fprintf(FID, "];\n");
585  }
586 }
587 
588 
589 void
591 {
592 
593  int domainIndex = 1;
594  Domain *domain = emodel->giveDomain( domainIndex );
595 
596  // Output header
597  fprintf( FID, "\n %%%% Export of internal variables in integration points \n\n" );
598  fprintf( FID, "\n %% for interpretation of internal var. numbers see internalstatetype.h\n");
599 
600 
601  int numVars = this->internalVarsToExport.giveSize();
602  // Output the internalVarsToExport-list
603  fprintf( FID, "\tIntegrationPointFields.InternalVarsToExport = [" );
604  for ( int i = 1; i <= numVars; i++ ) {
605  fprintf( FID, "%i ", this->internalVarsToExport.at(i) );
606  }
607  fprintf( FID, "];\n" );
608 
609 
610 
611 
612  if ( this->IPFieldsElSet > 0 ) {
613  Set *set = domain->giveSet( this->IPFieldsElSet );
614  elList = set->giveElementList();
615  }
616 
617 
618  FloatArray valueArray;
619 
620  int nelem = this->elList.giveSize();
621 
622  fprintf( FID, "\tIntegrationPointFields.Elements = cell(%i,1); \n", nelem );
623 
624  for ( int ielem = 1; ielem <= nelem; ielem++ ) {
625  Element *el = domain->giveElement( this->elList.at(ielem) );
626  fprintf( FID, "\tIntegrationPointFields.Elements{%i}.elementNumber = %i; \n", ielem, el->giveNumber());
627 
628  int numIntRules = el->giveNumberOfIntegrationRules();
629  fprintf( FID, "\tIntegrationPointFields.Elements{%i}.integrationRule = cell(%i,1); \n", ielem, numIntRules);
630  for ( int i = 1; i <= numIntRules; i++ ) {
631  IntegrationRule *iRule = el->giveIntegrationRule(i-1);
632 
633  fprintf( FID, "\tIntegrationPointFields.Elements{%i}.integrationRule{%i}.ip = cell(%i,1); \n ",
634  ielem, i, iRule->giveNumberOfIntegrationPoints() );
635 
636  // Loop over integration points
637  for ( GaussPoint *ip: *iRule ) {
638 
639  double weight = ip->giveWeight();
640 
641  fprintf( FID, "\tIntegrationPointFields.Elements{%i}.integrationRule{%i}.ip{%i}.ipWeight = %e; \n ",
642  ielem, i, ip->giveNumber(), weight);
643 
644 
645  // export Gauss point coordinates
646  fprintf( FID, "\tIntegrationPointFields.Elements{%i}.integrationRule{%i}.ip{%i}.coords = [",
647  ielem, i, ip->giveNumber());
648 
649  FloatArray coords;
650  el->computeGlobalCoordinates( coords, ip->giveNaturalCoordinates() );
651  for ( int ic = 1; ic <= coords.giveSize(); ic++ ) {
652  fprintf( FID, "%e ", coords.at(ic) );
653  }
654  fprintf( FID, "]; \n" );
655 
656  // export internal variables
657  fprintf( FID, "\tIntegrationPointFields.Elements{%i}.integrationRule{%i}.ip{%i}.valArray = cell(%i,1); \n",
658  ielem, i, ip->giveNumber(), numVars);
659 
660  for ( int iv = 1; iv <= numVars; iv++ ) {
661  fprintf( FID, "\tIntegrationPointFields.Elements{%i}.integrationRule{%i}.ip{%i}.valArray{%i} = [",
662  ielem, i, ip->giveNumber(), iv);
664  el->giveIPValue(valueArray, ip, vartype, tStep);
665  int nv = valueArray.giveSize();
666  for ( int ic = 1; ic <= nv; ic++ ) {
667  fprintf( FID, "%.6e ", valueArray.at(ic) );
668  }
669  fprintf( FID, "]; \n" );
670  }
671  }
672 
673  }
674  }
675 
676 }
677 
678 
679 void
681 {
683 }
684 
685 
686 void
688 { }
689 
690 
691 FILE *
693 {
694  FILE *answer;
695 
696  char fext[100];
697  sprintf( fext, "_m%d_%d", this->number, tStep->giveNumber() );
698 
699  if ( this->testSubStepOutput() ) {
700  // include tStep version in output file name
701  if ( this->emodel->isParallel() && this->emodel->giveNumberOfProcesses() > 1 ) {
702  sprintf( fext, "_%03d_m%d_%d_%d", emodel->giveRank(), this->number, tStep->giveNumber(), tStep->giveSubStepNumber() );
703  } else {
704  sprintf( fext, "_m%d_%d_%d", this->number, tStep->giveNumber(), tStep->giveSubStepNumber() );
705  }
706  } else {
707  if ( this->emodel->isParallel() && this->emodel->giveNumberOfProcesses() > 1 ) {
708  sprintf( fext, "_%03d_m%d_%d", emodel->giveRank(), this->number, tStep->giveNumber() );
709  } else {
710  sprintf( fext, "_m%d_%d", this->number, tStep->giveNumber() );
711  }
712  }
713 
714  std :: string fileName;
715 
716  fileName = this->emodel->giveOutputBaseFileName();
717 
718  size_t foundDot;
719  foundDot = fileName.rfind(".");
720 
721  // CARL
722  while (foundDot != std :: string :: npos) {
723  fileName.replace(foundDot, 1, "_");
724  foundDot = fileName.rfind(".");
725 // printf("%s\n", fileName.c_str());
726  }
727 
728  fileName += fext;
729 
730  std :: string temp;
731  temp = fileName;
732  size_t backslash = temp.rfind("/");
733 
734  if (backslash != std :: string :: npos ) {
735  functionname = temp.substr(backslash+1, std :: string :: npos);
736  } else {
737  functionname = temp;
738  }
739 
740  fileName += ".m";
741 
742  if ( ( answer = fopen(fileName.c_str(), "w") ) == NULL ) {
743  OOFEM_ERROR("failed to open file %s", fileName.c_str() );
744  }
745 
746  return answer;
747 }
748 
749 void
751 {
752 
753  std :: vector <FloatArray*> HomQuantities;
754  double Vol = 0.0;
755 
756  // Initialize vector of arrays constaining homogenized quantities
757  HomQuantities.resize(internalVarsToExport.giveSize());
758 
759  for (int j=0; j<internalVarsToExport.giveSize(); j++) {
760  HomQuantities.at(j) = new FloatArray;
761  }
762 
763  int nelem = this->elList.giveSize();
764  for (int i = 1; i<=nelem; i++) {
765  Element *e = this->emodel->giveDomain(1)->giveElement(elList.at(i));
766  FEInterpolation *Interpolation = e->giveInterpolation();
767 
768  Vol = Vol + e->computeVolumeAreaOrLength();
769 
770  for ( GaussPoint *gp: *e->giveDefaultIntegrationRulePtr() ) {
771 
772  for (int j=0; j<internalVarsToExport.giveSize(); j++) {
773  FloatArray elementValues;
774  e->giveIPValue(elementValues, gp, (InternalStateType) internalVarsToExport(j), tStep);
775  double detJ=fabs(Interpolation->giveTransformationJacobian( gp->giveNaturalCoordinates(), FEIElementGeometryWrapper(e)));
776 
777  elementValues.times(gp->giveWeight()*detJ);
778  if (HomQuantities.at(j)->giveSize() == 0) {
779  HomQuantities.at(j)->resize(elementValues.giveSize());
780  HomQuantities.at(j)->zero();
781  };
782  HomQuantities.at(j)->add(elementValues);
783  }
784  }
785  }
786 
787 
788  if (noscaling) Vol=1.0;
789 
790  for ( std :: size_t i = 0; i < HomQuantities.size(); i ++) {
791  FloatArray *thisIS;
792  thisIS = HomQuantities.at(i);
793  thisIS->times(1.0/Vol);
794  fprintf(FID, "\tspecials.%s = [", __InternalStateTypeToString ( InternalStateType (internalVarsToExport(i)) ) );
795 
796  for (int j = 0; j<thisIS->giveSize(); j++) {
797  fprintf(FID, "%e", thisIS->at(j+1));
798  if (j!=(thisIS->giveSize()-1) ) {
799  fprintf(FID, ", ");
800  }
801  }
802  fprintf(FID, "];\n");
803  delete HomQuantities.at(i);
804  }
805 
806 }
807 
808 } // end namespace oofem
bool contains(int value) const
Definition: intarray.h:283
#define _IFT_MatlabExportModule_DataNodeSet
InternalStateType
Type representing the physical meaning of element or constitutive model internal variable.
void enumerate(int maxVal)
Resizes receiver and enumerates from 1 to the maximum value given.
Definition: intarray.C:136
bool testTimeStepOutput(TimeStep *tStep)
Tests if given time step output is required.
Definition: exportmodule.C:148
virtual DofManager * giveInternalDofManager(int i)
Gives an internal dof manager from receiver.
virtual int giveIPValue(FloatArray &answer, GaussPoint *gp, InternalStateType type, TimeStep *tStep)
Returns the integration point corresponding value in full form.
Definition: element.C:1257
std::string giveOutputBaseFileName()
Returns base output file name to which extensions, like .out .vtu .osf should be added.
Definition: engngm.h:363
Class and object Domain.
Definition: domain.h:115
virtual IntegrationRule * giveDefaultIntegrationRulePtr()
Access method for default integration rule.
Definition: element.h:822
virtual IntegrationRule * giveIntegrationRule(int i)
Definition: element.h:835
virtual double giveTransformationJacobian(const FloatArray &lcoords, const FEICellGeometry &cellgeo)
Evaluates the determinant of the transformation.
Definition: feinterpol.C:43
int giveNumberOfDofManagers() const
Returns number of dof managers in domain.
Definition: domain.h:432
Abstract base class for "structural" finite elements with geometrical nonlinearities.
double & at(int i)
Coefficient access function.
Definition: floatarray.h:131
int max(int i, int j)
Returns bigger value form two given decimals.
Definition: mathfem.h:71
#define _IFT_MatlabExportModule_area
virtual bool hasField(InputFieldType id)=0
Returns true if record contains field identified by idString keyword.
std::vector< double > partVolume
virtual void initialize()
Definition: exportmodule.C:86
double giveTargetTime()
Returns target time.
Definition: timestep.h:146
bool isParallel() const
Returns true if receiver in parallel mode.
Definition: engngm.h:1056
Abstract base class for all finite elements.
Definition: element.h:145
Base class for dof managers.
Definition: dofmanager.h:113
int giveNumberOfProcesses() const
Returns the number of collaborating processes.
Definition: engngm.h:1060
std::vector< std::unique_ptr< DofManager > > & giveDofManagers()
Definition: domain.h:400
int giveNumberOfElements() const
Returns number of elements in domain.
Definition: domain.h:434
void computeArea(TimeStep *tStep)
int giveNumberOfSpatialDimensions()
Returns number of spatial dimensions.
Definition: domain.C:1067
Represents export output module - a base class for all output modules.
Definition: exportmodule.h:71
Class implementing an array of integers.
Definition: intarray.h:61
int & at(int i)
Coefficient access function.
Definition: intarray.h:103
#define _IFT_MatlabExportModule_ReactionForces
virtual int giveNumberOfDofManagers() const
Definition: element.h:656
virtual FEInterpolation * giveInterpolation() const
Definition: element.h:629
Abstract base class representing integration rule.
virtual double computeVolumeAreaOrLength()
Computes the volume, area or length of the element depending on its spatial dimension.
Definition: element.C:1059
int giveNumberOfIntegrationRules()
Definition: element.h:830
#define _IFT_MatlabExportModule_noScaledHomogenization
virtual IRResultType initializeFrom(InputRecord *ir)
Initializes receiver according to object description stored in input record.
Class representing a general abstraction for finite element interpolation class.
Definition: feinterpol.h:132
#define _IFT_MatlabExportModule_data
int giveSubStepNumber()
Returns receiver&#39;s substep number.
Definition: timestep.h:137
void buildReactionTable(IntArray &restrDofMans, IntArray &restrDofs, IntArray &eqn, TimeStep *tStep, int di)
Builds the reaction force table.
#define _IFT_MatlabExportModule_specials
void doOutputMesh(TimeStep *tStep, FILE *FID)
std::vector< std::unique_ptr< GeneralBoundaryCondition > > & giveBcs()
Definition: domain.h:322
virtual void terminate()
Terminates the receiver.
int giveNumber()
Returns receiver&#39;s number.
Definition: timestep.h:129
Element * giveElement(int n)
Service for accessing particular domain fe element.
Definition: domain.C:160
#define OOFEM_ERROR(...)
Definition: error.h:61
bool testSubStepOutput()
Initializes receiver.
Definition: exportmodule.h:138
void clear()
Clears the array (zero size).
Definition: intarray.h:177
EngngModel * emodel
Problem pointer.
Definition: exportmodule.h:77
#define _IFT_MatlabExportModule_DofManList
Set of elements, boundaries, edges and/or nodes.
Definition: set.h:66
Wrapper around element definition to provide FEICellGeometry interface.
Definition: feinterpol.h:95
Set * giveSet(int n)
Service for accessing particular domain set.
Definition: domain.C:363
#define _IFT_MatlabExportModule_homogenizeInternalVars
std::vector< double > smin
void resize(int n)
Checks size of receiver towards requested bounds.
Definition: intarray.C:124
virtual void doOutput(TimeStep *tStep, bool forcedOutput=false)
Writes the output.
void doOutputReactionForces(TimeStep *tStep, FILE *FID)
void doOutputData(TimeStep *tStep, FILE *FID)
Class representing vector of real numbers.
Definition: floatarray.h:82
virtual DofManager * giveInternalDofManager(int i)
Gives an internal dof manager from receiver.
#define _IFT_MatlabExportModule_IPFieldsElSet
void doOutputSpecials(TimeStep *tStep, FILE *FID)
#define _IFT_MatlabExportModule_mesh
IRResultType
Type defining the return values of InputRecord reading operations.
Definition: irresulttype.h:47
#define _IFT_MatlabExportModule_ElementList
virtual IRResultType initializeFrom(InputRecord *ir)
Initializes receiver according to object description stored in input record.
Definition: exportmodule.C:58
Class representing the general Input Record.
Definition: inputrecord.h:101
The representation of EngngModel default prescribed unknown numbering.
std::vector< Dof * >::iterator begin()
Definition: dofmanager.h:157
int number
Component number.
Definition: exportmodule.h:75
void followedBy(const IntArray &b, int allocChunk=0)
Appends array b at the end of receiver.
Definition: intarray.C:145
int giveNumberOfIntegrationPoints() const
Returns number of integration points of receiver.
#define _IFT_MatlabExportModule_ReactionForcesNodeSet
void doOutputIntegrationPointFields(TimeStep *tStep, FILE *FID)
std::vector< std::string > partName
int giveRank() const
Returns domain rank in a group of collaborating processes (0..groupSize-1)
Definition: engngm.h:1058
#define _IFT_MatlabExportModule_IntegrationPoints
FILE * giveOutputStream(TimeStep *)
void times(double s)
Multiplies receiver with scalar.
Definition: floatarray.C:818
void doOutputHomogenizeDofIDs(TimeStep *tStep, FILE *FID)
virtual int giveNumberOfInternalDofManagers()
Gives the number of internal dof managers.
This class implements extension of EngngModel for structural models.
int min(int i, int j)
Returns smaller value from two given decimals.
Definition: mathfem.h:59
std::vector< std::unique_ptr< Element > > & giveElements()
Definition: domain.h:279
void computeReaction(FloatArray &answer, TimeStep *tStep, int di)
Computes reaction forces.
virtual DofManager * giveInternalDofManager(int i)
Gives an internal dof manager from receiver.
(Under development) The Matlab export module enables oofem to export the results to a textfile contai...
const char * __InternalStateTypeToString(InternalStateType _value)
Definition: cltypes.C:298
Abstract base class representing the "problem" under consideration.
Definition: engngm.h:181
#define IR_GIVE_OPTIONAL_FIELD(__ir, __value, __id)
Macro facilitating the use of input record reading methods.
Definition: inputrecord.h:78
int giveSize() const
Definition: intarray.h:203
IntArray internalVarsToExport
list of InternalStateType values, identifying the selected vars for export
int giveSize() const
Returns the size of receiver.
Definition: floatarray.h:218
virtual double giveCoordinate(int i)
Definition: dofmanager.h:380
the oofem namespace is to define a context or scope in which all oofem names are defined.
Domain * giveDomain(int n)
Service for accessing particular problem domain.
Definition: engngm.C:1720
Abstract class Dof represents Degree Of Freedom in finite element mesh.
Definition: dof.h:93
int giveNumber() const
Definition: femcmpnn.h:107
DofManager * giveDofManager(int n)
Service for accessing particular domain dof manager.
Definition: domain.C:314
#define _IFT_MatlabExportModule_internalVarsToExport
Imposes weak periodicity on the doftype of choice.
std::vector< double > smax
Class representing integration point in finite element program.
Definition: gausspoint.h:93
Class representing solution step.
Definition: timestep.h:80
virtual int computeGlobalCoordinates(FloatArray &answer, const FloatArray &lcoords)
Computes the global coordinates from given element&#39;s local coordinates.
Definition: element.C:1207
REGISTER_ExportModule(ErrorCheckingExportModule)
int findFirstIndexOf(int value) const
Finds index of first occurrence of given value in array.
Definition: intarray.C:331

This page is part of the OOFEM documentation. Copyright (c) 2011 Borek Patzak
Project e-mail: info@oofem.org
Generated at Tue Jan 2 2018 20:07:29 for OOFEM by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2011