49 #include <lifev/core/LifeV.hpp> 51 #include <lifev/core/array/VectorEpetra.hpp> 52 #include <lifev/core/filter/GetPot.hpp> 53 #include <lifev/core/util/LifeChrono.hpp> 54 #include <lifev/core/fem/FESpace.hpp> 55 #include <lifev/core/mesh/MarkerDefinitions.hpp> 69 template<
typename MeshType >
77 typedef MeshType mesh_Type;
78 typedef VectorEpetra vector_Type;
79 typedef std::shared_ptr<vector_Type> vectorPtr_Type;
80 typedef FESpace< mesh_Type, MapEpetra > feSpace_Type;
81 typedef std::shared_ptr<feSpace_Type> feSpacePtr_Type;
122 ExporterData (
const FieldTypeEnum& fieldType,
123 const std::string& variableName,
124 const feSpacePtr_Type& feSpacePtr,
125 const vectorPtr_Type& vectorPtr,
127 const FieldRegimeEnum& regime,
128 const WhereEnum& where = Node);
139 Real operator() (
const UInt i)
const;
153 void setRegime (FieldRegimeEnum regime)
159 void setWhere ( WhereEnum where )
170 const std::string& variableName()
const 172 return M_variableName;
189 const FieldTypeEnum& fieldType()
const 195 const vectorPtr_Type storedArrayPtr()
const 197 return M_storedArrayPtr;
201 FieldRegimeEnum regime()
const 207 std::string typeName()
const;
210 UInt fieldDim()
const;
213 const WhereEnum& where()
const 219 std::string whereName()
const;
221 const feSpacePtr_Type& feSpacePtr()
const 231 std::string M_variableName;
234 feSpacePtr_Type M_feSpacePtr;
237 vectorPtr_Type M_storedArrayPtr;
246 FieldTypeEnum M_fieldType;
249 FieldRegimeEnum M_regime;
265 template<
typename MeshType>
272 typedef MeshType mesh_Type;
273 typedef std::shared_ptr<MeshType> meshPtr_Type;
274 typedef Epetra_Comm comm_Type;
275 typedef std::shared_ptr<comm_Type> commPtr_Type;
276 typedef ExporterData<mesh_Type> exporterData_Type;
277 typedef typename exporterData_Type::vector_Type vector_Type;
278 typedef typename exporterData_Type::vectorPtr_Type vectorPtr_Type;
279 typedef typename exporterData_Type::feSpace_Type feSpace_Type;
280 typedef typename exporterData_Type::feSpacePtr_Type feSpacePtr_Type;
281 typedef typename exporterData_Type::WhereEnum WhereEnum;
282 typedef typename exporterData_Type::FieldTypeEnum FieldTypeEnum;
283 typedef typename exporterData_Type::FieldRegimeEnum FieldRegimeEnum;
284 typedef typename std::vector<exporterData_Type > dataVector_Type;
285 typedef typename dataVector_Type::iterator dataVectorIterator_Type;
286 typedef typename std::multimap<WhereEnum, UInt > whereToDataIdMap_Type;
287 typedef typename std::multimap<FE_TYPE, UInt > feTypeToDataIdMap_Type;
305 Exporter (
const GetPot& dfile,
const std::string& prefix);
308 virtual ~Exporter() {};
325 void addVariable (
const FieldTypeEnum& type,
326 const std::string& variableName,
327 const feSpacePtr_Type& feSpacePtr,
328 const vectorPtr_Type& vectorPtr,
330 const FieldRegimeEnum& regime = exporterData_Type::UnsteadyRegime,
331 const WhereEnum& where = exporterData_Type::Node );
337 virtual void postProcess (
const Real& time) = 0;
343 virtual UInt importFromTime (
const Real& Time ) = 0;
350 virtual void import (
const Real& startTime,
const Real& dt) = 0;
353 virtual void import (
const Real& startTime) = 0;
355 virtual void readVariable (exporterData_Type& dvar);
358 virtual void exportPID ( meshPtr_Type& mesh, commPtr_Type& comm,
const bool binaryFormat =
false );
361 void exportRegionMarkerID ( std::shared_ptr<MeshType> mesh, std::shared_ptr<Epetra_Comm> comm );
364 virtual void exportFlags ( std::shared_ptr<MeshType> mesh, std::shared_ptr<Epetra_Comm> comm,
flag_Type const& flag =
EntityFlags::ALL );
376 virtual void setDataFromGetPot (
const GetPot& dataFile,
const std::string& section =
"exporter" );
382 void setPrefix (
const std::string& prefix )
391 void setPostDir (
const std::string& Directory )
393 M_postDir = Directory;
400 void setTimeIndex (
const UInt& timeIndex )
402 M_timeIndex = timeIndex;
409 void setTimeIndexStart (
const UInt& timeIndexStart )
411 M_timeIndexStart = timeIndexStart;
418 void setSave (
const UInt& save )
427 void setMultimesh (
const bool& multimesh )
429 M_multimesh = multimesh;
432 virtual void setMeshProcId (
const meshPtr_Type mesh,
const int& procId );
438 virtual void closeFile() {}
450 const UInt& timeIndexStart()
const 452 return M_timeIndexStart;
470 void computePostfix();
476 virtual void readScalar ( exporterData_Type& dvar ) = 0;
481 virtual void readVector ( exporterData_Type& dvar ) = 0;
488 std::string M_prefix;
490 std::string M_postDir;
506 std::string M_postfix;
510 whereToDataIdMap_Type M_whereToDataIdMap;
512 feTypeToDataIdMap_Type M_feTypeToDataIdMap;
514 dataVector_Type M_dataVector;
516 std::list<Real> M_timeSteps;
528 template<
typename MeshType >
529 ExporterData<MeshType>::ExporterData (
const FieldTypeEnum& type,
530 const std::string& variableName,
531 const feSpacePtr_Type& feSpacePtr,
532 const vectorPtr_Type& vectorPtr,
534 const FieldRegimeEnum& regime,
535 const WhereEnum& where ) :
536 M_variableName ( variableName ),
537 M_feSpacePtr ( feSpacePtr ),
538 M_storedArrayPtr ( vectorPtr ),
539 M_numDOF ( feSpacePtr->dim() ),
541 M_fieldType ( type ),
550 template<
typename MeshType >
551 Real ExporterData<MeshType>::operator() (
const UInt i )
const 553 return (*M_storedArrayPtr) [i];
556 template<
typename MeshType >
557 Real& ExporterData<MeshType>::operator() (
const UInt i )
559 return (*M_storedArrayPtr) [i];
562 template<
typename MeshType >
563 std::string ExporterData<MeshType>::typeName()
const 574 return std::string();
577 template<
typename MeshType >
578 UInt ExporterData<MeshType>::fieldDim()
const 580 return M_feSpacePtr->fieldDim();
583 template<
typename MeshType >
584 std::string ExporterData<MeshType>::whereName()
const 594 ERROR_MSG (
"Unknown location of data" );
595 return std::string();
605 template<
typename MeshType>
606 Exporter<MeshType>::Exporter() :
607 M_prefix (
"output"),
609 M_timeIndexStart ( 0 ),
610 M_timeIndex ( M_timeIndexStart ),
612 M_multimesh (
true ),
613 M_timeIndexWidth ( 5 ),
614 M_numImportProc ( 0 )
617 template<
typename MeshType>
618 Exporter<MeshType>::Exporter (
const GetPot& dfile,
const std::string& prefix ) :
621 setDataFromGetPot (dfile);
627 template<
typename MeshType>
628 void Exporter<MeshType>::addVariable (
const FieldTypeEnum& type,
629 const std::string& variableName,
630 const feSpacePtr_Type& feSpacePtr,
631 const vectorPtr_Type& vectorPtr,
633 const FieldRegimeEnum& regime,
634 const WhereEnum& where )
636 M_dataVector.push_back ( exporterData_Type (type, variableName, feSpacePtr, vectorPtr, start, regime, where) );
637 M_whereToDataIdMap.insert ( std::pair<WhereEnum, UInt > (where, M_dataVector.size() - 1 ) );
638 M_feTypeToDataIdMap.insert ( std::pair<FE_TYPE, UInt > (feSpacePtr->fe().refFE().type(), M_dataVector.size() - 1 ) );
641 template <
typename MeshType>
642 void Exporter<MeshType>::readVariable (exporterData_Type& dvar)
644 switch ( dvar.fieldType() )
646 case exporterData_Type::ScalarField:
649 case exporterData_Type::VectorField:
655 template <
typename MeshType>
656 void Exporter<MeshType>::exportFlags ( std::shared_ptr<MeshType> mesh, std::shared_ptr<Epetra_Comm> comm, flag_Type
const& compareFlag )
663 const ReferenceFE& refFE = feTetraP1;
664 const QuadratureRule& qR = quadRuleTetra15pt;
665 const QuadratureRule& bdQr = quadRuleTria4pt;
667 feSpacePtr_Type FlagFESpacePtr (
new feSpace_Type ( mesh, refFE, qR, bdQr, 1, comm ) );
669 std::vector< vectorPtr_Type > FlagData ( EntityFlags::number );
671 for ( flag_Type kFlag ( 1 ), flagCount ( 0 ); kFlag < EntityFlags::ALL; kFlag *= 2, flagCount++ )
673 if ( kFlag & compareFlag )
675 FlagData[ flagCount ].reset (
new vector_Type ( FlagFESpacePtr->map() ) );
677 for ( UInt iPoint ( 0 ); iPoint < FlagFESpacePtr->mesh()->numPoints(); ++iPoint )
679 typename MeshType::point_Type
const& point = FlagFESpacePtr->mesh()->pointList[ iPoint ];
680 FlagData[ flagCount ]->setCoefficient ( point.id() , Flag::testOneSet ( point.flag(), kFlag ) );
683 addVariable ( exporterData_Type::ScalarField,
684 "Flag " + EntityFlags::name ( kFlag ),
686 FlagData[ flagCount ],
688 exporterData_Type::SteadyRegime,
689 exporterData_Type::Node );
694 template <
typename MeshType>
695 void Exporter<MeshType>::exportPID ( meshPtr_Type& mesh, commPtr_Type& comm,
bool const binaryFormat )
702 switch ( MeshType::S_geoDimensions )
705 refFEPtr = &feTetraP0;
708 refFEPtr = &feTriaP0;
714 ERROR_MSG (
"Dimension not supported " );
720 feSpacePtr_Type PID_FESpacePtr (
new feSpace_Type ( mesh, *refFEPtr, dummyQR, dummyQR, 1, comm ) );
722 vectorPtr_Type PIDData (
new vector_Type ( PID_FESpacePtr->map() ) );
730 for ( UInt iElem ( 0 ); iElem < mesh->numElements(); ++iElem )
732 const ID globalElem = mesh->element (iElem).id();
734 PIDValue <<= comm->MyPID();
735 PIDData->sumIntoGlobalValues ( globalElem, PIDValue );
737 PIDData->globalAssemble();
742 for ( UInt iElem ( 0 ); iElem < mesh->numElements(); ++iElem )
744 const ID globalElem = mesh->element (iElem).id();
745 (*PIDData) [ globalElem ] = comm->MyPID();
749 addVariable ( exporterData_Type::ScalarField,
754 exporterData_Type::SteadyRegime,
755 exporterData_Type::Cell );
759 template <
typename MeshType>
760 void Exporter<MeshType>::exportRegionMarkerID ( std::shared_ptr<MeshType> mesh, std::shared_ptr<Epetra_Comm> comm )
763 const ReferenceFE* refFEPtr;
767 switch ( MeshType::S_geoDimensions )
770 refFEPtr = &feTetraP0;
773 refFEPtr = &feTriaP0;
779 ERROR_MSG (
"Dimension not supported " );
783 const QuadratureRule& dummyQR = quadRuleDummy;
785 const feSpacePtr_Type regionMarkerID_FESpacePtr (
new feSpace_Type ( mesh, *refFEPtr,
789 vectorPtr_Type regionMarkerIDData (
new vector_Type ( regionMarkerID_FESpacePtr->map() ) );
791 for ( UInt iElem ( 0 ); iElem < mesh->numElements(); ++iElem )
793 const ID globalElem = mesh->element (iElem).id();
794 (*regionMarkerIDData) [ globalElem ] = mesh->element (iElem).markerID();
797 addVariable ( exporterData_Type::ScalarField,
799 regionMarkerID_FESpacePtr,
802 exporterData_Type::SteadyRegime,
803 exporterData_Type::Cell );
807 template <
typename MeshType>
808 void Exporter<MeshType>::computePostfix()
810 std::ostringstream index;
813 if (M_timeIndex % M_save == 0)
815 index << std::setw (M_timeIndexWidth) << ( M_timeIndex / M_save );
817 M_postfix =
"." + index.str();
822 std::string stars (
"");
823 for (
UInt cc (0); cc < M_timeIndexWidth; ++cc)
836 template<
typename MeshType>
837 void Exporter<MeshType>::setDataFromGetPot (
const GetPot& dataFile,
const std::string& section )
839 M_postDir = dataFile ( ( section +
"/post_dir" ).data(),
"./" );
840 M_timeIndexStart = dataFile ( ( section +
"/start" ).data(), 0 );
841 M_timeIndex = M_timeIndexStart;
842 M_save = dataFile ( ( section +
"/save" ).data(), 1 );
843 M_multimesh = dataFile ( ( section +
"/multimesh" ).data(),
true );
844 M_timeIndexWidth = dataFile ( ( section +
"/time_id_width" ).data(), 5);
845 M_numImportProc = dataFile ( ( section +
"/numImportProc" ).data(), 1);
848 template<
typename MeshType>
849 void Exporter<MeshType>::setMeshProcId (
const meshPtr_Type mesh ,
const int& procId )
const QuadratureRule quadRuleDummy(pt_node_0pt, QUAD_RULE_DUMMY, "Dummy quadrature rule", NONE, 0, 0)
uint32_type flag_Type
bit-flag with up to 32 different flags
FESpace - Short description here please!
const flag_Type ALL(0x7F)
int32_type Int
Generic integer data.
double Real
Generic real data.
The class for a reference Lagrangian finite element.
available bit-flags for different geometric properties
QuadratureRule - The basis class for storing and accessing quadrature rules.
uint32_type UInt
generic unsigned integer (used mainly for addressing)