FEBio  1.5.0
FEBio/FEBioImport.h
00001 #pragma once
00002 
00003 #include "FileImport.h"
00004 #include "XMLReader.h"
00005 #include "FETransverselyIsotropic.h"
00006 #include "FERigid.h"
00007 #include "FEElasticMixture.h"
00008 #include "FEUncoupledElasticMixture.h"
00009 #include "FEBiphasic.h"
00010 #include "FEBiphasicSolute.h"
00011 #include "FETriphasic.h"
00012 #include "FEMultiphasic.h"
00013 #include <map>
00014 #include <string>
00015 using namespace std;
00016 
00017 class FEFEBioImport;
00018 
00019 //-----------------------------------------------------------------------------
00020 // Base class for XML sections parsers
00021 class FEBioFileSection
00022 {
00023 public:
00024         FEBioFileSection(FEFEBioImport* pim) { m_pim = pim; }
00025 
00026         virtual void Parse(XMLTag& tag) = 0;
00027 
00028         FEM* GetFEM();
00029         FEAnalysis* GetStep();
00030 
00031 protected:
00032         FEFEBioImport*  m_pim;
00033 };
00034 
00035 //-----------------------------------------------------------------------------
00036 // class that manages file section parsers
00037 class FEBioFileSectionMap : public map<string, FEBioFileSection*>
00038 {
00039 public:
00040         ~FEBioFileSectionMap();
00041 };
00042 
00043 //-----------------------------------------------------------------------------
00044 // Module Section
00045 class FEBioModuleSection : public FEBioFileSection
00046 {
00047 public:
00048         FEBioModuleSection(FEFEBioImport* pim) : FEBioFileSection(pim) {}
00049         void Parse(XMLTag& tag);
00050 };
00051 
00052 //-----------------------------------------------------------------------------
00053 // Control Section
00054 class FEBioControlSection : public FEBioFileSection
00055 {
00056 public:
00057         FEBioControlSection(FEFEBioImport* pim) : FEBioFileSection(pim) {}
00058         void Parse(XMLTag& tag);
00059 
00060 protected:
00061         FESolver* BuildSolver(int nmod, FEM& fem);
00062 
00063         bool ParseCommonParams   (XMLTag& tag);
00064         bool ParseSolidParams    (XMLTag& tag);
00065         bool ParsePoroParams     (XMLTag& tag);
00066         bool ParseSoluteParams   (XMLTag& tag);
00067 };
00068 
00069 //-----------------------------------------------------------------------------
00070 // Material Section
00071 class FEBioMaterialSection : public FEBioFileSection
00072 {
00073 public:
00074         FEBioMaterialSection(FEFEBioImport* pim) : FEBioFileSection(pim){}
00075         void Parse(XMLTag& tag);
00076 
00077 protected:
00078         void ParseMaterial                                      (XMLTag& tag, FEMaterial* pm);
00079         bool ParseElasticMaterial                       (XMLTag& tag, FEElasticMaterial* pm);
00080         bool ParseTransIsoMaterial                      (XMLTag& tag, FETransverselyIsotropic* pm);
00081         bool ParseRigidMaterial                         (XMLTag& tag, FERigidMaterial* pm);
00082         bool ParseElasticMixture                        (XMLTag& tag, FEElasticMixture* pm);
00083         bool ParseUncoupledElasticMixture       (XMLTag& tag, FEUncoupledElasticMixture* pm);
00084         bool ParseBiphasicMaterial                      (XMLTag& tag, FEBiphasic* pm);
00085         bool ParseBiphasicSoluteMaterial        (XMLTag& tag, FEBiphasicSolute* pm);
00086         bool ParseSoluteMaterial                        (XMLTag& tag, FESolute* pm);
00087         bool ParseTriphasicMaterial                     (XMLTag& tag, FETriphasic* pm);
00088         bool ParseMultiphasicMaterial           (XMLTag& tag, FEMultiphasic* pm);
00089         bool ParseNestedMaterial                        (XMLTag& tag, FENestedMaterial* pm);
00090 
00091 protected:
00092         int     m_nmat;
00093 };
00094 
00095 //-----------------------------------------------------------------------------
00096 // Geometry Section
00097 class FEBioGeometrySection : public FEBioFileSection
00098 {
00099 private:
00100         enum {
00101                 ET_HEX,
00102                 ET_PENTA,
00103                 ET_TET,
00104                 ET_QUAD,
00105                 ET_TRI,
00106                 ET_TRUSS
00107         };
00108 
00109         struct FEDOMAIN 
00110         {
00111                 int             mat;    // material ID
00112                 int             elem;   // element type
00113                 int             nel;    // number of elements
00114         };
00115         
00116 public:
00117         FEBioGeometrySection(FEFEBioImport* pim) : FEBioFileSection(pim){}
00118         void Parse(XMLTag& tag);
00119 
00120 protected:
00121         void ParseNodeSection       (XMLTag& tag);
00122         void ParseElementSection    (XMLTag& tag);
00123         void ParseElementDataSection(XMLTag& tag);
00124         void ParseGroupSection      (XMLTag& tag);
00125 
00126         void ReadSolidElement(XMLTag& tag, FESolidElement& el, int ntype, int nid, int gid, int nmat);
00127         void ReadShellElement(XMLTag& tag, FEShellElement& el, int ntype, int nid, int gid, int nmat);
00128         void ReadTrussElement(XMLTag& tag, FETrussElement& el, int ntype, int nid, int gid, int nmat);
00129 
00130         int ElementType(XMLTag& tag);
00131         int DomainType(int etype, FEMaterial* pmat);
00132         FEDomain* CreateDomain(int ntype, FEMesh* pm, FEMaterial* pmat);
00133 };
00134 
00135 //-----------------------------------------------------------------------------
00136 // Boundary Section
00137 class FEBioBoundarySection : public FEBioFileSection
00138 {
00139 public:
00140         FEBioBoundarySection(FEFEBioImport* pim) : FEBioFileSection(pim){}
00141         void Parse(XMLTag& tag);
00142 
00143 protected:
00144         void ParseBCFix               (XMLTag& tag);
00145         void ParseBCPrescribe         (XMLTag& tag);
00146         void ParseBCForce             (XMLTag& tag);
00147         void ParseBCPressure          (XMLTag& tag);
00148         void ParseBCTraction          (XMLTag& tag);
00149         void ParseBCPoroNormalTraction(XMLTag& tag);
00150         void ParseBCFluidFlux         (XMLTag& tag);
00151         void ParseBCSoluteFlux        (XMLTag &tag);
00152         void ParseBCHeatFlux          (XMLTag& tag);
00153         void ParseContactSection      (XMLTag& tag);
00154         void ParseConstraints         (XMLTag& tag);
00155         void ParseSpringSection       (XMLTag& tag);
00156         bool ParseSurfaceSection      (XMLTag& tag, FESurface& s, int nfmt);
00157 };
00158 
00159 //-----------------------------------------------------------------------------
00160 // Loads Section (new in version 1.2)
00161 class FEBioLoadsSection : public FEBioBoundarySection
00162 {
00163 public:
00164         FEBioLoadsSection(FEFEBioImport* pim) : FEBioBoundarySection(pim){}
00165         void Parse(XMLTag& tag);
00166 
00167 protected:
00168         void ParseBodyForce(XMLTag& tag);
00169 };
00170 
00171 //-----------------------------------------------------------------------------
00172 // Initial Section
00173 class FEBioInitialSection : public FEBioFileSection
00174 {
00175 public:
00176         FEBioInitialSection(FEFEBioImport* pim) : FEBioFileSection(pim){}
00177         void Parse(XMLTag& tag);
00178 };
00179 
00180 //-----------------------------------------------------------------------------
00181 // Globals Section
00182 class FEBioGlobalsSection : public FEBioFileSection
00183 {
00184 public:
00185         FEBioGlobalsSection(FEFEBioImport* pim) : FEBioFileSection(pim){}
00186         void Parse            (XMLTag& tag);
00187 
00188 protected:
00189         void ParseBodyForce   (XMLTag& tag);    // only for versions < 1.2
00190         void ParseConstants   (XMLTag& tag);
00191         void ParseGSSoluteData(XMLTag& tag);
00192 };
00193 
00194 //-----------------------------------------------------------------------------
00195 // LoadData Section
00196 class FEBioLoadDataSection : public FEBioFileSection
00197 {
00198 public:
00199         FEBioLoadDataSection(FEFEBioImport* pim) : FEBioFileSection(pim) {}
00200         void Parse(XMLTag& tag);
00201 };
00202 
00203 //-----------------------------------------------------------------------------
00204 // Output Section
00205 class FEBioOutputSection : public FEBioFileSection
00206 {
00207 public:
00208         FEBioOutputSection(FEFEBioImport* pim) : FEBioFileSection(pim){}
00209         void Parse(XMLTag& tag);
00210 
00211 protected:
00212         void ParseLogfile (XMLTag& tag);
00213         void ParsePlotfile(XMLTag& tag);
00214 };
00215 
00216 //-----------------------------------------------------------------------------
00217 // Constraints Section
00218 class FEBioConstraintsSection : public FEBioFileSection
00219 {
00220 public:
00221         FEBioConstraintsSection(FEFEBioImport* pim) : FEBioFileSection(pim){}
00222         void Parse(XMLTag& tag);
00223 
00224 protected:
00225         void ParseRigidConstraint(XMLTag& tag);
00226         void ParsePointConstraint(XMLTag& tag);
00227 };
00228 
00229 //-----------------------------------------------------------------------------
00230 // Step Section
00231 class FEBioStepSection : public FEBioFileSection
00232 {
00233 public:
00234         FEBioStepSection(FEFEBioImport* pim) : FEBioFileSection(pim){}
00235         void Parse(XMLTag& tag);
00236 };
00237 
00238 //=============================================================================
00241 class FEFEBioImport : public FEFileImport
00242 {
00243 public:
00244         // Element types
00245         enum { ET_HEX8, ET_PENTA6, ET_TET4, ET_UT4, ET_TETG1, ET_QUAD4, ET_TRI3, ET_TRUSS2 };
00246 
00247         // element classes
00248         enum { EC_STRUCT, EC_RIGID, EC_PORO, EC_HEAT };
00249 
00250 public:
00251         class InvalidVersion{};
00252         class InvalidMaterial
00253         { 
00254         public: 
00255                 InvalidMaterial(int nel) : m_nel(nel){}
00256                 int m_nel; 
00257         };
00258         class InvalidDomainType{};
00259         class FailedCreatingDomain{};
00260         class InvalidElementType{};
00261         class FailedLoadingPlugin
00262         {
00263         public:
00264                 FailedLoadingPlugin(const char* sz) : m_szfile(sz) {}
00265                 const char* FileName() { return m_szfile.c_str(); }
00266         public:
00267                 string  m_szfile;
00268         };
00269         class DuplicateMaterialSection {};
00270 
00271 public:
00272         bool Load(FEM& fem, const char* szfile);
00273 
00274         FEM* GetFEM() { return m_pfem; }
00275         FEAnalysis*     GetStep() { return m_pStep; }
00276 
00277         int Version() { return m_nversion; }
00278 
00279         bool ReadParameter(XMLTag& tag, FEParameterList& pl);
00280 
00281 protected:
00282         void ParseVersion                       (XMLTag& tag);
00283 
00284 public:
00285         FEM*            m_pfem;         
00286         FEAnalysis*     m_pStep;        
00287 
00288 protected:
00289         XMLReader       m_xml;  
00290 
00291 public:
00292         int     m_ntet4;        // tetrahedral integration rule
00293         int     m_nut4;         // integration rule for stabilization of UT4
00294         int m_nsteps;   // nr of step sections read
00295         int     m_nmat;         // nr of materials
00296         int     m_maxid;        // max element ID
00297 
00298         bool    m_b3field;      // three-field element flag
00299         int             m_nhex8;        // hex integration rule
00300 
00301 protected:
00302         int     m_nversion;     // version of file
00303 };