From 75cb8badcc5ed8dd26e8d0e2f1029f6e45fe9144 Mon Sep 17 00:00:00 2001 From: michael Date: Sat, 30 Oct 2021 23:01:54 +0200 Subject: [PATCH] Better handling of field support (CELLS vs NODES) --- .../inc/StationaryDiffusionEquation.hxx | 2 +- CoreFlows/Models/src/ProblemCoreFlows.cxx | 11 ++- CoreFlows/Models/src/ProblemFluid.cxx | 9 ++- .../src/StationaryDiffusionEquation.cxx | 73 +++++++------------ CoreFlows/Models/src/TransportEquation.cxx | 2 + 5 files changed, 44 insertions(+), 53 deletions(-) diff --git a/CoreFlows/Models/inc/StationaryDiffusionEquation.hxx b/CoreFlows/Models/inc/StationaryDiffusionEquation.hxx index 7810a39..7bd065e 100755 --- a/CoreFlows/Models/inc/StationaryDiffusionEquation.hxx +++ b/CoreFlows/Models/inc/StationaryDiffusionEquation.hxx @@ -217,7 +217,7 @@ protected : 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 + static Vector gradientNodal(Matrix M, vector< double > v);//gradient of nodal shape functions double computeDiffusionMatrixFE(bool & stop); static int fact(int n); static int unknownNodeIndex(int globalIndex, std::vector< int > dirichletNodes); diff --git a/CoreFlows/Models/src/ProblemCoreFlows.cxx b/CoreFlows/Models/src/ProblemCoreFlows.cxx index c19cc8d..aea9a50 100755 --- a/CoreFlows/Models/src/ProblemCoreFlows.cxx +++ b/CoreFlows/Models/src/ProblemCoreFlows.cxx @@ -124,6 +124,12 @@ void ProblemCoreFlows::setInitialField(const Field &VV) _runLogFile->close(); throw CdmathException("ProblemCoreFlows::setInitialField: Initial field has incorrect number of components"); } + if(_FECalculation && VV.getTypeOfField()!=NODES) + { + *_runLogFile<<"ProblemCoreFlows::setInitialField: Initial field has incorrect support : should be on nodes for the Finite Element method"<close(); + throw CdmathException("ProblemCoreFlows::setInitialField: Initial field has incorrect support : should be on nodes for the Finite Element method"); + } _VV=VV; _VV.setName("SOLVERLAB results"); @@ -622,10 +628,7 @@ ProblemCoreFlows::getEigenvectorsField(int nev, EPSWhich which, double tol) cons 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 = Field("Eigenvectors field", _VV.getTypeOfField(), _mesh, nev); my_eigenfield.setFieldByDataArrayDouble(d); diff --git a/CoreFlows/Models/src/ProblemFluid.cxx b/CoreFlows/Models/src/ProblemFluid.cxx index 8f497d3..731b5a7 100755 --- a/CoreFlows/Models/src/ProblemFluid.cxx +++ b/CoreFlows/Models/src/ProblemFluid.cxx @@ -42,11 +42,18 @@ void ProblemFluid::setNumericalScheme(SpaceScheme spaceScheme, TimeScheme timeSc void ProblemFluid::initialize() { - if(!_initialDataSet){ + if(!_initialDataSet) + { *_runLogFile<<"ProblemFluid::initialize() set initial data first"<close(); throw CdmathException("ProblemFluid::initialize() set initial data first"); } + else if (_VV.getTypeOfField() != CELLS) + { + *_runLogFile<<"Initial data should be a field on CELLS, not NODES, neither FACES"<close(); + throw CdmathException("ProblemFluid::initialize() Initial data should be a field on CELLS, not NODES, neither FACES"); + } cout << "Number of Phases = " << _nbPhases << " mesh dimension = "<<_Ndim<<" number of variables = "<<_nVar< values){ - vector< Matrix > matrices(_Ndim); +Vector StationaryDiffusionEquation::gradientNodal(Matrix M, vector< double > values) +{ + if(! M.isSquare() ) + throw CdmathException("DiffusionEquation::gradientNodal Matrix M should be square !!!"); + + int Ndim = M.getNumberOfRows(); + vector< Matrix > matrices(Ndim); - for (int idim=0; idim<_Ndim;idim++){ + for (int idim=0; idim