From: Bernard Secher Date: Thu, 3 Sep 2020 05:41:15 +0000 (+0200) Subject: update CoreFlows X-Git-Tag: V9_6_0~58 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=8d75250c8a620dc1bab221405876864c1227b9bb;p=tools%2Fsolverlab.git update CoreFlows --- diff --git a/CoreFlows/CMakeLists.txt b/CoreFlows/CMakeLists.txt index d079a84..3da857a 100755 --- a/CoreFlows/CMakeLists.txt +++ b/CoreFlows/CMakeLists.txt @@ -13,6 +13,10 @@ option (COREFLOWS_WITH_PYTHON "Compile Python interface for COREFLOWS." OFF) option (COREFLOWS_WITH_GUI "Compile Graphic user Interface for COREFLOWS." OFF) option (COREFLOWS_WITH_PACKAGE "Generate RPM, Debian and tarball packages." OFF) +#Path to installed libraries +set (PETSC_DIR OFF CACHE STRING "PETSc library path" ) +set (SLEPC_DIR OFF CACHE STRING "SLEPc library path" ) + enable_testing() # # Debug mode activates testing and profiling --------------------------------------------------------------# if (CMAKE_BUILD_TYPE STREQUAL Debug) # @@ -35,36 +39,74 @@ find_package (CDMATH REQUIRED) # PETSC ----------------------------------------------------------------------------------------------------# message ( STATUS "Checking variable PETSC_DIR : " $ENV{PETSC_DIR} ) -if ( NOT DEFINED ENV{PETSC_DIR} AND IS_DIRECTORY "/usr/include/petsc/" AND EXISTS "/usr/lib64/libpetsc.so") #Case fedora/redhat system install +if ( NOT PETSC_DIR AND NOT DEFINED ENV{PETSC_DIR} AND IS_DIRECTORY "/usr/include/petsc/" AND EXISTS "/usr/lib64/libpetsc.so") #Case fedora/redhat system install message ( STATUS "PETSC includes found in /usr/include/petsc/" ) message ( STATUS "PETSC library found in /usr/lib64" ) set(PETSC_DIR /usr/) + set(PETSC_ARCH lib64) set(PETSC_INCLUDES /usr/include/petsc /usr/include/petsc/petsc/mpiuni) set(PETSC_INCLUDES_PATH /usr/include/petsc:/usr/include/petsc/petsc/mpiuni) set(PETSC_LIBRARIES /usr/lib64/libpetsc.so) - set(PETSC_VERSION "3.7") #3.7 for fedora 25/26 , 3.9 for fedora 29 - set (CPACK_RPM_PACKAGE_REQUIRES "${CPACK_RPM_PACKAGE_REQUIRES}, petsc-devel (>= 3.4)") # This is not fully working yet. + set(PETSC_VERSION "3.7") #3.7 for fedora 25/26 , 3.9 for fedora 29 , 3.10 for fedora 30, , 3.12 for fedora 32 + set(CPACK_RPM_PACKAGE_REQUIRES "${CPACK_RPM_PACKAGE_REQUIRES}, petsc-devel (>= 3.4)") # This is not fully working yet. + + #Define and search slepc variables + if ( IS_DIRECTORY "/usr/include/slepc/" AND EXISTS "/usr/lib64/libslepc.so" ) + message( STATUS "SLEPc includes found in /usr/include/slepc/" ) + message( STATUS "SLEPc library found in /usr/lib64/slepc/" ) + set(SLEPC_DIR /usr/) + set(SLEPC_INCLUDES ${SLEPC_DIR}/include) + set(SLEPC_LIBRARIES ${SLEPC_DIR}/lib/libslepc.so) + set (CPACK_RPM_PACKAGE_REQUIRES "${CPACK_RPM_PACKAGE_REQUIRES}, slepc-devel (>= 3.4)") # This is not fully working yet. + else ( IS_DIRECTORY "/usr/include/slepc/" AND EXISTS "/usr/lib64/libslepc.so" ) + message( FATAL_ERROR "SLEPc not found in the system" ) + endif( IS_DIRECTORY "/usr/include/slepc/" AND EXISTS "/usr/lib64/libslepc.so" ) #elseif ( IS_DIRECTORY "/usr/lib/petsc/") #Case ubuntu/debian system install # message ( STATUS "PETSC found in /usr/lib/petsc/" ) # set(PETSC_DIR /usr/lib/petsc/) +# set(PETSC_ARCH ) # find_package (PETSc 3.4 REQUIRED) # petsc_get_version () # set (CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}, petsc-dev (>= 3.4)") # This is not fully working yet. #elseif ( IS_DIRECTORY "/usr/local/lib/python2.7/dist-packages/petsc") #Case ubuntu/debian system pip install # message ( STATUS "PETSC found in /usr/local/lib/python2.7/dist-packages/petsc" ) -# set(PETSC_DIR /usr/local/lib/python2.7/dist-packages/petsc) -# set(PETSC_INCLUDES /usr/local/lib/python2.7/dist-packages/petsc/include /usr/include/openmpi) -# set(PETSC_INCLUDES_PATH /usr/local/lib/python2.7/dist-packages/petsc/include:/usr/include/openmpi) -# set(PETSC_LIBRARIES /usr/local/lib/python2.7/dist-packages/petsc/lib/libpetsc.so) +# set(PETSC_DIR /usr/local/lib/python2.7/dist-packages/petsc/) +# set(PETSC_ARCH lib) +# set(PETSC_INCLUDES $PETSC_DIR/include /usr/include/openmpi) +# set(PETSC_INCLUDES_PATH $PETSC_DIR/include:/usr/include/openmpi) +# set(PETSC_LIBRARIES $PETSC_DIR/lib/libpetsc.so) # set(PETSC_VERSION "3.8") #value for Ubuntu 16.04 -else () +else ( NOT PETSC_DIR AND NOT DEFINED ENV{PETSC_DIR} AND IS_DIRECTORY "/usr/include/petsc/" AND EXISTS "/usr/lib64/libpetsc.so") + if(NOT PETSC_DIR) + set(PETSC_DIR $ENV{PETSC_DIR}) + endif(NOT PETSC_DIR) + find_package (PETSc 3.4 REQUIRED) petsc_get_version () string(REPLACE ";" ":" PETSC_INCLUDES_PATH "${PETSC_INCLUDES}")# use colon instead of semicolon in environment file env_CoreFlows.sh -endif () + + #Define and search slepc variables + if ( NOT SLEPC_DIR ) + if ( DEFINED ENV{SLEPC_DIR} ) + set(SLEPC_DIR $ENV{SLEPC_DIR}) + else ( DEFINED ENV{SLEPC_DIR} ) + set(SLEPC_DIR ${PETSC_DIR}/${PETSC_ARCH}) + endif( DEFINED ENV{SLEPC_DIR} ) + endif( NOT SLEPC_DIR) + + message ( STATUS "Checking variable SLEPC_DIR" ) + if ( IS_DIRECTORY ${SLEPC_DIR}/include AND EXISTS ${SLEPC_DIR}/lib/libslepc.so) + set(SLEPC_INCLUDES ${SLEPC_DIR}/include) + set(SLEPC_LIBRARIES ${SLEPC_DIR}/lib/libslepc.so) + message( STATUS "SLEPc found at ${SLEPC_DIR}" ) + else() + message( FATAL_ERROR "SLEPc not found at ${SLEPC_DIR}" ) + endif() + +endif( NOT PETSC_DIR AND NOT DEFINED ENV{PETSC_DIR} AND IS_DIRECTORY "/usr/include/petsc/" AND EXISTS "/usr/lib64/libpetsc.so") if (${PETSC_VERSION} VERSION_GREATER 3.5) add_definitions(-DPETSC_VERSION_GREATER_3_5) @@ -89,18 +131,24 @@ endif () # #-----------------------------------------------------------------------------------------------------------# - # Base directories set (CoreFlows_SRC ${CoreFlows_SOURCE_DIR}/Models ) set (CoreFlows_EXAMPLES ${CoreFlows_SOURCE_DIR}/examples) + +set( CoreFlows_INCLUDES + ${CDMATH_INCLUDES} # + ${MED_INCLUDES} # + ${MEDCOUPLING_INCLUDES} # + ${PETSC_INCLUDES} # + ${CoreFlows_SRC}/inc # + ) # + add_subdirectory (${CoreFlows_SRC}) add_subdirectory (${CoreFlows_EXAMPLES}) if (COREFLOWS_WITH_PYTHON) # add_subdirectory (${CoreFlows_SWIG_DIR}) # endif () # - - # Documentation --------------------------------------------------------------------------------------------# # if (COREFLOWS_WITH_DOCUMENTATION) # @@ -137,18 +185,13 @@ endif () #--------------------- COMPILATION MAIN --------------------------------------------------------------------# # INCLUDE_DIRECTORIES( # - # - ${PETSC_INCLUDES} # - ${CDMATH_INCLUDES} # - ${CDMATH_INCLUDES}/med # - ${CDMATH_INCLUDES}/medcoupling # - ${CoreFlows_SRC}/inc # + ${CoreFlows_INCLUDES} # ) # # SET(CoreFlowsMain_SOURCES # ${CoreFlows_SRC}/src/Fluide.cxx # ${CoreFlows_SRC}/src/DiffusionEquation.cxx # - ${CoreFlows_SRC}/src/StationaryDiffusionEquation.cxx # + ${CoreFlows_SRC}/src/StationaryDiffusionEquation.cx # ${CoreFlows_SRC}/src/ProblemFluid.cxx # ${CoreFlows_SRC}/src/IsothermalTwoFluid.cxx # ${CoreFlows_SRC}/src/utilitaire_algebre.cxx # diff --git a/CoreFlows/Models/inc/DiffusionEquation.hxx b/CoreFlows/Models/inc/DiffusionEquation.hxx index cbdee4f..73dc61f 100755 --- a/CoreFlows/Models/inc/DiffusionEquation.hxx +++ b/CoreFlows/Models/inc/DiffusionEquation.hxx @@ -20,6 +20,23 @@ using namespace std; +//! enumeration BoundaryType +/*! Boundary condition type */ +enum BoundaryTypeDiffusion { NeumannDiffusion, DirichletDiffusion, NoneBCDiffusion}; + +/** \struct LimitField + * \brief value of some fields on the boundary */ +struct LimitFieldDiffusion{ + LimitFieldDiffusion(){bcType=NoneBCDiffusion; T=0; normalFlux=0;} + LimitFieldDiffusion(BoundaryTypeDiffusion _bcType, double _T, double _normalFlux){ + bcType=_bcType; T=_T; normalFlux=_normalFlux; + } + + BoundaryTypeDiffusion bcType; + double T; //for Dirichlet + double normalFlux; //for Neumann +}; + class DiffusionEquation: public ProblemCoreFlows { @@ -45,7 +62,7 @@ public : void validateTimeStep(); /* Boundary conditions */ - void setBoundaryFields(map boundaryFields){ + void setBoundaryFields(map boundaryFields){ _limitField = boundaryFields; }; /** \fn setDirichletBoundaryCondition @@ -56,7 +73,7 @@ public : * \param [out] void * */ void setDirichletBoundaryCondition(string groupName,double Temperature){ - _limitField[groupName]=LimitField(Dirichlet,-1,vector(_Ndim,0),vector(_Ndim,0),vector(_Ndim,0),Temperature,-1,-1,-1); + _limitField[groupName]=LimitFieldDiffusion(DirichletDiffusion,Temperature,-1); }; /** \fn setNeumannBoundaryCondition * \brief adds a new boundary condition of type Neumann @@ -64,9 +81,8 @@ public : * \param [in] string : the name of the boundary * \param [out] void * */ - void setNeumannBoundaryCondition(string groupName){ - _limitField[groupName]=LimitField(Neumann,-1, vector(0),vector(0), - vector(0),-1,-1,-1,-1); + void setNeumannBoundaryCondition(string groupName, double normalFlux=0){ + _limitField[groupName]=LimitFieldDiffusion(NeumannDiffusion,-1, normalFlux); }; void setRodDensity(double rho){ @@ -79,18 +95,26 @@ public : _fluidTemperatureField=coupledTemperatureField; _fluidTemperatureFieldSet=true; }; + + void setDiffusiontensor(Matrix DiffusionTensor){ + _DiffusionTensor=DiffusionTensor; + }; + void setFluidTemperature(double fluidTemperature){ _fluidTemperature=fluidTemperature; } + + //get output fields for postprocessing or coupling + vector getOutputFieldsNames() ;//liste tous les champs que peut fournir le code pour le postraitement + Field& getOutputField(const string& nameField );//Renvoie un champs pour le postraitement + Field& getRodTemperatureField(){ return _VV; } Field& getFluidTemperatureField(){ return _fluidTemperatureField; } - void setDiffusiontensor(Matrix DiffusionTensor){ - _DiffusionTensor=DiffusionTensor; - }; + protected : double computeDiffusionMatrix(bool & stop); double computeDiffusionMatrixFV(bool & stop); @@ -121,6 +145,8 @@ protected : int unknownNodeIndex(int globalIndex, std::vector< int > dirichletNodes); int globalNodeIndex(int unknownIndex, std::vector< int > dirichletNodes); + TimeScheme _timeScheme; + map _limitField; }; #endif /* DiffusionEquation_HXX_ */ diff --git a/CoreFlows/Models/inc/LinearElasticityModel.hxx b/CoreFlows/Models/inc/LinearElasticityModel.hxx new file mode 100755 index 0000000..4a431b7 --- /dev/null +++ b/CoreFlows/Models/inc/LinearElasticityModel.hxx @@ -0,0 +1,175 @@ +//============================================================================ +/** + * \file LinearElasticityModel.hxx + * \author Michael NDJINGA + * \version 1.0 + * \date August 2020 + * \brief Stationary linear elasticity model + * -div \sigma = f + * with the stress \sigma given by the Hooke's law + * \sigma=2\mu e(u)+\lambda Tr(e(u)) I_d + * solved with either finite elements or finite volume method + * Dirichlet (fixed boundary) or Neumann (free boundary) boundary conditions + * */ +//============================================================================ + +/*! \class LinearElasticityModel LinearElasticityModel.hxx "LinearElasticityModel.hxx" + * \brief Linear Elasticity Model solved with either finite elements or finite volume method. + * -div \sigma = f + * \sigma=2\mu e(u)+\lambda Tr(e(u)) I_d + */ +#ifndef LinearElasticityModel_HXX_ +#define LinearElasticityModel_HXX_ + +#include "ProblemCoreFlows.hxx" + +using namespace std; + +class LinearElasticityModel +{ + +public : + /** \fn LinearElasticityModel + * \brief Constructor for the linear elasticity in a solid + * \param [in] int : space dimension + * \param [in] double : numerical method + * \param [in] double : solid density + * \param [in] double : first Lamé coefficient + * \param [in] double : second Lamé coefficient + * */ + + LinearElasticityModel( int dim, bool FECalculation=true, double rho, double lambda, double mu); + + void setConstantDensity(double rho) { _rho=rho; } + void setDensityField(Field densityField) { _densityField=densityField; _densityFieldSet=true;} + void setLameCoefficient(double lambda, double mu) { _lambda = lambda; _mu = mu;} + void setYoungAndPoissonModuli(double E, double nu) { _lambda = E*nu/(1+nu)/(1-2*nu); _mu = E/2/(1+nu);} + void setGravity(Vector gravite ) { _gravite=gravite; } + + void setMesh(const Mesh &M); + void setFileName(string fileName){ + _fileName = fileName; + } + bool solveStationaryProblem(); + Field getOutputDisplacementField(); + + //Linear system and spectrum + void setLinearSolver(linearSolver kspType, preconditioner pcType); + double getConditionNumber(bool isSingular=false, double tol=1e-6) const; + + //Gestion du calcul + void initialize(); + void terminate();//vide la mémoire et enregistre le résultat final + double computeStiffnessMatrix(bool & stop); + bool solveLinearSystem();//return true if resolution successfull + void save(); + + /* Boundary conditions */ + void setBoundaryFields(map boundaryFields){ + _limitField = boundaryFields; + }; + /** \fn setDirichletBoundaryCondition + * \brief adds a new boundary condition of type Dirichlet + * \details + * \param [in] string : the name of the boundary + * \param [in] double : the value of the temperature at the boundary + * \param [out] void + * */ + void setDirichletBoundaryCondition(string groupName,double Temperature){ + _limitField[groupName]=LimitField(Dirichlet,-1, vector(_Ndim,0),vector(_Ndim,0), + vector(_Ndim,0),Temperature,-1,-1,-1); + }; + + /** \fn setNeumannBoundaryCondition + * \brief adds a new boundary condition of type Neumann + * \details + * \param [in] string : the name of the boundary + * \param [out] void + * */ + void setNeumannBoundaryCondition(string groupName){ + _limitField[groupName]=LimitField(Neumann,-1, vector(0),vector(0), + vector(0),-1,-1,-1,-1); + }; + + void setDirichletValues(map< int, double> dirichletBoundaryValues); + + +protected : + //Main unknown field + Field _VV; + + int _Ndim;//space dimension + int _nVar;//Number of equations to solve=1 + + //Mesh data + Mesh _mesh; + bool _meshSet; + bool _initializedMemory; + int _Nmailles;//number of cells for FV calculation + int _neibMaxNbCells;//maximum number of cells around a cell + + double _precision; + double _precision_Newton; + double _erreur_rel;//norme(Uk+1-Uk) + bool _computationCompletedSuccessfully; + + //Linear solver and petsc + KSP _ksp; + KSPType _ksptype; + PC _pc; + PCType _pctype; + string _pc_hypre; + int _maxPetscIts;//nombre maximum d'iteration gmres autorisé au cours d'une resolution de système lineaire + int _PetscIts;//the number of iterations of the linear solver + Mat _A;//Linear system matrix + Vec _b;//Linear system right hand side + double _MaxIterLinearSolver;//nombre maximum d'iteration gmres obtenu au cours par les resolution de systemes lineaires au cours d'un pas de tmeps + bool _conditionNumber;//computes an estimate of the condition number + + map _limitField; + bool _onlyNeumannBC;//if true then the linear system is singular and should be solved up to a constant vector + + Vector _normale; + Vec _displacements;//unknown of the linear system + + //Physical parameterss + double _lambda, _mu;//Lamé coefficients + double _rho;//constantDensity + Field _densityField;//For non constant density field + bool _densityFieldSet; + Vector _gravity; + + //Display variables + bool _verbose, _system; + ofstream * _runLogFile;//for creation of a log file to save the history of the simulation + //saving parameters + string _fileName;//name of the calculation + string _path;//path to execution directory used for saving results + saveFormat _saveFormat;//file saving format : MED, VTK or CSV + + double computeRHS(bool & stop); + double computeStiffnessMatrixFV(bool & stop); + + /************ Data for FE calculation *************/ + bool _FECalculation; + int _Nnodes;/* number of nodes for FE calculation */ + int _neibMaxNbNodes;/* maximum number of nodes around a node */ + int _NunknownNodes;/* number of unknown nodes for FE calculation */ + int _NboundaryNodes;/* total number of boundary nodes */ + int _NdirichletNodes;/* number of boundary nodes with Dirichlet BC for FE calculation */ + std::vector< int > _boundaryNodeIds;/* List of boundary nodes */ + std::vector< int > _dirichletNodeIds;/* List of boundary nodes with Dirichlet BC */ + + /*********** Functions for finite element method ***********/ + Vector gradientNodal(Matrix M, vector< double > v);//gradient of nodal shape functions + double computeStiffnessMatrixFE(bool & stop); + int fact(int n); + int unknownNodeIndex(int globalIndex, std::vector< int > dirichletNodes); + int globalNodeIndex(int unknownIndex, std::vector< int > dirichletNodes); + + /********* Possibility to set a boundary field as Dirichlet boundary condition *********/ + bool _dirichletValuesSet; + std::map< int, double> _dirichletBoundaryValues; +}; + +#endif /* LinearElasticityModel_HXX_ */ diff --git a/CoreFlows/Models/inc/ProblemCoreFlows.hxx b/CoreFlows/Models/inc/ProblemCoreFlows.hxx index 1953c40..2756110 100755 --- a/CoreFlows/Models/inc/ProblemCoreFlows.hxx +++ b/CoreFlows/Models/inc/ProblemCoreFlows.hxx @@ -3,7 +3,7 @@ // Author : M. Ndjinga // Version : // Copyright : CEA Saclay 2014 -// Description : Generic class for thermal hydraulics problems +// Description : Generic class for PDEs problems //============================================================================ /* A ProblemCoreFlows class */ @@ -23,6 +23,8 @@ #include #include +#include +#include #include "Field.hxx" #include "Mesh.hxx" @@ -32,43 +34,6 @@ using namespace std; -//! enumeration TimeScheme -/*! The numerical method can be Explicit or Implicit */ -enum TimeScheme -{ - Explicit,/**< Explicit numerical scheme */ - Implicit/**< Implicit numerical scheme */ -}; -//! enumeration SpaceScheme -/*! Several numerical schemes are available */ -enum SpaceScheme -{ - upwind,/**< classical full upwinding scheme (first order in space) */ - centered,/**< centered scheme (second order in space) */ - pressureCorrection,/**< include a pressure correction in the upwind scheme to increase precision at low Mach numbers */ - lowMach,/**< include an upwinding proportional to the Mach numer scheme to increase precision at low Mach numbers */ - staggered,/**< scheme inspired by staggered discretisations */ -}; - -//! enumeration pressureEstimate -/*! the pressure estimate needed to fit physical parameters */ -enum pressureEstimate -{ - around1bar300K,/**< pressure is around 1 bar and temperature around 300K (for TransportEquation, SinglePhase and IsothermalTwoFluid) or 373 K (saturation for DriftModel and FiveEqsTwoFluid) */ - around155bars600K/**< pressure is around 155 bars and temperature around 618 K (saturation) */ -}; - -//! enumeration BoundaryType -/*! Boundary condition type */ -enum BoundaryType {Wall, InnerWall, Inlet, InletPressure, InletRotationVelocity, InletEnthalpy, Outlet, Neumann, Dirichlet, NoTypeSpecified}; -//! enumeration Fluid -/*! The fluid type can be Gas or water */ -enum phaseType -{ - Liquid,/**< Fluid considered is water */ - Gas/**< Fluid considered is Gas */ -}; - //! enumeration linearSolver /*! the linearSolver can be GMRES or BiCGStab (see Petsc documentation) */ enum linearSolver @@ -98,22 +63,12 @@ enum saveFormat CSV/**< CSV format is used */ }; -/** \struct LimitField - * \brief value of some fields on the boundary */ -struct LimitField{ - LimitField(){bcType=NoTypeSpecified; p=0; v_x=vector (0,0); v_y=vector (0,0); v_z=vector (0,0); T=0; h=0; alpha=0; conc=0;} - LimitField(BoundaryType _bcType, double _p, vector _v_x, vector _v_y, vector _v_z, - double _T, double _h, double _alpha, double _conc){ - bcType=_bcType; p=_p; v_x=_v_x; v_y=_v_y; v_z=_v_z; T=_T; h=_h; alpha=_alpha; conc=_conc; - } - - BoundaryType bcType; - double p;//For outlet (fluid models) - vector v_x; vector v_y; vector v_z;//For wall and inlet (fluid models) - double T; //for wall and inlet (DriftModel and FiveEqsTwoFluid) and for Dirichlet (DiffusionEquation) - double h; //for inlet (TransportEquation) - double alpha; //For inlet (IsothermalTwoFluid and FiveEqsTwoFluid) - double conc;//For inlet (DriftModel) +//! enumeration TimeScheme +/*! The numerical method can be Explicit or Implicit */ +enum TimeScheme +{ + Explicit,/**< Explicit numerical scheme */ + Implicit/**< Implicit numerical scheme */ }; class ProblemCoreFlows @@ -227,25 +182,6 @@ public : virtual Field& getOutputField(const string& nameField )=0;//Renvoie un champs pour le postraitement */ - /** \fn setBoundaryFields - * \brief met à jour _limitField ( le type de condition limite ) - * \details - * \param [in] string - * \param [out] void - * */ - void setBoundaryFields(map boundaryFields){ - _limitField = boundaryFields; - }; - /** \fn setNeumannBoundaryCondition - * \brief adds a new boundary condition of type Neumann - * \details - * \param [in] string the name of the boundary - * \param [out] void - * */ - void setNeumannBoundaryCondition(string groupName){ - _limitField[groupName]=LimitField(Neumann,-1,vector(_Ndim,0),vector(_Ndim,0),vector(_Ndim,0),-1,-1,-1,-1); - }; - //paramètres du calcul -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* /** \fn setPresentTime @@ -438,20 +374,6 @@ public : * */ double getPrecision(); - /** \fn getSpaceScheme - * \brief returns the space scheme name - * \param [in] void - * \param [out] enum SpaceScheme(upwind, centred, pressureCorrection, pressureCorrection, staggered) - * */ - SpaceScheme getSpaceScheme(); - - /** \fn getTimeScheme - * \brief returns the time scheme name - * \param [in] void - * \param [out] enum TimeScheme (explicit or implicit) - * */ - TimeScheme getTimeScheme(); - /** \fn getMesh * \brief renvoie _Mesh (le maillage du problème) * \details @@ -504,15 +426,6 @@ public : return _nVar; }; - /** \fn setNumericalScheme - * \brief sets the numerical method (upwind vs centered and explicit vs implicit - * \details - * \param [in] SpaceScheme - * \param [in] TimeScheme - * \param [out] void - * */ - void setNumericalScheme(SpaceScheme scheme, TimeScheme method=Explicit); - /** \fn setWellBalancedCorrection * \brief include a well balanced correction to treat stiff source terms * @param boolean that is true if a well balanced correction should be applied @@ -657,6 +570,12 @@ public : _system = system; }; + //Spectrum analysis + double getConditionNumber(bool isSingular=false, double tol=1e-6) const; + std::vector< double > getEigenvalues (int nev, EPSWhich which=EPS_SMALLEST_MAGNITUDE, double tol=1e-6) const; + std::vector< Vector > getEigenvectors(int nev, EPSWhich which=EPS_SMALLEST_MAGNITUDE, double tol=1e-6) const; + Field getEigenvectorsField(int nev, EPSWhich which=EPS_SMALLEST_MAGNITUDE, double tol=1e-6) const; + // some supplementary functions /** \fn displayMatrix @@ -677,6 +596,22 @@ public : * */ void displayVector(double *vector, int size, string name); + /** \fn getTimeScheme + * \brief returns the time scheme name + * \param [in] void + * \param [out] enum TimeScheme (explicit or implicit) + * */ + TimeScheme getTimeScheme(); + + /** \fn setNumericalScheme + * \brief sets the numerical method ( explicit vs implicit ) + * \details + * \param [in] TimeScheme + * \param [out] void + * */ + void setTimeScheme( TimeScheme method); + + protected : int _Ndim;//space dimension @@ -697,11 +632,10 @@ protected : double _cfl; double _maxvp;//valeur propre max pour calcul cfl double _minl;//minimum cell diameter - map _limitField; - TimeScheme _timeScheme; - SpaceScheme _spaceScheme; + bool _FECalculation; /** boolean used to specify that a well balanced correction should be used */ bool _wellBalancedCorrection; + TimeScheme _timeScheme; //Linear solver and petsc KSP _ksp; @@ -722,6 +656,8 @@ protected : bool _isStationary; bool _initialDataSet; bool _initializedMemory; + bool _restartWithNewTimeScheme; + bool _restartWithNewFileName; double _timeMax,_time; int _maxNbOfTimeStep,_nbTimeStep; double _precision; diff --git a/CoreFlows/Models/inc/ProblemFluid.hxx b/CoreFlows/Models/inc/ProblemFluid.hxx index 1429e7b..3f8fea8 100755 --- a/CoreFlows/Models/inc/ProblemFluid.hxx +++ b/CoreFlows/Models/inc/ProblemFluid.hxx @@ -19,6 +19,33 @@ using namespace std; +//! enumeration SpaceScheme +/*! Several numerical schemes are available */ +enum SpaceScheme +{ + upwind,/**< classical full upwinding scheme (first order in space) */ + centered,/**< centered scheme (second order in space) */ + pressureCorrection,/**< include a pressure correction in the upwind scheme to increase precision at low Mach numbers */ + lowMach,/**< include an upwinding proportional to the Mach numer scheme to increase precision at low Mach numbers */ + staggered,/**< scheme inspired by staggered discretisations */ +}; + +//! enumeration pressureEstimate +/*! the pressure estimate needed to fit physical parameters */ +enum pressureEstimate +{ + around1bar300K,/**< pressure is around 1 bar and temperature around 300K (for TransportEquation, SinglePhase and IsothermalTwoFluid) or 373 K (saturation for DriftModel and FiveEqsTwoFluid) */ + around155bars600K/**< pressure is around 155 bars and temperature around 618 K (saturation) */ +}; + +//! enumeration phaseType +/*! The fluid type can be Gas or water */ +enum phaseType +{ + Liquid,/**< Fluid considered is water */ + Gas/**< Fluid considered is Gas */ +}; + //! enumeration NonLinearFormulation /*! the formulation used to compute the non viscous fluxes */ enum NonLinearFormulation @@ -29,6 +56,27 @@ enum NonLinearFormulation reducedRoe,/**< compacted formulation of Roe scheme without computation of the fluxes */ }; +//! enumeration BoundaryType +/*! Boundary condition type */ +enum BoundaryType {Wall, InnerWall, Inlet, InletPressure, InletRotationVelocity, InletEnthalpy, Outlet, Neumann, NoTypeSpecified}; +/** \struct LimitField + * \brief value of some fields on the boundary */ +struct LimitField{ + LimitField(){bcType=NoTypeSpecified; p=0; v_x=vector (0,0); v_y=vector (0,0); v_z=vector (0,0); T=0; h=0; alpha=0; conc=0;} + LimitField(BoundaryType _bcType, double _p, vector _v_x, vector _v_y, vector _v_z, + double _T, double _h, double _alpha, double _conc){ + bcType=_bcType; p=_p; v_x=_v_x; v_y=_v_y; v_z=_v_z; T=_T; h=_h; alpha=_alpha; conc=_conc; + } + + BoundaryType bcType; + double p;//For outlet (fluid models) + vector v_x; vector v_y; vector v_z;//For wall and inlet (fluid models) + double T; //for wall and inlet (DriftModel and FiveEqsTwoFluid) and for Dirichlet (DiffusionEquation) + double h; //for inlet (TransportEquation) + double alpha; //For inlet (IsothermalTwoFluid and FiveEqsTwoFluid) + double conc;//For inlet (DriftModel) +}; + class ProblemFluid: public ProblemCoreFlows { @@ -94,6 +142,17 @@ public : * */ virtual void validateTimeStep(); + /* Boundary conditions */ + /** \fn setNeumannBoundaryCondition + * \brief adds a new boundary condition of type Neumann + * \details + * \param [in] string the name of the boundary + * \param [out] void + * */ + void setNeumannBoundaryCondition(string groupName){ + _limitField[groupName]=LimitField(Neumann,-1,vector(_Ndim,0),vector(_Ndim,0),vector(_Ndim,0),-1,-1,-1,-1); + }; + /** \fn setOutletBoundaryCondition * \brief Adds a new boundary condition of type Outlet * \details @@ -119,6 +178,16 @@ public : _limitField[groupName]=LimitField(Outlet,referencePressure,vector(_nbPhases,0),vector(_nbPhases,0),vector(_nbPhases,0),-1,-1,-1,-1); }; + /** \fn setBoundaryFields + * \brief met à jour _limitField ( le type de condition limite ) + * \details + * \param [in] string + * \param [out] void + * */ + void setBoundaryFields(map boundaryFields){ + _limitField = boundaryFields; + }; + /** \fn setViscosity * \brief sets the vector of viscosity coefficients * @param viscosite is a vector of size equal to the number of phases and containing the viscosity of each phase @@ -386,6 +455,22 @@ public : _usePrimitiveVarsInNewton=usePrimitiveVarsInNewton; } + /** \fn getSpaceScheme + * \brief returns the space scheme name + * \param [in] void + * \param [out] enum SpaceScheme(upwind, centred, pressureCorrection, pressureCorrection, staggered) + * */ + SpaceScheme getSpaceScheme(); + + /** \fn setNumericalScheme + * \brief sets the numerical method (upwind vs centered and explicit vs implicit) + * \details + * \param [in] SpaceScheme + * \param [in] TimeScheme + * \param [out] void + * */ + void setNumericalScheme(SpaceScheme scheme, TimeScheme method=Explicit); + //données initiales /* virtual vector getInputFieldsNames()=0 ;//Renvoie les noms des champs dont le problème a besoin (données initiales) @@ -402,9 +487,13 @@ protected : Field _UU; /** Field of interfacial states of the VFRoe scheme **/ Field _UUstar, _VVstar; + + SpaceScheme _spaceScheme; /** the formulation used to compute the non viscous fluxes **/ NonLinearFormulation _nonLinearFormulation; + map _limitField; + /** boolean used to specify that an entropic correction should be used **/ bool _entropicCorrection; /** Vector containing the eigenvalue jumps for the entropic correction **/ diff --git a/CoreFlows/Models/inc/SinglePhase.hxx b/CoreFlows/Models/inc/SinglePhase.hxx index f82e337..18c313f 100755 --- a/CoreFlows/Models/inc/SinglePhase.hxx +++ b/CoreFlows/Models/inc/SinglePhase.hxx @@ -27,6 +27,15 @@ public : * \param [in] bool : There are two possible equations of state for the fluid * */ SinglePhase(phaseType fluid, pressureEstimate pEstimate,int dim,bool useDellacherieEOS=false); + + /** \fn setViscosity + * \brief sets the viscosity + * @param viscosite : value of the dynamic viscosity + * * */ + void setViscosityConstant( double viscosite ){ + _fluides[0]->setViscosity(viscosite); + }; + //! system initialisation void initialize(); @@ -125,9 +134,20 @@ public : double getReferencePressure() { return _Pref; }; double getReferenceTemperature() { return _Tref; }; + + //get output fields for postprocessing or coupling + vector getOutputFieldsNames() ;//liste tous les champs que peut fournir le code pour le postraitement + Field& getOutputField(const string& nameField );//Renvoie un champs pour le postraitement + Field& getPressureField(); + Field& getVelocityField(); + Field& getVelocityXField(); + Field& getTemperatureField(); + Field& getDensityField(); + Field& getMomentumField(); + Field& getTotalEnergyField(); + Field& getEnthalpyField(); protected : - Field _Vitesse; double _drho_sur_dp, _drho_sur_dT;//derivatives of the density rho wrt cv, p, T double _drhoE_sur_dp, _drhoE_sur_dT;//derivatives of the total energy rho E wrt cv, p, T bool _useDellacherieEOS; @@ -188,5 +208,8 @@ protected : */ void getDensityDerivatives( double pressure, double temperature, double v2); -}; + bool _saveAllFields; + Field _Enthalpy, _Pressure, _Density, _Temperature, _Momentum, _TotalEnergy, _Vitesse, _VitesseX, _VitesseY, _VitesseZ; + + }; #endif /* SINGLEPHASE_HXX_*/ diff --git a/CoreFlows/Models/inc/StationaryDiffusionEquation.hxx b/CoreFlows/Models/inc/StationaryDiffusionEquation.hxx index d2f4ff1..7b8ced5 100755 --- a/CoreFlows/Models/inc/StationaryDiffusionEquation.hxx +++ b/CoreFlows/Models/inc/StationaryDiffusionEquation.hxx @@ -6,6 +6,7 @@ * \date June 2019 * \brief Stationary heat diffusion equation solved with either finite elements or finite volume method. * -\lambda\Delta T=\Phi + \lambda_{sf} (T_{fluid}-T) + * Dirichlet (imposed temperature) or Neumann (imposed normal flux) boundary conditions * */ //============================================================================ @@ -18,10 +19,30 @@ #define StationaryDiffusionEquation_HXX_ #include "ProblemCoreFlows.hxx" -#include "Node.hxx" + +/* for the laplacian spectrum */ +#include +#include using namespace std; +//! enumeration BoundaryType +/*! Boundary condition type */ +enum BoundaryTypeStationaryDiffusion { NeumannStationaryDiffusion, DirichletStationaryDiffusion, NoneBCStationaryDiffusion}; + +/** \struct LimitField + * \brief value of some fields on the boundary */ +struct LimitFieldStationaryDiffusion{ + LimitFieldStationaryDiffusion(){bcType=NoneBCStationaryDiffusion; T=0; normalFlux=0;} + LimitFieldStationaryDiffusion(BoundaryTypeStationaryDiffusion _bcType, double _T, double _normalFlux){ + bcType=_bcType; T=_T; normalFlux=_normalFlux; + } + + BoundaryTypeStationaryDiffusion bcType; + double T; //for Dirichlet + double normalFlux; //for Neumann +}; + class StationaryDiffusionEquation { @@ -29,21 +50,25 @@ public : /** \fn StationaryDiffusionEquation * \brief Constructor for the temperature diffusion in a solid * \param [in] int : space dimension - * \param [in] double : solid density - * \param [in] double : solid specific heat at constant pressure * \param [in] double : solid conductivity * */ StationaryDiffusionEquation( int dim,bool FECalculation=true,double lambda=1); void setMesh(const Mesh &M); - void setLinearSolver(linearSolver kspType, preconditioner pcType); void setFileName(string fileName){ _fileName = fileName; } bool solveStationaryProblem(); Field getOutputTemperatureField(); + //Linear system and spectrum + void setLinearSolver(linearSolver kspType, preconditioner pcType); + double getConditionNumber(bool isSingular=false, double tol=1e-6) const; + std::vector< double > getEigenvalues (int nev, EPSWhich which=EPS_SMALLEST_MAGNITUDE, double tol=1e-6) const; + std::vector< Vector > getEigenvectors(int nev, EPSWhich which=EPS_SMALLEST_MAGNITUDE, double tol=1e-6) const; + Field getEigenvectorsField(int nev, EPSWhich which=EPS_SMALLEST_MAGNITUDE, double tol=1e-6) const; + //Gestion du calcul void initialize(); void terminate();//vide la mémoire et enregistre le résultat final @@ -53,7 +78,7 @@ public : void save(); /* Boundary conditions */ - void setBoundaryFields(map boundaryFields){ + void setBoundaryFields(map boundaryFields){ _limitField = boundaryFields; }; /** \fn setDirichletBoundaryCondition @@ -64,8 +89,7 @@ public : * \param [out] void * */ void setDirichletBoundaryCondition(string groupName,double Temperature){ - _limitField[groupName]=LimitField(Dirichlet,-1, vector(_Ndim,0),vector(_Ndim,0), - vector(_Ndim,0),Temperature,-1,-1,-1); + _limitField[groupName]=LimitFieldStationaryDiffusion(DirichletStationaryDiffusion,Temperature,-1); }; /** \fn setNeumannBoundaryCondition @@ -74,12 +98,12 @@ public : * \param [in] string : the name of the boundary * \param [out] void * */ - void setNeumannBoundaryCondition(string groupName){ - _limitField[groupName]=LimitField(Neumann,-1, vector(0),vector(0), - vector(0),-1,-1,-1,-1); + void setNeumannBoundaryCondition(string groupName, double normalFlux=0){ + _limitField[groupName]=LimitFieldStationaryDiffusion(NeumannStationaryDiffusion,-1, normalFlux); }; void setDirichletValues(map< int, double> dirichletBoundaryValues); + void setNeumannValues (map< int, double> neumannBoundaryValues); void setConductivity(double conductivite){ _conductivity=conductivite; @@ -158,7 +182,7 @@ protected : double _MaxIterLinearSolver;//nombre maximum d'iteration gmres obtenu au cours par les resolution de systemes lineaires au cours d'un pas de tmeps bool _conditionNumber;//computes an estimate of the condition number - map _limitField; + map _limitField; bool _onlyNeumannBC;//if true then the linear system is singular and should be solved up to a constant vector bool _diffusionMatrixSet; @@ -198,12 +222,14 @@ protected : Vector gradientNodal(Matrix M, vector< double > v);//gradient of nodal shape functions double computeDiffusionMatrixFE(bool & stop); int fact(int n); - int unknownNodeIndex(int globalIndex, std::vector< int > dirichletNodes); - int globalNodeIndex(int unknownIndex, std::vector< int > dirichletNodes); + int unknownNodeIndex(int globalIndex, std::vector< int > dirichletNodes) const; + int globalNodeIndex(int unknownIndex, std::vector< int > dirichletNodes) const; - /********* Possibility to set a boundary field as Dirichlet boundary condition *********/ + /********* Possibility to set a boundary field as DirichletNeumann boundary condition *********/ bool _dirichletValuesSet; + bool _neumannValuesSet; std::map< int, double> _dirichletBoundaryValues; + std::map< int, double> _neumannBoundaryValues; }; #endif /* StationaryDiffusionEquation_HXX_ */ diff --git a/CoreFlows/Models/inc/TransportEquation.hxx b/CoreFlows/Models/inc/TransportEquation.hxx index 4c0f59f..ec6361d 100755 --- a/CoreFlows/Models/inc/TransportEquation.hxx +++ b/CoreFlows/Models/inc/TransportEquation.hxx @@ -19,17 +19,52 @@ using namespace std; + +//! enumeration phase +/*! The fluid type can be LiquidPhase or water */ +enum phase +{ + LiquidPhase,/**< Fluid considered is GasPhase */ + GasPhase/**< Fluid considered is Gas */ +}; + +//! enumeration pressureEstimate +/*! the pressure estimate needed to fit physical parameters */ +enum pressureMagnitude +{ + around1bar300KTransport,/**< pressure is around 1 bar and temperature around 300K (for TransportEquation, SinglePhase and IsothermalTwoFluid) or 373 K (saturation for DriftModel and FiveEqsTwoFluid) */ + around155bars600KTransport/**< pressure is around 155 bars and temperature around 618 K (saturation) */ +}; + +//! enumeration BoundaryType +/*! Boundary condition type */ +enum BoundaryTypeTransport {InletTransport, OutletTransport, NeumannTransport, DirichletTransport, NoneBCTransport};//Actually Inlet=Dirichlet and Outlet=Neumann + +/** \struct LimitField + * \brief value of some fields on the boundary */ +struct LimitFieldTransport{ + LimitFieldTransport(){bcType=NoneBCTransport; T=0; h=0; flux=0; } + LimitFieldTransport(BoundaryTypeTransport _bcType, double _T, double _h,double _flux ){ + bcType=_bcType; T=_T; h=_h; flux=_flux; + } + + BoundaryTypeTransport bcType; + double T; //for inlet or Dirichlet + double h; //for inlet or Dirichlet + double flux; //for Neumann or outlet +}; + class TransportEquation: public ProblemCoreFlows { public : /** \fn TransportEquation * \brief Constructor for the enthalpy transport in a fluid - * \param [in] phaseType : \ref Liquid or \ref Gas - * \param [in] pressureEstimate : \ref around1bar or \ref around155bars + * \param [in] phase : \ref Liquid or \ref Gas + * \param [in] pressureMagnitude : \ref around1bar or \ref around155bars * \param [in] vector : fluid velocity (assumed constant) * */ - TransportEquation(phaseType fluid, pressureEstimate pEstimate,vector vitesseTransport); + TransportEquation(phase fluid, pressureMagnitude pEstimate,vector vitesseTransport); //Gestion du calcul virtual void initialize(); @@ -41,6 +76,7 @@ public : virtual void save(); virtual void validateTimeStep(); + /* Boundary conditions */ /** \fn setIntletBoundaryCondition * \brief adds a new boundary condition of type Inlet * \details @@ -49,14 +85,31 @@ public : * \param [out] void * */ void setInletBoundaryCondition(string groupName,double enthalpy){ - _limitField[groupName]=LimitField(Inlet,-1,vector(_Ndim,0),vector(_Ndim,0),vector(_Ndim,0),-1,enthalpy,-1,-1); + _limitField[groupName]=LimitFieldTransport(InletTransport,-1,enthalpy,-1); + }; + + /** \fn setNeumannBoundaryCondition + * \brief adds a new boundary condition of type Neumann + * \details + * \param [in] string the name of the boundary + * \param [out] void + * */ + void setNeumannBoundaryCondition(string groupName, double flux=0){ + _limitField[groupName]=LimitFieldTransport(NeumannTransport,-1,flux,-1); + }; + + /** \fn setBoundaryFields + * \brief met à jour _limitField ( le type de condition limite ) + * \details + * \param [in] string + * \param [out] void + * */ + void setBoundaryFields(map boundaryFields){ + _limitField = boundaryFields; }; - /*Physical parameters*/ - Field& getFluidTemperatureField(){ - return _TT; - } + /*Physical parameters*/ void setLiqSatEnthalpy(double hsatl){ _hsatl=hsatl; }; @@ -72,6 +125,26 @@ public : void setTransportVelocity(Vector v){ _vitesseTransport=v; }; + + //get output fields for postprocessing or coupling + vector getOutputFieldsNames() ;//liste tous les champs que peut fournir le code pour le postraitement + Field& getOutputField(const string& nameField );//Renvoie un champs pour le postraitement + + Field& getFluidTemperatureField(){ + return _TT; + } + + Field& getEnthalpyField(){ + return _VV; + } + + /** \fn getTimeScheme + * \brief returns the time scheme name + * \param [in] void + * \param [out] enum TimeScheme (explicit or implicit) + * */ + TimeScheme getTimeScheme(); + protected : double computeTransportMatrix(); double computeRHS(); @@ -98,6 +171,8 @@ protected : bool _transportMatrixSet; Vec _Hn, _deltaH, _Hk, _Hkm1, _b0; double _dt_transport, _dt_src; + + map _limitField; }; #endif /* TransportEquation_HXX_ */ diff --git a/CoreFlows/Models/src/CMakeLists.txt b/CoreFlows/Models/src/CMakeLists.txt index 32f3c7a..d55ec75 100755 --- a/CoreFlows/Models/src/CMakeLists.txt +++ b/CoreFlows/Models/src/CMakeLists.txt @@ -1,10 +1,6 @@ INCLUDE_DIRECTORIES( - ${PETSC_INCLUDES} - ${CDMATH_INCLUDES} - ${CDMATH_INCLUDES}/med # - ${CDMATH_INCLUDES}/medcoupling # - ${CoreFlows_SRC}/inc + ${CoreFlows_INCLUDES} # ) SET(src_models_CXX @@ -22,6 +18,6 @@ SET(src_models_CXX ) ADD_LIBRARY(CoreFlows SHARED ${src_models_CXX}) -target_link_libraries(CoreFlows ${CDMATH_LIBRARIES} ${PETSC_LIBRARIES}) +target_link_libraries(CoreFlows ${CDMATH_LIBRARIES} ${PETSC_LIBRARIES} ${SLEPC_LIBRARIES}) INSTALL(TARGETS CoreFlows DESTINATION lib) diff --git a/CoreFlows/Models/src/DiffusionEquation.cxx b/CoreFlows/Models/src/DiffusionEquation.cxx index bbc5cf5..59cad62 100755 --- a/CoreFlows/Models/src/DiffusionEquation.cxx +++ b/CoreFlows/Models/src/DiffusionEquation.cxx @@ -224,7 +224,7 @@ void DiffusionEquation::initialize() cout<<"!!!!! Warning : all nodes are boundary nodes !!!!!"< DiffusionEquation::getOutputFieldsNames() +{ + vector result(2); + + result[0]="FluidTemperature"; + result[1]="RodTemperature"; + + return result; +} + +Field& DiffusionEquation::getOutputField(const string& nameField ) +{ + if(nameField=="FluidTemperature" || nameField=="FLUIDTEMPERATURE" || nameField=="TemperatureFluide" || nameField=="TEMPERATUREFLUIDE" ) + return getFluidTemperatureField(); + else if(nameField=="RodTemperature" || nameField=="RODTEMPERATURE" || nameField=="TEMPERATURECOMBUSTIBLE" || nameField=="TemperatureCombustible" ) + return getRodTemperatureField(); + else + { + cout<<"Error : Field name "<< nameField << " does not exist, call getOutputFieldsNames first" << endl; + throw CdmathException("DiffusionEquation::getOutputField error : Unknown Field name"); + } +} + diff --git a/CoreFlows/Models/src/DriftModel.cxx b/CoreFlows/Models/src/DriftModel.cxx index 3e96807..7df3613 100755 --- a/CoreFlows/Models/src/DriftModel.cxx +++ b/CoreFlows/Models/src/DriftModel.cxx @@ -116,7 +116,7 @@ void DriftModel::initialize(){ bool DriftModel::iterateTimeStep(bool &converged) { if(_timeScheme == Explicit || !_usePrimitiveVarsInNewton) - ProblemFluid::iterateTimeStep(converged); + return ProblemFluid::iterateTimeStep(converged); else { bool stop=false; @@ -3505,7 +3505,9 @@ void DriftModel::save(){ } _VV.setTime(_time,_nbTimeStep); // create mesh and component info - if (_nbTimeStep ==0){ + if (_nbTimeStep ==0 || _restartWithNewFileName){ + if (_restartWithNewFileName) + _restartWithNewFileName=false; string suppress_previous_runs ="rm -rf *"+_fileName+"_*"; system(suppress_previous_runs.c_str());//Nettoyage des précédents calculs identiques @@ -3596,7 +3598,7 @@ void DriftModel::save(){ _Vitesse(i,j)=0; } _Vitesse.setTime(_time,_nbTimeStep); - if (_nbTimeStep ==0){ + if (_nbTimeStep ==0 || _restartWithNewFileName){ _Vitesse.setInfoOnComponent(0,"Velocity_x_(m/s)"); _Vitesse.setInfoOnComponent(1,"Velocity_y_(m/s)"); _Vitesse.setInfoOnComponent(2,"Velocity_z_(m/s)"); @@ -3696,7 +3698,7 @@ void DriftModel::save(){ if(_Ndim>2) _VitesseZ.setTime(_time,_nbTimeStep); } - if (_nbTimeStep ==0){ + if (_nbTimeStep ==0 || _restartWithNewFileName){ switch(_saveFormat) { case VTK : @@ -3934,6 +3936,9 @@ void DriftModel::save(){ } } } + + if (_restartWithNewFileName) + _restartWithNewFileName=false; } void DriftModel::testConservation() diff --git a/CoreFlows/Models/src/FiveEqsTwoFluid.cxx b/CoreFlows/Models/src/FiveEqsTwoFluid.cxx index 6bc3a36..cd31022 100755 --- a/CoreFlows/Models/src/FiveEqsTwoFluid.cxx +++ b/CoreFlows/Models/src/FiveEqsTwoFluid.cxx @@ -2262,7 +2262,7 @@ void FiveEqsTwoFluid::save(){ } _VV.setTime(_time,_nbTimeStep+1); - if (_nbTimeStep ==0){ + if (_nbTimeStep ==0 || _restartWithNewFileName){ string prim_suppress ="rm -rf "+prim+"_*"; string cons_suppress ="rm -rf "+cons+"_*"; system(prim_suppress.c_str());//Nettoyage des précédents calculs identiques @@ -2370,7 +2370,7 @@ void FiveEqsTwoFluid::save(){ } _Vitesse1.setTime(_time,_nbTimeStep); _Vitesse2.setTime(_time,_nbTimeStep); - if (_nbTimeStep ==0){ + if (_nbTimeStep ==0 || _restartWithNewFileName){ _Vitesse1.setInfoOnComponent(0,"Velocity_x_(m/s)"); _Vitesse1.setInfoOnComponent(1,"Velocity_y_(m/s)"); _Vitesse1.setInfoOnComponent(2,"Velocity_z_(m/s)"); @@ -2413,4 +2413,7 @@ void FiveEqsTwoFluid::save(){ } } } + + if (_restartWithNewFileName) + _restartWithNewFileName=false; } diff --git a/CoreFlows/Models/src/IsothermalTwoFluid.cxx b/CoreFlows/Models/src/IsothermalTwoFluid.cxx index 2434fc8..b2e4d18 100755 --- a/CoreFlows/Models/src/IsothermalTwoFluid.cxx +++ b/CoreFlows/Models/src/IsothermalTwoFluid.cxx @@ -1648,7 +1648,7 @@ void IsothermalTwoFluid::save(){ _UU.setTime(_time,_nbTimeStep); } _VV.setTime(_time,_nbTimeStep); - if (_nbTimeStep ==0){ + if (_nbTimeStep ==0 || _restartWithNewFileName){ string prim_suppress ="rm -rf "+prim+"_*"; string cons_suppress ="rm -rf "+cons+"_*"; system(prim_suppress.c_str());//Nettoyage des précédents calculs identiques @@ -1755,7 +1755,7 @@ void IsothermalTwoFluid::save(){ } _Vitesse1.setTime(_time,_nbTimeStep); _Vitesse2.setTime(_time,_nbTimeStep); - if (_nbTimeStep ==0){ + if (_nbTimeStep ==0 || _restartWithNewFileName){ _Vitesse1.setInfoOnComponent(0,"Velocity_x_(m/s)"); _Vitesse1.setInfoOnComponent(1,"Velocity_y_(m/s)"); _Vitesse1.setInfoOnComponent(2,"Velocity_z_(m/s)"); @@ -1798,5 +1798,8 @@ void IsothermalTwoFluid::save(){ } } } + + if (_restartWithNewFileName) + _restartWithNewFileName=false; } diff --git a/CoreFlows/Models/src/LinearElasticityModel.cxx b/CoreFlows/Models/src/LinearElasticityModel.cxx new file mode 100755 index 0000000..6bb90d3 --- /dev/null +++ b/CoreFlows/Models/src/LinearElasticityModel.cxx @@ -0,0 +1,815 @@ +#include "LinearElasticityModel.hxx" +#include "SparseMatrixPetsc.hxx" +#include "Node.hxx" +#include "math.h" +#include +#include +#include + +using namespace std; + +int LinearElasticityModel::fact(int n) +{ + return (n == 1 || n == 0) ? 1 : fact(n - 1) * n; +} +int LinearElasticityModel::unknownNodeIndex(int globalIndex, std::vector< int > dirichletNodes) +{//assumes Dirichlet node numbering is strictly increasing + int j=0;//indice de parcours des noeuds frontière avec CL Dirichlet + int boundarySize=dirichletNodes.size(); + while(jglobalIndex) + return globalIndex-j; + else + throw CdmathException("LinearElasticityModel::unknownNodeIndex : Error : node is a Dirichlet boundary node"); +} + +int LinearElasticityModel::globalNodeIndex(int unknownNodeIndex, std::vector< int > dirichletNodes) +{//assumes Dirichlet boundary node numbering is strictly increasing + int boundarySize=dirichletNodes.size(); + /* trivial case where all boundary nodes are Neumann BC */ + if(boundarySize==0) + return unknownNodeIndex; + + double unknownNodeMax=-1;//max unknown node number in the interval between jth and (j+1)th Dirichlet boundary nodes + int j=0;//indice de parcours des noeuds frontière + //On cherche l'intervale [j,j+1] qui contient le noeud de numéro interieur unknownNodeIndex + while(j+1=unknownNodeIndex) hence our node global number is between dirichletNodes[j-1] and dirichletNodes[j] + return unknownNodeIndex - unknownNodeMax + dirichletNodes[j]-1; +} + +LinearElasticityModel::LinearElasticityModel(int dim, bool FECalculation, double rho, double lambda, double mu){ + PetscBool petscInitialized; + PetscInitialized(&petscInitialized); + if(!petscInitialized) + PetscInitialize(NULL,NULL,0,0); + + if(lambda < 0.) + { + std::cout<<"First Lamé coefficient="<(0); + _dirichletNodeIds=std::vector< int >(0); + _NboundaryNodes=0; + _NdirichletNodes=0; + _NunknownNodes=0; + _dirichletValuesSet=false; + + //Linear solver data + _precision=1.e-6; + _precision_Newton=_precision; + _MaxIterLinearSolver=0;//During several newton iterations, stores the max petssc interations + _maxPetscIts=50; + int _PetscIts=0;//the number of iterations of the linear solver + _ksptype = (char*)&KSPGMRES; + _pctype = (char*)&PCLU; + _conditionNumber=false; + _erreur_rel= 0; + + //parameters for monitoring simulation + _verbose = false; + _system = false; + _runLogFile=new ofstream; + + //result save parameters + _fileName = "LinearElasticityProblem"; + char result[ PATH_MAX ];//extracting current directory + getcwd(result, PATH_MAX ); + _path=string( result ); + _saveFormat=VTK; + _computationCompletedSuccessfully=false; + + //heat transfer parameters + _lambda= lambda; + _mu = mu; + _rho = rho; + _densityFieldSet=false; +} + +void LinearElasticityModel::initialize() +{ + _runLogFile->open((_fileName+".log").c_str(), ios::out | ios::trunc);;//for creation of a log file to save the history of the simulation + + if(!_meshSet) + throw CdmathException("LinearElasticityModel::initialize() set mesh first"); + else + { + cout<<"!!!! Initialisation of the computation of the elastic deformation of a solid using "; + *_runLogFile<<"!!!!! Initialisation of the computation of the elastic deformation of a solid using "; + if(!_FECalculation) + { + cout<< "Finite volumes method"<::iterator it=_dirichletBoundaryValues.find(_boundaryNodeIds[i]); + if( it != _dirichletBoundaryValues.end() ) + _dirichletNodeIds.push_back(_boundaryNodeIds[i]); + else if( _mesh.getNode(_boundaryNodeIds[i]).getGroupNames().size()==0 ) + { + cout<<"!!! No boundary value set for boundary node" << _boundaryNodeIds[i]<< endl; + *_runLogFile<< "!!! No boundary value set for boundary node" << _boundaryNodeIds[i]<close(); + throw CdmathException("Missing boundary value"); + } + else if(_limitField[_mesh.getNode(_boundaryNodeIds[i]).getGroupName()].bcType==NoTypeSpecified) + { + cout<<"!!! No boundary condition set for boundary node " << _boundaryNodeIds[i]<< endl; + *_runLogFile<< "!!!No boundary condition set for boundary node " << _boundaryNodeIds[i]<close(); + throw CdmathException("Missing boundary condition"); + } + else if(_limitField[_mesh.getNode(_boundaryNodeIds[i]).getGroupName()].bcType==Dirichlet) + _dirichletNodeIds.push_back(_boundaryNodeIds[i]); + else if(_limitField[_mesh.getNode(_boundaryNodeIds[i]).getGroupName()].bcType!=Neumann) + { + cout<<"!!! Wrong boundary condition "<< _limitField[_mesh.getNode(_boundaryNodeIds[i]).getGroupName()].bcType<< " set for boundary node " << _boundaryNodeIds[i]<< endl; + cout<<"!!! Accepted boundary conditions are Dirichlet "<< Dirichlet <<" and Neumann "<< Neumann << endl; + *_runLogFile<< "Wrong boundary condition "<< _limitField[_mesh.getNode(_boundaryNodeIds[i]).getGroupName()].bcType<< " set for boundary node " << _boundaryNodeIds[i]<close(); + throw CdmathException("Wrong boundary condition"); + } + } + _NdirichletNodes=_dirichletNodeIds.size(); + _NunknownNodes=_Nnodes - _NdirichletNodes; + cout<<"Number of unknown nodes " << _NunknownNodes <<", Number of boundary nodes " << _NboundaryNodes<< ", Number of Dirichlet boundary nodes " << _NdirichletNodes <::iterator it = _limitField.begin(); + while(it != _limitField.end() and (it->second).bcType == Neumann) + it++; + _onlyNeumannBC = (it == _limitField.end() && _limitField.size()>0); + //If only Neumann BC, then matrix is singular and solution should be sought in space of mean zero vectors + if(_onlyNeumannBC) + { + std::cout<<"## Warning all boundary conditions are Neumann. System matrix is not invertible since constant vectors are in the kernel."< values){ + vector< Matrix > matrices(_Ndim); + + for (int idim=0; idim<_Ndim;idim++){ + matrices[idim]=M.deepCopy(); + for (int jdim=0; jdim<_Ndim+1;jdim++) + matrices[idim](jdim,idim) = values[jdim] ; + } + + Vector result(_Ndim); + for (int idim=0; idim<_Ndim;idim++) + result[idim] = matrices[idim].determinant(); + + return result; +} + +double LinearElasticityModel::computeDiffusionMatrix(bool & stop) +{ + double result; + + if(_FECalculation) + result=computeDiffusionMatrixFE(stop); + else + result=computeDiffusionMatrixFV(stop); + + if(_verbose or _system) + MatView(_A,PETSC_VIEWER_STDOUT_SELF); + + return result; +} + +double LinearElasticityModel::computeDiffusionMatrixFE(bool & stop){ + Cell Cj; + string nameOfGroup; + double dn; + MatZeroEntries(_A); + VecZeroEntries(_b); + + Matrix M(_Ndim+1,_Ndim+1);//cell geometry matrix + std::vector< Vector > GradShapeFuncs(_Ndim+1);//shape functions of cell nodes + std::vector< int > nodeIds(_Ndim+1);//cell node Ids + std::vector< Node > nodes(_Ndim+1);//cell nodes + int i_int, j_int; //index of nodes j and k considered as unknown nodes + bool dirichletCell_treated; + + std::vector< vector< double > > values(_Ndim+1,vector< double >(_Ndim+1,0));//values of shape functions on cell node + for (int idim=0; idim<_Ndim+1;idim++) + values[idim][idim]=1; + + /* parameters for boundary treatment */ + vector< Vector > valuesBorder(_Ndim+1); + Vector GradShapeFuncBorder(_Ndim+1); + + for (int j=0; j<_Nmailles;j++) + { + Cj = _mesh.getCell(j); + + for (int idim=0; idim<_Ndim+1;idim++){ + nodeIds[idim]=Cj.getNodeId(idim); + nodes[idim]=_mesh.getNode(nodeIds[idim]); + for (int jdim=0; jdim<_Ndim;jdim++) + M(idim,jdim)=nodes[idim].getPoint()[jdim]; + M(idim,_Ndim)=1; + } + for (int idim=0; idim<_Ndim+1;idim++) + GradShapeFuncs[idim]=gradientNodal(M,values[idim])/fact(_Ndim); + + /* Loop on the edges of the cell */ + for (int idim=0; idim<_Ndim+1;idim++) + { + if(find(_dirichletNodeIds.begin(),_dirichletNodeIds.end(),nodeIds[idim])==_dirichletNodeIds.end())//!_mesh.isBorderNode(nodeIds[idim]) + {//First node of the edge is not Dirichlet node + i_int=unknownNodeIndex(nodeIds[idim], _dirichletNodeIds);//assumes Dirichlet boundary node numbering is strictly increasing + dirichletCell_treated=false; + for (int jdim=0; jdim<_Ndim+1;jdim++) + { + if(find(_dirichletNodeIds.begin(),_dirichletNodeIds.end(),nodeIds[jdim])==_dirichletNodeIds.end())//!_mesh.isBorderNode(nodeIds[jdim]) + {//Second node of the edge is not Dirichlet node + j_int= unknownNodeIndex(nodeIds[jdim], _dirichletNodeIds);//assumes Dirichlet boundary node numbering is strictly increasing + MatSetValue(_A,i_int,j_int,_conductivity*(_DiffusionTensor*GradShapeFuncs[idim])*GradShapeFuncs[jdim]/Cj.getMeasure(), ADD_VALUES); + } + else if (!dirichletCell_treated) + {//Second node of the edge is a Dirichlet node + dirichletCell_treated=true; + for (int kdim=0; kdim<_Ndim+1;kdim++) + { + std::map::iterator it=_dirichletBoundaryValues.find(nodeIds[kdim]); + if( it != _dirichletBoundaryValues.end() ) + { + if( _dirichletValuesSet )//New way of storing BC + valuesBorder[kdim]=_dirichletBoundaryValues[it->second]; + else //old way of storing BC + valuesBorder[kdim]=_limitField[_mesh.getNode(nodeIds[kdim]).getGroupName()].Displacements; + } + else + valuesBorder[kdim]=Vector(_Ndim); + } + GradShapeFuncBorder=gradientNodal(M,valuesBorder)/fact(_Ndim); + double coeff =-_conductivity*(_DiffusionTensor*GradShapeFuncBorder)*GradShapeFuncs[idim]/Cj.getMeasure(); + VecSetValue(_b,i_int,coeff, ADD_VALUES); + } + } + } + } + } + + MatAssemblyBegin(_A, MAT_FINAL_ASSEMBLY); + MatAssemblyEnd(_A, MAT_FINAL_ASSEMBLY); + VecAssemblyBegin(_b); + VecAssemblyEnd(_b); + + stop=false ; + + return INFINITY; +} + +double LinearElasticityModel::computeDiffusionMatrixFV(bool & stop){ + long nbFaces = _mesh.getNumberOfFaces(); + Face Fj; + Cell Cell1,Cell2; + string nameOfGroup; + double inv_dxi, inv_dxj; + double barycenterDistance; + Vector normale(_Ndim); + double dn; + PetscInt idm, idn; + std::vector< int > idCells; + MatZeroEntries(_A); + VecZeroEntries(_b); + + for (int j=0; j::iterator it=_dirichletBoundaryValues.find(j); + if( it != _dirichletBoundaryValues.end() ) + { + barycenterDistance=Cell1.getBarryCenter().distance(Fj.getBarryCenter()); + MatSetValue(_A,idm,idm,dn*inv_dxi/barycenterDistance , ADD_VALUES); + VecSetValue(_b,idm, dn*inv_dxi/barycenterDistance*it->second, ADD_VALUES); + } + else + { + nameOfGroup = Fj.getGroupName(); + + if (_limitField[nameOfGroup].bcType==Neumann){//Nothing to do + } + else if(_limitField[nameOfGroup].bcType==Dirichlet){ + barycenterDistance=Cell1.getBarryCenter().distance(Fj.getBarryCenter()); + MatSetValue(_A,idm,idm,dn*inv_dxi/barycenterDistance , ADD_VALUES); + VecSetValue(_b,idm, dn*inv_dxi/barycenterDistance*_limitField[nameOfGroup].T, ADD_VALUES); + } + else { + stop=true ; + cout<<"!!!!!!!!!!!!!!! Error LinearElasticityModel::computeDiffusionMatrixFV !!!!!!!!!!"< 1) + inv_dxj = Fj.getMeasure()/Cell2.getMeasure(); + else + inv_dxj = 1/Cell2.getMeasure(); + + barycenterDistance=Cell1.getBarryCenter().distance(Cell2.getBarryCenter()); + + MatSetValue(_A,idm,idm, dn*inv_dxi/barycenterDistance, ADD_VALUES); + MatSetValue(_A,idm,idn,-dn*inv_dxi/barycenterDistance, ADD_VALUES); + MatSetValue(_A,idn,idn, dn*inv_dxj/barycenterDistance, ADD_VALUES); + MatSetValue(_A,idn,idm,-dn*inv_dxj/barycenterDistance, ADD_VALUES); + } + else + { + *_runLogFile<<"LinearElasticityModel::computeDiffusionMatrixFV(): incompatible number of cells around a face"< nodesId; + for (int i=0; i<_Nmailles;i++) + { + Ci=_mesh.getCell(i); + nodesId=Ci.getNodesId(); + for (int j=0; jclose(); + throw CdmathException("LinearElasticityModel::setMesh: mesh has incorrect dimension"); + } + + _mesh=M; + _Nmailles = _mesh.getNumberOfCells(); + _Nnodes = _mesh.getNumberOfNodes(); + + cout<<"Mesh has "<< _Nmailles << " cells and " << _Nnodes << " nodes"<close(); + throw CdmathException("LinearElasticityModel::setMesh: mesh has incorrect cell types"); + } + } + else if(_Ndim==3) + { + if( _mesh.isTetrahedral() )//Mesh dim=3 + cout<<"3D Finite element method on tetrahedra"<close(); + throw CdmathException("LinearElasticityModel::setMesh: mesh has incorrect cell types"); + } + } + + _VV=Field ("Temperature", NODES, _mesh, _Ndim); + + _neibMaxNbNodes=_mesh.getMaxNbNeighbours(NODES); + _boundaryNodeIds = _mesh.getBoundaryNodeIds(); + _NboundaryNodes=_boundaryNodeIds.size(); + } + + _meshSet=true; +} + +void LinearElasticityModel::setLinearSolver(linearSolver kspType, preconditioner pcType) +{ + //_maxPetscIts=maxIterationsPetsc; + // set linear solver algorithm + if (kspType==GMRES) + _ksptype = (char*)&KSPGMRES; + else if (kspType==CG) + _ksptype = (char*)&KSPCG; + else if (kspType==BCGS) + _ksptype = (char*)&KSPBCGS; + else { + cout << "!!! Error : only 'GMRES', 'CG' or 'BCGS' is acceptable as a linear solver !!!" << endl; + *_runLogFile << "!!! Error : only 'GMRES', 'CG' or 'BCGS' is acceptable as a linear solver !!!" << endl; + _runLogFile->close(); + throw CdmathException("!!! Error : only 'GMRES', 'CG' or 'BCGS' algorithm is acceptable !!!"); + } + // set preconditioner + if (pcType == NONE) + _pctype = (char*)&PCNONE; + else if (pcType ==LU) + _pctype = (char*)&PCLU; + else if (pcType == ILU) + _pctype = (char*)&PCILU; + else if (pcType ==CHOLESKY) + _pctype = (char*)&PCCHOLESKY; + else if (pcType == ICC) + _pctype = (char*)&PCICC; + else { + cout << "!!! Error : only 'NONE', 'LU', 'ILU', 'CHOLESKY' or 'ICC' preconditioners are acceptable !!!" << endl; + *_runLogFile << "!!! Error : only 'NONE' or 'LU' or 'ILU' preconditioners are acceptable !!!" << endl; + _runLogFile->close(); + throw CdmathException("!!! Error : only 'NONE' or 'LU' or 'ILU' preconditioners are acceptable !!!" ); + } +} + +bool LinearElasticityModel::solveStationaryProblem() +{ + if(!_initializedMemory) + { + *_runLogFile<< "ProblemCoreFlows::run() call initialize() first"<< _fileName<close(); + throw CdmathException("ProblemCoreFlows::run() call initialize() first"); + } + bool stop=false; // Does the Problem want to stop (error) ? + + cout<< "!!! Running test case "<< _fileName << " using "; + *_runLogFile<< "!!! Running test case "<< _fileName<< " using "; + + if(!_FECalculation) + { + cout<< "Finite volumes method"<close(); + throw CdmathException("Failed computing diffusion matrix"); + } + computeRHS(stop); + if (stop){ + cout << "Error : failed computing right hand side, stopping calculation"<< endl; + *_runLogFile << "Error : failed computing right hand side, stopping calculation"<< endl; + throw CdmathException("Failed computing right hand side"); + } + stop = !solveLinearSystem(); + if (stop){ + cout << "Error : failed solving linear system, stopping calculation"<< endl; + *_runLogFile << "Error : failed linear system, stopping calculation"<< endl; + _runLogFile->close(); + throw CdmathException("Failed solving linear system"); + } + + _computationCompletedSuccessfully=true; + save(); + + *_runLogFile<< "!!!!!! Computation successful"<< endl; + _runLogFile->close(); + + return !stop; +} + +void LinearElasticityModel::save(){ + cout<< "Saving numerical results"< dirichletBoundaryValues) +{ + _dirichletValuesSet=true; + _dirichletBoundaryValues=dirichletBoundaryValues; +} + +double +LinearElasticityModel::getConditionNumber(bool isSingular, double tol) const +{ + SparseMatrixPetsc A = SparseMatrixPetsc(_A); + return A.getConditionNumber( isSingular, tol); +} diff --git a/CoreFlows/Models/src/ProblemCoreFlows.cxx b/CoreFlows/Models/src/ProblemCoreFlows.cxx index 5c6f505..916f607 100755 --- a/CoreFlows/Models/src/ProblemCoreFlows.cxx +++ b/CoreFlows/Models/src/ProblemCoreFlows.cxx @@ -11,6 +11,8 @@ //============================================================================ #include "ProblemCoreFlows.hxx" +#include "SparseMatrixPetsc.hxx" + #include #include @@ -39,9 +41,11 @@ ProblemCoreFlows::ProblemCoreFlows() _freqSave = 1; _initialDataSet=false; _initializedMemory=false; - _spaceScheme=upwind; + _restartWithNewTimeScheme=false; + _restartWithNewFileName=false; _timeScheme=Explicit; _wellBalancedCorrection=false; + _FECalculation=false; _maxPetscIts=50; _MaxIterLinearSolver=0;//During several newton iterations, stores the max petssc interations _maxNewtonIts=50; @@ -66,6 +70,18 @@ ProblemCoreFlows::ProblemCoreFlows() _saveFormat=VTK; } +TimeScheme ProblemCoreFlows::getTimeScheme() +{ + return _timeScheme; +} + +void ProblemCoreFlows::setTimeScheme(TimeScheme timeScheme) +{ + if( _nbTimeStep>0 && timeScheme!=_timeScheme)//This is a change of time scheme during a simulation + _restartWithNewTimeScheme=true; + _timeScheme = timeScheme; +} + bool ProblemCoreFlows::isStationary() const { return _isStationary; @@ -93,11 +109,6 @@ void ProblemCoreFlows::setPrecision(double precision) { _precision=precision; } -void ProblemCoreFlows::setNumericalScheme(SpaceScheme spaceScheme, TimeScheme timeScheme){ - _timeScheme = timeScheme; - _spaceScheme = spaceScheme; -} - void ProblemCoreFlows::setInitialField(const Field &VV) { @@ -351,14 +362,6 @@ double ProblemCoreFlows::getPrecision() { return _precision; } -SpaceScheme ProblemCoreFlows::getSpaceScheme() -{ - return _spaceScheme; -} -TimeScheme ProblemCoreFlows::getTimeScheme() -{ - return _timeScheme; -} Mesh ProblemCoreFlows::getMesh() { return _mesh; @@ -404,7 +407,7 @@ void ProblemCoreFlows::setLinearSolver(linearSolver kspType, preconditioner pcTy // Elle peut etre utilisee si le probleme n'est couple a aucun autre. // (s'il n'a besoin d'aucun champ d'entree). // Precondition: initialize -// Seule la methode terminate peut etre appelee apres +// Seule la methode terminate peut etre appelée apres bool ProblemCoreFlows::run() { if(!_initializedMemory) @@ -448,12 +451,15 @@ bool ProblemCoreFlows::run() if (!ok) // The resolution failed, try with a new time interval. { - abortTimeStep(); if(_dt>_precision){ - cout << "Failed solving time step "<<_nbTimeStep<<", time = " << _time <<" _dt= "<<_dt<<", cfl= "<<_cfl<<", trying again with cfl/2"<< endl; - *_runLogFile << "Failed solving time step "<<_nbTimeStep<<", time = " << _time <<" _dt= "<<_dt<<", cfl= "<<_cfl<<", trying again with cfl/2"<< endl; - _dt*=0.5; - _cfl*=0.5; + cout<<"ComputeTimeStep returned _dt="<<_dt<0 && fileName!=_fileName)//This is a change of file name during a simulation + _restartWithNewFileName=true; _fileName = fileName; } @@ -578,3 +586,38 @@ ProblemCoreFlows::~ProblemCoreFlows() */ delete _runLogFile; } + +double +ProblemCoreFlows::getConditionNumber(bool isSingular, double tol) const +{ + SparseMatrixPetsc A = SparseMatrixPetsc(_A); + return A.getConditionNumber( isSingular, tol); +} +std::vector< double > +ProblemCoreFlows::getEigenvalues(int nev, EPSWhich which, double tol) const +{ + SparseMatrixPetsc A = SparseMatrixPetsc(_A); + return A.getEigenvalues( nev, which, tol); +} +std::vector< Vector > +ProblemCoreFlows::getEigenvectors(int nev, EPSWhich which, double tol) const +{ + SparseMatrixPetsc A = SparseMatrixPetsc(_A); + return A.getEigenvectors( nev, which, tol); +} +Field +ProblemCoreFlows::getEigenvectorsField(int nev, EPSWhich which, double tol) const +{ + SparseMatrixPetsc A = SparseMatrixPetsc(_A); + MEDCoupling::DataArrayDouble * d = A.getEigenvectorsDataArrayDouble( nev, which, tol); + Field my_eigenfield; + + if(_FECalculation) + my_eigenfield = Field("Eigenvectors field", NODES, _mesh, nev); + else + my_eigenfield = Field("Eigenvectors field", CELLS, _mesh, nev); + + my_eigenfield.setFieldByDataArrayDouble(d); + + return my_eigenfield; +} diff --git a/CoreFlows/Models/src/ProblemFluid.cxx b/CoreFlows/Models/src/ProblemFluid.cxx index 1d736f1..6141766 100755 --- a/CoreFlows/Models/src/ProblemFluid.cxx +++ b/CoreFlows/Models/src/ProblemFluid.cxx @@ -20,13 +20,25 @@ ProblemFluid::ProblemFluid(void){ _saveConservativeField=false; _usePrimitiveVarsInNewton=false; _saveInterfacialField=false; - //Pour affichage donnees diphasiques dans IterateTimeStep - _err_press_max=0; _part_imag_max=0; _nbMaillesNeg=0; _nbVpCplx=0;_minm1=1e30;_minm2=1e30; + _err_press_max=0; _part_imag_max=0; _nbMaillesNeg=0; _nbVpCplx=0;_minm1=1e30;_minm2=1e30;//Pour affichage paramètres diphasiques dans IterateTimeStep _isScaling=false; _entropicCorrection=false; _pressureCorrectionOrder=2; _nonLinearFormulation=Roe; _maxvploc=0.; + _spaceScheme=upwind; +} + +SpaceScheme ProblemFluid::getSpaceScheme() +{ + return _spaceScheme; +} +void ProblemFluid::setNumericalScheme(SpaceScheme spaceScheme, TimeScheme timeScheme) +{ + if( _nbTimeStep>0 && timeScheme!=_timeScheme)//This is a change of time scheme during a simulation + _restartWithNewTimeScheme=true; + _timeScheme = timeScheme; + _spaceScheme = spaceScheme; } void ProblemFluid::initialize() @@ -192,7 +204,7 @@ void ProblemFluid::initialize() bool ProblemFluid::initTimeStep(double dt){ _dt = dt; - return _dt>0; + return _dt>0;//No need to call MatShift as the linear system matrix is filled at each Newton iteration (unlike linear problem) } bool ProblemFluid::iterateTimeStep(bool &converged) @@ -201,7 +213,7 @@ bool ProblemFluid::iterateTimeStep(bool &converged) if(_NEWTON_its>0){//Pas besoin de computeTimeStep à la première iteration de Newton _maxvp=0.; - computeTimeStep(stop); + computeTimeStep(stop);//This compute timestep is just to update the linear system. The time step was imposed befor starting the Newton iterations } if(stop){//Le compute time step ne s'est pas bien passé cout<<"ComputeTimeStep failed"<(1,0); _fluides.resize(1); _useDellacherieEOS=useDellacherieEOS; + _saveAllFields=false; if(pEstimate==around1bar300K){//EOS at 1 bar and 300K _Tref=300; @@ -59,9 +60,24 @@ void SinglePhase::initialize(){ _gravite[i+1]=_GravityField3d[i]; _GravityImplicitationMatrix = new PetscScalar[_nVar*_nVar]; - if(_saveVelocity) + if(_saveVelocity || _saveAllFields) _Vitesse=Field("Velocity",CELLS,_mesh,3);//Forcement en dimension 3 pour le posttraitement des lignes de courant + if(_saveAllFields) + { + _Enthalpy=Field("Enthalpy",CELLS,_mesh,1); + _Pressure=Field("Pressure",CELLS,_mesh,1); + _Density=Field("Density",CELLS,_mesh,1); + _Temperature=Field("Temperature",CELLS,_mesh,1); + _VitesseX=Field("Velocity x",CELLS,_mesh,1); + if(_Ndim>1) + { + _VitesseY=Field("Velocity y",CELLS,_mesh,1); + if(_Ndim>2) + _VitesseZ=Field("Velocity z",CELLS,_mesh,1); + } + } + if(_entropicCorrection) _entropicShift=vector(3,0);//at most 3 distinct eigenvalues @@ -71,7 +87,7 @@ void SinglePhase::initialize(){ bool SinglePhase::iterateTimeStep(bool &converged) { if(_timeScheme == Explicit || !_usePrimitiveVarsInNewton) - ProblemFluid::iterateTimeStep(converged); + return ProblemFluid::iterateTimeStep(converged); else { bool stop=false; @@ -2708,8 +2724,10 @@ void SinglePhase::getDensityDerivatives( double pressure, double temperature, do void SinglePhase::save(){ string prim(_path+"/SinglePhasePrim_");///Results string cons(_path+"/SinglePhaseCons_"); + string allFields(_path+"/"); prim+=_fileName; cons+=_fileName; + allFields+=_fileName; PetscInt Ii; for (long i = 0; i < _Nmailles; i++){ @@ -2732,7 +2750,7 @@ void SinglePhase::save(){ _VV.setTime(_time,_nbTimeStep); // create mesh and component info - if (_nbTimeStep ==0){ + if (_nbTimeStep ==0 || _restartWithNewFileName){ string prim_suppress ="rm -rf "+prim+"_*"; string cons_suppress ="rm -rf "+cons+"_*"; @@ -2782,6 +2800,7 @@ void SinglePhase::save(){ _VV.writeCSV(prim); break; } + } // do not create mesh else{ @@ -2812,7 +2831,7 @@ void SinglePhase::save(){ } } } - if(_saveVelocity){ + if(_saveVelocity || _saveAllFields){ for (long i = 0; i < _Nmailles; i++){ // j = 0 : pressure; j = _nVar - 1: temperature; j = 1,..,_nVar-2: velocity for (int j = 0; j < _Ndim; j++)//On récupère les composantes de vitesse @@ -2824,7 +2843,7 @@ void SinglePhase::save(){ _Vitesse(i,j)=0; } _Vitesse.setTime(_time,_nbTimeStep); - if (_nbTimeStep ==0){ + if (_nbTimeStep ==0 || _restartWithNewFileName){ _Vitesse.setInfoOnComponent(0,"Velocity_x_(m/s)"); _Vitesse.setInfoOnComponent(1,"Velocity_y_(m/s)"); _Vitesse.setInfoOnComponent(2,"Velocity_z_(m/s)"); @@ -2857,6 +2876,145 @@ void SinglePhase::save(){ } } } + + if(_saveAllFields) + { + double p,T,rho, h, vx,vy,vz; + int Ii; + for (long i = 0; i < _Nmailles; i++){ + Ii = i*_nVar; + VecGetValues(_conservativeVars,1,&Ii,&rho); + Ii = i*_nVar; + VecGetValues(_primitiveVars,1,&Ii,&p); + Ii = i*_nVar +_nVar-1; + VecGetValues(_primitiveVars,1,&Ii,&T); + Ii = i*_nVar + 1; + VecGetValues(_primitiveVars,1,&Ii,&vx); + if(_Ndim>1) + { + Ii = i*_nVar + 2; + VecGetValues(_primitiveVars,1,&Ii,&vy); + if(_Ndim>2){ + Ii = i*_nVar + 3; + VecGetValues(_primitiveVars,1,&Ii,&vz); + } + } + + h = _fluides[0]->getEnthalpy(T,rho); + + _Enthalpy(i)=h; + _Density(i)=rho; + _Pressure(i)=p; + _Temperature(i)=T; + _VitesseX(i)=vx; + if(_Ndim>1) + { + _VitesseY(i)=vy; + if(_Ndim>2) + _VitesseZ(i)=vz; + } + } + _Enthalpy.setTime(_time,_nbTimeStep); + _Density.setTime(_time,_nbTimeStep); + _Pressure.setTime(_time,_nbTimeStep); + _Temperature.setTime(_time,_nbTimeStep); + _VitesseX.setTime(_time,_nbTimeStep); + if(_Ndim>1) + { + _VitesseY.setTime(_time,_nbTimeStep); + if(_Ndim>2) + _VitesseZ.setTime(_time,_nbTimeStep); + } + if (_nbTimeStep ==0 || _restartWithNewFileName){ + switch(_saveFormat) + { + case VTK : + _Enthalpy.writeVTK(allFields+"_Enthalpy"); + _Density.writeVTK(allFields+"_Density"); + _Pressure.writeVTK(allFields+"_Pressure"); + _Temperature.writeVTK(allFields+"_Temperature"); + _VitesseX.writeVTK(allFields+"_VelocityX"); + if(_Ndim>1) + { + _VitesseY.writeVTK(allFields+"_VelocityY"); + if(_Ndim>2) + _VitesseZ.writeVTK(allFields+"_VelocityZ"); + } + break; + case MED : + _Enthalpy.writeMED(allFields+"_Enthalpy"); + _Density.writeMED(allFields+"_Density"); + _Pressure.writeMED(allFields+"_Pressure"); + _Temperature.writeMED(allFields+"_Temperature"); + _VitesseX.writeMED(allFields+"_VelocityX"); + if(_Ndim>1) + { + _VitesseY.writeMED(allFields+"_VelocityY"); + if(_Ndim>2) + _VitesseZ.writeMED(allFields+"_VelocityZ"); + } + break; + case CSV : + _Enthalpy.writeCSV(allFields+"_Enthalpy"); + _Density.writeCSV(allFields+"_Density"); + _Pressure.writeCSV(allFields+"_Pressure"); + _Temperature.writeCSV(allFields+"_Temperature"); + _VitesseX.writeCSV(allFields+"_VelocityX"); + if(_Ndim>1) + { + _VitesseY.writeCSV(allFields+"_VelocityY"); + if(_Ndim>2) + _VitesseZ.writeCSV(allFields+"_VelocityZ"); + } + break; + } + } + else{ + switch(_saveFormat) + { + case VTK : + _Enthalpy.writeVTK(allFields+"_Enthalpy",false); + _Density.writeVTK(allFields+"_Density",false); + _Pressure.writeVTK(allFields+"_Pressure",false); + _Temperature.writeVTK(allFields+"_Temperature",false); + _VitesseX.writeVTK(allFields+"_VelocityX",false); + if(_Ndim>1) + { + _VitesseY.writeVTK(allFields+"_VelocityY",false); + if(_Ndim>2) + _VitesseZ.writeVTK(allFields+"_VelocityZ",false); + } + break; + case MED : + _Enthalpy.writeMED(allFields+"_Enthalpy",false); + _Density.writeMED(allFields+"_Density",false); + _Pressure.writeMED(allFields+"_Pressure",false); + _Temperature.writeMED(allFields+"_Temperature",false); + _VitesseX.writeMED(allFields+"_VelocityX",false); + if(_Ndim>1) + { + _VitesseY.writeMED(allFields+"_VelocityY",false); + if(_Ndim>2) + _VitesseZ.writeMED(allFields+"_VelocityZ",false); + } + break; + case CSV : + _Enthalpy.writeCSV(allFields+"_Enthalpy"); + _Density.writeCSV(allFields+"_Density"); + _Pressure.writeCSV(allFields+"_Pressure"); + _Temperature.writeCSV(allFields+"_Temperature"); + _VitesseX.writeCSV(allFields+"_VelocityX"); + if(_Ndim>1) + { + _VitesseY.writeCSV(allFields+"_VelocityY"); + if(_Ndim>2) + _VitesseZ.writeCSV(allFields+"_VelocityZ"); + } + break; + } + } + } + if(_isStationary) { prim+="_Stat"; @@ -2890,7 +3048,7 @@ void SinglePhase::save(){ } } - if(_saveVelocity){ + if(_saveVelocity || _saveAllFields){ switch(_saveFormat) { case VTK : @@ -2905,4 +3063,186 @@ void SinglePhase::save(){ } } } + + if (_restartWithNewFileName) + _restartWithNewFileName=false; +} + +Field& SinglePhase::getPressureField() +{ + if(!_saveAllFields) + { + _Pressure=Field("Pressure",CELLS,_mesh,1); + int Ii; + for (long i = 0; i < _Nmailles; i++){ + Ii = i*_nVar; + VecGetValues(_primitiveVars,1,&Ii,&_Pressure(i)); + } + _Pressure.setTime(_time,_nbTimeStep); + } + return _Pressure; +} + +Field& SinglePhase::getTemperatureField() +{ + if(!_saveAllFields) + { + _Temperature=Field("Temperature",CELLS,_mesh,1); + int Ii; + for (long i = 0; i < _Nmailles; i++){ + Ii = i*_nVar +_nVar-1; + VecGetValues(_primitiveVars,1,&Ii,&_Temperature(i)); + } + _Temperature.setTime(_time,_nbTimeStep); + } + return _Temperature; +} + +Field& SinglePhase::getVelocityField() +{ + if(!_saveAllFields ) + { + _Vitesse=Field("Vitesse",CELLS,_mesh,3); + int Ii; + for (long i = 0; i < _Nmailles; i++) + { + for (int j = 0; j < _Ndim; j++)//On récupère les composantes de vitesse + { + int Ii = i*_nVar +1+j; + VecGetValues(_primitiveVars,1,&Ii,&_Vitesse(i,j)); + } + for (int j = _Ndim; j < 3; j++)//On met à zero les composantes de vitesse si la dimension est <3 + _Vitesse(i,j)=0; + } + _Vitesse.setTime(_time,_nbTimeStep); + _Vitesse.setInfoOnComponent(0,"Velocity_x_(m/s)"); + _Vitesse.setInfoOnComponent(1,"Velocity_y_(m/s)"); + _Vitesse.setInfoOnComponent(2,"Velocity_z_(m/s)"); + } + + return _Vitesse; +} + +Field& SinglePhase::getVelocityXField() +{ + if(!_saveAllFields ) + { + _VitesseX=Field("Velocity X",CELLS,_mesh,1); + int Ii; + for (long i = 0; i < _Nmailles; i++) + { + int Ii = i*_nVar +1; + VecGetValues(_primitiveVars,1,&Ii,&_VitesseX(i)); + } + _VitesseX.setTime(_time,_nbTimeStep); + _VitesseX.setInfoOnComponent(0,"Velocity_x_(m/s)"); + } + + return _VitesseX; +} + +Field& SinglePhase::getDensityField() +{ + if(!_saveAllFields ) + { + _Density=Field("Density",CELLS,_mesh,1); + int Ii; + for (long i = 0; i < _Nmailles; i++){ + Ii = i*_nVar; + VecGetValues(_conservativeVars,1,&Ii,&_Density(i)); + } + _Density.setTime(_time,_nbTimeStep); + } + return _Density; +} + +Field& SinglePhase::getMomentumField()//not yet managed by parameter _saveAllFields +{ + _Momentum=Field("Momentum",CELLS,_mesh,_Ndim); + int Ii; + for (long i = 0; i < _Nmailles; i++) + for (int j = 0; j < _Ndim; j++)//On récupère les composantes de qdm + { + int Ii = i*_nVar +1+j; + VecGetValues(_conservativeVars,1,&Ii,&_Momentum(i,j)); + } + _Momentum.setTime(_time,_nbTimeStep); + + return _Momentum; +} + +Field& SinglePhase::getTotalEnergyField()//not yet managed by parameter _saveAllFields +{ + _TotalEnergy=Field("TotalEnergy",CELLS,_mesh,1); + int Ii; + for (long i = 0; i < _Nmailles; i++){ + Ii = i*_nVar +_nVar-1; + VecGetValues(_conservativeVars,1,&Ii,&_TotalEnergy(i)); + } + _TotalEnergy.setTime(_time,_nbTimeStep); + + return _TotalEnergy; +} + +Field& SinglePhase::getEnthalpyField() +{ + if(!_saveAllFields ) + { + _Enthalpy=Field("Enthalpy",CELLS,_mesh,1); + int Ii; + double p,T,rho; + for (long i = 0; i < _Nmailles; i++){ + Ii = i*_nVar; + VecGetValues(_primitiveVars,1,&Ii,&p); + Ii = i*_nVar +_nVar-1; + VecGetValues(_primitiveVars,1,&Ii,&T); + + rho=_fluides[0]->getDensity(p,T); + _Enthalpy(i)=_fluides[0]->getEnthalpy(T,rho); + } + _Enthalpy.setTime(_time,_nbTimeStep); + } + + return _Enthalpy; +} + +vector SinglePhase::getOutputFieldsNames() +{ + vector result(8); + + result[0]="Pressure"; + result[1]="Velocity"; + result[2]="Temperature"; + result[3]="Density"; + result[4]="Momentum"; + result[5]="TotalEnergy"; + result[6]="Enthalpy"; + result[7]="VelocityX"; + + return result; +} + +Field& SinglePhase::getOutputField(const string& nameField ) +{ + if(nameField=="pressure" || nameField=="Pressure" || nameField=="PRESSURE" || nameField=="PRESSION" || nameField=="Pression" || nameField=="pression" ) + return getPressureField(); + else if(nameField=="velocity" || nameField=="Velocity" || nameField=="VELOCITY" || nameField=="Vitesse" || nameField=="VITESSE" || nameField=="vitesse" ) + return getVelocityField(); + else if(nameField=="velocityX" || nameField=="VelocityX" || nameField=="VELOCITYX" || nameField=="VitesseX" || nameField=="VITESSEX" || nameField=="vitesseX" ) + return getVelocityXField(); + else if(nameField=="temperature" || nameField=="Temperature" || nameField=="TEMPERATURE" || nameField=="temperature" ) + return getTemperatureField(); + else if(nameField=="density" || nameField=="Density" || nameField=="DENSITY" || nameField=="Densite" || nameField=="DENSITE" || nameField=="densite" ) + return getDensityField(); + else if(nameField=="momentum" || nameField=="Momentum" || nameField=="MOMENTUM" || nameField=="Qdm" || nameField=="QDM" || nameField=="qdm" ) + return getMomentumField(); + else if(nameField=="enthalpy" || nameField=="Enthalpy" || nameField=="ENTHALPY" || nameField=="Enthalpie" || nameField=="ENTHALPIE" || nameField=="enthalpie" ) + return getEnthalpyField(); + else if(nameField=="totalenergy" || nameField=="TotalEnergy" || nameField=="TOTALENERGY" || nameField=="ENERGIETOTALE" || nameField=="EnergieTotale" || nameField=="energietotale" ) + return getTotalEnergyField(); + else + { + cout<<"Error : Field name "<< nameField << " does not exist, call getOutputFieldsNames first" << endl; + throw CdmathException("SinglePhase::getOutputField error : Unknown Field name"); + } } diff --git a/CoreFlows/Models/src/StationaryDiffusionEquation.cxx b/CoreFlows/Models/src/StationaryDiffusionEquation.cxx index 0f2e8e6..eccee5e 100755 --- a/CoreFlows/Models/src/StationaryDiffusionEquation.cxx +++ b/CoreFlows/Models/src/StationaryDiffusionEquation.cxx @@ -1,4 +1,6 @@ #include "StationaryDiffusionEquation.hxx" +#include "Node.hxx" +#include "SparseMatrixPetsc.hxx" #include "math.h" #include #include @@ -10,7 +12,7 @@ int StationaryDiffusionEquation::fact(int n) { return (n == 1 || n == 0) ? 1 : fact(n - 1) * n; } -int StationaryDiffusionEquation::unknownNodeIndex(int globalIndex, std::vector< int > dirichletNodes) +int StationaryDiffusionEquation::unknownNodeIndex(int globalIndex, std::vector< int > dirichletNodes) const {//assumes Dirichlet node numbering is strictly increasing int j=0;//indice de parcours des noeuds frontière avec CL Dirichlet int boundarySize=dirichletNodes.size(); @@ -24,7 +26,7 @@ int StationaryDiffusionEquation::unknownNodeIndex(int globalIndex, std::vector< throw CdmathException("StationaryDiffusionEquation::unknownNodeIndex : Error : node is a Dirichlet boundary node"); } -int StationaryDiffusionEquation::globalNodeIndex(int unknownNodeIndex, std::vector< int > dirichletNodes) +int StationaryDiffusionEquation::globalNodeIndex(int unknownNodeIndex, std::vector< int > dirichletNodes) const {//assumes Dirichlet boundary node numbering is strictly increasing int boundarySize=dirichletNodes.size(); /* trivial case where all boundary nodes are Neumann BC */ @@ -42,7 +44,7 @@ int StationaryDiffusionEquation::globalNodeIndex(int unknownNodeIndex, std::vect if(j+1==boundarySize) return unknownNodeIndex+boundarySize; - else //unknownNodeMax>=unknownNodeIndex) hence our node global number is between dirichletNodes[j-1] and dirichletNodes[j] + else //unknownNodeMax>=unknownNodeIndex, hence our node global number is between dirichletNodes[j-1] and dirichletNodes[j] return unknownNodeIndex - unknownNodeMax + dirichletNodes[j]-1; } @@ -54,12 +56,12 @@ StationaryDiffusionEquation::StationaryDiffusionEquation(int dim, bool FECalcula if(lambda < 0.) { - std::cout<<"conductivity="< _boundaryFaceIds = _mesh.getBoundaryFaceIds(); - - cout <<"Total number of faces " <<_mesh.getNumberOfFaces()<<", Number of boundary faces " << _boundaryFaceIds.size()<close(); - throw CdmathException("Missing boundary value"); + throw CdmathException("Missing boundary group"); } - else if(_limitField[_mesh.getNode(_boundaryNodeIds[i]).getGroupName()].bcType==NoTypeSpecified) + else if(_limitField[_mesh.getNode(_boundaryNodeIds[i]).getGroupName()].bcType==NoneBCStationaryDiffusion) { cout<<"!!! No boundary condition set for boundary node " << _boundaryNodeIds[i]<< endl; - *_runLogFile<< "!!!No boundary condition set for boundary node " << _boundaryNodeIds[i]<close(); throw CdmathException("Missing boundary condition"); } - else if(_limitField[_mesh.getNode(_boundaryNodeIds[i]).getGroupName()].bcType==Dirichlet) + else if(_limitField[_mesh.getNode(_boundaryNodeIds[i]).getGroupName()].bcType==DirichletStationaryDiffusion) _dirichletNodeIds.push_back(_boundaryNodeIds[i]); - else if(_limitField[_mesh.getNode(_boundaryNodeIds[i]).getGroupName()].bcType!=Neumann) + else if(_limitField[_mesh.getNode(_boundaryNodeIds[i]).getGroupName()].bcType!=NeumannStationaryDiffusion) { cout<<"!!! Wrong boundary condition "<< _limitField[_mesh.getNode(_boundaryNodeIds[i]).getGroupName()].bcType<< " set for boundary node " << _boundaryNodeIds[i]<< endl; - cout<<"!!! Accepted boundary conditions are Dirichlet "<< Dirichlet <<" and Neumann "<< Neumann << endl; - *_runLogFile<< "Wrong boundary condition "<< _limitField[_mesh.getNode(_boundaryNodeIds[i]).getGroupName()].bcType<< " set for boundary node " << _boundaryNodeIds[i]<close(); throw CdmathException("Wrong boundary condition"); } @@ -256,22 +248,34 @@ void StationaryDiffusionEquation::initialize() KSPGetPC(_ksp, &_pc); PCSetType(_pc, _pctype); - //Checking whether all boundaries are Neumann boundaries - map::iterator it = _limitField.begin(); - while(it != _limitField.end() and (it->second).bcType == Neumann) - it++; - _onlyNeumannBC = (it == _limitField.end() && _limitField.size()>0); + //Checking whether all boundary conditions are Neumann boundary condition + //if(_FECalculation) _onlyNeumannBC = _NdirichletNodes==0; + if(!_neumannValuesSet)//Boundary conditions set via LimitField structure + { + map::iterator it = _limitField.begin(); + while(it != _limitField.end() and (it->second).bcType == NeumannStationaryDiffusion) + it++; + _onlyNeumannBC = (it == _limitField.end() && _limitField.size()>0);//what if _limitField.size()==0 ??? + } + else + if(_FECalculation) + _onlyNeumannBC = _neumannBoundaryValues.size()==_NboundaryNodes; + else + _onlyNeumannBC = _neumannBoundaryValues.size()==_mesh.getBoundaryFaceIds().size(); + //If only Neumann BC, then matrix is singular and solution should be sought in space of mean zero vectors if(_onlyNeumannBC) { - std::cout<<"## Warning all boundary conditions are Neumann. System matrix is not invertible since constant vectors are in the kernel."<dirichletNodes.upper_bound() + if(!_mesh.isBorderNode(nodesId[j])) { double coeff = _heatTransfertCoeff*_fluidTemperatureField(nodesId[j]) + _heatPowerField(nodesId[j]); - VecSetValue(_b,unknownNodeIndex(nodesId[j], _dirichletNodeIds), coeff*Ci.getMeasure()/(_Ndim+1),ADD_VALUES);//assumes node numbering starts with unknown nodes. otherwise unknownNodes.index(j) + VecSetValue(_b,unknownNodeIndex(nodesId[j], _dirichletNodeIds), coeff*Ci.getMeasure()/(_Ndim+1),ADD_VALUES); } } } @@ -824,7 +851,7 @@ bool StationaryDiffusionEquation::solveStationaryProblem() } */ - *_runLogFile<< "!!!!!! Computation successful"<< endl; + *_runLogFile<< "!!!!!! Computation successful !!!!!!"<< endl; _runLogFile->close(); return !stop; @@ -860,12 +887,12 @@ void StationaryDiffusionEquation::save(){ { VecGetValues(_Tk, 1, &i, &Ti); globalIndex = globalNodeIndex(i, _dirichletNodeIds); - _VV(globalIndex)=Ti;//Assumes node numbering starts with border nodes + _VV(globalIndex)=Ti; } Node Ni; string nameOfGroup; - for(int i=0; i<_NdirichletNodes; i++)//Assumes node numbering starts with border nodes + for(int i=0; i<_NdirichletNodes; i++) { Ni=_mesh.getNode(_dirichletNodeIds[i]); nameOfGroup = Ni.getGroupName(); @@ -911,3 +938,66 @@ StationaryDiffusionEquation::setDirichletValues(map< int, double> dirichletBound _dirichletBoundaryValues=dirichletBoundaryValues; } +void +StationaryDiffusionEquation::setNeumannValues(map< int, double> neumannBoundaryValues) +{ + _neumannValuesSet=true; + _neumannBoundaryValues=neumannBoundaryValues; +} + +double +StationaryDiffusionEquation::getConditionNumber(bool isSingular, double tol) const +{ + SparseMatrixPetsc A = SparseMatrixPetsc(_A); + return A.getConditionNumber( isSingular, tol); +} +std::vector< double > +StationaryDiffusionEquation::getEigenvalues(int nev, EPSWhich which, double tol) const +{ + SparseMatrixPetsc A = SparseMatrixPetsc(_A); + + if(_FECalculation)//We need to scale the FE matrix, otherwise the eigenvalues go to zero as the mesh is refined + { + Vector nodal_volumes(_NunknownNodes); + int j_int; + for(int i = 0; i< _Nmailles ; i++)//On parcourt les cellules du maillage + { + Cell Ci = _mesh.getCell(i); + for(int j = 0 ; j<_Ndim+1 ; j++)//On parcourt les noeuds de la cellule + { + if(find(_dirichletNodeIds.begin(),_dirichletNodeIds.end(),Ci.getNodeId(j))==_dirichletNodeIds.end())//node j is an unknown node (not a Dirichlet node) + { + j_int=unknownNodeIndex(Ci.getNodeId(j), _dirichletNodeIds);//indice du noeud j en tant que noeud inconnu + nodal_volumes[j_int]+=Ci.getMeasure()/(_Ndim+1); + } + } + } + for( j_int = 0; j_int< _NunknownNodes ; j_int++) + nodal_volumes[j_int]=1/nodal_volumes[j_int]; + A.leftDiagonalScale(nodal_volumes); + } + + return A.getEigenvalues( nev, which, tol); +} +std::vector< Vector > +StationaryDiffusionEquation::getEigenvectors(int nev, EPSWhich which, double tol) const +{ + SparseMatrixPetsc A = SparseMatrixPetsc(_A); + return A.getEigenvectors( nev, which, tol); +} +Field +StationaryDiffusionEquation::getEigenvectorsField(int nev, EPSWhich which, double tol) const +{ + SparseMatrixPetsc A = SparseMatrixPetsc(_A); + MEDCoupling::DataArrayDouble * d = A.getEigenvectorsDataArrayDouble( nev, which, tol); + Field my_eigenfield; + + if(_FECalculation) + my_eigenfield = Field("Eigenvectors field", NODES, _mesh, nev); + else + my_eigenfield = Field("Eigenvectors field", CELLS, _mesh, nev); + + my_eigenfield.setFieldByDataArrayDouble(d); + + return my_eigenfield; +} diff --git a/CoreFlows/Models/src/TransportEquation.cxx b/CoreFlows/Models/src/TransportEquation.cxx index 424b196..f7eef8f 100755 --- a/CoreFlows/Models/src/TransportEquation.cxx +++ b/CoreFlows/Models/src/TransportEquation.cxx @@ -5,10 +5,10 @@ using namespace std; -TransportEquation::TransportEquation(phaseType fluid, pressureEstimate pEstimate,vector vitesseTransport){ - if(pEstimate==around1bar300K){ +TransportEquation::TransportEquation(phase fluid, pressureMagnitude pEstimate,vector vitesseTransport){ + if(pEstimate==around1bar300KTransport){ _Tref=300; - if(fluid==Gas){//Nitrogen pressure 1 bar and temperature 27°C + if(fluid==GasPhase){//Nitrogen pressure 1 bar and temperature 27°C _href=3.11e5; //nitrogen enthalpy at 1 bar and 300K _cpref=1041;//nitrogen specific heat at constant pressure 1 bar and 300K //saturation data for nitrogen at 1 bar and 77K @@ -30,7 +30,7 @@ TransportEquation::TransportEquation(phaseType fluid, pressureEstimate pEstimate } else{//around155bars600K _Tref=618;//=Tsat - if(fluid==Gas){ + if(fluid==GasPhase){ _href=2.675e6; //Gas enthalpy at 155 bars and 618K _cpref=14001;//Gas specific heat at 155 bar and 618K } @@ -179,10 +179,10 @@ double TransportEquation::computeTransportMatrix(){ } nameOfGroup = Fj.getGroupName(); - if (_limitField[nameOfGroup].bcType==Neumann){ + if (_limitField[nameOfGroup].bcType==NeumannTransport){ MatSetValue(_A,idm,idm,inv_dxi*un, ADD_VALUES); } - else if(_limitField[nameOfGroup].bcType==Inlet){ + else if(_limitField[nameOfGroup].bcType==InletTransport){ if(un>0){ MatSetValue(_A,idm,idm,inv_dxi*un, ADD_VALUES); } @@ -194,7 +194,7 @@ double TransportEquation::computeTransportMatrix(){ else { cout<<"!!!!!!!!!!!!!!! Error TransportEquation::computeTransportMatrix() !!!!!!!!!!"< TransportEquation::getOutputFieldsNames() +{ + vector result(2); + + result[0]="Enthalpy"; + result[1]="FluidTemperature"; + + return result; +} + +Field& TransportEquation::getOutputField(const string& nameField ) +{ + if(nameField=="FluidTemperature" || nameField=="FLUIDTEMPERATURE" ) + return getFluidTemperatureField(); + else if(nameField=="Enthalpy" || nameField=="ENTHALPY" || nameField=="Enthalpie" || nameField=="ENTHALPY" ) + return getEnthalpyField(); + else + { + cout<<"Error : Field name "<< nameField << " does not exist, call getOutputFieldsNames first" << endl; + throw CdmathException("TransportEquation::getOutputField error : Unknown Field name"); + } +} + diff --git a/CoreFlows/README.md b/CoreFlows/README.md index 52a5f8f..f653709 100755 --- a/CoreFlows/README.md +++ b/CoreFlows/README.md @@ -84,7 +84,7 @@ Either of these latter commands results in the creation of a directory `~/worksp In the following steps we assume that [PETSC](https://www.mcs.anl.gov/petsc/) (version 3.4 or more recent) has been installed with CDMATH with the process described above. You need to set the following variables -- `CDMATH_DIR`, the path to your CDMATH installation, for example `~/workspace/cdmath/cdmath_install//share/petsc-3.8.3 ` +- `CDMATH_INSTALL`, the path to your CDMATH installation, for example `~/workspace/cdmath/cdmath_install//share/petsc-3.8.3 ` - `PETSC_DIR`, the path to your PETSc installation. If [PETSC](https://www.mcs.anl.gov/petsc/) was installed by CDMATH then [CDMATH-Toolbox](https://github.com/ndjinga/CDMATH) can be defined as `~/workspace/cdmath/cdmath_install` - `PETSC_ARCH`, the type of installation used (usually arch-linux2-c-opt or linux-gnu-c-opt) @@ -98,7 +98,7 @@ Go to the build directory - `cd CoreFlows_build ` Then run the command -- `../CDMATH-CoreFlows-master/configure --prefix=../CDMATH-CoreFlows_install/ --with-petsc-dir=$PETSC_DIR --with-petsc-arch=$PETSC_ARCH --with-cdmath-dir=$CDMATH_DIR --with-python --with-doc` +- `../CDMATH-CoreFlows-master/configure --prefix=../CDMATH-CoreFlows_install/ --with-petsc-dir=$PETSC_DIR --with-petsc-arch=$PETSC_ARCH --with-cdmath-dir=$CDMATH_INSTALL --with-python --with-doc` - `make doc install` You can add the following optional commands diff --git a/CoreFlows/cmake_files/FindCDMATH.cmake b/CoreFlows/cmake_files/FindCDMATH.cmake index 7be0a10..85892d1 100755 --- a/CoreFlows/cmake_files/FindCDMATH.cmake +++ b/CoreFlows/cmake_files/FindCDMATH.cmake @@ -54,6 +54,14 @@ set(CDMATH_INCLUDES ${CDMATH_DIR}/include) if (NOT (IS_DIRECTORY ${CDMATH_INCLUDES}) ) message (SEND_ERROR "CDMATH_INCLUDES can not be used, ${CDMATH_INCLUDES} does not exist.") endif () +set(MED_INCLUDES $ENV{MEDFILE_INCLUDE_DIRS}) +if (NOT (IS_DIRECTORY ${MED_INCLUDES}) ) + message (SEND_ERROR "MED_INCLUDES can not be used, ${MED_INCLUDES} does not exist.") +endif () +set(MEDCOUPLING_INCLUDES $ENV{MEDCOUPLING_INCLUDE_DIR}) +if (NOT (IS_DIRECTORY ${MEDCOUPLING_INCLUDES}) ) + message (SEND_ERROR "MEDCOUPLING_INCLUDES can not be used, ${MEDCOUPLING_INCLUDES} does not exist.") +endif () # CDMATH libraries against which to link # This sets the variable ${CDMATH_LIBRARIES}. @@ -61,19 +69,17 @@ set(CDMATH_LIBDIR ${CDMATH_DIR}/lib) if ( NOT (IS_DIRECTORY ${CDMATH_LIBDIR}) ) message (SEND_ERROR "CDMATH_LIBDIR can not be used, ${CDMATH_LIBDIR} does not exist.") endif () -find_library (INTERPKERNEL_LIB NAMES interpkernel PATHS ${CDMATH_LIBDIR}/medcoupling) -find_library (MEDC_LIB NAMES medC PATHS ${CDMATH_LIBDIR}) -find_library (MEDLOADER_LIB NAMES medloader PATHS ${CDMATH_LIBDIR}/medcoupling) -find_library (MEDCOUPLING_LIB NAMES medcoupling PATHS ${CDMATH_LIBDIR}/medcoupling) find_library (CDMATHBASE_LIB NAMES base PATHS ${CDMATH_LIBDIR}) find_library (CDMATHMESH_LIB NAMES mesh PATHS ${CDMATH_LIBDIR}) -#find_library (CDMATHLINEARSOLVER_LIB NAMES linearsolver PATHS ${CDMATH_LIBDIR}) +find_library (MEDC_LIB NAMES medC PATHS $ENV{MEDFILE_LIBRARIES}) +find_library (MEDLOADER_LIB NAMES medloader PATHS $ENV{MEDCOUPLING_LIBRARIES}) +find_library (MEDCOUPLING_LIB NAMES medcoupling PATHS $ENV{MEDCOUPLING_LIBRARIES}) +find_library (CDMATHLINEARSOLVER_LIB NAMES linearsolver PATHS ${CDMATH_LIBDIR}) set (CDMATH_LIBRARIES - ${INTERPKERNEL_LIB} ${MEDC_LIB} ${MEDLOADER_LIB} ${MEDCOUPLING_LIB} ${CDMATHBASE_LIB} ${CDMATHMESH_LIB} -# ${CDMATHLINEARSOLVER_LIB} + ${CDMATHLINEARSOLVER_LIB} ) diff --git a/CoreFlows/cmake_files/FindPETSc.cmake b/CoreFlows/cmake_files/FindPETSc.cmake old mode 100755 new mode 100644 index 649ae8e..a81c9f9 --- a/CoreFlows/cmake_files/FindPETSc.cmake +++ b/CoreFlows/cmake_files/FindPETSc.cmake @@ -81,8 +81,9 @@ find_path (PETSC_DIR include/petsc.h #RedHat paths /usr/include/petsc # Debian paths - /usr/lib/petscdir/3.7.6 /usr/lib/petscdir/3.7 - /usr/lib/petscdir/3.6.2 /usr/lib/petscdir/3.6 + /usr/lib/petscdir/3.12.4 /usr/lib/petscdir/3.12 #Ubuntu 20.04 + /usr/lib/petscdir/3.7.6 /usr/lib/petscdir/3.7 #Ubuntu 18.04 + /usr/lib/petscdir/3.6.2 /usr/lib/petscdir/3.6 #Ubuntu 16.04 /usr/lib/petscdir/3.5.1 /usr/lib/petscdir/3.5 /usr/lib/petscdir/3.4.2 /usr/lib/petscdir/3.4 /usr/lib/petscdir/3.3 /usr/lib/petscdir/3.2 /usr/lib/petscdir/3.1 @@ -97,9 +98,10 @@ find_program (MAKE_EXECUTABLE NAMES make gmake) if (PETSC_DIR AND NOT PETSC_ARCH) set (_petsc_arches $ENV{PETSC_ARCH} # If set, use environment variable first - linux-gnu-c-debug linux-gnu-c-opt # Debian defaults (petsc compilation) + linux-gnu-c-debug linux-gnu-c-opt # old Debian defaults (petsc compilation) + arch-linux-c-opt or arch-linux-c-debug # new Debian defaults (petsc compilation) x86_64-linux-gnu-real i686-linux-gnu-real # Debian defaults (petsc system installation) - arch-linux2-c-opt or arch-linux2-c-debug # RedHat defaults (petsc compilation) + arch-linux2-c-opt or arch-linux2-c-debug # old RedHat defaults (petsc compilation) x86_64-redhat-linux-gnu i686-redhat-linux-gnu # RedHat defaults (petsc apt installation) x86_64-unknown-linux-gnu i386-unknown-linux-gnu) set (petscconf "NOTFOUND" CACHE FILEPATH "Cleared" FORCE) diff --git a/CoreFlows/cmake_files/FindPYTHON.cmake b/CoreFlows/cmake_files/FindPYTHON.cmake index df658fb..f9e7c6e 100755 --- a/CoreFlows/cmake_files/FindPYTHON.cmake +++ b/CoreFlows/cmake_files/FindPYTHON.cmake @@ -59,6 +59,9 @@ IF(PYTHON_STATUS) IF(NOT PYTHON_ROOT_USER) SET(PYTHON_ROOT_USER $ENV{PYTHONHOME}) ENDIF(NOT PYTHON_ROOT_USER) + IF(NOT PYTHON_ROOT_USER) + SET(PYTHON_ROOT_USER /usr) + ENDIF(NOT PYTHON_ROOT_USER) ENDIF(PYTHON_STATUS) # ------ diff --git a/CoreFlows/env_CoreFlows.sh b/CoreFlows/env_CoreFlows.sh index 839dfd9..991bb77 100755 --- a/CoreFlows/env_CoreFlows.sh +++ b/CoreFlows/env_CoreFlows.sh @@ -7,10 +7,9 @@ export CoreFlows_INSTALL=@CMAKE_INSTALL_PREFIX@ export PETSC_DIR=@PETSC_DIR@ export PETSC_ARCH=@PETSC_ARCH@ export PETSC_INCLUDES=@PETSC_INCLUDES_PATH@ -export PETSC_LIBRARIES=@PETSC_LIBRARIES@ #------------------------------------------------------------------------------------------------------------------- export CoreFlows=$CoreFlows_INSTALL/bin/Executable/CoreFlowsMainExe -export LD_LIBRARY_PATH=$PETSC_DIR/$PETSC_ARCH/lib:${PETSC_DIR}/lib:/usr/lib64/:$CoreFlows_INSTALL/lib:$PETSC_LIBRARIES:${LD_LIBRARY_PATH} -export PYTHONPATH=$CoreFlows_INSTALL/lib:$CoreFlows_INSTALL/lib/CoreFlows_Python:$CoreFlows_INSTALL/bin/CoreFlows_Python:$CoreFlows_INSTALL/lib/python2.7/site-packages/salome:${PYTHONPATH} +export LD_LIBRARY_PATH=$CoreFlows_INSTALL/lib:$CDMATH_DIR/lib:${PETSC_DIR}/${PETSC_ARCH}/lib:${MEDCOUPLING_LIBRARIES}:${MEDFILE_C_LIBRARIES}:${LD_LIBRARY_PATH} +export PYTHONPATH=$CoreFlows_INSTALL/lib:$CoreFlows_INSTALL/lib/CoreFlows_Python:$CoreFlows_INSTALL/bin/CoreFlows_Python:$CoreFlows_INSTALL/lib/python2.7/site-packages/salome:$CDMATH_DIR/lib/cdmath:$CDMATH_DIR/bin/cdmath:$CDMATH_DIR/bin/cdmath/postprocessing:${PETSC_DIR}/${PETSC_ARCH}/lib:${MEDCOUPLING_LIBRARIES}:${MEDFILE_C_LIBRARIES}:${PYTHONPATH} export CoreFlowsGUI=$CoreFlows_INSTALL/bin/salome/CoreFlows_Standalone.py diff --git a/CoreFlows/examples/C/CMakeLists.txt b/CoreFlows/examples/C/CMakeLists.txt new file mode 100755 index 0000000..c18e4bd --- /dev/null +++ b/CoreFlows/examples/C/CMakeLists.txt @@ -0,0 +1,100 @@ +project(testC) + +INCLUDE_DIRECTORIES( + ${CoreFlows_INCLUDES} # +) + + +SET(_extra_lib_CoreFlows CoreFlows ${PETSC_LIBRARIES} ${CDMATH_LIBRARIES}) + + +if(CMAKE_COMPILER_IS_GNUCXX) + if (CMAKE_BUILD_TYPE STREQUAL Debug) + include(CodeCoverage) + setup_target_for_coverage(cov ctest coverage) + endif() +endif() + + +##################################### test generation with ctest + +# this function creates a target and a ctest test +function(CreateTestExec SourceTestFile libList) + get_filename_component( FILE_BASENAME ${SourceTestFile} NAME_WE) # /testxxx.c --> testxxx + set( EXECNAME "${FILE_BASENAME}.exe" ) # testxxx --> testxxx.exe + add_executable(${EXECNAME} ${SourceTestFile}) # compilation of the testxxx.exe + set_target_properties(${EXECNAME} PROPERTIES COMPILE_FLAGS "") + target_link_libraries(${EXECNAME} ${libList}) # provide required lib for testxxx.exe + add_test(${FILE_BASENAME} ${EXECNAME} "./${EXECNAME}") # adding a ctest Test +endfunction(CreateTestExec) + +# this function creates a target and a ctest test +# and also create install rules for copying the example +# in the install dir +function(CreateTestExecAndInstall SourceTestFile libList) + get_filename_component( FILE_BASENAME ${SourceTestFile} NAME_WE) # /testxxx.c --> testxxx + set( EXECNAME "${FILE_BASENAME}.exe" ) # testxxx --> testxxx.exe + add_executable(${EXECNAME} ${SourceTestFile}) # compilation of the testxxx.exe + set_target_properties(${EXECNAME} PROPERTIES COMPILE_FLAGS "") + target_link_libraries(${EXECNAME} ${libList}) # provide required lib for testxxx.exe + add_test(NAME ${EXECNAME} COMMAND "./${EXECNAME}") # adding a ctest Test + install(TARGETS ${EXECNAME} DESTINATION share/examples) +endfunction(CreateTestExecAndInstall) + + +set( libs_for_tests ${_extra_lib_CoreFlows} ) + +# copy tests resources (med files etc.) into the build directory +file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/../resources DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) + +CreateTestExecAndInstall(CoupledTransportDiffusionEquations_1DHeatedChannel.cxx "${libs_for_tests}" ) +CreateTestExecAndInstall(DiffusionEquation_1DHeatedRod.cxx "${libs_for_tests}" ) +CreateTestExecAndInstall(DiffusionEquation_1DHeatedRod_FE.cxx "${libs_for_tests}" ) +CreateTestExecAndInstall(DriftModel_1DBoilingAssembly.cxx "${libs_for_tests}" ) +CreateTestExecAndInstall(DriftModel_1DBoilingChannel.cxx "${libs_for_tests}" ) +CreateTestExecAndInstall(DriftModel_1DChannelGravity.cxx "${libs_for_tests}" ) +CreateTestExecAndInstall(DriftModel_1DDepressurisation.cxx "${libs_for_tests}" ) +CreateTestExecAndInstall(DriftModel_1DPorosityJump.cxx "${libs_for_tests}" ) +CreateTestExecAndInstall(DriftModel_1DPressureLoss.cxx "${libs_for_tests}" ) +CreateTestExecAndInstall(DriftModel_1DRiemannProblem.cxx "${libs_for_tests}" ) +CreateTestExecAndInstall(DriftModel_1DVidangeReservoir.cxx "${libs_for_tests}" ) +CreateTestExecAndInstall(DriftModel_2DInclinedBoilingChannel.cxx "${libs_for_tests}" ) +CreateTestExecAndInstall(DriftModel_2DInclinedChannelGravity.cxx "${libs_for_tests}" ) +CreateTestExecAndInstall(DriftModel_2DInclinedChannelGravityBarriers.cxx "${libs_for_tests}" ) +CreateTestExecAndInstall(DriftModel_3DCanalCloison.cxx "${libs_for_tests}" ) +CreateTestExecAndInstall(FiveEqsTwoFluid_1DBoilingChannel.cxx "${libs_for_tests}" ) +CreateTestExecAndInstall(FiveEqsTwoFluid_1DDepressurisation.cxx "${libs_for_tests}" ) +CreateTestExecAndInstall(FiveEqsTwoFluid_1DRiemannProblem.cxx "${libs_for_tests}" ) +CreateTestExecAndInstall(FiveEqsTwoFluid_2DInclinedBoilingChannel.cxx "${libs_for_tests}" ) +CreateTestExecAndInstall(FiveEqsTwoFluid_2DInclinedSedimentation.cxx "${libs_for_tests}" ) +CreateTestExecAndInstall(IsothermalTwoFluid_1DDepressurisation.cxx "${libs_for_tests}" ) +CreateTestExecAndInstall(IsothermalTwoFluid_1DRiemannProblem.cxx "${libs_for_tests}" ) +#CreateTestExecAndInstall(IsothermalTwoFluid_1DSedimentation.cxx "${libs_for_tests}" ) +CreateTestExecAndInstall(IsothermalTwoFluid_2DInclinedSedimentation.cxx "${libs_for_tests}" ) +CreateTestExecAndInstall(IsothermalTwoFluid_2DVidangeReservoir.cxx "${libs_for_tests}" ) +CreateTestExecAndInstall(SinglePhase_1DDepressurisation.cxx "${libs_for_tests}" ) +CreateTestExecAndInstall(SinglePhase_1DHeatedChannel.cxx "${libs_for_tests}" ) +CreateTestExecAndInstall(SinglePhase_1DPorosityJump.cxx "${libs_for_tests}" ) +CreateTestExecAndInstall(SinglePhase_1DRiemannProblem.cxx "${libs_for_tests}" ) +CreateTestExecAndInstall(SinglePhase_2DHeatDrivenCavity.cxx "${libs_for_tests}" ) +CreateTestExecAndInstall(SinglePhase_2DHeatDrivenCavity_unstructured.cxx "${libs_for_tests}" ) +CreateTestExecAndInstall(SinglePhase_2DHeatedChannelInclined.cxx "${libs_for_tests}" ) +CreateTestExecAndInstall(SinglePhase_2DLidDrivenCavity.cxx "${libs_for_tests}" ) +CreateTestExecAndInstall(SinglePhase_2DLidDrivenCavity_unstructured.cxx "${libs_for_tests}" ) +CreateTestExecAndInstall(SinglePhase_2DSphericalExplosion_unstructured.cxx "${libs_for_tests}" ) +CreateTestExecAndInstall(SinglePhase_3DSphericalExplosion_unstructured.cxx "${libs_for_tests}" ) +CreateTestExecAndInstall(SinglePhase_2DWallHeatedChannel_ChangeSect.cxx "${libs_for_tests}" ) +CreateTestExecAndInstall(SinglePhase_2DWallHeatedChannel.cxx "${libs_for_tests}" ) +CreateTestExecAndInstall(SinglePhase_3DHeatDrivenCavity.cxx "${libs_for_tests}" ) +CreateTestExecAndInstall(SinglePhase_HeatedWire_2Branches.cxx "${libs_for_tests}" ) +CreateTestExecAndInstall(TransportEquation_1DHeatedChannel.cxx "${libs_for_tests}" ) +CreateTestExecAndInstall(StationaryDiffusionEquation_2DEF_StructuredTriangles.cxx "${libs_for_tests}" ) +CreateTestExecAndInstall(StationaryDiffusionEquation_2DEF_StructuredTriangles_Neumann.cxx "${libs_for_tests}" ) +CreateTestExecAndInstall(StationaryDiffusionEquation_2DEF_UnstructuredTriangles.cxx "${libs_for_tests}" ) +CreateTestExecAndInstall(StationaryDiffusionEquation_2DFV_StructuredTriangles.cxx "${libs_for_tests}" ) +CreateTestExecAndInstall(StationaryDiffusionEquation_2DFV_StructuredTriangles_Neumann.cxx "${libs_for_tests}" ) +CreateTestExecAndInstall(StationaryDiffusionEquation_2DFV_StructuredSquares.cxx "${libs_for_tests}" ) +CreateTestExecAndInstall(StationaryDiffusionEquation_3DEF_StructuredTetrahedra.cxx "${libs_for_tests}" ) +CreateTestExecAndInstall(StationaryDiffusionEquation_3DFV_StructuredTetrahedra.cxx "${libs_for_tests}" ) +CreateTestExecAndInstall(testEOS.cxx "${libs_for_tests}" ) + diff --git a/CoreFlows/examples/C/CoupledTransportDiffusionEquations_1DHeatedChannel.cxx b/CoreFlows/examples/C/CoupledTransportDiffusionEquations_1DHeatedChannel.cxx new file mode 100755 index 0000000..e7f2679 --- /dev/null +++ b/CoreFlows/examples/C/CoupledTransportDiffusionEquations_1DHeatedChannel.cxx @@ -0,0 +1,201 @@ +#include "TransportEquation.hxx" +#include "DiffusionEquation.hxx" + +using namespace std; + +#define PI 3.14159265 + +void power_field_CoupledTransportDiffusionTest(Field & Phi){ + double L=4.2; + double lambda=0.2; + double phi=1e5; + double x; + Mesh M = Phi.getMesh(); + int nbCells = M.getNumberOfCells(); + for (int j = 0; j < nbCells; j++) { + x=M.getCell(j).x(); + Phi(j) = phi*cos(PI*(x-L/2)/(L+lambda)); + } +} + +int main(int argc, char** argv) +{ + //Preprocessing: mesh and group creation + double xinf=0.0; + double xsup=4.2; + int nx=100; + double eps=1.E-6; + cout << "Building of the diffusion mesh with "< boundaryFieldsDiffusion; + map boundaryFieldsTransport; + + // Boundary conditions for the solid + LimitFieldDiffusion limitNeumann; + limitNeumann.bcType=NeumannDiffusion; + boundaryFieldsDiffusion["Neumann"] = limitNeumann; + + // Boundary conditions for the fluid + LimitFieldTransport limitInlet; + limitInlet.bcType=InletTransport; + limitInlet.h =1.3e6;//Inlet water enthalpy + boundaryFieldsTransport["Inlet"] = limitInlet; + + //Set the fluid transport velocity + vector transportVelocity(1,5);//Vitesse du fluide + + //Solid parameters + double cp_ur=300;//Uranium specific heat + double rho_ur=10000;//Uranium density + double lambda_ur=5; + + TransportEquation myTransportEquation(LiquidPhase, around155bars600KTransport,transportVelocity); + Field fluidEnthalpy("Enthalpie", CELLS, transportMesh, 1); + bool FECalculation=false; + DiffusionEquation myDiffusionEquation(spaceDim,FECalculation,rho_ur, cp_ur, lambda_ur); + + Field solidTemp("Solid temperature", CELLS, diffusionMesh, 1); + Field fluidTemp("Fluid temperature", CELLS, transportMesh, 1); + + double heatTransfertCoeff=10000;//fluid/solid heat exchange coefficient + myTransportEquation.setHeatTransfertCoeff(heatTransfertCoeff); + myDiffusionEquation.setHeatTransfertCoeff(heatTransfertCoeff); + + //Set heat source in the solid + Field Phi("Heat power field", CELLS, diffusionMesh, 1); + power_field_CoupledTransportDiffusionTest(Phi); + myDiffusionEquation.setHeatPowerField(Phi); + Phi.writeVTK("1DheatPowerField"); + + //Initial field creation + Vector VV_Constant(1); + VV_Constant(0) = 623;//Rod clad temperature nucleaire + + cout << "Construction de la condition initiale " << endl; + // generate initial condition + myDiffusionEquation.setInitialFieldConstant(diffusionMesh,VV_Constant); + + + VV_Constant(0) = 1.3e6; + myTransportEquation.setInitialFieldConstant(transportMesh,VV_Constant); + + //set the boundary conditions + myTransportEquation.setBoundaryFields(boundaryFieldsTransport);//Neumann and Inlet BC will be used + myDiffusionEquation.setBoundaryFields(boundaryFieldsDiffusion);//Only Neumann BC will be used + + // set the numerical method + myDiffusionEquation.setTimeScheme( Explicit); + myTransportEquation.setTimeScheme( Explicit); + + // name result file + string fluidFileName = "1DFluidEnthalpy"; + string solidFileName = "1DSolidTemperature"; + + // parameters calculation + unsigned MaxNbOfTimeStep =3; + int freqSave = 10; + double cfl = 0.5; + double maxTime = 1000000; + double precision = 1e-6; + + myDiffusionEquation.setCFL(cfl); + myDiffusionEquation.setPrecision(precision); + myDiffusionEquation.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myDiffusionEquation.setTimeMax(maxTime); + myDiffusionEquation.setFreqSave(freqSave); + myDiffusionEquation.setFileName(solidFileName); + + myTransportEquation.setCFL(cfl); + myTransportEquation.setPrecision(precision); + myTransportEquation.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myTransportEquation.setTimeMax(maxTime); + myTransportEquation.setFreqSave(freqSave); + myTransportEquation.setFileName(fluidFileName); + + // loop on time steps + myDiffusionEquation.initialize(); + myTransportEquation.initialize(); + + double time=0,dt=0; + int nbTimeStep=0; + bool stop=false, stop_transport=false, stop_diffusion=false; // Does the Problem want to stop (error) ? + bool ok; // Is the time interval successfully solved ? + + // Time step loop + while(!stop && !(myDiffusionEquation.isStationary() && myTransportEquation.isStationary()) &&time=maxTime) + cout<<"Maximum time "<=MaxNbOfTimeStep) + cout<<"Maximum number of time steps "< xinfcore && x< xsupcore) + heatPowerField[i]=1e8; + else + heatPowerField[i]=0; + } + heatPowerField.writeVTK("heatPowerField",true); + + DriftModel myProblem(around155bars600K,spaceDim); + int nbPhase = myProblem.getNumberOfPhases(); + int nVar = myProblem.getNumberOfVariables(); + Field VV("Primitive", CELLS, M, nVar); + + // Prepare for the initial condition + Vector VV_Constant(nVar); + // constant vector + VV_Constant(0) = 0.; + VV_Constant(1) = 155e5; + for (int idim=0; idim(1,xsup)); + + // physical parameters + myProblem.setHeatPowerField(heatPowerField); + + + // set the numerical method + myProblem.setNumericalScheme(upwind, Explicit); + myProblem.setWellBalancedCorrection(true); + + // name the result file + string fileName = "DriftModel1DBoilingAssembly"; + + // setting numerical parameters + unsigned MaxNbOfTimeStep =3 ; + int freqSave = 1; + double cfl = 0.5; + double maxTime = 1; + double precision = 1e-7; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + myProblem.saveAllFields(true); + bool ok; + + // evolution + myProblem.initialize(); + + ok = myProblem.run(); + if (ok) + cout << "Simulation "<(1,xsup)); + + // physical parameters + myProblem.setHeatSource(heatPower); + + + // set the numerical method + myProblem.setNumericalScheme(upwind, Implicit); + myProblem.setWellBalancedCorrection(true); + myProblem.setNonLinearFormulation(VFFC); + + // name the result file + string fileName = "Driftmodel1DBoilingChannel"; + + // setting numerical parameters + unsigned MaxNbOfTimeStep =3 ; + int freqSave = 1; + double cfl = 100; + double maxTime = 1; + double precision = 1e-7; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + myProblem.usePrimitiveVarsInNewton(true); + myProblem.saveAllFields(true); + myProblem.displayConditionNumber(); + myProblem.setSaveFileFormat(CSV); + + // evolution + myProblem.initialize(); + + bool ok = myProblem.run(); + if (ok) + cout << "Simulation "< gravite(spaceDim,0.) ; + gravite[0]=-10; + + DriftModel myProblem(around155bars600K,spaceDim); + int nbPhase = myProblem.getNumberOfPhases(); + int nVar = myProblem.getNumberOfVariables(); + + // Prepare for the initial condition + Vector VV_Constant(nVar); + // constant vector + VV_Constant(0) = 0.; + VV_Constant(1) = 155e5; + for (int idim=0; idim(1,xsup)); + + // physical parameters + myProblem.setGravity(gravite); + + // set the numerical method + myProblem.setNumericalScheme(upwind, Implicit); + myProblem.setWellBalancedCorrection(true); + myProblem.setNonLinearFormulation(VFRoe); + + // name the result file + string fileName = "Driftmodel_1DChannelGravity"; + + // setting numerical parameters + unsigned MaxNbOfTimeStep =3 ; + int freqSave = 1; + double cfl = 100; + double maxTime = 1; + double precision = 1e-7; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + myProblem.usePrimitiveVarsInNewton(true); + myProblem.saveAllFields(true); + myProblem.displayConditionNumber(); + myProblem.setSaveFileFormat(CSV); + + // evolution + myProblem.initialize(); + + bool ok = myProblem.run(); + if (ok) + cout << "Simulation "< VV_Constant(nVar); + VV_Constant[1] = initialConc; + VV_Constant[1] = initialPressure; + VV_Constant[2] = initialVelocityX; + VV_Constant[3] = initialTemperature; + + //Initial field creation + cout << "Building initial data " << endl; + myProblem.setInitialFieldConstant( spaceDim, VV_Constant, xinf, xsup, nx,"wall","Outlet"); + + //set the boundary conditions + myProblem.setWallBoundaryCondition("wall", wallTemperature, wallVelocityX); + myProblem.setOutletBoundaryCondition("Outlet",outletPressure,vector(1,xsup)); + + // set the numerical method + myProblem.setNumericalScheme(upwind, Explicit); + myProblem.setEntropicCorrection(true); + + // name file save + string fileName = "1DDepressurisation"; + + //Numerical parameters calculation + unsigned MaxNbOfTimeStep =3; + int freqSave = 1; + double cfl = 1; + double maxTime = 1; + double precision = 1e-7; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + bool ok; + + // evolution + myProblem.initialize(); + + ok = myProblem.run(); + if (ok) + cout << "Simulation "< (xsup-xinf)/3 && x< 2*(xsup-xinf)/3) + porosityField[i]=0.5; + else + porosityField[i]=1; + } + porosityField.writeVTK("PorosityField",true); + + + DriftModel myProblem(around155bars600K,spaceDim); + int nVar = myProblem.getNumberOfVariables(); + + // Prepare for the initial condition + vector VV_Constant(nVar); + // constant vector + VV_Constant[1] = initialConc; + VV_Constant[1] = initialPressure; + VV_Constant[2] = initialVelocityX; + VV_Constant[3] = initialTemperature; + + cout << "Building initial data " << endl; + + // generate initial condition + myProblem.setInitialFieldConstant( spaceDim, VV_Constant, xinf, xsup, nx,"Inlet","Outlet"); + + //set the boundary conditions + myProblem.setInletBoundaryCondition("Inlet",initialTemperature,initialConc,initialVelocityX); + myProblem.setOutletBoundaryCondition("Outlet",initialPressure,vector(1,xsup)); + + // physical parameters + myProblem.setPorosityField(porosityField); + + // set the numerical method + myProblem.setNumericalScheme(upwind, Explicit); + myProblem.setWellBalancedCorrection(true); + myProblem.setNonLinearFormulation(VFFC) ; + + // name file save + string fileName = "1DPorosityJumpUpwindWB"; + + + /* set numerical parameters */ + unsigned MaxNbOfTimeStep =3; + int freqSave = 1; + double cfl = 0.95; + double maxTime = 5; + double precision = 1e-5; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + bool ok; + + // evolution + myProblem.initialize(); + + ok = myProblem.run(); + if (ok) + cout << "Simulation "< VV_Constant(nVar); + // constant vector + VV_Constant[0] = inletConc; + VV_Constant[1] = outletPressure; + VV_Constant[2] = inletVelocityX; + VV_Constant[3] = inletTemperature; + + cout << "Building initial data " << endl; + + // generate initial condition + myProblem.setInitialFieldConstant( spaceDim, VV_Constant, xinf, xsup, nx,"inlet","outlet"); + + //set the boundary conditions + myProblem.setInletBoundaryCondition("inlet",inletTemperature,inletConc,inletVelocityX); + myProblem.setOutletBoundaryCondition("outlet", outletPressure,vector(1,xsup)); + + // physical parameters + myProblem.setPressureLossField(pressureLossField); + + // set the numerical method + myProblem.setNumericalScheme(upwind, Explicit); + myProblem.setWellBalancedCorrection(true); + + // name file save + string fileName = "1DPressureLossUpwindWB"; + + // parameters calculation + unsigned MaxNbOfTimeStep =3; + int freqSave = 1; + double cfl = 0.95; + double maxTime = 5; + double precision = 1e-5; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + + // evolution + myProblem.initialize(); + + bool ok = myProblem.run(); + if (ok) + cout << "Simulation "< boundaryFields; + boundaryFields["Neumann"] = limitNeumann; + + DriftModel myProblem(around155bars600K,spaceDim); + int nbPhase = myProblem.getNumberOfPhases(); + int nVar = myProblem.getNumberOfVariables(); + Field VV("Primitive", CELLS, M, nVar);//3+spaceDim*nbPhase + + // Prepare for the initial condition + Vector VV_Left(nVar),VV_Right(nVar); + double discontinuity = (xinf+xsup)/2.; + VV_Left(0) = 0.5; VV_Right(0) = 0.2; + VV_Left(1) = 155e5; VV_Right(1) = 155e5; + for (int idim=0; idim gravite(spaceDim, 0.); + gravite[0] = -10; + + DriftModel myProblem(around1bar300K, spaceDim, false); + int nbPhase = myProblem.getNumberOfPhases(); + int nVar = myProblem.getNumberOfVariables(); + + // Prepare for the initial condition + Vector VV_top(nVar), VV_bottom(nVar); + +// top and bottom vectors + VV_top[0] = initialConcTop; + VV_top[1] = initialPressure; + VV_top[2] = initialVelocityX; + VV_top[3] = initialTemperature; + + VV_bottom[0] = initialConcBottom; + VV_bottom[1] = initialPressure; + VV_bottom[2] = initialVelocityX; + VV_bottom[3] = initialTemperature; + + //Initial field creation + cout << "Setting initial data " << endl; + myProblem.setInitialFieldStepFunction(M, VV_bottom, VV_top, .8, 0); + + //set the boundary conditions + myProblem.setInletPressureBoundaryCondition("Inlet", outletPressure,inletTemperature, inletConc, vector(1, xinf)); + myProblem.setOutletBoundaryCondition("Outlet", outletPressure,vector(1, xsup)); + + // physical parameters + myProblem.setGravity(gravite); + + // set the numerical method + myProblem.setNumericalScheme(upwind, Explicit); + myProblem.setWellBalancedCorrection(true); + myProblem.setNonLinearFormulation(VFFC); + + // name the result file + string fileName = "Driftmodel_1DVidangeReservoir"; + + // setting numerical parameters + unsigned MaxNbOfTimeStep = 1; + int freqSave = 1; + double cfl = 0.95; + double maxTime = 1; + double precision = 1e-5; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + myProblem.usePrimitiveVarsInNewton(true); + myProblem.saveAllFields(true); + myProblem.setVerbose(true); + myProblem.displayConditionNumber(); + myProblem.setSaveFileFormat(CSV); + + // evolution + myProblem.initialize(); + + bool ok = myProblem.run(); + if (ok) + cout << "Simulation " << fileName << " is successful !" << endl; + else + cout << "Simulation " << fileName << " failed ! " << endl; + + cout << "------------ End of calculation -----------" << endl; + myProblem.terminate(); + + return EXIT_SUCCESS; +} diff --git a/CoreFlows/examples/C/DriftModel_2DInclinedBoilingChannel.cxx b/CoreFlows/examples/C/DriftModel_2DInclinedBoilingChannel.cxx new file mode 100755 index 0000000..12ac3dc --- /dev/null +++ b/CoreFlows/examples/C/DriftModel_2DInclinedBoilingChannel.cxx @@ -0,0 +1,98 @@ +#include "DriftModel.hxx" + +using namespace std; + +int main(int argc, char** argv) +{ + int spaceDim = 2; + + // set the limit field for each boundary + double wallVelocityX=0; + double wallVelocityY=0; + double wallTemperature=563; + + double inletConcentration=0; + double inletVelocityX=0; + double inletVelocityY=1; + double inletTemperature=563; + + double outletPressure=155e5; + + // physical constants + vector gravite(spaceDim,0.) ; + gravite[1]=-7; + gravite[0]=7; + double heatPower=1e8; + + DriftModel myProblem(around155bars600K,spaceDim); + int nVar = myProblem.getNumberOfVariables(); + + //Prepare for the mesh + double xinf=0.0; + double xsup=1.0; + double yinf=0.0; + double ysup=1.0; + int nx=20; + int ny=20; + + // Prepare for the initial condition + vector VV_Constant(nVar); + // constant vector + VV_Constant[0] = 0; + VV_Constant[1] = 155e5; + VV_Constant[2] = 0; + VV_Constant[3] = 1; + VV_Constant[4] = 563; + + //Initial field creation + cout << "Building initial data" << endl; + myProblem.setInitialFieldConstant(spaceDim,VV_Constant,xinf,xsup,nx,"wall","wall",yinf,ysup,ny,"inlet","outlet"); + + //set the boundary conditions + vectorpressure_reference_point(2); + pressure_reference_point[0]=xsup; + pressure_reference_point[1]=ysup; + myProblem.setOutletBoundaryCondition("outlet", outletPressure,pressure_reference_point); + myProblem.setInletBoundaryCondition("inlet", inletTemperature, inletConcentration, inletVelocityX, inletVelocityY); + myProblem.setWallBoundaryCondition("wall", wallTemperature, wallVelocityX, wallVelocityY); + + // set physical parameters + myProblem.setHeatSource(heatPower); + myProblem.setGravity(gravite); + + // set the numerical method + myProblem.setNumericalScheme(upwind, Explicit); + myProblem.setWellBalancedCorrection(true); + + // name of result file + string fileName = "DriftModel_2DInclinedBoilingChannel"; + + // computation parameters + unsigned MaxNbOfTimeStep = 3 ; + int freqSave = 1; + double cfl = 0.5; + double maxTime = 5; + double precision = 1e-4; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + myProblem.saveVelocity(); + + // evolution + myProblem.initialize(); + + bool ok = myProblem.run(); + if (ok) + cout << "Simulation "< gravite(spaceDim,0.) ; + gravite[1]=-8.5; + gravite[0]=5; + + DriftModel myProblem(around155bars600K,spaceDim); + int nVar = myProblem.getNumberOfVariables(); + + // Prepare for the initial condition + vector VV_Constant(nVar); + // constant vector + VV_Constant[0] = 0; + VV_Constant[1] = 155e5; + VV_Constant[2] = 0; + VV_Constant[3] = 1; + VV_Constant[4] = 563; + + //Initial field creation + cout << "Building initial data" << endl; + myProblem.setInitialFieldConstant(spaceDim,VV_Constant,xinf,xsup,nx,"wall","wall",yinf,ysup,ny,"inlet","outlet"); + + //set the boundary conditions + vectorpressure_reference_point(2); + pressure_reference_point[0]=xsup; + pressure_reference_point[1]=ysup; + myProblem.setOutletBoundaryCondition("outlet", outletPressure,pressure_reference_point); + myProblem.setInletBoundaryCondition("inlet", inletTemperature, inletConcentration, inletVelocityX, inletVelocityY); + myProblem.setWallBoundaryCondition("wall", wallTemperature, wallVelocityX, wallVelocityY); + + // set physical parameters + myProblem.setGravity(gravite); + + // set the numerical method + myProblem.setNumericalScheme(upwind, Explicit); + myProblem.setWellBalancedCorrection(true); + myProblem.setNonLinearFormulation(VFFC); + + // name of result file + string fileName = "2DInclinedChannelGravity"; + + // computation parameters + unsigned MaxNbOfTimeStep = 3 ; + int freqSave = 1; + double cfl = 0.5; + double maxTime = 5; + double precision = 1e-6; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + myProblem.usePrimitiveVarsInNewton(true); + + // evolution + myProblem.initialize(); + + bool ok = myProblem.run(); + if (ok) + cout << "Simulation "< yinf+(ysup-yinf)/4) && (abs(x-xcloison1)< eps or abs(x-xcloison2)< eps) ) || abs(x-xinf)< eps || abs(x-xsup)< eps) + barrierField[i]=1; + else + barrierField[i]=0; + } + + barrierField.writeVTK("barrierField",true); + + // set the limit field for each boundary + double wallVelocityX=0; + double wallVelocityY=0; + double wallTemperature=563; + + double inletConcentration=0; + double inletVelocityX=0; + double inletVelocityY=1; + double inletTemperature=563; + + double outletPressure=155e5; + + // physical constants + vector gravite(spaceDim,0.) ; + gravite[1]=-7; + gravite[0]=7; + + DriftModel myProblem(around155bars600K,spaceDim); + int nVar = myProblem.getNumberOfVariables(); + + // Prepare for the initial condition + vector VV_Constant(nVar); + // constant vector + VV_Constant[0] = 0; + VV_Constant[1] = 155e5; + VV_Constant[2] = 0; + VV_Constant[3] = 1; + VV_Constant[4] = 563; + + //Initial field creation + cout << "Building initial data" << endl; + myProblem.setInitialFieldConstant(M,VV_Constant); + + //set the boundary conditions + vectorpressure_reference_point(2); + pressure_reference_point[0]=xsup; + pressure_reference_point[1]=ysup; + myProblem.setOutletBoundaryCondition("outlet", outletPressure,pressure_reference_point); + myProblem.setInletBoundaryCondition("inlet", inletTemperature, inletConcentration, inletVelocityX, inletVelocityY); + myProblem.setWallBoundaryCondition("wall", wallTemperature, wallVelocityX, wallVelocityY); + + // set physical parameters + myProblem.setGravity(gravite); + + // set the numerical method + myProblem.setNumericalScheme(upwind, Explicit); + myProblem.setWellBalancedCorrection(true); + myProblem.setNonLinearFormulation(VFFC); + + // name of result file + string fileName = "2DInclinedChannelGravityBarriers"; + + // computation parameters + unsigned MaxNbOfTimeStep = 3 ; + int freqSave = 1; + double cfl = 0.5; + double maxTime = 500; + double precision = 1e-6; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + myProblem.usePrimitiveVarsInNewton(true); + + // evolution + myProblem.initialize(); + + bool ok = myProblem.run(); + if (ok) + cout << "Simulation "< gravite = vector(spaceDim,0); + + gravite[0]=0; + gravite[1]=0; + gravite[2]=-10; + + double heatPower1=0; + double heatPower2=0.25e8; + double heatPower3=0.5e8; + double heatPower4=1e8; + + DriftModel myProblem = DriftModel(around155bars600K,spaceDim); + int nVar =myProblem.getNumberOfVariables(); + Field heatPowerField=Field("heatPowerField", CELLS, M, 1); + + int nbCells=M.getNumberOfCells(); + + for (int i=0;i zcloisonmin && z< zcloisonmax) + if (yxcloison) + heatPowerField[i]=heatPower2; + if (y>ycloison && xycloison && x>xcloison) + heatPowerField[i]=heatPower4; + else + heatPowerField[i]=0; + } + heatPowerField.writeVTK("heatPowerField",true); + + //Prepare for the initial condition + Vector VV_Constant =Vector(nVar); + + // constant vector + VV_Constant[0] = inletConc ; + VV_Constant[1] = outletPressure ; + VV_Constant[2] = inletVelocityX; + VV_Constant[3] = inletVelocityY; + VV_Constant[4] = inletVelocityZ; + VV_Constant[5] = inletTemperature ; + + //Initial field creation + cout<<"Building initial data " <inletVelocityX(2,2); + double inletTemperature=563; + + double outletPressure=155e5; + + // physical constants + double heatPower=1e8; + int nbPhase=2; + + FiveEqsTwoFluid myProblem(around155bars600K,spaceDim); + int nVar = myProblem.getNumberOfVariables(); + + // Prepare for the initial condition + vector VV_Constant(nVar); + // constant vector + VV_Constant[0] = inletVoidFraction; + VV_Constant[1] = outletPressure; + VV_Constant[2] = inletVelocityX[0]; + VV_Constant[3] = inletVelocityX[1]; + VV_Constant[2+spaceDim*nbPhase] = inletTemperature; + + cout << "Building initial data" << endl; + // generate initial condition + myProblem.setInitialFieldConstant( spaceDim, VV_Constant, xinf, xsup, nx,"inlet","outlet"); + + //set the boundary conditions + myProblem.setInletBoundaryCondition("inlet",inletVoidFraction,inletTemperature,inletVelocityX); + myProblem.setOutletBoundaryCondition("outlet", outletPressure); + + // physical parameters + myProblem.setHeatSource(heatPower); + + // set the numerical method + myProblem.setNumericalScheme(upwind, Explicit); + myProblem.setWellBalancedCorrection(true); + myProblem.setEntropicCorrection(true); + + // name file save + string fileName = "1DBoilingChannel"; + + // parameters calculation + unsigned MaxNbOfTimeStep =3; + int freqSave = 1; + double cfl = 0.5; + double maxTime = 5; + double precision = 1e-8; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + + // evolution + myProblem.initialize(); + + bool ok = myProblem.run(); + if (ok) + cout << "Simulation "< boundaryFields; + limitOutlet.bcType=Outlet; + limitOutlet.p = 100e5; + boundaryFields["Outlet"] = limitOutlet; + + limitWall.bcType=Wall; + limitWall.T = 600; + limitWall.v_x = vector(2,0); + boundaryFields["Wall"]= limitWall; + + // physical constants + double latentHeat=1e6; + double satTemp=618; + double dHsatl_over_dp=0.05; + double Psat=85e5; + + FiveEqsTwoFluid myProblem(around155bars600K,spaceDim); + int nbPhase = myProblem.getNumberOfPhases(); + int nVar = myProblem.getNumberOfVariables(); + + //Initial field creation + Vector VV_Constant(nVar); + VV_Constant(0) = 0.; + VV_Constant(1) = 155e5; + for (int idim=0; idim boundaryFields; + + limitNeumann.bcType=Neumann; + limitNeumann.T =0.; + limitNeumann.p = 155e5; + limitNeumann.alpha = 0; + limitNeumann.v_x = vector(2,0); + limitNeumann.v_y = vector(2,0); + limitNeumann.v_z = vector(2,0); + boundaryFields["Neumann"] = limitNeumann; + + FiveEqsTwoFluid myProblem(around155bars600K,spaceDim); + int nbPhase = myProblem.getNumberOfPhases(); + int nVar = myProblem.getNumberOfVariables(); + Field VV("Primitive", CELLS, M, nVar); + + // Prepare for the initial condition + Vector VV_Left(nVar),VV_Right(nVar); + double discontinuity = (xinf+xsup)/2.; + // two vectors + VV_Left(0) = 0.5; VV_Right(0) = 0.2; + VV_Left(1) = 155e5; VV_Right(1) = 155e5; + for (int idim=0; idim gravite(spaceDim,0.) ; + gravite[1]=-7; + gravite[0]=7; + + // set the limit field for each boundary + LimitField limitWall; + map boundaryFields; + limitWall.bcType=Wall; + limitWall.T = 563; + limitWall.v_x = vector(2,0); + limitWall.v_y = vector(2,0); + boundaryFields["Wall"]= limitWall; + + LimitField limitInlet; + limitInlet.bcType=Inlet; + limitInlet.T = 563; + limitInlet.alpha = 0; + limitInlet.v_x = vector(2,0); + limitInlet.v_y = vector(2,1); + boundaryFields["Inlet"]= limitInlet; + + LimitField limitOutlet; + limitOutlet.bcType=Outlet; + limitOutlet.p = 155e5; + boundaryFields["Outlet"]= limitOutlet; + + // physical constants + double heatPower=1e8; + + FiveEqsTwoFluid myProblem(around155bars600K,spaceDim); + int nbPhase = myProblem.getNumberOfPhases(); + int nVar = myProblem.getNumberOfVariables(); + // Prepare for the initial condition + Vector VV_Constant(nVar); + // constant vector + VV_Constant(0) = 0; + VV_Constant(1) = 155e5; + VV_Constant(2) = 0; + VV_Constant(3) = 1; + VV_Constant(4) = 0; + VV_Constant(5) = 1; + VV_Constant(6) = 563; + + //Initial field creation + cout << "Building initial data " << endl; + myProblem.setInitialFieldConstant(M,VV_Constant); + + //set the boundary conditions + myProblem.setBoundaryFields(boundaryFields); + + // set physical parameters + myProblem.setHeatSource(heatPower); + myProblem.setGravity(gravite); + + // name file save + string fileName = "2DInclinedBoilingChannel"; + + //numerical parameters + myProblem.setNumericalScheme(upwind, Explicit); + unsigned MaxNbOfTimeStep = 3 ; + int freqSave = 5; + double cfl = 0.5; + double maxTime = 5; + double precision = 1e-6; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + myProblem.saveVelocity(); + + // evolution + myProblem.initialize(); + + bool ok = myProblem.run(); + if (ok) + cout << "Simulation "< wallVelocityX(2,0); + vector wallVelocityY(2,0); + double wallTemperature=300; + + // physical constants + vector gravite(spaceDim,0.) ; + gravite[1]=-7; + gravite[0]=7; + + FiveEqsTwoFluid myProblem(around1bar300K,spaceDim); + int nbPhase = myProblem.getNumberOfPhases(); + int nVar = myProblem.getNumberOfVariables(); + // Prepare for the initial condition + Vector VV_Constant(nVar); + // constant vector + VV_Constant(0) = 0.5; + VV_Constant(1) = 1e5; + VV_Constant(2) = 0; + VV_Constant(3) = 0; + VV_Constant(4) = 0; + VV_Constant(5) = 0; + VV_Constant(6) = wallTemperature; + + //Initial field creation + cout << "Building initial data" << endl; + myProblem.setInitialFieldConstant(M,VV_Constant); + + //set the boundary conditions + myProblem.setWallBoundaryCondition("Wall",wallTemperature,wallVelocityX,wallVelocityY); + + // set physical parameters + myProblem.setGravity(gravite); + + // set the numerical method + myProblem.setNumericalScheme(upwind, Implicit); + + // name file save + string fileName = "2DInclinedSedimentation"; + + // parameters calculation + unsigned MaxNbOfTimeStep = 3 ; + int freqSave = 1; + double cfl = 0.1; + double maxTime = 5; + double precision = 1e-6; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + myProblem.saveVelocity(); + myProblem.displayConditionNumber(); + myProblem.setSaveFileFormat(CSV); + + // evolution + myProblem.initialize(); + + bool ok = myProblem.run(); + if (ok) + cout << "Simulation "< boundaryFields; + limitOutlet.bcType=Outlet; + limitOutlet.p = 80e5; + boundaryFields["Outlet"] = limitOutlet; + + limitWall.bcType=Wall; + limitWall.v_x = vector(2,0); + boundaryFields["Wall"]= limitWall; + IsothermalTwoFluid myProblem(around155bars600K,spaceDim); + // Prepare for the initial condition + int nVar = myProblem.getNumberOfVariables(); + Vector VV_Constant(nVar); + VV_Constant(0) = 0.; + VV_Constant(1) = 155e5; + VV_Constant(2) = 0; + VV_Constant(3) = 0; + + //Initial field creation + cout << "Building initial data" << endl; + myProblem.setInitialFieldConstant(M,VV_Constant); + + //set the boundary conditions + myProblem.setBoundaryFields(boundaryFields); + + //set physical parameters +// myProblem.setSatPressure( Psat, dHsatl_over_dp); +// myProblem.setLatentHeat(latentHeat); + + // set the numerical method + myProblem.setNumericalScheme(upwind, Explicit); + myProblem.setEntropicCorrection(true); + + // name file save + string fileName = "1DDepressurisation"; + + // parameters calculation + unsigned MaxNbOfTimeStep = 3; + int freqSave = 1; + double cfl = 0.95; + double maxTime = 5; + double precision = 1e-6; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + bool ok; + + // evolution + myProblem.initialize(); + + ok = myProblem.run(); + if (ok) + cout << "Simulation "< boundaryFields; + + limitNeumann.p = 155e5; + limitNeumann.alpha = 0; + limitNeumann.v_x = vector(2,0); + limitNeumann.v_y = vector(2,0); + limitNeumann.v_z = vector(2,0); + boundaryFields["Neumann"] = limitNeumann; + + IsothermalTwoFluid myProblem(around155bars600K,spaceDim); + int nbPhase = myProblem.getNumberOfPhases(); + int nVar = myProblem.getNumberOfVariables(); + Field VV("Primitive", CELLS, M, nVar); + + // Prepare for the initial condition + Vector VV_Left(nVar),VV_Right(nVar); + double discontinuity = (xinf+xsup)/2.; + // two vectors + VV_Left(0) = 0.5; VV_Right(0) = 0.2; + VV_Left(1) = 155e5; VV_Right(1) = 155e5; + for (int idim=0; idim wallVelocityX(2,0); + + // physical constants + vector gravite(spaceDim,0.) ; + gravite[0]=-10; + + IsothermalTwoFluid myProblem(around1bar300K,spaceDim); + int nVar = myProblem.getNumberOfVariables(); + + // Prepare for the initial condition + vector VV_Constant(nVar,0.); + // constant vector + VV_Constant[0] = 0.5; + VV_Constant[1] = 1e5; + VV_Constant[2] = 0; + VV_Constant[3] = 0; + + //Initial field creation + cout << "Building initial data " << endl; + myProblem.setInitialFieldConstant(spaceDim,VV_Constant,xinf,xsup,nx,"wall","wall"); + myProblem.setWallBoundaryCondition("wall",wallVelocityX); + + + // physical parameters + myProblem.setGravity(gravite); + + // set the numerical method + myProblem.setNumericalScheme(upwind, Implicit); + myProblem.setEntropicCorrection(true); + + // name file save + string fileName = "1DSedimentation"; + + // parameters calculation + unsigned MaxNbOfTimeStep = 3; + int freqSave = 1; + double cfl = 1; + double maxTime = 5; + double precision = 1e-6; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + myProblem.displayConditionNumber(); + myProblem.setSaveFileFormat(CSV); + + // evolution + myProblem.initialize(); + + bool ok = myProblem.run(); + if (ok) + cout << "Simulation "< wallVelocityX(2,0); + vector wallVelocityY(2,0); + + // physical constants + vector gravite(spaceDim,0.) ; + gravite[1]=-7; + gravite[0]=7; + + IsothermalTwoFluid myProblem(around1bar300K,spaceDim); + int nbPhase = myProblem.getNumberOfPhases(); + int nVar = myProblem.getNumberOfVariables(); + // Prepare for the initial condition + Vector VV_Constant(nVar); + // constant vector + VV_Constant(0) = 0.5; + VV_Constant(1) = 1e5; + VV_Constant(2) = 0; + VV_Constant(3) = 0; + VV_Constant(4) = 0; + VV_Constant(5) = 0; + + //Initial field creation + cout << "Building initial data" << endl; + myProblem.setInitialFieldConstant(M,VV_Constant); + + //set the boundary conditions + myProblem.setWallBoundaryCondition("Wall",wallVelocityX,wallVelocityY); + + // set physical parameters + myProblem.setGravity(gravite); + + // set the numerical method + myProblem.setNumericalScheme(upwind, Explicit); + + // name file save + string fileName = "2DInclinedSedimentation"; + + // parameters calculation + unsigned MaxNbOfTimeStep = 3 ; + int freqSave = 1; + double cfl = 0.25; + double maxTime = 5; + double precision = 1e-6; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + myProblem.saveVelocity(); + + // evolution + myProblem.initialize(); + + bool ok = myProblem.run(); + if (ok) + cout << "Simulation "< + +using namespace std; + +int main(int argc, char** argv) +{ + //Preprocessing: mesh and group creation + cout << "Building Cartesian mesh " << endl; + double xinf=0.0; + double xsup=1.0; + double yinf=0.0; + double ysup=1.0; + int nx=50; + int ny=50; + Mesh M(xinf,xsup,nx,yinf,ysup,ny); + double eps=1.E-6; + M.setGroupAtPlan(xsup,0,eps,"Wall"); + M.setGroupAtPlan(xinf,0,eps,"Wall"); + M.setGroupAtPlan(yinf,1,eps,"Wall"); + M.setGroupAtPlan(ysup,1,eps,"inlet"); + int spaceDim = M.getSpaceDimension(); + + // set the limit field for each boundary + vector wallVelocityX(2,0); + vector wallVelocityY(2,0); + double inletAlpha=1; + double outletPressure=1e5; + + // physical constants + vector gravite(spaceDim,0.) ; + gravite[1]=-10; + gravite[0]=0; + + IsothermalTwoFluid myProblem(around1bar300K,spaceDim); + int nbPhase = myProblem.getNumberOfPhases(); + int nVar = myProblem.getNumberOfVariables(); + // Prepare for the initial condition + Vector VV_Constant(nVar); + // constant vector + VV_Constant(0) = 0.; + VV_Constant(1) = 1e5; + VV_Constant(2) = 0; + VV_Constant(3) = 0; + + //Initial field creation + cout << "Building initial data" << endl; + myProblem.setInitialFieldConstant(M,VV_Constant); + + //set the boundary conditions + myProblem.setWallBoundaryCondition("Wall",wallVelocityX,wallVelocityY); + myProblem.setInletPressureBoundaryCondition("inlet", inletAlpha, outletPressure); + + // set physical parameters + myProblem.setGravity(gravite); + + // set the numerical method + myProblem.setNumericalScheme(upwind, Explicit); + + // name file save + string fileName = "2DInclinedSedimentation"; + + // parameters calculation + unsigned MaxNbOfTimeStep = 3 ; + int freqSave = 1; + double cfl = 0.1; + double maxTime = 5; + double precision = 1e-6; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + myProblem.saveVelocity(); + + // evolution + myProblem.initialize(); + + bool ok = myProblem.run(); + if (ok) + cout << "Simulation "<(1,xsup)); + + // set the numerical method + myProblem.setNumericalScheme(upwind, Explicit); + myProblem.setEntropicCorrection(true); + + // name file save + string fileName = "1DDepressurisation"; + + // parameters calculation + unsigned MaxNbOfTimeStep = 3; + int freqSave = 1; + double cfl = 0.95; + double maxTime = 5; + double precision = 1e-8; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + bool ok; + + // evolution + myProblem.initialize(); + + ok = myProblem.run(); + if (ok) + cout << "Simulation "< boundaryFields; + + limitInlet.T =573.; + limitInlet.bcType=Inlet; + limitInlet.v_x = vector(1,5); + boundaryFields["Inlet"] = limitInlet; + + limitOutlet.bcType=Outlet; + limitOutlet.p = 155e5; + boundaryFields["Outlet"] = limitOutlet; + + SinglePhase myProblem(Liquid,around155bars600K,spaceDim); + int nbPhase = myProblem.getNumberOfPhases(); + int nVar = myProblem.getNumberOfVariables(); + Field VV("Primitive", CELLS, M, nVar);//Field of primitive unknowns + + // Prepare for the initial condition + Vector VV_Constant(nVar); + VV_Constant(0) = 155e5;//pression initiale + VV_Constant(1) = 5;//vitesse initiale + VV_Constant(2) = 573;//temperature initiale + + cout << "Number of Phases = " << nbPhase << endl; + cout << "Construction de la condition initiale ... " << endl; + //set the initial field + myProblem.setInitialFieldConstant(M,VV_Constant); + + //set the boundary conditions + myProblem.setBoundaryFields(boundaryFields); + + //Physical parameters + double heatPower=1e8; + myProblem.setHeatSource(heatPower); + // set the numerical method + myProblem.setNumericalScheme(upwind, Explicit); + + // name file save + string fileName = "1DHeatedChannel"; + + // parameters calculation + unsigned MaxNbOfTimeStep =3; + int freqSave = 1; + double cfl = 0.95; + double maxTime = 5; + double precision = 1e-7; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + bool ok; + + // evolution + myProblem.initialize(); + + ok = myProblem.run(); + if (ok) + cout << "Simulation "< (xsup-xinf)/3 && x< 2*(xsup-xinf)/3) + porosityField[i]=0.5; + else + porosityField[i]=1; + } + porosityField.writeVTK("PorosityField",true); + + + SinglePhase myProblem(Liquid,around155bars600K,spaceDim); + int nVar = myProblem.getNumberOfVariables(); + + // Prepare for the initial condition + vector VV_Constant(nVar); + // constant vector + VV_Constant[0] = initialPressure; + VV_Constant[1] = initialVelocityX; + VV_Constant[2] = initialTemperature; + + cout << "Building initial data " << endl; + + // generate initial condition + myProblem.setInitialFieldConstant( spaceDim, VV_Constant, xinf, xsup, nx,"Inlet","Outlet"); + + //set the boundary conditions + myProblem.setInletBoundaryCondition("Inlet",initialTemperature,initialVelocityX); + myProblem.setOutletBoundaryCondition("Outlet",initialPressure,vector(1,xsup)); + // physical parameters + myProblem.setPorosityField(porosityField); + + // set the numerical method + myProblem.setNumericalScheme(upwind, Explicit); + myProblem.setWellBalancedCorrection(true); + myProblem.setNonLinearFormulation(VFFC) ; + + // name file save + string fileName = "1DPorosityJumpUpwindWB"; + + + /* set numerical parameters */ + unsigned MaxNbOfTimeStep =3; + int freqSave = 1; + double cfl = 0.95; + double maxTime = 5; + double precision = 1e-5; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + bool ok; + + // evolution + myProblem.initialize(); + + ok = myProblem.run(); + if (ok) + cout << "Simulation "< viscosite(1), conductivite(1); + viscosite[0]= 8.85e-5; + conductivite[0]=1000;//transfert de chaleur du à l'ébullition en paroi. + vector gravite(spaceDim,0.) ; + gravite[1]=-10; + gravite[0]=0; + + // set the limit field for each boundary + LimitField limitColdWall, limitHotWall; + map boundaryFields; + limitColdWall.bcType=Wall; + limitColdWall.T = 590;//Temperature de la parois froide + limitColdWall.v_x = vector(1,0); + limitColdWall.v_y = vector(1,0); + boundaryFields["coldWall"]= limitColdWall; + + limitHotWall.bcType=Wall; + limitHotWall.T = 560;//Temperature des parois chauffantes + limitHotWall.v_x = vector(1,0); + limitHotWall.v_y = vector(1,0); + boundaryFields["hotWall"]= limitHotWall; + + SinglePhase myProblem(Liquid,around155bars600K,spaceDim); + int nVar = myProblem.getNumberOfVariables(); + + //Initial field creation + cout << "Building initial data" << endl; + /* First case constant initial data */ + Vector VV_Constant(nVar); + // constant vector + VV_Constant(0) = 155e5; + VV_Constant(1) = 0; + VV_Constant(2) = 0; + VV_Constant(3) = 573; + + myProblem.setInitialFieldConstant(M,VV_Constant); + + //set the boundary conditions + myProblem.setBoundaryFields(boundaryFields); + + // physical parameters + myProblem.setViscosity(viscosite); + myProblem.setConductivity(conductivite); + myProblem.setGravity(gravite); + + // set the numerical method + myProblem.setNumericalScheme(upwind, Implicit); + + // set the Petsc resolution + myProblem.setLinearSolver(GMRES,LU,false); + + // name result file + string fileName = "2DHeatDrivenCavity"; + + // parameters calculation + unsigned MaxNbOfTimeStep = 3; + int freqSave = 1; + double cfl = 10; + double maxTime = 50; + double precision = 1e-6; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + myProblem.setNewtonSolver(precision,50); + myProblem.saveVelocity(); + + // evolution + myProblem.initialize(); + + bool ok = myProblem.run(); + if (ok) + cout << "Simulation "< viscosite(1), conductivite(1); + viscosite[0]= 8.85e-5; + conductivite[0]=1000;//transfert de chaleur du à l'ébullition en paroi. + vector gravite(spaceDim,0.) ; + gravite[1]=-10; + gravite[0]=0; + + // set the limit field for each boundary + LimitField limitColdWall, limitHotWall; + map boundaryFields; + limitColdWall.bcType=Wall; + limitColdWall.T = 590;//Temperature de la parois froide + limitColdWall.v_x = vector(1,0); + limitColdWall.v_y = vector(1,0); + boundaryFields["coldWall"]= limitColdWall; + + limitHotWall.bcType=Wall; + limitHotWall.T = 560;//Temperature des parois chauffantes + limitHotWall.v_x = vector(1,0); + limitHotWall.v_y = vector(1,0); + boundaryFields["hotWall"]= limitHotWall; + + SinglePhase myProblem(Liquid,around155bars600K,spaceDim); + int nVar = myProblem.getNumberOfVariables(); + + //Initial field creation + cout << "Construction de la condition initiale" << endl; + /* First case constant initial data */ + Vector VV_Constant(nVar); + // constant vector + VV_Constant(0) = 155e5; + VV_Constant(1) = 0; + VV_Constant(2) = 0; + VV_Constant(3) = 573; + + myProblem.setInitialFieldConstant(M,VV_Constant); + + //set the boundary conditions + myProblem.setBoundaryFields(boundaryFields); + + // physical parameters + myProblem.setViscosity(viscosite); + myProblem.setConductivity(conductivite); + myProblem.setGravity(gravite); + + // set the numerical method + myProblem.setNumericalScheme(upwind, Implicit); + + // set the Petsc resolution + myProblem.setLinearSolver(GMRES,ILU,true); + + // name result file + string fileName = "2DHeatDrivenCavity_unstructured"; + + // parameters calculation + unsigned MaxNbOfTimeStep = 3; + int freqSave = 1; + double cfl = 1; + double maxTime = 50; + double precision = 1e-7; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + myProblem.setNewtonSolver(precision,50); + myProblem.saveVelocity(); + + // evolution + myProblem.initialize(); + bool ok = myProblem.run(); + if (ok) + cout << "Simulation "< + +using namespace std; + +int main(int argc, char** argv) +{ + int spaceDim = 2; + + // Prepare for the mesh + double xinf = 0 ; + double xsup=3.0; + double yinf=0.0; + double ysup=5.0; + int nx=10; + int ny=10; + + // set the limit field for each boundary + double wallVelocityX=0; + double wallVelocityY=0; + double wallTemperature=573; + double inletVelocityX=0; + double inletVelocityY=0.5; + double inletTemperature=563; + double outletPressure=155e5; + + // physical constants + vector gravite (spaceDim); + + gravite[1]=-7; + gravite[0]=7; + + double heatPower=1e8; + + SinglePhase myProblem(Liquid,around155bars600K,spaceDim); + int nVar =myProblem.getNumberOfVariables(); + + // Prepare for the initial condition + vector VV_Constant (nVar); + + // constant vector + VV_Constant[0] = outletPressure ; + VV_Constant[1] = inletVelocityX; + VV_Constant[2] = inletVelocityY; + VV_Constant[3] = inletTemperature ; + + //Initial field creation + cout<<"Building initial data"<pressure_reference_point(2); + pressure_reference_point[0]=xsup; + pressure_reference_point[1]=ysup; + myProblem.setOutletBoundaryCondition("outlet", outletPressure,pressure_reference_point); + myProblem.setInletBoundaryCondition("inlet", inletTemperature, inletVelocityX, inletVelocityY); + myProblem.setWallBoundaryCondition("wall", wallTemperature, wallVelocityX, wallVelocityY); + + // set physical parameters + myProblem.setHeatSource(heatPower); + myProblem.setGravity(gravite); + + // set the numerical method + myProblem.setNumericalScheme(staggered, Implicit); + myProblem.setNonLinearFormulation(VFFC); + + // name file save + string fileName = "2DInclinedHeatedChannel"; + + /* set numerical parameters */ + unsigned MaxNbOfTimeStep =3; + int freqSave = 1; + double cfl = 0.95; + double maxTime = 5; + double precision = 1e-5; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + myProblem.usePrimitiveVarsInNewton(true); + bool ok; + + // evolution + myProblem.initialize(); + + ok = myProblem.run(); + if (ok) + cout << "Simulation "< viscosite(1) ; + viscosite[0]= 0.025; + + // set the limit field for each boundary + double fixedWallVelocityX=0; + double fixedWallVelocityY=0; + double fixedWallTemperature=273; + + double movingWallVelocityX=1; + double movingWallVelocityY=0; + double movingWallTemperature=273; + + + SinglePhase myProblem(Gas,around1bar300K,spaceDim); + // Prepare for the initial condition + int nVar = myProblem.getNumberOfVariables(); + vector VV_Constant(nVar); + // constant vector + VV_Constant[0] = 1e5; + VV_Constant[1] = 0; + VV_Constant[2] = 0; + VV_Constant[3] = 273; + + // name output file + string fileName = "2DLidDrivenCavityStructuredCentered1bar"; + + //Initial field creation + cout << "Building initial data" << endl; + myProblem.setInitialFieldConstant(spaceDim,VV_Constant,xinf,xsup,nx,"fixedWall","fixedWall",yinf,ysup,ny,"fixedWall","movingWall"); + + //set the boundary conditions + myProblem.setWallBoundaryCondition("fixedWall", fixedWallTemperature, fixedWallVelocityX, fixedWallVelocityY); + myProblem.setWallBoundaryCondition("movingWall", movingWallTemperature, movingWallVelocityX, movingWallVelocityY); + + // physical parameters + myProblem.setViscosity(viscosite); + + // set the numerical method + myProblem.setNumericalScheme(staggered, Implicit); + + // set the Petsc resolution + myProblem.setLinearSolver(GMRES,LU,true); + + //Numerical parameters + unsigned MaxNbOfTimeStep = 3 ; + int freqSave = 1; + double cfl = 1; + double maxTime = 100000; + double precision = 1e-9; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + myProblem.setNewtonSolver(precision*1e8,20); + myProblem.saveVelocity(); + + // evolution + myProblem.initialize(); + + bool ok = myProblem.run(); + if (ok) + cout << "Simulation "< viscosite(1) ; + viscosite[0]= 0.025; + + /* set the limit field for each boundary*/ + LimitField limitWall; + map boundaryFields; + limitWall.bcType=Wall; + limitWall.T = 273; + limitWall.p = 1e5; + limitWall.v_x = vector(1,0); + limitWall.v_y = vector(1,0); + limitWall.v_z = vector(1,0); + boundaryFields["wall"]= limitWall; + + LimitField limitMovingWall; + limitMovingWall.bcType=Wall; + limitMovingWall.T = 273; + limitMovingWall.p = 1e5; + limitMovingWall.v_x = vector(1,1); + limitMovingWall.v_y = vector(1,0); + limitMovingWall.v_z = vector(1,0); + boundaryFields["MovingWall"]= limitMovingWall; + + + SinglePhase myProblem(Liquid,around1bar300K,spaceDim); + int nbPhase = myProblem.getNumberOfPhases(); + // Prepare for the initial condition + int nVar = myProblem.getNumberOfVariables(); + Vector VV_Constant(nVar); + // constant vector + VV_Constant(0) = 1e5; + VV_Constant(1) = 0; + VV_Constant(2) = 0; + VV_Constant(3) = 273; + + //Initial field creation + cout << "Setting initial data " << endl; + myProblem.setInitialFieldConstant(M,VV_Constant); + + //set the boundary conditions + myProblem.setBoundaryFields(boundaryFields); + + // physical parameters + myProblem.setViscosity(viscosite); + + // set the numerical method + myProblem.setNumericalScheme(upwind, Implicit); + + // set the Petsc resolution + myProblem.setLinearSolver(GMRES,ILU,true); + + // name file save + string fileName = "2DLidDrivenCavity_unstructured"; + + // parameters calculation + unsigned MaxNbOfTimeStep = 3 ; + int freqSave = 1; + double cfl = 5; + double maxTime = 5; + double precision = 1e-8; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + myProblem.setNewtonSolver(precision,20); + myProblem.saveVelocity(); + + // evolution + myProblem.initialize(); + + bool ok = myProblem.run(); + if (ok) + cout << "Simulation "<Vout(nVar), Vin(nVar); + Vin[0]=1.1; + Vin[1]=0; + Vin[2]=0; + Vin[3]=300; + Vout[0]=1; + Vout[1]=0; + Vout[2]=0; + Vout[3]=300; + + for(int i=0;i viscosite(1), conductivite(1); + viscosite[0]= 8.85e-5; + conductivite[0]=1000;//transfert de chaleur du à l'ébullition en paroi. + + // set the limit field for each boundary + LimitField limitWall; + map boundaryFields; + limitWall.bcType=Wall; + limitWall.T = 623;//Temperature des parois chauffantes + limitWall.p = 155e5; + limitWall.v_x = vector(1,0); + limitWall.v_y = vector(1,0); + boundaryFields["wall"]= limitWall; + + LimitField limitInlet; + limitInlet.bcType=Inlet; + limitInlet.T = 573;//Temperature d'entree du fluide + limitInlet.v_x = vector(1,0); + limitInlet.v_y = vector(1,5);//Vitesse d'entree du fluide + boundaryFields["Inlet"]= limitInlet; + + LimitField limitOutlet; + limitOutlet.bcType=Outlet; + limitOutlet.p = 155e5; + boundaryFields["Outlet"]= limitOutlet; + + LimitField limitNeumann; + limitNeumann.bcType=Neumann; + boundaryFields["Neumann"] = limitNeumann; + + SinglePhase myProblem(Liquid,around155bars600K,spaceDim); + int nVar = myProblem.getNumberOfVariables(); + + //Initial field creation + cout << "Construction de la condition initiale" << endl; + /* First case constant initial data */ + Vector VV_Constant(nVar); + // constant vector + VV_Constant(0) = 155e5; + VV_Constant(1) = 0; + VV_Constant(2) = 5; + VV_Constant(3) = 573; + /* Second case restart from a previous calculation */ +/* + string inputfile = "SinglePhasePrim_2DChannelWithViscosityWithConduction";//nom du fichier (sans le .med) + int iter=50400;//numero du pas de temps a recuperer dans le fichier + Field VV1(inputfile,CELLS,"P,vx,vy,T",iter,0);//Chargement des valeurs du champ + for(int i=0;i boundaryFields; + limitWall.bcType=Wall; + limitWall.T = 623;//Temperature des parois chauffantes + limitWall.p = 155e5; + limitWall.v_x = vector(1,0); + limitWall.v_y = vector(1,0); + boundaryFields["Wall"]= limitWall; + + LimitField limitInlet; + limitInlet.bcType=Inlet; + limitInlet.T = 573;//Temperature d'entree du fluide + limitInlet.v_x = vector(1,0); + limitInlet.v_y = vector(1,2.5);//Vitesse d'entree du fluide + boundaryFields["Inlet"]= limitInlet; + + LimitField limitOutlet; + limitOutlet.bcType=Outlet; + limitOutlet.p = 155e5; + boundaryFields["Outlet"]= limitOutlet; + + SinglePhase myProblem(Liquid,around155bars600K,spaceDim); + // Prepare for the initial condition + int nVar = myProblem.getNumberOfVariables(); + Vector VV_Constant(nVar); + // constant vector + VV_Constant(0) = 155e5; + VV_Constant(1) = 0; + VV_Constant(2) = 2.5; + VV_Constant(3) = 573; + + //Initial field creation + cout << "Building initial data" << endl; + myProblem.setInitialFieldConstant(M,VV_Constant); + + // physical constants + vector viscosite(1), conductivite(1); + viscosite[0]= 8.85e-5; + conductivite[0]=1000;//transfert de chaleur du à l'ébullition en paroi. + + //Set boundary values + myProblem.setBoundaryFields(boundaryFields); + + // set the numerical method + myProblem.setNumericalScheme(upwind, Explicit); + + // name result file + string fileName = "2DWallHeatedChannel_ChangeSect"; + + // parameters calculation + unsigned MaxNbOfTimeStep = 3; + int freqSave = 1; + double cfl =.5; + double maxTime = 500; + double precision = 1e-6; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + myProblem.setNewtonSolver(precision,50); + myProblem.saveVelocity(); + + // evolution + myProblem.initialize(); + bool ok = myProblem.run(); + if (ok) + cout << "Simulation "< gravite(spaceDim,0.) ; + gravite[2]=-10; + gravite[1]=0; + gravite[0]=0; + vector viscosite(1), conductivite(1); + viscosite[0]= 8.85e-5; + conductivite[0]=1000;//nucleate boiling heat transfert coefficient + + SinglePhase myProblem(Liquid,around155bars600K,spaceDim); + int nVar = myProblem.getNumberOfVariables(); + + //Initial field creation + cout << "Construction de la condition initiale" << endl; + vector VV_Constant(nVar); + // constant vector + VV_Constant[0] = 155e5; + VV_Constant[1] = 0; + VV_Constant[2] = 0; + VV_Constant[3] = 0; + VV_Constant[4] = 573; + myProblem.setInitialFieldConstant(spaceDim,VV_Constant,xinf,xsup,nx,"hotWall","hotWall", + yinf,ysup,ny,"hotWall","hotWall", + zinf,zsup,nz,"hotWall","coldWall"); + + //set the boundary conditions + myProblem.setWallBoundaryCondition("coldWall", coldWallTemperature, coldWallVelocityX, coldWallVelocityY, coldWallVelocityZ); + myProblem.setWallBoundaryCondition("hotWall", hotWallTemperature, hotWallVelocityX, hotWallVelocityY, hotWallVelocityZ); + + + // physical parameters + myProblem.setViscosity(viscosite); + myProblem.setConductivity(conductivite); + myProblem.setGravity(gravite); + + // set the numerical method + myProblem.setNumericalScheme(upwind, Implicit); + + // set the Petsc resolution + myProblem.setLinearSolver(GMRES,ILU,false); + + // name result file + string fileName = "3DHeatDrivenCavity"; + + // parameters calculation + unsigned MaxNbOfTimeStep = 3; + int freqSave = 1; + double cfl = 10; + double maxTime = 50; + double precision = 1e-6; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + myProblem.setNewtonSolver(precision,50); + myProblem.saveVelocity(); + + // evolution + myProblem.initialize(); + bool ok = myProblem.run(); + if (ok) + cout << "Simulation "< gravite(1,-10); + myProblem.setGravity(gravite); + + //Set section field + myProblem.setSectionField(Sections); + // Prepare the initial condition + Vector VV_Constant(nVar); + VV_Constant(0) = 155e5; + VV_Constant(1) = 5; + VV_Constant(2) = 573; + + cout << "Building initial data " << endl; + + // generate initial condition + myProblem.setInitialFieldConstant(M,VV_Constant); + + //set the boundary conditions + myProblem.setInletBoundaryCondition("Inlet",inletTemperature,inletVelocityX); + myProblem.setOutletBoundaryCondition("Outlet", outletPressure); + + // set the numerical method + myProblem.setNumericalScheme(upwind, Explicit); + myProblem.setWellBalancedCorrection(true); + + // name file save + string fileName = "2BranchesHeatedChannels"; + + // parameters calculation + unsigned MaxNbOfTimeStep =3; + int freqSave = 1; + double cfl = 0.5; + double maxTime = 5; + double precision = 1e-6; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + bool ok; + + // evolution + myProblem.initialize(); + ok = myProblem.run(); + if (ok) + cout << "Simulation "< + +double pi = M_PI; +using namespace std; + +int main(int argc, char** argv) +{ + int spaceDim = 2; + + /* Mesh data */ + double xinf=0.0; + double xsup=1.0; + double yinf=0.0; + double ysup=1.0; + int nx=20; + int ny=20; + + /* Mesh construction */ + Mesh M(xinf,xsup,nx,yinf,ysup,ny,0); //Regular triangular mesh + + /* set the limit field for each boundary */ + double eps=1e-6; + M.setGroupAtPlan(xsup,0,eps,"Bord1"); + M.setGroupAtPlan(xinf,0,eps,"Bord2"); + M.setGroupAtPlan(ysup,1,eps,"Bord3"); + M.setGroupAtPlan(yinf,1,eps,"Bord4"); + + /* set the boundary values for each boundary */ + double T1=0; + double T2=0; + double T3=0; + double T4=0; + + cout<< "Built a regular triangular 2D mesh from a square mesh with "<< nx<<"x" < + +double pi = M_PI; +using namespace std; + +int main(int argc, char** argv) +{ + int spaceDim = 2; + + /* Mesh data */ + double xinf=0.0; + double xsup=1.0; + double yinf=0.0; + double ysup=1.0; + int nx=20; + int ny=20; + + /* Mesh construction */ + Mesh M(xinf,xsup,nx,yinf,ysup,ny,0); //Regular triangular mesh + + /* set the limit field for each boundary */ + double eps=1e-6; + M.setGroupAtPlan(xsup,0,eps,"Bord1"); + M.setGroupAtPlan(xinf,0,eps,"Bord2"); + M.setGroupAtPlan(ysup,1,eps,"Bord3"); + M.setGroupAtPlan(yinf,1,eps,"Bord4"); + + /* set the boundary values for each boundary */ + double T1=0; + double T2=0; + double T3=0; + double T4=0; + + cout<< "Built a regular triangular 2D mesh from a square mesh with "<< nx<<"x" < + +double pi = M_PI; +using namespace std; + +int main(int argc, char** argv) +{ + int spaceDim = 2; + + /* Square mesh and groups loading */ + string filename="resources/squareWithTriangles.med"; + cout << "Loading mesh and groups from file" << filename< + +double pi = M_PI; +using namespace std; + +int main(int argc, char** argv) +{ + int spaceDim = 2; + + /* Mesh data */ + double xinf=0.0; + double xsup=1.0; + double yinf=0.0; + double ysup=1.0; + int nx=30; + int ny=30; + + /* Mesh construction */ + Mesh M(xinf,xsup,nx,yinf,ysup,ny); //Regular square mesh + + /* set the limit field for each boundary */ + double eps=1e-6; + M.setGroupAtPlan(xsup,0,eps,"Bord1"); + M.setGroupAtPlan(xinf,0,eps,"Bord2"); + M.setGroupAtPlan(ysup,1,eps,"Bord3"); + M.setGroupAtPlan(yinf,1,eps,"Bord4"); + + /* set the boundary values for each boundary */ + double T1=0; + double T2=0; + double T3=0; + double T4=0; + + cout<< "Built a regular square 2D mesh with "<< nx<<"x" < + +double pi = M_PI; +using namespace std; + +int main(int argc, char** argv) +{ + int spaceDim = 2; + + /* Mesh data */ + double xinf=0.0; + double xsup=1.0; + double yinf=0.0; + double ysup=1.0; + int nx=20; + int ny=20; + + /* Mesh construction */ + Mesh M(xinf,xsup,nx,yinf,ysup,ny,0); //Regular triangular mesh + + /* set the limit field for each boundary */ + double eps=1e-6; + M.setGroupAtPlan(xsup,0,eps,"Bord1"); + M.setGroupAtPlan(xinf,0,eps,"Bord2"); + M.setGroupAtPlan(ysup,1,eps,"Bord3"); + M.setGroupAtPlan(yinf,1,eps,"Bord4"); + + /* set the boundary values for each boundary */ + double T1=0; + double T2=0; + double T3=0; + double T4=0; + + cout<< "Building of a regular triangular 2D mesh from a square mesh with "<< nx<<"x" < + +double pi = M_PI; +using namespace std; + +int main(int argc, char** argv) +{ + int spaceDim = 2; + + /* Mesh data */ + double xinf=0.0; + double xsup=1.0; + double yinf=0.0; + double ysup=1.0; + int nx=20; + int ny=20; + + /* Mesh construction */ + Mesh M(xinf,xsup,nx,yinf,ysup,ny,0); //Regular triangular mesh + + /* set the limit field for each boundary */ + double eps=1e-6; + M.setGroupAtPlan(xsup,0,eps,"Bord1"); + M.setGroupAtPlan(xinf,0,eps,"Bord2"); + M.setGroupAtPlan(ysup,1,eps,"Bord3"); + M.setGroupAtPlan(yinf,1,eps,"Bord4"); + + /* set the boundary values for each boundary */ + double T1=0; + double T2=0; + double T3=0; + double T4=0; + + cout<< "Building of a regular triangular 2D mesh from a square mesh with "<< nx<<"x" < + +double pi = M_PI; +using namespace std; + +int main(int argc, char** argv) +{ + int spaceDim = 3; + + /* Mesh data */ + double xinf=0.0; + double xsup=1.0; + double yinf=0.0; + double ysup=1.0; + double zinf=0.0; + double zsup=1.0; + int nx=2; + int ny=2; + int nz=2; + + /* Mesh construction : splitting polity to 0 yield all nodes considered boundary nodes */ + Mesh M(xinf,xsup,nx,yinf,ysup,ny,zinf,zsup,nz,0); //Regular tetrahadral mesh + + /* set the limit field for each boundary */ + double eps=1e-6; + M.setGroupAtPlan(xsup,0,eps,"Bord1"); + M.setGroupAtPlan(xinf,0,eps,"Bord2"); + M.setGroupAtPlan(ysup,1,eps,"Bord3"); + M.setGroupAtPlan(yinf,1,eps,"Bord4"); + M.setGroupAtPlan(zsup,2,eps,"Bord5"); + M.setGroupAtPlan(zinf,2,eps,"Bord6"); + + /* set the boundary values for each boundary */ + double T1=0; + double T2=0; + double T3=0; + double T4=0; + double T5=0; + double T6=0; + + cout<< "Built a regular tetrahedral 3D mesh from a cube mesh with "<< nx<<"x" < + +double pi = M_PI; +using namespace std; + +int main(int argc, char** argv) +{ + int spaceDim = 3; + + /* Mesh data */ + double xinf=0.0; + double xsup=1.0; + double yinf=0.0; + double ysup=1.0; + double zinf=0.0; + double zsup=1.0; + int nx=2; + int ny=2; + int nz=2; + + /* Mesh construction : splitting polity to 0 yield all nodes considered boundary nodes */ + Mesh M(xinf,xsup,nx,yinf,ysup,ny,zinf,zsup,nz,0); //Regular tetrahadral mesh + + /* set the limit field for each boundary */ + double eps=1e-6; + M.setGroupAtPlan(xsup,0,eps,"Bord1"); + M.setGroupAtPlan(xinf,0,eps,"Bord2"); + M.setGroupAtPlan(ysup,1,eps,"Bord3"); + M.setGroupAtPlan(yinf,1,eps,"Bord4"); + M.setGroupAtPlan(zsup,2,eps,"Bord5"); + M.setGroupAtPlan(zinf,2,eps,"Bord6"); + + /* set the boundary values for each boundary */ + double T1=0; + double T2=0; + double T3=0; + double T4=0; + double T5=0; + double T6=0; + + cout<< "Built a regular tetrahedral 3D mesh from a cube mesh with "<< nx<<"x" < boundaryFields; + + LimitFieldTransport limitNeumann; + limitNeumann.bcType=NeumannTransport; + boundaryFields["Neumann"] = limitNeumann; + + LimitFieldTransport limitInlet; + limitInlet.bcType=InletTransport; + limitInlet.h =1.3e6;//Inlet water enthalpy + boundaryFields["Inlet"] = limitInlet; + + //Set the fluid transport velocity + vector transportVelocity(1,5);//fluid velocity vector + + TransportEquation myProblem(LiquidPhase,around155bars600KTransport,transportVelocity); + Field VV("Enthalpy", CELLS, M, 1); + + //Set rod temperature and heat exchamge coefficient + double rodTemp=623;//Rod clad temperature + double heatTransfertCoeff=1000;//fluid/solid exchange coefficient + myProblem.setRodTemperature(rodTemp); + myProblem.setHeatTransfertCoeff(heatTransfertCoeff); + + //Initial field creation + Vector VV_Constant(1);//initial enthalpy + VV_Constant(0) = 1.3e6; + + cout << "Building the initial data " << endl; + + // generate initial condition + myProblem.setInitialFieldConstant(M,VV_Constant); + + //set the boundary conditions + myProblem.setBoundaryFields(boundaryFields); + + // set the numerical method + myProblem.setTimeScheme( Explicit); + + // name result file + string fileName = "1DFluidEnthalpy"; + + // parameters calculation + unsigned MaxNbOfTimeStep =3; + int freqSave = 1; + double cfl = 0.95; + double maxTime = 5; + double precision = 1e-6; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + + // set display option to monitor the calculation + bool computation=true; + bool system=true; + myProblem.setVerbose( computation, system); + myProblem.setSaveFileFormat(CSV); + + // evolution + myProblem.initialize(); + bool ok = myProblem.run(); + if (ok) + cout << "Simulation "< + +#include + +using namespace std; + +int main(int argc, char** argv) { + double _Tsat = 656; //saturation temperature used in Dellacherie EOS + StiffenedGasDellacherie fluid1 = StiffenedGasDellacherie(1.43, 0, + 2.030255e6, 1040.14); //stiffened gas law for Gas from S. Dellacherie + StiffenedGasDellacherie fluid2 = StiffenedGasDellacherie(2.35, 1e9, + -1.167056e6, 1816.2); //stiffened gas law for water from S. Dellacherie + + double P = 155e6; + double T = 500; + double h = 0; + + double rho1 = fluid1.getDensity(P, T); + double Tvalid1 = fluid1.getTemperatureFromPressure(P, rho1); + double h1 = fluid1.getEnthalpy(T, rho1); + + cout << endl; + cout << "density fluide 1 = " << rho1 << endl; + cout << "Tvalid1 fluide 1 = " << Tvalid1 << endl; + cout << "h1 fluide 1 = " << h1 << endl; + + return EXIT_SUCCESS; +} diff --git a/CoreFlows/examples/CMakeLists.txt b/CoreFlows/examples/CMakeLists.txt index 6314d27..d96eaff 100755 --- a/CoreFlows/examples/CMakeLists.txt +++ b/CoreFlows/examples/CMakeLists.txt @@ -1,122 +1,38 @@ project(test) -INCLUDE_DIRECTORIES( - ${PETSC_INCLUDES} - ${CDMATH_INCLUDES} - ${CDMATH_INCLUDES}/med # - ${CDMATH_INCLUDES}/medcoupling # - ${CoreFlows_SRC}/inc -) +file(GLOB MESHES_TO_INSTALL resources ) +install(DIRECTORY ${MESHES_TO_INSTALL} DESTINATION share/examples) - -SET(_extra_lib_CoreFlows CoreFlows ${PETSC_LIBRARIES} ${CDMATH_LIBRARIES}) - - -if(CMAKE_COMPILER_IS_GNUCXX) - if (CMAKE_BUILD_TYPE STREQUAL Debug) - include(CodeCoverage) - setup_target_for_coverage(cov ctest coverage) - endif() -endif() - - -file(GLOB NICE_EXAMPLES_TO_INSTALL resources ) -install(DIRECTORY ${NICE_EXAMPLES_TO_INSTALL} DESTINATION share/examples) - -##################################### test generation with ctest - -# this function creates a target and a ctest test -function(CreateTestExec SourceTestFile libList) - message("Setting cpp test ${EXECNAME}") - get_filename_component( FILE_BASENAME ${SourceTestFile} NAME_WE) # /testxxx.c --> testxxx - set( EXECNAME "${FILE_BASENAME}.exe" ) # testxxx --> testxxx.exe - add_executable(${EXECNAME} ${SourceTestFile}) # compilation of the testxxx.exe - set_target_properties(${EXECNAME} PROPERTIES COMPILE_FLAGS "") - target_link_libraries(${EXECNAME} ${libList}) # provide required lib for testxxx.exe - add_test(${FILE_BASENAME} ${EXECNAME} "./${EXECNAME}") # adding a ctest Test -endfunction(CreateTestExec) - -# this function creates a target and a ctest test -# and also create install rules for copying the example -# in the install dir -function(CreateTestExecAndInstall SourceTestFile libList) - message("Setting cpp test ${EXECNAME}") - get_filename_component( FILE_BASENAME ${SourceTestFile} NAME_WE) # /testxxx.c --> testxxx - set( EXECNAME "${FILE_BASENAME}.exe" ) # testxxx --> testxxx.exe - add_executable(${EXECNAME} ${SourceTestFile}) # compilation of the testxxx.exe - set_target_properties(${EXECNAME} PROPERTIES COMPILE_FLAGS "") - target_link_libraries(${EXECNAME} ${libList}) # provide required lib for testxxx.exe - add_test(NAME ${EXECNAME} COMMAND "./${EXECNAME}") # adding a ctest Test - install(TARGETS ${EXECNAME} DESTINATION share/examples) -endfunction(CreateTestExecAndInstall) - - -set( libs_for_tests ${_extra_lib_CoreFlows} ) - -# copy tests resources (med files etc.) into the build directory -file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/resources DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) - -CreateTestExecAndInstall(CoupledTransportDiffusionEquations_1DHeatedChannel.cxx "${libs_for_tests}" ) -CreateTestExecAndInstall(DiffusionEquation_1DHeatedRod.cxx "${libs_for_tests}" ) -CreateTestExecAndInstall(DiffusionEquation_1DHeatedRod_FE.cxx "${libs_for_tests}" ) -CreateTestExecAndInstall(DriftModel_1DBoilingAssembly.cxx "${libs_for_tests}" ) -CreateTestExecAndInstall(DriftModel_1DBoilingChannel.cxx "${libs_for_tests}" ) -CreateTestExecAndInstall(DriftModel_1DChannelGravity.cxx "${libs_for_tests}" ) -CreateTestExecAndInstall(DriftModel_1DDepressurisation.cxx "${libs_for_tests}" ) -CreateTestExecAndInstall(DriftModel_1DPorosityJump.cxx "${libs_for_tests}" ) -CreateTestExecAndInstall(DriftModel_1DPressureLoss.cxx "${libs_for_tests}" ) -CreateTestExecAndInstall(DriftModel_1DRiemannProblem.cxx "${libs_for_tests}" ) -CreateTestExecAndInstall(DriftModel_1DVidangeReservoir.cxx "${libs_for_tests}" ) -CreateTestExecAndInstall(DriftModel_2DInclinedBoilingChannel.cxx "${libs_for_tests}" ) -CreateTestExecAndInstall(DriftModel_2DInclinedChannelGravity.cxx "${libs_for_tests}" ) -CreateTestExecAndInstall(DriftModel_2DInclinedChannelGravityBarriers.cxx "${libs_for_tests}" ) -CreateTestExecAndInstall(DriftModel_3DCanalCloison.cxx "${libs_for_tests}" ) -CreateTestExecAndInstall(FiveEqsTwoFluid_1DBoilingChannel.cxx "${libs_for_tests}" ) -CreateTestExecAndInstall(FiveEqsTwoFluid_1DDepressurisation.cxx "${libs_for_tests}" ) -CreateTestExecAndInstall(FiveEqsTwoFluid_1DRiemannProblem.cxx "${libs_for_tests}" ) -CreateTestExecAndInstall(FiveEqsTwoFluid_2DInclinedBoilingChannel.cxx "${libs_for_tests}" ) -CreateTestExecAndInstall(FiveEqsTwoFluid_2DInclinedSedimentation.cxx "${libs_for_tests}" ) -CreateTestExecAndInstall(IsothermalTwoFluid_1DDepressurisation.cxx "${libs_for_tests}" ) -CreateTestExecAndInstall(IsothermalTwoFluid_1DRiemannProblem.cxx "${libs_for_tests}" ) -#CreateTestExecAndInstall(IsothermalTwoFluid_1DSedimentation.cxx "${libs_for_tests}" ) -CreateTestExecAndInstall(IsothermalTwoFluid_2DInclinedSedimentation.cxx "${libs_for_tests}" ) -CreateTestExecAndInstall(IsothermalTwoFluid_2DVidangeReservoir.cxx "${libs_for_tests}" ) -CreateTestExecAndInstall(SinglePhase_1DDepressurisation.cxx "${libs_for_tests}" ) -CreateTestExecAndInstall(SinglePhase_1DHeatedChannel.cxx "${libs_for_tests}" ) -CreateTestExecAndInstall(SinglePhase_1DPorosityJump.cxx "${libs_for_tests}" ) -CreateTestExecAndInstall(SinglePhase_1DRiemannProblem.cxx "${libs_for_tests}" ) -CreateTestExecAndInstall(SinglePhase_2DHeatDrivenCavity.cxx "${libs_for_tests}" ) -CreateTestExecAndInstall(SinglePhase_2DHeatDrivenCavity_unstructured.cxx "${libs_for_tests}" ) -CreateTestExecAndInstall(SinglePhase_2DHeatedChannelInclined.cxx "${libs_for_tests}" ) -CreateTestExecAndInstall(SinglePhase_2DLidDrivenCavity.cxx "${libs_for_tests}" ) -CreateTestExecAndInstall(SinglePhase_2DLidDrivenCavity_unstructured.cxx "${libs_for_tests}" ) -CreateTestExecAndInstall(SinglePhase_2DSphericalExplosion_unstructured.cxx "${libs_for_tests}" ) -CreateTestExecAndInstall(SinglePhase_3DSphericalExplosion_unstructured.cxx "${libs_for_tests}" ) -CreateTestExecAndInstall(SinglePhase_2DWallHeatedChannel_ChangeSect.cxx "${libs_for_tests}" ) -CreateTestExecAndInstall(SinglePhase_2DWallHeatedChannel.cxx "${libs_for_tests}" ) -CreateTestExecAndInstall(SinglePhase_3DHeatDrivenCavity.cxx "${libs_for_tests}" ) -CreateTestExecAndInstall(SinglePhase_HeatedWire_2Branches.cxx "${libs_for_tests}" ) -CreateTestExecAndInstall(TransportEquation_1DHeatedChannel.cxx "${libs_for_tests}" ) -CreateTestExecAndInstall(StationaryDiffusionEquation_2DEF_StructuredTriangles.cxx "${libs_for_tests}" ) -CreateTestExecAndInstall(StationaryDiffusionEquation_2DEF_StructuredTriangles_Neumann.cxx "${libs_for_tests}" ) -CreateTestExecAndInstall(StationaryDiffusionEquation_2DEF_UnstructuredTriangles.cxx "${libs_for_tests}" ) -CreateTestExecAndInstall(StationaryDiffusionEquation_2DFV_StructuredTriangles.cxx "${libs_for_tests}" ) -CreateTestExecAndInstall(StationaryDiffusionEquation_2DFV_StructuredTriangles_Neumann.cxx "${libs_for_tests}" ) -CreateTestExecAndInstall(StationaryDiffusionEquation_2DFV_StructuredSquares.cxx "${libs_for_tests}" ) -CreateTestExecAndInstall(StationaryDiffusionEquation_3DEF_StructuredTetrahedra.cxx "${libs_for_tests}" ) -CreateTestExecAndInstall(StationaryDiffusionEquation_3DFV_StructuredTetrahedra.cxx "${libs_for_tests}" ) -CreateTestExecAndInstall(testEOS.cxx "${libs_for_tests}" ) - - -#TODO: install for tests and test data +add_subdirectory (C) if (COREFLOWS_WITH_PYTHON ) - add_subdirectory (${CoreFlows_EXAMPLES}/Python) - - file(GLOB PYTHON_EXAMPLES_TO_INSTALL Python ) - install(DIRECTORY ${PYTHON_EXAMPLES_TO_INSTALL} DESTINATION share/examples) + add_subdirectory (Python) endif (COREFLOWS_WITH_PYTHON ) +add_custom_target (tests COMMAND ctest -O testsCoreFlows.log) + +add_custom_target (SinglePhase COMMAND ctest -R SinglePhase)# may be replace ctest -R with ctest -L +add_custom_target (DriftModel COMMAND ctest -R DriftModel) # may be replace ctest -R with ctest -L +add_custom_target (IsothermalTwoFluid COMMAND ctest -R IsothermalTwoFluid)# may be replace ctest -R with ctest -L +add_custom_target ( FiveEqsTwoFluid COMMAND ctest -R FiveEqsTwoFluid)# may be replace ctest -R with ctest -L + +add_custom_target (DiffusionEquation COMMAND ctest -R DiffusionEquation -E StationaryDiffusionEquation)# may be replace ctest -R with ctest -L +add_custom_target (diffusion COMMAND ctest -R DiffusionEquation)# may be replace ctest -R with ctest -L +add_custom_target (TransportEquation COMMAND ctest -R TransportEquation)# may be replace ctest -R with ctest -L +add_custom_target (transport COMMAND ctest -R TransportEquation)# may be replace ctest -R with ctest -L +add_custom_target (StationaryDiffusionEquation COMMAND ctest -R StationaryDiffusionEquation)# may be replace ctest -R with ctest -L + +add_custom_target (convergence COMMAND ctest -R convergence)# may be replace ctest -R with ctest -L + +add_custom_target (fv COMMAND ctest -R FV)# may be replace ctest -R with ctest -L +add_custom_target (FV COMMAND ctest -R FV)# may be replace ctest -R with ctest -L +add_custom_target (fe COMMAND ctest -R FE)# may be replace ctest -R with ctest -L +add_custom_target (FE COMMAND ctest -R FE)# may be replace ctest -R with ctest -L +add_custom_target (1D COMMAND ctest -R 1D)# may be replace ctest -R with ctest -L +add_custom_target (2D COMMAND ctest -R 2D)# may be replace ctest -R with ctest -L +add_custom_target (3D COMMAND ctest -R 3D)# may be replace ctest -R with ctest -L +add_custom_target (Dirichlet COMMAND ctest -R Dirichlet)# may be replace ctest -R with ctest -L +add_custom_target (Neumann COMMAND ctest -R Neumann)# may be replace ctest -R with ctest -L diff --git a/CoreFlows/examples/CoupledTransportDiffusionEquations_1DHeatedChannel.cxx b/CoreFlows/examples/CoupledTransportDiffusionEquations_1DHeatedChannel.cxx deleted file mode 100755 index 03c9ec5..0000000 --- a/CoreFlows/examples/CoupledTransportDiffusionEquations_1DHeatedChannel.cxx +++ /dev/null @@ -1,200 +0,0 @@ -#include "TransportEquation.hxx" -#include "DiffusionEquation.hxx" - -using namespace std; - -#define PI 3.14159265 - -void power_field_CoupledTransportDiffusionTest(Field & Phi){ - double L=4.2; - double lambda=0.2; - double phi=1e5; - double x; - Mesh M = Phi.getMesh(); - int nbCells = M.getNumberOfCells(); - for (int j = 0; j < nbCells; j++) { - x=M.getCell(j).x(); - Phi(j) = phi*cos(PI*(x-L/2)/(L+lambda)); - } -} - -int main(int argc, char** argv) -{ - //Preprocessing: mesh and group creation - double xinf=0.0; - double xsup=4.2; - int nx=100; - double eps=1.E-6; - cout << "Building of the diffusion mesh with "< boundaryFields; - - // Boundary conditions for the solid - LimitField limitNeumann; - limitNeumann.bcType=Neumann; - boundaryFields["Neumann"] = limitNeumann; - - // Boundary conditions for the fluid - LimitField limitInlet; - limitInlet.bcType=Inlet; - limitInlet.h =1.3e6;//Inlet water enthalpy - boundaryFields["Inlet"] = limitInlet; - - //Set the fluid transport velocity - vector transportVelocity(1,5);//Vitesse du fluide - - //Solid parameters - double cp_ur=300;//Uranium specific heat - double rho_ur=10000;//Uranium density - double lambda_ur=5; - - TransportEquation myTransportEquation(Liquid, around155bars600K,transportVelocity); - Field fluidEnthalpy("Enthalpie", CELLS, transportMesh, 1); - bool FECalculation=false; - DiffusionEquation myDiffusionEquation(spaceDim,FECalculation,rho_ur, cp_ur, lambda_ur); - - Field solidTemp("Solid temperature", CELLS, diffusionMesh, 1); - Field fluidTemp("Fluid temperature", CELLS, transportMesh, 1); - - double heatTransfertCoeff=10000;//fluid/solid heat exchange coefficient - myTransportEquation.setHeatTransfertCoeff(heatTransfertCoeff); - myDiffusionEquation.setHeatTransfertCoeff(heatTransfertCoeff); - - //Set heat source in the solid - Field Phi("Heat power field", CELLS, diffusionMesh, 1); - power_field_CoupledTransportDiffusionTest(Phi); - myDiffusionEquation.setHeatPowerField(Phi); - Phi.writeVTK("1DheatPowerField"); - - //Initial field creation - Vector VV_Constant(1); - VV_Constant(0) = 623;//Rod clad temperature nucleaire - - cout << "Construction de la condition initiale " << endl; - // generate initial condition - myDiffusionEquation.setInitialFieldConstant(diffusionMesh,VV_Constant); - - - VV_Constant(0) = 1.3e6; - myTransportEquation.setInitialFieldConstant(transportMesh,VV_Constant); - - //set the boundary conditions - myTransportEquation.setBoundaryFields(boundaryFields);//Neumann and Inlet BC will be used - myDiffusionEquation.setBoundaryFields(boundaryFields);//Only Neumann BC will be used - - // set the numerical method - myDiffusionEquation.setNumericalScheme(upwind, Explicit); - myTransportEquation.setNumericalScheme(upwind, Explicit); - - // name result file - string fluidFileName = "1DFluidEnthalpy"; - string solidFileName = "1DSolidTemperature"; - - // parameters calculation - unsigned MaxNbOfTimeStep =3; - int freqSave = 10; - double cfl = 0.5; - double maxTime = 1000000; - double precision = 1e-6; - - myDiffusionEquation.setCFL(cfl); - myDiffusionEquation.setPrecision(precision); - myDiffusionEquation.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myDiffusionEquation.setTimeMax(maxTime); - myDiffusionEquation.setFreqSave(freqSave); - myDiffusionEquation.setFileName(solidFileName); - - myTransportEquation.setCFL(cfl); - myTransportEquation.setPrecision(precision); - myTransportEquation.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myTransportEquation.setTimeMax(maxTime); - myTransportEquation.setFreqSave(freqSave); - myTransportEquation.setFileName(fluidFileName); - - // loop on time steps - myDiffusionEquation.initialize(); - myTransportEquation.initialize(); - - double time=0,dt=0; - int nbTimeStep=0; - bool stop=false, stop_transport=false, stop_diffusion=false; // Does the Problem want to stop (error) ? - bool ok; // Is the time interval successfully solved ? - - // Time step loop - while(!stop && !(myDiffusionEquation.isStationary() && myTransportEquation.isStationary()) &&time=maxTime) - cout<<"Maximum time "<=MaxNbOfTimeStep) - cout<<"Maximum number of time steps "< xinfcore && x< xsupcore) - heatPowerField[i]=1e8; - else - heatPowerField[i]=0; - } - heatPowerField.writeVTK("heatPowerField",true); - - DriftModel myProblem(around155bars600K,spaceDim); - int nbPhase = myProblem.getNumberOfPhases(); - int nVar = myProblem.getNumberOfVariables(); - Field VV("Primitive", CELLS, M, nVar); - - // Prepare for the initial condition - Vector VV_Constant(nVar); - // constant vector - VV_Constant(0) = 0.; - VV_Constant(1) = 155e5; - for (int idim=0; idim(1,xsup)); - - // physical parameters - myProblem.setHeatPowerField(heatPowerField); - - - // set the numerical method - myProblem.setNumericalScheme(upwind, Explicit); - myProblem.setWellBalancedCorrection(true); - - // name the result file - string fileName = "DriftModel1DBoilingAssembly"; - - // setting numerical parameters - unsigned MaxNbOfTimeStep =3 ; - int freqSave = 1; - double cfl = 0.5; - double maxTime = 1; - double precision = 1e-7; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - myProblem.saveAllFields(true); - bool ok; - - // evolution - myProblem.initialize(); - - ok = myProblem.run(); - if (ok) - cout << "Simulation "<(1,xsup)); - - // physical parameters - myProblem.setHeatSource(heatPower); - - - // set the numerical method - myProblem.setNumericalScheme(upwind, Implicit); - myProblem.setWellBalancedCorrection(true); - myProblem.setNonLinearFormulation(VFFC); - - // name the result file - string fileName = "Driftmodel1DBoilingChannel"; - - // setting numerical parameters - unsigned MaxNbOfTimeStep =3 ; - int freqSave = 1; - double cfl = 100; - double maxTime = 1; - double precision = 1e-7; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - myProblem.usePrimitiveVarsInNewton(true); - myProblem.saveAllFields(true); - myProblem.displayConditionNumber(); - myProblem.setSaveFileFormat(CSV); - - // evolution - myProblem.initialize(); - - bool ok = myProblem.run(); - if (ok) - cout << "Simulation "< gravite(spaceDim,0.) ; - gravite[0]=-10; - - DriftModel myProblem(around155bars600K,spaceDim); - int nbPhase = myProblem.getNumberOfPhases(); - int nVar = myProblem.getNumberOfVariables(); - - // Prepare for the initial condition - Vector VV_Constant(nVar); - // constant vector - VV_Constant(0) = 0.; - VV_Constant(1) = 155e5; - for (int idim=0; idim(1,xsup)); - - // physical parameters - myProblem.setGravity(gravite); - - // set the numerical method - myProblem.setNumericalScheme(upwind, Implicit); - myProblem.setWellBalancedCorrection(true); - myProblem.setNonLinearFormulation(VFRoe); - - // name the result file - string fileName = "Driftmodel_1DChannelGravity"; - - // setting numerical parameters - unsigned MaxNbOfTimeStep =3 ; - int freqSave = 1; - double cfl = 100; - double maxTime = 1; - double precision = 1e-7; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - myProblem.usePrimitiveVarsInNewton(true); - myProblem.saveAllFields(true); - myProblem.displayConditionNumber(); - myProblem.setSaveFileFormat(CSV); - - // evolution - myProblem.initialize(); - - bool ok = myProblem.run(); - if (ok) - cout << "Simulation "< VV_Constant(nVar); - VV_Constant[1] = initialConc; - VV_Constant[1] = initialPressure; - VV_Constant[2] = initialVelocityX; - VV_Constant[3] = initialTemperature; - - //Initial field creation - cout << "Building initial data " << endl; - myProblem.setInitialFieldConstant( spaceDim, VV_Constant, xinf, xsup, nx,"wall","Outlet"); - - //set the boundary conditions - myProblem.setWallBoundaryCondition("wall", wallTemperature, wallVelocityX); - myProblem.setOutletBoundaryCondition("Outlet",outletPressure,vector(1,xsup)); - - // set the numerical method - myProblem.setNumericalScheme(upwind, Explicit); - myProblem.setEntropicCorrection(true); - - // name file save - string fileName = "1DDepressurisation"; - - //Numerical parameters calculation - unsigned MaxNbOfTimeStep =3; - int freqSave = 1; - double cfl = 1; - double maxTime = 1; - double precision = 1e-7; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - bool ok; - - // evolution - myProblem.initialize(); - - ok = myProblem.run(); - if (ok) - cout << "Simulation "< (xsup-xinf)/3 && x< 2*(xsup-xinf)/3) - porosityField[i]=0.5; - else - porosityField[i]=1; - } - porosityField.writeVTK("PorosityField",true); - - - DriftModel myProblem(around155bars600K,spaceDim); - int nVar = myProblem.getNumberOfVariables(); - - // Prepare for the initial condition - vector VV_Constant(nVar); - // constant vector - VV_Constant[1] = initialConc; - VV_Constant[1] = initialPressure; - VV_Constant[2] = initialVelocityX; - VV_Constant[3] = initialTemperature; - - cout << "Building initial data " << endl; - - // generate initial condition - myProblem.setInitialFieldConstant( spaceDim, VV_Constant, xinf, xsup, nx,"Inlet","Outlet"); - - //set the boundary conditions - myProblem.setInletBoundaryCondition("Inlet",initialTemperature,initialConc,initialVelocityX); - myProblem.setOutletBoundaryCondition("Outlet",initialPressure,vector(1,xsup)); - - // physical parameters - myProblem.setPorosityField(porosityField); - - // set the numerical method - myProblem.setNumericalScheme(upwind, Explicit); - myProblem.setWellBalancedCorrection(true); - myProblem.setNonLinearFormulation(VFFC) ; - - // name file save - string fileName = "1DPorosityJumpUpwindWB"; - - - /* set numerical parameters */ - unsigned MaxNbOfTimeStep =3; - int freqSave = 1; - double cfl = 0.95; - double maxTime = 5; - double precision = 1e-5; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - bool ok; - - // evolution - myProblem.initialize(); - - ok = myProblem.run(); - if (ok) - cout << "Simulation "< VV_Constant(nVar); - // constant vector - VV_Constant[0] = inletConc; - VV_Constant[1] = outletPressure; - VV_Constant[2] = inletVelocityX; - VV_Constant[3] = inletTemperature; - - cout << "Building initial data " << endl; - - // generate initial condition - myProblem.setInitialFieldConstant( spaceDim, VV_Constant, xinf, xsup, nx,"inlet","outlet"); - - //set the boundary conditions - myProblem.setInletBoundaryCondition("inlet",inletTemperature,inletConc,inletVelocityX); - myProblem.setOutletBoundaryCondition("outlet", outletPressure,vector(1,xsup)); - - // physical parameters - myProblem.setPressureLossField(pressureLossField); - - // set the numerical method - myProblem.setNumericalScheme(upwind, Explicit); - myProblem.setWellBalancedCorrection(true); - - // name file save - string fileName = "1DPressureLossUpwindWB"; - - // parameters calculation - unsigned MaxNbOfTimeStep =3; - int freqSave = 1; - double cfl = 0.95; - double maxTime = 5; - double precision = 1e-5; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - - // evolution - myProblem.initialize(); - - bool ok = myProblem.run(); - if (ok) - cout << "Simulation "< boundaryFields; - boundaryFields["Neumann"] = limitNeumann; - - DriftModel myProblem(around155bars600K,spaceDim); - int nbPhase = myProblem.getNumberOfPhases(); - int nVar = myProblem.getNumberOfVariables(); - Field VV("Primitive", CELLS, M, nVar);//3+spaceDim*nbPhase - - // Prepare for the initial condition - Vector VV_Left(nVar),VV_Right(nVar); - double discontinuity = (xinf+xsup)/2.; - VV_Left(0) = 0.5; VV_Right(0) = 0.2; - VV_Left(1) = 155e5; VV_Right(1) = 155e5; - for (int idim=0; idim gravite(spaceDim, 0.); - gravite[0] = -10; - - DriftModel myProblem(around1bar300K, spaceDim, false); - int nbPhase = myProblem.getNumberOfPhases(); - int nVar = myProblem.getNumberOfVariables(); - - // Prepare for the initial condition - Vector VV_top(nVar), VV_bottom(nVar); - -// top and bottom vectors - VV_top[0] = initialConcTop; - VV_top[1] = initialPressure; - VV_top[2] = initialVelocityX; - VV_top[3] = initialTemperature; - - VV_bottom[0] = initialConcBottom; - VV_bottom[1] = initialPressure; - VV_bottom[2] = initialVelocityX; - VV_bottom[3] = initialTemperature; - - //Initial field creation - cout << "Setting initial data " << endl; - myProblem.setInitialFieldStepFunction(M, VV_bottom, VV_top, .8, 0); - - //set the boundary conditions - myProblem.setInletPressureBoundaryCondition("Inlet", outletPressure,inletTemperature, inletConc, vector(1, xinf)); - myProblem.setOutletBoundaryCondition("Outlet", outletPressure,vector(1, xsup)); - - // physical parameters - myProblem.setGravity(gravite); - - // set the numerical method - myProblem.setNumericalScheme(upwind, Explicit); - myProblem.setWellBalancedCorrection(true); - myProblem.setNonLinearFormulation(VFFC); - - // name the result file - string fileName = "Driftmodel_1DVidangeReservoir"; - - // setting numerical parameters - unsigned MaxNbOfTimeStep = 1; - int freqSave = 1; - double cfl = 0.95; - double maxTime = 1; - double precision = 1e-5; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - myProblem.usePrimitiveVarsInNewton(true); - myProblem.saveAllFields(true); - myProblem.setVerbose(true); - myProblem.displayConditionNumber(); - myProblem.setSaveFileFormat(CSV); - - // evolution - myProblem.initialize(); - - bool ok = myProblem.run(); - if (ok) - cout << "Simulation " << fileName << " is successful !" << endl; - else - cout << "Simulation " << fileName << " failed ! " << endl; - - cout << "------------ End of calculation -----------" << endl; - myProblem.terminate(); - - return EXIT_SUCCESS; -} diff --git a/CoreFlows/examples/DriftModel_2DInclinedBoilingChannel.cxx b/CoreFlows/examples/DriftModel_2DInclinedBoilingChannel.cxx deleted file mode 100755 index 12ac3dc..0000000 --- a/CoreFlows/examples/DriftModel_2DInclinedBoilingChannel.cxx +++ /dev/null @@ -1,98 +0,0 @@ -#include "DriftModel.hxx" - -using namespace std; - -int main(int argc, char** argv) -{ - int spaceDim = 2; - - // set the limit field for each boundary - double wallVelocityX=0; - double wallVelocityY=0; - double wallTemperature=563; - - double inletConcentration=0; - double inletVelocityX=0; - double inletVelocityY=1; - double inletTemperature=563; - - double outletPressure=155e5; - - // physical constants - vector gravite(spaceDim,0.) ; - gravite[1]=-7; - gravite[0]=7; - double heatPower=1e8; - - DriftModel myProblem(around155bars600K,spaceDim); - int nVar = myProblem.getNumberOfVariables(); - - //Prepare for the mesh - double xinf=0.0; - double xsup=1.0; - double yinf=0.0; - double ysup=1.0; - int nx=20; - int ny=20; - - // Prepare for the initial condition - vector VV_Constant(nVar); - // constant vector - VV_Constant[0] = 0; - VV_Constant[1] = 155e5; - VV_Constant[2] = 0; - VV_Constant[3] = 1; - VV_Constant[4] = 563; - - //Initial field creation - cout << "Building initial data" << endl; - myProblem.setInitialFieldConstant(spaceDim,VV_Constant,xinf,xsup,nx,"wall","wall",yinf,ysup,ny,"inlet","outlet"); - - //set the boundary conditions - vectorpressure_reference_point(2); - pressure_reference_point[0]=xsup; - pressure_reference_point[1]=ysup; - myProblem.setOutletBoundaryCondition("outlet", outletPressure,pressure_reference_point); - myProblem.setInletBoundaryCondition("inlet", inletTemperature, inletConcentration, inletVelocityX, inletVelocityY); - myProblem.setWallBoundaryCondition("wall", wallTemperature, wallVelocityX, wallVelocityY); - - // set physical parameters - myProblem.setHeatSource(heatPower); - myProblem.setGravity(gravite); - - // set the numerical method - myProblem.setNumericalScheme(upwind, Explicit); - myProblem.setWellBalancedCorrection(true); - - // name of result file - string fileName = "DriftModel_2DInclinedBoilingChannel"; - - // computation parameters - unsigned MaxNbOfTimeStep = 3 ; - int freqSave = 1; - double cfl = 0.5; - double maxTime = 5; - double precision = 1e-4; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - myProblem.saveVelocity(); - - // evolution - myProblem.initialize(); - - bool ok = myProblem.run(); - if (ok) - cout << "Simulation "< gravite(spaceDim,0.) ; - gravite[1]=-8.5; - gravite[0]=5; - - DriftModel myProblem(around155bars600K,spaceDim); - int nVar = myProblem.getNumberOfVariables(); - - // Prepare for the initial condition - vector VV_Constant(nVar); - // constant vector - VV_Constant[0] = 0; - VV_Constant[1] = 155e5; - VV_Constant[2] = 0; - VV_Constant[3] = 1; - VV_Constant[4] = 563; - - //Initial field creation - cout << "Building initial data" << endl; - myProblem.setInitialFieldConstant(spaceDim,VV_Constant,xinf,xsup,nx,"wall","wall",yinf,ysup,ny,"inlet","outlet"); - - //set the boundary conditions - vectorpressure_reference_point(2); - pressure_reference_point[0]=xsup; - pressure_reference_point[1]=ysup; - myProblem.setOutletBoundaryCondition("outlet", outletPressure,pressure_reference_point); - myProblem.setInletBoundaryCondition("inlet", inletTemperature, inletConcentration, inletVelocityX, inletVelocityY); - myProblem.setWallBoundaryCondition("wall", wallTemperature, wallVelocityX, wallVelocityY); - - // set physical parameters - myProblem.setGravity(gravite); - - // set the numerical method - myProblem.setNumericalScheme(upwind, Explicit); - myProblem.setWellBalancedCorrection(true); - myProblem.setNonLinearFormulation(VFFC); - - // name of result file - string fileName = "2DInclinedChannelGravity"; - - // computation parameters - unsigned MaxNbOfTimeStep = 3 ; - int freqSave = 1; - double cfl = 0.5; - double maxTime = 5; - double precision = 1e-6; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - myProblem.usePrimitiveVarsInNewton(true); - - // evolution - myProblem.initialize(); - - bool ok = myProblem.run(); - if (ok) - cout << "Simulation "< yinf+(ysup-yinf)/4) && (abs(x-xcloison1)< eps or abs(x-xcloison2)< eps) ) || abs(x-xinf)< eps || abs(x-xsup)< eps) - barrierField[i]=1; - else - barrierField[i]=0; - } - - barrierField.writeVTK("barrierField",true); - - // set the limit field for each boundary - double wallVelocityX=0; - double wallVelocityY=0; - double wallTemperature=563; - - double inletConcentration=0; - double inletVelocityX=0; - double inletVelocityY=1; - double inletTemperature=563; - - double outletPressure=155e5; - - // physical constants - vector gravite(spaceDim,0.) ; - gravite[1]=-7; - gravite[0]=7; - - DriftModel myProblem(around155bars600K,spaceDim); - int nVar = myProblem.getNumberOfVariables(); - - // Prepare for the initial condition - vector VV_Constant(nVar); - // constant vector - VV_Constant[0] = 0; - VV_Constant[1] = 155e5; - VV_Constant[2] = 0; - VV_Constant[3] = 1; - VV_Constant[4] = 563; - - //Initial field creation - cout << "Building initial data" << endl; - myProblem.setInitialFieldConstant(M,VV_Constant); - - //set the boundary conditions - vectorpressure_reference_point(2); - pressure_reference_point[0]=xsup; - pressure_reference_point[1]=ysup; - myProblem.setOutletBoundaryCondition("outlet", outletPressure,pressure_reference_point); - myProblem.setInletBoundaryCondition("inlet", inletTemperature, inletConcentration, inletVelocityX, inletVelocityY); - myProblem.setWallBoundaryCondition("wall", wallTemperature, wallVelocityX, wallVelocityY); - - // set physical parameters - myProblem.setGravity(gravite); - - // set the numerical method - myProblem.setNumericalScheme(upwind, Explicit); - myProblem.setWellBalancedCorrection(true); - myProblem.setNonLinearFormulation(VFFC); - - // name of result file - string fileName = "2DInclinedChannelGravityBarriers"; - - // computation parameters - unsigned MaxNbOfTimeStep = 3 ; - int freqSave = 1; - double cfl = 0.5; - double maxTime = 500; - double precision = 1e-6; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - myProblem.usePrimitiveVarsInNewton(true); - - // evolution - myProblem.initialize(); - - bool ok = myProblem.run(); - if (ok) - cout << "Simulation "< gravite = vector(spaceDim,0); - - gravite[0]=0; - gravite[1]=0; - gravite[2]=-10; - - double heatPower1=0; - double heatPower2=0.25e8; - double heatPower3=0.5e8; - double heatPower4=1e8; - - DriftModel myProblem = DriftModel(around155bars600K,spaceDim); - int nVar =myProblem.getNumberOfVariables(); - Field heatPowerField=Field("heatPowerField", CELLS, M, 1); - - int nbCells=M.getNumberOfCells(); - - for (int i=0;i zcloisonmin && z< zcloisonmax) - if (yxcloison) - heatPowerField[i]=heatPower2; - if (y>ycloison && xycloison && x>xcloison) - heatPowerField[i]=heatPower4; - else - heatPowerField[i]=0; - } - heatPowerField.writeVTK("heatPowerField",true); - - //Prepare for the initial condition - Vector VV_Constant =Vector(nVar); - - // constant vector - VV_Constant[0] = inletConc ; - VV_Constant[1] = outletPressure ; - VV_Constant[2] = inletVelocityX; - VV_Constant[3] = inletVelocityY; - VV_Constant[4] = inletVelocityZ; - VV_Constant[5] = inletTemperature ; - - //Initial field creation - cout<<"Building initial data " <inletVelocityX(2,2); - double inletTemperature=563; - - double outletPressure=155e5; - - // physical constants - double heatPower=1e8; - int nbPhase=2; - - FiveEqsTwoFluid myProblem(around155bars600K,spaceDim); - int nVar = myProblem.getNumberOfVariables(); - - // Prepare for the initial condition - vector VV_Constant(nVar); - // constant vector - VV_Constant[0] = inletVoidFraction; - VV_Constant[1] = outletPressure; - VV_Constant[2] = inletVelocityX[0]; - VV_Constant[3] = inletVelocityX[1]; - VV_Constant[2+spaceDim*nbPhase] = inletTemperature; - - cout << "Building initial data" << endl; - // generate initial condition - myProblem.setInitialFieldConstant( spaceDim, VV_Constant, xinf, xsup, nx,"inlet","outlet"); - - //set the boundary conditions - myProblem.setInletBoundaryCondition("inlet",inletVoidFraction,inletTemperature,inletVelocityX); - myProblem.setOutletBoundaryCondition("outlet", outletPressure); - - // physical parameters - myProblem.setHeatSource(heatPower); - - // set the numerical method - myProblem.setNumericalScheme(upwind, Explicit); - myProblem.setWellBalancedCorrection(true); - myProblem.setEntropicCorrection(true); - - // name file save - string fileName = "1DBoilingChannel"; - - // parameters calculation - unsigned MaxNbOfTimeStep =3; - int freqSave = 1; - double cfl = 0.5; - double maxTime = 5; - double precision = 1e-8; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - - // evolution - myProblem.initialize(); - - bool ok = myProblem.run(); - if (ok) - cout << "Simulation "< boundaryFields; - limitOutlet.bcType=Outlet; - limitOutlet.p = 100e5; - boundaryFields["Outlet"] = limitOutlet; - - limitWall.bcType=Wall; - limitWall.T = 600; - limitWall.v_x = vector(2,0); - boundaryFields["Wall"]= limitWall; - - // physical constants - double latentHeat=1e6; - double satTemp=618; - double dHsatl_over_dp=0.05; - double Psat=85e5; - - FiveEqsTwoFluid myProblem(around155bars600K,spaceDim); - int nbPhase = myProblem.getNumberOfPhases(); - int nVar = myProblem.getNumberOfVariables(); - - //Initial field creation - Vector VV_Constant(nVar); - VV_Constant(0) = 0.; - VV_Constant(1) = 155e5; - for (int idim=0; idim boundaryFields; - - limitNeumann.bcType=Neumann; - limitNeumann.T =0.; - limitNeumann.p = 155e5; - limitNeumann.alpha = 0; - limitNeumann.v_x = vector(2,0); - limitNeumann.v_y = vector(2,0); - limitNeumann.v_z = vector(2,0); - boundaryFields["Neumann"] = limitNeumann; - - FiveEqsTwoFluid myProblem(around155bars600K,spaceDim); - int nbPhase = myProblem.getNumberOfPhases(); - int nVar = myProblem.getNumberOfVariables(); - Field VV("Primitive", CELLS, M, nVar); - - // Prepare for the initial condition - Vector VV_Left(nVar),VV_Right(nVar); - double discontinuity = (xinf+xsup)/2.; - // two vectors - VV_Left(0) = 0.5; VV_Right(0) = 0.2; - VV_Left(1) = 155e5; VV_Right(1) = 155e5; - for (int idim=0; idim gravite(spaceDim,0.) ; - gravite[1]=-7; - gravite[0]=7; - - // set the limit field for each boundary - LimitField limitWall; - map boundaryFields; - limitWall.bcType=Wall; - limitWall.T = 563; - limitWall.v_x = vector(2,0); - limitWall.v_y = vector(2,0); - boundaryFields["Wall"]= limitWall; - - LimitField limitInlet; - limitInlet.bcType=Inlet; - limitInlet.T = 563; - limitInlet.alpha = 0; - limitInlet.v_x = vector(2,0); - limitInlet.v_y = vector(2,1); - boundaryFields["Inlet"]= limitInlet; - - LimitField limitOutlet; - limitOutlet.bcType=Outlet; - limitOutlet.p = 155e5; - boundaryFields["Outlet"]= limitOutlet; - - // physical constants - double heatPower=1e8; - - FiveEqsTwoFluid myProblem(around155bars600K,spaceDim); - int nbPhase = myProblem.getNumberOfPhases(); - int nVar = myProblem.getNumberOfVariables(); - // Prepare for the initial condition - Vector VV_Constant(nVar); - // constant vector - VV_Constant(0) = 0; - VV_Constant(1) = 155e5; - VV_Constant(2) = 0; - VV_Constant(3) = 1; - VV_Constant(4) = 0; - VV_Constant(5) = 1; - VV_Constant(6) = 563; - - //Initial field creation - cout << "Building initial data " << endl; - myProblem.setInitialFieldConstant(M,VV_Constant); - - //set the boundary conditions - myProblem.setBoundaryFields(boundaryFields); - - // set physical parameters - myProblem.setHeatSource(heatPower); - myProblem.setGravity(gravite); - - // name file save - string fileName = "2DInclinedBoilingChannel"; - - //numerical parameters - myProblem.setNumericalScheme(upwind, Explicit); - unsigned MaxNbOfTimeStep = 3 ; - int freqSave = 5; - double cfl = 0.5; - double maxTime = 5; - double precision = 1e-6; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - myProblem.saveVelocity(); - - // evolution - myProblem.initialize(); - - bool ok = myProblem.run(); - if (ok) - cout << "Simulation "< wallVelocityX(2,0); - vector wallVelocityY(2,0); - double wallTemperature=300; - - // physical constants - vector gravite(spaceDim,0.) ; - gravite[1]=-7; - gravite[0]=7; - - FiveEqsTwoFluid myProblem(around1bar300K,spaceDim); - int nbPhase = myProblem.getNumberOfPhases(); - int nVar = myProblem.getNumberOfVariables(); - // Prepare for the initial condition - Vector VV_Constant(nVar); - // constant vector - VV_Constant(0) = 0.5; - VV_Constant(1) = 1e5; - VV_Constant(2) = 0; - VV_Constant(3) = 0; - VV_Constant(4) = 0; - VV_Constant(5) = 0; - VV_Constant(6) = wallTemperature; - - //Initial field creation - cout << "Building initial data" << endl; - myProblem.setInitialFieldConstant(M,VV_Constant); - - //set the boundary conditions - myProblem.setWallBoundaryCondition("Wall",wallTemperature,wallVelocityX,wallVelocityY); - - // set physical parameters - myProblem.setGravity(gravite); - - // set the numerical method - myProblem.setNumericalScheme(upwind, Implicit); - - // name file save - string fileName = "2DInclinedSedimentation"; - - // parameters calculation - unsigned MaxNbOfTimeStep = 3 ; - int freqSave = 1; - double cfl = 0.1; - double maxTime = 5; - double precision = 1e-6; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - myProblem.saveVelocity(); - myProblem.displayConditionNumber(); - myProblem.setSaveFileFormat(CSV); - - // evolution - myProblem.initialize(); - - bool ok = myProblem.run(); - if (ok) - cout << "Simulation "< boundaryFields; - limitOutlet.bcType=Outlet; - limitOutlet.p = 80e5; - boundaryFields["Outlet"] = limitOutlet; - - limitWall.bcType=Wall; - limitWall.v_x = vector(2,0); - boundaryFields["Wall"]= limitWall; - IsothermalTwoFluid myProblem(around155bars600K,spaceDim); - // Prepare for the initial condition - int nVar = myProblem.getNumberOfVariables(); - Vector VV_Constant(nVar); - VV_Constant(0) = 0.; - VV_Constant(1) = 155e5; - VV_Constant(2) = 0; - VV_Constant(3) = 0; - - //Initial field creation - cout << "Building initial data" << endl; - myProblem.setInitialFieldConstant(M,VV_Constant); - - //set the boundary conditions - myProblem.setBoundaryFields(boundaryFields); - - //set physical parameters -// myProblem.setSatPressure( Psat, dHsatl_over_dp); -// myProblem.setLatentHeat(latentHeat); - - // set the numerical method - myProblem.setNumericalScheme(upwind, Explicit); - myProblem.setEntropicCorrection(true); - - // name file save - string fileName = "1DDepressurisation"; - - // parameters calculation - unsigned MaxNbOfTimeStep = 3; - int freqSave = 1; - double cfl = 0.95; - double maxTime = 5; - double precision = 1e-6; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - bool ok; - - // evolution - myProblem.initialize(); - - ok = myProblem.run(); - if (ok) - cout << "Simulation "< boundaryFields; - - limitNeumann.p = 155e5; - limitNeumann.alpha = 0; - limitNeumann.v_x = vector(2,0); - limitNeumann.v_y = vector(2,0); - limitNeumann.v_z = vector(2,0); - boundaryFields["Neumann"] = limitNeumann; - - IsothermalTwoFluid myProblem(around155bars600K,spaceDim); - int nbPhase = myProblem.getNumberOfPhases(); - int nVar = myProblem.getNumberOfVariables(); - Field VV("Primitive", CELLS, M, nVar); - - // Prepare for the initial condition - Vector VV_Left(nVar),VV_Right(nVar); - double discontinuity = (xinf+xsup)/2.; - // two vectors - VV_Left(0) = 0.5; VV_Right(0) = 0.2; - VV_Left(1) = 155e5; VV_Right(1) = 155e5; - for (int idim=0; idim wallVelocityX(2,0); - - // physical constants - vector gravite(spaceDim,0.) ; - gravite[0]=-10; - - IsothermalTwoFluid myProblem(around1bar300K,spaceDim); - int nVar = myProblem.getNumberOfVariables(); - - // Prepare for the initial condition - vector VV_Constant(nVar,0.); - // constant vector - VV_Constant[0] = 0.5; - VV_Constant[1] = 1e5; - VV_Constant[2] = 0; - VV_Constant[3] = 0; - - //Initial field creation - cout << "Building initial data " << endl; - myProblem.setInitialFieldConstant(spaceDim,VV_Constant,xinf,xsup,nx,"wall","wall"); - myProblem.setWallBoundaryCondition("wall",wallVelocityX); - - - // physical parameters - myProblem.setGravity(gravite); - - // set the numerical method - myProblem.setNumericalScheme(upwind, Implicit); - myProblem.setEntropicCorrection(true); - - // name file save - string fileName = "1DSedimentation"; - - // parameters calculation - unsigned MaxNbOfTimeStep = 3; - int freqSave = 1; - double cfl = 1; - double maxTime = 5; - double precision = 1e-6; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - myProblem.displayConditionNumber(); - myProblem.setSaveFileFormat(CSV); - - // evolution - myProblem.initialize(); - - bool ok = myProblem.run(); - if (ok) - cout << "Simulation "< wallVelocityX(2,0); - vector wallVelocityY(2,0); - - // physical constants - vector gravite(spaceDim,0.) ; - gravite[1]=-7; - gravite[0]=7; - - IsothermalTwoFluid myProblem(around1bar300K,spaceDim); - int nbPhase = myProblem.getNumberOfPhases(); - int nVar = myProblem.getNumberOfVariables(); - // Prepare for the initial condition - Vector VV_Constant(nVar); - // constant vector - VV_Constant(0) = 0.5; - VV_Constant(1) = 1e5; - VV_Constant(2) = 0; - VV_Constant(3) = 0; - VV_Constant(4) = 0; - VV_Constant(5) = 0; - - //Initial field creation - cout << "Building initial data" << endl; - myProblem.setInitialFieldConstant(M,VV_Constant); - - //set the boundary conditions - myProblem.setWallBoundaryCondition("Wall",wallVelocityX,wallVelocityY); - - // set physical parameters - myProblem.setGravity(gravite); - - // set the numerical method - myProblem.setNumericalScheme(upwind, Explicit); - - // name file save - string fileName = "2DInclinedSedimentation"; - - // parameters calculation - unsigned MaxNbOfTimeStep = 3 ; - int freqSave = 1; - double cfl = 0.25; - double maxTime = 5; - double precision = 1e-6; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - myProblem.saveVelocity(); - - // evolution - myProblem.initialize(); - - bool ok = myProblem.run(); - if (ok) - cout << "Simulation "< - -using namespace std; - -int main(int argc, char** argv) -{ - //Preprocessing: mesh and group creation - cout << "Building Cartesian mesh " << endl; - double xinf=0.0; - double xsup=1.0; - double yinf=0.0; - double ysup=1.0; - int nx=50; - int ny=50; - Mesh M(xinf,xsup,nx,yinf,ysup,ny); - double eps=1.E-6; - M.setGroupAtPlan(xsup,0,eps,"Wall"); - M.setGroupAtPlan(xinf,0,eps,"Wall"); - M.setGroupAtPlan(yinf,1,eps,"Wall"); - M.setGroupAtPlan(ysup,1,eps,"inlet"); - int spaceDim = M.getSpaceDimension(); - - // set the limit field for each boundary - vector wallVelocityX(2,0); - vector wallVelocityY(2,0); - double inletAlpha=1; - double outletPressure=1e5; - - // physical constants - vector gravite(spaceDim,0.) ; - gravite[1]=-10; - gravite[0]=0; - - IsothermalTwoFluid myProblem(around1bar300K,spaceDim); - int nbPhase = myProblem.getNumberOfPhases(); - int nVar = myProblem.getNumberOfVariables(); - // Prepare for the initial condition - Vector VV_Constant(nVar); - // constant vector - VV_Constant(0) = 0.; - VV_Constant(1) = 1e5; - VV_Constant(2) = 0; - VV_Constant(3) = 0; - - //Initial field creation - cout << "Building initial data" << endl; - myProblem.setInitialFieldConstant(M,VV_Constant); - - //set the boundary conditions - myProblem.setWallBoundaryCondition("Wall",wallVelocityX,wallVelocityY); - myProblem.setInletPressureBoundaryCondition("inlet", inletAlpha, outletPressure); - - // set physical parameters - myProblem.setGravity(gravite); - - // set the numerical method - myProblem.setNumericalScheme(upwind, Explicit); - - // name file save - string fileName = "2DInclinedSedimentation"; - - // parameters calculation - unsigned MaxNbOfTimeStep = 3 ; - int freqSave = 1; - double cfl = 0.1; - double maxTime = 5; - double precision = 1e-6; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - myProblem.saveVelocity(); - - // evolution - myProblem.initialize(); - - bool ok = myProblem.run(); - if (ok) - cout << "Simulation "< xinfcore) and (x< xsupcore): + heatPowerField[i]=1e8 + else: + heatPowerField[i]=0 + heatPowerField.writeVTK("heatPowerField",True) + + myProblem = cf.DriftModel(cf.around155bars600K,spaceDim); + nVar = myProblem.getNumberOfVariables(); + + # Prepare for the initial condition + VV_Constant =[0]*nVar; + + # constant vector + VV_Constant[0] = inletConc; + VV_Constant[1] = outletPressure ; + VV_Constant[2] = inletVelocityX; + VV_Constant[3] = inletTemperature ; + + + #Initial field creation + print("Building initial data " ); + myProblem.setInitialFieldConstant( spaceDim, VV_Constant, xinf, xsup, nx,"inlet","outlet"); + + # set the boundary conditions + myProblem.setInletBoundaryCondition("inlet",inletTemperature,inletConc,inletVelocityX) + myProblem.setOutletBoundaryCondition("outlet", outletPressure,[xsup]); + + # set physical parameters + myProblem.setHeatPowerField(heatPowerField); + + # set the numerical method + myProblem.setNumericalScheme(cf.upwind, cf.Explicit); + myProblem.setWellBalancedCorrection(True); + myProblem.setNonLinearFormulation(cf.VFFC) + + # name of result file + fileName = "1DBoilingAssemblyUpwindWB"; + + # simulation parameters + MaxNbOfTimeStep = 3 ; + freqSave = 1; + cfl = 0.5; + maxTime = 500; + precision = 1e-7; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + myProblem.setNewtonSolver(precision,20); + myProblem.saveConservativeField(True); + + # evolution + myProblem.initialize(); + + ok = myProblem.run(); + if (ok): + print( "Simulation python " + fileName + " is successful !" ); + pass + else: + print( "Simulation python " + fileName + " failed ! " ); + pass + + print( "------------ End of calculation !!! -----------" ); + + myProblem.terminate(); + return ok + +if __name__ == """__main__""": + DriftModel_1DBoilingAssembly() diff --git a/CoreFlows/examples/Python/DriftModel/DriftModel_1DBoilingChannel.py b/CoreFlows/examples/Python/DriftModel/DriftModel_1DBoilingChannel.py new file mode 100755 index 0000000..6984043 --- /dev/null +++ b/CoreFlows/examples/Python/DriftModel/DriftModel_1DBoilingChannel.py @@ -0,0 +1,90 @@ +#!/usr/bin/env python +# -*-coding:utf-8 -* + +import CoreFlows as cf + +def DriftModel_1DBoilingChannel(): + + spaceDim = 1; + # Prepare for the mesh + print("Building mesh " ); + xinf = 0 ; + xsup=4.2; + nx=50; + + # set the limit field for each boundary + + inletConc=0; + inletVelocityX=1; + inletTemperature=565; + outletPressure=155e5; + + # physical parameters + heatPower=1e8; + + myProblem = cf.DriftModel(cf.around155bars600K,spaceDim); + nVar = myProblem.getNumberOfVariables(); + + # Prepare for the initial condition + VV_Constant =[0]*nVar; + + # constant vector + VV_Constant[0] = inletConc; + VV_Constant[1] = outletPressure ; + VV_Constant[2] = inletVelocityX; + VV_Constant[3] = inletTemperature ; + + + #Initial field creation + print("Building initial data " ); + myProblem.setInitialFieldConstant( spaceDim, VV_Constant, xinf, xsup, nx,"inlet","outlet"); + + # set the boundary conditions + myProblem.setInletBoundaryCondition("inlet",inletTemperature,inletConc,inletVelocityX) + myProblem.setOutletBoundaryCondition("outlet", outletPressure,[xsup]); + + # set physical parameters + myProblem.setHeatSource(heatPower); + + # set the numerical method + myProblem.setNumericalScheme(cf.upwind, cf.Implicit); + myProblem.setWellBalancedCorrection(True); + myProblem.setNonLinearFormulation(cf.VFFC) + + # name of result file + fileName = "1DBoilingChannelUpwindWBImplicite"; + + # simulation parameters + MaxNbOfTimeStep = 3 ; + freqSave = 1; + cfl = 100; + maxTime = 500; + precision = 1e-7; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + myProblem.saveAllFields(True); + myProblem.usePrimitiveVarsInNewton(True); + + # evolution + myProblem.initialize(); + + ok = myProblem.run(); + if (ok): + print( "Simulation python " + fileName + " is successful !" ); + pass + else: + print( "Simulation python " + fileName + " failed ! " ); + pass + + print( "------------ End of calculation !!! -----------" ); + + myProblem.terminate(); + return ok + +if __name__ == """__main__""": + DriftModel_1DBoilingChannel() diff --git a/CoreFlows/examples/Python/DriftModel/DriftModel_1DChannelGravity.py b/CoreFlows/examples/Python/DriftModel/DriftModel_1DChannelGravity.py new file mode 100755 index 0000000..8a23587 --- /dev/null +++ b/CoreFlows/examples/Python/DriftModel/DriftModel_1DChannelGravity.py @@ -0,0 +1,89 @@ +#!/usr/bin/env python +# -*-coding:utf-8 -* + +import CoreFlows as cf + +def DriftModel_1DChannelGravity(): + + spaceDim = 1; + # Prepare for the mesh + print("Building mesh " ); + xinf = 0 ; + xsup=4.2; + nx=50; + + # set the limit field for each boundary + + inletConc=0; + inletVelocityX=1; + inletEnthalpy=1.3e6; + outletPressure=155e5; + + # physical parameters + gravite=[-10]; + + myProblem = cf.DriftModel(cf.around155bars600K,spaceDim); + nVar = myProblem.getNumberOfVariables(); + + # Prepare for the initial condition + VV_Constant =[0]*nVar; + + # constant vector + VV_Constant[0] = inletConc; + VV_Constant[1] = outletPressure ; + VV_Constant[2] = inletVelocityX; + VV_Constant[3] = 578 ; + + + #Initial field creation + print("Building initial data " ); + myProblem.setInitialFieldConstant( spaceDim, VV_Constant, xinf, xsup, nx,"inlet","outlet"); + + # set the boundary conditions + myProblem.setInletEnthalpyBoundaryCondition("inlet",inletEnthalpy,inletConc,inletVelocityX) + myProblem.setOutletBoundaryCondition("outlet", outletPressure,[xsup]); + + # set physical parameters + myProblem.setGravity(gravite); + + # set the numerical method + myProblem.setNumericalScheme(cf.upwind, cf.Implicit); + myProblem.setNonLinearFormulation(cf.VFRoe) + + # name of result file + fileName = "1DChannelGravityUpwindImplicite"; + + # simulation parameters + MaxNbOfTimeStep = 3 ; + freqSave = 1; + cfl = 100; + maxTime = 500; + precision = 1e-7; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + myProblem.saveAllFields(True); + myProblem.usePrimitiveVarsInNewton(True); + + # evolution + myProblem.initialize(); + + ok = myProblem.run(); + if (ok): + print( "Simulation python " + fileName + " is successful !" ); + pass + else: + print( "Simulation python " + fileName + " failed ! " ); + pass + + print( "------------ End of calculation !!! -----------" ); + + myProblem.terminate(); + return ok + +if __name__ == """__main__""": + DriftModel_1DChannelGravity() diff --git a/CoreFlows/examples/Python/DriftModel/DriftModel_1DDepressurisation.py b/CoreFlows/examples/Python/DriftModel/DriftModel_1DDepressurisation.py new file mode 100755 index 0000000..3c7d25b --- /dev/null +++ b/CoreFlows/examples/Python/DriftModel/DriftModel_1DDepressurisation.py @@ -0,0 +1,88 @@ +#!/usr/bin/env python +# -*-coding:utf-8 -* + +import CoreFlows as cf + +def DriftModel_1DDepressurisation(): + + spaceDim = 1; + # Prepare for the mesh + print("Building mesh " ); + xinf = 0 ; + xsup=4.2; + nx=50; + + # set the boundary field for each boundary + initialConc=0; + initialVelocityX=0; + initialTemperature=565; + initialPressure=155e5 + # set the boundary field for each boundary + wallVelocityX=0; + wallTemperature=565; + outletPressure=1e5; + + myProblem = cf.DriftModel(cf.around155bars600K,spaceDim); + nVar = myProblem.getNumberOfVariables(); + + # Prepare for the initial condition + VV_Constant =[0]*nVar; + + # constant vector + VV_Constant[0] = initialConc; + VV_Constant[1] = initialPressure ; + VV_Constant[2] = initialVelocityX; + VV_Constant[3] = initialTemperature ; + + + #Initial field creation + print("Building initial data " ); + myProblem.setInitialFieldConstant( spaceDim, VV_Constant, xinf, xsup, nx,"wall","outlet"); + + # set the boundary conditions + myProblem.setWallBoundaryCondition("wall",wallTemperature,wallVelocityX) + myProblem.setOutletBoundaryCondition("outlet", outletPressure,[xsup]); + + # set the numerical method + myProblem.setNumericalScheme(cf.upwind, cf.Explicit); + myProblem.setEntropicCorrection(True); + + # name of result file + fileName = "1DDepressurisation"; + + # simulation parameters + MaxNbOfTimeStep = 3 ; + freqSave = 1; + cfl = 1; + maxTime = 500; + precision = 1e-6; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + myProblem.setNewtonSolver(precision*1e7,20); + myProblem.saveConservativeField(True); + myProblem.saveAllFields(True); + + # evolution + myProblem.initialize(); + print("Running python "+ fileName ); + + ok = myProblem.run(); + if (ok): + print( "Simulation python " + fileName + " is successful !" ); + pass + else: + print( "Simulation python " + fileName + " failed ! " ); + pass + + print( "------------ End of calculation !!! -----------" ); + + myProblem.terminate(); + return ok + +if __name__ == """__main__""": + DriftModel_1DDepressurisation() diff --git a/CoreFlows/examples/Python/DriftModel/DriftModel_1DPorosityJump.py b/CoreFlows/examples/Python/DriftModel/DriftModel_1DPorosityJump.py new file mode 100755 index 0000000..ec65a81 --- /dev/null +++ b/CoreFlows/examples/Python/DriftModel/DriftModel_1DPorosityJump.py @@ -0,0 +1,101 @@ +#!/usr/bin/env python +# -*-coding:utf-8 -* + +import CoreFlows as cf +import cdmath as cm + +def DriftModel_1DPorosityJump(): + + # Prepare for the mesh + print("Building mesh " ); + xinf = 0 ; + xsup=4.2; + nx=100; + M=cm.Mesh(xinf,xsup,nx) + spaceDim = M.getSpaceDimension() + + # set the limit field for each boundary + initialConc=0; + initialVelocityX=1; + initialTemperature=600; + initialPressure=155e5; + + # physical parameters + porosityField=cm.Field("Porosity",cm.CELLS,M,1); + for i in xrange(M.getNumberOfCells()): + x=M.getCell(i).x(); + if x > (xsup-xinf)/3. and x<(xsup-xinf)*2./3: + porosityField[i]=0.5; + else: + porosityField[i]=1; + pass + porosityField.writeVTK("PorosityField"); + + myProblem = cf.DriftModel(cf.around155bars600K,spaceDim); + nVar = myProblem.getNumberOfVariables(); + + # Prepare for the initial condition + VV_Constant =[0]*nVar; + + # constant vector + VV_Constant[0] = initialConc; + VV_Constant[1] = initialPressure ; + VV_Constant[2] = initialVelocityX; + VV_Constant[3] = initialTemperature ; + + + #Initial field creation + print("Building initial data " ); + #myProblem.setInitialFieldConstant( spaceDim, VV_Constant, xinf, xsup, nx,"Inlet","Outlet"); + myProblem.setInitialFieldConstant( spaceDim, VV_Constant, xinf, xsup, nx,"Neumann","Neumann"); + + # set the boundary conditions + #myProblem.setInletBoundaryCondition("Inlet",initialTemperature,initialConc,initialVelocityX) + #myProblem.setOutletBoundaryCondition("Outlet", initialPressure,[xsup]); + myProblem.setNeumannBoundaryCondition("Neumann"); + + # set physical parameters + myProblem.setPorosityField(porosityField); + + # set the numerical method + myProblem.setNumericalScheme(cf.upwind, cf.Explicit); + myProblem.setWellBalancedCorrection(True); + myProblem.setNonLinearFormulation(cf.VFFC) + + # name of result file + fileName = "1DPorosityJumpUpwindWB"; + + # simulation parameters + MaxNbOfTimeStep = 3 ; + freqSave = 1; + cfl = 0.95; + maxTime = 500; + precision = 1e-5; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + myProblem.setNewtonSolver(precision,20); + myProblem.saveConservativeField(True); + + # evolution + myProblem.initialize(); + + ok = myProblem.run(); + if (ok): + print( "Simulation python " + fileName + " is successful !" ); + pass + else: + print( "Simulation python " + fileName + " failed ! " ); + pass + + print( "------------ End of calculation !!! -----------" ); + + myProblem.terminate(); + return ok + +if __name__ == """__main__""": + DriftModel_1DPorosityJump() diff --git a/CoreFlows/examples/Python/DriftModel/DriftModel_1DPressureLoss.py b/CoreFlows/examples/Python/DriftModel/DriftModel_1DPressureLoss.py new file mode 100755 index 0000000..014ce38 --- /dev/null +++ b/CoreFlows/examples/Python/DriftModel/DriftModel_1DPressureLoss.py @@ -0,0 +1,99 @@ +#!/usr/bin/env python +# -*-coding:utf-8 -* + +import CoreFlows as cf +import cdmath as cm + +def DriftModel_1DPressureLoss(): + + spaceDim = 1; + # Prepare for the mesh + print("Building mesh " ); + xinf = 0 ; + xsup=4.2; + nx=50; + M=cm.Mesh(xinf,xsup,nx) + + # set the limit field for each boundary + + inletConc=0; + inletVelocityX=1; + inletTemperature=565; + outletPressure=155e5; + + # physical parameters + pressureLossField=cm.Field("PressureLossCoeff", cm.FACES, M, 1); + nbFaces=M.getNumberOfFaces(); + + for i in range (nbFaces): + pressureLossField[i]=0 + pressureLossField[nx/4]=50; + pressureLossField[nx/2]=100; + pressureLossField[3*nx/4]=150; + + myProblem = cf.DriftModel(cf.around155bars600K,spaceDim); + nVar = myProblem.getNumberOfVariables(); + + # Prepare for the initial condition + VV_Constant =[0]*nVar; + + # constant vector + VV_Constant[0] = inletConc; + VV_Constant[1] = outletPressure ; + VV_Constant[2] = inletVelocityX; + VV_Constant[3] = inletTemperature ; + + + #Initial field creation + print("Building initial data " ); + myProblem.setInitialFieldConstant( spaceDim, VV_Constant, xinf, xsup, nx,"inlet","outlet"); + + # set the boundary conditions + myProblem.setInletBoundaryCondition("inlet",inletTemperature,inletConc,inletVelocityX) + myProblem.setOutletBoundaryCondition("outlet", outletPressure,[xsup]); + + # set physical parameters + myProblem.setPressureLossField(pressureLossField); + + # set the numerical method + myProblem.setNumericalScheme(cf.upwind, cf.Explicit); + myProblem.setWellBalancedCorrection(True); + myProblem.setNonLinearFormulation(cf.VFFC) + + # name of result file + fileName = "1DPressureLossUpwindWB"; + + # simulation parameters + MaxNbOfTimeStep = 3 ; + freqSave = 1; + cfl = 0.95; + maxTime = 500; + precision = 1e-5; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + myProblem.setNewtonSolver(precision,20); + myProblem.saveConservativeField(True); + + # evolution + myProblem.initialize(); + + ok = myProblem.run(); + if (ok): + print( "Simulation python " + fileName + " is successful !" ); + pass + else: + print( "Simulation python " + fileName + " failed ! " ); + pass + + print( "------------ End of calculation !!! -----------" ); + + myProblem.terminate(); + return ok + +if __name__ == """__main__""": + DriftModel_1DPressureLoss() diff --git a/CoreFlows/examples/Python/DriftModel/DriftModel_1DRiemannProblem.py b/CoreFlows/examples/Python/DriftModel/DriftModel_1DRiemannProblem.py new file mode 100755 index 0000000..f73d704 --- /dev/null +++ b/CoreFlows/examples/Python/DriftModel/DriftModel_1DRiemannProblem.py @@ -0,0 +1,99 @@ +#!/usr/bin/env python +# -*-coding:utf-8 -* + +import CoreFlows as cf +import cdmath as cm + +def DriftModel_1DRiemannProblem(): + + spaceDim = 1; + # Prepare for the mesh + print("Building mesh " ); + xinf = 0 ; + xsup=4.2; + nx=50; + discontinuity=(xinf+xsup)/2 + M=cm.Mesh(xinf,xsup,nx) + eps=1e-6 + M.setGroupAtPlan(xsup,0,eps,"RightBoundary") + M.setGroupAtPlan(xinf,0,eps,"LeftBoundary") + + # set the limit field for each boundary + + inletConc_Left=0; + inletVelocity_Left=1; + inletTemperature_Left=565; + outletPressure_Left=155e5; + + inletConc_Right=0; + inletVelocity_Right=1; + inletTemperature_Right=565; + outletPressure_Right=155.1e5; + + myProblem = cf.DriftModel(cf.around155bars600K,spaceDim); + nVar = myProblem.getNumberOfVariables(); + + # Prepare for the initial condition + VV_Constant_Left =cm.Vector(nVar) + VV_Constant_Right =cm.Vector(nVar) + + # constant vectors + VV_Constant_Left[0] = inletConc_Left ; + VV_Constant_Left[1] = outletPressure_Left; + VV_Constant_Left[2] = inletVelocity_Left; + VV_Constant_Left[3] = inletTemperature_Left ; + + VV_Constant_Right[0] = inletConc_Right ; + VV_Constant_Right[1] = outletPressure_Right; + VV_Constant_Right[2] = inletVelocity_Right; + VV_Constant_Right[3] = inletTemperature_Right ; + + + #Initial field creation + print("Building initial data " ); + myProblem.setInitialFieldStepFunction(M,VV_Constant_Left,VV_Constant_Right,discontinuity) + + # set the boundary conditions + myProblem.setNeumannBoundaryCondition("LeftBoundary") + myProblem.setNeumannBoundaryCondition("RightBoundary"); + + # set the numerical method + myProblem.setNumericalScheme(cf.upwind, cf.Explicit); + + # name of result file + fileName = "1DRiemannProblemUpwind"; + + # simulation parameters + MaxNbOfTimeStep = 3 ; + freqSave = 1; + cfl = 0.95; + maxTime = 500; + precision = 1e-6; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + myProblem.setNewtonSolver(precision,20); + myProblem.saveConservativeField(True); + + # evolution + myProblem.initialize(); + + ok = myProblem.run(); + if (ok): + print( "Simulation python " + fileName + " is successful !" ); + pass + else: + print( "Simulation python " + fileName + " failed ! " ); + pass + + print( "------------ End of calculation !!! -----------" ); + + myProblem.terminate(); + return ok + +if __name__ == """__main__""": + DriftModel_1DRiemannProblem() diff --git a/CoreFlows/examples/Python/DriftModel/DriftModel_1DVidangeReservoir.py b/CoreFlows/examples/Python/DriftModel/DriftModel_1DVidangeReservoir.py new file mode 100755 index 0000000..01fce36 --- /dev/null +++ b/CoreFlows/examples/Python/DriftModel/DriftModel_1DVidangeReservoir.py @@ -0,0 +1,103 @@ +#!/usr/bin/env python +# -*-coding:utf-8 -* + +import CoreFlows as cf +import cdmath as cm + +def DriftModel_1DVidangeReservoir(): + + spaceDim = 1; + # Prepare for the mesh + print("Building mesh " ); + xinf = 0. ; + xsup=1.0; + nx=50; + M=cm.Mesh(xinf,xsup,nx) + # set the limit field for each boundary + eps=1e-6; + M.setGroupAtPlan(xinf,0,eps,"outlet") + M.setGroupAtPlan(xsup,0,eps,"inlet") + + # set the limit field for each boundary + inletConc=1; + inletTemperature=300; + outletPressure=1e5; + + initialConcTop=1; + initialConcBottom=0.0001; + initialVelocityX=[0]; + initialPressure=1e5; + initialTemperature=300 + + # physical constants + gravite=[-10]; + + myProblem = cf.DriftModel(cf.around1bar300K,spaceDim); + nVar = myProblem.getNumberOfVariables(); + + # Prepare for the initial condition + VV_top =cm.Vector(nVar) + VV_bottom =cm.Vector(nVar) + + # top and bottom vectors + VV_top[0] = initialConcTop ; + VV_top[1] = initialPressure ; + VV_top[2] = initialVelocityX[0]; + VV_top[3] = initialTemperature + + VV_bottom[0] = initialConcBottom ; + VV_bottom[1] = initialPressure ; + VV_bottom[2] = initialVelocityX[0]; + VV_bottom[3] = initialTemperature + + #Initial field creation + print("Building initial data " ); + myProblem.setInitialFieldStepFunction( M, VV_bottom, VV_top, .8, 0); + + # the boundary conditions + myProblem.setInletPressureBoundaryCondition("inlet", outletPressure, inletTemperature, inletConc,[xinf]); + myProblem.setOutletBoundaryCondition("outlet", outletPressure,[xsup]); + + # set physical parameters + myProblem.setGravity(gravite); + + # set the numerical method + myProblem.setNumericalScheme(cf.upwind, cf.Explicit); + myProblem.setNonLinearFormulation(cf.VFFC) + + # name file save + fileName = "1DVidangeReservoir"; + + # simulation parameters + MaxNbOfTimeStep = 3 ; + freqSave = 1; + cfl = .95; + maxTime = 5.; + precision = 1e-5; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + + # evolution + myProblem.initialize(); + + ok = myProblem.run(); + if (ok): + print( "Simulation python " + fileName + " is successful !" ); + pass + else: + print( "Simulation python " + fileName + " failed ! " ); + pass + + print( "------------ End of calculation !!! -----------" ); + + myProblem.terminate(); + return ok + + +if __name__ == """__main__""": + DriftModel_1DVidangeReservoir() diff --git a/CoreFlows/examples/Python/DriftModel/DriftModel_2BranchesBoilingChannels.py b/CoreFlows/examples/Python/DriftModel/DriftModel_2BranchesBoilingChannels.py new file mode 100755 index 0000000..f6c0f92 --- /dev/null +++ b/CoreFlows/examples/Python/DriftModel/DriftModel_2BranchesBoilingChannels.py @@ -0,0 +1,97 @@ +#!/usr/bin/env python +# -*-coding:utf-8 -* + +import CoreFlows as cf +import cdmath as cm + + +def DriftModel_2BranchesBoilingChannels(): + + spaceDim = 1; + # Prepare for the mesh + M=cm.Mesh("../resources/BifurcatingFlow2BranchesEqualSections.med") + M.getFace(0).setGroupName("Inlet")#z=0 + M.getFace(31).setGroupName("Outlet")#z=4.2 + + # set the initial field + initialConc=0; + initialPressure=155e5; + initialVelocityX=5; + initialTemperature=573; + + # set the limit field for each boundary + inletConc=0; + inletVelocityX=5; + inletTemperature=573; + outletPressure=155e5 + + myProblem = cf.DriftModel(cf.around155bars600K,spaceDim); + nVar = myProblem.getNumberOfVariables(); + + # Prepare for the initial condition + VV_Constant =[0]*nVar; + + # constant vector + VV_Constant[0] = initialConc ; + VV_Constant[1] = initialPressure ; + VV_Constant[2] = initialVelocityX; + VV_Constant[3] = initialTemperature ; + + + #Initial field creation + print("Building initial data" ); + myProblem.setInitialFieldConstant( M, VV_Constant); + + # set the boundary conditions + myProblem.setInletBoundaryCondition("Inlet", inletTemperature, inletConc,inletVelocityX); + myProblem.setOutletBoundaryCondition("Outlet",outletPressure); + + #set porosity, heat and gravity source + Sections=cm.Field("../resources/BifurcatingFlow2BranchesEqualSections", cm.CELLS,"Section area"); + heatPowerField=cm.Field("../resources/BifurcatingFlow2BranchesEqualSections", cm.CELLS,"Heat power"); + myProblem.setSectionField(Sections); + myProblem.setHeatPowerField(heatPowerField) + gravite=[-10] + myProblem.setGravity(gravite) + # set the numerical method + myProblem.setNumericalScheme(cf.upwind, cf.Explicit); + myProblem.setWellBalancedCorrection(True) + myProblem.setNonLinearFormulation(cf.VFFC) + + # name of result file + fileName = "2BranchesBoilingChannels"; + + # simulation parameters + MaxNbOfTimeStep = 3 ; + freqSave = 1; + cfl = 0.5; + maxTime = 500; + precision = 1e-6; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + myProblem.setNewtonSolver(precision,20); + myProblem.saveConservativeField(True); + + # evolution + myProblem.initialize(); + + ok = myProblem.run(); + if (ok): + print( "Simulation python " + fileName + " is successful !" ); + pass + else: + print( "Simulation python " + fileName + " failed ! " ); + pass + + print( "------------ End of calculation !!! -----------" ); + + myProblem.terminate(); + return ok + +if __name__ == """__main__""": + DriftModel_2BranchesBoilingChannels() diff --git a/CoreFlows/examples/Python/DriftModel/DriftModel_2DBoilingChannelBarrier.py b/CoreFlows/examples/Python/DriftModel/DriftModel_2DBoilingChannelBarrier.py new file mode 100755 index 0000000..387b13b --- /dev/null +++ b/CoreFlows/examples/Python/DriftModel/DriftModel_2DBoilingChannelBarrier.py @@ -0,0 +1,134 @@ +#!/usr/bin/env python +# -*-coding:utf-8 -* + + +import CoreFlows as cf +import cdmath as cm + + +def DriftModel_2DBoilingChannelBarrier(): + + spaceDim = 2; + # Prepare for the mesh + print("Building mesh " ); + xinf = 0 ; + xsup=2.0; + yinf=0.0; + ysup=4.0; + nx=20; + ny=40; + cloison=(xinf+xsup)/2 + M=cm.Mesh(xinf,xsup,nx,yinf,ysup,ny) + # set the limit field for each boundary + eps=1e-6; + M.setGroupAtPlan(xsup,0,eps,"wall") + M.setGroupAtPlan(xinf,0,eps,"wall") + M.setGroupAtPlan(ysup,1,eps,"outlet") + M.setGroupAtPlan(yinf,1,eps,"inlet") + dy=(ysup-yinf)/ny + ncloison=ny/2 + i=0 + while i<= ncloison+1: + M.setGroupAtFaceByCoords(cloison,((ysup-yinf)/4)+(i+0.5)*dy,0,eps,"wall") + i=i+1 + + + # set the limit field for each boundary + wallVelocityX=0; + wallVelocityY=0; + wallTemperature=573; + inletConc=0; + inletVelocityX=0; + inletVelocityY=1; + inletTemperature=563; + outletPressure=155e5; + + # physical constants + gravite = [0] * spaceDim + + gravite[0]=0; + gravite[1]=-10; + + heatPower=1e8; + heatPower_nul=0; + + myProblem = cf.DriftModel(cf.around155bars600K,spaceDim); + nVar =myProblem.getNumberOfVariables(); + heatPowerField=cm.Field("heatPowerField", cm.CELLS, M, 1); + + nbCells=M.getNumberOfCells(); + + for i in range (nbCells): + x=M.getCell(i).x(); + y=M.getCell(i).y(); + if (y> (ysup-yinf)/4) and (y< (ysup-yinf)*3/4) and (x1): + myProblem.saveVelocity(); + pass + + # evolution + myProblem.initialize(); + + ok = myProblem.run(); + if (ok): + print( "Simulation python " + fileName + " is successful !" ); + pass + else: + print( "Simulation python " + fileName + " failed ! " ); + pass + + print( "------------ End of calculation !!! -----------" ); + + myProblem.terminate(); + return ok + +if __name__ == """__main__""": + DriftModel_2DInclinedBoilingChannel() diff --git a/CoreFlows/examples/Python/DriftModel/DriftModel_2DInclinedBoilingChannelBarrier.py b/CoreFlows/examples/Python/DriftModel/DriftModel_2DInclinedBoilingChannelBarrier.py new file mode 100755 index 0000000..c024637 --- /dev/null +++ b/CoreFlows/examples/Python/DriftModel/DriftModel_2DInclinedBoilingChannelBarrier.py @@ -0,0 +1,133 @@ +#!/usr/bin/env python +# -*-coding:utf-8 -* + + +import CoreFlows as cf +import cdmath as cm + + +def DriftModel_2DInclinedBoilingChannelBarrier(): + + spaceDim = 2; + # Prepare for the mesh + print("Building mesh " ); + xinf = 0 ; + xsup=2.0; + yinf=0.0; + ysup=4.0; + nx=20; + ny=40; + cloison=(xinf+xsup)/2 + M=cm.Mesh(xinf,xsup,nx,yinf,ysup,ny) + # set the limit field for each boundary + eps=1e-6; + M.setGroupAtPlan(xsup,0,eps,"wall") + M.setGroupAtPlan(xinf,0,eps,"wall") + M.setGroupAtPlan(ysup,1,eps,"outlet") + M.setGroupAtPlan(yinf,1,eps,"inlet") + dy=(ysup-yinf)/ny + ncloison=ny/2 + i=0 + while i<= ncloison+1: + M.setGroupAtFaceByCoords(cloison,((ysup-yinf)/4)+(i+0.5)*dy,0,eps,"wall") + i=i+1 + + + # set the limit field for each boundary + wallVelocityX=0; + wallVelocityY=0; + wallTemperature=573; + inletConc=0; + inletVelocityX=0; + inletVelocityY=1; + inletTemperature=563; + outletPressure=155e5; + + # source terms + gravite = [0] * spaceDim + + gravite[0]=7; + gravite[1]=-7; + + heatPower=1e8; + heatPower_nul=0; + heatPowerField=cm.Field("heatPowerField", cm.CELLS, M, 1); + + nbCells=M.getNumberOfCells(); + + for i in range (nbCells): + x=M.getCell(i).x(); + y=M.getCell(i).y(); + if (y> (ysup-yinf)/4) and (y< (ysup-yinf)*3/4) and (x yinf+(ysup-yinf)/4) and (abs(x-xcloison1)< eps or abs(x-xcloison2)< eps)) or abs(x-xinf)< eps or abs(x-xsup)< eps : + barrierField[i]=1 + else: + barrierField[i]=0 + barrierField.writeVTK("barrierField",True) + + # set the limit field for each boundary + wallVelocityX=0; + wallVelocityY=0; + wallTemperature=563; + inletConcentration=0; + inletVelocityX=0; + inletVelocityY=1; + inletTemperature=563; + outletPressure=155e5; + + # physical constants + gravite = [0] * spaceDim + + gravite[1]=-8.5; + gravite[0]=5; + + heatPower=0e8; + + myProblem = cf.DriftModel(cf.around155bars600K,spaceDim); + nVar =myProblem.getNumberOfVariables(); + + # Prepare for the initial condition + VV_Constant =[0]*nVar + + # constant vector + VV_Constant[0] = inletConcentration; + VV_Constant[1] = outletPressure ; + VV_Constant[2] = inletVelocityX; + VV_Constant[3] = inletVelocityY; + VV_Constant[4] = inletTemperature ; + + #Initial field creation + print("Building mesh and initial data " ); + myProblem.setInitialFieldConstant(M,VV_Constant) + + # the boundary conditions + myProblem.setOutletBoundaryCondition("outlet", outletPressure,[xsup,ysup]); + myProblem.setInletBoundaryCondition("inlet", inletTemperature, inletConcentration, inletVelocityX, inletVelocityY); + myProblem.setWallBoundaryCondition("wall", wallTemperature, wallVelocityX, wallVelocityY); + + # set physical parameters + myProblem.setHeatSource(heatPower); + myProblem.setGravity(gravite); + + # set the numerical method + myProblem.setNumericalScheme(cf.staggered, cf.Implicit); + myProblem.setWellBalancedCorrection(True); + myProblem.setNonLinearFormulation(cf.VFFC) + + # name of result file + fileName = "2DInclinedChannelVFFCStaggeredWB3x100CFL100"; + + # simulation parameters + MaxNbOfTimeStep = 3 ; + freqSave = 1000; + cfl = 100; + maxTime = 500; + precision = 1e-6; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + myProblem.usePrimitiveVarsInNewton(True) + + # evolution + myProblem.initialize(); + + ok = myProblem.run(); + if (ok): + print( "Simulation python " + fileName + " is successful !" ); + pass + else: + print( "Simulation python " + fileName + " failed ! " ); + pass + + print( "------------ End of calculation !!! -----------" ); + + myProblem.terminate(); + return ok + +if __name__ == """__main__""": + DriftModel_2DInclinedBoilingChannel() diff --git a/CoreFlows/examples/Python/DriftModel/DriftModel_2DInclinedChannelGravityTriangles.py b/CoreFlows/examples/Python/DriftModel/DriftModel_2DInclinedChannelGravityTriangles.py new file mode 100755 index 0000000..5675db9 --- /dev/null +++ b/CoreFlows/examples/Python/DriftModel/DriftModel_2DInclinedChannelGravityTriangles.py @@ -0,0 +1,106 @@ +#!/usr/bin/env python +# -*-coding:utf-8 -* + +import CoreFlows as cf + +def DriftModel_2DInclinedBoilingChannel(): + spaceDim = 2; + + # Prepare for the mesh + print( "Loading unstructured mesh " ); + inputfile="../resources/CanalTrianglesStructures.med"; + xinf = 0 ; + xsup=1.0; + yinf=0.0; + ysup=4.0; + nx=10; + ny=40; + + # set the limit field for each boundary + wallVelocityX=0; + wallVelocityY=0; + wallTemperature=563; + inletConcentration=0; + inletVelocityX=0; + inletVelocityY=1; + inletTemperature=563; + outletPressure=155e5; + + # physical constants + gravite = [0] * spaceDim + + gravite[1]=-8.5; + gravite[0]=5; + + heatPower=0e8; + + myProblem = cf.DriftModel(cf.around155bars600K,spaceDim); + nVar =myProblem.getNumberOfVariables(); + + # Prepare for the initial condition + VV_Constant =[0]*nVar + + # constant vector + VV_Constant[0] = inletConcentration; + VV_Constant[1] = outletPressure ; + VV_Constant[2] = inletVelocityX; + VV_Constant[3] = inletVelocityY; + VV_Constant[4] = inletTemperature ; + + #Initial field creation + print("Building mesh and initial data " ); + myProblem.setInitialFieldConstant(spaceDim,VV_Constant, + xinf,xsup,nx,"wall","wall", + yinf,ysup,ny,"inlet","outlet", + 0.0,0.0, 0, "", "") + + # the boundary conditions + myProblem.setOutletBoundaryCondition("outlet", outletPressure,[xsup,ysup]); + myProblem.setInletBoundaryCondition("inlet", inletTemperature, inletConcentration, inletVelocityX, inletVelocityY); + myProblem.setWallBoundaryCondition("wall", wallTemperature, wallVelocityX, wallVelocityY); + + # set physical parameters + myProblem.setHeatSource(heatPower); + myProblem.setGravity(gravite); + + # set the numerical method + myProblem.setNumericalScheme(cf.staggered, cf.Implicit); + myProblem.setWellBalancedCorrection(True); + myProblem.setNonLinearFormulation(cf.VFFC) + + # name of result file + fileName = "2DInclinedChannelGravityTriangles"; + + # simulation parameters + MaxNbOfTimeStep = 3 ; + freqSave = 1; + cfl = 0.5; + maxTime = 500; + precision = 1e-6; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + myProblem.usePrimitiveVarsInNewton(True) + + # evolution + myProblem.initialize(); + + ok = myProblem.run(); + if (ok): + print( "Simulation python " + fileName + " is successful !" ); + pass + else: + print( "Simulation python " + fileName + " failed ! " ); + pass + + print( "------------ End of calculation !!! -----------" ); + + myProblem.terminate(); + return ok + +if __name__ == """__main__""": + DriftModel_2DInclinedBoilingChannel() diff --git a/CoreFlows/examples/Python/DriftModel/DriftModel_2DPorosityJump.py b/CoreFlows/examples/Python/DriftModel/DriftModel_2DPorosityJump.py new file mode 100755 index 0000000..d306e92 --- /dev/null +++ b/CoreFlows/examples/Python/DriftModel/DriftModel_2DPorosityJump.py @@ -0,0 +1,119 @@ +#!/usr/bin/env python +# -*-coding:utf-8 -* + + +import CoreFlows as cf +import cdmath as cm +import math + +def DriftModel_2DPorosityJump(): + spaceDim = 2; + + # Prepare for the mesh + print("Building mesh " ); + xinf = 0 ; + xsup=1.5; + yinf=0.0; + ysup=0.8; + nx=20; + ny=20; + discontinuity=(xinf+xsup)/2 + M=cm.Mesh(xinf,xsup,nx,yinf,ysup,ny) + # set the limit field for each boundary + eps=1e-6; + M.setGroupAtPlan(xsup,0,eps,"Outlet") + M.setGroupAtPlan(xinf,0,eps,"Inlet") + M.setGroupAtPlan(ysup,1,eps,"Wall") + M.setGroupAtPlan(yinf,1,eps,"Wall") + dx=(xsup-xinf)/nx + ndis=(discontinuity-xinf)/dx + + + # set the limit field for each boundary + inletConc=0; + inletVelocityX=1. ; + inletVelocityY=0 ; + inletTemperature=563 ; + outletPressure=155e5 ; + + + # physical parameters + porosityField=cm.Field("Porosity",cm.CELLS,M,1); + for i in xrange(M.getNumberOfCells()): + x=M.getCell(i).x(); + y=M.getCell(i).y(); + if x > (xsup-xinf)/3. and x<(xsup-xinf)*2./3 and y> (ysup-yinf)/4. and y<(ysup-yinf)*3./4: + porosityField[i]=0.5; + else: + porosityField[i]=1; + pass + porosityField.writeVTK("PorosityField"); + + myProblem = cf.DriftModel(cf.around155bars600K,spaceDim); + nVar =myProblem.getNumberOfVariables(); + + # Prepare for the initial condition + VV_Constant =cm.Vector(nVar) + + # constant vectorsetOutletBoundaryCondition + VV_Constant[0] = inletConc; + VV_Constant[1] = outletPressure ; + VV_Constant[2] = inletVelocityX; + VV_Constant[3] = inletVelocityY; + VV_Constant[4] = inletTemperature ; + + # set physical parameters + myProblem.setPorosityField(porosityField); + + print("Building initial data"); + myProblem.setInitialFieldConstant(M,VV_Constant) + + + # the boundary conditions + myProblem.setOutletBoundaryCondition("Outlet", outletPressure); + myProblem.setInletBoundaryCondition("Inlet", inletTemperature,inletConc, inletVelocityX, inletVelocityY); + myProblem.setWallBoundaryCondition("Wall", inletTemperature, 0,0); + myProblem.setNonLinearFormulation(cf.VFFC) + + + # set the numerical method + myProblem.setNumericalScheme(cf.upwind, cf.Explicit); + myProblem.setWellBalancedCorrection(True); + + # name file save + fileName = "2DPorosityJump"; + + # parameters calculation + MaxNbOfTimeStep = 3 ; + freqSave = 1; + cfl = 0.5; + maxTime = 5000; + precision = 1e-4; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + myProblem.setNewtonSolver(1e10,20); + myProblem.saveVelocity(); + + # evolution + myProblem.initialize(); + + ok = myProblem.run(); + if (ok): + print( "Simulation python " + fileName + " is successful !" ); + pass + else: + print( "Simulation python " + fileName + " failed ! " ); + pass + + print( "------------ End of calculation !!! -----------" ); + + myProblem.terminate(); + return ok + +if __name__ == """__main__""": + DriftModel_2DPorosityJump() diff --git a/CoreFlows/examples/Python/DriftModel/DriftModel_2DPressureLoss.py b/CoreFlows/examples/Python/DriftModel/DriftModel_2DPressureLoss.py new file mode 100755 index 0000000..2d3a802 --- /dev/null +++ b/CoreFlows/examples/Python/DriftModel/DriftModel_2DPressureLoss.py @@ -0,0 +1,144 @@ +#!/usr/bin/env python +# -*-coding:utf-8 -* + + +import CoreFlows as cf +import cdmath as cm +import math + +def DriftModel_2DPressureLoss(): + spaceDim = 2; + + # Prepare for the mesh + print("Building mesh " ); + xinf = 0 ; + xsup=0.42; + yinf=0.0; + ysup=4.2; + nx=2; + ny=100; + discontinuity=(xinf+xsup)/2 + M=cm.Mesh(xinf,xsup,nx,yinf,ysup,ny) + # set the limit field for each boundary + eps=1e-6; + M.setGroupAtPlan(xsup,0,eps,"RightWall") + M.setGroupAtPlan(xinf,0,eps,"LeftWall") + M.setGroupAtPlan(ysup,1,eps,"outlet") + dx=(xsup-xinf)/nx + ndis=(discontinuity-xinf)/dx + print("ndis=",math.floor(ndis) ); + i=0 +# while i<= ndis: + M.setGroupAtFaceByCoords(xinf+(i+0.5)*dx,yinf,0,eps,"inlet_1") + i=1 +# while i<= nx: + M.setGroupAtFaceByCoords(xinf+(i+0.5)*dx,yinf,0,eps,"inlet_2") + + + + # set the limit field for each boundary + inletConc=0; + inletVelocityX1=0. ; + inletVelocityY1=2.7 ; + inletVelocityX2=0 ; + inletVelocityY2=1.5 ; + inletTemperature=563 ; + outletPressure=155e5 ; + + + # physical parameters + pressureLossField=cm.Field("PressureLossCoeff", cm.FACES, M, 1); + nbFaces=M.getNumberOfFaces(); + + for i in range (nbFaces): + if abs(M.getFace(i).y() - 1.0500) zcloisonmin) and (z< zcloisonmax) : + if (yxcloison): + heatPowerField[i]=heatPower2 + if (y>ycloison) and (xycloison) and (x>xcloison): + heatPowerField[i]=heatPower4 + else: + heatPowerField[i]=0 + + heatPowerField.writeVTK("heatPowerField",True) + + # Prepare for the initial condition + VV_Constant =[0]*nVar + + # constant vector + VV_Constant[0] = inletConc ; + VV_Constant[1] = outletPressure ; + VV_Constant[2] = inletVelocityX; + VV_Constant[3] = inletVelocityY; + VV_Constant[4] = inletVelocityZ; + VV_Constant[5] = inletTemperature ; + + #Initial field creation + print("Building initial data " ); + myProblem.setInitialFieldConstant(M,VV_Constant) + + # the boundary conditions + myProblem.setOutletBoundaryCondition("outlet", outletPressure,[xsup,ysup,zsup]); + myProblem.setInletBoundaryCondition("inlet", inletTemperature, inletConc, inletVelocityX, inletVelocityY, inletVelocityZ); + myProblem.setWallBoundaryCondition("wall", wallTemperature, wallVelocityX, wallVelocityY,wallVelocityZ); + + # set physical parameters + myProblem.setHeatPowerField(heatPowerField) + myProblem.setGravity(gravite); + + # set the numerical method + myProblem.setNumericalScheme(cf.upwind, cf.Explicit); + myProblem.setLinearSolver(cf.GMRES,cf.ILU,True); + myProblem.setWellBalancedCorrection(True); + + # name file save + fileName = "3DBoilingChannelBarrier"; + + # parameters calculation + MaxNbOfTimeStep = 3; + freqSave = 100; + cfl = .3; + maxTime = 5000; + precision = 1e-6; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + myProblem.setNewtonSolver(precision,20); + myProblem.saveVelocity(); + + # evolution + myProblem.initialize(); + print("Running python "+ fileName ); + + ok = myProblem.run(); + if (ok): + print( "Simulation python " + fileName + " is successful !" ); + pass + else: + print( "Simulation python " + fileName + " failed ! " ); + pass + + print( "------------ End of calculation !!! -----------" ); + + myProblem.terminate(); + return ok + +if __name__ == """__main__""": + DriftModel_3DBoilingChannelBarrier() diff --git a/CoreFlows/examples/Python/DriftModel_1DBoilingAssembly.py b/CoreFlows/examples/Python/DriftModel_1DBoilingAssembly.py deleted file mode 100755 index 254740a..0000000 --- a/CoreFlows/examples/Python/DriftModel_1DBoilingAssembly.py +++ /dev/null @@ -1,104 +0,0 @@ -#!/usr/bin/env python -# -*-coding:utf-8 -* - -import CoreFlows as cf -import cdmath as cm - -def DriftModel_1DBoilingAssembly(): - - spaceDim = 1; - # Prepare for the mesh - print("Building mesh " ); - xinf = 0 ; - xsup=4.2; - xinfcore=(xsup-xinf)/4 - xsupcore=3*(xsup-xinf)/4 - nx=50; - M=cm.Mesh(xinf,xsup,nx) - - # set the limit field for each boundary - - inletConc=0; - inletVelocityX=1; - inletTemperature=565; - outletPressure=155e5; - - # physical parameters - heatPowerField=cm.Field("heatPowerField", cm.CELLS, M, 1); - nbCells=M.getNumberOfCells(); - - for i in range (nbCells): - x=M.getCell(i).x(); - - if (x> xinfcore) and (x< xsupcore): - heatPowerField[i]=1e8 - else: - heatPowerField[i]=0 - heatPowerField.writeVTK("heatPowerField",True) - - myProblem = cf.DriftModel(cf.around155bars600K,spaceDim); - nVar = myProblem.getNumberOfVariables(); - - # Prepare for the initial condition - VV_Constant =[0]*nVar; - - # constant vector - VV_Constant[0] = inletConc; - VV_Constant[1] = outletPressure ; - VV_Constant[2] = inletVelocityX; - VV_Constant[3] = inletTemperature ; - - - #Initial field creation - print("Building initial data " ); - myProblem.setInitialFieldConstant( spaceDim, VV_Constant, xinf, xsup, nx,"inlet","outlet"); - - # set the boundary conditions - myProblem.setInletBoundaryCondition("inlet",inletTemperature,inletConc,inletVelocityX) - myProblem.setOutletBoundaryCondition("outlet", outletPressure,[xsup]); - - # set physical parameters - myProblem.setHeatPowerField(heatPowerField); - - # set the numerical method - myProblem.setNumericalScheme(cf.upwind, cf.Explicit); - myProblem.setWellBalancedCorrection(True); - myProblem.setNonLinearFormulation(cf.VFFC) - - # name of result file - fileName = "1DBoilingAssemblyUpwindWB"; - - # simulation parameters - MaxNbOfTimeStep = 3 ; - freqSave = 1; - cfl = 0.5; - maxTime = 500; - precision = 1e-7; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - myProblem.setNewtonSolver(precision,20); - myProblem.saveConservativeField(True); - - # evolution - myProblem.initialize(); - - ok = myProblem.run(); - if (ok): - print( "Simulation python " + fileName + " is successful !" ); - pass - else: - print( "Simulation python " + fileName + " failed ! " ); - pass - - print( "------------ End of calculation !!! -----------" ); - - myProblem.terminate(); - return ok - -if __name__ == """__main__""": - DriftModel_1DBoilingAssembly() diff --git a/CoreFlows/examples/Python/DriftModel_1DBoilingChannel.py b/CoreFlows/examples/Python/DriftModel_1DBoilingChannel.py deleted file mode 100755 index 6984043..0000000 --- a/CoreFlows/examples/Python/DriftModel_1DBoilingChannel.py +++ /dev/null @@ -1,90 +0,0 @@ -#!/usr/bin/env python -# -*-coding:utf-8 -* - -import CoreFlows as cf - -def DriftModel_1DBoilingChannel(): - - spaceDim = 1; - # Prepare for the mesh - print("Building mesh " ); - xinf = 0 ; - xsup=4.2; - nx=50; - - # set the limit field for each boundary - - inletConc=0; - inletVelocityX=1; - inletTemperature=565; - outletPressure=155e5; - - # physical parameters - heatPower=1e8; - - myProblem = cf.DriftModel(cf.around155bars600K,spaceDim); - nVar = myProblem.getNumberOfVariables(); - - # Prepare for the initial condition - VV_Constant =[0]*nVar; - - # constant vector - VV_Constant[0] = inletConc; - VV_Constant[1] = outletPressure ; - VV_Constant[2] = inletVelocityX; - VV_Constant[3] = inletTemperature ; - - - #Initial field creation - print("Building initial data " ); - myProblem.setInitialFieldConstant( spaceDim, VV_Constant, xinf, xsup, nx,"inlet","outlet"); - - # set the boundary conditions - myProblem.setInletBoundaryCondition("inlet",inletTemperature,inletConc,inletVelocityX) - myProblem.setOutletBoundaryCondition("outlet", outletPressure,[xsup]); - - # set physical parameters - myProblem.setHeatSource(heatPower); - - # set the numerical method - myProblem.setNumericalScheme(cf.upwind, cf.Implicit); - myProblem.setWellBalancedCorrection(True); - myProblem.setNonLinearFormulation(cf.VFFC) - - # name of result file - fileName = "1DBoilingChannelUpwindWBImplicite"; - - # simulation parameters - MaxNbOfTimeStep = 3 ; - freqSave = 1; - cfl = 100; - maxTime = 500; - precision = 1e-7; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - myProblem.saveAllFields(True); - myProblem.usePrimitiveVarsInNewton(True); - - # evolution - myProblem.initialize(); - - ok = myProblem.run(); - if (ok): - print( "Simulation python " + fileName + " is successful !" ); - pass - else: - print( "Simulation python " + fileName + " failed ! " ); - pass - - print( "------------ End of calculation !!! -----------" ); - - myProblem.terminate(); - return ok - -if __name__ == """__main__""": - DriftModel_1DBoilingChannel() diff --git a/CoreFlows/examples/Python/DriftModel_1DChannelGravity.py b/CoreFlows/examples/Python/DriftModel_1DChannelGravity.py deleted file mode 100755 index 8a23587..0000000 --- a/CoreFlows/examples/Python/DriftModel_1DChannelGravity.py +++ /dev/null @@ -1,89 +0,0 @@ -#!/usr/bin/env python -# -*-coding:utf-8 -* - -import CoreFlows as cf - -def DriftModel_1DChannelGravity(): - - spaceDim = 1; - # Prepare for the mesh - print("Building mesh " ); - xinf = 0 ; - xsup=4.2; - nx=50; - - # set the limit field for each boundary - - inletConc=0; - inletVelocityX=1; - inletEnthalpy=1.3e6; - outletPressure=155e5; - - # physical parameters - gravite=[-10]; - - myProblem = cf.DriftModel(cf.around155bars600K,spaceDim); - nVar = myProblem.getNumberOfVariables(); - - # Prepare for the initial condition - VV_Constant =[0]*nVar; - - # constant vector - VV_Constant[0] = inletConc; - VV_Constant[1] = outletPressure ; - VV_Constant[2] = inletVelocityX; - VV_Constant[3] = 578 ; - - - #Initial field creation - print("Building initial data " ); - myProblem.setInitialFieldConstant( spaceDim, VV_Constant, xinf, xsup, nx,"inlet","outlet"); - - # set the boundary conditions - myProblem.setInletEnthalpyBoundaryCondition("inlet",inletEnthalpy,inletConc,inletVelocityX) - myProblem.setOutletBoundaryCondition("outlet", outletPressure,[xsup]); - - # set physical parameters - myProblem.setGravity(gravite); - - # set the numerical method - myProblem.setNumericalScheme(cf.upwind, cf.Implicit); - myProblem.setNonLinearFormulation(cf.VFRoe) - - # name of result file - fileName = "1DChannelGravityUpwindImplicite"; - - # simulation parameters - MaxNbOfTimeStep = 3 ; - freqSave = 1; - cfl = 100; - maxTime = 500; - precision = 1e-7; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - myProblem.saveAllFields(True); - myProblem.usePrimitiveVarsInNewton(True); - - # evolution - myProblem.initialize(); - - ok = myProblem.run(); - if (ok): - print( "Simulation python " + fileName + " is successful !" ); - pass - else: - print( "Simulation python " + fileName + " failed ! " ); - pass - - print( "------------ End of calculation !!! -----------" ); - - myProblem.terminate(); - return ok - -if __name__ == """__main__""": - DriftModel_1DChannelGravity() diff --git a/CoreFlows/examples/Python/DriftModel_1DDepressurisation.py b/CoreFlows/examples/Python/DriftModel_1DDepressurisation.py deleted file mode 100755 index 3c7d25b..0000000 --- a/CoreFlows/examples/Python/DriftModel_1DDepressurisation.py +++ /dev/null @@ -1,88 +0,0 @@ -#!/usr/bin/env python -# -*-coding:utf-8 -* - -import CoreFlows as cf - -def DriftModel_1DDepressurisation(): - - spaceDim = 1; - # Prepare for the mesh - print("Building mesh " ); - xinf = 0 ; - xsup=4.2; - nx=50; - - # set the boundary field for each boundary - initialConc=0; - initialVelocityX=0; - initialTemperature=565; - initialPressure=155e5 - # set the boundary field for each boundary - wallVelocityX=0; - wallTemperature=565; - outletPressure=1e5; - - myProblem = cf.DriftModel(cf.around155bars600K,spaceDim); - nVar = myProblem.getNumberOfVariables(); - - # Prepare for the initial condition - VV_Constant =[0]*nVar; - - # constant vector - VV_Constant[0] = initialConc; - VV_Constant[1] = initialPressure ; - VV_Constant[2] = initialVelocityX; - VV_Constant[3] = initialTemperature ; - - - #Initial field creation - print("Building initial data " ); - myProblem.setInitialFieldConstant( spaceDim, VV_Constant, xinf, xsup, nx,"wall","outlet"); - - # set the boundary conditions - myProblem.setWallBoundaryCondition("wall",wallTemperature,wallVelocityX) - myProblem.setOutletBoundaryCondition("outlet", outletPressure,[xsup]); - - # set the numerical method - myProblem.setNumericalScheme(cf.upwind, cf.Explicit); - myProblem.setEntropicCorrection(True); - - # name of result file - fileName = "1DDepressurisation"; - - # simulation parameters - MaxNbOfTimeStep = 3 ; - freqSave = 1; - cfl = 1; - maxTime = 500; - precision = 1e-6; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - myProblem.setNewtonSolver(precision*1e7,20); - myProblem.saveConservativeField(True); - myProblem.saveAllFields(True); - - # evolution - myProblem.initialize(); - print("Running python "+ fileName ); - - ok = myProblem.run(); - if (ok): - print( "Simulation python " + fileName + " is successful !" ); - pass - else: - print( "Simulation python " + fileName + " failed ! " ); - pass - - print( "------------ End of calculation !!! -----------" ); - - myProblem.terminate(); - return ok - -if __name__ == """__main__""": - DriftModel_1DDepressurisation() diff --git a/CoreFlows/examples/Python/DriftModel_1DPorosityJump.py b/CoreFlows/examples/Python/DriftModel_1DPorosityJump.py deleted file mode 100755 index ec65a81..0000000 --- a/CoreFlows/examples/Python/DriftModel_1DPorosityJump.py +++ /dev/null @@ -1,101 +0,0 @@ -#!/usr/bin/env python -# -*-coding:utf-8 -* - -import CoreFlows as cf -import cdmath as cm - -def DriftModel_1DPorosityJump(): - - # Prepare for the mesh - print("Building mesh " ); - xinf = 0 ; - xsup=4.2; - nx=100; - M=cm.Mesh(xinf,xsup,nx) - spaceDim = M.getSpaceDimension() - - # set the limit field for each boundary - initialConc=0; - initialVelocityX=1; - initialTemperature=600; - initialPressure=155e5; - - # physical parameters - porosityField=cm.Field("Porosity",cm.CELLS,M,1); - for i in xrange(M.getNumberOfCells()): - x=M.getCell(i).x(); - if x > (xsup-xinf)/3. and x<(xsup-xinf)*2./3: - porosityField[i]=0.5; - else: - porosityField[i]=1; - pass - porosityField.writeVTK("PorosityField"); - - myProblem = cf.DriftModel(cf.around155bars600K,spaceDim); - nVar = myProblem.getNumberOfVariables(); - - # Prepare for the initial condition - VV_Constant =[0]*nVar; - - # constant vector - VV_Constant[0] = initialConc; - VV_Constant[1] = initialPressure ; - VV_Constant[2] = initialVelocityX; - VV_Constant[3] = initialTemperature ; - - - #Initial field creation - print("Building initial data " ); - #myProblem.setInitialFieldConstant( spaceDim, VV_Constant, xinf, xsup, nx,"Inlet","Outlet"); - myProblem.setInitialFieldConstant( spaceDim, VV_Constant, xinf, xsup, nx,"Neumann","Neumann"); - - # set the boundary conditions - #myProblem.setInletBoundaryCondition("Inlet",initialTemperature,initialConc,initialVelocityX) - #myProblem.setOutletBoundaryCondition("Outlet", initialPressure,[xsup]); - myProblem.setNeumannBoundaryCondition("Neumann"); - - # set physical parameters - myProblem.setPorosityField(porosityField); - - # set the numerical method - myProblem.setNumericalScheme(cf.upwind, cf.Explicit); - myProblem.setWellBalancedCorrection(True); - myProblem.setNonLinearFormulation(cf.VFFC) - - # name of result file - fileName = "1DPorosityJumpUpwindWB"; - - # simulation parameters - MaxNbOfTimeStep = 3 ; - freqSave = 1; - cfl = 0.95; - maxTime = 500; - precision = 1e-5; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - myProblem.setNewtonSolver(precision,20); - myProblem.saveConservativeField(True); - - # evolution - myProblem.initialize(); - - ok = myProblem.run(); - if (ok): - print( "Simulation python " + fileName + " is successful !" ); - pass - else: - print( "Simulation python " + fileName + " failed ! " ); - pass - - print( "------------ End of calculation !!! -----------" ); - - myProblem.terminate(); - return ok - -if __name__ == """__main__""": - DriftModel_1DPorosityJump() diff --git a/CoreFlows/examples/Python/DriftModel_1DPressureLoss.py b/CoreFlows/examples/Python/DriftModel_1DPressureLoss.py deleted file mode 100755 index 014ce38..0000000 --- a/CoreFlows/examples/Python/DriftModel_1DPressureLoss.py +++ /dev/null @@ -1,99 +0,0 @@ -#!/usr/bin/env python -# -*-coding:utf-8 -* - -import CoreFlows as cf -import cdmath as cm - -def DriftModel_1DPressureLoss(): - - spaceDim = 1; - # Prepare for the mesh - print("Building mesh " ); - xinf = 0 ; - xsup=4.2; - nx=50; - M=cm.Mesh(xinf,xsup,nx) - - # set the limit field for each boundary - - inletConc=0; - inletVelocityX=1; - inletTemperature=565; - outletPressure=155e5; - - # physical parameters - pressureLossField=cm.Field("PressureLossCoeff", cm.FACES, M, 1); - nbFaces=M.getNumberOfFaces(); - - for i in range (nbFaces): - pressureLossField[i]=0 - pressureLossField[nx/4]=50; - pressureLossField[nx/2]=100; - pressureLossField[3*nx/4]=150; - - myProblem = cf.DriftModel(cf.around155bars600K,spaceDim); - nVar = myProblem.getNumberOfVariables(); - - # Prepare for the initial condition - VV_Constant =[0]*nVar; - - # constant vector - VV_Constant[0] = inletConc; - VV_Constant[1] = outletPressure ; - VV_Constant[2] = inletVelocityX; - VV_Constant[3] = inletTemperature ; - - - #Initial field creation - print("Building initial data " ); - myProblem.setInitialFieldConstant( spaceDim, VV_Constant, xinf, xsup, nx,"inlet","outlet"); - - # set the boundary conditions - myProblem.setInletBoundaryCondition("inlet",inletTemperature,inletConc,inletVelocityX) - myProblem.setOutletBoundaryCondition("outlet", outletPressure,[xsup]); - - # set physical parameters - myProblem.setPressureLossField(pressureLossField); - - # set the numerical method - myProblem.setNumericalScheme(cf.upwind, cf.Explicit); - myProblem.setWellBalancedCorrection(True); - myProblem.setNonLinearFormulation(cf.VFFC) - - # name of result file - fileName = "1DPressureLossUpwindWB"; - - # simulation parameters - MaxNbOfTimeStep = 3 ; - freqSave = 1; - cfl = 0.95; - maxTime = 500; - precision = 1e-5; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - myProblem.setNewtonSolver(precision,20); - myProblem.saveConservativeField(True); - - # evolution - myProblem.initialize(); - - ok = myProblem.run(); - if (ok): - print( "Simulation python " + fileName + " is successful !" ); - pass - else: - print( "Simulation python " + fileName + " failed ! " ); - pass - - print( "------------ End of calculation !!! -----------" ); - - myProblem.terminate(); - return ok - -if __name__ == """__main__""": - DriftModel_1DPressureLoss() diff --git a/CoreFlows/examples/Python/DriftModel_1DRiemannProblem.py b/CoreFlows/examples/Python/DriftModel_1DRiemannProblem.py deleted file mode 100755 index f73d704..0000000 --- a/CoreFlows/examples/Python/DriftModel_1DRiemannProblem.py +++ /dev/null @@ -1,99 +0,0 @@ -#!/usr/bin/env python -# -*-coding:utf-8 -* - -import CoreFlows as cf -import cdmath as cm - -def DriftModel_1DRiemannProblem(): - - spaceDim = 1; - # Prepare for the mesh - print("Building mesh " ); - xinf = 0 ; - xsup=4.2; - nx=50; - discontinuity=(xinf+xsup)/2 - M=cm.Mesh(xinf,xsup,nx) - eps=1e-6 - M.setGroupAtPlan(xsup,0,eps,"RightBoundary") - M.setGroupAtPlan(xinf,0,eps,"LeftBoundary") - - # set the limit field for each boundary - - inletConc_Left=0; - inletVelocity_Left=1; - inletTemperature_Left=565; - outletPressure_Left=155e5; - - inletConc_Right=0; - inletVelocity_Right=1; - inletTemperature_Right=565; - outletPressure_Right=155.1e5; - - myProblem = cf.DriftModel(cf.around155bars600K,spaceDim); - nVar = myProblem.getNumberOfVariables(); - - # Prepare for the initial condition - VV_Constant_Left =cm.Vector(nVar) - VV_Constant_Right =cm.Vector(nVar) - - # constant vectors - VV_Constant_Left[0] = inletConc_Left ; - VV_Constant_Left[1] = outletPressure_Left; - VV_Constant_Left[2] = inletVelocity_Left; - VV_Constant_Left[3] = inletTemperature_Left ; - - VV_Constant_Right[0] = inletConc_Right ; - VV_Constant_Right[1] = outletPressure_Right; - VV_Constant_Right[2] = inletVelocity_Right; - VV_Constant_Right[3] = inletTemperature_Right ; - - - #Initial field creation - print("Building initial data " ); - myProblem.setInitialFieldStepFunction(M,VV_Constant_Left,VV_Constant_Right,discontinuity) - - # set the boundary conditions - myProblem.setNeumannBoundaryCondition("LeftBoundary") - myProblem.setNeumannBoundaryCondition("RightBoundary"); - - # set the numerical method - myProblem.setNumericalScheme(cf.upwind, cf.Explicit); - - # name of result file - fileName = "1DRiemannProblemUpwind"; - - # simulation parameters - MaxNbOfTimeStep = 3 ; - freqSave = 1; - cfl = 0.95; - maxTime = 500; - precision = 1e-6; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - myProblem.setNewtonSolver(precision,20); - myProblem.saveConservativeField(True); - - # evolution - myProblem.initialize(); - - ok = myProblem.run(); - if (ok): - print( "Simulation python " + fileName + " is successful !" ); - pass - else: - print( "Simulation python " + fileName + " failed ! " ); - pass - - print( "------------ End of calculation !!! -----------" ); - - myProblem.terminate(); - return ok - -if __name__ == """__main__""": - DriftModel_1DRiemannProblem() diff --git a/CoreFlows/examples/Python/DriftModel_1DVidangeReservoir.py b/CoreFlows/examples/Python/DriftModel_1DVidangeReservoir.py deleted file mode 100755 index 01fce36..0000000 --- a/CoreFlows/examples/Python/DriftModel_1DVidangeReservoir.py +++ /dev/null @@ -1,103 +0,0 @@ -#!/usr/bin/env python -# -*-coding:utf-8 -* - -import CoreFlows as cf -import cdmath as cm - -def DriftModel_1DVidangeReservoir(): - - spaceDim = 1; - # Prepare for the mesh - print("Building mesh " ); - xinf = 0. ; - xsup=1.0; - nx=50; - M=cm.Mesh(xinf,xsup,nx) - # set the limit field for each boundary - eps=1e-6; - M.setGroupAtPlan(xinf,0,eps,"outlet") - M.setGroupAtPlan(xsup,0,eps,"inlet") - - # set the limit field for each boundary - inletConc=1; - inletTemperature=300; - outletPressure=1e5; - - initialConcTop=1; - initialConcBottom=0.0001; - initialVelocityX=[0]; - initialPressure=1e5; - initialTemperature=300 - - # physical constants - gravite=[-10]; - - myProblem = cf.DriftModel(cf.around1bar300K,spaceDim); - nVar = myProblem.getNumberOfVariables(); - - # Prepare for the initial condition - VV_top =cm.Vector(nVar) - VV_bottom =cm.Vector(nVar) - - # top and bottom vectors - VV_top[0] = initialConcTop ; - VV_top[1] = initialPressure ; - VV_top[2] = initialVelocityX[0]; - VV_top[3] = initialTemperature - - VV_bottom[0] = initialConcBottom ; - VV_bottom[1] = initialPressure ; - VV_bottom[2] = initialVelocityX[0]; - VV_bottom[3] = initialTemperature - - #Initial field creation - print("Building initial data " ); - myProblem.setInitialFieldStepFunction( M, VV_bottom, VV_top, .8, 0); - - # the boundary conditions - myProblem.setInletPressureBoundaryCondition("inlet", outletPressure, inletTemperature, inletConc,[xinf]); - myProblem.setOutletBoundaryCondition("outlet", outletPressure,[xsup]); - - # set physical parameters - myProblem.setGravity(gravite); - - # set the numerical method - myProblem.setNumericalScheme(cf.upwind, cf.Explicit); - myProblem.setNonLinearFormulation(cf.VFFC) - - # name file save - fileName = "1DVidangeReservoir"; - - # simulation parameters - MaxNbOfTimeStep = 3 ; - freqSave = 1; - cfl = .95; - maxTime = 5.; - precision = 1e-5; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - - # evolution - myProblem.initialize(); - - ok = myProblem.run(); - if (ok): - print( "Simulation python " + fileName + " is successful !" ); - pass - else: - print( "Simulation python " + fileName + " failed ! " ); - pass - - print( "------------ End of calculation !!! -----------" ); - - myProblem.terminate(); - return ok - - -if __name__ == """__main__""": - DriftModel_1DVidangeReservoir() diff --git a/CoreFlows/examples/Python/DriftModel_2BranchesBoilingChannels.py b/CoreFlows/examples/Python/DriftModel_2BranchesBoilingChannels.py deleted file mode 100755 index f6c0f92..0000000 --- a/CoreFlows/examples/Python/DriftModel_2BranchesBoilingChannels.py +++ /dev/null @@ -1,97 +0,0 @@ -#!/usr/bin/env python -# -*-coding:utf-8 -* - -import CoreFlows as cf -import cdmath as cm - - -def DriftModel_2BranchesBoilingChannels(): - - spaceDim = 1; - # Prepare for the mesh - M=cm.Mesh("../resources/BifurcatingFlow2BranchesEqualSections.med") - M.getFace(0).setGroupName("Inlet")#z=0 - M.getFace(31).setGroupName("Outlet")#z=4.2 - - # set the initial field - initialConc=0; - initialPressure=155e5; - initialVelocityX=5; - initialTemperature=573; - - # set the limit field for each boundary - inletConc=0; - inletVelocityX=5; - inletTemperature=573; - outletPressure=155e5 - - myProblem = cf.DriftModel(cf.around155bars600K,spaceDim); - nVar = myProblem.getNumberOfVariables(); - - # Prepare for the initial condition - VV_Constant =[0]*nVar; - - # constant vector - VV_Constant[0] = initialConc ; - VV_Constant[1] = initialPressure ; - VV_Constant[2] = initialVelocityX; - VV_Constant[3] = initialTemperature ; - - - #Initial field creation - print("Building initial data" ); - myProblem.setInitialFieldConstant( M, VV_Constant); - - # set the boundary conditions - myProblem.setInletBoundaryCondition("Inlet", inletTemperature, inletConc,inletVelocityX); - myProblem.setOutletBoundaryCondition("Outlet",outletPressure); - - #set porosity, heat and gravity source - Sections=cm.Field("../resources/BifurcatingFlow2BranchesEqualSections", cm.CELLS,"Section area"); - heatPowerField=cm.Field("../resources/BifurcatingFlow2BranchesEqualSections", cm.CELLS,"Heat power"); - myProblem.setSectionField(Sections); - myProblem.setHeatPowerField(heatPowerField) - gravite=[-10] - myProblem.setGravity(gravite) - # set the numerical method - myProblem.setNumericalScheme(cf.upwind, cf.Explicit); - myProblem.setWellBalancedCorrection(True) - myProblem.setNonLinearFormulation(cf.VFFC) - - # name of result file - fileName = "2BranchesBoilingChannels"; - - # simulation parameters - MaxNbOfTimeStep = 3 ; - freqSave = 1; - cfl = 0.5; - maxTime = 500; - precision = 1e-6; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - myProblem.setNewtonSolver(precision,20); - myProblem.saveConservativeField(True); - - # evolution - myProblem.initialize(); - - ok = myProblem.run(); - if (ok): - print( "Simulation python " + fileName + " is successful !" ); - pass - else: - print( "Simulation python " + fileName + " failed ! " ); - pass - - print( "------------ End of calculation !!! -----------" ); - - myProblem.terminate(); - return ok - -if __name__ == """__main__""": - DriftModel_2BranchesBoilingChannels() diff --git a/CoreFlows/examples/Python/DriftModel_2DBoilingChannelBarrier.py b/CoreFlows/examples/Python/DriftModel_2DBoilingChannelBarrier.py deleted file mode 100755 index 387b13b..0000000 --- a/CoreFlows/examples/Python/DriftModel_2DBoilingChannelBarrier.py +++ /dev/null @@ -1,134 +0,0 @@ -#!/usr/bin/env python -# -*-coding:utf-8 -* - - -import CoreFlows as cf -import cdmath as cm - - -def DriftModel_2DBoilingChannelBarrier(): - - spaceDim = 2; - # Prepare for the mesh - print("Building mesh " ); - xinf = 0 ; - xsup=2.0; - yinf=0.0; - ysup=4.0; - nx=20; - ny=40; - cloison=(xinf+xsup)/2 - M=cm.Mesh(xinf,xsup,nx,yinf,ysup,ny) - # set the limit field for each boundary - eps=1e-6; - M.setGroupAtPlan(xsup,0,eps,"wall") - M.setGroupAtPlan(xinf,0,eps,"wall") - M.setGroupAtPlan(ysup,1,eps,"outlet") - M.setGroupAtPlan(yinf,1,eps,"inlet") - dy=(ysup-yinf)/ny - ncloison=ny/2 - i=0 - while i<= ncloison+1: - M.setGroupAtFaceByCoords(cloison,((ysup-yinf)/4)+(i+0.5)*dy,0,eps,"wall") - i=i+1 - - - # set the limit field for each boundary - wallVelocityX=0; - wallVelocityY=0; - wallTemperature=573; - inletConc=0; - inletVelocityX=0; - inletVelocityY=1; - inletTemperature=563; - outletPressure=155e5; - - # physical constants - gravite = [0] * spaceDim - - gravite[0]=0; - gravite[1]=-10; - - heatPower=1e8; - heatPower_nul=0; - - myProblem = cf.DriftModel(cf.around155bars600K,spaceDim); - nVar =myProblem.getNumberOfVariables(); - heatPowerField=cm.Field("heatPowerField", cm.CELLS, M, 1); - - nbCells=M.getNumberOfCells(); - - for i in range (nbCells): - x=M.getCell(i).x(); - y=M.getCell(i).y(); - if (y> (ysup-yinf)/4) and (y< (ysup-yinf)*3/4) and (x1): - myProblem.saveVelocity(); - pass - - # evolution - myProblem.initialize(); - - ok = myProblem.run(); - if (ok): - print( "Simulation python " + fileName + " is successful !" ); - pass - else: - print( "Simulation python " + fileName + " failed ! " ); - pass - - print( "------------ End of calculation !!! -----------" ); - - myProblem.terminate(); - return ok - -if __name__ == """__main__""": - DriftModel_2DInclinedBoilingChannel() diff --git a/CoreFlows/examples/Python/DriftModel_2DInclinedBoilingChannelBarrier.py b/CoreFlows/examples/Python/DriftModel_2DInclinedBoilingChannelBarrier.py deleted file mode 100755 index c024637..0000000 --- a/CoreFlows/examples/Python/DriftModel_2DInclinedBoilingChannelBarrier.py +++ /dev/null @@ -1,133 +0,0 @@ -#!/usr/bin/env python -# -*-coding:utf-8 -* - - -import CoreFlows as cf -import cdmath as cm - - -def DriftModel_2DInclinedBoilingChannelBarrier(): - - spaceDim = 2; - # Prepare for the mesh - print("Building mesh " ); - xinf = 0 ; - xsup=2.0; - yinf=0.0; - ysup=4.0; - nx=20; - ny=40; - cloison=(xinf+xsup)/2 - M=cm.Mesh(xinf,xsup,nx,yinf,ysup,ny) - # set the limit field for each boundary - eps=1e-6; - M.setGroupAtPlan(xsup,0,eps,"wall") - M.setGroupAtPlan(xinf,0,eps,"wall") - M.setGroupAtPlan(ysup,1,eps,"outlet") - M.setGroupAtPlan(yinf,1,eps,"inlet") - dy=(ysup-yinf)/ny - ncloison=ny/2 - i=0 - while i<= ncloison+1: - M.setGroupAtFaceByCoords(cloison,((ysup-yinf)/4)+(i+0.5)*dy,0,eps,"wall") - i=i+1 - - - # set the limit field for each boundary - wallVelocityX=0; - wallVelocityY=0; - wallTemperature=573; - inletConc=0; - inletVelocityX=0; - inletVelocityY=1; - inletTemperature=563; - outletPressure=155e5; - - # source terms - gravite = [0] * spaceDim - - gravite[0]=7; - gravite[1]=-7; - - heatPower=1e8; - heatPower_nul=0; - heatPowerField=cm.Field("heatPowerField", cm.CELLS, M, 1); - - nbCells=M.getNumberOfCells(); - - for i in range (nbCells): - x=M.getCell(i).x(); - y=M.getCell(i).y(); - if (y> (ysup-yinf)/4) and (y< (ysup-yinf)*3/4) and (x yinf+(ysup-yinf)/4) and (abs(x-xcloison1)< eps or abs(x-xcloison2)< eps)) or abs(x-xinf)< eps or abs(x-xsup)< eps : - barrierField[i]=1 - else: - barrierField[i]=0 - barrierField.writeVTK("barrierField",True) - - # set the limit field for each boundary - wallVelocityX=0; - wallVelocityY=0; - wallTemperature=563; - inletConcentration=0; - inletVelocityX=0; - inletVelocityY=1; - inletTemperature=563; - outletPressure=155e5; - - # physical constants - gravite = [0] * spaceDim - - gravite[1]=-8.5; - gravite[0]=5; - - heatPower=0e8; - - myProblem = cf.DriftModel(cf.around155bars600K,spaceDim); - nVar =myProblem.getNumberOfVariables(); - - # Prepare for the initial condition - VV_Constant =[0]*nVar - - # constant vector - VV_Constant[0] = inletConcentration; - VV_Constant[1] = outletPressure ; - VV_Constant[2] = inletVelocityX; - VV_Constant[3] = inletVelocityY; - VV_Constant[4] = inletTemperature ; - - #Initial field creation - print("Building mesh and initial data " ); - myProblem.setInitialFieldConstant(M,VV_Constant) - - # the boundary conditions - myProblem.setOutletBoundaryCondition("outlet", outletPressure,[xsup,ysup]); - myProblem.setInletBoundaryCondition("inlet", inletTemperature, inletConcentration, inletVelocityX, inletVelocityY); - myProblem.setWallBoundaryCondition("wall", wallTemperature, wallVelocityX, wallVelocityY); - - # set physical parameters - myProblem.setHeatSource(heatPower); - myProblem.setGravity(gravite); - - # set the numerical method - myProblem.setNumericalScheme(cf.staggered, cf.Implicit); - myProblem.setWellBalancedCorrection(True); - myProblem.setNonLinearFormulation(cf.VFFC) - - # name of result file - fileName = "2DInclinedChannelVFFCStaggeredWB3x100CFL100"; - - # simulation parameters - MaxNbOfTimeStep = 3 ; - freqSave = 1000; - cfl = 100; - maxTime = 500; - precision = 1e-6; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - myProblem.usePrimitiveVarsInNewton(True) - - # evolution - myProblem.initialize(); - - ok = myProblem.run(); - if (ok): - print( "Simulation python " + fileName + " is successful !" ); - pass - else: - print( "Simulation python " + fileName + " failed ! " ); - pass - - print( "------------ End of calculation !!! -----------" ); - - myProblem.terminate(); - return ok - -if __name__ == """__main__""": - DriftModel_2DInclinedBoilingChannel() diff --git a/CoreFlows/examples/Python/DriftModel_2DInclinedChannelGravityTriangles.py b/CoreFlows/examples/Python/DriftModel_2DInclinedChannelGravityTriangles.py deleted file mode 100755 index 5675db9..0000000 --- a/CoreFlows/examples/Python/DriftModel_2DInclinedChannelGravityTriangles.py +++ /dev/null @@ -1,106 +0,0 @@ -#!/usr/bin/env python -# -*-coding:utf-8 -* - -import CoreFlows as cf - -def DriftModel_2DInclinedBoilingChannel(): - spaceDim = 2; - - # Prepare for the mesh - print( "Loading unstructured mesh " ); - inputfile="../resources/CanalTrianglesStructures.med"; - xinf = 0 ; - xsup=1.0; - yinf=0.0; - ysup=4.0; - nx=10; - ny=40; - - # set the limit field for each boundary - wallVelocityX=0; - wallVelocityY=0; - wallTemperature=563; - inletConcentration=0; - inletVelocityX=0; - inletVelocityY=1; - inletTemperature=563; - outletPressure=155e5; - - # physical constants - gravite = [0] * spaceDim - - gravite[1]=-8.5; - gravite[0]=5; - - heatPower=0e8; - - myProblem = cf.DriftModel(cf.around155bars600K,spaceDim); - nVar =myProblem.getNumberOfVariables(); - - # Prepare for the initial condition - VV_Constant =[0]*nVar - - # constant vector - VV_Constant[0] = inletConcentration; - VV_Constant[1] = outletPressure ; - VV_Constant[2] = inletVelocityX; - VV_Constant[3] = inletVelocityY; - VV_Constant[4] = inletTemperature ; - - #Initial field creation - print("Building mesh and initial data " ); - myProblem.setInitialFieldConstant(spaceDim,VV_Constant, - xinf,xsup,nx,"wall","wall", - yinf,ysup,ny,"inlet","outlet", - 0.0,0.0, 0, "", "") - - # the boundary conditions - myProblem.setOutletBoundaryCondition("outlet", outletPressure,[xsup,ysup]); - myProblem.setInletBoundaryCondition("inlet", inletTemperature, inletConcentration, inletVelocityX, inletVelocityY); - myProblem.setWallBoundaryCondition("wall", wallTemperature, wallVelocityX, wallVelocityY); - - # set physical parameters - myProblem.setHeatSource(heatPower); - myProblem.setGravity(gravite); - - # set the numerical method - myProblem.setNumericalScheme(cf.staggered, cf.Implicit); - myProblem.setWellBalancedCorrection(True); - myProblem.setNonLinearFormulation(cf.VFFC) - - # name of result file - fileName = "2DInclinedChannelGravityTriangles"; - - # simulation parameters - MaxNbOfTimeStep = 3 ; - freqSave = 1; - cfl = 0.5; - maxTime = 500; - precision = 1e-6; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - myProblem.usePrimitiveVarsInNewton(True) - - # evolution - myProblem.initialize(); - - ok = myProblem.run(); - if (ok): - print( "Simulation python " + fileName + " is successful !" ); - pass - else: - print( "Simulation python " + fileName + " failed ! " ); - pass - - print( "------------ End of calculation !!! -----------" ); - - myProblem.terminate(); - return ok - -if __name__ == """__main__""": - DriftModel_2DInclinedBoilingChannel() diff --git a/CoreFlows/examples/Python/DriftModel_2DPorosityJump.py b/CoreFlows/examples/Python/DriftModel_2DPorosityJump.py deleted file mode 100755 index d306e92..0000000 --- a/CoreFlows/examples/Python/DriftModel_2DPorosityJump.py +++ /dev/null @@ -1,119 +0,0 @@ -#!/usr/bin/env python -# -*-coding:utf-8 -* - - -import CoreFlows as cf -import cdmath as cm -import math - -def DriftModel_2DPorosityJump(): - spaceDim = 2; - - # Prepare for the mesh - print("Building mesh " ); - xinf = 0 ; - xsup=1.5; - yinf=0.0; - ysup=0.8; - nx=20; - ny=20; - discontinuity=(xinf+xsup)/2 - M=cm.Mesh(xinf,xsup,nx,yinf,ysup,ny) - # set the limit field for each boundary - eps=1e-6; - M.setGroupAtPlan(xsup,0,eps,"Outlet") - M.setGroupAtPlan(xinf,0,eps,"Inlet") - M.setGroupAtPlan(ysup,1,eps,"Wall") - M.setGroupAtPlan(yinf,1,eps,"Wall") - dx=(xsup-xinf)/nx - ndis=(discontinuity-xinf)/dx - - - # set the limit field for each boundary - inletConc=0; - inletVelocityX=1. ; - inletVelocityY=0 ; - inletTemperature=563 ; - outletPressure=155e5 ; - - - # physical parameters - porosityField=cm.Field("Porosity",cm.CELLS,M,1); - for i in xrange(M.getNumberOfCells()): - x=M.getCell(i).x(); - y=M.getCell(i).y(); - if x > (xsup-xinf)/3. and x<(xsup-xinf)*2./3 and y> (ysup-yinf)/4. and y<(ysup-yinf)*3./4: - porosityField[i]=0.5; - else: - porosityField[i]=1; - pass - porosityField.writeVTK("PorosityField"); - - myProblem = cf.DriftModel(cf.around155bars600K,spaceDim); - nVar =myProblem.getNumberOfVariables(); - - # Prepare for the initial condition - VV_Constant =cm.Vector(nVar) - - # constant vectorsetOutletBoundaryCondition - VV_Constant[0] = inletConc; - VV_Constant[1] = outletPressure ; - VV_Constant[2] = inletVelocityX; - VV_Constant[3] = inletVelocityY; - VV_Constant[4] = inletTemperature ; - - # set physical parameters - myProblem.setPorosityField(porosityField); - - print("Building initial data"); - myProblem.setInitialFieldConstant(M,VV_Constant) - - - # the boundary conditions - myProblem.setOutletBoundaryCondition("Outlet", outletPressure); - myProblem.setInletBoundaryCondition("Inlet", inletTemperature,inletConc, inletVelocityX, inletVelocityY); - myProblem.setWallBoundaryCondition("Wall", inletTemperature, 0,0); - myProblem.setNonLinearFormulation(cf.VFFC) - - - # set the numerical method - myProblem.setNumericalScheme(cf.upwind, cf.Explicit); - myProblem.setWellBalancedCorrection(True); - - # name file save - fileName = "2DPorosityJump"; - - # parameters calculation - MaxNbOfTimeStep = 3 ; - freqSave = 1; - cfl = 0.5; - maxTime = 5000; - precision = 1e-4; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - myProblem.setNewtonSolver(1e10,20); - myProblem.saveVelocity(); - - # evolution - myProblem.initialize(); - - ok = myProblem.run(); - if (ok): - print( "Simulation python " + fileName + " is successful !" ); - pass - else: - print( "Simulation python " + fileName + " failed ! " ); - pass - - print( "------------ End of calculation !!! -----------" ); - - myProblem.terminate(); - return ok - -if __name__ == """__main__""": - DriftModel_2DPorosityJump() diff --git a/CoreFlows/examples/Python/DriftModel_2DPressureLoss.py b/CoreFlows/examples/Python/DriftModel_2DPressureLoss.py deleted file mode 100755 index 2d3a802..0000000 --- a/CoreFlows/examples/Python/DriftModel_2DPressureLoss.py +++ /dev/null @@ -1,144 +0,0 @@ -#!/usr/bin/env python -# -*-coding:utf-8 -* - - -import CoreFlows as cf -import cdmath as cm -import math - -def DriftModel_2DPressureLoss(): - spaceDim = 2; - - # Prepare for the mesh - print("Building mesh " ); - xinf = 0 ; - xsup=0.42; - yinf=0.0; - ysup=4.2; - nx=2; - ny=100; - discontinuity=(xinf+xsup)/2 - M=cm.Mesh(xinf,xsup,nx,yinf,ysup,ny) - # set the limit field for each boundary - eps=1e-6; - M.setGroupAtPlan(xsup,0,eps,"RightWall") - M.setGroupAtPlan(xinf,0,eps,"LeftWall") - M.setGroupAtPlan(ysup,1,eps,"outlet") - dx=(xsup-xinf)/nx - ndis=(discontinuity-xinf)/dx - print("ndis=",math.floor(ndis) ); - i=0 -# while i<= ndis: - M.setGroupAtFaceByCoords(xinf+(i+0.5)*dx,yinf,0,eps,"inlet_1") - i=1 -# while i<= nx: - M.setGroupAtFaceByCoords(xinf+(i+0.5)*dx,yinf,0,eps,"inlet_2") - - - - # set the limit field for each boundary - inletConc=0; - inletVelocityX1=0. ; - inletVelocityY1=2.7 ; - inletVelocityX2=0 ; - inletVelocityY2=1.5 ; - inletTemperature=563 ; - outletPressure=155e5 ; - - - # physical parameters - pressureLossField=cm.Field("PressureLossCoeff", cm.FACES, M, 1); - nbFaces=M.getNumberOfFaces(); - - for i in range (nbFaces): - if abs(M.getFace(i).y() - 1.0500) zcloisonmin) and (z< zcloisonmax) : - if (yxcloison): - heatPowerField[i]=heatPower2 - if (y>ycloison) and (xycloison) and (x>xcloison): - heatPowerField[i]=heatPower4 - else: - heatPowerField[i]=0 - - heatPowerField.writeVTK("heatPowerField",True) - - # Prepare for the initial condition - VV_Constant =[0]*nVar - - # constant vector - VV_Constant[0] = inletConc ; - VV_Constant[1] = outletPressure ; - VV_Constant[2] = inletVelocityX; - VV_Constant[3] = inletVelocityY; - VV_Constant[4] = inletVelocityZ; - VV_Constant[5] = inletTemperature ; - - #Initial field creation - print("Building initial data " ); - myProblem.setInitialFieldConstant(M,VV_Constant) - - # the boundary conditions - myProblem.setOutletBoundaryCondition("outlet", outletPressure,[xsup,ysup,zsup]); - myProblem.setInletBoundaryCondition("inlet", inletTemperature, inletConc, inletVelocityX, inletVelocityY, inletVelocityZ); - myProblem.setWallBoundaryCondition("wall", wallTemperature, wallVelocityX, wallVelocityY,wallVelocityZ); - - # set physical parameters - myProblem.setHeatPowerField(heatPowerField) - myProblem.setGravity(gravite); - - # set the numerical method - myProblem.setNumericalScheme(cf.upwind, cf.Explicit); - myProblem.setLinearSolver(cf.GMRES,cf.ILU,True); - myProblem.setWellBalancedCorrection(True); - - # name file save - fileName = "3DBoilingChannelBarrier"; - - # parameters calculation - MaxNbOfTimeStep = 3; - freqSave = 100; - cfl = .3; - maxTime = 5000; - precision = 1e-6; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - myProblem.setNewtonSolver(precision,20); - myProblem.saveVelocity(); - - # evolution - myProblem.initialize(); - print("Running python "+ fileName ); - - ok = myProblem.run(); - if (ok): - print( "Simulation python " + fileName + " is successful !" ); - pass - else: - print( "Simulation python " + fileName + " failed ! " ); - pass - - print( "------------ End of calculation !!! -----------" ); - - myProblem.terminate(); - return ok - -if __name__ == """__main__""": - DriftModel_3DBoilingChannelBarrier() diff --git a/CoreFlows/examples/Python/FiveEqsTwoFluid/FiveEqsTwoFluid_1DBoilingAssembly.py b/CoreFlows/examples/Python/FiveEqsTwoFluid/FiveEqsTwoFluid_1DBoilingAssembly.py new file mode 100755 index 0000000..c9f3bb0 --- /dev/null +++ b/CoreFlows/examples/Python/FiveEqsTwoFluid/FiveEqsTwoFluid_1DBoilingAssembly.py @@ -0,0 +1,111 @@ +#!/usr/bin/env python +# -*-coding:utf-8 -* + +import CoreFlows as cf +import cdmath as cm + +def FiveEqsTwoFluid_1DBoilingAssembly(): + + spaceDim = 1; + # Prepare for the mesh + print("Building mesh " ); + xinf = 0 ; + xsup=4.2; + nx=50; + M=cm.Mesh(xinf,xsup,nx) + eps=1e-6; + M.setGroupAtPlan(xsup,0,eps,"outlet") + M.setGroupAtPlan(xinf,0,eps,"inlet") + + # set the limit field for each boundary + + inletVoidFraction=0; + inletVelocityX=[1]*2; + inletTemperature=563; + outletPressure=155e5; + + # physical constants + heatPowerField=cm.Field("heatPowerField", cm.CELLS, M, 1); + + nbCells=M.getNumberOfCells(); + + for i in range (nbCells): + x=M.getCell(i).x(); + if (x> (xsup-xinf)/4) and (x< (xsup-xinf)*3/4): + heatPowerField[i]=1e8 + else: + heatPowerField[i]=0 + heatPowerField.writeVTK("heatPowerField",True) + + + myProblem = cf.FiveEqsTwoFluid(cf.around155bars600K,spaceDim); + nVar = myProblem.getNumberOfVariables(); + + # Prepare for the initial condition + VV_Constant =[0]*nVar; + + # constant vector + VV_Constant[0] = inletVoidFraction; + VV_Constant[1] = outletPressure ; + VV_Constant[2] = inletVelocityX[0]; + VV_Constant[3] = inletVelocityX[1]; + VV_Constant[4] = inletTemperature ; + + + #Initial field creation + print("Building initial data " ); + myProblem.setInitialFieldConstant(M,VV_Constant) + + # set the boundary conditions + myProblem.setInletBoundaryCondition("inlet",inletVoidFraction,inletTemperature,inletVelocityX) + myProblem.setOutletBoundaryCondition("outlet", outletPressure); + + # set physical parameters + myProblem.setHeatPowerField(heatPowerField) + + # set the numerical method + myProblem.setNumericalScheme(cf.upwind, cf.Explicit); + myProblem.setEntropicCorrection(True); + myProblem.setWellBalancedCorrection(True); + + # name of result file + fileName = "1DBoilingAssembly"; + + # simulation parameters + MaxNbOfTimeStep = 3 ; + freqSave = 1; + cfl = 0.5; + maxTime = 500; + precision = 1e-6; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + myProblem.setNewtonSolver(precision,20); + #myProblem.saveConservativeField(True); + if(spaceDim>1): + myProblem.saveVelocity(); + pass + + # evolution + myProblem.initialize(); + print("Running python "+ fileName ); + + ok = myProblem.run(); + if (ok): + print( "Simulation python " + fileName + " is successful !" ); + pass + else: + print( "Simulation python " + fileName + " failed ! " ); + pass + + print( "------------ End of calculation !!! -----------" ); + + myProblem.terminate(); + return ok + +if __name__ == """__main__""": + FiveEqsTwoFluid_1DBoilingAssembly() diff --git a/CoreFlows/examples/Python/FiveEqsTwoFluid/FiveEqsTwoFluid_1DBoilingChannel.py b/CoreFlows/examples/Python/FiveEqsTwoFluid/FiveEqsTwoFluid_1DBoilingChannel.py new file mode 100755 index 0000000..4b011d2 --- /dev/null +++ b/CoreFlows/examples/Python/FiveEqsTwoFluid/FiveEqsTwoFluid_1DBoilingChannel.py @@ -0,0 +1,94 @@ +#!/usr/bin/env python +# -*-coding:utf-8 -* + +import CoreFlows as cf + +def FiveEqsTwoFluid_1DBoilingChannel(): + + spaceDim = 1; + # Prepare for the mesh + xinf = 0 ; + xsup=4.2; + nx=50; + + # set the limit field for each boundary + + inletVoidFraction=0; + inletVelocityX=[1]*2; + inletTemperature=563; + outletPressure=155e5; + + # physical constants + heatPower=1e8; + + myProblem = cf.FiveEqsTwoFluid(cf.around155bars600K,spaceDim); + nVar = myProblem.getNumberOfVariables(); + + # Prepare for the initial condition + VV_Constant =[0]*nVar; + + # constant vector + VV_Constant[0] = inletVoidFraction; + VV_Constant[1] = outletPressure ; + VV_Constant[2] = inletVelocityX[0]; + VV_Constant[3] = inletVelocityX[1]; + VV_Constant[4] = inletTemperature ; + + + #Initial field creation + print("Building mesh and initial data " ); + myProblem.setInitialFieldConstant( spaceDim, VV_Constant, xinf, xsup, nx,"inlet","outlet"); + + # set the boundary conditions + myProblem.setInletBoundaryCondition("inlet",inletVoidFraction,inletTemperature,inletVelocityX) + myProblem.setOutletBoundaryCondition("outlet", outletPressure); + + # set physical parameters + myProblem.setHeatSource(heatPower); + + # set the numerical method + myProblem.setNumericalScheme(cf.upwind, cf.Explicit); + myProblem.setEntropicCorrection(True); + myProblem.setWellBalancedCorrection(True); + + # name of result file + fileName = "1DBoilingChannel"; + + # simulation parameters + MaxNbOfTimeStep = 3 ; + freqSave = 1; + cfl = 0.5; + maxTime = 500; + precision = 1e-6; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + myProblem.setNewtonSolver(precision,20); + #myProblem.saveConservativeField(True); + if(spaceDim>1): + myProblem.saveVelocity(); + pass + + # evolution + myProblem.initialize(); + print("Running python "+ fileName ); + + ok = myProblem.run(); + if (ok): + print( "Simulation python " + fileName + " is successful !" ); + pass + else: + print( "Simulation python " + fileName + " failed ! " ); + pass + + print( "------------ End of calculation !!! -----------" ); + + myProblem.terminate(); + return ok + +if __name__ == """__main__""": + FiveEqsTwoFluid_1DBoilingChannel() diff --git a/CoreFlows/examples/Python/FiveEqsTwoFluid/FiveEqsTwoFluid_1DVidangeReservoir.py b/CoreFlows/examples/Python/FiveEqsTwoFluid/FiveEqsTwoFluid_1DVidangeReservoir.py new file mode 100755 index 0000000..75436f6 --- /dev/null +++ b/CoreFlows/examples/Python/FiveEqsTwoFluid/FiveEqsTwoFluid_1DVidangeReservoir.py @@ -0,0 +1,107 @@ +#!/usr/bin/env python +# -*-coding:utf-8 -* + +import CoreFlows as cf +import cdmath as cm + +def FiveEqsTwoFluid_1DVidangeReservoir(): + + spaceDim = 1; + # Prepare for the mesh + print("Building mesh " ); + xinf = 0. ; + xsup=1.0; + nx=50; + M=cm.Mesh(xinf,xsup,nx) + # set the limit field for each boundary + eps=1e-6; + M.setGroupAtPlan(xinf,0,eps,"wall") + M.setGroupAtPlan(xsup,0,eps,"inlet") + + # set the limit field for each boundary + wallVelocityX=[0] * 2 + wallTemperature=300 + + # set the limit field for each boundary + initialAlphaTop=1; + initialAlphaBottom=0.; + initialVelocityX=[0]*2; + initialPressure=1e5; + initialTemperature=300 + + # physical constants + gravite=[-10]; + + myProblem = cf.FiveEqsTwoFluid(cf.around1bar300K,spaceDim); + nVar = myProblem.getNumberOfVariables(); + + # Prepare for the initial condition + VV_top =cm.Vector(nVar) + VV_bottom =cm.Vector(nVar) + + # top and bottom vectors + VV_top[0] = initialAlphaTop ; + VV_top[1] = initialPressure ; + VV_top[2] = initialVelocityX[0]; + VV_top[3] = initialVelocityX[1]; + VV_top[4] = initialTemperature + + VV_bottom[0] = initialAlphaBottom ; + VV_bottom[1] = initialPressure ; + VV_bottom[2] = initialVelocityX[0]; + VV_bottom[3] = initialVelocityX[1]; + VV_bottom[4] = initialTemperature + + #Initial field creation + print("Building initial data " ); + myProblem.setInitialFieldStepFunction( M, VV_bottom, VV_top, .8, 0); + + # the boundary conditions + myProblem.setWallBoundaryCondition("wall",initialTemperature, wallVelocityX); + myProblem.setNeumannBoundaryCondition("inlet"); + + # set physical parameters + myProblem.setGravity(gravite); + + # set the numerical method + myProblem.setNumericalScheme(cf.upwind, cf.Explicit); + #myProblem.setEntropicCorrection(True); + myProblem.setNonLinearFormulation(cf.VFFC) + + # name file save + fileName = "1DVidangeReservoir"; + + # simulation parameters + MaxNbOfTimeStep = 3 ; + freqSave = 1; + cfl = .1; + maxTime = 5.; + precision = 1e-6; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + + # evolution + myProblem.initialize(); + + ok = myProblem.run(); + if (ok): + print( "Simulation python " + fileName + " is successful !" ); + pass + else: + print( "Simulation python " + fileName + " failed ! " ); + pass + + print( "------------ End of calculation !!! -----------" ); + + myProblem.terminate(); + + return ok + + +if __name__ == """__main__""": + FiveEqsTwoFluid_1DVidangeReservoir() diff --git a/CoreFlows/examples/Python/FiveEqsTwoFluid/FiveEqsTwoFluid_2DInclinedBoilingChannel.py b/CoreFlows/examples/Python/FiveEqsTwoFluid/FiveEqsTwoFluid_2DInclinedBoilingChannel.py new file mode 100755 index 0000000..932b15c --- /dev/null +++ b/CoreFlows/examples/Python/FiveEqsTwoFluid/FiveEqsTwoFluid_2DInclinedBoilingChannel.py @@ -0,0 +1,113 @@ +#!/usr/bin/env python +# -*-coding:utf-8 -* + + +import CoreFlows as cf + +def FiveEqsTwoFluid_2DInclinedBoilingChannel(): + spaceDim = 2; + + # Prepare for the mesh + xinf = 0 ; + xsup=2; + yinf=0.0; + ysup=4; + nx=20; + ny=40; + + # set the limit field for each boundary + wallVelocityX=[0]; + wallVelocityY=[0]; + wallTemperature=573; + inletVoidFraction=0; + inletVelocityX=[0]*2; + inletVelocityY=[1]*2; + inletTemperature=573; + outletPressure=155e5; + + # physical constants + gravite = [0] * spaceDim + + gravite[1]=-7; + gravite[0]=7; + + heatPower=5e7; + + myProblem = cf.FiveEqsTwoFluid(cf.around155bars600K,spaceDim); + nVar =myProblem.getNumberOfVariables(); + + # Prepare for the initial condition + VV_Constant =[0]*nVar + + # constant vector + VV_Constant[0] = inletVoidFraction; + VV_Constant[1] = outletPressure ; + VV_Constant[2] = inletVelocityX[0]; + VV_Constant[3] = inletVelocityY[0]; + VV_Constant[4] = inletVelocityX[1]; + VV_Constant[5] = inletVelocityY[1]; + VV_Constant[6] = inletTemperature ; + + #Initial field creation + print("Building mesh and initial data " ); + myProblem.setInitialFieldConstant(spaceDim,VV_Constant, + xinf,xsup,nx,"wall","wall", + yinf,ysup,ny,"inlet","outlet", + 0.0,0.0, 0, "", "") + + # the boundary conditions + myProblem.setOutletBoundaryCondition("outlet", outletPressure); + myProblem.setInletBoundaryCondition("inlet", inletVoidFraction, inletTemperature, inletVelocityX, inletVelocityY); + myProblem.setWallBoundaryCondition("wall", wallTemperature, wallVelocityX, wallVelocityY); + + # set physical parameters + myProblem.setHeatSource(heatPower); + myProblem.setGravity(gravite); + + # set the numerical method + myProblem.setNumericalScheme(cf.upwind, cf.Explicit); + myProblem.setLinearSolver(cf.GMRES,cf.ILU,True); + myProblem.setEntropicCorrection(True); + #myProblem.setWellBalancedCorrection(True); + + # name of result file + fileName = "2DInclinedBoilingChannel"; + + # simulation parameters + MaxNbOfTimeStep = 3 ; + freqSave = 1; + cfl = 0.25; + maxTime = 5; + precision = 1e-6; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + myProblem.setNewtonSolver(precision,20); + #myProblem.saveConservativeField(True); + if(spaceDim>1): + myProblem.saveVelocity(); + pass + + # evolution + myProblem.initialize(); + print("Running python "+ fileName ); + + ok = myProblem.run(); + if (ok): + print( "Simulation python " + fileName + " is successful !" ); + pass + else: + print( "Simulation python " + fileName + " failed ! " ); + pass + + print( "------------ End of calculation !!! -----------" ); + + myProblem.terminate(); + return ok + +if __name__ == """__main__""": + FiveEqsTwoFluid_2DInclinedBoilingChannel() diff --git a/CoreFlows/examples/Python/FiveEqsTwoFluid/FiveEqsTwoFluid_2DInclinedSedimentation.py b/CoreFlows/examples/Python/FiveEqsTwoFluid/FiveEqsTwoFluid_2DInclinedSedimentation.py new file mode 100755 index 0000000..297bf87 --- /dev/null +++ b/CoreFlows/examples/Python/FiveEqsTwoFluid/FiveEqsTwoFluid_2DInclinedSedimentation.py @@ -0,0 +1,108 @@ +#!/usr/bin/env python +# -*-coding:utf-8 -* + + +import CoreFlows as cf + +def FiveEqsTwoFluid_2DInclinedSedimentation(): + spaceDim = 2; + + # Prepare for the mesh + xinf = 0 ; + xsup=2.0; + yinf=0.0; + ysup=4.0; + nx=20; + ny=40; + + # set the limit field for each boundary + wallVelocityX=[0]; + wallVelocityY=[0]; + wallTemperature=573; + + # set the initial field + initialVoidFraction=0.5; + initialVelocityX=[0]*2; + initialVelocityY=[1]*2; + initialTemperature=573; + initialPressure=155e5; + + # physical constants + gravite = [0] * spaceDim + + gravite[1]=-7; + gravite[0]=7; + + myProblem = cf.FiveEqsTwoFluid(cf.around155bars600K,spaceDim); + nVar =myProblem.getNumberOfVariables(); + + # Prepare for the initial condition + VV_Constant =[0]*nVar + + # constant vector + VV_Constant[0] = initialVoidFraction; + VV_Constant[1] = initialPressure ; + VV_Constant[2] = initialVelocityX[0]; + VV_Constant[3] = initialVelocityY[0]; + VV_Constant[4] = initialVelocityX[1]; + VV_Constant[5] = initialVelocityY[1]; + VV_Constant[6] = initialTemperature ; + + #Initial field creation + print("Building initial data " ); + myProblem.setInitialFieldConstant(spaceDim,VV_Constant, + xinf,xsup,nx,"wall","wall", + yinf,ysup,ny,"wall","wall", + 0.0,0.0, 0, "", "") + + # the boundary conditions + myProblem.setWallBoundaryCondition("wall", wallTemperature, wallVelocityX, wallVelocityY); + + # set physical parameters + myProblem.setGravity(gravite); + + # set the numerical method + myProblem.setNumericalScheme(cf.upwind, cf.Explicit); + myProblem.setEntropicCorrection(True); + + # name of result file + fileName = "2DInclinedSedimentation"; + + # simulation parameters + MaxNbOfTimeStep = 3 ; + freqSave = 1; + cfl = 0.25; + maxTime = 5; + precision = 1e-6; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + myProblem.setNewtonSolver(precision,20); + myProblem.saveConservativeField(True); + if(spaceDim>1): + myProblem.saveVelocity(); + pass + + # evolution + myProblem.initialize(); + print("Running python "+ fileName ); + + ok = myProblem.run(); + if (ok): + print( "Simulation python " + fileName + " is successful !" ); + pass + else: + print( "Simulation python " + fileName + " failed ! " ); + pass + + print( "------------ End of calculation !!! -----------" ); + + myProblem.terminate(); + return ok + +if __name__ == """__main__""": + FiveEqsTwoFluid_2DInclinedSedimentation() diff --git a/CoreFlows/examples/Python/FiveEqsTwoFluid/FiveEqsTwoFluid_2DVidangeReservoir.py b/CoreFlows/examples/Python/FiveEqsTwoFluid/FiveEqsTwoFluid_2DVidangeReservoir.py new file mode 100755 index 0000000..92aa869 --- /dev/null +++ b/CoreFlows/examples/Python/FiveEqsTwoFluid/FiveEqsTwoFluid_2DVidangeReservoir.py @@ -0,0 +1,135 @@ +#!/usr/bin/env python +# -*-coding:utf-8 -* + +import CoreFlows as cf +import cdmath as cm + +def FiveEqsTwoFluid_2DVidangeReservoir(): + + spaceDim = 2; + # Prepare for the mesh + print("Building mesh " ); + xinf = 0 ; + xsup=1.0; + yinf=0.0; + ysup=1.0; + nx=50; + ny=50; + diametreSortie=(ysup-yinf)/10.#10 percent of the height + nsortie=ny*diametreSortie/(ysup-yinf) + M=cm.Mesh(xinf,xsup,nx,yinf,ysup,ny) + # set the limit field for each boundary + eps=1e-6; + M.setGroupAtPlan(xinf,0,eps,"wall") + M.setGroupAtPlan(ysup,1,eps,"inlet") + M.setGroupAtPlan(yinf,1,eps,"wall") + dy=(ysup-yinf)/ny + i=0 + while i < nsortie: + M.setGroupAtFaceByCoords(xsup,yinf+(i+0.5)*dy,0,eps,"wall") + i=i+1 + while i < ny: + M.setGroupAtFaceByCoords(xsup,yinf+(i+0.5)*dy,0,eps,"wall") + i=i+1 + + + + # set the limit field for each boundary + wallVelocityX=[0]*2; + wallVelocityY=[0]*2; + wallTemperature=300; + outletPressure=1e5; + inletTemperature=300; + + # set the limit field for each boundary + initialAlphaTop=1.; + initialAlphaBottom=0.; + initialVelocityX=[0]*2; + initialVelocityY=[0]*2; + initialPressure=1e5; + initialTemperature=300; + + # physical constants + gravite = [0] * spaceDim + + gravite[0]=0; + gravite[1]=-10; + + myProblem = cf.FiveEqsTwoFluid(cf.around1bar300K,spaceDim); + nVar =myProblem.getNumberOfVariables(); + # Prepare for the initial condition + VV_top =cm.Vector(nVar) + VV_bottom =cm.Vector(nVar) + + # constant vector + VV_top[0] = initialAlphaTop ; + VV_top[1] = initialPressure ; + VV_top[2] = initialVelocityX[0]; + VV_top[3] = initialVelocityX[1]; + VV_top[4] = initialVelocityY[0]; + VV_top[5] = initialVelocityY[1]; + VV_top[6] = initialTemperature ; + + VV_bottom[0] = initialAlphaBottom ; + VV_bottom[1] = initialPressure ; + VV_bottom[2] = initialVelocityX[0]; + VV_bottom[3] = initialVelocityX[1]; + VV_bottom[4] = initialVelocityY[0]; + VV_bottom[5] = initialVelocityY[1]; + VV_bottom[6] = initialTemperature ; + + #Initial field creation + print("Building initial data" ); + myProblem.setInitialFieldStepFunction( M, VV_bottom, VV_top, .8, 1); + + # the boundary conditions + myProblem.setOutletBoundaryCondition("outlet", outletPressure); + myProblem.setNeumannBoundaryCondition("inlet"); + myProblem.setWallBoundaryCondition("wall", wallTemperature,wallVelocityX, wallVelocityY); + + # set physical parameters + myProblem.setGravity(gravite); + + # set the numerical method + myProblem.setNumericalScheme(cf.upwind, cf.Explicit); + #myProblem.setEntropicCorrection(True); + myProblem.setNonLinearFormulation(cf.VFFC) + + # name file save + fileName = "2DVidangeReservoir"; + + # parameters calculation + MaxNbOfTimeStep = 3 ; + freqSave = 1; + cfl = 0.1; + maxTime = 500; + precision = 1e-4; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + myProblem.setNewtonSolver(precision,20); + myProblem.saveVelocity(); + + # evolution + myProblem.initialize(); + + ok = myProblem.run(); + if (ok): + print( "Simulation python " + fileName + " is successful !" ); + pass + else: + print( "Simulation python " + fileName + " failed ! " ); + pass + + print( "------------ End of calculation !!! -----------" ); + + myProblem.terminate(); + + return ok + +if __name__ == """__main__""": + FiveEqsTwoFluid_2DVidangeReservoir() diff --git a/CoreFlows/examples/Python/FiveEqsTwoFluid_1DBoilingAssembly.py b/CoreFlows/examples/Python/FiveEqsTwoFluid_1DBoilingAssembly.py deleted file mode 100755 index c9f3bb0..0000000 --- a/CoreFlows/examples/Python/FiveEqsTwoFluid_1DBoilingAssembly.py +++ /dev/null @@ -1,111 +0,0 @@ -#!/usr/bin/env python -# -*-coding:utf-8 -* - -import CoreFlows as cf -import cdmath as cm - -def FiveEqsTwoFluid_1DBoilingAssembly(): - - spaceDim = 1; - # Prepare for the mesh - print("Building mesh " ); - xinf = 0 ; - xsup=4.2; - nx=50; - M=cm.Mesh(xinf,xsup,nx) - eps=1e-6; - M.setGroupAtPlan(xsup,0,eps,"outlet") - M.setGroupAtPlan(xinf,0,eps,"inlet") - - # set the limit field for each boundary - - inletVoidFraction=0; - inletVelocityX=[1]*2; - inletTemperature=563; - outletPressure=155e5; - - # physical constants - heatPowerField=cm.Field("heatPowerField", cm.CELLS, M, 1); - - nbCells=M.getNumberOfCells(); - - for i in range (nbCells): - x=M.getCell(i).x(); - if (x> (xsup-xinf)/4) and (x< (xsup-xinf)*3/4): - heatPowerField[i]=1e8 - else: - heatPowerField[i]=0 - heatPowerField.writeVTK("heatPowerField",True) - - - myProblem = cf.FiveEqsTwoFluid(cf.around155bars600K,spaceDim); - nVar = myProblem.getNumberOfVariables(); - - # Prepare for the initial condition - VV_Constant =[0]*nVar; - - # constant vector - VV_Constant[0] = inletVoidFraction; - VV_Constant[1] = outletPressure ; - VV_Constant[2] = inletVelocityX[0]; - VV_Constant[3] = inletVelocityX[1]; - VV_Constant[4] = inletTemperature ; - - - #Initial field creation - print("Building initial data " ); - myProblem.setInitialFieldConstant(M,VV_Constant) - - # set the boundary conditions - myProblem.setInletBoundaryCondition("inlet",inletVoidFraction,inletTemperature,inletVelocityX) - myProblem.setOutletBoundaryCondition("outlet", outletPressure); - - # set physical parameters - myProblem.setHeatPowerField(heatPowerField) - - # set the numerical method - myProblem.setNumericalScheme(cf.upwind, cf.Explicit); - myProblem.setEntropicCorrection(True); - myProblem.setWellBalancedCorrection(True); - - # name of result file - fileName = "1DBoilingAssembly"; - - # simulation parameters - MaxNbOfTimeStep = 3 ; - freqSave = 1; - cfl = 0.5; - maxTime = 500; - precision = 1e-6; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - myProblem.setNewtonSolver(precision,20); - #myProblem.saveConservativeField(True); - if(spaceDim>1): - myProblem.saveVelocity(); - pass - - # evolution - myProblem.initialize(); - print("Running python "+ fileName ); - - ok = myProblem.run(); - if (ok): - print( "Simulation python " + fileName + " is successful !" ); - pass - else: - print( "Simulation python " + fileName + " failed ! " ); - pass - - print( "------------ End of calculation !!! -----------" ); - - myProblem.terminate(); - return ok - -if __name__ == """__main__""": - FiveEqsTwoFluid_1DBoilingAssembly() diff --git a/CoreFlows/examples/Python/FiveEqsTwoFluid_1DBoilingChannel.py b/CoreFlows/examples/Python/FiveEqsTwoFluid_1DBoilingChannel.py deleted file mode 100755 index 4b011d2..0000000 --- a/CoreFlows/examples/Python/FiveEqsTwoFluid_1DBoilingChannel.py +++ /dev/null @@ -1,94 +0,0 @@ -#!/usr/bin/env python -# -*-coding:utf-8 -* - -import CoreFlows as cf - -def FiveEqsTwoFluid_1DBoilingChannel(): - - spaceDim = 1; - # Prepare for the mesh - xinf = 0 ; - xsup=4.2; - nx=50; - - # set the limit field for each boundary - - inletVoidFraction=0; - inletVelocityX=[1]*2; - inletTemperature=563; - outletPressure=155e5; - - # physical constants - heatPower=1e8; - - myProblem = cf.FiveEqsTwoFluid(cf.around155bars600K,spaceDim); - nVar = myProblem.getNumberOfVariables(); - - # Prepare for the initial condition - VV_Constant =[0]*nVar; - - # constant vector - VV_Constant[0] = inletVoidFraction; - VV_Constant[1] = outletPressure ; - VV_Constant[2] = inletVelocityX[0]; - VV_Constant[3] = inletVelocityX[1]; - VV_Constant[4] = inletTemperature ; - - - #Initial field creation - print("Building mesh and initial data " ); - myProblem.setInitialFieldConstant( spaceDim, VV_Constant, xinf, xsup, nx,"inlet","outlet"); - - # set the boundary conditions - myProblem.setInletBoundaryCondition("inlet",inletVoidFraction,inletTemperature,inletVelocityX) - myProblem.setOutletBoundaryCondition("outlet", outletPressure); - - # set physical parameters - myProblem.setHeatSource(heatPower); - - # set the numerical method - myProblem.setNumericalScheme(cf.upwind, cf.Explicit); - myProblem.setEntropicCorrection(True); - myProblem.setWellBalancedCorrection(True); - - # name of result file - fileName = "1DBoilingChannel"; - - # simulation parameters - MaxNbOfTimeStep = 3 ; - freqSave = 1; - cfl = 0.5; - maxTime = 500; - precision = 1e-6; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - myProblem.setNewtonSolver(precision,20); - #myProblem.saveConservativeField(True); - if(spaceDim>1): - myProblem.saveVelocity(); - pass - - # evolution - myProblem.initialize(); - print("Running python "+ fileName ); - - ok = myProblem.run(); - if (ok): - print( "Simulation python " + fileName + " is successful !" ); - pass - else: - print( "Simulation python " + fileName + " failed ! " ); - pass - - print( "------------ End of calculation !!! -----------" ); - - myProblem.terminate(); - return ok - -if __name__ == """__main__""": - FiveEqsTwoFluid_1DBoilingChannel() diff --git a/CoreFlows/examples/Python/FiveEqsTwoFluid_1DVidangeReservoir.py b/CoreFlows/examples/Python/FiveEqsTwoFluid_1DVidangeReservoir.py deleted file mode 100755 index 75436f6..0000000 --- a/CoreFlows/examples/Python/FiveEqsTwoFluid_1DVidangeReservoir.py +++ /dev/null @@ -1,107 +0,0 @@ -#!/usr/bin/env python -# -*-coding:utf-8 -* - -import CoreFlows as cf -import cdmath as cm - -def FiveEqsTwoFluid_1DVidangeReservoir(): - - spaceDim = 1; - # Prepare for the mesh - print("Building mesh " ); - xinf = 0. ; - xsup=1.0; - nx=50; - M=cm.Mesh(xinf,xsup,nx) - # set the limit field for each boundary - eps=1e-6; - M.setGroupAtPlan(xinf,0,eps,"wall") - M.setGroupAtPlan(xsup,0,eps,"inlet") - - # set the limit field for each boundary - wallVelocityX=[0] * 2 - wallTemperature=300 - - # set the limit field for each boundary - initialAlphaTop=1; - initialAlphaBottom=0.; - initialVelocityX=[0]*2; - initialPressure=1e5; - initialTemperature=300 - - # physical constants - gravite=[-10]; - - myProblem = cf.FiveEqsTwoFluid(cf.around1bar300K,spaceDim); - nVar = myProblem.getNumberOfVariables(); - - # Prepare for the initial condition - VV_top =cm.Vector(nVar) - VV_bottom =cm.Vector(nVar) - - # top and bottom vectors - VV_top[0] = initialAlphaTop ; - VV_top[1] = initialPressure ; - VV_top[2] = initialVelocityX[0]; - VV_top[3] = initialVelocityX[1]; - VV_top[4] = initialTemperature - - VV_bottom[0] = initialAlphaBottom ; - VV_bottom[1] = initialPressure ; - VV_bottom[2] = initialVelocityX[0]; - VV_bottom[3] = initialVelocityX[1]; - VV_bottom[4] = initialTemperature - - #Initial field creation - print("Building initial data " ); - myProblem.setInitialFieldStepFunction( M, VV_bottom, VV_top, .8, 0); - - # the boundary conditions - myProblem.setWallBoundaryCondition("wall",initialTemperature, wallVelocityX); - myProblem.setNeumannBoundaryCondition("inlet"); - - # set physical parameters - myProblem.setGravity(gravite); - - # set the numerical method - myProblem.setNumericalScheme(cf.upwind, cf.Explicit); - #myProblem.setEntropicCorrection(True); - myProblem.setNonLinearFormulation(cf.VFFC) - - # name file save - fileName = "1DVidangeReservoir"; - - # simulation parameters - MaxNbOfTimeStep = 3 ; - freqSave = 1; - cfl = .1; - maxTime = 5.; - precision = 1e-6; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - - # evolution - myProblem.initialize(); - - ok = myProblem.run(); - if (ok): - print( "Simulation python " + fileName + " is successful !" ); - pass - else: - print( "Simulation python " + fileName + " failed ! " ); - pass - - print( "------------ End of calculation !!! -----------" ); - - myProblem.terminate(); - - return ok - - -if __name__ == """__main__""": - FiveEqsTwoFluid_1DVidangeReservoir() diff --git a/CoreFlows/examples/Python/FiveEqsTwoFluid_2DInclinedBoilingChannel.py b/CoreFlows/examples/Python/FiveEqsTwoFluid_2DInclinedBoilingChannel.py deleted file mode 100755 index 932b15c..0000000 --- a/CoreFlows/examples/Python/FiveEqsTwoFluid_2DInclinedBoilingChannel.py +++ /dev/null @@ -1,113 +0,0 @@ -#!/usr/bin/env python -# -*-coding:utf-8 -* - - -import CoreFlows as cf - -def FiveEqsTwoFluid_2DInclinedBoilingChannel(): - spaceDim = 2; - - # Prepare for the mesh - xinf = 0 ; - xsup=2; - yinf=0.0; - ysup=4; - nx=20; - ny=40; - - # set the limit field for each boundary - wallVelocityX=[0]; - wallVelocityY=[0]; - wallTemperature=573; - inletVoidFraction=0; - inletVelocityX=[0]*2; - inletVelocityY=[1]*2; - inletTemperature=573; - outletPressure=155e5; - - # physical constants - gravite = [0] * spaceDim - - gravite[1]=-7; - gravite[0]=7; - - heatPower=5e7; - - myProblem = cf.FiveEqsTwoFluid(cf.around155bars600K,spaceDim); - nVar =myProblem.getNumberOfVariables(); - - # Prepare for the initial condition - VV_Constant =[0]*nVar - - # constant vector - VV_Constant[0] = inletVoidFraction; - VV_Constant[1] = outletPressure ; - VV_Constant[2] = inletVelocityX[0]; - VV_Constant[3] = inletVelocityY[0]; - VV_Constant[4] = inletVelocityX[1]; - VV_Constant[5] = inletVelocityY[1]; - VV_Constant[6] = inletTemperature ; - - #Initial field creation - print("Building mesh and initial data " ); - myProblem.setInitialFieldConstant(spaceDim,VV_Constant, - xinf,xsup,nx,"wall","wall", - yinf,ysup,ny,"inlet","outlet", - 0.0,0.0, 0, "", "") - - # the boundary conditions - myProblem.setOutletBoundaryCondition("outlet", outletPressure); - myProblem.setInletBoundaryCondition("inlet", inletVoidFraction, inletTemperature, inletVelocityX, inletVelocityY); - myProblem.setWallBoundaryCondition("wall", wallTemperature, wallVelocityX, wallVelocityY); - - # set physical parameters - myProblem.setHeatSource(heatPower); - myProblem.setGravity(gravite); - - # set the numerical method - myProblem.setNumericalScheme(cf.upwind, cf.Explicit); - myProblem.setLinearSolver(cf.GMRES,cf.ILU,True); - myProblem.setEntropicCorrection(True); - #myProblem.setWellBalancedCorrection(True); - - # name of result file - fileName = "2DInclinedBoilingChannel"; - - # simulation parameters - MaxNbOfTimeStep = 3 ; - freqSave = 1; - cfl = 0.25; - maxTime = 5; - precision = 1e-6; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - myProblem.setNewtonSolver(precision,20); - #myProblem.saveConservativeField(True); - if(spaceDim>1): - myProblem.saveVelocity(); - pass - - # evolution - myProblem.initialize(); - print("Running python "+ fileName ); - - ok = myProblem.run(); - if (ok): - print( "Simulation python " + fileName + " is successful !" ); - pass - else: - print( "Simulation python " + fileName + " failed ! " ); - pass - - print( "------------ End of calculation !!! -----------" ); - - myProblem.terminate(); - return ok - -if __name__ == """__main__""": - FiveEqsTwoFluid_2DInclinedBoilingChannel() diff --git a/CoreFlows/examples/Python/FiveEqsTwoFluid_2DInclinedSedimentation.py b/CoreFlows/examples/Python/FiveEqsTwoFluid_2DInclinedSedimentation.py deleted file mode 100755 index 297bf87..0000000 --- a/CoreFlows/examples/Python/FiveEqsTwoFluid_2DInclinedSedimentation.py +++ /dev/null @@ -1,108 +0,0 @@ -#!/usr/bin/env python -# -*-coding:utf-8 -* - - -import CoreFlows as cf - -def FiveEqsTwoFluid_2DInclinedSedimentation(): - spaceDim = 2; - - # Prepare for the mesh - xinf = 0 ; - xsup=2.0; - yinf=0.0; - ysup=4.0; - nx=20; - ny=40; - - # set the limit field for each boundary - wallVelocityX=[0]; - wallVelocityY=[0]; - wallTemperature=573; - - # set the initial field - initialVoidFraction=0.5; - initialVelocityX=[0]*2; - initialVelocityY=[1]*2; - initialTemperature=573; - initialPressure=155e5; - - # physical constants - gravite = [0] * spaceDim - - gravite[1]=-7; - gravite[0]=7; - - myProblem = cf.FiveEqsTwoFluid(cf.around155bars600K,spaceDim); - nVar =myProblem.getNumberOfVariables(); - - # Prepare for the initial condition - VV_Constant =[0]*nVar - - # constant vector - VV_Constant[0] = initialVoidFraction; - VV_Constant[1] = initialPressure ; - VV_Constant[2] = initialVelocityX[0]; - VV_Constant[3] = initialVelocityY[0]; - VV_Constant[4] = initialVelocityX[1]; - VV_Constant[5] = initialVelocityY[1]; - VV_Constant[6] = initialTemperature ; - - #Initial field creation - print("Building initial data " ); - myProblem.setInitialFieldConstant(spaceDim,VV_Constant, - xinf,xsup,nx,"wall","wall", - yinf,ysup,ny,"wall","wall", - 0.0,0.0, 0, "", "") - - # the boundary conditions - myProblem.setWallBoundaryCondition("wall", wallTemperature, wallVelocityX, wallVelocityY); - - # set physical parameters - myProblem.setGravity(gravite); - - # set the numerical method - myProblem.setNumericalScheme(cf.upwind, cf.Explicit); - myProblem.setEntropicCorrection(True); - - # name of result file - fileName = "2DInclinedSedimentation"; - - # simulation parameters - MaxNbOfTimeStep = 3 ; - freqSave = 1; - cfl = 0.25; - maxTime = 5; - precision = 1e-6; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - myProblem.setNewtonSolver(precision,20); - myProblem.saveConservativeField(True); - if(spaceDim>1): - myProblem.saveVelocity(); - pass - - # evolution - myProblem.initialize(); - print("Running python "+ fileName ); - - ok = myProblem.run(); - if (ok): - print( "Simulation python " + fileName + " is successful !" ); - pass - else: - print( "Simulation python " + fileName + " failed ! " ); - pass - - print( "------------ End of calculation !!! -----------" ); - - myProblem.terminate(); - return ok - -if __name__ == """__main__""": - FiveEqsTwoFluid_2DInclinedSedimentation() diff --git a/CoreFlows/examples/Python/FiveEqsTwoFluid_2DVidangeReservoir.py b/CoreFlows/examples/Python/FiveEqsTwoFluid_2DVidangeReservoir.py deleted file mode 100755 index 92aa869..0000000 --- a/CoreFlows/examples/Python/FiveEqsTwoFluid_2DVidangeReservoir.py +++ /dev/null @@ -1,135 +0,0 @@ -#!/usr/bin/env python -# -*-coding:utf-8 -* - -import CoreFlows as cf -import cdmath as cm - -def FiveEqsTwoFluid_2DVidangeReservoir(): - - spaceDim = 2; - # Prepare for the mesh - print("Building mesh " ); - xinf = 0 ; - xsup=1.0; - yinf=0.0; - ysup=1.0; - nx=50; - ny=50; - diametreSortie=(ysup-yinf)/10.#10 percent of the height - nsortie=ny*diametreSortie/(ysup-yinf) - M=cm.Mesh(xinf,xsup,nx,yinf,ysup,ny) - # set the limit field for each boundary - eps=1e-6; - M.setGroupAtPlan(xinf,0,eps,"wall") - M.setGroupAtPlan(ysup,1,eps,"inlet") - M.setGroupAtPlan(yinf,1,eps,"wall") - dy=(ysup-yinf)/ny - i=0 - while i < nsortie: - M.setGroupAtFaceByCoords(xsup,yinf+(i+0.5)*dy,0,eps,"wall") - i=i+1 - while i < ny: - M.setGroupAtFaceByCoords(xsup,yinf+(i+0.5)*dy,0,eps,"wall") - i=i+1 - - - - # set the limit field for each boundary - wallVelocityX=[0]*2; - wallVelocityY=[0]*2; - wallTemperature=300; - outletPressure=1e5; - inletTemperature=300; - - # set the limit field for each boundary - initialAlphaTop=1.; - initialAlphaBottom=0.; - initialVelocityX=[0]*2; - initialVelocityY=[0]*2; - initialPressure=1e5; - initialTemperature=300; - - # physical constants - gravite = [0] * spaceDim - - gravite[0]=0; - gravite[1]=-10; - - myProblem = cf.FiveEqsTwoFluid(cf.around1bar300K,spaceDim); - nVar =myProblem.getNumberOfVariables(); - # Prepare for the initial condition - VV_top =cm.Vector(nVar) - VV_bottom =cm.Vector(nVar) - - # constant vector - VV_top[0] = initialAlphaTop ; - VV_top[1] = initialPressure ; - VV_top[2] = initialVelocityX[0]; - VV_top[3] = initialVelocityX[1]; - VV_top[4] = initialVelocityY[0]; - VV_top[5] = initialVelocityY[1]; - VV_top[6] = initialTemperature ; - - VV_bottom[0] = initialAlphaBottom ; - VV_bottom[1] = initialPressure ; - VV_bottom[2] = initialVelocityX[0]; - VV_bottom[3] = initialVelocityX[1]; - VV_bottom[4] = initialVelocityY[0]; - VV_bottom[5] = initialVelocityY[1]; - VV_bottom[6] = initialTemperature ; - - #Initial field creation - print("Building initial data" ); - myProblem.setInitialFieldStepFunction( M, VV_bottom, VV_top, .8, 1); - - # the boundary conditions - myProblem.setOutletBoundaryCondition("outlet", outletPressure); - myProblem.setNeumannBoundaryCondition("inlet"); - myProblem.setWallBoundaryCondition("wall", wallTemperature,wallVelocityX, wallVelocityY); - - # set physical parameters - myProblem.setGravity(gravite); - - # set the numerical method - myProblem.setNumericalScheme(cf.upwind, cf.Explicit); - #myProblem.setEntropicCorrection(True); - myProblem.setNonLinearFormulation(cf.VFFC) - - # name file save - fileName = "2DVidangeReservoir"; - - # parameters calculation - MaxNbOfTimeStep = 3 ; - freqSave = 1; - cfl = 0.1; - maxTime = 500; - precision = 1e-4; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - myProblem.setNewtonSolver(precision,20); - myProblem.saveVelocity(); - - # evolution - myProblem.initialize(); - - ok = myProblem.run(); - if (ok): - print( "Simulation python " + fileName + " is successful !" ); - pass - else: - print( "Simulation python " + fileName + " failed ! " ); - pass - - print( "------------ End of calculation !!! -----------" ); - - myProblem.terminate(); - - return ok - -if __name__ == """__main__""": - FiveEqsTwoFluid_2DVidangeReservoir() diff --git a/CoreFlows/examples/Python/IsothermalTwoFluid/IsothermalTwoFluid_1DSedimentation.py b/CoreFlows/examples/Python/IsothermalTwoFluid/IsothermalTwoFluid_1DSedimentation.py new file mode 100755 index 0000000..2ae5d0b --- /dev/null +++ b/CoreFlows/examples/Python/IsothermalTwoFluid/IsothermalTwoFluid_1DSedimentation.py @@ -0,0 +1,86 @@ +#!/usr/bin/env python +# -*-coding:utf-8 -* + +import CoreFlows as cf + +def IsothermalTwoFluid_1DSedimentation(): + + spaceDim = 1; + # Prepare for the mesh + xinf = 0. ; + xsup=1.0; + nx=50; + + # set the limit field for each boundary + wallVelocityX=[0] * 2; + wallPressure=1.e5; + + initialVoidFraction=0.5; + + # physical constants + gravite=[-10]; + + myProblem = cf.IsothermalTwoFluid(cf.around1bar300K,spaceDim); + nVar = myProblem.getNumberOfVariables(); + print(nVar) + + # Prepare for the initial condition + VV_Constant =[0] *nVar + + # constant vector + VV_Constant[0] = initialVoidFraction; + VV_Constant[1] = wallPressure; + VV_Constant[2] = wallVelocityX[0]; + VV_Constant[3] = wallVelocityX[1]; + + #Initial field creation + print("Building mesh and initial data " ); + myProblem.setInitialFieldConstant(spaceDim,VV_Constant,xinf,xsup,nx,"wall","wall") + + # the boundary conditions + myProblem.setWallBoundaryCondition("wall", wallVelocityX); + + # set physical parameters + myProblem.setGravity(gravite); + + # set the numerical method + myProblem.setNumericalScheme(cf.upwind, cf.Implicit); + myProblem.setEntropicCorrection(True); + + # name file save + fileName = "1DSedimentation"; + + # simulation parameters + MaxNbOfTimeStep = 3 ; + freqSave = 1; + cfl = 5.; + maxTime = 5.; + precision = 1e-6; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + + # evolution + myProblem.initialize(); + print("Running python"+ fileName ); + + ok = myProblem.run(); + if (ok): + print( "Simulation python " + fileName + " is successful !" ); + pass + else: + print( "Simulation python " + fileName + " failed ! " ); + pass + + print( "------------ End of calculation !!! -----------" ); + + myProblem.terminate(); + return ok + + +if __name__ == """__main__""": + IsothermalTwoFluid_1DSedimentation() diff --git a/CoreFlows/examples/Python/IsothermalTwoFluid/IsothermalTwoFluid_1DVidangeReservoir.py b/CoreFlows/examples/Python/IsothermalTwoFluid/IsothermalTwoFluid_1DVidangeReservoir.py new file mode 100755 index 0000000..123554b --- /dev/null +++ b/CoreFlows/examples/Python/IsothermalTwoFluid/IsothermalTwoFluid_1DVidangeReservoir.py @@ -0,0 +1,104 @@ +#!/usr/bin/env python +# -*-coding:utf-8 -* + +import CoreFlows as cf +import cdmath as cm + +def IsothermalTwoFluid_1DVidangeReservoir(): + + spaceDim = 1; + # Prepare for the mesh + print("Building mesh " ); + xinf = 0. ; + xsup=1.0; + nx=50; + M=cm.Mesh(xinf,xsup,nx) + # set the limit field for each boundary + eps=1e-6; + M.setGroupAtPlan(xinf,0,eps,"wall") + M.setGroupAtPlan(xsup,0,eps,"inlet") + + # set the limit field for each boundary + wallVelocityX=[0] * 2 + + # set the limit field for each boundary + initialAlphaTop=1; + initialAlphaBottom=0.; + initialVelocityX=[0]*2; + initialPressure=1e5; + + + # physical constants + gravite=[-10]; + + myProblem = cf.IsothermalTwoFluid(cf.around1bar300K,spaceDim); + nVar = myProblem.getNumberOfVariables(); + + # Prepare for the initial condition + VV_top =cm.Vector(nVar) + VV_bottom =cm.Vector(nVar) + + # top and bottom vectors + VV_top[0] = initialAlphaTop ; + VV_top[1] = initialPressure ; + VV_top[2] = initialVelocityX[0]; + VV_top[3] = initialVelocityX[1]; + + VV_bottom[0] = initialAlphaBottom ; + VV_bottom[1] = initialPressure ; + VV_bottom[2] = initialVelocityX[0]; + VV_bottom[3] = initialVelocityX[1]; + + #Initial field creation + print("Building initial data " ); + myProblem.setInitialFieldStepFunction( M, VV_bottom, VV_top, .8, 0); + + # the boundary conditions + myProblem.setWallBoundaryCondition("wall", wallVelocityX); + myProblem.setNeumannBoundaryCondition("inlet"); + + # set physical parameters + myProblem.setGravity(gravite); + + # set the numerical method + myProblem.setNumericalScheme(cf.upwind, cf.Explicit); + #myProblem.setEntropicCorrection(True); + myProblem.setNonLinearFormulation(cf.VFFC) + + # name file save + fileName = "1DVidangeReservoir"; + + # simulation parameters + MaxNbOfTimeStep = 3 ; + freqSave = 1; + cfl = .1; + maxTime = 5.; + precision = 1e-6; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + + # evolution + myProblem.initialize(); + + ok = myProblem.run(); + if (ok): + print( "Simulation python " + fileName + " is successful !" ); + pass + else: + print( "Simulation python " + fileName + " failed ! " ); + pass + + print( "------------ End of calculation !!! -----------" ); + + myProblem.terminate(); + + return ok + + +if __name__ == """__main__""": + IsothermalTwoFluid_1DVidangeReservoir() diff --git a/CoreFlows/examples/Python/IsothermalTwoFluid/IsothermalTwoFluid_2DVidangeReservoir.py b/CoreFlows/examples/Python/IsothermalTwoFluid/IsothermalTwoFluid_2DVidangeReservoir.py new file mode 100755 index 0000000..d92a888 --- /dev/null +++ b/CoreFlows/examples/Python/IsothermalTwoFluid/IsothermalTwoFluid_2DVidangeReservoir.py @@ -0,0 +1,131 @@ +#!/usr/bin/env python +# -*-coding:utf-8 -* + +import CoreFlows as cf +import cdmath as cm + +def IsothermalTwoFluid_2DVidangeReservoir(): + + spaceDim = 2; + print("Building mesh " ); + # Prepare for the mesh + xinf = 0 ; + xsup=1.0; + yinf=0.0; + ysup=1.0; + nx=50; + ny=50; + diametreSortie=(ysup-yinf)/10.#10 percent of the height + nsortie=ny*diametreSortie/(ysup-yinf) + M=cm.Mesh(xinf,xsup,nx,yinf,ysup,ny) + # set the limit field for each boundary + eps=1e-6; + M.setGroupAtPlan(xinf,0,eps,"wall") + M.setGroupAtPlan(ysup,1,eps,"inlet") + M.setGroupAtPlan(yinf,1,eps,"wall") + dy=(ysup-yinf)/ny + i=0 + while i < nsortie: + M.setGroupAtFaceByCoords(xsup,yinf+(i+0.5)*dy,0,eps,"wall") + i=i+1 + while i < ny: + M.setGroupAtFaceByCoords(xsup,yinf+(i+0.5)*dy,0,eps,"wall") + i=i+1 + + + + # set the limit field for each boundary + wallVelocityX=[0]*2; + wallVelocityY=[0]*2; + inletAlpha=1; + outletPressure=1e5; + + # set the limit field for each boundary + initialAlphaTop=1; + initialAlphaBottom=0.; + initialVelocityX=[0]*2; + initialVelocityY=[0]*2; + initialPressure=1e5; + + # physical constants + gravite = [0] * spaceDim + + gravite[0]=0; + gravite[1]=-10; + + myProblem = cf.IsothermalTwoFluid(cf.around1bar300K,spaceDim); + nVar =myProblem.getNumberOfVariables(); + # Prepare for the initial condition + VV_top =cm.Vector(nVar) + VV_bottom =cm.Vector(nVar) + + # top and bottom vectors + VV_top[0] = initialAlphaTop ; + VV_top[1] = initialPressure ; + VV_top[2] = initialVelocityX[0]; + VV_top[3] = initialVelocityX[1]; + VV_top[4] = initialVelocityY[0]; + VV_top[5] = initialVelocityY[1]; + + VV_bottom[0] = initialAlphaBottom ; + VV_bottom[1] = initialPressure ; + VV_bottom[2] = initialVelocityX[0]; + VV_bottom[3] = initialVelocityX[1]; + VV_bottom[4] = initialVelocityY[0]; + VV_bottom[5] = initialVelocityY[1]; + + #Initial field creation + print("Building initial data" ); + myProblem.setInitialFieldStepFunction( M, VV_bottom, VV_top, .8, 1); + + # the boundary conditions + myProblem.setOutletBoundaryCondition("outlet", outletPressure); + myProblem.setNeumannBoundaryCondition("inlet"); + myProblem.setWallBoundaryCondition("wall",wallVelocityX, wallVelocityY); + + # set physical parameters + myProblem.setGravity(gravite); + + # set the numerical method + myProblem.setNumericalScheme(cf.upwind, cf.Explicit); + myProblem.setNonLinearFormulation(cf.VFFC) + myProblem.setEntropicCorrection(True); + + # name file save + fileName = "2DVidangeReservoir"; + + # parameters calculation + MaxNbOfTimeStep = 3 ; + freqSave = 1; + cfl = .1; + maxTime = 500; + precision = 1e-6; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + myProblem.setNewtonSolver(precision,20); + myProblem.saveVelocity(); + + # evolution + myProblem.initialize(); + + ok = myProblem.run(); + if (ok): + print( "Simulation python " + fileName + " is successful !" ); + pass + else: + print( "Simulation python " + fileName + " failed ! " ); + pass + + print( "------------ End of calculation !!! -----------" ); + + myProblem.terminate(); + + return ok + +if __name__ == """__main__""": + IsothermalTwoFluid_2DVidangeReservoir() diff --git a/CoreFlows/examples/Python/IsothermalTwoFluid_1DSedimentation.py b/CoreFlows/examples/Python/IsothermalTwoFluid_1DSedimentation.py deleted file mode 100755 index 2ae5d0b..0000000 --- a/CoreFlows/examples/Python/IsothermalTwoFluid_1DSedimentation.py +++ /dev/null @@ -1,86 +0,0 @@ -#!/usr/bin/env python -# -*-coding:utf-8 -* - -import CoreFlows as cf - -def IsothermalTwoFluid_1DSedimentation(): - - spaceDim = 1; - # Prepare for the mesh - xinf = 0. ; - xsup=1.0; - nx=50; - - # set the limit field for each boundary - wallVelocityX=[0] * 2; - wallPressure=1.e5; - - initialVoidFraction=0.5; - - # physical constants - gravite=[-10]; - - myProblem = cf.IsothermalTwoFluid(cf.around1bar300K,spaceDim); - nVar = myProblem.getNumberOfVariables(); - print(nVar) - - # Prepare for the initial condition - VV_Constant =[0] *nVar - - # constant vector - VV_Constant[0] = initialVoidFraction; - VV_Constant[1] = wallPressure; - VV_Constant[2] = wallVelocityX[0]; - VV_Constant[3] = wallVelocityX[1]; - - #Initial field creation - print("Building mesh and initial data " ); - myProblem.setInitialFieldConstant(spaceDim,VV_Constant,xinf,xsup,nx,"wall","wall") - - # the boundary conditions - myProblem.setWallBoundaryCondition("wall", wallVelocityX); - - # set physical parameters - myProblem.setGravity(gravite); - - # set the numerical method - myProblem.setNumericalScheme(cf.upwind, cf.Implicit); - myProblem.setEntropicCorrection(True); - - # name file save - fileName = "1DSedimentation"; - - # simulation parameters - MaxNbOfTimeStep = 3 ; - freqSave = 1; - cfl = 5.; - maxTime = 5.; - precision = 1e-6; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - - # evolution - myProblem.initialize(); - print("Running python"+ fileName ); - - ok = myProblem.run(); - if (ok): - print( "Simulation python " + fileName + " is successful !" ); - pass - else: - print( "Simulation python " + fileName + " failed ! " ); - pass - - print( "------------ End of calculation !!! -----------" ); - - myProblem.terminate(); - return ok - - -if __name__ == """__main__""": - IsothermalTwoFluid_1DSedimentation() diff --git a/CoreFlows/examples/Python/IsothermalTwoFluid_1DVidangeReservoir.py b/CoreFlows/examples/Python/IsothermalTwoFluid_1DVidangeReservoir.py deleted file mode 100755 index 123554b..0000000 --- a/CoreFlows/examples/Python/IsothermalTwoFluid_1DVidangeReservoir.py +++ /dev/null @@ -1,104 +0,0 @@ -#!/usr/bin/env python -# -*-coding:utf-8 -* - -import CoreFlows as cf -import cdmath as cm - -def IsothermalTwoFluid_1DVidangeReservoir(): - - spaceDim = 1; - # Prepare for the mesh - print("Building mesh " ); - xinf = 0. ; - xsup=1.0; - nx=50; - M=cm.Mesh(xinf,xsup,nx) - # set the limit field for each boundary - eps=1e-6; - M.setGroupAtPlan(xinf,0,eps,"wall") - M.setGroupAtPlan(xsup,0,eps,"inlet") - - # set the limit field for each boundary - wallVelocityX=[0] * 2 - - # set the limit field for each boundary - initialAlphaTop=1; - initialAlphaBottom=0.; - initialVelocityX=[0]*2; - initialPressure=1e5; - - - # physical constants - gravite=[-10]; - - myProblem = cf.IsothermalTwoFluid(cf.around1bar300K,spaceDim); - nVar = myProblem.getNumberOfVariables(); - - # Prepare for the initial condition - VV_top =cm.Vector(nVar) - VV_bottom =cm.Vector(nVar) - - # top and bottom vectors - VV_top[0] = initialAlphaTop ; - VV_top[1] = initialPressure ; - VV_top[2] = initialVelocityX[0]; - VV_top[3] = initialVelocityX[1]; - - VV_bottom[0] = initialAlphaBottom ; - VV_bottom[1] = initialPressure ; - VV_bottom[2] = initialVelocityX[0]; - VV_bottom[3] = initialVelocityX[1]; - - #Initial field creation - print("Building initial data " ); - myProblem.setInitialFieldStepFunction( M, VV_bottom, VV_top, .8, 0); - - # the boundary conditions - myProblem.setWallBoundaryCondition("wall", wallVelocityX); - myProblem.setNeumannBoundaryCondition("inlet"); - - # set physical parameters - myProblem.setGravity(gravite); - - # set the numerical method - myProblem.setNumericalScheme(cf.upwind, cf.Explicit); - #myProblem.setEntropicCorrection(True); - myProblem.setNonLinearFormulation(cf.VFFC) - - # name file save - fileName = "1DVidangeReservoir"; - - # simulation parameters - MaxNbOfTimeStep = 3 ; - freqSave = 1; - cfl = .1; - maxTime = 5.; - precision = 1e-6; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - - # evolution - myProblem.initialize(); - - ok = myProblem.run(); - if (ok): - print( "Simulation python " + fileName + " is successful !" ); - pass - else: - print( "Simulation python " + fileName + " failed ! " ); - pass - - print( "------------ End of calculation !!! -----------" ); - - myProblem.terminate(); - - return ok - - -if __name__ == """__main__""": - IsothermalTwoFluid_1DVidangeReservoir() diff --git a/CoreFlows/examples/Python/IsothermalTwoFluid_2DVidangeReservoir.py b/CoreFlows/examples/Python/IsothermalTwoFluid_2DVidangeReservoir.py deleted file mode 100755 index d92a888..0000000 --- a/CoreFlows/examples/Python/IsothermalTwoFluid_2DVidangeReservoir.py +++ /dev/null @@ -1,131 +0,0 @@ -#!/usr/bin/env python -# -*-coding:utf-8 -* - -import CoreFlows as cf -import cdmath as cm - -def IsothermalTwoFluid_2DVidangeReservoir(): - - spaceDim = 2; - print("Building mesh " ); - # Prepare for the mesh - xinf = 0 ; - xsup=1.0; - yinf=0.0; - ysup=1.0; - nx=50; - ny=50; - diametreSortie=(ysup-yinf)/10.#10 percent of the height - nsortie=ny*diametreSortie/(ysup-yinf) - M=cm.Mesh(xinf,xsup,nx,yinf,ysup,ny) - # set the limit field for each boundary - eps=1e-6; - M.setGroupAtPlan(xinf,0,eps,"wall") - M.setGroupAtPlan(ysup,1,eps,"inlet") - M.setGroupAtPlan(yinf,1,eps,"wall") - dy=(ysup-yinf)/ny - i=0 - while i < nsortie: - M.setGroupAtFaceByCoords(xsup,yinf+(i+0.5)*dy,0,eps,"wall") - i=i+1 - while i < ny: - M.setGroupAtFaceByCoords(xsup,yinf+(i+0.5)*dy,0,eps,"wall") - i=i+1 - - - - # set the limit field for each boundary - wallVelocityX=[0]*2; - wallVelocityY=[0]*2; - inletAlpha=1; - outletPressure=1e5; - - # set the limit field for each boundary - initialAlphaTop=1; - initialAlphaBottom=0.; - initialVelocityX=[0]*2; - initialVelocityY=[0]*2; - initialPressure=1e5; - - # physical constants - gravite = [0] * spaceDim - - gravite[0]=0; - gravite[1]=-10; - - myProblem = cf.IsothermalTwoFluid(cf.around1bar300K,spaceDim); - nVar =myProblem.getNumberOfVariables(); - # Prepare for the initial condition - VV_top =cm.Vector(nVar) - VV_bottom =cm.Vector(nVar) - - # top and bottom vectors - VV_top[0] = initialAlphaTop ; - VV_top[1] = initialPressure ; - VV_top[2] = initialVelocityX[0]; - VV_top[3] = initialVelocityX[1]; - VV_top[4] = initialVelocityY[0]; - VV_top[5] = initialVelocityY[1]; - - VV_bottom[0] = initialAlphaBottom ; - VV_bottom[1] = initialPressure ; - VV_bottom[2] = initialVelocityX[0]; - VV_bottom[3] = initialVelocityX[1]; - VV_bottom[4] = initialVelocityY[0]; - VV_bottom[5] = initialVelocityY[1]; - - #Initial field creation - print("Building initial data" ); - myProblem.setInitialFieldStepFunction( M, VV_bottom, VV_top, .8, 1); - - # the boundary conditions - myProblem.setOutletBoundaryCondition("outlet", outletPressure); - myProblem.setNeumannBoundaryCondition("inlet"); - myProblem.setWallBoundaryCondition("wall",wallVelocityX, wallVelocityY); - - # set physical parameters - myProblem.setGravity(gravite); - - # set the numerical method - myProblem.setNumericalScheme(cf.upwind, cf.Explicit); - myProblem.setNonLinearFormulation(cf.VFFC) - myProblem.setEntropicCorrection(True); - - # name file save - fileName = "2DVidangeReservoir"; - - # parameters calculation - MaxNbOfTimeStep = 3 ; - freqSave = 1; - cfl = .1; - maxTime = 500; - precision = 1e-6; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - myProblem.setNewtonSolver(precision,20); - myProblem.saveVelocity(); - - # evolution - myProblem.initialize(); - - ok = myProblem.run(); - if (ok): - print( "Simulation python " + fileName + " is successful !" ); - pass - else: - print( "Simulation python " + fileName + " failed ! " ); - pass - - print( "------------ End of calculation !!! -----------" ); - - myProblem.terminate(); - - return ok - -if __name__ == """__main__""": - IsothermalTwoFluid_2DVidangeReservoir() diff --git a/CoreFlows/examples/Python/SinglePhase/SinglePhase_1DDepressurisation.py b/CoreFlows/examples/Python/SinglePhase/SinglePhase_1DDepressurisation.py new file mode 100755 index 0000000..f675485 --- /dev/null +++ b/CoreFlows/examples/Python/SinglePhase/SinglePhase_1DDepressurisation.py @@ -0,0 +1,91 @@ +#!/usr/bin/env python +# -*-coding:utf-8 -* + +import CoreFlows as cf +import cdmath as cm +import math + +def SinglePhase_1DDepressurisation(): + + spaceDim = 1; + # Prepare for the mesh + print("Building mesh " ); + xinf = 0 ; + xsup=4.2; + nx=50; + M=cm.Mesh(xinf,xsup,nx) + + # set the initial field + initialPressure=155e5; + initialVelocityX=0; + initialTemperature=573; + + # set the boundary data for each boundary + outletPressure=80e5; + wallVelocityX=0; + wallTemperature=573; + + myProblem = cf.SinglePhase(cf.Liquid,cf.around155bars600K,spaceDim); + nVar = myProblem.getNumberOfVariables(); + + # Prepare for the initial condition + VV_Constant =[0]*nVar; + + # constant vector + VV_Constant[0] = initialPressure ; + VV_Constant[1] = initialVelocityX; + VV_Constant[2] = initialTemperature ; + + + #Initial field creation + print("Building initial data" ); + myProblem.setInitialFieldConstant( spaceDim, VV_Constant, xinf, xsup, nx,"wall","outlet"); + + # set the boundary conditions + myProblem.setWallBoundaryCondition("wall", wallTemperature, wallVelocityX); + myProblem.setOutletBoundaryCondition("outlet", outletPressure,[xsup]); + + + # set the numerical method + myProblem.setNumericalScheme(cf.upwind, cf.Explicit); + + # name of result file + fileName = "1DDepressurisation"; + + # simulation parameters + MaxNbOfTimeStep = 3 ; + freqSave = 1; + cfl = 0.95; + maxTime = 500; + precision = 1e-6; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + myProblem.setNewtonSolver(precision,20); + #myProblem.saveConservativeField(True); + if(spaceDim>1): + myProblem.saveVelocity(); + pass + + # evolution + myProblem.initialize(); + + ok = myProblem.run(); + if (ok): + print( "Simulation python " + fileName + " is successful !" ); + pass + else: + print( "Simulation python " + fileName + " failed ! " ); + pass + + print( "------------ End of calculation !!! -----------" ); + + myProblem.terminate(); + return ok + +if __name__ == """__main__""": + SinglePhase_1DDepressurisation() diff --git a/CoreFlows/examples/Python/SinglePhase/SinglePhase_1DHeatedAssembly.py b/CoreFlows/examples/Python/SinglePhase/SinglePhase_1DHeatedAssembly.py new file mode 100755 index 0000000..619562c --- /dev/null +++ b/CoreFlows/examples/Python/SinglePhase/SinglePhase_1DHeatedAssembly.py @@ -0,0 +1,104 @@ +#!/usr/bin/env python +# -*-coding:utf-8 -* + +import CoreFlows as cf +import cdmath as cm + +def SinglePhase_1DHeatedAssembly(): + + spaceDim = 1; + # Prepare for the mesh + print("Building mesh " ); + xinf = 0 ; + xsup=4.2; + xinfcore=(xsup-xinf)/4 + xsupcore=3*(xsup-xinf)/4 + nx=50; + M=cm.Mesh(xinf,xsup,nx) + + # set the limit field for each boundary + + inletVelocityX=5; + inletTemperature=565; + outletPressure=155e5; + + # physical parameters + heatPowerField=cm.Field("heatPowerField", cm.CELLS, M, 1); + nbCells=M.getNumberOfCells(); + + for i in range (nbCells): + x=M.getCell(i).x(); + + if (x> xinfcore) and (x< xsupcore): + heatPowerField[i]=1e8 + else: + heatPowerField[i]=0 + heatPowerField.writeVTK("heatPowerField",True) + + myProblem = cf.SinglePhase(cf.Liquid,cf.around155bars600K,spaceDim); + nVar = myProblem.getNumberOfVariables(); + + # Prepare for the initial condition + VV_Constant =[0]*nVar; + + # constant vector + VV_Constant[0] = outletPressure ; + VV_Constant[1] = inletVelocityX; + VV_Constant[2] = inletTemperature ; + + + #Initial field creation + print("Building initial data " ); + myProblem.setInitialFieldConstant( spaceDim, VV_Constant, xinf, xsup, nx,"inlet","outlet"); + + # set the boundary conditions + myProblem.setInletBoundaryCondition("inlet",inletTemperature,inletVelocityX) + myProblem.setOutletBoundaryCondition("outlet", outletPressure,[xsup]); + + # set physical parameters + myProblem.setHeatPowerField(heatPowerField); + + # set the numerical method + myProblem.setNumericalScheme(cf.upwind, cf.Explicit); + myProblem.setWellBalancedCorrection(True); + + # name of result file + fileName = "1DHeatedChannelUpwindWB"; + + # simulation parameters + MaxNbOfTimeStep = 3 ; + freqSave = 1; + cfl = 0.95; + maxTime = 500; + precision = 1e-7; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + myProblem.setNewtonSolver(precision,20); + myProblem.saveConservativeField(True); + if(spaceDim>1): + myProblem.saveVelocity(); + pass + + # evolution + myProblem.initialize(); + + ok = myProblem.run(); + if (ok): + print( "Simulation python " + fileName + " is successful !" ); + pass + else: + print( "Simulation python " + fileName + " failed ! " ); + pass + + print( "------------ End of calculation !!! -----------" ); + + myProblem.terminate(); + return ok + +if __name__ == """__main__""": + SinglePhase_1DHeatedAssembly() diff --git a/CoreFlows/examples/Python/SinglePhase/SinglePhase_1DHeatedChannel.py b/CoreFlows/examples/Python/SinglePhase/SinglePhase_1DHeatedChannel.py new file mode 100755 index 0000000..a969cbb --- /dev/null +++ b/CoreFlows/examples/Python/SinglePhase/SinglePhase_1DHeatedChannel.py @@ -0,0 +1,90 @@ +#!/usr/bin/env python +# -*-coding:utf-8 -* + +import CoreFlows as cf + +def SinglePhase_1DHeatedChannel(): + + spaceDim = 1; + # Prepare for the mesh + print("Building mesh " ); + xinf = 0 ; + xsup=4.2; + nx=50; + + # set the limit field for each boundary + + inletVelocityX=5; + inletTemperature=565; + outletPressure=155e5; + + # physical parameters + heatPower=1e7; + + myProblem = cf.SinglePhase(cf.Liquid,cf.around155bars600K,spaceDim); + nVar = myProblem.getNumberOfVariables(); + + # Prepare for the initial condition + VV_Constant =[0]*nVar; + + # constant vector + VV_Constant[0] = outletPressure ; + VV_Constant[1] = inletVelocityX; + VV_Constant[2] = inletTemperature ; + + + #Initial field creation + print("Building initial data " ); + myProblem.setInitialFieldConstant( spaceDim, VV_Constant, xinf, xsup, nx,"inlet","outlet"); + + # set the boundary conditions + myProblem.setInletBoundaryCondition("inlet",inletTemperature,inletVelocityX) + myProblem.setOutletBoundaryCondition("outlet", outletPressure,[xsup]); + + # set physical parameters + myProblem.setHeatSource(heatPower); + + # set the numerical method + myProblem.setNumericalScheme(cf.upwind, cf.Explicit); + myProblem.setWellBalancedCorrection(True); + + # name of result file + fileName = "1DHeatedChannelUpwindWB"; + + # simulation parameters + MaxNbOfTimeStep = 3 ; + freqSave = 1; + cfl = 0.95; + maxTime = 500; + precision = 1e-7; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + myProblem.setNewtonSolver(precision,20); + myProblem.saveConservativeField(True); + if(spaceDim>1): + myProblem.saveVelocity(); + pass + + # evolution + myProblem.initialize(); + + ok = myProblem.run(); + if (ok): + print( "Simulation python " + fileName + " is successful !" ); + pass + else: + print( "Simulation python " + fileName + " failed ! " ); + pass + + print( "------------ End of calculation !!! -----------" ); + + myProblem.terminate(); + return ok + +if __name__ == """__main__""": + SinglePhase_1DHeatedChannel() diff --git a/CoreFlows/examples/Python/SinglePhase/SinglePhase_1DRiemannProblem.py b/CoreFlows/examples/Python/SinglePhase/SinglePhase_1DRiemannProblem.py new file mode 100755 index 0000000..4f52e9d --- /dev/null +++ b/CoreFlows/examples/Python/SinglePhase/SinglePhase_1DRiemannProblem.py @@ -0,0 +1,95 @@ +#!/usr/bin/env python +# -*-coding:utf-8 -* + +import CoreFlows as cf +import cdmath as cm + +def SinglePhase_1DRiemannProblem(): + + spaceDim = 1; + # Prepare for the mesh + print("Building mesh " ); + xinf = 0 ; + xsup=4.2; + nx=50; + discontinuity=(xinf+xsup)/2 + M=cm.Mesh(xinf,xsup,nx) + eps=1e-6 + M.setGroupAtPlan(xsup,0,eps,"RightBoundary") + M.setGroupAtPlan(xinf,0,eps,"LeftBoundary") + + # set the limit field for each boundary + + initialVelocity_Left=1; + initialTemperature_Left=565; + initialPressure_Left=155e5; + + initialVelocity_Right=1; + initialTemperature_Right=565; + initialPressure_Right=150e5; + + myProblem = cf.SinglePhase(cf.Liquid,cf.around155bars600K,spaceDim); + nVar = myProblem.getNumberOfVariables(); + + # Prepare for the initial condition + VV_Left =cm.Vector(nVar) + VV_Right =cm.Vector(nVar) + + # left and right constant vectors + VV_Left[0] = initialPressure_Left; + VV_Left[1] = initialVelocity_Left; + VV_Left[2] = initialTemperature_Left ; + + VV_Right[0] = initialPressure_Right; + VV_Right[1] = initialVelocity_Right; + VV_Right[2] = initialTemperature_Right ; + + + #Initial field creation + print("Building initial data " ); + myProblem.setInitialFieldStepFunction(M,VV_Left,VV_Right,discontinuity); + + # set the boundary conditions + myProblem.setNeumannBoundaryCondition("LeftBoundary"); + myProblem.setNeumannBoundaryCondition("RightBoundary"); + + # set the numerical method + myProblem.setNumericalScheme(cf.staggered, cf.Implicit); + + # name of result file + fileName = "1DRiemannProblem"; + + # simulation parameters + MaxNbOfTimeStep = 3 ; + freqSave = 1; + cfl = 0.95; + maxTime = 500; + precision = 1e-6; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + myProblem.setNewtonSolver(precision,20); + myProblem.usePrimitiveVarsInNewton(True) + + # evolution + myProblem.initialize(); + + ok = myProblem.run(); + if (ok): + print( "Simulation python " + fileName + " is successful !" ); + pass + else: + print( "Simulation python " + fileName + " failed ! " ); + pass + + print( "------------ End of calculation !!! -----------" ); + + myProblem.terminate(); + return ok + +if __name__ == """__main__""": + SinglePhase_1DRiemannProblem() diff --git a/CoreFlows/examples/Python/SinglePhase/SinglePhase_1DWaterHammer.py b/CoreFlows/examples/Python/SinglePhase/SinglePhase_1DWaterHammer.py new file mode 100755 index 0000000..fd67cb8 --- /dev/null +++ b/CoreFlows/examples/Python/SinglePhase/SinglePhase_1DWaterHammer.py @@ -0,0 +1,91 @@ +#!/usr/bin/env python +# -*-coding:utf-8 -* + +import CoreFlows as cf +import cdmath as cm + +def SinglePhase_1DWaterHammer(): + + spaceDim = 1; + # Prepare for the mesh + print("Building mesh " ); + xinf = 0 ; + xsup=4.2; + nx=50; + M=cm.Mesh(xinf,xsup,nx) + + # set the initial field + + initialPressure=155e5; + initialVelocityX=-5; + initialTemperature=573; + + # set the limit field for each boundary + + wallVelocityX=0; + wallTemperature=573; + + myProblem = cf.SinglePhase(cf.Liquid,cf.around155bars600K,spaceDim); + nVar = myProblem.getNumberOfVariables(); + + # Prepare for the initial condition + VV_Constant =[0]*nVar; + + # constant vector + VV_Constant[0] = initialPressure ; + VV_Constant[1] = initialVelocityX; + VV_Constant[2] = initialTemperature ; + + + #Initial field creation + print("Building initial data" ); + myProblem.setInitialFieldConstant( spaceDim, VV_Constant, xinf, xsup, nx,"wall","neumann"); + + # set the boundary conditions + myProblem.setWallBoundaryCondition("wall", wallTemperature, wallVelocityX); + myProblem.setNeumannBoundaryCondition("neumann"); + + + # set the numerical method + myProblem.setNumericalScheme(cf.upwind, cf.Explicit); + + # name of result file + fileName = "1DSinglePhase_1DWaterHammer"; + + # simulation parameters + MaxNbOfTimeStep = 3 ; + freqSave = 1; + cfl = 0.95; + maxTime = 500; + precision = 1e-6; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + myProblem.setNewtonSolver(precision,20); + #myProblem.saveConservativeField(True); + if(spaceDim>1): + myProblem.saveVelocity(); + pass + + # evolution + myProblem.initialize(); + + ok = myProblem.run(); + if (ok): + print( "Simulation python " + fileName + " is successful !" ); + pass + else: + print( "Simulation python " + fileName + " failed ! " ); + pass + + print( "------------ End of calculation !!! -----------" ); + + myProblem.terminate(); + return ok + +if __name__ == """__main__""": + SinglePhase_1DWaterHammer() diff --git a/CoreFlows/examples/Python/SinglePhase/SinglePhase_2BranchesHeatedChannels.py b/CoreFlows/examples/Python/SinglePhase/SinglePhase_2BranchesHeatedChannels.py new file mode 100755 index 0000000..7a6554a --- /dev/null +++ b/CoreFlows/examples/Python/SinglePhase/SinglePhase_2BranchesHeatedChannels.py @@ -0,0 +1,100 @@ +#!/usr/bin/env python +# -*-coding:utf-8 -* + +import CoreFlows as cf +import cdmath as cm + + +def SinglePhase_2BranchesHeatedChannels(): + + spaceDim = 1; + # Prepare for the mesh + M=cm.Mesh("../resources/BifurcatingFlow2BranchesEqualSections.med") + M.getFace(0).setGroupName("Inlet")#z=0 + M.getFace(31).setGroupName("Outlet")#z=4.2 + + # set the initial field + initialPressure=155e5; + initialVelocityX=5; + initialTemperature=573; + + # set the limit field for each boundary + inletVelocityX=5; + inletTemperature=573; + outletPressure=155e5 + + myProblem = cf.SinglePhase(cf.Liquid,cf.around155bars600K,spaceDim); + nVar = myProblem.getNumberOfVariables(); + + # Prepare for the initial condition + VV_Constant =[0]*nVar; + + # constant vector + VV_Constant[0] = initialPressure ; + VV_Constant[1] = initialVelocityX; + VV_Constant[2] = initialTemperature ; + + + #Initial field creation + print("Building initial data" ); + myProblem.setInitialFieldConstant( M, VV_Constant); + + # set the boundary conditions + myProblem.setInletBoundaryCondition("Inlet", inletTemperature, inletVelocityX); + myProblem.setOutletBoundaryCondition("Outlet",outletPressure); + + #set porosity, heat and gravity source + Sections=cm.Field("../resources/BifurcatingFlow2BranchesEqualSections", cm.CELLS,"Section area"); + heatPowerField=cm.Field("../resources/BifurcatingFlow2BranchesEqualSections", cm.CELLS,"Heat power"); + + heatPowerField.writeVTK("heatPowerField"); + Sections.writeVTK("crossSectionPowerField"); + + myProblem.setSectionField(Sections); + myProblem.setHeatPowerField(heatPowerField) + gravite=[-10] + myProblem.setGravity(gravite) + # set the numerical method + myProblem.setNumericalScheme(cf.upwind, cf.Explicit); + myProblem.setWellBalancedCorrection(True) + + # name of result file + fileName = "2BranchesHeatedChannels"; + + # simulation parameters + MaxNbOfTimeStep = 3 ; + freqSave = 1; + cfl = 0.95; + maxTime = 500; + precision = 1e-6; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + myProblem.setNewtonSolver(precision,20); + #myProblem.saveConservativeField(True); + if(spaceDim>1): + myProblem.saveVelocity(); + pass + + # evolution + myProblem.initialize(); + + ok = myProblem.run(); + if (ok): + print( "Simulation python " + fileName + " is successful !" ); + pass + else: + print( "Simulation python " + fileName + " failed ! " ); + pass + + print( "------------ End of calculation !!! -----------" ); + + myProblem.terminate(); + return ok + +if __name__ == """__main__""": + SinglePhase_2BranchesHeatedChannels() diff --git a/CoreFlows/examples/Python/SinglePhase/SinglePhase_2DHeatedChannelInclined.py b/CoreFlows/examples/Python/SinglePhase/SinglePhase_2DHeatedChannelInclined.py new file mode 100755 index 0000000..2cc5289 --- /dev/null +++ b/CoreFlows/examples/Python/SinglePhase/SinglePhase_2DHeatedChannelInclined.py @@ -0,0 +1,104 @@ +#!/usr/bin/env python +# -*-coding:utf-8 -* + +import CoreFlows as cf + +def SinglePhase_2DHeatedChannelInclined(): + spaceDim = 2; + + # Prepare the mesh data + xinf = 0 ; + xsup=3.0; + yinf=0.0; + ysup=5.0; + nx=50; + ny=50; + + # set the limit field for each boundary + wallVelocityX=0; + wallVelocityY=0; + wallTemperature=573; + inletVelocityX=0; + inletVelocityY=0.5; + inletTemperature=563; + outletPressure=155e5; + + # physical constants + gravite = [0] * spaceDim + + gravite[1]=-7; + gravite[0]=7; + + heatPower=1e8; + + myProblem = cf.SinglePhase(cf.Liquid,cf.around155bars600K,spaceDim); + nVar =myProblem.getNumberOfVariables(); + + # Prepare for the initial condition + VV_Constant =[0]*nVar + + # constant vector + VV_Constant[0] = outletPressure ; + VV_Constant[1] = inletVelocityX; + VV_Constant[2] = inletVelocityY; + VV_Constant[3] = inletTemperature ; + + #Initial field creation + print("Building mesh and initial data" ); + myProblem.setInitialFieldConstant(spaceDim,VV_Constant, + xinf,xsup,nx,"wall","wall", + yinf,ysup,ny,"inlet","outlet", + 0.0,0.0, 0, "", "") + + # the boundary conditions + myProblem.setOutletBoundaryCondition("outlet", outletPressure,[xsup,ysup]); + myProblem.setInletBoundaryCondition("inlet", inletTemperature, inletVelocityX, inletVelocityY); + myProblem.setWallBoundaryCondition("wall", wallTemperature, wallVelocityX, wallVelocityY); + # set physical parameters + + myProblem.setHeatSource(heatPower); + myProblem.setGravity(gravite); + + # set the numerical method + myProblem.setNumericalScheme(cf.staggered, cf.Implicit); + myProblem.setWellBalancedCorrection(False); + + # name file save + fileName = "2DInclinedHeatedChannel"; + + # parameters calculation + MaxNbOfTimeStep = 3 ; + freqSave = 1; + cfl = 0.5; + maxTime = 5000; + precision = 1e-6; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + myProblem.saveConservativeField(True); + if(spaceDim>1): + myProblem.saveVelocity(); + pass + + # evolution + myProblem.initialize(); + + ok = myProblem.run(); + if (ok): + print( "Simulation python " + fileName + " is successful !" ); + pass + else: + print( "Simulation python " + fileName + " failed ! " ); + pass + + print( "------------ End of calculation !!! -----------" ); + + myProblem.terminate(); + return ok + +if __name__ == """__main__""": + SinglePhase_2DHeatedChannelInclined() diff --git a/CoreFlows/examples/Python/SinglePhase/SinglePhase_2DLidDrivenCavity.py b/CoreFlows/examples/Python/SinglePhase/SinglePhase_2DLidDrivenCavity.py new file mode 100755 index 0000000..9eb9976 --- /dev/null +++ b/CoreFlows/examples/Python/SinglePhase/SinglePhase_2DLidDrivenCavity.py @@ -0,0 +1,104 @@ +#!/usr/bin/env python +# -*-coding:utf-8 -* + + +import CoreFlows as cf + +def SinglePhase_2DLidDrivenCavity(): + + spaceDim = 2; + #Preprocessing: mesh data + xinf=0; + xsup=1; + yinf=0; + ysup=1; + + nx=50; + ny=50; + + # set the limit field for each boundary + + fixedWallVelocityX=0; + fixedWallVelocityY=0; + fixedWallTemperature=273; + + movingWallVelocityX=1; + movingWallVelocityY=0; + movingWallTemperature=273; + + # physical constants + + viscosite=[0.025]; + + myProblem = cf.SinglePhase(cf.Gas,cf.around1bar300K,spaceDim); + nVar = myProblem.getNumberOfVariables(); + + #Initial field creation + print("Building initial data " ); + + # Prepare for the initial condition + + VV_Constant = [0] * nVar + + # constant vector + VV_Constant[0] = 1e5; + VV_Constant[1] = 0 ; + VV_Constant[2] = 0; + VV_Constant[3] = 273; + + #Initial field creation + print("Building mesh and initial data" ); + myProblem.setInitialFieldConstant(spaceDim,VV_Constant,xinf,xsup,nx,"fixedWall","fixedWall",yinf,ysup,ny,"fixedWall","movingWall"); + + # Set the boundary conditions + myProblem.setWallBoundaryCondition("fixedWall", fixedWallTemperature, fixedWallVelocityX, fixedWallVelocityY); + myProblem.setWallBoundaryCondition("movingWall", movingWallTemperature, movingWallVelocityX, movingWallVelocityY); + + # set physical parameters + myProblem.setViscosity(viscosite); + + # set the numerical method + myProblem.setNumericalScheme(cf.staggered, cf.Implicit); + myProblem.setLinearSolver(cf.GMRES,cf.LU,True); + + # name file save + fileName = "2DLidDrivenCavity"; + + # simulation parameters + MaxNbOfTimeStep = 3 ; + freqSave = 1; + cfl = 10; + maxTime = 50; + precision = 1e-9; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + myProblem.setNewtonSolver(float('inf'),20); + myProblem.saveConservativeField(True); + if(spaceDim>1): + myProblem.saveVelocity(); + pass + + # evolution + myProblem.initialize(); + + ok = myProblem.run(); + if (ok): + print( "Simulation python " + fileName + " is successful !" ); + pass + else: + print( "Simulation python " + fileName + " failed ! " ); + pass + + print( "------------ End of calculation !!! -----------" ); + + myProblem.terminate(); + return ok + + +if __name__ == """__main__""": + SinglePhase_2DLidDrivenCavity() diff --git a/CoreFlows/examples/Python/SinglePhase/SinglePhase_2DLidDrivenCavity_unstructured.py b/CoreFlows/examples/Python/SinglePhase/SinglePhase_2DLidDrivenCavity_unstructured.py new file mode 100755 index 0000000..a7380dc --- /dev/null +++ b/CoreFlows/examples/Python/SinglePhase/SinglePhase_2DLidDrivenCavity_unstructured.py @@ -0,0 +1,99 @@ +#!/usr/bin/env python +# -*-coding:utf-8 -* + + +import CoreFlows as cf + +def SinglePhase_2DLidDrivenCavity_unstructured(): + spaceDim = 2; + + print( "Loading unstructured mesh " ); + inputfile="../resources/BoxWithMeshWithTriangularCells.med"; + + # set the limit field for each boundary + + fixedWallVelocityX=0; + fixedWallVelocityY=0; + fixedWallTemperature=273; + + movingWallVelocityX=1; + movingWallVelocityY=0; + movingWallTemperature=273; + + # physical constants + + viscosite=[0.025]; + + myProblem = cf.SinglePhase(cf.Gas,cf.around1bar300K,spaceDim); + nVar = myProblem.getNumberOfVariables(); + + #Initial field creation + print("Building initial data " ); + + # Prepare for the initial condition + + VV_Constant = [0] * nVar + + # constant vector + VV_Constant[0] = 1e5; + VV_Constant[1] = 0 ; + VV_Constant[2] = 0; + VV_Constant[3] = 273; + + #Initial field creation + print("Setting mesh and initial data" ); + myProblem.setInitialFieldConstant(inputfile,VV_Constant); + + # Set the boundary conditions + myProblem.setWallBoundaryCondition("BAS", fixedWallTemperature, fixedWallVelocityX, fixedWallVelocityY); + myProblem.setWallBoundaryCondition("GAUCHE", fixedWallTemperature, fixedWallVelocityX, fixedWallVelocityY); + myProblem.setWallBoundaryCondition("DROITE", fixedWallTemperature, fixedWallVelocityX, fixedWallVelocityY); + myProblem.setWallBoundaryCondition("HAUT", movingWallTemperature, movingWallVelocityX, movingWallVelocityY); + + # set physical parameters + myProblem.setViscosity(viscosite); + + # set the numerical method + myProblem.setNumericalScheme(cf.pressureCorrection, cf.Implicit); + myProblem.setLinearSolver(cf.GMRES,cf.ILU,True); + + # name file save + fileName = "2DLidDrivenCavityUnstructured"; + + # simulation parameters + MaxNbOfTimeStep = 3 ; + freqSave = 1; + cfl = 10; + maxTime = 50; + precision = 1e-9; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + myProblem.setNewtonSolver(precision,20); + myProblem.saveConservativeField(True); + if(spaceDim>1): + myProblem.saveVelocity(); + pass + + # evolution + myProblem.initialize(); + + ok = myProblem.run(); + if (ok): + print( "Simulation python " + fileName + " is successful !" ); + pass + else: + print( "Simulation python " + fileName + " failed ! " ); + pass + + print( "------------ End of calculation !!! -----------" ); + + myProblem.terminate(); + return ok + +if __name__ == """__main__""": + SinglePhase_2DLidDrivenCavity_unstructured() diff --git a/CoreFlows/examples/Python/SinglePhase/SinglePhase_2DPoiseuilleFlow.py b/CoreFlows/examples/Python/SinglePhase/SinglePhase_2DPoiseuilleFlow.py new file mode 100644 index 0000000..ba23937 --- /dev/null +++ b/CoreFlows/examples/Python/SinglePhase/SinglePhase_2DPoiseuilleFlow.py @@ -0,0 +1,109 @@ +#!/usr/bin/env python +# -*-coding:utf-8 -* + +import CoreFlows as cf +import cdmath as cm + +def SinglePhase_2DPoiseuilleFlow(): + spaceDim = 2; + + print("Building the mesh" ); + # Prepare the mesh data + xinf = 0 ; + xsup = 1.0; + yinf = 0.0; + ysup = 4; + nx = 10; + ny = 40; + + my_mesh=cm.Mesh(xinf,xsup,nx,yinf,ysup,ny) + # set the boundary names for each boundary + eps=1e-6; + my_mesh.setGroupAtPlan(xsup,0,eps,"wall") + my_mesh.setGroupAtPlan(xinf,0,eps,"wall") + my_mesh.setGroupAtPlan(ysup,1,eps,"neumann") + my_mesh.setGroupAtPlan(yinf,1,eps,"neumann") + + # physical constants + viscosity=0.025 + viscosite=[viscosity]; + Vy_max = 1.5 + a = -8*viscosity*Vy_max / ((ysup-yinf)*(ysup-yinf) ) #pressure slope + + initialTemperature = 573 + outletPressure = 155e5 + + initial_field=cm.Field("Initial field", cm.CELLS, my_mesh, 4) + for i in range( 0 , my_mesh.getNumberOfCells() ): + Ci=my_mesh.getCell(i) + x=Ci.x() + y=Ci.y() + initial_field[i,0] = outletPressure + a*(y - ysup ) + initial_field[i,1] = 0 #x component of the velocity + initial_field[i,2] = a/(2*viscosity)*( (x-(xsup+xinf)/2)*(x-(xsup+xinf)/2) - (xsup-xinf)*(xsup-xinf)/4) #y component of the velocity + initial_field[i,3] = initialTemperature + + + # set the limit field for each boundary + wallVelocityX=0; + wallVelocityY=0; + wallTemperature=573; + + myProblem = cf.SinglePhase(cf.Liquid,cf.around155bars600K,spaceDim); + nVar =myProblem.getNumberOfVariables(); + + #Initial field creation + print("Setting initial data" ); + myProblem.setInitialField(initial_field) + + # the boundary conditions + myProblem.setWallBoundaryCondition("wall", wallTemperature, wallVelocityX, wallVelocityY); + myProblem.setNeumannBoundaryCondition("neumann"); + + # set physical parameters + myProblem.setViscosity(viscosite); + + # set the numerical method + myProblem.setNumericalScheme(cf.upwind, cf.Implicit); + #myProblem.setLinearSolver(cf.GMRES,cf.LU,True); + + # name file save + fileName = "2DPoiseuilleFlow"; + + # parameters calculation + MaxNbOfTimeStep = 10000 ; + freqSave = 1; + cfl = 0.5; + maxTime = 5000; + precision = 1e-6; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setNewtonSolver(float('inf'),20); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + myProblem.saveConservativeField(True); + if(spaceDim>1): + myProblem.saveVelocity(); + pass + + # evolution + myProblem.initialize(); + + ok = myProblem.run(); + if (ok): + print( "Simulation python " + fileName + " is successful !" ); + pass + else: + print( "Simulation python " + fileName + " failed ! " ); + pass + + print( "------------ End of calculation !!! -----------" ); + + myProblem.terminate(); + return ok + +if __name__ == """__main__""": + SinglePhase_2DPoiseuilleFlow() diff --git a/CoreFlows/examples/Python/SinglePhase/SinglePhase_2DPoiseuilleFlow_outputFields.py b/CoreFlows/examples/Python/SinglePhase/SinglePhase_2DPoiseuilleFlow_outputFields.py new file mode 100644 index 0000000..4ef030e --- /dev/null +++ b/CoreFlows/examples/Python/SinglePhase/SinglePhase_2DPoiseuilleFlow_outputFields.py @@ -0,0 +1,199 @@ +#!/usr/bin/env python +# -*-coding:utf-8 -* + +import CoreFlows as cf +import cdmath as cm + +def SinglePhase_2DPoiseuilleFlow(): + spaceDim = 2; + + print("Building the mesh" ); + # Prepare the mesh data + xinf = 0 ; + xsup = 1.0; + yinf = 0.0; + ysup = 4; + nx = 10; + ny = 40; + + my_mesh=cm.Mesh(xinf,xsup,nx,yinf,ysup,ny) + # set the boundary names for each boundary + eps=1e-6; + my_mesh.setGroupAtPlan(xsup,0,eps,"wall") + my_mesh.setGroupAtPlan(xinf,0,eps,"wall") + my_mesh.setGroupAtPlan(ysup,1,eps,"neumann") + my_mesh.setGroupAtPlan(yinf,1,eps,"neumann") + + # physical constants + viscosity=0.025 + viscosite=[viscosity]; + Vy_max = 1.5 + a = -8*viscosity*Vy_max / ((ysup-yinf)*(ysup-yinf) ) #pressure slope + + initialTemperature = 573 + outletPressure = 155e5 + + initial_field=cm.Field("Initial field", cm.CELLS, my_mesh, 4) + for i in range( 0 , my_mesh.getNumberOfCells() ): + Ci=my_mesh.getCell(i) + x=Ci.x() + y=Ci.y() + initial_field[i,0] = outletPressure + a*(y - ysup ) + initial_field[i,1] = 0 #x component of the velocity + initial_field[i,2] = a/(2*viscosity)*( (x-(xsup+xinf)/2)*(x-(xsup+xinf)/2) - (xsup-xinf)*(xsup-xinf)/4) #y component of the velocity + initial_field[i,3] = initialTemperature + + + # set the limit field for each boundary + wallVelocityX=0; + wallVelocityY=0; + wallTemperature=573; + + myProblem = cf.SinglePhase(cf.Liquid,cf.around155bars600K,spaceDim); + nVar =myProblem.getNumberOfVariables(); + + #Initial field creation + print("Setting initial data" ); + myProblem.setInitialField(initial_field) + + # the boundary conditions + myProblem.setWallBoundaryCondition("wall", wallTemperature, wallVelocityX, wallVelocityY); + myProblem.setNeumannBoundaryCondition("neumann"); + + # set physical parameters + myProblem.setViscosity(viscosite); + + # set the numerical method + myProblem.setNumericalScheme(cf.upwind, cf.Implicit); + #myProblem.setLinearSolver(cf.GMRES,cf.LU,True); + + # name file save + fileName = "2DPoiseuilleFlow"; + + # parameters calculation + MaxNbOfTimeStep = 10000 ; + freqSave = 1; + cfl = 0.5; + maxTime = 5000; + precision = 1e-6; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setNewtonSolver(float('inf'),20); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + myProblem.saveConservativeField(True); + if(spaceDim>1): + myProblem.saveVelocity(); + pass + + # evolution + myProblem.initialize(); + + ok = myProblem.run(); + if (ok): + print( "Simulation python " + fileName + " is successful !" ); + pass + else: + print( "Simulation python " + fileName + " failed ! " ); + pass + + print( "------------ End of calculation !!! -----------" ); + + message=myProblem.getOutputFieldsNames() + numberOfFields=len(message) + + for i in range(numberOfFields): + print( message[i]) + + pressureField=myProblem.getOutputField("Pressure") + pressureField.writeMED("pressureField") + pressureField.writeVTK("pressureField") + print("Pressure in first cell ", pressureField[0]) + + PressureField=myProblem.getPressureField() + PressureField.writeMED("PressureField2") + PressureField.writeVTK("PressureField2") + print("Pressure in first cell ", pressureField[0]) + + temperatureField=myProblem.getTemperatureField() + temperatureField.writeMED("temperatureField") + temperatureField.writeVTK("temperatureField") + print("Temperature in first cell ", temperatureField[0]) + + temperatureField=myProblem.getOutputField("Temperature") + temperatureField.writeMED("temperatureField2") + temperatureField.writeVTK("temperatureField2") + print("Temperature in first cell ", temperatureField[0]) + + velocityField=myProblem.getVelocityField() + velocityField.writeMED("velocityField") + velocityField.writeVTK("velocityField") + print("Velocity X in first cell ", velocityField[0,0]) + print("Velocity Y in first cell ", velocityField[0,1]) + + velocityField=myProblem.getOutputField("Velocity") + velocityField.writeMED("velocityField2") + velocityField.writeVTK("velocityField2") + print("Velocity X in first cell ", velocityField[0,0]) + print("Velocity Y in first cell ", velocityField[0,1]) + + densityField=myProblem.getDensityField() + densityField.writeMED("densityField") + densityField.writeVTK("densityField") + print("Density in first cell ", densityField[0]) + + densityField=myProblem.getOutputField("Density") + densityField.writeMED("densityField2") + densityField.writeVTK("densityField2") + print("Density in first cell ", densityField[0]) + + momentumField=myProblem.getMomentumField() + momentumField.writeMED("momentumField") + momentumField.writeVTK("momentumField") + print("Momentum X in first cell ", momentumField[0,0]) + print("Momentum Y in first cell ", momentumField[0,1]) + + momentumField=myProblem.getOutputField("Momentum") + momentumField.writeMED("momentumField2") + momentumField.writeVTK("momentumField2") + print("Momentum X in first cell ", momentumField[0,0]) + print("Momentum Y in first cell ", momentumField[0,1]) + + totalEnergyField=myProblem.getTotalEnergyField() + totalEnergyField.writeMED("totalEnergyField") + totalEnergyField.writeVTK("totalEnergyField") + print("Total energy in first cell ", totalEnergyField[0]) + + totalEnergyField=myProblem.getOutputField("TotalEnergy") + totalEnergyField.writeMED("totalEnergyField2") + totalEnergyField.writeVTK("totalEnergyField2") + print("Total energy in first cell ", totalEnergyField[0]) + + enthalpyField=myProblem.getEnthalpyField() + enthalpyField.writeMED("enthalpyField") + enthalpyField.writeVTK("enthalpyField") + print("Enthalpy in first cell ", enthalpyField[0]) + + enthalpyField=myProblem.getOutputField("Enthalpy") + enthalpyField.writeMED("enthalpyField2") + enthalpyField.writeVTK("enthalpyField2") + print("Enthalpy in first cell ", enthalpyField[0]) + + velocityXField=myProblem.getVelocityXField() + velocityXField.writeMED("velocityXField") + velocityXField.writeVTK("velocityXField") + print("Velocity X in first cell ", velocityXField[0]) + + velocityXField=myProblem.getOutputField("VelocityX") + velocityXField.writeMED("velocityXField2") + velocityXField.writeVTK("velocityXField2") + print("Velocity X in first cell ", velocityXField[0]) + + myProblem.terminate(); + return ok + +if __name__ == """__main__""": + SinglePhase_2DPoiseuilleFlow() diff --git a/CoreFlows/examples/Python/SinglePhase/SinglePhase_2DPoiseuilleFlow_restart.py b/CoreFlows/examples/Python/SinglePhase/SinglePhase_2DPoiseuilleFlow_restart.py new file mode 100644 index 0000000..647aa3e --- /dev/null +++ b/CoreFlows/examples/Python/SinglePhase/SinglePhase_2DPoiseuilleFlow_restart.py @@ -0,0 +1,121 @@ +#!/usr/bin/env python +# -*-coding:utf-8 -* + +import CoreFlows as cf + +def SinglePhase_2DPoiseuilleFlow(): + spaceDim = 2; + + # Prepare the mesh data + xinf = 0 ; + xsup=1.0; + yinf=0.0; + ysup=4; + nx=10; + ny=40; + + # set the limit field for each boundary + wallVelocityX=0; + wallVelocityY=0; + wallTemperature=573; + + # physical constants + viscosite=[0.025]; + + myProblem = cf.SinglePhase(cf.Liquid,cf.around155bars600K,spaceDim); + nVar =myProblem.getNumberOfVariables(); + + # Prepare for the initial condition + VV_Constant =[0]*nVar + + # constant vector + initialVelocityX=0; + initialVelocityY=1; + initialTemperature=573; + initialPressure=155e5; + VV_Constant[0] = initialPressure ; + VV_Constant[1] = initialVelocityX; + VV_Constant[2] = initialVelocityY; + VV_Constant[3] = initialTemperature ; + + #Initial field creation + print("Building mesh and initial data" ); + myProblem.setInitialFieldConstant(spaceDim,VV_Constant, + xinf,xsup,nx,"wall","wall", + yinf,ysup,ny,"neumann","neumann", + 0.0,0.0, 0, "", "") + + # the boundary conditions + myProblem.setWallBoundaryCondition("wall", wallTemperature, wallVelocityX, wallVelocityY); + myProblem.setNeumannBoundaryCondition("neumann"); + + # set physical parameters + myProblem.setViscosity(viscosite); + + # set the numerical method + myProblem.setNumericalScheme(cf.upwind, cf.Explicit); + + # name file save + fileName = "2DPoiseuilleFlowExplicit_Phase1"; + + # parameters calculation + MaxNbOfTimeStep = 10 + freqSave = 1; + cfl = 0.5; + maxTime = 5000; + precision = 1e-7; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setNewtonSolver(1e-3,20); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + myProblem.saveConservativeField(True); + if(spaceDim>1): + myProblem.saveVelocity(); + pass + + # evolution + myProblem.initialize(); + + ok = myProblem.run(); + if (ok): + print( "Simulation python " + fileName + " is successful !" ); + pass + else: + print( "Simulation python " + fileName + " failed ! " ); + pass + + print( "------------ End of Phase 1 !!! -----------" ); + + # set the numerical method + myProblem.setNumericalScheme(cf.upwind, cf.Implicit); + + # name file save + fileName = "2DPoiseuilleFlowImplicit_Phase2"; + + cfl = 0.5; + MaxNbOfTimeStep = 20 ; + myProblem.setCFL(cfl); + myProblem.setNewtonSolver(1e-6,20); + myProblem.setFileName(fileName); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + + # evolution + ok = myProblem.run(); + if (ok): + print( "Simulation python " + fileName + " is successful !" ); + pass + else: + print( "Simulation python " + fileName + " failed ! " ); + pass + + print( "------------ End of phase 2 !!! -----------" ); + + myProblem.terminate(); + return ok + +if __name__ == """__main__""": + SinglePhase_2DPoiseuilleFlow() diff --git a/CoreFlows/examples/Python/SinglePhase/SinglePhase_2DSphericalExplosion_unstructured.py b/CoreFlows/examples/Python/SinglePhase/SinglePhase_2DSphericalExplosion_unstructured.py new file mode 100755 index 0000000..ca6b79c --- /dev/null +++ b/CoreFlows/examples/Python/SinglePhase/SinglePhase_2DSphericalExplosion_unstructured.py @@ -0,0 +1,77 @@ +#!/usr/bin/env python +# -*-coding:utf-8 -* + +import CoreFlows as cf + + + +def SinglePhase_2DSphericalExplosion_unstructured(): + + inputfile="../resources/BoxWithMeshWithTriangularCells"; + fieldName="Initial variables for spherical explosion"; + spaceDim=2 + + myProblem = cf.SinglePhase(cf.Liquid,cf.around155bars600K,spaceDim); + nVar=myProblem.getNumberOfVariables(); + + # Initial field creation + print ("Loading unstructured mesh and initial data for test SinglePhase_2DSphericalExplosion_unstructured()" ) ; + myProblem.setInitialField(inputfile,fieldName,0); + + # set the boundary conditions + wallVelocityX=0; + wallVelocityY=0; + wallTemperature=563; + + myProblem.setWallBoundaryCondition("GAUCHE", wallTemperature, wallVelocityX, wallVelocityY); + myProblem.setWallBoundaryCondition("DROITE", wallTemperature, wallVelocityX, wallVelocityY); + myProblem.setWallBoundaryCondition("HAUT", wallTemperature, wallVelocityX, wallVelocityY); + myProblem.setWallBoundaryCondition("BAS", wallTemperature, wallVelocityX, wallVelocityY); + + # set the numerical method + myProblem.setNumericalScheme(cf.upwind, cf.Explicit); + myProblem.setLinearSolver(cf.GMRES,cf.ILU,True); + myProblem.setEntropicCorrection(False); + myProblem.setWellBalancedCorrection(False); + + # name file save + fileName = "2DSphericalExplosion_unstructured"; + + # parameters calculation + MaxNbOfTimeStep = 3 ; + freqSave = 5; + cfl = 0.5; + maxTime = 5; + precision = 1e-6; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + myProblem.setNewtonSolver(precision,20); + myProblem.saveConservativeField(True); + if(spaceDim>1): + myProblem.saveVelocity(); + pass + + + # evolution + myProblem.initialize(); + + ok = myProblem.run(); + if (ok): + print( "Simulation python " + fileName + " is successful !" ); + pass + else: + print( "Simulation python " + fileName + " failed ! " ); + pass + + print( "------------ End of calculation !!! -----------" ); + + myProblem.terminate(); + return ok + +if __name__ == """__main__""": + SinglePhase_2DSphericalExplosion_unstructured() diff --git a/CoreFlows/examples/Python/SinglePhase/SinglePhase_2DThermalDiffusion.py b/CoreFlows/examples/Python/SinglePhase/SinglePhase_2DThermalDiffusion.py new file mode 100755 index 0000000..fdfd695 --- /dev/null +++ b/CoreFlows/examples/Python/SinglePhase/SinglePhase_2DThermalDiffusion.py @@ -0,0 +1,121 @@ +#!/usr/bin/env python +# -*-coding:utf-8 -* + + +import CoreFlows as cf +import cdmath as cm +import math + +def SinglePhase_2DThermalDiffusion(): + spaceDim = 2; + + # Prepare for the mesh + print("Building mesh " ); + xinf = 0 ; + xsup=0.2; + yinf=0.0; + ysup=0.4; + nx=10; + ny=20; + discontinuity=(xinf+xsup)/2 + M=cm.Mesh(xinf,xsup,nx,yinf,ysup,ny) + # set the limit field for each boundary + eps=1e-6; + M.setGroupAtPlan(xsup,0,eps,"RightWall") + M.setGroupAtPlan(xinf,0,eps,"LeftWall") + M.setGroupAtPlan(ysup,1,eps,"outlet") + dx=(xsup-xinf)/nx + ndis=(discontinuity-xinf)/dx + print("ndis=",math.floor(ndis) ); + i=0 + while i<= ndis: + M.setGroupAtFaceByCoords(xinf+(i+0.5)*dx,yinf,0,eps,"inlet_1") + i=i+1 + while i<= nx: + M.setGroupAtFaceByCoords(xinf+(i+0.5)*dx,yinf,0,eps,"inlet_2") + i=i+1 + + + # set the limit field for each boundary + inletVelocityX=0; + inletVelocityY=1; + inletTemperature1=563; + inletTemperature2=593; + outletPressure=155e5; + + viscosite= [1.5]; + conductivite=[5000]; + + myProblem = cf.SinglePhase(cf.Liquid,cf.around155bars600K,spaceDim); + nVar =myProblem.getNumberOfVariables(); + + # Prepare for the initial condition + VV_Constant_Left =cm.Vector(nVar) + VV_Constant_Right =cm.Vector(nVar) + + # constant vectors + VV_Constant_Left[0] = outletPressure ; + VV_Constant_Left[1] = inletVelocityX; + VV_Constant_Left[2] = inletVelocityY; + VV_Constant_Left[3] = inletTemperature1 ; + + VV_Constant_Right[0] = outletPressure ; + VV_Constant_Right[1] = inletVelocityX; + VV_Constant_Right[2] = inletVelocityY; + VV_Constant_Right[3] = inletTemperature2 ; + + print("Building initial data" ); + myProblem.setInitialFieldStepFunction(M,VV_Constant_Left,VV_Constant_Right,discontinuity) + + + # the boundary conditions + myProblem.setOutletBoundaryCondition("outlet", outletPressure); + myProblem.setInletBoundaryCondition("inlet_1", inletTemperature1, inletVelocityX, inletVelocityY); + myProblem.setInletBoundaryCondition("inlet_2", inletTemperature2, inletVelocityX, inletVelocityY); + myProblem.setWallBoundaryCondition("LeftWall", inletTemperature1, 0,0); + myProblem.setWallBoundaryCondition("RightWall", inletTemperature2, 0,0); + + + myProblem.setViscosity(viscosite); + myProblem.setConductivity(conductivite); + + # set the numerical method + myProblem.setNumericalScheme(cf.staggered, cf.Implicit); + + # name file save + fileName = "2DThermalDiffusion"; + + # parameters calculation + MaxNbOfTimeStep = 3 ; + freqSave = 1; + cfl = .01; + maxTime = 5000; + precision = 1e-6; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + myProblem.setNewtonSolver(precision,20); + myProblem.saveVelocity(); + + # evolution + myProblem.initialize(); + + ok = myProblem.run(); + if (ok): + print( "Simulation python " + fileName + " is successful !" ); + pass + else: + print( "Simulation python " + fileName + " failed ! " ); + pass + + print( "------------ End of calculation !!! -----------" ); + + myProblem.terminate(); + return ok + +if __name__ == """__main__""": + SinglePhase_2DThermalDiffusion() diff --git a/CoreFlows/examples/Python/SinglePhase/SinglePhase_2DVidangeReservoir.py b/CoreFlows/examples/Python/SinglePhase/SinglePhase_2DVidangeReservoir.py new file mode 100755 index 0000000..18e3e90 --- /dev/null +++ b/CoreFlows/examples/Python/SinglePhase/SinglePhase_2DVidangeReservoir.py @@ -0,0 +1,120 @@ +#!/usr/bin/env python +# -*-coding:utf-8 -* + +import CoreFlows as cf +import cdmath as cm + +def SinglePhase_2DVidangeReservoir(): + + spaceDim = 2; + # Prepare for the mesh + print("Building mesh " ); + xinf = 0 ; + xsup=1.0; + yinf=0.0; + ysup=1.0; + nx=50; + ny=50; + diametreSortie=(ysup-yinf)/10.#10 percent of the height + nsortie=ny*diametreSortie/(ysup-yinf) + M=cm.Mesh(xinf,xsup,nx,yinf,ysup,ny) + # set the limit field for each boundary + eps=1e-6; + M.setGroupAtPlan(xinf,0,eps,"wall") + M.setGroupAtPlan(ysup,1,eps,"inlet") + M.setGroupAtPlan(yinf,1,eps,"wall") + dy=(ysup-yinf)/ny + i=0 + while i < nsortie: + M.setGroupAtFaceByCoords(xsup,yinf+(i+0.5)*dy,0,eps,"outlet") + i=i+1 + while i < ny: + M.setGroupAtFaceByCoords(xsup,yinf+(i+0.5)*dy,0,eps,"wall") + i=i+1 + + + + # set the limit field for each boundary + wallVelocityX=0; + wallVelocityY=0; + wallTemperature=300; + inletTemperature=300; + outletPressure=1e5; + + # set the limit field for each boundary + initialVelocityX=0; + initialVelocityY=0; + initialTemperature=300; + initialPressure=1e5; + + # physical constants + gravite = [0] * spaceDim + + gravite[0]=0; + gravite[1]=-10; + + myProblem = cf.SinglePhase(cf.Liquid,cf.around1bar300K,spaceDim); + nVar =myProblem.getNumberOfVariables(); + # Prepare for the initial condition + VV_constant =cm.Vector(nVar) + + # constant vector + VV_constant[0] = initialPressure ; + VV_constant[1] = initialVelocityX; + VV_constant[2] = initialVelocityY; + VV_constant[3] = initialTemperature ; + + + #Initial field creation + print("Building initial data" ); + myProblem.setInitialFieldConstant( M, VV_constant) + + # the boundary conditions + myProblem.setOutletBoundaryCondition("outlet", outletPressure,[xsup,ysup]); + myProblem.setInletPressureBoundaryCondition("inlet", outletPressure, inletTemperature,[xsup,yinf]); + myProblem.setWallBoundaryCondition("wall", wallTemperature, wallVelocityX, wallVelocityY); + + # set physical parameters + myProblem.setGravity(gravite); + + # set the numerical method + myProblem.setNumericalScheme(cf.upwind, cf.Explicit); + myProblem.setLinearSolver(cf.GMRES,cf.ILU,True); + + # name file save + fileName = "2DVidangeReservoir"; + + # parameters calculation + MaxNbOfTimeStep = 3 ; + freqSave = 1; + cfl = .05; + maxTime = 5000; + precision = 1e-6; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + myProblem.setNewtonSolver(precision,20); + myProblem.saveVelocity(); + + # evolution + myProblem.initialize(); + + ok = myProblem.run(); + if (ok): + print( "Simulation python " + fileName + " is successful !" ); + pass + else: + print( "Simulation python " + fileName + " failed ! " ); + pass + + print( "------------ End of calculation !!! -----------" ); + + myProblem.terminate(); + return ok + +if __name__ == """__main__""": + SinglePhase_2DVidangeReservoir() diff --git a/CoreFlows/examples/Python/SinglePhase/SinglePhase_2DWallHeatedChannel_ChangeSect.py b/CoreFlows/examples/Python/SinglePhase/SinglePhase_2DWallHeatedChannel_ChangeSect.py new file mode 100755 index 0000000..9097c8a --- /dev/null +++ b/CoreFlows/examples/Python/SinglePhase/SinglePhase_2DWallHeatedChannel_ChangeSect.py @@ -0,0 +1,124 @@ +#!/usr/bin/env python +# -*-coding:utf-8 -* + +import CoreFlows as cf +import cdmath as cm + +def SinglePhase_2DWallHeatedChannel_ChangeSect(): + + #import themesh + print("Reading a mesh with sudden cross-section change for test SinglePhase_2DWallHeatedChannel_ChangeSect()") + M=cm.Mesh("../resources/VaryingSectionDuct.med") + + # Prepare the mesh boundaries + xinf=0.0; + xsup=0.01; + yinf=0.0; + ysup=0.01; + eps=1.E-6; + M.setGroupAtPlan(xsup,0,eps,"Wall"); + M.setGroupAtPlan(xinf,0,eps,"Wall"); + M.setGroupAtPlan(yinf,1,eps,"Inlet"); + M.setGroupAtPlan(ysup,1,eps,"Outlet"); + + #Nombre de cellules utilisees au depart dans Salome ou Alamos + nx=60 + ny=60 + #taille d'une cellule + dx = (xsup-xinf)/nx + dy = (ysup-yinf)/ny; + for i in range(ny/2): + M.setGroupAtFaceByCoords((xsup-xinf)/4,(ysup-yinf)/4+(i+0.5)*dy,0,eps,"Wall");#Paroi verticale intérieure gauche + M.setGroupAtFaceByCoords((xsup-xinf)*3/4,(ysup-yinf)/4+(i+0.5)*dy,0,eps,"Wall");#Paroi verticale intérieure droitee + + for i in range(nx/4): + M.setGroupAtFaceByCoords((i+0.5)*dx,(ysup-yinf)/4,0,eps,"Wall");#paroi horizontale en bas à gauche + M.setGroupAtFaceByCoords((i+0.5)*dx,(ysup-yinf)*3/4,0,eps,"Wall");#paroi horizontale en haut à gauche + M.setGroupAtFaceByCoords((xsup-xinf)*3/4+(i+0.5)*dx,(ysup-yinf)/4,0,eps,"Wall");#paroi horizontale en bas à droite + M.setGroupAtFaceByCoords((xsup-xinf)*3/4+(i+0.5)*dx,(ysup-yinf)*3/4,0,eps,"Wall");#paroi horizontale en haut à droite + + spaceDim = M.getSpaceDimension(); + + # set the limit field for each boundary + wallVelocityX=0; + wallVelocityY=0; + wallTemperature=623; + inletVelocityX=0; + inletVelocityY=2.5; + inletTemperature=563; + outletPressure=155e5; + + # physical constants + viscosite=[8.85e-5] + conductivite=[1000] + + myProblem = cf.SinglePhase(cf.Liquid,cf.around155bars600K,spaceDim); + nVar =myProblem.getNumberOfVariables(); + + # Prepare for the initial condition + VV_Constant =cm.Vector(nVar) + + # constant vector + VV_Constant[0] = outletPressure ; + VV_Constant[1] = inletVelocityX; + VV_Constant[2] = inletVelocityY; + VV_Constant[3] = inletTemperature ; + + #Initial field creation + print("Building mesh and initial data" ); + myProblem.setInitialFieldConstant(M,VV_Constant); + + # the boundary conditions + myProblem.setOutletBoundaryCondition("Outlet", outletPressure,[xsup,ysup]); + myProblem.setInletBoundaryCondition("Inlet", inletTemperature, inletVelocityX, inletVelocityY); + myProblem.setWallBoundaryCondition("Wall", wallTemperature, wallVelocityX, wallVelocityY); + + # set physical parameters + myProblem.setViscosity(viscosite); + myProblem.setConductivity(conductivite); + + + # set the numerical method + myProblem.setNumericalScheme(cf.upwind, cf.Implicit); + myProblem.setLinearSolver(cf.GMRES,cf.ILU,True); + + # name file save + fileName = "2DWallHeatedChannel_ChangeSect"; + + # parameters calculation + MaxNbOfTimeStep = 3 ; + freqSave = 1; + cfl = 0.5; + maxTime = 5000; + precision = 1e-6; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + myProblem.setNewtonSolver(float('inf'),20);#newton precision should be infinite for staggered scheme!!! + myProblem.saveConservativeField(True); + if(spaceDim>1): + myProblem.saveVelocity(); + pass + + # evolution + myProblem.initialize(); + + ok = myProblem.run(); + if (ok): + print( "Simulation python " + fileName + " is successful !" ); + pass + else: + print( "Simulation python " + fileName + " failed ! " ); + pass + + print( "------------ End of calculation !!! -----------" ); + + myProblem.terminate(); + return ok + +if __name__ == """__main__""": + SinglePhase_2DWallHeatedChannel_ChangeSect() diff --git a/CoreFlows/examples/Python/SinglePhase/SinglePhase_3DHeatDrivenCavity.py b/CoreFlows/examples/Python/SinglePhase/SinglePhase_3DHeatDrivenCavity.py new file mode 100755 index 0000000..c129e4c --- /dev/null +++ b/CoreFlows/examples/Python/SinglePhase/SinglePhase_3DHeatDrivenCavity.py @@ -0,0 +1,119 @@ +#!/usr/bin/env python +# -*-coding:utf-8 -* + + +import CoreFlows as cf + +def SinglePhase_3DHeatDrivenCavity(): + + spaceDim = 3; + #Preprocessing: mesh data + xinf=0; + xsup=1; + yinf=0; + ysup=1; + zinf=0; + zsup=1; + + nx=10; + ny=10; + nz=10; + + # set the limit field for each boundary + + coldWallVelocityX=0; + coldWallVelocityY=0; + coldWallVelocityZ=0; + coldWallTemperature=563; + + hotWallVelocityX=0; + hotWallVelocityY=0; + hotWallVelocityZ=0; + hotWallTemperature=613; + + # physical constants + + gravite = [0] * spaceDim + gravite[2]=-10; + gravite[1]=0; + gravite[0]=0; + viscosite=[8.85e-5]; + conductivite=[1000];#Wall heat transfert due to nucleate boiling. + + + myProblem = cf.SinglePhase(cf.Liquid,cf.around155bars600K,spaceDim); + nVar = myProblem.getNumberOfVariables(); + + #Initial field creation + print("Building initial data " ); + + # Prepare for the initial condition + + VV_Constant = [0] * nVar + + # constant vector + VV_Constant[0] = 155e5; + VV_Constant[1] = 0 ; + VV_Constant[2] = 0; + VV_Constant[3] = 0; + VV_Constant[4] = 573; + + #Initial field creation + print("Setting mesh and initial data" ); + myProblem.setInitialFieldConstant(spaceDim,VV_Constant,xinf,xsup,nx,"hotWall","hotWall",yinf,ysup,ny,"hotWall","hotWall",zinf,zsup,nz, "hotWall", "coldWall"); + + # Set the boundary conditions + myProblem.setWallBoundaryCondition("coldWall", coldWallTemperature, coldWallVelocityX, coldWallVelocityY, coldWallVelocityZ); + myProblem.setWallBoundaryCondition("hotWall", hotWallTemperature, hotWallVelocityX, hotWallVelocityY, hotWallVelocityZ); + + # set physical parameters + myProblem.setViscosity(viscosite); + myProblem.setConductivity(conductivite); + myProblem.setGravity(gravite); + + # set the numerical method + myProblem.setNumericalScheme(cf.upwind, cf.Implicit); + myProblem.setLinearSolver(cf.GMRES,cf.ILU,True); + myProblem.setEntropicCorrection(False); + myProblem.setWellBalancedCorrection(False); + + # name file save + fileName = "3DHeatDrivenCavity"; + + # simulation parameters + MaxNbOfTimeStep = 3 ; + freqSave = 1; + cfl = 10; + maxTime = 50; + precision = 1e-6; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + myProblem.setNewtonSolver(precision,50); + myProblem.saveConservativeField(True); + if(spaceDim>1): + myProblem.saveVelocity(); + pass + + # evolution + myProblem.initialize(); + + ok = myProblem.run(); + if (ok): + print( "Simulation python " + fileName + " is successful !" ); + pass + else: + print( "Simulation python " + fileName + " failed ! " ); + pass + + print( "------------ End of calculation !!! -----------" ); + + myProblem.terminate(); + return ok + +if __name__ == """__main__""": + SinglePhase_3DHeatDrivenCavity() diff --git a/CoreFlows/examples/Python/SinglePhase/SinglePhase_3DSphericalExplosion_unstructured.py b/CoreFlows/examples/Python/SinglePhase/SinglePhase_3DSphericalExplosion_unstructured.py new file mode 100755 index 0000000..814dad6 --- /dev/null +++ b/CoreFlows/examples/Python/SinglePhase/SinglePhase_3DSphericalExplosion_unstructured.py @@ -0,0 +1,111 @@ +#!/usr/bin/env python +# -*-coding:utf-8 -* + +import CoreFlows as cf +import cdmath + + +def SinglePhase_3DSphericalExplosion_unstructured(): + + inputfile="../../resources/meshCube.med"; + + xinf=0; + xsup=1; + yinf=0; + ysup=1; + zinf=0; + zsup=1; + M=cdmath.Mesh(inputfile); + eps=1.E-6; + M.setGroupAtPlan(xinf,0,eps,"GAUCHE"); + M.setGroupAtPlan(xsup,0,eps,"DROITE"); + M.setGroupAtPlan(yinf,1,eps,"ARRIERE"); + M.setGroupAtPlan(ysup,1,eps,"AVANT"); + M.setGroupAtPlan(zinf,2,eps,"BAS"); + M.setGroupAtPlan(zsup,2,eps,"HAUT"); + + # Initial field data + spaceDim = 3; + nVar=2+spaceDim; + radius=0.5; + Center=cdmath.Vector(3);#default value is (0,0,0) + Vout=cdmath.Vector(nVar) + Vin =cdmath.Vector(nVar) + Vin[0]=1.1; + Vin[1]=0; + Vin[2]=0; + Vin[3]=0; + Vin[4]=300; + Vout[0]=1; + Vout[1]=0; + Vout[2]=0; + Vout[3]=0; + Vout[4]=300; + + myProblem = cf.SinglePhase(cf.Liquid,cf.around155bars600K,spaceDim); + nVar=myProblem.getNumberOfVariables(); + + # Initial field creation + print ("Setting mesh and initial data" ) ; + myProblem.setInitialFieldSphericalStepFunction( M, Vout, Vin, radius, Center); + + # set the boundary conditions + wallVelocityX=0; + wallVelocityY=0; + wallVelocityZ=0; + wallTemperature=563; + + myProblem.setWallBoundaryCondition("GAUCHE", wallTemperature, wallVelocityX, wallVelocityY, wallVelocityZ); + myProblem.setWallBoundaryCondition("DROITE", wallTemperature, wallVelocityX, wallVelocityY, wallVelocityZ); + myProblem.setWallBoundaryCondition("HAUT", wallTemperature, wallVelocityX, wallVelocityY, wallVelocityZ); + myProblem.setWallBoundaryCondition("BAS", wallTemperature, wallVelocityX, wallVelocityY, wallVelocityZ); + myProblem.setWallBoundaryCondition("AVANT", wallTemperature, wallVelocityX, wallVelocityY, wallVelocityZ); + myProblem.setWallBoundaryCondition("ARRIERE", wallTemperature, wallVelocityX, wallVelocityY, wallVelocityZ); + + # set the numerical method + myProblem.setNumericalScheme(cf.upwind, cf.Explicit); + myProblem.setLinearSolver(cf.GMRES,cf.ILU,True); + myProblem.setEntropicCorrection(False); + myProblem.setWellBalancedCorrection(False); + + # name file save + fileName = "3DSphericalExplosion_unstructured"; + + # parameters calculation + MaxNbOfTimeStep = 3 ; + freqSave = 1; + cfl = 0.5; + maxTime = 5; + precision = 1e-6; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + myProblem.setNewtonSolver(precision,20); + myProblem.saveConservativeField(True); + if(spaceDim>1): + myProblem.saveVelocity(); + pass + + + # evolution + myProblem.initialize(); + + ok = myProblem.run(); + if (ok): + print( "Simulation python " + fileName + " is successful !" ); + pass + else: + print( "Simulation python " + fileName + " failed ! " ); + pass + + print( "------------ End of calculation !!! -----------" ); + + myProblem.terminate(); + return ok + +if __name__ == """__main__""": + SinglePhase_3DSphericalExplosion_unstructured() diff --git a/CoreFlows/examples/Python/SinglePhase/SinglePhase_3DVortexTube_NoCone_NoViscosity.py b/CoreFlows/examples/Python/SinglePhase/SinglePhase_3DVortexTube_NoCone_NoViscosity.py new file mode 100755 index 0000000..b1fc887 --- /dev/null +++ b/CoreFlows/examples/Python/SinglePhase/SinglePhase_3DVortexTube_NoCone_NoViscosity.py @@ -0,0 +1,96 @@ +#!/usr/bin/env python +# -*-coding:utf-8 -* + + +import CoreFlows as cf + +def SinglePhase_3DVortexTube_WithoutCone(): + spaceDim = 3; + + print( "Loading mesh of vortex tube without cone" ); + inputfile="../resources/VortexTubeWithoutCone.med"; + + # set the limit field for each boundary + outletPressure = 1e5; + inletPressure = 10e5; + inletTemperature = 300; + + # physical constants + #viscosite=[0.025]; + + myProblem = cf.SinglePhase(cf.Gas,cf.around1bar300K,spaceDim); + nVar = myProblem.getNumberOfVariables(); + + #Initial field creation + print("Building initial data " ); + + # Prepare for the initial condition + + VV_Constant = [0] * nVar + + # constant vector + VV_Constant[0] = 1e5; + VV_Constant[1] = 0 ; + VV_Constant[2] = 0; + VV_Constant[3] = 0; + VV_Constant[4] = 300; + + #Initial field creation + print("Setting mesh and initial data" ); + myProblem.setInitialFieldConstant(inputfile,VV_Constant); + + # Set the boundary conditions + myProblem.setInletPressureBoundaryCondition("Inlet flow", inletPressure, inletTemperature,0,100,0) + myProblem.setOutletBoundaryCondition("Hot outlet", outletPressure) + myProblem.setOutletBoundaryCondition("Cold outlet", outletPressure) + myProblem.setWallBoundaryCondition("Wall", inletTemperature) + + # set physical parameters + #myProblem.setViscosity(viscosite); + + # set the numerical method + myProblem.setNumericalScheme(cf.upwind, cf.Explicit); + myProblem.setNonLinearFormulation(cf.reducedRoe); + myProblem.setEntropicCorrection(True) + #myProblem.setLinearSolver(cf.GMRES,cf.ILU,True); + + # name file save + fileName = "3DVortexTubeWithoutCone"; + + # simulation parameters + MaxNbOfTimeStep = 10000 ; + freqSave = 100; + cfl = 1./3; + maxTime = 50; + precision = 1e-6; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + #myProblem.setNewtonSolver(precision,20); + #yProblem.saveConservativeField(True); + if(spaceDim>1): + myProblem.saveVelocity(); + pass + + # evolution + myProblem.initialize(); + + ok = myProblem.run(); + if (ok): + print( "Simulation python " + fileName + " is successful !" ); + pass + else: + print( "Simulation python " + fileName + " failed ! " ); + pass + + print( "------------ End of calculation !!! -----------" ); + + myProblem.terminate(); + return ok + +if __name__ == """__main__""": + SinglePhase_3DVortexTube_WithoutCone() diff --git a/CoreFlows/examples/Python/SinglePhase/SinglePhase_3DVortexTube_WithCone_NoViscosity.py b/CoreFlows/examples/Python/SinglePhase/SinglePhase_3DVortexTube_WithCone_NoViscosity.py new file mode 100755 index 0000000..a449b67 --- /dev/null +++ b/CoreFlows/examples/Python/SinglePhase/SinglePhase_3DVortexTube_WithCone_NoViscosity.py @@ -0,0 +1,97 @@ +#!/usr/bin/env python +# -*-coding:utf-8 -* + + +import CoreFlows as cf + +def SinglePhase_3DVortexTube_WithCone(): + spaceDim = 3; + + print( "Loading mesh of vortex tube with cone" ); + inputfile="../resources/VortexTubeWithCone.med"; + + # set the limit field for each boundary + outletPressure = 1.e5; + inletPressure = 10.e5; + inletTemperature = 300.; + + # physical constants + #viscosite=[0.025]; + + myProblem = cf.SinglePhase(cf.Gas,cf.around1bar300K,spaceDim); + nVar = myProblem.getNumberOfVariables(); + + #Initial field creation + print("Building initial data " ); + + # Prepare for the initial condition + + VV_Constant = [0] * nVar + + # constant vector + VV_Constant[0] = 1.e5; + VV_Constant[1] = 0 ; + VV_Constant[2] = 0; + VV_Constant[3] = 0; + VV_Constant[4] = 300.; + + #Initial field creation + print("Setting mesh and initial data" ); + myProblem.setInitialFieldConstant(inputfile,VV_Constant); + + # Set the boundary conditions + myProblem.setInletPressureBoundaryCondition("Inlet flow", inletPressure, inletTemperature,0,100,0) + myProblem.setOutletBoundaryCondition("Hot outlet", outletPressure) + myProblem.setOutletBoundaryCondition("Cold outlet", outletPressure) + myProblem.setWallBoundaryCondition("Wall", inletTemperature) + + # set physical parameters + #myProblem.setViscosity(viscosite); + + # set the numerical method + myProblem.setNumericalScheme(cf.upwind, cf.Explicit); + myProblem.setNonLinearFormulation(cf.reducedRoe); + myProblem.setEntropicCorrection(False) + #myProblem.setLinearSolver(cf.GMRES,cf.ILU,True); + + # name file save + fileName = "3DVortexTubeWithCone"; + + # simulation parameters + MaxNbOfTimeStep = 100000 ; + freqSave = 1; + cfl = 0.3; + maxTime = 50; + precision = 1e-6; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + #myProblem.setNewtonSolver(precision,20); + #yProblem.saveConservativeField(True); + #myProblem.setVerbose(False,True); + if(spaceDim>1): + myProblem.saveVelocity(); + pass + + # evolution + myProblem.initialize(); + + ok = myProblem.run(); + if (ok): + print( "Simulation python " + fileName + " is successful !" ); + pass + else: + print( "Simulation python " + fileName + " failed ! " ); + pass + + print( "------------ End of calculation !!! -----------" ); + + myProblem.terminate(); + return ok + +if __name__ == """__main__""": + SinglePhase_3DVortexTube_WithCone() diff --git a/CoreFlows/examples/Python/SinglePhase_1DDepressurisation.py b/CoreFlows/examples/Python/SinglePhase_1DDepressurisation.py deleted file mode 100755 index f675485..0000000 --- a/CoreFlows/examples/Python/SinglePhase_1DDepressurisation.py +++ /dev/null @@ -1,91 +0,0 @@ -#!/usr/bin/env python -# -*-coding:utf-8 -* - -import CoreFlows as cf -import cdmath as cm -import math - -def SinglePhase_1DDepressurisation(): - - spaceDim = 1; - # Prepare for the mesh - print("Building mesh " ); - xinf = 0 ; - xsup=4.2; - nx=50; - M=cm.Mesh(xinf,xsup,nx) - - # set the initial field - initialPressure=155e5; - initialVelocityX=0; - initialTemperature=573; - - # set the boundary data for each boundary - outletPressure=80e5; - wallVelocityX=0; - wallTemperature=573; - - myProblem = cf.SinglePhase(cf.Liquid,cf.around155bars600K,spaceDim); - nVar = myProblem.getNumberOfVariables(); - - # Prepare for the initial condition - VV_Constant =[0]*nVar; - - # constant vector - VV_Constant[0] = initialPressure ; - VV_Constant[1] = initialVelocityX; - VV_Constant[2] = initialTemperature ; - - - #Initial field creation - print("Building initial data" ); - myProblem.setInitialFieldConstant( spaceDim, VV_Constant, xinf, xsup, nx,"wall","outlet"); - - # set the boundary conditions - myProblem.setWallBoundaryCondition("wall", wallTemperature, wallVelocityX); - myProblem.setOutletBoundaryCondition("outlet", outletPressure,[xsup]); - - - # set the numerical method - myProblem.setNumericalScheme(cf.upwind, cf.Explicit); - - # name of result file - fileName = "1DDepressurisation"; - - # simulation parameters - MaxNbOfTimeStep = 3 ; - freqSave = 1; - cfl = 0.95; - maxTime = 500; - precision = 1e-6; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - myProblem.setNewtonSolver(precision,20); - #myProblem.saveConservativeField(True); - if(spaceDim>1): - myProblem.saveVelocity(); - pass - - # evolution - myProblem.initialize(); - - ok = myProblem.run(); - if (ok): - print( "Simulation python " + fileName + " is successful !" ); - pass - else: - print( "Simulation python " + fileName + " failed ! " ); - pass - - print( "------------ End of calculation !!! -----------" ); - - myProblem.terminate(); - return ok - -if __name__ == """__main__""": - SinglePhase_1DDepressurisation() diff --git a/CoreFlows/examples/Python/SinglePhase_1DHeatedAssembly.py b/CoreFlows/examples/Python/SinglePhase_1DHeatedAssembly.py deleted file mode 100755 index 619562c..0000000 --- a/CoreFlows/examples/Python/SinglePhase_1DHeatedAssembly.py +++ /dev/null @@ -1,104 +0,0 @@ -#!/usr/bin/env python -# -*-coding:utf-8 -* - -import CoreFlows as cf -import cdmath as cm - -def SinglePhase_1DHeatedAssembly(): - - spaceDim = 1; - # Prepare for the mesh - print("Building mesh " ); - xinf = 0 ; - xsup=4.2; - xinfcore=(xsup-xinf)/4 - xsupcore=3*(xsup-xinf)/4 - nx=50; - M=cm.Mesh(xinf,xsup,nx) - - # set the limit field for each boundary - - inletVelocityX=5; - inletTemperature=565; - outletPressure=155e5; - - # physical parameters - heatPowerField=cm.Field("heatPowerField", cm.CELLS, M, 1); - nbCells=M.getNumberOfCells(); - - for i in range (nbCells): - x=M.getCell(i).x(); - - if (x> xinfcore) and (x< xsupcore): - heatPowerField[i]=1e8 - else: - heatPowerField[i]=0 - heatPowerField.writeVTK("heatPowerField",True) - - myProblem = cf.SinglePhase(cf.Liquid,cf.around155bars600K,spaceDim); - nVar = myProblem.getNumberOfVariables(); - - # Prepare for the initial condition - VV_Constant =[0]*nVar; - - # constant vector - VV_Constant[0] = outletPressure ; - VV_Constant[1] = inletVelocityX; - VV_Constant[2] = inletTemperature ; - - - #Initial field creation - print("Building initial data " ); - myProblem.setInitialFieldConstant( spaceDim, VV_Constant, xinf, xsup, nx,"inlet","outlet"); - - # set the boundary conditions - myProblem.setInletBoundaryCondition("inlet",inletTemperature,inletVelocityX) - myProblem.setOutletBoundaryCondition("outlet", outletPressure,[xsup]); - - # set physical parameters - myProblem.setHeatPowerField(heatPowerField); - - # set the numerical method - myProblem.setNumericalScheme(cf.upwind, cf.Explicit); - myProblem.setWellBalancedCorrection(True); - - # name of result file - fileName = "1DHeatedChannelUpwindWB"; - - # simulation parameters - MaxNbOfTimeStep = 3 ; - freqSave = 1; - cfl = 0.95; - maxTime = 500; - precision = 1e-7; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - myProblem.setNewtonSolver(precision,20); - myProblem.saveConservativeField(True); - if(spaceDim>1): - myProblem.saveVelocity(); - pass - - # evolution - myProblem.initialize(); - - ok = myProblem.run(); - if (ok): - print( "Simulation python " + fileName + " is successful !" ); - pass - else: - print( "Simulation python " + fileName + " failed ! " ); - pass - - print( "------------ End of calculation !!! -----------" ); - - myProblem.terminate(); - return ok - -if __name__ == """__main__""": - SinglePhase_1DHeatedAssembly() diff --git a/CoreFlows/examples/Python/SinglePhase_1DHeatedChannel.py b/CoreFlows/examples/Python/SinglePhase_1DHeatedChannel.py deleted file mode 100755 index a969cbb..0000000 --- a/CoreFlows/examples/Python/SinglePhase_1DHeatedChannel.py +++ /dev/null @@ -1,90 +0,0 @@ -#!/usr/bin/env python -# -*-coding:utf-8 -* - -import CoreFlows as cf - -def SinglePhase_1DHeatedChannel(): - - spaceDim = 1; - # Prepare for the mesh - print("Building mesh " ); - xinf = 0 ; - xsup=4.2; - nx=50; - - # set the limit field for each boundary - - inletVelocityX=5; - inletTemperature=565; - outletPressure=155e5; - - # physical parameters - heatPower=1e7; - - myProblem = cf.SinglePhase(cf.Liquid,cf.around155bars600K,spaceDim); - nVar = myProblem.getNumberOfVariables(); - - # Prepare for the initial condition - VV_Constant =[0]*nVar; - - # constant vector - VV_Constant[0] = outletPressure ; - VV_Constant[1] = inletVelocityX; - VV_Constant[2] = inletTemperature ; - - - #Initial field creation - print("Building initial data " ); - myProblem.setInitialFieldConstant( spaceDim, VV_Constant, xinf, xsup, nx,"inlet","outlet"); - - # set the boundary conditions - myProblem.setInletBoundaryCondition("inlet",inletTemperature,inletVelocityX) - myProblem.setOutletBoundaryCondition("outlet", outletPressure,[xsup]); - - # set physical parameters - myProblem.setHeatSource(heatPower); - - # set the numerical method - myProblem.setNumericalScheme(cf.upwind, cf.Explicit); - myProblem.setWellBalancedCorrection(True); - - # name of result file - fileName = "1DHeatedChannelUpwindWB"; - - # simulation parameters - MaxNbOfTimeStep = 3 ; - freqSave = 1; - cfl = 0.95; - maxTime = 500; - precision = 1e-7; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - myProblem.setNewtonSolver(precision,20); - myProblem.saveConservativeField(True); - if(spaceDim>1): - myProblem.saveVelocity(); - pass - - # evolution - myProblem.initialize(); - - ok = myProblem.run(); - if (ok): - print( "Simulation python " + fileName + " is successful !" ); - pass - else: - print( "Simulation python " + fileName + " failed ! " ); - pass - - print( "------------ End of calculation !!! -----------" ); - - myProblem.terminate(); - return ok - -if __name__ == """__main__""": - SinglePhase_1DHeatedChannel() diff --git a/CoreFlows/examples/Python/SinglePhase_1DRiemannProblem.py b/CoreFlows/examples/Python/SinglePhase_1DRiemannProblem.py deleted file mode 100755 index 4f52e9d..0000000 --- a/CoreFlows/examples/Python/SinglePhase_1DRiemannProblem.py +++ /dev/null @@ -1,95 +0,0 @@ -#!/usr/bin/env python -# -*-coding:utf-8 -* - -import CoreFlows as cf -import cdmath as cm - -def SinglePhase_1DRiemannProblem(): - - spaceDim = 1; - # Prepare for the mesh - print("Building mesh " ); - xinf = 0 ; - xsup=4.2; - nx=50; - discontinuity=(xinf+xsup)/2 - M=cm.Mesh(xinf,xsup,nx) - eps=1e-6 - M.setGroupAtPlan(xsup,0,eps,"RightBoundary") - M.setGroupAtPlan(xinf,0,eps,"LeftBoundary") - - # set the limit field for each boundary - - initialVelocity_Left=1; - initialTemperature_Left=565; - initialPressure_Left=155e5; - - initialVelocity_Right=1; - initialTemperature_Right=565; - initialPressure_Right=150e5; - - myProblem = cf.SinglePhase(cf.Liquid,cf.around155bars600K,spaceDim); - nVar = myProblem.getNumberOfVariables(); - - # Prepare for the initial condition - VV_Left =cm.Vector(nVar) - VV_Right =cm.Vector(nVar) - - # left and right constant vectors - VV_Left[0] = initialPressure_Left; - VV_Left[1] = initialVelocity_Left; - VV_Left[2] = initialTemperature_Left ; - - VV_Right[0] = initialPressure_Right; - VV_Right[1] = initialVelocity_Right; - VV_Right[2] = initialTemperature_Right ; - - - #Initial field creation - print("Building initial data " ); - myProblem.setInitialFieldStepFunction(M,VV_Left,VV_Right,discontinuity); - - # set the boundary conditions - myProblem.setNeumannBoundaryCondition("LeftBoundary"); - myProblem.setNeumannBoundaryCondition("RightBoundary"); - - # set the numerical method - myProblem.setNumericalScheme(cf.staggered, cf.Implicit); - - # name of result file - fileName = "1DRiemannProblem"; - - # simulation parameters - MaxNbOfTimeStep = 3 ; - freqSave = 1; - cfl = 0.95; - maxTime = 500; - precision = 1e-6; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - myProblem.setNewtonSolver(precision,20); - myProblem.usePrimitiveVarsInNewton(True) - - # evolution - myProblem.initialize(); - - ok = myProblem.run(); - if (ok): - print( "Simulation python " + fileName + " is successful !" ); - pass - else: - print( "Simulation python " + fileName + " failed ! " ); - pass - - print( "------------ End of calculation !!! -----------" ); - - myProblem.terminate(); - return ok - -if __name__ == """__main__""": - SinglePhase_1DRiemannProblem() diff --git a/CoreFlows/examples/Python/SinglePhase_1DWaterHammer.py b/CoreFlows/examples/Python/SinglePhase_1DWaterHammer.py deleted file mode 100755 index fd67cb8..0000000 --- a/CoreFlows/examples/Python/SinglePhase_1DWaterHammer.py +++ /dev/null @@ -1,91 +0,0 @@ -#!/usr/bin/env python -# -*-coding:utf-8 -* - -import CoreFlows as cf -import cdmath as cm - -def SinglePhase_1DWaterHammer(): - - spaceDim = 1; - # Prepare for the mesh - print("Building mesh " ); - xinf = 0 ; - xsup=4.2; - nx=50; - M=cm.Mesh(xinf,xsup,nx) - - # set the initial field - - initialPressure=155e5; - initialVelocityX=-5; - initialTemperature=573; - - # set the limit field for each boundary - - wallVelocityX=0; - wallTemperature=573; - - myProblem = cf.SinglePhase(cf.Liquid,cf.around155bars600K,spaceDim); - nVar = myProblem.getNumberOfVariables(); - - # Prepare for the initial condition - VV_Constant =[0]*nVar; - - # constant vector - VV_Constant[0] = initialPressure ; - VV_Constant[1] = initialVelocityX; - VV_Constant[2] = initialTemperature ; - - - #Initial field creation - print("Building initial data" ); - myProblem.setInitialFieldConstant( spaceDim, VV_Constant, xinf, xsup, nx,"wall","neumann"); - - # set the boundary conditions - myProblem.setWallBoundaryCondition("wall", wallTemperature, wallVelocityX); - myProblem.setNeumannBoundaryCondition("neumann"); - - - # set the numerical method - myProblem.setNumericalScheme(cf.upwind, cf.Explicit); - - # name of result file - fileName = "1DSinglePhase_1DWaterHammer"; - - # simulation parameters - MaxNbOfTimeStep = 3 ; - freqSave = 1; - cfl = 0.95; - maxTime = 500; - precision = 1e-6; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - myProblem.setNewtonSolver(precision,20); - #myProblem.saveConservativeField(True); - if(spaceDim>1): - myProblem.saveVelocity(); - pass - - # evolution - myProblem.initialize(); - - ok = myProblem.run(); - if (ok): - print( "Simulation python " + fileName + " is successful !" ); - pass - else: - print( "Simulation python " + fileName + " failed ! " ); - pass - - print( "------------ End of calculation !!! -----------" ); - - myProblem.terminate(); - return ok - -if __name__ == """__main__""": - SinglePhase_1DWaterHammer() diff --git a/CoreFlows/examples/Python/SinglePhase_2BranchesHeatedChannels.py b/CoreFlows/examples/Python/SinglePhase_2BranchesHeatedChannels.py deleted file mode 100755 index 7a6554a..0000000 --- a/CoreFlows/examples/Python/SinglePhase_2BranchesHeatedChannels.py +++ /dev/null @@ -1,100 +0,0 @@ -#!/usr/bin/env python -# -*-coding:utf-8 -* - -import CoreFlows as cf -import cdmath as cm - - -def SinglePhase_2BranchesHeatedChannels(): - - spaceDim = 1; - # Prepare for the mesh - M=cm.Mesh("../resources/BifurcatingFlow2BranchesEqualSections.med") - M.getFace(0).setGroupName("Inlet")#z=0 - M.getFace(31).setGroupName("Outlet")#z=4.2 - - # set the initial field - initialPressure=155e5; - initialVelocityX=5; - initialTemperature=573; - - # set the limit field for each boundary - inletVelocityX=5; - inletTemperature=573; - outletPressure=155e5 - - myProblem = cf.SinglePhase(cf.Liquid,cf.around155bars600K,spaceDim); - nVar = myProblem.getNumberOfVariables(); - - # Prepare for the initial condition - VV_Constant =[0]*nVar; - - # constant vector - VV_Constant[0] = initialPressure ; - VV_Constant[1] = initialVelocityX; - VV_Constant[2] = initialTemperature ; - - - #Initial field creation - print("Building initial data" ); - myProblem.setInitialFieldConstant( M, VV_Constant); - - # set the boundary conditions - myProblem.setInletBoundaryCondition("Inlet", inletTemperature, inletVelocityX); - myProblem.setOutletBoundaryCondition("Outlet",outletPressure); - - #set porosity, heat and gravity source - Sections=cm.Field("../resources/BifurcatingFlow2BranchesEqualSections", cm.CELLS,"Section area"); - heatPowerField=cm.Field("../resources/BifurcatingFlow2BranchesEqualSections", cm.CELLS,"Heat power"); - - heatPowerField.writeVTK("heatPowerField"); - Sections.writeVTK("crossSectionPowerField"); - - myProblem.setSectionField(Sections); - myProblem.setHeatPowerField(heatPowerField) - gravite=[-10] - myProblem.setGravity(gravite) - # set the numerical method - myProblem.setNumericalScheme(cf.upwind, cf.Explicit); - myProblem.setWellBalancedCorrection(True) - - # name of result file - fileName = "2BranchesHeatedChannels"; - - # simulation parameters - MaxNbOfTimeStep = 3 ; - freqSave = 1; - cfl = 0.95; - maxTime = 500; - precision = 1e-6; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - myProblem.setNewtonSolver(precision,20); - #myProblem.saveConservativeField(True); - if(spaceDim>1): - myProblem.saveVelocity(); - pass - - # evolution - myProblem.initialize(); - - ok = myProblem.run(); - if (ok): - print( "Simulation python " + fileName + " is successful !" ); - pass - else: - print( "Simulation python " + fileName + " failed ! " ); - pass - - print( "------------ End of calculation !!! -----------" ); - - myProblem.terminate(); - return ok - -if __name__ == """__main__""": - SinglePhase_2BranchesHeatedChannels() diff --git a/CoreFlows/examples/Python/SinglePhase_2DHeatedChannelInclined.py b/CoreFlows/examples/Python/SinglePhase_2DHeatedChannelInclined.py deleted file mode 100755 index 2cc5289..0000000 --- a/CoreFlows/examples/Python/SinglePhase_2DHeatedChannelInclined.py +++ /dev/null @@ -1,104 +0,0 @@ -#!/usr/bin/env python -# -*-coding:utf-8 -* - -import CoreFlows as cf - -def SinglePhase_2DHeatedChannelInclined(): - spaceDim = 2; - - # Prepare the mesh data - xinf = 0 ; - xsup=3.0; - yinf=0.0; - ysup=5.0; - nx=50; - ny=50; - - # set the limit field for each boundary - wallVelocityX=0; - wallVelocityY=0; - wallTemperature=573; - inletVelocityX=0; - inletVelocityY=0.5; - inletTemperature=563; - outletPressure=155e5; - - # physical constants - gravite = [0] * spaceDim - - gravite[1]=-7; - gravite[0]=7; - - heatPower=1e8; - - myProblem = cf.SinglePhase(cf.Liquid,cf.around155bars600K,spaceDim); - nVar =myProblem.getNumberOfVariables(); - - # Prepare for the initial condition - VV_Constant =[0]*nVar - - # constant vector - VV_Constant[0] = outletPressure ; - VV_Constant[1] = inletVelocityX; - VV_Constant[2] = inletVelocityY; - VV_Constant[3] = inletTemperature ; - - #Initial field creation - print("Building mesh and initial data" ); - myProblem.setInitialFieldConstant(spaceDim,VV_Constant, - xinf,xsup,nx,"wall","wall", - yinf,ysup,ny,"inlet","outlet", - 0.0,0.0, 0, "", "") - - # the boundary conditions - myProblem.setOutletBoundaryCondition("outlet", outletPressure,[xsup,ysup]); - myProblem.setInletBoundaryCondition("inlet", inletTemperature, inletVelocityX, inletVelocityY); - myProblem.setWallBoundaryCondition("wall", wallTemperature, wallVelocityX, wallVelocityY); - # set physical parameters - - myProblem.setHeatSource(heatPower); - myProblem.setGravity(gravite); - - # set the numerical method - myProblem.setNumericalScheme(cf.staggered, cf.Implicit); - myProblem.setWellBalancedCorrection(False); - - # name file save - fileName = "2DInclinedHeatedChannel"; - - # parameters calculation - MaxNbOfTimeStep = 3 ; - freqSave = 1; - cfl = 0.5; - maxTime = 5000; - precision = 1e-6; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - myProblem.saveConservativeField(True); - if(spaceDim>1): - myProblem.saveVelocity(); - pass - - # evolution - myProblem.initialize(); - - ok = myProblem.run(); - if (ok): - print( "Simulation python " + fileName + " is successful !" ); - pass - else: - print( "Simulation python " + fileName + " failed ! " ); - pass - - print( "------------ End of calculation !!! -----------" ); - - myProblem.terminate(); - return ok - -if __name__ == """__main__""": - SinglePhase_2DHeatedChannelInclined() diff --git a/CoreFlows/examples/Python/SinglePhase_2DLidDrivenCavity.py b/CoreFlows/examples/Python/SinglePhase_2DLidDrivenCavity.py deleted file mode 100755 index 9eb9976..0000000 --- a/CoreFlows/examples/Python/SinglePhase_2DLidDrivenCavity.py +++ /dev/null @@ -1,104 +0,0 @@ -#!/usr/bin/env python -# -*-coding:utf-8 -* - - -import CoreFlows as cf - -def SinglePhase_2DLidDrivenCavity(): - - spaceDim = 2; - #Preprocessing: mesh data - xinf=0; - xsup=1; - yinf=0; - ysup=1; - - nx=50; - ny=50; - - # set the limit field for each boundary - - fixedWallVelocityX=0; - fixedWallVelocityY=0; - fixedWallTemperature=273; - - movingWallVelocityX=1; - movingWallVelocityY=0; - movingWallTemperature=273; - - # physical constants - - viscosite=[0.025]; - - myProblem = cf.SinglePhase(cf.Gas,cf.around1bar300K,spaceDim); - nVar = myProblem.getNumberOfVariables(); - - #Initial field creation - print("Building initial data " ); - - # Prepare for the initial condition - - VV_Constant = [0] * nVar - - # constant vector - VV_Constant[0] = 1e5; - VV_Constant[1] = 0 ; - VV_Constant[2] = 0; - VV_Constant[3] = 273; - - #Initial field creation - print("Building mesh and initial data" ); - myProblem.setInitialFieldConstant(spaceDim,VV_Constant,xinf,xsup,nx,"fixedWall","fixedWall",yinf,ysup,ny,"fixedWall","movingWall"); - - # Set the boundary conditions - myProblem.setWallBoundaryCondition("fixedWall", fixedWallTemperature, fixedWallVelocityX, fixedWallVelocityY); - myProblem.setWallBoundaryCondition("movingWall", movingWallTemperature, movingWallVelocityX, movingWallVelocityY); - - # set physical parameters - myProblem.setViscosity(viscosite); - - # set the numerical method - myProblem.setNumericalScheme(cf.staggered, cf.Implicit); - myProblem.setLinearSolver(cf.GMRES,cf.LU,True); - - # name file save - fileName = "2DLidDrivenCavity"; - - # simulation parameters - MaxNbOfTimeStep = 3 ; - freqSave = 1; - cfl = 10; - maxTime = 50; - precision = 1e-9; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - myProblem.setNewtonSolver(float('inf'),20); - myProblem.saveConservativeField(True); - if(spaceDim>1): - myProblem.saveVelocity(); - pass - - # evolution - myProblem.initialize(); - - ok = myProblem.run(); - if (ok): - print( "Simulation python " + fileName + " is successful !" ); - pass - else: - print( "Simulation python " + fileName + " failed ! " ); - pass - - print( "------------ End of calculation !!! -----------" ); - - myProblem.terminate(); - return ok - - -if __name__ == """__main__""": - SinglePhase_2DLidDrivenCavity() diff --git a/CoreFlows/examples/Python/SinglePhase_2DLidDrivenCavity_unstructured.py b/CoreFlows/examples/Python/SinglePhase_2DLidDrivenCavity_unstructured.py deleted file mode 100755 index a7380dc..0000000 --- a/CoreFlows/examples/Python/SinglePhase_2DLidDrivenCavity_unstructured.py +++ /dev/null @@ -1,99 +0,0 @@ -#!/usr/bin/env python -# -*-coding:utf-8 -* - - -import CoreFlows as cf - -def SinglePhase_2DLidDrivenCavity_unstructured(): - spaceDim = 2; - - print( "Loading unstructured mesh " ); - inputfile="../resources/BoxWithMeshWithTriangularCells.med"; - - # set the limit field for each boundary - - fixedWallVelocityX=0; - fixedWallVelocityY=0; - fixedWallTemperature=273; - - movingWallVelocityX=1; - movingWallVelocityY=0; - movingWallTemperature=273; - - # physical constants - - viscosite=[0.025]; - - myProblem = cf.SinglePhase(cf.Gas,cf.around1bar300K,spaceDim); - nVar = myProblem.getNumberOfVariables(); - - #Initial field creation - print("Building initial data " ); - - # Prepare for the initial condition - - VV_Constant = [0] * nVar - - # constant vector - VV_Constant[0] = 1e5; - VV_Constant[1] = 0 ; - VV_Constant[2] = 0; - VV_Constant[3] = 273; - - #Initial field creation - print("Setting mesh and initial data" ); - myProblem.setInitialFieldConstant(inputfile,VV_Constant); - - # Set the boundary conditions - myProblem.setWallBoundaryCondition("BAS", fixedWallTemperature, fixedWallVelocityX, fixedWallVelocityY); - myProblem.setWallBoundaryCondition("GAUCHE", fixedWallTemperature, fixedWallVelocityX, fixedWallVelocityY); - myProblem.setWallBoundaryCondition("DROITE", fixedWallTemperature, fixedWallVelocityX, fixedWallVelocityY); - myProblem.setWallBoundaryCondition("HAUT", movingWallTemperature, movingWallVelocityX, movingWallVelocityY); - - # set physical parameters - myProblem.setViscosity(viscosite); - - # set the numerical method - myProblem.setNumericalScheme(cf.pressureCorrection, cf.Implicit); - myProblem.setLinearSolver(cf.GMRES,cf.ILU,True); - - # name file save - fileName = "2DLidDrivenCavityUnstructured"; - - # simulation parameters - MaxNbOfTimeStep = 3 ; - freqSave = 1; - cfl = 10; - maxTime = 50; - precision = 1e-9; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - myProblem.setNewtonSolver(precision,20); - myProblem.saveConservativeField(True); - if(spaceDim>1): - myProblem.saveVelocity(); - pass - - # evolution - myProblem.initialize(); - - ok = myProblem.run(); - if (ok): - print( "Simulation python " + fileName + " is successful !" ); - pass - else: - print( "Simulation python " + fileName + " failed ! " ); - pass - - print( "------------ End of calculation !!! -----------" ); - - myProblem.terminate(); - return ok - -if __name__ == """__main__""": - SinglePhase_2DLidDrivenCavity_unstructured() diff --git a/CoreFlows/examples/Python/SinglePhase_2DSphericalExplosion_unstructured.py b/CoreFlows/examples/Python/SinglePhase_2DSphericalExplosion_unstructured.py deleted file mode 100755 index ca6b79c..0000000 --- a/CoreFlows/examples/Python/SinglePhase_2DSphericalExplosion_unstructured.py +++ /dev/null @@ -1,77 +0,0 @@ -#!/usr/bin/env python -# -*-coding:utf-8 -* - -import CoreFlows as cf - - - -def SinglePhase_2DSphericalExplosion_unstructured(): - - inputfile="../resources/BoxWithMeshWithTriangularCells"; - fieldName="Initial variables for spherical explosion"; - spaceDim=2 - - myProblem = cf.SinglePhase(cf.Liquid,cf.around155bars600K,spaceDim); - nVar=myProblem.getNumberOfVariables(); - - # Initial field creation - print ("Loading unstructured mesh and initial data for test SinglePhase_2DSphericalExplosion_unstructured()" ) ; - myProblem.setInitialField(inputfile,fieldName,0); - - # set the boundary conditions - wallVelocityX=0; - wallVelocityY=0; - wallTemperature=563; - - myProblem.setWallBoundaryCondition("GAUCHE", wallTemperature, wallVelocityX, wallVelocityY); - myProblem.setWallBoundaryCondition("DROITE", wallTemperature, wallVelocityX, wallVelocityY); - myProblem.setWallBoundaryCondition("HAUT", wallTemperature, wallVelocityX, wallVelocityY); - myProblem.setWallBoundaryCondition("BAS", wallTemperature, wallVelocityX, wallVelocityY); - - # set the numerical method - myProblem.setNumericalScheme(cf.upwind, cf.Explicit); - myProblem.setLinearSolver(cf.GMRES,cf.ILU,True); - myProblem.setEntropicCorrection(False); - myProblem.setWellBalancedCorrection(False); - - # name file save - fileName = "2DSphericalExplosion_unstructured"; - - # parameters calculation - MaxNbOfTimeStep = 3 ; - freqSave = 5; - cfl = 0.5; - maxTime = 5; - precision = 1e-6; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - myProblem.setNewtonSolver(precision,20); - myProblem.saveConservativeField(True); - if(spaceDim>1): - myProblem.saveVelocity(); - pass - - - # evolution - myProblem.initialize(); - - ok = myProblem.run(); - if (ok): - print( "Simulation python " + fileName + " is successful !" ); - pass - else: - print( "Simulation python " + fileName + " failed ! " ); - pass - - print( "------------ End of calculation !!! -----------" ); - - myProblem.terminate(); - return ok - -if __name__ == """__main__""": - SinglePhase_2DSphericalExplosion_unstructured() diff --git a/CoreFlows/examples/Python/SinglePhase_2DThermalDiffusion.py b/CoreFlows/examples/Python/SinglePhase_2DThermalDiffusion.py deleted file mode 100755 index fdfd695..0000000 --- a/CoreFlows/examples/Python/SinglePhase_2DThermalDiffusion.py +++ /dev/null @@ -1,121 +0,0 @@ -#!/usr/bin/env python -# -*-coding:utf-8 -* - - -import CoreFlows as cf -import cdmath as cm -import math - -def SinglePhase_2DThermalDiffusion(): - spaceDim = 2; - - # Prepare for the mesh - print("Building mesh " ); - xinf = 0 ; - xsup=0.2; - yinf=0.0; - ysup=0.4; - nx=10; - ny=20; - discontinuity=(xinf+xsup)/2 - M=cm.Mesh(xinf,xsup,nx,yinf,ysup,ny) - # set the limit field for each boundary - eps=1e-6; - M.setGroupAtPlan(xsup,0,eps,"RightWall") - M.setGroupAtPlan(xinf,0,eps,"LeftWall") - M.setGroupAtPlan(ysup,1,eps,"outlet") - dx=(xsup-xinf)/nx - ndis=(discontinuity-xinf)/dx - print("ndis=",math.floor(ndis) ); - i=0 - while i<= ndis: - M.setGroupAtFaceByCoords(xinf+(i+0.5)*dx,yinf,0,eps,"inlet_1") - i=i+1 - while i<= nx: - M.setGroupAtFaceByCoords(xinf+(i+0.5)*dx,yinf,0,eps,"inlet_2") - i=i+1 - - - # set the limit field for each boundary - inletVelocityX=0; - inletVelocityY=1; - inletTemperature1=563; - inletTemperature2=593; - outletPressure=155e5; - - viscosite= [1.5]; - conductivite=[5000]; - - myProblem = cf.SinglePhase(cf.Liquid,cf.around155bars600K,spaceDim); - nVar =myProblem.getNumberOfVariables(); - - # Prepare for the initial condition - VV_Constant_Left =cm.Vector(nVar) - VV_Constant_Right =cm.Vector(nVar) - - # constant vectors - VV_Constant_Left[0] = outletPressure ; - VV_Constant_Left[1] = inletVelocityX; - VV_Constant_Left[2] = inletVelocityY; - VV_Constant_Left[3] = inletTemperature1 ; - - VV_Constant_Right[0] = outletPressure ; - VV_Constant_Right[1] = inletVelocityX; - VV_Constant_Right[2] = inletVelocityY; - VV_Constant_Right[3] = inletTemperature2 ; - - print("Building initial data" ); - myProblem.setInitialFieldStepFunction(M,VV_Constant_Left,VV_Constant_Right,discontinuity) - - - # the boundary conditions - myProblem.setOutletBoundaryCondition("outlet", outletPressure); - myProblem.setInletBoundaryCondition("inlet_1", inletTemperature1, inletVelocityX, inletVelocityY); - myProblem.setInletBoundaryCondition("inlet_2", inletTemperature2, inletVelocityX, inletVelocityY); - myProblem.setWallBoundaryCondition("LeftWall", inletTemperature1, 0,0); - myProblem.setWallBoundaryCondition("RightWall", inletTemperature2, 0,0); - - - myProblem.setViscosity(viscosite); - myProblem.setConductivity(conductivite); - - # set the numerical method - myProblem.setNumericalScheme(cf.staggered, cf.Implicit); - - # name file save - fileName = "2DThermalDiffusion"; - - # parameters calculation - MaxNbOfTimeStep = 3 ; - freqSave = 1; - cfl = .01; - maxTime = 5000; - precision = 1e-6; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - myProblem.setNewtonSolver(precision,20); - myProblem.saveVelocity(); - - # evolution - myProblem.initialize(); - - ok = myProblem.run(); - if (ok): - print( "Simulation python " + fileName + " is successful !" ); - pass - else: - print( "Simulation python " + fileName + " failed ! " ); - pass - - print( "------------ End of calculation !!! -----------" ); - - myProblem.terminate(); - return ok - -if __name__ == """__main__""": - SinglePhase_2DThermalDiffusion() diff --git a/CoreFlows/examples/Python/SinglePhase_2DVidangeReservoir.py b/CoreFlows/examples/Python/SinglePhase_2DVidangeReservoir.py deleted file mode 100755 index 18e3e90..0000000 --- a/CoreFlows/examples/Python/SinglePhase_2DVidangeReservoir.py +++ /dev/null @@ -1,120 +0,0 @@ -#!/usr/bin/env python -# -*-coding:utf-8 -* - -import CoreFlows as cf -import cdmath as cm - -def SinglePhase_2DVidangeReservoir(): - - spaceDim = 2; - # Prepare for the mesh - print("Building mesh " ); - xinf = 0 ; - xsup=1.0; - yinf=0.0; - ysup=1.0; - nx=50; - ny=50; - diametreSortie=(ysup-yinf)/10.#10 percent of the height - nsortie=ny*diametreSortie/(ysup-yinf) - M=cm.Mesh(xinf,xsup,nx,yinf,ysup,ny) - # set the limit field for each boundary - eps=1e-6; - M.setGroupAtPlan(xinf,0,eps,"wall") - M.setGroupAtPlan(ysup,1,eps,"inlet") - M.setGroupAtPlan(yinf,1,eps,"wall") - dy=(ysup-yinf)/ny - i=0 - while i < nsortie: - M.setGroupAtFaceByCoords(xsup,yinf+(i+0.5)*dy,0,eps,"outlet") - i=i+1 - while i < ny: - M.setGroupAtFaceByCoords(xsup,yinf+(i+0.5)*dy,0,eps,"wall") - i=i+1 - - - - # set the limit field for each boundary - wallVelocityX=0; - wallVelocityY=0; - wallTemperature=300; - inletTemperature=300; - outletPressure=1e5; - - # set the limit field for each boundary - initialVelocityX=0; - initialVelocityY=0; - initialTemperature=300; - initialPressure=1e5; - - # physical constants - gravite = [0] * spaceDim - - gravite[0]=0; - gravite[1]=-10; - - myProblem = cf.SinglePhase(cf.Liquid,cf.around1bar300K,spaceDim); - nVar =myProblem.getNumberOfVariables(); - # Prepare for the initial condition - VV_constant =cm.Vector(nVar) - - # constant vector - VV_constant[0] = initialPressure ; - VV_constant[1] = initialVelocityX; - VV_constant[2] = initialVelocityY; - VV_constant[3] = initialTemperature ; - - - #Initial field creation - print("Building initial data" ); - myProblem.setInitialFieldConstant( M, VV_constant) - - # the boundary conditions - myProblem.setOutletBoundaryCondition("outlet", outletPressure,[xsup,ysup]); - myProblem.setInletPressureBoundaryCondition("inlet", outletPressure, inletTemperature,[xsup,yinf]); - myProblem.setWallBoundaryCondition("wall", wallTemperature, wallVelocityX, wallVelocityY); - - # set physical parameters - myProblem.setGravity(gravite); - - # set the numerical method - myProblem.setNumericalScheme(cf.upwind, cf.Explicit); - myProblem.setLinearSolver(cf.GMRES,cf.ILU,True); - - # name file save - fileName = "2DVidangeReservoir"; - - # parameters calculation - MaxNbOfTimeStep = 3 ; - freqSave = 1; - cfl = .05; - maxTime = 5000; - precision = 1e-6; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - myProblem.setNewtonSolver(precision,20); - myProblem.saveVelocity(); - - # evolution - myProblem.initialize(); - - ok = myProblem.run(); - if (ok): - print( "Simulation python " + fileName + " is successful !" ); - pass - else: - print( "Simulation python " + fileName + " failed ! " ); - pass - - print( "------------ End of calculation !!! -----------" ); - - myProblem.terminate(); - return ok - -if __name__ == """__main__""": - SinglePhase_2DVidangeReservoir() diff --git a/CoreFlows/examples/Python/SinglePhase_2DWallHeatedChannel_ChangeSect.py b/CoreFlows/examples/Python/SinglePhase_2DWallHeatedChannel_ChangeSect.py deleted file mode 100755 index 9097c8a..0000000 --- a/CoreFlows/examples/Python/SinglePhase_2DWallHeatedChannel_ChangeSect.py +++ /dev/null @@ -1,124 +0,0 @@ -#!/usr/bin/env python -# -*-coding:utf-8 -* - -import CoreFlows as cf -import cdmath as cm - -def SinglePhase_2DWallHeatedChannel_ChangeSect(): - - #import themesh - print("Reading a mesh with sudden cross-section change for test SinglePhase_2DWallHeatedChannel_ChangeSect()") - M=cm.Mesh("../resources/VaryingSectionDuct.med") - - # Prepare the mesh boundaries - xinf=0.0; - xsup=0.01; - yinf=0.0; - ysup=0.01; - eps=1.E-6; - M.setGroupAtPlan(xsup,0,eps,"Wall"); - M.setGroupAtPlan(xinf,0,eps,"Wall"); - M.setGroupAtPlan(yinf,1,eps,"Inlet"); - M.setGroupAtPlan(ysup,1,eps,"Outlet"); - - #Nombre de cellules utilisees au depart dans Salome ou Alamos - nx=60 - ny=60 - #taille d'une cellule - dx = (xsup-xinf)/nx - dy = (ysup-yinf)/ny; - for i in range(ny/2): - M.setGroupAtFaceByCoords((xsup-xinf)/4,(ysup-yinf)/4+(i+0.5)*dy,0,eps,"Wall");#Paroi verticale intérieure gauche - M.setGroupAtFaceByCoords((xsup-xinf)*3/4,(ysup-yinf)/4+(i+0.5)*dy,0,eps,"Wall");#Paroi verticale intérieure droitee - - for i in range(nx/4): - M.setGroupAtFaceByCoords((i+0.5)*dx,(ysup-yinf)/4,0,eps,"Wall");#paroi horizontale en bas à gauche - M.setGroupAtFaceByCoords((i+0.5)*dx,(ysup-yinf)*3/4,0,eps,"Wall");#paroi horizontale en haut à gauche - M.setGroupAtFaceByCoords((xsup-xinf)*3/4+(i+0.5)*dx,(ysup-yinf)/4,0,eps,"Wall");#paroi horizontale en bas à droite - M.setGroupAtFaceByCoords((xsup-xinf)*3/4+(i+0.5)*dx,(ysup-yinf)*3/4,0,eps,"Wall");#paroi horizontale en haut à droite - - spaceDim = M.getSpaceDimension(); - - # set the limit field for each boundary - wallVelocityX=0; - wallVelocityY=0; - wallTemperature=623; - inletVelocityX=0; - inletVelocityY=2.5; - inletTemperature=563; - outletPressure=155e5; - - # physical constants - viscosite=[8.85e-5] - conductivite=[1000] - - myProblem = cf.SinglePhase(cf.Liquid,cf.around155bars600K,spaceDim); - nVar =myProblem.getNumberOfVariables(); - - # Prepare for the initial condition - VV_Constant =cm.Vector(nVar) - - # constant vector - VV_Constant[0] = outletPressure ; - VV_Constant[1] = inletVelocityX; - VV_Constant[2] = inletVelocityY; - VV_Constant[3] = inletTemperature ; - - #Initial field creation - print("Building mesh and initial data" ); - myProblem.setInitialFieldConstant(M,VV_Constant); - - # the boundary conditions - myProblem.setOutletBoundaryCondition("Outlet", outletPressure,[xsup,ysup]); - myProblem.setInletBoundaryCondition("Inlet", inletTemperature, inletVelocityX, inletVelocityY); - myProblem.setWallBoundaryCondition("Wall", wallTemperature, wallVelocityX, wallVelocityY); - - # set physical parameters - myProblem.setViscosity(viscosite); - myProblem.setConductivity(conductivite); - - - # set the numerical method - myProblem.setNumericalScheme(cf.upwind, cf.Implicit); - myProblem.setLinearSolver(cf.GMRES,cf.ILU,True); - - # name file save - fileName = "2DWallHeatedChannel_ChangeSect"; - - # parameters calculation - MaxNbOfTimeStep = 3 ; - freqSave = 1; - cfl = 0.5; - maxTime = 5000; - precision = 1e-6; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - myProblem.setNewtonSolver(float('inf'),20);#newton precision should be infinite for staggered scheme!!! - myProblem.saveConservativeField(True); - if(spaceDim>1): - myProblem.saveVelocity(); - pass - - # evolution - myProblem.initialize(); - - ok = myProblem.run(); - if (ok): - print( "Simulation python " + fileName + " is successful !" ); - pass - else: - print( "Simulation python " + fileName + " failed ! " ); - pass - - print( "------------ End of calculation !!! -----------" ); - - myProblem.terminate(); - return ok - -if __name__ == """__main__""": - SinglePhase_2DWallHeatedChannel_ChangeSect() diff --git a/CoreFlows/examples/Python/SinglePhase_3DHeatDrivenCavity.py b/CoreFlows/examples/Python/SinglePhase_3DHeatDrivenCavity.py deleted file mode 100755 index c129e4c..0000000 --- a/CoreFlows/examples/Python/SinglePhase_3DHeatDrivenCavity.py +++ /dev/null @@ -1,119 +0,0 @@ -#!/usr/bin/env python -# -*-coding:utf-8 -* - - -import CoreFlows as cf - -def SinglePhase_3DHeatDrivenCavity(): - - spaceDim = 3; - #Preprocessing: mesh data - xinf=0; - xsup=1; - yinf=0; - ysup=1; - zinf=0; - zsup=1; - - nx=10; - ny=10; - nz=10; - - # set the limit field for each boundary - - coldWallVelocityX=0; - coldWallVelocityY=0; - coldWallVelocityZ=0; - coldWallTemperature=563; - - hotWallVelocityX=0; - hotWallVelocityY=0; - hotWallVelocityZ=0; - hotWallTemperature=613; - - # physical constants - - gravite = [0] * spaceDim - gravite[2]=-10; - gravite[1]=0; - gravite[0]=0; - viscosite=[8.85e-5]; - conductivite=[1000];#Wall heat transfert due to nucleate boiling. - - - myProblem = cf.SinglePhase(cf.Liquid,cf.around155bars600K,spaceDim); - nVar = myProblem.getNumberOfVariables(); - - #Initial field creation - print("Building initial data " ); - - # Prepare for the initial condition - - VV_Constant = [0] * nVar - - # constant vector - VV_Constant[0] = 155e5; - VV_Constant[1] = 0 ; - VV_Constant[2] = 0; - VV_Constant[3] = 0; - VV_Constant[4] = 573; - - #Initial field creation - print("Setting mesh and initial data" ); - myProblem.setInitialFieldConstant(spaceDim,VV_Constant,xinf,xsup,nx,"hotWall","hotWall",yinf,ysup,ny,"hotWall","hotWall",zinf,zsup,nz, "hotWall", "coldWall"); - - # Set the boundary conditions - myProblem.setWallBoundaryCondition("coldWall", coldWallTemperature, coldWallVelocityX, coldWallVelocityY, coldWallVelocityZ); - myProblem.setWallBoundaryCondition("hotWall", hotWallTemperature, hotWallVelocityX, hotWallVelocityY, hotWallVelocityZ); - - # set physical parameters - myProblem.setViscosity(viscosite); - myProblem.setConductivity(conductivite); - myProblem.setGravity(gravite); - - # set the numerical method - myProblem.setNumericalScheme(cf.upwind, cf.Implicit); - myProblem.setLinearSolver(cf.GMRES,cf.ILU,True); - myProblem.setEntropicCorrection(False); - myProblem.setWellBalancedCorrection(False); - - # name file save - fileName = "3DHeatDrivenCavity"; - - # simulation parameters - MaxNbOfTimeStep = 3 ; - freqSave = 1; - cfl = 10; - maxTime = 50; - precision = 1e-6; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - myProblem.setNewtonSolver(precision,50); - myProblem.saveConservativeField(True); - if(spaceDim>1): - myProblem.saveVelocity(); - pass - - # evolution - myProblem.initialize(); - - ok = myProblem.run(); - if (ok): - print( "Simulation python " + fileName + " is successful !" ); - pass - else: - print( "Simulation python " + fileName + " failed ! " ); - pass - - print( "------------ End of calculation !!! -----------" ); - - myProblem.terminate(); - return ok - -if __name__ == """__main__""": - SinglePhase_3DHeatDrivenCavity() diff --git a/CoreFlows/examples/Python/SinglePhase_3DSphericalExplosion_unstructured.py b/CoreFlows/examples/Python/SinglePhase_3DSphericalExplosion_unstructured.py deleted file mode 100755 index 814dad6..0000000 --- a/CoreFlows/examples/Python/SinglePhase_3DSphericalExplosion_unstructured.py +++ /dev/null @@ -1,111 +0,0 @@ -#!/usr/bin/env python -# -*-coding:utf-8 -* - -import CoreFlows as cf -import cdmath - - -def SinglePhase_3DSphericalExplosion_unstructured(): - - inputfile="../../resources/meshCube.med"; - - xinf=0; - xsup=1; - yinf=0; - ysup=1; - zinf=0; - zsup=1; - M=cdmath.Mesh(inputfile); - eps=1.E-6; - M.setGroupAtPlan(xinf,0,eps,"GAUCHE"); - M.setGroupAtPlan(xsup,0,eps,"DROITE"); - M.setGroupAtPlan(yinf,1,eps,"ARRIERE"); - M.setGroupAtPlan(ysup,1,eps,"AVANT"); - M.setGroupAtPlan(zinf,2,eps,"BAS"); - M.setGroupAtPlan(zsup,2,eps,"HAUT"); - - # Initial field data - spaceDim = 3; - nVar=2+spaceDim; - radius=0.5; - Center=cdmath.Vector(3);#default value is (0,0,0) - Vout=cdmath.Vector(nVar) - Vin =cdmath.Vector(nVar) - Vin[0]=1.1; - Vin[1]=0; - Vin[2]=0; - Vin[3]=0; - Vin[4]=300; - Vout[0]=1; - Vout[1]=0; - Vout[2]=0; - Vout[3]=0; - Vout[4]=300; - - myProblem = cf.SinglePhase(cf.Liquid,cf.around155bars600K,spaceDim); - nVar=myProblem.getNumberOfVariables(); - - # Initial field creation - print ("Setting mesh and initial data" ) ; - myProblem.setInitialFieldSphericalStepFunction( M, Vout, Vin, radius, Center); - - # set the boundary conditions - wallVelocityX=0; - wallVelocityY=0; - wallVelocityZ=0; - wallTemperature=563; - - myProblem.setWallBoundaryCondition("GAUCHE", wallTemperature, wallVelocityX, wallVelocityY, wallVelocityZ); - myProblem.setWallBoundaryCondition("DROITE", wallTemperature, wallVelocityX, wallVelocityY, wallVelocityZ); - myProblem.setWallBoundaryCondition("HAUT", wallTemperature, wallVelocityX, wallVelocityY, wallVelocityZ); - myProblem.setWallBoundaryCondition("BAS", wallTemperature, wallVelocityX, wallVelocityY, wallVelocityZ); - myProblem.setWallBoundaryCondition("AVANT", wallTemperature, wallVelocityX, wallVelocityY, wallVelocityZ); - myProblem.setWallBoundaryCondition("ARRIERE", wallTemperature, wallVelocityX, wallVelocityY, wallVelocityZ); - - # set the numerical method - myProblem.setNumericalScheme(cf.upwind, cf.Explicit); - myProblem.setLinearSolver(cf.GMRES,cf.ILU,True); - myProblem.setEntropicCorrection(False); - myProblem.setWellBalancedCorrection(False); - - # name file save - fileName = "3DSphericalExplosion_unstructured"; - - # parameters calculation - MaxNbOfTimeStep = 3 ; - freqSave = 1; - cfl = 0.5; - maxTime = 5; - precision = 1e-6; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - myProblem.setNewtonSolver(precision,20); - myProblem.saveConservativeField(True); - if(spaceDim>1): - myProblem.saveVelocity(); - pass - - - # evolution - myProblem.initialize(); - - ok = myProblem.run(); - if (ok): - print( "Simulation python " + fileName + " is successful !" ); - pass - else: - print( "Simulation python " + fileName + " failed ! " ); - pass - - print( "------------ End of calculation !!! -----------" ); - - myProblem.terminate(); - return ok - -if __name__ == """__main__""": - SinglePhase_3DSphericalExplosion_unstructured() diff --git a/CoreFlows/examples/Python/SinglePhase_3DVortexTube_NoCone_NoViscosity.py b/CoreFlows/examples/Python/SinglePhase_3DVortexTube_NoCone_NoViscosity.py deleted file mode 100755 index b1fc887..0000000 --- a/CoreFlows/examples/Python/SinglePhase_3DVortexTube_NoCone_NoViscosity.py +++ /dev/null @@ -1,96 +0,0 @@ -#!/usr/bin/env python -# -*-coding:utf-8 -* - - -import CoreFlows as cf - -def SinglePhase_3DVortexTube_WithoutCone(): - spaceDim = 3; - - print( "Loading mesh of vortex tube without cone" ); - inputfile="../resources/VortexTubeWithoutCone.med"; - - # set the limit field for each boundary - outletPressure = 1e5; - inletPressure = 10e5; - inletTemperature = 300; - - # physical constants - #viscosite=[0.025]; - - myProblem = cf.SinglePhase(cf.Gas,cf.around1bar300K,spaceDim); - nVar = myProblem.getNumberOfVariables(); - - #Initial field creation - print("Building initial data " ); - - # Prepare for the initial condition - - VV_Constant = [0] * nVar - - # constant vector - VV_Constant[0] = 1e5; - VV_Constant[1] = 0 ; - VV_Constant[2] = 0; - VV_Constant[3] = 0; - VV_Constant[4] = 300; - - #Initial field creation - print("Setting mesh and initial data" ); - myProblem.setInitialFieldConstant(inputfile,VV_Constant); - - # Set the boundary conditions - myProblem.setInletPressureBoundaryCondition("Inlet flow", inletPressure, inletTemperature,0,100,0) - myProblem.setOutletBoundaryCondition("Hot outlet", outletPressure) - myProblem.setOutletBoundaryCondition("Cold outlet", outletPressure) - myProblem.setWallBoundaryCondition("Wall", inletTemperature) - - # set physical parameters - #myProblem.setViscosity(viscosite); - - # set the numerical method - myProblem.setNumericalScheme(cf.upwind, cf.Explicit); - myProblem.setNonLinearFormulation(cf.reducedRoe); - myProblem.setEntropicCorrection(True) - #myProblem.setLinearSolver(cf.GMRES,cf.ILU,True); - - # name file save - fileName = "3DVortexTubeWithoutCone"; - - # simulation parameters - MaxNbOfTimeStep = 10000 ; - freqSave = 100; - cfl = 1./3; - maxTime = 50; - precision = 1e-6; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - #myProblem.setNewtonSolver(precision,20); - #yProblem.saveConservativeField(True); - if(spaceDim>1): - myProblem.saveVelocity(); - pass - - # evolution - myProblem.initialize(); - - ok = myProblem.run(); - if (ok): - print( "Simulation python " + fileName + " is successful !" ); - pass - else: - print( "Simulation python " + fileName + " failed ! " ); - pass - - print( "------------ End of calculation !!! -----------" ); - - myProblem.terminate(); - return ok - -if __name__ == """__main__""": - SinglePhase_3DVortexTube_WithoutCone() diff --git a/CoreFlows/examples/Python/SinglePhase_3DVortexTube_WithCone_NoViscosity.py b/CoreFlows/examples/Python/SinglePhase_3DVortexTube_WithCone_NoViscosity.py deleted file mode 100755 index a449b67..0000000 --- a/CoreFlows/examples/Python/SinglePhase_3DVortexTube_WithCone_NoViscosity.py +++ /dev/null @@ -1,97 +0,0 @@ -#!/usr/bin/env python -# -*-coding:utf-8 -* - - -import CoreFlows as cf - -def SinglePhase_3DVortexTube_WithCone(): - spaceDim = 3; - - print( "Loading mesh of vortex tube with cone" ); - inputfile="../resources/VortexTubeWithCone.med"; - - # set the limit field for each boundary - outletPressure = 1.e5; - inletPressure = 10.e5; - inletTemperature = 300.; - - # physical constants - #viscosite=[0.025]; - - myProblem = cf.SinglePhase(cf.Gas,cf.around1bar300K,spaceDim); - nVar = myProblem.getNumberOfVariables(); - - #Initial field creation - print("Building initial data " ); - - # Prepare for the initial condition - - VV_Constant = [0] * nVar - - # constant vector - VV_Constant[0] = 1.e5; - VV_Constant[1] = 0 ; - VV_Constant[2] = 0; - VV_Constant[3] = 0; - VV_Constant[4] = 300.; - - #Initial field creation - print("Setting mesh and initial data" ); - myProblem.setInitialFieldConstant(inputfile,VV_Constant); - - # Set the boundary conditions - myProblem.setInletPressureBoundaryCondition("Inlet flow", inletPressure, inletTemperature,0,100,0) - myProblem.setOutletBoundaryCondition("Hot outlet", outletPressure) - myProblem.setOutletBoundaryCondition("Cold outlet", outletPressure) - myProblem.setWallBoundaryCondition("Wall", inletTemperature) - - # set physical parameters - #myProblem.setViscosity(viscosite); - - # set the numerical method - myProblem.setNumericalScheme(cf.upwind, cf.Explicit); - myProblem.setNonLinearFormulation(cf.reducedRoe); - myProblem.setEntropicCorrection(False) - #myProblem.setLinearSolver(cf.GMRES,cf.ILU,True); - - # name file save - fileName = "3DVortexTubeWithCone"; - - # simulation parameters - MaxNbOfTimeStep = 100000 ; - freqSave = 1; - cfl = 0.3; - maxTime = 50; - precision = 1e-6; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - #myProblem.setNewtonSolver(precision,20); - #yProblem.saveConservativeField(True); - #myProblem.setVerbose(False,True); - if(spaceDim>1): - myProblem.saveVelocity(); - pass - - # evolution - myProblem.initialize(); - - ok = myProblem.run(); - if (ok): - print( "Simulation python " + fileName + " is successful !" ); - pass - else: - print( "Simulation python " + fileName + " failed ! " ); - pass - - print( "------------ End of calculation !!! -----------" ); - - myProblem.terminate(); - return ok - -if __name__ == """__main__""": - SinglePhase_3DVortexTube_WithCone() diff --git a/CoreFlows/examples/Python/StationaryDiffusionEquation/StationaryDiffusionEquation_2DEF.py b/CoreFlows/examples/Python/StationaryDiffusionEquation/StationaryDiffusionEquation_2DEF.py new file mode 100755 index 0000000..17069e6 --- /dev/null +++ b/CoreFlows/examples/Python/StationaryDiffusionEquation/StationaryDiffusionEquation_2DEF.py @@ -0,0 +1,102 @@ +#!/usr/bin/env python +# -*-coding:utf-8 -* +#=============================================================================================================================== +# Name : Résolution EF de l'équation de Poisson 2D -\triangle T = f avec conditions aux limites de Dirichlet T=0 +# Author : Michaël Ndjinga +# Copyright : CEA Saclay 2019 +# Description : Utilisation de la méthode des éléménts finis P1 avec champs T et f discrétisés aux noeuds d'un maillage triangulaire +# Création et sauvegarde du champ résultant ainsi que du champ second membre en utilisant la librairie CDMATH +# Comparaison de la solution numérique avec la solution exacte T=-sin(pi*x)*sin(pi*y) +#================================================================================================================================ + +import CoreFlows as cf +import cdmath as cm +from math import sin, pi + +def StationaryDiffusionEquation_2DEF_StructuredTriangles(): + spaceDim = 2; + # Prepare for the mesh + print("Building mesh " ); + xinf = 0 ; + xsup=1.0; + yinf=0.0; + ysup=1.0; + nx=20; + ny=20; + M=cm.Mesh(xinf,xsup,nx,yinf,ysup,ny,0)#Regular triangular mesh + # set the limit field for each boundary + eps=1e-6; + M.setGroupAtPlan(xsup,0,eps,"Bord1") + M.setGroupAtPlan(xinf,0,eps,"Bord2") + M.setGroupAtPlan(ysup,1,eps,"Bord3") + M.setGroupAtPlan(yinf,1,eps,"Bord4") + + print "Built a regular triangular 2D mesh from a square mesh with ", nx,"x" ,ny, " cells" + + FEComputation=True + myProblem = cf.StationaryDiffusionEquation(spaceDim,FEComputation); + myProblem.setMesh(M); + + # set the limit value for each boundary + T1=0; + T2=0; + T3=0; + T4=0; + + myProblem.setDirichletBoundaryCondition("Bord1",T1) + myProblem.setDirichletBoundaryCondition("Bord2",T2) + myProblem.setDirichletBoundaryCondition("Bord3",T3) + myProblem.setDirichletBoundaryCondition("Bord4",T4) + + #Set the right hand side function + my_RHSfield = cm.Field("RHS_field", cm.NODES, M, 1) + for i in range(M.getNumberOfNodes()): + Ni= M.getNode(i) + x = Ni.x() + y = Ni.y() + + my_RHSfield[i]=2*pi*pi*sin(pi*x)*sin(pi*y)#mettre la fonction definie au second membre de l'edp + + myProblem.setHeatPowerField(my_RHSfield) + myProblem.setLinearSolver(cf.GMRES,cf.ILU); + + # name of result file + fileName = "StationnaryDiffusion_2DEF_StructuredTriangles"; + + # computation parameters + myProblem.setFileName(fileName); + + # Run the computation + myProblem.initialize(); + print("Running python "+ fileName ); + + ok = myProblem.solveStationaryProblem(); + if (not ok): + print( "Python simulation of " + fileName + " failed ! " ); + pass + else: + ####################### Postprocessing ######################### + my_ResultField = myProblem.getOutputTemperatureField() + #The following formulas use the fact that the exact solution is equal the right hand side divided by 2*pi*pi + max_abs_sol_exacte=max(my_RHSfield.max(),-my_RHSfield.min())/(2*pi*pi) + max_sol_num=my_ResultField.max() + min_sol_num=my_ResultField.min() + erreur_abs=0 + for i in range(M.getNumberOfNodes()) : + if erreur_abs < abs(my_RHSfield[i]/(2*pi*pi) - my_ResultField[i]) : + erreur_abs = abs(my_RHSfield[i]/(2*pi*pi) - my_ResultField[i]) + + print("Absolute error = max(| exact solution - numerical solution |) = ",erreur_abs ) + print("Relative error = max(| exact solution - numerical solution |)/max(| exact solution |) = ",erreur_abs/max_abs_sol_exacte) + print ("Maximum numerical solution = ", max_sol_num, " Minimum numerical solution = ", min_sol_num) + + assert erreur_abs/max_abs_sol_exacte <1. + pass + + print( "------------ !!! End of calculation !!! -----------" ); + + myProblem.terminate(); + return ok + +if __name__ == """__main__""": + StationaryDiffusionEquation_2DEF_StructuredTriangles() diff --git a/CoreFlows/examples/Python/StationaryDiffusionEquation/StationaryDiffusionEquation_2DEF_Neumann.py b/CoreFlows/examples/Python/StationaryDiffusionEquation/StationaryDiffusionEquation_2DEF_Neumann.py new file mode 100755 index 0000000..74411a9 --- /dev/null +++ b/CoreFlows/examples/Python/StationaryDiffusionEquation/StationaryDiffusionEquation_2DEF_Neumann.py @@ -0,0 +1,97 @@ +#!/usr/bin/env python +# -*-coding:utf-8 -* +#=============================================================================================================================== +# Name : Résolution EF de l'équation de Poisson 2D -\triangle T = f avec conditions aux limites de Neumann T=0 +# Author : Michaël Ndjinga +# Copyright : CEA Saclay 2019 +# Description : Utilisation de la méthode des éléménts finis P1 avec champs T et f discrétisés aux noeuds d'un maillage triangulaire +# Création et sauvegarde du champ résultant ainsi que du champ second membre en utilisant la librairie CDMATH +# Comparaison de la solution numérique avec la solution exacte T=-cos(pi*x)*cos(pi*y) +#================================================================================================================================ + +import CoreFlows as cf +import cdmath as cm +from math import cos, pi + +def StationaryDiffusionEquation_2DEF_StructuredTriangles_Neumann(): + spaceDim = 2; + # Prepare for the mesh + print("Building mesh " ); + xinf = 0.0; + xsup = 1.0; + yinf = 0.0; + ysup = 1.0; + nx=20; + ny=20; + M=cm.Mesh(xinf,xsup,nx,yinf,ysup,ny,0)#Regular triangular mesh + # set the limit field for each boundary + eps=1e-6; + M.setGroupAtPlan(xsup,0,eps,"Bord1") + M.setGroupAtPlan(xinf,0,eps,"Bord2") + M.setGroupAtPlan(ysup,1,eps,"Bord3") + M.setGroupAtPlan(yinf,1,eps,"Bord4") + + print "Built a regular triangular 2D mesh from a square mesh with ", nx,"x" ,ny, " cells" + + FEComputation=True + myProblem = cf.StationaryDiffusionEquation(spaceDim,FEComputation); + myProblem.setMesh(M); + + # set the boundary condition for each boundary + myProblem.setNeumannBoundaryCondition("Bord1") + myProblem.setNeumannBoundaryCondition("Bord2") + myProblem.setNeumannBoundaryCondition("Bord3") + myProblem.setNeumannBoundaryCondition("Bord4") + + #Set the right hand side function + my_RHSfield = cm.Field("RHS_field", cm.NODES, M, 1) + for i in range(M.getNumberOfNodes()): + Ni= M.getNode(i) + x = Ni.x() + y = Ni.y() + + my_RHSfield[i]=2*pi*pi*cos(pi*x)*cos(pi*y)#mettre la fonction definie au second membre de l'edp + + myProblem.setHeatPowerField(my_RHSfield) + myProblem.setLinearSolver(cf.GMRES,cf.ILU); + + # name of result file + fileName = "StationnaryDiffusion_2DEF_StructuredTriangles_Neumann"; + + # computation parameters + myProblem.setFileName(fileName); + + # Run the computation + myProblem.initialize(); + print("Running python "+ fileName ); + + ok = myProblem.solveStationaryProblem(); + if (not ok): + print( "Python simulation of " + fileName + " failed ! " ); + pass + else: + ####################### Postprocessing ######################### + my_ResultField = myProblem.getOutputTemperatureField() + #The following formulas use the fact that the exact solution is equal the right hand side divided by 2*pi*pi + max_abs_sol_exacte=max(my_RHSfield.max(),-my_RHSfield.min())/(2*pi*pi) + max_sol_num=my_ResultField.max() + min_sol_num=my_ResultField.min() + erreur_abs=0 + for i in range(M.getNumberOfNodes()) : + if erreur_abs < abs(my_RHSfield[i]/(2*pi*pi) - my_ResultField[i]) : + erreur_abs = abs(my_RHSfield[i]/(2*pi*pi) - my_ResultField[i]) + + print("Absolute error = max(| exact solution - numerical solution |) = ",erreur_abs ) + print("Relative error = max(| exact solution - numerical solution |)/max(| exact solution |) = ",erreur_abs/max_abs_sol_exacte) + print ("Maximum numerical solution = ", max_sol_num, " Minimum numerical solution = ", min_sol_num) + + assert erreur_abs/max_abs_sol_exacte <1. + pass + + print( "------------ !!! End of calculation !!! -----------" ); + + myProblem.terminate(); + return ok + +if __name__ == """__main__""": + StationaryDiffusionEquation_2DEF_StructuredTriangles_Neumann() diff --git a/CoreFlows/examples/Python/StationaryDiffusionEquation/StationaryDiffusionEquation_2DFV_EquilateralTriangles.py b/CoreFlows/examples/Python/StationaryDiffusionEquation/StationaryDiffusionEquation_2DFV_EquilateralTriangles.py new file mode 100755 index 0000000..2cc35c3 --- /dev/null +++ b/CoreFlows/examples/Python/StationaryDiffusionEquation/StationaryDiffusionEquation_2DFV_EquilateralTriangles.py @@ -0,0 +1,92 @@ +#!/usr/bin/env python +# -*-coding:utf-8 -* +#=============================================================================================================================== +# Name : Résolution VF de l'équation de Poisson 2D -\triangle T = f sur un carré avec conditions aux limites de Dirichlet T=0 +# Author : Michaël Ndjinga +# Copyright : CEA Saclay 2019 +# Description : Utilisation de la méthode des volumes finis avec champs T et f discrétisés aux cellules d'un maillage de triangules équilatéraux +# Création et sauvegarde du champ résultant ainsi que du champ second membre en utilisant CDMATH +# Comparaison de la solution numérique avec la solution exacte T=sin(pi*x)*sin(pi*y) +#================================================================================================================================ + +import CoreFlows as cf +import cdmath as cm +from math import sin, pi +import os + +def StationaryDiffusionEquation_2DFV_EquilateralTriangles(): + spaceDim = 2; + # Prepare for the mesh + print("Loading mesh " ); + M=cm.Mesh(os.environ['CDMATH_INSTALL']+'/share/meshes/2DEquilateralTriangles/squareWithEquilateralTriangles20.med')#Equilateral triangular mesh + + print( "Loaded 2D equilateral triangle mesh with ", M.getNumberOfCells(), " cells") + + # set the limit field + boundaryFaces = M.getBoundaryFaceIds() + boundaryValues = {} + print("Setting Dirichlet boundary values") + for i in boundaryFaces : + Fi=M.getFace(i) + x=Fi.x() + y=Fi.y() + boundaryValues[i] = sin(pi*x)*sin(pi*y) + + FEComputation=False + myProblem = cf.StationaryDiffusionEquation(spaceDim,FEComputation); + myProblem.setMesh(M); + myProblem.setDirichletValues(cf.MapIntDouble(boundaryValues)) + + #Set the right hand side function + my_RHSfield = cm.Field("RHS_field", cm.CELLS, M, 1) + for i in range(M.getNumberOfCells()): + Ci= M.getCell(i) + x = Ci.x() + y = Ci.y() + + my_RHSfield[i]=2*pi*pi*sin(pi*x)*sin(pi*y)#mettre la fonction definie au second membre de l'edp + + myProblem.setHeatPowerField(my_RHSfield) + myProblem.setLinearSolver(cf.GMRES,cf.ILU); + + # name of result file + fileName = "StationnaryDiffusion_2DFV_StructuredTriangles"; + + # computation parameters + myProblem.setFileName(fileName); + + # Run the computation + myProblem.initialize(); + print("Running python "+ fileName ); + + ok = myProblem.solveStationaryProblem(); + if (not ok): + print( "Python simulation of " + fileName + " failed ! " ); + pass + else: + print( "Python simulation of " + fileName + " is successful !" ); + ####################### Postprocessing ######################### + my_ResultField = myProblem.getOutputTemperatureField() + #The following formulas use the fact that the exact solution is equal the right hand side divided by 2*pi*pi + max_abs_sol_exacte=max(my_RHSfield.max(),-my_RHSfield.min())/(2*pi*pi) + max_sol_num=my_ResultField.max() + min_sol_num=my_ResultField.min() + erreur_abs=0 + for i in range(M.getNumberOfCells()) : + if erreur_abs < abs(my_RHSfield[i]/(2*pi*pi) - my_ResultField[i]) : + erreur_abs = abs(my_RHSfield[i]/(2*pi*pi) - my_ResultField[i]) + + print("Absolute error = max(| exact solution - numerical solution |) = ",erreur_abs ) + print("Relative error = max(| exact solution - numerical solution |)/max(| exact solution |) = ",erreur_abs/max_abs_sol_exacte) + print ("Maximum numerical solution = ", max_sol_num, " Minimum numerical solution = ", min_sol_num) + + assert erreur_abs/max_abs_sol_exacte <1. + pass + + print( "------------ !!! End of calculation !!! -----------" ); + + myProblem.terminate(); + return ok + +if __name__ == """__main__""": + StationaryDiffusionEquation_2DFV_EquilateralTriangles() diff --git a/CoreFlows/examples/Python/StationaryDiffusionEquation/StationaryDiffusionEquation_2DFV_StructuredSquares.py b/CoreFlows/examples/Python/StationaryDiffusionEquation/StationaryDiffusionEquation_2DFV_StructuredSquares.py new file mode 100755 index 0000000..d47ef43 --- /dev/null +++ b/CoreFlows/examples/Python/StationaryDiffusionEquation/StationaryDiffusionEquation_2DFV_StructuredSquares.py @@ -0,0 +1,103 @@ +#!/usr/bin/env python +# -*-coding:utf-8 -* +#=============================================================================================================================== +# Name : Résolution VF de l'équation de Poisson 2D -\triangle T = f sur un carré avec conditions aux limites de Dirichlet T=0 +# Author : Michaël Ndjinga +# Copyright : CEA Saclay 2019 +# Description : Utilisation de la méthode des volumes finis avec champs T et f discrétisés aux cellules d'un maillage triangulaire +# Création et sauvegarde du champ résultant ainsi que du champ second membre en utilisant CDMATH +# Comparaison de la solution numérique avec la solution exacte T=sin(pi*x)*sin(pi*y) +#================================================================================================================================ + +import CoreFlows as cf +import cdmath as cm +from math import sin, pi + +def StationaryDiffusionEquation_2DFV_StructuredSquares(): + spaceDim = 2; + # Prepare for the mesh + print("Building mesh " ); + xinf = 0 ; + xsup=1.0; + yinf=0.0; + ysup=1.0; + nx=30; + ny=30; + M=cm.Mesh(xinf,xsup,nx,yinf,ysup,ny)#Regular square mesh + # set the limit field for each boundary + eps=1e-6; + M.setGroupAtPlan(xsup,0,eps,"Bord1") + M.setGroupAtPlan(xinf,0,eps,"Bord2") + M.setGroupAtPlan(ysup,1,eps,"Bord3") + M.setGroupAtPlan(yinf,1,eps,"Bord4") + + print "Built a regular 2D square mesh with ", nx,"x" ,ny, " cells" + + FEComputation=False + myProblem = cf.StationaryDiffusionEquation(spaceDim,FEComputation); + myProblem.setMesh(M); + + # set the limit value for each boundary + T1=0; + T2=0; + T3=0; + T4=0; + + myProblem.setDirichletBoundaryCondition("Bord1",T1) + myProblem.setDirichletBoundaryCondition("Bord2",T2) + myProblem.setDirichletBoundaryCondition("Bord3",T3) + myProblem.setDirichletBoundaryCondition("Bord4",T4) + + #Set the right hand side function + my_RHSfield = cm.Field("RHS_field", cm.CELLS, M, 1) + for i in range(M.getNumberOfCells()): + Ci= M.getCell(i) + x = Ci.x() + y = Ci.y() + + my_RHSfield[i]=2*pi*pi*sin(pi*x)*sin(pi*y)#mettre la fonction definie au second membre de l'edp + + myProblem.setHeatPowerField(my_RHSfield) + myProblem.setLinearSolver(cf.GMRES,cf.ILU); + + # name of result file + fileName = "StationnaryDiffusion_2DFV_StructuredSquares"; + + # computation parameters + myProblem.setFileName(fileName); + + # Run the computation + myProblem.initialize(); + print("Running python "+ fileName ); + + ok = myProblem.solveStationaryProblem(); + if (not ok): + print( "Python simulation of " + fileName + " failed ! " ); + pass + else: + print( "Python simulation of " + fileName + " is successful !" ); + ####################### Postprocessing ######################### + my_ResultField = myProblem.getOutputTemperatureField() + #The following formulas use the fact that the exact solution is equal the right hand side divided by 2*pi*pi + max_abs_sol_exacte=max(my_RHSfield.max(),-my_RHSfield.min())/(2*pi*pi) + max_sol_num=my_ResultField.max() + min_sol_num=my_ResultField.min() + erreur_abs=0 + for i in range(M.getNumberOfCells()) : + if erreur_abs < abs(my_RHSfield[i]/(2*pi*pi) - my_ResultField[i]) : + erreur_abs = abs(my_RHSfield[i]/(2*pi*pi) - my_ResultField[i]) + + print("Absolute error = max(| exact solution - numerical solution |) = ",erreur_abs ) + print("Relative error = max(| exact solution - numerical solution |)/max(| exact solution |) = ",erreur_abs/max_abs_sol_exacte) + print ("Maximum numerical solution = ", max_sol_num, " Minimum numerical solution = ", min_sol_num) + + assert erreur_abs/max_abs_sol_exacte <1. + pass + + print( "------------ !!! End of calculation !!! -----------" ); + + myProblem.terminate(); + return ok + +if __name__ == """__main__""": + StationaryDiffusionEquation_2DFV_StructuredSquares() diff --git a/CoreFlows/examples/Python/StationaryDiffusionEquation/StationaryDiffusionEquation_2DFV_StructuredSquares_Neumann.py b/CoreFlows/examples/Python/StationaryDiffusionEquation/StationaryDiffusionEquation_2DFV_StructuredSquares_Neumann.py new file mode 100755 index 0000000..041a082 --- /dev/null +++ b/CoreFlows/examples/Python/StationaryDiffusionEquation/StationaryDiffusionEquation_2DFV_StructuredSquares_Neumann.py @@ -0,0 +1,103 @@ +#!/usr/bin/env python +# -*-coding:utf-8 -* +#=============================================================================================================================== +# Name : Résolution VF de l'équation de Poisson 2D -\triangle T = f sur un carré avec conditions aux limites de Neumann T=0 +# Author : Michaël Ndjinga +# Copyright : CEA Saclay 2019 +# Description : Utilisation de la méthode des volumes finis avec champs T et f discrétisés aux cellules d'un maillage triangulaire +# Création et sauvegarde du champ résultant ainsi que du champ second membre en utilisant CDMATH +# Comparaison de la solution numérique avec la solution exacte T=cos(pi*x)*cos(pi*y) +#================================================================================================================================ + +import CoreFlows as cf +import cdmath as cm +from math import cos, pi + +def StationaryDiffusionEquation_2DFV_StructuredSquares_Neumann(): + spaceDim = 2; + # Prepare for the mesh + print("Building mesh " ); + xinf = 0.0; + xsup = 1.0; + yinf = 0.0; + ysup = 1.0; + nx=30; + ny=30; + M=cm.Mesh(xinf,xsup,nx,yinf,ysup,ny)#Regular square mesh + # set the limit field for each boundary + eps=1e-6; + M.setGroupAtPlan(xsup,0,eps,"Bord1") + M.setGroupAtPlan(xinf,0,eps,"Bord2") + M.setGroupAtPlan(ysup,1,eps,"Bord3") + M.setGroupAtPlan(yinf,1,eps,"Bord4") + + print "Built a regular 2D square mesh with ", nx,"x" ,ny, " cells" + + FEComputation=False + myProblem = cf.StationaryDiffusionEquation(spaceDim,FEComputation); + myProblem.setMesh(M); + + # set the limit value for each boundary + T1=0; + T2=0; + T3=0; + T4=0; + + myProblem.setNeumannBoundaryCondition("Bord1") + myProblem.setNeumannBoundaryCondition("Bord2") + myProblem.setNeumannBoundaryCondition("Bord3") + myProblem.setNeumannBoundaryCondition("Bord4") + + #Set the right hand side function + my_RHSfield = cm.Field("RHS_field", cm.CELLS, M, 1) + for i in range(M.getNumberOfCells()): + Ci= M.getCell(i) + x = Ci.x() + y = Ci.y() + + my_RHSfield[i]=2*pi*pi*cos(pi*x)*cos(pi*y)#mettre la fonction definie au second membre de l'edp + + myProblem.setHeatPowerField(my_RHSfield) + myProblem.setLinearSolver(cf.GMRES,cf.ILU); + + # name of result file + fileName = "StationnaryDiffusion_2DFV_StructuredSquares_Neumann"; + + # computation parameters + myProblem.setFileName(fileName); + + # Run the computation + myProblem.initialize(); + print("Running python "+ fileName ); + + ok = myProblem.solveStationaryProblem(); + if (not ok): + print( "Python simulation of " + fileName + " failed ! " ); + pass + else: + print( "Python simulation of " + fileName + " is successful !" ); + ####################### Postprocessing ######################### + my_ResultField = myProblem.getOutputTemperatureField() + #The following formulas use the fact that the exact solution is equal the right hand side divided by 2*pi*pi + max_abs_sol_exacte=max(my_RHSfield.max(),-my_RHSfield.min())/(2*pi*pi) + max_sol_num=my_ResultField.max() + min_sol_num=my_ResultField.min() + erreur_abs=0 + for i in range(M.getNumberOfCells()) : + if erreur_abs < abs(my_RHSfield[i]/(2*pi*pi) - my_ResultField[i]) : + erreur_abs = abs(my_RHSfield[i]/(2*pi*pi) - my_ResultField[i]) + + print("Absolute error = max(| exact solution - numerical solution |) = ",erreur_abs ) + print("Relative error = max(| exact solution - numerical solution |)/max(| exact solution |) = ",erreur_abs/max_abs_sol_exacte) + print ("Maximum numerical solution = ", max_sol_num, " Minimum numerical solution = ", min_sol_num) + + assert erreur_abs/max_abs_sol_exacte <1. + pass + + print( "------------ !!! End of calculation !!! -----------" ); + + myProblem.terminate(); + return ok + +if __name__ == """__main__""": + StationaryDiffusionEquation_2DFV_StructuredSquares_Neumann() diff --git a/CoreFlows/examples/Python/StationaryDiffusionEquation/StationaryDiffusionEquation_2DFV_StructuredTriangles.py b/CoreFlows/examples/Python/StationaryDiffusionEquation/StationaryDiffusionEquation_2DFV_StructuredTriangles.py new file mode 100755 index 0000000..8aef892 --- /dev/null +++ b/CoreFlows/examples/Python/StationaryDiffusionEquation/StationaryDiffusionEquation_2DFV_StructuredTriangles.py @@ -0,0 +1,103 @@ +#!/usr/bin/env python +# -*-coding:utf-8 -* +#=============================================================================================================================== +# Name : Résolution VF de l'équation de Poisson 2D -\triangle T = f sur un carré avec conditions aux limites de Dirichlet T=0 +# Author : Michaël Ndjinga +# Copyright : CEA Saclay 2019 +# Description : Utilisation de la méthode des volumes finis avec champs T et f discrétisés aux cellules d'un maillage triangulaire +# Création et sauvegarde du champ résultant ainsi que du champ second membre en utilisant CDMATH +# Comparaison de la solution numérique avec la solution exacte T=sin(pi*x)*sin(pi*y) +#================================================================================================================================ + +import CoreFlows as cf +import cdmath as cm +from math import sin, pi + +def StationaryDiffusionEquation_2DFV_StructuredTriangles(): + spaceDim = 2; + # Prepare for the mesh + print("Building mesh " ); + xinf = 0 ; + xsup=1.0; + yinf=0.0; + ysup=1.0; + nx=20; + ny=20; + M=cm.Mesh(xinf,xsup,nx,yinf,ysup,ny,0)#Regular triangular mesh + # set the limit field for each boundary + eps=1e-6; + M.setGroupAtPlan(xsup,0,eps,"Bord1") + M.setGroupAtPlan(xinf,0,eps,"Bord2") + M.setGroupAtPlan(ysup,1,eps,"Bord3") + M.setGroupAtPlan(yinf,1,eps,"Bord4") + + print "Built a regular triangular 2D mesh from a square mesh with ", nx,"x" ,ny, " cells" + + FEComputation=False + myProblem = cf.StationaryDiffusionEquation(spaceDim,FEComputation); + myProblem.setMesh(M); + + # set the limit value for each boundary + T1=0; + T2=0; + T3=0; + T4=0; + + myProblem.setDirichletBoundaryCondition("Bord1",T1) + myProblem.setDirichletBoundaryCondition("Bord2",T2) + myProblem.setDirichletBoundaryCondition("Bord3",T3) + myProblem.setDirichletBoundaryCondition("Bord4",T4) + + #Set the right hand side function + my_RHSfield = cm.Field("RHS_field", cm.CELLS, M, 1) + for i in range(M.getNumberOfCells()): + Ci= M.getCell(i) + x = Ci.x() + y = Ci.y() + + my_RHSfield[i]=2*pi*pi*sin(pi*x)*sin(pi*y)#mettre la fonction definie au second membre de l'edp + + myProblem.setHeatPowerField(my_RHSfield) + myProblem.setLinearSolver(cf.GMRES,cf.ILU); + + # name of result file + fileName = "StationnaryDiffusion_2DFV_StructuredTriangles"; + + # computation parameters + myProblem.setFileName(fileName); + + # Run the computation + myProblem.initialize(); + print("Running python "+ fileName ); + + ok = myProblem.solveStationaryProblem(); + if (not ok): + print( "Python simulation of " + fileName + " failed ! " ); + pass + else: + print( "Python simulation of " + fileName + " is successful !" ); + ####################### Postprocessing ######################### + my_ResultField = myProblem.getOutputTemperatureField() + #The following formulas use the fact that the exact solution is equal the right hand side divided by 2*pi*pi + max_abs_sol_exacte=max(my_RHSfield.max(),-my_RHSfield.min())/(2*pi*pi) + max_sol_num=my_ResultField.max() + min_sol_num=my_ResultField.min() + erreur_abs=0 + for i in range(M.getNumberOfCells()) : + if erreur_abs < abs(my_RHSfield[i]/(2*pi*pi) - my_ResultField[i]) : + erreur_abs = abs(my_RHSfield[i]/(2*pi*pi) - my_ResultField[i]) + + print("Absolute error = max(| exact solution - numerical solution |) = ",erreur_abs ) + print("Relative error = max(| exact solution - numerical solution |)/max(| exact solution |) = ",erreur_abs/max_abs_sol_exacte) + print ("Maximum numerical solution = ", max_sol_num, " Minimum numerical solution = ", min_sol_num) + + assert erreur_abs/max_abs_sol_exacte <1. + pass + + print( "------------ !!! End of calculation !!! -----------" ); + + myProblem.terminate(); + return ok + +if __name__ == """__main__""": + StationaryDiffusionEquation_2DFV_StructuredTriangles() diff --git a/CoreFlows/examples/Python/StationaryDiffusionEquation/StationaryDiffusionEquation_3DEF.py b/CoreFlows/examples/Python/StationaryDiffusionEquation/StationaryDiffusionEquation_3DEF.py new file mode 100755 index 0000000..59fc326 --- /dev/null +++ b/CoreFlows/examples/Python/StationaryDiffusionEquation/StationaryDiffusionEquation_3DEF.py @@ -0,0 +1,112 @@ +#!/usr/bin/env python +# -*-coding:utf-8 -* +#=============================================================================================================================== +# Name : Résolution EF de l'équation de Poisson 3D -\triangle T = f avec conditions aux limites de Dirichlet T=0 +# Author : Michaël Ndjinga +# Copyright : CEA Saclay 2019 +# Description : Utilisation de la méthode des éléménts finis P1 avec champs T et f discrétisés aux noeuds d'un maillage tétraédrique +# Création et sauvegarde du champ résultant ainsi que du champ second membre en utilisant la librairie CDMATH +# Comparaison de la solution numérique avec la solution exacte T=-sin(pi*x)*sin(pi*y)*sin(pi*z) +#================================================================================================================================ + +import CoreFlows as cf +import cdmath as cm +from math import sin, pi + +def StationaryDiffusionEquation_3DEF_StructuredTriangles(): + spaceDim = 3; + # Prepare for the mesh + print("Building mesh " ); + xinf = 0.0; + xsup = 1.0; + yinf = 0.0; + ysup = 1.0; + zinf = 0.0; + zsup = 1.0; + nx = 5; + ny = 5; + nz = 5; + M=cm.Mesh(xinf,xsup,nx,yinf,ysup,ny,zinf,zsup,nz,1)#Regular tetrahedral mesh + # set the limit field for each boundary + eps=1e-6; + M.setGroupAtPlan(xsup,0,eps,"Bord1") + M.setGroupAtPlan(xinf,0,eps,"Bord2") + M.setGroupAtPlan(ysup,1,eps,"Bord3") + M.setGroupAtPlan(yinf,1,eps,"Bord4") + M.setGroupAtPlan(zsup,2,eps,"Bord5") + M.setGroupAtPlan(zinf,2,eps,"Bord6") + + print "Built a regular tetrahedra 3D mesh from a cube mesh with ", nx,"x" ,ny,"x" ,nz, " cells" + + FEComputation=True + myProblem = cf.StationaryDiffusionEquation(spaceDim,FEComputation); + myProblem.setMesh(M); + + # set the limit value for each boundary + T1=0; + T2=0; + T3=0; + T4=0; + T5=0; + T6=0; + + myProblem.setDirichletBoundaryCondition("Bord1",T1) + myProblem.setDirichletBoundaryCondition("Bord2",T2) + myProblem.setDirichletBoundaryCondition("Bord3",T3) + myProblem.setDirichletBoundaryCondition("Bord4",T4) + myProblem.setDirichletBoundaryCondition("Bord5",T5) + myProblem.setDirichletBoundaryCondition("Bord6",T6) + + #Set the right hand side function + my_RHSfield = cm.Field("RHS_field", cm.NODES, M, 1) + for i in range(M.getNumberOfNodes()): + Ni= M.getNode(i) + x = Ni.x() + y = Ni.y() + z = Ni.z() + + my_RHSfield[i]=2*pi*pi*sin(pi*x)*sin(pi*y)*sin(pi*z)#mettre la fonction definie au second membre de l'edp + + myProblem.setHeatPowerField(my_RHSfield) + myProblem.setLinearSolver(cf.GMRES,cf.ILU); + + # name of result file + fileName = "StationnaryDiffusion_3DEF_StructuredTriangles"; + + # computation parameters + myProblem.setFileName(fileName); + + # Run the computation + myProblem.initialize(); + print("Running python "+ fileName ); + + ok = myProblem.solveStationaryProblem(); + if (not ok): + print( "Python simulation of " + fileName + " failed ! " ); + pass + else: + ####################### Postprocessing ######################### + my_ResultField = myProblem.getOutputTemperatureField() + #The following formulas use the fact that the exact solution is equal the right hand side divided by 3*pi*pi + max_abs_sol_exacte=max(my_RHSfield.max(),-my_RHSfield.min())/(3*pi*pi) + max_sol_num=my_ResultField.max() + min_sol_num=my_ResultField.min() + erreur_abs=0 + for i in range(M.getNumberOfNodes()) : + if erreur_abs < abs(my_RHSfield[i]/(3*pi*pi) - my_ResultField[i]) : + erreur_abs = abs(my_RHSfield[i]/(3*pi*pi) - my_ResultField[i]) + + print("Absolute error = max(| exact solution - numerical solution |) = ",erreur_abs ) + print("Relative error = max(| exact solution - numerical solution |)/max(| exact solution |) = ",erreur_abs/max_abs_sol_exacte) + print ("Maximum numerical solution = ", max_sol_num, " Minimum numerical solution = ", min_sol_num) + + assert erreur_abs/max_abs_sol_exacte <1. + pass + + print( "------------ !!! End of calculation !!! -----------" ); + + myProblem.terminate(); + return ok + +if __name__ == """__main__""": + StationaryDiffusionEquation_3DEF_StructuredTriangles() diff --git a/CoreFlows/examples/Python/StationaryDiffusionEquation/StationaryDiffusionEquation_3DEF_RoomCooling.py b/CoreFlows/examples/Python/StationaryDiffusionEquation/StationaryDiffusionEquation_3DEF_RoomCooling.py new file mode 100755 index 0000000..a66d8cd --- /dev/null +++ b/CoreFlows/examples/Python/StationaryDiffusionEquation/StationaryDiffusionEquation_3DEF_RoomCooling.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python +# -*-coding:utf-8 -* +#=============================================================================================================================== +# Name : Résolution EF de l'équation de Laplace 3D -\Delta T = 0 avec conditions aux limites de Dirichlet u non nulle (fenetre et radiateur) +# Authors : Michaël Ndjinga, Sédrick Kameni Ngwamou +# Copyright : CEA Saclay 2019 +# Description : Utilisation de la méthode des éléménts finis P1 avec champs u discrétisés aux noeuds d'un maillage tétraédrique +# Condition limites correspondant au refroidissement dû à une fenêtre et au chauffage dû à un radiateur +# Création et sauvegarde du champ résultant ainsi que du champ second membre en utilisant la librairie CDMATH +#================================================================================================================================ + +import CoreFlows as cf +import cdmath + +def StationaryDiffusionEquation_3DEF_RoomCooling(): + spaceDim = 3; + + #Chargement du maillage tétraédrique du domaine + #============================================== + my_mesh = cdmath.Mesh("../resources/RoomWithTetras2488.med") + + print "Loaded unstructured 3D mesh" + + #Conditions limites + Tmur=20 + Tfenetre=0 + Tradiateur=40 + + FEComputation=True + myProblem = cf.StationaryDiffusionEquation(spaceDim,FEComputation); + myProblem.setMesh(my_mesh); + + myProblem.setDirichletBoundaryCondition("Fenetre",Tfenetre) + myProblem.setDirichletBoundaryCondition("Radiateur_sous_fenetre",Tradiateur) + myProblem.setDirichletBoundaryCondition("Radiateur_Devant",Tmur) + myProblem.setDirichletBoundaryCondition("Radiateur_droit",Tmur) + myProblem.setDirichletBoundaryCondition("Murs",Tmur) + + # name of result file + fileName = "StationnaryDiffusion_3DEF_UnstructuredTetrahedra"; + + # computation parameters + myProblem.setFileName(fileName); + + # Run the computation + myProblem.initialize(); + print("Running python "+ fileName ); + + ok = myProblem.solveStationaryProblem(); + if (not ok): + print( "Python simulation of " + fileName + " failed ! " ); + pass + else: + print( "Python simulation of " + fileName + " successful ! " ); + pass + + myProblem.terminate(); + return ok + +if __name__ == """__main__""": + StationaryDiffusionEquation_3DEF_RoomCooling() diff --git a/CoreFlows/examples/Python/StationaryDiffusionEquation/StationaryDiffusionEquation_3DFV_StructuredCubes.py b/CoreFlows/examples/Python/StationaryDiffusionEquation/StationaryDiffusionEquation_3DFV_StructuredCubes.py new file mode 100755 index 0000000..940d99f --- /dev/null +++ b/CoreFlows/examples/Python/StationaryDiffusionEquation/StationaryDiffusionEquation_3DFV_StructuredCubes.py @@ -0,0 +1,113 @@ +#!/usr/bin/env python +# -*-coding:utf-8 -* +#=============================================================================================================================== +# Name : Résolution VF de l'équation de Poisson 3D -\triangle T = f sur un cube avec conditions aux limites de Dirichlet T=0 +# Author : Michaël Ndjinga +# Copyright : CEA Saclay 2019 +# Description : Utilisation de la méthode des volumes finis avec champs T et f discrétisés aux cellules d'un maillage de cubes +# Création et sauvegarde du champ résultant ainsi que du champ second membre en utilisant CDMATH +# Comparaison de la solution numérique avec la solution exacte T=sin(pi*x)*sin(pi*y)*sin(pi*z) +#================================================================================================================================ + +import CoreFlows as cf +import cdmath as cm +from math import sin, pi + +def StationaryDiffusionEquation_3DFV_StructuredCubes(): + spaceDim = 3; + # Prepare for the mesh + print("Building mesh " ); + xinf = 0 ; + xsup = 1.0; + yinf = 0.0; + ysup = 1.0; + zinf = 0.0; + zsup = 1.0; + nx = 20; + ny = 20; + nz = 20; + M=cm.Mesh(xinf,xsup,nx,yinf,ysup,ny,zinf,zsup,nz)#Regular cube mesh + # set the limit field for each boundary + eps=1e-6; + M.setGroupAtPlan(xsup,0,eps,"Bord1") + M.setGroupAtPlan(xinf,0,eps,"Bord2") + M.setGroupAtPlan(ysup,1,eps,"Bord3") + M.setGroupAtPlan(yinf,1,eps,"Bord4") + M.setGroupAtPlan(zsup,2,eps,"Bord5") + M.setGroupAtPlan(zinf,2,eps,"Bord6") + + print "Built a regular 3D cube mesh with ", nx,"x" ,ny,"x" ,nz, " cells" + + FEComputation=False + myProblem = cf.StationaryDiffusionEquation(spaceDim,FEComputation); + myProblem.setMesh(M); + + # set the limit value for each boundary + T1=0; + T2=0; + T3=0; + T4=0; + T5=0; + T6=0; + + myProblem.setDirichletBoundaryCondition("Bord1",T1) + myProblem.setDirichletBoundaryCondition("Bord2",T2) + myProblem.setDirichletBoundaryCondition("Bord3",T3) + myProblem.setDirichletBoundaryCondition("Bord4",T4) + myProblem.setDirichletBoundaryCondition("Bord5",T5) + myProblem.setDirichletBoundaryCondition("Bord6",T6) + + #Set the right hand side function + my_RHSfield = cm.Field("RHS_field", cm.CELLS, M, 1) + for i in range(M.getNumberOfCells()): + Ci= M.getCell(i) + x = Ci.x() + y = Ci.y() + z = Ci.z() + + my_RHSfield[i]=2*pi*pi*sin(pi*x)*sin(pi*y)*sin(pi*z)#mettre la fonction definie au second membre de l'edp + + myProblem.setHeatPowerField(my_RHSfield) + myProblem.setLinearSolver(cf.GMRES,cf.ILU); + + # name of result file + fileName = "StationaryDiffusion_3DFV_StructuredCubes"; + + # computation parameters + myProblem.setFileName(fileName); + + # Run the computation + myProblem.initialize(); + print("Running python "+ fileName ); + + ok = myProblem.solveStationaryProblem(); + if (not ok): + print( "Python simulation of " + fileName + " failed ! " ); + pass + else: + print( "Python simulation of " + fileName + " is successful !" ); + ####################### Postprocessing ######################### + my_ResultField = myProblem.getOutputTemperatureField() + #The following formulas use the fact that the exact solution is equal the right hand side divided by 3*pi*pi + max_abs_sol_exacte=max(my_RHSfield.max(),-my_RHSfield.min())/(3*pi*pi) + max_sol_num=my_ResultField.max() + min_sol_num=my_ResultField.min() + erreur_abs=0 + for i in range(M.getNumberOfCells()) : + if erreur_abs < abs(my_RHSfield[i]/(3*pi*pi) - my_ResultField[i]) : + erreur_abs = abs(my_RHSfield[i]/(3*pi*pi) - my_ResultField[i]) + + print("Absolute error = max(| exact solution - numerical solution |) = ",erreur_abs ) + print("Relative error = max(| exact solution - numerical solution |)/max(| exact solution |) = ",erreur_abs/max_abs_sol_exacte) + print ("Maximum numerical solution = ", max_sol_num, " Minimum numerical solution = ", min_sol_num) + + assert erreur_abs/max_abs_sol_exacte <1. + pass + + print( "------------ !!! End of calculation !!! -----------" ); + + myProblem.terminate(); + return ok + +if __name__ == """__main__""": + StationaryDiffusionEquation_3DFV_StructuredCubes() diff --git a/CoreFlows/examples/Python/StationaryDiffusionEquation/StationaryDiffusionEquation_3DFV_StructuredTetrahedra.py b/CoreFlows/examples/Python/StationaryDiffusionEquation/StationaryDiffusionEquation_3DFV_StructuredTetrahedra.py new file mode 100755 index 0000000..9dba121 --- /dev/null +++ b/CoreFlows/examples/Python/StationaryDiffusionEquation/StationaryDiffusionEquation_3DFV_StructuredTetrahedra.py @@ -0,0 +1,113 @@ +#!/usr/bin/env python +# -*-coding:utf-8 -* +#=============================================================================================================================== +# Name : Résolution VF de l'équation de Poisson 3D -\triangle T = f sur un cube avec conditions aux limites de Dirichlet T=0 +# Author : Michaël Ndjinga +# Copyright : CEA Saclay 2019 +# Description : Utilisation de la méthode des volumes finis avec champs T et f discrétisés aux cellules d'un maillage tétraédrique +# Création et sauvegarde du champ résultant ainsi que du champ second membre en utilisant CDMATH +# Comparaison de la solution numérique avec la solution exacte T=sin(pi*x)*sin(pi*y)*sin(pi*z) +#================================================================================================================================ + +import CoreFlows as cf +import cdmath as cm +from math import sin, pi + +def StationaryDiffusionEquation_3DFV_StructuredTetrahedra(): + spaceDim = 3; + # Prepare for the mesh + print("Building mesh " ); + xinf = 0 ; + xsup = 1.0; + yinf = 0.0; + ysup = 1.0; + zinf = 0.0; + zsup = 1.0; + nx = 5; + ny = 5; + nz = 5; + M=cm.Mesh(xinf,xsup,nx,yinf,ysup,ny,zinf,zsup,nz,1)#Regular tetrahedral mesh + # set the limit field for each boundary + eps=1e-6; + M.setGroupAtPlan(xsup,0,eps,"Bord1") + M.setGroupAtPlan(xinf,0,eps,"Bord2") + M.setGroupAtPlan(ysup,1,eps,"Bord3") + M.setGroupAtPlan(yinf,1,eps,"Bord4") + M.setGroupAtPlan(zsup,2,eps,"Bord5") + M.setGroupAtPlan(zinf,2,eps,"Bord6") + + print "Built a regular 3D tetrahedral mesh from ", nx,"x" ,ny,"x" ,nz, " cubic cells" + + FEComputation=False + myProblem = cf.StationaryDiffusionEquation(spaceDim,FEComputation); + myProblem.setMesh(M); + + # set the limit value for each boundary + T1=0; + T2=0; + T3=0; + T4=0; + T5=0; + T6=0; + + myProblem.setDirichletBoundaryCondition("Bord1",T1) + myProblem.setDirichletBoundaryCondition("Bord2",T2) + myProblem.setDirichletBoundaryCondition("Bord3",T3) + myProblem.setDirichletBoundaryCondition("Bord4",T4) + myProblem.setDirichletBoundaryCondition("Bord5",T5) + myProblem.setDirichletBoundaryCondition("Bord6",T6) + + #Set the right hand side function + my_RHSfield = cm.Field("RHS_field", cm.CELLS, M, 1) + for i in range(M.getNumberOfCells()): + Ci= M.getCell(i) + x = Ci.x() + y = Ci.y() + z = Ci.z() + + my_RHSfield[i]=2*pi*pi*sin(pi*x)*sin(pi*y)*sin(pi*z)#mettre la fonction definie au second membre de l'edp + + myProblem.setHeatPowerField(my_RHSfield) + myProblem.setLinearSolver(cf.GMRES,cf.ILU); + + # name of result file + fileName = "StationaryDiffusion_3DFV_StructuredTetrahedra"; + + # computation parameters + myProblem.setFileName(fileName); + + # Run the computation + myProblem.initialize(); + print("Running python "+ fileName ); + + ok = myProblem.solveStationaryProblem(); + if (not ok): + print( "Python simulation of " + fileName + " failed ! " ); + pass + else: + print( "Python simulation of " + fileName + " is successful !" ); + ####################### Postprocessing ######################### + my_ResultField = myProblem.getOutputTemperatureField() + #The following formulas use the fact that the exact solution is equal the right hand side divided by 3*pi*pi + max_abs_sol_exacte=max(my_RHSfield.max(),-my_RHSfield.min())/(3*pi*pi) + max_sol_num=my_ResultField.max() + min_sol_num=my_ResultField.min() + erreur_abs=0 + for i in range(M.getNumberOfCells()) : + if erreur_abs < abs(my_RHSfield[i]/(3*pi*pi) - my_ResultField[i]) : + erreur_abs = abs(my_RHSfield[i]/(3*pi*pi) - my_ResultField[i]) + + print("Absolute error = max(| exact solution - numerical solution |) = ",erreur_abs ) + print("Relative error = max(| exact solution - numerical solution |)/max(| exact solution |) = ",erreur_abs/max_abs_sol_exacte) + print ("Maximum numerical solution = ", max_sol_num, " Minimum numerical solution = ", min_sol_num) + + assert erreur_abs/max_abs_sol_exacte <1. + pass + + print( "------------ !!! End of calculation !!! -----------" ); + + myProblem.terminate(); + return ok + +if __name__ == """__main__""": + StationaryDiffusionEquation_3DFV_StructuredTetrahedra() diff --git a/CoreFlows/examples/Python/StationaryDiffusionEquation/StationaryDiffusionEquation_3DVF_RoomCooling_StructuredCubes.py b/CoreFlows/examples/Python/StationaryDiffusionEquation/StationaryDiffusionEquation_3DVF_RoomCooling_StructuredCubes.py new file mode 100755 index 0000000..cc24432 --- /dev/null +++ b/CoreFlows/examples/Python/StationaryDiffusionEquation/StationaryDiffusionEquation_3DVF_RoomCooling_StructuredCubes.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python +# -*-coding:utf-8 -* +#=============================================================================================================================== +# Name : Résolution VF de l'équation de Laplace 3D -\Delta T = 0 avec conditions aux limites de Dirichlet u non nulle (fenetre et radiateur) +# Authors : Michaël Ndjinga, Sédrick Kameni Ngwamou +# Copyright : CEA Saclay 2019 +# Description : Utilisation de la méthode des volumes finis avec champs u discrétisés aux cellules d'un maillage de cubes +# Conditions limites correspondant au refroidissement dû à une fenêtre et au chauffage dû à un radiateur +# Création et sauvegarde du champ résultant ainsi que du champ second membre en utilisant la librairie CDMATH +#================================================================================================================================ + +import CoreFlows as cf +import cdmath + +def StationaryDiffusionEquation_3DVF_RoomCooling_StructuredCubes(): + spaceDim = 3; + + #Chargement du maillage cartésien du domaine + #============================================== + my_mesh = cdmath.Mesh("../resources/RoomWithCubes480.med") + + print "Loaded Structured 3D mesh" + + #Conditions limites + Tmur=20 + Tfenetre=0 + Tradiateur=40 + + FEComputation=False + myProblem = cf.StationaryDiffusionEquation(spaceDim,FEComputation); + myProblem.setMesh(my_mesh); + + myProblem.setDirichletBoundaryCondition("Fenetre",Tfenetre) + myProblem.setDirichletBoundaryCondition("Radiateur_sous_fenetre",Tradiateur) + myProblem.setDirichletBoundaryCondition("Radiateur_devant",Tmur) + myProblem.setDirichletBoundaryCondition("Radiateur_droite",Tmur) + myProblem.setDirichletBoundaryCondition("Mur",Tmur) + + # name of result file + fileName = "StationnaryDiffusion_3DVF_StructuredCubes"; + + # computation parameters + myProblem.setFileName(fileName); + + # Run the computation + myProblem.initialize(); + print("Running python "+ fileName ); + + ok = myProblem.solveStationaryProblem(); + if (not ok): + print( "Python simulation of " + fileName + " failed ! " ); + pass + else: + print( "Python simulation of " + fileName + " successful ! " ); + pass + + myProblem.terminate(); + return ok + +if __name__ == """__main__""": + StationaryDiffusionEquation_3DVF_RoomCooling_StructuredCubes() diff --git a/CoreFlows/examples/Python/StationaryDiffusionEquation/StationaryDiffusionEquation_3DVF_RoomCooling_UnstructuredTetras.py b/CoreFlows/examples/Python/StationaryDiffusionEquation/StationaryDiffusionEquation_3DVF_RoomCooling_UnstructuredTetras.py new file mode 100755 index 0000000..931bbeb --- /dev/null +++ b/CoreFlows/examples/Python/StationaryDiffusionEquation/StationaryDiffusionEquation_3DVF_RoomCooling_UnstructuredTetras.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python +# -*-coding:utf-8 -* +#=============================================================================================================================== +# Name : Résolution VF de l'équation de Laplace 3D -\Delta T = 0 avec conditions aux limites de Dirichlet u non nulle (fenetre et radiateur) +# Authors : Michaël Ndjinga, Sédrick Kameni Ngwamou +# Copyright : CEA Saclay 2019 +# Description : Utilisation de la méthode des volumes finis avec champs u discrétisés aux cellules d'un maillage de tétraèdres +# Conditions limites correspondant au refroidissement dû à une fenêtre et au chauffage dû à un radiateur +# Création et sauvegarde du champ résultant ainsi que du champ second membre en utilisant la librairie CDMATH +#================================================================================================================================ + +import CoreFlows as cf +import cdmath + +def StationaryDiffusionEquation_3DVF_RoomCooling_UnstructuredTetras(): + spaceDim = 3; + + #Chargement du maillage cartésien du domaine + #============================================== + my_mesh = cdmath.Mesh("../resources/RoomWithTetras2488.med") + + print "Loaded Structured 3D mesh" + + #Conditions limites + Tmur=20 + Tfenetre=0 + Tradiateur=40 + + FEComputation=False + myProblem = cf.StationaryDiffusionEquation(spaceDim,FEComputation); + myProblem.setMesh(my_mesh); + + myProblem.setDirichletBoundaryCondition("Fenetre",Tfenetre) + myProblem.setDirichletBoundaryCondition("Radiateur_sous_fenetre",Tradiateur) + myProblem.setDirichletBoundaryCondition("Radiateur_Devant",Tmur) + myProblem.setDirichletBoundaryCondition("Radiateur_droit",Tmur) + myProblem.setDirichletBoundaryCondition("Murs",Tmur) + + # name of result file + fileName = "StationnaryDiffusion_3DVF_UnstructuredTetras"; + + # computation parameters + myProblem.setFileName(fileName); + + # Run the computation + myProblem.initialize(); + print("Running python "+ fileName ); + + ok = myProblem.solveStationaryProblem(); + if (not ok): + print( "Python simulation of " + fileName + " failed ! " ); + pass + else: + print( "Python simulation of " + fileName + " successful ! " ); + pass + + myProblem.terminate(); + return ok + +if __name__ == """__main__""": + StationaryDiffusionEquation_3DVF_RoomCooling_UnstructuredTetras() diff --git a/CoreFlows/examples/Python/StationaryDiffusionEquation_2DEF.py b/CoreFlows/examples/Python/StationaryDiffusionEquation_2DEF.py deleted file mode 100755 index 17069e6..0000000 --- a/CoreFlows/examples/Python/StationaryDiffusionEquation_2DEF.py +++ /dev/null @@ -1,102 +0,0 @@ -#!/usr/bin/env python -# -*-coding:utf-8 -* -#=============================================================================================================================== -# Name : Résolution EF de l'équation de Poisson 2D -\triangle T = f avec conditions aux limites de Dirichlet T=0 -# Author : Michaël Ndjinga -# Copyright : CEA Saclay 2019 -# Description : Utilisation de la méthode des éléménts finis P1 avec champs T et f discrétisés aux noeuds d'un maillage triangulaire -# Création et sauvegarde du champ résultant ainsi que du champ second membre en utilisant la librairie CDMATH -# Comparaison de la solution numérique avec la solution exacte T=-sin(pi*x)*sin(pi*y) -#================================================================================================================================ - -import CoreFlows as cf -import cdmath as cm -from math import sin, pi - -def StationaryDiffusionEquation_2DEF_StructuredTriangles(): - spaceDim = 2; - # Prepare for the mesh - print("Building mesh " ); - xinf = 0 ; - xsup=1.0; - yinf=0.0; - ysup=1.0; - nx=20; - ny=20; - M=cm.Mesh(xinf,xsup,nx,yinf,ysup,ny,0)#Regular triangular mesh - # set the limit field for each boundary - eps=1e-6; - M.setGroupAtPlan(xsup,0,eps,"Bord1") - M.setGroupAtPlan(xinf,0,eps,"Bord2") - M.setGroupAtPlan(ysup,1,eps,"Bord3") - M.setGroupAtPlan(yinf,1,eps,"Bord4") - - print "Built a regular triangular 2D mesh from a square mesh with ", nx,"x" ,ny, " cells" - - FEComputation=True - myProblem = cf.StationaryDiffusionEquation(spaceDim,FEComputation); - myProblem.setMesh(M); - - # set the limit value for each boundary - T1=0; - T2=0; - T3=0; - T4=0; - - myProblem.setDirichletBoundaryCondition("Bord1",T1) - myProblem.setDirichletBoundaryCondition("Bord2",T2) - myProblem.setDirichletBoundaryCondition("Bord3",T3) - myProblem.setDirichletBoundaryCondition("Bord4",T4) - - #Set the right hand side function - my_RHSfield = cm.Field("RHS_field", cm.NODES, M, 1) - for i in range(M.getNumberOfNodes()): - Ni= M.getNode(i) - x = Ni.x() - y = Ni.y() - - my_RHSfield[i]=2*pi*pi*sin(pi*x)*sin(pi*y)#mettre la fonction definie au second membre de l'edp - - myProblem.setHeatPowerField(my_RHSfield) - myProblem.setLinearSolver(cf.GMRES,cf.ILU); - - # name of result file - fileName = "StationnaryDiffusion_2DEF_StructuredTriangles"; - - # computation parameters - myProblem.setFileName(fileName); - - # Run the computation - myProblem.initialize(); - print("Running python "+ fileName ); - - ok = myProblem.solveStationaryProblem(); - if (not ok): - print( "Python simulation of " + fileName + " failed ! " ); - pass - else: - ####################### Postprocessing ######################### - my_ResultField = myProblem.getOutputTemperatureField() - #The following formulas use the fact that the exact solution is equal the right hand side divided by 2*pi*pi - max_abs_sol_exacte=max(my_RHSfield.max(),-my_RHSfield.min())/(2*pi*pi) - max_sol_num=my_ResultField.max() - min_sol_num=my_ResultField.min() - erreur_abs=0 - for i in range(M.getNumberOfNodes()) : - if erreur_abs < abs(my_RHSfield[i]/(2*pi*pi) - my_ResultField[i]) : - erreur_abs = abs(my_RHSfield[i]/(2*pi*pi) - my_ResultField[i]) - - print("Absolute error = max(| exact solution - numerical solution |) = ",erreur_abs ) - print("Relative error = max(| exact solution - numerical solution |)/max(| exact solution |) = ",erreur_abs/max_abs_sol_exacte) - print ("Maximum numerical solution = ", max_sol_num, " Minimum numerical solution = ", min_sol_num) - - assert erreur_abs/max_abs_sol_exacte <1. - pass - - print( "------------ !!! End of calculation !!! -----------" ); - - myProblem.terminate(); - return ok - -if __name__ == """__main__""": - StationaryDiffusionEquation_2DEF_StructuredTriangles() diff --git a/CoreFlows/examples/Python/StationaryDiffusionEquation_2DEF_Neumann.py b/CoreFlows/examples/Python/StationaryDiffusionEquation_2DEF_Neumann.py deleted file mode 100755 index 74411a9..0000000 --- a/CoreFlows/examples/Python/StationaryDiffusionEquation_2DEF_Neumann.py +++ /dev/null @@ -1,97 +0,0 @@ -#!/usr/bin/env python -# -*-coding:utf-8 -* -#=============================================================================================================================== -# Name : Résolution EF de l'équation de Poisson 2D -\triangle T = f avec conditions aux limites de Neumann T=0 -# Author : Michaël Ndjinga -# Copyright : CEA Saclay 2019 -# Description : Utilisation de la méthode des éléménts finis P1 avec champs T et f discrétisés aux noeuds d'un maillage triangulaire -# Création et sauvegarde du champ résultant ainsi que du champ second membre en utilisant la librairie CDMATH -# Comparaison de la solution numérique avec la solution exacte T=-cos(pi*x)*cos(pi*y) -#================================================================================================================================ - -import CoreFlows as cf -import cdmath as cm -from math import cos, pi - -def StationaryDiffusionEquation_2DEF_StructuredTriangles_Neumann(): - spaceDim = 2; - # Prepare for the mesh - print("Building mesh " ); - xinf = 0.0; - xsup = 1.0; - yinf = 0.0; - ysup = 1.0; - nx=20; - ny=20; - M=cm.Mesh(xinf,xsup,nx,yinf,ysup,ny,0)#Regular triangular mesh - # set the limit field for each boundary - eps=1e-6; - M.setGroupAtPlan(xsup,0,eps,"Bord1") - M.setGroupAtPlan(xinf,0,eps,"Bord2") - M.setGroupAtPlan(ysup,1,eps,"Bord3") - M.setGroupAtPlan(yinf,1,eps,"Bord4") - - print "Built a regular triangular 2D mesh from a square mesh with ", nx,"x" ,ny, " cells" - - FEComputation=True - myProblem = cf.StationaryDiffusionEquation(spaceDim,FEComputation); - myProblem.setMesh(M); - - # set the boundary condition for each boundary - myProblem.setNeumannBoundaryCondition("Bord1") - myProblem.setNeumannBoundaryCondition("Bord2") - myProblem.setNeumannBoundaryCondition("Bord3") - myProblem.setNeumannBoundaryCondition("Bord4") - - #Set the right hand side function - my_RHSfield = cm.Field("RHS_field", cm.NODES, M, 1) - for i in range(M.getNumberOfNodes()): - Ni= M.getNode(i) - x = Ni.x() - y = Ni.y() - - my_RHSfield[i]=2*pi*pi*cos(pi*x)*cos(pi*y)#mettre la fonction definie au second membre de l'edp - - myProblem.setHeatPowerField(my_RHSfield) - myProblem.setLinearSolver(cf.GMRES,cf.ILU); - - # name of result file - fileName = "StationnaryDiffusion_2DEF_StructuredTriangles_Neumann"; - - # computation parameters - myProblem.setFileName(fileName); - - # Run the computation - myProblem.initialize(); - print("Running python "+ fileName ); - - ok = myProblem.solveStationaryProblem(); - if (not ok): - print( "Python simulation of " + fileName + " failed ! " ); - pass - else: - ####################### Postprocessing ######################### - my_ResultField = myProblem.getOutputTemperatureField() - #The following formulas use the fact that the exact solution is equal the right hand side divided by 2*pi*pi - max_abs_sol_exacte=max(my_RHSfield.max(),-my_RHSfield.min())/(2*pi*pi) - max_sol_num=my_ResultField.max() - min_sol_num=my_ResultField.min() - erreur_abs=0 - for i in range(M.getNumberOfNodes()) : - if erreur_abs < abs(my_RHSfield[i]/(2*pi*pi) - my_ResultField[i]) : - erreur_abs = abs(my_RHSfield[i]/(2*pi*pi) - my_ResultField[i]) - - print("Absolute error = max(| exact solution - numerical solution |) = ",erreur_abs ) - print("Relative error = max(| exact solution - numerical solution |)/max(| exact solution |) = ",erreur_abs/max_abs_sol_exacte) - print ("Maximum numerical solution = ", max_sol_num, " Minimum numerical solution = ", min_sol_num) - - assert erreur_abs/max_abs_sol_exacte <1. - pass - - print( "------------ !!! End of calculation !!! -----------" ); - - myProblem.terminate(); - return ok - -if __name__ == """__main__""": - StationaryDiffusionEquation_2DEF_StructuredTriangles_Neumann() diff --git a/CoreFlows/examples/Python/StationaryDiffusionEquation_2DFV_EquilateralTriangles.py b/CoreFlows/examples/Python/StationaryDiffusionEquation_2DFV_EquilateralTriangles.py deleted file mode 100755 index 2cc35c3..0000000 --- a/CoreFlows/examples/Python/StationaryDiffusionEquation_2DFV_EquilateralTriangles.py +++ /dev/null @@ -1,92 +0,0 @@ -#!/usr/bin/env python -# -*-coding:utf-8 -* -#=============================================================================================================================== -# Name : Résolution VF de l'équation de Poisson 2D -\triangle T = f sur un carré avec conditions aux limites de Dirichlet T=0 -# Author : Michaël Ndjinga -# Copyright : CEA Saclay 2019 -# Description : Utilisation de la méthode des volumes finis avec champs T et f discrétisés aux cellules d'un maillage de triangules équilatéraux -# Création et sauvegarde du champ résultant ainsi que du champ second membre en utilisant CDMATH -# Comparaison de la solution numérique avec la solution exacte T=sin(pi*x)*sin(pi*y) -#================================================================================================================================ - -import CoreFlows as cf -import cdmath as cm -from math import sin, pi -import os - -def StationaryDiffusionEquation_2DFV_EquilateralTriangles(): - spaceDim = 2; - # Prepare for the mesh - print("Loading mesh " ); - M=cm.Mesh(os.environ['CDMATH_INSTALL']+'/share/meshes/2DEquilateralTriangles/squareWithEquilateralTriangles20.med')#Equilateral triangular mesh - - print( "Loaded 2D equilateral triangle mesh with ", M.getNumberOfCells(), " cells") - - # set the limit field - boundaryFaces = M.getBoundaryFaceIds() - boundaryValues = {} - print("Setting Dirichlet boundary values") - for i in boundaryFaces : - Fi=M.getFace(i) - x=Fi.x() - y=Fi.y() - boundaryValues[i] = sin(pi*x)*sin(pi*y) - - FEComputation=False - myProblem = cf.StationaryDiffusionEquation(spaceDim,FEComputation); - myProblem.setMesh(M); - myProblem.setDirichletValues(cf.MapIntDouble(boundaryValues)) - - #Set the right hand side function - my_RHSfield = cm.Field("RHS_field", cm.CELLS, M, 1) - for i in range(M.getNumberOfCells()): - Ci= M.getCell(i) - x = Ci.x() - y = Ci.y() - - my_RHSfield[i]=2*pi*pi*sin(pi*x)*sin(pi*y)#mettre la fonction definie au second membre de l'edp - - myProblem.setHeatPowerField(my_RHSfield) - myProblem.setLinearSolver(cf.GMRES,cf.ILU); - - # name of result file - fileName = "StationnaryDiffusion_2DFV_StructuredTriangles"; - - # computation parameters - myProblem.setFileName(fileName); - - # Run the computation - myProblem.initialize(); - print("Running python "+ fileName ); - - ok = myProblem.solveStationaryProblem(); - if (not ok): - print( "Python simulation of " + fileName + " failed ! " ); - pass - else: - print( "Python simulation of " + fileName + " is successful !" ); - ####################### Postprocessing ######################### - my_ResultField = myProblem.getOutputTemperatureField() - #The following formulas use the fact that the exact solution is equal the right hand side divided by 2*pi*pi - max_abs_sol_exacte=max(my_RHSfield.max(),-my_RHSfield.min())/(2*pi*pi) - max_sol_num=my_ResultField.max() - min_sol_num=my_ResultField.min() - erreur_abs=0 - for i in range(M.getNumberOfCells()) : - if erreur_abs < abs(my_RHSfield[i]/(2*pi*pi) - my_ResultField[i]) : - erreur_abs = abs(my_RHSfield[i]/(2*pi*pi) - my_ResultField[i]) - - print("Absolute error = max(| exact solution - numerical solution |) = ",erreur_abs ) - print("Relative error = max(| exact solution - numerical solution |)/max(| exact solution |) = ",erreur_abs/max_abs_sol_exacte) - print ("Maximum numerical solution = ", max_sol_num, " Minimum numerical solution = ", min_sol_num) - - assert erreur_abs/max_abs_sol_exacte <1. - pass - - print( "------------ !!! End of calculation !!! -----------" ); - - myProblem.terminate(); - return ok - -if __name__ == """__main__""": - StationaryDiffusionEquation_2DFV_EquilateralTriangles() diff --git a/CoreFlows/examples/Python/StationaryDiffusionEquation_2DFV_StructuredSquares.py b/CoreFlows/examples/Python/StationaryDiffusionEquation_2DFV_StructuredSquares.py deleted file mode 100755 index d47ef43..0000000 --- a/CoreFlows/examples/Python/StationaryDiffusionEquation_2DFV_StructuredSquares.py +++ /dev/null @@ -1,103 +0,0 @@ -#!/usr/bin/env python -# -*-coding:utf-8 -* -#=============================================================================================================================== -# Name : Résolution VF de l'équation de Poisson 2D -\triangle T = f sur un carré avec conditions aux limites de Dirichlet T=0 -# Author : Michaël Ndjinga -# Copyright : CEA Saclay 2019 -# Description : Utilisation de la méthode des volumes finis avec champs T et f discrétisés aux cellules d'un maillage triangulaire -# Création et sauvegarde du champ résultant ainsi que du champ second membre en utilisant CDMATH -# Comparaison de la solution numérique avec la solution exacte T=sin(pi*x)*sin(pi*y) -#================================================================================================================================ - -import CoreFlows as cf -import cdmath as cm -from math import sin, pi - -def StationaryDiffusionEquation_2DFV_StructuredSquares(): - spaceDim = 2; - # Prepare for the mesh - print("Building mesh " ); - xinf = 0 ; - xsup=1.0; - yinf=0.0; - ysup=1.0; - nx=30; - ny=30; - M=cm.Mesh(xinf,xsup,nx,yinf,ysup,ny)#Regular square mesh - # set the limit field for each boundary - eps=1e-6; - M.setGroupAtPlan(xsup,0,eps,"Bord1") - M.setGroupAtPlan(xinf,0,eps,"Bord2") - M.setGroupAtPlan(ysup,1,eps,"Bord3") - M.setGroupAtPlan(yinf,1,eps,"Bord4") - - print "Built a regular 2D square mesh with ", nx,"x" ,ny, " cells" - - FEComputation=False - myProblem = cf.StationaryDiffusionEquation(spaceDim,FEComputation); - myProblem.setMesh(M); - - # set the limit value for each boundary - T1=0; - T2=0; - T3=0; - T4=0; - - myProblem.setDirichletBoundaryCondition("Bord1",T1) - myProblem.setDirichletBoundaryCondition("Bord2",T2) - myProblem.setDirichletBoundaryCondition("Bord3",T3) - myProblem.setDirichletBoundaryCondition("Bord4",T4) - - #Set the right hand side function - my_RHSfield = cm.Field("RHS_field", cm.CELLS, M, 1) - for i in range(M.getNumberOfCells()): - Ci= M.getCell(i) - x = Ci.x() - y = Ci.y() - - my_RHSfield[i]=2*pi*pi*sin(pi*x)*sin(pi*y)#mettre la fonction definie au second membre de l'edp - - myProblem.setHeatPowerField(my_RHSfield) - myProblem.setLinearSolver(cf.GMRES,cf.ILU); - - # name of result file - fileName = "StationnaryDiffusion_2DFV_StructuredSquares"; - - # computation parameters - myProblem.setFileName(fileName); - - # Run the computation - myProblem.initialize(); - print("Running python "+ fileName ); - - ok = myProblem.solveStationaryProblem(); - if (not ok): - print( "Python simulation of " + fileName + " failed ! " ); - pass - else: - print( "Python simulation of " + fileName + " is successful !" ); - ####################### Postprocessing ######################### - my_ResultField = myProblem.getOutputTemperatureField() - #The following formulas use the fact that the exact solution is equal the right hand side divided by 2*pi*pi - max_abs_sol_exacte=max(my_RHSfield.max(),-my_RHSfield.min())/(2*pi*pi) - max_sol_num=my_ResultField.max() - min_sol_num=my_ResultField.min() - erreur_abs=0 - for i in range(M.getNumberOfCells()) : - if erreur_abs < abs(my_RHSfield[i]/(2*pi*pi) - my_ResultField[i]) : - erreur_abs = abs(my_RHSfield[i]/(2*pi*pi) - my_ResultField[i]) - - print("Absolute error = max(| exact solution - numerical solution |) = ",erreur_abs ) - print("Relative error = max(| exact solution - numerical solution |)/max(| exact solution |) = ",erreur_abs/max_abs_sol_exacte) - print ("Maximum numerical solution = ", max_sol_num, " Minimum numerical solution = ", min_sol_num) - - assert erreur_abs/max_abs_sol_exacte <1. - pass - - print( "------------ !!! End of calculation !!! -----------" ); - - myProblem.terminate(); - return ok - -if __name__ == """__main__""": - StationaryDiffusionEquation_2DFV_StructuredSquares() diff --git a/CoreFlows/examples/Python/StationaryDiffusionEquation_2DFV_StructuredSquares_Neumann.py b/CoreFlows/examples/Python/StationaryDiffusionEquation_2DFV_StructuredSquares_Neumann.py deleted file mode 100755 index 041a082..0000000 --- a/CoreFlows/examples/Python/StationaryDiffusionEquation_2DFV_StructuredSquares_Neumann.py +++ /dev/null @@ -1,103 +0,0 @@ -#!/usr/bin/env python -# -*-coding:utf-8 -* -#=============================================================================================================================== -# Name : Résolution VF de l'équation de Poisson 2D -\triangle T = f sur un carré avec conditions aux limites de Neumann T=0 -# Author : Michaël Ndjinga -# Copyright : CEA Saclay 2019 -# Description : Utilisation de la méthode des volumes finis avec champs T et f discrétisés aux cellules d'un maillage triangulaire -# Création et sauvegarde du champ résultant ainsi que du champ second membre en utilisant CDMATH -# Comparaison de la solution numérique avec la solution exacte T=cos(pi*x)*cos(pi*y) -#================================================================================================================================ - -import CoreFlows as cf -import cdmath as cm -from math import cos, pi - -def StationaryDiffusionEquation_2DFV_StructuredSquares_Neumann(): - spaceDim = 2; - # Prepare for the mesh - print("Building mesh " ); - xinf = 0.0; - xsup = 1.0; - yinf = 0.0; - ysup = 1.0; - nx=30; - ny=30; - M=cm.Mesh(xinf,xsup,nx,yinf,ysup,ny)#Regular square mesh - # set the limit field for each boundary - eps=1e-6; - M.setGroupAtPlan(xsup,0,eps,"Bord1") - M.setGroupAtPlan(xinf,0,eps,"Bord2") - M.setGroupAtPlan(ysup,1,eps,"Bord3") - M.setGroupAtPlan(yinf,1,eps,"Bord4") - - print "Built a regular 2D square mesh with ", nx,"x" ,ny, " cells" - - FEComputation=False - myProblem = cf.StationaryDiffusionEquation(spaceDim,FEComputation); - myProblem.setMesh(M); - - # set the limit value for each boundary - T1=0; - T2=0; - T3=0; - T4=0; - - myProblem.setNeumannBoundaryCondition("Bord1") - myProblem.setNeumannBoundaryCondition("Bord2") - myProblem.setNeumannBoundaryCondition("Bord3") - myProblem.setNeumannBoundaryCondition("Bord4") - - #Set the right hand side function - my_RHSfield = cm.Field("RHS_field", cm.CELLS, M, 1) - for i in range(M.getNumberOfCells()): - Ci= M.getCell(i) - x = Ci.x() - y = Ci.y() - - my_RHSfield[i]=2*pi*pi*cos(pi*x)*cos(pi*y)#mettre la fonction definie au second membre de l'edp - - myProblem.setHeatPowerField(my_RHSfield) - myProblem.setLinearSolver(cf.GMRES,cf.ILU); - - # name of result file - fileName = "StationnaryDiffusion_2DFV_StructuredSquares_Neumann"; - - # computation parameters - myProblem.setFileName(fileName); - - # Run the computation - myProblem.initialize(); - print("Running python "+ fileName ); - - ok = myProblem.solveStationaryProblem(); - if (not ok): - print( "Python simulation of " + fileName + " failed ! " ); - pass - else: - print( "Python simulation of " + fileName + " is successful !" ); - ####################### Postprocessing ######################### - my_ResultField = myProblem.getOutputTemperatureField() - #The following formulas use the fact that the exact solution is equal the right hand side divided by 2*pi*pi - max_abs_sol_exacte=max(my_RHSfield.max(),-my_RHSfield.min())/(2*pi*pi) - max_sol_num=my_ResultField.max() - min_sol_num=my_ResultField.min() - erreur_abs=0 - for i in range(M.getNumberOfCells()) : - if erreur_abs < abs(my_RHSfield[i]/(2*pi*pi) - my_ResultField[i]) : - erreur_abs = abs(my_RHSfield[i]/(2*pi*pi) - my_ResultField[i]) - - print("Absolute error = max(| exact solution - numerical solution |) = ",erreur_abs ) - print("Relative error = max(| exact solution - numerical solution |)/max(| exact solution |) = ",erreur_abs/max_abs_sol_exacte) - print ("Maximum numerical solution = ", max_sol_num, " Minimum numerical solution = ", min_sol_num) - - assert erreur_abs/max_abs_sol_exacte <1. - pass - - print( "------------ !!! End of calculation !!! -----------" ); - - myProblem.terminate(); - return ok - -if __name__ == """__main__""": - StationaryDiffusionEquation_2DFV_StructuredSquares_Neumann() diff --git a/CoreFlows/examples/Python/StationaryDiffusionEquation_2DFV_StructuredTriangles.py b/CoreFlows/examples/Python/StationaryDiffusionEquation_2DFV_StructuredTriangles.py deleted file mode 100755 index 8aef892..0000000 --- a/CoreFlows/examples/Python/StationaryDiffusionEquation_2DFV_StructuredTriangles.py +++ /dev/null @@ -1,103 +0,0 @@ -#!/usr/bin/env python -# -*-coding:utf-8 -* -#=============================================================================================================================== -# Name : Résolution VF de l'équation de Poisson 2D -\triangle T = f sur un carré avec conditions aux limites de Dirichlet T=0 -# Author : Michaël Ndjinga -# Copyright : CEA Saclay 2019 -# Description : Utilisation de la méthode des volumes finis avec champs T et f discrétisés aux cellules d'un maillage triangulaire -# Création et sauvegarde du champ résultant ainsi que du champ second membre en utilisant CDMATH -# Comparaison de la solution numérique avec la solution exacte T=sin(pi*x)*sin(pi*y) -#================================================================================================================================ - -import CoreFlows as cf -import cdmath as cm -from math import sin, pi - -def StationaryDiffusionEquation_2DFV_StructuredTriangles(): - spaceDim = 2; - # Prepare for the mesh - print("Building mesh " ); - xinf = 0 ; - xsup=1.0; - yinf=0.0; - ysup=1.0; - nx=20; - ny=20; - M=cm.Mesh(xinf,xsup,nx,yinf,ysup,ny,0)#Regular triangular mesh - # set the limit field for each boundary - eps=1e-6; - M.setGroupAtPlan(xsup,0,eps,"Bord1") - M.setGroupAtPlan(xinf,0,eps,"Bord2") - M.setGroupAtPlan(ysup,1,eps,"Bord3") - M.setGroupAtPlan(yinf,1,eps,"Bord4") - - print "Built a regular triangular 2D mesh from a square mesh with ", nx,"x" ,ny, " cells" - - FEComputation=False - myProblem = cf.StationaryDiffusionEquation(spaceDim,FEComputation); - myProblem.setMesh(M); - - # set the limit value for each boundary - T1=0; - T2=0; - T3=0; - T4=0; - - myProblem.setDirichletBoundaryCondition("Bord1",T1) - myProblem.setDirichletBoundaryCondition("Bord2",T2) - myProblem.setDirichletBoundaryCondition("Bord3",T3) - myProblem.setDirichletBoundaryCondition("Bord4",T4) - - #Set the right hand side function - my_RHSfield = cm.Field("RHS_field", cm.CELLS, M, 1) - for i in range(M.getNumberOfCells()): - Ci= M.getCell(i) - x = Ci.x() - y = Ci.y() - - my_RHSfield[i]=2*pi*pi*sin(pi*x)*sin(pi*y)#mettre la fonction definie au second membre de l'edp - - myProblem.setHeatPowerField(my_RHSfield) - myProblem.setLinearSolver(cf.GMRES,cf.ILU); - - # name of result file - fileName = "StationnaryDiffusion_2DFV_StructuredTriangles"; - - # computation parameters - myProblem.setFileName(fileName); - - # Run the computation - myProblem.initialize(); - print("Running python "+ fileName ); - - ok = myProblem.solveStationaryProblem(); - if (not ok): - print( "Python simulation of " + fileName + " failed ! " ); - pass - else: - print( "Python simulation of " + fileName + " is successful !" ); - ####################### Postprocessing ######################### - my_ResultField = myProblem.getOutputTemperatureField() - #The following formulas use the fact that the exact solution is equal the right hand side divided by 2*pi*pi - max_abs_sol_exacte=max(my_RHSfield.max(),-my_RHSfield.min())/(2*pi*pi) - max_sol_num=my_ResultField.max() - min_sol_num=my_ResultField.min() - erreur_abs=0 - for i in range(M.getNumberOfCells()) : - if erreur_abs < abs(my_RHSfield[i]/(2*pi*pi) - my_ResultField[i]) : - erreur_abs = abs(my_RHSfield[i]/(2*pi*pi) - my_ResultField[i]) - - print("Absolute error = max(| exact solution - numerical solution |) = ",erreur_abs ) - print("Relative error = max(| exact solution - numerical solution |)/max(| exact solution |) = ",erreur_abs/max_abs_sol_exacte) - print ("Maximum numerical solution = ", max_sol_num, " Minimum numerical solution = ", min_sol_num) - - assert erreur_abs/max_abs_sol_exacte <1. - pass - - print( "------------ !!! End of calculation !!! -----------" ); - - myProblem.terminate(); - return ok - -if __name__ == """__main__""": - StationaryDiffusionEquation_2DFV_StructuredTriangles() diff --git a/CoreFlows/examples/Python/StationaryDiffusionEquation_3DEF.py b/CoreFlows/examples/Python/StationaryDiffusionEquation_3DEF.py deleted file mode 100755 index 59fc326..0000000 --- a/CoreFlows/examples/Python/StationaryDiffusionEquation_3DEF.py +++ /dev/null @@ -1,112 +0,0 @@ -#!/usr/bin/env python -# -*-coding:utf-8 -* -#=============================================================================================================================== -# Name : Résolution EF de l'équation de Poisson 3D -\triangle T = f avec conditions aux limites de Dirichlet T=0 -# Author : Michaël Ndjinga -# Copyright : CEA Saclay 2019 -# Description : Utilisation de la méthode des éléménts finis P1 avec champs T et f discrétisés aux noeuds d'un maillage tétraédrique -# Création et sauvegarde du champ résultant ainsi que du champ second membre en utilisant la librairie CDMATH -# Comparaison de la solution numérique avec la solution exacte T=-sin(pi*x)*sin(pi*y)*sin(pi*z) -#================================================================================================================================ - -import CoreFlows as cf -import cdmath as cm -from math import sin, pi - -def StationaryDiffusionEquation_3DEF_StructuredTriangles(): - spaceDim = 3; - # Prepare for the mesh - print("Building mesh " ); - xinf = 0.0; - xsup = 1.0; - yinf = 0.0; - ysup = 1.0; - zinf = 0.0; - zsup = 1.0; - nx = 5; - ny = 5; - nz = 5; - M=cm.Mesh(xinf,xsup,nx,yinf,ysup,ny,zinf,zsup,nz,1)#Regular tetrahedral mesh - # set the limit field for each boundary - eps=1e-6; - M.setGroupAtPlan(xsup,0,eps,"Bord1") - M.setGroupAtPlan(xinf,0,eps,"Bord2") - M.setGroupAtPlan(ysup,1,eps,"Bord3") - M.setGroupAtPlan(yinf,1,eps,"Bord4") - M.setGroupAtPlan(zsup,2,eps,"Bord5") - M.setGroupAtPlan(zinf,2,eps,"Bord6") - - print "Built a regular tetrahedra 3D mesh from a cube mesh with ", nx,"x" ,ny,"x" ,nz, " cells" - - FEComputation=True - myProblem = cf.StationaryDiffusionEquation(spaceDim,FEComputation); - myProblem.setMesh(M); - - # set the limit value for each boundary - T1=0; - T2=0; - T3=0; - T4=0; - T5=0; - T6=0; - - myProblem.setDirichletBoundaryCondition("Bord1",T1) - myProblem.setDirichletBoundaryCondition("Bord2",T2) - myProblem.setDirichletBoundaryCondition("Bord3",T3) - myProblem.setDirichletBoundaryCondition("Bord4",T4) - myProblem.setDirichletBoundaryCondition("Bord5",T5) - myProblem.setDirichletBoundaryCondition("Bord6",T6) - - #Set the right hand side function - my_RHSfield = cm.Field("RHS_field", cm.NODES, M, 1) - for i in range(M.getNumberOfNodes()): - Ni= M.getNode(i) - x = Ni.x() - y = Ni.y() - z = Ni.z() - - my_RHSfield[i]=2*pi*pi*sin(pi*x)*sin(pi*y)*sin(pi*z)#mettre la fonction definie au second membre de l'edp - - myProblem.setHeatPowerField(my_RHSfield) - myProblem.setLinearSolver(cf.GMRES,cf.ILU); - - # name of result file - fileName = "StationnaryDiffusion_3DEF_StructuredTriangles"; - - # computation parameters - myProblem.setFileName(fileName); - - # Run the computation - myProblem.initialize(); - print("Running python "+ fileName ); - - ok = myProblem.solveStationaryProblem(); - if (not ok): - print( "Python simulation of " + fileName + " failed ! " ); - pass - else: - ####################### Postprocessing ######################### - my_ResultField = myProblem.getOutputTemperatureField() - #The following formulas use the fact that the exact solution is equal the right hand side divided by 3*pi*pi - max_abs_sol_exacte=max(my_RHSfield.max(),-my_RHSfield.min())/(3*pi*pi) - max_sol_num=my_ResultField.max() - min_sol_num=my_ResultField.min() - erreur_abs=0 - for i in range(M.getNumberOfNodes()) : - if erreur_abs < abs(my_RHSfield[i]/(3*pi*pi) - my_ResultField[i]) : - erreur_abs = abs(my_RHSfield[i]/(3*pi*pi) - my_ResultField[i]) - - print("Absolute error = max(| exact solution - numerical solution |) = ",erreur_abs ) - print("Relative error = max(| exact solution - numerical solution |)/max(| exact solution |) = ",erreur_abs/max_abs_sol_exacte) - print ("Maximum numerical solution = ", max_sol_num, " Minimum numerical solution = ", min_sol_num) - - assert erreur_abs/max_abs_sol_exacte <1. - pass - - print( "------------ !!! End of calculation !!! -----------" ); - - myProblem.terminate(); - return ok - -if __name__ == """__main__""": - StationaryDiffusionEquation_3DEF_StructuredTriangles() diff --git a/CoreFlows/examples/Python/StationaryDiffusionEquation_3DEF_RoomCooling.py b/CoreFlows/examples/Python/StationaryDiffusionEquation_3DEF_RoomCooling.py deleted file mode 100755 index a66d8cd..0000000 --- a/CoreFlows/examples/Python/StationaryDiffusionEquation_3DEF_RoomCooling.py +++ /dev/null @@ -1,61 +0,0 @@ -#!/usr/bin/env python -# -*-coding:utf-8 -* -#=============================================================================================================================== -# Name : Résolution EF de l'équation de Laplace 3D -\Delta T = 0 avec conditions aux limites de Dirichlet u non nulle (fenetre et radiateur) -# Authors : Michaël Ndjinga, Sédrick Kameni Ngwamou -# Copyright : CEA Saclay 2019 -# Description : Utilisation de la méthode des éléménts finis P1 avec champs u discrétisés aux noeuds d'un maillage tétraédrique -# Condition limites correspondant au refroidissement dû à une fenêtre et au chauffage dû à un radiateur -# Création et sauvegarde du champ résultant ainsi que du champ second membre en utilisant la librairie CDMATH -#================================================================================================================================ - -import CoreFlows as cf -import cdmath - -def StationaryDiffusionEquation_3DEF_RoomCooling(): - spaceDim = 3; - - #Chargement du maillage tétraédrique du domaine - #============================================== - my_mesh = cdmath.Mesh("../resources/RoomWithTetras2488.med") - - print "Loaded unstructured 3D mesh" - - #Conditions limites - Tmur=20 - Tfenetre=0 - Tradiateur=40 - - FEComputation=True - myProblem = cf.StationaryDiffusionEquation(spaceDim,FEComputation); - myProblem.setMesh(my_mesh); - - myProblem.setDirichletBoundaryCondition("Fenetre",Tfenetre) - myProblem.setDirichletBoundaryCondition("Radiateur_sous_fenetre",Tradiateur) - myProblem.setDirichletBoundaryCondition("Radiateur_Devant",Tmur) - myProblem.setDirichletBoundaryCondition("Radiateur_droit",Tmur) - myProblem.setDirichletBoundaryCondition("Murs",Tmur) - - # name of result file - fileName = "StationnaryDiffusion_3DEF_UnstructuredTetrahedra"; - - # computation parameters - myProblem.setFileName(fileName); - - # Run the computation - myProblem.initialize(); - print("Running python "+ fileName ); - - ok = myProblem.solveStationaryProblem(); - if (not ok): - print( "Python simulation of " + fileName + " failed ! " ); - pass - else: - print( "Python simulation of " + fileName + " successful ! " ); - pass - - myProblem.terminate(); - return ok - -if __name__ == """__main__""": - StationaryDiffusionEquation_3DEF_RoomCooling() diff --git a/CoreFlows/examples/Python/StationaryDiffusionEquation_3DFV_StructuredCubes.py b/CoreFlows/examples/Python/StationaryDiffusionEquation_3DFV_StructuredCubes.py deleted file mode 100755 index 940d99f..0000000 --- a/CoreFlows/examples/Python/StationaryDiffusionEquation_3DFV_StructuredCubes.py +++ /dev/null @@ -1,113 +0,0 @@ -#!/usr/bin/env python -# -*-coding:utf-8 -* -#=============================================================================================================================== -# Name : Résolution VF de l'équation de Poisson 3D -\triangle T = f sur un cube avec conditions aux limites de Dirichlet T=0 -# Author : Michaël Ndjinga -# Copyright : CEA Saclay 2019 -# Description : Utilisation de la méthode des volumes finis avec champs T et f discrétisés aux cellules d'un maillage de cubes -# Création et sauvegarde du champ résultant ainsi que du champ second membre en utilisant CDMATH -# Comparaison de la solution numérique avec la solution exacte T=sin(pi*x)*sin(pi*y)*sin(pi*z) -#================================================================================================================================ - -import CoreFlows as cf -import cdmath as cm -from math import sin, pi - -def StationaryDiffusionEquation_3DFV_StructuredCubes(): - spaceDim = 3; - # Prepare for the mesh - print("Building mesh " ); - xinf = 0 ; - xsup = 1.0; - yinf = 0.0; - ysup = 1.0; - zinf = 0.0; - zsup = 1.0; - nx = 20; - ny = 20; - nz = 20; - M=cm.Mesh(xinf,xsup,nx,yinf,ysup,ny,zinf,zsup,nz)#Regular cube mesh - # set the limit field for each boundary - eps=1e-6; - M.setGroupAtPlan(xsup,0,eps,"Bord1") - M.setGroupAtPlan(xinf,0,eps,"Bord2") - M.setGroupAtPlan(ysup,1,eps,"Bord3") - M.setGroupAtPlan(yinf,1,eps,"Bord4") - M.setGroupAtPlan(zsup,2,eps,"Bord5") - M.setGroupAtPlan(zinf,2,eps,"Bord6") - - print "Built a regular 3D cube mesh with ", nx,"x" ,ny,"x" ,nz, " cells" - - FEComputation=False - myProblem = cf.StationaryDiffusionEquation(spaceDim,FEComputation); - myProblem.setMesh(M); - - # set the limit value for each boundary - T1=0; - T2=0; - T3=0; - T4=0; - T5=0; - T6=0; - - myProblem.setDirichletBoundaryCondition("Bord1",T1) - myProblem.setDirichletBoundaryCondition("Bord2",T2) - myProblem.setDirichletBoundaryCondition("Bord3",T3) - myProblem.setDirichletBoundaryCondition("Bord4",T4) - myProblem.setDirichletBoundaryCondition("Bord5",T5) - myProblem.setDirichletBoundaryCondition("Bord6",T6) - - #Set the right hand side function - my_RHSfield = cm.Field("RHS_field", cm.CELLS, M, 1) - for i in range(M.getNumberOfCells()): - Ci= M.getCell(i) - x = Ci.x() - y = Ci.y() - z = Ci.z() - - my_RHSfield[i]=2*pi*pi*sin(pi*x)*sin(pi*y)*sin(pi*z)#mettre la fonction definie au second membre de l'edp - - myProblem.setHeatPowerField(my_RHSfield) - myProblem.setLinearSolver(cf.GMRES,cf.ILU); - - # name of result file - fileName = "StationaryDiffusion_3DFV_StructuredCubes"; - - # computation parameters - myProblem.setFileName(fileName); - - # Run the computation - myProblem.initialize(); - print("Running python "+ fileName ); - - ok = myProblem.solveStationaryProblem(); - if (not ok): - print( "Python simulation of " + fileName + " failed ! " ); - pass - else: - print( "Python simulation of " + fileName + " is successful !" ); - ####################### Postprocessing ######################### - my_ResultField = myProblem.getOutputTemperatureField() - #The following formulas use the fact that the exact solution is equal the right hand side divided by 3*pi*pi - max_abs_sol_exacte=max(my_RHSfield.max(),-my_RHSfield.min())/(3*pi*pi) - max_sol_num=my_ResultField.max() - min_sol_num=my_ResultField.min() - erreur_abs=0 - for i in range(M.getNumberOfCells()) : - if erreur_abs < abs(my_RHSfield[i]/(3*pi*pi) - my_ResultField[i]) : - erreur_abs = abs(my_RHSfield[i]/(3*pi*pi) - my_ResultField[i]) - - print("Absolute error = max(| exact solution - numerical solution |) = ",erreur_abs ) - print("Relative error = max(| exact solution - numerical solution |)/max(| exact solution |) = ",erreur_abs/max_abs_sol_exacte) - print ("Maximum numerical solution = ", max_sol_num, " Minimum numerical solution = ", min_sol_num) - - assert erreur_abs/max_abs_sol_exacte <1. - pass - - print( "------------ !!! End of calculation !!! -----------" ); - - myProblem.terminate(); - return ok - -if __name__ == """__main__""": - StationaryDiffusionEquation_3DFV_StructuredCubes() diff --git a/CoreFlows/examples/Python/StationaryDiffusionEquation_3DFV_StructuredTetrahedra.py b/CoreFlows/examples/Python/StationaryDiffusionEquation_3DFV_StructuredTetrahedra.py deleted file mode 100755 index 9dba121..0000000 --- a/CoreFlows/examples/Python/StationaryDiffusionEquation_3DFV_StructuredTetrahedra.py +++ /dev/null @@ -1,113 +0,0 @@ -#!/usr/bin/env python -# -*-coding:utf-8 -* -#=============================================================================================================================== -# Name : Résolution VF de l'équation de Poisson 3D -\triangle T = f sur un cube avec conditions aux limites de Dirichlet T=0 -# Author : Michaël Ndjinga -# Copyright : CEA Saclay 2019 -# Description : Utilisation de la méthode des volumes finis avec champs T et f discrétisés aux cellules d'un maillage tétraédrique -# Création et sauvegarde du champ résultant ainsi que du champ second membre en utilisant CDMATH -# Comparaison de la solution numérique avec la solution exacte T=sin(pi*x)*sin(pi*y)*sin(pi*z) -#================================================================================================================================ - -import CoreFlows as cf -import cdmath as cm -from math import sin, pi - -def StationaryDiffusionEquation_3DFV_StructuredTetrahedra(): - spaceDim = 3; - # Prepare for the mesh - print("Building mesh " ); - xinf = 0 ; - xsup = 1.0; - yinf = 0.0; - ysup = 1.0; - zinf = 0.0; - zsup = 1.0; - nx = 5; - ny = 5; - nz = 5; - M=cm.Mesh(xinf,xsup,nx,yinf,ysup,ny,zinf,zsup,nz,1)#Regular tetrahedral mesh - # set the limit field for each boundary - eps=1e-6; - M.setGroupAtPlan(xsup,0,eps,"Bord1") - M.setGroupAtPlan(xinf,0,eps,"Bord2") - M.setGroupAtPlan(ysup,1,eps,"Bord3") - M.setGroupAtPlan(yinf,1,eps,"Bord4") - M.setGroupAtPlan(zsup,2,eps,"Bord5") - M.setGroupAtPlan(zinf,2,eps,"Bord6") - - print "Built a regular 3D tetrahedral mesh from ", nx,"x" ,ny,"x" ,nz, " cubic cells" - - FEComputation=False - myProblem = cf.StationaryDiffusionEquation(spaceDim,FEComputation); - myProblem.setMesh(M); - - # set the limit value for each boundary - T1=0; - T2=0; - T3=0; - T4=0; - T5=0; - T6=0; - - myProblem.setDirichletBoundaryCondition("Bord1",T1) - myProblem.setDirichletBoundaryCondition("Bord2",T2) - myProblem.setDirichletBoundaryCondition("Bord3",T3) - myProblem.setDirichletBoundaryCondition("Bord4",T4) - myProblem.setDirichletBoundaryCondition("Bord5",T5) - myProblem.setDirichletBoundaryCondition("Bord6",T6) - - #Set the right hand side function - my_RHSfield = cm.Field("RHS_field", cm.CELLS, M, 1) - for i in range(M.getNumberOfCells()): - Ci= M.getCell(i) - x = Ci.x() - y = Ci.y() - z = Ci.z() - - my_RHSfield[i]=2*pi*pi*sin(pi*x)*sin(pi*y)*sin(pi*z)#mettre la fonction definie au second membre de l'edp - - myProblem.setHeatPowerField(my_RHSfield) - myProblem.setLinearSolver(cf.GMRES,cf.ILU); - - # name of result file - fileName = "StationaryDiffusion_3DFV_StructuredTetrahedra"; - - # computation parameters - myProblem.setFileName(fileName); - - # Run the computation - myProblem.initialize(); - print("Running python "+ fileName ); - - ok = myProblem.solveStationaryProblem(); - if (not ok): - print( "Python simulation of " + fileName + " failed ! " ); - pass - else: - print( "Python simulation of " + fileName + " is successful !" ); - ####################### Postprocessing ######################### - my_ResultField = myProblem.getOutputTemperatureField() - #The following formulas use the fact that the exact solution is equal the right hand side divided by 3*pi*pi - max_abs_sol_exacte=max(my_RHSfield.max(),-my_RHSfield.min())/(3*pi*pi) - max_sol_num=my_ResultField.max() - min_sol_num=my_ResultField.min() - erreur_abs=0 - for i in range(M.getNumberOfCells()) : - if erreur_abs < abs(my_RHSfield[i]/(3*pi*pi) - my_ResultField[i]) : - erreur_abs = abs(my_RHSfield[i]/(3*pi*pi) - my_ResultField[i]) - - print("Absolute error = max(| exact solution - numerical solution |) = ",erreur_abs ) - print("Relative error = max(| exact solution - numerical solution |)/max(| exact solution |) = ",erreur_abs/max_abs_sol_exacte) - print ("Maximum numerical solution = ", max_sol_num, " Minimum numerical solution = ", min_sol_num) - - assert erreur_abs/max_abs_sol_exacte <1. - pass - - print( "------------ !!! End of calculation !!! -----------" ); - - myProblem.terminate(); - return ok - -if __name__ == """__main__""": - StationaryDiffusionEquation_3DFV_StructuredTetrahedra() diff --git a/CoreFlows/examples/Python/StationaryDiffusionEquation_3DVF_RoomCooling_StructuredCubes.py b/CoreFlows/examples/Python/StationaryDiffusionEquation_3DVF_RoomCooling_StructuredCubes.py deleted file mode 100755 index cc24432..0000000 --- a/CoreFlows/examples/Python/StationaryDiffusionEquation_3DVF_RoomCooling_StructuredCubes.py +++ /dev/null @@ -1,61 +0,0 @@ -#!/usr/bin/env python -# -*-coding:utf-8 -* -#=============================================================================================================================== -# Name : Résolution VF de l'équation de Laplace 3D -\Delta T = 0 avec conditions aux limites de Dirichlet u non nulle (fenetre et radiateur) -# Authors : Michaël Ndjinga, Sédrick Kameni Ngwamou -# Copyright : CEA Saclay 2019 -# Description : Utilisation de la méthode des volumes finis avec champs u discrétisés aux cellules d'un maillage de cubes -# Conditions limites correspondant au refroidissement dû à une fenêtre et au chauffage dû à un radiateur -# Création et sauvegarde du champ résultant ainsi que du champ second membre en utilisant la librairie CDMATH -#================================================================================================================================ - -import CoreFlows as cf -import cdmath - -def StationaryDiffusionEquation_3DVF_RoomCooling_StructuredCubes(): - spaceDim = 3; - - #Chargement du maillage cartésien du domaine - #============================================== - my_mesh = cdmath.Mesh("../resources/RoomWithCubes480.med") - - print "Loaded Structured 3D mesh" - - #Conditions limites - Tmur=20 - Tfenetre=0 - Tradiateur=40 - - FEComputation=False - myProblem = cf.StationaryDiffusionEquation(spaceDim,FEComputation); - myProblem.setMesh(my_mesh); - - myProblem.setDirichletBoundaryCondition("Fenetre",Tfenetre) - myProblem.setDirichletBoundaryCondition("Radiateur_sous_fenetre",Tradiateur) - myProblem.setDirichletBoundaryCondition("Radiateur_devant",Tmur) - myProblem.setDirichletBoundaryCondition("Radiateur_droite",Tmur) - myProblem.setDirichletBoundaryCondition("Mur",Tmur) - - # name of result file - fileName = "StationnaryDiffusion_3DVF_StructuredCubes"; - - # computation parameters - myProblem.setFileName(fileName); - - # Run the computation - myProblem.initialize(); - print("Running python "+ fileName ); - - ok = myProblem.solveStationaryProblem(); - if (not ok): - print( "Python simulation of " + fileName + " failed ! " ); - pass - else: - print( "Python simulation of " + fileName + " successful ! " ); - pass - - myProblem.terminate(); - return ok - -if __name__ == """__main__""": - StationaryDiffusionEquation_3DVF_RoomCooling_StructuredCubes() diff --git a/CoreFlows/examples/Python/StationaryDiffusionEquation_3DVF_RoomCooling_UnstructuredTetras.py b/CoreFlows/examples/Python/StationaryDiffusionEquation_3DVF_RoomCooling_UnstructuredTetras.py deleted file mode 100755 index 931bbeb..0000000 --- a/CoreFlows/examples/Python/StationaryDiffusionEquation_3DVF_RoomCooling_UnstructuredTetras.py +++ /dev/null @@ -1,61 +0,0 @@ -#!/usr/bin/env python -# -*-coding:utf-8 -* -#=============================================================================================================================== -# Name : Résolution VF de l'équation de Laplace 3D -\Delta T = 0 avec conditions aux limites de Dirichlet u non nulle (fenetre et radiateur) -# Authors : Michaël Ndjinga, Sédrick Kameni Ngwamou -# Copyright : CEA Saclay 2019 -# Description : Utilisation de la méthode des volumes finis avec champs u discrétisés aux cellules d'un maillage de tétraèdres -# Conditions limites correspondant au refroidissement dû à une fenêtre et au chauffage dû à un radiateur -# Création et sauvegarde du champ résultant ainsi que du champ second membre en utilisant la librairie CDMATH -#================================================================================================================================ - -import CoreFlows as cf -import cdmath - -def StationaryDiffusionEquation_3DVF_RoomCooling_UnstructuredTetras(): - spaceDim = 3; - - #Chargement du maillage cartésien du domaine - #============================================== - my_mesh = cdmath.Mesh("../resources/RoomWithTetras2488.med") - - print "Loaded Structured 3D mesh" - - #Conditions limites - Tmur=20 - Tfenetre=0 - Tradiateur=40 - - FEComputation=False - myProblem = cf.StationaryDiffusionEquation(spaceDim,FEComputation); - myProblem.setMesh(my_mesh); - - myProblem.setDirichletBoundaryCondition("Fenetre",Tfenetre) - myProblem.setDirichletBoundaryCondition("Radiateur_sous_fenetre",Tradiateur) - myProblem.setDirichletBoundaryCondition("Radiateur_Devant",Tmur) - myProblem.setDirichletBoundaryCondition("Radiateur_droit",Tmur) - myProblem.setDirichletBoundaryCondition("Murs",Tmur) - - # name of result file - fileName = "StationnaryDiffusion_3DVF_UnstructuredTetras"; - - # computation parameters - myProblem.setFileName(fileName); - - # Run the computation - myProblem.initialize(); - print("Running python "+ fileName ); - - ok = myProblem.solveStationaryProblem(); - if (not ok): - print( "Python simulation of " + fileName + " failed ! " ); - pass - else: - print( "Python simulation of " + fileName + " successful ! " ); - pass - - myProblem.terminate(); - return ok - -if __name__ == """__main__""": - StationaryDiffusionEquation_3DVF_RoomCooling_UnstructuredTetras() diff --git a/CoreFlows/examples/Python/TransportEquation/TransportEquation_1DHeatedChannel.py b/CoreFlows/examples/Python/TransportEquation/TransportEquation_1DHeatedChannel.py new file mode 100755 index 0000000..4d6cabc --- /dev/null +++ b/CoreFlows/examples/Python/TransportEquation/TransportEquation_1DHeatedChannel.py @@ -0,0 +1,78 @@ +#!/usr/bin/env python +# -*-coding:utf-8 -* + +import CoreFlows as cf + +def TransportEquation_1DHeatedChannel(): + + spaceDim = 1; + # Prepare for the mesh + xinf = 0 ; + xsup=4.2; + nx=10; + + # set the limit field for each boundary + inletEnthalpy=1.3e6; + + # Set the transport velocity + transportVelocity=[5]; + + myProblem = cf.TransportEquation(cf.LiquidPhase,cf.around155bars600KTransport,transportVelocity); + nVar = myProblem.getNumberOfVariables(); + + # Prepare for the initial condition + VV_Constant = [1.3e6]; #initial enthalpy + + #Set rod temperature and heat exchamge coefficient + rodTemp=623;#Rod clad temperature + heatTransfertCoeff=1000;#fluid/solid heat exchange coefficient + myProblem.setRodTemperature(rodTemp); + myProblem.setHeatTransfertCoeff(heatTransfertCoeff); + + #Initial field creation + print("Building mesh and initial data " ); + myProblem.setInitialFieldConstant(spaceDim,VV_Constant,xinf,xsup,nx,"inlet","neumann"); + + # Set the boundary conditions + myProblem.setInletBoundaryCondition("inlet", inletEnthalpy); + myProblem.setNeumannBoundaryCondition("neumann") + + # Set the numerical method + myProblem.setTimeScheme( cf.Explicit); + + # name file save + fileName = "1DFluidEnthalpy"; + + # parameters calculation + MaxNbOfTimeStep = 3 ; + freqSave = 5; + cfl = 0.95; + maxTime = 5; + precision = 1e-6; + + myProblem.setCFL(cfl); + myProblem.setPrecision(precision); + myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); + myProblem.setTimeMax(maxTime); + myProblem.setFreqSave(freqSave); + myProblem.setFileName(fileName); + + + # evolution + myProblem.initialize(); + + ok = myProblem.run(); + if (ok): + print( "Simulation python " + fileName + " is successful !" ); + pass + else: + print( "Simulation python " + fileName + " failed ! " ); + pass + + print( "------------ End of calculation !!! -----------" ); + + myProblem.terminate(); + return ok + +if __name__ == """__main__""": + TransportEquation_1DHeatedChannel() diff --git a/CoreFlows/examples/Python/TransportEquation_1DHeatedChannel.py b/CoreFlows/examples/Python/TransportEquation_1DHeatedChannel.py deleted file mode 100755 index 78d48e3..0000000 --- a/CoreFlows/examples/Python/TransportEquation_1DHeatedChannel.py +++ /dev/null @@ -1,78 +0,0 @@ -#!/usr/bin/env python -# -*-coding:utf-8 -* - -import CoreFlows as cf - -def TransportEquation_1DHeatedChannel(): - - spaceDim = 1; - # Prepare for the mesh - xinf = 0 ; - xsup=4.2; - nx=10; - - # set the limit field for each boundary - inletEnthalpy=1.3e6; - - # Set the transport velocity - transportVelocity=[5]; - - myProblem = cf.TransportEquation(cf.Liquid,cf.around155bars600K,transportVelocity); - nVar = myProblem.getNumberOfVariables(); - - # Prepare for the initial condition - VV_Constant = [1.3e6]; #initial enthalpy - - #Set rod temperature and heat exchamge coefficient - rodTemp=623;#Rod clad temperature - heatTransfertCoeff=1000;#fluid/solid heat exchange coefficient - myProblem.setRodTemperature(rodTemp); - myProblem.setHeatTransfertCoeff(heatTransfertCoeff); - - #Initial field creation - print("Building mesh and initial data " ); - myProblem.setInitialFieldConstant(spaceDim,VV_Constant,xinf,xsup,nx,"inlet","neumann"); - - # Set the boundary conditions - myProblem.setInletBoundaryCondition("inlet", inletEnthalpy); - myProblem.setNeumannBoundaryCondition("neumann") - - # Set the numerical method - myProblem.setNumericalScheme(cf.upwind, cf.Explicit); - - # name file save - fileName = "1DFluidEnthalpy"; - - # parameters calculation - MaxNbOfTimeStep = 3 ; - freqSave = 5; - cfl = 0.95; - maxTime = 5; - precision = 1e-6; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - - - # evolution - myProblem.initialize(); - - ok = myProblem.run(); - if (ok): - print( "Simulation python " + fileName + " is successful !" ); - pass - else: - print( "Simulation python " + fileName + " failed ! " ); - pass - - print( "------------ End of calculation !!! -----------" ); - - myProblem.terminate(); - return ok - -if __name__ == """__main__""": - TransportEquation_1DHeatedChannel() diff --git a/CoreFlows/examples/SinglePhase_1DDepressurisation.cxx b/CoreFlows/examples/SinglePhase_1DDepressurisation.cxx deleted file mode 100755 index 57d61ca..0000000 --- a/CoreFlows/examples/SinglePhase_1DDepressurisation.cxx +++ /dev/null @@ -1,82 +0,0 @@ -#include "SinglePhase.hxx" - -using namespace std; - -int main(int argc, char** argv) -{ - //Preprocessing: mesh and group creation - cout << "Building cartesian mesh" << endl; - double xinf=0.0; - double xsup=4.2; - int nx=50; - Mesh M(xinf,xsup,nx); - double eps=1.E-8; - M.setGroupAtPlan(xsup,0,eps,"Outlet"); - M.setGroupAtPlan(xinf,0,eps,"Wall"); - int spaceDim = M.getSpaceDimension(); - - // set the initial field - double initialPressure=155e5; - double initialVelocityX=0; - double initialTemperature=573; - - //set the boundary data for each boundary - double outletPressure=80e5; - double wallVelocityX=0; - double wallTemperature=573; - - SinglePhase myProblem(Liquid,around155bars600K,spaceDim); - int nbPhase = myProblem.getNumberOfPhases(); - - // Prepare for the initial condition - int nVar = myProblem.getNumberOfVariables(); - Vector VV_constant(nVar); - VV_constant(0) = initialPressure ; - VV_constant(1) = initialVelocityX; - VV_constant(2) = initialTemperature ; - - cout << "Building initial data" << endl; - Field VV("Primitive", CELLS, M, nVar); - - myProblem.setInitialFieldConstant(M,VV_constant); - - //set the boundary conditions - myProblem.setWallBoundaryCondition("Wall", wallTemperature, wallVelocityX); - myProblem.setOutletBoundaryCondition("Outlet", outletPressure,vector(1,xsup)); - - // set the numerical method - myProblem.setNumericalScheme(upwind, Explicit); - myProblem.setEntropicCorrection(true); - - // name file save - string fileName = "1DDepressurisation"; - - // parameters calculation - unsigned MaxNbOfTimeStep = 3; - int freqSave = 1; - double cfl = 0.95; - double maxTime = 5; - double precision = 1e-8; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - bool ok; - - // evolution - myProblem.initialize(); - - ok = myProblem.run(); - if (ok) - cout << "Simulation "< boundaryFields; - - limitInlet.T =573.; - limitInlet.bcType=Inlet; - limitInlet.v_x = vector(1,5); - boundaryFields["Inlet"] = limitInlet; - - limitOutlet.bcType=Outlet; - limitOutlet.p = 155e5; - boundaryFields["Outlet"] = limitOutlet; - - SinglePhase myProblem(Liquid,around155bars600K,spaceDim); - int nbPhase = myProblem.getNumberOfPhases(); - int nVar = myProblem.getNumberOfVariables(); - Field VV("Primitive", CELLS, M, nVar);//Field of primitive unknowns - - // Prepare for the initial condition - Vector VV_Constant(nVar); - VV_Constant(0) = 155e5;//pression initiale - VV_Constant(1) = 5;//vitesse initiale - VV_Constant(2) = 573;//temperature initiale - - cout << "Number of Phases = " << nbPhase << endl; - cout << "Construction de la condition initiale ... " << endl; - //set the initial field - myProblem.setInitialFieldConstant(M,VV_Constant); - - //set the boundary conditions - myProblem.setBoundaryFields(boundaryFields); - - //Physical parameters - double heatPower=1e8; - myProblem.setHeatSource(heatPower); - // set the numerical method - myProblem.setNumericalScheme(upwind, Explicit); - - // name file save - string fileName = "1DHeatedChannel"; - - // parameters calculation - unsigned MaxNbOfTimeStep =3; - int freqSave = 1; - double cfl = 0.95; - double maxTime = 5; - double precision = 1e-7; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - bool ok; - - // evolution - myProblem.initialize(); - - ok = myProblem.run(); - if (ok) - cout << "Simulation "< (xsup-xinf)/3 && x< 2*(xsup-xinf)/3) - porosityField[i]=0.5; - else - porosityField[i]=1; - } - porosityField.writeVTK("PorosityField",true); - - - SinglePhase myProblem(Liquid,around155bars600K,spaceDim); - int nVar = myProblem.getNumberOfVariables(); - - // Prepare for the initial condition - vector VV_Constant(nVar); - // constant vector - VV_Constant[0] = initialPressure; - VV_Constant[1] = initialVelocityX; - VV_Constant[2] = initialTemperature; - - cout << "Building initial data " << endl; - - // generate initial condition - myProblem.setInitialFieldConstant( spaceDim, VV_Constant, xinf, xsup, nx,"Inlet","Outlet"); - - //set the boundary conditions - myProblem.setInletBoundaryCondition("Inlet",initialTemperature,initialVelocityX); - myProblem.setOutletBoundaryCondition("Outlet",initialPressure,vector(1,xsup)); - // physical parameters - myProblem.setPorosityField(porosityField); - - // set the numerical method - myProblem.setNumericalScheme(upwind, Explicit); - myProblem.setWellBalancedCorrection(true); - myProblem.setNonLinearFormulation(VFFC) ; - - // name file save - string fileName = "1DPorosityJumpUpwindWB"; - - - /* set numerical parameters */ - unsigned MaxNbOfTimeStep =3; - int freqSave = 1; - double cfl = 0.95; - double maxTime = 5; - double precision = 1e-5; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - bool ok; - - // evolution - myProblem.initialize(); - - ok = myProblem.run(); - if (ok) - cout << "Simulation "< viscosite(1), conductivite(1); - viscosite[0]= 8.85e-5; - conductivite[0]=1000;//transfert de chaleur du à l'ébullition en paroi. - vector gravite(spaceDim,0.) ; - gravite[1]=-10; - gravite[0]=0; - - // set the limit field for each boundary - LimitField limitColdWall, limitHotWall; - map boundaryFields; - limitColdWall.bcType=Wall; - limitColdWall.T = 590;//Temperature de la parois froide - limitColdWall.v_x = vector(1,0); - limitColdWall.v_y = vector(1,0); - boundaryFields["coldWall"]= limitColdWall; - - limitHotWall.bcType=Wall; - limitHotWall.T = 560;//Temperature des parois chauffantes - limitHotWall.v_x = vector(1,0); - limitHotWall.v_y = vector(1,0); - boundaryFields["hotWall"]= limitHotWall; - - SinglePhase myProblem(Liquid,around155bars600K,spaceDim); - int nVar = myProblem.getNumberOfVariables(); - - //Initial field creation - cout << "Building initial data" << endl; - /* First case constant initial data */ - Vector VV_Constant(nVar); - // constant vector - VV_Constant(0) = 155e5; - VV_Constant(1) = 0; - VV_Constant(2) = 0; - VV_Constant(3) = 573; - - myProblem.setInitialFieldConstant(M,VV_Constant); - - //set the boundary conditions - myProblem.setBoundaryFields(boundaryFields); - - // physical parameters - myProblem.setViscosity(viscosite); - myProblem.setConductivity(conductivite); - myProblem.setGravity(gravite); - - // set the numerical method - myProblem.setNumericalScheme(upwind, Implicit); - - // set the Petsc resolution - myProblem.setLinearSolver(GMRES,LU,false); - - // name result file - string fileName = "2DHeatDrivenCavity"; - - // parameters calculation - unsigned MaxNbOfTimeStep = 3; - int freqSave = 1; - double cfl = 10; - double maxTime = 50; - double precision = 1e-6; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - myProblem.setNewtonSolver(precision,50); - myProblem.saveVelocity(); - - // evolution - myProblem.initialize(); - - bool ok = myProblem.run(); - if (ok) - cout << "Simulation "< viscosite(1), conductivite(1); - viscosite[0]= 8.85e-5; - conductivite[0]=1000;//transfert de chaleur du à l'ébullition en paroi. - vector gravite(spaceDim,0.) ; - gravite[1]=-10; - gravite[0]=0; - - // set the limit field for each boundary - LimitField limitColdWall, limitHotWall; - map boundaryFields; - limitColdWall.bcType=Wall; - limitColdWall.T = 590;//Temperature de la parois froide - limitColdWall.v_x = vector(1,0); - limitColdWall.v_y = vector(1,0); - boundaryFields["coldWall"]= limitColdWall; - - limitHotWall.bcType=Wall; - limitHotWall.T = 560;//Temperature des parois chauffantes - limitHotWall.v_x = vector(1,0); - limitHotWall.v_y = vector(1,0); - boundaryFields["hotWall"]= limitHotWall; - - SinglePhase myProblem(Liquid,around155bars600K,spaceDim); - int nVar = myProblem.getNumberOfVariables(); - - //Initial field creation - cout << "Construction de la condition initiale" << endl; - /* First case constant initial data */ - Vector VV_Constant(nVar); - // constant vector - VV_Constant(0) = 155e5; - VV_Constant(1) = 0; - VV_Constant(2) = 0; - VV_Constant(3) = 573; - - myProblem.setInitialFieldConstant(M,VV_Constant); - - //set the boundary conditions - myProblem.setBoundaryFields(boundaryFields); - - // physical parameters - myProblem.setViscosity(viscosite); - myProblem.setConductivity(conductivite); - myProblem.setGravity(gravite); - - // set the numerical method - myProblem.setNumericalScheme(upwind, Implicit); - - // set the Petsc resolution - myProblem.setLinearSolver(GMRES,ILU,true); - - // name result file - string fileName = "2DHeatDrivenCavity_unstructured"; - - // parameters calculation - unsigned MaxNbOfTimeStep = 3; - int freqSave = 1; - double cfl = 1; - double maxTime = 50; - double precision = 1e-7; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - myProblem.setNewtonSolver(precision,50); - myProblem.saveVelocity(); - - // evolution - myProblem.initialize(); - bool ok = myProblem.run(); - if (ok) - cout << "Simulation "< - -using namespace std; - -int main(int argc, char** argv) -{ - int spaceDim = 2; - - // Prepare for the mesh - double xinf = 0 ; - double xsup=3.0; - double yinf=0.0; - double ysup=5.0; - int nx=10; - int ny=10; - - // set the limit field for each boundary - double wallVelocityX=0; - double wallVelocityY=0; - double wallTemperature=573; - double inletVelocityX=0; - double inletVelocityY=0.5; - double inletTemperature=563; - double outletPressure=155e5; - - // physical constants - vector gravite (spaceDim); - - gravite[1]=-7; - gravite[0]=7; - - double heatPower=1e8; - - SinglePhase myProblem(Liquid,around155bars600K,spaceDim); - int nVar =myProblem.getNumberOfVariables(); - - // Prepare for the initial condition - vector VV_Constant (nVar); - - // constant vector - VV_Constant[0] = outletPressure ; - VV_Constant[1] = inletVelocityX; - VV_Constant[2] = inletVelocityY; - VV_Constant[3] = inletTemperature ; - - //Initial field creation - cout<<"Building initial data"<pressure_reference_point(2); - pressure_reference_point[0]=xsup; - pressure_reference_point[1]=ysup; - myProblem.setOutletBoundaryCondition("outlet", outletPressure,pressure_reference_point); - myProblem.setInletBoundaryCondition("inlet", inletTemperature, inletVelocityX, inletVelocityY); - myProblem.setWallBoundaryCondition("wall", wallTemperature, wallVelocityX, wallVelocityY); - - // set physical parameters - myProblem.setHeatSource(heatPower); - myProblem.setGravity(gravite); - - // set the numerical method - myProblem.setNumericalScheme(staggered, Implicit); - myProblem.setNonLinearFormulation(VFFC); - - // name file save - string fileName = "2DInclinedHeatedChannel"; - - /* set numerical parameters */ - unsigned MaxNbOfTimeStep =3; - int freqSave = 1; - double cfl = 0.95; - double maxTime = 5; - double precision = 1e-5; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - myProblem.usePrimitiveVarsInNewton(true); - bool ok; - - // evolution - myProblem.initialize(); - - ok = myProblem.run(); - if (ok) - cout << "Simulation "< viscosite(1) ; - viscosite[0]= 0.025; - - // set the limit field for each boundary - double fixedWallVelocityX=0; - double fixedWallVelocityY=0; - double fixedWallTemperature=273; - - double movingWallVelocityX=1; - double movingWallVelocityY=0; - double movingWallTemperature=273; - - - SinglePhase myProblem(Gas,around1bar300K,spaceDim); - // Prepare for the initial condition - int nVar = myProblem.getNumberOfVariables(); - vector VV_Constant(nVar); - // constant vector - VV_Constant[0] = 1e5; - VV_Constant[1] = 0; - VV_Constant[2] = 0; - VV_Constant[3] = 273; - - // name output file - string fileName = "2DLidDrivenCavityStructuredCentered1bar"; - - //Initial field creation - cout << "Building initial data" << endl; - myProblem.setInitialFieldConstant(spaceDim,VV_Constant,xinf,xsup,nx,"fixedWall","fixedWall",yinf,ysup,ny,"fixedWall","movingWall"); - - //set the boundary conditions - myProblem.setWallBoundaryCondition("fixedWall", fixedWallTemperature, fixedWallVelocityX, fixedWallVelocityY); - myProblem.setWallBoundaryCondition("movingWall", movingWallTemperature, movingWallVelocityX, movingWallVelocityY); - - // physical parameters - myProblem.setViscosity(viscosite); - - // set the numerical method - myProblem.setNumericalScheme(staggered, Implicit); - - // set the Petsc resolution - myProblem.setLinearSolver(GMRES,LU,true); - - //Numerical parameters - unsigned MaxNbOfTimeStep = 3 ; - int freqSave = 1; - double cfl = 1; - double maxTime = 100000; - double precision = 1e-9; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - myProblem.setNewtonSolver(precision*1e8,20); - myProblem.saveVelocity(); - - // evolution - myProblem.initialize(); - - bool ok = myProblem.run(); - if (ok) - cout << "Simulation "< viscosite(1) ; - viscosite[0]= 0.025; - - /* set the limit field for each boundary*/ - LimitField limitWall; - map boundaryFields; - limitWall.bcType=Wall; - limitWall.T = 273; - limitWall.p = 1e5; - limitWall.v_x = vector(1,0); - limitWall.v_y = vector(1,0); - limitWall.v_z = vector(1,0); - boundaryFields["wall"]= limitWall; - - LimitField limitMovingWall; - limitMovingWall.bcType=Wall; - limitMovingWall.T = 273; - limitMovingWall.p = 1e5; - limitMovingWall.v_x = vector(1,1); - limitMovingWall.v_y = vector(1,0); - limitMovingWall.v_z = vector(1,0); - boundaryFields["MovingWall"]= limitMovingWall; - - - SinglePhase myProblem(Liquid,around1bar300K,spaceDim); - int nbPhase = myProblem.getNumberOfPhases(); - // Prepare for the initial condition - int nVar = myProblem.getNumberOfVariables(); - Vector VV_Constant(nVar); - // constant vector - VV_Constant(0) = 1e5; - VV_Constant(1) = 0; - VV_Constant(2) = 0; - VV_Constant(3) = 273; - - //Initial field creation - cout << "Setting initial data " << endl; - myProblem.setInitialFieldConstant(M,VV_Constant); - - //set the boundary conditions - myProblem.setBoundaryFields(boundaryFields); - - // physical parameters - myProblem.setViscosity(viscosite); - - // set the numerical method - myProblem.setNumericalScheme(upwind, Implicit); - - // set the Petsc resolution - myProblem.setLinearSolver(GMRES,ILU,true); - - // name file save - string fileName = "2DLidDrivenCavity_unstructured"; - - // parameters calculation - unsigned MaxNbOfTimeStep = 3 ; - int freqSave = 1; - double cfl = 5; - double maxTime = 5; - double precision = 1e-8; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - myProblem.setNewtonSolver(precision,20); - myProblem.saveVelocity(); - - // evolution - myProblem.initialize(); - - bool ok = myProblem.run(); - if (ok) - cout << "Simulation "<Vout(nVar), Vin(nVar); - Vin[0]=1.1; - Vin[1]=0; - Vin[2]=0; - Vin[3]=300; - Vout[0]=1; - Vout[1]=0; - Vout[2]=0; - Vout[3]=300; - - for(int i=0;i viscosite(1), conductivite(1); - viscosite[0]= 8.85e-5; - conductivite[0]=1000;//transfert de chaleur du à l'ébullition en paroi. - - // set the limit field for each boundary - LimitField limitWall; - map boundaryFields; - limitWall.bcType=Wall; - limitWall.T = 623;//Temperature des parois chauffantes - limitWall.p = 155e5; - limitWall.v_x = vector(1,0); - limitWall.v_y = vector(1,0); - boundaryFields["wall"]= limitWall; - - LimitField limitInlet; - limitInlet.bcType=Inlet; - limitInlet.T = 573;//Temperature d'entree du fluide - limitInlet.v_x = vector(1,0); - limitInlet.v_y = vector(1,5);//Vitesse d'entree du fluide - boundaryFields["Inlet"]= limitInlet; - - LimitField limitOutlet; - limitOutlet.bcType=Outlet; - limitOutlet.p = 155e5; - boundaryFields["Outlet"]= limitOutlet; - - LimitField limitNeumann; - limitNeumann.bcType=Neumann; - boundaryFields["Neumann"] = limitNeumann; - - SinglePhase myProblem(Liquid,around155bars600K,spaceDim); - int nVar = myProblem.getNumberOfVariables(); - - //Initial field creation - cout << "Construction de la condition initiale" << endl; - /* First case constant initial data */ - Vector VV_Constant(nVar); - // constant vector - VV_Constant(0) = 155e5; - VV_Constant(1) = 0; - VV_Constant(2) = 5; - VV_Constant(3) = 573; - /* Second case restart from a previous calculation */ -/* - string inputfile = "SinglePhasePrim_2DChannelWithViscosityWithConduction";//nom du fichier (sans le .med) - int iter=50400;//numero du pas de temps a recuperer dans le fichier - Field VV1(inputfile,CELLS,"P,vx,vy,T",iter,0);//Chargement des valeurs du champ - for(int i=0;i boundaryFields; - limitWall.bcType=Wall; - limitWall.T = 623;//Temperature des parois chauffantes - limitWall.p = 155e5; - limitWall.v_x = vector(1,0); - limitWall.v_y = vector(1,0); - boundaryFields["Wall"]= limitWall; - - LimitField limitInlet; - limitInlet.bcType=Inlet; - limitInlet.T = 573;//Temperature d'entree du fluide - limitInlet.v_x = vector(1,0); - limitInlet.v_y = vector(1,2.5);//Vitesse d'entree du fluide - boundaryFields["Inlet"]= limitInlet; - - LimitField limitOutlet; - limitOutlet.bcType=Outlet; - limitOutlet.p = 155e5; - boundaryFields["Outlet"]= limitOutlet; - - SinglePhase myProblem(Liquid,around155bars600K,spaceDim); - // Prepare for the initial condition - int nVar = myProblem.getNumberOfVariables(); - Vector VV_Constant(nVar); - // constant vector - VV_Constant(0) = 155e5; - VV_Constant(1) = 0; - VV_Constant(2) = 2.5; - VV_Constant(3) = 573; - - //Initial field creation - cout << "Building initial data" << endl; - myProblem.setInitialFieldConstant(M,VV_Constant); - - // physical constants - vector viscosite(1), conductivite(1); - viscosite[0]= 8.85e-5; - conductivite[0]=1000;//transfert de chaleur du à l'ébullition en paroi. - - //Set boundary values - myProblem.setBoundaryFields(boundaryFields); - - // set the numerical method - myProblem.setNumericalScheme(upwind, Explicit); - - // name result file - string fileName = "2DWallHeatedChannel_ChangeSect"; - - // parameters calculation - unsigned MaxNbOfTimeStep = 3; - int freqSave = 1; - double cfl =.5; - double maxTime = 500; - double precision = 1e-6; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - myProblem.setNewtonSolver(precision,50); - myProblem.saveVelocity(); - - // evolution - myProblem.initialize(); - bool ok = myProblem.run(); - if (ok) - cout << "Simulation "< gravite(spaceDim,0.) ; - gravite[2]=-10; - gravite[1]=0; - gravite[0]=0; - vector viscosite(1), conductivite(1); - viscosite[0]= 8.85e-5; - conductivite[0]=1000;//nucleate boiling heat transfert coefficient - - SinglePhase myProblem(Liquid,around155bars600K,spaceDim); - int nVar = myProblem.getNumberOfVariables(); - - //Initial field creation - cout << "Construction de la condition initiale" << endl; - vector VV_Constant(nVar); - // constant vector - VV_Constant[0] = 155e5; - VV_Constant[1] = 0; - VV_Constant[2] = 0; - VV_Constant[3] = 0; - VV_Constant[4] = 573; - myProblem.setInitialFieldConstant(spaceDim,VV_Constant,xinf,xsup,nx,"hotWall","hotWall", - yinf,ysup,ny,"hotWall","hotWall", - zinf,zsup,nz,"hotWall","coldWall"); - - //set the boundary conditions - myProblem.setWallBoundaryCondition("coldWall", coldWallTemperature, coldWallVelocityX, coldWallVelocityY, coldWallVelocityZ); - myProblem.setWallBoundaryCondition("hotWall", hotWallTemperature, hotWallVelocityX, hotWallVelocityY, hotWallVelocityZ); - - - // physical parameters - myProblem.setViscosity(viscosite); - myProblem.setConductivity(conductivite); - myProblem.setGravity(gravite); - - // set the numerical method - myProblem.setNumericalScheme(upwind, Implicit); - - // set the Petsc resolution - myProblem.setLinearSolver(GMRES,ILU,false); - - // name result file - string fileName = "3DHeatDrivenCavity"; - - // parameters calculation - unsigned MaxNbOfTimeStep = 3; - int freqSave = 1; - double cfl = 10; - double maxTime = 50; - double precision = 1e-6; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - myProblem.setNewtonSolver(precision,50); - myProblem.saveVelocity(); - - // evolution - myProblem.initialize(); - bool ok = myProblem.run(); - if (ok) - cout << "Simulation "< gravite(1,-10); - myProblem.setGravity(gravite); - - //Set section field - myProblem.setSectionField(Sections); - // Prepare the initial condition - Vector VV_Constant(nVar); - VV_Constant(0) = 155e5; - VV_Constant(1) = 5; - VV_Constant(2) = 573; - - cout << "Building initial data " << endl; - - // generate initial condition - myProblem.setInitialFieldConstant(M,VV_Constant); - - //set the boundary conditions - myProblem.setInletBoundaryCondition("Inlet",inletTemperature,inletVelocityX); - myProblem.setOutletBoundaryCondition("Outlet", outletPressure); - - // set the numerical method - myProblem.setNumericalScheme(upwind, Explicit); - myProblem.setWellBalancedCorrection(true); - - // name file save - string fileName = "2BranchesHeatedChannels"; - - // parameters calculation - unsigned MaxNbOfTimeStep =3; - int freqSave = 1; - double cfl = 0.5; - double maxTime = 5; - double precision = 1e-6; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - bool ok; - - // evolution - myProblem.initialize(); - ok = myProblem.run(); - if (ok) - cout << "Simulation "< - -double pi = M_PI; -using namespace std; - -int main(int argc, char** argv) -{ - int spaceDim = 2; - - /* Mesh data */ - double xinf=0.0; - double xsup=1.0; - double yinf=0.0; - double ysup=1.0; - int nx=20; - int ny=20; - - /* Mesh construction */ - Mesh M(xinf,xsup,nx,yinf,ysup,ny,0); //Regular triangular mesh - - /* set the limit field for each boundary */ - double eps=1e-6; - M.setGroupAtPlan(xsup,0,eps,"Bord1"); - M.setGroupAtPlan(xinf,0,eps,"Bord2"); - M.setGroupAtPlan(ysup,1,eps,"Bord3"); - M.setGroupAtPlan(yinf,1,eps,"Bord4"); - - /* set the boundary values for each boundary */ - double T1=0; - double T2=0; - double T3=0; - double T4=0; - - cout<< "Built a regular triangular 2D mesh from a square mesh with "<< nx<<"x" < - -double pi = M_PI; -using namespace std; - -int main(int argc, char** argv) -{ - int spaceDim = 2; - - /* Mesh data */ - double xinf=0.0; - double xsup=1.0; - double yinf=0.0; - double ysup=1.0; - int nx=20; - int ny=20; - - /* Mesh construction */ - Mesh M(xinf,xsup,nx,yinf,ysup,ny,0); //Regular triangular mesh - - /* set the limit field for each boundary */ - double eps=1e-6; - M.setGroupAtPlan(xsup,0,eps,"Bord1"); - M.setGroupAtPlan(xinf,0,eps,"Bord2"); - M.setGroupAtPlan(ysup,1,eps,"Bord3"); - M.setGroupAtPlan(yinf,1,eps,"Bord4"); - - /* set the boundary values for each boundary */ - double T1=0; - double T2=0; - double T3=0; - double T4=0; - - cout<< "Built a regular triangular 2D mesh from a square mesh with "<< nx<<"x" < - -double pi = M_PI; -using namespace std; - -int main(int argc, char** argv) -{ - int spaceDim = 2; - - /* Square mesh and groups loading */ - string filename="resources/squareWithTriangles.med"; - cout << "Loading mesh and groups from file" << filename< - -double pi = M_PI; -using namespace std; - -int main(int argc, char** argv) -{ - int spaceDim = 2; - - /* Mesh data */ - double xinf=0.0; - double xsup=1.0; - double yinf=0.0; - double ysup=1.0; - int nx=30; - int ny=30; - - /* Mesh construction */ - Mesh M(xinf,xsup,nx,yinf,ysup,ny); //Regular square mesh - - /* set the limit field for each boundary */ - double eps=1e-6; - M.setGroupAtPlan(xsup,0,eps,"Bord1"); - M.setGroupAtPlan(xinf,0,eps,"Bord2"); - M.setGroupAtPlan(ysup,1,eps,"Bord3"); - M.setGroupAtPlan(yinf,1,eps,"Bord4"); - - /* set the boundary values for each boundary */ - double T1=0; - double T2=0; - double T3=0; - double T4=0; - - cout<< "Built a regular square 2D mesh with "<< nx<<"x" < - -double pi = M_PI; -using namespace std; - -int main(int argc, char** argv) -{ - int spaceDim = 2; - - /* Mesh data */ - double xinf=0.0; - double xsup=1.0; - double yinf=0.0; - double ysup=1.0; - int nx=20; - int ny=20; - - /* Mesh construction */ - Mesh M(xinf,xsup,nx,yinf,ysup,ny,0); //Regular triangular mesh - - /* set the limit field for each boundary */ - double eps=1e-6; - M.setGroupAtPlan(xsup,0,eps,"Bord1"); - M.setGroupAtPlan(xinf,0,eps,"Bord2"); - M.setGroupAtPlan(ysup,1,eps,"Bord3"); - M.setGroupAtPlan(yinf,1,eps,"Bord4"); - - /* set the boundary values for each boundary */ - double T1=0; - double T2=0; - double T3=0; - double T4=0; - - cout<< "Building of a regular triangular 2D mesh from a square mesh with "<< nx<<"x" < - -double pi = M_PI; -using namespace std; - -int main(int argc, char** argv) -{ - int spaceDim = 2; - - /* Mesh data */ - double xinf=0.0; - double xsup=1.0; - double yinf=0.0; - double ysup=1.0; - int nx=20; - int ny=20; - - /* Mesh construction */ - Mesh M(xinf,xsup,nx,yinf,ysup,ny,0); //Regular triangular mesh - - /* set the limit field for each boundary */ - double eps=1e-6; - M.setGroupAtPlan(xsup,0,eps,"Bord1"); - M.setGroupAtPlan(xinf,0,eps,"Bord2"); - M.setGroupAtPlan(ysup,1,eps,"Bord3"); - M.setGroupAtPlan(yinf,1,eps,"Bord4"); - - /* set the boundary values for each boundary */ - double T1=0; - double T2=0; - double T3=0; - double T4=0; - - cout<< "Building of a regular triangular 2D mesh from a square mesh with "<< nx<<"x" < - -double pi = M_PI; -using namespace std; - -int main(int argc, char** argv) -{ - int spaceDim = 3; - - /* Mesh data */ - double xinf=0.0; - double xsup=1.0; - double yinf=0.0; - double ysup=1.0; - double zinf=0.0; - double zsup=1.0; - int nx=2; - int ny=2; - int nz=2; - - /* Mesh construction : splitting polity to 0 yield all nodes considered boundary nodes */ - Mesh M(xinf,xsup,nx,yinf,ysup,ny,zinf,zsup,nz,0); //Regular tetrahadral mesh - - /* set the limit field for each boundary */ - double eps=1e-6; - M.setGroupAtPlan(xsup,0,eps,"Bord1"); - M.setGroupAtPlan(xinf,0,eps,"Bord2"); - M.setGroupAtPlan(ysup,1,eps,"Bord3"); - M.setGroupAtPlan(yinf,1,eps,"Bord4"); - M.setGroupAtPlan(zsup,2,eps,"Bord5"); - M.setGroupAtPlan(zinf,2,eps,"Bord6"); - - /* set the boundary values for each boundary */ - double T1=0; - double T2=0; - double T3=0; - double T4=0; - double T5=0; - double T6=0; - - cout<< "Built a regular tetrahedral 3D mesh from a cube mesh with "<< nx<<"x" < - -double pi = M_PI; -using namespace std; - -int main(int argc, char** argv) -{ - int spaceDim = 3; - - /* Mesh data */ - double xinf=0.0; - double xsup=1.0; - double yinf=0.0; - double ysup=1.0; - double zinf=0.0; - double zsup=1.0; - int nx=2; - int ny=2; - int nz=2; - - /* Mesh construction : splitting polity to 0 yield all nodes considered boundary nodes */ - Mesh M(xinf,xsup,nx,yinf,ysup,ny,zinf,zsup,nz,0); //Regular tetrahadral mesh - - /* set the limit field for each boundary */ - double eps=1e-6; - M.setGroupAtPlan(xsup,0,eps,"Bord1"); - M.setGroupAtPlan(xinf,0,eps,"Bord2"); - M.setGroupAtPlan(ysup,1,eps,"Bord3"); - M.setGroupAtPlan(yinf,1,eps,"Bord4"); - M.setGroupAtPlan(zsup,2,eps,"Bord5"); - M.setGroupAtPlan(zinf,2,eps,"Bord6"); - - /* set the boundary values for each boundary */ - double T1=0; - double T2=0; - double T3=0; - double T4=0; - double T5=0; - double T6=0; - - cout<< "Built a regular tetrahedral 3D mesh from a cube mesh with "<< nx<<"x" < boundaryFields; - - LimitField limitNeumann; - limitNeumann.bcType=Neumann; - boundaryFields["Neumann"] = limitNeumann; - - LimitField limitInlet; - limitInlet.bcType=Inlet; - limitInlet.h =1.3e6;//Inlet water enthalpy - boundaryFields["Inlet"] = limitInlet; - - //Set the fluid transport velocity - vector transportVelocity(1,5);//fluid velocity vector - - TransportEquation myProblem(Liquid,around155bars600K,transportVelocity); - Field VV("Enthalpy", CELLS, M, 1); - - //Set rod temperature and heat exchamge coefficient - double rodTemp=623;//Rod clad temperature - double heatTransfertCoeff=1000;//fluid/solid exchange coefficient - myProblem.setRodTemperature(rodTemp); - myProblem.setHeatTransfertCoeff(heatTransfertCoeff); - - //Initial field creation - Vector VV_Constant(1);//initial enthalpy - VV_Constant(0) = 1.3e6; - - cout << "Building the initial data " << endl; - - // generate initial condition - myProblem.setInitialFieldConstant(M,VV_Constant); - - //set the boundary conditions - myProblem.setBoundaryFields(boundaryFields); - - // set the numerical method - myProblem.setNumericalScheme(upwind, Explicit); - - // name result file - string fileName = "1DFluidEnthalpy"; - - // parameters calculation - unsigned MaxNbOfTimeStep =3; - int freqSave = 1; - double cfl = 0.95; - double maxTime = 5; - double precision = 1e-6; - - myProblem.setCFL(cfl); - myProblem.setPrecision(precision); - myProblem.setMaxNbOfTimeStep(MaxNbOfTimeStep); - myProblem.setTimeMax(maxTime); - myProblem.setFreqSave(freqSave); - myProblem.setFileName(fileName); - - // set display option to monitor the calculation - bool computation=true; - bool system=true; - myProblem.setVerbose( computation, system); - myProblem.setSaveFileFormat(CSV); - - // evolution - myProblem.initialize(); - bool ok = myProblem.run(); - if (ok) - cout << "Simulation "< - -#include - -using namespace std; - -int main(int argc, char** argv) { - double _Tsat = 656; //saturation temperature used in Dellacherie EOS - StiffenedGasDellacherie fluid1 = StiffenedGasDellacherie(1.43, 0, - 2.030255e6, 1040.14); //stiffened gas law for Gas from S. Dellacherie - StiffenedGasDellacherie fluid2 = StiffenedGasDellacherie(2.35, 1e9, - -1.167056e6, 1816.2); //stiffened gas law for water from S. Dellacherie - - double P = 155e6; - double T = 500; - double h = 0; - - double rho1 = fluid1.getDensity(P, T); - double Tvalid1 = fluid1.getTemperatureFromPressure(P, rho1); - double h1 = fluid1.getEnthalpy(T, rho1); - - cout << endl; - cout << "density fluide 1 = " << rho1 << endl; - cout << "Tvalid1 fluide 1 = " << Tvalid1 << endl; - cout << "h1 fluide 1 = " << h1 << endl; - - return EXIT_SUCCESS; -} diff --git a/CoreFlows/swig/CMakeLists.txt b/CoreFlows/swig/CMakeLists.txt index 7b005ea..0ad4399 100755 --- a/CoreFlows/swig/CMakeLists.txt +++ b/CoreFlows/swig/CMakeLists.txt @@ -6,15 +6,9 @@ SET_SOURCE_FILES_PROPERTIES(CoreFlows.i PROPERTIES SWIG_DEFINITIONS "-shadow") INCLUDE_DIRECTORIES( ${PYTHON_INCLUDE_DIRS} - ${CoreFlows_SRC}/inc + ${CoreFlows_INCLUDES} # ) -INCLUDE_DIRECTORIES( - ${PETSC_INCLUDES} - ${CDMATH_INCLUDES} - ${CDMATH_INCLUDES}/med # - ${CDMATH_INCLUDES}/medcoupling # -) SET(_extra_lib_SWIG ${CDMATH_LIBRARIES} ${PETSC_LIBRARIES})